Loading...
 

Build from source - UEFI EDK II

EDK II is a modern, feature-rich, cross-platform firmware development environment for the UEFI and PI specifications. MACCHATIObin supports to use EDK II plus ATF as its bootloader.

Build EDK II

First, set your $BASEDIR environment variable, as it will be used in the commands/scripts below. It is supposed to point to the working directory, where all repositories will be placed.

mcbin@buildserver:~$ cd ~
mcbin@buildserver:~$ mkdir mcbin
mcbin@buildserver:~$ export BASEDIR=~/mcbin


Cross-compilation - OPTIONAL Now the toolchain needs to be set up in order to build the EDK II. Please download the gcc-7.5 at https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz .

mcbin@buildserver:~$ cd ${BASEDIR}
mcbin@buildserver:~/mcbin$ mkdir gcc5
mcbin@buildserver:~/mcbin$ cd gcc5
mcbin@buildserver:~/mcbin/gcc5$ wget https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz
mcbin@buildserver:~/mcbin/gcc5$ tar -xf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz

 
Cross-compilation - OPTIONAL Once the toolchain is extracted, setup the path and the compiler prefix to the environment variable GCC5_AARCH64_PREFIX.

mcbin@buildserver:~$ export GCC5_AARCH64_PREFIX=${BASEDIR}/gcc5/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

 

 Information

In order to create the UEFI image, ACPI tables (iasl) and Device Tree (dtc) compilers have to be installed on your build machine. Please issue 'sudo apt install uuid-dev iasl device-tree-compiler' to install the iasl complier and dtc.


Also make, python, gcc and g++ are required, for that execute: 'sudo apt install make gcc g++ python'


Now, obtain the upstream Tianocore edk2 sources. The default ('master') branches are used in all cases.

mcbin@buildserver:~$ cd ${BASEDIR}
mcbin@buildserver:~/mcbin$ git clone https://github.com/tianocore/edk2.git
mcbin@buildserver:~/mcbin$ cd edk2
mcbin@buildserver:~/mcbin$ git submodule update --init
mcbin@buildserver:~/mcbin$ cd ..
mcbin@buildserver:~/mcbin$ git clone https://github.com/tianocore/edk2-platforms.git
mcbin@buildserver:~/mcbin$ git clone https://github.com/tianocore/edk2-non-osi.git


Additional environment setup need to run before build the EDK II binaries. Please make sure the commands below finish without error.

mcbin@buildserver:~/$ cd ${BASEDIR}
mcbin@buildserver:~/mcbin$ export WORKSPACE=$PWD
mcbin@buildserver:~/mcbin$ export PACKAGES_PATH=$PWD/edk2:$PWD/edk2-platforms:$PWD/edk2-non-osi
mcbin@buildserver:~/mcbin$ make -C edk2/BaseTools
mcbin@buildserver:~/mcbin$ source edk2/edksetup.sh


Now, to build the RELEASE version (DEBUG can be used alternatively) of the EDK II binary for MACCHIATObin, run the build command with parameters as below:

mcbin@buildserver:~$ cd ${BASEDIR}
mcbin@buildserver:~/mcbin$ build -a AARCH64 -t GCC5 -b RELEASE -D INCLUDE_TFTP_COMMAND -p Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc


Please wait until the build process finish without failure, the output binary will be available at the directory of Build/Armada80x0McBin-AARCH64/RELEASE_GCC5/FV/

mcbin@buildserver:~/mcbin$ ls Build/Armada80x0McBin-AARCH64/RELEASE_GCC5/FV/
ARMADA_EFI.fd             FVMAIN.Fv.txt          Ffs
CAPSULEDISPATCHFV.Fv      FVMAIN.ext             Guid.xref
CAPSULEDISPATCHFV.Fv.map  FVMAIN.inf             GuidedSectionTools.txt
CAPSULEDISPATCHFV.Fv.txt  FVMAIN_COMPACT.Fv      SYSTEMFIRMWAREDESCRIPTOR.Fv
CAPSULEDISPATCHFV.inf     FVMAIN_COMPACT.Fv.map  SYSTEMFIRMWAREDESCRIPTOR.Fv.map
FVMAIN.Fv                 FVMAIN_COMPACT.Fv.txt  SYSTEMFIRMWAREDESCRIPTOR.Fv.txt
FVMAIN.Fv.map             FVMAIN_COMPACT.inf     SYSTEMFIRMWAREDESCRIPTOR.inf


Setup the EDK II binary as the payload of the ARM Trusted Firmware (TF-A). This step is needed to build the bootloader image including TF-A and EDK II for MACCHIATObin.

mcbin@buildserver:~/mcbin$ export BL33=${BASEDIR}/Build/Armada80x0McBin-AARCH64/RELEASE_GCC5/FV/ARMADA_EFI.fd

 

Build TF-A


Before building the Trusted Firmware A for MACCHIATObin with EDK II binary packaged, please make sure you have exported BL33 correctly to point to the EDK II binary for TF-A. If you have gone through the previous Build EDK II section, you should have already done so.

mcbin@buildserver:~/mcbin$ export BL33=${BASEDIR}/Build/Armada80x0McBin-AARCH64/RELEASE_GCC5/FV/ARMADA_EFI.fd

 Information

