Barebox

barebox.png

Introduction

Barebox (formerly known as u-boot-v2) is a bootloader that inherits the best of U-Boot and the Linux kernel:
The size and look-and-feel of U-Boot, with driver model and lots of design concepts from the kernel. A kernel hacker friendly bootloader!

Pre-built images

A revision of barebox for AT91 boards is built from the barebox Linux4SAM GitHub website and it is based on official tree of barebox.

2013.01-next (linux4sam_4.0 tag)
Board Description Binary Configuration file
sama5d3xek barebox binary based on 2013.01-next zbarebox-sama5d3xek.bin sama5d3xek_defconfig

Pointing hand Note that barebox uses a filesystem as it's environment. You have to edit and execute files to configure barebox. You can see barebox as a "pseudo Linux".

Use barebox

Using a terminal software on your host system, you can connect to barebox through the DBGU interface. Actually, for SAMA5D3-EK board, you can use both DBGU and USART0 as serial console.

Exceptions:

  • sama5d2 revision A, only to access the ROMCode through serial interface and see the RomBOOT message appearing, configure your serial line to 57600.
    Change it back to 115200 for normal operation.
    All components and demo binaries are now configured to work at 115200 8-N-1.

The usual serial communication parameters are 115200 8-N-1 :

Baud rate 115200
Data 8 bits
Parity None
Stop 1 bit
Flow control None

On the LCD you should see the splash screen below:
splash.png

In your terminal window you should see something similar to the information displayed below:
barebox_screenshot.png

If you don't stop the auto countdown, you can notice barebox tries to boot from the nand.
Issue a <ctrl-c> from your terminal to stop the network boot stage as it is not probably well configured.

How to install a UBI rootfs from barebox

Prepare the Flash before UBI rootfs install

The /dev/nand0.root partition can be attached to ubi using

ubiattach /dev/nand0.rootfs

Warning, important Warning: Before attaching the rootfs partition to ubi please erase it with

erase /dev/nand0.rootfs

Create a volume on the UBI device

ubimkvol /dev/ubi0 root 0

Load a file from a tftp or nfs server

Setup a tftp server on your host and copy the UBI rootfs from linux4sam-buildroot-sama5d3xek_linux4sam_4.0 to your tftp directory.

Setup your network from barebox: If you have a dhcp server available on your network you can see the network parameters by issuing the following command:

devinfo eth0

If you want to modify for example the serverip you have to issue the following command:

eth0.ipaddr=192.168.1.19
eth0.serverip=192.168.1.10

As your network setup is ok, you can load a file from barebox with the command below:

tftp zImage

or for nfs

nfs /opt/work/linux4sam-buildroot-sama5d3xek_linux4sam_4.0/zImage

Issue ls and you should see your file in the / directory

Flash the UBI rootfs from barebox

The UBI volume can then be flashed with the command below:

tftp rootfs.ubifs /dev/ubi0.root

or for nfs

nfs rootfs.ubifs /dev/ubi0.root

Save your network settings

From the barebox command line you can save your network settings by editing the config file in /env directory

edit env/config

 /env/config                <ctrl-d>: Save and quit <ctrl-c>: quit

#!/bin/sh

# use 'dhcp' to do dhcp in barebox and in kernel
# use 'none' if you want to skip kernel ip autoconfiguration
#ip=dhcp-barebox
ip=none
global.dhcp.vendor_id=barebox-sama5d3xek
global.dhcp.client_id="${sama5d3xcm.board}-${sama5d3xcm.vendor}"

# or set your networking parameters here
#eth0.ipaddr=a.b.c.d
#eth0.netmask=a.b.c.d
#eth0.gateway=a.b.c.d
#eth0.serverip=a.b.c.d

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=nand
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=nand
# can be either 'nfs', 'tftp', 'nor', 'nand' or empty
oftree_loc=nand

Uncomment and setup your network parameters as below:

# or set your networking parameters here
eth0.ipaddr=192.168.1.100
eth0.netmask=255.255.255.0
eth0.gateway=192.168.1.10
eth0.serverip=192.168.1.10

