RPi U-Boot

= Overview =

Das U-Boot, often abbreviated to just U-Boot, is a bootloader commonly used on embedded systems. U-Boot can be used on the RPi to add flexibility by allowing other boot configurations to be used on top of the single specified file on the SD card. If you wish to run an upstream kernel, booting it via U-Boot is recommended.

This page explains how to get U-Boot working on the RPi, and explains how to boot images off both the SD card and over TFTP from the network.

= Get the source =

Various forks of U-Boot contain (different levels of) support for the Raspberry Pi. You will to download the source from one of the locations below; pick one, and ignore the others.

If you don't need USB networking or keyboard support in U-Boot, the mainline repository is recommended. If you do need USB networking or keyboard support in U-Boot, Stephen Warren's repository is recommended.

Mainline
The primary repository for U-Boot is git://git.denx.de/u-boot.git master branch. This supports the UART (serial port), SD card, and HDMI display. As of 20140210, the primary missing feature is USB support, and hence networking support.

To download this repository into a new local repository (this is what you want if you don't know better):

git clone git://git.denx.de/u-boot.git

To add this repository to an existing local repository:

git remote add u-boot git://git.denx.de/u-boot.git git fetch u-boot git checkout -b your_branch_name u-boot/master

Stephen Warren's work-in-progress branch
Stephen Warren is working on getting BCM2835 USB support into the mainline repository described above. His work-in-progress repository is git://github.com/swarren/u-boot.git rpi_dev branch. Note that this branch is often rebased, and may contain work other than mainline-quality RPi-related patches.

To download this repository into a new local repository (this is what you want if you don't know better):

git clone git://github.com/swarren/u-boot.git git checkout -b rpi_dev origin/rpi_dev

To add this repository to an existing local repository:

git remote add github_swarren_u-boot git://github.com/swarren/u-boot.git git fetch github_swarren_u-boot git checkout -b rpi_dev github_swarren_u-boot/rpi_dev

Oleksandr Tymoshenko's branch
Oleksandr's branch is based on an old U-Boot release, and hence some instructions later in this document will need to be adjusted since the "bootz" command isn't supported; use "bootm" instead, and mkimage to create e.g. uImage from zImage. This is left as an exercise for the reader.

This branch does contain working USB support. It is available at git://github.com/gonzoua/u-boot-pi.git branch master.

To download this repository into a new local repository (this is what you want if you don't know better):

git clone git://github.com/gonzoua/u-boot-pi.git

To add this repository to an existing local repository:

git remote add github_gonzoua_u-boot-pi git://github.com/gonzoua/u-boot-pi.git git fetch github_gonzoua_u-boot-pi git checkout -b your_branch_name github_gonzoua_u-boot-pi/master

You can download a source tarball from this link.

= Get an ARM compiler =

If you are building U-Boot on a Raspberry Pi, or other ARM platform, you can skip this step; the native compiler already generates ARM instructions.

If you are building U-Boot on a different system, e.g. an x86 PC, you will need an ARM cross-compiler. Pick one of the options below, and ignore the others.

The toolchain you pick needs to have its associated libgcc compiled in a manner that is compatible with the RPi's ARM CPU. If this is not the case, see the section below that describes the Linaro compiler.

Ubuntu packages
(Stephen Warren recommends this option)

Ubuntu includes an ARM cross compiler in its standard package step. You can install it as follows:

apt-get install gcc-arm-linux-gnueabi

Each time you start a new shell to compile U-Boot, run the following first:

export CROSS_COMPILE=arm-linux-gnueabi-

Other distributions likely also provide ARM cross-compilers. Consult distro-specific documentation for details.

Raspberry Pi Foundation Tools
The Raspberry Pi Foundation provides a compiler in their tools repository. You can obtain it by:

cd $HOME git clone git://github.com/raspberrypi/tools rpi-tools

Each time you start a new shell to compile U-Boot, run one of the following first, depending on which particular toolchain you want to use:

export CROSS_COMPILE=$HOME/rpi-tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/arm-bcm2708hardfp-linux-gnueabi-

export CROSS_COMPILE=$HOME/rpi-tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-

export CROSS_COMPILE=$HOME/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/bin/

Linaro Compilers
The Linaro compilers (at least those current as of 20140210) contain a non-multilib libgcc that is compiled for a newer CPU architecture than the RPI's CPU. Hence, by default, the Linaro compiler will generate a U-Boot image that doesn't work. To solve this, run the following before compiling U-Boot:

export USE_PRIVATE_LIBGCC=yes

You can also create or edit the file arch/arm/cpu/arm1176/bcm2835/config.mk, with the following content:

USE_PRIVATE_LIBGCC = yes

Make sure you perform a clean build after making setting USE_PRIVATE_LIBGCC.

= Compile the source =

(Remember to set up CROSS_COMPILE first, as described above.)

Then, in the U-Boot source directory, run the following to start the build:

make -j8 -s rpi_b

You may wish to change the "8" in "-j8" to match the number of CPUs on your build system, or whatever make job limit you find works best.

The build process should take no more than a few minutes. This should generate u-boot.bin.

= Copy U-Boot to your SD card =

The RPi binary firmware can boot U-Boot just like it can boot a downstream kernel. As such, you can simply copy u-boot.bin to kernel.img on the SD card. You shouldn't need any options in config.txt for this to work. Something like the following should work, as root:

Once, to back up your original config.txt:

mount /dev/sdb1 /mnt/tmp mv /mnt/tmp/config.txt /mnt/tmp/config.txt.pre-uboot umount /mnt/tmp

Every time you want to copy a new U-Boot binary to the SD card:

mount /dev/sdb1 /mnt/tmp cp u-boot.bin /mnt/tmp/kernel.img umount /mnt/tmp

Alternatively, you may wish not to rename the U-Boot binary. If so, the following should work, as root:

Once, to back up your original config.txt:

mount /dev/sdb1 /mnt/tmp mv /mnt/tmp/config.txt /mnt/tmp/config.txt.pre-uboot umount /mnt/tmp

Every time you want to copy a new U-Boot binary to the SD card:

mount /dev/sdb1 /mnt/tmp cp u-boot.bin /mnt/tmp/ echo 'kernel=uboot.img' > /mnt/tmp/config.txt umount /mnt/tmp

In the commands above, you may need to replace "/dev/sdb1" with a different device filename, depending on where your SD card reader shows up. cat /proc/partitions should help you locate the correct device filename.

= Test U-Boot =

Boot up the RPi with your new U-Boot image. You should see U-Boot load on the screen (HDMI), and also on the serial port output (if you have it connected up).

= Kernel Command-Line =

In all of the example commands shown below to boot a kernel:


 * You may omit earlyprintk if you're not doing kernel development/testing, and are not experiencing early boot problems.
 * You may omit console=ttyAMA0 if you don't want to use the serial console.
 * You may omit console=tty1</tt> if you don't want to use a virtual terminal console (HDMI/USB keyboard).
 * The root=</tt> option is correct for a Raspbian image. You may need to adjust this if your partition layout is different.

= Booting from an SD card =

To boot a kernel that doesn't use Device Tree:

mmc dev 0 fatload mmc 0:1 ${kernel_addr_r} zImage setenv bootargs earlyprintk console=ttyAMA0 console=tty1 root=/dev/mmcblk0p2 rootwait bootz ${kernel_addr_r}

If your kernel uses Device Tree:

setenv fdtfile bcm2835-rpi-b.dtb mmc dev 0 fatload mmc 0:1 ${kernel_addr_r} zImage fatload mmc 0:1 ${fdt_addr_r} ${fdtfile} setenv bootargs earlyprintk console=ttyAMA0 console=tty1 root=/dev/mmcblk0p2 rootwait bootz ${kernel_addr_r} - ${fdt_addr_r}
 * 1) swarren's branch already sets this automatically, so you can skip this
 * 2) Mainline U-Boot will set the following automatically soon

= Network boot via TFTP =

Configure DHCP server
If you don't want to use a static IP for the RPi, you'll need to make sure it's attached to a network with an active DHCP server.

Configure TFTP Server
You will need to have a TFTP server installed and configured.Place your zImage and DTB file(s) in the TFTP root directory, and ensure that the file permissions are set accordingly (everyone should have read access - use chmod a+r zImage</tt> if unsure).

Boot Using Dynamic IP
To boot a kernel that doesn't use Device Tree:

usb start dhcp ${kernel_addr_r} zImage setenv bootargs earlyprintk console=ttyAMA0 console=tty1 root=/dev/mmcblk0p2 rootwait bootz ${kernel_addr_r}

If your kernel uses Device Tree:

setenv fdtfile bcm2835-rpi-b.dtb usb start dhcp ${kernel_addr_r} zImage tftp ${fdt_addr_r} ${fdtfile} setenv bootargs earlyprintk console=ttyAMA0 console=tty1 root=/dev/mmcblk0p2 rootwait bootz ${kernel_addr_r} - ${fdt_addr_r}
 * 1) swarren's branch already sets this automatically, so you can skip this
 * 2) Mainline U-Boot will set the following automatically soon

