u-boot编译过程分析

按照readme 所说的
make NAME_config
make


-------------------------------------------------------------------------

其中NAME_config在根目录的Makefile中,其中包含了很多
NAME_config,代表各个不同的板子。
如果要新添加一块板子的支持,需要在Makefile中新添加一个NAME_config
比如
#########################################################################
## HFRK S3C44B0 Systems
#########################################################################

hfrks3c44b0_config            unconfig
       @./mkconfig $(@:_config=) arm s3c44b0 hfrks3c44b0 hfrk
      
后面的几个参数依次表示 ARCH,CPU,BOARD,VENDOR
-------------------------------------------------------------------------


然后跟到mkconfig去看看执行了什么
根据该脚本的注释知道他做了三件事情
1)为变量赋值并输出到./include/config.mk文件的末尾(不要和根目录下面的config.mk搞混)
     对于上面的配置项
         ARCH = arm
         CPU = s3c44b0
         BOARD = hfrks3c44b0
        
2)在./include下面建立了几个链接文件
       rm -f asm
              ln -s asm-$2 asm
              rm -f asm-$2/arch
              ln -s arch-$3 asm-$2/arch
              if [ "$2" = "arm" ] ; then
                     rm -f asm-$2/proc
                     ln -s proc-armv asm-$2/proc
              fi
              也就是
         asm/ --->asm-arm
         arch-s3c44b0 --->asm-arm/arch
         proc-armv ---> asm-arm/proc
        
3)   生产config.h文件
         一般要编译一个软件,要有一个配置文件和一个makefile.u-BOOT底下,配置文件不是动态生成的。
         而是手工编写的。文件中包含了很多CFG_xxx CONFIG_xxxx这类的东西,这些在u-boot的README中
         有详细的说明。
         看此步骤的脚本:
           #
                     # 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 "" >>config.h
                     echo "#include <configs/$1.h>" >>config.h
                     exit 0
         就是在./include中生成一个config.h文件,该文件中包含了实际的config文件
         如上面的配置中:
                                   config.h如下:
                                   include <configs/hfrks3c44b0.h>
         所以hfrks3c44b0.h才是真正的配置文件,如果要添加一个新板子,要把该板子的
         配置文件放入./include/configs/底下,名字就用NAME_config中的NAME。
----------------------------------------------------------------------------------


下面看看根目录下面的config.mk
该文件也配置了一下常用的重要选项
包括
              编译器如AS,LD,CC等
              一些重要的FLAGS 如CFLAGS CPPFLAGS LDFLAGS.....
              由*.s *.c生成*.o的规则
              #########################################
              %.s:       %.S
                     $(CPP) $(AFLAGS) -o $@ $(CURDIR)/$<
              %.o:       %.S
                     $(CC) $(AFLAGS) -c -o $@ $(CURDIR)/$<
              %.o:       %.c
                     $(CC) $(CFLAGS) -c -o $@ $<

       #############################################
       还包含了几个文件
             sinclude $(TOPDIR)/$(ARCH)_config.mk     PLATFORM_CPPFLAGS += -DCONFIG_ARM -D__ARM__

             sinclude $(TOPDIR)/cpu/$(CPU)/config.mk PLATFORM_CPPFLAGS,PLATFORM_RELFLAGS
                                                                                          
             sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk   TEXT_BASE , PLATFORM_CPPFLAGS
  ------------------------------------------------------------------------------------------------
 
 
   接下来看跟目录下面的Makefile文件,这个是编译u-boot的核心
   整个Makefile可以分成下面几个部分:
                       初始化变量
                       Include文件
                       确定要编译的OBJS和LIBS
                       编译规则(就是说如果编译出Image)
                       所有的配置项 NAME_config ......
                       clean规则
                      
     下面主要看看编译规则部分:
    
       #########################################################################

                            ALL = u-boot.srec u-boot.bin System.map
                           
                            all:              $(ALL)
                           
                            u-boot.srec:       u-boot
                                          $(OBJCOPY) ${OBJCFLAGS} -O srec $< $@
                           
                            u-boot.bin:       u-boot
                                          $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@
                           
                            u-boot.img:       u-boot.bin
                                          ./tools/mkimage -A $(ARCH) -T firmware -C none \
                                          -a $(TEXT_BASE) -e 0 \
                                          -n $(shell sed -n -e 's/.*U_BOOT_VERSION//p' include/version.h | \
                                                 sed -e 's/"[        ]*$$/ for $(BOARD) board"/') \
                                          -d $< $@
                           
                            u-boot.dis:       u-boot
                                          $(OBJDUMP) -d $< > $@
                           
                            u-boot:              depend $(SUBDIRS) $(OBJS) $(LIBS) $(LDSCRIPT)
                                          UNDEF_SYM=`$(OBJDUMP) -x $(LIBS) |sed   -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
                                          $(LD) $(LDFLAGS) $$UNDEF_SYM $(OBJS) \
                                                 --start-group $(LIBS) $(PLATFORM_LIBS) --end-group \
                                                 -Map u-boot.map -o u-boot
                           
                            $(LIBS):
                                          $(MAKE) -C `dirname $@`
                           
                            $(SUBDIRS):
                                          $(MAKE) -C $@ all
                           
                            gdbtools:
                                          $(MAKE) -C tools/gdb || exit 1
                           
                            depend dep:
                                          @for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir .depend ; done
                           
                            tags:
                                          ctags -w `find $(SUBDIRS) include \
                                                        lib_generic board/$(BOARDDIR) cpu/$(CPU) lib_$(ARCH) \
                                                        fs/cramfs fs/fat fs/fdos fs/jffs2 \
                                                        net disk rtc dtt drivers drivers/sk98lin common \
                                                 \( -name CVS -prune \) -o \( -name '*.[ch]' -print \)`
                           
                            etags:
                                          etags -a `find $(SUBDIRS) include \
                                                 \( -name CVS -prune \) -o \( -name '*.[ch]' -print \)`
                           
                            System.map:       u-boot
                                          @$(NM) $< | \
                                          grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
                                          sort > System.map
                           
                            #########################################################################
                           
                            如果用make 或者make all ,可以编译出   u-boot.srec u-boot.bin System.map
                            其中       - "u-boot.bin" is a raw binary image
                                                 - "u-boot" is an image in ELF binary format
                                                 - "u-boot.srec" is in Motorola S-Record format
                                                
                            u-boot.bin:       u-boot
                            可以看出来u-boot.bin 的生成需要u-boot这个elf文件
                            从u-boot的生成过程可以看到,生成u-boot需要所有的OBJS和LIBS.
                            u-boot.img 是由u-boot自带的mkimage工具生成的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值