or by dhcp

ip=dhcp

or by dhcp in barebox and static Linux

ip=dhcp-barebox

Save and quit the edition of your configuration file by issuing <ctrl-d>

Now to store the whole environment on non-volatile flash issue the following command:

saveenv

To tell barebox to take into account this new environment file, you will have to execute the /env/config file like a shell script:

/env/config

or, an other method is to simply reset the board.

Modify the default boot sequence

By default barebox tries to boot from NAND FLASH.

How to boot from nfs

When you are setting up your rootfs for your target, it can be interesting to use nfs.

Indeed when your Ethernet is functional on your target you can easily mount a rootfs available on your host.

First setup an nfs server on your host.

Edit the env/config file by issuing the command below:

edit env/config

#!/bin/sh

# use 'dhcp' to do dhcp in barebox and in kernel
# use 'none' if you want to skip kernel ip autoconfiguration
#ip=dhcp-barebox
ip=none
global.dhcp.vendor_id=barebox-sama5d3xek
global.dhcp.client_id="${sama5d3xcm.board}-${sama5d3xcm.vendor}"

# or set your networking parameters here
#eth0.ipaddr=a.b.c.d
#eth0.netmask=a.b.c.d
#eth0.gateway=a.b.c.d
#eth0.serverip=a.b.c.d

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=nand
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=nand
# can be either 'nfs', 'tftp', 'nand' or empty
oftree_loc=nand

# can be either 'jffs2' or 'ubifs'
rootfs_type=ubifs
rootfsimage=root.$rootfs_type
ubiroot=rootfs

# The image type of the kernel. Can be uimage, zimage, raw, or raw_lzo
kernelimage=zImage
#kernelimage=uImage
#kernelimage=Image
#kernelimage=Image.lzo

nand_device=atmel_nand
nand_parts="256k(at91bootstrap),384k(barebox)ro,256k@768k(bareboxenv),256k(bareboxenv2),128k@1536k(oftree),5M@2M(kernel),-@8M(rootfs)"
rootfs_mtdblock_nand=6

m25p80_parts="64k(bootstrap),384k(barebox),256k(bareboxenv),256k(bareboxenv2),128k(oftree),-(updater)"

autoboot_timeout=1

bootargs="console=ttyS0,115200 rw"

# set a fancy prompt (if support is compiled in)
PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m\n# "

You can load the kernel and oftree (dtb) via nfs or tftp

via nfs

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=nfs
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=net
# can be either 'nfs', 'tftp', 'nand' or empty
oftree_loc=nfs

via tftp

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=nfs
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=net
# can be either 'nfs', 'tftp', 'nand' or empty
oftree_loc=nfs

You can now save your file with <ctrl-d> and saveenv. Then reset your board.

if you use bootp via dhcp the Device Tree Binary (DTB) need to be provided by private extension 224

E.g. the ISC dhcp server can be configured with

option oftree-path code 224 = string    
class "sama5d3ek" {
        match if substring (option vendor-class-identifier,0,20) = "barebox-sama5d3ek";

        filename "/tftpboot/atmel/sama5d3/sama5d3ek/zImage";
        option tftp-server-name "192.168.200.98";
        option root-path "192.168.200.98:/opt/work/buildroot/build/sama5d3ek/target";
        option oftree-path "/tftpboot/atmel/sama5d3/sama5d3ek/sama5d31ek.dtb";
}

otherwise you can provided it directly in the /env/config

# can be either 'nfs', 'tftp', 'nor' or 'nand'
kernel_loc=nfs
# can be either 'net', 'nor', 'nand' or 'initrd'
rootfs_loc=net
# can be either 'nfs', 'tftp', 'nand' or empty
oftree_loc=nfs

kernelimage=/tftpboot/atmel/sama5d3/sama5d3ek/zImage
oftreeimage=/tftpboot/atmel/sama5d3/sama5d3ek/sama5d31ek.dtb
nfsroot=/opt/work/buildroot/build/sama5d3ek/target

