[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
State Accepted
Headers show

Commit Message

Guilherme Salgado Jan. 26, 2011, 5:59 p.m.
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 <salgado@canonical.com>
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

Patch

=== 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))