From patchwork Mon Oct 28 03:46:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vince Chang X-Patchwork-Id: 51390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E42FBD13595 for ; Mon, 28 Oct 2024 03:46:27 +0000 (UTC) Received: from TWMBX01.aspeed.com (TWMBX01.aspeed.com [211.20.114.72]) by mx.groups.io with SMTP id smtpd.web10.43841.1730087180638284109 for ; Sun, 27 Oct 2024 20:46:21 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: aspeedtech.com, ip: 211.20.114.72, mailfrom: vince_chang@aspeedtech.com) Received: from TWMBX01.aspeed.com (192.168.0.62) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 28 Oct 2024 11:46:18 +0800 Received: from localhost.localdomain (192.168.10.10) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Mon, 28 Oct 2024 11:46:18 +0800 From: Vince Chang To: CC: , Subject: [PATCH v2 1/2] wic: add WIC_SECTOR_SIZE variable Date: Mon, 28 Oct 2024 11:46:17 +0800 Message-ID: <20241028034618.1504830-2-vince_chang@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241028034618.1504830-1-vince_chang@aspeedtech.com> References: <20241028034618.1504830-1-vince_chang@aspeedtech.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 28 Oct 2024 03:46:27 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/206418 Currently WIC is unable to generate images that requires a sector size different of 512. Add WIC_SECTOR_SIZE variable to handle the sector size of 4096 for UFS. For "wic ls" command modify get_partitions() to support WIC_SECTOR_SIZE. Signed-off-by: Vince Chang --- scripts/lib/wic/engine.py | 18 +++++++- scripts/lib/wic/plugins/imager/direct.py | 56 ++++++++++++++---------- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index ce7e6c5d75..64b1d52882 100644 --- a/scripts/lib/wic/engine.py +++ b/scripts/lib/wic/engine.py @@ -232,6 +232,16 @@ class Disk: self._psector_size = None self._ptable_format = None + # define sector size + sector_size_str = get_bitbake_var('WIC_SECTOR_SIZE') + if sector_size_str is not None: + try: + self.sector_size = int(sector_size_str) + except ValueError: + self.sector_size = None + else: + self.sector_size = None + # find parted # read paths from $PATH environment variable # if it fails, use hardcoded paths @@ -258,7 +268,13 @@ class Disk: def get_partitions(self): if self._partitions is None: self._partitions = OrderedDict() - out = exec_cmd("%s -sm %s unit B print" % (self.parted, self.imagepath)) + + if self.sector_size is not None: + out = exec_cmd("export PARTED_SECTOR_SIZE=%d; %s -sm %s unit B print" % \ + (self.sector_size, self.parted, self.imagepath), True) + else: + out = exec_cmd("%s -sm %s unit B print" % (self.parted, self.imagepath)) + parttype = namedtuple("Part", "pnum start end size fstype") splitted = out.splitlines() # skip over possible errors in exec_cmd output diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index a1d152659b..2124ceac7f 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py @@ -321,7 +321,15 @@ class PartitionedImage(): self.partitions = partitions self.partimages = [] # Size of a sector used in calculations - self.sector_size = SECTOR_SIZE + sector_size_str = get_bitbake_var('WIC_SECTOR_SIZE') + if sector_size_str is not None: + try: + self.sector_size = int(sector_size_str) + except ValueError: + self.sector_size = SECTOR_SIZE + else: + self.sector_size = SECTOR_SIZE + self.native_sysroot = native_sysroot num_real_partitions = len([p for p in self.partitions if not p.no_table]) self.extra_space = extra_space @@ -508,7 +516,8 @@ class PartitionedImage(): logger.debug("Added '%s' partition, sectors %d-%d, size %d sectors", parttype, start, end, size) - cmd = "parted -s %s unit s mkpart %s" % (device, parttype) + cmd = "export PARTED_SECTOR_SIZE=%d; parted -s %s unit s mkpart %s" % \ + (self.sector_size, device, parttype) if fstype: cmd += " %s" % fstype cmd += " %d %d" % (start, end) @@ -527,8 +536,8 @@ class PartitionedImage(): os.ftruncate(sparse.fileno(), min_size) logger.debug("Initializing partition table for %s", device) - exec_native_cmd("parted -s %s mklabel %s" % (device, ptable_format), - self.native_sysroot) + exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s mklabel %s" % + (self.sector_size, device, ptable_format), self.native_sysroot) def _write_disk_guid(self): if self.ptable_format in ('gpt', 'gpt-hybrid'): @@ -538,7 +547,8 @@ class PartitionedImage(): self.disk_guid = uuid.uuid4() logger.debug("Set disk guid %s", self.disk_guid) - sfdisk_cmd = "sfdisk --disk-id %s %s" % (self.path, self.disk_guid) + sfdisk_cmd = "sfdisk --sector-size %s --disk-id %s %s" % \ + (self.sector_size, self.path, self.disk_guid) exec_native_cmd(sfdisk_cmd, self.native_sysroot) def create(self): @@ -613,45 +623,44 @@ class PartitionedImage(): partition_label = part.part_name if part.part_name else part.label logger.debug("partition %d: set name to %s", part.num, partition_label) - exec_native_cmd("sgdisk --change-name=%d:%s %s" % \ - (part.num, partition_label, - self.path), self.native_sysroot) - + exec_native_cmd("sfdisk --sector-size %s --part-label %s %d %s" % \ + (self.sector_size, self.path, part.num, + partition_label), self.native_sysroot) if part.part_type: logger.debug("partition %d: set type UID to %s", part.num, part.part_type) - exec_native_cmd("sgdisk --typecode=%d:%s %s" % \ - (part.num, part.part_type, - self.path), self.native_sysroot) + exec_native_cmd("sfdisk --sector-size %s --part-type %s %d %s" % \ + (self.sector_size, self.path, part.num, + part.part_type), self.native_sysroot) if part.uuid and self.ptable_format in ("gpt", "gpt-hybrid"): logger.debug("partition %d: set UUID to %s", part.num, part.uuid) - exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \ - (part.num, part.uuid, self.path), + exec_native_cmd("sfdisk --sector-size %s --part-uuid %s %d %s" % \ + (self.sector_size, self.path, part.num, part.uuid), self.native_sysroot) if part.active: flag_name = "legacy_boot" if self.ptable_format in ('gpt', 'gpt-hybrid') else "boot" logger.debug("Set '%s' flag for partition '%s' on disk '%s'", flag_name, part.num, self.path) - exec_native_cmd("parted -s %s set %d %s on" % \ - (self.path, part.num, flag_name), + exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s set %d %s on" % \ + (self.sector_size, self.path, part.num, flag_name), self.native_sysroot) if self.ptable_format == 'gpt-hybrid' and part.mbr: - exec_native_cmd("parted -s %s set %d %s on" % \ - (mbr_path, hybrid_mbr_part_num, "boot"), + exec_native_cmd("export PARTED_SECTOR_SIZE=%d; parted -s %s set %d %s on" % \ + (self.sector_size, mbr_path, hybrid_mbr_part_num, "boot"), self.native_sysroot) if part.system_id: - exec_native_cmd("sfdisk --part-type %s %s %s" % \ - (self.path, part.num, part.system_id), + exec_native_cmd("sfdisk --sector-size %s --part-type %s %s %s" % \ + (self.sector_size, self.path, part.num, part.system_id), self.native_sysroot) if part.hidden and self.ptable_format == "gpt": logger.debug("Set hidden attribute for partition '%s' on disk '%s'", part.num, self.path) - exec_native_cmd("sfdisk --part-attrs %s %s RequiredPartition" % \ - (self.path, part.num), + exec_native_cmd("sfdisk --sector-size %s --part-attrs %s %s RequiredPartition" % \ + (self.sector_size, self.path, part.num), self.native_sysroot) if self.ptable_format == "gpt-hybrid": @@ -664,7 +673,8 @@ class PartitionedImage(): # create with an arbitrary type, then change it to the correct type # with sfdisk self._create_partition(mbr_path, "primary", "fat32", 1, GPT_OVERHEAD) - exec_native_cmd("sfdisk --part-type %s %d 0xee" % (mbr_path, hybrid_mbr_part_num), + exec_native_cmd("sfdisk --sector-size %s --part-type %s %d 0xee" % \ + (self.sector_size, mbr_path, hybrid_mbr_part_num), self.native_sysroot) # Copy hybrid MBR From patchwork Mon Oct 28 03:46:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vince Chang X-Patchwork-Id: 51389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6D12D13588 for ; Mon, 28 Oct 2024 03:46:27 +0000 (UTC) Received: from TWMBX01.aspeed.com (TWMBX01.aspeed.com [211.20.114.72]) by mx.groups.io with SMTP id smtpd.web10.43841.1730087180638284109 for ; Sun, 27 Oct 2024 20:46:22 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: aspeedtech.com, ip: 211.20.114.72, mailfrom: vince_chang@aspeedtech.com) Received: from TWMBX01.aspeed.com (192.168.0.62) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 28 Oct 2024 11:46:18 +0800 Received: from localhost.localdomain (192.168.10.10) by TWMBX01.aspeed.com (192.168.0.62) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Mon, 28 Oct 2024 11:46:18 +0800 From: Vince Chang To: CC: , Subject: [PATCH v2 2/2] selftest: wic: add test for WIC_SECTOR_SIZE Date: Mon, 28 Oct 2024 11:46:18 +0800 Message-ID: <20241028034618.1504830-3-vince_chang@aspeedtech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241028034618.1504830-1-vince_chang@aspeedtech.com> References: <20241028034618.1504830-1-vince_chang@aspeedtech.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 28 Oct 2024 03:46:27 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/206419 Add test for WIC_SECTOR_SIZE=4096. Verified it on ext4 file system. Signed-off-by: Vince Chang --- meta/lib/oeqa/selftest/cases/wic.py | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index 5e475f9e3f..c96018abbb 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py @@ -839,6 +839,56 @@ bootloader --ptable gpt""") finally: os.remove(wks_file) + def test_wic_sector_size(self): + """Test generation image sector size""" + # Add WIC_SECTOR_SIZE into config + config = 'WIC_SECTOR_SIZE = "4096"\n'\ + 'WIC_BLOCK_SIZE = "4096"\n'\ + 'WICVARS:append = " WIC_SECTOR_SIZE WIC_BLOCK_SIZE"\n' + self.append_config(config) + bitbake('core-image-minimal') + + # Check WIC_SECTOR_SIZE apply to bitbake variable + wic_sector_size_str = get_bb_var('WIC_SECTOR_SIZE', 'core-image-minimal') + wic_sector_size = int(wic_sector_size_str) + self.assertEqual(4096, wic_sector_size) + + self.logger.info("Test wic_sector_size: %d \n" % wic_sector_size) + + with NamedTemporaryFile("w", suffix=".wks") as wks: + wks.writelines( + ['bootloader --ptable gpt\n', + 'part --fstype ext4 --source rootfs --label rofs-a --mkfs-extraopts "-b 4096"\n', + 'part --fstype ext4 --source rootfs --use-uuid --mkfs-extraopts "-b 4096"\n']) + wks.flush() + cmd = "wic create %s -e core-image-minimal -o %s" % (wks.name, self.resultdir) + runCmd(cmd) + wksname = os.path.splitext(os.path.basename(wks.name))[0] + images = glob(os.path.join(self.resultdir, "%s-*direct" % wksname)) + self.assertEqual(1, len(images)) + + sysroot = get_bb_var('RECIPE_SYSROOT_NATIVE', 'wic-tools') + # list partitions + result = runCmd("wic ls %s -n %s" % (images[0], sysroot)) + self.assertEqual(3, len(result.output.split('\n'))) + self.logger.info("result: %s \n" % result.output) + + # verify partition size with wic + res = runCmd("export PARTED_SECTOR_SIZE=%d; parted -m %s unit b p 2>/dev/null" % (wic_sector_size, images[0])) + + self.logger.info("res: %s \n" % res.output) + # parse parted output which looks like this: + # BYT;\n + # /var/tmp/wic/build/tmpgjzzefdd-202410281021-sda.direct:78569472B:file:4096:4096:gpt::;\n + # 1:139264B:39284735B:39145472B:ext4:rofs-a:;\n + # 2:39284736B:78430207B:39145472B:ext4:primary:;\n + disk_info = res.output.splitlines()[1] + # Check sector sizes + sector_size_logical = int(disk_info.split(":")[3]) + sector_size_physical = int(disk_info.split(":")[4]) + self.assertEqual(wic_sector_size, sector_size_logical, "Logical sector size is not %d." % wic_sector_size) + self.assertEqual(wic_sector_size, sector_size_physical, "Physical sector size is not %d." % wic_sector_size) + class Wic2(WicTestCase):