Build U-Boot for TI AM62x-based SoMs
Introduction
This article guides you on how to build from source and deploy U-Boot for Toradex's TI AM62x-based System on Modules (SoMs).
Install Tools and Dependencies
Run the command below to install the dependencies necessary to build U-Boot from source:
$ sudo apt-get install bc build-essential git wget libncurses5-dev lzop perl libssl-dev bison flex swig libyaml-dev pkg-config python3-dev python3-venv xz-utils xxd device-tree-compiler u-boot-tools
Prepare the Environment for Cross-Compilation
Since the TI AM62 SoC has cores with 32-bit and 64-bit architectures, the cross-compilation environment must be set for both architectures.
To cross-compile software for Toradex System on Modules (SoMs), you need to download either the 32 bit or 64 bit Arm cross-toolchain, according to the architecture of your System on Module SoC. Select the correct one from the tabs below:
- For 32 bit Arm:
arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz - For 64 bit Arm:
arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
You can use versions 9.2 or higher of the Arm releases binary toolchains to cross-compile software for Toradex modules. The instructions below reference version 12.3, which is the version used in Toradex build environments.
To install the toolchain on your host machine, download and unpack the .tar.xz file with the command below. Alternatively, you can obtain the toolchain directly from the Arm website.
$ cd ~
$ wget -O arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz "https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz?rev=9d73bfdd64a34550b9ec38a5ead7c01a&hash=774AAE1A6D6996CFB89FD7E367C0B59B"
$ tar xvf arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz && rm arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz
$ ln -s arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-linux-gnueabihf gcc-linaro-arm
U-Boot and Linux Makefiles use environment variables such as ARCH and CROSS_COMPILE to configure and call the appropriate compiler. Therefore, you must set these variables in the current shell when compiling the Kernel or U-Boot.
To facilitate this process, create an export-compiler-32 setup file with the commands below.
export ARCH=arm
export PATH=${HOME}/gcc-linaro-arm/bin/:${PATH}
export DTC_FLAGS='-@'
export CROSS_COMPILE=arm-none-linux-gnueabihf-
Please note that creating the setup file is not mandatory, it serves only to simplify executing the commands above. You could also run each command individually on every new shell, or create a different environment setup file during the build process.
Then, source the setup file using the command below. Note that you will also need to source it every time you open a new shell to build the Kernel/U-Boot.
$ source ~/export-compiler-32
You can use versions 9.2 or higher of the Arm releases binary toolchains to cross-compile software for Toradex modules. The instructions below reference version 12.3, which is the version used in Toradex build environments.
To install the toolchain on your host machine, download and unpack the .tar.xz file with the command below. Alternatively, you can obtain the toolchain directly from the Arm website.
$ cd ~
$ wget -O arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz "https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz?rev=cf8baa0ef2e54e9286f0409cdda4f66c&hash=4E1BA6BFC2C09EA04DBD36C393C9DD3A"
$ tar xvf arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz && rm arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz
$ ln -s arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-linux-gnu gcc-linaro-aarch64
U-Boot and Linux Makefiles use environment variables such as ARCH and CROSS_COMPILE to configure and call the appropriate compiler. Therefore, you must set these variables in the current shell when compiling the Kernel or U-Boot.
To facilitate this process, create an export-compiler-64 setup file with the commands below.
export ARCH=arm64
export PATH=${HOME}/gcc-linaro-aarch64/bin/:${PATH}
export DTC_FLAGS='-@'
export CROSS_COMPILE=aarch64-none-linux-gnu-
Please note that creating the setup file is not mandatory, it serves only to simplify executing the commands above. You could also run each command individually on every new shell, or create a different environment setup file during the build process.
Source the setup file. Note that you will also need to source it every time you open a new shell to build the Kernel/U-Boot.
$ source ~/export-compiler-64
Get the Sources
Create a directory to store the build files and repositories:
$ mkdir -p ~/workdir
$ cd ~/workdir
The following steps are intended to be run from the ~/workdir directory, created previously.
-
Get the U-Boot source code: For the AM62x based modules, clone U-Boot from Toradex's Downstream source, on the branch
toradex_ti-u-boot-2024.04.$ git clone -b toradex_ti-u-boot-2024.04 https://git.toradex.com/u-boot-toradex.git -
Get the binary-only System Firmware (SYSFW):
$ git clone git://git.ti.com/k3-image-gen/k3-image-gen.git -
Get the TI Linux Firmware:
$ git clone -b ti-linux-firmware git://git.ti.com/processor-firmware/ti-linux-firmware.git -
Get the ARM Trusted Firmware (ATF/TF-A):
$ git clone https://github.com/ARM-software/arm-trusted-firmware.git -
Get the OP-TEE image source code:
$ git clone https://github.com/OP-TEE/optee_os.git -
Get the K3 Security development package:
$ git clone https://git.ti.com/git/security-development-tools/core-secdev-k3.git -b master
The next steps include commands that are intended to be run from the root of the U-Boot source tree unless otherwise specified. The root of the U-Boot tree is the top-level directory u-boot-toradex.
Prepare the Environment
By following the steps below, you will create the env-uboot file, which you must source every time you open a new shell when building U-Boot.
-
Create and append the following environment variables to the
env-ubootfile. Note that this step includes the symbolic links to the cross compilation toolchains in your home directory (gcc-linaro-aarch64andgcc-linaro-arm), which you've set up in Prepare the Environment for Cross-Compilation.$ cd ~/workdir
$ echo "export UBOOT_DIR=$(pwd)/u-boot-toradex" >> env-uboot
$ echo "export K3_DIR=$(pwd)/k3-image-gen" >> env-uboot
$ echo "export TI_LINUX_FW_DIR=$(pwd)/ti-linux-firmware" >> env-uboot
$ echo "export TFA_DIR=$(pwd)/arm-trusted-firmware" >> env-uboot
$ echo "export OPTEE_DIR=$(pwd)/optee_os" >> env-uboot
$ echo "export CORE_SECDEV_K3_DIR=$(pwd)/core-secdev-k3" >> env-uboot
$ echo "export PATH=${HOME}/gcc-linaro-aarch64/bin/:${HOME}/gcc-linaro-arm/bin/:$PATH" >> env-uboot -
Source the
env-ubootfile to export the environment variables:$ source env-uboot
Prepare the Python Environment
The U-Boot build process utilizes third-party Python modules that are not installed by default. Create a Python virtual environment to install these modules:
$ cd ~/workdir
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install cryptography pyelftools setuptools pyyaml yamllint jsonschema
Make sure to always activate the Python venv when spawning new shells to use the same setup configured in the Prepare the Environment section. This will ensure the environment has the required dependencies to proceed with the build.
Build U-Boot
Build ARM Trusted Firmware (ATF/TF-A)
ATF is used as the initial start code on ARMv8-A cores for all K3 platforms. To compile it, go to the directory where you cloned the ARM Trusted Firmware and compile it for the ARM64 architecture.
$ cd $TFA_DIR
$ export ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu-
$ unset TFA_EXTRA_ARGS
$ make PLAT=k3 SPD=opteed $TFA_EXTRA_ARGS TARGET_BOARD=lite
Build OP-TEE Image
Quoting the TI documentation:
OP-TEE is a Trusted Execution Environment (TEE) designed as a companion to a non-secure Linux kernel running on Arm Cortex-A cores using the TrustZone technology.
To build the OP-TEE image, go to the directory where you clone it and perform the steps below:
$ cd $OPTEE_DIR
$ export OPTEE_EXTRA_ARGS="CFG_WITH_SOFTWARE_PRNG=y"
$ export ARCH=arm
$ export CROSS_COMPILE=arm-none-linux-gnueabihf-
$ export CROSS_COMPILE64=aarch64-none-linux-gnu-
$ make PLATFORM=k3-am62x CFG_ARM64_core=y $OPTEE_EXTRA_ARGS
Build U-Boot for the Cortex-R5
-
In the U-boot directory, compile the source code for the R5 core:
$ cd $UBOOT_DIR
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- verdin-am62_r5_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- BINMAN_INDIRS=$TI_LINUX_FW_DIR -
Go to the System Firmware directory and build it.
$ cd $K3_DIR
$ make SOC=am62x SOC_TYPE="hs-fs" TI_SECURE_DEV_PKG=$CORE_SECDEV_K3_DIR SBL=$UBOOT_DIR/spl/u-boot-spl.bin SYSFW_DIR=$TI_LINUX_FW_DIR/ti-sysfw
$ cp tiboot3-am62x-hs-fs-evm.bin ../tiboot3-am62x-hs-fs-verdin.bin
Build U-Boot for the Cortex-A53
In the U-boot directory, compile the source code for the A53 cores:
$ cd $UBOOT_DIR
$ export ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu-
$ make verdin-am62_a53_defconfig
$ make BINMAN_INDIRS=$TI_LINUX_FW_DIR \
BL31=$TFA_DIR/build/k3/lite/release/bl31.bin \
TEE=$OPTEE_DIR/out/arm-plat-k3/core/tee-raw.bin
$ cp tispl.bin ../
$ cp u-boot.img ../
Deploy the U-Boot Binary to an Image
To deploy your custom U-Boot binary to an image, follow the steps described below:
-
Start from an existing sample image: Download and extract one of the Toradex prebuilt images appropriate image for your SoM.
-
Integrate artifacts: Replace the bootloader binary by the one you built. You can find the name of the u-boot binary in the
content/rawfiles/filenamefield of theimage.jsonfile. The following snippet shows, as an example, theimage.jsonfile for the Verdin iMX8M Plus.image.json"name": "mmcblk0boot0",
"erase": true,
"content": {
"filesystem_type": "raw",
"rawfiles": [
{
"filename": "imx-boot",
"dd_options": "seek=2"
}
]
} -
Adjust image.json: If you change the name of the U-Boot binary, change the name of the
content/rawfiles/filenamefield onimage.json -
Deploy the Toradex Easy Installer image: Deploy the modified Toradex Easy Installer package with Toradex Easy Installer.