官方uboot的mkconfig分析

    科技2022-07-11  105

    (1)Makefile配置所传的参数

    $1=-A $2=s5p_goni(mkconfig会通过这个参数在boards.cfg中找到与参数相对应的一行)

    %_config:: unconfig @$(MKCONFIG) -A $(@:_config=)

    (2)解析boards.cfg

    (1)#通过正则表达式在boards.cfg中查找与$2=s5p_goni相对应的一行,将对应行的参数赋值到$1到$8

    if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then # Automatic mode line=`awk '($0 !~ /^#/ && $7 ~ /^'"$2"'$/) { print $1, $2, $3, $4, $5, $6, $7, $8 }' boards.cfg` if [ -z "$line" ] ; then echo "make: *** No rule to make target \`$2_config'. Stop." >&2 exit 1 fi set ${line} # add default board name if needed [add default board name if needed [ $# = 3 ] && set ${line} ${1} fi

    (2)boards.cfg中的对应行为 所以$的值为 $1:Active $2:arm $3:armv7 $4:s5pc1xx $5:samsung $6:goni $7:s5p_goni $8:-

    (3)

    #判断传参个数是否大于0 while [ $# -gt 0 ] ; do case "$1" in --) shift ; break ;; -a) shift ; APPEND=yes ;; -n) shift ; BOARD_NAME="${7%_config}" ; shift ;; -t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;; #如果$1与上面的不匹配就退出 *) break ;; esac done #传参个数是否小于7 [ $# -lt 7 ] && exit 1 #传参个数是否大于8 [ $# -gt 8 ] && exit 1

    (4)

    #CONFIG_NAM=s5p_goni _config CONFIG_NAME="${7%_config}" #如果没有配置名就把配置名设置为s5p_goni _config [ "${BOARD_NAME}" ] || BOARD_NAME="${7%_config}" #arch=arm arch="$2" #cpu=armv7 cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $1}'` spl_cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $2}'` if [ "$6" = "-" ] ; then board=${BOARD_NAME} else #board=goni board="$6" fi #vendor=samsung [ "$5" != "-" ] && vendor="$5" #soc=s5pc1xx [ "$4" != "-" ] && soc="$4" [ $# -gt 7 ] && [ "$8" != "-" ] && { # check if we have a board config name in the options field # the options field mave have a board config name and a list # of options, both separated by a colon (':'); the options are # separated by commas (','). # # Check for board name tmp="${8%:*}" if [ "$tmp" ] ; then CONFIG_NAME="$tmp" fi # Check if we only have a colon... if [ "${tmp}" != "$8" ] ; then options=${8#*:} TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}" fi }

    配置结果 arch=arm cpu=armv7 soc=s5pc1xx vendor=samsung board=goni

    (5)创建符号链接

    if [ "$SRCTREE" != "$OBJTREE" ] ; then mkdir -p ${OBJTREE}/include mkdir -p ${OBJTREE}/include2 cd ${OBJTREE}/include2 rm -f asm #在include下创建asm指向arm/include/asm文件 ln -s ${SRCTREE}/arch/${arch}/include/asm asm LNPREFIX=${SRCTREE}/arch/${arch}/include/asm/ cd ../include mkdir -p asm else cd ./include rm -f asm #在include下创建asm指向arm/include/asm文件 ln -s ../arch/${arch}/include/asm asm fi rm -f asm/arch if [ -z "${soc}" ] ; then #在asm目录下创建arch文件指向arch-arm ln -s ${LNPREFIX}arch-${cpu} asm/arch else ln -s ${LNPREFIX}arch-${soc} asm/arch fi if [ "${arch}" = "arm" ] ; then rm -f asm/proc #在asm目录下创建proc文件指向proc-armv ln -s ${LNPREFIX}proc-armv asm/proc fi

    (6)创建config.h和config.mk文件并添加信息

    ( echo “ARCH = a r c h " i f [ ! − z " {arch}" if [ ! -z " arch"if[!z"spl_cpu” ] ; then echo ‘ifeq ($(CONFIG_SPL_BUILD),y)’ echo “CPU = ${spl_cpu}” echo “else” echo “CPU = ${cpu}” echo “endif” else echo “CPU = ${cpu}” fi echo “BOARD = ${board}”

    [ "${vendor}" ] && echo "VENDOR = ${vendor}" [ "${soc}" ] && echo "SOC = ${soc}" exit 0 ) > config.mk

    Assign board directory to BOARDIR variable

    if [ -z " v e n d o r " ] ; t h e n B O A R D D I R = {vendor}" ] ; then BOARDDIR= vendor"];thenBOARDDIR={board} else BOARDDIR= v e n d o r / {vendor}/ vendor/{board} fi

    Create board specific header file

    if [ "$APPEND" = "yes" ] # Append to existing config file then echo >> config.h else > config.h # Create new config file fi echo "/* Automatically generated - do not edit */" >>config.h for i in ${TARGETS} ; do i="`echo ${i} | sed '/=/ {s/=/ /;q; } ; { s/$/ 1/; }'`" echo "#define CONFIG_${i}" >>config.h ; done echo "#define CONFIG_SYS_ARCH \"${arch}\"" >> config.h echo "#define CONFIG_SYS_CPU \"${cpu}\"" >> config.h echo "#define CONFIG_SYS_BOARD \"${board}\"" >> config.h [ "${vendor}" ] && echo "#define CONFIG_SYS_VENDOR \"${vendor}\"" >> config.h [ "${soc}" ] && echo "#define CONFIG_SYS_SOC \"${soc}\"" >> config.h
    Processed: 0.010, SQL: 8