diff options
| author | Jon Mason <jon.mason@arm.com> | 2025-10-03 11:08:37 -0400 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-10-06 17:01:10 +0100 |
| commit | bcddcc0243183786b9373c2a7055e49b0458dfb4 (patch) | |
| tree | 54719c0dbb3ba950c76f28fae7aab560084fd739 /scripts/runqemu | |
| parent | bd89cf856fa527d142b76f854527933a268a43ad (diff) | |
| download | poky-bcddcc0243183786b9373c2a7055e49b0458dfb4.tar.gz | |
runqemu: resize rootfs image to power of 2 for SD or pflash
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
(From OE-Core rev: 9ecedac7dcd858cef32192304d59bfa44ca77b3c)
Signed-off-by: Jon Mason <jon.mason@arm.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/runqemu')
| -rwxr-xr-x | scripts/runqemu | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index b692bfbdb5..4bac151ccf 100755 --- a/scripts/runqemu +++ b/scripts/runqemu | |||
| @@ -421,8 +421,27 @@ class BaseConfig(object): | |||
| 421 | else: | 421 | else: |
| 422 | raise RunQemuError("Unknown path arg %s" % p) | 422 | raise RunQemuError("Unknown path arg %s" % p) |
| 423 | 423 | ||
| 424 | def uncompress_rootfs(self): | 424 | def rootfs_fixups(self): |
| 425 | """Decompress ZST rootfs image if needed""" | 425 | |
| 426 | """Decompress and/or resize the rootfs image, if needed""" | ||
| 427 | qb_rootfs_opt = self.get('QB_ROOTFS_OPT') | ||
| 428 | |||
| 429 | # Check if sdcard size is a power of 2, as that is currently a requirement for qemu | ||
| 430 | # See https://gitlab.com/qemu-project/qemu/-/issues/1754 | ||
| 431 | rootfs_size = os.path.getsize(self.rootfs) | ||
| 432 | rootfs_size_pwr2 = 1 << (rootfs_size - 1).bit_length() | ||
| 433 | if ("if=sd" in qb_rootfs_opt or "if=pflash" in qb_rootfs_opt) and rootfs_size != rootfs_size_pwr2: | ||
| 434 | 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)) | ||
| 435 | logger.info("Attempting to use truncate to correct this.") | ||
| 436 | |||
| 437 | # Ensure the 'truncate' tool is installed before attempting to make a power of 2. | ||
| 438 | if not shutil.which('truncate'): | ||
| 439 | raise RunQemuError(f"'truncate' is required to make {self.rootfs} a power of 2 in size but was not found in PATH") | ||
| 440 | try: | ||
| 441 | subprocess.check_call(['truncate', '-s', str(rootfs_size_pwr2), self.rootfs]) | ||
| 442 | except subprocess.CalledProcessError as e: | ||
| 443 | raise RunQemuError(f"Failed to make {self.rootfs} power of 2 in size: {e}") | ||
| 444 | |||
| 426 | if not self.rootfs or not self.fstype.endswith('.zst'): | 445 | if not self.rootfs or not self.fstype.endswith('.zst'): |
| 427 | return | 446 | return |
| 428 | 447 | ||
| @@ -1809,7 +1828,7 @@ def main(): | |||
| 1809 | config.check_args() | 1828 | config.check_args() |
| 1810 | config.read_qemuboot() | 1829 | config.read_qemuboot() |
| 1811 | config.check_and_set() | 1830 | config.check_and_set() |
| 1812 | config.uncompress_rootfs() | 1831 | config.rootfs_fixups() |
| 1813 | # Check whether the combos is valid or not | 1832 | # Check whether the combos is valid or not |
| 1814 | config.validate_combos() | 1833 | config.validate_combos() |
| 1815 | config.print_config() | 1834 | config.print_config() |
