1# 2# Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved. 3# 4# SPDX-License-Identifier: BSD-3-Clause 5# 6 7# Report an error if the eval make function is not available. 8$(eval eval_available := T) 9ifneq (${eval_available},T) 10 $(error This makefile only works with a Make program that supports $$(eval)) 11endif 12 13# Some utility macros for manipulating awkward (whitespace) characters. 14blank := 15space :=${blank} ${blank} 16 17# A user defined function to recursively search for a filename below a directory 18# $1 is the directory root of the recursive search (blank for current directory). 19# $2 is the file name to search for. 20define rwildcard 21$(strip $(foreach d,$(wildcard ${1}*),$(call rwildcard,${d}/,${2}) $(filter $(subst *,%,%${2}),${d}))) 22endef 23 24# This table is used in converting lower case to upper case. 25uppercase_table:=a,A b,B c,C d,D e,E f,F g,G h,H i,I j,J k,K l,L m,M n,N o,O p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z 26 27# Internal macro used for converting lower case to upper case. 28# $(1) = upper case table 29# $(2) = String to convert 30define uppercase_internal 31$(if $(1),$$(subst $(firstword $(1)),$(call uppercase_internal,$(wordlist 2,$(words $(1)),$(1)),$(2))),$(2)) 32endef 33 34# A macro for converting a string to upper case 35# $(1) = String to convert 36define uppercase 37$(eval uppercase_result:=$(call uppercase_internal,$(uppercase_table),$(1)))$(uppercase_result) 38endef 39 40# Convenience function for adding build definitions 41# $(eval $(call add_define,FOO)) will have: 42# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise 43define add_define 44 DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) 45endef 46 47 48# Convenience function for addding multiple build definitions 49# $(eval $(call add_defines,FOO BOO)) 50define add_defines 51 $(foreach def,$1,$(eval $(call add_define,$(def)))) 52endef 53 54# Convenience function for adding build definitions 55# $(eval $(call add_define_val,FOO,BAR)) will have: 56# -DFOO=BAR 57define add_define_val 58 DEFINES += -D$(1)=$(2) 59endef 60 61# Convenience function for verifying option has a boolean value 62# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 63define assert_boolean 64 $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean)) 65endef 66 67# Convenience function for verifying options have boolean values 68# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values 69define assert_booleans 70 $(foreach bool,$1,$(eval $(call assert_boolean,$(bool)))) 71endef 72 730-9 := 0 1 2 3 4 5 6 7 8 9 74 75# Function to verify that a given option $(1) contains a numeric value 76define assert_numeric 77$(if $($(1)),,$(error $(1) must not be empty)) 78$(eval __numeric := $($(1))) 79$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) 80$(if $(__numeric),$(error $(1) must be numeric)) 81endef 82 83# Convenience function for verifying options have numeric values 84# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values 85define assert_numerics 86 $(foreach num,$1,$(eval $(call assert_numeric,$(num)))) 87endef 88 89# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to 90# $(2) and assign the sequence to $(1) 91define CREATE_SEQ 92$(if $(word $(2), $($(1))),\ 93 $(eval $(1) += $(words $($(1))))\ 94 $(eval $(1) := $(filter-out 0,$($(1)))),\ 95 $(eval $(1) += $(words $($(1))))\ 96 $(call CREATE_SEQ,$(1),$(2))\ 97) 98endef 99 100# IMG_MAPFILE defines the output file describing the memory map corresponding 101# to a BL stage 102# $(1) = BL stage 103define IMG_MAPFILE 104 ${BUILD_DIR}/$(1).map 105endef 106 107# IMG_ELF defines the elf file corresponding to a BL stage 108# $(1) = BL stage 109define IMG_ELF 110 ${BUILD_DIR}/$(1).elf 111endef 112 113# IMG_DUMP defines the symbols dump file corresponding to a BL stage 114# $(1) = BL stage 115define IMG_DUMP 116 ${BUILD_DIR}/$(1).dump 117endef 118 119# IMG_BIN defines the default image file corresponding to a BL stage 120# $(1) = BL stage 121define IMG_BIN 122 ${BUILD_PLAT}/$(1).bin 123endef 124 125# IMG_ENC_BIN defines the default encrypted image file corresponding to a 126# BL stage 127# $(1) = BL stage 128define IMG_ENC_BIN 129 ${BUILD_PLAT}/$(1)_enc.bin 130endef 131 132# ENCRYPT_FW invokes enctool to encrypt firmware binary 133# $(1) = input firmware binary 134# $(2) = output encrypted firmware binary 135define ENCRYPT_FW 136$(2): $(1) enctool 137 $$(ECHO) " ENC $$<" 138 $$(Q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@ 139endef 140 141# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to 142# package a new payload and/or by cert_create to generate certificate. 143# Optionally, it adds the dependency on this payload 144# $(1) = payload filename (i.e. bl31.bin) 145# $(2) = command line option for the specified payload (i.e. --soc-fw) 146# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 147# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 148# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 149define TOOL_ADD_PAYLOAD 150ifneq ($(5),) 151 $(4)FIP_ARGS += $(2) $(5) 152 $(if $(3),$(4)CRT_DEPS += $(1)) 153else 154 $(4)FIP_ARGS += $(2) $(1) 155 $(if $(3),$(4)CRT_DEPS += $(3)) 156endif 157 $(if $(3),$(4)FIP_DEPS += $(3)) 158 $(4)CRT_ARGS += $(2) $(1) 159endef 160 161# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters 162# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined. 163# $(1) = image_type (scp_bl2, bl33, etc.) 164# $(2) = payload filepath (ex. build/fvp/release/bl31.bin) 165# $(3) = command line option for the specified payload (ex. --soc-fw) 166# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 167# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 168# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 169 170define TOOL_ADD_IMG_PAYLOAD 171 172$(eval PRE_TOOL_FILTER := $($(call uppercase,$(1))_PRE_TOOL_FILTER)) 173 174ifneq ($(PRE_TOOL_FILTER),) 175 176$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX)) 177 178$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2)) 179 180$(PROCESSED_PATH): $(4) 181 182$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6)) 183 184else 185$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6)) 186endif 187endef 188 189# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation 190# $(1) = parameter filename 191# $(2) = cert_create command line option for the specified parameter 192# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 193define CERT_ADD_CMD_OPT 194 $(3)CRT_ARGS += $(2) $(1) 195endef 196 197# TOOL_ADD_IMG allows the platform to specify an external image to be packed 198# in the FIP and/or for which certificate is generated. It also adds a 199# dependency on the image file, aborting the build if the file does not exist. 200# $(1) = image_type (scp_bl2, bl33, etc.) 201# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc) 202# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 203# $(4) = Image encryption flag (optional) (0, 1) 204# Example: 205# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 206define TOOL_ADD_IMG 207 # Build option to specify the image filename (SCP_BL2, BL33, etc) 208 # This is the uppercase form of the first parameter 209 $(eval _V := $(call uppercase,$(1))) 210 211 # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also 212 # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the 213 # target ${BUILD_PLAT}/${$(3)FIP_NAME}. 214 $(eval check_$(1)_cmd := \ 215 $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \ 216 $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \ 217 ) 218 219 $(3)CRT_DEPS += check_$(1) 220 CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd) 221ifeq ($(4),1) 222 $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin) 223 $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN)) 224 $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(ENC_BIN),$(3), \ 225 $(ENC_BIN)) 226else 227 $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3)) 228endif 229 230.PHONY: check_$(1) 231check_$(1): 232 $(check_$(1)_cmd) 233endef 234 235# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to 236# build the host tools by checking the version of OpenSSL located under 237# the path defined by the OPENSSL_DIR variable. It receives no parameters. 238define SELECT_OPENSSL_API_VERSION 239 # Set default value for USING_OPENSSL3 macro to 0 240 $(eval USING_OPENSSL3 = 0) 241 # Obtain the OpenSSL version for the build located under OPENSSL_DIR 242 $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version)) 243 $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO})) 244 $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER)))) 245 # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1 246 $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1)) 247endef 248 249################################################################################ 250# Generic image processing filters 251################################################################################ 252 253# GZIP 254define GZIP_RULE 255$(1): $(2) 256 $(ECHO) " GZIP $$@" 257 $(Q)gzip -n -f -9 $$< --stdout > $$@ 258endef 259 260GZIP_SUFFIX := .gz 261 262################################################################################ 263# Auxiliary macros to build TF images from sources 264################################################################################ 265 266MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP 267 268 269# MAKE_C_LIB builds a C source file and generates the dependency file 270# $(1) = output directory 271# $(2) = source file (%.c) 272# $(3) = library name 273define MAKE_C_LIB 274$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 275$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 276 277$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs 278 $$(ECHO) " CC $$<" 279 $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@ 280 281-include $(DEP) 282 283endef 284 285# MAKE_S_LIB builds an assembly source file and generates the dependency file 286# $(1) = output directory 287# $(2) = source file (%.S) 288# $(3) = library name 289define MAKE_S_LIB 290$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 291$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 292 293$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs 294 $$(ECHO) " AS $$<" 295 $$(Q)$$(AS) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@ 296 297-include $(DEP) 298 299endef 300 301 302# MAKE_C builds a C source file and generates the dependency file 303# $(1) = output directory 304# $(2) = source file (%.c) 305# $(3) = BL stage 306define MAKE_C 307 308$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 309$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 310$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3))) 311$(eval BL_CFLAGS := $($(call uppercase,$(3))_CFLAGS)) 312 313$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 314 $$(ECHO) " CC $$<" 315 $$(Q)$$(CC) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@ 316 317-include $(DEP) 318 319endef 320 321 322# MAKE_S builds an assembly source file and generates the dependency file 323# $(1) = output directory 324# $(2) = assembly file (%.S) 325# $(3) = BL stage 326define MAKE_S 327 328$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 329$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 330$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3))) 331$(eval BL_ASFLAGS := $($(call uppercase,$(3))_ASFLAGS)) 332 333$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 334 $$(ECHO) " AS $$<" 335 $$(Q)$$(AS) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@ 336 337-include $(DEP) 338 339endef 340 341 342# MAKE_LD generate the linker script using the C preprocessor 343# $(1) = output linker script 344# $(2) = input template 345# $(3) = BL stage 346define MAKE_LD 347 348$(eval DEP := $(1).d) 349$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3))) 350 351$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 352 $$(ECHO) " PP $$<" 353 $$(Q)$$(CPP) $$(CPPFLAGS) $(BL_CPPFLAGS) $(TF_CFLAGS_$(ARCH)) -P -x assembler-with-cpp -D__LINKER__ $(MAKE_DEP) -o $$@ $$< 354 355-include $(DEP) 356 357endef 358 359# MAKE_LIB_OBJS builds both C and assembly source files 360# $(1) = output directory 361# $(2) = list of source files 362# $(3) = name of the library 363define MAKE_LIB_OBJS 364 $(eval C_OBJS := $(filter %.c,$(2))) 365 $(eval REMAIN := $(filter-out %.c,$(2))) 366 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3)))) 367 368 $(eval S_OBJS := $(filter %.S,$(REMAIN))) 369 $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 370 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3)))) 371 372 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 373endef 374 375 376# MAKE_OBJS builds both C and assembly source files 377# $(1) = output directory 378# $(2) = list of source files (both C and assembly) 379# $(3) = BL stage 380define MAKE_OBJS 381 $(eval C_OBJS := $(filter %.c,$(2))) 382 $(eval REMAIN := $(filter-out %.c,$(2))) 383 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3)))) 384 385 $(eval S_OBJS := $(filter %.S,$(REMAIN))) 386 $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 387 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3)))) 388 389 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 390endef 391 392 393# NOTE: The line continuation '\' is required in the next define otherwise we 394# end up with a line-feed characer at the end of the last c filename. 395# Also bear this issue in mind if extending the list of supported filetypes. 396define SOURCES_TO_OBJS 397 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ 398 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) 399endef 400 401# Allow overriding the timestamp, for example for reproducible builds, or to 402# synchronize timestamps across multiple projects. 403# This must be set to a C string (including quotes where applicable). 404BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__ 405 406.PHONY: libraries 407 408# MAKE_LIB_DIRS macro defines the target for the directory where 409# libraries are created 410define MAKE_LIB_DIRS 411 $(eval LIB_DIR := ${BUILD_PLAT}/lib) 412 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 413 $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper) 414 $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT})) 415 $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT})) 416 $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT})) 417endef 418 419# MAKE_LIB macro defines the targets and options to build each BL image. 420# Arguments: 421# $(1) = Library name 422define MAKE_LIB 423 $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1)) 424 $(eval LIB_DIR := ${BUILD_PLAT}/lib) 425 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 426 $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS)) 427 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 428 429$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) 430$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) 431 432.PHONY : lib${1}_dirs 433lib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR} 434libraries: ${LIB_DIR}/lib$(1).a 435ifneq ($(findstring armlink,$(notdir $(LD))),) 436LDPATHS = --userlibpath=${LIB_DIR} 437LDLIBS += --library=$(1) 438else 439LDPATHS = -L${LIB_DIR} 440LDLIBS += -l$(1) 441endif 442 443ifeq ($(USE_ROMLIB),1) 444LIBWRAPPER = -lwrappers 445endif 446 447all: ${LIB_DIR}/lib$(1).a 448 449${LIB_DIR}/lib$(1).a: $(OBJS) 450 $$(ECHO) " AR $$@" 451 $$(Q)$$(AR) cr $$@ $$? 452endef 453 454# Generate the path to one or more preprocessed linker scripts given the paths 455# of their sources. 456# 457# Arguments: 458# $(1) = path to one or more linker script sources 459define linker_script_path 460 $(patsubst %.S,$(BUILD_DIR)/%,$(1)) 461endef 462 463# MAKE_BL macro defines the targets and options to build each BL image. 464# Arguments: 465# $(1) = BL stage 466# $(2) = FIP command line option (if empty, image will not be included in the FIP) 467# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 468# $(4) = BL encryption flag (optional) (0, 1) 469define MAKE_BL 470 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1)) 471 $(eval BL_SOURCES := $($(call uppercase,$(1))_SOURCES)) 472 $(eval SOURCES := $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES)) 473 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 474 $(eval MAPFILE := $(call IMG_MAPFILE,$(1))) 475 $(eval ELF := $(call IMG_ELF,$(1))) 476 $(eval DUMP := $(call IMG_DUMP,$(1))) 477 $(eval BIN := $(call IMG_BIN,$(1))) 478 $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1))) 479 $(eval BL_LIBS := $($(call uppercase,$(1))_LIBS)) 480 481 $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(call uppercase,$(1))_DEFAULT_LINKER_SCRIPT_SOURCE)) 482 $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE))) 483 484 # We use sort only to get a list of unique object directory names. 485 # ordering is not relevant but sort removes duplicates. 486 $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${DEFAULT_LINKER_SCRIPT}))) 487 # The $(dir ) function leaves a trailing / on the directory names 488 # Rip off the / to match directory names with make rule targets. 489 $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS))) 490 491# Create generators for object directory structure 492 493$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) 494 495$(eval $(foreach objd,${OBJ_DIRS}, 496 $(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) 497 498.PHONY : ${1}_dirs 499 500# We use order-only prerequisites to ensure that directories are created, 501# but do not cause re-builds every time a file is written. 502${1}_dirs: | ${OBJ_DIRS} 503 504$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) 505$(eval $(call MAKE_LD,$(DEFAULT_LINKER_SCRIPT),$(DEFAULT_LINKER_SCRIPT_SOURCE),$(1))) 506$(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS)) 507 508ifeq ($(USE_ROMLIB),1) 509$(ELF): romlib.bin 510endif 511 512# MODULE_OBJS can be assigned by vendors with different compiled 513# object file path, and prebuilt object file path. 514$(eval OBJS += $(MODULE_OBJS)) 515 516$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) | $(1)_dirs libraries $(BL_LIBS) 517 $$(ECHO) " LD $$@" 518ifdef MAKE_BUILD_STRINGS 519 $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o) 520else 521 @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \ 522 const char version_string[] = "${VERSION_STRING}"; \ 523 const char version[] = "${VERSION}";' | \ 524 $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o 525endif 526ifneq ($(findstring armlink,$(notdir $(LD))),) 527 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \ 528 --predefine="-D__LINKER__=$(__LINKER__)" \ 529 --predefine="-DTF_CFLAGS=$(TF_CFLAGS)" \ 530 --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \ 531 $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) \ 532 $(BUILD_DIR)/build_message.o $(OBJS) 533else ifneq ($(findstring gcc,$(notdir $(LD))),) 534 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Wl,-Map=$(MAPFILE) \ 535 $(EXTRA_LINKERFILE) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) $(BUILD_DIR)/build_message.o \ 536 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) 537else 538 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \ 539 --script $(DEFAULT_LINKER_SCRIPT) $(BUILD_DIR)/build_message.o \ 540 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) 541endif 542ifeq ($(DISABLE_BIN_GENERATION),1) 543 @${ECHO_BLANK_LINE} 544 @echo "Built $$@ successfully" 545 @${ECHO_BLANK_LINE} 546endif 547 548$(DUMP): $(ELF) 549 $${ECHO} " OD $$@" 550 $${Q}$${OD} -dx $$< > $$@ 551 552$(BIN): $(ELF) 553 $${ECHO} " BIN $$@" 554 $$(Q)$$(OC) -O binary $$< $$@ 555 @${ECHO_BLANK_LINE} 556 @echo "Built $$@ successfully" 557 @${ECHO_BLANK_LINE} 558 559.PHONY: $(1) 560ifeq ($(DISABLE_BIN_GENERATION),1) 561$(1): $(ELF) $(DUMP) 562else 563$(1): $(BIN) $(DUMP) 564endif 565 566all: $(1) 567 568ifeq ($(4),1) 569$(call ENCRYPT_FW,$(BIN),$(ENC_BIN)) 570$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(ENC_BIN),$(3), \ 571 $(ENC_BIN))) 572else 573$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(BIN),$(3))) 574endif 575 576endef 577 578# Convert device tree source file names to matching blobs 579# $(1) = input dts 580define SOURCES_TO_DTBS 581 $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1)))) 582endef 583 584# MAKE_FDT_DIRS macro creates the prerequisite directories that host the 585# FDT binaries 586# $(1) = output directory 587# $(2) = input dts 588define MAKE_FDT_DIRS 589 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 590 $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS}))) 591 # The $(dir ) function leaves a trailing / on the directory names 592 # Rip off the / to match directory names with make rule targets. 593 $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS))) 594 595$(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) 596 597fdt_dirs: ${DTB_DIRS} 598endef 599 600# MAKE_DTB generate the Flattened device tree binary 601# $(1) = output directory 602# $(2) = input dts 603define MAKE_DTB 604 605# List of DTB file(s) to generate, based on DTS file basename list 606$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 607# List of the pre-compiled DTS file(s) 608$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2))))) 609# Dependencies of the pre-compiled DTS file(s) on its source and included files 610$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ))) 611# Dependencies of the DT compilation on its pre-compiled DTS 612$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ))) 613 614$(DOBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs 615 $${ECHO} " CPP $$<" 616 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 617 $$(Q)$$(PP) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$< 618 $${ECHO} " DTC $$<" 619 $$(Q)$$(DTC) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $(DPRE) 620 621-include $(DTBDEP) 622-include $(DTSDEP) 623 624endef 625 626# MAKE_DTBS builds flattened device tree sources 627# $(1) = output directory 628# $(2) = list of flattened device tree source files 629define MAKE_DTBS 630 $(eval DOBJS := $(filter %.dts,$(2))) 631 $(eval REMAIN := $(filter-out %.dts,$(2))) 632 $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN))) 633 $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj)))) 634 635 $(eval $(call MAKE_FDT_DIRS,$(1),$(2))) 636 637dtbs: $(DTBS) 638all: dtbs 639endef 640