Merge lp:~lool/linaro-image-tools/samsung-v310-v3 into lp:~angus-akkea/linaro-image-tools/Samsung-SMDKV310
- samsung-v310-v3
- Merge into Samsung-SMDKV310
Proposed by
Loïc Minier
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 309 | ||||
Proposed branch: | lp:~lool/linaro-image-tools/samsung-v310-v3 | ||||
Merge into: | lp:~angus-akkea/linaro-image-tools/Samsung-SMDKV310 | ||||
Diff against target: |
420 lines (+112/-70) 2 files modified
linaro_media_create/boards.py (+46/-28) linaro_media_create/tests/test_media_create.py (+66/-42) |
||||
To merge this branch: | bzr merge lp:~lool/linaro-image-tools/samsung-v310-v3 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Angus Ainslie | Pending | ||
Review via email:
|
Commit message
Description of the change
This addresses some other comments from Guilherme and adds tests.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'linaro_media_create/boards.py' | |||
2 | --- linaro_media_create/boards.py 2011-03-02 19:57:43 +0000 | |||
3 | +++ linaro_media_create/boards.py 2011-03-05 00:53:54 +0000 | |||
4 | @@ -95,7 +95,7 @@ | |||
5 | 95 | SAMSUNG_V310_UINITRD_START = ( | 95 | SAMSUNG_V310_UINITRD_START = ( |
6 | 96 | SAMSUNG_V310_UIMAGE_START + SAMSUNG_V310_UIMAGE_LEN) | 96 | SAMSUNG_V310_UIMAGE_START + SAMSUNG_V310_UIMAGE_LEN) |
7 | 97 | SAMSUNG_V310_UINITRD_RESERVED_LEN = 204800 | 97 | SAMSUNG_V310_UINITRD_RESERVED_LEN = 204800 |
9 | 98 | SAMSUNG_V310_UINITRD_COPY_LEN = 32768 | 98 | SAMSUNG_V310_UINITRD_COPY_LEN = 32768 |
10 | 99 | assert SAMSUNG_V310_UINITRD_START == 9281, ( | 99 | assert SAMSUNG_V310_UINITRD_START == 9281, ( |
11 | 100 | "BL2 (u-boot) expects uInitrd at +9281s") | 100 | "BL2 (u-boot) expects uInitrd at +9281s") |
12 | 101 | assert SAMSUNG_V310_UINITRD_RESERVED_LEN * SECTOR_SIZE == 100 * 1024 * 1024, ( | 101 | assert SAMSUNG_V310_UINITRD_RESERVED_LEN * SECTOR_SIZE == 100 * 1024 * 1024, ( |
13 | @@ -120,6 +120,14 @@ | |||
14 | 120 | return start, end, length | 120 | return start, end, length |
15 | 121 | 121 | ||
16 | 122 | 122 | ||
17 | 123 | class classproperty(object): | ||
18 | 124 | """A descriptor that provides @property behavior on class methods.""" | ||
19 | 125 | def __init__(self, getter): | ||
20 | 126 | self.getter = getter | ||
21 | 127 | def __get__(self, instance, cls): | ||
22 | 128 | return self.getter(cls) | ||
23 | 129 | |||
24 | 130 | |||
25 | 123 | class BoardConfig(object): | 131 | class BoardConfig(object): |
26 | 124 | """The configuration used when building an image for a board.""" | 132 | """The configuration used when building an image for a board.""" |
27 | 125 | # These attributes may not need to be redefined on some subclasses. | 133 | # These attributes may not need to be redefined on some subclasses. |
28 | @@ -178,8 +186,8 @@ | |||
29 | 178 | return '%s,%s,%s,*\n%s,,,-' % ( | 186 | return '%s,%s,%s,*\n%s,,,-' % ( |
30 | 179 | boot_start, boot_len, partition_type, root_start) | 187 | boot_start, boot_len, partition_type, root_start) |
31 | 180 | 188 | ||
34 | 181 | @classmethod | 189 | @classproperty |
35 | 182 | def _get_bootcmd(cls): | 190 | def bootcmd(cls): |
36 | 183 | """Get the bootcmd for this board. | 191 | """Get the bootcmd for this board. |
37 | 184 | 192 | ||
38 | 185 | In general subclasses should not have to override this. | 193 | In general subclasses should not have to override this. |
39 | @@ -232,7 +240,7 @@ | |||
40 | 232 | boot_env = {} | 240 | boot_env = {} |
41 | 233 | boot_env["bootargs"] = cls._get_bootargs( | 241 | boot_env["bootargs"] = cls._get_bootargs( |
42 | 234 | is_live, is_lowmem, consoles, rootfs_uuid) | 242 | is_live, is_lowmem, consoles, rootfs_uuid) |
44 | 235 | boot_env["bootcmd"] = cls._get_bootcmd() | 243 | boot_env["bootcmd"] = cls.bootcmd |
45 | 236 | return boot_env | 244 | return boot_env |
46 | 237 | 245 | ||
47 | 238 | @classmethod | 246 | @classmethod |
48 | @@ -255,14 +263,6 @@ | |||
49 | 255 | raise NotImplementedError() | 263 | raise NotImplementedError() |
50 | 256 | 264 | ||
51 | 257 | 265 | ||
52 | 258 | class classproperty(object): | ||
53 | 259 | """A descriptor that provides @property behavior on class methods.""" | ||
54 | 260 | def __init__(self, getter): | ||
55 | 261 | self.getter = getter | ||
56 | 262 | def __get__(self, instance, cls): | ||
57 | 263 | return self.getter(cls) | ||
58 | 264 | |||
59 | 265 | |||
60 | 266 | class OmapConfig(BoardConfig): | 266 | class OmapConfig(BoardConfig): |
61 | 267 | uboot_in_boot_part = True | 267 | uboot_in_boot_part = True |
62 | 268 | 268 | ||
63 | @@ -588,10 +588,7 @@ | |||
64 | 588 | 588 | ||
65 | 589 | def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None, | 589 | def _dd(input_file, output_file, block_size=SECTOR_SIZE, count=None, seek=None, |
66 | 590 | skip=None): | 590 | skip=None): |
71 | 591 | """a generic dd function used to insert blobs into files or devices | 591 | """Wrapper around the dd command""" |
68 | 592 | |||
69 | 593 | uses the OS dd function | ||
70 | 594 | """ | ||
72 | 595 | cmd = [ | 592 | cmd = [ |
73 | 596 | "dd", "if=%s" % input_file, "of=%s" % output_file, | 593 | "dd", "if=%s" % input_file, "of=%s" % output_file, |
74 | 597 | "bs=%s" % block_size, "conv=notrunc"] | 594 | "bs=%s" % block_size, "conv=notrunc"] |
75 | @@ -675,11 +672,16 @@ | |||
76 | 675 | 672 | ||
77 | 676 | def make_flashable_env(boot_env, env_size): | 673 | def make_flashable_env(boot_env, env_size): |
78 | 677 | env_strings = ["%s=%s" % (k, v) for k, v in boot_env.items()] | 674 | env_strings = ["%s=%s" % (k, v) for k, v in boot_env.items()] |
79 | 675 | env_strings.sort() | ||
80 | 678 | env = struct.pack('B', 0).join(env_strings) | 676 | env = struct.pack('B', 0).join(env_strings) |
81 | 679 | 677 | ||
85 | 680 | # pad the rest of the env for the CRC calc | 678 | # we still need to zero-terminate the last string, and 4 bytes for crc |
86 | 681 | while len(env) < (env_size - 4): | 679 | assert len(env) + 1 + 4 <= env_size, ( |
87 | 682 | env += struct.pack('B', 0) | 680 | "environment doesn't fit in %s bytes" % env_size) |
88 | 681 | |||
89 | 682 | # pad the rest of the env for the CRC calc; the "s" format will write zero | ||
90 | 683 | # bytes to pad the (empty) string to repeat count | ||
91 | 684 | env += struct.pack('%ss' % (env_size - len(env) - 4), '') | ||
92 | 683 | 685 | ||
93 | 684 | crc = crc32(env) | 686 | crc = crc32(env) |
94 | 685 | env = struct.pack('<i', crc) + env | 687 | env = struct.pack('<i', crc) + env |
95 | @@ -693,8 +695,14 @@ | |||
96 | 693 | 695 | ||
97 | 694 | 696 | ||
98 | 695 | def install_mx5_boot_loader(imx_file, boot_device_or_file): | 697 | def install_mx5_boot_loader(imx_file, boot_device_or_file): |
101 | 696 | # XXX need to check that the length of imx_file is smaller than | 698 | # bootloader partition starts at +1s but we write the file at +2s, so we |
102 | 697 | # LOADER_MIN_SIZE_S | 699 | # need to check that the bootloader partition minus 1s is at least as large |
103 | 700 | # as the u-boot binary; note that the real bootloader partition might be | ||
104 | 701 | # larger than LOADER_MIN_SIZE_S, but if u-boot is larger it's a sign we | ||
105 | 702 | # need to bump LOADER_MIN_SIZE_S | ||
106 | 703 | max_size = (LOADER_MIN_SIZE_S - 1) * SECTOR_SIZE | ||
107 | 704 | assert os.path.getsize(imx_file) <= max_size, ( | ||
108 | 705 | "%s is larger than guaranteed bootloader partition size" % imx_file) | ||
109 | 698 | _dd(imx_file, boot_device_or_file, seek=2) | 706 | _dd(imx_file, boot_device_or_file, seek=2) |
110 | 699 | 707 | ||
111 | 700 | 708 | ||
112 | @@ -735,23 +743,32 @@ | |||
113 | 735 | 743 | ||
114 | 736 | 744 | ||
115 | 737 | def install_smdkv310_uImage(uImage_file, boot_device_or_file): | 745 | def install_smdkv310_uImage(uImage_file, boot_device_or_file): |
118 | 738 | # XXX need to check that the length of uImage_file is smaller than | 746 | # the layout keeps SAMSUNG_V310_UIMAGE_LEN sectors for uImage; make sure |
119 | 739 | # SAMSUNG_V310_UIMAGE_LEN | 747 | # uImage isn't actually larger or it would be truncated |
120 | 748 | max_size = SAMSUNG_V310_UIMAGE_LEN * SECTOR_SIZE | ||
121 | 749 | assert os.path.getsize(uImage_file) <= max_size, ( | ||
122 | 750 | "%s is larger than the allocated v310 uImage length" % uImage_file) | ||
123 | 740 | _dd(uImage_file, boot_device_or_file, count=SAMSUNG_V310_UIMAGE_LEN, | 751 | _dd(uImage_file, boot_device_or_file, count=SAMSUNG_V310_UIMAGE_LEN, |
124 | 741 | seek=SAMSUNG_V310_UIMAGE_START) | 752 | seek=SAMSUNG_V310_UIMAGE_START) |
125 | 742 | 753 | ||
126 | 743 | 754 | ||
127 | 744 | def install_smdkv310_initrd(initrd_file, boot_device_or_file): | 755 | def install_smdkv310_initrd(initrd_file, boot_device_or_file): |
131 | 745 | # XXX need to check that the length of initrd_file is smaller than | 756 | # the layout keeps SAMSUNG_V310_UINITRD_RESERVED_LEN sectors for uInitrd |
132 | 746 | # SAMSUNG_V310_UINITRD_LEN | 757 | # but only SAMSUNG_V310_UINITRD_COPY_LEN sectors are loaded into memory; |
133 | 747 | _dd(initrd_file, boot_device_or_file, | 758 | # make sure uInitrd isn't actually larger or it would be truncated in |
134 | 759 | # memory | ||
135 | 760 | max_size = SAMSUNG_V310_UINITRD_COPY_LEN * SECTOR_SIZE | ||
136 | 761 | assert os.path.getsize(initrd_file) <= max_size, ( | ||
137 | 762 | "%s is larger than the v310 uInitrd length as used by u-boot" | ||
138 | 763 | % initrd_file) | ||
139 | 764 | _dd(initrd_file, boot_device_or_file, | ||
140 | 748 | count=SAMSUNG_V310_UINITRD_COPY_LEN, | 765 | count=SAMSUNG_V310_UINITRD_COPY_LEN, |
141 | 749 | seek=SAMSUNG_V310_UINITRD_START) | 766 | seek=SAMSUNG_V310_UINITRD_START) |
142 | 750 | 767 | ||
143 | 751 | 768 | ||
144 | 752 | def install_smdkv310_boot_env(env_file, boot_device_or_file): | 769 | def install_smdkv310_boot_env(env_file, boot_device_or_file): |
147 | 753 | # XXX need to check that the length of env_file is smaller than | 770 | # the environment file is exactly SAMSUNG_V310_ENV_LEN as created by |
148 | 754 | # SAMSUNG_V310_ENV_LEN | 771 | # make_flashable_env(), so we don't need to check the size of env_file |
149 | 755 | _dd(env_file, boot_device_or_file, count=SAMSUNG_V310_ENV_LEN, | 772 | _dd(env_file, boot_device_or_file, count=SAMSUNG_V310_ENV_LEN, |
150 | 756 | seek=SAMSUNG_V310_ENV_START) | 773 | seek=SAMSUNG_V310_ENV_START) |
151 | 757 | 774 | ||
152 | @@ -773,3 +790,4 @@ | |||
153 | 773 | # SAMSUNG_V310_BL2_LEN | 790 | # SAMSUNG_V310_BL2_LEN |
154 | 774 | _dd(v310_file, boot_device_or_file, seek=SAMSUNG_V310_BL2_START, | 791 | _dd(v310_file, boot_device_or_file, seek=SAMSUNG_V310_BL2_START, |
155 | 775 | skip=(SAMSUNG_V310_BL2_START - SAMSUNG_V310_BL1_START)) | 792 | skip=(SAMSUNG_V310_BL2_START - SAMSUNG_V310_BL1_START)) |
156 | 793 | |||
157 | 776 | 794 | ||
158 | === modified file 'linaro_media_create/tests/test_media_create.py' | |||
159 | --- linaro_media_create/tests/test_media_create.py 2011-03-02 14:51:14 +0000 | |||
160 | +++ linaro_media_create/tests/test_media_create.py 2011-03-05 00:53:54 +0000 | |||
161 | @@ -43,9 +43,12 @@ | |||
162 | 43 | ) | 43 | ) |
163 | 44 | import linaro_media_create | 44 | import linaro_media_create |
164 | 45 | from linaro_media_create.boards import ( | 45 | from linaro_media_create.boards import ( |
165 | 46 | LOADER_MIN_SIZE_S, | ||
166 | 47 | SECTOR_SIZE, | ||
167 | 46 | align_up, | 48 | align_up, |
168 | 47 | align_partition, | 49 | align_partition, |
169 | 48 | board_configs, | 50 | board_configs, |
170 | 51 | make_flashable_env, | ||
171 | 49 | install_mx5_boot_loader, | 52 | install_mx5_boot_loader, |
172 | 50 | install_omap_boot_loader, | 53 | install_omap_boot_loader, |
173 | 51 | make_boot_script, | 54 | make_boot_script, |
174 | @@ -621,14 +624,35 @@ | |||
175 | 621 | '-d', 'parts_dir/initrd.img-*-sub_arch', 'boot_disk/uInitrd'] | 624 | '-d', 'parts_dir/initrd.img-*-sub_arch', 'boot_disk/uInitrd'] |
176 | 622 | self.assertEqual([expected], fixture.mock.calls) | 625 | self.assertEqual([expected], fixture.mock.calls) |
177 | 623 | 626 | ||
178 | 627 | def test_make_flashable_env_too_small_env(self): | ||
179 | 628 | env = {'verylong': 'evenlonger'} | ||
180 | 629 | self.assertRaises(AssertionError, make_flashable_env, env, 8) | ||
181 | 630 | |||
182 | 631 | def test_make_flashable_env(self): | ||
183 | 632 | env_file = self.createTempFileAsFixture() | ||
184 | 633 | self.useFixture(MockSomethingFixture( | ||
185 | 634 | tempfile, "mkstemp", lambda: (None, env_file))) | ||
186 | 635 | env = {'a': 'b', 'x': 'y'} | ||
187 | 636 | make_flashable_env(env, 12) | ||
188 | 637 | with open(env_file, "r") as fd: | ||
189 | 638 | self.assertEqual("\x80\x29\x2E\x89a=b\x00x=y\x00", fd.read()) | ||
190 | 639 | |||
191 | 624 | def test_install_mx5_boot_loader(self): | 640 | def test_install_mx5_boot_loader(self): |
192 | 625 | fixture = self._mock_Popen() | 641 | fixture = self._mock_Popen() |
194 | 626 | install_mx5_boot_loader("imx_file", "boot_device_or_file") | 642 | imx_file = self.createTempFileAsFixture() |
195 | 643 | install_mx5_boot_loader(imx_file, "boot_device_or_file") | ||
196 | 627 | expected = [ | 644 | expected = [ |
199 | 628 | 'sudo', 'dd', 'if=imx_file', 'of=boot_device_or_file', 'bs=512', | 645 | 'sudo', 'dd', 'if=%s' % imx_file, 'of=boot_device_or_file', |
200 | 629 | 'conv=notrunc', 'seek=2'] | 646 | 'bs=512', 'conv=notrunc', 'seek=2'] |
201 | 630 | self.assertEqual([expected], fixture.mock.calls) | 647 | self.assertEqual([expected], fixture.mock.calls) |
202 | 631 | 648 | ||
203 | 649 | def test_install_mx5_boot_loader_too_large(self): | ||
204 | 650 | self.useFixture(MockSomethingFixture( | ||
205 | 651 | os.path, "getsize", | ||
206 | 652 | lambda s: (LOADER_MIN_SIZE_S - 1) * SECTOR_SIZE + 1)) | ||
207 | 653 | self.assertRaises(AssertionError, | ||
208 | 654 | install_mx5_boot_loader, "imx_file", "boot_device_or_file") | ||
209 | 655 | |||
210 | 632 | def test_install_omap_boot_loader(self): | 656 | def test_install_omap_boot_loader(self): |
211 | 633 | fixture = self._mock_Popen() | 657 | fixture = self._mock_Popen() |
212 | 634 | self.useFixture(MockSomethingFixture( | 658 | self.useFixture(MockSomethingFixture( |
213 | @@ -763,9 +787,9 @@ | |||
214 | 763 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | 787 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) |
215 | 764 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) | 788 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) |
216 | 765 | 789 | ||
218 | 766 | tempfile = self.createTempFileAsFixture() | 790 | tmpfile = self.createTempFileAsFixture() |
219 | 767 | create_partitions( | 791 | create_partitions( |
221 | 768 | board_configs['beagle'], Media(tempfile), 255, 63, '') | 792 | board_configs['beagle'], Media(tmpfile), 255, 63, '') |
222 | 769 | 793 | ||
223 | 770 | # Unlike the test for partitioning of a regular block device, in this | 794 | # Unlike the test for partitioning of a regular block device, in this |
224 | 771 | # case parted was not called as there's no existing partition table | 795 | # case parted was not called as there's no existing partition table |
225 | @@ -773,26 +797,26 @@ | |||
226 | 773 | self.assertEqual([['sync']], popen_fixture.mock.calls) | 797 | self.assertEqual([['sync']], popen_fixture.mock.calls) |
227 | 774 | 798 | ||
228 | 775 | self.assertEqual( | 799 | self.assertEqual( |
230 | 776 | [('63,106432,0x0C,*\n106496,,,-', 255, 63, '', tempfile)], | 800 | [('63,106432,0x0C,*\n106496,,,-', 255, 63, '', tmpfile)], |
231 | 777 | sfdisk_fixture.mock.calls) | 801 | sfdisk_fixture.mock.calls) |
232 | 778 | 802 | ||
233 | 779 | def test_run_sfdisk_commands(self): | 803 | def test_run_sfdisk_commands(self): |
235 | 780 | tempfile = self.createTempFileAsFixture() | 804 | tmpfile = self.createTempFileAsFixture() |
236 | 781 | proc = cmd_runner.run( | 805 | proc = cmd_runner.run( |
238 | 782 | ['qemu-img', 'create', '-f', 'raw', tempfile, '10M'], | 806 | ['qemu-img', 'create', '-f', 'raw', tmpfile, '10M'], |
239 | 783 | stdout=subprocess.PIPE) | 807 | stdout=subprocess.PIPE) |
240 | 784 | proc.communicate() | 808 | proc.communicate() |
241 | 785 | stdout, stderr = run_sfdisk_commands( | 809 | stdout, stderr = run_sfdisk_commands( |
243 | 786 | '2,16063,0xDA', 255, 63, '', tempfile, as_root=False, | 810 | '2,16063,0xDA', 255, 63, '', tmpfile, as_root=False, |
244 | 787 | stderr=subprocess.PIPE) | 811 | stderr=subprocess.PIPE) |
245 | 788 | self.assertIn('Successfully wrote the new partition table', stdout) | 812 | self.assertIn('Successfully wrote the new partition table', stdout) |
246 | 789 | 813 | ||
247 | 790 | def test_run_sfdisk_commands_raises_on_non_zero_returncode(self): | 814 | def test_run_sfdisk_commands_raises_on_non_zero_returncode(self): |
249 | 791 | tempfile = self.createTempFileAsFixture() | 815 | tmpfile = self.createTempFileAsFixture() |
250 | 792 | self.assertRaises( | 816 | self.assertRaises( |
251 | 793 | cmd_runner.SubcommandNonZeroReturnValue, | 817 | cmd_runner.SubcommandNonZeroReturnValue, |
252 | 794 | run_sfdisk_commands, | 818 | run_sfdisk_commands, |
254 | 795 | ',1,0xDA', 255, 63, '', tempfile, as_root=False, | 819 | ',1,0xDA', 255, 63, '', tmpfile, as_root=False, |
255 | 796 | stderr=subprocess.PIPE) | 820 | stderr=subprocess.PIPE) |
256 | 797 | 821 | ||
257 | 798 | 822 | ||
258 | @@ -808,7 +832,7 @@ | |||
259 | 808 | super(TestPartitionSetup, self).tearDown() | 832 | super(TestPartitionSetup, self).tearDown() |
260 | 809 | time.sleep = self.orig_sleep | 833 | time.sleep = self.orig_sleep |
261 | 810 | 834 | ||
263 | 811 | def _create_tempfile(self): | 835 | def _create_tmpfile(self): |
264 | 812 | # boot part at +8 MiB, root part at +16 MiB | 836 | # boot part at +8 MiB, root part at +16 MiB |
265 | 813 | return self._create_qemu_img_with_partitions( | 837 | return self._create_qemu_img_with_partitions( |
266 | 814 | '16384,15746,0x0C,*\n32768,,,-') | 838 | '16384,15746,0x0C,*\n32768,,,-') |
267 | @@ -823,19 +847,19 @@ | |||
268 | 823 | self.assertEqual(12 * 1024**3, convert_size_to_bytes('12G')) | 847 | self.assertEqual(12 * 1024**3, convert_size_to_bytes('12G')) |
269 | 824 | 848 | ||
270 | 825 | def test_calculate_partition_size_and_offset(self): | 849 | def test_calculate_partition_size_and_offset(self): |
272 | 826 | tempfile = self._create_tempfile() | 850 | tmpfile = self._create_tmpfile() |
273 | 827 | vfat_size, vfat_offset, linux_size, linux_offset = ( | 851 | vfat_size, vfat_offset, linux_size, linux_offset = ( |
275 | 828 | calculate_partition_size_and_offset(tempfile)) | 852 | calculate_partition_size_and_offset(tmpfile)) |
276 | 829 | self.assertEqual( | 853 | self.assertEqual( |
277 | 830 | [8061952L, 8388608L, 14680064L, 16777216L], | 854 | [8061952L, 8388608L, 14680064L, 16777216L], |
278 | 831 | [vfat_size, vfat_offset, linux_size, linux_offset]) | 855 | [vfat_size, vfat_offset, linux_size, linux_offset]) |
279 | 832 | 856 | ||
280 | 833 | def test_partition_numbering(self): | 857 | def test_partition_numbering(self): |
281 | 834 | # another Linux partition at +24 MiB after the boot/root parts | 858 | # another Linux partition at +24 MiB after the boot/root parts |
283 | 835 | tempfile = self._create_qemu_img_with_partitions( | 859 | tmpfile = self._create_qemu_img_with_partitions( |
284 | 836 | '16384,15746,0x0C,*\n32768,15427,,-\n49152,,,-') | 860 | '16384,15746,0x0C,*\n32768,15427,,-\n49152,,,-') |
285 | 837 | vfat_size, vfat_offset, linux_size, linux_offset = ( | 861 | vfat_size, vfat_offset, linux_size, linux_offset = ( |
287 | 838 | calculate_partition_size_and_offset(tempfile)) | 862 | calculate_partition_size_and_offset(tmpfile)) |
288 | 839 | # check that the linux partition offset starts at +16 MiB so that it's | 863 | # check that the linux partition offset starts at +16 MiB so that it's |
289 | 840 | # the partition immediately following the vfat one | 864 | # the partition immediately following the vfat one |
290 | 841 | self.assertEqual(linux_offset, 32768 * 512) | 865 | self.assertEqual(linux_offset, 32768 * 512) |
291 | @@ -843,39 +867,39 @@ | |||
292 | 843 | def test_get_boot_and_root_partitions_for_media_beagle(self): | 867 | def test_get_boot_and_root_partitions_for_media_beagle(self): |
293 | 844 | self.useFixture(MockSomethingFixture( | 868 | self.useFixture(MockSomethingFixture( |
294 | 845 | partitions, '_get_device_file_for_partition_number', | 869 | partitions, '_get_device_file_for_partition_number', |
298 | 846 | lambda dev, partition: '%s%d' % (tempfile, partition))) | 870 | lambda dev, partition: '%s%d' % (tmpfile, partition))) |
299 | 847 | tempfile = self.createTempFileAsFixture() | 871 | tmpfile = self.createTempFileAsFixture() |
300 | 848 | media = Media(tempfile) | 872 | media = Media(tmpfile) |
301 | 849 | media.is_block_device = True | 873 | media.is_block_device = True |
302 | 850 | self.assertEqual( | 874 | self.assertEqual( |
304 | 851 | ("%s%d" % (tempfile, 1), "%s%d" % (tempfile, 2)), | 875 | ("%s%d" % (tmpfile, 1), "%s%d" % (tmpfile, 2)), |
305 | 852 | get_boot_and_root_partitions_for_media( | 876 | get_boot_and_root_partitions_for_media( |
306 | 853 | media, board_configs['beagle'])) | 877 | media, board_configs['beagle'])) |
307 | 854 | 878 | ||
308 | 855 | def test_get_boot_and_root_partitions_for_media_mx5(self): | 879 | def test_get_boot_and_root_partitions_for_media_mx5(self): |
309 | 856 | self.useFixture(MockSomethingFixture( | 880 | self.useFixture(MockSomethingFixture( |
310 | 857 | partitions, '_get_device_file_for_partition_number', | 881 | partitions, '_get_device_file_for_partition_number', |
314 | 858 | lambda dev, partition: '%s%d' % (tempfile, partition))) | 882 | lambda dev, partition: '%s%d' % (tmpfile, partition))) |
315 | 859 | tempfile = self.createTempFileAsFixture() | 883 | tmpfile = self.createTempFileAsFixture() |
316 | 860 | media = Media(tempfile) | 884 | media = Media(tmpfile) |
317 | 861 | media.is_block_device = True | 885 | media.is_block_device = True |
318 | 862 | self.assertEqual( | 886 | self.assertEqual( |
320 | 863 | ("%s%d" % (tempfile, 2), "%s%d" % (tempfile, 3)), | 887 | ("%s%d" % (tmpfile, 2), "%s%d" % (tmpfile, 3)), |
321 | 864 | get_boot_and_root_partitions_for_media(media, boards.Mx5Config)) | 888 | get_boot_and_root_partitions_for_media(media, boards.Mx5Config)) |
322 | 865 | 889 | ||
323 | 866 | def _create_qemu_img_with_partitions(self, sfdisk_commands): | 890 | def _create_qemu_img_with_partitions(self, sfdisk_commands): |
325 | 867 | tempfile = self.createTempFileAsFixture() | 891 | tmpfile = self.createTempFileAsFixture() |
326 | 868 | proc = cmd_runner.run( | 892 | proc = cmd_runner.run( |
328 | 869 | ['qemu-img', 'create', '-f', 'raw', tempfile, '30M'], | 893 | ['qemu-img', 'create', '-f', 'raw', tmpfile, '30M'], |
329 | 870 | stdout=subprocess.PIPE) | 894 | stdout=subprocess.PIPE) |
330 | 871 | proc.communicate() | 895 | proc.communicate() |
331 | 872 | stdout, stderr = run_sfdisk_commands( | 896 | stdout, stderr = run_sfdisk_commands( |
333 | 873 | sfdisk_commands, 255, 63, '', tempfile, as_root=False, | 897 | sfdisk_commands, 255, 63, '', tmpfile, as_root=False, |
334 | 874 | # Throw away stderr as sfdisk complains a lot when operating on a | 898 | # Throw away stderr as sfdisk complains a lot when operating on a |
335 | 875 | # qemu image. | 899 | # qemu image. |
336 | 876 | stderr=subprocess.PIPE) | 900 | stderr=subprocess.PIPE) |
337 | 877 | self.assertIn('Successfully wrote the new partition table', stdout) | 901 | self.assertIn('Successfully wrote the new partition table', stdout) |
339 | 878 | return tempfile | 902 | return tmpfile |
340 | 879 | 903 | ||
341 | 880 | def test_ensure_partition_is_not_mounted_for_mounted_partition(self): | 904 | def test_ensure_partition_is_not_mounted_for_mounted_partition(self): |
342 | 881 | self.useFixture(MockSomethingFixture( | 905 | self.useFixture(MockSomethingFixture( |
343 | @@ -893,18 +917,18 @@ | |||
344 | 893 | self.assertEqual(None, popen_fixture.mock.calls) | 917 | self.assertEqual(None, popen_fixture.mock.calls) |
345 | 894 | 918 | ||
346 | 895 | def test_get_boot_and_root_loopback_devices(self): | 919 | def test_get_boot_and_root_loopback_devices(self): |
348 | 896 | tempfile = self._create_tempfile() | 920 | tmpfile = self._create_tmpfile() |
349 | 897 | atexit_fixture = self.useFixture(MockSomethingFixture( | 921 | atexit_fixture = self.useFixture(MockSomethingFixture( |
350 | 898 | atexit, 'register', AtExitRegister())) | 922 | atexit, 'register', AtExitRegister())) |
351 | 899 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | 923 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) |
352 | 900 | # We can't test the return value of get_boot_and_root_loopback_devices | 924 | # We can't test the return value of get_boot_and_root_loopback_devices |
353 | 901 | # because it'd require running losetup as root, so we just make sure | 925 | # because it'd require running losetup as root, so we just make sure |
354 | 902 | # it calls losetup correctly. | 926 | # it calls losetup correctly. |
356 | 903 | get_boot_and_root_loopback_devices(tempfile) | 927 | get_boot_and_root_loopback_devices(tmpfile) |
357 | 904 | self.assertEqual( | 928 | self.assertEqual( |
359 | 905 | [['sudo', 'losetup', '-f', '--show', tempfile, '--offset', | 929 | [['sudo', 'losetup', '-f', '--show', tmpfile, '--offset', |
360 | 906 | '8388608', '--sizelimit', '8061952'], | 930 | '8388608', '--sizelimit', '8061952'], |
362 | 907 | ['sudo', 'losetup', '-f', '--show', tempfile, '--offset', | 931 | ['sudo', 'losetup', '-f', '--show', tmpfile, '--offset', |
363 | 908 | '16777216', '--sizelimit', '14680064']], | 932 | '16777216', '--sizelimit', '14680064']], |
364 | 909 | popen_fixture.mock.calls) | 933 | popen_fixture.mock.calls) |
365 | 910 | 934 | ||
366 | @@ -925,7 +949,7 @@ | |||
367 | 925 | # but here we mock Popen() and thanks to that the image is not setup | 949 | # but here we mock Popen() and thanks to that the image is not setup |
368 | 926 | # (via qemu-img) inside setup_partitions. That's why we pass an | 950 | # (via qemu-img) inside setup_partitions. That's why we pass an |
369 | 927 | # already setup image file. | 951 | # already setup image file. |
371 | 928 | tempfile = self._create_tempfile() | 952 | tmpfile = self._create_tmpfile() |
372 | 929 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | 953 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) |
373 | 930 | self.useFixture(MockSomethingFixture( | 954 | self.useFixture(MockSomethingFixture( |
374 | 931 | sys, 'stdout', open('/dev/null', 'w'))) | 955 | sys, 'stdout', open('/dev/null', 'w'))) |
375 | @@ -942,14 +966,14 @@ | |||
376 | 942 | partitions, 'get_boot_and_root_loopback_devices', | 966 | partitions, 'get_boot_and_root_loopback_devices', |
377 | 943 | lambda image: ('/dev/loop99', '/dev/loop98'))) | 967 | lambda image: ('/dev/loop99', '/dev/loop98'))) |
378 | 944 | bootfs_dev, rootfs_dev = setup_partitions( | 968 | bootfs_dev, rootfs_dev = setup_partitions( |
380 | 945 | board_configs['beagle'], Media(tempfile), '2G', 'boot', | 969 | board_configs['beagle'], Media(tmpfile), '2G', 'boot', |
381 | 946 | 'root', 'ext3', True, True, True) | 970 | 'root', 'ext3', True, True, True) |
382 | 947 | self.assertEqual( | 971 | self.assertEqual( |
383 | 948 | # This is the call that would create a 2 GiB image file. | 972 | # This is the call that would create a 2 GiB image file. |
385 | 949 | [['qemu-img', 'create', '-f', 'raw', tempfile, '2147483648'], | 973 | [['qemu-img', 'create', '-f', 'raw', tmpfile, '2147483648'], |
386 | 950 | # This call would partition the image file. | 974 | # This call would partition the image file. |
387 | 951 | ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S', | 975 | ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S', |
389 | 952 | '63', '-C', '261', tempfile], | 976 | '63', '-C', '261', tmpfile], |
390 | 953 | # Make sure changes are written to disk. | 977 | # Make sure changes are written to disk. |
391 | 954 | ['sync'], | 978 | ['sync'], |
392 | 955 | ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'], | 979 | ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'], |
393 | @@ -962,21 +986,21 @@ | |||
394 | 962 | # Pretend the partitions are mounted. | 986 | # Pretend the partitions are mounted. |
395 | 963 | self.useFixture(MockSomethingFixture( | 987 | self.useFixture(MockSomethingFixture( |
396 | 964 | partitions, 'is_partition_mounted', lambda part: True)) | 988 | partitions, 'is_partition_mounted', lambda part: True)) |
398 | 965 | tempfile = self._create_tempfile() | 989 | tmpfile = self._create_tmpfile() |
399 | 966 | self.useFixture(MockSomethingFixture( | 990 | self.useFixture(MockSomethingFixture( |
400 | 967 | partitions, '_get_device_file_for_partition_number', | 991 | partitions, '_get_device_file_for_partition_number', |
404 | 968 | lambda dev, partition: '%s%d' % (tempfile, partition))) | 992 | lambda dev, partition: '%s%d' % (tmpfile, partition))) |
405 | 969 | media = Media(tempfile) | 993 | media = Media(tmpfile) |
406 | 970 | # Pretend our tempfile is a block device. | 994 | # Pretend our tmpfile is a block device. |
407 | 971 | media.is_block_device = True | 995 | media.is_block_device = True |
408 | 972 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | 996 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) |
409 | 973 | bootfs_dev, rootfs_dev = setup_partitions( | 997 | bootfs_dev, rootfs_dev = setup_partitions( |
410 | 974 | board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3', | 998 | board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3', |
411 | 975 | True, True, True) | 999 | True, True, True) |
412 | 976 | self.assertEqual( | 1000 | self.assertEqual( |
414 | 977 | [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'], | 1001 | [['sudo', 'parted', '-s', tmpfile, 'mklabel', 'msdos'], |
415 | 978 | ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S', | 1002 | ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S', |
417 | 979 | '63', tempfile], | 1003 | '63', tmpfile], |
418 | 980 | ['sync'], | 1004 | ['sync'], |
419 | 981 | # Since the partitions are mounted, setup_partitions will umount | 1005 | # Since the partitions are mounted, setup_partitions will umount |
420 | 982 | # them before running mkfs. | 1006 | # them before running mkfs. |