From patchwork Mon Oct 6 14:24:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Mason X-Patchwork-Id: 71714 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 AF591CCA471 for ; Mon, 6 Oct 2025 14:24:49 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.35095.1759760679505798337 for ; Mon, 06 Oct 2025 07:24:39 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: jon.mason@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DC7BB1515 for ; Mon, 6 Oct 2025 07:24:30 -0700 (PDT) Received: from H24V3P4C17.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BCDBA3F738 for ; Mon, 6 Oct 2025 07:24:38 -0700 (PDT) From: Jon Mason To: openembedded-core@lists.openembedded.org Subject: [PATCH v3 1/2] runqemu: remove setting of mem on kernel command line for certain systems Date: Mon, 6 Oct 2025 10:24:36 -0400 Message-ID: <20251006142437.18240-1-jon.mason@arm.com> X-Mailer: git-send-email 2.50.1 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, 06 Oct 2025 14:24:49 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/224491 Some emulated hardware will not boot if mem is set on the kernel command line (all of the Raspberry Pi machines seemed to fail with this set, possibly many others). Also, it is not necessary if the device tree file is present, as that _should_ have the memory size specified in it. Add a check for QB_DTB and don't set mem in the kernel command line if present. Signed-off-by: Jon Mason --- scripts/runqemu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/runqemu b/scripts/runqemu index 32c7a2aab3b5..a8144aa68c3d 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -884,7 +884,7 @@ to your build configuration. self.set('QB_MEM', qb_mem) mach = self.get('MACHINE') - if not mach.startswith(('qemumips', 'qemux86', 'qemuloongarch64')): + if not mach.startswith(('qemumips', 'qemux86', 'qemuloongarch64')) and self.get('QB_DTB') == "": self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M' self.qemu_opt_script += ' %s' % self.get('QB_MEM') From patchwork Mon Oct 6 14:24:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Mason X-Patchwork-Id: 71715 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 B036BCCA476 for ; Mon, 6 Oct 2025 14:24:49 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.35096.1759760679526184071 for ; Mon, 06 Oct 2025 07:24:39 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: jon.mason@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1CD931516 for ; Mon, 6 Oct 2025 07:24:31 -0700 (PDT) Received: from H24V3P4C17.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F22E63F738 for ; Mon, 6 Oct 2025 07:24:38 -0700 (PDT) From: Jon Mason To: openembedded-core@lists.openembedded.org Subject: [PATCH v3 2/2] runqemu: resize rootfs image to power of 2 for SD or pflash Date: Mon, 6 Oct 2025 10:24:37 -0400 Message-ID: <20251006142437.18240-2-jon.mason@arm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251006142437.18240-1-jon.mason@arm.com> References: <20251006142437.18240-1-jon.mason@arm.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, 06 Oct 2025 14:24:49 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/224490 QEMU requires that SD and pflash images are sized to be a power of 2 (e.g., 32M, 64M, etc). So, if the image being used is not a power of 2 and it's being used for SD or pflash, increase it to the next power of 2 size via the truncate command. This might not be an actual spec requirement, and is being investigated in https://gitlab.com/qemu-project/qemu/-/issues/1754 Signed-off-by: Jon Mason --- scripts/runqemu | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/runqemu b/scripts/runqemu index a8144aa68c3d..21d75ad8a319 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -421,8 +421,27 @@ class BaseConfig(object): else: raise RunQemuError("Unknown path arg %s" % p) - def uncompress_rootfs(self): - """Decompress ZST rootfs image if needed""" + def rootfs_fixups(self): + + """Decompress and/or resize the rootfs image, if needed""" + qb_rootfs_opt = self.get('QB_ROOTFS_OPT') + + # Check if sdcard size is a power of 2, as that is currently a requirement for qemu + # See https://gitlab.com/qemu-project/qemu/-/issues/1754 + rootfs_size = os.path.getsize(self.rootfs) + rootfs_size_pwr2 = 1 << (rootfs_size - 1).bit_length() + if ("if=sd" in qb_rootfs_opt or "if=pflash" in qb_rootfs_opt) and rootfs_size != rootfs_size_pwr2: + logger.info("Using sd-card or pflash and is not power of 2. File size %d, power of 2 size %d" %(rootfs_size, rootfs_size_pwr2)) + logger.info("Attempting to use truncate to correct this.") + + # Ensure the 'truncate' tool is installed before attempting to make a power of 2. + if not shutil.which('truncate'): + raise RunQemuError(f"'truncate' is required to make {self.rootfs} a power of 2 in size but was not found in PATH") + try: + subprocess.check_call(['truncate', '-s', str(rootfs_size_pwr2), self.rootfs]) + except subprocess.CalledProcessError as e: + raise RunQemuError(f"Failed to make {self.rootfs} power of 2 in size: {e}") + if not self.rootfs or not self.fstype.endswith('.zst'): return @@ -1808,7 +1827,7 @@ def main(): config.check_args() config.read_qemuboot() config.check_and_set() - config.uncompress_rootfs() + config.rootfs_fixups() # Check whether the combos is valid or not config.validate_combos() config.print_config()