[ATF]-ATF makefile的导读
作者:互联网
根据BLx_SOURCE是否定义,来选择编译的镜像. BLx_SOURCE的第一次定义一般在plat/xxx/platform.mk
ifdef BL1_SOURCES
NEED_BL1 := yes
include bl1/bl1.mk
endif
ifdef BL2_SOURCES
NEED_BL2 := yes
include bl2/bl2.mk
endif
ifdef BL2U_SOURCES
NEED_BL2U := yes
include bl2u/bl2u.mk
endif
ifdef BL31_SOURCES
# When booting an EL3 payload, there is no need to compile the BL31 image nor
# put it in the FIP.
ifndef EL3_PAYLOAD_BASE
NEED_BL31 := yes
include bl31/bl31.mk
endif
endif
这里是平台的定义,选择哪一个SPD(secure payload dispatcher)
即当敲击make -C $DIRPATH RESET_TO_BL31=1 PLAT=xxx all,传过来的PLAT值
ifeq (${PLAT},xxx)
SPD := opteed
endif
ifneq (${SPD},none)
ifdef EL3_PAYLOAD_BASE
$(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
$(warning "The SPD and its BL32 companion will be present but ignored.")
endif
# We expect to locate an spd.mk under the specified SPD directory
SPD_MAKE := $(shell m="services/spd/${SPD}/${SPD}.mk"; [ -f "$$m" ] && echo "$$m")
ifeq (${SPD_MAKE},)
$(error Error: No services/spd/${SPD}/${SPD}.mk located)
endif
$(info Including ${SPD_MAKE})
include ${SPD_MAKE}
# If there's BL32 companion for the chosen SPD, we expect that the SPD's
# Makefile would set NEED_BL32 to "yes". In this case, the build system
# supports two mutually exclusive options:
# * BL32 is built from source: then BL32_SOURCES must contain the list
# of source files to build BL32
# * BL32 is a prebuilt binary: then BL32 must point to the image file
# that will be included in the FIP
# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
# over the sources.
endif
给NEED_BL31宏赋值
ifdef BL31_SOURCES
# When booting an EL3 payload, there is no need to compile the BL31 image nor
# put it in the FIP.
ifndef EL3_PAYLOAD_BASE
NEED_BL31 := yes
include bl31/bl31.mk
endif
endif
调用MAKE_BL(31,in_fip)编译BL31
(Makefile)
ifeq (${NEED_BL31},yes)
BL31_SOURCES += ${SPD_SOURCES}
$(if ${BL31}, $(eval $(call MAKE_TOOL_ARGS,31,${BL31},in_fip)),\
$(eval $(call MAKE_BL,31,in_fip)))
endif
MAKE_BL函数的实现:
(make_helpers/build_macros.mk)
# MAKE_BL macro defines the targets and options to build each BL image.
# Arguments:
# $(1) = BL stage (2, 2u, 30, 31, 32, 33)
# $(2) = In FIP (false if empty)
define MAKE_BL
$(eval BUILD_DIR := ${BUILD_PLAT}/bl$(1))
$(eval BL_SOURCES := $(BL$(call uppercase,$(1))_SOURCES))
$(eval SOURCES := $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))
$(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
$(eval LINKERFILE := $(call IMG_LINKERFILE,$(1)))
$(eval MAPFILE := $(call IMG_MAPFILE,$(1)))
$(eval ELF := $(call IMG_ELF,$(1)))
$(eval DUMP := $(call IMG_DUMP,$(1)))
$(eval BIN := $(call IMG_BIN,$(1)))
$(eval BL_LINKERFILE := $(BL$(call uppercase,$(1))_LINKERFILE))
$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE)))
$(BUILD_DIR):
$$(Q)mkdir -p "$$@"
$(ELF): $(OBJS) $(LINKERFILE)
@echo " LD $$@"
@echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
const char version_string[] = "${VERSION_STRING}";' | \
$$(CC) $$(CFLAGS) -xc - -o $(BUILD_DIR)/build_message.o
$$(Q)$$(LD) -o $$@ $$(LDFLAGS) -Map=$(MAPFILE) --script $(LINKERFILE) \
$(BUILD_DIR)/build_message.o $(OBJS)
$(DUMP): $(ELF)
@echo " OD $$@"
$${Q}$${OD} -dx $$< > $$@
$(BIN): $(ELF)
@echo " BIN $$@"
$$(Q)$$(OC) -O binary $$< $$@
@echo
@echo "Built $$@ successfully"
@echo
ifeq ($(1),31)
cp $$@ $(BUILD_PLAT)/sloader.img
endif
.PHONY: bl$(1)
bl$(1): $(BUILD_DIR) $(BIN) $(DUMP)
all: bl$(1)
$(eval $(call MAKE_TOOL_ARGS,$(1),$(BIN),$(2)))
endef
ELF的生成使用到了LINKERFILE,而LINKERFILE就等于bl31.ld.S
$(eval BL_LINKERFILE := $(BL$(call uppercase,$(1))_LINKERFILE))
$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE)))
BL31_LINKERFILE := bl31/bl31.ld.S
标签:ATF,BL,makefile,导读,SOURCES,call,eval,LINKERFILE,SPD 来源: https://blog.51cto.com/u_15278218/2931168