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

Build U-Boot From Source Code

Introduction​

This series of articles describes how to build the U-Boot without using a higher-level build system such as the Yocto Project/OpenEmbedded. This procedure mostly makes sense during bootloader development.

We provide OpenEmbedded recipes that build U-Boot and Linux as part of a complete BSP image. If you plan to build a full BSP image, follow the Build a Reference Image with Yocto Project/OpenEmbedded article.

This is an overview article of the necessary process for building the bootloader from source code. If you are looking for specific information regarding module- or SoC-specific instructions, check the Additional Module-specific Steps section.

Prerequisites​

Check out our Embedded Linux Release Matrix for a high-level overview of the BSP Versions. There you will find the version information of the Linux kernel, U-Boot, Yocto/OpenEmbedded, the Toradex BSP, and Linux images, along with release dates.

Prepare the Environment for Cross Compilation​

It's recommended to use the version 9.2 or higher of the ARM GNU Toolchain to cross-compile software for Toradex modules. To install the toolchain on your host machine, . From the command-line:

  1. Download and unpack the the 32-bit and/or 64-bit Arm cross-toolchain files

    $ 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
  2. Set the toolchain path:

    $ ln -s arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-linux-gnueabihf gcc-linaro
  3. Prepare the environment variables:

    $ export ARCH=arm
    $ export DTC_FLAGS="-@"
    $ export PATH=~/gcc-linaro/bin/:$PATH
    $ export CROSS_COMPILE=arm-none-linux-gnueabihf-

Install Tools and Dependencies​

  1. Install the Device Tree Compiler (DTC) Tool: U-Boot and the device tree overlays compilation for some modules need a device tree compiler (DTC). We recommend DTC version 1.6.0 or higher.

    $ git clone git://git.kernel.org/pub/scm/utils/dtc/dtc.git -b v1.6.0 ~/dtc
    $ cd ~/dtc
    $ make
    $ export PATH=$HOME/dtc/:$PATH
    info

    On Fedora and on Ubuntu 22.04, there have been reported DTC build errors libfdt/libfdt.h:251:28: warning: array subscript β€˜struct fdt_header[0]’ is partly outside array bounds of β€˜unsigned char[4]’ [-Warray-bounds].

    To disable treating warnings as errors, you can remove the flag -Werror from the CFLAGS on the Makefile.
    We have not evaluated the consequences of doing it, do it at your own risk!

  2. Install U-Boot Tools: The uImage target of the Linux kernel compilation needs a recent mkimage tool.

    $ sudo apt-get install u-boot-tools

    Alternatively, mkimage tool is also built during the U-Boot compilation. You can follow the U-Boot building instructions as explained further in this article, and after that, include it in PATH.

  3. Install Bison, Flex, Swig and OpenSSL: The Bison, Flex and Swig packages are necessary to configure U-Boot from a defconfig, while the OpenSSL development package is used in the U-Boot compilation.

    $ sudo apt-get install bison flex swig libssl-dev

U-Boot Version Information​

The required git branch, U-Boot configuration, and U-Boot/Linux binaries to be used depend on the module type and the BSP version, as we will explain in this article.

SoCU-Boot Git BranchU-Boot ConfigurationU-Boot Binary
i.MX 8/8X/8MM/8MPtoradex_imx_lf_v2022.04apalis-imx8_defconfig
colibri-imx8x_defconfig
verdin-imx8mm_defconfig
verdin-imx8mp_defconfig
imx-boot
i.MX 7v2022.07colibri_imx7_defconfig
colibri_imx7_emmc_defconfig
u-boot-nand.imx
u-boot.imx
i.MX 6v2022.07apalis_imx6_defconfig
colibri_imx6_defconfig
u-boot.img
i.MX 6ULLv2022.07colibri-imx6ull_defconfig
colibri-imx6ull-emmc_defconfig
u-boot-nand.imx
u-boot.imx
TI AM62xtoradex_ti-u-boot-2023.04verdin-am62_a53_defconfig
verdin-am62_r5_defconfig
u-boot.img
tispl.bin
tiboot3-am62x-gp-verdin.bin
tiboot3-am62x-hs-fs-verdin.bin

In the case of TI AM62x-based modules, both defconfig configurations are used.

The meta-toradex-bsp-common hashes for each BSP version to be used in the following steps are presented in the table below:

BSP VersionHash
6.0.07b2a41b8da74d7b783cb5a15ba945ebdb9b57f26
6.1.01a14c2724ab0cbcf3d01042fed7b60b48c8ab836
6.2.0a969df0f7e2188271e80f67f97ab1a0bc0e67b9c
6.3.0f7ff10a3b560dcf4e258115da679d1f864e09837
6.4.056e195b10849e2973130695a1917c987a4fe1813

Building U-Boot​

In the following instructions, you will be directed to create a directory called ~/workdir to store all the source and build files. You can, of course, replace this directory name with any other name you prefer.

Fetch U-Boot Sources​

