Merge lp:~salgado/linaro-image-tools/mx51evk-code-cleanup into lp:linaro-image-tools/11.11
- mx51evk-code-cleanup
- Merge into trunk
Proposed by
Guilherme Salgado
Status: | Merged |
---|---|
Merged at revision: | 260 |
Proposed branch: | lp:~salgado/linaro-image-tools/mx51evk-code-cleanup |
Merge into: | lp:linaro-image-tools/11.11 |
Diff against target: |
211 lines (+56/-34) 4 files modified
linaro-media-create (+2/-3) linaro_media_create/boards.py (+21/-0) linaro_media_create/partitions.py (+10/-24) linaro_media_create/tests/test_media_create.py (+23/-7) |
To merge this branch: | bzr merge lp:~salgado/linaro-image-tools/mx51evk-code-cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Loïc Minier (community) | Approve | ||
James Westby (community) | Approve | ||
Review via email:
|
Commit message
Description of the change
Get rid of the mx51evk-specific code in create_partitions
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
James Westby (james-w) : | # |
review:
Approve
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Loïc Minier (lool) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'linaro-media-create' | |||
2 | --- linaro-media-create 2011-01-25 12:51:19 +0000 | |||
3 | +++ linaro-media-create 2011-01-25 20:07:57 +0000 | |||
4 | @@ -104,9 +104,8 @@ | |||
5 | 104 | install_hwpacks(ROOTFS_DIR, TMP_DIR, args.hwpack_force_yes, *hwpacks) | 104 | install_hwpacks(ROOTFS_DIR, TMP_DIR, args.hwpack_force_yes, *hwpacks) |
6 | 105 | 105 | ||
7 | 106 | boot_partition, root_partition = setup_partitions( | 106 | boot_partition, root_partition = setup_partitions( |
11 | 107 | args.board, media, board_config.fat_size, args.image_size, | 107 | board_config, media, args.image_size, args.boot_label, args.rfs_label, |
12 | 108 | args.boot_label, args.rfs_label, args.rootfs, ROOTFS_UUID, | 108 | args.rootfs, ROOTFS_UUID, args.should_create_partitions, |
10 | 109 | args.should_create_partitions, | ||
13 | 110 | args.should_format_bootfs, args.should_format_rootfs) | 109 | args.should_format_bootfs, args.should_format_rootfs) |
14 | 111 | 110 | ||
15 | 112 | if args.should_format_bootfs: | 111 | if args.should_format_bootfs: |
16 | 113 | 112 | ||
17 | === modified file 'linaro_media_create/boards.py' | |||
18 | --- linaro_media_create/boards.py 2011-01-25 12:02:38 +0000 | |||
19 | +++ linaro_media_create/boards.py 2011-01-25 20:07:57 +0000 | |||
20 | @@ -35,6 +35,19 @@ | |||
21 | 35 | boot_script = None | 35 | boot_script = None |
22 | 36 | 36 | ||
23 | 37 | @classmethod | 37 | @classmethod |
24 | 38 | def get_sfdisk_cmd(cls): | ||
25 | 39 | """Return the sfdisk command to partition the media.""" | ||
26 | 40 | if cls.fat_size == 32: | ||
27 | 41 | partition_type = '0x0C' | ||
28 | 42 | else: | ||
29 | 43 | partition_type = '0x0E' | ||
30 | 44 | |||
31 | 45 | # This will create a partition of the given type, containing 9 | ||
32 | 46 | # cylinders (74027520 bytes, ~70 MiB), followed by a Linux-type | ||
33 | 47 | # partition containing the rest of the free space. | ||
34 | 48 | return ',9,%s,*\n,,,-' % partition_type | ||
35 | 49 | |||
36 | 50 | @classmethod | ||
37 | 38 | def _get_boot_cmd(cls, is_live, is_lowmem, consoles): | 51 | def _get_boot_cmd(cls, is_live, is_lowmem, consoles): |
38 | 39 | """Get the boot command for this board. | 52 | """Get the boot command for this board. |
39 | 40 | 53 | ||
40 | @@ -195,6 +208,14 @@ | |||
41 | 195 | mmc_option = '0:2' | 208 | mmc_option = '0:2' |
42 | 196 | 209 | ||
43 | 197 | @classmethod | 210 | @classmethod |
44 | 211 | def get_sfdisk_cmd(cls): | ||
45 | 212 | # Create a one cylinder partition for fixed-offset bootloader data at | ||
46 | 213 | # the beginning of the image (size is one cylinder, so 8224768 bytes | ||
47 | 214 | # with the first sector for MBR). | ||
48 | 215 | sfdisk_cmd = super(Mx51evkConfig, cls).get_sfdisk_cmd() | ||
49 | 216 | return ',1,0xDA\n%s' % sfdisk_cmd | ||
50 | 217 | |||
51 | 218 | @classmethod | ||
52 | 198 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, | 219 | def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, |
53 | 199 | boot_dir, boot_script, boot_device_or_file): | 220 | boot_dir, boot_script, boot_device_or_file): |
54 | 200 | uboot_file = os.path.join( | 221 | uboot_file = os.path.join( |
55 | 201 | 222 | ||
56 | === modified file 'linaro_media_create/partitions.py' | |||
57 | --- linaro_media_create/partitions.py 2011-01-24 19:39:45 +0000 | |||
58 | +++ linaro_media_create/partitions.py 2011-01-25 20:07:57 +0000 | |||
59 | @@ -24,15 +24,14 @@ | |||
60 | 24 | # the appropriate function for the given type of device? I think it's still | 24 | # the appropriate function for the given type of device? I think it's still |
61 | 25 | # small enough that there's not much benefit in doing that, but if it grows we | 25 | # small enough that there's not much benefit in doing that, but if it grows we |
62 | 26 | # might want to do it. | 26 | # might want to do it. |
65 | 27 | def setup_partitions(board, media, fat_size, image_size, | 27 | def setup_partitions(board_config, media, image_size, bootfs_label, |
66 | 28 | bootfs_label, rootfs_label, rootfs_type, rootfs_uuid, | 28 | rootfs_label, rootfs_type, rootfs_uuid, |
67 | 29 | should_create_partitions, should_format_bootfs, | 29 | should_create_partitions, should_format_bootfs, |
68 | 30 | should_format_rootfs): | 30 | should_format_rootfs): |
69 | 31 | """Make sure the given device is partitioned to boot the given board. | 31 | """Make sure the given device is partitioned to boot the given board. |
70 | 32 | 32 | ||
72 | 33 | :param board: The board's name, as a string. | 33 | :param board_config: A BoardConfig class. |
73 | 34 | :param media: The Media we should partition. | 34 | :param media: The Media we should partition. |
74 | 35 | :param fat_size: The FAT size (16 or 32) for the boot partition. | ||
75 | 36 | :param image_size: The size of the image file, in case we're setting up a | 35 | :param image_size: The size of the image file, in case we're setting up a |
76 | 37 | QEMU image. | 36 | QEMU image. |
77 | 38 | :param should_create_partitions: Whether or not we should erase existing | 37 | :param should_create_partitions: Whether or not we should erase existing |
78 | @@ -49,7 +48,8 @@ | |||
79 | 49 | proc.wait() | 48 | proc.wait() |
80 | 50 | 49 | ||
81 | 51 | if should_create_partitions: | 50 | if should_create_partitions: |
83 | 52 | create_partitions(board, media, fat_size, HEADS, SECTORS, cylinders) | 51 | create_partitions( |
84 | 52 | board_config, media, HEADS, SECTORS, cylinders) | ||
85 | 53 | 53 | ||
86 | 54 | if media.is_block_device: | 54 | if media.is_block_device: |
87 | 55 | bootfs, rootfs = get_boot_and_root_partitions_for_media(media) | 55 | bootfs, rootfs = get_boot_and_root_partitions_for_media(media) |
88 | @@ -63,7 +63,8 @@ | |||
89 | 63 | # filesystem. | 63 | # filesystem. |
90 | 64 | ensure_partition_is_not_mounted(bootfs) | 64 | ensure_partition_is_not_mounted(bootfs) |
91 | 65 | proc = cmd_runner.run( | 65 | proc = cmd_runner.run( |
93 | 66 | ['mkfs.vfat', '-F', str(fat_size), bootfs, '-n', bootfs_label], | 66 | ['mkfs.vfat', '-F', str(board_config.fat_size), bootfs, '-n', |
94 | 67 | bootfs_label], | ||
95 | 67 | as_root=True) | 68 | as_root=True) |
96 | 68 | proc.wait() | 69 | proc.wait() |
97 | 69 | 70 | ||
98 | @@ -272,12 +273,11 @@ | |||
99 | 272 | return proc.communicate("%s\n" % commands) | 273 | return proc.communicate("%s\n" % commands) |
100 | 273 | 274 | ||
101 | 274 | 275 | ||
103 | 275 | def create_partitions(board, media, fat_size, heads, sectors, cylinders=None): | 276 | def create_partitions(board_config, media, heads, sectors, cylinders=None): |
104 | 276 | """Partition the given media according to the board requirements. | 277 | """Partition the given media according to the board requirements. |
105 | 277 | 278 | ||
107 | 278 | :param board: A string with the board type (e.g. beagle, panda, etc) | 279 | :param board_config: A BoardConfig class. |
108 | 279 | :param media: A setup_partitions.Media object to partition. | 280 | :param media: A setup_partitions.Media object to partition. |
109 | 280 | :param fat_size: The type of FATs used in the boot partition (16 or 32). | ||
110 | 281 | :param heads: Number of heads to use in the disk geometry of | 281 | :param heads: Number of heads to use in the disk geometry of |
111 | 282 | partitions. | 282 | partitions. |
112 | 283 | :param sectors: Number of sectors to use in the disk geometry of | 283 | :param sectors: Number of sectors to use in the disk geometry of |
113 | @@ -291,21 +291,7 @@ | |||
114 | 291 | ['parted', '-s', media.path, 'mklabel', 'msdos'], as_root=True) | 291 | ['parted', '-s', media.path, 'mklabel', 'msdos'], as_root=True) |
115 | 292 | proc.wait() | 292 | proc.wait() |
116 | 293 | 293 | ||
132 | 294 | if fat_size == 32: | 294 | sfdisk_cmd = board_config.get_sfdisk_cmd() |
118 | 295 | partition_type = '0x0C' | ||
119 | 296 | else: | ||
120 | 297 | partition_type = '0x0E' | ||
121 | 298 | |||
122 | 299 | sfdisk_cmd = ',9,%s,*\n,,,-' % partition_type | ||
123 | 300 | if board == 'mx51evk': | ||
124 | 301 | # Create a one cylinder partition for fixed-offset bootloader data at | ||
125 | 302 | # the beginning of the image (size is one cylinder, so 8224768 bytes | ||
126 | 303 | # with the first sector for MBR). | ||
127 | 304 | sfdisk_cmd = ',1,0xDA\n%s' % sfdisk_cmd | ||
128 | 305 | |||
129 | 306 | # Create a VFAT or FAT16 partition of 9 cylinders (74027520 bytes, ~70 | ||
130 | 307 | # MiB), followed by a Linux-type partition containing the rest of the free | ||
131 | 308 | # space. | ||
133 | 309 | run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path) | 295 | run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path) |
134 | 310 | 296 | ||
135 | 311 | # Sync and sleep to wait for the partition to settle. | 297 | # Sync and sleep to wait for the partition to settle. |
136 | 312 | 298 | ||
137 | === modified file 'linaro_media_create/tests/test_media_create.py' | |||
138 | --- linaro_media_create/tests/test_media_create.py 2011-01-25 13:44:16 +0000 | |||
139 | +++ linaro_media_create/tests/test_media_create.py 2011-01-25 20:07:57 +0000 | |||
140 | @@ -218,6 +218,19 @@ | |||
141 | 218 | 'make_boot_script', 'make_boot_ini'] | 218 | 'make_boot_script', 'make_boot_ini'] |
142 | 219 | self.assertEqual(expected, self.funcs_calls) | 219 | self.assertEqual(expected, self.funcs_calls) |
143 | 220 | 220 | ||
144 | 221 | |||
145 | 222 | class TestGetSfdiskCmd(TestCase): | ||
146 | 223 | |||
147 | 224 | def test_default(self): | ||
148 | 225 | self.assertEquals( | ||
149 | 226 | ',9,0x0C,*\n,,,-', boards.BoardConfig.get_sfdisk_cmd()) | ||
150 | 227 | |||
151 | 228 | def test_mx51evk(self): | ||
152 | 229 | self.assertEquals( | ||
153 | 230 | ',1,0xDA\n,9,0x0C,*\n,,,-', | ||
154 | 231 | board_configs['mx51evk'].get_sfdisk_cmd()) | ||
155 | 232 | |||
156 | 233 | |||
157 | 221 | class TestGetBootCmd(TestCase): | 234 | class TestGetBootCmd(TestCase): |
158 | 222 | 235 | ||
159 | 223 | def test_vexpress(self): | 236 | def test_vexpress(self): |
160 | @@ -447,7 +460,8 @@ | |||
161 | 447 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | 460 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) |
162 | 448 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) | 461 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) |
163 | 449 | 462 | ||
165 | 450 | create_partitions('mx51evk', self.media, 32, 255, 63, '') | 463 | create_partitions( |
166 | 464 | board_configs['mx51evk'], self.media, 255, 63, '') | ||
167 | 451 | 465 | ||
168 | 452 | self.assertEqual( | 466 | self.assertEqual( |
169 | 453 | [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], | 467 | [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], |
170 | @@ -464,7 +478,8 @@ | |||
171 | 464 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | 478 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) |
172 | 465 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) | 479 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) |
173 | 466 | 480 | ||
175 | 467 | create_partitions('beagle', self.media, 32, 255, 63, '') | 481 | create_partitions( |
176 | 482 | board_configs['beagle'], self.media, 255, 63, '') | ||
177 | 468 | 483 | ||
178 | 469 | self.assertEqual( | 484 | self.assertEqual( |
179 | 470 | [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], | 485 | [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], |
180 | @@ -479,7 +494,8 @@ | |||
181 | 479 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) | 494 | sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) |
182 | 480 | 495 | ||
183 | 481 | tempfile = self.createTempFileAsFixture() | 496 | tempfile = self.createTempFileAsFixture() |
185 | 482 | create_partitions('beagle', Media(tempfile), 32, 255, 63, '') | 497 | create_partitions( |
186 | 498 | board_configs['beagle'], Media(tempfile), 255, 63, '') | ||
187 | 483 | 499 | ||
188 | 484 | # Unlike the test for partitioning of a regular block device, in this | 500 | # Unlike the test for partitioning of a regular block device, in this |
189 | 485 | # case parted was not called as there's no existing partition table | 501 | # case parted was not called as there's no existing partition table |
190 | @@ -648,8 +664,8 @@ | |||
191 | 648 | lambda image: ('/dev/loop99', '/dev/loop98'))) | 664 | lambda image: ('/dev/loop99', '/dev/loop98'))) |
192 | 649 | uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a' | 665 | uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a' |
193 | 650 | bootfs_dev, rootfs_dev = setup_partitions( | 666 | bootfs_dev, rootfs_dev = setup_partitions( |
196 | 651 | 'beagle', Media(tempfile), 32, '2G', 'boot', 'root', 'ext3', | 667 | board_configs['beagle'], Media(tempfile), '2G', 'boot', |
197 | 652 | uuid, True, True, True) | 668 | 'root', 'ext3', uuid, True, True, True) |
198 | 653 | self.assertEqual( | 669 | self.assertEqual( |
199 | 654 | # This is the call that would create the image file. | 670 | # This is the call that would create the image file. |
200 | 655 | [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'], | 671 | [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'], |
201 | @@ -680,8 +696,8 @@ | |||
202 | 680 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) | 696 | popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) |
203 | 681 | uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a' | 697 | uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a' |
204 | 682 | bootfs_dev, rootfs_dev = setup_partitions( | 698 | bootfs_dev, rootfs_dev = setup_partitions( |
207 | 683 | 'beagle', media, 32, '2G', 'boot', 'root', 'ext3', uuid, True, | 699 | board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3', |
208 | 684 | True, True) | 700 | uuid, True, True, True) |
209 | 685 | self.assertEqual( | 701 | self.assertEqual( |
210 | 686 | [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'], | 702 | [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'], |
211 | 687 | ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile], | 703 | ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile], |