From patchwork Wed Jan 26 17:59:28 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 32 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:21 -0000 Delivered-To: patches@linaro.org Received: by 10.147.124.10 with SMTP id b10cs90218yan; Wed, 26 Jan 2011 10:17:19 -0800 (PST) Received: by 10.204.114.72 with SMTP id d8mr734278bkq.68.1296064769160; Wed, 26 Jan 2011 09:59:29 -0800 (PST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id c20si39242716bkc.100.2011.01.26.09.59.28; Wed, 26 Jan 2011 09:59: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 1Pi9eS-0001sU-8Y for ; Wed, 26 Jan 2011 17:59:28 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 3D98B2E86C5 for ; Wed, 26 Jan 2011 17:59: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: 262 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-maintainers/linaro-image-tools/trunk] Rev 262: Use the board's mmc_part_offset (instead of the media's partition count) to figure out the boot/r... Message-Id: <20110126175928.21387.89270.launchpad@loganberry.canonical.com> Date: Wed, 26 Jan 2011 17:59: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="12263"; Instance="initZopeless config overlay" X-Launchpad-Hash: 115204eac7e61a3537391f8181de6814f2c1e29d Merge authors: Guilherme Salgado (salgado) Related merge proposals: https://code.launchpad.net/~salgado/linaro-image-tools/drop-udisks-when-not-strictly-necessary/+merge/47537 proposed by: Guilherme Salgado (salgado) review: Approve - James Westby (james-w) ------------------------------------------------------------ revno: 262 [merge] committer: Guilherme Salgado branch nick: trunk timestamp: Wed 2011-01-26 15:47:15 -0200 message: Use the board's mmc_part_offset (instead of the media's partition count) to figure out the boot/root partition numbers modified: 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/boards.py' --- linaro_media_create/boards.py 2011-01-25 20:04:45 +0000 +++ linaro_media_create/boards.py 2011-01-26 15:16:34 +0000 @@ -134,6 +134,7 @@ 'earlyprintk fixrtc nocompcache vram=12M ' 'omapfb.mode=dvi:1280x720MR-16@60') + class OveroConfig(OmapConfig): uboot_flavor = 'omap3_overo' extra_serial_opts = 'console=tty0 console=ttyO2,115200n8' @@ -145,6 +146,7 @@ extra_boot_args_options = ( 'earlyprintk') + class PandaConfig(OmapConfig): uboot_flavor = 'omap4_panda' extra_serial_opts = 'console=tty0 console=ttyO2,115200n8' === modified file 'linaro_media_create/partitions.py' --- linaro_media_create/partitions.py 2011-01-25 20:04:45 +0000 +++ linaro_media_create/partitions.py 2011-01-26 15:16:34 +0000 @@ -52,7 +52,8 @@ board_config, media, HEADS, SECTORS, cylinders) if media.is_block_device: - bootfs, rootfs = get_boot_and_root_partitions_for_media(media) + bootfs, rootfs = get_boot_and_root_partitions_for_media( + media, board_config) else: bootfs, rootfs = get_boot_and_root_loopback_devices(media.path) @@ -151,34 +152,21 @@ return vfat_size, vfat_offset, linux_size, linux_offset -def get_boot_and_root_partitions_for_media(media): +def get_boot_and_root_partitions_for_media(media, board_config): """Return the device files for the boot and root partitions of media. - If the given media has 2 partitions, the first is boot and the second is - root. If there are 3 partitions, the second is boot and third is root. - - If there are any other number of partitions, ValueError is raised. + For boot we use partition number 1 plus the board's defined partition + offset and for root we use partition number 2 plus the board's offset. This function must only be used for block devices. """ assert media.is_block_device, ( "This function must only be used for block devices") - partition_count = _get_partition_count(media) - - if partition_count == 2: - partition_offset = 0 - elif partition_count == 3: - partition_offset = 1 - else: - raise ValueError( - "Unexpected number of partitions on %s: %d" % ( - media.path, partition_count)) - boot_partition = _get_device_file_for_partition_number( - media.path, 1 + partition_offset) + media.path, 1 + board_config.mmc_part_offset) root_partition = _get_device_file_for_partition_number( - media.path, 2 + partition_offset) + media.path, 2 + board_config.mmc_part_offset) assert boot_partition is not None and root_partition is not None, ( "Could not find boot/root partition for %s" % media.path) return boot_partition, root_partition @@ -203,16 +191,6 @@ return None -def _get_partition_count(media): - """Return the number of partitions on the given media.""" - # We could do the same easily using python-parted but it requires root - # rights to read block devices, so we use UDisks here. - device_path = _get_udisks_device_path(media.path) - device = dbus.SystemBus().get_object(UDISKS, device_path) - return device.Get( - device_path, 'PartitionTableCount', dbus_interface=DBUS_PROPERTIES) - - def _get_udisks_device_path(device): """Return the UDisks path for the given device.""" bus = dbus.SystemBus() === modified file 'linaro_media_create/tests/test_media_create.py' --- linaro_media_create/tests/test_media_create.py 2011-01-25 20:04:45 +0000 +++ linaro_media_create/tests/test_media_create.py 2011-01-26 15:16:34 +0000 @@ -560,36 +560,29 @@ [129024L, 32256L, 10321920L, 161280L], [vfat_size, vfat_offset, linux_size, linux_offset]) - def test_get_boot_and_root_partitions_for_media_with_2_partitions(self): - self.useFixture(MockSomethingFixture( - partitions, '_get_partition_count', lambda media: 2)) - tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-') + def test_get_boot_and_root_partitions_for_media_beagle(self): self.useFixture(MockSomethingFixture( partitions, '_get_device_file_for_partition_number', lambda dev, partition: '%s%d' % (tempfile, partition))) + tempfile = self.createTempFileAsFixture() media = Media(tempfile) - # Pretend the image file is a block device, or else - # get_boot_and_root_partitions_for_media will choke. media.is_block_device = True self.assertEqual( ("%s%d" % (tempfile, 1), "%s%d" % (tempfile, 2)), - get_boot_and_root_partitions_for_media(media)) + get_boot_and_root_partitions_for_media( + media, board_configs['beagle'])) - def test_get_boot_and_root_partitions_for_media_with_3_partitions(self): - self.useFixture(MockSomethingFixture( - partitions, '_get_partition_count', lambda media: 3)) - tempfile = self._create_qemu_img_with_partitions( - ',1,0xDA\n,1,0x0C,*\n,,,-') + def test_get_boot_and_root_partitions_for_media_mx51evk(self): self.useFixture(MockSomethingFixture( partitions, '_get_device_file_for_partition_number', lambda dev, partition: '%s%d' % (tempfile, partition))) + tempfile = self.createTempFileAsFixture() media = Media(tempfile) - # Pretend the image file is a block device, or else - # get_boot_and_root_partitions_for_media will choke. media.is_block_device = True self.assertEqual( ("%s%d" % (tempfile, 2), "%s%d" % (tempfile, 3)), - get_boot_and_root_partitions_for_media(media)) + get_boot_and_root_partitions_for_media( + media, board_configs['mx51evk'])) def _create_qemu_img_with_partitions(self, sfdisk_commands): tempfile = self.createTempFileAsFixture() @@ -681,8 +674,6 @@ def test_setup_partitions_for_block_device(self): self.useFixture(MockSomethingFixture( sys, 'stdout', open('/dev/null', 'w'))) - self.useFixture(MockSomethingFixture( - partitions, '_get_partition_count', lambda media: 2)) # Pretend the partitions are mounted. self.useFixture(MockSomethingFixture( partitions, 'is_partition_mounted', lambda part: True))