Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | SUMMARY = "OVMF - UEFI firmware for Qemu and KVM" |
| 2 | DESCRIPTION = "OVMF is an EDK II based project to enable UEFI support for \ |
| 3 | Virtual Machines. OVMF contains sample UEFI firmware for QEMU and KVM" |
| 4 | HOMEPAGE = "https://github.com/tianocore/tianocore.github.io/wiki/OVMF" |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 5 | LICENSE = "BSD-2-Clause-Patent" |
| 6 | LICENSE:class-target = "${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'BSD-2-Clause-Patent & OpenSSL', 'BSD-2-Clause-Patent', d)}" |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 7 | LIC_FILES_CHKSUM = "file://OvmfPkg/License.txt;md5=06357ddc23f46577c2aeaeaf7b776d65" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8 | |
| 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. |
| 12 | PACKAGECONFIG ??= "" |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 13 | PACKAGECONFIG += "${@bb.utils.contains('MACHINE_FEATURES', 'tpm', 'tpm', '', d)}" |
| 14 | PACKAGECONFIG += "${@bb.utils.contains('MACHINE_FEATURES', 'tpm2', 'tpm', '', d)}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | PACKAGECONFIG[secureboot] = ",,," |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 16 | PACKAGECONFIG[tpm] = "-D TPM_ENABLE=TRUE,-D TPM_ENABLE=FALSE,," |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 17 | |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 18 | # GCC12 trips on it |
| 19 | #see https://src.fedoraproject.org/rpms/edk2/blob/rawhide/f/0032-Basetools-turn-off-gcc12-warning.patch |
| 20 | BUILD_CFLAGS += "-Wno-error=stringop-overflow" |
| 21 | |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 22 | SRC_URI = "gitsm://github.com/tianocore/edk2.git;branch=master;protocol=https \ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 23 | file://0001-ovmf-update-path-to-native-BaseTools.patch \ |
| 24 | file://0002-BaseTools-makefile-adjust-to-build-in-under-bitbake.patch \ |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 25 | file://0005-debug-prefix-map.patch \ |
| 26 | file://0006-reproducible.patch \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 27 | " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 28 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 29 | PV = "edk2-stable202211" |
| 30 | SRCREV = "fff6d81270b57ee786ea18ad74f43149b9f03494" |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 31 | UPSTREAM_CHECK_GITTAGREGEX = "(?P<pver>edk2-stable.*)" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 32 | |
| 33 | inherit deploy |
| 34 | |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 35 | PARALLEL_MAKE = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | |
| 37 | S = "${WORKDIR}/git" |
| 38 | |
Brad Bishop | 1d80a2e | 2019-11-15 16:35:03 -0500 | [diff] [blame] | 39 | DEPENDS = "nasm-native acpica-native ovmf-native util-linux-native" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 40 | |
| 41 | EDK_TOOLS_DIR="edk2_basetools" |
| 42 | |
| 43 | # OVMF has trouble building with the default optimization of -O2. |
| 44 | BUILD_OPTIMIZATION="-pipe" |
| 45 | |
| 46 | # OVMF supports IA only, although it could conceivably support ARM someday. |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 47 | COMPATIBLE_HOST:class-target='(i.86|x86_64).*' |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | |
| 49 | # Additional build flags for OVMF with Secure Boot. |
| 50 | # Fedora also uses "-D SMM_REQUIRE -D EXCLUDE_SHELL_FROM_FD". |
| 51 | OVMF_SECURE_BOOT_EXTRA_FLAGS ??= "" |
| 52 | OVMF_SECURE_BOOT_FLAGS = "-DSECURE_BOOT_ENABLE=TRUE ${OVMF_SECURE_BOOT_EXTRA_FLAGS}" |
| 53 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 54 | export PYTHON_COMMAND = "${HOSTTOOLS_DIR}/python3" |
| 55 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | do_patch[postfuncs] += "fix_basetools_location" |
| 57 | fix_basetools_location () { |
| 58 | } |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 59 | fix_basetools_location:class-target() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | # Replaces the fake path inserted by 0002-ovmf-update-path-to-native-BaseTools.patch. |
| 61 | # Necessary for finding the actual BaseTools from ovmf-native. |
| 62 | sed -i -e 's#BBAKE_EDK_TOOLS_PATH#${STAGING_BINDIR_NATIVE}/${EDK_TOOLS_DIR}#' ${S}/OvmfPkg/build.sh |
| 63 | } |
| 64 | |
| 65 | do_patch[postfuncs] += "fix_iasl" |
| 66 | fix_iasl() { |
| 67 | } |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 68 | fix_iasl:class-native() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 69 | # iasl is not installed under /usr/bin when building with OE. |
| 70 | sed -i -e 's#/usr/bin/iasl#${STAGING_BINDIR_NATIVE}/iasl#' ${S}/BaseTools/Conf/tools_def.template |
| 71 | } |
| 72 | |
| 73 | # Inject CC and friends into the build. LINKER already is in GNUmakefile. |
| 74 | # Must be idempotent and thus remove old assignments that were inserted |
| 75 | # earlier. |
| 76 | do_patch[postfuncs] += "fix_toolchain" |
| 77 | fix_toolchain() { |
| 78 | sed -i \ |
| 79 | -e '/^\(CC\|CXX\|AS\|AR\|LD\|LINKER\) =/d' \ |
| 80 | -e '/^APPLICATION/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}\nLINKER = $(CC)' \ |
| 81 | ${S}/BaseTools/Source/C/Makefiles/app.makefile |
| 82 | sed -i \ |
| 83 | -e '/^\(CC\|CXX\|AS\|AR\|LD\)/d' \ |
| 84 | -e '/^VFR_CPPFLAGS/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}' \ |
| 85 | ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile |
| 86 | } |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 87 | fix_toolchain:append:class-native() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 88 | # This tools_def.template is going to be used by the target ovmf and |
| 89 | # defines which compilers to use. For the GCC toolchain definitions, |
| 90 | # that will be ${HOST_PREFIX}gcc. However, "make" doesn't need that |
| 91 | # prefix. |
| 92 | # |
| 93 | # Injecting ENV(HOST_PREFIX) matches exporting that value as env |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 94 | # variable in do_compile:class-target. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 95 | sed -i \ |
| 96 | -e 's#\(ENV\|DEF\)(GCC.*_PREFIX)#ENV(HOST_PREFIX)#' \ |
| 97 | -e 's#ENV(HOST_PREFIX)make#make#' \ |
| 98 | ${S}/BaseTools/Conf/tools_def.template |
| 99 | sed -i \ |
| 100 | -e '/^\(LFLAGS\|CFLAGS\) +=/d' \ |
| 101 | -e '/^LINKER/a LFLAGS += ${BUILD_LDFLAGS}\nCFLAGS += ${BUILD_CFLAGS}' \ |
| 102 | ${S}/BaseTools/Source/C/Makefiles/app.makefile \ |
| 103 | ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile |
| 104 | # Linking with gold fails: |
| 105 | # internal error in do_layout, at ../../gold/object.cc:1821 |
| 106 | # make: *** [.../OUTPUT/Facs.acpi] Error 1 |
| 107 | # We intentionally hard-code the use of ld.bfd regardless of DISTRO_FEATURES |
| 108 | # to make ovmf-native reusable across distros. |
| 109 | sed -i \ |
| 110 | -e 's#^\(DEFINE GCC.*DLINK.*FLAGS *=\)#\1 -fuse-ld=bfd#' \ |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 111 | -e 's#-flto#-fno-lto#g' \ |
| 112 | -e 's#-DUSING_LTO##g' \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 113 | ${S}/BaseTools/Conf/tools_def.template |
| 114 | } |
| 115 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 116 | # We disable lto above since the results are not reproducible and make it hard to compare |
| 117 | # binary build aretfacts to debug reproducibility problems. |
| 118 | # Surprisingly, if you disable lto, you see compiler warnings which are fatal. We therefore |
| 119 | # have to hack warnings overrides into GCC_PREFIX_MAP to allow it to build. |
| 120 | |
| 121 | # We want to pass ${DEBUG_PREFIX_MAP} to gcc commands and also pass in |
| 122 | # --debug-prefix-map to nasm (we carry a patch to nasm for this). The |
| 123 | # tools definitions are built by ovmf-native so we need to pass this in |
| 124 | # at target build time when we know the right values. |
| 125 | export NASM_PREFIX_MAP = "--debug-prefix-map=${WORKDIR}=/usr/src/debug/ovmf/${EXTENDPE}${PV}-${PR}" |
| 126 | export GCC_PREFIX_MAP = "${DEBUG_PREFIX_MAP} -Wno-stringop-overflow -Wno-maybe-uninitialized" |
| 127 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 128 | GCC_VER="$(${CC} -v 2>&1 | tail -n1 | awk '{print $3}')" |
| 129 | |
| 130 | fixup_target_tools() { |
| 131 | case ${1} in |
| 132 | 4.4.*) |
| 133 | FIXED_GCCVER=GCC44 |
| 134 | ;; |
| 135 | 4.5.*) |
| 136 | FIXED_GCCVER=GCC45 |
| 137 | ;; |
| 138 | 4.6.*) |
| 139 | FIXED_GCCVER=GCC46 |
| 140 | ;; |
| 141 | 4.7.*) |
| 142 | FIXED_GCCVER=GCC47 |
| 143 | ;; |
| 144 | 4.8.*) |
| 145 | FIXED_GCCVER=GCC48 |
| 146 | ;; |
| 147 | 4.9.*) |
| 148 | FIXED_GCCVER=GCC49 |
| 149 | ;; |
| 150 | *) |
| 151 | FIXED_GCCVER=GCC5 |
| 152 | ;; |
| 153 | esac |
| 154 | echo ${FIXED_GCCVER} |
| 155 | } |
| 156 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 157 | do_compile:class-native() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 158 | oe_runmake -C ${S}/BaseTools |
| 159 | } |
| 160 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 161 | do_compile:class-target() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 162 | export LFLAGS="${LDFLAGS}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 163 | PARALLEL_JOBS="${@oe.utils.parallel_make_argument(d, '-n %d')}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 164 | OVMF_ARCH="X64" |
| 165 | if [ "${TARGET_ARCH}" != "x86_64" ] ; then |
| 166 | OVMF_ARCH="IA32" |
| 167 | fi |
| 168 | |
| 169 | # The build for the target uses BaseTools/Conf/tools_def.template |
| 170 | # from ovmf-native to find the compiler, which depends on |
| 171 | # exporting HOST_PREFIX. |
| 172 | export HOST_PREFIX="${HOST_PREFIX}" |
| 173 | |
| 174 | # BaseTools/Conf gets copied to Conf, but only if that does not |
| 175 | # exist yet. To ensure that an updated template gets used during |
| 176 | # incremental builds, we need to remove the copy before we start. |
| 177 | rm -f `ls ${S}/Conf/*.txt | grep -v ReadMe.txt` |
| 178 | |
| 179 | # ${WORKDIR}/ovmf is a well-known location where do_install and |
| 180 | # do_deploy will be able to find the files. |
| 181 | rm -rf ${WORKDIR}/ovmf |
| 182 | mkdir ${WORKDIR}/ovmf |
| 183 | OVMF_DIR_SUFFIX="X64" |
| 184 | if [ "${TARGET_ARCH}" != "x86_64" ] ; then |
| 185 | OVMF_DIR_SUFFIX="Ia32" # Note the different capitalization |
| 186 | fi |
| 187 | FIXED_GCCVER=$(fixup_target_tools ${GCC_VER}) |
| 188 | bbnote FIXED_GCCVER is ${FIXED_GCCVER} |
| 189 | build_dir="${S}/Build/Ovmf$OVMF_DIR_SUFFIX/RELEASE_${FIXED_GCCVER}" |
| 190 | |
| 191 | bbnote "Building without Secure Boot." |
| 192 | rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 193 | ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER} ${PACKAGECONFIG_CONFARGS} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 194 | ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.fd |
| 195 | ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.code.fd |
| 196 | ln ${build_dir}/FV/OVMF_VARS.fd ${WORKDIR}/ovmf/ovmf.vars.fd |
| 197 | ln ${build_dir}/${OVMF_ARCH}/Shell.efi ${WORKDIR}/ovmf/ |
| 198 | |
| 199 | if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 200 | # Repeat build with the Secure Boot flags. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 201 | bbnote "Building with Secure Boot." |
| 202 | rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 203 | ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER} ${PACKAGECONFIG_CONFARGS} ${OVMF_SECURE_BOOT_FLAGS} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 204 | ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.secboot.fd |
| 205 | ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.secboot.code.fd |
| 206 | ln ${build_dir}/${OVMF_ARCH}/EnrollDefaultKeys.efi ${WORKDIR}/ovmf/ |
| 207 | fi |
| 208 | } |
| 209 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 210 | do_install:class-native() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 211 | install -d ${D}/${bindir}/edk2_basetools |
| 212 | cp -r ${S}/BaseTools ${D}/${bindir}/${EDK_TOOLS_DIR} |
| 213 | } |
| 214 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 215 | do_install:class-target() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 216 | # Content for UEFI shell iso. We install the EFI shell as |
| 217 | # bootx64/ia32.efi because then it can be started even when the |
| 218 | # firmware itself does not contain it. |
| 219 | install -d ${D}/efi/boot |
| 220 | install ${WORKDIR}/ovmf/Shell.efi ${D}/efi/boot/boot${@ "ia32" if "${TARGET_ARCH}" != "x86_64" else "x64"}.efi |
| 221 | if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then |
| 222 | install ${WORKDIR}/ovmf/EnrollDefaultKeys.efi ${D} |
| 223 | fi |
| 224 | } |
| 225 | |
| 226 | # This always gets packaged because ovmf-shell-image depends on it. |
| 227 | # This allows testing that recipe in all configurations because it |
| 228 | # can always be part of a world build. |
| 229 | # |
| 230 | # However, EnrollDefaultKeys.efi is only included when Secure Boot is enabled. |
| 231 | PACKAGES =+ "ovmf-shell-efi" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 232 | FILES:ovmf-shell-efi = " \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 233 | EnrollDefaultKeys.efi \ |
| 234 | efi/ \ |
| 235 | " |
| 236 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 237 | DEPLOYDEP = "" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 238 | DEPLOYDEP:class-target = "qemu-system-native:do_populate_sysroot" |
| 239 | DEPLOYDEP:class-target += " ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'openssl-native:do_populate_sysroot', '', d)}" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 240 | do_deploy[depends] += "${DEPLOYDEP}" |
| 241 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 242 | do_deploy() { |
| 243 | } |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 244 | do_deploy:class-target() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 245 | # For use with "runqemu ovmf". |
| 246 | for i in \ |
| 247 | ovmf \ |
| 248 | ovmf.code \ |
| 249 | ovmf.vars \ |
| 250 | ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'ovmf.secboot ovmf.secboot.code', '', d)} \ |
| 251 | ; do |
| 252 | qemu-img convert -f raw -O qcow2 ${WORKDIR}/ovmf/$i.fd ${DEPLOYDIR}/$i.qcow2 |
| 253 | done |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 254 | |
| 255 | if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then |
| 256 | # Create a test Platform Key and first Key Exchange Key to use with EnrollDefaultKeys |
| 257 | openssl req -new -x509 -newkey rsa:2048 -keyout ${DEPLOYDIR}/OvmfPkKek1.key \ |
| 258 | -out ${DEPLOYDIR}/OvmfPkKek1.crt -nodes -days 20 -subj "/CN=OVMFSecBootTest" |
| 259 | openssl x509 -in ${DEPLOYDIR}/OvmfPkKek1.crt -out ${DEPLOYDIR}/OvmfPkKek1.pem -outform PEM |
| 260 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 261 | } |
| 262 | addtask do_deploy after do_compile before do_build |
| 263 | |
| 264 | BBCLASSEXTEND = "native" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 265 | TOOLCHAIN = "gcc" |