Merge lp:~salgado/linaro-image-tools/mx51evk-code-cleanup into lp:linaro-image-tools/11.11

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
Reviewer Review Type Date Requested Status
Loïc Minier (community) Approve
James Westby (community) Approve
Review via email: mp+47456@code.launchpad.net

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
James Westby (james-w) :
review: Approve
Revision history for this message
Loïc Minier (lool) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'linaro-media-create'
--- linaro-media-create 2011-01-25 12:51:19 +0000
+++ linaro-media-create 2011-01-25 20:07:57 +0000
@@ -104,9 +104,8 @@
104 install_hwpacks(ROOTFS_DIR, TMP_DIR, args.hwpack_force_yes, *hwpacks)104 install_hwpacks(ROOTFS_DIR, TMP_DIR, args.hwpack_force_yes, *hwpacks)
105105
106 boot_partition, root_partition = setup_partitions(106 boot_partition, root_partition = setup_partitions(
107 args.board, media, board_config.fat_size, args.image_size,107 board_config, media, args.image_size, args.boot_label, args.rfs_label,
108 args.boot_label, args.rfs_label, args.rootfs, ROOTFS_UUID,108 args.rootfs, ROOTFS_UUID, args.should_create_partitions,
109 args.should_create_partitions,
110 args.should_format_bootfs, args.should_format_rootfs)109 args.should_format_bootfs, args.should_format_rootfs)
111110
112 if args.should_format_bootfs:111 if args.should_format_bootfs:
113112
=== modified file 'linaro_media_create/boards.py'
--- linaro_media_create/boards.py 2011-01-25 12:02:38 +0000
+++ linaro_media_create/boards.py 2011-01-25 20:07:57 +0000
@@ -35,6 +35,19 @@
35 boot_script = None35 boot_script = None
3636
37 @classmethod37 @classmethod
38 def get_sfdisk_cmd(cls):
39 """Return the sfdisk command to partition the media."""
40 if cls.fat_size == 32:
41 partition_type = '0x0C'
42 else:
43 partition_type = '0x0E'
44
45 # This will create a partition of the given type, containing 9
46 # cylinders (74027520 bytes, ~70 MiB), followed by a Linux-type
47 # partition containing the rest of the free space.
48 return ',9,%s,*\n,,,-' % partition_type
49
50 @classmethod
38 def _get_boot_cmd(cls, is_live, is_lowmem, consoles):51 def _get_boot_cmd(cls, is_live, is_lowmem, consoles):
39 """Get the boot command for this board.52 """Get the boot command for this board.
4053
@@ -195,6 +208,14 @@
195 mmc_option = '0:2'208 mmc_option = '0:2'
196209
197 @classmethod210 @classmethod
211 def get_sfdisk_cmd(cls):
212 # Create a one cylinder partition for fixed-offset bootloader data at
213 # the beginning of the image (size is one cylinder, so 8224768 bytes
214 # with the first sector for MBR).
215 sfdisk_cmd = super(Mx51evkConfig, cls).get_sfdisk_cmd()
216 return ',1,0xDA\n%s' % sfdisk_cmd
217
218 @classmethod
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,
199 boot_dir, boot_script, boot_device_or_file):220 boot_dir, boot_script, boot_device_or_file):
200 uboot_file = os.path.join(221 uboot_file = os.path.join(
201222
=== modified file 'linaro_media_create/partitions.py'
--- linaro_media_create/partitions.py 2011-01-24 19:39:45 +0000
+++ linaro_media_create/partitions.py 2011-01-25 20:07:57 +0000
@@ -24,15 +24,14 @@
24# the appropriate function for the given type of device? I think it's still24# the appropriate function for the given type of device? I think it's still
25# small enough that there's not much benefit in doing that, but if it grows we25# small enough that there's not much benefit in doing that, but if it grows we
26# might want to do it.26# might want to do it.
27def setup_partitions(board, media, fat_size, image_size,27def setup_partitions(board_config, media, image_size, bootfs_label,
28 bootfs_label, rootfs_label, rootfs_type, rootfs_uuid,28 rootfs_label, rootfs_type, rootfs_uuid,
29 should_create_partitions, should_format_bootfs,29 should_create_partitions, should_format_bootfs,
30 should_format_rootfs):30 should_format_rootfs):
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.
3232
33 :param board: The board's name, as a string.33 :param board_config: A BoardConfig class.
34 :param media: The Media we should partition.34 :param media: The Media we should partition.
35 :param fat_size: The FAT size (16 or 32) for the boot partition.
36 :param image_size: The size of the image file, in case we're setting up a35 :param image_size: The size of the image file, in case we're setting up a
37 QEMU image.36 QEMU image.
38 :param should_create_partitions: Whether or not we should erase existing37 :param should_create_partitions: Whether or not we should erase existing
@@ -49,7 +48,8 @@
49 proc.wait()48 proc.wait()
5049
51 if should_create_partitions:50 if should_create_partitions:
52 create_partitions(board, media, fat_size, HEADS, SECTORS, cylinders)51 create_partitions(
52 board_config, media, HEADS, SECTORS, cylinders)
5353
54 if media.is_block_device:54 if media.is_block_device:
55 bootfs, rootfs = get_boot_and_root_partitions_for_media(media)55 bootfs, rootfs = get_boot_and_root_partitions_for_media(media)
@@ -63,7 +63,8 @@
63 # filesystem.63 # filesystem.
64 ensure_partition_is_not_mounted(bootfs)64 ensure_partition_is_not_mounted(bootfs)
65 proc = cmd_runner.run(65 proc = cmd_runner.run(
66 ['mkfs.vfat', '-F', str(fat_size), bootfs, '-n', bootfs_label],66 ['mkfs.vfat', '-F', str(board_config.fat_size), bootfs, '-n',
67 bootfs_label],
67 as_root=True)68 as_root=True)
68 proc.wait()69 proc.wait()
6970
@@ -272,12 +273,11 @@
272 return proc.communicate("%s\n" % commands)273 return proc.communicate("%s\n" % commands)
273274
274275
275def create_partitions(board, media, fat_size, heads, sectors, cylinders=None):276def create_partitions(board_config, media, heads, sectors, cylinders=None):
276 """Partition the given media according to the board requirements.277 """Partition the given media according to the board requirements.
277278
278 :param board: A string with the board type (e.g. beagle, panda, etc)279 :param board_config: A BoardConfig class.
279 :param media: A setup_partitions.Media object to partition.280 :param media: A setup_partitions.Media object to partition.
280 :param fat_size: The type of FATs used in the boot partition (16 or 32).
281 :param heads: Number of heads to use in the disk geometry of281 :param heads: Number of heads to use in the disk geometry of
282 partitions.282 partitions.
283 :param sectors: Number of sectors to use in the disk geometry of283 :param sectors: Number of sectors to use in the disk geometry of
@@ -291,21 +291,7 @@
291 ['parted', '-s', media.path, 'mklabel', 'msdos'], as_root=True)291 ['parted', '-s', media.path, 'mklabel', 'msdos'], as_root=True)
292 proc.wait()292 proc.wait()
293293
294 if fat_size == 32:294 sfdisk_cmd = board_config.get_sfdisk_cmd()
295 partition_type = '0x0C'
296 else:
297 partition_type = '0x0E'
298
299 sfdisk_cmd = ',9,%s,*\n,,,-' % partition_type
300 if board == 'mx51evk':
301 # Create a one cylinder partition for fixed-offset bootloader data at
302 # the beginning of the image (size is one cylinder, so 8224768 bytes
303 # with the first sector for MBR).
304 sfdisk_cmd = ',1,0xDA\n%s' % sfdisk_cmd
305
306 # Create a VFAT or FAT16 partition of 9 cylinders (74027520 bytes, ~70
307 # MiB), followed by a Linux-type partition containing the rest of the free
308 # space.
309 run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path)295 run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path)
310296
311 # Sync and sleep to wait for the partition to settle.297 # Sync and sleep to wait for the partition to settle.
312298
=== modified file 'linaro_media_create/tests/test_media_create.py'
--- linaro_media_create/tests/test_media_create.py 2011-01-25 13:44:16 +0000
+++ linaro_media_create/tests/test_media_create.py 2011-01-25 20:07:57 +0000
@@ -218,6 +218,19 @@
218 'make_boot_script', 'make_boot_ini']218 'make_boot_script', 'make_boot_ini']
219 self.assertEqual(expected, self.funcs_calls)219 self.assertEqual(expected, self.funcs_calls)
220220
221
222class TestGetSfdiskCmd(TestCase):
223
224 def test_default(self):
225 self.assertEquals(
226 ',9,0x0C,*\n,,,-', boards.BoardConfig.get_sfdisk_cmd())
227
228 def test_mx51evk(self):
229 self.assertEquals(
230 ',1,0xDA\n,9,0x0C,*\n,,,-',
231 board_configs['mx51evk'].get_sfdisk_cmd())
232
233
221class TestGetBootCmd(TestCase):234class TestGetBootCmd(TestCase):
222235
223 def test_vexpress(self):236 def test_vexpress(self):
@@ -447,7 +460,8 @@
447 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())460 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
448 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())461 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
449462
450 create_partitions('mx51evk', self.media, 32, 255, 63, '')463 create_partitions(
464 board_configs['mx51evk'], self.media, 255, 63, '')
451465
452 self.assertEqual(466 self.assertEqual(
453 [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'],467 [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'],
@@ -464,7 +478,8 @@
464 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())478 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
465 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())479 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
466480
467 create_partitions('beagle', self.media, 32, 255, 63, '')481 create_partitions(
482 board_configs['beagle'], self.media, 255, 63, '')
468483
469 self.assertEqual(484 self.assertEqual(
470 [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'],485 [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'],
@@ -479,7 +494,8 @@
479 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())494 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
480495
481 tempfile = self.createTempFileAsFixture()496 tempfile = self.createTempFileAsFixture()
482 create_partitions('beagle', Media(tempfile), 32, 255, 63, '')497 create_partitions(
498 board_configs['beagle'], Media(tempfile), 255, 63, '')
483499
484 # Unlike the test for partitioning of a regular block device, in this500 # Unlike the test for partitioning of a regular block device, in this
485 # case parted was not called as there's no existing partition table501 # case parted was not called as there's no existing partition table
@@ -648,8 +664,8 @@
648 lambda image: ('/dev/loop99', '/dev/loop98')))664 lambda image: ('/dev/loop99', '/dev/loop98')))
649 uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'665 uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'
650 bootfs_dev, rootfs_dev = setup_partitions(666 bootfs_dev, rootfs_dev = setup_partitions(
651 'beagle', Media(tempfile), 32, '2G', 'boot', 'root', 'ext3',667 board_configs['beagle'], Media(tempfile), '2G', 'boot',
652 uuid, True, True, True)668 'root', 'ext3', uuid, True, True, True)
653 self.assertEqual(669 self.assertEqual(
654 # This is the call that would create the image file.670 # This is the call that would create the image file.
655 [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'],671 [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'],
@@ -680,8 +696,8 @@
680 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())696 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
681 uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'697 uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'
682 bootfs_dev, rootfs_dev = setup_partitions(698 bootfs_dev, rootfs_dev = setup_partitions(
683 'beagle', media, 32, '2G', 'boot', 'root', 'ext3', uuid, True,699 board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3',
684 True, True)700 uuid, True, True, True)
685 self.assertEqual(701 self.assertEqual(
686 [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'],702 [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'],
687 ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile],703 ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile],

Subscribers

People subscribed via source and target branches