Barebox

cancel
Showing results for 
Search instead for 
Did you mean: 

Barebox

Barebox

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. You can find the latest of the timed releases in the https://www.barebox.org/download/

https://www.barebox.org/

There is a very good summary one can find the the Pengutronix CELF Japan Technical Jamboree 32 introduction:

 

  • scripts are scripts, no "runnable environment variables"
  • use a shell-like environment
  • KBuild + Kconfig (easy configuration & build process)
  • models taken from the Linux kernel (clocks,...)
  • kernel coding style
  • "best of U-Boot and Linux"

Test system description

This is the SOPC system we are going to use on the NEEK board :

8/8d/Sopc.png

 

This is an MMU system. However, Barebox can be used with a non MMU system without any modification. Barebox use a free running timer, thus the SOPC must include a Full-featured timer.

You'll find the Quartus project nioslinux.qar. You can also directly download the configuration nioslinux-time-limited-barebox.sof

Get sources / compile

Once you have installed git (https://github.com/intel), you are ready to download the Barebox sources:

 

git clone git://git.pengutronix.de/git/barebox.git

 

This will download the Barebox sources and put it in the barebox directory.

Barebox uses Kconfig/Kbuild scripts from the Linux Kernel. The Barebox compilation process is very close (the same) as Kernel one. Architecture and cross-compile are selected through environment variable :

 

ARCH=nios2

CROSS_COMPILE=<compiler-prefix>

Once you've set those variables, we can configure barebox with the generic configuration:

make generic_defconfig

and compile:

make

The compilation generates:

- barebox.bin (binary file to be flashed),

- barebox (elf file),

- System.map (symbol table).

 

Barebox is now ready to be configured. In the next chapter, we are going to create a board configuration and add drivers via make menuconfig.

Add a board configuration

In order to create a new board configuration, we have to add a folder in arch/nios2/boards. In this folder, we can find:

  • a source file where devices are declared (generic.c),
  • the SOPC description header file (nios_sopc.h),
  • a configuration file where the SOPC components names are matched to barebox devices names (config.h),
  • a shell configuration script (config file, located in ./env).

We'll use the Neek board as an example. The easiest way to create a new board configuration is to copy and rename the generic folder (let's call the new folder neek). Then, in the neek folder, rename generic.c to neek.c and edit the Makefile (in arch/nios2/boards/neek) to change the compiled file name (generic.o -> neek.o).

Let's configure flash memory partitions. In env/config, you'll find an environment variable called nor_parts. It defines flash partitions which will be created at runtime in the device file system (via defaultenv/init script). So adjust partitions as you want. In this example, we use this mapping:

 

nor_parts="128k(env),768k(fpga),256k(barebox),-(kernel)"

 

If you do change partitions size/mapping, you have to check the matching of the runtime created partitions and built-in partitions (especially env0) created in the board init (neek.c in our example). The env0 is needed to load the environment during the beginning of the boot process. In our example:

 

devfs_add_partition("nor0", 0xe0000, 0x40000, PARTITION_FIXED, "self0");

devfs_add_partition("nor0", 0x00000, 0x20000, PARTITION_FIXED, "env0");

 

The next step is to create the nios_sopc.h file from the *.sopcinfo created during the SOPC system generation. We use sopc-create-header-file (in a Nios2 command shell):

2/27/Sopc-create-header.png

 

The command has to be executed in the folder containing the *.sopcinfo file to be converted. Once the file has been generated without any problem, it must be copied to arch/nios2/boards/neek (don't change its name) and the config.h file must be edited to match your devices names.

Here you can find the nios_sopc.h corresponding to the system example (nios-sopc.h).

 

Now, we are going to add our board to the Makefile in arch/nios2:

 

board-$(CONFIG_GENERIC) := generic

board-$(CONFIG_NEEK) := neek

Finally, CONFIG_NEEK must be defined in the Kconfig located in the same folder:

config BOARDINFO

default "Altera Generic Board" if GENERIC

default "Altera NEEK Board" if NEEK

choice

prompt "Select your board"

config GENERIC

bool "Generic "

select NIOS2

config NEEK

bool "NEEK "

select NIOS2

endchoice

Barebox is now ready to compile. Let's configure it via:

make menuconfig

In General Settings we must change the Default environment path to arch/nios2/boards/neek/env. Then add the Networking Support and at least tftp (and most likely ping). In Drivers-->Network drivers add Altera TSE ethernet driver. Now you can exit and save your configuration with:

make savedefconfig

The resulting file (defconfig) can be copied to arch/nios2/configs as neek_defconfig for example. If you want to load the neek default configuration you just have to do a:

make neek_defconfig

Compile barebox and go to the next chapter.

Let's use it

Before starting this chapter, make sure you have a tftp server ready to be used. Then copy barebox.bin you've built in the tftp server directory (this is my barebox-bin.zip and barebox-bin.zip elf file). You can also copy this linux kernel (uimage.zip) to the tftp server.

 

Turn on your neek and configure the fpga, then download barebox:

 

nios2-configure-sof NiosLinux_time_limited.sof

nios2-download -g barebox

 

Barebox should boot on the UART (9600).....

During the startup, barebox tells you it couldn't find a valid environment on /dev/env0 and it uses the default environment. The default environment is the one defined in env/config in your board source files.

In order to use the Ethernet connection, we need to set ip parameters up. In barebox, devices have parameters and those parameters can be set from the console. You can use devinfo to display the devices list and devinfo <device> to get device informations. You can see the empty parameters on eth0 with the command devinfo eth0. To set parameters, we use this syntax (example of ip address on eth0):

 

eth0.ipaddr=192.168.0.13

eth0.serverip=xx.xx.xx.xx

 

Once you've set Ethernet parameters, you can ping something in your LAN to see if it works. If you want to set those parameters permanently, edit the env/config file (with the edit command), add eth0 parameters in the file and save/exit with CTRL+D. Then you can save the environment with saveenv.

Now we're about to flash barebox. First, we need to erase the barebox flash partition:

 

unprotect /dev/nor0.barebox

erase /dev/nor0.barebox

 

Then we have to download and flash barebox. This can be done with one command:

tftp barebox.bin /dev/nor0.barebox

Erase the kernel partition and put the Linux image in it the same way we did it with barebox.bin.

Here we are !! Boot the kernel with bootm /dev/nor0.kernel or reset barebox with the reset command and you should see the kernel booting.

 

Attachments
Version history
Last update:
‎12-08-2022 02:36 PM
Updated by: