RPi4 Boot Files - lulu98/projects-with-sel4 GitHub Wiki

RPi4 Boot Files

Basic Boot Files

The necessary files were taken: from https://www.raspberrypi.org/documentation/configuration/boot_folder.md. The file bootcode.bin is not used on the Raspberry Pi 4, because it has been replaced by boot code in the onboard EEPROM.

start4.elf

Download from: https://github.com/raspberrypi/firmware/blob/master/boot/start4.elf These are binary blobs (firmware) that are loaded on to the VideoCore in the SoC, which then take over the boot process.

fixup4.dat

Download from: https://github.com/raspberrypi/firmware/blob/master/boot/fixup4.dat These are linker files and are matched pairs with the start4.elf files listed in the previous section.

bcm2711-rpi-4-b.dtb

Download from: https://github.com/raspberrypi/firmware/blob/master/boot/bcm2711-rpi-4-b.dtb There are various Device Tree blob files, which have the extension .dtb. These contain the hardware definitions of the various models of Raspberry Pi, and are used on boot to set up the kernel according to which Pi model is detected. If this file is missing, U-Boot will only print garbage over UART.

u-boot.bin

The final U-Boot image used in the project is https://github.com/apritzel/u-boot/tree/rpi4-eth-v3 as this version offers support for the new Gigabit Ethernet (GENET) controller on the RPi4. The source code can be obtained with:

git clone https://github.com/apritzel/u-boot.git
cd <path/to/u-boot>
git checkout rpi4-eth-v3

Compile U-Boot binary for RPi4 in 64-bit mode (aarch64-linux-gnu-) with:

make CROSS_COMPILE=aarch64-linux-gnu- rpi_4_defconfig
make CROSS_COMPILE=aarch64-linux-gnu- -j8

config.txt

Contains many configuration parameters for setting up the Pi. Current configuration for 64-bit platform:

arm_64bit=1
uart_2ndstage=1
enable_uart=1
kernel=u-boot.bin

Boot script

We use a boot script boot.scr to tell U-Boot where to get the executable from, i.e. either from the SD card itself or via TFTP.

SD card boot

Content of boot.cmd:

fatload mmc 0 0x10000000 os_image.bin
bootefi 0x10000000

Create boot.scr for 64-bit platform from boot.cmd file:

mkimage -A arm64 -T script -C none -n "Boot script" -d "boot.cmd" boot.scr

TFTP Boot

Content of boot.cmd:

setenv serverip <ip-address-of-server>
dhcp 0x10000000
bootefi 0x10000000

Create boot.scr for 64-bit platform from boot.cmd file:

mkimage -A arm64 -T script -C none -n "Boot script" -d "boot.cmd" boot.scr

seL4 kernel image

The boot.scr file specifies the address the kernel image will be loaded in RAM and starts the kernel from this address. The kernel image represents the seL4 microkernel as well as the application that runs on top of the kernel. In this project, the kernel image is called os_image.bin.

SD card layout

All the boot files can be copied to the root folder of the SD card. The SD card must FAT32 formatted (you can use gparted for formatting). The directory structure of the SD card is as follows:

|__ start4.elf
|__ fixup4.dat
|__ bcm2711-rpi-4-b.dtb
|__ u-boot.bin
|__ boot.scr
|__ os_image.bin

Boot sequence

At power-up, the CPU is offline and a small RISC core on the GPU boots the SoC. Thus, most of the boot components are run on the GPU instead of the CPU. The RPi4 offers different boot modes to boot from, e.g. USB, SD, SPI, Flash (GPIO). The according boot mode is determined by the OTP (one-time programmable) memory and whether ROM finds the FSBL bootcode.bin in one of the boot sources listed in the OTP memory. It probes the list of boot mediums until it finds the according file. It starts with the SD, NAND, SPI and USB.

The following boot order holds for the Raspberry Pi 4:

  1. First stage bootloader (FSBL) - ROM code: On-chip ROM code mounts the FAT32 partition on the SD card so that the second stage bootloader can be accessed. It is programmed on the SoC during manufacture and can not be reprogrammed by the user. The FSBL loads stage 2 in the L2 cache.

(2. Second stage bootloader (SSBL) - bootcode.bin: SSBL retrieves the GPU firmware from the SD card, program the firmware and starts the GPU. In earlier versions of RPi there was also a third stage bootloader (loader.bin) that is no longer required. The Raspberry Pi 4 has an SPI-attached EEPROM (4MBits/512KB), which contains code to boot up the system and replaces bootcode.bin previously found in the boot partition of the SD card.)

  1. GPU firmware - start4.elf: This file allows the GPU to start the CPU. An additional file, fixup4.dat is used to configure the SDRAM partition between the GPU and the CPU. At this point, the CPU is released from reset and execution is transferred over.

  2. User code: This can be any number of binaries. By default, it is the Linux kernel (kernel.img), but it can also be another bootloader (e.g. U-Boot) or a bare-metal application. start4.elf loads kernel.img and reads config.txt, cmdline.txt, bcm2xxx.dtb. The kernel kernel.img is then run on the ARM cores.