Buildroot with Raspberry Pi - Automating and sharing

Automation is an important part of every software project. If you need to do something repeatedly, chances are, that it can be easily put in a script and done for you. It is especially important in build systems, that is why I would like to automate all the steps, that are needed for building a custom Linux for RPi using Buildroot.

First, check out previous posts:

First step is to choose a version control system. Since Buildroot uses git, I will stick to that. A fork of Buildroot's repository needs to be made:

$ git clone
$ cd buildroot
$ git push origin/master

Basically, I copied the existing repo to another, hosted on bitbucket. This allows me to make all the changes, and, when needed, merge any new code that is added to the original repository. From now on, I can clone the repository directly from:

$ git clone

Most of the configuration changes made to Buildroot up until now were made using make nconfig. The configuration can be saved using:

$ make savedefconfig

The outcome of this command is a new configuration file which can be found in configs/raspberrypi_defconfig. Just copy this configuration to the newly setup repo, and from now on, Buildroot will use this config by default.

Now, u-boot command scripts needs to be added. Copy boot.scr and update.scr into board/raspberrypi/

In order to convert them to u-boot images the board/raspberrypi/ needs to be changed to:


BOARD_DIR="$(dirname $0)"  
BOARD_NAME="$(basename ${BOARD_DIR})"  

# U-Boot script
if [ -e $MKIMAGE -a -e $BOOT_CMD ];  
    $MKIMAGE -A arm -O linux -T script -C none -d $BOOT_CMD $BOOT_CMD_H

# U-Boot script
if [ -e $MKIMAGE -a -e $UPDATE_CMD ];  
    $MKIMAGE -A arm -O linux -T script -C none -d $UPDATE_CMD $UPDATE_CMD_H

# Mark the kernel as DT-enabled
mkdir -p "${BINARIES_DIR}/kernel-marked"  
${HOST_DIR}/usr/bin/mkknlimg "${BINARIES_DIR}/zImage" \

rm -rf "${GENIMAGE_TMP}"

genimage                           \  
    --rootpath "${TARGET_DIR}"     \
    --tmppath "${GENIMAGE_TMP}"    \
    --inputpath "${BINARIES_DIR}"  \
    --outputpath "${BINARIES_DIR}" \
    --config "${GENIMAGE_CFG}"

exit $? is a script which is automatically run by Buildroot after compilation and rootfs preparation. In case of Raspberry Pi, this scripts generates the sdcard.img using genimage tool, based on board/raspberrypi/genimage-raspberrypi.cfg

The genimage-raspberrypi.cfg needs to be changed to add u-boot, scripts and initial root file system:

image boot.vfat {  
  vfat {
    files = {
  size = 32M

image sdcard.img {  
  hdimage {

  partition boot {
    partition-type = 0xC
    bootable = "true"
    image = "boot.vfat"

Lastly, we need to change cmdline.txt and config.txt, so that u-boot.bin is executed at startup. Both files are part of rpi-firmware, which can be found in package/rpi-firmware/

After all, the changes are:

$ git status
On branch master  
Your branch is up-to-date with 'origin/master'.  
Changes to be committed:  
  (use "git reset HEAD <file>..." to unstage)

    new file:   board/raspberrypi/boot.scr
    modified:   board/raspberrypi/genimage-raspberrypi.cfg
    modified:   board/raspberrypi/
    new file:   board/raspberrypi/update.scr
    modified:   configs/raspberrypi_defconfig
    modified:   package/rpi-firmware/cmdline.txt
    modified:   package/rpi-firmware/config.txt

After pushing those changes, the whole build system, with its initial configuration, can be shared with other developers.