Obtain the U-Boot source code using Git. For upstream-based modules (i.e. NXP i.MX 6/6 ULL and 7) U-Boot is fetched from https://gitlab.com/u-boot/u-boot.git. For downstream-based modules (NXP i.MX 8/8X/8MM/8MP and TI AM-62x), U-Boot is fetched from https://git.toradex.com/u-boot-toradex.git.

$ mkdir -p ~/workdir
$ cd ~/workdir
$ git clone https://gitlab.com/u-boot/u-boot.git
caution

The following section is only necessary if using an upstream-based module. If you are using a downstream-based module, please, go to the Configure U-Boot section.

Get and Apply the Necessary Patches​

  1. Once inside the root folder of you local copy of U-Boot repository, checkout to the <branch> according to the U-Boot Git Branch for your specific configuration. Check the section U-boot Version for this specific information. Then create a branch based on the <branch> to just checked out. Also create a patches directory to store the patches you will fetch.

    $ cd u-boot
    $ git checkout <branch>
    $ git checkout -b toradex-<branch>
    $ mkdir patches
    $ cd patches
  2. Get the patches from Toradex git in the BSP Common OE layer at meta-toradex-bsp-common.git - recipes common to all modules. The patches for U-boot are located inside the folder meta-toradex-bsp-common/recipes-bsp/u-boot/u-boot-toradex. Fetch the layer with git and checkout it to the hash of the BSP release version and then copy the patches to U-Boot patches directory.

    $ cd ~/workdir
    $ git clone https://git.toradex.com/cgit/meta-toradex-bsp-common.git
    $ cd meta-toradex-bsp-common
    $ git checkout <meta-toradex-bsp-common-hash>
    $ cp -r ../meta-toradex-bsp-common/recipes-bsp/u-boot/u-boot-toradex/*.patch ../u-boot/patches
  3. Apply the patches using git am from the patches directory in the correct order as shown on the command below. All the patches must apply with no errors. For a double check, use git log --oneline to see the patches commit messages.

    $ cd ../u-boot/patches

    $ git am 0001-toradex-tdx-cfg-block-use-only-snprintf.patch \
    0002-toradex-tdx-cfg-block-use-defines-for-string-length.patch \
    0003-toradex-tdx-cfg-block-extend-assembly-version.patch \
    0004-toradex-tdx-cfg-block-add-new-toradex-oui-range.patch \
    0005-toradex-tdx-cfg-block-add-0068-i.mx-8m-mini-sku.patch \
    0006-toradex-common-Remove-stale-comments-about-modules-a.patch \
    0007-toradex-common-Use-ARRAY_SIZE-macro.patch \
    0008-toradex-tdx-cfg-block-Cleanup-interactive-cfg-block-.patch \
    0009-toradex-common-Remove-stale-function-declaration.patch \
    0010-toradex-common-Remove-ifdef-usage-for-2nd-ethaddr.patch \
    0011-toradex-tdx-cfg-block-Use-official-SKU-names.patch \
    0012-toradex-common-Improve-product-serial-print-during-b.patch \
    0013-configs-colibri-imx7-Enable-bootd-command.patch \
    0001-ARM-imx8mp-verdin-imx8mp-Add-memory-size-detection.patch \
    0001-apalis-colibri_imx6-imx6ull-_imx7-update-env-memory-.patch \
    0001-configs-colibri-imx7-Fix-bad-block-table-in-flash-co.patch \
    0001-colibri_imx6-fix-RALAT-and-WALAT-values.patch

    $ git log --oneline

Configure U-Boot​

  1. Find the right configuration file at the U-Boot Version Information table.

  2. Go to the u-boot directory and use make mrproper for a clean configuration. Then, execute make <board_defconfig> (check the board_defconfig in the table of the section U-boot Version Information) to configure U-boot from a defconfig:

    $ cd ~/workdir/u-boot
    $ make mrproper
    $ make <board_defconfig>

Compile U-Boot​

After the configuration process, the sources of U-Boot are ready to be built.

$ make -j$(nproc) 2>&1 | tee build.log

Additional Module-specific Steps​

The following articles contain mandatory specific steps for a full bootloader build and configuration:

Deploy the U-Boot binary to an Image​

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

  1. Start from a Existing Sample Image: Download and extract one of the Toradex prebuilt images. Choose the appropriate image for your SoM in the Reference Images for Yocto Project Software Downloads
  2. Integrate Artifacts: Integrate the U-Boot artifacts into our regular Toradex Easy Installer package by replacing the U-Boot binary (according to the U-Boot Version Information) and, if applicable, the SPL in the unpacked Toradex prebuilt image downloaded above.
  3. Adjust Image.json: Now, adjust the image.json to your liking (e.g., change the name and description to distinguish it from the original package). You may, of course, also change any of the other properties as documented in the Toradex Easy Installer article on our developer website.
  4. Deploy the Toradex Easy Installer Image: You may now use the above prepared Toradex Easy Installer package with the Toradex Easy Installer.


Send Feedback!