近期在看buildroot manual文档,发现有个章节“Chapter 21. Debugging Buildroot”,里面提到了可以对buildroot编译各阶段加入想要的操作。
但是网上找了下,没有发现有相关案例,打算实操下
Debugging Buildroot官方说明 Debugging Buildroot
It is possible to instrument the steps Buildroot does when building packages. Define the variable BR2_INSTRUMENTATION_SCRIPTS to contain the path of one or more scripts (or other executables), in a space-separated list, you want called before and after each step. The scripts are called in sequence, with three parameters:
start or end to denote the start (resp. the end) of a step;
the name of the step about to be started, or which just ended;
the name of the package.
For example :
1 make BR2_INSTRUMENTATION_SCRIPTS="/path/to/my/script1 /path/to/my/script2"
The list of steps is:
extract
patch
configure
build
install-host, when a host-package is installed in $(HOST_DIR)
install-target, when a target-package is installed in $(TARGET_DIR)
install-staging, when a target-package is installed in $(STAGING_DIR)
install-image, when a target-package installs files in $(BINARIES_DIR)
The script has access to the following variables:
BR2_CONFIG: the path to the Buildroot .config file
HOST_DIR, STAGING_DIR, TARGET_DIR: see Section 18.6.2, “generic-package reference”
BUILD_DIR: the directory where packages are extracted and built
BINARIES_DIR: the place where all binary files (aka images) are stored
BASE_DIR: the base output directory
简单来说,在执行make时,可以加入BR2_INSTRUMENTATION_SCRIPTS参数,该参数可以指定一些脚本(脚本之间用空格区分开)。在编译每个软件包的extract、patch、configure等各阶段的start、end会执行这些脚本,脚本带有3个参数:
参数1,表示每个阶段的start还是end
参数2,表示该阶段的名字
参数3,表示软件包的名字
另外脚本中还可以调用BR2_CONFIG、HOST_DIR、BUILD_DIR等变量。
看起来很迷糊,直接实操一下。
BR2_INSTRUMENTATION_SCRIPTS实操 编写script脚本。其中scripts1.sh如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 #!/bin/bash echo "Debugging: ======>scripts1.sh" echo "Debugging: para1 \$1 is: $1" echo "Debugging: para2 \$2 is: $2" echo "Debugging: para3 \$3 is: $3" echo Debugging: BR2_CONFIG: ${BR2_CONFIG} echo Debugging: HOST_DIR: ${HOST_DIR} echo Debugging: BUILD_DIR: ${BUILD_DIR} echo Debugging: BINARIES_DIR: ${BINARIES_DIR} echo Debugging: BASE_DIR: ${BASE_DIR}
scripts2.sh脚本如下:
1 2 3 #!/bin/bash echo "Debugging: ======>scripts2.sh"
在buildroot下执行如下命令:
1 $ make -C /home/u ser/work/ buildroot/out <pkg-name> BR2_INSTRUMENTATION_SCRIPTS="scripts1.sh scripts2.sh"
输出结果如下:
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 Debugging: ======>scripts1.sh Debugging: para1 $1 is: start Debugging: para2 $2 is: rsync Debugging: para3 $3 is: <pkg-name> Debugging: BR2_CONFIG: /home/u ser/work/ buildroot/out/ .config Debugging: HOST_DIR: /home/u ser/work/ buildroot/out/ host Debugging: BUILD_DIR: /home/u ser/work/ buildroot/out/ build Debugging: BINARIES_DIR: /home/u ser/work/ buildroot/out/im ages Debugging: BASE_DIR: /home/u ser/work/ buildroot/out Debugging: ======>scripts2.sh Debugging: ======>scripts1.sh Debugging: para1 $1 is: end Debugging: para2 $2 is: rsync Debugging: para3 $3 is: <pkg-name> Debugging: BR2_CONFIG: /home/u ser/work/ buildroot/out/ .config Debugging: HOST_DIR: /home/u ser/work/ buildroot/out/ host Debugging: BUILD_DIR: /home/u ser/work/ buildroot/out/ build Debugging: BINARIES_DIR: /home/u ser/work/ buildroot/out/im ages Debugging: BASE_DIR: /home/u ser/work/ buildroot/out Debugging: ======>scripts2.sh Debugging: ======>scripts1.sh Debugging: para1 $1 is: start Debugging: para2 $2 is: configure Debugging: para3 $3 is: <pkg-name> Debugging: BR2_CONFIG: /home/u ser/work/ buildroot/out/ .config Debugging: HOST_DIR: /home/u ser/work/ buildroot/out/ host Debugging: BUILD_DIR: /home/u ser/work/ buildroot/out/ build Debugging: BINARIES_DIR: /home/u ser/work/ buildroot/out/im ages Debugging: BASE_DIR: /home/u ser/work/ buildroot/out Debugging: ======>scripts2.sh Debugging: ======>scripts1.sh Debugging: para1 $1 is: end Debugging: para2 $2 is: configure Debugging: para3 $3 is: <pkg-name> Debugging: BR2_CONFIG: /home/u ser/work/ buildroot/out/ .config Debugging: HOST_DIR: /home/u ser/work/ buildroot/out/ host Debugging: BUILD_DIR: /home/u ser/work/ buildroot/out/ build Debugging: BINARIES_DIR: /home/u ser/work/ buildroot/out/im ages Debugging: BASE_DIR: /home/u ser/work/ buildroot/out Debugging: ======>scripts2.sh Debugging: ======>scripts1.sh Debugging: para1 $1 is: start Debugging: para2 $2 is: build Debugging: para3 $3 is: <pkg-name> Debugging: BR2_CONFIG: /home/u ser/work/ buildroot/out/ .config Debugging: HOST_DIR: /home/u ser/work/ buildroot/out/ host Debugging: BUILD_DIR: /home/u ser/work/ buildroot/out/ build Debugging: BINARIES_DIR: /home/u ser/work/ buildroot/out/im ages Debugging: BASE_DIR: /home/u ser/work/ buildroot/out Debugging: ======>scripts2.sh Debugging: ======>scripts1.sh Debugging: para1 $1 is: end Debugging: para2 $2 is: build Debugging: para3 $3 is: <pkg-name> Debugging: BR2_CONFIG: /home/u ser/work/ buildroot/out/ .config Debugging: HOST_DIR: /home/u ser/work/ buildroot/out/ host Debugging: BUILD_DIR: /home/u ser/work/ buildroot/out/ build Debugging: BINARIES_DIR: /home/u ser/work/ buildroot/out/im ages Debugging: BASE_DIR: /home/u ser/work/ buildroot/out Debugging: ======>scripts2.sh Debugging: ======>scripts1.sh Debugging: para1 $1 is: start Debugging: para2 $2 is: install-target Debugging: para3 $3 is: <pkg-name> Debugging: BR2_CONFIG: /home/u ser/work/ buildroot/out/ .config Debugging: HOST_DIR: /home/u ser/work/ buildroot/out/ host Debugging: BUILD_DIR: /home/u ser/work/ buildroot/out/ build Debugging: BINARIES_DIR: /home/u ser/work/ buildroot/out/im ages Debugging: BASE_DIR: /home/u ser/work/ buildroot/out Debugging: ======>scripts2.sh Debugging: ======>scripts1.sh Debugging: para1 $1 is: end Debugging: para2 $2 is: install-target Debugging: para3 $3 is: <pkg-name> Debugging: BR2_CONFIG: /home/u ser/work/ buildroot/out/ .config Debugging: HOST_DIR: /home/u ser/work/ buildroot/out/ host Debugging: BUILD_DIR: /home/u ser/work/ buildroot/out/ build Debugging: BINARIES_DIR: /home/u ser/work/ buildroot/out/im ages Debugging: BASE_DIR: /home/u ser/work/ buildroot/out Debugging: ======>scripts2.sh