Step-by-Step Guide to Building Root Filesystem with Buildroot

The three main components of embedded systems: bootloader (uboot), Linux kernel, root filesystem.

There are three powerful tools for creating root filesystems: busybox, buildroot, yocto.

Using busybox to build the filesystem only helps us set up some common commands and files. Libraries, files in the /etc directory, etc., need to be created manually, and we also have to port some third-party software and libraries, such as alsa, iperf, mplayer, etc. Additionally, the root filesystem built by busybox does not have a username and password set by default.

If you want to build a complete root filesystem, most people generally use buildroot. It not only includes the functionality of busybox but also integrates various software. You can select the software you need without having to port it yourself. Buildroot greatly facilitates embedded Linux developers in building practical root filesystems.

As for using yocto to build the root filesystem, it is overly complex and takes a long time, so we generally do not choose this method.

Downloading Buildroot

The source code for buildroot must be downloaded from the official buildroot website, which is https://buildroot.org/.

After downloading, unzip it as shown:

Step-by-Step Guide to Building Root Filesystem with Buildroot

Buildroot, like uboot and the Linux kernel, also supports graphical configuration. Enter the following command to open the graphical configuration interface:

make menuconfig
Step-by-Step Guide to Building Root Filesystem with Buildroot

1. Configure Target Options

Target options
  -> Target Architecture = ARM (little endian) 
  -> Target Binary Format = ELF
  -> Target Architecture Variant = cortex-A7
  -> Target ABI = EABIhf
  -> Floating point strategy = NEON/VFPv4
  -> ARM instruction set = ARM

2. Configure Toolchain

This configuration item is used to configure the cross-compilation toolchain, set to the cross-compiler you use, and must be the absolute path.

Currently, in the development of ARM Linux, people tend to use the Linaro ( http://www.linaro.org/) toolchain maintained by the ARM toolchain team, which releases new versions monthly. The compiled executable files can be downloaded from http://www.linaro.org/downloads/. Linaro is the most famous and technically accomplished open-source organization in the ARM Linux field, with members including ARM, Broadcom, Samsung, TI, Qualcomm, etc. Domestic companies like HiSilicon, ZTE, Allwinner, and MediaTek from Taiwan are also members.

A typical ARM Linux toolchain includes arm-linux-gnueabihf-gcc (subsequent tools omit the prefix), strip, gcc, objdump, ld, gprof, nm, readelf, addr2line, etc. The “hf” in the prefix indicates that the toolchain is fully hard-float.

Toolchain
  -> Toolchain type = External toolchain
  -> Toolchain = Custom toolchain //User's own cross-compiler
  -> Toolchain origin = Pre-installed toolchain //Pre-installed compiler
  -> Toolchain path =   //Compiler absolute path 
  -> Toolchain prefix = $(ARCH)-linux-gnueabihf //Prefix
  -> External toolchain gcc version = 4.9.x
  -> External toolchain kernel headers series = 4.1.x
  -> External toolchain C library = glibc/eglibc 
  -> [*] Toolchain has SSP support? (NEW) //Selected
  -> [*] Toolchain has RPC support? (NEW) //Selected
  -> [*] Toolchain has C++ support? //Selected
  -> [*] Enable MMU support (NEW) //Selected

3. Configure System Configuration

This is used to set some system configurations, such as the board name, welcome message, username, password, etc.

System configuration
 -> System hostname = Jasonangel //Platform name, set by yourself
 -> System banner = Welcome to xxxxx //Welcome message
 -> Init system = BusyBox //Use busybox
 -> /dev management = Dynamic using devtmpfs + mdev //Use mdev
 -> [*] Enable root login with password (NEW) //Enable login password
  -> Root password = 123456 //Login password is 123456

4. Configure Filesystem Images

This option configures the format of the root filesystem we ultimately create, configured as follows:

-> Filesystem images
 -> [*] ext2/3/4 root filesystem //If using EMMC or SD card, use ext3/ext4
  -> ext2/3/4 variant = ext4 //Select ext4 format
 -> [*] ubi image containing an ubifs root filesystem //If using NAND, use ubifs

5. Disable Compilation of Linux Kernel and Uboot

Buildroot can not only build the root filesystem but also compile the Linux kernel and uboot. When configuring buildroot, enabling the Linux kernel and uboot will cause buildroot to automatically download the latest Linux kernel and uboot source code and compile it. However, we generally do not use the Linux kernel and uboot downloaded by buildroot because the official source code downloaded by buildroot lacks many driver files, and the latest Linux kernel and uboot may have requirements for the compiler version, which could lead to compilation failures. Therefore, we need to configure buildroot to disable the compilation of the Linux kernel and uboot, only using buildroot to build the root filesystem. First, disable the compilation of the Linux kernel with the following configuration:

-> Kernel 
 -> [ ] Linux Kernel //Do not select to compile the Linux Kernel option!

Next, disable the compilation of Uboot with the following configuration:

-> Bootloaders 
-> [ ] U-Boot //Do not select to compile the U-Boot option!

6. Configure Target Packages

This option is used to configure the third-party libraries or software to choose, such as alsa-utils, ffmpeg, iperf, ftp, ssh, etc., which can be selected as needed.

Once the configuration is complete, you can compile buildroot. After compilation, buildroot will generate a compressed package of the generated root filesystem, which we can use directly. Enter the following command to start compiling:

sudo make //Note, you must add sudo, and do not specify multi-core compilation with -jx!!!

The buildroot compilation process will take a lot of time, please be patient! After the compilation is complete, the root filesystem will be generated under buildroot-2019.02.6/output/images and can be used.

The compilation process requires some extra memory, so be careful to leave enough memory; otherwise, you may encounter the following error:

g++: internal compiler error: Killed (program cc1plus) Please submit a full bug report

Busybox Configuration in Buildroot

Buildroot also uses busybox when constructing the root filesystem. Since busybox is used, it involves the configuration of busybox. Buildroot will automatically download the busybox compressed package, and the source code compressed packages downloaded by buildroot are stored in the /dl directory. In the dl directory, there is a folder called “busybox” where the busybox compressed package is saved.

To open the busybox configuration interface in buildroot, enter the following command:

sudo make busybox-menuconfig

After entering, the busybox configuration interface under buildroot will open, and you can enable any necessary functions. You can modify files in busybox to support Chinese, which can be searched on Baidu.

After the compilation is complete, a rootfs.tar will be generated. After copying it out, you can decompress it and use nfs to mount it to the board, or directly use an SD card to burn it. The compiled filesystem can be used. If you need any commands or tools, you can enable them again in make menuconfig and recompile.

·················· END ··················

Click to follow the official account for free learning materials

Welcome to follow my WeChat public account, where I regularly share articles related to C language, microcontrollers, embedded Linux, hardware design, and coding life. Reply with [eBook] in the public account to obtain a complete set of 500 electronic books on embedded systems. Reply with [Join Group] to join the embedded technology exchange group.

I have created a knowledge planet, and everyone is welcome to scan the code to join. There are answers to all questions in the knowledge planet. It provides a complete embedded learning plan, embedded learning materials, resume guidance, embedded job planning, embedded written interview guidance, company recommendations, etc.

Step-by-Step Guide to Building Root Filesystem with Buildroot

Recommended Reading

My 2021 Fall Recruitment Record

Series of Embedded Written and Interview Questions (Summary)

Embedded Book Recommendations

Why Read the Linux Kernel Source Code and How to Read the Linux Kernel Source Code

What is an Embedded Full-Stack?

Click “Like” and “View”!Step-by-Step Guide to Building Root Filesystem with Buildroot

Leave a Comment