Buildroot Development

Buildroot development basis

Specific development skills can be learned from the Buildroot website.

Buildroot version

Current version of Buildroot is Buildroot-2018.02

Configuration options and building

After finishing the configuration according to the following steps, please run make.

source buildroot/build/envsetup.sh
You're building on Linux
Lunch menu...pick a combo:

1. firefly_rk3308_release
2. firefly_rk3308_recovery
3. firefly_rk3308_pcba

Which would you like? [1] 1
===========================================

If selecting firefly_rk3308_release, please input corresponding serial number 1

make

After completing the compiling, please run mkfirmware.sh script under the SDK root directory to generate the firmware.

Compiling execution process

Execution process:

  • Download source code;

  • Configure, compile, and install the cross toolchain;

  • Configure, compile, install the selected packages;

  • Generate root file system according to the selected options;

Results of building Buildroot should be saved in output directory. As for specific directory, it should be determined by the configuration files. For example, compile and configure firefly_rk3308_release, and the output results should be saved under directory of buildroot/output/firefly_rk3308_release .

The following compiling could be executed under directory of buildroot/output/firefly_rk3308_release or the project root directory (make menuconfig could also be executed under project root directory). This directory consists of several sub-directories:

  • image/: Contains the zipped image files of the root file system.

  • build/: Contains all source files, including the host tools and selected packages required by Buildroot. This directory contains source code of all modules.

  • staging/: This is a directory with structure similar to the root file system. It contains all header files, libraries, and other development files generated by the compilation. But all of the above are not tailored so that they are in huge quantity and not suitable for target file system.

Module configuration

The Buildroot as a whole is composed of Makefile scripts and Kconfig configuration files. It seems like the same as compiling a Linux kernel in operation.

make menuconfig

The configuration interface is as follows:

_images/make-menuconfig.png

Add and tailor some certain tools in Target packages, customize system functions according to requirements. All the commonly used libdrm, ssh, vsftpd, wpa_supplicant, and pppd can be configured inside it.

Execute the following command to save the current configuration and automatically modify the default configuration files under the directory of buildroot/configs/:

make savedefconfig

It needs to be noted that:

  • While compiling, buildroot can automatically get related packages from the network according to the configuration, including some certain third-party libraries, plug-ins, and tools, and then, they shall be put under the directory of dl/.

  • The package will be unzipped under the directory of the output/build/, and then be compiled.

  • The source code of the package can be modified by patches, which shall be stored under the directory of package/, and the buildroot will patch the package when it is unzipped.

Modify Busybox configuration

Configuration command:

make busybox-menuconfig

The configuration of the completed modification can be saved by the command as below:

make busybox-update-config

Cross compiling tools

After the Buildroot compiling is finished, a cross compiling tool will be generated under the host directory, which is the specified output directory. And this tool can be used to compile the target program. The default directory, under which, the cross compiling tool is configured and generated is:

cd buildroot/output/firefly_rk3308_release/host/usr/bin/

We can compile the program directly by the cross compiling tool, for example:

./buildroot/output/firefly_rk3308_release/host/usr/bin/aarch64-rockchip-linux-gnu-gcc main.c -o test

Floating point support (the following configuration opens neon support), RK3308 supports features of crc/crypto/fp/simd, and the configuration is as follows:

CFLAGS += -mcpu=cortex-a35+crc+crypto

Compiling

In the development process, the source code of a module under output/build/ has been modified, and the package needs to be recompiled separately.

Some certain sample files can be recorded during the process when compiling a package in Buildroot, and saved under directory of corresponding package source code. These files include:

.stamp_configured
.stamp_downloaded
.stamp_extracted
.stamp_patched
.stamp_staging_installed
.stamp_target_installed

These sample files mainly control the download, unzip, zip, configuration, compiling, and installation of this package. For specific details, please refer to:

docs/manual/rebuilding-packages.txt

Or directly view mk files to get to know the principles:

package/pkg-generic.mk

In order to re-execute a step, the corresponding sample files should be deleted accordingly. For example, if you want to recompile the source code of a package, just delete the .stamp_built and .stamp_target_installed under the directory, and then compile the entire Buildroot.

There’s a another faster implementation in Buildroot.

  • Run make show-targets to show all the targets to be compiled in this current configuration.

  • Run make <package> to build and install this package and its dependent items.

Meanwhile, we can also call a certain step in the process of building the package through make <package>-<target>, see the followings:

Package-specific:
  <pkg>                  - Build and install <pkg> and all its dependencies
  <pkg>-source           - Only download the source files for <pkg>
  <pkg>-extract          - Extract <pkg> sources
  <pkg>-patch            - Apply patches to <pkg>
  <pkg>-depends          - Build <pkg>'s dependencies
  <pkg>-configure        - Build <pkg> up to the configure step
  <pkg>-build            - Build <pkg> up to the build step
  <pkg>-graph-depends    - Generate a graph of <pkg>'s dependencies
  <pkg>-dirclean         - Remove <pkg> build directory
  <pkg>-reconfigure      - Restart the build from the configure step
  <pkg>-rebuild          - Restart the build from the build step

Therefore, if we want to recompile the xxx package, we just need to run make xxx-rebuild.

