Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # |
| 8 | # This class contains functions for recipes that need QEMU or test for its |
| 9 | # existence. |
| 10 | # |
| 11 | |
| 12 | def qemu_target_binary(data): |
| 13 | package_arch = data.getVar("PACKAGE_ARCH") |
| 14 | qemu_target_binary = (data.getVar("QEMU_TARGET_BINARY_%s" % package_arch) or "") |
| 15 | if qemu_target_binary: |
| 16 | return qemu_target_binary |
| 17 | |
| 18 | target_arch = data.getVar("TARGET_ARCH") |
| 19 | if target_arch in ("i486", "i586", "i686"): |
| 20 | target_arch = "i386" |
| 21 | elif target_arch == "powerpc": |
| 22 | target_arch = "ppc" |
| 23 | elif target_arch == "powerpc64": |
| 24 | target_arch = "ppc64" |
| 25 | elif target_arch == "powerpc64le": |
| 26 | target_arch = "ppc64le" |
| 27 | |
| 28 | return "qemu-" + target_arch |
| 29 | |
| 30 | def qemu_wrapper_cmdline(data, rootfs_path, library_paths): |
| 31 | import string |
| 32 | |
| 33 | qemu_binary = qemu_target_binary(data) |
| 34 | if qemu_binary == "qemu-allarch": |
| 35 | qemu_binary = "qemuwrapper" |
| 36 | |
Patrick Williams | 705982a | 2024-01-12 09:51:57 -0600 | [diff] [blame] | 37 | qemu_options = data.getVar("QEMU_OPTIONS") or "" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 38 | |
| 39 | return "PSEUDO_UNLOAD=1 " + qemu_binary + " " + qemu_options + " -L " + rootfs_path\ |
| 40 | + " -E LD_LIBRARY_PATH=" + ":".join(library_paths) + " " |
| 41 | |
| 42 | # Next function will return a string containing the command that is needed to |
| 43 | # to run a certain binary through qemu. For example, in order to make a certain |
| 44 | # postinstall scriptlet run at do_rootfs time and running the postinstall is |
| 45 | # architecture dependent, we can run it through qemu. For example, in the |
| 46 | # postinstall scriptlet, we could use the following: |
| 47 | # |
| 48 | # ${@qemu_run_binary(d, '$D', '/usr/bin/test_app')} [test_app arguments] |
| 49 | # |
| 50 | def qemu_run_binary(data, rootfs_path, binary): |
| 51 | libdir = rootfs_path + data.getVar("libdir", False) |
| 52 | base_libdir = rootfs_path + data.getVar("base_libdir", False) |
| 53 | |
| 54 | return qemu_wrapper_cmdline(data, rootfs_path, [libdir, base_libdir]) + rootfs_path + binary |
| 55 | |
| 56 | # QEMU_EXTRAOPTIONS is not meant to be directly used, the extensions are |
| 57 | # PACKAGE_ARCH, *NOT* overrides. |
| 58 | # In some cases (e.g. ppc) simply being arch specific (apparently) isn't good |
| 59 | # enough and a PACKAGE_ARCH specific -cpu option is needed (hence we have to do |
| 60 | # this dance). For others (e.g. arm) a -cpu option is not necessary, since the |
| 61 | # qemu-arm default CPU supports all required architecture levels. |
| 62 | |
| 63 | QEMU_OPTIONS = "-r ${OLDEST_KERNEL} ${@d.getVar("QEMU_EXTRAOPTIONS_%s" % d.getVar('PACKAGE_ARCH')) or ""}" |
| 64 | QEMU_OPTIONS[vardeps] += "QEMU_EXTRAOPTIONS_${PACKAGE_ARCH}" |
| 65 | |
| 66 | QEMU_EXTRAOPTIONS_ppce500v2 = " -cpu e500v2" |
| 67 | QEMU_EXTRAOPTIONS_ppce500mc = " -cpu e500mc" |
| 68 | QEMU_EXTRAOPTIONS_ppce5500 = " -cpu e500mc" |
| 69 | QEMU_EXTRAOPTIONS_ppc64e5500 = " -cpu e500mc" |
| 70 | QEMU_EXTRAOPTIONS_ppce6500 = " -cpu e500mc" |
| 71 | QEMU_EXTRAOPTIONS_ppc64e6500 = " -cpu e500mc" |
| 72 | QEMU_EXTRAOPTIONS_ppc7400 = " -cpu 7400" |
| 73 | QEMU_EXTRAOPTIONS_powerpc64le = " -cpu POWER9" |
| 74 | # Some packages e.g. fwupd sets PACKAGE_ARCH = MACHINE_ARCH and uses meson which |
| 75 | # needs right options to usermode qemu |
| 76 | QEMU_EXTRAOPTIONS_qemuppc = " -cpu 7400" |
| 77 | QEMU_EXTRAOPTIONS_qemuppc64 = " -cpu POWER9" |