【Buildroot】基础知识:目录、根文件系统目录覆盖、编译性能分析(编译时间、目标尺寸、包依赖图)


buildroot官方教程
buildroot使用介绍

Buildroot官网上可以下载发布版
国内的SOC厂商Rockchip就是在Buildroot的基础上开发的SDK,类似BSP版本的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。
├── README
├── support
├── system
└── toolchain

二、Finalizing target

在buildroot编译的末期,需要对编译结果进行一些检查或者其他操作。

buildroot预留了两个接口:

  • BR2_ROOTFS_OVERLAY:指向一个目录,此目录下的所有文件将会覆盖到output/target下。比如一些配置文件,或者预编译的库等可以在此阶段处理。

  • BR2_ROOTFS_POST_BUILD_SCRIPT:一个脚本,更加复杂的对文件进行删除、重命名、strip等等功能。

  • BR2_ROOTFS_POST_IMAGE_SCRIPT:对最终生成的images进行打包处理等。

2.1 fs overlay

在文件系统构建过程中,有些应用或者配置不通过编译,直接采取拷贝的方式集成到rootfs中,可以设置“System configuration”->“Root filesystem overlay directories”。
比如下面就是RV1126的rootfs_overlay配置信息:
在这里插入图片描述
在这里插入图片描述
sdk/buildroot/configs/rockchip_rv1126_rv1109_facial_gate_defconfig文件对于rootfs overlay的描述。

在这里插入图片描述
这里涉及到五个文件,而这些文件都会在buildroot编译成功后拷贝到buildroot/output/xxx/build/target/的文件系统里面去替换里面原有的或没有的目录。

board/rockchip/rv1126_rv1109/fs-overlay-facial/ 
board/rockchip/rv1126_rv1109/fs-overlay-sysv/
board/rockchip/rv1126_rv1109/fs-overlay/
board/rockchip/common/base 
board/rockchip/common/wifi

设置的目录中的内容,会对output/target进行覆盖。

相关处理在Makefile中如下:

@$(foreach d, $(call qstrip,$(BR2_ROOTFS_OVERLAY)), \
    $(call MESSAGE,"Copying overlay $(d)"); \
    rsync -a --ignore-times --keep-dirlinks $(RSYNC_VCS_EXCLUSIONS) \
        --chmod=u=rwX,go=rX --exclude .empty --exclude '*~' \
        $(d)/ $(TARGET_DIR)$(sep))

2.2 post build

除了fs overlay这种方式,buildroot还提供了一个脚本进行更加复杂的处理。

可以进行文件删除、重命名,甚至对带调试信息的文件进行strip等。

@$(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_BUILD_SCRIPT)), \
        $(call MESSAGE,"Executing post-build script $(s)"); \
        $(EXTRA_ENV) $(s) $(TARGET_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))

在这里插入图片描述post.sh

#!/bin/bash

BUILDROOT=$(pwd)
TARGET=$1
NAME=$(whoami)
HOST=$(hostname)
DATETIME=`date +"%Y-%m-%d %H:%M:%S"`
if [[ $RK_ROOTFS_TYPE -eq "squashfs" ]]; then
	echo "# rootfs type is $RK_ROOTFS_TYPE, create ssh keys to $(pwd)/output/$RK_CFG_BUILDROOT/target/etc/ssh"
	ssh-keygen -A -f $(pwd)/output/$RK_CFG_BUILDROOT/target
fi
echo "built by $NAME on $HOST at $DATETIME" > $TARGET/timestamp
exit 0

2.3 post image

post image在post build之后,更倾向于生成完整的release文件。包括进行一些images打包、debug文件打包等等。

.PHONY: target-post-image
target-post-image: $(TARGETS_ROOTFS) target-finalize
    @$(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_IMAGE_SCRIPT)), \
        $(call MESSAGE,"Executing post-image script $(s)"); \
        $(EXTRA_ENV) $(s) $(BINARIES_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))

一个范例如下,对images文件进行打包操作。

#!/bin/sh
set -x -e

IMG_DIR=output/images
DEBUG_DIR=${IMG_DIR}/debug
KERNEL_DIR=output/build/linux-master

ROOTFS_CPIO=${IMG_DIR}/rootfs.cpio
KERNEL_IMAGE=${IMG_DIR}/uImage
SPL_IMAGE=${IMG_DIR}/u-boot-spl-bh.bin
UBOOT_IMAGE=${IMG_DIR}/u-boot.bin

IMG_TAR=images.tar.gz
DEBUG_TAR=debug.tar.gz
IMG_MD5=images.md5

rm -f ${IMG_TAR} ${DEBUG_TAR} ${IMG_MD5}

mkdir -p ${DEBUG_DIR}
cp -a ${KERNEL_DIR}/vmlinux ${KERNEL_DIR}/System.map ${ROOTFS_CPIO} ${DEBUG_DIR}/

tar -czf ${IMG_TAR} ${KERNEL_IMAGE} ${SPL_IMAGE} ${UBOOT_IMAGE}
tar -czf ${DEBUG_TAR} -C ${IMG_DIR} debug/

md5sum ${IMG_TAR} > ${IMG_MD5}

三、编译性能

需要安装:

sudo apt-get install python-matplotlib python-numpy

使用命令make help

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)

还可以使用的命令:

  • make graph-build
  • make graph-depends
  • make graph-size
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)

3.1 编译耗时

使用命令:make graph-build
RV1126在SDK根目录执行make graph-build会生成如下文件:

liefyuan@ubuntu:~/rv1126/rp_rv1126_sdk$ make graph-build
umask 0022 && make -C /home/liefyuan/rv1126/rp_rv1126_sdk/buildroot O=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate graph-build
./support/scripts/graph-build-time --type=histogram --order=name --input=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/build/build-time.log --output=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/graphs/build.hist-name.pdf 
./support/scripts/graph-build-time --type=histogram --order=build --input=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/build/build-time.log --output=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/graphs/build.hist-build.pdf 
./support/scripts/graph-build-time --type=histogram --order=duration --input=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/build/build-time.log --output=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/graphs/build.hist-duration.pdf 
./support/scripts/graph-build-time --type=pie-packages --input=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/build/build-time.log --output=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/graphs/build.pie-packages.pdf 
./support/scripts/graph-build-time --type=pie-steps --input=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/build/build-time.log --output=/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/graphs/build.pie-steps.pdf 

生成的文件目录在:

/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/graphs/

在这里插入图片描述
其中比较有参考意义的文件是build.hist-duration.pdf文件,按照耗时从大到小排列。

通过此图可以明白整个编译流程时间都耗在哪里,针对性进行分析优化,有利于提高编译效率。
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

3.2 编译依赖关系

命令:make graph-depends
这需要安装graphviz

sudo apt-get install graphviz

生成的文件地址还是在:

/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/graphs/

graph-depends.pdf
在这里插入图片描述比较复杂!

3.3 编译结果尺寸分析

命令:make graph-size
生成的文件地址还是在:

/home/liefyuan/rv1126/rp_rv1126_sdk/buildroot/output/rockchip_rv1126_rv1109_facial_gate/graphs/

graph-size.pdf
在这里插入图片描述
另外更有参考意义的是file-size-stats.csv和package-size-stats.csv文件

3.4 其他文件

file-size-stats.csv文件的部分内容:

在这里插入图片描述
package-size-stats.csv文件的部分内容:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值