In order to create the TF-A image, it requires openssl headers to be installed on your build machine. Please execute sudo apt-get install libssl-dev to install the openssl headers before starting to build the TF-A.

Clone the upstream TF-A sources. The default 'master' branch will be used.

mcbin@buildserver:~$ cd ${BASEDIR}
mcbin@buildserver:~/mcbin$ git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git


Marvell uses a separate repository to hold the algorithm for ddr training. It is necessary to download it as well to build the bootloader binary. Clone the repository to your local build machine. The default 'master' branch will be used.

mcbin@buildserver:~$ cd ${BASEDIR}
mcbin@buildserver:~/mcbin$ git clone https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell.git


In the newest versions it is obligatory to use an auxiliary firmware on the SoC co-processors. For that purpose it is required to download and appropriately expose a pre-built image.

mcbin@buildserver:~$ cd ${BASEDIR}
mcbin@buildserver:~/mcbin$ git clone https://github.com/MarvellEmbeddedProcessors/binaries-marvell.git
mcbin@buildserver:~$ cd binaries-marvell/


Check-out binaries-marvell-armada-SDK10.0.1.0 and export SCP_BL2 variable, which points to the image.

mcbin@buildserver:~/mcbin/binaries-marvell$ git checkout -b binaries-marvell-armada-SDK10.0.1.0 remotes/origin/binaries-marvell-armada-SDK10.0.1.0
Branch 'binaries-marvell-armada-SDK10.0.1.0' set up to track remote branch 'binaries-marvell-armada-SDK10.0.1.0' from 'origin'.
Switched to a new branch 'binaries-marvell-armada-SDK10.0.1.0'
mcbin@buildserver:~/mcbin/binaries-marvell$ export SCP_BL2=${BASEDIR}/binaries-marvell/mrvl_scp_bl2.img


Cross-compilation - OPTIONAL Next step is to setup the CROSS_COMPILE and ARCH properly on your build machine.

export ARCH=arm64
export CROSS_COMPILE=${BASEDIR}/gcc5/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-


Now, go back to your TF-A directory and execute a command:

mcbin@buildserver:~/mcbin/binaries-marvell$ cd ${BASEDIR}/trusted-firmware-a/
mcbin@buildserver:~/mcbin/trusted-firmware-a$ make USE_COHERENT_MEM=0 LOG_LEVEL=20 MV_DDR_PATH=${BASEDIR}/mv-ddr-marvell/ PLAT=a80x0_mcbin all fip mrvl_flash


The example instruction above compiles a release version of the TF-A. Once the build process is done, the firmware image flash-image.bin will be located at the ${BASEDIR}/trusted-firmware-a/build/a80x0_mcbin/release/ directory.

mcbin@buildserver:~$ ls ${BASEDIR}/trusted-firmware-a/build/a80x0_mcbin/release/
bl1      bl2      bl31      ble      boot-image.bin  flash-image.bin  libc        romlib
bl1.bin  bl2.bin  bl31.bin  ble.bin  fip.bin         lib              libwrapper


Now you have your bootloader image flash-image.bin ready, the image file can be flashed into the MACCHIATObin boot devices.

Quick build


In case all the prerequisites above are ready, there is no need to repeat all the steps every time. It is enough to setup the environment as below only once.

mcbin@buildserver:~$ cat a8040mcbin_prepare_env.sh 
#!/bin/bash

export BASEDIR=~/mcbin
#Skip below step if building natively on arm64 platform
export GCC5_AARCH64_PREFIX=${BASEDIR}/gcc5/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
export SCP_BL2=${BASEDIR}/binaries-marvell/mrvl_scp_bl2.img
cd ${BASEDIR}
export WORKSPACE=$PWD
export PACKAGES_PATH=$PWD/edk2:$PWD/edk2-platforms:$PWD/edk2-non-osi
make -C edk2/BaseTools
source edk2/edksetup.sh


Then following script may be handy for issuing a quick build of the firmware.

mcbin@buildserver:~/mcbin$ cat a8040mcbin.sh
#!/bin/bash

cd ${BASEDIR}
build -a AARCH64 -t GCC5 -b RELEASE -D INCLUDE_TFTP_COMMAND -p Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc

cd ${BASEDIR}/trusted-firmware-a
#Skip below step if building natively on arm64 platform
export ARCH=arm64
#Skip below step if building natively on arm64 platform
export CROSS_COMPILE=${BASEDIR}/gcc5/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
export SCP_BL2=${BASEDIR}/binaries-marvell/mrvl_scp_bl2.img
export BL33=${BASEDIR}/Build/Armada80x0McBin-AARCH64/RELEASE_GCC5/FV/ARMADA_EFI.fd
make USE_COHERENT_MEM=0 LOG_LEVEL=20 MV_DDR_PATH=${BASEDIR}/mv-ddr-marvell/ PLAT=a80x0_mcbin all fip mrvl_flash
#Skip below step if building natively on arm64 platform
export ARCH=
cd -


Above script takes one argument - edk2 build target (RELEASE/DEBUG). Example usage:

mcbin@buildserver:~$ source ~/a8040mcbin_prepare_env.sh
mcbin@buildserver:~/mcbin$ ./a8040mcbin.sh RELEASE