ovmf_git.bb 9.0 KB

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