Building a Custom Linux System with Buildroot

Introduction to Buildroot
Buildroot is a tool for automating the building of embedded Linux systems. Buildroot can generate cross-compilation toolchains, root filesystems, Linux kernel images, and bootloaders. Buildroot can be used independently with any combination of these options (for example, you can use an existing cross-compilation toolchain and only use Buildroot to build your root filesystem).

Buildroot is particularly useful for those engaged in embedded systems development. The processors commonly used in embedded systems are not the x86 processors we are familiar with on personal computers; they may be PowerPC processors, MIPS processors, ARM processors, etc.

Buildroot supports various processors and their variants; it also provides default configurations for several off-the-shelf development boards. Additionally, many third-party projects are based on Buildroot or develop their own BSP or SDK on top of it.

Building a Custom Linux System with Buildroot

Compilation Environment

Download Path: http://buildroot.org/downloads/

Required Software Dependencies

• Build Tools:– which– sed– make (version 3.81 or any later)– binutils– build-essential (only for Debian based systems)– diffutils– gcc (version 4.8 or any later)– g++ (version 4.8 or any later)– bash– patch– gzip– bzip2– perl (version 5.8.7 or any later)– tar– cpio– unzip– rsync– file (must be in /usr/bin/file)– bc– findutils• Source Acquisition Tools:– wget

Optional Software Dependencies

Recommended Dependency: Python 2.7 or higher

Configuration Interface Dependencies:

1. ncurses5: for using the menuconfig interface.

2. qt5: for using the xconfig interface.

3. glib2, gtk2, and glade2: for using the gconfig interface.

Compilation Process

Compilation Configuration

Run the following command from the Buildroot directory to start different configuration interfaces:

1. Use the original curses-based configurator, which is the traditional text-based configuration interface:

make menuconfig

2. Use the new curses-based configurator:

 make nconfig

3. Use the Qt-based graphical configurator:

 make xconfig

4. Use the GTK-based graphical configurator:

 make gconfig

Compilation Command

make -j32

Directory Overview

Directory Structure

Building a Custom Linux System with Buildroot

arch: contains files and configurations related to specific architectures, typically used to support different hardware architectures.

Building a Custom Linux System with Buildroot

board: contains support files and configurations for specific development boards, usually including settings and patches related to specific hardware.

Building a Custom Linux System with Buildroot

boot: files and configurations related to bootloaders and startup.

Building a Custom Linux System with Buildroot

configs: contains predefined configuration files to quickly set up Buildroot to support specific target systems or development boards.

Building a Custom Linux System with Buildroot

docs: contains documentation and user manuals for Buildroot, providing detailed information on using and configuring Buildroot.

fs: files and configurations related to the filesystem, which may include the construction and configuration of the root filesystem.

Building a Custom Linux System with Buildroot

linux: contains files and configurations related to the Linux kernel, usually for building and customizing the kernel.

Building a Custom Linux System with Buildroot

Makefile: the main Makefile that defines the rules and targets for the build process.

Makefile.legacy: possibly a Makefile for older versions or compatibility purposes.

package: contains definitions and configurations for all available software packages, allowing users to select which packages to include in the build.

Building a Custom Linux System with Buildroot

support: provides support files and tools, possibly including scripts and help documentation.

Building a Custom Linux System with Buildroot

system: files and settings related to system configuration and management.

Building a Custom Linux System with Buildroot

utils: contains utility tools and scripts, possibly for various tasks during the build process.

Building a Custom Linux System with Buildroot

Compilation Output Directory

Building a Custom Linux System with Buildroot

images: stores all image files (kernel images, bootloaders, and root filesystem images).

Building a Custom Linux System with Buildroot

build: the build directory for all components (including the tools required by Buildroot on the host and the software packages compiled for the target). This directory contains a subdirectory for each component.

Building a Custom Linux System with Buildroot

host: contains tools built for the host and the sysroot of the target toolchain. The former is the installation of tools compiled for the host, which are required for Buildroot to function properly, including the cross-compilation toolchain. The latter is a directory resembling the root filesystem hierarchy that contains all the header files and libraries for user-space software packages, which are provided and installed for use by other packages. However, this directory is not intended to be used as the target’s root filesystem, as it contains a large number of development files, unstripped binaries, and libraries, making it too bulky for embedded systems. These development files are used to compile target libraries and applications that depend on other libraries.

Building a Custom Linux System with Buildroot

staging: a symbolic link to the target toolchain sysroot in host, existing for backward compatibility.

Building a Custom Linux System with Buildroot

target: contains almost the complete root filesystem for the target: everything needed is here except for the device files in /dev (Buildroot cannot create them as it does not run as root, nor does it want to run as root). Moreover, it does not have the correct permissions (for example, the setuid permission for busybox binaries). Therefore, this directory should not be used on your target. Instead, you should use the images built in the images directory. If you need a tarball image for a root filesystem to boot via NFS, then use the tarball image generated in images and extract it as root. Compared to staging/, target only contains the files and libraries necessary to run the selected target applications: it does not include development files (header files, etc.), and binaries have been stripped.

Building a Custom Linux System with Buildroot

Actual Environment Compilation Testing

Error opening compilation interface: make menuconfig error, prompting to install ncurses,

