1SUMMARY = "Fast open source processor emulator"
2DESCRIPTION = "QEMU is a hosted virtual machine monitor: it emulates the \
3machine's processor through dynamic binary translation and provides a set \
4of different hardware and device models for the machine, enabling it to run \
5a variety of guest operating systems"
6HOMEPAGE = "http://qemu.org"
7LICENSE = "GPLv2 & LGPLv2.1"
8
9RDEPENDS:${PN}-ptest = "bash"
10
11require qemu-targets.inc
12inherit pkgconfig ptest
13
14LIC_FILES_CHKSUM = "file://COPYING;md5=441c28d2cf86e15a37fa47e15a72fbac \
15                    file://COPYING.LIB;endline=24;md5=8c5efda6cf1e1b03dcfd0e6c0d271c7f"
16
17SRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \
18           file://powerpc_rom.bin \
19           file://run-ptest \
20           file://0001-qemu-Add-missing-wacom-HID-descriptor.patch \
21           file://0003-qemu-Add-addition-environment-space-to-boot-loader-q.patch \
22           file://0004-qemu-disable-Valgrind.patch \
23           file://0006-chardev-connect-socket-to-a-spawned-command.patch \
24           file://0007-apic-fixup-fallthrough-to-PIC.patch \
25           file://0010-configure-Add-pkg-config-handling-for-libgcrypt.patch \
26           file://0001-Add-enable-disable-udev.patch \
27           file://0001-qemu-Do-not-include-file-if-not-exists.patch \
28           file://mmap2.patch \
29           file://determinism.patch \
30           file://0001-tests-meson.build-use-relative-path-to-refer-to-file.patch \
31           file://0001-configure-fix-detection-of-gdbus-codegen.patch \
32           file://0001-vhost-user-gpu-fix-memory-disclosure-in-virgl_cmd_ge.patch \
33           file://0002-vhost-user-gpu-fix-resource-leak-in-vg_resource_crea.patch \
34           file://0003-vhost-user-gpu-fix-memory-leak-in-vg_resource_attach.patch \
35           file://0004-vhost-user-gpu-fix-memory-leak-while-calling-vg_reso.patch \
36           file://0005-vhost-user-gpu-fix-memory-leak-in-virgl_cmd_resource.patch \
37           file://0006-vhost-user-gpu-fix-memory-leak-in-virgl_resource_att.patch \
38           file://0007-vhost-user-gpu-fix-OOB-write-in-virgl_cmd_get_capset.patch \
39           file://0001-linux-user-Tag-vsx-with-ieee128-fpbits.patch \
40           file://CVE-2021-3527-1.patch \
41           file://CVE-2021-3527-2.patch \
42           file://CVE-2021-3682.patch \
43           "
44UPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar"
45
46SRC_URI[sha256sum] = "87bc1a471ca24b97e7005711066007d443423d19aacda3d442558ae032fa30b9"
47
48SRC_URI:append:class-target = " file://cross.patch"
49SRC_URI:append:class-nativesdk = " file://cross.patch"
50
51# Applies against virglrender < 0.6.0 and not qemu itself
52CVE_CHECK_WHITELIST += "CVE-2017-5957"
53
54# The VNC server can expose host files uder some circumstances. We don't
55# enable it by default.
56CVE_CHECK_WHITELIST += "CVE-2007-0998"
57
58# 'The issues identified by this CVE were determined to not constitute a vulnerability.'
59# https://bugzilla.redhat.com/show_bug.cgi?id=1609015#c11
60CVE_CHECK_WHITELIST += "CVE-2018-18438"
61
62COMPATIBLE_HOST:mipsarchn32 = "null"
63COMPATIBLE_HOST:mipsarchn64 = "null"
64
65# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
66# upstream states qemu doesn't work without optimization
67DEBUG_BUILD = "0"
68
69do_install:append() {
70    # Prevent QA warnings about installed ${localstatedir}/run
71    if [ -d ${D}${localstatedir}/run ]; then rmdir ${D}${localstatedir}/run; fi
72}
73
74do_install_ptest() {
75	cp -rL ${B}/tests ${D}${PTEST_PATH}
76	find ${D}${PTEST_PATH}/tests -type f -name "*.[Sshcodp]" | xargs -i rm -rf {}
77
78	# Don't check the file genreated by configure
79	sed -i -e "1s,#!/usr/bin/bash,#!${base_bindir}/bash," ${D}${PTEST_PATH}/tests/data/acpi/disassemle-aml.sh
80
81	# Strip the paths from the QEMU variable, we can use PATH
82	sed -i -e "s#^QEMU=.*/qemu-#QEMU=qemu-#g" ${D}${PTEST_PATH}/tests/tcg/*.mak
83}
84
85# QEMU_TARGETS is overridable variable
86QEMU_TARGETS ?= "arm aarch64 i386 mips mipsel mips64 mips64el ppc ppc64 ppc64le riscv32 riscv64 sh4 x86_64"
87
88EXTRA_OECONF = " \
89    --prefix=${prefix} \
90    --bindir=${bindir} \
91    --includedir=${includedir} \
92    --libdir=${libdir} \
93    --mandir=${mandir} \
94    --datadir=${datadir} \
95    --docdir=${docdir}/${BPN} \
96    --sysconfdir=${sysconfdir} \
97    --libexecdir=${libexecdir} \
98    --localstatedir=${localstatedir} \
99    --with-suffix=${BPN} \
100    --disable-strip \
101    --disable-werror \
102    --extra-cflags='${CFLAGS}' \
103    --extra-ldflags='${LDFLAGS}' \
104    --with-git=/bin/false \
105    --with-git-submodules=ignore \
106    --meson=meson \
107    ${PACKAGECONFIG_CONFARGS} \
108    "
109
110export LIBTOOL="${HOST_SYS}-libtool"
111
112B = "${WORKDIR}/build"
113
114#EXTRA_OECONF:append = " --python=${HOSTTOOLS_DIR}/python3"
115
116do_configure:prepend:class-native() {
117	# Append build host pkg-config paths for native target since the host may provide sdl
118	BHOST_PKGCONFIG_PATH=$(PATH=/usr/bin:/bin pkg-config --variable pc_path pkg-config || echo "")
119	if [ ! -z "$BHOST_PKGCONFIG_PATH" ]; then
120		export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$BHOST_PKGCONFIG_PATH
121	fi
122}
123
124do_configure() {
125    ${S}/configure ${EXTRA_OECONF}
126}
127do_configure[cleandirs] += "${B}"
128
129do_install () {
130	export STRIP=""
131	oe_runmake 'DESTDIR=${D}' install
132}
133
134# The following fragment will create a wrapper for qemu-mips user emulation
135# binary in order to work around a segmentation fault issue. Basically, by
136# default, the reserved virtual address space for 32-on-64 bit is set to 4GB.
137# This will trigger a MMU access fault in the virtual CPU. With this change,
138# the qemu-mips works fine.
139# IMPORTANT: This piece needs to be removed once the root cause is fixed!
140do_install:append() {
141	if [ -e "${D}/${bindir}/qemu-mips" ]; then
142		create_wrapper ${D}/${bindir}/qemu-mips \
143			QEMU_RESERVED_VA=0x0
144	fi
145}
146# END of qemu-mips workaround
147
148make_qemu_wrapper() {
149        gdk_pixbuf_module_file=`pkg-config --variable=gdk_pixbuf_cache_file gdk-pixbuf-2.0`
150
151        for tool in `ls ${D}${bindir}/qemu-system-*`; do
152                create_wrapper $tool \
153                        GDK_PIXBUF_MODULE_FILE=$gdk_pixbuf_module_file \
154                        FONTCONFIG_PATH=/etc/fonts \
155                        GTK_THEME=Adwaita
156        done
157}
158
159# Disable kvm/virgl/mesa on targets that do not support it
160PACKAGECONFIG:remove:darwin = "kvm virglrenderer glx gtk+"
161PACKAGECONFIG:remove:mingw32 = "kvm virglrenderer glx gtk+"
162
163PACKAGECONFIG[sdl] = "--enable-sdl,--disable-sdl,libsdl2"
164PACKAGECONFIG[virtfs] = "--enable-virtfs --enable-attr --enable-cap-ng,--disable-virtfs,libcap-ng attr,"
165PACKAGECONFIG[aio] = "--enable-linux-aio,--disable-linux-aio,libaio,"
166PACKAGECONFIG[xfs] = "--enable-xfsctl,--disable-xfsctl,xfsprogs,"
167PACKAGECONFIG[xen] = "--enable-xen,--disable-xen,xen-tools,xen-tools-libxenstore xen-tools-libxenctrl xen-tools-libxenguest"
168PACKAGECONFIG[vnc-sasl] = "--enable-vnc --enable-vnc-sasl,--disable-vnc-sasl,cyrus-sasl,"
169PACKAGECONFIG[vnc-jpeg] = "--enable-vnc --enable-vnc-jpeg,--disable-vnc-jpeg,jpeg,"
170PACKAGECONFIG[vnc-png] = "--enable-vnc --enable-vnc-png,--disable-vnc-png,libpng,"
171PACKAGECONFIG[libcurl] = "--enable-curl,--disable-curl,curl,"
172PACKAGECONFIG[nss] = "--enable-smartcard,--disable-smartcard,nss,"
173PACKAGECONFIG[curses] = "--enable-curses,--disable-curses,ncurses,"
174PACKAGECONFIG[gtk+] = "--enable-gtk,--disable-gtk,gtk+3 gettext-native"
175PACKAGECONFIG[vte] = "--enable-vte,--disable-vte,vte gettext-native"
176PACKAGECONFIG[libcap-ng] = "--enable-cap-ng,--disable-cap-ng,libcap-ng,"
177PACKAGECONFIG[ssh] = "--enable-libssh,--disable-libssh,libssh,"
178PACKAGECONFIG[gcrypt] = "--enable-gcrypt,--disable-gcrypt,libgcrypt,"
179PACKAGECONFIG[nettle] = "--enable-nettle,--disable-nettle,nettle"
180PACKAGECONFIG[libusb] = "--enable-libusb,--disable-libusb,libusb1"
181PACKAGECONFIG[fdt] = "--enable-fdt,--disable-fdt,dtc"
182PACKAGECONFIG[alsa] = "--audio-drv-list='oss alsa',,alsa-lib"
183PACKAGECONFIG[glx] = "--enable-opengl,--disable-opengl,virtual/libgl"
184PACKAGECONFIG[lzo] = "--enable-lzo,--disable-lzo,lzo"
185PACKAGECONFIG[numa] = "--enable-numa,--disable-numa,numactl"
186PACKAGECONFIG[gnutls] = "--enable-gnutls,--disable-gnutls,gnutls"
187PACKAGECONFIG[bzip2] = "--enable-bzip2,--disable-bzip2,bzip2"
188PACKAGECONFIG[libiscsi] = "--enable-libiscsi,--disable-libiscsi"
189PACKAGECONFIG[kvm] = "--enable-kvm,--disable-kvm"
190PACKAGECONFIG[virglrenderer] = "--enable-virglrenderer,--disable-virglrenderer,virglrenderer"
191# spice will be in meta-networking layer
192PACKAGECONFIG[spice] = "--enable-spice,--disable-spice,spice"
193# usbredir will be in meta-networking layer
194PACKAGECONFIG[usb-redir] = "--enable-usb-redir,--disable-usb-redir,usbredir"
195PACKAGECONFIG[snappy] = "--enable-snappy,--disable-snappy,snappy"
196PACKAGECONFIG[glusterfs] = "--enable-glusterfs,--disable-glusterfs,glusterfs"
197PACKAGECONFIG[xkbcommon] = "--enable-xkbcommon,--disable-xkbcommon,libxkbcommon"
198PACKAGECONFIG[libudev] = "--enable-libudev,--disable-libudev,eudev"
199PACKAGECONFIG[libxml2] = "--enable-libxml2,--disable-libxml2,libxml2"
200PACKAGECONFIG[attr] = "--enable-attr,--disable-attr,attr,"
201PACKAGECONFIG[rbd] = "--enable-rbd,--disable-rbd,ceph,ceph"
202PACKAGECONFIG[vhost] = "--enable-vhost-net,--disable-vhost-net,,"
203PACKAGECONFIG[ust] = "--enable-trace-backend=ust,--enable-trace-backend=nop,lttng-ust,"
204PACKAGECONFIG[pie] = "--enable-pie,--disable-pie,,"
205PACKAGECONFIG[seccomp] = "--enable-seccomp,--disable-seccomp,libseccomp"
206
207INSANE_SKIP:${PN} = "arch"
208
209FILES:${PN} += "${datadir}/icons"
210