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

Build U-Boot for NXP i.MX 8M Mini/Plus-based SoMs

Introduction

This article guides you on how to build from source and deploy U-Boot for Toradex's NXP i.MX 8M Mini/Plus-based System on Modules (SoMs).

Prepare the Environment for Cross-Compilation

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-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-compiler-64
export ARCH=arm64
export PATH=${HOME}/gcc-linaro-aarch64/bin/:${PATH}
export DTC_FLAGS='-@'
export CROSS_COMPILE=aarch64-none-linux-gnu-
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.

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

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

The following steps are intended to be run from the ~/workdir directory, created previously.

Get the U-Boot source code: For the i.MX 8M Mini/Plus based modules, clone U-Boot from the Upstream source. Choose the <u-boot-git-branch> according to the table below.

$ git clone -b <u-boot-git-branch> https://gitlab.com/u-boot/u-boot.git
SoCU-Boot Git BranchU-Boot ConfigurationU-Boot Binary
i.MX 8M Miniv2024.07verdin-imx8mm_defconfigimx-boot
i.MX 8M Plusv2024.07verdin-imx8mp_defconfigimx-boot

Apply Required Patches

  1. Create a branch based on the <u-boot-git-branch>, and create a patches directory to store the patches you are going to apply.

    $ cd u-boot
    $ git checkout -b toradex-<branch>
    $ mkdir patches && cd patches
  2. Clone the meta-toradex-bsp-common repository, which contains recipes common to all modules. Checkout to the BSP release commit hash (<meta-toradex-bsp-common-hash>) and copy the patches to the U-Boot patches directory. You can check the <meta-toradex-bsp-common-hash> for your BSP version on the table below.

    BSP VersionHash
    7.5.03fead3b1e2dcf83e086647b4f0e4185a94f12f11
    7.4.0c884e6b86563a011f43959c23eda075828f7d75d
    7.3.095c85e1a570732a4680a5b7a720bb691741b78b7
    $ cd ~/workdir
    $ git clone https://git.toradex.cn/cgit/meta-toradex-bsp-common.git
    $ cd meta-toradex-bsp-common
    $ git checkout <meta-toradex-bsp-common-hash>
    $ cp recipes-bsp/u-boot/u-boot-toradex/*.patch ~/workdir/u-boot/patches
  3. Apply the patches with the commands below. You must apply the patches in the same order as the TDX_PATCHES variable from the Toradex U-Boot Upstream Recipe.

    $ cd ~/u-boot/patches

    $ git am [first-patch-file-name].patch \
    [second-patch-file-name].patch \
    [third-patch-file-name].patch \
    [fourth-patch-file-name].patch \
    [fifth-patch-file-name].patch \

    Check if the patches were applied using the command below. You should see the commit messages for each applied patch.

    $ git log --oneline

Build U-Boot

The i.MX 8M Mini/Plus-based modules use the Upstream U-Boot source. Therefore, you should follow the instructions provided in the U-Boot official documentation for each module using the links below. Keep in mind that you must choose the corresponding _defconfig for your module according to the table in the previous section.

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!