Installation command: yum install ncurses-devel

[]# tar xzf buildroot-2024.02.8.tar.gz []# cd buildroot-2024.02.8/[buildroot-2024.02.8]# lsarch   boot     Config.in         configs  DEVELOPERS  fs     Makefile         package  support  toolchainboard  CHANGES  Config.in.legacy  COPYING  docs        linux  Makefile.legacy  README   system   utils[buildroot-2024.02.8]# make menuconfigmkdir -p /root/buildroot-2024.02.8/output/build/buildroot-config/lxdialogPKG_CONFIG_PATH="" make CC="/usr/bin/gcc" HOSTCC="/usr/bin/gcc" \
    obj=/root/buildroot-2024.02.8/output/build/buildroot-config -C support/kconfig -f Makefile.br mconfmake[1]: Entering directory '/root/buildroot-2024.02.8/support/kconfig'/usr/bin/gcc -DCURSES_LOC="<curses.h>" -DLOCALE  -I/root/buildroot-2024.02.8/output/build/buildroot-config -DCONFIG_=""  -MM *.c > /root/buildroot-2024.02.8/output/build/buildroot-config/.depend 2>/dev/null || :/usr/bin/gcc -DCURSES_LOC="<curses.h>" -DLOCALE  -I/root/buildroot-2024.02.8/output/build/buildroot-config -DCONFIG_=""   -c conf.c -o /root/buildroot-2024.02.8/output/build/buildroot-config/conf.o *** Unable to find the ncurses libraries or the *** required header files. *** 'make menuconfig' requires the ncurses libraries. ***  *** Install ncurses (ncurses-devel or libncurses-dev  *** depending on your distribution) and try again. *** make[1]: *** [Makefile:253: /root/buildroot-2024.02.8/output/build/buildroot-config/dochecklxdialog] Error 1make[1]: Leaving directory '/root/buildroot-2024.02.8/support/kconfig'make: *** [Makefile:956: /root/buildroot-2024.02.8/output/build/buildroot-config/mconf] Error 2[buildroot-2024.02.8]# yum install ncurses-devel

Error during compilation: make error

Installation: yum install perl-ExtUtils-MakeMaker perl-IPC-Cmd

[buildroot-2024.02.8]# make/usr/bin/make -j1  O=/root/buildroot-2024.02.8/output HOSTCC="/usr/bin/gcc" HOSTCXX="/usr/bin/g++" syncconfigmake[1]: Entering directory '/root/buildroot-2024.02.8'mkdir -p /root/buildroot-2024.02.8/output/build/buildroot-config/lxdialogPKG_CONFIG_PATH="" /usr/bin/make CC="/usr/bin/gcc" HOSTCC="/usr/bin/gcc" \
    obj=/root/buildroot-2024.02.8/output/build/buildroot-config -C support/kconfig -f Makefile.br confmake[2]: Entering directory '/root/buildroot-2024.02.8/support/kconfig'/usr/bin/gcc -D_GNU_SOURCE -D_DEFAULT_SOURCE  -DCURSES_LOC="&lt;<ncurses.h&gt;" '="" ***="" -dconfig_="" -dlocale="" -dncurses_widechar="1" -i="" -o="" 1<="" [support="" are="" at="" build="" buildroot-2024.02.8="" buildroot-2024.02.8'your="" buildroot-config="" code="" complete="" conf.o="" confmake[2]:="" dependencies="" dependencies.mk:27:="" dependencies]="" directory="" enough;="" error="" extutils::makemaker="" followingmodules="" installation="" ipc::cmdmake:="" is="" kconfig'make[1]:="" least="" leaving="" missing:="" not="" output="" perl="" root="" support="" the="" zconf.tab.o=""></ncurses.h&gt;">

Compilation Results

[output]# lsbuild  host  images  staging  target[output]# ls images/rootfs.tar[output]# ls target/bin  etc  lib32    media  opt   root  sbin  THIS_IS_NOT_YOUR_ROOT_FILESYSTEM  usrdev  lib  linuxrc  mnt    proc  run   sys   tmp                               var[output]# ls build/buildroot-config                                         host-makedevsbuildroot-fs                                             host-mpc-1.2.1build-time.log                                           host-mpfr-4.1.1busybox-1.36.1                                           host-patchelf-0.13gcc-final-12.4.0                                         host-skeletonglibc-2.38-81-gc8cb4d2b86ece572793e31a3422ea29e88d77df5  ifupdown-scriptshost-acl-2.3.2                                           initscriptshost-attr-2.5.2                                          linux-headers-6.6.58host-autoconf-2.72                                       locales.nopurgehost-automake-1.16.5                                     packages-file-list-host.txthost-binutils-2.40                                       packages-file-list-staging.txthost-bison-3.8.2                                         packages-file-list.txthost-fakeroot-1.32.1                                     skeletonhost-gawk-5.3.0                                          skeleton-init-commonhost-gcc-final-12.4.0                                    skeleton-init-sysvhost-gcc-initial-12.4.0                                  toolchainhost-gmp-6.3.0                                           toolchain-buildroothost-libtool-2.4.6                                       urandom-scriptshost-m4-1.4.19

Leave a Comment