blob: 91c1b6ba14b541d25c2f692a86c6fc41b2dbcd35 [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"
Brad Bishop6e60e8b2018-02-01 10:27:11 -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 \
18 file://0003-ovmf-enable-long-path-file.patch \
Andrew Geisslerc182c622020-05-15 14:13:32 -050019 file://0001-ovmf-Update-to-latest.patch \
Brad Bishop6e60e8b2018-02-01 10:27:11 -050020 "
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021
Andrew Geissler5a43b432020-06-13 10:46:56 -050022PV = "edk2-stable202005"
23SRCREV = "ca407c7246bf405da6d9b1b9d93e5e7f17b4b1f9"
Brad Bishop08902b02019-08-20 09:16:51 -040024UPSTREAM_CHECK_GITTAGREGEX = "(?P<pver>edk2-stable.*)"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025
26inherit deploy
27
Brad Bishopd5ae7d92018-06-14 09:52:03 -070028PARALLEL_MAKE = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029
30S = "${WORKDIR}/git"
31
Brad Bishop1d80a2e2019-11-15 16:35:03 -050032DEPENDS = "nasm-native acpica-native ovmf-native util-linux-native"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033
34EDK_TOOLS_DIR="edk2_basetools"
35
36# OVMF has trouble building with the default optimization of -O2.
37BUILD_OPTIMIZATION="-pipe"
38
39# OVMF supports IA only, although it could conceivably support ARM someday.
40COMPATIBLE_HOST='(i.86|x86_64).*'
41
42# Additional build flags for OVMF with Secure Boot.
43# Fedora also uses "-D SMM_REQUIRE -D EXCLUDE_SHELL_FROM_FD".
44OVMF_SECURE_BOOT_EXTRA_FLAGS ??= ""
45OVMF_SECURE_BOOT_FLAGS = "-DSECURE_BOOT_ENABLE=TRUE ${OVMF_SECURE_BOOT_EXTRA_FLAGS}"
46
Brad Bishop08902b02019-08-20 09:16:51 -040047export PYTHON_COMMAND = "${HOSTTOOLS_DIR}/python3"
48
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049do_patch[postfuncs] += "fix_basetools_location"
50fix_basetools_location () {
51}
52fix_basetools_location_class-target() {
53 # Replaces the fake path inserted by 0002-ovmf-update-path-to-native-BaseTools.patch.
54 # Necessary for finding the actual BaseTools from ovmf-native.
55 sed -i -e 's#BBAKE_EDK_TOOLS_PATH#${STAGING_BINDIR_NATIVE}/${EDK_TOOLS_DIR}#' ${S}/OvmfPkg/build.sh
56}
57
58do_patch[postfuncs] += "fix_iasl"
59fix_iasl() {
60}
61fix_iasl_class-native() {
62 # iasl is not installed under /usr/bin when building with OE.
63 sed -i -e 's#/usr/bin/iasl#${STAGING_BINDIR_NATIVE}/iasl#' ${S}/BaseTools/Conf/tools_def.template
64}
65
66# Inject CC and friends into the build. LINKER already is in GNUmakefile.
67# Must be idempotent and thus remove old assignments that were inserted
68# earlier.
69do_patch[postfuncs] += "fix_toolchain"
70fix_toolchain() {
71 sed -i \
72 -e '/^\(CC\|CXX\|AS\|AR\|LD\|LINKER\) =/d' \
73 -e '/^APPLICATION/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}\nLINKER = $(CC)' \
74 ${S}/BaseTools/Source/C/Makefiles/app.makefile
75 sed -i \
76 -e '/^\(CC\|CXX\|AS\|AR\|LD\)/d' \
77 -e '/^VFR_CPPFLAGS/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}' \
78 ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile
79}
80fix_toolchain_append_class-native() {
81 # This tools_def.template is going to be used by the target ovmf and
82 # defines which compilers to use. For the GCC toolchain definitions,
83 # that will be ${HOST_PREFIX}gcc. However, "make" doesn't need that
84 # prefix.
85 #
86 # Injecting ENV(HOST_PREFIX) matches exporting that value as env
87 # variable in do_compile_class-target.
88 sed -i \
89 -e 's#\(ENV\|DEF\)(GCC.*_PREFIX)#ENV(HOST_PREFIX)#' \
90 -e 's#ENV(HOST_PREFIX)make#make#' \
91 ${S}/BaseTools/Conf/tools_def.template
92 sed -i \
93 -e '/^\(LFLAGS\|CFLAGS\) +=/d' \
94 -e '/^LINKER/a LFLAGS += ${BUILD_LDFLAGS}\nCFLAGS += ${BUILD_CFLAGS}' \
95 ${S}/BaseTools/Source/C/Makefiles/app.makefile \
96 ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile
97 # Linking with gold fails:
98 # internal error in do_layout, at ../../gold/object.cc:1821
99 # make: *** [.../OUTPUT/Facs.acpi] Error 1
100 # We intentionally hard-code the use of ld.bfd regardless of DISTRO_FEATURES
101 # to make ovmf-native reusable across distros.
102 sed -i \
103 -e 's#^\(DEFINE GCC.*DLINK.*FLAGS *=\)#\1 -fuse-ld=bfd#' \
104 ${S}/BaseTools/Conf/tools_def.template
105}
106
107GCC_VER="$(${CC} -v 2>&1 | tail -n1 | awk '{print $3}')"
108
109fixup_target_tools() {
110 case ${1} in
111 4.4.*)
112 FIXED_GCCVER=GCC44
113 ;;
114 4.5.*)
115 FIXED_GCCVER=GCC45
116 ;;
117 4.6.*)
118 FIXED_GCCVER=GCC46
119 ;;
120 4.7.*)
121 FIXED_GCCVER=GCC47
122 ;;
123 4.8.*)
124 FIXED_GCCVER=GCC48
125 ;;
126 4.9.*)
127 FIXED_GCCVER=GCC49
128 ;;
129 *)
130 FIXED_GCCVER=GCC5
131 ;;
132 esac
133 echo ${FIXED_GCCVER}
134}
135
136do_compile_class-native() {
137 oe_runmake -C ${S}/BaseTools
138}
139
140do_compile_class-target() {
141 export LFLAGS="${LDFLAGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400142 PARALLEL_JOBS="${@oe.utils.parallel_make_argument(d, '-n %d')}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500143 OVMF_ARCH="X64"
144 if [ "${TARGET_ARCH}" != "x86_64" ] ; then
145 OVMF_ARCH="IA32"
146 fi
147
148 # The build for the target uses BaseTools/Conf/tools_def.template
149 # from ovmf-native to find the compiler, which depends on
150 # exporting HOST_PREFIX.
151 export HOST_PREFIX="${HOST_PREFIX}"
152
153 # BaseTools/Conf gets copied to Conf, but only if that does not
154 # exist yet. To ensure that an updated template gets used during
155 # incremental builds, we need to remove the copy before we start.
156 rm -f `ls ${S}/Conf/*.txt | grep -v ReadMe.txt`
157
158 # ${WORKDIR}/ovmf is a well-known location where do_install and
159 # do_deploy will be able to find the files.
160 rm -rf ${WORKDIR}/ovmf
161 mkdir ${WORKDIR}/ovmf
162 OVMF_DIR_SUFFIX="X64"
163 if [ "${TARGET_ARCH}" != "x86_64" ] ; then
164 OVMF_DIR_SUFFIX="Ia32" # Note the different capitalization
165 fi
166 FIXED_GCCVER=$(fixup_target_tools ${GCC_VER})
167 bbnote FIXED_GCCVER is ${FIXED_GCCVER}
168 build_dir="${S}/Build/Ovmf$OVMF_DIR_SUFFIX/RELEASE_${FIXED_GCCVER}"
169
170 bbnote "Building without Secure Boot."
171 rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX
172 ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER}
173 ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.fd
174 ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.code.fd
175 ln ${build_dir}/FV/OVMF_VARS.fd ${WORKDIR}/ovmf/ovmf.vars.fd
176 ln ${build_dir}/${OVMF_ARCH}/Shell.efi ${WORKDIR}/ovmf/
177
178 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
Brad Bishop08902b02019-08-20 09:16:51 -0400179 # Repeat build with the Secure Boot flags.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500180 bbnote "Building with Secure Boot."
181 rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500182 ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER} ${OVMF_SECURE_BOOT_FLAGS}
183 ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.secboot.fd
184 ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.secboot.code.fd
185 ln ${build_dir}/${OVMF_ARCH}/EnrollDefaultKeys.efi ${WORKDIR}/ovmf/
186 fi
187}
188
189do_install_class-native() {
190 install -d ${D}/${bindir}/edk2_basetools
191 cp -r ${S}/BaseTools ${D}/${bindir}/${EDK_TOOLS_DIR}
192}
193
194do_install_class-target() {
195 # Content for UEFI shell iso. We install the EFI shell as
196 # bootx64/ia32.efi because then it can be started even when the
197 # firmware itself does not contain it.
198 install -d ${D}/efi/boot
199 install ${WORKDIR}/ovmf/Shell.efi ${D}/efi/boot/boot${@ "ia32" if "${TARGET_ARCH}" != "x86_64" else "x64"}.efi
200 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
201 install ${WORKDIR}/ovmf/EnrollDefaultKeys.efi ${D}
202 fi
203}
204
205# This always gets packaged because ovmf-shell-image depends on it.
206# This allows testing that recipe in all configurations because it
207# can always be part of a world build.
208#
209# However, EnrollDefaultKeys.efi is only included when Secure Boot is enabled.
210PACKAGES =+ "ovmf-shell-efi"
211FILES_ovmf-shell-efi = " \
212 EnrollDefaultKeys.efi \
213 efi/ \
214"
215
Brad Bishop19323692019-04-05 15:28:33 -0400216DEPLOYDEP = ""
217DEPLOYDEP_class-target = "qemu-system-native:do_populate_sysroot"
Brad Bishop08902b02019-08-20 09:16:51 -0400218DEPLOYDEP_class-target += " ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'openssl-native:do_populate_sysroot', '', d)}"
Brad Bishop19323692019-04-05 15:28:33 -0400219do_deploy[depends] += "${DEPLOYDEP}"
220
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500221do_deploy() {
222}
223do_deploy[cleandirs] = "${DEPLOYDIR}"
224do_deploy_class-target() {
225 # For use with "runqemu ovmf".
226 for i in \
227 ovmf \
228 ovmf.code \
229 ovmf.vars \
230 ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'ovmf.secboot ovmf.secboot.code', '', d)} \
231 ; do
232 qemu-img convert -f raw -O qcow2 ${WORKDIR}/ovmf/$i.fd ${DEPLOYDIR}/$i.qcow2
233 done
Brad Bishop08902b02019-08-20 09:16:51 -0400234
235 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
236 # Create a test Platform Key and first Key Exchange Key to use with EnrollDefaultKeys
237 openssl req -new -x509 -newkey rsa:2048 -keyout ${DEPLOYDIR}/OvmfPkKek1.key \
238 -out ${DEPLOYDIR}/OvmfPkKek1.crt -nodes -days 20 -subj "/CN=OVMFSecBootTest"
239 openssl x509 -in ${DEPLOYDIR}/OvmfPkKek1.crt -out ${DEPLOYDIR}/OvmfPkKek1.pem -outform PEM
240 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500241}
242addtask do_deploy after do_compile before do_build
243
244BBCLASSEXTEND = "native"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500245TOOLCHAIN = "gcc"