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

简要描述

  • 本文正式从compile.sh脚本分析其编译过程,跟着脚本代码开始深入学习

开始解析

从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.sh

 25 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:hash@depth(**)
#
# *: Implies ref_subdir=no
# **: Not implemented yet
# <ref_subdir>: "yes" to create subdirectory for tag or branch name
#
fingerprint_image()
       将编译信息生成至etc/armbian.txt,其中包含      
Title:  Armbian $REVISION ${BOARD^} $DISTRIBUTION $RELEASE $BRANCH
        Kernel:                 Linux $VER
        Build date:             $(date +'%d.%m.%Y')
        Authors:                https://www.armbian.com/authors
        Sources:                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.sh

download_toolchain()
         用于下载工具链。

download_etcher_cli()
        用于下载etcher_cli,该命令工具的功能相当于dd命令与校验功能的合体。

其中display_alert()函数用于做不同的级别显示
在这里插入图片描述

接来再次回到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_LEVEL="make,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_LANG="en_US.UTF-8"                 # sl_SI.UTF-8, en_US.UTF-8

# advanced
KERNEL_KEEP_CONFIG="no"                 # do not overwrite kernel config before compilation
EXTERNAL="yes"                          # build and install extra applications and drivers
EXTERNAL_NEW="prebuilt"                 # compile and install or install prebuilt additional packages
CREATE_PATCHES="no"                     # wait that you make changes to uboot and kernel source and creates patches
BUILD_ALL="no"                          # 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_TAG="master"                        # 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_FILE="yes"
BUILD_KSRC="no"

在compile.sh当中允许传递 key=value, 比如./compile.sh test_cmd=test_value

 51 # 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.sh

 74 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. 获取并解析默认的参数。通过源码分析可知 config-default.conf 就是用户可以自定义配置信息的地方。

  3. 最后的主要功能还是在/lib/main.sh脚本当中,接下来我们会来解析main.sh脚本的功能。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式实操

希望博文有助于您,您不必加班。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值