diff options
| author | Chen Qi <Qi.Chen@windriver.com> | 2025-04-29 12:29:40 +0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-05-01 14:22:54 +0100 |
| commit | 0d5afd177864cc248f345701805592c5c9c82a70 (patch) | |
| tree | 8cc28c806023eebf88e94a7117952d37af4cca3d /meta/lib | |
| parent | c07ded97d7303c2db56dd3ae8b362dbe7f7aa554 (diff) | |
| download | poky-0d5afd177864cc248f345701805592c5c9c82a70.tar.gz | |
lib/classes/conf: refactor qemu.bbclass functions into library functions
Move the functions in qemu.bbclass to meta/lib/oe/qemu.py as they are
generally useful.
The qemu.bbclass is still kept, and recipes can continue to use functions
from it, though they have become wrapper functions on qemu.py functions.
Note that the QEMU_OPTIONS settings are still kept in qemu.bbclass.
This sets a clear barrier for people to use qemu user mode.
(From OE-Core rev: 7b3563b3b3901c96c3e498799a83ab8cabcf84b4)
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
| -rw-r--r-- | meta/lib/oe/__init__.py | 2 | ||||
| -rw-r--r-- | meta/lib/oe/qemu.py | 54 |
2 files changed, 55 insertions, 1 deletions
diff --git a/meta/lib/oe/__init__.py b/meta/lib/oe/__init__.py index a55694669d..dd094a874a 100644 --- a/meta/lib/oe/__init__.py +++ b/meta/lib/oe/__init__.py | |||
| @@ -10,6 +10,6 @@ __path__ = extend_path(__path__, __name__) | |||
| 10 | # Modules with vistorcode need to go first else anything depending on them won't be | 10 | # Modules with vistorcode need to go first else anything depending on them won't be |
| 11 | # processed correctly (e.g. qa) | 11 | # processed correctly (e.g. qa) |
| 12 | BBIMPORTS = ["qa", "data", "path", "utils", "types", "package", "packagedata", \ | 12 | BBIMPORTS = ["qa", "data", "path", "utils", "types", "package", "packagedata", \ |
| 13 | "packagegroup", "sstatesig", "lsb", "cachedpath", "license", \ | 13 | "packagegroup", "sstatesig", "lsb", "cachedpath", "license", "qemu", \ |
| 14 | "reproducible", "rust", "buildcfg", "go", "spdx30_tasks", "spdx_common", \ | 14 | "reproducible", "rust", "buildcfg", "go", "spdx30_tasks", "spdx_common", \ |
| 15 | "cve_check"] | 15 | "cve_check"] |
diff --git a/meta/lib/oe/qemu.py b/meta/lib/oe/qemu.py new file mode 100644 index 0000000000..769865036c --- /dev/null +++ b/meta/lib/oe/qemu.py | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | # | ||
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 5 | # | ||
| 6 | |||
| 7 | def qemu_target_binary(d): | ||
| 8 | package_arch = d.getVar("PACKAGE_ARCH") | ||
| 9 | qemu_target_binary = (d.getVar("QEMU_TARGET_BINARY_%s" % package_arch) or "") | ||
| 10 | if qemu_target_binary: | ||
| 11 | return qemu_target_binary | ||
| 12 | |||
| 13 | target_arch = d.getVar("TARGET_ARCH") | ||
| 14 | if target_arch in ("i486", "i586", "i686"): | ||
| 15 | target_arch = "i386" | ||
| 16 | elif target_arch == "powerpc": | ||
| 17 | target_arch = "ppc" | ||
| 18 | elif target_arch == "powerpc64": | ||
| 19 | target_arch = "ppc64" | ||
| 20 | elif target_arch == "powerpc64le": | ||
| 21 | target_arch = "ppc64le" | ||
| 22 | |||
| 23 | return "qemu-" + target_arch | ||
| 24 | |||
| 25 | def qemu_wrapper_cmdline(d, rootfs_path, library_paths, qemu_options=None): | ||
| 26 | import string | ||
| 27 | |||
| 28 | package_arch = d.getVar("PACKAGE_ARCH") | ||
| 29 | if package_arch == "all": | ||
| 30 | return "false" | ||
| 31 | |||
| 32 | qemu_binary = qemu_target_binary(d) | ||
| 33 | if qemu_binary == "qemu-allarch": | ||
| 34 | qemu_binary = "qemuwrapper" | ||
| 35 | |||
| 36 | if qemu_options == None: | ||
| 37 | qemu_options = d.getVar("QEMU_OPTIONS") or "" | ||
| 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(d, rootfs_path, binary): | ||
| 51 | libdir = rootfs_path + d.getVar("libdir", False) | ||
| 52 | base_libdir = rootfs_path + d.getVar("base_libdir", False) | ||
| 53 | |||
| 54 | return qemu_wrapper_cmdline(d, rootfs_path, [libdir, base_libdir]) + rootfs_path + binary | ||
