uboot - 配置过程1(分析国产君正的ingenic-linux-kernel3.10.14-x1000-v8.2-20181116\u-boot\mkconfig脚本)

=分析uboot的配置过程(mkconfig脚本)=
uboot怎么配置?我们在终端上执行make NAME_config时的运行过程解析!

STEP1:

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

我们执行make *_config时会运行makefile的这两行程序,先分析下:
这个其实就是运行uboot根目录下的mkconfig文件,
并传入2个参数:

$1: -A
$2: $(@:_config=) :去掉目标*_config中的_config字符串也就是 *

STEP2:

然后开始运行mkconfig

STEP2.1:

APPEND=no	# Default: Create new config file
BOARD_NAME=""	# Name to print in make output
TARGETS=""

arch=""
cpu=""
board=""
vendor=""
soc=""
options=""

if [ \( $# -eq 2 \) -a \( "$1" = "-A" \) ] ; then
	# Automatic mode
	line=`egrep -i "^[[:space:]]*${2}[[:space:]]" boards.cfg` || {
		echo "make: *** No rule to make target \`$2_config'.  Stop." >&2
		exit 1
	}

	set ${line}
	# add default board name if needed
	[ $# = 3 ] && set ${line} ${1}
fi

这里面涉及到shell脚本if的使用语法,单分支语句结构

if [ 条件表达式 ]; then
    指令
fi

分析条件语句:

\( $# -eq 2 \) -a \( "$1" = "-A" \) 

其中-a表示&& (语法:-o = or = ||, -a = and = && )
( $# -eq 2 )表示:输入的参数数目=2
( “$1” = “-A” ) 表示:输入的第一个参数=-A
这里条件满足,执行内部语句。

line=`egrep -i "^[[:space:]]*${2}[[:space:]]" boards.cfg` ||
       {echo "make: *** No rule to make target \`$2_config'.  Stop." >&2 exit 1}

两个语句执行||。
语句1:搜索文件获得模式。-i表示当进行比较时忽略字符的大小写。表示在boards.cfg里面搜索字符串"^ [[:space:]]*${2}[[:space:]]"即含有2#参数的字符串
例如:配置命令为

make halley2_xImage_nand_spl_boot_config

在boards.cfg里面line586

halley2_xImage_nand_spl_boot   mips        xburst     halley2		 ingenic        x1000       halley2:SPL_SFC_NAND,SPL_OS_BOOT,MTD_SFCNAND

如果有该行代码则赋值给line,否则打印

"make: *** No rule to make target \`$2_config'.  Stop." 

同时退出。
继续!

set ${line}

表示把line中存储的变量作为本文件的输入参数,即执行该语句之前参数数量为2,执行之后为7!

STEP2.2:

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

关于shell指令的while循环语法:

while expression
do
	command
done

条件是:参数个数$# -greater than 0 then…

关于shell指令的case语法:

case $xxx in
yyy)
	do something
	;;
	esac

检查1#参数是否有这几个符号,这里1#参数是

halley2_xImage_nand_spl_boot

条件不满足,则不执行该语句。

STEP2.3:

[ $# -lt 4 ] && exit 1			//$# -less than 4 退出
[ $# -gt 7 ] && exit 1		//$# -great than 7 退出

# Strip all options and/or _config suffixes
CONFIG_NAME="${1%_config}"

[ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"

如果定义了BOARD_NAME,则给它赋值。BOARD_NAME=halley2_xImage_nand_spl_boot_config

arch="$2"															#赋值arch=mips
cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $1}'`					#赋值cpu=xburst
spl_cpu=`echo $3 | awk 'BEGIN {FS = ":"} ; {print $2}'`				#

awk为shell命令,具体参见收藏具体介绍。

if [ "$4" = "-" ] ; then
	board=${BOARD_NAME}
else
	board="$4"
fi

board="$4"=halley2

STEP2.4

1#halley2_xImage_nand_spl_boot
2#mips
3#xburst
4#halley2
5#ingenic
6#x1000
7#halley2:SPL_SFC_NAND,SPL_OS_BOOT,MTD_SFCNAND
[ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5" 
[ $# -gt 5 ] && [ "$6" != "-" ] && soc="$6"

这里参数数量为7,两个条件均满足,所以vendor="$5" &&soc="$6"

[ $# -gt 6 ] && [ "$7" != "-" ] && {
	
	tmp="${7%:*}"		
	if [ "$tmp" ] ; then
		CONFIG_NAME="$tmp"
	fi
	# Check if we only have a colon...
	if [ "${tmp}" != "$7" ] ; then
		options=${7#*:}
		TARGETS="`echo ${options} | sed 's:,: :g'` ${TARGETS}"
	fi
}

以上条件满足,
#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
#截取7#参数:前面的部分和后面的部分,分别给CONFIG_NAMEoptions

语法1:${VALUE%.*}或${VALUE%%.*}删除VALUE字符串中以分隔符“.”匹配的右边字符,保留左边字符。tmp="${7%:*}"这里tmp=halley2
CONFIG_NAME="$tmp"=halley2

语法2:sed是shell指令

if [ "${ARCH}" -a "${ARCH}" != "${arch}" ]; then
	echo "Failed: \$ARCH=${ARCH}, should be '${arch}' for ${BOARD_NAME}" 1>&2
	exit 1
fi

语法:-a表示and,条件与
这里条件不满足。

if [ "$options" ] ; then
	echo "Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}"
else
	echo "Configuring for ${BOARD_NAME} board..."
fi

options变量存在,打印以下内容Configuring for ${BOARD_NAME} - Board: ${CONFIG_NAME}, Options: ${options}=Configuring for halley2_xImage_nand_spl_boot - Board: halley2, Options: SPL_SFC_NAND,SPL_OS_BOOT,MTD_SFCNAND

STEP2.5 创建asm链接

if [ "$SRCTREE" != "$OBJTREE" ] ; then
	mkdir -p ${OBJTREE}/include
	mkdir -p ${OBJTREE}/include2
	cd ${OBJTREE}/include2
	rm -f 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
	ln -s ../arch/${arch}/include/asm asm
fi

条件不满足,进入else分支,创建一个名称为asm的链接文件指向../arch/${arch}/include/asm
如果提示一下错误:在这里插入图片描述
不可使用共享文件夹的方式进行

STEP2.6

if [ -z "${soc}" ] ; then
	ln -s ${LNPREFIX}arch-${cpu} asm/arch
else
	ln -s ${LNPREFIX}arch-${soc} asm/arch
fi

语法1:shell脚本中的if 参数-a至-z
[-z string] “string”的长度为零则为真
这里条件不满足,执行else 创建链接文件asm/arch指向${LNPREFIX}arch-${soc}arch-x1000

STEP2.7

#
# Create include file for Make
#
( echo "ARCH   = ${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

在include/建立config.mk文件,

1.echo "ARCH   = ${arch}"   ----------------------->ARCH   = mips
2.
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
        -------------------->CPU    = xburst
3.echo "BOARD  = ${board}"--------------------->BOARD  = halley2
4.echo "VENDOR = ${vendor}"--------------->VENDOR = ingenic
5.echo "SOC    = ${soc}"--------------------->SOC    = x1000

STEP2.8

#
# 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

创建文件./include/config.h,打印第一句到文件

for i in ${TARGETS} ; do
	i="`echo ${i} | sed '/=/ {s/=/	/;q; } ; { s/$/	1/; }'`"
	echo "#define CONFIG_${i}" >>config.h ;
done

???需要查阅语法
对应文本为:

#define CONFIG_SPL_SFC_NAND	1
#define CONFIG_SPL_OS_BOOT	1
#define CONFIG_MTD_SFCNAND	1

打印下列语句到文件

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

===

#define CONFIG_SYS_ARCH  "mips"
#define CONFIG_SYS_CPU   "xburst"
#define CONFIG_SYS_BOARD "halley2"
#define CONFIG_SYS_VENDOR "ingenic"
#define CONFIG_SYS_SOC    "x1000"
cat << EOF >> config.h
#define CONFIG_BOARDDIR board/$BOARDDIR
#include <config_cmd_defaults.h>
#include <config_defaults.h>
#include <configs/${CONFIG_NAME}.h>
#include <asm/config.h>
#include <config_fallbacks.h>
#include <config_uncmd_spl.h>
EOF

=============

#define CONFIG_BOARDDIR board/ingenic/halley2
#include <config_cmd_defaults.h>
#include <config_defaults.h>
#include <configs/halley2.h>
#include <asm/config.h>
#include <config_fallbacks.h>
#include <config_uncmd_spl.h>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值