新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > GNU ARM匯編--(十七)u-boot的makefile和mkconfig解讀

GNU ARM匯編--(十七)u-boot的makefile和mkconfig解讀

作者: 時(shí)間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
  • AFLAGS:=$(AFLAGS_DEBUG)-D__ASSEMBLY__$(CPPFLAGS)
  • LDFLAGS+=$(PLATFORM_LDFLAGS)
  • LDFLAGS_FINAL+=-Bstatic
  • LDFLAGS_u-boot+=-T$(obj)u-boot.lds$(LDFLAGS_FINAL)
  • ifneq($(CONFIG_SYS_TEXT_BASE),)
  • LDFLAGS_u-boot+=-Ttext$(CONFIG_SYS_TEXT_BASE)
  • endif
  • LDFLAGS_u-boot-spl+=-T$(obj)u-boot-spl.lds$(LDFLAGS_FINAL)
  • ifneq($(CONFIG_SPL_TEXT_BASE),)
  • LDFLAGS_u-boot-spl+=-Ttext$(CONFIG_SPL_TEXT_BASE)
  • endif
  • #LocationofausableBFDlibrary,wherewedefine"usable"as
  • #"builtfor${HOST},supports${TARGET}".Sensiblevaluesare
  • #-Whencross-compiling:therootofthecross-environment
  • #-Linux/ppc(native):/usr
  • #-NetBSD/ppc(native):youlose...(mustextractthesefromthe
  • #binutilsbuilddirectory,plusthenativeandU-Bootinclude
  • #filesdontlikeeachother)
  • #
  • #Sofar,thisisusedonlybytools/gdb/Makefile.
  • ifeq($(HOSTOS),darwin)
  • BFD_ROOT_DIR=/usr/local/tools
  • else
  • ifeq($(HOSTARCH),$(ARCH))
  • #native
  • BFD_ROOT_DIR=/usr
  • else
  • #BFD_ROOT_DIR=/LinuxPPC/CDK#Linux/i386
  • #BFD_ROOT_DIR=/usr/pkg/cross#NetBSD/i386
  • BFD_ROOT_DIR=/opt/powerpc
  • endif
  • endif
  • #########################################################################
  • exportHOSTCCHOSTCFLAGSHOSTLDFLAGSPEDCFLAGSHOSTSTRIPCROSS_COMPILE
  • ASLDCCCPPARNMSTRIPOBJCOPYOBJDUMPMAKE
  • exportCONFIG_SYS_TEXT_BASEPLATFORM_CPPFLAGSPLATFORM_RELFLAGSCPPFLAGSCFLAGSAFLAGS
  • #########################################################################
  • #Allowboardstousecustomoptimizeflagsonaperdir/filebasis
  • BCURDIR=$(subst$(SRCTREE)/,,$(CURDIR:$(obj)%=%))
  • ALL_AFLAGS=$(AFLAGS)$(AFLAGS_$(BCURDIR)/$(@F))$(AFLAGS_$(BCURDIR))
  • ALL_CFLAGS=$(CFLAGS)$(CFLAGS_$(BCURDIR)/$(@F))$(CFLAGS_$(BCURDIR))
  • EXTRA_CPPFLAGS=$(CPPFLAGS_$(BCURDIR)/$(@F))$(CPPFLAGS_$(BCURDIR))
  • ALL_CFLAGS+=$(EXTRA_CPPFLAGS)
  • #The_DEPversionusesthe$
  • #Seerules.mk
  • EXTRA_CPPFLAGS_DEP=$(CPPFLAGS_$(BCURDIR)/$(addsuffix.o,$(basename$<)))
  • $(CPPFLAGS_$(BCURDIR))
  • $(obj)%.s:%.S
  • $(CPP)$(ALL_AFLAGS)-o$@$<
  • $(obj)%.o:%.S
  • $(CC)$(ALL_AFLAGS)-o$@$<-c
  • $(obj)%.o:%.c
  • $(CC)$(ALL_CFLAGS)-o$@$<-c
  • $(obj)%.i:%.c
  • $(CPP)$(ALL_CFLAGS)-o$@$<-c
  • $(obj)%.s:%.c
  • $(CC)$(ALL_CFLAGS)-o$@$<-c-S
  • #########################################################################
  • #Ifthelistofobjectstolinkisempty,justcreateanemptybuilt-in.o
  • cmd_link_o_target=$(if$(strip$1),
  • $(LD)$(LDFLAGS)-r-o$@$1,
  • rm-f$@;$(AR)rcs$@)
  • #########################################################################

  • 主要是一些變量和函數(shù)的定義,編譯鏈接的參數(shù)設(shè)置以及依賴規(guī)則.

    本文引用地址:http://m.butianyuan.cn/article/201611/321714.htm

    最后分析下make:

    [cpp]view plaincopy
    1. $(obj)include/autoconf.mk.dep:$(obj)include/config.hinclude/common.h
    2. @$(XECHO)Generating$@;
    3. set-e;
    4. :Generatethedependancies;
    5. $(CC)-xc-DDO_DEPS_ONLY-M$(CFLAGS)$(CPPFLAGS)
    6. -MQ$(obj)include/autoconf.mkinclude/common.h>$@
    7. $(obj)include/autoconf.mk:$(obj)include/config.h
    8. @$(XECHO)Generating$@;
    9. set-e;
    10. :Extracttheconfigmacros;
    11. $(CPP)$(CFLAGS)-DDO_DEPS_ONLY-dMinclude/common.h|
    12. sed-n-ftools/scripts/define2mk.sed>$@.tmp&&
    13. mv$@.tmp$@
    第一個(gè)是生成include/autoconf.mk的依賴文件

    第二個(gè)是根據(jù)include/config.h的文件內(nèi)容,利用tools/scripts/define2mk.sed腳本將所有的CONFIG提取到autoconf.mk文件中

    終極目標(biāo)是:ALL-y += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map

    u-boot.srec也是根據(jù)u-boot用objcopy工具搞出來的,不知的什么作用

    u-boot.bin也是根據(jù)u-boot用objcopy工具搞出來的,最終燒寫的二進(jìn)制bin檔

    System.map是符號(hào)列表

    [cpp]view plaincopy
    1. $(obj)u-boot.bin:$(obj)u-boot
    2. $(OBJCOPY)${OBJCFLAGS}-Obinary$<$@
    3. $(BOARD_SIZE_CHECK)
    4. ###################################################################################
    5. #要得到最后的u-boot.bin,必須得到u-boot.u-boot.bin是最后要燒寫到板子上的二進(jìn)制bin檔
    6. #利用objcopy來得到這個(gè)二進(jìn)制文件($@是規(guī)則的目標(biāo)文件名,$<是規(guī)則的第一個(gè)依賴文件名)
    7. #調(diào)用BOARD_SIZE_CHECK
    8. ###################################################################################

    u-boot的依賴分析:
    $(obj)u-boot: depend
    $(SUBDIR_TOOLS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds
    $(GEN_UBOOT)


    u-boot 依賴depend $(SUBDIR_TOOLS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT) $(obj)u-boot.lds
    然后用$(GEN_UBOOT)生成最后的u-boot,GEN_UBOOT就是用ld鏈接的過程


    a.看一下depend:
    depend dep: $(TIMESTAMP_FILE) $(VERSION_FILE)
    $(obj)include/autoconf.mk
    $(obj)include/generated/generic-asm-offsets.h
    $(obj)include/generated/asm-offsets.h
    for dir in $(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR) ; do
    $(MAKE) -C $$dir _depend ; done
    對(duì)$(SUBDIRS) $(CPUDIR) $(LDSCRIPT_MAKEFILE_DIR)目錄生成depend依賴文件;
    而_depend是在rules.mk中定義的,利用CC的-M選項(xiàng)生成依賴文件.

    b.看一下$(SUBDIR_TOOLS):
    tools目錄

    c.看一下$(OBJS):
    $(OBJS): depend
    $(MAKE) -C $(CPUDIR) $(if $(REMOTE_BUILD),$@,$(notdir $@))
    看下$(if $(REMOTE_BUILD),$@,$(notdir $@))
    因?yàn)?(REMOTE_BUILD)為空,所以返回的是$(notdir $@)的值;
    因?yàn)?@指的是規(guī)則的目標(biāo),所以就是$(OBJS),而$(OBJS)就是arch/arm/cpu/arm920t/start.o
    notdir內(nèi)嵌函數(shù)返回的文件名;所以返回start.o
    執(zhí)行makc -C arch/arm/cpu/arm920t start.o

    d.$(LIBBOARD)
    $(LIBBOARD): depend $(LIBS)
    $(MAKE) -C $(dir $(subst $(obj),,$@))
    執(zhí)行make -C board/samsung/smdk2410

    e.$(LIBS)
    $(LIBS): depend $(SUBDIR_TOOLS)
    $(MAKE) -C $(dir $(subst $(obj),,$@))
    進(jìn)入到LIBS包含的很多目錄,執(zhí)行make,生成很多.a文件.

    f.$(LDSCRIPT)
    $(LDSCRIPT): depend
    $(MAKE) -C $(dir $@) $(notdir $@)
    在前面找鏈接腳本時(shí)已然知曉LDSCRIPT就是arch/arm/cpu/u-boot.lds
    執(zhí)行make -C arch/arm/cpu u-boot.lds 這個(gè)目錄沒有makefile,這什么意思??。。?br />
    g.$(obj)u-boot.lds
    $(obj)u-boot.lds: $(LDSCRIPT)
    $(CPP) $(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@

    這些就是編譯uboot的規(guī)則,分析的比較粗糙,在移植的過程中肯定還會(huì)遇到各式各樣的問題,在移植過程中再進(jìn)一步深入并修正.
    上一頁 1 2 3 4 下一頁

    關(guān)鍵詞: ARM匯編u-bootmakefilemkconfi

    評(píng)論


    相關(guān)推薦

    技術(shù)專區(qū)

    關(guān)閉