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 download section. Check the repositoryfor the most recent developments. Feel free to subscribe to the mailing list. Note also the slidesfrom the ELCE09 talk by Sascha Hauer, creator of barebox.
There is a very good summary one can find the the Pengutronix CELF Japan Technical Jamboree 32 introduction :
You can find a more recent version of this article here:www.elec4fun.fr[[|]]
This is the SOPC system we are going to use on the NEEK board :
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.
Once you have installed git (http://www.alterawiki.com/wiki/Git_Server), 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 :
Once you've set those variables, we can configure barebox with the generic configuration:
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.
In order to create a new board configuration, we have to add a folder in arch/nios2/boards. In this folder, we can find:
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:
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 begining 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):
The command has to be executed in the folder containing the *.sopcinfo file to be converted. Once the file has been generated witout 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 (File: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:
default "Altera Generic Board" if GENERIC
default "Altera NEEK Board" if NEEK
prompt "Select your board"
bool "Generic "
bool "NEEK "
Barebox is now ready to compile. Let's configure it via:
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 likelly ping). In Drivers-->Network drivers add Altera TSE ethernet driver. Now you can exit and save your configuration with:
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:
Compile barebox and go to the next chapter...
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 File:Barebox.bin.zip and File:Barebox.elf.zip elf file). You can also copy this linux kernel (File:UImage.zip) to the tftp server.
Turn on your neek and configure the fpga, then download barebox:
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 environement 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):
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 (withe the edit command), add eth0 parameters in the file and save/exit with CTRL+D. Then you can save the environement with saveenv.
Now we're about to flash barebox. First, we need to erase the barebox flash partition:
Then we have to download and flash barebox. This can be done with one command:
tftp barebox.bin /dev/nor0.barebox
Erase the kernel parition 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....