Skip to content

1Buildroot

TrLeo42 edited this page Mar 3, 2021 · 12 revisions

buildroot

buildroot has two goals:

  • building a full operating system for a target with a different architecture (ARM in the context of oscimpDigital);
  • building a toolchain to allow users to cross-compile applications for the targeted hardware

In the context of oscimpDigital ecosystem, targets are based on ARM processors (Zynq or SocFPGA) while the host computer on which the user is working is most commonly running an AMD64 compatible processor : Buildroot is needed to cross-compile the operating system, to build the OscimpDigital drivers, libraries, and user applications. It will be assumed that the host computer is running a flavor of the Linux-based operating system.

Full buildroot compilation will take anything from half an hour to several hours depending on internet connection and computer speed, and requires about 8 GB of disk space for a basic setup.

Structure

Buildroot structure with an additional BR2_EXTERNAL repository to extend package list and/or boards configuration

brStruct

Buildroot structure is always the same with:

  • configs: directory where default boards configurations are stored
  • package: directory containing many sub-directories with recipes to build libraries or applications
  • dl: location where downloaded archives are stored
  • board: contains a sub-tree with files, patches and documentation about boards
  • output: contains a sub-tree populated by buildroot with some important directories :
    • host: everything mandatory to cross-compile (cross-compiler, libraries, tools used at build-time)
    • target: directory where final binaries are installed. Used to generate disk image.
    • images: Resulting files, with the most important being sdcard.img (in red). This file will be used to flash the SD-card
    • build: buildroot working directory for the cross-compilation step

The right part of the figure shows an extension, with a similar structure. See below for more details.

Setup

Buildroot supports a basic set of boards which does not include the Red Pitaya. To add support for a target board which is not officially supported, an additional repository must be cloned. This repository acts as a plugin for buildroot, providing a default configuration known to work with oscimpDigital. This type of plugin is called BR2_EXTERNAL

Prerequisites

buildroot has requirements (tools and libraries). They must be installed on the host development computer. To avoid duplicate documentation and an out-of-date list, install the mandatory packages indicated in the Buildroot documentation before going any further.

Download the buildroot archive

Get the latest version of buildroot compatible. You can either download the last tarball here or type the following command in a terminal :

wget https://buildroot.org/downloads/buildroot-YYYY.MM.R.tar.gz
tar -xf buildroot-YYYY.MM.R.tar.gz

Currently (March 1, 2021) YYYY.MM.R is 2020.11.1.

Prepare board support for buildroot

Clone the extension repository, depending on the targeted board.

For Red Pitaya 14 & 16 bits:

git clone https://github.com/trabucayre/redpitaya.git

For zedboard, zc706, de0nanoSoc:

git clone https://github.com/trabucayre/buildroot-external.git

For the Red Pitaya, the default network configuration file is located here : redpitaya/board/redpitaya/overlay/etc/network/interfaces. This file is used to configure the network of your board on first boot. It assigns it the static ip address 192.168.0.10. You may want to modify it if you want to access your board through ssh on first boot, if you use multiple Red Pitayas, or if the ip address 192.168.0.10 is already used in your network. You can find in Trabucayre's readme examples of static interfaces configurations.

Environment configuration

To add support for the new boards through the BR2_EXTERNAL mechanism, the sourceme.ggm configuration file must be loaded with the source command. This command will add to your shell a variable named $BR2_EXTERNAL, containing the path of the br2_external plugin downloaded at the previous step. This variable will be used during the build of buildroot. Here is the command if you downloaded the redpitaya git repository at the previous step :

source redpitaya/sourceme.ggm

If you want the variable to be automatically loaded each time you open a new terminal console, you can add the line export BR2_EXTERNAL=/path/to/the/br2_external/directory (i.e : BR2_EXTERNAL=/home/user/git/redpitaya) in your ~/.bashrc configuration file. If you don't do this, make sure to run the source command above in the same terminal console that you will use to build buildroot. Else, you won't be able to use the BR2_EXTERNAL plugin.

Now, go to the Buildroot directory.

cd buildroot-YYYY.MM.R

Launch configuration of buildroot using:

  • for 14-bit Red Pitaya
make redpitaya_defconfig
  • for 16-bit Red Pitaya
make redpitaya16_defconfig
  • for zedboard
make zedboard_defconfig
  • for zc706
make zc706_defconfig
  • for de0nanoSoc
make de0nanosoc_defconfig

Change default configuration / add additional packages

All libraries, tools and applications in buildroot are called packages.

The default configuration can be modified by adding packages which will be found in the firmware of the board. This is can be done using the command :

make menuconfig
  • arrows are used to move between menus
  • enter is used to open a sub-menu
  • space is used to enable/disable a package
  • esc is used to exit a sub-menu or to quit the menuconfig command.

For example, if you want to use Python and the associated web server Remi, you can add the following packages :

python3: Target packages -> Interpreter languages and scripting ->[*] python3

