Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

In embedded system development, quickly and seamlessly integrating proprietary applications into the Buildroot image is crucial for accelerating product iteration. Taking the Allwinner A40i platform as an example, this article walks you through the full process of creating a package directory, writing Config.in and .mk build scripts, and enabling your local application via the board-level defconfig.

Buildroot is essentially an automated build framework. Although build scripts for well-known open-source packages such as U-Boot and the Linux kernel are maintained by the community, you'll often need to add your own custom app_pkg packages to build and integrate your proprietary applications.

Buildroot offers a framework of functions and variable commands. Build scripts like app_pkg.mk, written using this framework, are parsed by the core script package/pkg-generic.mk, which integrates them into the main Buildroot Makefile. In the end, executing make all runs Buildroot's top-level Makefile and produces the target image.

package/pkg-generic.mk automatically handles routine tasks like downloading, extracting, and building dependencies by calling pkg-download.mk and pkg-utils.mk located in the same directory. Just follow the specified format to write the Makefile-style app_pkg.mk, filling in details such as the download URL, names of dependent libraries, and other package-specific build settings.

1. Run mkdir helloworld under the buildroot-201611/package/ directory to create a folder for helloworld.

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

2. In the demo_app directory, create the files Config.in and touch helloworld.mk. Note that the filenames are critical — helloworld.mk must be in lowercase and cannot be renamed, as the Buildroot framework follows specific naming conventions to process app packages. Therefore, when building projects in Buildroot, it is essential to adhere to the naming rules outlined in this article, or you may encounter various errors.

3. Modify the Config.in and helloworld.mk files.

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

Note:

Variables ending with _VERSION represent the source code version.

Variables ending with _SITE specify the source code downloading address.

Variables ending with _SITE_METHOD specify the method for downloading the source code.

Variables ending with _BUILD_CMDS are executed during the Buildroot framework compilation process. They are used to pass compilation and linking options to the source code's Makefile and to invoke the Makefile.

Variables ending with _INSTALL_TARGET_CMDS are executed after the compilation is complete, automating the installation process. They typically instruct Buildroot to copy the compiled binaries or libraries to the specified directory.

The most important part is $(eval $(generic-package)), which must not be omitted, or else the source code will not be compiled. This function expands the entire .mk build script into the Makefile under the buildroot/ directory, following the Buildroot framework, to generate the build targets.

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

Note that demo_app.mk does not replace the actual Makefile of the demo_app source code. It is simply an upper-level Makefile that tells Buildroot where to fetch the source code, how to extract the source, which compilation options to pass to the variables in the source code's Makefile, and where the compiled libraries and binaries should be installed in the root filesystem (rootfs). The specific step-by-step compilation of the demo_app source code relies on the Makefile within the demo_app source code itself.

The official website also has an English version of the documentation

https://buildroot.org/downloads/manual/manual.html#adding-packages. For a detailed explanation of the principles, you can refer to this document.

4. Create and modify/home/forlinx/helloworld/helloworld.c

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

5. Create and modify buildroot/package/app/helloworld/Makefile

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

6. Add the helloworld option in buildroot-201611/package/Config.in.

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

7. Add BR2_PACKAGE_HELLOWORLD=y in lichee/buildroot-201611/configs/sun8iw11p1_hf_defconfig.

The configuration file for Buildroot-201611 is located at buildroot-201611/configs/sun8iw11p1_hf_defconfig. You can modify this configuration file to set up the source code. After configuring, copy the file to out/sun8iw11p1/linux/common/buildroot/.config, and the compilation will follow the settings in .config.

Error: After running make menuconfig, a .config file will be generated. Replacing the .config in the out directory with it will result in an error

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

8. ./build.sh to perform a full compilation

from out/sun8iw11p1/linux/common/buildroot/build/helloworld-1.0.0/ to out/sun8iw11p1/linux/common/buildroot/target/bin.

Quick Integration Solution for Local Applications in Buildroot on the Allwinner A40i Platform

9. ./build.sh pack to make package.




Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!