Build barebox from sources

Getting barebox sources

To get the source code, you have to clone the repository:

$ git clone git://github.com/linux4sam/barebox-at91.git
Cloning into 'barebox-at91'...
remote: Counting objects: 85649, done.
remote: Compressing objects: 100% (17123/17123), done.
remote: Total 85649 (delta 66891), reused 85649 (delta 66891)
Receiving objects: 100% (85649/85649), 27.09 MiB | 1.91 MiB/s, done.
Resolving deltas: 100% (66891/66891), done.
$ cd barebox-at91
$ ls
arch      common   CREDITS  defaultenv    Documentation  drivers  include  lib   MAKEALL   net  README   TODO
commands  COPYING  crypto   defaultenv-2  Doxyfile       fs       Kconfig  logo  Makefile  pbl  scripts

The source code has been taken from the master branch which is pointing on the latest branch we use.

If you want to use an other branch, you can list them and use one of them by doing this:

$ git branch -r
  origin/HEAD -> origin/master
  origin/barebox-2013.01-next-at91
  origin/master
$ git checkout origin/barebox-2013.01-next-at91 -b barebox-2013.01-next-at91
Branch barebox-2013.01-next-at91 set up to track remote branch barebox-2013.01-next-at91 from origin.
Switched to a new branch 'barebox-2013.01-next-at91'

Cross-compiling barebox

Barebox uses the Linux kernel configuration (Kconfig) and build (Kbuild) system

So you will configure and build it the same way. The exception is where the result binary are located

$ ls arch/arm/configs/+(at91|sama)*
arch/arm/configs/at91rm9200ek_defconfig               arch/arm/configs/at91sam9g20ek_defconfig
arch/arm/configs/at91sam9260ek_defconfig              arch/arm/configs/at91sam9m10g45ek_defconfig
arch/arm/configs/at91sam9261ek_bootstrap_defconfig    arch/arm/configs/at91sam9m10ihd_defconfig
arch/arm/configs/at91sam9261ek_defconfig              arch/arm/configs/at91sam9n12ek_defconfig
arch/arm/configs/at91sam9261ek_first_stage_defconfig  arch/arm/configs/at91sam9x5ek_defconfig
arch/arm/configs/at91sam9263ek_defconfig              arch/arm/configs/sama5d3xek_defconfig
arch/arm/configs/at91sam9g10ek_defconfig
$
$ make ARCH=arm sama5d3xek_defconfig
$ make ARCH=arm CROSS_COMPILE=<path_to_cross-compiler/cross-compiler-prefix->

now you will and in the directory a symlink file name barebox-flash-image that will point you the image to flash

barebox-flash-image -> arch/arm/pbl/zbarebox.bin

the zbarebox.bin is something similar as the zImage for the kernel it's a compressed file (here lzo) with an embedded self-decompressor

Configure barebox

make ARCH=arm menuconfig

barebox_menuconfig.png


Documentation provided by JCrosoft.Ling Limited and Calao-Systems.

Topic attachments
I Attachment Action Size Date Who Comment
PNGpng barebox.png manage 69.9 K 2013-02-01 - 16:50 UnknownUser barebox logo 200x200
PNGpng barebox_menuconfig.png manage 138.3 K 2013-02-03 - 22:12 UnknownUser barebox menuconfig
PNGpng barebox_screenshot.png manage 85.6 K 2013-02-03 - 21:32 UnknownUser barebox screenshot
PNGpng splash.png manage 46.7 K 2013-02-04 - 13:29 UnknownUser sama5d3x splash 800x400
r14 - 08 Feb 2013 - 15:13:02 - NicolasFerre
 
Linux & Open Source related information for AT91 Smart ARM Microcontrollers

Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.

Atmel® and others, are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. This site is powered by the TWiki collaboration platform

ARM® and others are registered trademarks or trademarks of ARM Ltd. Other terms and product names may be trademarks of others.

Ideas, requests, contributions ? Connect to LinksToCommunities page.

Syndicate this siteRSS ATOM