Skip to main content
Version: BSP 7.x.y

Build U-Boot for TI AM62Px-based SoMs

Introduction

This article guides you on how to build from source and deploy U-Boot for Toradex's TI AM62Px-based System on Modules (SoMs).

Prepare the Environment for Cross-Compilation

warning

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
info

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-compiler-32
export ARCH=arm
export PATH=${HOME}/gcc-linaro-arm/bin/:${PATH}
export DTC_FLAGS='-@'
export CROSS_COMPILE=arm-none-linux-gnueabihf-
tip

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

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 device-tree-compiler u-boot-tools 

Get the Sources

Create a directory to store the build files and repositories:

$ mkdir -p ~/workdir
$ cd ~/workdir
  1. 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.cn/u-boot-toradex.git
  2. Get the TI Linux Firmware:

    $ git clone -b ti-linux-firmware git://git.ti.com/processor-firmware/ti-linux-firmware.git
  3. Get the ARM Trusted Firmware (ATF/TF-A):

    $ git clone https://github.com/ARM-software/arm-trusted-firmware.git
  4. Get the OP-TEE image source code:

    $ git clone https://github.com/OP-TEE/optee_os.git
  5. Get the K3 Security development package:

    $ git clone https://git.ti.com/git/security-development-tools/core-secdev-k3.git -b master

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.

  1. Create and append the following environment variables to the env-uboot file. Note that this step includes the symbolic links to the cross compilation toolchains in your home directory (gcc-linaro-aarch64 and gcc-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 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 PATH=${HOME}/gcc-linaro-aarch64/bin/:${HOME}/gcc-linaro-arm/bin/:$PATH" >> env-uboot
  2. Source the env-uboot file 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
tip

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

Source the env-uboot and venv/bin/activate files to activate the Python virtual environment and export all the required environment variables, if you haven't done so already:

$ source env-uboot
$ source venv/bin/activate

Create a directory to store the U-Boot binaries:

$ mkdir build

Build ARM Trusted Firmware (ATF/TF-A)

ATF is used as the initial start code on ARMv8-A cores for all K3 platforms. 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

OP-TEE is a Trusted Execution Environment (TEE) that runs alongside the non-secure Linux kernel in the Cortex-A, protecting the Trusted Applications (TAs) via hardware support. For further information about OP-TEE, check out the OP-TEE documentation. Go to the directory where you cloned the OP-TEE source and compile it:

$ 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-am62px 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-am62p_r5_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- BINMAN_INDIRS=$TI_LINUX_FW_DIR
$ cp tiboot3-am62px-hs-fs-verdin.bin ../build/

Build U-Boot for the Cortex-A72

In the U-Boot directory, compile the source code for the A72 cores:

$ cd $UBOOT_DIR 
$ export ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu-
$ make verdin-am62p_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 ../build/
$ cp u-boot.img ../build/

Deploy the U-Boot Binary to an Image

To deploy your custom U-Boot binary to an image, follow the steps described below:

  1. Start from an existing sample image: Download and extract one of the Toradex prebuilt images appropriate image for your SoM.

  2. 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/filename field of the image.json file. The following snippet shows, as an example, the image.json file for the Verdin iMX8M Plus.

    image.json
    "name": "mmcblk0boot0",
    "erase": true,
    "content": {
    "filesystem_type": "raw",
    "rawfiles": [
    {
    "filename": "imx-boot",
    "dd_options": "seek=2"
    }
    ]
    }
  3. Adjust image.json: If you change the name of the U-Boot binary, change the name of the content/rawfiles/filename field on image.json

  4. Deploy the Toradex Easy Installer image: Deploy the modified Toradex Easy Installer package with Toradex Easy Installer.

Send Feedback!