0.下载buildroot
Buildroot版本每2个月,2月,5月,8月和11月发布一次。版本号的格式为YYYY.MM,例如2013.02、2014.08。
可以从http://buildroot.org/downloads/获得发行包。
如果要在Linux或Mac Os X上设置隔离的buildroot环境,请将此行粘贴到终端上:
curl -O https://buildroot.org/downloads/Vagrantfile
buildroot目录结构
解压buildroot源码目录如下:
...
编译出的output输出目录介绍:
images/存储所有映像(内核映像,引导加载程序和根文件系统映像)的位置。这些是您需要放在目标系统上的文件。
build/构建所有组件的位置(包括主机上Buildroot所需的工具和针对目标编译的软件包)。该目录为每个组件包含一个子目录。
host/包含为主机构建的工具和目标工具链。
staging/是到内部目标工具链host/的符号链接
target/它几乎包含了目标的完整根文件系统。除了设备文件/dev/(Buildroot无法创建它们,因为Buildroot不能以root身份运行并且不想以root身份运行)之外,所需的一切都存在。
工具链
Buildroot为交叉编译工具链提供了两种解决方案:
- 内部工具链,称为Buildroot toolchain在配置接口。
- 外部工具链External toolchain。
1.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
Configuration:
menuconfig - interactive curses-based configurator--------------------------------对整个buildroot进行配置
savedefconfig - Save current config to BR2_DEFCONFIG (minimal config)----------------保存menuconfig的配置
Package-specific:-------------------------------------------------------------------------------对package配置
<pkg> - Build and install <pkg> and all its dependencies---------------------单独编译对应APP
<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-depends - List packages on which <pkg> depends
<pkg>-show-rdepends - 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-----------------------------------------清除对应APP的编译目录
<pkg>-reconfigure - Restart the build from the configure step
<pkg>-rebuild - Restart the build from the build step--------------------------------单独重新编译对应APP
busybox:
busybox-menuconfig - Run BusyBox menuconfig
uclibc:
uclibc-menuconfig - Run uClibc menuconfig
linux:
linux-menuconfig - Run Linux kernel menuconfig-----------------------------------------配置Linux并保存设置
linux-savedefconfig - Run Linux kernel savedefconfig
linux-update-defconfig - Save the Linux configuration to the path specified
by BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE
Documentation:
manual - build manual in all formats
manual-pdf - build manual in PDF
graph-build - generate graphs of the build times----------------------------------对编译时间、编译依赖、文件系统大小生成图标
graph-depends - generate graph of the dependency tree
graph-size - generate stats of the filesystem size
make menuconfig(make linux-menuconfig, make uboot-menuconfig, make busybox-menuconfig):进行图形化配置
make:编译
make命令通常将执行以下步骤:
- 下载源文件(根据需要);
- 配置、构建和安装交叉编译工具链,或仅导入外部工具链;
- 配置、构建和安装选定的目标软件包;
- 构建内核映像(如果选择);
- 构建引导加载程序映像(如果选择);
- 以选定的格式创建一个根文件系统
make clean:delete all build products (including build directories, host, staging and target trees, the images and the toolchain)
make distclean: 等于make clean+删除配置
2.buildroot框架
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文件,已经帮你自动实现了下载、解压、依赖包下载编译等一系列机械化的流程。
你只要需要按照格式写app_pkg.mk,填充下载地址,链接依赖库的名字等一些特有的构建细节即可。 总而言之,Buildroot本身提供构建流程的框架,开发者按照格式写脚本,提供必要的构建细节,配置整个系统,最后自动构建出你的系统。
3.添加自己的APP
要添加自己的本地APP, 首先在package/Config.in中添加指向新增APP目录的Config.in;
然后在package中新增目录helloworld,并在里面添加Config.in和helloworld.mk;
最后添加对应的helloworld目录。
3.1添加package/Config.in入口
添加如下语句:
menu "Private package"
source "package/helloworld/Config.in"
系统在make menuconfig的时候就可以找到对应的APP的Config.in,如果在make menuconfig的时候选中helloworld,在make savedefconfig的时候就会打开BR2_PACKAGE_HELLOWORLD=y。
3.2配置APP对应的Config.in和mk文件
在package中新增目录helloworld,并在里面添加Config.in和helloworld.mk
1)Config.in
config BR2_PACKAGE_HELLOWORLD
bool "helloworld"
help
This is a demo to add yourself app.
helloworld/Config.in文件,通过make menuconfig可以对helloworld进行选择。只有在BR2_PACKAGE_HELLOWORLD=y条件下,才会调用helloworld.mk进行编译
2)helloworld.mk
################################################################################
#
# helloworld
#
################################################################################
HELLOWORLD_VERSION:= 1.0.0
HELLOWORLD_SITE:= $(CURDIR)/work/helloworld
HELLOWORLD_SITE_METHOD:=local
HELLOWORLD_INSTALL_TARGET:=YES
define HELLOWORLD_BUILD_CMDS
$(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D) all
endef
define HELLOWORLD_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(@D)/helloworld $(TARGET_DIR)/bin
endef
define HELLOWORLD_PERMISSIONS
/bin/helloworld f 4755 0 0 - - - - -
endef
$(eval $(generic-package))
helloworld.mk包括源码位置、安装目录、权限设置等。
3.3编写APP源码和Makefile
3.4通过make menuconfig选中APP
通过Target packages -> Private package进入,选中helloworld。
然后make savedefconfig,对helloworld的配置就会保存到xxx_defconfig中.
3.4编译APP
可以和整个平台一起编译APP;或者make helloworld单独编译。
这两个文件在选中此APP之后,都会被拷贝到output/build/helloworld-1.0.0文件夹中。
然后生成的bin文件拷贝到output/target/bin/helloworld,这个文件会打包到文件系统中。
如果需要清空相应的源文件,通过make helloworld-dirclean。
4如何重新编译软件包
经过第一次完整编译后,如果我们需要对源码包重新配置,我们不能直接在buildroot上的根目录下直接make,buildroot是不知道你已经对源码进行重新配置,它只会将第一次编译出来的文件,再次打包成根文件系统镜像文件。
那么可以通过以下2种方式重新编译:
直接删除源码包,然后make all
例如我们要重新编译helloworld,那么可以直接删除output/build/helloworld目录,那么当你make的时候,就会自动从dl文件夹下,解压缩源码包,并重新安装。这种效率偏低
进行xxx-rebuild,然后make all
也是以helloworld为例子,我们直接输入make helloworld-rebuild,即可对build/helloworld/目录进行重新编译,然后还要进行make all(或者make world 或者 make target-post-image)
如果要重新配置编译安装:
make <package>-reconfigure; make all
5.单独生成目标(build out of tree)
make O=/tmp/build