How to compile mainline u-boot for Raspberry Pi ?

By | July 2, 2016

U-boot is a powerful and famous open source bootloader. It supports multiple architectures, processors and contains many features. In this post, let’s compile Das u-boot bootloader for raspberry pi boards.

Recall :

In the previous post, we discussed the procedure to create complete a embedded Linux BSP using buildroot. We also discussed the procedure to boot the board till Linux prompt etc ..

Embedded Linux Development on Raspberry PI using Buildroot – part1

Embedded Linux Development on Raspberry PI using Buildroot – part2

Development Environment :

For u-boot compilation, noting much required

  • Software
    • Ubuntu 14.04
  • Others
    • Internet

Install cross compiler and export environment variables:

If you have any cross compiler like the one generated from buildroot in the previous posts, then export that.

Else, you can run below command to get a ARM based linaro cross compiler.

$ sudo apt-get install gcc-arm-linux-gnueabi

Export below environment variables. These variables informs to the build environment to use ARM architecture, and use ARM cross compiler instead of native GCC compiler.

$ export ARCH=arm
$ export CROSS_COMPILE=arm-linux-gnueabi-

Cross verify the environment by running below command

$ echo $CROSS_COMPILE
$ echo $ARCH

You should get response as below. If you see an empty response, then the environment variables have not set properly.

minion@ubuntu:~/minion/rpi/u-boot$ echo $CROSS_COMPILE
arm-linux-gnueabi-
minion@ubuntu:~/minion/rpi/u-boot$ echo $ARCH
arm

Download U-boot source and checkout latest branch:

As always, we will use mainline Denx u-boot source for our development. Run below command to download that.

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

After successful download, checkout a latest tag.

$ git checkout v2016.05 -b v2016.05

RPI+uBOOT

Apply configuration files:

Our next step is to find the appropriate configuration files and apply to the build environment.

In the latest u-boot, all configuration files are available in the configs folder.

$ ls configs/

In specific, to verify the list of configuration files for raspberry Pi boards, run below command.

$ ls configs/rpi_*

Responce of the command is something as shown below in the latest u-boot.

minion@ubuntu:~/minion/rpi/u-boot$ ls configs/rpi_*
configs/rpi_2_defconfig      configs/rpi_3_defconfig
configs/rpi_3_32b_defconfig  configs/rpi_defconfig

In this branch we have 4 defconfig files. All config file names are informative.  Just a brief about each file

rpi_defconfig        - For Raspberry pi A, A+, B, B+
rpi_2_defconfig      - For Raspberry pi 2 board
rpi_3_defconfig      - For Raspberry pi 3 board
rpi_3_32b_defconfig  - For Raspberry pi 3 32 bit u-boot

Now apply appropriate configuration file. Command is as shown below.

$ make < def configuration file >

Choose required tab and apply accordingly

RPI A A+ B B+

$ make rpi_defconfig

RPI 2

$ make rpi_2_defconfig

RPI 3

$ make rpi_3_defconfig

RPI 3 32 bit

$ make rpi_3_32b_defconfig

After applying the configuration, you will get below messages in the terminal.,

#
# configuration written to .config
#

Compile u-boot:

Now. just issue make command to build the source. Compilation takes around one minute.

$ make -j4

Once compilation is done, you will see below messages in the terminal.

  OBJCOPY examples/standalone/hello_world.bin
  OBJCOPY examples/standalone/hello_world.srec
  LD      u-boot
  OBJCOPY u-boot.srec
  OBJCOPY u-boot-nodtb.bin
  SYM     u-boot.sym
  COPY    u-boot.bin
  $

What Next:

In the upcoming posts, lets discuss the procedure to boot raspberry pi along with u-boot. We will also explore the other features of u-boot.

One thought on “How to compile mainline u-boot for Raspberry Pi ?

  1. taeik

    taker@ubuntu:~/u-boot$ sudo make -j4
    scripts/kconfig/conf –silentoldconfig Kconfig
    CHK include/config.h
    UPD include/config.h
    GEN include/autoconf.mk.dep
    GEN include/autoconf.mk
    CHK include/config/uboot.release
    CHK include/generated/timestamp_autogenerated.h
    UPD include/generated/timestamp_autogenerated.h
    CFG u-boot.cfg
    cc1: error: bad value (‘armv5’) for ‘-march=’ switch
    cc1: note: valid arguments to ‘-march=’ switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 bonnell atom silvermont slm knl x86-64 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 btver1 btver2
    Makefile:933: recipe for target ‘u-boot.cfg’ failed
    make: *** [u-boot.cfg] Error 1
    make: *** Waiting for unfinished jobs….
    UPD include/config/uboot.release

    Hello I hope you read this text
    I face to some error which is cc1: error: bad value (‘armv5’) for ‘-march=’ switch
    I surf the internet but I couldn’t find the solution
    How to solve this problem?
    (I followed your instruction perfectly 🙁 )

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *