ovmf_git.bb 12 KB

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