From 0b156dac83258a2789f21038216e43aacc91555a Mon Sep 17 00:00:00 2001 From: Alexandre Belloni Date: Sun, 8 Feb 2015 23:52:00 +0100 Subject: wic: allow creation of partitions not in table For some architectures it is necessary to reserve space on disk without it being present in the partition table. For example, u-boot on i.mx is placed at an offset of 1kB on the sdcard. While it would be possible to create a partition at that offset and place u-boot there, it would then be necessary to update the default u-boot environment to use partition 2 on the mmc instead of partition 1. (From OE-Core rev: 233b631ece5ee14d057932c146327065064b5196) Signed-off-by: Alexandre Belloni Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- scripts/lib/wic/imager/direct.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'scripts/lib/wic/imager/direct.py') diff --git a/scripts/lib/wic/imager/direct.py b/scripts/lib/wic/imager/direct.py index b1dc3e96f4..38d4e78e62 100644 --- a/scripts/lib/wic/imager/direct.py +++ b/scripts/lib/wic/imager/direct.py @@ -74,6 +74,22 @@ class DirectImageCreator(BaseImageCreator): self.kernel_dir = kernel_dir self.native_sysroot = native_sysroot + def __get_part_num(self, num, parts): + """calculate the real partition number, accounting for partitions not + in the partition table and logical partitions + """ + realnum = 0 + for n, p in enumerate(parts, 1): + if not p.no_table: + realnum += 1 + if n == num: + if p.no_table: + return 0 + if self._ptable_format == 'msdos' and realnum > 3: + # account for logical partition numbering, ex. sda5.. + return realnum + 1 + return realnum + def __write_fstab(self, image_rootfs): """overriden to generate fstab (temporarily) in rootfs. This is called from _create, make sure it doesn't get called from @@ -98,7 +114,8 @@ class DirectImageCreator(BaseImageCreator): def _update_fstab(self, fstab_lines, parts): """Assume partition order same as in wks""" for num, p in enumerate(parts, 1): - if not p.mountpoint or p.mountpoint == "/" or p.mountpoint == "/boot": + pnum = self.__get_part_num(num, parts) + if not p.mountpoint or p.mountpoint == "/" or p.mountpoint == "/boot" or pnum == 0: continue part = '' @@ -106,11 +123,6 @@ class DirectImageCreator(BaseImageCreator): if p.disk.startswith('mmcblk'): part = 'p' - pnum = num - if self._ptable_format == 'msdos' and pnum > 3: - # account for logical partition numbering, ex. sda5.. - pnum += 1 - device_name = "/dev/" + p.disk + part + str(pnum) opts = "defaults" @@ -262,6 +274,7 @@ class DirectImageCreator(BaseImageCreator): fsopts = p.fsopts, boot = p.active, align = p.align, + no_table = p.no_table, part_type = p.part_type) self.__image.layout_partitions(self._ptable_format) @@ -350,10 +363,8 @@ class DirectImageCreator(BaseImageCreator): if p.disk.startswith('mmcblk'): part = 'p' - if self._ptable_format == 'msdos' and num > 3: - rootdev = "/dev/%s%s%-d" % (p.disk, part, num + 1) - else: - rootdev = "/dev/%s%s%-d" % (p.disk, part, num) + pnum = self.__get_part_num(num, parts) + rootdev = "/dev/%s%s%-d" % (p.disk, part, pnum) root_part_uuid = p.part_type return (rootdev, root_part_uuid) -- cgit v1.2.3-54-g00ecf