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)依赖prepare 和 scripts, 最后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

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

被折叠的 条评论
为什么被折叠?



