Tiny4412 u-boot分析u-boot配置流程分析

Posted CrazyDiode

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tiny4412 u-boot分析u-boot配置流程分析相关的知识,希望对你有一定的参考价值。

参考Friendlyarm的文档,编译uboot的流程为

make tiny4412_config
make

这个过程主要涉及到两个文件,顶层的Makefile文件和mkconfig文件,makeconfig文件是一个脚本,通过文件的注释可以了解到它的作用

# Script to create header files and links to configure
# U-Boot for a specific board.
#
# Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]

意思是,mkconfig 是用来创建头文件和链接脚本,并以此来为特定的开发板配置u-boot的脚本。它的主要参数有

Target  Architecture  CPU  Board [VENDOR] [SOC]

首先来分析顶层的Makefile文件,在Makefile文件中我们可以看到下面的代码

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

%在Makefile中作为通配符用来通配任意长度的字符,因此当我们执行 make tiny4412_config的时候就会匹配到%_config这条语句。::在Makefile中用来强制执行下面的命令,所以匹配到%_config之后,就会去执行unconfig,unconfig的作用是去除原来的配置信息。然后去执行

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

这条命令,@的作用是用来去除回显,$(MKCONFIG)在前面被定义为

MKCONFIG    := $(SRCTREE)/mkconfig
SRCTREE    := $(CURDIR)

我们将@去掉,然后执行make tiny4412_config,可以通过回显看到以下内容

make tiny4412_config
awk (NF && $1 !~ /^#/) { print $1 ": " $1 "_config; $(MAKE)" } boards.cfg > .boards.depend
/....../uboot_tiny4412/mkconfig -A tiny4412
Configuring for tiny4412 board...

所以我们执行make tiny4412_config实际上被解析成

/....../uboot_tiny4412/mkconfig -A tiny4412

指定了-A选项,mkconfig脚本会自动去解析boards.cfg文件,找到以下内容

# Target                     ARCH        CPU         Board name          Vendor         SoC         Options
tiny4412                     arm         armv7       tiny4412            samsung        exynos

所以我们最终执行的命令为

./mkconfig  tiny4412   arm  armv7  tiny4412  samsung  exynos

总结一下,mkcongif脚本主要做了以下几件事

(1)解析boards.cfg tiny4412相关数据

tiny4412                     arm         armv7       tiny4412            samsung        exynos
2)针对平台做了一系列链接,创建平台、开发板相关的头文件的链接
#
# 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/${arch}/include/asm asm
    LNPREFIX=${SRCTREE}/arch/${arch}/include/asm/
    cd ../include
    rm -f asm
    ln -s ${SRCTREE}/arch/${arch}/include/asm asm
else
    cd ./include
    rm -f asm
    ln -s ../arch/${arch}/include/asm asm
fi
rm -f asm/arch
if [ -z "${soc}" ] ; then
    ln -s ${LNPREFIX}arch-${cpu} asm/arch
else
    ln -s ${LNPREFIX}arch-${soc} asm/arch
fi
if [ "${arch}" = "arm" ] ; then
    rm -f asm/proc
    ln -s ${LNPREFIX}proc-armv asm/proc
fi

实际执行的命令为

cd ./include
rm -f asm
ln -s ../arch/arm/include/asm asm
ln -s arch-exynos asm/arch

(3)创建顶层Makefile包含的文件 include/ config.mk

#
# Create include file for Make
#
echo "ARCH   = ${arch}"  >  config.mk
echo "CPU    = ${cpu}"   >> config.mk
echo "BOARD  = ${board}" >> config.mk
[ "${vendor}" ] && echo "VENDOR = ${vendor}" >> config.mk
[ "${soc}"    ] && echo "SOC    = ${soc}"    >> config.mk
# Assign board directory to BOARDIR variable
if [ -z "${vendor}" ] ; then
    BOARDDIR=${board}
else
    BOARDDIR=${vendor}/${board}
fi

生成的config.mk内容如下

ARCH   = arm 

CPU    = armv7
BOARD  = tiny4412
VENDOR = samsung
SOC    = exynos

(4)创建开发板相关的头文件inlucde/config.h

#
# 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/=/\t/;q } ; { s/$/\t1/ }‘`"
    echo "#define CONFIG_${i}" >>config.h ;
done
cat << EOF >> config.h
#define CONFIG_BOARDDIR board/$BOARDDIR
#include <config_defaults.h>
#include <configs/${CONFIG_NAME}.h>
#include <asm/config.h>
EOF

生成的include/config.h内容为

/* Automatically generated - do not edit */ 
#define CONFIG_BOARDDIR board/samsung/tiny4412
#include <config_defaults.h>
#include <configs/tiny4412.h>
#include <asm/config.h>

 

以上是关于Tiny4412 u-boot分析u-boot配置流程分析的主要内容,如果未能解决你的问题,请参考以下文章

Tiny4412 u-boot分析u-boot启动流程

第二章Tiny4412 U-BOOT移植二 启动分析

X-001 FriendlyARM Tiny4412 uboot移植前奏

tiny4412u-boot烧写及根文件系统制作(不进入终端问题)

X-007 FriendlyARM tiny4412 u-boot移植之内存初始化

X-006 FriendlyARM tiny4412 u-boot移植之Debug串口用起来