learning armbian steps(11) ----- armbian 源码分析(六)

2022-11-12,,,,

接下来我们来分析一下uboot的编写过程:

从 lib/compilation.sh  89开始阅读:

  compile_uboot()
{
# not optimal, but extra cleaning before overlayfs_wrapper should keep sources directory clean
if [[ $CLEAN_LEVEL == *make* ]]; then
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
(cd $SRC/cache/sources/$BOOTSOURCEDIR; make clean > /dev/null >&)
fi if [[ $USE_OVERLAYFS == yes ]]; then
local ubootdir=$(overlayfs_wrapper "wrap" "$SRC/cache/sources/$BOOTSOURCEDIR" "u-boot_${LINUXFAMILY}_${BRANCH}")
else
local ubootdir="$SRC/cache/sources/$BOOTSOURCEDIR"
fi
cd "$ubootdir" # read uboot version
local version=$(grab_version "$ubootdir") display_alert "Compiling u-boot" "$version" "info" local toolchain=$(find_toolchain "$UBOOT_COMPILER" "$UBOOT_USE_GCC")
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${UBOOT_COMPILER}gcc $UBOOT_USE_GCC" 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 继续阅读

         # create directory structure for the .deb package
local uboot_name=${CHOSEN_UBOOT}_${REVISION}_${ARCH}
rm -rf $SRC/.tmp/$uboot_name
mkdir -p $SRC/.tmp/$uboot_name/usr/lib/{u-boot,$uboot_name} $SRC/.tmp/$uboot_name/DEBIAN

113-118行 创建uboot相关的临时目录。

         # process compilation for one or multiple targets
while read -r target; do
local target_make=$(cut -d';' -f1 <<< $target)
local target_patchdir=$(cut -d';' -f2 <<< $target)
local target_files=$(cut -d';' -f3 <<< $target) display_alert "Checking out sources"
git checkout -f -q HEAD if [[ $CLEAN_LEVEL == *make* ]]; then
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
(cd $SRC/cache/sources/$BOOTSOURCEDIR; make clean > /dev/null >&)
fi advanced_patch "u-boot" "$BOOTPATCHDIR" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}" # create patch for manual source changes
[[ $CREATE_PATCHES == yes ]] && userpatch_create "u-boot" if [[ -n $ATFSOURCE ]]; then
local atftempdir=$SRC/.tmp/atf-${LINUXFAMILY}-${BOARD}-${BRANCH}
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
if [[ $BOOTBRANCH == "tag:v2018".* ]]; then
[[ -f .config ]] && sed -i 's/^.*CONFIG_ENV_IS_IN_FAT.*/# CONFIG_ENV_IS_IN_FAT is not set/g' .config
[[ -f .config ]] && sed -i 's/^.*CONFIG_ENV_IS_IN_EXT4.*/CONFIG_ENV_IS_IN_EXT4=y/g' .config
[[ -f .config ]] && sed -i 's/^.*CONFIG_ENV_IS_IN_MMC.*/# CONFIG_ENV_IS_IN_MMC is not set/g' .config
[[ -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
[[ -f .config ]] && echo 'CONFIG_ENV_EXT4_INTERFACE="mmc"' >> .config
[[ -f .config ]] && echo 'CONFIG_ENV_EXT4_DEVICE_AND_PART="0:auto"' >> .config
[[ -f .config ]] && echo 'CONFIG_ENV_EXT4_FILE="/boot/boot.env"' >> .config
fi
[[ -f tools/logos/udoo.bmp ]] && cp $SRC/packages/blobs/splash/udoo.bmp tools/logos/udoo.bmp
touch .scmversion # $BOOTDELAY can be set in board family config, ensure autoboot can be stopped even if set to
[[ $BOOTDELAY == ]] && echo -e "CONFIG_ZERO_BOOTDELAY_CHECK=y" >> .config
[[ -n $BOOTDELAY ]] && sed -i "s/^CONFIG_BOOTDELAY=.*/CONFIG_BOOTDELAY=${BOOTDELAY}/" .config || [[ -f .config ]] && echo "CONFIG_BOOTDELAY=${BOOTDELAY}" >> .config eval CCACHE_BASEDIR="$(pwd)" env PATH=$toolchain:$PATH \
'make $target_make $CTHREADS CROSS_COMPILE="$CCACHE $UBOOT_COMPILER"' >& \
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling u-boot..." $TTY_Y $TTY_X'} \
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'} [[ ${PIPESTATUS[]} -ne ]] && exit_with_error "U-boot compilation failed" [[ $(type -t uboot_custom_postprocess) == function ]] &&
# copy files to build directory
for f in $target_files; do
local f_src=$(cut -d':' -f1 <<< $f)
if [[ $f == *:* ]]; then
local f_dst=$(cut -d':' -f2 <<< $f)
else
local f_dst=$(basename $f_src)
fi
[[ ! -f $f_src ]] && exit_with_error "U-boot file not found" "$(basename $f_src)"
cp $f_src $SRC/.tmp/$uboot_name/usr/lib/$uboot_name/$f_dst
done
done <<< "$UBOOT_TARGET_MAP"

从126行 133行可以看出其主要目地是获取源码,及打上相应的补丁

163行主要是用于设计BOOTDELAY 选项

167-171主要是开始编译uboot

175行  uboot_custom_postprocess 这个shell 函数主要是用于客户定制功能,比如对MLO u-boot.img进行重新命令等处理

177-186行主要是用于后续针对将uboot镜像制作成deb包做准备。

learning armbian steps(11) ----- armbian 源码分析(六)的相关教程结束。

《learning armbian steps(11) ----- armbian 源码分析(六).doc》

下载本文的Word格式文档,以方便收藏与打印。