blob: 5d54bad473c3416eeedef7b41b8916696e12efd9 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001SUMMARY = "OVMF - UEFI firmware for Qemu and KVM"
2DESCRIPTION = "OVMF is an EDK II based project to enable UEFI support for \
3Virtual Machines. OVMF contains sample UEFI firmware for QEMU and KVM"
4HOMEPAGE = "https://github.com/tianocore/tianocore.github.io/wiki/OVMF"
Andrew Geissler5199d832021-09-24 16:47:35 -05005LICENSE = "BSD-2-Clause-Patent"
6LICENSE:class-target = "${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'BSD-2-Clause-Patent & OpenSSL', 'BSD-2-Clause-Patent', d)}"
Brad Bishop08902b02019-08-20 09:16:51 -04007LIC_FILES_CHKSUM = "file://OvmfPkg/License.txt;md5=06357ddc23f46577c2aeaeaf7b776d65"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008
9# Enabling Secure Boot adds a dependency on OpenSSL and implies
10# compiling OVMF twice, so it is disabled by default. Distros
11# may change that default.
12PACKAGECONFIG ??= ""
Patrick Williams93c203f2021-10-06 16:15:23 -050013PACKAGECONFIG += "${@bb.utils.contains('MACHINE_FEATURES', 'tpm', 'tpm', '', d)}"
14PACKAGECONFIG += "${@bb.utils.contains('MACHINE_FEATURES', 'tpm2', 'tpm', '', d)}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015PACKAGECONFIG[secureboot] = ",,,"
Patrick Williams93c203f2021-10-06 16:15:23 -050016PACKAGECONFIG[tpm] = "-D TPM_ENABLE=TRUE,-D TPM_ENABLE=FALSE,,"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017
Andrew Geisslerc182c622020-05-15 14:13:32 -050018SRC_URI = "gitsm://github.com/tianocore/edk2.git;branch=master;protocol=https \
Andrew Geissler82c905d2020-04-13 13:39:40 -050019 file://0001-ovmf-update-path-to-native-BaseTools.patch \
20 file://0002-BaseTools-makefile-adjust-to-build-in-under-bitbake.patch \
Andrew Geissler09036742021-06-25 14:25:14 -050021 file://0003-ovmf-Update-to-latest.patch \
22 file://0004-Strip-build-paths.patch \
23 file://0005-debug-prefix-map.patch \
24 file://0006-reproducible.patch \
William A. Kennington IIIac69b482021-06-02 12:28:27 -070025 file://0001-Fix-VLA-parameter-warning.patch \
Andrew Geisslerd1e89492021-02-12 15:35:20 -060026 "
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027
Andrew Geissler09036742021-06-25 14:25:14 -050028PV = "edk2-stable202105"
29SRCREV = "e1999b264f1f9d7230edf2448f757c73da567832"
Brad Bishop08902b02019-08-20 09:16:51 -040030UPSTREAM_CHECK_GITTAGREGEX = "(?P<pver>edk2-stable.*)"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031
32inherit deploy
33
Brad Bishopd5ae7d92018-06-14 09:52:03 -070034PARALLEL_MAKE = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035
36S = "${WORKDIR}/git"
37
Brad Bishop1d80a2e2019-11-15 16:35:03 -050038DEPENDS = "nasm-native acpica-native ovmf-native util-linux-native"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050039
40EDK_TOOLS_DIR="edk2_basetools"
41
42# OVMF has trouble building with the default optimization of -O2.
43BUILD_OPTIMIZATION="-pipe"
44
45# OVMF supports IA only, although it could conceivably support ARM someday.
Patrick Williams213cb262021-08-07 19:21:33 -050046COMPATIBLE_HOST:class-target='(i.86|x86_64).*'
Brad Bishop6e60e8b2018-02-01 10:27:11 -050047
48# Additional build flags for OVMF with Secure Boot.
49# Fedora also uses "-D SMM_REQUIRE -D EXCLUDE_SHELL_FROM_FD".
50OVMF_SECURE_BOOT_EXTRA_FLAGS ??= ""
51OVMF_SECURE_BOOT_FLAGS = "-DSECURE_BOOT_ENABLE=TRUE ${OVMF_SECURE_BOOT_EXTRA_FLAGS}"
52
Brad Bishop08902b02019-08-20 09:16:51 -040053export PYTHON_COMMAND = "${HOSTTOOLS_DIR}/python3"
54
Brad Bishop6e60e8b2018-02-01 10:27:11 -050055do_patch[postfuncs] += "fix_basetools_location"
56fix_basetools_location () {
57}
Patrick Williams213cb262021-08-07 19:21:33 -050058fix_basetools_location:class-target() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 # Replaces the fake path inserted by 0002-ovmf-update-path-to-native-BaseTools.patch.
60 # Necessary for finding the actual BaseTools from ovmf-native.
61 sed -i -e 's#BBAKE_EDK_TOOLS_PATH#${STAGING_BINDIR_NATIVE}/${EDK_TOOLS_DIR}#' ${S}/OvmfPkg/build.sh
62}
63
64do_patch[postfuncs] += "fix_iasl"
65fix_iasl() {
66}
Patrick Williams213cb262021-08-07 19:21:33 -050067fix_iasl:class-native() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050068 # iasl is not installed under /usr/bin when building with OE.
69 sed -i -e 's#/usr/bin/iasl#${STAGING_BINDIR_NATIVE}/iasl#' ${S}/BaseTools/Conf/tools_def.template
70}
71
72# Inject CC and friends into the build. LINKER already is in GNUmakefile.
73# Must be idempotent and thus remove old assignments that were inserted
74# earlier.
75do_patch[postfuncs] += "fix_toolchain"
76fix_toolchain() {
77 sed -i \
78 -e '/^\(CC\|CXX\|AS\|AR\|LD\|LINKER\) =/d' \
79 -e '/^APPLICATION/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}\nLINKER = $(CC)' \
80 ${S}/BaseTools/Source/C/Makefiles/app.makefile
81 sed -i \
82 -e '/^\(CC\|CXX\|AS\|AR\|LD\)/d' \
83 -e '/^VFR_CPPFLAGS/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}' \
84 ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile
85}
Patrick Williams213cb262021-08-07 19:21:33 -050086fix_toolchain:append:class-native() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050087 # This tools_def.template is going to be used by the target ovmf and
88 # defines which compilers to use. For the GCC toolchain definitions,
89 # that will be ${HOST_PREFIX}gcc. However, "make" doesn't need that
90 # prefix.
91 #
92 # Injecting ENV(HOST_PREFIX) matches exporting that value as env
Patrick Williams213cb262021-08-07 19:21:33 -050093 # variable in do_compile:class-target.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 sed -i \
95 -e 's#\(ENV\|DEF\)(GCC.*_PREFIX)#ENV(HOST_PREFIX)#' \
96 -e 's#ENV(HOST_PREFIX)make#make#' \
97 ${S}/BaseTools/Conf/tools_def.template
98 sed -i \
99 -e '/^\(LFLAGS\|CFLAGS\) +=/d' \
100 -e '/^LINKER/a LFLAGS += ${BUILD_LDFLAGS}\nCFLAGS += ${BUILD_CFLAGS}' \
101 ${S}/BaseTools/Source/C/Makefiles/app.makefile \
102 ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile
103 # Linking with gold fails:
104 # internal error in do_layout, at ../../gold/object.cc:1821
105 # make: *** [.../OUTPUT/Facs.acpi] Error 1
106 # We intentionally hard-code the use of ld.bfd regardless of DISTRO_FEATURES
107 # to make ovmf-native reusable across distros.
108 sed -i \
109 -e 's#^\(DEFINE GCC.*DLINK.*FLAGS *=\)#\1 -fuse-ld=bfd#' \
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700110 -e 's#-flto#-fno-lto#g' \
111 -e 's#-DUSING_LTO##g' \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 ${S}/BaseTools/Conf/tools_def.template
113}
114
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700115# We disable lto above since the results are not reproducible and make it hard to compare
116# binary build aretfacts to debug reproducibility problems.
117# Surprisingly, if you disable lto, you see compiler warnings which are fatal. We therefore
118# have to hack warnings overrides into GCC_PREFIX_MAP to allow it to build.
119
120# We want to pass ${DEBUG_PREFIX_MAP} to gcc commands and also pass in
121# --debug-prefix-map to nasm (we carry a patch to nasm for this). The
122# tools definitions are built by ovmf-native so we need to pass this in
123# at target build time when we know the right values.
124export NASM_PREFIX_MAP = "--debug-prefix-map=${WORKDIR}=/usr/src/debug/ovmf/${EXTENDPE}${PV}-${PR}"
125export GCC_PREFIX_MAP = "${DEBUG_PREFIX_MAP} -Wno-stringop-overflow -Wno-maybe-uninitialized"
126
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127GCC_VER="$(${CC} -v 2>&1 | tail -n1 | awk '{print $3}')"
128
129fixup_target_tools() {
130 case ${1} in
131 4.4.*)
132 FIXED_GCCVER=GCC44
133 ;;
134 4.5.*)
135 FIXED_GCCVER=GCC45
136 ;;
137 4.6.*)
138 FIXED_GCCVER=GCC46
139 ;;
140 4.7.*)
141 FIXED_GCCVER=GCC47
142 ;;
143 4.8.*)
144 FIXED_GCCVER=GCC48
145 ;;
146 4.9.*)
147 FIXED_GCCVER=GCC49
148 ;;
149 *)
150 FIXED_GCCVER=GCC5
151 ;;
152 esac
153 echo ${FIXED_GCCVER}
154}
155
Patrick Williams213cb262021-08-07 19:21:33 -0500156do_compile:class-native() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500157 oe_runmake -C ${S}/BaseTools
158}
159
Patrick Williams213cb262021-08-07 19:21:33 -0500160do_compile:class-target() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500161 export LFLAGS="${LDFLAGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400162 PARALLEL_JOBS="${@oe.utils.parallel_make_argument(d, '-n %d')}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500163 OVMF_ARCH="X64"
164 if [ "${TARGET_ARCH}" != "x86_64" ] ; then
165 OVMF_ARCH="IA32"
166 fi
167
168 # The build for the target uses BaseTools/Conf/tools_def.template
169 # from ovmf-native to find the compiler, which depends on
170 # exporting HOST_PREFIX.
171 export HOST_PREFIX="${HOST_PREFIX}"
172
173 # BaseTools/Conf gets copied to Conf, but only if that does not
174 # exist yet. To ensure that an updated template gets used during
175 # incremental builds, we need to remove the copy before we start.
176 rm -f `ls ${S}/Conf/*.txt | grep -v ReadMe.txt`
177
178 # ${WORKDIR}/ovmf is a well-known location where do_install and
179 # do_deploy will be able to find the files.
180 rm -rf ${WORKDIR}/ovmf
181 mkdir ${WORKDIR}/ovmf
182 OVMF_DIR_SUFFIX="X64"
183 if [ "${TARGET_ARCH}" != "x86_64" ] ; then
184 OVMF_DIR_SUFFIX="Ia32" # Note the different capitalization
185 fi
186 FIXED_GCCVER=$(fixup_target_tools ${GCC_VER})
187 bbnote FIXED_GCCVER is ${FIXED_GCCVER}
188 build_dir="${S}/Build/Ovmf$OVMF_DIR_SUFFIX/RELEASE_${FIXED_GCCVER}"
189
190 bbnote "Building without Secure Boot."
191 rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX
Patrick Williams93c203f2021-10-06 16:15:23 -0500192 ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER} ${PACKAGECONFIG_CONFARGS}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500193 ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.fd
194 ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.code.fd
195 ln ${build_dir}/FV/OVMF_VARS.fd ${WORKDIR}/ovmf/ovmf.vars.fd
196 ln ${build_dir}/${OVMF_ARCH}/Shell.efi ${WORKDIR}/ovmf/
197
198 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
Brad Bishop08902b02019-08-20 09:16:51 -0400199 # Repeat build with the Secure Boot flags.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500200 bbnote "Building with Secure Boot."
201 rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX
Patrick Williams93c203f2021-10-06 16:15:23 -0500202 ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER} ${PACKAGECONFIG_CONFARGS} ${OVMF_SECURE_BOOT_FLAGS}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500203 ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.secboot.fd
204 ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.secboot.code.fd
205 ln ${build_dir}/${OVMF_ARCH}/EnrollDefaultKeys.efi ${WORKDIR}/ovmf/
206 fi
207}
208
Patrick Williams213cb262021-08-07 19:21:33 -0500209do_install:class-native() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500210 install -d ${D}/${bindir}/edk2_basetools
211 cp -r ${S}/BaseTools ${D}/${bindir}/${EDK_TOOLS_DIR}
212}
213
Patrick Williams213cb262021-08-07 19:21:33 -0500214do_install:class-target() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500215 # Content for UEFI shell iso. We install the EFI shell as
216 # bootx64/ia32.efi because then it can be started even when the
217 # firmware itself does not contain it.
218 install -d ${D}/efi/boot
219 install ${WORKDIR}/ovmf/Shell.efi ${D}/efi/boot/boot${@ "ia32" if "${TARGET_ARCH}" != "x86_64" else "x64"}.efi
220 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
221 install ${WORKDIR}/ovmf/EnrollDefaultKeys.efi ${D}
222 fi
223}
224
225# This always gets packaged because ovmf-shell-image depends on it.
226# This allows testing that recipe in all configurations because it
227# can always be part of a world build.
228#
229# However, EnrollDefaultKeys.efi is only included when Secure Boot is enabled.
230PACKAGES =+ "ovmf-shell-efi"
Patrick Williams213cb262021-08-07 19:21:33 -0500231FILES:ovmf-shell-efi = " \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500232 EnrollDefaultKeys.efi \
233 efi/ \
234"
235
Brad Bishop19323692019-04-05 15:28:33 -0400236DEPLOYDEP = ""
Patrick Williams213cb262021-08-07 19:21:33 -0500237DEPLOYDEP:class-target = "qemu-system-native:do_populate_sysroot"
238DEPLOYDEP:class-target += " ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'openssl-native:do_populate_sysroot', '', d)}"
Brad Bishop19323692019-04-05 15:28:33 -0400239do_deploy[depends] += "${DEPLOYDEP}"
240
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500241do_deploy() {
242}
Patrick Williams213cb262021-08-07 19:21:33 -0500243do_deploy:class-target() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500244 # For use with "runqemu ovmf".
245 for i in \
246 ovmf \
247 ovmf.code \
248 ovmf.vars \
249 ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'ovmf.secboot ovmf.secboot.code', '', d)} \
250 ; do
251 qemu-img convert -f raw -O qcow2 ${WORKDIR}/ovmf/$i.fd ${DEPLOYDIR}/$i.qcow2
252 done
Brad Bishop08902b02019-08-20 09:16:51 -0400253
254 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
255 # Create a test Platform Key and first Key Exchange Key to use with EnrollDefaultKeys
256 openssl req -new -x509 -newkey rsa:2048 -keyout ${DEPLOYDIR}/OvmfPkKek1.key \
257 -out ${DEPLOYDIR}/OvmfPkKek1.crt -nodes -days 20 -subj "/CN=OVMFSecBootTest"
258 openssl x509 -in ${DEPLOYDIR}/OvmfPkKek1.crt -out ${DEPLOYDIR}/OvmfPkKek1.pem -outform PEM
259 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500260}
261addtask do_deploy after do_compile before do_build
262
263BBCLASSEXTEND = "native"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500264TOOLCHAIN = "gcc"