diff options
Diffstat (limited to 'scripts/runqemu')
-rwxr-xr-x | scripts/runqemu | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index 2be7a0f286..72d827260f 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 | ||
@@ -884,7 +903,7 @@ to your build configuration. | |||
884 | self.set('QB_MEM', qb_mem) | 903 | self.set('QB_MEM', qb_mem) |
885 | 904 | ||
886 | mach = self.get('MACHINE') | 905 | mach = self.get('MACHINE') |
887 | if not mach.startswith(('qemumips', 'qemux86', 'qemuloongarch64')): | 906 | if not mach.startswith(('qemumips', 'qemux86', 'qemuloongarch64')) and self.get('QB_DTB') == "": |
888 | self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M' | 907 | self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M' |
889 | 908 | ||
890 | self.qemu_opt_script += ' %s' % self.get('QB_MEM') | 909 | self.qemu_opt_script += ' %s' % self.get('QB_MEM') |
@@ -1783,7 +1802,7 @@ def main(): | |||
1783 | config.check_args() | 1802 | config.check_args() |
1784 | config.read_qemuboot() | 1803 | config.read_qemuboot() |
1785 | config.check_and_set() | 1804 | config.check_and_set() |
1786 | config.uncompress_rootfs() | 1805 | config.rootfs_fixups() |
1787 | # Check whether the combos is valid or not | 1806 | # Check whether the combos is valid or not |
1788 | config.validate_combos() | 1807 | config.validate_combos() |
1789 | config.print_config() | 1808 | config.print_config() |