blob: 145240e77e899dfce5e79b7ad89b365a3e0bdb0d [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"
Brad Bishopf3f93bb2019-10-16 14:33:32 -04005LICENSE = "BSD-2-Clause"
Patrick Williams213cb262021-08-07 19:21:33 -05006LICENSE:class-target = "${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'BSD & OpenSSL', 'BSD', 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 ??= ""
13PACKAGECONFIG[secureboot] = ",,,"
14
Andrew Geisslerc182c622020-05-15 14:13:32 -050015SRC_URI = "gitsm://github.com/tianocore/edk2.git;branch=master;protocol=https \
Andrew Geissler82c905d2020-04-13 13:39:40 -050016 file://0001-ovmf-update-path-to-native-BaseTools.patch \
17 file://0002-BaseTools-makefile-adjust-to-build-in-under-bitbake.patch \
Andrew Geissler09036742021-06-25 14:25:14 -050018 file://0003-ovmf-Update-to-latest.patch \
19 file://0004-Strip-build-paths.patch \
20 file://0005-debug-prefix-map.patch \
21 file://0006-reproducible.patch \
William A. Kennington IIIac69b482021-06-02 12:28:27 -070022 file://0001-Fix-VLA-parameter-warning.patch \
Andrew Geisslerd1e89492021-02-12 15:35:20 -060023 "
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024
Andrew Geissler09036742021-06-25 14:25:14 -050025PV = "edk2-stable202105"
26SRCREV = "e1999b264f1f9d7230edf2448f757c73da567832"
Brad Bishop08902b02019-08-20 09:16:51 -040027UPSTREAM_CHECK_GITTAGREGEX = "(?P<pver>edk2-stable.*)"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028
29inherit deploy
30
Brad Bishopd5ae7d92018-06-14 09:52:03 -070031PARALLEL_MAKE = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032
33S = "${WORKDIR}/git"
34
Brad Bishop1d80a2e2019-11-15 16:35:03 -050035DEPENDS = "nasm-native acpica-native ovmf-native util-linux-native"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036
37EDK_TOOLS_DIR="edk2_basetools"
38
39# OVMF has trouble building with the default optimization of -O2.
40BUILD_OPTIMIZATION="-pipe"
41
42# OVMF supports IA only, although it could conceivably support ARM someday.
Patrick Williams213cb262021-08-07 19:21:33 -050043COMPATIBLE_HOST:class-target='(i.86|x86_64).*'
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044
45# Additional build flags for OVMF with Secure Boot.
46# Fedora also uses "-D SMM_REQUIRE -D EXCLUDE_SHELL_FROM_FD".
47OVMF_SECURE_BOOT_EXTRA_FLAGS ??= ""
48OVMF_SECURE_BOOT_FLAGS = "-DSECURE_BOOT_ENABLE=TRUE ${OVMF_SECURE_BOOT_EXTRA_FLAGS}"
49
Brad Bishop08902b02019-08-20 09:16:51 -040050export PYTHON_COMMAND = "${HOSTTOOLS_DIR}/python3"
51
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052do_patch[postfuncs] += "fix_basetools_location"
53fix_basetools_location () {
54}
Patrick Williams213cb262021-08-07 19:21:33 -050055fix_basetools_location:class-target() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056 # Replaces the fake path inserted by 0002-ovmf-update-path-to-native-BaseTools.patch.
57 # Necessary for finding the actual BaseTools from ovmf-native.
58 sed -i -e 's#BBAKE_EDK_TOOLS_PATH#${STAGING_BINDIR_NATIVE}/${EDK_TOOLS_DIR}#' ${S}/OvmfPkg/build.sh
59}
60
61do_patch[postfuncs] += "fix_iasl"
62fix_iasl() {
63}
Patrick Williams213cb262021-08-07 19:21:33 -050064fix_iasl:class-native() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 # iasl is not installed under /usr/bin when building with OE.
66 sed -i -e 's#/usr/bin/iasl#${STAGING_BINDIR_NATIVE}/iasl#' ${S}/BaseTools/Conf/tools_def.template
67}
68
69# Inject CC and friends into the build. LINKER already is in GNUmakefile.
70# Must be idempotent and thus remove old assignments that were inserted
71# earlier.
72do_patch[postfuncs] += "fix_toolchain"
73fix_toolchain() {
74 sed -i \
75 -e '/^\(CC\|CXX\|AS\|AR\|LD\|LINKER\) =/d' \
76 -e '/^APPLICATION/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}\nLINKER = $(CC)' \
77 ${S}/BaseTools/Source/C/Makefiles/app.makefile
78 sed -i \
79 -e '/^\(CC\|CXX\|AS\|AR\|LD\)/d' \
80 -e '/^VFR_CPPFLAGS/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}' \
81 ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile
82}
Patrick Williams213cb262021-08-07 19:21:33 -050083fix_toolchain:append:class-native() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050084 # This tools_def.template is going to be used by the target ovmf and
85 # defines which compilers to use. For the GCC toolchain definitions,
86 # that will be ${HOST_PREFIX}gcc. However, "make" doesn't need that
87 # prefix.
88 #
89 # Injecting ENV(HOST_PREFIX) matches exporting that value as env
Patrick Williams213cb262021-08-07 19:21:33 -050090 # variable in do_compile:class-target.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050091 sed -i \
92 -e 's#\(ENV\|DEF\)(GCC.*_PREFIX)#ENV(HOST_PREFIX)#' \
93 -e 's#ENV(HOST_PREFIX)make#make#' \
94 ${S}/BaseTools/Conf/tools_def.template
95 sed -i \
96 -e '/^\(LFLAGS\|CFLAGS\) +=/d' \
97 -e '/^LINKER/a LFLAGS += ${BUILD_LDFLAGS}\nCFLAGS += ${BUILD_CFLAGS}' \
98 ${S}/BaseTools/Source/C/Makefiles/app.makefile \
99 ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile
100 # Linking with gold fails:
101 # internal error in do_layout, at ../../gold/object.cc:1821
102 # make: *** [.../OUTPUT/Facs.acpi] Error 1
103 # We intentionally hard-code the use of ld.bfd regardless of DISTRO_FEATURES
104 # to make ovmf-native reusable across distros.
105 sed -i \
106 -e 's#^\(DEFINE GCC.*DLINK.*FLAGS *=\)#\1 -fuse-ld=bfd#' \
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700107 -e 's#-flto#-fno-lto#g' \
108 -e 's#-DUSING_LTO##g' \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 ${S}/BaseTools/Conf/tools_def.template
110}
111
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700112# We disable lto above since the results are not reproducible and make it hard to compare
113# binary build aretfacts to debug reproducibility problems.
114# Surprisingly, if you disable lto, you see compiler warnings which are fatal. We therefore
115# have to hack warnings overrides into GCC_PREFIX_MAP to allow it to build.
116
117# We want to pass ${DEBUG_PREFIX_MAP} to gcc commands and also pass in
118# --debug-prefix-map to nasm (we carry a patch to nasm for this). The
119# tools definitions are built by ovmf-native so we need to pass this in
120# at target build time when we know the right values.
121export NASM_PREFIX_MAP = "--debug-prefix-map=${WORKDIR}=/usr/src/debug/ovmf/${EXTENDPE}${PV}-${PR}"
122export GCC_PREFIX_MAP = "${DEBUG_PREFIX_MAP} -Wno-stringop-overflow -Wno-maybe-uninitialized"
123
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124GCC_VER="$(${CC} -v 2>&1 | tail -n1 | awk '{print $3}')"
125
126fixup_target_tools() {
127 case ${1} in
128 4.4.*)
129 FIXED_GCCVER=GCC44
130 ;;
131 4.5.*)
132 FIXED_GCCVER=GCC45
133 ;;
134 4.6.*)
135 FIXED_GCCVER=GCC46
136 ;;
137 4.7.*)
138 FIXED_GCCVER=GCC47
139 ;;
140 4.8.*)
141 FIXED_GCCVER=GCC48
142 ;;
143 4.9.*)
144 FIXED_GCCVER=GCC49
145 ;;
146 *)
147 FIXED_GCCVER=GCC5
148 ;;
149 esac
150 echo ${FIXED_GCCVER}
151}
152
Patrick Williams213cb262021-08-07 19:21:33 -0500153do_compile:class-native() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500154 oe_runmake -C ${S}/BaseTools
155}
156
Patrick Williams213cb262021-08-07 19:21:33 -0500157do_compile:class-target() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500158 export LFLAGS="${LDFLAGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400159 PARALLEL_JOBS="${@oe.utils.parallel_make_argument(d, '-n %d')}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500160 OVMF_ARCH="X64"
161 if [ "${TARGET_ARCH}" != "x86_64" ] ; then
162 OVMF_ARCH="IA32"
163 fi
164
165 # The build for the target uses BaseTools/Conf/tools_def.template
166 # from ovmf-native to find the compiler, which depends on
167 # exporting HOST_PREFIX.
168 export HOST_PREFIX="${HOST_PREFIX}"
169
170 # BaseTools/Conf gets copied to Conf, but only if that does not
171 # exist yet. To ensure that an updated template gets used during
172 # incremental builds, we need to remove the copy before we start.
173 rm -f `ls ${S}/Conf/*.txt | grep -v ReadMe.txt`
174
175 # ${WORKDIR}/ovmf is a well-known location where do_install and
176 # do_deploy will be able to find the files.
177 rm -rf ${WORKDIR}/ovmf
178 mkdir ${WORKDIR}/ovmf
179 OVMF_DIR_SUFFIX="X64"
180 if [ "${TARGET_ARCH}" != "x86_64" ] ; then
181 OVMF_DIR_SUFFIX="Ia32" # Note the different capitalization
182 fi
183 FIXED_GCCVER=$(fixup_target_tools ${GCC_VER})
184 bbnote FIXED_GCCVER is ${FIXED_GCCVER}
185 build_dir="${S}/Build/Ovmf$OVMF_DIR_SUFFIX/RELEASE_${FIXED_GCCVER}"
186
187 bbnote "Building without Secure Boot."
188 rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX
189 ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER}
190 ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.fd
191 ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.code.fd
192 ln ${build_dir}/FV/OVMF_VARS.fd ${WORKDIR}/ovmf/ovmf.vars.fd
193 ln ${build_dir}/${OVMF_ARCH}/Shell.efi ${WORKDIR}/ovmf/
194
195 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
Brad Bishop08902b02019-08-20 09:16:51 -0400196 # Repeat build with the Secure Boot flags.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500197 bbnote "Building with Secure Boot."
198 rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500199 ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER} ${OVMF_SECURE_BOOT_FLAGS}
200 ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.secboot.fd
201 ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.secboot.code.fd
202 ln ${build_dir}/${OVMF_ARCH}/EnrollDefaultKeys.efi ${WORKDIR}/ovmf/
203 fi
204}
205
Patrick Williams213cb262021-08-07 19:21:33 -0500206do_install:class-native() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500207 install -d ${D}/${bindir}/edk2_basetools
208 cp -r ${S}/BaseTools ${D}/${bindir}/${EDK_TOOLS_DIR}
209}
210
Patrick Williams213cb262021-08-07 19:21:33 -0500211do_install:class-target() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500212 # Content for UEFI shell iso. We install the EFI shell as
213 # bootx64/ia32.efi because then it can be started even when the
214 # firmware itself does not contain it.
215 install -d ${D}/efi/boot
216 install ${WORKDIR}/ovmf/Shell.efi ${D}/efi/boot/boot${@ "ia32" if "${TARGET_ARCH}" != "x86_64" else "x64"}.efi
217 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
218 install ${WORKDIR}/ovmf/EnrollDefaultKeys.efi ${D}
219 fi
220}
221
222# This always gets packaged because ovmf-shell-image depends on it.
223# This allows testing that recipe in all configurations because it
224# can always be part of a world build.
225#
226# However, EnrollDefaultKeys.efi is only included when Secure Boot is enabled.
227PACKAGES =+ "ovmf-shell-efi"
Patrick Williams213cb262021-08-07 19:21:33 -0500228FILES:ovmf-shell-efi = " \
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500229 EnrollDefaultKeys.efi \
230 efi/ \
231"
232
Brad Bishop19323692019-04-05 15:28:33 -0400233DEPLOYDEP = ""
Patrick Williams213cb262021-08-07 19:21:33 -0500234DEPLOYDEP:class-target = "qemu-system-native:do_populate_sysroot"
235DEPLOYDEP:class-target += " ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'openssl-native:do_populate_sysroot', '', d)}"
Brad Bishop19323692019-04-05 15:28:33 -0400236do_deploy[depends] += "${DEPLOYDEP}"
237
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500238do_deploy() {
239}
Patrick Williams213cb262021-08-07 19:21:33 -0500240do_deploy:class-target() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500241 # For use with "runqemu ovmf".
242 for i in \
243 ovmf \
244 ovmf.code \
245 ovmf.vars \
246 ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'ovmf.secboot ovmf.secboot.code', '', d)} \
247 ; do
248 qemu-img convert -f raw -O qcow2 ${WORKDIR}/ovmf/$i.fd ${DEPLOYDIR}/$i.qcow2
249 done
Brad Bishop08902b02019-08-20 09:16:51 -0400250
251 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
252 # Create a test Platform Key and first Key Exchange Key to use with EnrollDefaultKeys
253 openssl req -new -x509 -newkey rsa:2048 -keyout ${DEPLOYDIR}/OvmfPkKek1.key \
254 -out ${DEPLOYDIR}/OvmfPkKek1.crt -nodes -days 20 -subj "/CN=OVMFSecBootTest"
255 openssl x509 -in ${DEPLOYDIR}/OvmfPkKek1.crt -out ${DEPLOYDIR}/OvmfPkKek1.pem -outform PEM
256 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500257}
258addtask do_deploy after do_compile before do_build
259
260BBCLASSEXTEND = "native"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500261TOOLCHAIN = "gcc"