From: Jon Mason <jon.mason@arm.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH v2 2/2] runqemu: resize rootfs image to power of 2 for SD or pflash
Date: Fri, 3 Oct 2025 11:08:37 -0400 [thread overview]
Message-ID: <20251003150837.39814-2-jon.mason@arm.com> (raw)
In-Reply-To: <20251003150837.39814-1-jon.mason@arm.com>
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 <jon.mason@arm.com>
---
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()
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2025-10-03 15:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-03 15:08 [PATCH v2 1/2] runqemu: remove setting of mem on kernel command line for certain systems Jon Mason
2025-10-03 15:08 ` Jon Mason [this message]
2025-10-06 8:58 ` [OE-core] " Alexander Kanavin
2025-10-06 14:16 ` Jon Mason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251003150837.39814-2-jon.mason@arm.com \
--to=jon.mason@arm.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox