UBOOT之分析配置過程 make 100ask24x0_config
阿新 • • 發佈:2018-11-21
windows啟動和嵌入式系統啟動對比,bootloader的終極目的是啟動核心。
分析配置過程 make 100ask24x0_config
開啟頂層Makefile
我們在編譯uboot是執行 make 100ask24x0_config
100ask24x0_config : unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
make 100ask24x0_config 就相當於執行
@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
- @$(MKCONFIG)
@表示在執行命令時不輸出命令本身,只輸出結果
$(MKCONFIG)表示(MKCONFIG) 這個變數的值mkconfig - $(@:_config=)
這裡用到了Makefile變數替換規則, $(VAR:A=B)表示替換變數 $ VAR中的A為B,
即把 [email protected]中的_config替換為空變成smdk2410, [email protected] 目標檔案, $^ 所有的依賴檔案, $< 第一個依賴檔案。
$(@:_config=) =100ask24x0 表示把 [email protected]中的_config替換為空 得到smdk2410;
綜上make 100ask24x0_config 其實就是執行
mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0
Makefile中
SRCTREE := $(CURDIR)
$(SRCTREE)/mkconfig MakeFile所在目錄
所以開啟MakeFile所在目錄中的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]>
#
# mkconfig 100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0
$0 $1 $2 $3 $4 $5 $6
APPEND=no # Default: Create new config file
BOARD_NAME="" # Name to print in make output
while [ $# -gt 0 ] ; do # 引數總數大於0 第一個引數是不是-- -a -n 沒有跳出
case "$1" in
--) shift ; break ;;
-a) shift ; APPEND=yes ;;
-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
*) break ;;
esac
done
[ "${BOARD_NAME}" ] || BOARD_NAME="$1" #如果BOARD_NAME已經被定義了,就執行前者,如果沒有定義就執
#行BOARD_NAME="$1,12行說明沒有定義,所以BOARD_NAME="100ask24x0"
[ $# -lt 4 ] && exit 1
[ $# -gt 6 ] && exit 1 #mkconfig引數的個數<4或者大於6個退出,這裡它有6個引數,不退出
echo "Configuring for ${BOARD_NAME} board..."
#
# Create link to architecture specific headers
#
if [ "$SRCTREE" != "$OBJTREE" ] ; then
#有Makefile 知OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
#如果定義了BUILD_DIR,OBJTREE=BUILD_DIR,否則OBJTREE=CURDIR
#由Makefile知BUILD_DIR := $(O) ,BUILD_DIR沒有被定義
#所以SRCTREE:= $(CURDIR)
mkdir -p ${OBJTREE}/include
mkdir -p ${OBJTREE}/include2
cd ${OBJTREE}/include2
rm -f asm
ln -s ${SRCTREE}/include/asm-$2 asm
LNPREFIX="../../include2/asm/"
cd ../include
rm -rf asm-$2
rm -f asm
mkdir asm-$2
ln -s asm-$2 asm
else #執行else分支
cd ./include
rm -f asm #刪除原來的asm
ln -s asm-$2 asm # ln -s asm-arm asm 建立一個新的連結目錄 asm-->asm-arm
fi
rm -f asm-$2/arch
if [ -z "$6" -o "$6" = "NULL" ] ; then #-z為空的意思 -o 或者的意思 這裡判斷$6是否為空或者賦值為
#為NULL 這裡$6 s3c24x0,執行else分支
ln -s ${LNPREFIX}arch-$3 asm-$2/arch
else
ln -s ${LNPREFIX}arch-$6 asm-$2/arch
# ln -s arch-s3c24x0 asm-arm/arch 結果 asm-arm/arch -->arch-s3c24x0
fi
if [ "$2" = "arm" ] ; then
rm -f asm-$2/proc
ln -s ${LNPREFIX}proc-armv asm-$2/proc
#ln -s proc-armv asm-arm/proc 連結結果:asm-arm/proc-->proc-armv
fi
#
# Create include file for Make
#
echo "ARCH = $2" > config.mk # >表示新建一個檔案 >>表示追加,將某一個內容追加進去
echo "CPU = $3" >> config.mk
echo "BOARD = $4" >> config.mk
# 上面三條語句執行完的結果是建立了config.mk 裡面的內容是:
# ARCH=arm
#CPU=arm920t
#BOARD=h100ask24x0
[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk
# 如果第五個引數存在,並且不等於NULL,執行echo後面的,這第五個引數為NULL
[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk
#第六個引數存在並且不等於NULL,SOC=s3c24x0,放入 include/config.mk
#程式執行到這裡,config.mk的內容:
# ARCH=arm
#CPU=arm920t
#BOARD=h100ask24x0
#SOC=s3c24x0
# Create board specific header file
#
if [ "$APPEND" = "yes" ] # Append to existing config file 由第一行知道APPEND=no 執行else分支
then
echo >> config.h
else
> config.h # Create new config file >表示新建一個檔案,這裡新建一個config.h檔案
fi
echo "/* Automatically generated - do not edit */" >>config.h
echo "#include <configs/$1.h>" >>config.h
# config.h的內容是
# /* Automatically generated - do not edit */
# #include <configs/100ask24x0.h>"
exit 0
總結一下:執行@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
產生一下結果:
1.BOARD_NAME 等於$1
2.建立到平臺/開發板相關標頭檔案的連結
3.建立頂層Makefile包含的檔案include/config.mk
內容如下:
ARCH = arm
CPU = arm920t
BOARD = 100ask24x0
SOC = s3c24x0
4.建立開發板相關的標頭檔案include/config.h
內容如下:
/* Automatically generated - do not edit */
#include <configs/100ask24x0.h>