Merge lp:~salgado/linaro-image-tools/drop-udisks-when-not-strictly-necessary into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 262
Proposed branch: lp:~salgado/linaro-image-tools/drop-udisks-when-not-strictly-necessary
Merge into: lp:linaro-image-tools/11.11
Diff against target: 148 lines (+17/-46)
3 files modified
linaro_media_create/boards.py (+2/-0)
linaro_media_create/partitions.py (+7/-29)
linaro_media_create/tests/test_media_create.py (+8/-17)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/drop-udisks-when-not-strictly-necessary
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+47537@code.launchpad.net

Description of the change

Use the board's mmc_part_offset (instead of the media's partition count) to figure out the boot/root partition numbers

This is a nice simplification that allows us to get rid of a udisks callsite as a side effect

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Looks good to me.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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:22:54 +0000
@@ -134,6 +134,7 @@
134 'earlyprintk fixrtc nocompcache vram=12M '134 'earlyprintk fixrtc nocompcache vram=12M '
135 'omapfb.mode=dvi:1280x720MR-16@60')135 'omapfb.mode=dvi:1280x720MR-16@60')
136136
137
137class OveroConfig(OmapConfig):138class OveroConfig(OmapConfig):
138 uboot_flavor = 'omap3_overo'139 uboot_flavor = 'omap3_overo'
139 extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'140 extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'
@@ -145,6 +146,7 @@
145 extra_boot_args_options = (146 extra_boot_args_options = (
146 'earlyprintk')147 'earlyprintk')
147148
149
148class PandaConfig(OmapConfig):150class PandaConfig(OmapConfig):
149 uboot_flavor = 'omap4_panda'151 uboot_flavor = 'omap4_panda'
150 extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'152 extra_serial_opts = 'console=tty0 console=ttyO2,115200n8'
151153
=== 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:22:54 +0000
@@ -52,7 +52,8 @@
52 board_config, media, HEADS, SECTORS, cylinders)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(
56 media, board_config)
56 else:57 else:
57 bootfs, rootfs = get_boot_and_root_loopback_devices(media.path)58 bootfs, rootfs = get_boot_and_root_loopback_devices(media.path)
5859
@@ -151,34 +152,21 @@
151 return vfat_size, vfat_offset, linux_size, linux_offset152 return vfat_size, vfat_offset, linux_size, linux_offset
152153
153154
154def get_boot_and_root_partitions_for_media(media):155def get_boot_and_root_partitions_for_media(media, board_config):
155 """Return the device files for the boot and root partitions of media.156 """Return the device files for the boot and root partitions of media.
156157
157 If the given media has 2 partitions, the first is boot and the second is158 For boot we use partition number 1 plus the board's defined partition
158 root. If there are 3 partitions, the second is boot and third is root.159 offset and for root we use partition number 2 plus the board's offset.
159
160 If there are any other number of partitions, ValueError is raised.
161160
162 This function must only be used for block devices.161 This function must only be used for block devices.
163 """162 """
164 assert media.is_block_device, (163 assert media.is_block_device, (
165 "This function must only be used for block devices")164 "This function must only be used for block devices")
166165
167 partition_count = _get_partition_count(media)
168
169 if partition_count == 2:
170 partition_offset = 0
171 elif partition_count == 3:
172 partition_offset = 1
173 else:
174 raise ValueError(
175 "Unexpected number of partitions on %s: %d" % (
176 media.path, partition_count))
177
178 boot_partition = _get_device_file_for_partition_number(166 boot_partition = _get_device_file_for_partition_number(
179 media.path, 1 + partition_offset)167 media.path, 1 + board_config.mmc_part_offset)
180 root_partition = _get_device_file_for_partition_number(168 root_partition = _get_device_file_for_partition_number(
181 media.path, 2 + partition_offset)169 media.path, 2 + board_config.mmc_part_offset)
182 assert boot_partition is not None and root_partition is not None, (170 assert boot_partition is not None and root_partition is not None, (
183 "Could not find boot/root partition for %s" % media.path)171 "Could not find boot/root partition for %s" % media.path)
184 return boot_partition, root_partition172 return boot_partition, root_partition
@@ -203,16 +191,6 @@
203 return None191 return None
204192
205193
206def _get_partition_count(media):
207 """Return the number of partitions on the given media."""
208 # We could do the same easily using python-parted but it requires root
209 # rights to read block devices, so we use UDisks here.
210 device_path = _get_udisks_device_path(media.path)
211 device = dbus.SystemBus().get_object(UDISKS, device_path)
212 return device.Get(
213 device_path, 'PartitionTableCount', dbus_interface=DBUS_PROPERTIES)
214
215
216def _get_udisks_device_path(device):194def _get_udisks_device_path(device):
217 """Return the UDisks path for the given device."""195 """Return the UDisks path for the given device."""
218 bus = dbus.SystemBus()196 bus = dbus.SystemBus()
219197
=== 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:22:54 +0000
@@ -560,36 +560,29 @@
560 [129024L, 32256L, 10321920L, 161280L],560 [129024L, 32256L, 10321920L, 161280L],
561 [vfat_size, vfat_offset, linux_size, linux_offset])561 [vfat_size, vfat_offset, linux_size, linux_offset])
562562
563 def test_get_boot_and_root_partitions_for_media_with_2_partitions(self):563 def test_get_boot_and_root_partitions_for_media_beagle(self):
564 self.useFixture(MockSomethingFixture(
565 partitions, '_get_partition_count', lambda media: 2))
566 tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-')
567 self.useFixture(MockSomethingFixture(564 self.useFixture(MockSomethingFixture(
568 partitions, '_get_device_file_for_partition_number',565 partitions, '_get_device_file_for_partition_number',
569 lambda dev, partition: '%s%d' % (tempfile, partition)))566 lambda dev, partition: '%s%d' % (tempfile, partition)))
567 tempfile = self.createTempFileAsFixture()
570 media = Media(tempfile)568 media = Media(tempfile)
571 # Pretend the image file is a block device, or else
572 # get_boot_and_root_partitions_for_media will choke.
573 media.is_block_device = True569 media.is_block_device = True
574 self.assertEqual(570 self.assertEqual(
575 ("%s%d" % (tempfile, 1), "%s%d" % (tempfile, 2)),571 ("%s%d" % (tempfile, 1), "%s%d" % (tempfile, 2)),
576 get_boot_and_root_partitions_for_media(media))572 get_boot_and_root_partitions_for_media(
573 media, board_configs['beagle']))
577574
578 def test_get_boot_and_root_partitions_for_media_with_3_partitions(self):575 def test_get_boot_and_root_partitions_for_media_mx51evk(self):
579 self.useFixture(MockSomethingFixture(
580 partitions, '_get_partition_count', lambda media: 3))
581 tempfile = self._create_qemu_img_with_partitions(
582 ',1,0xDA\n,1,0x0C,*\n,,,-')
583 self.useFixture(MockSomethingFixture(576 self.useFixture(MockSomethingFixture(
584 partitions, '_get_device_file_for_partition_number',577 partitions, '_get_device_file_for_partition_number',
585 lambda dev, partition: '%s%d' % (tempfile, partition)))578 lambda dev, partition: '%s%d' % (tempfile, partition)))
579 tempfile = self.createTempFileAsFixture()
586 media = Media(tempfile)580 media = Media(tempfile)
587 # Pretend the image file is a block device, or else
588 # get_boot_and_root_partitions_for_media will choke.
589 media.is_block_device = True581 media.is_block_device = True
590 self.assertEqual(582 self.assertEqual(
591 ("%s%d" % (tempfile, 2), "%s%d" % (tempfile, 3)),583 ("%s%d" % (tempfile, 2), "%s%d" % (tempfile, 3)),
592 get_boot_and_root_partitions_for_media(media))584 get_boot_and_root_partitions_for_media(
585 media, board_configs['mx51evk']))
593586
594 def _create_qemu_img_with_partitions(self, sfdisk_commands):587 def _create_qemu_img_with_partitions(self, sfdisk_commands):
595 tempfile = self.createTempFileAsFixture()588 tempfile = self.createTempFileAsFixture()
@@ -681,8 +674,6 @@
681 def test_setup_partitions_for_block_device(self):674 def test_setup_partitions_for_block_device(self):
682 self.useFixture(MockSomethingFixture(675 self.useFixture(MockSomethingFixture(
683 sys, 'stdout', open('/dev/null', 'w')))676 sys, 'stdout', open('/dev/null', 'w')))
684 self.useFixture(MockSomethingFixture(
685 partitions, '_get_partition_count', lambda media: 2))
686 # Pretend the partitions are mounted.677 # Pretend the partitions are mounted.
687 self.useFixture(MockSomethingFixture(678 self.useFixture(MockSomethingFixture(
688 partitions, 'is_partition_mounted', lambda part: True))679 partitions, 'is_partition_mounted', lambda part: True))

Subscribers

People subscribed via source and target branches