On 04/06/17 20:07, Peter Hornyack wrote: > I'd like to make an adjustment to the edk2 build (locally, not for > upstream) and I'm hoping someone can offer some guidance. > > My goal is to pre-build an edk2 library in a separate build process, > then pull that library into the full build later on. Specifically I'm > building my firmware image using OvmfPkgX64.dsc, but I want to build > OpensslLib (CryptoPkg/Library/OpensslLib/OpensslLib.inf) in advance, > then pull the resulting lib into the full build later. How can I > achieve this? > > In my build output I can see that when OpensslLib.inf is built, all of > the openssl .c files are compiled into .obj files, then an ar command > wraps those up into OpensslLib.lib. I want to pull those steps out and > pre-build OpensslLib.lib, but I've been unable to find where/how the > edk2 build grabs that .lib file and turns it into the final firmware > image. I've reviewed the edk2 build documentation but still can't > figure this out. Can anyone point me to the right place in the edk2 > build files where I can make this happen? Or perhaps is there an > example of this already in the edk2 build that I can imitate? (1) Apply the attached patch OvmfPkg: add USE_EXTERNAL_OPENSSL for external, binary OpenSSL in your edk2 clone. (Don't forget to pass --keep-cr to git-am.) (2) Create a new directory somewhere, initialize it as a git repository, and apply the attached patch ExternalSslPkg: create INF files for OpensslLib binaries in it: export EXTERNAL_OPENSSL_DIR=... mkdir -pv -- "$EXTERNAL_OPENSSL_DIR" cd "$EXTERNAL_OPENSSL_DIR" git init git am --keep-cr ... (3) Set another variable (customize as necessary): export TOOLCHAIN=GCC48 (4) Go to your normal edk2 clone, and run the following commands, for initially building the OpenSSL binaries only, and installing them. This assumes that OpenSSL has been embedded in the edk2 tree, as directed by CryptoPkg/Library/OpensslLib/OpenSSL-HOWTO.txt This step has to be done only once. ( ARCH_ID=(IA32 X64) ARCH_NAME=(Ia32 X64) SSL_FLAVOR=("" Crypto) SSL_TLS=(TRUE FALSE) SSLD=CryptoPkg/Library/OpensslLib source edksetup.sh set -e -u -C -x make -C "$EDK_TOOLS_PATH" for TARGET in DEBUG NOOPT RELEASE; do for ((ARCH_IDX=0; ARCH_IDX < ${#ARCH_ID[@]}; ARCH_IDX++)); do for ((SSL_IDX=0; SSL_IDX < ${#SSL_FLAVOR[@]}; SSL_IDX++)); do build \ --arch="${ARCH_ID[ARCH_IDX]}" \ --platform="OvmfPkg/OvmfPkg${ARCH_NAME[ARCH_IDX]}.dsc" \ --module="$SSLD/OpensslLib${SSL_FLAVOR[SSL_IDX]}.inf" \ --buildtarget="$TARGET" \ --tagname="$TOOLCHAIN" \ --define=TLS_ENABLE="${SSL_TLS[SSL_IDX]}" LIBF="Build/Ovmf${ARCH_NAME[ARCH_IDX]}/${TARGET}_${TOOLCHAIN}" LIBF="$LIBF/${ARCH_ID[ARCH_IDX]}" LIBF="$LIBF/$SSLD/OpensslLib${SSL_FLAVOR[SSL_IDX]}" LIBF="$LIBF/OUTPUT/OpensslLib${SSL_FLAVOR[SSL_IDX]}.lib" DSTF="$EXTERNAL_OPENSSL_DIR/ExternalSslPkg/Library/OpensslLib" DSTF="$DSTF/$TARGET/${ARCH_ID[ARCH_IDX]}" DSTF="$DSTF/OpensslLib${SSL_FLAVOR[SSL_IDX]}.lib" install -m 0644 -D -- "$LIBF" "$DSTF" done done done rm -r Build ) At the end of this step, the binaries will be available under $EXTERNAL_OPENSSL_DIR, in addition to the INF files from step (2): ExternalSslPkg/Library/OpensslLib/DEBUG/IA32/OpensslLib.lib ExternalSslPkg/Library/OpensslLib/DEBUG/IA32/OpensslLibCrypto.lib ExternalSslPkg/Library/OpensslLib/DEBUG/X64/OpensslLib.lib ExternalSslPkg/Library/OpensslLib/DEBUG/X64/OpensslLibCrypto.lib ExternalSslPkg/Library/OpensslLib/NOOPT/IA32/OpensslLib.lib ExternalSslPkg/Library/OpensslLib/NOOPT/IA32/OpensslLibCrypto.lib ExternalSslPkg/Library/OpensslLib/NOOPT/X64/OpensslLib.lib ExternalSslPkg/Library/OpensslLib/NOOPT/X64/OpensslLibCrypto.lib ExternalSslPkg/Library/OpensslLib/OpensslLibBin.inf ExternalSslPkg/Library/OpensslLib/OpensslLibBinCrypto.inf ExternalSslPkg/Library/OpensslLib/RELEASE/IA32/OpensslLib.lib ExternalSslPkg/Library/OpensslLib/RELEASE/IA32/OpensslLibCrypto.lib ExternalSslPkg/Library/OpensslLib/RELEASE/X64/OpensslLib.lib ExternalSslPkg/Library/OpensslLib/RELEASE/X64/OpensslLibCrypto.lib If you wish, you can add and commit the lib files to the repository, or save them for later by other means. Either case they have to stick together with the INF files. (5) Now build OVMF against the external libraries. For this, we use PACKAGES_PATH (see ). Also note -D USE_EXTERNAL_OPENSSL in COMMON_OPTS, which utilizes the patch from step (1). This step can be repeated as many times as necessary. Two builds are included below as examples. ( export PACKAGES_PATH="$EXTERNAL_OPENSSL_DIR" source edksetup.sh COMMON_OPTS="-t GCC48 -n 12 -D USE_EXTERNAL_OPENSSL -D SMM_REQUIRE" COMMON_OPTS="$COMMON_OPTS -D SECURE_BOOT_ENABLE -D HTTP_BOOT_ENABLE" build $COMMON_OPTS \ -a IA32 -p OvmfPkg/OvmfPkgIa32.dsc \ -b NOOPT build $COMMON_OPTS \ -a IA32 -a X64 -p OvmfPkg/OvmfPkgIa32X64.dsc \ -D TLS_ENABLE \ -b DEBUG ) Thanks Laszlo