调用 scripts/Kbuild.include
主 Makefile 会调用文件 scripts/Kbuild.include 这个文件
交叉编译工具变量设置
上面我们只是设置了 CROSS_COMPILE 的名字,但是交叉编译器其他的工具还没有设置
导出其他变量
接下来在顶层 Makefile 会导出很多变量,
)ARCH CPU BOARD VENDOR SOC CPUDIR BOARDDIR是在外部config.mk中定义的
#
# (Tegra needs different flags for SPL.
# That's the reason why this file must be included from spl/Makefile too.
# If we did not have Tegra SoCs, build system would be much simpler...)
PLATFORM_RELFLAGS :=
PLATFORM_CPPFLAGS :=
PLATFORM_LDFLAGS :=
LDFLAGS :=
LDFLAGS_FINAL :=
OBJCOPYFLAGS :=
# clear VENDOR for tcsh
VENDOR :=
#########################################################################
ARCH := $(CONFIG_SYS_ARCH:"%"=%)
CPU := $(CONFIG_SYS_CPU:"%"=%)
ifdef CONFIG_SPL_BUILD
ifdef CONFIG_TEGRA
CPU := arm720t
endif
endif
BOARD := $(CONFIG_SYS_BOARD:"%"=%)
ifneq ($(CONFIG_SYS_VENDOR),)
VENDOR := $(CONFIG_SYS_VENDOR:"%"=%)
endif
ifneq ($(CONFIG_SYS_SOC),)
SOC := $(CONFIG_SYS_SOC:"%"=%)
endif
# Some architecture config.mk files need to know what CPUDIR is set to,
# so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
# Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
# CPU-specific code.
CPUDIR=arch/$(ARCH)/cpu$(if $(CPU),/$(CPU),)
sinclude $(srctree)/arch/$(ARCH)/config.mk # include architecture dependend rules
sinclude $(srctree)/$(CPUDIR)/config.mk # include CPU specific rules
ifdef SOC
sinclude $(srctree)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules
endif
ifneq ($(BOARD),)
ifdef VENDOR
BOARDDIR = $(VENDOR)/$(BOARD)
else
BOARDDIR = $(BOARD)
endif
endif
ifdef BOARD
sinclude $(srctree)/board/$(BOARDDIR)/config.mk # include board specific rules
endif
ifdef FTRACE
PLATFORM_CPPFLAGS += -finstrument-functions -DFTRACE
endif
# Allow use of stdint.h if available
ifneq ($(USE_STDINT),)
PLATFORM_CPPFLAGS += -DCONFIG_USE_STDINT
endif
#########################################################################
RELFLAGS := $(PLATFORM_RELFLAGS)
PLATFORM_CPPFLAGS += $(RELFLAGS)
PLATFORM_CPPFLAGS += -pipe
LDFLAGS += $(PLATFORM_LDFLAGS)
LDFLAGS_FINAL += -Bstatic
export PLATFORM_CPPFLAGS
export RELFLAGS
export LDFLAGS_FINAL
export CONFIG_STANDALONE_LOAD_ADDR
第 25 行 定 义 变 量 ARCH , 值 为 (CONFIGSYSARCH:"第26行定义变量CPU,值为(CONFIG_SYS_ARCH:"%"=%) , 也 就 是 提 取CONFIG_SYS_ARCH 里面双引号“”之间的内容。比如 CONFIG_SYS_ARCH=“arm”的话,ARCH=arm。
第 26 行定义变量 CPU,值为(CONFIGSYSARCH:"第26行定义变量CPU,值为(CONFIG_SYS_CPU:"%"=%)。
第 32 行定义变量 BOARD,值为(CONFIG_SYS_BOARD:"%"=%)。
第 34 行定义变量 VENDOR,值为(CONFIGSYSVENDOR:"第37行定义变量SOC,值为(CONFIG_SYS_VENDOR:"%"=%)。
第 37 行定义变量 SOC,值为(CONFIGSYSVENDOR:"第37行定义变量SOC,值为(CONFIG_SYS_SOC:"%"=%)。
第 44 行定义变量 CPUDIR,值为 arch/(ARCH)/cpu(ARCH)/cpu(ARCH)/cpu(if (CPU),/(CPU),/(CPU),/(CPU),)。
第 46 行 sinclude 和 include 的功能类似,在 Makefile 中都是读取指定文件内容,这里读取文件(srctree)/arch/(srctree)/arch/(srctree)/arch/(ARCH)/config.mk 的内容。 sinclude 读取的文件如果不存在的话不会报错。
第 47 行读取文件(srctree)/(srctree)/(srctree)/(CPUDIR)/config.mk 的内容。
第 50 行读取文件(srctree)/(srctree)/(srctree)/(CPUDIR)/(SOC)/config.mk的内容。第54行定义变量BOARDDIR,如果定义了VENDOR那么BOARDDIR=(SOC)/config.mk 的内容。
第 54 行 定 义 变 量 BOARDDIR , 如 果 定 义 了 VENDOR 那 么BOARDDIR=(SOC)/config.mk的内容。第54行定义变量BOARDDIR,如果定义了VENDOR那么BOARDDIR=(VENDOR)/(BOARD),否则的BOARDDIR=(BOARD),否则的BOARDDIR=(BOARD),否则的BOARDDIR=(BOARD)。
第 60 行读取文件(srctree)/board/(srctree)/board/(srctree)/board/(BOARDDIR)/config.mk。
CONFIG_SYS_ARCH、 CONFIG_SYS_CPU、 CONFIG_SYS_BOARD、CONFIG_SYS_VENDOR 和 CONFIG_SYS_SOC 这 5 个变量的值。这 5 个变量在 uboot 根目录下的.config 文件中有定义
make xxx_defconfig 过程
在编译 uboot 之前要使用“make xxx_defconfig”命令来配置 uboot