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