learning armbian steps(11) ----- armbian 源码分析(六)
接下来我们来分析一下uboot的编写过程:
从 lib/compilation.sh 89开始阅读:
89 compile_uboot() 90 { 91 # not optimal, but extra cleaning before overlayfs_wrapper should keep sources directory clean 92 if [[ $CLEAN_LEVEL == *make* ]]; then 93 display_alert "Cleaning" "$BOOTSOURCEDIR" "info" 94 (cd $SRC/cache/sources/$BOOTSOURCEDIR; make clean > /dev/null 2>&1) 95 fi 96 97 if [[ $USE_OVERLAYFS == yes ]]; then 98 local ubootdir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$BOOTSOURCEDIR" "u-boot_${LINUXFAMILY}_${BRANCH}") 99 else 100 local ubootdir="$SRC/cache/sources/$BOOTSOURCEDIR" 101 fi 102 cd "$ubootdir" 103 104 # read uboot version 105 local version=$(grab_version "$ubootdir") 106 107 display_alert "Compiling u-boot" "$version" "info" 108 109 local toolchain=$(find_toolchain "$UBOOT_COMPILER" "$UBOOT_USE_GCC") 110 [[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${UBOOT_COMPILER}gcc $UBOOT_USE_GCC" 111 112 display_alert "Compiler version" "${UBOOT_COMPILER}gcc $(eval env PATH=$toolchain:$PATH ${UBOOT_COMPILER}gcc -dumpversion)" "info"
89-112行,主是是进行uboot源代码的目录 cache/sources/u-boot-am335x/ti-u-boot-2017.01 ,获取uboot的版本信息,找到交叉编译工具链,并导出至环境变量当中。
overlayfs_wrapper
grap_version
find_toolchain
这三个shell函数可自动阅读。
lib/compilation.sh 继续阅读
113 114 # create directory structure for the .deb package 115 local uboot_name=${CHOSEN_UBOOT}_${REVISION}_${ARCH} 116 rm -rf $SRC/.tmp/$uboot_name 117 mkdir -p $SRC/.tmp/$uboot_name/usr/lib/{u-boot,$uboot_name} $SRC/.tmp/$uboot_name/DEBIAN 118
113-118行 创建uboot相关的临时目录。
119 # process compilation for one or multiple targets 120 while read -r target; do 121 local target_make=$(cut -d';' -f1 <<< $target) 122 local target_patchdir=$(cut -d';' -f2 <<< $target) 123 local target_files=$(cut -d';' -f3 <<< $target) 124 125 display_alert "Checking out sources" 126 git checkout -f -q HEAD 127 128 if [[ $CLEAN_LEVEL == *make* ]]; then 129 display_alert "Cleaning" "$BOOTSOURCEDIR" "info" 130 (cd $SRC/cache/sources/$BOOTSOURCEDIR; make clean > /dev/null 2>&1) 131 fi 132 133 advanced_patch "u-boot" "$BOOTPATCHDIR" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}" 134 135 # create patch for manual source changes 136 [[ $CREATE_PATCHES == yes ]] && userpatch_create "u-boot" 137 138 if [[ -n $ATFSOURCE ]]; then 139 local atftempdir=$SRC/.tmp/atf-${LINUXFAMILY}-${BOARD}-${BRANCH} 140 cp -Rv $atftempdir/*.bin . 141 fi 142 143 eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \ 144 'make $CTHREADS $BOOTCONFIG CROSS_COMPILE="$CCACHE $UBOOT_COMPILER"' 2>&1 \ 145 ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \ 146 ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'} 147 148 # armbian specifics u-boot settings 149 [[ -f .config ]] && sed -i 's/CONFIG_LOCALVERSION=""/CONFIG_LOCALVERSION="-armbian"/g' .config 150 [[ -f .config ]] && sed -i 's/CONFIG_LOCALVERSION_AUTO=.*/# CONFIG_LOCALVERSION_AUTO is not set/g' .config 151 if [[ $BOOTBRANCH == "tag:v2018".* ]]; then 152 [[ -f .config ]] && sed -i 's/^.*CONFIG_ENV_IS_IN_FAT.*/# CONFIG_ENV_IS_IN_FAT is not set/g' .config 153 [[ -f .config ]] && sed -i 's/^.*CONFIG_ENV_IS_IN_EXT4.*/CONFIG_ENV_IS_IN_EXT4=y/g' .config 154 [[ -f .config ]] && sed -i 's/^.*CONFIG_ENV_IS_IN_MMC.*/# CONFIG_ENV_IS_IN_MMC is not set/g' .config 155 [[ -f .config ]] && sed -i 's/^.*CONFIG_ENV_IS_NOWHERE.*/# CONFIG_ENV_IS_NOWHERE is not set/g' .config | echo "# CONFIG_ENV_IS_NOWHERE is not set" >> .config 156 [[ -f .config ]] && echo 'CONFIG_ENV_EXT4_INTERFACE="mmc"' >> .config 157 [[ -f .config ]] && echo 'CONFIG_ENV_EXT4_DEVICE_AND_PART="0:auto"' >> .config 158 [[ -f .config ]] && echo 'CONFIG_ENV_EXT4_FILE="/boot/boot.env"' >> .config 159 fi 160 [[ -f tools/logos/udoo.bmp ]] && cp $SRC/packages/blobs/splash/udoo.bmp tools/logos/udoo.bmp 161 touch .scmversion 162 163 # $BOOTDELAY can be set in board family config, ensure autoboot can be stopped even if set to 0 164 [[ $BOOTDELAY == 0 ]] && echo -e "CONFIG_ZERO_BOOTDELAY_CHECK=y" >> .config 165 [[ -n $BOOTDELAY ]] && sed -i "s/^CONFIG_BOOTDELAY=.*/CONFIG_BOOTDELAY=${BOOTDELAY}/" .config || [[ -f .config ]] && echo "CONFIG_BOOTDELAY=${BOOTDELAY}" >> .config 166 167 eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \ 168 'make $target_make $CTHREADS CROSS_COMPILE="$CCACHE $UBOOT_COMPILER"' 2>&1 \ 169 ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \ 170 ${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling u-boot..." $TTY_Y $TTY_X'} \ 171 ${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'} 172 173 [[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "U-boot compilation failed" 174 175 [[ $(type -t uboot_custom_postprocess) == function ]] &&176 177 # copy files to build directory 178 for f in $target_files; do 179 local f_src=$(cut -d':' -f1 <<< $f) 180 if [[ $f == *:* ]]; then 181 local f_dst=$(cut -d':' -f2 <<< $f) 182 else 183 local f_dst=$(basename $f_src) 184 fi 185 [[ ! -f $f_src ]] && exit_with_error "U-boot file not found" "$(basename $f_src)" 186 cp $f_src $SRC/.tmp/$uboot_name/usr/lib/$uboot_name/$f_dst 187 done 188 done <<< "$UBOOT_TARGET_MAP"
从126行 133行可以看出其主要目地是获取源码,及打上相应的补丁
163行主要是用于设计BOOTDELAY 选项
167-171主要是开始编译uboot
175行 uboot_custom_postprocess 这个shell 函数主要是用于客户定制功能,比如对MLO u-boot.img进行重新命令等处理
177-186行主要是用于后续针对将uboot镜像制作成deb包做准备。