u-boot 编译流程 (二)

本文详细解析U-Boot.bin的构建过程,包括目标选择、依赖解析、配置文件生成及最终链接步骤。深入探讨如何从源码开始,一步步构建出U-Boot.bin。

1 U-Boot.bin

  • 研究U-Boot.bin的产生流程
  • U-Boot 2017.11
  • Source Insight 3.5
  • Ubuntu 18.04
  • arm-linux-gnueabi-xxx

1.1 find all target

首先当我们执行sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-命令后, 默认的target是all,所以我们首先在顶层Makefile中找到all, 发现如下代码片段

cfg: u-boot.cfg
all: $(ALL-y) cfg
	$(call cmd,cfgcheck,u-boot.cfg)

1.2 find $(All-y) and cfg

接着我们需要在顶层Makefile中找到$(All-y)cfg, 会发现如下代码片段, 这时后里面就有u-boot.bin

ALL-y += u-boot.srec u-boot.bin boot.sym System.map binary_size_check
  • 在源码中还会发现代码段 ALL-$(CONFIG_ONENAND_U_BOOT) += u-boot-onenand.bin, 也会增加到All-y , 本文不做进一步研究

1.3 find u-boot.bin

我们看见u-boot.bin依赖u-boot-nodtb.bin, 而u-boot-nodtb.bin依赖u-boot, 所以make需要产生u-boot.

u-boot.bin: u-boot-nodtb.bin FORCE
	$(call if_changed,copy)
u-boot-nodtb.bin: u-boot FORCE
	$(call if_changed,objcopy)
	$(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE))
	$(BOARD_SIZE_CHECK)

1.4 find u-boot

我们可以看见u-boot 依赖$(u-boot-init)$(u-boot-main)u-boot.lds ,而$(u-boot-init) $(u-boot-main) 依赖 $(u-boot-dirs), $(u-boot-dirs)依赖preparescripts, 最后make会调用命令行执行cmd_u-boot__$(u-boot-int)$(u-boot-main)通过u-boot.lds链接起来

head-y := arch/arm/cpu/$(CPU)/start.o
u-boot-init := $(head-y)
libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
u-boot-main := $(libs-y)

quiet_cmd_u-boot__ ?= LD      $@
      cmd_u-boot__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_u-boot) -o $@ \
      -T u-boot.lds $(u-boot-init)                             \
      --start-group $(u-boot-main) --end-group                 \
      $(PLATFORM_LIBS) -Map u-boot.map;                        \
      $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
      
u-boot:	$(u-boot-init) $(u-boot-main) u-boot.lds FORCE
	$(call if_changed,u-boot__)
	
$(sort $(u-boot-init) $(u-boot-main)): $(u-boot-dirs);
$(u-boot-dirs): prepare scripts
	$(Q)$(MAKE) $(build)=$@

NOTE: u-boot-init就是xxx/start.o, 而u-boot-main就是在libs-y目录下的built-in.o, 至于libs-y,自己可以细细查看

1.5 find prepare

从上面的分析看,make 首先会去执行prepare

prepare3: include/config/uboot.release
# prepare2 creates a makefile if using a separate output directory
prepare2: prepare3 outputmakefile
prepare1: prepare2 $(version_h) $(timestamp_h) \
                   include/config/auto.conf
archprepare: prepare1 scripts_basic

prepare0: archprepare FORCE
	@echo "eric_debug.....start:$@"
	$(Q)$(MAKE) $(build)=.
	@echo "eric_debug.....end:$@"

# All the preparing..
prepare: prepare0

我们直接找到prepare最后的依赖u-boot.release, 会发现uboot.release依赖include/config/auto.conf

define filechk_uboot.release
	echo "$(UBOOTVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
endef
include/config/uboot.release: include/config/auto.conf FORCE
	$(call filechk,uboot.release)

1.6 find auto.conf

KCONFIG_CONFIG = .config

#include/config/auto.conf.cmd为空
$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ; 

include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
	$(Q)$(MAKE) -f 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值