diff options
Diffstat (limited to 'scripts/runqemu')
-rwxr-xr-x | scripts/runqemu | 67 |
1 files changed, 11 insertions, 56 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index 4bac151ccf..2be7a0f286 100755 --- a/scripts/runqemu +++ b/scripts/runqemu | |||
@@ -421,27 +421,8 @@ 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 rootfs_fixups(self): | 424 | def uncompress_rootfs(self): |
425 | 425 | """Decompress ZST rootfs image if needed""" | |
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 | |||
445 | if not self.rootfs or not self.fstype.endswith('.zst'): | 426 | if not self.rootfs or not self.fstype.endswith('.zst'): |
446 | return | 427 | return |
447 | 428 | ||
@@ -903,7 +884,7 @@ to your build configuration. | |||
903 | self.set('QB_MEM', qb_mem) | 884 | self.set('QB_MEM', qb_mem) |
904 | 885 | ||
905 | mach = self.get('MACHINE') | 886 | mach = self.get('MACHINE') |
906 | if not mach.startswith(('qemumips', 'qemux86', 'qemuloongarch64')) and self.get('QB_DTB') == "": | 887 | if not mach.startswith(('qemumips', 'qemux86', 'qemuloongarch64')): |
907 | self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M' | 888 | self.kernel_cmdline_script += ' mem=%s' % self.get('QB_MEM').replace('-m','').strip() + 'M' |
908 | 889 | ||
909 | self.qemu_opt_script += ' %s' % self.get('QB_MEM') | 890 | self.qemu_opt_script += ' %s' % self.get('QB_MEM') |
@@ -1026,34 +1007,12 @@ to your build configuration. | |||
1026 | if not self.bitbake_e: | 1007 | if not self.bitbake_e: |
1027 | self.load_bitbake_env() | 1008 | self.load_bitbake_env() |
1028 | 1009 | ||
1029 | if self.bitbake_e: | 1010 | native_vars = ['STAGING_DIR_NATIVE'] |
1030 | native_vars = ['STAGING_DIR_NATIVE'] | 1011 | for nv in native_vars: |
1031 | for nv in native_vars: | 1012 | s = re.search('^%s="(.*)"' % nv, self.bitbake_e, re.M) |
1032 | s = re.search('^%s="(.*)"' % nv, self.bitbake_e, re.M) | 1013 | if s and s.group(1) != self.get(nv): |
1033 | if s and s.group(1) != self.get(nv): | 1014 | logger.info('Overriding conf file setting of %s to %s from Bitbake environment' % (nv, s.group(1))) |
1034 | logger.info('Overriding conf file setting of %s to %s from Bitbake environment' % (nv, s.group(1))) | 1015 | self.set(nv, s.group(1)) |
1035 | self.set(nv, s.group(1)) | ||
1036 | else: | ||
1037 | # when we're invoked from a running bitbake instance we won't | ||
1038 | # be able to call `bitbake -e`, then try: | ||
1039 | # - get OE_TMPDIR from environment and guess paths based on it | ||
1040 | # - get OECORE_NATIVE_SYSROOT from environment (for sdk) | ||
1041 | tmpdir = self.get('OE_TMPDIR') | ||
1042 | oecore_native_sysroot = self.get('OECORE_NATIVE_SYSROOT') | ||
1043 | if tmpdir: | ||
1044 | logger.info('Setting STAGING_DIR_NATIVE and STAGING_BINDIR_NATIVE relative to OE_TMPDIR (%s)' % tmpdir) | ||
1045 | hostos, _, _, _, machine = os.uname() | ||
1046 | buildsys = '%s-%s' % (machine, hostos.lower()) | ||
1047 | staging_dir_native = '%s/sysroots/%s' % (tmpdir, buildsys) | ||
1048 | self.set('STAGING_DIR_NATIVE', staging_dir_native) | ||
1049 | elif oecore_native_sysroot: | ||
1050 | logger.info('Setting STAGING_DIR_NATIVE to OECORE_NATIVE_SYSROOT (%s)' % oecore_native_sysroot) | ||
1051 | self.set('STAGING_DIR_NATIVE', oecore_native_sysroot) | ||
1052 | if self.get('STAGING_DIR_NATIVE'): | ||
1053 | # we have to assume that STAGING_BINDIR_NATIVE is at usr/bin | ||
1054 | staging_bindir_native = '%s/usr/bin' % self.get('STAGING_DIR_NATIVE') | ||
1055 | logger.info('Setting STAGING_BINDIR_NATIVE to %s' % staging_bindir_native) | ||
1056 | self.set('STAGING_BINDIR_NATIVE', '%s/usr/bin' % self.get('STAGING_DIR_NATIVE')) | ||
1057 | 1016 | ||
1058 | def print_config(self): | 1017 | def print_config(self): |
1059 | logoutput = ['Continuing with the following parameters:'] | 1018 | logoutput = ['Continuing with the following parameters:'] |
@@ -1764,11 +1723,7 @@ to your build configuration. | |||
1764 | cmd = 'MACHINE=%s bitbake -e %s %s' % (mach, multiconfig, target) | 1723 | cmd = 'MACHINE=%s bitbake -e %s %s' % (mach, multiconfig, target) |
1765 | else: | 1724 | else: |
1766 | cmd = 'bitbake -e %s %s' % (multiconfig, target) | 1725 | cmd = 'bitbake -e %s %s' % (multiconfig, target) |
1767 | try: | 1726 | return subprocess.check_output(cmd, shell=True).decode('utf-8') |
1768 | return subprocess.check_output(cmd, shell=True).decode('utf-8') | ||
1769 | except subprocess.CalledProcessError as err: | ||
1770 | logger.warning("Couldn't run '%s' to gather environment information, giving up with 'bitbake -e':\n%s" % (cmd, err.output.decode('utf-8'))) | ||
1771 | return '' | ||
1772 | 1727 | ||
1773 | 1728 | ||
1774 | def load_bitbake_env(self, mach=None, target=None): | 1729 | def load_bitbake_env(self, mach=None, target=None): |
@@ -1828,7 +1783,7 @@ def main(): | |||
1828 | config.check_args() | 1783 | config.check_args() |
1829 | config.read_qemuboot() | 1784 | config.read_qemuboot() |
1830 | config.check_and_set() | 1785 | config.check_and_set() |
1831 | config.rootfs_fixups() | 1786 | config.uncompress_rootfs() |
1832 | # Check whether the combos is valid or not | 1787 | # Check whether the combos is valid or not |
1833 | config.validate_combos() | 1788 | config.validate_combos() |
1834 | config.print_config() | 1789 | config.print_config() |