blob: 9d988e9d414762900449f6108a98e1525d09e57a [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001DESCRIPTION = "OVMF - UEFI firmware for Qemu and KVM"
2HOMEPAGE = "http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=OVMF"
3LICENSE = "BSD"
4LICENSE_class-target = "${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'BSD & OpenSSL', 'BSD', d)}"
5LIC_FILES_CHKSUM = "file://OvmfPkg/License.txt;md5=343dc88e82ff33d042074f62050c3496"
6
7# Enabling Secure Boot adds a dependency on OpenSSL and implies
8# compiling OVMF twice, so it is disabled by default. Distros
9# may change that default.
10PACKAGECONFIG ??= ""
11PACKAGECONFIG[secureboot] = ",,,"
12
13SRC_URI = "git://github.com/tianocore/edk2.git;branch=master \
14 file://0002-ovmf-update-path-to-native-BaseTools.patch \
15 file://0003-BaseTools-makefile-adjust-to-build-in-under-bitbake.patch \
16 file://VfrCompile-increase-path-length-limit.patch \
17 file://0001-MdeModulePkg-UefiHiiLib-Fix-incorrect-comparison-exp.patch \
18 "
19
20SRC_URI_append_class-target = " \
21 ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'http://www.openssl.org/source/openssl-1.0.2j.tar.gz;name=openssl;subdir=${S}/CryptoPkg/Library/OpensslLib', '', d)} \
22 file://0007-OvmfPkg-EnrollDefaultKeys-application-for-enrolling-.patch \
23"
24
25SRCREV="4575a602ca6072ee9d04150b38bfb143cbff8588"
26SRC_URI[openssl.md5sum] = "96322138f0b69e61b7212bc53d5e912b"
27SRC_URI[openssl.sha256sum] = "e7aff292be21c259c6af26469c7a9b3ba26e9abaaffd325e3dccc9785256c431"
28
29inherit deploy
30
31PARALLEL_MAKE_class-native = ""
32
33S = "${WORKDIR}/git"
34
35DEPENDS_class-native="util-linux-native iasl-native ossp-uuid-native qemu-native"
36
37DEPENDS_class-target="ovmf-native"
38
39DEPENDS_append = " nasm-native"
40
41EDK_TOOLS_DIR="edk2_basetools"
42
43# OVMF has trouble building with the default optimization of -O2.
44BUILD_OPTIMIZATION="-pipe"
45
46# OVMF supports IA only, although it could conceivably support ARM someday.
47COMPATIBLE_HOST='(i.86|x86_64).*'
48
49# Additional build flags for OVMF with Secure Boot.
50# Fedora also uses "-D SMM_REQUIRE -D EXCLUDE_SHELL_FROM_FD".
51OVMF_SECURE_BOOT_EXTRA_FLAGS ??= ""
52OVMF_SECURE_BOOT_FLAGS = "-DSECURE_BOOT_ENABLE=TRUE ${OVMF_SECURE_BOOT_EXTRA_FLAGS}"
53
54do_patch[postfuncs] += "fix_basetools_location"
55fix_basetools_location () {
56}
57fix_basetools_location_class-target() {
58 # Replaces the fake path inserted by 0002-ovmf-update-path-to-native-BaseTools.patch.
59 # Necessary for finding the actual BaseTools from ovmf-native.
60 sed -i -e 's#BBAKE_EDK_TOOLS_PATH#${STAGING_BINDIR_NATIVE}/${EDK_TOOLS_DIR}#' ${S}/OvmfPkg/build.sh
61}
62
63do_patch[postfuncs] += "fix_iasl"
64fix_iasl() {
65}
66fix_iasl_class-native() {
67 # iasl is not installed under /usr/bin when building with OE.
68 sed -i -e 's#/usr/bin/iasl#${STAGING_BINDIR_NATIVE}/iasl#' ${S}/BaseTools/Conf/tools_def.template
69}
70
71# Inject CC and friends into the build. LINKER already is in GNUmakefile.
72# Must be idempotent and thus remove old assignments that were inserted
73# earlier.
74do_patch[postfuncs] += "fix_toolchain"
75fix_toolchain() {
76 sed -i \
77 -e '/^\(CC\|CXX\|AS\|AR\|LD\|LINKER\) =/d' \
78 -e '/^APPLICATION/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}\nLINKER = $(CC)' \
79 ${S}/BaseTools/Source/C/Makefiles/app.makefile
80 sed -i \
81 -e '/^\(CC\|CXX\|AS\|AR\|LD\)/d' \
82 -e '/^VFR_CPPFLAGS/a CC = ${CC}\nCXX = ${CXX}\nAS = ${AS}\nAR = ${AR}\nLD = ${LD}' \
83 ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile
84}
85fix_toolchain_append_class-native() {
86 # This tools_def.template is going to be used by the target ovmf and
87 # defines which compilers to use. For the GCC toolchain definitions,
88 # that will be ${HOST_PREFIX}gcc. However, "make" doesn't need that
89 # prefix.
90 #
91 # Injecting ENV(HOST_PREFIX) matches exporting that value as env
92 # variable in do_compile_class-target.
93 sed -i \
94 -e 's#\(ENV\|DEF\)(GCC.*_PREFIX)#ENV(HOST_PREFIX)#' \
95 -e 's#ENV(HOST_PREFIX)make#make#' \
96 ${S}/BaseTools/Conf/tools_def.template
97 sed -i \
98 -e '/^\(LFLAGS\|CFLAGS\) +=/d' \
99 -e '/^LINKER/a LFLAGS += ${BUILD_LDFLAGS}\nCFLAGS += ${BUILD_CFLAGS}' \
100 ${S}/BaseTools/Source/C/Makefiles/app.makefile \
101 ${S}/BaseTools/Source/C/VfrCompile/GNUmakefile
102 # Linking with gold fails:
103 # internal error in do_layout, at ../../gold/object.cc:1821
104 # make: *** [.../OUTPUT/Facs.acpi] Error 1
105 # We intentionally hard-code the use of ld.bfd regardless of DISTRO_FEATURES
106 # to make ovmf-native reusable across distros.
107 sed -i \
108 -e 's#^\(DEFINE GCC.*DLINK.*FLAGS *=\)#\1 -fuse-ld=bfd#' \
109 ${S}/BaseTools/Conf/tools_def.template
110}
111
112GCC_VER="$(${CC} -v 2>&1 | tail -n1 | awk '{print $3}')"
113
114fixup_target_tools() {
115 case ${1} in
116 4.4.*)
117 FIXED_GCCVER=GCC44
118 ;;
119 4.5.*)
120 FIXED_GCCVER=GCC45
121 ;;
122 4.6.*)
123 FIXED_GCCVER=GCC46
124 ;;
125 4.7.*)
126 FIXED_GCCVER=GCC47
127 ;;
128 4.8.*)
129 FIXED_GCCVER=GCC48
130 ;;
131 4.9.*)
132 FIXED_GCCVER=GCC49
133 ;;
134 *)
135 FIXED_GCCVER=GCC5
136 ;;
137 esac
138 echo ${FIXED_GCCVER}
139}
140
141do_compile_class-native() {
142 oe_runmake -C ${S}/BaseTools
143}
144
145do_compile_class-target() {
146 export LFLAGS="${LDFLAGS}"
147 PARALLEL_JOBS="${@ '${PARALLEL_MAKE}'.replace('-j', '-n')}"
148 OVMF_ARCH="X64"
149 if [ "${TARGET_ARCH}" != "x86_64" ] ; then
150 OVMF_ARCH="IA32"
151 fi
152
153 # The build for the target uses BaseTools/Conf/tools_def.template
154 # from ovmf-native to find the compiler, which depends on
155 # exporting HOST_PREFIX.
156 export HOST_PREFIX="${HOST_PREFIX}"
157
158 # BaseTools/Conf gets copied to Conf, but only if that does not
159 # exist yet. To ensure that an updated template gets used during
160 # incremental builds, we need to remove the copy before we start.
161 rm -f `ls ${S}/Conf/*.txt | grep -v ReadMe.txt`
162
163 # ${WORKDIR}/ovmf is a well-known location where do_install and
164 # do_deploy will be able to find the files.
165 rm -rf ${WORKDIR}/ovmf
166 mkdir ${WORKDIR}/ovmf
167 OVMF_DIR_SUFFIX="X64"
168 if [ "${TARGET_ARCH}" != "x86_64" ] ; then
169 OVMF_DIR_SUFFIX="Ia32" # Note the different capitalization
170 fi
171 FIXED_GCCVER=$(fixup_target_tools ${GCC_VER})
172 bbnote FIXED_GCCVER is ${FIXED_GCCVER}
173 build_dir="${S}/Build/Ovmf$OVMF_DIR_SUFFIX/RELEASE_${FIXED_GCCVER}"
174
175 bbnote "Building without Secure Boot."
176 rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX
177 ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER}
178 ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.fd
179 ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.code.fd
180 ln ${build_dir}/FV/OVMF_VARS.fd ${WORKDIR}/ovmf/ovmf.vars.fd
181 ln ${build_dir}/${OVMF_ARCH}/Shell.efi ${WORKDIR}/ovmf/
182
183 if ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'true', 'false', d)}; then
184 # See CryptoPkg/Library/OpensslLib/Patch-HOWTO.txt and
185 # https://src.fedoraproject.org/cgit/rpms/edk2.git/tree/ for
186 # building with Secure Boot enabled.
187 bbnote "Building with Secure Boot."
188 rm -rf ${S}/Build/Ovmf$OVMF_DIR_SUFFIX
189 if ! [ -f ${S}/CryptoPkg/Library/OpensslLib/openssl-*/edk2-patch-applied ]; then
190 ( cd ${S}/CryptoPkg/Library/OpensslLib/openssl-* && patch -p1 <$(echo ../EDKII_openssl-*.patch) && touch edk2-patch-applied )
191 fi
192 ( cd ${S}/CryptoPkg/Library/OpensslLib/ && ./Install.sh )
193 ${S}/OvmfPkg/build.sh $PARALLEL_JOBS -a $OVMF_ARCH -b RELEASE -t ${FIXED_GCCVER} ${OVMF_SECURE_BOOT_FLAGS}
194 ln ${build_dir}/FV/OVMF.fd ${WORKDIR}/ovmf/ovmf.secboot.fd
195 ln ${build_dir}/FV/OVMF_CODE.fd ${WORKDIR}/ovmf/ovmf.secboot.code.fd
196 ln ${build_dir}/${OVMF_ARCH}/EnrollDefaultKeys.efi ${WORKDIR}/ovmf/
197 fi
198}
199
200do_install_class-native() {
201 install -d ${D}/${bindir}/edk2_basetools
202 cp -r ${S}/BaseTools ${D}/${bindir}/${EDK_TOOLS_DIR}
203}
204
205do_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
216# This always gets packaged because ovmf-shell-image depends on it.
217# This allows testing that recipe in all configurations because it
218# can always be part of a world build.
219#
220# However, EnrollDefaultKeys.efi is only included when Secure Boot is enabled.
221PACKAGES =+ "ovmf-shell-efi"
222FILES_ovmf-shell-efi = " \
223 EnrollDefaultKeys.efi \
224 efi/ \
225"
226
227do_deploy() {
228}
229do_deploy[cleandirs] = "${DEPLOYDIR}"
230do_deploy_class-target() {
231 # For use with "runqemu ovmf".
232 for i in \
233 ovmf \
234 ovmf.code \
235 ovmf.vars \
236 ${@bb.utils.contains('PACKAGECONFIG', 'secureboot', 'ovmf.secboot ovmf.secboot.code', '', d)} \
237 ; do
238 qemu-img convert -f raw -O qcow2 ${WORKDIR}/ovmf/$i.fd ${DEPLOYDIR}/$i.qcow2
239 done
240}
241addtask do_deploy after do_compile before do_build
242
243BBCLASSEXTEND = "native"