More skills about making the buildroot, please acquire from make help.

Add new local package

The above introduction shows us how to select and compile by Buildroot under the precondition of already having the source code package, then, what should we do if there’s no package, or how can we integrate the application that we write by ourselves to Buildroot?

Buildroot supports multiple compiling modes, including generic-package, cmake-package, autotools-package, etc. we hereby explain by taking generic-package for instance.

Example: buildroot/package/rockchip/fireflydemo

  • Create package directory

buildroot/package/rockchip/fireflydemo/
  • New a Config.in

config BR2_PACKAGE_FIREFLYDEMO
bool "Simple Firefly Demo"
  • New a fireflydemo.mk, fill in the following contents, of which, the source code directory shall point to external/fireflydemo/src/

##################################################
###########
#
## fireflydemo
#
###################################################
###########
ifeq ($(BR2_PACKAGE_FIREFLYDEMO), y)
    FIREFLYDEMO_VERSION:=1.0.0
    FIREFLYDEMO_SITE=$(TOPDIR)/../external/fireflydemo/src
    FIREFLYDEMO_SITE_METHOD=local
define FIREFLYDEMO_BUILD_CMDS
    $(TARGET_MAKE_ENV) $(MAKE) CC=$(TARGET_CC) CXX=$(TARGET_CXX) -C $(@D)
endef
define FIREFLYDEMO_CLEAN_CMDS
    $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) clean
endef
define FIREFLYDEMO_INSTALL_TARGET_CMDS
    $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install
endef
define FIREFLYDEMO_UNINSTALL_TARGET_CMDS
    $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) uninstall
endef
$(eval $(generic-package))
endif
  • Create source code directory

external/fireflydemo/src/
  • Write the source code demo.c

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
    printf("hello world\n");
    return 0;
}
  • Write Makefile

DEPS =
OBJ = demo.o
CFLAGS =
%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)
demo: $(OBJ)
    $(CXX) -o $@ $^ $(CFLAGS)
.PHONY: clean
clean:
    rm -f *.o *~ demo
.PHONY: install
install:
    cp -f demo $(TARGET_DIR)/usr/bin/
.PHONY: uninstall
uninstall:
    rm -f $(TARGET_DIR)/usr/bin/demo
  • Add the new package to the Buildroot compiling system;

  • Modify package/rockchip/Config.in and add the following line to the last line:

source "package/rockchip/fireflydemo/Config.in"
  • Configuring package, you can run make menuconfig and select fireflydemo package;

  • Running Make fireflydemo to compile

  • Running Make and Packaged into the root file system

  • Recompile package after modifying source code, run make fireflydemo-rebuild

fs-overlay

The default compiled root file system, some default configuration may not meet the customization needs At this time, the directory of fs-overlay can be used to replace the file system directory in the final stage of compilation, and package into the root file system. The fs-overlay path is specified by the default configuration file:

BR2_ROOTFS_OVERLAY="board/rockchip/rk3308/fs-overlay"

Rootfs switch as ext2

Rootfs can be configured as read-write ext2 file system, which is convenient for system debugging and using.

  • Modify bootargs configuration in Kernel:

diff --git a/kernel/arch/arm64/boot/dts/rockchip/rk3308-firefly.dtsi b/kernel/arch/arm64/boot/dts/rockchip/rk3308-firefly.dtsi
index acd0dab..939db3c 100644
--- a/kernel/arch/arm64/boot/dts/rockchip/rk3308-firefly.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3308-firefly.dtsi
@@ -11,7 +11,7 @@
        compatible = "firefly,rk3308-firefly", "firefly,rk3308";
 
        chosen {
-               bootargs = "earlycon=uart8250,mmio32,0xff0c0000 swiotlb=1 console=ttyFIQ0 root=PARTUUID=614e0000-0000 rootfstype=squashfs rootwait";
+               bootargs = "earlycon=uart8250,mmio32,0xff0c0000 swiotlb=1 console=ttyFIQ0 root=PARTUUID=614e0000-0000 rootfstype=ext2 rootwait";
        };
 
        adc-keys {
  • Modify parameter files corresponding to device/rockchip/rk3308/rockimg/, and make sure rootfs partition size is big enough to store the partition images.

  • Modify the file types of rootfs in device\rockchip\rk3308\BoardConfig.mk, as:

diff --git a/device/rockchip/rk3308/BoardConfig.mk b/device/rockchip/rk3308/BoardConfig.mk
index abb9e96..97662b3 100755
--- a/device/rockchip/rk3308/BoardConfig.mk
+++ b/device/rockchip/rk3308/BoardConfig.mk
@@ -28,7 +28,7 @@ TARGET_PRODUCT=rk3308
 
 # Set rootfs type, see buildroot.
 # ext4 squashfs
-ROOTFS_TYPE=squashfs
+ROOTFS_TYPE=ext2
 
 # Set data partition type.
 # ext2 squashfs
  • rootfs partition: a ext2 file system images can be automatically zipped and generated, or acquired directly from the following path:

buildroot/output/firefly_rk3308_release/images/rootfs.ext2

External storage devices

TF card device mount directory: /sdcard

USB device mount directory: /udisk

Currently supported file system formats: ext2, vfat, ntfs, etc.