buildroot详解和分析

原文地址::buildroot详解和分析_Alex-wu的博客-CSDN博客_buildroot

相关文章

1、认识Buildroot----认识Buildroot_就是个linux工程师的博客-CSDN博客_buildroot 

2、Buildroot 嵌入式 Linux 系统生成工具 ----Buildroot首页、文档和下载 - 嵌入式Linux系统生成工具 - OSCHINA - 中文开源技术交流社区

 buildroot是Linux平台上一个构建嵌入式Linux系统的框架。
  整个Buildroot是由Makefile脚本和Kconfig配置文件构成的。
  可以和编译Linux内核一样,通过buildroot配置,menuconfig修改,编译出一个完整的可以直接烧写到机器上运行的Linux系统软件(包含boot、kernel、rootfs以及rootfs中的各种库和应用程序)。
  buildboot也可以单独通过配置和使用交叉编译链工具来实现制作一个Linux文件系统。

buildroot准备工作
  下载地址: http://buildroot.uclibc.org/download.html(官网) ,
       https://github.com/buildroot/buildroot(github) 。
   硬件支持: Linux系统的电脑或者装有Linux虚拟机的电脑 。

   解压过程:

选择好相应的目录,将下载的压缩包放置在其下
解压:tar -xzvf buildroot-2017.02.9.tar.gz
   大致使用流程:

选择一个defconfig;
根据需要配置buildroot;
编译buildroot;
在目标板上运行buildroot构建的系统。
buildroot目录介绍
  解压之后,我们可以看到以下的目录情况:

├── arch:   存放CPU架构相关的配置脚本,如arm/mips/x86,这些CPU相关的配置,在制作工具链时,编译uboot和kernel时很关键.
├── board   存放了一些默认开发板的配置补丁之类的
├── boot
├── CHANGES
├── Config.in
├── Config.in.legacy
├── configs:  放置开发板的一些配置参数. 
├── COPYING
├── DEVELOPERS
├── dl:       存放下载的源代码及应用软件的压缩包. 
├── docs:     存放相关的参考文档. 
├── fs:       放各种文件系统的源代码. 
├── linux:    存放着Linux kernel的自动构建脚本. 
├── Makefile
├── Makefile.legacy
├── output: 是编译出来的输出文件夹. 
│   ├── build: 存放解压后的各种软件包编译完成后的现场.
│   ├── host: 存放着制作好的编译工具链,如gcc、arm-linux-gcc等工具.
│   ├── images: 存放着编译好的uboot.bin, zImage, rootfs等镜像文件,可烧写到板子里, 让linux系统跑起来.
│   ├── staging
│   └── target: 用来制作rootfs文件系统,里面放着Linux系统基本的目录结构,以及编译好的应用库和bin可执行文件. (buildroot根据用户配置把.ko .so .bin文件安装到对应的目录下去,根据用户的配置安装指定位置)
├── package:下面放着应用软件的配置文件,每个应用软件的配置文件有Config.in和soft_name.mk,其中soft_name.mk(这种其实就Makefile脚本的自动构建脚本)文件可以去下载应用软件的包。
├── README
├── support
├── system
└── toolchain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
buildroot配置
  通过make xxx_defconfig来选择一个defconfig,这个文件在config目录下。

  然后通过make menuconfig进行配置:

Target options  --->选择目标板架构特性。
Build options  --->配置编译选项。
Toolchain  ---> 配置交叉工具链,使用buildroot工具链还是外部提供。
System configuration  --->  系统配置
Kernel  ---> 配置内核
Target packages  ---> 
Filesystem images  --->配置文件系统
Bootloaders  --->硬件启动程序
Host utilities  --->
Legacy config options  --->
1
2
3
4
5
6
7
8
9
10
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
buildroot工作原理
  Buildroot原则上是一个自动构建框架,虽然说u-boot、linux kernel这些经典的开源软件包的构建脚本,官方社区都在帮你实现了,但是有时候你还是需要加入你自己特有的app_pkg软件包,用以构建自己的应用。

  buildroot的编译流程是先从dl/xxx.tar下解压出源码到output/build/xxx,然后它利用本身的配置文件(如果有的话)覆盖output/build/xxx下的配置文件,在开始编译连接完成后安装到output/相应文件夹下。

  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/packages里面有丰富的应用软件的配置文件,可以通过make menuconfig,出现图形化界面进行选择丰富的开源软件包的编译和构建。
  对buildroot的配置通过Config.in串联起来,起点在根目录Config.in中:

