Merge lp:~lool/linaro-image-tools/4-mib-align into lp:linaro-image-tools/11.11

Proposed by Loïc Minier
Status: Merged
Merged at revision: 288
Proposed branch: lp:~lool/linaro-image-tools/4-mib-align
Merge into: lp:linaro-image-tools/11.11
Prerequisite: lp:~lool/linaro-image-tools/part-size-rework
Diff against target: 506 lines (+193/-60)
5 files modified
linaro-media-create (+1/-1)
linaro_media_create/__init__.py (+4/-0)
linaro_media_create/boards.py (+104/-12)
linaro_media_create/partitions.py (+22/-15)
linaro_media_create/tests/test_media_create.py (+62/-32)
To merge this branch: bzr merge lp:~lool/linaro-image-tools/4-mib-align
Reviewer Review Type Date Requested Status
Guilherme Salgado (community) Approve
Review via email: mp+49168@code.launchpad.net

Description of the change

This aligns partitions to 4 MiB

I've tested this successfully with:
* qemu 2G natty image, albeit no serial so couldn't check from Linux
* qemu 4G maverick image, this wouldn't boot at first, I had to replace u-boot.bin and MLO and then it booted -- not sure why, don't think this is a regression
* 1G overo image file dd-ed to a MMC, this booted and was aligned, but CHS was incorrect from Linux (didn't appear at 63/255 anymore)
* 1G to MMC for overo; this worked much like the image file case; fdisk output below
* 1G to MMC for beagle on beaglexm; fdisk output below

fdisk output on overo:
root@localhost:~# fdisk -l

Disk /dev/mmcblk0: 1967 MB, 1967128576 bytes
4 heads, 16 sectors/track, 60032 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008ed19

        Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 257 2009 56068 c W95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary.
/dev/mmcblk0p2 2049 60032 1855488 83 Linux
Partition 2 does not end on cylinder boundary.

fdisk output on beaglexm:

Disk /dev/mmcblk0: 1967 MB, 1967128576 bytes
4 heads, 16 sectors/track, 60032 cylinders
Units = cylinders of 64 * 512 = 32768 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000bf37e

        Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 257 2009 56068 c W95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary.
/dev/mmcblk0p2 2049 60032 1855488 83 Linux
Partition 2 does not end on cylinder boundary.

To post a comment you must log in.
Revision history for this message
Guilherme Salgado (salgado) wrote :
Download full text (15.0 KiB)

On Thu, 2011-02-10 at 02:37 +0000, Loïc Minier wrote:
>
> This aligns partitions to 4 MiB
>
> I've tested this successfully with:
> * qemu 2G natty image, albeit no serial so couldn't check from Linux
> * qemu 4G maverick image, this wouldn't boot at first, I had to replace u-boot.bin and MLO and then it booted -- not sure why, don't think this is a regression

Can you test this using an image generated by trunk? I thought that
would work, but maybe I'm missing something?

> * 1G overo image file dd-ed to a MMC, this booted and was aligned, but CHS was incorrect from Linux (didn't appear at 63/255 anymore)

Is there any chance this wrong geometry would cause problems to the old
OMAP3 roms that rely on specific values for CHS? Any way we could test
it?

> * 1G to MMC for overo; this worked much like the image file case; fdisk output below
> * 1G to MMC for beagle on beaglexm; fdisk output below
>
> fdisk output on overo:
> root@localhost:~# fdisk -l
>
> Disk /dev/mmcblk0: 1967 MB, 1967128576 bytes
> 4 heads, 16 sectors/track, 60032 cylinders
> Units = cylinders of 64 * 512 = 32768 bytes
> Sector size (logical/physical): 512 bytes / 512 bytes
> I/O size (minimum/optimal): 512 bytes / 512 bytes
> Disk identifier: 0x0008ed19
>
> Device Boot Start End Blocks Id System
> /dev/mmcblk0p1 * 257 2009 56068 c W95 FAT32 (LBA)
> Partition 1 does not end on cylinder boundary.
> /dev/mmcblk0p2 2049 60032 1855488 83 Linux
> Partition 2 does not end on cylinder boundary.
>
> fdisk output on beaglexm:
>
> Disk /dev/mmcblk0: 1967 MB, 1967128576 bytes
> 4 heads, 16 sectors/track, 60032 cylinders
> Units = cylinders of 64 * 512 = 32768 bytes
> Sector size (logical/physical): 512 bytes / 512 bytes
> I/O size (minimum/optimal): 512 bytes / 512 bytes
> Disk identifier: 0x000bf37e
>
> Device Boot Start End Blocks Id System
> /dev/mmcblk0p1 * 257 2009 56068 c W95 FAT32 (LBA)
> Partition 1 does not end on cylinder boundary.
> /dev/mmcblk0p2 2049 60032 1855488 83 Linux
> Partition 2 does not end on cylinder boundary.
>
> differences between files attachment (review-diff.txt)
> === modified file 'linaro_media_create/boards.py'
> --- linaro_media_create/boards.py 2011-02-01 13:16:43 +0000
> +++ linaro_media_create/boards.py 2011-02-10 02:37:40 +0000
> @@ -32,6 +32,43 @@
>
> from linaro_media_create import cmd_runner
>
> +# Notes:
> +# * geometry is currently always 255 heads and 63 sectors due to limitations of
> +# older OMAP3 boot ROMs
> +# * we want partitions aligned on 4 MiB as to get the best performance and
> +# limit wear-leveling
> +# * partitions should preferably end on cylinder boundaries, at least to please
> +# sfdisk but also just to have them as big as possible
> +# * this assumes that root partition follows the boot partition which follows
> +# an optional bootloader partition
> +# * image_size is passed on the command-line and should preferably be a power
> +# of 2; it should be used as a "don't go over this size" information for a
> +# real device, and a "give me a fil...

Revision history for this message
Loïc Minier (lool) wrote :
Download full text (3.1 KiB)

On Thu, Feb 10, 2011, Guilherme Salgado wrote:
> > * qemu 4G maverick image, this wouldn't boot at first, I had to replace u-boot.bin and MLO and then it booted -- not sure why, don't think this is a regression
> Can you test this using an image generated by trunk? I thought that
> would work, but maybe I'm missing something?

 Ok; will try

> > * 1G overo image file dd-ed to a MMC, this booted and was aligned, but CHS was incorrect from Linux (didn't appear at 63/255 anymore)
>
> Is there any chance this wrong geometry would cause problems to the old
> OMAP3 roms that rely on specific values for CHS? Any way we could test
> it?

 There is; there is no good record of the actual limitation, so we're
 trying our best to do 63/255, but I don't know if it's enough as it is
 or not :-/

 I guess it might be that we need to have the boot part start at the
 beginning of a cylinder for x-loader.

 I have a C3 or C4 beagle I could test on; beagle xM worked so I'm not
 too worried -- worst case we use a different scheme for xm and for
 oldomap3?

> Neither relative nor absolute sizes can be specified for each of the
> partitions, right? Do we really care about that?

 Well, I think it would be helpful some day... but later :-)

> > - # 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
> > + # This will create a boot partition of type partition_type at offset
> > + # (in sectors) BOOT_PART_START_S and of size BOOT_PART_SIZE_S followed
> > + # by a root partition of the default type (Linux) at offset (in
> > + # sectors) ROOT_PART_START_S filling the remaining space
> > + # XXX we should honor the specified image size by specifying a
> > + # corresponding root partition size
>
> You mean we're no longer using the size as the upper limit for the image
> size or that the image size is not exactly what was requested? If the
> former, I think we need a bug to track it, but if it's the latter, do we
> really care about it?

 I don't think there's any regression, but I don't think we're enforcing
 the cylinder size properly; ideally, the sfdisk commands would include
 a length for the rootfs rather than "use all space".

> > - ',1,0xDA', 5, 63, '', tempfile, as_root=False,
> > + ',1,0xDA', 255, 63, '', tempfile, as_root=False,
>
> Why did you change the two tests above?

 I wanted to use 255/63 consistently

> > - sfdisk_commands, 5, 63, '', tempfile, as_root=False,
> > + sfdisk_commands, 255, 63, '', tempfile, as_root=False,
> I'd be interested in knowing what motivated this change as well.

 (same)

> > + # boot part at +8 MiB, root part at +16 MiB
> > + tempfile = self._create_qemu_img_with_partitions('16384,15746,0x0C,*\n32768,,,-')
> I've seen the above string hard-coded in way too many tests now so I
> think it'd make sense to make a constant out of it and use it here. That
> way you can even get rid of the comment above it.

 ack

--
Lo...

Read more...

Revision history for this message
Loïc Minier (lool) wrote :

There is definitely a regression with the new branch and the maverick hwpach:
./linaro-media-create --image_size 4G --image_file beagleold.img --dev beagle --rootfs ext4 --hwpack ~/downloads/linaro/10.11/hwpack_linaro-omap3_20101109-1_armel_supported.tar.gz --binary ~/downloads/linaro/11.05/linaro-natty-headless-tar-20110203-1.tar.gz --hwpack-force-yes

with lp:linaro-image-tools:
* qemu-system-arm -M beaglexm -sd beagleold.img -serial stdio: kernel error on boot
* qemu-system-arm -M beagle -sd beagleold.img -serial stdio: boots

with this branch:
* qemu-system-arm -M beaglexm -sd beagleold.img -serial stdio: x-loader error
* qemu-system-arm -M beagle -sd beagleold.img -serial stdio: x-loader error

the x-loader error is:

Texas Instruments X-Loader 1.4.4ss (Sep 30 2010 - 14:44:32)
Beagle xM Rev A
Reading boot sector
Error: reading boot sector
u-boot.bin not found or blank nand contents - attempting serial boot . . .
## Ready for binary (kermit) download to 0x80008000 at 115200 bps...

So technically, we don't care too much about x-loader since it's on the SD card (except on IGEP, but then u-boot is not on SD card either!); in general, I think we would only care when we want to provide u-boot and not x-loader.

It does break our 10.11 images though, not sure what to do about this; what do you think?

Revision history for this message
Guilherme Salgado (salgado) wrote :

IIUC there's just no way we can use 4MiB aligned partitions on 10.11
images, but this whole thing is an optimization anyway, so maybe we can
keep the old alignment as default and add a new argument to l-m-c that
causes the 4MiB alignment to be used. That should be straightforward to
do, no?

Revision history for this message
Loïc Minier (lool) wrote :

I guess; it does seem like non-trivial work to have variable alignment though.

Revision history for this message
Loïc Minier (lool) wrote :

Pushed fixes which address the comments from the review; now need to rework to have variable alignment.

290. By Loïc Minier

Add messages to asserts.

291. By Loïc Minier

Factorize the creation of a relatively common disk tempfile.

Revision history for this message
Loïc Minier (lool) wrote :

I've looked at our linaro-m final hwpacks:
* hwpack_linaro-bsp-omap4_20101109-1_armel_unsupported.tar.gz has pkgs/x-loader-omap4_L24.9git20100901-0ubuntu3_armel.deb
* hwpack_linaro-omap3_20101109-1_armel_supported.tar.gz has pkgs/x-loader-omap_1.4.4git20100713-1ubuntu2_armel.deb
* hwpack_linaro-omap3-x11-base_20101109-1_armel_supported.tar.gz has pkgs/x-loader-omap_1.4.4git20100713-1ubuntu2_armel.deb

vexpress, imx51 and bsp-ux500 don't need any x-loader; igep didn't have one.

Current linaro-m OMAP hwpacks use pkgs/x-loader-omap4-panda_1.4.4+git20110124+7d0e587-1ubuntu0_armel.deb, except IGEP which has no x-loader in the hwpack ATM.

292. By Loïc Minier

Merge with lp:linaro-image-tools to pick up the partition rework changes.
- adjust test_partition_numbering() to create a third partition at +24 MiB
  and to expect the linux part at +16 MiB
- bump tempfile for sfdisk tests to 30M instead of 20M as to fit above test
- adjust linux size in tests per above change

293. By Loïc Minier

Rework sfdisk commands again; completely bypass CHS calculations as they are
irrelevant (see LP #626907 for discussion).
- enforce some sensible sizes of >= 1 MiB, >= 50 MiB, and >= 50 MiB for
  (optional) bootloader partition, boot partition and root partition
  respectively
- document partition layout in get_sfdisk_cmd()
- update testsuite for new values

294. By Loïc Minier

Add tests for align_up and align_partition.

Revision history for this message
Loïc Minier (lool) wrote :

So after realizing that we don't really care about CHS (!), it's indeed not as bad as I thought; I've pushed some revisions to have flexible alignment where we like.

Currently, there is a small duplication of code between mx51 and the default partition layout, but I think I prefer it like this. I think, on the long term, we should have a set of partition layout classes, one per partition layout, and they'd provide the relevant sfdisk commands. Board configs would just have a field saying which layout they want, and we would have no default layout.

The default is to create a bootloader partition at +63s; I think we want to make this omap specific, but that would make code duplication a bit worse (an additional copy for vexpress); I think that's ok, but not urgent anyway.

Finally, there's currently no flag to force 4 MiB alignment of the boot partition on OMAP, but the i.MX5 partitions will always be aligned. I could implement that now, and we would have complete 4 MiB support, but I wonder whether we should just declare that hardware pack v2 implies that your x-loader is good enough and that we can do 4 MiB alignment all the time. Depends how long it takes to get hwpack v2.

295. By Loïc Minier

Add --align-boot-part flag to force (4 MiB) alignment of boot partition.

Revision history for this message
Dave Martin (dave-martin-arm) wrote :

> So after realizing that we don't really care about CHS (!), it's indeed not as
> bad as I thought; I've pushed some revisions to have flexible alignment where
> we like.
>
> Currently, there is a small duplication of code between mx51 and the default
> partition layout, but I think I prefer it like this. I think, on the long
> term, we should have a set of partition layout classes, one per partition
> layout, and they'd provide the relevant sfdisk commands. Board configs would
> just have a field saying which layout they want, and we would have no default
> layout.
>
> The default is to create a bootloader partition at +63s; I think we want to
> make this omap specific, but that would make code duplication a bit worse (an
> additional copy for vexpress); I think that's ok, but not urgent anyway.
>
> Finally, there's currently no flag to force 4 MiB alignment of the boot
> partition on OMAP, but the i.MX5 partitions will always be aligned. I could
> implement that now, and we would have complete 4 MiB support, but I wonder
> whether we should just declare that hardware pack v2 implies that your
> x-loader is good enough and that we can do 4 MiB alignment all the time.
> Depends how long it takes to get hwpack v2.

Doesn't X-loader come out of the FAT filesystem itself? I assume there must be some first-stage boot in ROM or flash which may also mave the restriction on the location of the boot partition.

This appears to be the case on my Beagle xM, because if the boot partition is misaligned I just get a cryptic error string like "60" printed to the UART-- X-loader does not appear to start at all.

That doesn't affect the validity of this patch -- we want need 4-MiB alignment capability regardless -- but we may have to keep the odd alignment for the FAT partition if the on-board boot can't cope with it being somewhere else.

Cheers
---Dave

Revision history for this message
Dave Martin (dave-martin-arm) wrote :

Does it work to use sfdisk -L instead of sfdisk --force?

--force might allow sfdisk to do bad stuff, whereas -L simply turns off sanity checks required for compatibility with silly OSes.

Revision history for this message
Loïc Minier (lool) wrote :

On Fri, Feb 11, 2011, Dave Martin wrote:
> Does it work to use sfdisk -L instead of sfdisk --force?

 I had tried that in earlier versions, but I didn't try with the latest
 one; see my comment in the code about --force for what I was seeing
 back then.

 In any case, it would be nice to add -L and drop -D if possible

--
Loïc Minier

Revision history for this message
Dave Martin (dave-martin-arm) wrote :

> On Fri, Feb 11, 2011, Dave Martin wrote:
> > Does it work to use sfdisk -L instead of sfdisk --force?
>
> I had tried that in earlier versions, but I didn't try with the latest
> one; see my comment in the code about --force for what I was seeing
> back then.
>
> In any case, it would be nice to add -L and drop -D if possible

For me, sfdisk prints warnings without --force but doesn't abort... if so, maybe it would be better not to have --force: using this just to suppress warnings may not be such a good idea.

Why do we have -D? IIUC, either we force the first partition to sector 63, or we force-align it to 4MiB. Either way, we don't trust sfdisk to place partitions for us, so -D probably doesn't do anything(?)

# sfdisk --version
sfdisk (util-linux-ng 2.17.2)

# echo '8192,73728,0xc,*'| sfdisk -S63 -H255 -uS -L /dev/sdg
Checking that no-one is using this disk right now ...
OK

Disk /dev/sdg: 15104 cylinders, 255 heads, 63 sectors/track
Old situation:
Warning: The partition table looks like it was made
  for C/H/S=*/16/32 (instead of 15104/255/63).
For this listing I'll assume that geometry.
Units = sectors of 512 bytes, counting from 0

   Device Boot Start End #sectors Id System
/dev/sdg1 * 8192 81919 73728 c W95 FAT32 (LBA)
/dev/sdg2 0 - 0 0 Empty
/dev/sdg3 0 - 0 0 Empty
/dev/sdg4 0 - 0 0 Empty
New situation:
Warning: The partition table looks like it was made
  for C/H/S=*/26/20 (instead of 15104/255/63).
For this listing I'll assume that geometry.
Units = sectors of 512 bytes, counting from 0

   Device Boot Start End #sectors Id System
/dev/sdg1 * 8192 81919 73728 c W95 FAT32 (LBA)
  start: (c,h,s) expected (15,19,13) found (0,130,3)
  end: (c,h,s) expected (157,13,20) found (5,25,20)
/dev/sdg2 0 - 0 0 Empty
/dev/sdg3 0 - 0 0 Empty
/dev/sdg4 0 - 0 0 Empty
Warning: partition 1 does not end at a cylinder boundary
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)

Revision history for this message
Loïc Minier (lool) wrote :

So I did another series of test on top of r295 with commands like:
./linaro-media-create --image_file /tmp/beagle.img --dev beagle --rootfs ext4 --hwpack ~/downloads/linaro/11.05/hwpack_linaro-omap3_20110208-0_armel_supported.tar.gz --binary ~/downloads/linaro/11.05/linaro-natty-headless-tar-20110203-1.tar.gz --hwpack-force-yes --align-boot-part

* --dev beagle, --image_file, --hwpack from maverick: boots under QEMU (only beagle, not beaglexm), does not boot on beagle-xM (no output, I guess x-loader doesn't support it), /!\ boots on beagle but seems to use NAND x-loader
* --dev beagle, --image_file, --hwpack from natty: boots under QEMU (beagle and beaglexm), /!\ does not boot no beagle-xM (no output, no idea what's going on), /!\ boots on beagle but seems to use NAND x-loader
* --dev beagle, --image_file, --hwpack from maverick, --align-boot-part: does not boot under QEMU (whatever the machine)
* --dev beagle, --image_file, --hwpack from natty, --align-boot-part: boots under QEMU (whatever the machine, no serial on beaglexm), /!\ does NOT boot under beagle (pressing user button across resets, it still boots from NAND), nor beagle-xM (no output)

I am starting to suspect broken micro SD or something as it's not consistent at all.

Revision history for this message
Loïc Minier (lool) wrote :

Fail with different SD, different SD reader and with:
./linaro-media-create --mmc /dev/sdd --dev overo --rootfs btrfs --hwpack ~/downloads/linaro/11.05/hwpack_linaro-overo_20110211-1_armel_supported.tar.gz --binary ~/downloads/linaro/11.05/linaro-natty-headless-tar-20110203-1.tar.gz --hwpack-force-yes

no output on Overo

Revision history for this message
Loïc Minier (lool) wrote :

Dave had an interesting idea: maybe the odd lengths for the boot vfat break it; we indeed discovered that on both beaglexm and overo, creating partitions of even length at sector 63 works and of odd length doesn't! on xm we get some "6" characater on the console

I tested with this:
size=80256; sudo dd if=/dev/zero of=/dev/sdb count=10 bs=1M; sudo parted -s /dev/sdb mklabel msdos; echo "63,$size,0x0C,*" | LC_ALL=C sudo sfdisk -L -uS -H 255 -S 63 /dev/sdb; sudo mkfs.vfat -F32 /dev/sdb1; loop-mnt-do /dev/sdb1 sudo cp -v /home/lool/MLO .; sync

296. By Loïc Minier

Make sure boot partition has an even length in sectors (partition length is an
entire number of KiBs) to please OMAP3 ROMs; these apparently don't care for
the start sector, but do care for the length of the partition... Update
comments as well.

Revision history for this message
Loïc Minier (lool) wrote :

With r296, which ensures that boot partition has an even number of sectors:

linaro-n, --mmc, beagle
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=30
./linaro-media-create --mmc /dev/sdb --dev beagle --rootfs btrfs --hwpack ~/Bureau/hwpack_linaro-omap3_20110211-0_armel_supported.tar.gz --binary ~/downloads/linaro/11.05/linaro-natty-headless-tar-20110203-1.tar.gz --hwpack-force-yes

=> works on beagle and on beagle xM!

linaro-n, --mmc, overo
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=30
./linaro-media-create --mmc /dev/sdb --dev overo --rootfs btrfs --hwpack ~/downloads/linaro/11.05/hwpack_linaro-overo_20110211-1_armel_supported.tar.gz --binary ~/Bureau/linaro-natty-headless-tar-20110211-3.tar.gz --hwpack-force-yes

=> works on overo (up to not finding fsck.btrfs :-)! also starts within qemu -M beagle and -M beaglexm, including Linux (and then crashes, since it can't emulate overo)

linaro-n, --mmc, beagle, +4MiB boot
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=30
./linaro-media-create --mmc /dev/sdb --dev beagle --rootfs btrfs --hwpack ~/Bureau/hwpack_linaro-omap3_20110211-0_armel_supported.tar.gz --binary ~/downloads/linaro/11.05/linaro-natty-headless-tar-20110203-1.tar.gz --hwpack-force-yes --align-boot-part

=> works on beagle and on beagle xM!

linaro-n, --mmc, overo, +4MiB boot
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=30
./linaro-media-create --mmc /dev/sdb --dev overo --rootfs btrfs --hwpack ~/downloads/linaro/11.05/hwpack_linaro-overo_20110211-1_armel_supported.tar.gz --binary ~/Bureau/linaro-natty-headless-tar-20110211-3.tar.gz --hwpack-force-yes --align-boot-part

=> works on overo! also starts within sudo qemu -M beagle and -M beaglexm, including Linux (and then crashes, since it can't emulate overo)

linaro-m, --mmc, beagle
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=30
./linaro-media-create --mmc /dev/sdb --dev beagle --rootfs btrfs --hwpack ~/downloads/linaro/10.11/hwpack_linaro-omap3_20101109-1_armel_supported.tar.gz --binary ~/downloads/linaro/10.11/linaro-m-headless-tar-20101108-2.tar.gz --hwpack-force-yes

=> works on beagle and beagle xM! also starts within sudo qemu -M beagle and -M beaglexm, including Linux (and then crashes since linaro-m didn't support xM)

Revision history for this message
Loïc Minier (lool) wrote :

On Fri, Feb 11, 2011, Dave Martin wrote:
> For me, sfdisk prints warnings without --force but doesn't abort... if
> so, maybe it would be better not to have --force: using this just to
> suppress warnings may not be such a good idea.

 Problem is not the warnings, but the error code: if it's non-zero we
 abort l-m-c.

> Why do we have -D?

 Not sure; didn't add it, but I'd like to remove it too

--
Loïc Minier

Revision history for this message
Guilherme Salgado (salgado) wrote :
Download full text (7.4 KiB)

Hi Loïc,

Thanks for working on this and for the cleanup in tests. I see a few
things that could be improved but overall it looks good.

> === modified file 'linaro_media_create/boards.py'
> --- linaro_media_create/boards.py 2011-02-10 16:58:11 +0000
> +++ linaro_media_create/boards.py 2011-02-11 20:17:14 +0000
> @@ -31,6 +31,44 @@
> import tempfile
>
> from linaro_media_create import cmd_runner
> +from linaro_media_create.partitions import SECTOR_SIZE
> +
> +# Notes:
> +# * geometry is currently always 255 heads and 63 sectors due to limitations of
> +# older OMAP3 boot ROMs
> +# * apparently some OMAP3 ROMs don't tolerate vfat length of an odd number of
> +# sectors (only sizes rounded to 1 KiB seem to boot)
> +# * we want partitions aligned on 4 MiB as to get the best performance and
> +# limit wear-leveling
> +# * image_size is passed on the command-line and should preferably be a power
> +# of 2; it should be used as a "don't go over this size" information for a
> +# real device, and a "give me a file exactly this big" requirement for an
> +# image file. Having exactly a power of 2 helps with QEMU; there seem to be
> +# some truncating issues otherwise. XXX to be researched
> +
> +# align on 4 MiB
> +PART_ALIGN_S = 4 * 1024 * 1024 / SECTOR_SIZE
> +
> +align_up = lambda x, a: (x + a - 1) / a * a

I think it'd be nicer to write this as a regular function instead of
defining an anonymous function and then giving it a name

> +
> +# optional bootloader partition; at least 1 MiB; in theory, an i.MX5 bootloader
> +# partition could hold RedBoot, FIS table, RedBoot config, kernel, and initrd,
> +# but we typically use U-Boot which is about 167 KiB as of 2011/02/11 and
> +# currently doesn't even store its environment there, so this should be enough
> +LOADER_MIN_SIZE_S = align_up(1 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
> +# boot partition; at least 50 MiB; XXX this shouldn't be hardcoded
> +BOOT_MIN_SIZE_S = align_up(50 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
> +# root partition; at least 50 MiB; XXX this shouldn't be hardcoded
> +ROOT_MIN_SIZE_S = align_up(50 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
> +
> +
> +def align_partition(min_start, min_length, start_alignment, end_alignment):

Care to add a docstring to this function?

> + start = align_up(min_start, start_alignment)
> + # end offset is inclusive, so substact one
> + end = align_up(start + min_length, end_alignment) - 1
> + # and add one to length
> + length = end - start + 1
> + return start, end, length
>
>
> class BoardConfig(object):
> @@ -53,17 +91,41 @@
> serial_tty = None
>
> @classmethod
> - def get_sfdisk_cmd(cls):
> - """Return the sfdisk command to partition the media."""
> + def get_sfdisk_cmd(cls, should_align_boot_part=False):
> + """Return the sfdisk command to partition the media.
> +
> + :param should_align_boot_part: Whether to align the boot partition too.
> +
> + This default implementation returns a boot vfat partition of type FAT16
> + or FAT32, followed by a root partition."""
> +
> if cls.fat_size == 32:
> partition_type = '0x0C'
> ...

Read more...

Revision history for this message
Guilherme Salgado (salgado) :
review: Approve
297. By Loïc Minier

Convert align_up to a real function and add docstrings to align_partition()
and align_up().

298. By Loïc Minier

Closing triple double-quotes need to stand on their own line.

299. By Loïc Minier

Fix typos in comments.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-media-create'
2--- linaro-media-create 2011-02-02 17:32:10 +0000
3+++ linaro-media-create 2011-02-14 16:29:48 +0000
4@@ -130,7 +130,7 @@
5 boot_partition, root_partition = setup_partitions(
6 board_config, media, args.image_size, args.boot_label, args.rfs_label,
7 args.rootfs, args.should_create_partitions, args.should_format_bootfs,
8- args.should_format_rootfs)
9+ args.should_format_rootfs, args.should_align_boot_part)
10
11 rootfs_uuid = get_uuid(root_partition)
12
13
14=== modified file 'linaro_media_create/__init__.py'
15--- linaro_media_create/__init__.py 2011-02-10 16:58:11 +0000
16+++ linaro_media_create/__init__.py 2011-02-14 16:29:48 +0000
17@@ -105,4 +105,8 @@
18 parser.add_argument(
19 '--no-part', dest='should_create_partitions', action='store_false',
20 help='Reuse existing partitions on the given media.')
21+ parser.add_argument(
22+ '--align-boot-part', dest='should_align_boot_part',
23+ action='store_true',
24+ help='Align boot partition too (might break older x-loaders).')
25 return parser
26
27=== modified file 'linaro_media_create/boards.py'
28--- linaro_media_create/boards.py 2011-02-10 16:58:11 +0000
29+++ linaro_media_create/boards.py 2011-02-14 16:29:48 +0000
30@@ -31,6 +31,54 @@
31 import tempfile
32
33 from linaro_media_create import cmd_runner
34+from linaro_media_create.partitions import SECTOR_SIZE
35+
36+# Notes:
37+# * geometry is currently always 255 heads and 63 sectors due to limitations of
38+# older OMAP3 boot ROMs
39+# * apparently some OMAP3 ROMs don't tolerate vfat length of an odd number of
40+# sectors (only sizes rounded to 1 KiB seem to boot)
41+# * we want partitions aligned on 4 MiB as to get the best performance and
42+# limit wear-leveling
43+# * image_size is passed on the command-line and should preferably be a power
44+# of 2; it should be used as a "don't go over this size" information for a
45+# real device, and a "give me a file exactly this big" requirement for an
46+# image file. Having exactly a power of 2 helps with QEMU; there seem to be
47+# some truncating issues otherwise. XXX to be researched
48+
49+# align on 4 MiB
50+PART_ALIGN_S = 4 * 1024 * 1024 / SECTOR_SIZE
51+
52+def align_up(value, align):
53+ """Round value to the next multiple of align."""
54+ return (value + align - 1) / align * align
55+
56+# optional bootloader partition; at least 1 MiB; in theory, an i.MX5 bootloader
57+# partition could hold RedBoot, FIS table, RedBoot config, kernel, and initrd,
58+# but we typically use U-Boot which is about 167 KiB as of 2011/02/11 and
59+# currently doesn't even store its environment there, so this should be enough
60+LOADER_MIN_SIZE_S = align_up(1 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
61+# boot partition; at least 50 MiB; XXX this shouldn't be hardcoded
62+BOOT_MIN_SIZE_S = align_up(50 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
63+# root partition; at least 50 MiB; XXX this shouldn't be hardcoded
64+ROOT_MIN_SIZE_S = align_up(50 * 1024 * 1024, SECTOR_SIZE) / SECTOR_SIZE
65+
66+
67+def align_partition(min_start, min_length, start_alignment, end_alignment):
68+ """Compute partition start and end offsets based on specified constraints.
69+
70+ :param min_start: Minimal start offset of partition
71+ :param min_lengh: Minimal length of partition
72+ :param start_alignment: Alignment of this partition
73+ :param end_alignment: Alignment of the data following this partition
74+ :return: start offset, end offset (inclusive), length
75+ """
76+ start = align_up(min_start, start_alignment)
77+ # end offset is inclusive, so substact one
78+ end = align_up(start + min_length, end_alignment) - 1
79+ # and add one to length
80+ length = end - start + 1
81+ return start, end, length
82
83
84 class BoardConfig(object):
85@@ -53,17 +101,41 @@
86 serial_tty = None
87
88 @classmethod
89- def get_sfdisk_cmd(cls):
90- """Return the sfdisk command to partition the media."""
91+ def get_sfdisk_cmd(cls, should_align_boot_part=False):
92+ """Return the sfdisk command to partition the media.
93+
94+ :param should_align_boot_part: Whether to align the boot partition too.
95+
96+ This default implementation returns a boot vfat partition of type FAT16
97+ or FAT32, followed by a root partition.
98+ """
99 if cls.fat_size == 32:
100 partition_type = '0x0C'
101 else:
102 partition_type = '0x0E'
103
104- # This will create a partition of the given type, containing 9
105- # cylinders (74027520 bytes, ~70 MiB), followed by a Linux-type
106- # partition containing the rest of the free space.
107- return ',9,%s,*\n,,,-' % partition_type
108+ # align on sector 63 for compatibility with broken versions of x-loader
109+ # unless align_boot_part is set
110+ boot_align = 63
111+ if should_align_boot_part:
112+ boot_align = PART_ALIGN_S
113+
114+ # can only start on sector 1 (sector 0 is MBR / partition table)
115+ boot_start, boot_end, boot_len = align_partition(
116+ 1, BOOT_MIN_SIZE_S, boot_align, PART_ALIGN_S)
117+ # apparently OMAP3 ROMs require the vfat length to be an even number
118+ # of sectors (multiple of 1 KiB); decrease the length if it's odd,
119+ # there should still be enough room
120+ boot_len = boot_len - boot_len % 2
121+ boot_end = boot_start + boot_len - 1
122+ # we ignore _root_end / _root_len and return a sfdisk command to
123+ # instruct the use of all remaining space; XXX if we had some root size
124+ # config, we could do something more sensible
125+ root_start, _root_end, _root_len = align_partition(
126+ boot_end + 1, ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
127+
128+ return '%s,%s,%s,*\n%s,,,-' % (
129+ boot_start, boot_len, partition_type, root_start)
130
131 @classmethod
132 def _get_boot_cmd(cls, is_live, is_lowmem, consoles, rootfs_uuid):
133@@ -287,12 +359,32 @@
134 mmc_option = '0:2'
135
136 @classmethod
137- def get_sfdisk_cmd(cls):
138- # Create a one cylinder partition for fixed-offset bootloader data at
139- # the beginning of the image (size is one cylinder, so 8224768 bytes
140- # with the first sector for MBR).
141- sfdisk_cmd = super(Mx51evkConfig, cls).get_sfdisk_cmd()
142- return ',1,0xDA\n%s' % sfdisk_cmd
143+ def get_sfdisk_cmd(cls, should_align_boot_part=None):
144+ """Return the sfdisk command to partition the media.
145+
146+ :param should_align_boot_part: Ignored.
147+
148+ This i.MX5 implementation returns a non-FS data bootloader partition,
149+ followed by a FAT32 boot partition, followed by a root partition.
150+ """
151+ # boot ROM expects bootloader at 0x400 which is sector 2 with the usual
152+ # SECTOR_SIZE of 512; we could theoretically leave sector 1 unused, but
153+ # older bootloaders like RedBoot might store the environment from 0x0
154+ # onwards, so it's safer to just start at the first sector, sector 1
155+ # (sector 0 is MBR / partition table)
156+ loader_start, loader_end, loader_len = align_partition(
157+ 1, LOADER_MIN_SIZE_S, 1, PART_ALIGN_S)
158+
159+ boot_start, boot_end, boot_len = align_partition(
160+ loader_end + 1, BOOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
161+ # we ignore _root_end / _root_len and return a sfdisk command to
162+ # instruct the use of all remaining space; XXX if we had some root size
163+ # config, we could do something more sensible
164+ root_start, _root_end, _root_len = align_partition(
165+ boot_end + 1, ROOT_MIN_SIZE_S, PART_ALIGN_S, PART_ALIGN_S)
166+
167+ return '%s,%s,0xDA\n%s,%s,0x0C,*\n%s,,,-' % (
168+ loader_start, loader_len, boot_start, boot_len, root_start)
169
170 @classmethod
171 def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir,
172
173=== modified file 'linaro_media_create/partitions.py'
174--- linaro_media_create/partitions.py 2011-02-10 17:16:48 +0000
175+++ linaro_media_create/partitions.py 2011-02-14 16:29:48 +0000
176@@ -47,15 +47,24 @@
177 # might want to do it.
178 def setup_partitions(board_config, media, image_size, bootfs_label,
179 rootfs_label, rootfs_type, should_create_partitions,
180- should_format_bootfs, should_format_rootfs):
181+ should_format_bootfs, should_format_rootfs,
182+ should_align_boot_part=False):
183 """Make sure the given device is partitioned to boot the given board.
184
185 :param board_config: A BoardConfig class.
186 :param media: The Media we should partition.
187 :param image_size: The size of the image file, in case we're setting up a
188 QEMU image.
189+ :param bootfs_label: Label for the boot partition.
190+ :param rootfs_label: Label for the root partition.
191+ :param rootfs_type: Filesystem for the root partition.
192 :param should_create_partitions: Whether or not we should erase existing
193 partitions and create new ones.
194+ :param should_format_bootfs: Whether to reuse the filesystem on the boot
195+ partition.
196+ :param should_format_rootfs: Whether to reuse the filesystem on the root
197+ partition.
198+ :param should_align_boot_part: Whether to align the boot partition too.
199 """
200 cylinders = None
201 if not media.is_block_device:
202@@ -69,7 +78,8 @@
203
204 if should_create_partitions:
205 create_partitions(
206- board_config, media, HEADS, SECTORS, cylinders)
207+ board_config, media, HEADS, SECTORS, cylinders,
208+ should_align_boot_part=should_align_boot_part)
209
210 if media.is_block_device:
211 bootfs, rootfs = get_boot_and_root_partitions_for_media(
212@@ -264,17 +274,6 @@
213 raise ValueError("Unknown size format: %s. Use K[bytes], M[bytes] "
214 "or G[bytes]" % size)
215
216- # Round the size of the raw disk image up to a multiple of 256K so it is
217- # an exact number of SD card erase blocks in length. Otherwise Linux
218- # under qemu cannot access the last part of the card and is likely to
219- # complain that the last partition on the disk has been truncated. This
220- # doesn't appear to work in all cases, though, as can be seen on
221- # https://bugs.launchpad.net/linux-linaro/+bug/673335.
222- if real_size % (1024 * 256):
223- cylinders = real_size / CYLINDER_SIZE
224- real_size = cylinders * CYLINDER_SIZE
225- real_size = ((((real_size - 1) / (1024 * 256)) + 1) * (1024 * 256))
226-
227 return real_size
228
229
230@@ -289,8 +288,13 @@
231 :param commands: A string of sfdisk commands; each on a separate line.
232 :return: A 2-tuple containing the subprocess' stdout and stderr.
233 """
234+ # --force is unfortunate, but a consequence of having partitions not
235+ # starting on cylinder boundaries: sfdisk will abort with "Warning:
236+ # partition 2 does not start at a cylinder boundary"
237 args = ['sfdisk',
238+ '--force',
239 '-D',
240+ '-uS',
241 '-H', str(heads),
242 '-S', str(sectors)]
243 if cylinders is not None:
244@@ -302,7 +306,8 @@
245 return proc.communicate("%s\n" % commands)
246
247
248-def create_partitions(board_config, media, heads, sectors, cylinders=None):
249+def create_partitions(board_config, media, heads, sectors, cylinders=None,
250+ should_align_boot_part=False):
251 """Partition the given media according to the board requirements.
252
253 :param board_config: A BoardConfig class.
254@@ -313,6 +318,7 @@
255 partitions.
256 :param cylinders: The number of cylinders to pass to sfdisk's -C argument.
257 If None the -C argument is not passed.
258+ :param should_align_boot_part: Whether to align the boot partition too.
259 """
260 if media.is_block_device:
261 # Overwrite any existing partition tables with a fresh one.
262@@ -320,7 +326,8 @@
263 ['parted', '-s', media.path, 'mklabel', 'msdos'], as_root=True)
264 proc.wait()
265
266- sfdisk_cmd = board_config.get_sfdisk_cmd()
267+ sfdisk_cmd = board_config.get_sfdisk_cmd(
268+ should_align_boot_part=should_align_boot_part)
269 run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path)
270
271 # Sync and sleep to wait for the partition to settle.
272
273=== modified file 'linaro_media_create/tests/test_media_create.py'
274--- linaro_media_create/tests/test_media_create.py 2011-02-10 19:08:06 +0000
275+++ linaro_media_create/tests/test_media_create.py 2011-02-14 16:29:48 +0000
276@@ -43,6 +43,8 @@
277 )
278 import linaro_media_create
279 from linaro_media_create.boards import (
280+ align_up,
281+ align_partition,
282 BoardConfig,
283 board_configs,
284 make_boot_script,
285@@ -283,6 +285,27 @@
286 self.assertEqual(expected, self.funcs_calls)
287
288
289+class TestAlignPartition(TestCase):
290+ def test_align_up_none(self):
291+ self.assertEqual(1024, align_up(1024, 1))
292+
293+ def test_align_up_no_rounding(self):
294+ self.assertEqual(512, align_up(512, 512))
295+
296+ def test_align_up_rounding(self):
297+ self.assertEqual(512, align_up(1, 512))
298+
299+ def test_align_partition_4_mib_4_mib(self):
300+ expected = (4 * 1024 * 1024, 8 * 1024 * 1024 - 1, 4 * 1024 * 1024)
301+ self.assertEqual(expected,
302+ align_partition(1, 1, 4 * 1024 * 1024, 4 * 1024 * 1024))
303+
304+ def test_align_partition_none_4_mib(self):
305+ expected = (1, 4 * 1024 * 1024 - 1, 4 * 1024 * 1024 - 1)
306+ self.assertEqual(expected,
307+ align_partition(1, 1, 1, 4 * 1024 * 1024))
308+
309+
310 class TestFixForBug697824(TestCaseWithFixtures):
311
312 def mock_set_appropriate_serial_tty(self, config):
313@@ -331,12 +354,18 @@
314 class TestGetSfdiskCmd(TestCase):
315
316 def test_default(self):
317- self.assertEquals(
318- ',9,0x0C,*\n,,,-', boards.BoardConfig.get_sfdisk_cmd())
319+ self.assertEqual(
320+ '63,106432,0x0C,*\n106496,,,-',
321+ boards.BoardConfig.get_sfdisk_cmd())
322+
323+ def test_default_aligned(self):
324+ self.assertEqual(
325+ '8192,106496,0x0C,*\n114688,,,-',
326+ boards.BoardConfig.get_sfdisk_cmd(should_align_boot_part=True))
327
328 def test_mx51evk(self):
329- self.assertEquals(
330- ',1,0xDA\n,9,0x0C,*\n,,,-',
331+ self.assertEqual(
332+ '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
333 board_configs['mx51evk'].get_sfdisk_cmd())
334
335
336@@ -633,7 +662,7 @@
337 # every time we run sfdisk it actually repartitions the device,
338 # erasing any partitions created previously.
339 self.assertEqual(
340- [(',1,0xDA\n,9,0x0C,*\n,,,-', 255, 63, '', self.media.path)],
341+ [('1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-', 255, 63, '', self.media.path)],
342 sfdisk_fixture.mock.calls)
343
344 def test_create_partitions_for_beagle(self):
345@@ -648,7 +677,7 @@
346 ['sync']],
347 popen_fixture.mock.calls)
348 self.assertEqual(
349- [(',9,0x0C,*\n,,,-', 255, 63, '', self.media.path)],
350+ [('63,106432,0x0C,*\n106496,,,-', 255, 63, '', self.media.path)],
351 sfdisk_fixture.mock.calls)
352
353 def test_create_partitions_with_img_file(self):
354@@ -665,7 +694,7 @@
355 self.assertEqual([['sync']], popen_fixture.mock.calls)
356
357 self.assertEqual(
358- [(',9,0x0C,*\n,,,-', 255, 63, '', tempfile)],
359+ [('63,106432,0x0C,*\n106496,,,-', 255, 63, '', tempfile)],
360 sfdisk_fixture.mock.calls)
361
362 def test_run_sfdisk_commands(self):
363@@ -675,7 +704,7 @@
364 stdout=subprocess.PIPE)
365 proc.communicate()
366 stdout, stderr = run_sfdisk_commands(
367- ',1,0xDA', 5, 63, '', tempfile, as_root=False,
368+ '2,16063,0xDA', 255, 63, '', tempfile, as_root=False,
369 stderr=subprocess.PIPE)
370 self.assertIn('Successfully wrote the new partition table', stdout)
371
372@@ -684,7 +713,7 @@
373 self.assertRaises(
374 cmd_runner.SubcommandNonZeroReturnValue,
375 run_sfdisk_commands,
376- ',1,0xDA', 5, 63, '', tempfile, as_root=False,
377+ ',1,0xDA', 255, 63, '', tempfile, as_root=False,
378 stderr=subprocess.PIPE)
379
380
381@@ -700,6 +729,11 @@
382 super(TestPartitionSetup, self).tearDown()
383 time.sleep = self.orig_sleep
384
385+ def _create_tempfile(self):
386+ # boot part at +8 MiB, root part at +16 MiB
387+ return self._create_qemu_img_with_partitions(
388+ '16384,15746,0x0C,*\n32768,,,-')
389+
390 def test_convert_size_in_kbytes_to_bytes(self):
391 self.assertEqual(512 * 1024, convert_size_to_bytes('512K'))
392
393@@ -709,28 +743,23 @@
394 def test_convert_size_in_gbytes_to_bytes(self):
395 self.assertEqual(12 * 1024**3, convert_size_to_bytes('12G'))
396
397- def test_convert_size_in_kbytes_to_bytes_rounds_to_256k_multiple(self):
398- # See comment in convert_size_to_bytes as to why we need to do this.
399- self.assertEqual(
400- 3891 * (1024 * 256), convert_size_to_bytes('1000537K'))
401-
402 def test_calculate_partition_size_and_offset(self):
403- tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-')
404+ tempfile = self._create_tempfile()
405 vfat_size, vfat_offset, linux_size, linux_offset = (
406 calculate_partition_size_and_offset(tempfile))
407 self.assertEqual(
408- [129024L, 32256L, 10321920L, 161280L],
409+ [8061952L, 8388608L, 14680064L, 16777216L],
410 [vfat_size, vfat_offset, linux_size, linux_offset])
411
412 def test_partition_numbering(self):
413- # another Linux partition after the boot/root parts
414+ # another Linux partition at +24 MiB after the boot/root parts
415 tempfile = self._create_qemu_img_with_partitions(
416- ',1,0x0C,*\n,1,,-\n,,,-')
417+ '16384,15746,0x0C,*\n32768,15427,,-\n49152,,,-')
418 vfat_size, vfat_offset, linux_size, linux_offset = (
419 calculate_partition_size_and_offset(tempfile))
420- # check that the linux partition offset starts on second cylinder so
421- # that it's the partition immediately following the vfat one
422- self.assertEqual(linux_offset, 5 * 63 * 512)
423+ # check that the linux partition offset starts at +16 MiB so that it's
424+ # the partition immediately following the vfat one
425+ self.assertEqual(linux_offset, 32768 * 512)
426
427 def test_get_boot_and_root_partitions_for_media_beagle(self):
428 self.useFixture(MockSomethingFixture(
429@@ -759,11 +788,11 @@
430 def _create_qemu_img_with_partitions(self, sfdisk_commands):
431 tempfile = self.createTempFileAsFixture()
432 proc = cmd_runner.run(
433- ['qemu-img', 'create', '-f', 'raw', tempfile, '10M'],
434+ ['qemu-img', 'create', '-f', 'raw', tempfile, '30M'],
435 stdout=subprocess.PIPE)
436 proc.communicate()
437 stdout, stderr = run_sfdisk_commands(
438- sfdisk_commands, 5, 63, '', tempfile, as_root=False,
439+ sfdisk_commands, 255, 63, '', tempfile, as_root=False,
440 # Throw away stderr as sfdisk complains a lot when operating on a
441 # qemu image.
442 stderr=subprocess.PIPE)
443@@ -786,7 +815,7 @@
444 self.assertEqual(None, popen_fixture.mock.calls)
445
446 def test_get_boot_and_root_loopback_devices(self):
447- tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-')
448+ tempfile = self._create_tempfile()
449 atexit_fixture = self.useFixture(MockSomethingFixture(
450 atexit, 'register', AtExitRegister()))
451 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
452@@ -796,9 +825,9 @@
453 get_boot_and_root_loopback_devices(tempfile)
454 self.assertEqual(
455 [['sudo', 'losetup', '-f', '--show', tempfile, '--offset',
456- '32256', '--sizelimit', '129024'],
457+ '8388608', '--sizelimit', '8061952'],
458 ['sudo', 'losetup', '-f', '--show', tempfile, '--offset',
459- '161280', '--sizelimit', '10321920']],
460+ '16777216', '--sizelimit', '14680064']],
461 popen_fixture.mock.calls)
462
463 # get_boot_and_root_loopback_devices will also setup two exit handlers
464@@ -818,7 +847,7 @@
465 # but here we mock Popen() and thanks to that the image is not setup
466 # (via qemu-img) inside setup_partitions. That's why we pass an
467 # already setup image file.
468- tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-')
469+ tempfile = self._create_tempfile()
470 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
471 self.useFixture(MockSomethingFixture(
472 sys, 'stdout', open('/dev/null', 'w')))
473@@ -838,11 +867,11 @@
474 board_configs['beagle'], Media(tempfile), '2G', 'boot',
475 'root', 'ext3', True, True, True)
476 self.assertEqual(
477- # This is the call that would create the image file.
478+ # This is the call that would create a 2 GiB image file.
479 [['qemu-img', 'create', '-f', 'raw', tempfile, '2147483648'],
480 # This call would partition the image file.
481- ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', '-C', '261',
482- tempfile],
483+ ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S',
484+ '63', '-C', '261', tempfile],
485 # Make sure changes are written to disk.
486 ['sync'],
487 ['sudo', 'mkfs.vfat', '-F', '32', bootfs_dev, '-n', 'boot'],
488@@ -855,7 +884,7 @@
489 # Pretend the partitions are mounted.
490 self.useFixture(MockSomethingFixture(
491 partitions, 'is_partition_mounted', lambda part: True))
492- tempfile = self._create_qemu_img_with_partitions(',1,0x0C,*\n,,,-')
493+ tempfile = self._create_tempfile()
494 self.useFixture(MockSomethingFixture(
495 partitions, '_get_device_file_for_partition_number',
496 lambda dev, partition: '%s%d' % (tempfile, partition)))
497@@ -868,7 +897,8 @@
498 True, True, True)
499 self.assertEqual(
500 [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'],
501- ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile],
502+ ['sudo', 'sfdisk', '--force', '-D', '-uS', '-H', '255', '-S',
503+ '63', tempfile],
504 ['sync'],
505 # Since the partitions are mounted, setup_partitions will umount
506 # them before running mkfs.

Subscribers

People subscribed via source and target branches