July 4, 2021

Developing EDK2 code using FreeBSD

The EDK2 doesn't work out-of-the-box with FreeBSD, but needs some extra packages and setup.

Packages to install are:

  • shells/bash
  • devel/binutils
  • lang/gcc5, or newer
  • devel/nasm
  • devel/acpica-tools
  • devel/git
  • devel/gmake
  • lang/python27
  • databases/py27-sqlite3

Create the following symlinks in BaseTools/Bin/FreeBSD-amd64:

python -> /usr/local/bin/python2.7
make -> /usr/local/bin/gmake
ld -> /usr/local/bin/ld
objcopy -> /usr/local/bin/objcopy
gcc -> /usr/local/bin/gcc5
g++ -> /usr/local/bin/g++5
gcc-ar -> /usr/local/bin/gcc-ar5
gcc-nm -> /usr/local/bin/gcc-nm5
gcc-ranlib -> /usr/local/bin/gcc-ranlib5

After that, you should be able to use the EDK2 as you would on a Linux system as long as you use bash - for example:

source edksetup.sh
./OvmfPkg/build.sh -a X64 -t GCC5 -b RELEASE

If you'd like to build for platforms other than i386 or x64, the process is a bit different.

Building for MACCHIATObin

Install the following:

  • devel/aarch64-binutils [Note Run make config before building to unset the STATIC option]
  • devel/aarch64-gcc

export GCC5_AARCH64_PREFIX=/usr/local/bin/aarch64-unknown-freebsd13.0-

Now you can build normally using the build command etc. I've put together a script to build for the MACCHIATObin board that can be found at the bottom of this page:


set -e

if [ "$1" == "" ]; then
        echo "usage: $0 [DEBUG|RELEASE]"
        exit 1

ncpu=$(sysctl -n hw.ncpu)

# Set up the build system for FreeBSD amd64
rm -rf ${TOOLBINDIR}
ln -sf ${LOCALBINDIR}/gmake ${TOOLBINDIR}/make
ln -sf ${LOCALBINDIR}/python2.7 ${TOOLBINDIR}/python
ln -sf ${LOCALBINDIR}/objcopy ${TOOLBINDIR}/objcopy
ln -sf ${LOCALBINDIR}/gcc7 ${TOOLBINDIR}/gcc
ln -sf ${LOCALBINDIR}/g++7 ${TOOLBINDIR}/g++
ln -sf ${LOCALBINDIR}/gcc-ar7 ${TOOLBINDIR}/gcc-ar
ln -sf ${LOCALBINDIR}/gcc-nm7 ${TOOLBINDIR}/gcc-nm
ln -sf ${LOCALBINDIR}/gcc-ranlib7 ${TOOLBINDIR}/gcc-ranlib

cd ${BASEDIR}/edk2
export GCC5_AARCH64_PREFIX=${LOCALBINDIR}/aarch64-unknown-freebsd13.0-

. ./edksetup.sh --reconfig
make -C BaseTools -j $ncpu
build -n $ncpu --genfds-multi-thread -a AARCH64 -t GCC5 -b ${1} -D INCLUDE_TFTP_COMMAND -p OpenPlatformPkg/Platforms/Marvell/Armada/Armada80x0McBin.dsc

cd ../macchiatobin/atf-marvell
export ARCH=arm64
export SCP_BL2=${BASEDIR}/macchiatobin/binaries-marvell/mrvl_scp_bl2_mss_ap_cp1_a8040.img
export BL33=${BASEDIR}/edk2/Build/Armada80x0McBin-AARCH64/${1}_GCC5/FV/ARMADA_EFI.fd
export SCP_BL2=${BASEDIR}/macchiatobin/binaries-marvell/mrvl_scp_bl2_mss_ap_cp1_a8040.img

make -j $ncpu USE_COHERENT_MEM=0 LOG_LEVEL=20 MV_DDR_PATH=${BASEDIR}/macchiatobin/mv-ddr-marvell PLAT=a80x0_mcbin all fip

© Rebecca Cran 2022