Difference between revisions of "RPi U-Boot"

From eLinux.org
Jump to: navigation, search
(Fix heading levels)
(New sd card boot cmdline, changed order (first, the default and more common scenario). Detailed the rootfs= clause too.)
(26 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
= Overview =
 
= Overview =
[http://www.denx.de/wiki/U-Boot 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.  
+
 
 +
[http://www.denx.de/wiki/U-Boot 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.
 
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.
Line 8: Line 9:
 
= Get the source =
 
= Get the source =
  
Various forks of U-Boot contain (different levels of) support for the Raspberry Pi.
+
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 support in U-Boot, the mainline repository is recommended. If you do need USB networking support in U-Boot, Stephen Warren's repository is recommended.
+
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 ==
 
== 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 20140110, the primary missing feature is USB support, and hence networking support.
+
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):
 
To download this repository into a new local repository (this is what you want if you don't know better):
Line 24: Line 25:
 
  git remote add u-boot git://git.denx.de/u-boot.git
 
  git remote add u-boot git://git.denx.de/u-boot.git
 
  git fetch u-boot
 
  git fetch u-boot
 +
git checkout -b your_branch_name u-boot/master
  
 
== Stephen Warren's work-in-progress branch ==
 
== Stephen Warren's work-in-progress branch ==
Line 42: Line 44:
 
== Oleksandr Tymoshenko's branch ==
 
== Oleksandr Tymoshenko's branch ==
  
Oleksandr's branch is based on an old U-Boot release, but does contain working USB support. It is available at git://github.com/gonzoua/u-boot-pi.git branch master.
+
Oleksandr's branch contains working USB support. Pre-built tarballs can be found [http://people.freebsd.org/~gonzo/arm/rpi/ here]. These releases are meant to boot FreeBSD; if you're booting Linux, copy only the u-boot binary to your boot partition and follow the instructions later on this page.
 +
 
 +
To build it yourself, get the source from git://github.com/gonzoua/u-boot-pi.git branch rpi.
  
 
To download this repository into a new local repository (this is what you want if you don't know better):
 
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
+
  git clone -b rpi git://github.com/gonzoua/u-boot-pi.git
  
 
To add this repository to an existing local repository:
 
To add this repository to an existing local repository:
Line 52: Line 56:
 
  git remote add github_gonzoua_u-boot-pi git://github.com/gonzoua/u-boot-pi.git
 
  git remote add github_gonzoua_u-boot-pi git://github.com/gonzoua/u-boot-pi.git
 
  git fetch github_gonzoua_u-boot-pi
 
  git fetch github_gonzoua_u-boot-pi
 +
git checkout -b your_branch_name github_gonzoua_u-boot-pi/rpi
  
 
You can download a source tarball from [https://github.com/gonzoua/u-boot-pi/archive/rpi.tar.gz this link].
 
You can download a source tarball from [https://github.com/gonzoua/u-boot-pi/archive/rpi.tar.gz 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 <tt>arch/arm/cpu/arm1176/bcm2835/config.mk</tt>, with the following content:
 +
 +
USE_PRIVATE_LIBGCC = yes
 +
 +
Make sure you perform a clean build after making setting <tt>USE_PRIVATE_LIBGCC</tt>.
  
 
= Compile the source =
 
= Compile the source =
  
Firstly, you will need to export the cross-compiler prefix in order to target the RPI. Assuming your gcc binary is arm-none-linux-gnueabi-gcc, the command is:
+
(Remember to set up CROSS_COMPILE first, as described above.)
<pre>
+
 
CROSS_COMPILE=arm-none-linux-gnueabi-
+
Then, in the U-Boot source directory, run one of the following to configure the source tree to build for the Raspberry Pi:
export CROSS_COMPILE
+
 
</pre>
+
# Very recent versions of U-Boot:
 +
make rpi_b_defconfig
 +
 +
# Older versions:
 +
make rpi_b_config
 +
 
 +
Then, perform the actual build:
 +
 
 +
make -j8 -s
 +
 
 +
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 <tt>u-boot.bin</tt>.
 +
 
 +
= 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 <tt>u-boot.bin</tt> to <tt>kernel.img</tt> 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:
  
Then, in the U-Boot source directory, run the following to start the build:
+
Once, to back up your original config.txt:
<pre>
 
make rpi_b
 
</pre>
 
  
The build process should take no more than a few minutes.  
+
  mount /dev/sdb1 /mnt/tmp
<tt>u-boot.bin</tt> should have been created.
+
mv /mnt/tmp/config.txt /mnt/tmp/config.txt.pre-uboot
 +
umount /mnt/tmp
  
= Prepare the image file =
+
Every time you want to copy a new U-Boot binary to the SD card:
  
Follow [[RPi_Kernel_Compilation#Prepare the image file|kernel compilation instructions]] to obtain <tt>kernel.img</tt> from <tt>u-boot.bin</tt>.
+
mount /dev/sdb1 /mnt/tmp
 +
cp u-boot.bin /mnt/tmp/kernel.img
 +
umount /mnt/tmp
  
Once complete, transfer your <tt>kernel.img</tt> file to the SD card. You may want to rename it to something like <tt>uboot.img</tt> to distinguish it from an actual kernel image. Ensure that you have the following line in your <tt>config.txt</tt> file:
+
Alternatively, you may wish not to rename the U-Boot binary. If so, the following should work, as root:
<pre>
 
kernel=uboot.img
 
</pre>
 
  
= Test the image =
+
Once, to back up your original config.txt:
  
Boot up the RPi with your new U-Boot image. You should see U-Boot load on the screen, and also on the serial port output (if you have it connected up).
+
mount /dev/sdb1 /mnt/tmp
 +
mv /mnt/tmp/config.txt /mnt/tmp/config.txt.pre-uboot
 +
umount /mnt/tmp
  
= Preparing a kernel image for use with U-Boot =
+
Every time you want to copy a new U-Boot binary to the SD card:
  
This assumes you have the kernel source and are familiar with the [[RPi_Kernel_Compilation|kernel compilation]] process.
+
mount /dev/sdb1 /mnt/tmp
As the kernel source already has the ability to build U-Boot image files, preparing a kernel image is relatively easy.
+
cp u-boot.bin /mnt/tmp/
First, you will need to put the U-Boot tool <tt>mkimage</tt> where it can be found by the kernel make process. This is done by copying it to the cross-compiler <tt>bin</tt> directory. From the U-Boot source directory, run the following, substituting the location and prefix of your cross compiler accordingly:
+
echo 'kernel=uboot.img' > /mnt/tmp/config.txt
<pre>
+
umount /mnt/tmp
cp tools/mkimage <your_cross_compiler_path>/bin/arm-none-linux-gnueabi-mkimage
 
</pre>
 
  
In the kernel source directory, you can now build the U-Boot image:
+
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. <tt>cat /proc/partitions</tt> should help you locate the correct device filename.
<pre>
 
make uImage
 
</pre>
 
  
The generated boot image file can be found at <tt>arch/arm/boot/uImage</tt>.
+
= Test U-Boot =
  
= U-Boot boot options =
+
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).
  
== Boot from SD card ==
+
= Kernel Command-Line =
Booting from the SD card allows multiple kernel images to be used without having to edit the <tt>config.txt</tt> file. Place your uImage file(s) on the SD card, then boot up. Press a key to drop to the command line, then enter the following:
 
<pre>
 
mmc rescan
 
fatload mmc 0:1 ${loadaddr} <your_uImage_file>
 
bootm
 
</pre>
 
  
== Network boot via TFTP ==
+
In all of the example commands shown below to boot a kernel:
You will need to have a TFTP server configured. Place your uImage file(s) in the TFTP root directory, and ensure that the file permissions are set accordingly (everyone should have read access - use <tt>chmod a+r uImage</tt> if unsure).
 
  
To boot using DHCP, ensure that the <tt>next-server</tt> and <tt>filename</tt> options are set in your DHCP server. Then, boot up the RPi, press a key to drop to the command line, then enter the following:
+
* You may omit <tt>earlyprintk</tt> if you're not doing kernel development/testing, and are not experiencing early boot problems.
<pre>
+
* You may omit <tt>console=ttyAMA0</tt> if you don't want to use the serial console.
usb start
+
* You may omit <tt>console=tty0</tt> if you don't want to use a virtual terminal console (HDMI/USB keyboard).
dhcp
+
* The <tt>root=</tt> option is correct for a Raspbian image. You may need to adjust this if your partition layout is different.
bootm
+
* The same applies for <tt>rootfstype=</tt> option. The default FS type is EXT4. You will need to change it if using a different filesystem.
</pre>
 
  
To boot using static IP:
+
= Booting from an SD card =
<pre>
+
If your kernel uses Device Tree (it is true for a default upstream kernel image):
usb start
+
 
setenv serverip <tftp_server_ip>
+
# swarren's branch already sets this automatically, so you can skip this
setenv ipaddr <a_spare_ip_address>
+
# Mainline U-Boot will set the following automatically soon
tftpboot uImage
+
setenv fdtfile bcm2835-rpi-b.dtb
bootm
+
</pre>
+
mmc dev 0
 +
fatload mmc 0:1 ${kernel_addr_r} zImage
 +
fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}
 +
setenv bootargs earlyprintk console=tty0 console=ttyAMA0 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait noinitrd
 +
bootz ${kernel_addr_r} - ${fdt_addr_r}
 +
 
 +
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}
 +
 
 +
 
 +
 
 +
= 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 <tt>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:
 +
 
 +
# swarren's branch already sets this automatically, so you can skip this
 +
# Mainline U-Boot will set the following automatically soon
 +
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}
 +
 
 +
== 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:
 +
 
 +
# swarren's branch already sets this automatically, so you can skip this
 +
# Mainline U-Boot will set the following automatically soon
 +
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}
  
 
= U-Boot script files =
 
= U-Boot script files =
The above instructions can be written into a text file and compiled into a U-Boot script file so that it automatically executes on boot. First, generate the script as follows (substituting your <tt>mkimage</tt> with that created earlier:
 
<pre>
 
arm-none-linux-gnueabi-mkimage -A arm -O linux -T script -C none -d <your_script_text_file> boot.scr
 
</pre>
 
  
Place the <tt>boot.scr</tt> file on the SD card and it will automatically be used when you power up the RPi.
+
== uEnv.txt ==
 +
 
 +
swarren's branch (and soon mainline) load file <tt>/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 <tt>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 <tt>boot.scr.uimg</tt> (or <tt>boot.scr</tt>) in either <tt>/</tt> or <tt>/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
 +
# Place the relevant set of boot commands into the file
 +
mkimage -A arm -O linux -T script -C none -n boot.scr -d boot.scr boot.scr.uimg
 +
 
 +
Now, copy <tt>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 <tt>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 ([http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/ BootLoaderSpec]) config file from a TFTP server. Create e.g. <tt>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 <tt>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.
  
 
{{Template:Raspberry Pi}}
 
{{Template:Raspberry Pi}}
 
[[Category:RaspberryPi]]
 
[[Category:RaspberryPi]]
 +
[[Category:U-Boot]]

Revision as of 08:55, 15 September 2014

Back to the Hub.


Software & Distributions:

Software - an overview.

Distributions - operating systems and development environments for the Raspberry Pi.

Kernel Compilation - advice on compiling a kernel.

Performance - measures of the Raspberry Pi's performance.

Programming - programming languages that might be used on the Raspberry Pi.

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 contains working USB support. Pre-built tarballs can be found here. These releases are meant to boot FreeBSD; if you're booting Linux, copy only the u-boot binary to your boot partition and follow the instructions later on this page.

To build it yourself, get the source from git://github.com/gonzoua/u-boot-pi.git branch rpi.

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

git clone -b rpi 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/rpi

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 one of the following to configure the source tree to build for the Raspberry Pi:

# Very recent versions of U-Boot:
make rpi_b_defconfig

# Older versions:
make rpi_b_config

Then, perform the actual build:

make -j8 -s

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=tty0 if you don't want to use a virtual terminal console (HDMI/USB keyboard).
  • The root= option is correct for a Raspbian image. You may need to adjust this if your partition layout is different.
  • The same applies for rootfstype= option. The default FS type is EXT4. You will need to change it if using a different filesystem.

Booting from an SD card

If your kernel uses Device Tree (it is true for a default upstream kernel image):

# swarren's branch already sets this automatically, so you can skip this
# Mainline U-Boot will set the following automatically soon
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=tty0 console=ttyAMA0 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait noinitrd
bootz ${kernel_addr_r} - ${fdt_addr_r}

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}


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 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:

# swarren's branch already sets this automatically, so you can skip this
# Mainline U-Boot will set the following automatically soon
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}

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:

# swarren's branch already sets this automatically, so you can skip this
# Mainline U-Boot will set the following automatically soon
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}

U-Boot script files

uEnv.txt

swarren's branch (and soon mainline) load file /uEnv.txt 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, 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 (or boot.scr) in either / or /boot. 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
# Place the relevant set of boot commands into the file
mkimage -A arm -O linux -T script -C none -n boot.scr -d boot.scr boot.scr.uimg

Now, copy boot.scr.uimg 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 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 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 may be used to configure which auto-boot targets are executed at boot. uEnv.txt may be used to configure this variable.