海思(Hi3521a)uboot详细分析(2)——顶层mkconfig分析

    在顶层的Makefile中,由语句MKCONFIG    := $(SRCTREE)/mkconfig 可以知道uboot进行配置的时候,会执行顶层目录的mkconfig脚本,以HI3521A板子为例,执行配置的时候最终会执行命令:

hi3521a_config: unconfig
    @$(MKCONFIG) $(@:_config=) arm hi3521a hi3521a NULL hi3521a

顶层Makefile的分析可以参考《顶层Makefile分析》,其它内容可以参考《序言和目录》


顶层mkconfig

APPEND=no	# Default: Create new config file
BOARD_NAME=""	# Name to print in make output
TARGETS=""
  • 定义三个变量APPEND,BOARD_NAME,TARGETS
while [ $# -gt 0 ] ; do
	case "$1" in
	--) shift ; break ;;
	-a) shift ; APPEND=yes ;;
	-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
	-t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;;
	*)  break ;;
	esac
done
  • “shift”是命令左移,使用$1=$2,$2=$3,...,而原来的$1将丢.
  • 依次执行(--,-a,-n,*),这些选项
  • 由于并没有传递给mkconfig以上任何选项,因此不会执行while
[ "${BOARD_NAME}" ] || BOARD_NAME="$1"
  • 如果BOARD_NAME定义了,就不会执行BOARD_NAME="$1",反之,则执行
  • 这里参数$1等于hi3521a
[ $# -lt 4 ] && exit 1
[ $# -gt 6 ] && exit 1
  • -lt小于:less than;-lt大于:greater than
  • 如果$#小于4或者大于6,就退出。$#表示传入的参数,这里是6个参数,他们的值分别为:
  • $0: /home/biao/test/uboot_study/u-boot-2010.06/mkconfig
  • $1 hi3521a
  • $2 arm
  • $3 hi3521a
  • $4 hi3521a
  • $5 NULL
  • $6 hi3521a
  • $0是脚本的目录,不是参数
if [ "${ARCH}" -a "${ARCH}" != "$2" ]; then
	echo "Failed: \$ARCH=${ARCH}, should be '$2' for ${BOARD_NAME}" 1>&2
	exit 1
fi

echo "Configuring for ${BOARD_NAME} board..."
  • ARCH如果有定义并且不等于$2的值,异常退出。
  • 这里$2=arm
#
# Create link to architecture specific headers
#
if [ "$SRCTREE" != "$OBJTREE" ] ; then
	mkdir -p ${OBJTREE}/include
	mkdir -p ${OBJTREE}/include2
	cd ${OBJTREE}/include2
	rm -f asm
	ln -s ${SRCTREE}/arch/$2/include/asm asm
	LNPREFIX=${SRCTREE}/arch/$2/include/asm/
	cd ../include
	rm -f asm
	ln -s ${SRCTREE}/arch/$2/include/asm asm
else
	cd ./include
	rm -f asm
	ln -s ../arch/$2/include/asm asm
fi
  • 创建连接文件,包括创建软连接
rm -f asm/arch 
  • 删除arch/arm/include/asm 下的 arch 
if [ -z "$6" -o "$6" = "NULL" ] ; then
	ln -s ${LNPREFIX}arch-$3 asm/arch
else
	ln -s ${LNPREFIX}arch-$6 asm/arch 
fi

if [ "$2" = "arm" ] ; then
	rm -f asm/proc
	ln -s ${LNPREFIX}proc-armv asm/proc #
fi
  • 建立软连接 asm/arch -> arch-hi3521a
  • 建立软连接 asm/proc -> proc-armv
#
# Create include file for Make
#
echo "ARCH   = $2" >  config.mk
echo "CPU    = $3" >> config.mk
echo "BOARD  = $4" >> config.mk

[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk

[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC    = $6" >> config.mk
  • 通过上面的cd ./include我们知道,执行到这里时,当前目录是在./include 这里是在./include目录下创建文件config.mk,然后将ARCH、CPU、BOARD信息输入到文件config.mk中
  • config.mk的内容为:
  •   ARCH   = arm                    
  •   CPU    = hi3521a
  •   BOARD  = hi3521a
  •   SOC    = hi3521a
# Assign board directory to BOARDIR variable
if [ -z "$5" -o "$5" = "NULL" ] ; then
    BOARDDIR=$4
else
    BOARDDIR=$5/$4
fi
  • 由于$4=hi3521a $5=NULL ,所以BOARDDIR=hi3521a
#
# Create board specific header file
#
if [ "$APPEND" = "yes" ]	# Append to existing config file
then
	echo >> config.h   #APPEND=no
else
	> config.h		# Create new config file
fi
echo "/* Automatically generated - do not edit */" >>config.h
  • 创建文件./include/config.h
for i in ${TARGETS} ; do
	echo "#define CONFIG_MK_${i} 1" >>config.h ;
done
  • TARGETS在这里为空,不执行
cat << EOF >> config.h
#define CONFIG_BOARDDIR board/$BOARDDIR
#include <config_defaults.h>
#include <configs/$1.h>
#include <asm/config.h>
EOF
  • 在./u-boot-2010/include/config.h 文件后面添加内容:
  • #define CONFIG_BOARDDIR board/$BOARDDIR
  • #include <config_defaults.h>
  • #include <configs/hi3520dv300.h>
  • #include <asm/config.h>
  • 这里主要注意一点,还是官方给的配置hi3520dv300这板子的命令是:
  • make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- hi3521a_config
  • make ARCH=arm CROSS_COMPILE=arm-hisiv300-linux- hi3520dv300_config
  • 需要配置hi3521a之后再配置hi3520dv300,从这里可以看出,这两款芯片其它部分都相同,唯一的不同就是configs/hi3520dv300.h 这里面的内容不同。
exit 0
  • 执行完成,退出脚本。
发布了164 篇原创文章 · 获赞 229 · 访问量 62万+

猜你喜欢

转载自blog.csdn.net/li_wen01/article/details/103238239