Rockchip RK3588 - Rockchip Linux SDK Buildroot文件系统构建
目录
----------------------------------------------------------------------------------------------------------------------------
开发板 :ArmSoM-Sige7
开发板
eMMC
:64GB
LPDDR4
:8GB
显示屏 :15.6
英寸HDMI
接口显示屏
u-boot
:2017.09
linux
:5.10
----------------------------------------------------------------------------------------------------------------------------
一、Buildroot
文件系统
在《Rockchip RK3588 - Rockchip Linux SDK
编译》中我们对Buildroot
进行了简单的介绍,并一键全自动编译生成了buildroot
文件系统。
1.1 Buildroot
系统
Buildroot
是Linux
平台上一个开源的嵌入式Linux
系统自动构建框架。整个Buildroot
是由Makefile
脚本和Kconfig
配置文件构成的。可通过Buildroot
配置,编译出一个完整的可以直接烧写到机器上运行的Linux
系统软件。

Buildroot
有以下几点优势:
- 通过源码构建,有很大的灵活性;
- 方便的交叉编译环境,可以进行快速构建,容易上手;
- 提供系统各组件的配置,方便定制开发。
使用Buildroot
的project
最出名的就是Openwrt
。可以看到,由它制作出的镜像可以跑在搭载16 Mb SPINOR
的路由器上,系统基本没包含多余的东西。 这就是得益于Buildroot
的简单化。整个Buildroot
工程在一个git
维护。
Buildroot
使用kconfig
和make
,一个defconfig
配置代表一种BSP
支持。Buildroot
本身不具备扩展能力,用户需要自己通过脚本来完成工作。这些列出来的特点,都是和Yocto
不同的地方。
注意:Buildroot
默认使用Busybox
来制作根文件系统。
1.2 Buildroot
框架
Rockchip Linux SDK
的Buildroot
系统,其包含了基于Linux
系统开发用到的各种系统源码,驱动,工具,应用软件包。
其目录结构如下:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll
drwxr-xr-x 2 root root 4096 6月 9 12:58 arch/
drwxr-xr-x 2 root root 4096 6月 9 12:58 archives/
drwxr-xr-x 75 root root 4096 6月 9 12:58 board/
drwxr-xr-x 26 root root 4096 6月 9 12:58 boot/
drwxr-xr-x 2 root root 4096 6月 9 12:58 build/
-rw-r--r-- 1 root root 454027 6月 9 12:58 CHANGES
-rw-r--r-- 1 root root 29466 6月 9 12:58 Config.in
-rw-r--r-- 1 root root 135314 6月 9 12:58 Config.in.legacy
drwxr-xr-x 3 root root 20480 6月 9 12:58 configs/
-rw-r--r-- 1 root root 18767 6月 9 12:58 COPYING
-rw-r--r-- 1 root root 1198 6月 9 12:58 .defconfig
-rw-r--r-- 1 root root 72437 6月 9 12:58 DEVELOPERS
drwxr-xr-x 176 root root 4096 6月 11 19:57 dl/
drwxr-xr-x 5 root root 4096 6月 9 12:58 docs/
lrwxrwxrwx 1 root root 17 6月 9 12:58 envsetup.sh -> build/envsetup.sh*
-rw-r--r-- 1 root root 96 6月 9 12:58 .flake8
drwxr-xr-x 20 root root 4096 6月 9 12:58 fs/
-rw-r--r-- 1 root root 125 6月 9 12:58 .gitignore
-rw-r--r-- 1 root root 721 6月 9 12:58 .gitlab-ci.yml
drwxr-xr-x 3 root root 4096 6月 9 12:58 linux/
-rw-r--r-- 1 root root 47335 6月 9 12:58 Makefile
-rw-r--r-- 1 root root 2292 6月 9 12:58 Makefile.legacy
drwxr-xr-x 5 root root 4096 6月 18 01:24 output/
drwxr-xr-x 2594 root root 73728 6月 9 12:58 package/
-rw-r--r-- 1 root root 1075 6月 9 12:58 README
-rw-r--r-- 1 root root 644 6月 9 12:58 README.rockchip
drwxr-xr-x 13 root root 4096 6月 9 12:58 support/
drwxr-xr-x 3 root root 4096 6月 9 12:58 system/
drwxr-xr-x 5 root root 4096 6月 9 12:58 toolchain/
drwxr-xr-x 3 root root 4096 6月 9 12:58 utils/
1.2.1 目录介绍
这里我们只介绍一些重要的目录,其中:
arch
: 存放CPU
架构相关的配置脚本,如arm/mips/x86
,这些CPU
相关的配置,在制作工具链时,编译uboot
和kernel
时很关键;board
:这个目录包含了针对特定开发板的配置文件和补丁。每块开发板都有自己的子目录,里面可能包含特定的配置文件、设备树文件、补丁以及其他相关文件;这些文件帮助Buildroot
在不同的硬件平台上进行适配和配置,以生成针对特定开发板的嵌入式linux
系统;boot
:这个目录包含与引导加载程序相关的文件和脚本。它通常包括引导加载程序(如u-boot
)、引导配置文件、引导脚本等;Buildroot
可以在这里生成和配置引导加载程序以及相关的启动文件;configs
: 放置开发板的一些配置,这些配置文件以_defconfig
结尾,比如rockchip_rk3358_recovery_defconfig
;dl
:存放从互联网下载的源代码及应用软件的压缩包,比如zip
、glic
、busybox
、alsa-lib
、alsa-plugins
等;docs
:存放相关的参考文档;fs
:存放各种文件系统的源代码,它控制着根文件系统的创建和各类文件系统映像的生成(如ext2
、squashfs
等);linux
:存放着linux kernel
的自动构建脚本,它用于下载、配置、编译linux
内核;output
:这个目录是构建输出目录,包含所有构建过程中生成的文件,如交叉编译工具链、内核映像、根文件系统等。默认情况下,这个目录不在源码树中,而是在构建时生成的,可以通过配置来改变其位置;package
:这个目录包含Buildroot
支持的所有软件包的目录结构;每个软件包都有自己的子目录,包括描述如何下载、配置、编译和安装该软件包的元数据和Makefile
;support
:这个目录包含一些支持脚本和工具。例如:scripts/
:包含各种辅助脚本,如生成配置文件、下载源代码等;kconfig/
:包含与Kconfig
系统相关的文件,用于配置Buildroot
构建系统;
system
:这个目录包含与基本系统配置相关的文件和脚本,例如初始化脚本、设备表、主机名等;toolchain
:这个目录包含工具链的构建和配置文件。工具链通常包括编译器、链接器、库和头文件,它们是构建其他软件包所必需的;utils
:一些工具。
Rockchip Linux SDK
集成了Buildroot
第三方包下载机制,确保客户能够有效下载。现在采用了更灵活的机制, 在原生dl
基础上增加archives
目录,预置第三方包。同时如果无法连接Google
,将切换到使用国内的kgithub
镜像,并优先从mk
脚本指定的源下载,如果失败将尝试mk
脚本和defconfig
配置的镜像源,最后才是官方备份源。
在官方树中,大多数源码都是使用wget
来获取;只有小部分通过他们的git
,mercurial
或者svn
储存库。
1.2.2 框架介绍
Buildroot
提供了函数框架和变量命令框架,采用它的框架编写的app_pkg.mk
这种Makefile
格式的自动构建脚本,将被package/pkg-generic.mk
这个核心脚本展开填充到buildroot
主目录下的Makefile
中去。
最后make all
执行Buildroot
主目录下的Makefile
,生成你想要的image
。 package/pkg-generic.mk
中通过调用同目录下的pkg-download.mk
、pkg-utils.mk
文件,已经自动实现了下载、解压、依赖包下载编译等一系列机械化的流程。
只要需要按照格式写Makefile
脚本app_pkg.mk
,填充下载地址,链接依赖库的名字等一些特有的构建细节即可。
总而言之,Buildroot
本身提供构建流程的框架,开发者按照格式写脚本,提供必要的构建细节,配置整个系统,最后自动构建出你的系统。

