uboot mkconfig文件分析

uboot mkconfig文件分析

一、在查看uboot的Makefile会看到mkconfig,现在来看看mkconfig到底做了什么?

二、源脚本
 
#!/bin/sh -e

# Script to create header files and links to configure
# U-Boot for a specific board.
#
# Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]
#
# (C) 2002-2006 DENX Software Engineering, Wolfgang Denk <[email protected]>
#

APPEND=no       # Default: Create new config file
BOARD_NAME=""   # Name to print in make output
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

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

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

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..."

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

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

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

# Assign board directory to BOARDIR variable
if [ -z "$5" -o "$5" = "NULL" ] ; then
    BOARDDIR=$4
else
    BOARDDIR=$5/$4
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
        echo "#define CONFIG_MK_${i} 1" >>config.h ;
done

cat << EOF >> config.h
#define CONFIG_BOARDDIR board/$BOARDDIR
#include <config_defaults.h>
#include <configs/$1.h>
#include <asm/config.h>
EOF

exit 0
三、分析

1、循环检测参数
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参数切换,即原参数2变成参数1,原参数3变成参数2


-a APPEND=yes即不创建新的config文件,直接添加到旧的config文件上
-n BOARD_NAME=“-n”的后一个参数;
-t 将TARGETS文件中_替换为空

2、将后面的第一个参数赋给BOARD_NAME
并检测剩余参数个数是否合法,必须大等于4个,小等于6个
检测ARCH与第二个参数是否一致;其中ARCH是在include/config.mk定义

3、开始configure
判断原路径和目标路径是否相同(make O)可以设置目标路径,否则为当前路径
不相同:
创建include和include2目录,并建立asm软连接;
相同:
进入include,建立asm软连接

建立asm下的arch软连接
生成config.mk,主要含有ARCH、CPU、BOARD参数
生成config.h

四、总结
综上所述,mkconfig作用是完成BOARD_NAME赋值,并在include创建相应的mkconfig.mk和mkconfig.h

你可能感兴趣的:(header,脚本,null,Parameters,include,makefile)