Boot Using Static IP
To boot a kernel that doesn't use Device Tree:

usb start setenv serverip <tftp_server_ip> setenv ipaddr <a_spare_ip_address> tftp ${kernel_addr_r} zImage setenv bootargs earlyprintk console=ttyAMA0 console=tty1 root=/dev/mmcblk0p2 rootwait bootz ${kernel_addr_r}

If your kernel uses Device Tree:

setenv fdtfile bcm2835-rpi-b.dtb usb start setenv serverip <tftp_server_ip> setenv ipaddr <a_spare_ip_address> tftp ${kernel_addr_r} zImage tftp ${fdt_addr_r} ${fdtfile} setenv bootargs earlyprintk console=ttyAMA0 console=tty1 root=/dev/mmcblk0p2 rootwait bootz ${kernel_addr_r} - ${fdt_addr_r}
 * 1) swarren's branch already sets this automatically, so you can skip this
 * 2) Mainline U-Boot will set the following automatically soon

= U-Boot script files =

uEnv.txt
swarren's branch (and soon mainline) load file /uEnv.txt</tt> from the SD card prior to auto-booting and/or entering the command-line. This file can be used to customize the U-Boot environment at an early stage. Each line, of the format name=value</tt>, sets one environment variable.

boot.scr.uimg
swarren's branch and mainline both search all known storage devices for a file name boot.scr.uimg</tt> (or boot.scr</tt>) in either /</tt> or /boot</tt>. The SD card is searched, as is any USB storage device if USB support is enabled in U-Boot. The commands described in the various booting sections above may be placed into this file, and will be automatically executed by U-Boot once the autoboot timer expires.

To create this file:

vi boot.scr mkimage -A arm -O linux -T script -C none -n boot.scr -d boot.scr boot.scr.uimg
 * 1) Place the relevant set of boot commands into the file

Now, copy boot.scr.uimg</tt> to your SD card.

"DHCP" boot
swarren's branch (and mainline once USB support lands there) both attempt to download a file named boot.scr.uimg</tt> from a TFTP server. Create the file as described in the previous section, and place it in your TFTP server's data directory.

PXE
swarren's branch (and mainline once USB support lands there) both attempt to download and execute an extlinux/syslinux (BootLoaderSpec) config file from a TFTP server. Create e.g. pxelinux.cfg/default</tt> in the TFTP server's data directory. An interactive menu will be displayed for the various boot options described in this file.

boot_targets
The U-Boot environment variable boot_targets</tt> may be used to configure which auto-boot targets are executed at boot. uEnv.txt may be used to configure this variable.