=== modified file 'linaro_media_create/partitions.py'
@@ -27,6 +27,7 @@
from parted import (
Device,
Disk,
+ PARTITION_NORMAL,
)
from linaro_media_create import cmd_runner
@@ -60,9 +61,9 @@
if not media.is_block_device:
image_size_in_bytes = convert_size_to_bytes(image_size)
cylinders = image_size_in_bytes / CYLINDER_SIZE
- image_size_in_bytes = cylinders * CYLINDER_SIZE
proc = cmd_runner.run(
- ['qemu-img', 'create', '-f', 'raw', media.path, image_size],
+ ['qemu-img', 'create', '-f', 'raw', media.path,
+ str(image_size_in_bytes)],
stdout=open('/dev/null', 'w'))
proc.wait()
@@ -173,19 +174,32 @@
# block device we'd need root rights.
disk = Disk(Device(image_file))
vfat_partition = None
+ linux_partition = None
for partition in disk.partitions:
+ assert partition.type == PARTITION_NORMAL, (
+ "Parted should only return normal partitions but got type %i" %
+ partition.type)
if 'boot' in partition.getFlagsAsString():
geometry = partition.geometry
vfat_offset = geometry.start * 512
vfat_size = geometry.length * 512
vfat_partition = partition
+ elif vfat_partition is not None:
+ # next partition after boot partition is the root partition
+ # NB: don't use vfat_partition.nextPartition() as that might return
+ # a partition of type PARTITION_FREESPACE; it's much easier to
+ # iterate disk.partitions which only returns
+ # parted.PARTITION_NORMAL partitions
+ geometry = partition.geometry
+ linux_offset = geometry.start * 512
+ linux_size = geometry.length * 512
+ linux_partition = partition
+ break
assert vfat_partition is not None, (
"Couldn't find boot partition on %s" % image_file)
- linux_partition = vfat_partition.nextPartition()
- geometry = linux_partition.geometry
- linux_offset = geometry.start * 512
- linux_size = geometry.length * 512
+ assert linux_partition is not None, (
+ "Couldn't find root partition on %s" % image_file)
return vfat_size, vfat_offset, linux_size, linux_offset
=== modified file 'linaro_media_create/tests/test_media_create.py'
@@ -722,6 +722,16 @@
[129024L, 32256L, 10321920L, 161280L],
[vfat_size, vfat_offset, linux_size, linux_offset])
+ def test_partition_numbering(self):
+ # another Linux partition after the boot/root parts
+ tempfile = self._create_qemu_img_with_partitions(
+ ',1,0x0C,*\n,1,,-\n,,,-')
+ vfat_size, vfat_offset, linux_size, linux_offset = (
+ calculate_partition_size_and_offset(tempfile))
+ # check that the linux partition offset starts on second cylinder so
+ # that it's the partition immediately following the vfat one
+ self.assertEqual(linux_offset, 5 * 63 * 512)
+
def test_get_boot_and_root_partitions_for_media_beagle(self):
self.useFixture(MockSomethingFixture(
partitions, '_get_device_file_for_partition_number',
@@ -829,7 +839,7 @@
'root', 'ext3', True, True, True)
self.assertEqual(
# This is the call that would create the image file.
- [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'],
+ [['qemu-img', 'create', '-f', 'raw', tempfile, '2147483648'],
# This call would partition the image file.
['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', '-C', '261',
tempfile],