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