python3-lxml: Target packages -> Interpreter languages and scripting -> External python modules -> [*] python-lxml

python-pyzmq: Target packages -> Interpreter languages and scripting -> External python modules -> [*] python-pyzmq

python-remi: Target packages -> Interpreter languages and scripting -> External python modules -> [*] python-remi

You may want to install nano since vi is the default text editor and you may not know how to use it. You can find the nano package in Target packages -> Text editor and viewers -> [*] nano

build buildroot

Now, with the default or a modified configuration, the next step is to build everything (cross-compiler, bootloader u-boot, operating system kernel Linux and filesystem including applications and libraries).

WARNING this command can take several hours according to your internet connection

Run this command in the buildroot-YYYY.MM.R directory :

make

The result of the compilation is a disk image named sdcard.img created in output/images/.

flash the SD card

Once the build is complete, insert in your computer the SD card you want to use as a memory for your board.

Identify the device name of your SD card. You can run the command lsblk -T in your terminal (it will list all the plugged in storage devices and the different memory partitions of these devices), or you can run the command dmesg -w before plugging in your SD card (It will show the device name of your SD card at the moment you insert it, avoiding confusion with other plugged in devices. This method usually requires high privileges. Press Ctrl+C to end the command).

The device name should be something like sdX if you use an USB adapter or mmcblkN if you use an SD port, where X is a lower case letter and N a number.

WARNING : The following step will destroy all the data stored in /dev/xxx, so, be sure to correctly identify the device name of the SD card

Flash the disk image on your SD card by running this command, in the buildroot-YYYY.MM.R directory :

sudo dd if=output/images/sdcard.img of=/dev/yourSdCardDeviceName bs=4M

examples :

if the device name of the SD card is mmblk0 : sudo dd if=output/images/sdcard.img of=/dev/mmcblk0 bs=4M

if the device name of the SD card is sdb : sudo dd if=output/images/sdcard.img of=/dev/sdb bs=4M

Note that the dd command doesn't show any output while processing. When you launch the command, just wait until it outputs the end message. Don't try to abort the program once you launched it : this could damage your SD card. See the dd man page for more information on this command.

Once the image has been written, remove the SD card from your computer and insert it in the target board (e.g. Red Pitaya) and power it on. The green LED should be on, and the red LED will blink.

Once the target board has booted, you can either connect from the host computer through ssh :

or through USB (com connector on Red Pitaya) using a tool like minicom (see the "Tweaks/minicom" section below for further details on minicom configuration)

minicom -D /dev/ttyUSB0

Tweaks

Password

By default, user is root, password root

Change password using buildroot

It's possible to change password using make menuconfig before compiling buildroot on the host computer :

System configuration --> (root) Root password

Change password at runtime

After logging in to the target board, run the command:

passwd

and follow the instructions

IP address

By default, all boards are configured with the IP address 192.168.0.10. You can change the address by modifying the file /etc/network/interfaces. This file is located in the second partition (labeled "rootfs") of the SD card. To get access to this file, you can insert the SD card in your host computer and modify it with a text editor, or you can modify it at runtime running vi /etc/network/interfaces while logged in to your board (this method will require you to restart the network service of the board OS, or to reboot the board to take into account the changes).

The default configuration is:

auto eth0
iface eth0 inet static
    address 192.168.0.10
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.2

For example, if the 192.168.10.x network is to be used:

auto eth0
iface eth0 inet static
    address 192.168.10.10
    netmask 255.255.255.0
    network 192.168.10.0
    broadcast 192.168.10.255
    gateway 192.168.10.2

MAC address (Red Pitaya only)

Ethernet MAC address is generated randomly (in fact, it appears to be always the same). If more than one Red Pitaya is to be used and if a dynamic IP address allocation is used from a DHCP server, the following line :

ethaddr=xx:xx:xx:xx

has to be added in the uEnv.txt file, located in the first SD-card partition. (To access it, you will have to mount the first partition of the SD card through command lines or through a graphical file manager).

Note: a sticker with the Official MAC address is glued on the Red Pitaya ethernet connector.

Minicom

If you want to use minicom to connect to your board through USB, you may need to tweak its configuration.

First, if you don't want to be forced to get superuser privileges to use minicom, you have to ensure you are part of the dialout user group. Type the following command :

groups YourUserName

This command prompts all the groups of the user YourUserName. If dialout doesn't appear in the list run the following command with superuser privilege :

adduser YourUserName dialout

Now dialout should appear in the list of the groups YourUserName command.

Then, when you use minicom -D /dev/ttyUSB0, you get to the main screen of minicom. Normally, you just have to press Enter once to launch the connection to the target board. If nothing happens, you may need to disable one option of minicom. Press Ctrl+A then press O to access the minicom configuration panel. Navigate with the arrow keys to select Serial port setup and press Enter. Make sure that Hardware Flow Control is set to No. If it is not the case, press F once. Then press escape two times to exit the configuration panel.

Now, if you press Enter, you should be able to connect to your board.

Refs