diff options
| -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() |
