Difference between revisions of "RPi U-Boot"
(→Oleksandr Tymoshenko's branch) |
|||
Line 132: | Line 132: | ||
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 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). | ||
− | = | + | = 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 | |
− | + | 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} | ||
+ | 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). | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | To boot | + | == Boot Using Dynamic IP == |
− | < | + | |
− | usb start | + | To boot a kernel that doesn't use Device Tree: |
− | setenv serverip <tftp_server_ip> | + | |
− | setenv ipaddr <a_spare_ip_address> | + | usb start |
− | tftpboot | + | dhcp ${kernel_addr_r} zImage |
− | + | 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 | ||
+ | dhcp ${fdt_addr_r} ${fdtfile} | ||
+ | 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> | ||
+ | tftpboot ${kernel_addr_r} zImage | ||
+ | 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> | ||
+ | tftpboot ${kernel_addr_r} zImage | ||
+ | tftpboot ${fdt_addr_r} ${fdtfile} | ||
+ | bootz ${kernel_addr_r} - ${fdt_addr_r} | ||
= U-Boot script files = | = U-Boot script files = |
Revision as of 22:09, 10 February 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.
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 20140110, 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
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. 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
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. Options available are:
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 wish 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 wish 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
As of 20140110, the standalone Linaro toolchains builds are known to generate a U-Boot image that doesn't work.
Compile the source
(Remember to set up CROSS_COMPILE 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:
mount /dev/sdb1 /mnt/tmp cp u-boot.bin /mnt/tmp/kernel.img mv /mnt/tmp/config.txt /mnt/tmp/config.txt.pre-uboot umount /mnt/tmp
Alternatively, you may wish not to rename the U-Boot binary. If so, the following should work, as root:
mount /dev/sdb1 /mnt/tmp cp u-boot.bin /mnt/tmp/ mv /mnt/tmp/config.txt /mnt/tmp/config.txt.pre-uboot 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).
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 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} 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 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 dhcp ${fdt_addr_r} ${fdtfile} 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> tftpboot ${kernel_addr_r} zImage 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> tftpboot ${kernel_addr_r} zImage tftpboot ${fdt_addr_r} ${fdtfile} bootz ${kernel_addr_r} - ${fdt_addr_r}
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 mkimage with that created earlier:
arm-none-linux-gnueabi-mkimage -A arm -O linux -T script -C none -d <your_script_text_file> boot.scr
Place the boot.scr file on the SD card and it will automatically be used when you power up the RPi.
|