Run U-Boot on a Raspberry Pi 3 Model B+

Updated: 4 minute read

Introduction

This is the third 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.

After Building a (Cross) Toolchain and Building U-Boot, it’s time to make U-Boot run on the Raspberry Pi 3 Model B+.

Several steps are needed to make it all happen. They will be described in the next sections.

Boot Process of the Raspberry Pi 3

To understand the boot process of a Raspberry Pi, I strongly encourage you to read the article “Compiling U-Boot with Device Tree Support for the Raspberry Pi” [1] by Craig Peacock. This article explains that next to the u-boot.bin bootloader we built in Building U-Boot, we need a second stage bootloader called bootcode.bin and a third stage bootloader called start.elf, both of which are closed firmware. More on where to get these later. bootcode.bin will load start.elf and start.elf in turn will load our u-boot.bin bootloader.

All the mentioned bootloaders will have to be on the first partition of the SD card (within a FAT file system). If you haven’t prepared the SD card yet, please refere to the article “Boot a Raspberry Pi 4 using u-boot and Initramfs” [2] by Hechao.

Install Closed Source Bootloaders

Note: Make absolutely sure you know which device node under /dev/ represents the SD card on your host system, before you mount any partitions on it. Otherwise you might lose data you didn’t want to lose. On my machine, I can find the SD card under /dev/sdb. The first partition is /dev/sdb1, the second one /dev/sdb2. This might be different on your machine, so you might have to adjust these paths in the following commands.

As mentioned in the last section, we need two files bootcode.bin and start.elf. This caused me some headaches. First I used the files that Craig Peacock used in the mentioned article [1]. Unfortunately they just didn’t work. U-Boot just did not boot. For ages I couldn’t figure out why. Anyway, at some point I realized that the downloaded files were the problem. I don’t know where I found the link that will be used in the following list of commands, but the files from there worked for me.

$> cd <project/root/dir>
$> mkdir rpi
$> cd rpi
$> wget https://github.com/raspberrypi/firmware/archive/master.zip
$> unzip master.zip
$> rm master.zip

The extracted archive firmware-master will contain a directory called boot. Within that directory you will find the necessary files. Mount the boot file system of the SD card and copy these files onto it. In case U-Boot does not start later on, remember that I had problems with the downloaded second and third stage bootloaders. It might be that you need another source for these files. I downloaded them on the 2nd of November 2023.

$> sudo mkdir -p /mnt/boot
$> sudo mount /dev/sdb1 /mnt/boot
$> sudo cp <project/root/dir>/rpi/firmware-master/boot/bootcode.bin /mnt/boot/
$> sudo cp <project/root/dir>/rpi/firmware-master/boot/start.elf /mnt/boot/

Install and Configure U-Boot

Installing U-Boot is as simple as copying the u-boot.bin file onto the SD card:

$> sudo cp <project/root/dir>/u-boot/u-boot.bin /mnt/boot/

To configure U-Boot or actually the third stage bootloader, place a file called config.txt onto the SD card with the following content:

enable_uart=1
kernel=u-boot.bin
arm_64bit=1
core_freq=250

This causes start.elf to load u-boot.bin and enables the UART interface of the Raspberry Pi.

At this point you should have four files on the SD card:

$> ls /mnt/boot
bootcode.bin  config.txt  start.elf  u-boot.bin

Run U-Boot

Now you can unmount the SD card from your host system:

$> sudo umount /mnt/boot

and place the card into the card holder of the Raspberry Pi. Once the SD card is in the Raspberry Pi and you have a connection to the UART interface, you can power up the board. You should see an output similar to the following:

U-Boot 2023.10-00730-gd9bb6d779b (Nov 02 2023 - 08:36:28 +0100)

DRAM:  128 MiB
RPI 3 Model B+ (0xa020d3)
Core:  67 devices, 14 uclasses, devicetree: embed
MMC:   mmc@7e202000: 0, mmc@7e300000: 1
Loading Environment from FAT... Unable to read "uboot.env" from mmc0:1...
In:    serial,usbkbd
Out:   serial,vidconsole
Err:   serial,vidconsole
Net:   No ethernet found.
starting USB...
Bus usb@7e980000: USB DWC2
scanning bus usb@7e980000 for devices... 4 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  2  1  0
lan78xx_eth Waiting for PHY auto negotiation to complete......... TIMEOUT !
phy_startup failed
lan78xx_eth Waiting for PHY auto negotiation to complete......... TIMEOUT !
phy_startup failed
U-Boot>

Well, that’s it for now. Have fun with U-Boot on the Raspberry Pi. The next step will be to Build the Linux Kernel for a Raspberry Pi 3 Model B+.

Change Log

2025-02-01:

  • Made the post fit into the series of posts about embedded Linus on a Raspberry Pi 3 Model B+.

2025-01-20:

  • Fixed a typo.
  • Adjusted link to “Boot a Raspberry Pi 4 using u-boot and Initramfs” blog post.

2023-11-08:

  • Correct name of Raspberry Pi model.
  • Added missing $> for some command to indicate the command prompt and differentiate command input and output. The $> indicates the command prompt on the host system. Once U-Boot has started it issues a command prompt as well: U-Boot>. This is on the target system (the Raspberry Pi).



Take care,
Andreas


References

  1. C. Peacock, “Compiling U-Boot with Device Tree Support for the Raspberry Pi,” 05-Oct-2018. [Online]. Available at: https://www.beyondlogic.org/compiling-u-boot-with-device-tree-support-for-the-raspberry-pi/. [Accessed: 02-Nov-2023].
  2. Hechao, “Boot a Raspberry Pi 4 using u-boot and Initramfs,” 20-Dec-2020. [Online]. Available at: https://hechao.li/posts/Boot-Raspberry-Pi-4-Using-uboot-and-Initramfs/. [Accessed: 31-Jan-2025].

Updated:

Leave a comment