配置选项    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
配置Kernel内核
  对Linux内核的配置包括两部分:通过make menuconfig进入Kernel对内核进行选择,通过make linux-menuconfig对内核内部进行配置。

内核配置
  进入buildroot目录,输入make menuconfig,选然后选择Kernel进行配置,如图:


“Kernel version”选择内核的版本;
“Defconfig name”选择内核config文件;
“Kernel binary formant”选择内核格式;
“Device tree source file names”选择DT文件;
“Linux Kernel Tools”中选择内核自带的工具,比如perf;
可以选择“Custom Git repository”来指定自己的Git库,在“Custom repository version”中指定branch名称。
选择“Using an in-tree defconfig file”,在“Defconfig name”中输入defconfig名称,注意不需要末尾_defconfig。
选择“Use a device tree present in the kernel”,在“Device Tree Source file names”中输入dts名称,不需要.dts扩展名。
“Kernel binary format”可以选择vmlinux或者uImage。
uImage是uboot专用的映像文件,它是在zImage之前加上一个长度为64字节的“头”,说明这个内核的版本、加载位置、生成时间、大小等信息;其0x40之后与zImage没区别。
zImage是ARM Linux常用的一种压缩映像文件,uImage是U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的“头”,说明这个映像文件的类型、加载位置、生成时间、大小等信息。
vmlinux编译出来的最原始的内核elf文件,未压缩。
zImage是vmlinux经过objcopy gzip压缩后的文件, objcopy实现由vmlinux的elf文件拷贝成纯二进制数据文件。
uImage是U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的tag。
选择vmlinux和uImage的区别在于:
   PATH="/bin..." 
   BR_BINARIES_DIR=/home/.../output/images /usr/bin/make -j9 
   HOSTCC="/usr/bin/gcc" 
   HOSTCFLAGS="" 
   ARCH=csky 
   INSTALL_MOD_PATH=/home/.../output/target 
   CROSS_COMPILE="/home/.../output/host/bin/csky-abiv2-linux-" 
   DEPMOD=/home/.../output/host/sbin/depmod 
   INSTALL_MOD_STRIP=1 -C /home/.../linux uImage
1
2
3
4
5
6
7
8
9
  如果是vmlinux,在结尾就是vmlinux。

内核内部配置
  通过make linux-menuconfig可以对内核内部细节进行配置。
  让Linux内核带符号表:

    CONFIG_COMPILE_TEST is not set
    CONFIG_DEBUG_INFO=y
1
2
配置文件系统
对目标板文件系统内容进行配置主要通过make menuconfig进入Target packages进行。
在Filesystem images中配置文件系统采用的格式,以及是否使用RAM fs。
配置Uboot
  使用uboot作为bootloader,需要进行一些配置。
  在选中U-boot作为bootloader之后,会弹出一系列相关配置。

“U-Boot board name”配置configs的defconfig名称。
“U-Boot Version”选择Custom Git repository,然后在“URL of custom repository”中选择自己的git地址,并在“Custom repository version”中选择git的分支。
在“U-Boot binary format”中选择想要输出的image格式,比如u-boot.img或者u-image.bin。
还可以选择“Intall U-Boot SPL binary image”,选择合适的SPL。

————————————————
版权声明:本文为CSDN博主「Alex-wu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/baidu_38661691/article/details/94732843

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值