Build U-Boot For a Raspberry Pi 3 Model B+

Updated: 2 minute read

Introduction

This is the second post in a series of posts (in a tutorial) about building an embedded Linux system for a Raspberry Pi 3 Model B+. A summary post for the tutorial can be found here. The summary post also talks about …

  • what is required to follow along,
  • the <project/root/dir>,
  • some terms that will be used throughout the series,
  • a link to an article that explains how to prepare the SD card,
  • some hints on how to use the UART interface of the Raspberry Pi.

This post is about building a bootlaoder for the embedded Linux system. To do so. There are different options for such a bootloader. Maybe the most popular option is U-Boot [1]. So, we will use U-Boot.

Let’s get started.

Building U-Boot

First of all you need to get the source code of U-Boot:

cd <project/root/dir>
git clone git://git.denx.de/u-boot.git
cd u-boot
git checkout v2023.10

As we need the toolchain that was build before, our PATH needs to be prepended. In case you followed my description in Building a (Cross) Toolchain, you just have to adjust <project/root/dir> in the following command. Otherwise you might have to adjust more. To prepend the PATH, run:

PATH=<project/root/dir>/x-tools/aarch64-rpi3-linux-gnu/bin/:$PATH

Additionally we need to set an environment variable:

export CROSS_COMPILE=aarch64-rpi3-linux-gnu-

Now we can start building the bootloader.

Note: The following command will delete a file called .config in your current working directory. In case you have been working on a configuration for a U-Boot before, you might want to save this .config file for later use.

For good measure, you should run:

make distclean

before you start building the bootloader.

The first thing you need to do to build U-Boot is to configure the bootloader you want to build. This can be quite complex. It helps to use a sample configuration and, if needed, adjust it. You can find U-Boot configurations in the configs directory of the source repository. For the Raspberry Pi 3 Model B+, I used the rpi_3_b_plus_defconfig configuration, by running:

make rpi_3_b_plus_defconfig

It is possible to adjust the configuration, but I left it as it was. If you do want to adjust anything, you can run the following command to launch a terminal based configuration tool:

make menuconfig

When you are satisfied with the configuration, the final step is to actually build the bootloader. This is as simple as just running make:

make

Once this command terminates and everything went to plan, you will have a bunch of new files in your current working directory. One of which is the newly build bootloader u-boot.bin.

If you run tree -L 2 in your <project/root/dir> now, you should see the following:

$> cd <project/root/dir>
$> tree -L 2
.
├── crosstool-ng
│   ├── bin
│   ├── ... (output shortened)
├── u-boot
│   ├── ... (output shortened)
│   ├── u-boot.bin
│   ├── ... (output shortened)
└── x-tools
    └── aarch64-rpi3-linux-gnu

How to run the bootloader, will be the subject of another post.

Change Log

2025-02-01:

  • Fixed the note about deleting the file .config. It spanned a little bit too far.
  • Rewrote the Introduction section.
  • Made the post fit into the series of posts about embedded Linus on a Raspberry Pi 3 Model B+.

2023-11-13:

  • Add link to post about running U-Boot.

2023-11-08:

  • Correct name of Raspberry Pi model.

2023-11-02:

  • Adjusted the used paths a little bit.



Take care,
Andreas


References

  1. The U-Boot development community, “The U-Boot Documentation.” [Online]. Available at: https://u-boot.readthedocs.io/en/latest/. [Accessed: 01-Nov-2023].

Updated:

Leave a comment