1eb8dc403SDave CobbleySUMMARY = "Fast open source processor emulator"
2f3f93bb8SBrad BishopDESCRIPTION = "QEMU is a hosted virtual machine monitor: it emulates the \
3f3f93bb8SBrad Bishopmachine's processor through dynamic binary translation and provides a set \
4f3f93bb8SBrad Bishopof different hardware and device models for the machine, enabling it to run \
5f3f93bb8SBrad Bishopa variety of guest operating systems"
6eb8dc403SDave CobbleyHOMEPAGE = "http://qemu.org"
77e0e3c0cSAndrew GeisslerLICENSE = "GPL-2.0-only & LGPL-2.1-only"
819323693SBrad Bishop
9213cb269SPatrick WilliamsRDEPENDS:${PN}-ptest = "bash"
1019323693SBrad Bishop
1115ae2509SBrad Bishoprequire qemu-targets.inc
12fc113eadSAndrew Geisslerinherit pkgconfig ptest update-rc.d systemd
1315ae2509SBrad Bishop
1419323693SBrad BishopLIC_FILES_CHKSUM = "file://COPYING;md5=441c28d2cf86e15a37fa47e15a72fbac \
15c342db35SBrad Bishop                    file://COPYING.LIB;endline=24;md5=8c5efda6cf1e1b03dcfd0e6c0d271c7f"
1619323693SBrad Bishop
1719323693SBrad BishopSRC_URI = "https://download.qemu.org/${BPN}-${PV}.tar.xz \
1819323693SBrad Bishop           file://powerpc_rom.bin \
1919323693SBrad Bishop           file://run-ptest \
20d583833aSAndrew Geissler           file://0001-qemu-Add-addition-environment-space-to-boot-loader-q.patch \
21d583833aSAndrew Geissler           file://0002-chardev-connect-socket-to-a-spawned-command.patch \
22d583833aSAndrew Geissler           file://0003-apic-fixup-fallthrough-to-PIC.patch \
23d583833aSAndrew Geissler           file://0004-configure-Add-pkg-config-handling-for-libgcrypt.patch \
24d583833aSAndrew Geissler           file://0005-qemu-Do-not-include-file-if-not-exists.patch \
25d583833aSAndrew Geissler           file://0006-qemu-Add-some-user-space-mmap-tweaks-to-address-musl.patch \
26d583833aSAndrew Geissler           file://0007-qemu-Determinism-fixes.patch \
27d583833aSAndrew Geissler           file://0008-tests-meson.build-use-relative-path-to-refer-to-file.patch \
28d583833aSAndrew Geissler           file://0009-Define-MAP_SYNC-and-MAP_SHARED_VALIDATE-on-needed-li.patch \
29d583833aSAndrew Geissler           file://0010-hw-pvrdma-Protect-against-buggy-or-malicious-guest-d.patch \
30517393d9SAndrew Geissler           file://0001-contrib-vhost-user-blk-Replace-lseek64-with-lseek.patch \
31517393d9SAndrew Geissler           file://0002-linux-user-Replace-use-of-lfs64-related-functions-an.patch \
32517393d9SAndrew Geissler           file://0001-configure-Fix-check-tcg-not-executing-any-tests.patch \
336aa7eec5SAndrew Geissler           file://0001-Revert-linux-user-add-more-compat-ioctl-definitions.patch \
346aa7eec5SAndrew Geissler           file://0002-Revert-linux-user-fix-compat-with-glibc-2.36-sys-mou.patch \
35*8e7b46e2SPatrick Williams           file://0001-tracetool-use-relative-paths-for-line-preprocessor-d.patch \
36fc113eadSAndrew Geissler           file://qemu-guest-agent.init \
37fc113eadSAndrew Geissler           file://qemu-guest-agent.udev \
3819323693SBrad Bishop           "
3919323693SBrad BishopUPSTREAM_CHECK_REGEX = "qemu-(?P<pver>\d+(\.\d+)+)\.tar"
4019323693SBrad Bishop
41517393d9SAndrew GeisslerSRC_URI[sha256sum] = "5b49ce2687744dad494ae90a898c52204a3406e84d072482a1e1be854eeb2157"
42d1e89497SAndrew Geissler
43213cb269SPatrick WilliamsSRC_URI:append:class-target = " file://cross.patch"
44213cb269SPatrick WilliamsSRC_URI:append:class-nativesdk = " file://cross.patch"
4519323693SBrad Bishop
46ac69b488SWilliam A. Kennington III# Applies against virglrender < 0.6.0 and not qemu itself
477e0e3c0cSAndrew GeisslerCVE_CHECK_IGNORE += "CVE-2017-5957"
48ac69b488SWilliam A. Kennington III
49ac69b488SWilliam A. Kennington III# The VNC server can expose host files uder some circumstances. We don't
50ac69b488SWilliam A. Kennington III# enable it by default.
517e0e3c0cSAndrew GeisslerCVE_CHECK_IGNORE += "CVE-2007-0998"
52ac69b488SWilliam A. Kennington III
53ac69b488SWilliam A. Kennington III# 'The issues identified by this CVE were determined to not constitute a vulnerability.'
54ac69b488SWilliam A. Kennington III# https://bugzilla.redhat.com/show_bug.cgi?id=1609015#c11
557e0e3c0cSAndrew GeisslerCVE_CHECK_IGNORE += "CVE-2018-18438"
56ac69b488SWilliam A. Kennington III
57213cb269SPatrick WilliamsCOMPATIBLE_HOST:mipsarchn32 = "null"
58213cb269SPatrick WilliamsCOMPATIBLE_HOST:mipsarchn64 = "null"
59595f6308SAndrew GeisslerCOMPATIBLE_HOST:riscv32 = "null"
6019323693SBrad Bishop
61c9f7865aSAndrew Geissler# Per https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg03873.html
62c9f7865aSAndrew Geissler# upstream states qemu doesn't work without optimization
63c9f7865aSAndrew GeisslerDEBUG_BUILD = "0"
64c9f7865aSAndrew Geissler
65213cb269SPatrick Williamsdo_install:append() {
6619323693SBrad Bishop    # Prevent QA warnings about installed ${localstatedir}/run
6719323693SBrad Bishop    if [ -d ${D}${localstatedir}/run ]; then rmdir ${D}${localstatedir}/run; fi
6819323693SBrad Bishop}
6919323693SBrad Bishop
7019323693SBrad Bishopdo_install_ptest() {
7119323693SBrad Bishop	cp -rL ${B}/tests ${D}${PTEST_PATH}
72d1e89497SAndrew Geissler	find ${D}${PTEST_PATH}/tests -type f -name "*.[Sshcodp]" | xargs -i rm -rf {}
7319323693SBrad Bishop
7419323693SBrad Bishop	# Don't check the file genreated by configure
75635e0e46SAndrew Geissler	sed -i -e "1s,#!/usr/bin/bash,#!${base_bindir}/bash," ${D}${PTEST_PATH}/tests/data/acpi/disassemle-aml.sh
7690fd73cbSAndrew Geissler
7790fd73cbSAndrew Geissler	# Strip the paths from the QEMU variable, we can use PATH
78517393d9SAndrew Geissler	makfiles=$(find ${D}${PTEST_PATH} -name "*.mak")
79517393d9SAndrew Geissler	sed -i -e "s#^QEMU=.*/qemu-#QEMU=qemu-#g" $makfiles
80eff27476SAndrew Geissler
81eff27476SAndrew Geissler	# Strip compiler flags as they break reproducibility
8287f5cff0SAndrew Geissler	sed -i -e "s,^CC=.*,CC=gcc," \
8387f5cff0SAndrew Geissler	       -e "s,^CCAS=.*,CCAS=gcc," \
84517393d9SAndrew Geissler	       -e "s,^LD=.*,LD=ld," $makfiles
8587f5cff0SAndrew Geissler
8687f5cff0SAndrew Geissler	# Update SRC_PATH variable to the right place on target
87517393d9SAndrew Geissler	sed -i -e "s#^SRC_PATH=.*#SRC_PATH=${PTEST_PATH}#g" $makfiles
8887f5cff0SAndrew Geissler
89517393d9SAndrew Geissler	# https://gitlab.com/qemu-project/qemu/-/issues/1403
90517393d9SAndrew Geissler	rm ${D}${PTEST_PATH}/tests/unit/test-io-channel-command
9119323693SBrad Bishop}
9219323693SBrad Bishop
93eb8dc403SDave Cobbley# QEMU_TARGETS is overridable variable
94864cc43bSPatrick WilliamsQEMU_TARGETS ?= "arm aarch64 i386 loongarch64 mips mipsel mips64 mips64el ppc ppc64 ppc64le riscv32 riscv64 sh4 x86_64"
95eb8dc403SDave Cobbley
96eb8dc403SDave CobbleyEXTRA_OECONF = " \
97eb8dc403SDave Cobbley    --prefix=${prefix} \
98eb8dc403SDave Cobbley    --bindir=${bindir} \
99eb8dc403SDave Cobbley    --includedir=${includedir} \
100eb8dc403SDave Cobbley    --libdir=${libdir} \
101eb8dc403SDave Cobbley    --mandir=${mandir} \
102eb8dc403SDave Cobbley    --datadir=${datadir} \
103eb8dc403SDave Cobbley    --docdir=${docdir}/${BPN} \
104eb8dc403SDave Cobbley    --sysconfdir=${sysconfdir} \
105eb8dc403SDave Cobbley    --libexecdir=${libexecdir} \
106eb8dc403SDave Cobbley    --localstatedir=${localstatedir} \
107d1e89497SAndrew Geissler    --with-suffix=${BPN} \
108eb8dc403SDave Cobbley    --disable-strip \
109eb8dc403SDave Cobbley    --disable-werror \
110eb8dc403SDave Cobbley    --extra-cflags='${CFLAGS}' \
111d25ed324SAndrew Geissler    --extra-ldflags='${LDFLAGS}' \
11282c905dcSAndrew Geissler    --with-git=/bin/false \
113ac69b488SWilliam A. Kennington III    --with-git-submodules=ignore \
114d1e89497SAndrew Geissler    --meson=meson \
1151a4b7ee2SBrad Bishop    ${PACKAGECONFIG_CONFARGS} \
116eb8dc403SDave Cobbley    "
117eb8dc403SDave Cobbley
1181a4b7ee2SBrad BishopB = "${WORKDIR}/build"
1191a4b7ee2SBrad Bishop
1200ca19ccfSPatrick Williams#EXTRA_OECONF:append = " --python=${HOSTTOOLS_DIR}/python3"
12196ff1984SBrad Bishop
122213cb269SPatrick Williamsdo_configure:prepend:class-native() {
123eb8dc403SDave Cobbley	# Append build host pkg-config paths for native target since the host may provide sdl
124eb8dc403SDave Cobbley	BHOST_PKGCONFIG_PATH=$(PATH=/usr/bin:/bin pkg-config --variable pc_path pkg-config || echo "")
125eb8dc403SDave Cobbley	if [ ! -z "$BHOST_PKGCONFIG_PATH" ]; then
126eb8dc403SDave Cobbley		export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$BHOST_PKGCONFIG_PATH
127eb8dc403SDave Cobbley	fi
128eb8dc403SDave Cobbley}
129eb8dc403SDave Cobbley
130eb8dc403SDave Cobbleydo_configure() {
131eb8dc403SDave Cobbley    ${S}/configure ${EXTRA_OECONF}
132eb8dc403SDave Cobbley}
13364c979e8SBrad Bishopdo_configure[cleandirs] += "${B}"
134eb8dc403SDave Cobbley
135eb8dc403SDave Cobbleydo_install () {
1361a4b7ee2SBrad Bishop	export STRIP=""
1371a4b7ee2SBrad Bishop	oe_runmake 'DESTDIR=${D}' install
138fc113eadSAndrew Geissler
139fc113eadSAndrew Geissler	# If we built the guest agent, also install startup/udev rules
140fc113eadSAndrew Geissler	if [ -e "${D}${bindir}/qemu-ga" ]; then
141fc113eadSAndrew Geissler		install -d ${D}${sysconfdir}/init.d/
142fc113eadSAndrew Geissler		install -m 0755 ${WORKDIR}/qemu-guest-agent.init ${D}${sysconfdir}/init.d/qemu-guest-agent
143fc113eadSAndrew Geissler		sed -i 's:@bindir@:${bindir}:' ${D}${sysconfdir}/init.d/qemu-guest-agent
144fc113eadSAndrew Geissler
145fc113eadSAndrew Geissler		install -d ${D}${sysconfdir}/udev/rules.d/
146fc113eadSAndrew Geissler		install -m 0644 ${WORKDIR}/qemu-guest-agent.udev ${D}${sysconfdir}/udev/rules.d/60-qemu-guest-agent.rules
147fc113eadSAndrew Geissler
148fc113eadSAndrew Geissler		install -d ${D}${systemd_unitdir}/system/
149fc113eadSAndrew Geissler		install -m 0644 ${S}/contrib/systemd/qemu-guest-agent.service ${D}${systemd_unitdir}/system
150fc113eadSAndrew Geissler		sed -i -e 's,-/usr/bin/,-${bindir}/,g' ${D}${systemd_unitdir}/system/qemu-guest-agent.service
151fc113eadSAndrew Geissler	fi
152eb8dc403SDave Cobbley}
153eb8dc403SDave Cobbley
154eb8dc403SDave Cobbley# The following fragment will create a wrapper for qemu-mips user emulation
155eb8dc403SDave Cobbley# binary in order to work around a segmentation fault issue. Basically, by
156eb8dc403SDave Cobbley# default, the reserved virtual address space for 32-on-64 bit is set to 4GB.
157eb8dc403SDave Cobbley# This will trigger a MMU access fault in the virtual CPU. With this change,
158eb8dc403SDave Cobbley# the qemu-mips works fine.
159eb8dc403SDave Cobbley# IMPORTANT: This piece needs to be removed once the root cause is fixed!
160213cb269SPatrick Williamsdo_install:append() {
161eb8dc403SDave Cobbley	if [ -e "${D}/${bindir}/qemu-mips" ]; then
162eb8dc403SDave Cobbley		create_wrapper ${D}/${bindir}/qemu-mips \
163eb8dc403SDave Cobbley			QEMU_RESERVED_VA=0x0
164eb8dc403SDave Cobbley	fi
165eb8dc403SDave Cobbley}
166eb8dc403SDave Cobbley# END of qemu-mips workaround
167eb8dc403SDave Cobbley
16819323693SBrad Bishop# Disable kvm/virgl/mesa on targets that do not support it
1699aee5003SAndrew GeisslerPACKAGECONFIG:remove:darwin = "kvm virglrenderer epoxy gtk+"
1709aee5003SAndrew GeisslerPACKAGECONFIG:remove:mingw32 = "kvm virglrenderer epoxy gtk+"
171eb8dc403SDave Cobbley
172c342db35SBrad BishopPACKAGECONFIG[sdl] = "--enable-sdl,--disable-sdl,libsdl2"
173517393d9SAndrew GeisslerPACKAGECONFIG[png] = "--enable-png,--disable-png,libpng"
174b7d28619SAndrew GeisslerPACKAGECONFIG[virtfs] = "--enable-virtfs --enable-attr --enable-cap-ng,--disable-virtfs,libcap-ng attr,"
175eb8dc403SDave CobbleyPACKAGECONFIG[aio] = "--enable-linux-aio,--disable-linux-aio,libaio,"
176db4c27eeSPatrick WilliamsPACKAGECONFIG[uring] = "--enable-linux-io-uring,--disable-linux-io-uring,liburing"
17782c905dcSAndrew GeisslerPACKAGECONFIG[xen] = "--enable-xen,--disable-xen,xen-tools,xen-tools-libxenstore xen-tools-libxenctrl xen-tools-libxenguest"
178eb8dc403SDave CobbleyPACKAGECONFIG[vnc-sasl] = "--enable-vnc --enable-vnc-sasl,--disable-vnc-sasl,cyrus-sasl,"
179eb8dc403SDave CobbleyPACKAGECONFIG[vnc-jpeg] = "--enable-vnc --enable-vnc-jpeg,--disable-vnc-jpeg,jpeg,"
18079641f25SBrad BishopPACKAGECONFIG[libcurl] = "--enable-curl,--disable-curl,curl,"
181eb8dc403SDave CobbleyPACKAGECONFIG[nss] = "--enable-smartcard,--disable-smartcard,nss,"
182eb8dc403SDave CobbleyPACKAGECONFIG[curses] = "--enable-curses,--disable-curses,ncurses,"
183c342db35SBrad BishopPACKAGECONFIG[gtk+] = "--enable-gtk,--disable-gtk,gtk+3 gettext-native"
184c342db35SBrad BishopPACKAGECONFIG[vte] = "--enable-vte,--disable-vte,vte gettext-native"
185eb8dc403SDave CobbleyPACKAGECONFIG[libcap-ng] = "--enable-cap-ng,--disable-cap-ng,libcap-ng,"
186c68388fcSBrad BishopPACKAGECONFIG[ssh] = "--enable-libssh,--disable-libssh,libssh,"
187eb8dc403SDave CobbleyPACKAGECONFIG[gcrypt] = "--enable-gcrypt,--disable-gcrypt,libgcrypt,"
188eb8dc403SDave CobbleyPACKAGECONFIG[nettle] = "--enable-nettle,--disable-nettle,nettle"
189eb8dc403SDave CobbleyPACKAGECONFIG[libusb] = "--enable-libusb,--disable-libusb,libusb1"
190eb8dc403SDave CobbleyPACKAGECONFIG[fdt] = "--enable-fdt,--disable-fdt,dtc"
191595f6308SAndrew GeisslerPACKAGECONFIG[alsa] = "--audio-drv-list=default,,alsa-lib"
1929aee5003SAndrew GeisslerPACKAGECONFIG[epoxy] = "--enable-opengl,--disable-opengl,libepoxy"
193eb8dc403SDave CobbleyPACKAGECONFIG[lzo] = "--enable-lzo,--disable-lzo,lzo"
194eb8dc403SDave CobbleyPACKAGECONFIG[numa] = "--enable-numa,--disable-numa,numactl"
195eb8dc403SDave CobbleyPACKAGECONFIG[gnutls] = "--enable-gnutls,--disable-gnutls,gnutls"
196eb8dc403SDave CobbleyPACKAGECONFIG[bzip2] = "--enable-bzip2,--disable-bzip2,bzip2"
197eb8dc403SDave CobbleyPACKAGECONFIG[libiscsi] = "--enable-libiscsi,--disable-libiscsi"
198eb8dc403SDave CobbleyPACKAGECONFIG[kvm] = "--enable-kvm,--disable-kvm"
1991a4b7ee2SBrad BishopPACKAGECONFIG[virglrenderer] = "--enable-virglrenderer,--disable-virglrenderer,virglrenderer"
2001a4b7ee2SBrad Bishop# spice will be in meta-networking layer
2011a4b7ee2SBrad BishopPACKAGECONFIG[spice] = "--enable-spice,--disable-spice,spice"
2021a4b7ee2SBrad Bishop# usbredir will be in meta-networking layer
2031a4b7ee2SBrad BishopPACKAGECONFIG[usb-redir] = "--enable-usb-redir,--disable-usb-redir,usbredir"
204c342db35SBrad BishopPACKAGECONFIG[snappy] = "--enable-snappy,--disable-snappy,snappy"
205d25ed324SAndrew GeisslerPACKAGECONFIG[glusterfs] = "--enable-glusterfs,--disable-glusterfs,glusterfs"
20682c905dcSAndrew GeisslerPACKAGECONFIG[xkbcommon] = "--enable-xkbcommon,--disable-xkbcommon,libxkbcommon"
20782c905dcSAndrew GeisslerPACKAGECONFIG[libudev] = "--enable-libudev,--disable-libudev,eudev"
208d25ed324SAndrew GeisslerPACKAGECONFIG[attr] = "--enable-attr,--disable-attr,attr,"
209d25ed324SAndrew GeisslerPACKAGECONFIG[rbd] = "--enable-rbd,--disable-rbd,ceph,ceph"
210d25ed324SAndrew GeisslerPACKAGECONFIG[vhost] = "--enable-vhost-net,--disable-vhost-net,,"
211*8e7b46e2SPatrick WilliamsPACKAGECONFIG[ust] = "--enable-trace-backends=ust,,lttng-ust,"
212d25ed324SAndrew GeisslerPACKAGECONFIG[pie] = "--enable-pie,--disable-pie,,"
213d1e89497SAndrew GeisslerPACKAGECONFIG[seccomp] = "--enable-seccomp,--disable-seccomp,libseccomp"
214eff27476SAndrew Geissler# libnfs is currently provided by meta-kodi
215eff27476SAndrew GeisslerPACKAGECONFIG[libnfs] = "--enable-libnfs,--disable-libnfs,libnfs"
216eff27476SAndrew GeisslerPACKAGECONFIG[pmem] = "--enable-libpmem,--disable-libpmem,pmdk"
217595f6308SAndrew GeisslerPACKAGECONFIG[pulsedio] = "--enable-pa,--disable-pa,pulseaudio"
218595f6308SAndrew GeisslerPACKAGECONFIG[selinux] = "--enable-selinux,--disable-selinux"
219d583833aSAndrew GeisslerPACKAGECONFIG[bpf] = "--enable-bpf,--disable-bpf,libbpf"
220615f2f11SAndrew GeisslerPACKAGECONFIG[capstone] = "--enable-capstone,--disable-capstone"
221615f2f11SAndrew GeisslerPACKAGECONFIG[rdma] = "--enable-rdma,--disable-rdma"
222615f2f11SAndrew GeisslerPACKAGECONFIG[vde] = "--enable-vde,--disable-vde"
223517393d9SAndrew GeisslerPACKAGECONFIG[slirp] = "--enable-slirp,--disable-slirp,libslirp"
224615f2f11SAndrew GeisslerPACKAGECONFIG[brlapi] = "--enable-brlapi,--disable-brlapi"
2252390b1b6SPatrick WilliamsPACKAGECONFIG[jack] = "--enable-jack,--disable-jack,jack,"
226eb8dc403SDave Cobbley
227213cb269SPatrick WilliamsINSANE_SKIP:${PN} = "arch"
228c342db35SBrad Bishop
229213cb269SPatrick WilliamsFILES:${PN} += "${datadir}/icons"
230fc113eadSAndrew Geissler
231fc113eadSAndrew Geissler# Put the guest agent in a separate package
232fc113eadSAndrew GeisslerPACKAGES =+ "${PN}-guest-agent"
233fc113eadSAndrew GeisslerSUMMARY:${PN}-guest-agent = "QEMU guest agent"
234fc113eadSAndrew GeisslerFILES:${PN}-guest-agent += " \
235fc113eadSAndrew Geissler    ${bindir}/qemu-ga \
236fc113eadSAndrew Geissler    ${sysconfdir}/udev/rules.d/60-qemu-guest-agent.rules \
237fc113eadSAndrew Geissler    ${sysconfdir}/init.d/qemu-guest-agent \
238fc113eadSAndrew Geissler    ${systemd_unitdir}/system/qemu-guest-agent.service \
239fc113eadSAndrew Geissler"
240fc113eadSAndrew Geissler
241fc113eadSAndrew GeisslerINITSCRIPT_PACKAGES = "${PN}-guest-agent"
242fc113eadSAndrew GeisslerINITSCRIPT_NAME:${PN}-guest-agent = "qemu-guest-agent"
243fc113eadSAndrew GeisslerINITSCRIPT_PARAMS:${PN}-guest-agent = "defaults"
244fc113eadSAndrew Geissler
245fc113eadSAndrew GeisslerSYSTEMD_PACKAGES = "${PN}-guest-agent"
246fc113eadSAndrew GeisslerSYSTEMD_SERVICE:${PN}-guest-agent = "qemu-guest-agent.service"
247