2014-10 u-boot make xxx_defconfig 過程分析


/**
******************************************************************************
* @author    Maoxiao Hu
* @version   V1.0.0
* @date       Dec-2014
******************************************************************************
* < COPYRIGHT 2014 ISE of SHANDONG UNIVERSITY >
*******************************************************************************
**/
 
Based on u-boot-2014-10.
 
當我們執行make xxx_defconfig時,頂層Makefile中唯一的匹配目標是:
 

%config: scripts_basic outputmakefile FORCE

    +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/multiconfig.sh $@

 
依賴條件1:scripts_basic

scripts_basic:

    $(Q)$(MAKE) $(build)=scripts/basic

 

    $(Q)rm -f .tmp_quiet_recordmcount

 
依賴條件2:outputmakefile

outputmakefile:

ifneq ($(KBUILD_SRC),)

    $(Q)ln -fsn $(srctree) source

    $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile  

    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)

endif

 

此時由於KBUILD_SRC為空,所以此條依賴條件並不執行。

依賴條件3:FORCE

FORCE:

執行命令:

+$(Q)$(CONFIG_SHELL) $(srctree)/scripts/multiconfig.sh $@

幾個變量:

$(Q) = @  

$(CONFIG_SHELL) = /bin/sh

$(MAKE) = make

$@ = %config

$(srctree) = .

所以依賴條件1變成:

scripts_basic:

    @make $(build)=scripts/basic

    @rm -f .tmp_quiet_recordmcount

$(build)的定義在:scripts/Kbuild.include

build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj

KBUILD_SRC為空,所以$(if $(KBUILD_SRC),$(srctree)/)也為空。

所以變為:build := -f scripts/Makefile.build obj

所以依賴條件1變為:

scripts_basic:

    @make -f scripts/Makefile.build obj=scripts/basic

    @rm -f .tmp_quiet_recordmcount

此時主目標變成:

%config: scripts_basic

    +@/bin/sh ./scripts/multiconfig.sh %config

 

一、script_basic分析

scripts_basic:

    @make -f scripts/Makefile.build obj=scripts/basic

    @rm -f .tmp_quiet_recordmcount

在這里主要還是對@make -f scripts/Makefile.build obj=scripts/basic

這句命令的分析。

將obj = scripts/basic 這個變量名傳入Makefile.build。

二、主目標分析

%config: scripts_basic

    +@/bin/sh ./scripts/multiconfig.sh %config

加入我們輸入的命令是:make trats_defconfig

那么得到:

trats_defconfig: scripts_basic

    +@/bin/sh ./scripts/multiconfig.sh trats_defconfig

也就是將trats_defconfig這個文件傳入multiconfig.sh腳本中,然后執行。

三、調用 multiconfig.sh 腳本過程分析

下面再來解析multiconfig.sh:

target=$1

 

case $target in

 

*_defconfig)

 

    do_board_defconfig $target;;

esac

 

此時target = trats_defconfig 符合*_defconfig,執行:

do_board_defconfig trats_defconfig;

do_board_defconfig是一個內部函數,另外經過替換一些已知變量后得到:

 do_board_defconfig () {
     defconfig_path=$srctree/configs/trats_defconfig
     tmp_defconfig_path=configs/.tmp_defconfig
 
     sed -n -e '/^[+A-Z]*:/!p' -e 's/^+[A-Z]*://p'$srctree/configs/trats_defconfig > configs/.tmp_defconfig
 
     run_make_config .tmp_defconfig || {
         cleanup_after_defconfig
         exit 1
     }
 
     for img in $(get_enabled_subimages)
     do
         symbol=$(echo$img| cut -c 1 | tr '[a-z]' '[A-Z]')
 
         # defconfig for SPL, TPL:
         #   pick lines with 'S', 'T' prefix and rip the prefixes off
         sed -n -e 's/^[+A-Z]*'$symbol'[A-Z]*://p'$defconfig_path > configs/.tmp_defconfig
        run_make_config .tmp_defconfig $img || {
            cleanup_after_defconfig
            exit 1
        }
    done
    cleanup_after_defconfig
}

大概意思是先把trats_defconfig復制一份到configs/.tmp_defconfig然后,

基本可以分為紅色和粉紅色兩部分:

紅色部分:

run_make_config .tmp_defconfig || {
         cleanup_after_defconfig
         exit 1
}

再次把.tmp_defconfig當作參數給run_make_config函數,run_make_config經過已知變量代換后變成:

run_make_config () {
      target= .tmp_defconfig
      objdir=
 
      options="SRCARCH=.. KCONFIG_OBJDIR="
      build scripts/kconfig SRCARCH=.. KCONFIG_OBJDIR= .tmp_defconfig
}

最后一句再次調用build函數:

 build () {
     make -f $srctree/scripts/Makefile.build obj=“$@"
}
變量代換后變成:
make  -f $srctree/scripts/Makefile.build obj=scripts/kconfig SRCARCH=.. KCONFIG_OBJDIR= .tmp_defconfig
 
粉紅色部分:
     for img in $(get_enabled_subimages)
     do
         symbol=$(echo$img| cut -c 1 | tr '[a-z]' '[A-Z]')
 
         # defconfig for SPL, TPL:
         #   pick lines with 'S', 'T' prefix and rip the prefixes off
         sed -n -e 's/^[+A-Z]*'$symbol'[A-Z]*://p'$defconfig_path > configs/.tmp_defconfig
        run_make_config .tmp_defconfig $img || {
            cleanup_after_defconfig
            exit 1
        }

在這我們沒有定義過SPL和TPL,所以跳過這一步。

最后,其實只有一句話:

make -f $srctree/scripts/Makefile.build obj=scripts/kconfig SRCARCH=.. KCONFIG_OBJDIR= .tmp_defconfig

四、Makefile.build分析

從二三節得到了兩條待執行的指令:

make -f scripts/Makefile.build obj=scripts/basic

make -f scripts/Makefile.build obj=scripts/kconfig SRCARCH=.. KCONFIG_OBJDIR= .tmp_defconfig

先分析第1條:

make -f scripts/Makefile.build obj=scripts/basic

編譯scripts/basic.c文件

再分析第2條:

把scripts/kconfig 先傳入Makefile.build中,然后再將根據其初始化的值暴露到頂層Makefile中。

匹配kconfig/Makefile里的:

%_defconfig:$(obj)/conf

    $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)

展開后:

.tmp_defconfig:scripts/kconfig/conf

    @scripts/kconfig/conf —defconfig=arch/../configs/.tmp_defconfig Kconfig

這句話的意圖很明顯,先編譯scripts/kconfig/conf.c生成scripts/kconfig/conf,然后輸入兩個參數:

—defconfig=arch/../configs/.tmp_defconfig

Kconfig

五、scripts/kconfig/conf.c 解析

詳見以后博客。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM