一,Kbuild.include
此文件位于scripts下,含有很多变量函数,以下是文件截取
# echo command. # Short version is used, if $(quiet) equals `quiet_', otherwise full one. echo-cmd = $(if $($(quiet)cmd_$(1)), echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) # 找到比目标更新或者依赖项不存在条件. # PHONY targets skipped in both cases. any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) # Check if both arguments has same arguments. Result is empty string if equal. # User may override this check using make KBUILD_NOCMDDEP=1 arg-check = $(if $(strip $(cmd_$@)),,1) # Execute command if command has changed or prerequisite(s) are updated. #使用举例 #u-boot.bin: u-boot-dtb.bin FORCE # $(call if_changed,copy) if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ @set -e; \ $(echo-cmd) $(cmd_$(1)); \ printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) # Execute the command and also postprocess generated .d dependencies file. if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ @set -e; \ $(echo-cmd) $(cmd_$(1)); \ scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ rm -f $(depfile); \ mv -f $(dot-target).tmp $(dot-target).cmd) # Usage: $(call if_changed_rule,foo) # Will check if $(cmd_foo) or any of the prerequisites changed, # and if so will execute $(rule_foo). if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \ @set -e; \ $(rule_$(1)))
1.any-prereq 变量是检查:$(filter-out $(PHONY),$?)是否依赖项第日期比较新;$(filter-out $(PHONY) $(wildcard $^),$^)依赖项是否缺失;arg-check 检查cmd_u-boot.bin是否存在,不存在会导致生成
2.@set -e;有错误就i退出
3.$(echo-cmd)在终端输出当前的命令
4.$(cmd_$(1)) 执行相关命令,如果any-prereq与arg-check为真就执行,这些命令的定义在顶层Makefile中,如cmd_copy;举的例子最终$(cmd_$(1))=$(cmd_copy)=cp $< $@
二,make xxx_defconfig
用到了 xxx_defconfig 文件,比如 mx6ull_alientek_emmc_defconfig。这里会将mx6ull_alientek_emmc_defconfig 中的配置输出到.config 文件中,最终生成 uboot 根目录下的.config 文件。这个命令主要是生成了fixdep工具以及生成.confg文件
如下是此命令对应的菜单:
%config: scripts_basic outputmakefile FORCE
$(Q)$(MAKE) $(build)=scripts/kconfig $@ #从 scripts/Kbuild.include可得 build=-f $(srctree)/scripts/Makefile.build obj
1.依赖项scripts_basic
经过查看outputmakefile为空,scripts_basic是有实际动作的,先分析scripts_basic,如下,scripts_basic最终只干了一件事生成fixdep,而且fixdep的生成规则是在scripts/basic/Makefile定义的
scripts_basic: $(Q)$(MAKE) $(build)=scripts/basic #也就是 make -f ./scripts/Makefile.build obj=scripts/basic,调用了子文件夹的MakeFile,而且没有最终目标,故子Makefile第一个目标就是"__build" #./scripts/Makefile.build 中的默认目标__build: __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \ $(subdir-ym) $(always) @: #$(KBUILD_BUILTIN)=1;$(KBUILD_MODULES)=0,故简化为 __build: $(builtin-target) $(lib-target) $(extra-y)) $(subdir-ym) $(always) @: #然而这些变量仅$(always)有值故在此简化后最终为 __build: scripts/basic/fixdep @:
2.$(Q)$(MAKE) $(build)=scripts/kconfig $@
这条命令最终生成了.config文件。实际为:make -f ./scripts/Makefile.build obj=scripts/kconfig **_defconfig,与scripts_basic 的区别是1.有最终的目标:***_defconfig 2.obj的值不一样scripts/basic.在Kbuild.include找不到**_defconfig,实际上前面已经include ./scripts/kconfig/Makefile了。如下是./scripts/kconfig/Makefile 中**_defconfig的生成规则:
%_defconfig: $(obj)/conf
$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
#$(obj)=./scripts/kconfig ;Kconfig=Kconfig;$(SRCARCH)= ..; 可以简化为
%_defconfig: scripts/kconfig/conf
scripts/kconfig/conf --defconfig=arch/../configs/$@ Kconfig
#其实就是
%_defconfig: scripts/kconfig/conf
scripts/kconfig/conf --defconfig=configs/***_defconfig Kconfig
3.fixdep工具作用
fixdep <depfile> <target> <cmdline>
将生成u-boot的%.c编译输出为%.o是会调用rule_cc_o_c,rule_cc_o_c又会调用fixdep生成%.o的依赖文件.%.cmd;新生成一个目标时,调用if_changed_dep检测并更新依赖文件,其中if_changed_dep会调用fixdep去处理依赖文件,但是将用于生成u-boot的%.c文件编译输出为%.o的规则除外;
三,make 过程
1.All-y决定最终生成文件
不难发信啊All-y控制着一系列u-boot.*文件是否生成
2.libs-y决定uboot所支持的命令
不难发信啊All-y控制着一系列u-boot.*文件是否生成
3.文件生成命令
#u-boot.bin: #copy 复制获得 u-boot.bin: u-boot-nodtb.bin FORCE $(call if_changed,copy) #u-boot-nodtb.bin: arm-linux-gnueabihf-objcopy 获得 u-boot-nodtb.bin: u-boot FORCE $(call if_changed,objcopy) #arm-linux-gnueabihf-objcopy --gap-fill=0xff $< $@ $(call DO_STATIC_RELA,$<,$@,$(CONFIG_SYS_TEXT_BASE)) $(BOARD_SIZE_CHECK)
u-boot->$(OBJCOPY) –gap-fill=0xff $(OBJCOPYFLAGS) \
$(OBJCOPYFLAGS_$(@F)) $< $@