OVMF is the Open Virtual Machine Firmware, a UEFI firmware implementation for system emulators such as QEMU. It is provided as part of the EDKII development kit at: http://tianocore.org OVMF is very useful for creating a simulated UEFI-based system for experimentation with and debugging of UEFI applications and OS loaders. The EDKII developer kit is supported on many platforms. Below are my notes for building OVMF on FreeBSD. Using the EDKII with FreeBSD is not that different from other platforms, with the one major difference being that you can't use the host tool chain to build: you have to use the cross compiler approach instead, with a GCC and binutils targeted for a MinGW configuration. (This approach is a little more portable anyway.) At least with FreeBSD 9.x, although support for building EFI applications is included in the host tool chain, and it does work if you're using GNU EFI, the host tools aren't quite good enough for building with EDKII. Using the cross compiler tools avoids all of the potential compatibility issues, and also makes EDKII project creation more consistent across different releases of FreeBSD. Note however that this build method is not regularly tested, so there may be compiler warnings that show up when using the cross build toolchain that aren't visible when using the more typical build methods. Note also that I have only built IA32 and X64 executables. You would need different tools to build any EDKII projects for Itanium or ARM. The OVMF firmware can be used with pretty much any QEMU version supported by FreeBSD. You may want to install QEMU 1.6.2 or 1.7.0 if you want to experiment with PXE boot support with OVMF. The process described here is based on the "UNIX-like" EDKII build instructions as shown here: http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=Unix-like_systems Prerequisites: - FreeBSD 9.0-RELEASE, 9.1-RELEASE and 9.2-RELEASE have been tested. FreeBSD 10 or 11 should also work. I have used both FreeBSD/i386 and FreeBSD/amd64 as host environments. - Python 2.7 -- can be installed from packages. It's likely already on your system if you installed any interesting X11 packages. - Remember to install py27-sqlite3 too -- this may not be added by default when you install Python 2.7. The build system needs it. - Subversion -- svn client should be present in base OS - libmpfr and libgmp -- can be installed from packages. These are required for building the cross compilers. - bash -- many supplied scripts want bash, can be installed from packages. - GNU make (gmake) -- BSD make isn't quite compatible with the supplied makefiles. Can be installed from packages. - bison and flex -- needed for the building the cross-compiler tools. Can be installed from packages. - gzip and bzip2 -- should be part of the base OS - openssl-0.9.8w.tar.gz -- for secure boot support get it from: http://www.openssl.org/source/openssl-0.9.8w.tar.gz - binutils 2.20.51.0.5 -- needed for cross-compiling get it from: https://distfiles.macports.org/binutils/binutils-2.20.51.0.5.tar.bz2 - gcc 4.3.0 -- needed for cross-compiling get it from: http://ftpmirror.gnu.org/gcc/gcc-4.3.0/gcc-4.3.0.tar.bz2 - QEMU -- you can install the qemu or qemu-devel package. The package version you get may vary depending on which FreeBSD version you have. The qemu package may be as old as 0.11.1 while qemu-devel can be 1.1.1 for FreeBSD 9.1 or 1.7.0 for FreeBSD 11. You can also build QEMU 1.6.2 or 1.7.0 direct from source code. (I have compiled both on FreeBSD 9.1.) See below for build notes. Steps: 1) Download the EDKII source code by checking it out from the Subversion repository: % mkdir /home/$USER/myEDKdir % cd /home/$USER/myEDKdir % svn co https://svn.code.sf.net/p/edk2/code/trunk/edk2 --username guest 2) The build system expects "make" to be GNU make. On FreeBSD, "make" is BSD make(1), while /usr/local/bin/gmake is GNU make. You either have to rename /usr/local/bin/gmake and fix your path so that /usr/local/bin comes first, or you can use the following trick: % cd myEDKdir % ln -s /usr/local/bin/gmake make % setenv PATH `pwd`:$PATH 3) There are several special EDKII-specific utilities which are supplied as C programs. Binaries are included for Windows and Linux, but you can compile native binaries for FreeBSD. The makefiles expect that the ARCH environment variable will be set to indicate the host architecture as either IA32 or X64. If you're on FreeBSD/i386, then do: % setenv ARCH IA32 For FreeBSD/amd64, do: % setenv ARCH X64 There is one file in the BaseTools that must be tweaked so that it will compile on FreeBSD. Do the following: . edit edk2/BaseTools/Source/C/GenFv/GenFvInternalLib.c . change #include to just #include Now you should be able to compile the tools as follows: % cd edk2/BaseTools % make 4) You need to set up a cross-compiler environment. There is a supplied Python script for building the cross compiler toolchains. You need to do the following: . Put gcc-4.3.0.tar.bz2 and binutils-2.20.51.0.5.tar.bz2 in edk2/BaseTools/gcc/src . Set the following additional environment variables so that the GCC configure script can find libmpfr and libgmp: % setenv CFLAGS -I/usr/local/include % setenv LDFLAGS -L/usr/local/lib . Run the script to generate the tools: % cd edk2/BaseTools/gcc % ./mingw-gcc-build.py --arch=ia32 --prefix=/home/$USER/myEDKdir/programs % ./mingw-gcc-build.py --arch=x64 --prefix=/home/$USER/myEDKdir/programs . Once you're done, you can unset the environment variables you set previously: % unsetenv ARCH % unsetenv CFLAGS % unsetenv LDFLAGS 5) For secure boot support, you need to set up OpenSSL. This is done as follows: . Copy openssl-0.9.8w.tar.gz to edk2/CryptoPkg/Library/OpensslLib . IMPORTANT: There is an EDKII_openssl-0.9.8w.patch file in the edk2/CryptoPkg/Library/OpensslLib directory. It is polluted with ^M characters from Windows. You must edit the file to remove them. If you don't do this, the patch won't apply correctly and you'll get curious build errors later. You have been warned. . Go to the edk2/CryptoPkg/Library/OpensslLib directory and run the following commands: % cat openssl-0.9.8w.tar.gz | gzip -d | tar -xvf - % cd openssl-0.9.8w % patch -p0 -i ../EDKII_openssl-0.9.8w.patch % cd .. % ./Install.sh 6) Switch to using bash % bash bash$ 7) Set up the bash environment: bash$ cd /home/$USER/myEDKdir/edk2 bash$ export EDK_TOOLS_PATH=/home/$USER/myEDKdir/edk2/BaseTools bash$ . edksetup.sh BaseTools Note that this should copy an initial set of configuration files into edk2/Conf. For later sessions, it is not necessary to copy them again, so it should be okay to skip the setting of the EDK_TOOLS_PATH environment variable after doing it the first time. 8) You need to edit the edk2/Conf/tools_def.txt file so that it can find the cross compiler tools you just built. The following variables should be set as shown: DEFINE UNIXGCC_IA32_PETOOLS_PREFIX = ENV(HOME)/myEDKdir/programs/bin/i686-pc-mingw32- DEFINE UNIXGCC_X64_PETOOLS_PREFIX = ENV(HOME)/myEDKdir/programs/bin/x86_64-pc-mingw32- The above case is a modification of what is defined for "Option 5" in the tools_def.txt file (use the user's home directory). Note that the path for the Intel ASL compiler is different for FreeBSD than it is for Linux, so you must also set the following (note the sbin path instead of bin): DEFINE UNIX_IASL_BIN = /usr/sbin/iasl 9) You should now be ready to compile OVMF. Run the following commands: bash$ build -a IA32 -b RELEASE -t UNIXGCC -DFD_SIZE_2MB -DSECURE_BOOT_ENABLE=TRUE -p OvmfPkg/OvmfPkgIa32.dsc bash$ build -a X64 -b RELEASE -t UNIXGCC -DFD_SIZE_2MB -DSECURE_BOOT_ENABLE=TRUE -p OvmfPkg/OvmfPkgX64.dsc The FD_SIZE_2MB option is used because I have found that when building with secure boot enabled, the X64 object code is too big to fit into a 1MB compressed image, which is the default for the RELEASE build target. If you elect not to build with secure boot, or are fine with the default DEBUG build target, it should be okay to leave -DFD_SIZE_2MB out. The -n THREADS option can be optionally specified for a parallel (faster) build. NOTE: Compilation may halt due to warnings when building the edk2/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c source file. On lines 249, 289, 342, 428 and 692, you will see the following declaration: EFI_FW_VOL_INSTANCE *FwhInstance; To correct the warnings, change the these declarations to this: EFI_FW_VOL_INSTANCE *FwhInstance = NULL; This may be fixed in future versions. ============================================================================== QEMU BUILD NOTE: The QEMU distribution builds a linker script when you configure it. For some reason, this script was generated incorrectly when I tried to compile on my FreeBSD 9.1 system. This caused the linker to emit a syntax error during the build process. The corrupted section should be corrected to look like this: PROVIDE (__executable_start = 0x60000000); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS; The problem seems to be that an incorrect substitution is made somewhere and the SEGMENT_START portion is inserted twice, such that the PROVIDE and SEGMENT_START directives end up mashed together on the same line. Once you correct the config-host.ld script as shown above, it should link correctly.