Buildroot
的配置(即make menuconfig
所看到的配置)通过Config.in
串联起来,起点在根目录Config.in
中,该文件包含了各个模块目录下的Config.in
文件:
mainmenu "Buildroot $BR2_VERSION Configuration"
......
source "toolchain/Config.in"
source "system/Config.in"
source "linux/Config.in"
source "package/Config.in"
source "fs/Config.in"
source "boot/Config.in"
source "package/Config.in.host"
source "Config.in.legacy"
# br2-external menus definitions
source "$BR2_BASE_DIR/.br2-external.in.menus"
其中:
配置选项 | Config.in位置 |
---|---|
Target options | arch/Config.in |
Build options | Config.in |
Toolchain | toolchain/Config.in |
System configuration | system/Config.in |
Kernel | linux/Config.in |
Target packages | package/Config.in |
Target packages->Busybox | |
Filesystem images | fs/Config.in |
Bootloaders | boot/Config.in |
Host utilities | package/Config.in.host |
Legacy config options | Config.in.legacy |
1.3 Buildroot
配置
同内核编译有点类似,首先需要选择一个单板的配置,单板的默认配置在configs
目录下。
也可以通过如下命令列出来,然后选择具体平台编译;
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo -s source envsetup.sh
比如这里选择rockchip_rk3588_defconfig
;
#include "base/base.config"
#include "chips/rk3588_aarch64.config"
#include "font/chinese.config"
#include "fs/exfat.config"
#include "fs/ntfs.config"
#include "fs/vfat.config"
#include "gpu/gpu.config"
#include "multimedia/audio.config"
#include "multimedia/camera.config"
#include "multimedia/gst/audio.config"
#include "multimedia/gst/camera.config"
#include "multimedia/gst/rtsp.config"
#include "multimedia/gst/video.config"
#include "multimedia/mpp.config"
#include "wifibt/bt.config"
#include "wifibt/wireless.config"
#include "benchmark.config"
#include "chromium.config"
#include "debug.config"
#include "npu2.config"
#include "powermanager.config"
#include "test.config"
#include "weston.config"
或者直接执行如下命令:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make rockchip_rk3588_defconfig
GEN /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/Makefile
/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/build/parse_defconfig.sh /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/configs/rockchip_rk3588_defconfig /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/.config.in
Parsing defconfig: /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/configs/rockchip_rk3588_defconfig
Using configs/rockchip/base/kernel.config as base
Merging configs/rockchip/fs/e2fs.config
Merging configs/rockchip/base/common.config
Merging configs/rockchip/base/base.config
Merging configs/rockchip/chips/rk3588.config
Value of BR2_ROOTFS_OVERLAY is redefined by configs/rockchip/chips/rk3588.config:
Previous value: BR2_ROOTFS_OVERLAY="board/rockchip/common/base"
Modify value: BR2_ROOTFS_OVERLAY+="board/rockchip/rk3588/fs-overlay/"
New value: BR2_ROOTFS_OVERLAY="board/rockchip/common/base board/rockchip/rk3588/fs-overlay/"
Merging configs/rockchip/chips/rk3588_aarch64.config
Merging configs/rockchip/font/font.config
Merging configs/rockchip/font/chinese.config
Merging configs/rockchip/fs/exfat.config
Merging configs/rockchip/fs/ntfs.config
Merging configs/rockchip/fs/vfat.config
Merging configs/rockchip/gpu/gpu.config
Merging configs/rockchip/multimedia/audio.config
Merging configs/rockchip/multimedia/camera.config
Merging configs/rockchip/multimedia/gst/audio.config
Merging configs/rockchip/multimedia/gst/camera.config
Merging configs/rockchip/multimedia/gst/rtsp.config
Merging configs/rockchip/multimedia/gst/video.config
Merging configs/rockchip/multimedia/mpp.config
Merging configs/rockchip/wifibt/bt.config
Merging configs/rockchip/wifibt/network.config
Merging configs/rockchip/wifibt/wireless.config
Merging configs/rockchip/benchmark.config
Merging configs/rockchip/chromium.config
Merging configs/rockchip/debug.config
Merging configs/rockchip/npu2.config
Merging configs/rockchip/powermanager.config
Merging configs/rockchip/test.config
Merging configs/rockchip/weston.config
Merging /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/configs/rockchip_rk3588_defconfig
#
# merged configuration written to /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/.config.in (needs make)
#
BR2_DEFCONFIG='' KCONFIG_AUTOCONFIG=/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/build/buildroot-config/auto.conf KCONFIG_AUTOHEADER=/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/build/buildroot-config/autoconf.h KCONFIG_TRISTATE=/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/build/buildroot-config/tristate.config BR2_CONFIG=/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/.config HOST_GCC_VERSION="9" BASE_DIR=/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588 SKIP_LEGACY= CUSTOM_KERNEL_VERSION="5.10" BR2_DEFCONFIG=/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/configs/rockchip_rk3588_defconfig /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/build/buildroot-config/conf --defconfig=/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/.config.in Config.in
#
# configuration written to /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/.config
#
在目录output/rockchip_rk3588
生成.config
文件。
接着我们需要执行make menuconfig
做一些配置。
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make menuconfig
1.3.1 配置Target options
需要配置的项目和其对应的内容如下:
Target options --->
Target Architecture (AArch64 (little endian)) --->
(X) AArch64 (little endian)
( ) AArch64 (big endian)
......
Target Architecture Variant (cortex-A76/A55 big.LITTLE) --->
( ) cortex-A76
(X) cortex-A76/A55 big.LITTLE
......
Floating point strategy (Auto) --->
(X) Auto
( ) VFPv2
......
MMU Page Size (4KB) --->
(X) 4KB
( ) 64KB
Target Binary Format (ELF) --->
(X) ELF
其中:
- 目标架构:
ARM64
; - 目标架构变体:
cortex-A76/A55 big.LITTLE
; - 浮点策略:
Auto
; - 目标二进制格式:
ELF
。
1.3.2 配置Toolchain
Toolchain --->
Toolchain type (Buildroot toolchain) --->
(X) Buildroot toolchain
( ) External toolchain
glibc version (glibc latest) --->
(X) glibc latest
( ) glibc 2.28
.......
这里工具链直接使用toolchain-buildroot
即可,当然也可以用自己的交叉编译器。
1.3.3 配置System configuration
此选项用于设置一些系统配置,比如开发板名字、欢迎语、用户名、密码等。需要配置的项目和其对应的内容如下:
System configuration --->
(rk3588) System hostname // 平台名字
(Welcome to rk3588 Buildroot) System banner // 欢迎语
Passwords encoding (sha-256) --->
(X) sha-256
( ) sha-512
Init system (BusyBox) ---> // 使用 busybox
(X) BusyBox
( ) systemV
......
/dev management (Dynamic using devtmpfs + eudev) ---> // 使用 eudev
( ) Dynamic using devtmpfs + mdev
(X) Dynamic using devtmpfs + eudev
......
[*] Enable root login with password (NEW) // 使能登录密码
(rockchip) Root password // 登录密码
......
1.3.4 配置Filesystem images
此选项配置我们最终制作的根文件系统为什么格式的,配置如下:
Filesystem images --->
[*] cpio the root filesystem (for use as an initial RAM filesystem)
[*] ext2/3/4 root filesystem // 如果是 EMMC 或 SD 卡的话就用 ext3/ext4
ext2/3/4 variant (ext4) ---> // 选择 ext4 格式
......
( ) ext3
(X) ext4
(auto) exact size //ext4 格式根文件系统 可以根据实际情况修改, 也可以设置为auto
[*] squashfs root filesystem
[*] pad to a 4K boundary
Compression algorithm (gzip) --->
(X) gzip
( ) lz4
......
[*] tar the root filesystem
Compression method (no compression) --->
(X) no compression
( ) gzip
......
[ ] ubi image containing an ubifs/squashfs root filesystem // 如果使用 NAND 的话就用 ubifs
[ ] ubifs root filesystem
[ ] yaffs2 root filesystem
......
buildroot
可以直接制作出ext4
格式的根文件系统,但是一般我们会自行往根文件系统里面添加很多其他的文件,所以产品开发完成以后需要自行打包根文件系统,然后烧写到开发板里面。
1.3.5 禁止编译Linux
内核和uboot
buildroot
不仅仅能构建根文件系统,也可以编译linux
内核和uboot
。我们一般都不会使用buildroot
下载的linux
内核和uboot
,因为buildroot
下载的linux
和uboot
官方源码,里面会缺少很多驱动文件,而且最新的linux
内核和uboot
会对编译器版本号有要求,可能导致编译失败。
因此我们需要配置buildroot
,关闭linux
内核和uboot
的编译,只使用buildroot
来构建根文件系统,配置如下:
Kernel --->
[ ] Linux Kernel // 不要选择编译Linux Kernel选项
......
Bootloaders --->
[ ] U-Boot // 不要选择编译U-Boot选项
......
1.3.6 编译Target packages
此选项用于配置要选择的第三方库或软件、比如alsa-utils
、 ffmpeg
、 iperf
等工具,这里我们先只选择内核的模块加载相关软件,配置如下:
Target packages --->
Hardware Platforms --->
[*] Rockchip Platform --->
Rockchip SoC (rk3588) --->
( ) rk3358 chip
(X) rk3588 chip
......
[*] Rockchip Camera Engine For ISP
Rockchip BSP packages ---> // Rockchip板级支持包,很重要
[*] Rockchip Camera Engine 3A service run in booting
Specify a directory to store xml speed up bin (disabled) --->
() Rockchip Camera Engine IQ xml file
[ ] rockchip common algorithm
[*] gstreamer1-rockchip
[*] A rockchip-mpp V4L2 wrapper plugin for chromium V4L2 VDA
[ ] Rockchip NPU power control for linux
[ ] Rockchip NPU power control combine for linux
[ ] rk n4 camera
[ ] Rockchip recovery for linux
[ ] rknpu
[ ] rknpu pcie
[ ] rknpu2
[ ] rknn_demo
[*] rockchip script
() default PCM
[ ] rkscript iodomain notice script
......
[ ] Rockchip rkupdate for linux
[*] rkwifibt
[ ] Enable static
[ ] rkwifibt wireless applicantion
[*] rockchip-alsa-config
[*] rockchip-rga
[*] prefer using rockchip-rga
[*] rockchip-mali
......
[*] wayland winsys
[*] GBM
[*] OpenGL EGL
[*] OpenGL EGL Wayland
[*] OpenGL ES
[*] OpenCL
[ ] Vulkan
[*] rockchip-mpp --->
......
-*- BusyBox
Audio and video applications --->
.......
Compressors and decompressors --->
.......
Filesystem and flash utilities --->
.......
System tools --->
[*] kmod // 使能内核模块相关命令
......
......
上面包含了若干库的配置,但是我们实际上较为关心的就是和硬件驱动相关的库,即Rockchip BSP packages
中的配置项。
Rockchip
提供的这些软件包位于package/rockchip
目录下;
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll package/rockchip/
drwxr-xr-x 2 root root 4096 6月 9 12:58 camera-engine-rkaiq/
drwxr-xr-x 2 root root 4096 6月 9 12:58 camera-engine-rkisp/
drwxr-xr-x 2 root root 4096 6月 9 12:58 common_algorithm/
-rw-r--r-- 1 root root 3908 6月 9 12:58 Config.in
drwxr-xr-x 2 root root 4096 6月 9 12:58 gstreamer1-rockchip/
drwxr-xr-x 2 root root 4096 6月 9 12:58 libv4l-rkmpp/
drwxr-xr-x 2 root root 4096 6月 9 12:58 n4/
drwxr-xr-x 2 root root 4096 6月 9 12:58 npu_powerctrl/
drwxr-xr-x 2 root root 4096 6月 9 12:58 npu_powerctrl_combine/
drwxr-xr-x 2 root root 4096 6月 9 12:58 recovery/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rkadk/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rknn_demo/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rknpu/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rknpu2/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rknpu-fw/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rkscript/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rktoolkit/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rkupdate/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rkwifibt/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rkwifibt-app/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rockchip-alsa-config/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rockchip-mali/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rockchip-mali-nvr/
-rw-r--r-- 1 root root 52 6月 9 12:58 rockchip.mk
drwxr-xr-x 2 root root 4096 6月 9 12:58 rockchip-mpp/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rockchip-rga/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rockchip-test/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rockchip-uac-app/
drwxr-xr-x 2 root root 4096 6月 9 12:58 rockit/
drwxr-xr-x 2 root root 4096 6月 9 12:58 slt_gpu_light/
drwxr-xr-x 3 root root 4096 6月 9 12:58 tee-user-app/
1.3.7 保存配置
和uboot
、 kernel
一样,通过图形化界面配置好buildroot
以后最好保存一下配置项,防止清除工程以后将配置项给删除掉。 buildroot
的默认配置项都保存在configs
目录下,配置完成以后移动到Save
按回车保存到 .config
,移动到 Exit
按回车退出。
接着我们执行如下命令保存配置,可以生成一个新的默认配置文件(defconfig
),这个文件会基于当前配置生成,并且只包含当前确实需要的配置选项,移除了所有未被使用的选项;
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make savedefconfig
将配置文件拷贝到configs
目录:
root@ubuntu:/work/sambashare/rk3588/recovery/buildroot-2024.02.4# cp defconfig ./configs/rockchip_rk3588_defconfig
将修改保存到配置文件 configs/rockchip_rk3588_defconfig
。
1.4 make
命令使用
过make help
可以看到buildroot
下make
的使用细节,包括对package
、uclibc
、busybox
、linux
以及文档生成等配置。
Cleaning:
clean - delete all files created by build
distclean - delete all non-source files (including .config)
Build:
all - make world
toolchain - build toolchain
sdk - build relocatable SDK
reinstall - reinstall all
Configuration:
menuconfig - interactive curses-based configurator
nconfig - interactive ncurses-based configurator
xconfig - interactive Qt-based configurator
gconfig - interactive GTK-based configurator
oldconfig - resolve any unresolved symbols in .config
syncconfig - Same as oldconfig, but quietly, additionally update deps
olddefconfig - Same as syncconfig but sets new symbols to their default value
randconfig - New config with random answer to all options
defconfig - New config with default answer to all options;
BR2_DEFCONFIG, if set on the command line, is used as input
savedefconfig - Save current config to BR2_DEFCONFIG (minimal config)
update-defconfig - Same as savedefconfig, but with fragments
allyesconfig - New config where all options are accepted with yes
allnoconfig - New config where all options are answered with no
alldefconfig - New config where all options are set to default
randpackageconfig - New config with random answer to package options
allyespackageconfig - New config where pkg options are accepted with yes
allnopackageconfig - New config where package options are answered with no
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>-show-info - generate info about <pkg>, as a JSON blurb
<pkg>-show-depends - List packages on which <pkg> depends
<pkg>-show-rdepends - List packages which have <pkg> as a dependency
<pkg>-show-recursive-depends
- Recursively list packages on which <pkg> depends
<pkg>-show-recursive-rdepends
- Recursively list packages which have <pkg> as a dependency
<pkg>-graph-depends - Generate a graph of <pkg>'s dependencies
<pkg>-graph-rdepends - Generate a graph of <pkg>'s reverse 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
<pkg>-reinstall - Restart the build from the install step
busybox:
busybox-menuconfig - Run busybox menuconfig
busybox-xconfig - Run busybox xconfig
busybox-gconfig - Run busybox gconfig
busybox-update-config - Save the busybox configuration as a full .config file
to package/busybox/busybox.config
(or override with BUSYBOX_KCONFIG_FILE)
Documentation:
manual - build manual in all formats
manual-html - build manual in HTML
manual-split-html - build manual in split HTML
manual-pdf - build manual in PDF
manual-text - build manual in text
manual-epub - build manual in ePub
graph-build - generate graphs of the build times
graph-depends - generate graph of the dependency tree
graph-size - generate stats of the filesystem size
list-defconfigs - list all defconfigs (pre-configured minimal systems)
Miscellaneous:
source - download all sources needed for offline-build
external-deps - list external packages used
legal-info - generate info about license compliance
show-info - generate info about packages, as a JSON blurb
pkg-stats - generate info about packages as JSON and HTML
missing-cpe - generate XML snippets for missing CPE identifiers
printvars - dump internal variables selected with VARS=...
make V=0|1 - 0 => quiet build (default), 1 => verbose build
make O=dir - Locate all output files in "dir", including .config
For further details, see README, generate the Buildroot manual, or consult
it on-line at http://buildroot.org/docs.html
1.4.1 busybox
配置
当执行buildroot
编译会自动下载busybox
压缩包, buildroot
下载的源码压缩包都存放在dl
目录下,在dl
目录下就有一个叫做busybox
的文件夹,此目录下保存着busybox
压缩包,如下图所示:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll dl/busybox/
-rw-r--r-- 1 root root 2523487 6月 11 02:44 busybox-1.36.0.tar.bz2
-rw-r--r-- 1 root root 0 6月 11 02:44 .lock
进入busybox
图形化配置界面:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make busybox-menuconfig
此处可以进行busybox
的配置,配置完成后,移动到 Exit
按回车退出,在弹窗页面选择 Yes
保存到 .config
。
保存配置文件:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make busybox-update-config
将修改保存到配置文件 board/rockchip/common/base/busybox.config
。
配置完成后如果我们想单独编译并安装busybox
的话执行下面命令即可:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make busybox
编译完成以后重新编译buildroot
,主要是对其进行打包,输入如下命令:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make -j8
1.4.2 buildroot
编译
配置好buildroot
后,如需编译buildroot
,运行如下命令即可:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make -j8
运行 make
进行编译时,会执行以下过程:
- 下载源码;
- 配置、编译、安装交叉编译工具链;
- 配置、编译、安装选择的软件包;
- 按选择的格式生成根文件系统;
编译大概需要十几个小时,耐心等待。编译完成后,在编译输出目录 output/rockchip_rk3588
会生成子目录,说明如下:
build
: 除了交叉编译的工具链之外的所有组件,包括Buildroot
所需主机工具和选择的软件包,这个目录包含所有软件包源码;host
:包含为主机编译的工具的安装,这些工具是正确执行Buildroot
所必需的,包括交叉编译工具
链;images
:所有镜像(文件系统,比如ext2/4
、squashfs
、cpio
等格式镜像)存储目录;staging
:其中的层次结构类似于根文件系统层次结构。这个目录包含了安装交叉编译工具链和为目标选择的所有用户空间包,但是,这个目录不是用来成为目标的根文件系统:它包含许多开发文件、未剥离的二进制文件和库,这些文件和库也非常多,对嵌入式系统来说是很大的;这些开发文件用于为所依赖的目标提供编译库和应用程序需要的其他库;target
: 几乎包含了目标的完整根文件系统:除了/dev/
目录中的设备文件,所有需要的东西都是存在(Buildroot
不能创建它们,因为Buildroot
不会以root
身份运行,也不希望以root
身份运行)。此外,它没有正确的权限(例如,busybox
二进制文件的setuid
),因此,该目录不应该用于你的目标;相反,您应该使用images/
目录中构建的映像之一;如果你需要在根文件系统中用NFS
挂载外部镜像,必须用root
用户在images/
目录中生成镜像,相比对于staging/
,target/
只包含运行所选目标应用程序所需的文件和库:开发文件(头文件)不存在,二进制文件被剥离。
查看output/rockchip_rk3588
目录:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll output/rockchip_rk3588
-rw-r--r-- 1 root root 82 6月 19 22:39 .br2-external.in.init
-rw-r--r-- 1 root root 82 6月 19 22:39 .br2-external.in.jpeg
-rw-r--r-- 1 root root 82 6月 19 22:39 .br2-external.in.linux
-rw-r--r-- 1 root root 82 6月 19 22:39 .br2-external.in.menus
-rw-r--r-- 1 root root 82 6月 19 22:39 .br2-external.in.openssl
-rw-r--r-- 1 root root 82 6月 19 22:39 .br2-external.in.paths
-rw-r--r-- 1 root root 82 6月 19 22:39 .br2-external.in.skeleton
-rw-r--r-- 1 root root 82 6月 19 22:39 .br2-external.in.toolchains
-rw-r--r-- 1 root root 162 6月 19 22:39 .br2-external.mk
drwxr-xr-x 235 root root 12288 6月 19 22:42 build/
-rw-r--r-- 1 root root 140337 6月 19 22:34 .config
-rw------- 1 root root 8569 6月 19 22:18 .config.in
-rw-r--r-- 1 root root 140337 6月 19 22:30 .config.old
-rw-r--r-- 1 root root 140337 6月 18 00:23 .config.orig
-rw-r--r-- 1 root root 105085 6月 19 22:36 ..config.tmp
drwxr-xr-x 12 root root 4096 6月 18 01:17 host/
drwxr-xr-x 2 root root 4096 6月 19 22:43 images/
-rw-r--r-- 1 root root 681 6月 19 22:36 Makefile
lrwxrwxrwx 1 root root 122 6月 18 01:24 staging -> /work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot/output/rockchip_rk3588/host/aarch64-buildroot-linux-gnu/sysroot/
drwxr-xr-x 19 root root 4096 6月 9 12:58 target/
包含压缩好的根文件系统镜像文件位于 output/rockchip_rk3588/images
目录下;
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll output/rockchip_rk3588/images/
-rw-r--r-- 1 root root 616497664 6月 19 22:42 rootfs.cpio
-rw-r--r-- 1 root root 274253269 6月 19 22:43 rootfs.cpio.gz
-rw-r--r-- 1 root root 763363328 6月 19 22:43 rootfs.ext2
lrwxrwxrwx 1 root root 11 6月 19 22:43 rootfs.ext4 -> rootfs.ext2
-rw-r--r-- 1 root root 275308544 6月 19 22:43 rootfs.squashfs
-rw-r--r-- 1 root root 625326080 6月 19 22:44 rootfs.tar
查看编译好的根文件系统:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll output/rockchip_rk3588/target/
lrwxrwxrwx 1 root root 7 6月 18 00:28 bin -> usr/bin/
-rw-r--r-- 1 root root 489 6月 9 12:58 busybox.fragment
lrwxrwxrwx 1 root root 8 6月 19 22:42 data -> userdata/
drwxr-xr-x 4 root root 4096 6月 9 12:58 dev/
drwxr-xr-x 22 root root 4096 6月 9 12:58 etc/
drwxr-xr-x 2 root root 4096 6月 19 22:42 info/
lrwxrwxrwx 1 root root 7 6月 18 00:28 lib -> usr/lib/
lrwxrwxrwx 1 root root 3 6月 18 00:28 lib64 -> lib/
lrwxrwxrwx 1 root root 11 6月 18 00:49 linuxrc -> bin/busybox*
drwxr-xr-x 11 root root 4096 6月 18 01:18 media/
drwxr-xr-x 5 root root 4096 6月 19 22:42 mnt/
drwxr-xr-x 2 root root 4096 6月 18 01:22 oem/
drwxr-xr-x 3 root root 4096 6月 18 01:18 opt/
drwxr-xr-x 2 root root 4096 6月 9 12:58 proc/
drwxr-xr-x 15 root root 4096 6月 19 22:40 rockchip-test/
drwxr-xr-x 2 root root 4096 6月 9 12:58 root/
drwxr-xr-x 3 root root 4096 6月 18 00:38 run/
lrwxrwxrwx 1 root root 8 6月 18 00:28 sbin -> usr/sbin/
lrwxrwxrwx 1 root root 10 6月 19 22:42 sdcard -> mnt/sdcard/
-rw-r--r-- 1 root root 0 6月 9 12:58 .skip_fsck
drwxr-xr-x 4 root root 4096 6月 18 01:22 sys/
drwxr-xr-x 3 root root 4096 6月 19 22:42 system/
-rw-r--r-- 1 root root 1336 6月 18 00:28 THIS_IS_NOT_YOUR_ROOT_FILESYSTEM
drwxr-xr-x 4 root root 4096 6月 18 01:21 tmp/
lrwxrwxrwx 1 root root 9 6月 19 22:42 udisk -> mnt/udisk/
drwxr-xr-x 2 root root 4096 6月 18 01:22 userdata/
drwxr-xr-x 7 root root 4096 6月 19 22:42 usr/
drwxr-xr-x 5 root root 4096 6月 18 00:51 var/
lrwxrwxrwx 1 root root 6 6月 19 22:42 vendor -> system/
1.4.3 编译目标包
我们可以执行 make <pkg>
单独编译某个软件包。软件包的编译主要包括下载,解压,打补丁,构建依赖,配置,编译,安装等过程,具体可以查看 package/pkg-generic.mk
;
- 下载:
Buildroot
会根据配置package/<package>/<package>.mk
,自动从网络获取对应的软件包,包括一些第三方库,插件,实用工具等,放在dl/
目录; - 解压:软件包会解压在
output/rockchip_rk3588/build/<package>-<version>
目录下; - 打补丁:补丁集中放在
package/<packgae>/
目录,Buildroot
会在解压软件包后为其打上相应的补丁。如果要修改源码,可以通过打补丁的方式进行修改; - 构建依赖:构建和安装构建软件包所需的所有相依性;
- 配置:运行
configure
命令,如果有的话; - 编译:运行编译命令;
- 安装:编译完成后,会将需要的编译生成文件拷贝到
output/rockchip_rk3588/target/
某个目录。
对于某个软件包,我们可以通过 make <pkg>-<target>
调用软件包构建中的某一步骤,如下:
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>-show-info - generate info about <pkg>, as a JSON blurb
<pkg>-show-depends - List packages on which <pkg> depends
<pkg>-show-rdepends - List packages which have <pkg> as a dependency
<pkg>-show-recursive-depends
- Recursively list packages on which <pkg> depends
<pkg>-show-recursive-rdepends
- Recursively list packages which have <pkg> as a dependency
<pkg>-graph-depends - Generate a graph of <pkg>'s dependencies
<pkg>-graph-rdepends - Generate a graph of <pkg>'s reverse 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
<pkg>-reinstall - Restart the build from the install step
可以看到除了之前介绍的,,还有一些其他有用的目标;
show-depends
:显示构建软件包所需的依赖性;clean
:运行软件包的清除命令,也可以从目标和暂存目录中卸载软件;注意,这并不是针对所有包实现的;dirclean
:删除整个包构建目录;reconfigure
:从配置步骤重新启动构建;rebuild
:从构建步骤重新启动构建;reinstall
:从安装步骤重新启动构建。
需要注意的是:在开发过程中,若修改了某个软件包的源码,Buildroot
是不会重新编译该软件包的。可以按如下方式操作:
make <package>-rebuild
# 或者
# 删除软件包的编译输出目录
rm -rf output/rockchip_rk3588/build/<package>-<version>
# 编译
make <pkg>
1.4.4 完全重建
当通过make menuconfig
,make xconfig
或其他配置工具之一更改系统配置时,Buildroot
不会尝试检测应重建系统的哪些部分。
在某些情况下,Buildroot
应该重建整个系统,在某些情况下,仅应重建软件包的特定子集。但是以完全可靠的方式检测到这一点非常困难,因此Buildroot
开发人员已决定不尝试这样做。
何时需要完全重建:
- 更改目标体系结构配置时,需要完全重建;
- 更改工具链配置时,需要完全重建;
- 将其他软件包添加到配置中时,不一定需要完全重建;
- 从配置中删除软件包时,
Buildroot
不会执行任何特殊操作。它不会从目标根文件系统或工具链中删除此软件包安装的文件。需要完全重建才能删除这些文件; - 更改软件包的子选项时,不会自动重建软件包;
- 对根文件系统框架进行更改时,需要完全重建。
一般而言,当你遇到构建错误并且不确定所做的配置更改可能带来的后果时,请进行完全重建。具体说明可以查看文档 docs/manual/rebuilding-packages.txt
。
重建方式有两种:
(1) 直接删除编译输出目录,之后重新进行配置、编译;
rm -rf output/
(2) 执行如下命令,会删除编译输出并重新编译;
make clean all
1.5 交叉编译工具
Buildroot
提供了不同的交叉编译工具链构建解决方案:
- 内部工具链后端,在配置界面中称为
Buildroot
工具链; - 外部工具链后端,在配置界面中称为外部工具链.
注意:Rockchip Linux SDK
默认使用内部工具链。
1.5.1 内部工具链端
内部工具链后端是内置的后端,在构建之前,Buildroot
自己构建了一个交叉编译的工具链。
用于目标嵌入式系统的用户空间应用程序和库,这个后端是Buildroot
的历史后端,并且仅限于uClibc C
库的使用(i.e,glibc
和eglibc C
库不受此后端支持,请参阅外部工具链后端和跨界工具链后端解决方案使用glibc
或eglibc
)。
优点:
- 与
Buildroot
有良好的兼容性; - 快速,只构建必要的东西;
缺点:
- 在进行清洁工作时,需要重建工具链,这需要时间。如果你想减少你的构建时间,考虑使用外部工具链后端;
- 仅限于
uClibc C
库。
Buildroot
编译完成后,会在 output/rockchip_rk3588/host/
目录下,生成交叉编译工具,我们可以用来编译目标程序;
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll output/rockchip_rk3588/host/
drwxr-xr-x 7 root root 4096 6月 18 00:37 aarch64-buildroot-linux-gnu/
drwxr-xr-x 2 root root 12288 6月 18 01:21 bin/
drwxr-xr-x 3 root root 4096 6月 18 00:26 doc/
-rw-r--r-- 1 root root 3100 6月 18 00:52 environment-setup
drwxr-xr-x 5 root root 4096 6月 18 01:21 etc/
drwxr-xr-x 33 root root 4096 6月 18 01:21 include/
drwxr-xr-x 14 root root 12288 6月 18 01:21 lib/
lrwxrwxrwx 1 root root 3 6月 18 00:18 lib64 -> lib/
drwxr-xr-x 5 root root 4096 6月 18 01:20 libexec/
drwxr-xr-x 3 root root 4096 6月 18 01:17 man/
drwxr-xr-x 2 root root 4096 6月 18 01:07 sbin/
drwxr-xr-x 35 root root 4096 6月 18 01:20 share/
lrwxrwxrwx 1 root root 1 6月 18 00:18 usr -> ./
交叉编译工具为bin
目录;
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ls output/rockchip_rk3588/host/bin/ | grep aarch64
aarch64-buildroot-linux-gnu-addr2line
aarch64-buildroot-linux-gnu-ar
aarch64-buildroot-linux-gnu-as
aarch64-buildroot-linux-gnu-c++
aarch64-buildroot-linux-gnu-c++.br_real
aarch64-buildroot-linux-gnu-cc
aarch64-buildroot-linux-gnu-cc.br_real
aarch64-buildroot-linux-gnu-c++filt
........
aarch64-linux-addr2line
aarch64-linux-ar
aarch64-linux-as
aarch64-linux-c++
aarch64-linux-c++.br_real
aarch64-linux-cc
aarch64-linux-cc.br_real
........
输入命令查看:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ./output/rockchip_rk3588/host/bin/aarch64-linux-gcc --version
aarch64-linux-gcc.br_real (Buildroot -g28f720bc5-dirty) 12.3.0
Copyright © 2022 Free Software Foundation, Inc.
接下来我们演示一个编译示例程序,简单的编写一个helloworld.c
文件:
#include <stdio.h>
void main(void)
{
printf("Hello world.\n");
}
进行编译:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo ./output/rockchip_rk3588/host/bin/aarch64-buildroot-linux-gnu-gcc helloworld.c -o helloworld
将可执行程序helloworld
拷贝到开发板,运行./helloworld
,则会看到打印信息 Hello World.
。
1.5.2 外部工具链端
外部工具链后端允许使用现有的预构建交叉编译工具链。Buildroot
能识别几种常见的交叉编译工具链(从ARM
的Linaro
,ARM
的Sourcery CodeBench
,x86
,x86-64
,PowerPC
,MIPS
和SuperH
,来自ADI
的Blackfin
工具链, Xilinx
用于Microblaze
的工具链,等等。) 并且能够自动下载它们,或者它可以指向一个自定义的工具链,可以在本地下载或安装。
优点:
- 允许使用知名的、经过良好测试的交叉编译工具链;
- 避免交叉编译工具链的构建时间,这在嵌入式
Linux
系统的总体构建时间中通常非常重要; - 不局限于
uClibc:glibc
和eglibc
工具链得到了支持;
缺点:
- 如果你的预构建的外部工具链有缺陷,可能很难从工具链供应商那里得到解决方案,除非你构建外部工具使用交叉的工具链。
Rockchip Linux SDK
目录内置交叉编译,当Buildroot
外部工具链使用Rockchip Linux SDK prebuilts
目录预置交叉编译,如下:
目录 | 说明 |
---|---|
prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-nonelinux- gnu |
gcc arm 10.3.1 64位工具链 |
prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linuxgnueabihf | gcc arm 10.3.1 32位工具链 |
对应版本:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp# prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc -v
......
gcc 版本 10.3.1 20210621 (GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29))
1.6 rootfs-overlay
rootfs-overly
是一个相当不错的功能,它能够在目标文件系统编译完成后将指定文件覆盖到某个目录。
通过这种方式,我们可以方便地添加或修改一些文件到根文件系统。
假设我们要在根文件系统的 /etc/
目录下添加文件 overlay-test
,可以按如下步骤操作:
1.6.1 设置rootfs-overlay
根目录
打开配置菜单 make menuconfig
,通过设置 BR2_ROOTFS_OVERLAY
选项,添加用于覆盖的根目录。
对于rk3588
,默认已添加了目录 board/rockchip/rk3588/fs-overlay/
;
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll board/rockchip/rk3588/fs-overlay/
-rw-r--r-- 1 root root 0 6月 9 12:58 .empty
drwxr-xr-x 3 root root 4096 6月 9 12:58 etc/
-rw-r--r-- 1 root root 0 6月 9 12:58 .skip_fsck
drwxr-xr-x 3 root root 4096 6月 9 12:58 usr/
1.6.2 添加文件到覆盖目录
我们可以执行如下命令:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ cd board/rockchip/rk3288/fs-overlay/
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ mkdir etc/
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ touch etc/overlay-test
1.6.3 编译根文件系统
执行如下命令:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make -j8
1.6.4 下载根文件系统
将编译好的根文件系统 output/rockchip_rk3588/images/rootfs.ext2
下载到开发板。
启动开发板,可以看到已添加文件 /etc/overlay-test
。
也可以通过查看 target/
目录,验证是否添加成功:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ ll output/rockchip_rk3588/target/etc/overlay-test
二、新增本地源码包
开发过程中,Buildroot
自带的软件包有时可能无法满足我们的需求,为此我们需要添加自定义的软件包。
Buildroot
支持多种格式的软件包,包括generic-package
、cmake-package
、autotools-package
等,我们以generic-package
举例说明。
要添加自己的本地源码包,:
- 首先创建工程目录,比如这里演示使用的
helloworld
目录; - 接着
helloworld
里面添加Config.in
和helloworld.mk
; - 最后在
package/Config.in
中添加指向新增helloworld
目录的Config.in
。
2.1 创建工程目录
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo mkdir package/helloworld
2.2 helloworld
目录
2.2.1 Config.in
在helloworld
目录新建Config.in
,内容如下:
config BR2_PACKAGE_HELLOWORLD
bool "helloworld"
help
This is a demo to add local app.
只有在BR2_PACKAGE_HELLOWORLD=y
条件下,才会调用helloworld.mk
进行编译。
2.2.2 helloworld.mk
buildroot
编译helloworld
所需要的设置helloworld.mk
,包括源码位置、安装目录、权限设置等。
在helloworld
目录新建helloworld.mk
,内容如下:
################################################################################
#
# helloworld
#
################################################################################
ifeq ($(BR2_PACKAGE_HELLOWORLD), y)
HELLOWORLD_VERSION:=1.0.0
HELLOWORLD_SITE=$(TOPDIR)/../external/helloworld
HELLOWORLD_SITE_METHOD=local
define HELLOWORLD_BUILD_CMDS
$(TARGET_MAKE_ENV) $(MAKE) CC=$(TARGET_CC) CXX=$(TARGET_CXX) -C $(@D)
endef
define HELLOWORLD_CLEAN_CMDS
$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) clean
endef
define HELLOWORLD_INSTALL_TARGET_CMDS
$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install
endef
define HELLOWORLD_UNINSTALL_TARGET_CMDS
$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) uninstall
endef
$(eval $(generic-package))
endif
注意:上面的HELLOWORLD
的开头也是必须的。
如果源码在git
上,需要如下设置:
HELLOWORLD_VERSION:=master--------------------------------------仓库分支名称
HELLOWORLD_SITE:=http://.../dma.git-----------------------------仓库git地址
HELLOWORLD_SITE_METHOD:=git-------------------------------------获取源码的方式
_VERSION
结尾的变量是源码的版本号;_SITE_METHOD
结尾的变量是源码下载方法;_SITE
结尾变量是源码下载地址。
_BUILD_CMDS
结尾的变量会在buildroot
框架编译的时候执行,用于给源码的Makefile
传递编译选项和链接选项,调用源码的Makefile
。
_INSTALL_TARGET_CMDS
结尾的变量是在编译完之后,自动安装执行,一般是让buildroot
把编译出来的的bin
或lib
拷贝到指定目录。
(eval(generic-package
)) 最核心的就是这个东西了,一定不能够漏了,不然源码不会被编译,这个函数就是把整个.mk
构建脚本,通过Buildroot
框架的方式,展开到Buildroot/
目录下的Makfile
中,生成的构建目标。
2.2.3 创建源码目录
上文的helloworld.mk
文件里已经指定了源码目录 external/helloworld
。
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp$ sudo mkdir -p external/helloworld
在external/helloworld
目录下简单的编写一个helloworld.c
文件:
#include <stdio.h>
void main(void)
{
printf("Hello world.\n");
}
然后编写Makefile
文件:
CPPFLAGS +=
LDLIBS +=
all: helloworld
analyzestack: helloworld.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
clean:
rm -f *.o helloworld
.PHONY: install
install:
cp -f helloworld $(TARGET_DIR)/usr/bin/
.PHONY: uninstall
uninstall:
rm -f $(TARGET_DIR)/usr/bin/helloworld
.PHONY: all clean
由于在helloworld.mk
中指定了命令CLEAN
、INSTALL
、UNINSTALL
,因此这里需要配置目标install
、clean
、uninstall
。
2.2.4 添加package/Config.in
入口
在 package/Config.in
末尾添加一行:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo vim package/Config.in
menu "Target packages"
......
menu "Private package"
source "package/helloworld/Config.in"
endmenu
endmenu
2.3 配置软件包
打开配置菜单 :
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make menuconfig
通过Target packages
-> Private package
进入,选中helloworld
。
保存配置:
root@ubuntu:/work/sambashare/rk3588/armsom/armsom-rk3588-bsp/buildroot$ sudo make savedefconfig
对helloworld
的配置就会保存到rockchip_rk3588_defconfig
中;
BR2_PACKAGE_HELLOWORLD=y
亲爱的读者和支持者们,自动博客加入了打赏功能,陆陆续续收到了各位老铁的打赏。在此,我想由衷地感谢每一位对我们博客的支持和打赏。你们的慷慨与支持,是我们前行的动力与源泉。
日期 | 姓名 | 金额 |
---|---|---|
2023-09-06 | *源 | 19 |
2023-09-11 | *朝科 | 88 |
2023-09-21 | *号 | 5 |
2023-09-16 | *真 | 60 |
2023-10-26 | *通 | 9.9 |
2023-11-04 | *慎 | 0.66 |
2023-11-24 | *恩 | 0.01 |
2023-12-30 | I*B | 1 |
2024-01-28 | *兴 | 20 |
2024-02-01 | QYing | 20 |
2024-02-11 | *督 | 6 |
2024-02-18 | 一*x | 1 |
2024-02-20 | c*l | 18.88 |
2024-01-01 | *I | 5 |
2024-04-08 | *程 | 150 |
2024-04-18 | *超 | 20 |
2024-04-26 | .*V | 30 |
2024-05-08 | D*W | 5 |
2024-05-29 | *辉 | 20 |
2024-05-30 | *雄 | 10 |
2024-06-08 | *: | 10 |
2024-06-23 | 小狮子 | 666 |
2024-06-28 | *s | 6.66 |
2024-06-29 | *炼 | 1 |
2024-06-30 | *! | 1 |
2024-07-08 | *方 | 20 |
2024-07-18 | A*1 | 6.66 |
2024-07-31 | *北 | 12 |
2024-08-13 | *基 | 1 |
2024-08-23 | n*s | 2 |
2024-09-02 | *源 | 50 |
2024-09-04 | *J | 2 |
2024-09-06 | *强 | 8.8 |
2024-09-09 | *波 | 1 |
2024-09-10 | *口 | 1 |
2024-09-10 | *波 | 1 |
2024-09-12 | *波 | 10 |
2024-09-18 | *明 | 1.68 |
2024-09-26 | B*h | 10 |
2024-09-30 | 岁 | 10 |
2024-10-02 | M*i | 1 |
2024-10-14 | *朋 | 10 |
2024-10-22 | *海 | 10 |
2024-10-23 | *南 | 10 |
2024-10-26 | *节 | 6.66 |
2024-10-27 | *o | 5 |
2024-10-28 | W*F | 6.66 |
2024-10-29 | R*n | 6.66 |
2024-11-02 | *球 | 6 |
2024-11-021 | *鑫 | 6.66 |
2024-11-25 | *沙 | 5 |
2024-11-29 | C*n | 2.88 |

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-06-19 Java基础 -- 数组