ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[ATF]-ATF makefile的导读

2021-06-21 15:04:37  阅读:364  来源: 互联网

标签:ATF BL makefile 导读 SOURCES call eval LINKERFILE SPD


快速链接:
.
???????????? 个人博客笔记导读目录(全部) ????????????

根据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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有