Difference between revisions of "RPi U-Boot"

From eLinux.org
Jump to: navigation, search
(Page creation)
 
 
(29 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.
  
= Prepare a U-Boot image file =
+
= Get the source =
  
== 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.
Currently, the main U-Boot source tree does not fully support the RPi. Instead, you will need to get the code from [https://github.com/gonzoua/u-boot-pi/tree/rpi Gonzoua's GitHub branch]. Note that the code in 'master' (shown by default) is the unmodified U-Boot code - you should select the 'rpi' branch to view the correct code.
+
  
You can download the source tarball using [https://github.com/gonzoua/u-boot-pi/archive/rpi.tar.gz this link].
+
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.
  
== Compile the source ==
+
== Mainline ==
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:
+
 
<pre>
+
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.
CROSS_COMPILE=arm-none-linux-gnueabi-
+
 
export CROSS_COMPILE
+
To download this repository into a new local repository (this is what you want if you don't know better):
</pre>
+
 
 +
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 [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 =
 +
 
 +
(Remember to set up CROSS_COMPILE first, as described above.)
  
 
Then, in the U-Boot source directory, run the following to start the build:
 
Then, in the U-Boot source directory, run the following to start the build:
<pre>
 
make rpi_b
 
</pre>
 
  
The build process should take no more than a few minutes.
+
make -j8 -s rpi_b
  
== Prepare the image file ==
+
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.
Follow the instructions on the [[RPi_Kernel_Compilation#Prepare the image file|kernel compilation]] page to prepare the image file. The file <tt>u-boot.bin</tt> should be used as the input file.
+
  
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:
+
The build process should take no more than a few minutes. This should generate <tt>u-boot.bin</tt>.
<pre>
+
kernel=uboot.img
+
</pre>
+
  
== Test the image ==
+
= Copy U-Boot to your SD card =
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).
+
  
= Preparing a kernel image for use with U-Boot =
+
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:
This assumes you have the kernel source and are familiar with the [[RPi_Kernel_Compilation|kernel compilation]] process.
+
As the kernel source already has the ability to build U-Boot image files, preparing a kernel image is relatively easy.
+
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:
+
<pre>
+
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:
+
Once, to back up your original config.txt:
<pre>
+
make uImage
+
</pre>
+
  
The generated boot image file can be found at <tt>arch/arm/boot/uImage</tt>.
+
mount /dev/sdb1 /mnt/tmp
 +
mv /mnt/tmp/config.txt /mnt/tmp/config.txt.pre-uboot
 +
umount /mnt/tmp
  
= U-Boot boot options =
+
Every time you want to copy a new U-Boot binary to the SD card:
  
== Boot from SD card ==
+
mount /dev/sdb1 /mnt/tmp
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:
+
cp u-boot.bin /mnt/tmp/kernel.img
<pre>
+
umount /mnt/tmp
mmc rescan
+
fatload mmc 0:1 ${loadaddr} <your_uImage_file>
+
bootm
+
</pre>
+
  
== Network boot via TFTP ==
+
Alternatively, you may wish not to rename the U-Boot binary. If so, the following should work, as root:
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:
+
Once, to back up your original config.txt:
<pre>
+
usb start
+
dhcp
+
bootm
+
</pre>
+
  
To boot using static IP:
+
mount /dev/sdb1 /mnt/tmp
<pre>
+
mv /mnt/tmp/config.txt /mnt/tmp/config.txt.pre-uboot
usb start
+
umount /mnt/tmp
setenv serverip <tftp_server_ip>
+
 
setenv ipaddr <a_spare_ip_address>
+
Every time you want to copy a new U-Boot binary to the SD card:
tftpboot uImage
+
 
bootm
+
mount /dev/sdb1 /mnt/tmp
</pre>
+
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. <tt>cat /proc/partitions</tt> 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 <tt>earlyprintk</tt> if you're not doing kernel development/testing, and are not experiencing early boot problems.
 +
* You may omit <tt>console=ttyAMA0</tt> if you don't want to use the serial console.
 +
* You may omit <tt>console=tty1</tt> if you don't want to use a virtual terminal console (HDMI/USB keyboard).
 +
* The <tt>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:
 +
 
 +
# 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=ttyAMA0 console=tty1 root=/dev/mmcblk0p2 rootwait
 +
bootz ${kernel_addr_r} - ${fdt_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]]

Latest revision as of 20:44, 14 May 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 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 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.

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:

# 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=ttyAMA0 console=tty1 root=/dev/mmcblk0p2 rootwait
bootz ${kernel_addr_r} - ${fdt_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.