当前位置: 代码迷 >> 综合 >> uboot和系统移植扩展--配置脚本mkconfig分析
  详细解决方案

uboot和系统移植扩展--配置脚本mkconfig分析

热度:42   发布时间:2024-02-28 09:52:17.0

详细分析 

根据Makefile分析可知

  • $1:    x210_sd
  • $2:    arm
  • $3: s5pc11x
  • $4:    x210
  • $5: samsumg
  • $6:    s5pc110

所以,$# = 6

 

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

第23行:其实就是看BOARD_NAME变量是否有值,如果有值就维持不变;如果无值就给他赋值为$1,实际分析结果:BOARD_NAME=x210_sd

[ $# -lt 4 ] && exit 1
[ $# -gt 6 ] && exit 1

第25行:如果$#小于4,则exit 1(mkconfig脚本返回1)

第26行:如果$#大于6,则也返回1.

所以:mkconfig脚本传参只能是4、5、6,如果大于6或者小于4都不行。 

#
# Create link to architecture specific headers
#
if [ "$SRCTREE" != "$OBJTREE" ] ; thenmkdir -p ${OBJTREE}/includemkdir -p ${OBJTREE}/include2cd ${OBJTREE}/include2rm -f asmln -s ${SRCTREE}/include/asm-$2 asmLNPREFIX="../../include2/asm/"cd ../includerm -rf asm-$2rm -f asmmkdir asm-$2ln -s asm-$2 asm
else
#46行cd ./includerm -f asmln -s asm-$2 asm
#48行
firm -f asm-$2/arch#53行
if [ -z "$6" -o "$6" = "NULL" ] ; thenln -s ${LNPREFIX}arch-$3 asm-$2/arch
elseln -s ${LNPREFIX}arch-$6 asm-$2/arch
fi
#57行# create link for s3c24xx SoC
if [ "$3" = "s3c24xx" ] ; thenrm -f regs.hln -s $6.h regs.hrm -f asm-$2/archln -s arch-$3 asm-$2/arch
fi# create link for s3c64xx SoC
if [ "$3" = "s3c64xx" ] ; thenrm -f regs.hln -s $6.h regs.hrm -f asm-$2/archln -s arch-$3 asm-$2/arch
fi# create link for s5pc1xx SoC
if [ "$3" = "s5pc1xx" ] ; thenrm -f regs.hln -s $6.h regs.hrm -f asm-$2/archln -s arch-$3 asm-$2/arch
fi# create link for s5pc11x SoC
if [ "$3" = "s5pc11x" ] ; then
#85行rm -f regs.hln -s $6.h regs.hrm -f asm-$2/archln -s arch-$3 asm-$2/arch
#88行
fi# create link for s5p64xx SoC
if [ "$3" = "s5p64xx" ] ; thenrm -f regs.hln -s $6.h regs.hrm -f asm-$2/archln -s arch-$3 asm-$2/arch
fi# create link for s5p644x SoC
if [ "$3" = "s5p644x" ] ; thenrm -f regs.hln -s $6.h regs.hrm -f asm-$2/archln -s arch-$3 asm-$2/arch
fiif [ "$2" = "arm" ] ; thenrm -f asm-$2/proc
#109行ln -s ${LNPREFIX}proc-armv asm-$2/proc
fi# create link for s3c64xx-mp SoC
if [ "$3" = "s3c64xx-mp" ] ; thenrm -f regs.hln -s $6.h regs.hrm -f asm-$2/archln -s arch-$3 asm-$2/arch
fi

 从第33行到第118行,都是在创建符号链接。这些符号链接文件的存在就是整个配置过程的核心,这些符号链接文件(文件夹)的主要作用是给头文件包含等过程提供指向性连接。根本目的是让uboot具有可移植性。

uboot可移植性的实现原理:在uboot中有很多彼此平行的代码,各自属于各自不同的架构/CPU/开发板,我们在具体到一个开发板的编译时用符号连接的方式提供一个具体的名字的文件夹供编译时使用。这样就可以在配置的过程中通过不同的配置使用不同的文件,就可以正确的包含正确的文件。

在include目录下创建asm文件,指向asm-arm。(46-48行)

在inlcude/asm-arm下创建一个arch文件,指向include/asm-arm/arch-s5pc110。(53-57行)

在include目录下创建regs.h文件,指向include/s5pc110.h。删除上一步的inlcude/asm-arm/arch。在inlcude/asm-arm下创建一个arch文件,指向include/asm-arm/arch-s5pc11x。(85到88行)

在include/asm-arm下创建一个proc文件,指向include/asm-arm/proc-armv。(109行)

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

创建include/config.mk文件(123-129行)

创建include/config.mk文件是为了让主Makefile在第133行去包含的

if [ "$APPEND" = "yes" ]	# Append to existing config file
thenecho >> config.h
else> config.h		# Create new config file
fi
echo "/* Automatically generated - do not edit */" >>config.h
echo "#include <configs/$1.h>" >>config.h

创建(默认情况)/追加(make -a时追加)include/config.h文件(134-141行) 

这个文件里面的内容就一行#include <configs/x210_sd.h>,这个头文件是我们移植x210开发板时,对开发板的宏定义配置文件。这个文件是我们移植x210时最主要的文件

x210_sd.h文件会被用来生成一个autoconfig.mk文件,这个文件会被主Makefile引入,指导整个编译过程。这里面的这些宏定义会影响我们对uboot中大部分.c文件中一些条件编译的选择。从而实现最终的可移植性。