From patchwork Tue Jan 25 22:33:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 25 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:39:19 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.10 with SMTP id b10cs70904yan; Tue, 25 Jan 2011 14:33:30 -0800 (PST) Received: by 10.216.13.194 with SMTP id b44mr393132web.68.1295994809569; Tue, 25 Jan 2011 14:33:29 -0800 (PST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id h61si23601506wes.155.2011.01.25.14.33.28; Tue, 25 Jan 2011 14:33:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1PhrS4-0006JR-NG for ; Tue, 25 Jan 2011 22:33:28 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id AC8AB2E8EDC for ; Tue, 25 Jan 2011 22:33:28 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-maintainers/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 260 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-maintainers/linaro-image-tools/trunk] Rev 260: Get rid of the mx51evk-specific code in create_partitions Message-Id: <20110125223328.12811.50837.launchpad@loganberry.canonical.com> Date: Tue, 25 Jan 2011 22:33:28 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="12248"; Instance="initZopeless config overlay" X-Launchpad-Hash: c57c2ac214ab09babc7aea201f0445bd40217f1e Merge authors: Guilherme Salgado (salgado) Related merge proposals: https://code.launchpad.net/~salgado/linaro-image-tools/mx51evk-code-cleanup/+merge/47456 proposed by: Guilherme Salgado (salgado) review: Approve - Loïc Minier (lool) review: Approve - James Westby (james-w) ------------------------------------------------------------ revno: 260 [merge] committer: Guilherme Salgado branch nick: trunk timestamp: Tue 2011-01-25 20:31:26 -0200 message: Get rid of the mx51evk-specific code in create_partitions modified: linaro-media-create linaro_media_create/boards.py linaro_media_create/partitions.py linaro_media_create/tests/test_media_create.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk You are subscribed to branch lp:linaro-image-tools. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro-media-create' --- linaro-media-create 2011-01-25 12:51:19 +0000 +++ linaro-media-create 2011-01-25 20:04:45 +0000 @@ -104,9 +104,8 @@ install_hwpacks(ROOTFS_DIR, TMP_DIR, args.hwpack_force_yes, *hwpacks) boot_partition, root_partition = setup_partitions( - args.board, media, board_config.fat_size, args.image_size, - args.boot_label, args.rfs_label, args.rootfs, ROOTFS_UUID, - args.should_create_partitions, + board_config, media, args.image_size, args.boot_label, args.rfs_label, + args.rootfs, ROOTFS_UUID, args.should_create_partitions, args.should_format_bootfs, args.should_format_rootfs) if args.should_format_bootfs: === 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:04:45 +0000 @@ -35,6 +35,19 @@ boot_script = None @classmethod + def get_sfdisk_cmd(cls): + """Return the sfdisk command to partition the media.""" + if cls.fat_size == 32: + partition_type = '0x0C' + else: + partition_type = '0x0E' + + # This will create a partition of the given type, containing 9 + # cylinders (74027520 bytes, ~70 MiB), followed by a Linux-type + # partition containing the rest of the free space. + return ',9,%s,*\n,,,-' % partition_type + + @classmethod def _get_boot_cmd(cls, is_live, is_lowmem, consoles): """Get the boot command for this board. @@ -195,6 +208,14 @@ mmc_option = '0:2' @classmethod + def get_sfdisk_cmd(cls): + # Create a one cylinder partition for fixed-offset bootloader data at + # the beginning of the image (size is one cylinder, so 8224768 bytes + # with the first sector for MBR). + sfdisk_cmd = super(Mx51evkConfig, cls).get_sfdisk_cmd() + return ',1,0xDA\n%s' % sfdisk_cmd + + @classmethod def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir, boot_dir, boot_script, boot_device_or_file): uboot_file = os.path.join( === 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:04:45 +0000 @@ -24,15 +24,14 @@ # the appropriate function for the given type of device? I think it's still # small enough that there's not much benefit in doing that, but if it grows we # might want to do it. -def setup_partitions(board, media, fat_size, image_size, - bootfs_label, rootfs_label, rootfs_type, rootfs_uuid, +def setup_partitions(board_config, media, image_size, bootfs_label, + rootfs_label, rootfs_type, rootfs_uuid, should_create_partitions, should_format_bootfs, should_format_rootfs): """Make sure the given device is partitioned to boot the given board. - :param board: The board's name, as a string. + :param board_config: A BoardConfig class. :param media: The Media we should partition. - :param fat_size: The FAT size (16 or 32) for the boot partition. :param image_size: The size of the image file, in case we're setting up a QEMU image. :param should_create_partitions: Whether or not we should erase existing @@ -49,7 +48,8 @@ proc.wait() if should_create_partitions: - create_partitions(board, media, fat_size, HEADS, SECTORS, cylinders) + create_partitions( + board_config, media, HEADS, SECTORS, cylinders) if media.is_block_device: bootfs, rootfs = get_boot_and_root_partitions_for_media(media) @@ -63,7 +63,8 @@ # filesystem. ensure_partition_is_not_mounted(bootfs) proc = cmd_runner.run( - ['mkfs.vfat', '-F', str(fat_size), bootfs, '-n', bootfs_label], + ['mkfs.vfat', '-F', str(board_config.fat_size), bootfs, '-n', + bootfs_label], as_root=True) proc.wait() @@ -272,12 +273,11 @@ return proc.communicate("%s\n" % commands) -def create_partitions(board, media, fat_size, heads, sectors, cylinders=None): +def create_partitions(board_config, media, heads, sectors, cylinders=None): """Partition the given media according to the board requirements. - :param board: A string with the board type (e.g. beagle, panda, etc) + :param board_config: A BoardConfig class. :param media: A setup_partitions.Media object to partition. - :param fat_size: The type of FATs used in the boot partition (16 or 32). :param heads: Number of heads to use in the disk geometry of partitions. :param sectors: Number of sectors to use in the disk geometry of @@ -291,21 +291,7 @@ ['parted', '-s', media.path, 'mklabel', 'msdos'], as_root=True) proc.wait() - if fat_size == 32: - partition_type = '0x0C' - else: - partition_type = '0x0E' - - sfdisk_cmd = ',9,%s,*\n,,,-' % partition_type - if board == 'mx51evk': - # Create a one cylinder partition for fixed-offset bootloader data at - # the beginning of the image (size is one cylinder, so 8224768 bytes - # with the first sector for MBR). - sfdisk_cmd = ',1,0xDA\n%s' % sfdisk_cmd - - # Create a VFAT or FAT16 partition of 9 cylinders (74027520 bytes, ~70 - # MiB), followed by a Linux-type partition containing the rest of the free - # space. + sfdisk_cmd = board_config.get_sfdisk_cmd() run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path) # Sync and sleep to wait for the partition to settle. === 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:04:45 +0000 @@ -218,6 +218,19 @@ 'make_boot_script', 'make_boot_ini'] self.assertEqual(expected, self.funcs_calls) + +class TestGetSfdiskCmd(TestCase): + + def test_default(self): + self.assertEquals( + ',9,0x0C,*\n,,,-', boards.BoardConfig.get_sfdisk_cmd()) + + def test_mx51evk(self): + self.assertEquals( + ',1,0xDA\n,9,0x0C,*\n,,,-', + board_configs['mx51evk'].get_sfdisk_cmd()) + + class TestGetBootCmd(TestCase): def test_vexpress(self): @@ -447,7 +460,8 @@ popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) - create_partitions('mx51evk', self.media, 32, 255, 63, '') + create_partitions( + board_configs['mx51evk'], self.media, 255, 63, '') self.assertEqual( [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], @@ -464,7 +478,8 @@ popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) - create_partitions('beagle', self.media, 32, 255, 63, '') + create_partitions( + board_configs['beagle'], self.media, 255, 63, '') self.assertEqual( [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'], @@ -479,7 +494,8 @@ sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture()) tempfile = self.createTempFileAsFixture() - create_partitions('beagle', Media(tempfile), 32, 255, 63, '') + create_partitions( + board_configs['beagle'], Media(tempfile), 255, 63, '') # Unlike the test for partitioning of a regular block device, in this # case parted was not called as there's no existing partition table @@ -648,8 +664,8 @@ lambda image: ('/dev/loop99', '/dev/loop98'))) uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a' bootfs_dev, rootfs_dev = setup_partitions( - 'beagle', Media(tempfile), 32, '2G', 'boot', 'root', 'ext3', - uuid, True, True, True) + board_configs['beagle'], Media(tempfile), '2G', 'boot', + 'root', 'ext3', uuid, True, True, True) self.assertEqual( # This is the call that would create the image file. [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'], @@ -680,8 +696,8 @@ popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a' bootfs_dev, rootfs_dev = setup_partitions( - 'beagle', media, 32, '2G', 'boot', 'root', 'ext3', uuid, True, - True, True) + board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3', + uuid, True, True, True) self.assertEqual( [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'], ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile],