learning armbian steps(7) ----- armbian 源码分析(二)

📅 2026/6/16 17:32:47 👤 管理员 👁 次浏览
learning armbian steps(7) ----- armbian 源码分析(二)
从compile.sh开始入手16 SRC$(dirname $(realpath ${BASH_SOURCE})) 17 # fallback for Trusty 18 [[ -z ${SRC} ]] SRC$(pwd) 19 20 # check for whitespace in $SRC and exit for safety reasons 21 grep -q [[:space:]] ${SRC} { echo \${SRC}\ contains whitespace. Not supported. Aborting. 2 ; exit 1 ; } 22 23 cd $SRC如上主要是获取源代码的路径并判断路径是否存在空格合法在compile.sh25 if [[ -f $SRC/lib/general.sh -L $SRC/main.sh ]]; then 26 source $SRC/lib/general.sh 27 else 28 echo Error: missing build directory structure 29 echo Please clone the full repository https://github.com/armbian/build/ 30 exit -1 31 fi很明显在这一步里我们可以进入general.sh看一下实际做了什么在lib/general.sh定义了很多的shell 函数Cleaning()根据不同的参数做清除工作Exit_with_error()出错时用于显示错误调节的功能文件行号是否高亮及相关的出错描述Get_package_list_hash()打印新构建的文件系统安装包列表以及文件系统的版本Create_source_list()更新apt source.list到新构建的文件系统当中fetch_from_repo()用于拉取git 仓库的代码# fetch_from_repo url directory ref ref_subdir# url: remote repository URL# directory: local directory; subdir for branch/tag will be created# ref:# branch:name# tag:name# head(*)# commit:hashdepth(**)## *: Implies ref_subdirno# **: Not implemented yet# ref_subdir: yes to create subdirectory for tag or branch name#display_alert()根据不同的级别显示fingerprint_image()将编译信息生成至etc/armbian.txt其中包含Title: Armbian $REVISION ${BOARD^} $DISTRIBUTION $RELEASE $BRANCHKernel: Linux $VERBuild date: $(date %d.%m.%Y)Authors: https://www.armbian.com/authorsSources: https://github.com/armbian/Support: https://forum.armbian.com/Changelog: https://www.armbian.com/logbook/Documantation: https://docs.armbian.com/addtorepo()用于创建本地的apt仓库下载交叉编译工具链下载etcher_cli工具。可定制自已的镜像打包脚本。[[ ! -f $SRC/userpatches/customize-image.sh ]] cp $SRC/config/templates/customize-image.sh.template $SRC/userpatches/customize-image.shdownload_toolchain()用于下载工具链。download_etcher_cli()用于下载etcher_cli该命令工具的功能相当于dd命令与校验功能的合体。接来再次回到compile.sh脚本当中33 # copy default config from the template 34 [[ ! -f $SRC/config-default.conf ]] cp $SRC/config/templates/config-example.conf $SRC/config-default.conf 35 36 # source build configuration file 37 if [[ -n $1 -f $SRC/config-$1.conf ]]; then 38 display_alert Using config file config-$1.conf info 39 source $SRC/config-$1.conf 40 else 41 display_alert Using config file config-default.conf info 42 source $SRC/config-default.conf 43 fi在默认的config-default.conf内容如下所示KERNEL_ONLY # leave empty to select each time, set to yes or no to skip dialog prompt KERNEL_CONFIGURE # leave empty to select each time, set to yes or no to skip dialog prompt CLEAN_LEVELmake,debs,oldcache # comma-separated list of clean targets: make make clean for selected kernel and u-boot, # debs delete packages in ./output/debs for current branch and family, # alldebs delete all packages in ./output/debs, images delete ./output/images, # cache delete ./output/cache, sources delete ./sources # oldcache remove old cached rootfs except for the newest 6 files DEST_LANGen_US.UTF-8 # sl_SI.UTF-8, en_US.UTF-8 # advanced KERNEL_KEEP_CONFIGno # do not overwrite kernel config before compilation EXTERNALyes # build and install extra applications and drivers EXTERNAL_NEWprebuilt # compile and install or install prebuilt additional packages CREATE_PATCHESno # wait that you make changes to uboot and kernel source and creates patches BUILD_ALLno # cycle through available boards and make images or kernel/u-boot packages. # set KERNEL_ONLY to yes or no to build all packages/all images BSPFREEZE # freeze armbian packages (u-boot, kernel, dtb) INSTALL_HEADERS # install kernel headers package LIB_TAGmaster # change to branchname to use any branch currently available. CARD_DEVICE # device name /dev/sdx of your SD card to burn directly to the card when done PROGRESS_LOG_TO_FILEyes BUILD_KSRCno在compile.sh当中允许传递 keyvalue, 比如./compile.sh test_cmdtest_value51 # Script parameters handling 52 for i in $; do 53 if [[ $i ** ]]; then 54 parameter${i%%*} 55 value${i##*} 56 display_alert Command line: setting $parameter to ${value:-(empty)} info 57 eval $parameter$value 58 fi 59 done接下来我们继续看compile.sh74 if [[ $BUILD_ALL yes || $BUILD_ALL demo ]]; then 75 source $SRC/lib/build-all.sh 76 else 77 source $SRC/lib/main.sh 78 fi由于默认的BUILD_ALL “no” , 所以接下来会去执行$SRC/lib/main.sh.脚本。总结一下compile.sh的功能1 获取shell脚本相关的钩子函数在lib/generate.sh当中2 获取并解析默认的参数。3 最后的主要功能还是在/lib/main.sh脚本当中接下来我们会来解析main.sh脚本的功能。