Adding the local hello_world package in the Buildroot framework and applying patches to the package
In Chapter 2, we discussed how to joyfully compile ffmpeg under the Buildroot framework. This chapter documents how to add a new software package to the Buildroot compilation framework to achieve consistency in development. The advantage of doing this is to maintain the uniformity of the entire build process; otherwise, you might need to build your project's compilation environment. The benefits of compatibility with the Buildroot compilation framework will gradually become evident as the complexity of developing software packages increases. Therefore, this chapter demonstrates how to follow the guidance in 'The Buildroot User Manual.pdf' to integrate the 'hello_world' project into the Buildroot package step by step.
Integrating the local 'hello_world' project into the Buildroot package compilation framework involves merging the patch integration work. During the build of 'hello_world', this patch is automatically applied. The primary reference material for this process is '[The Buildroot User Manual.pdf](The Buildroot User Manual.pdf )
Integration of 'hello_world' into BuildrootFirst, let's take a look at the structure and content of the 'hello_world' project itself:
The next step is to integrate 'hello_world' into Buildroot as a package for building. To start with, let's see how the Buildroot manual describes this process (detailed descriptions can be found in 'The Buildroot User Manual.pdf’):
Here are the key three categories totaling four files:
1. Config File (Configuration File):
2. Config.in file: For cross-compiling the project. In this case, we are using cross-compilation for the 'hello_world' project, and the final executable will run on YY3568. Therefore, we use this file.
Makefile (Build File - xxx.mk file):
3. xxx.mk file: Since I am familiar with traditional Makefiles, for this demonstration, I am using Makefiles for generic packages.
Hash File (Hash Verification File):
4. xxx.hash file: This file contains the hash verification for downloaded software packages. Since, in this case, we are directly using the local source code, there is no package file verification, so this file is not applicable for now.
Based on the above explanation, the first step is to create the 'hello_world' directory in the Buildroot package directory. Then, create the Config.in and hello_world.mk files. The content of these two files is as follows:
Config.in file: For demonstration purposes, we are only using an option to enable or disable the compilation of ‘hello_world
config BR2_PACKAGE_HELLO_WORLD
bool
"hello_world"
help
This
is
a
comment
that explains how
to
add
new package
to
buildroot
hello_world.mk file:
################################################################################ # # hello_world # ################################################################################HELLO_WORLD_VERSION = 0.9HELLO_WORLD_SOURCE = hello_world HELLO_WORLD_SITE = /home/red/Public/buildroot_sample/hello_world HELLO_WORLD_LICENSE = GPL-3.0+ HELLO_WORLD_LICENSE_FILES = COPYING HELLO_WORLD_INSTALL_STAGING = YES HELLO_WORLD_SITE_METHOD = local define HELLO_WORLD_BUILD_CMDS $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D) all endef define HELLO_WORLD_INSTALL_STAGING_CMDS $(INSTALL) -D -m 0755 $(@D)/hello_world $(STAGING_DIR)/usr/bin endef define HELLO_WORLD_INSTALL_TARGET_CMDS $(INSTALL) -D -m 0755 $(@D)/hello_world $(STAGING_DIR)/usr/bin endef
In the hello_world.mk file, the key points are that HELLO_WORLD_SITE_METHOD needs to be set to local, so that the original files in the local directory will be used; HELLO_WORLD_SITE needs to be set to the directory where the source code of the local hello_world project is located, not the directory where the hello_world project source code, not the directory where the hello_world project (folder) is located.
The final modification involves having Buildroot's Config.in reference the Config.in of 'hello_world', specifically the relevant diff files.
diff --git a/buildroot/package/Config.in b/buildroot/package/Config.in index d18c688..d06ec07 100644 --- a/buildroot/package/Config.in +++ b/buildroot/package/Config.in [url=home.php?mod=space&uid=1999721]@@[/url] -10,6 +10,7 @@ menu "Target packages" source "package/skeleton-init-sysv/Config.in" menu "Audio and video applications" + source "package/hello_world/Config.in" source "package/alsa-utils/Config.in" source "package/alsa-plugins/Config.in" source "package/atest/Config.in
Because I will be developing an application related to video processing, I have placed the reference to the 'hello_world' project in the "Audio and video applications" section.
In this way, when you launch the Buildroot menuconfig configuration, you can find the configuration options for 'hello_world'. Select it to build.
Transfer the compiled 'hello_world' using scp to YY3568, and print the following
2. Creating a patch for 'hello_world' and relying on Buildroot to merge the patch and compile during the build.
With the foundation of the first part, let's advance by creating a patch for 'hello_world'. We want Buildroot to apply this patch before compiling the project.
Here, we need to refer to this section for more details.
First, we create this patch, and the patch file is named 0001-say-sth-else.patch
diff --git a/main.c b/main.c index dd0e127..fcbbe7e 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,6 @@ int main(int argc, char *argv[]) { - printf("red say hello world to YY3568n"); + printf("red say sth else to YY3568 just for demonstate how to patch package in buildrootn"); return 0; }
Place it in the buildroot/package/hello_world directory.
Next, you need to package the original 'hello_world' project into a compressed file, such as hello_world.tar. Then, modify the hello_world.mk file as follows:
--- /tmp/tar_o.txt 2023-08-12 12:41:28.772370902 +0800 +++ /tmp/tar.txt 2023-08-12 12:41:53.564330270 +0800 @@ -4,12 +4,12 @@ # ################################################################################
HELLO_WORLD_VERSION = 0.9
-HELLO_WORLD_SOURCE = hello_world
-HELLO_WORLD_SITE = /home/red/Public/buildroot_sample/hello_world +HELLO_WORLD_SOURCE = hello_world.tar
+HELLO_WORLD_SITE = /home/red/Public/buildroot_sample HELLO_WORLD_LICENSE = GPL-3.0+ HELLO_WORLD_LICENSE_FILES = COPYING
HELLO_WORLD_INSTALL_STAGING = YES -HELLO_WORLD_SITE_METHOD = local
+HELLO_WORLD_SITE_METHOD = file define HELLO_WORLD_BUILD_CMDS $(MAKE) $(TARGET_CONFIGURE_OPTS) -C $(@D) all endef
Then, delete the buildroot/output/rockchip_rk3568/build/hello_world-0.9 directory and rebuild.
Please note that the method HELLO_WORLD_SITE_METHOD = local, as tested, does not perform the patching action.
So far, we have documented how to add a local package to Buildroot and apply a patch. The process is similar when including remote software packages in the Buildroot package. We won't cover that here for now. Just a reminder, if the patch is remote, you need to add the corresponding patch file to the _PATCH variable, and this is also explained in The Buildroot User Manual.pdf.
Comments
Please log in or sign up to comment.