1. 前言
UBOOT版本:uboot2018.03,开发板myimx8mmek240。
2. 概述
本文采用自顶向下的方法,从顶层目标开始到最原始的依赖。
3. u-boot编译
uboot的编译分为两步:配置、编译。
- 配置,执行make pmyimx8mmek240-8mm-2g_defconfig进行配置,在生成.config文件;
- 编译,执行make进行编译,生成u-boot*、System.map等。
4. u-boot编译过程涉及的目标分析
# 顶层Makefile
# If building an external module we do not care about the all: rule
# but instead _all depend on modules
PHONY += all //伪目标all
ifeq ($(KBUILD_EXTMOD),) //假设未定义KBUILD_EXTMOD
_all: all //_all 是顶层Makefile第一个目标,依赖是all
else
_all: modules
endif
......
all: $(ALL-y) cfg //all自身依赖于$(ALL-y)和cfg
ifeq ($(CONFIG_DM_I2C_COMPAT)$(CONFIG_SANDBOX),y)
@echo "===================== WARNING ======================"
@echo "This board uses CONFIG_DM_I2C_COMPAT. Please remove"
@echo "(possibly in a subsequent patch in your series)"
@echo "before sending patches to the mailing list."
@echo "===================================================="
endif
@# Check that this build does not use CONFIG options that we do not
@# know about unless they are in Kconfig. All the existing CONFIG
@# options are whitelisted, so new ones should not be added.
$(call cmd,cfgcheck,u-boot.cfg)
4.1 目标$(ALL-y)
# 顶层Makefile
# Read in config
-include include/config/auto.conf
......
-include include/autoconf.mk
......
# Always append ALL so that arch config.mk's can add custom ones
ALL-y += u-boot.srec u-boot.bin u-boot.sym System.map binary_size_check
ALL-$(CONFIG_ONENAND_U_BOOT) += u-boot-onenand.bin //include/config/auto.conf中未定义
ifeq ($(CONFIG_SPL_FSL_PBL),y) //include/config/auto.conf中未定义
ALL-$(CONFIG_RAMBOOT_PBL) += u-boot-with-spl-pbl.bin
else
ifneq ($(CONFIG_SECURE_BOOT), y) //include/config/auto.conf中未定义
# For Secure Boot The Image needs to be signed and Header must also
# be included. So The image has to be built explicitly
ALL-$(CONFIG_RAMBOOT_PBL) += u-boot.pbl
endif
endif
ALL-$(CONFIG_SPL) += spl/u-boot-spl.bin //关注:include/config/auto.conf中有定义
ifeq ($(CONFIG_MX6)$(CONFIG_SECURE_BOOT), yy) //include/config/auto.conf中未定义
ALL-$(CONFIG_SPL_FRAMEWORK) += u-boot-ivt.img
else
ALL-$(CONFIG_SPL_FRAMEWORK) += u-boot.img //关注:include/config/auto.conf中有定义
endif
ALL-$(CONFIG_TPL) += tpl/u-boot-tpl.bin //include/config/auto.conf中未定义
ALL-$(CONFIG_OF_SEPARATE) += u-boot.dtb //关注:include/config/auto.conf中有定义
ifeq ($(CONFIG_SPL_FRAMEWORK),y) //关注:include/config/auto.conf中有定义
ALL-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img //关注:include/config/auto.conf中有定义
endif
ALL-$(CONFIG_OF_HOSTFILE) += u-boot.dtb //include/config/auto.conf中未定义
ifneq ($(CONFIG_SPL_TARGET),) //include/config/auto.conf中未定义
ALL-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
endif
ALL-$(CONFIG_REMAKE_ELF) += u-boot.elf //关注:include include/autoconf.mk中有定义
ALL-$(CONFIG_EFI_APP) += u-boot-app.efi //include/config/auto.conf中未定义
ALL-$(CONFIG_EFI_STUB) += u-boot-payload.efi //include/config/auto.conf中未定义
ifneq ($(BUILD_ROM)$(CONFIG_BUILD_ROM),) //include/config/auto.conf中未定义
ALL-$(CONFIG_X86_RESET_VECTOR) += u-boot.rom
endif
# enable combined SPL/u-boot/dtb rules for tegra
ifeq ($(CONFIG_TEGRA)$(CONFIG_SPL),yy) //include/config/auto.conf中未定义
ALL-y += u-boot-tegra.bin u-boot-nodtb-tegra.bin
ALL-$(CONFIG_OF_SEPARATE) += u-boot-dtb-tegra