173c99d4eSJuan Castillo# 2cbd6cec3SBoyan Karatotev# Copyright (c) 2015-2025, Arm Limited and Contributors. All rights reserved. 373c99d4eSJuan Castillo# 482cb2c1aSdp-arm# SPDX-License-Identifier: BSD-3-Clause 573c99d4eSJuan Castillo# 673c99d4eSJuan Castillo 71670d9dfSEvan Lloyd# Report an error if the eval make function is not available. 81670d9dfSEvan Lloyd$(eval eval_available := T) 91670d9dfSEvan Lloydifneq (${eval_available},T) 101670d9dfSEvan Lloyd $(error This makefile only works with a Make program that supports $$(eval)) 111670d9dfSEvan Lloydendif 121670d9dfSEvan Lloyd 13231c1470SEvan Lloyd# A user defined function to recursively search for a filename below a directory 14231c1470SEvan Lloyd# $1 is the directory root of the recursive search (blank for current directory). 15231c1470SEvan Lloyd# $2 is the file name to search for. 16231c1470SEvan Lloyddefine rwildcard 17231c1470SEvan Lloyd$(strip $(foreach d,$(wildcard ${1}*),$(call rwildcard,${d}/,${2}) $(filter $(subst *,%,%${2}),${d}))) 18231c1470SEvan Lloydendef 19231c1470SEvan Lloyd 20e444763dSBoyan Karatotev# Convenience function for setting a variable to 0 if not previously set 21e444763dSBoyan Karatotev# $(eval $(call default_zero,FOO)) 22e444763dSBoyan Karatotevdefine default_zero 23e444763dSBoyan Karatotev $(eval $(1) ?= 0) 24e444763dSBoyan Karatotevendef 25e444763dSBoyan Karatotev 26e444763dSBoyan Karatotev# Convenience function for setting a list of variables to 0 if not previously set 27e444763dSBoyan Karatotev# $(eval $(call default_zeros,FOO BAR)) 28e444763dSBoyan Karatotevdefine default_zeros 29e444763dSBoyan Karatotev $(foreach var,$1,$(eval $(call default_zero,$(var)))) 30e444763dSBoyan Karatotevendef 31e444763dSBoyan Karatotev 322a71f163SGovindraj Raja# Convenience function for setting a variable to 1 if not previously set 332a71f163SGovindraj Raja# $(eval $(call default_one,FOO)) 342a71f163SGovindraj Rajadefine default_one 352a71f163SGovindraj Raja $(eval $(1) ?= 1) 362a71f163SGovindraj Rajaendef 372a71f163SGovindraj Raja 382a71f163SGovindraj Raja# Convenience function for setting a list of variables to 1 if not previously set 392a71f163SGovindraj Raja# $(eval $(call default_ones,FOO BAR)) 402a71f163SGovindraj Rajadefine default_ones 412a71f163SGovindraj Raja $(foreach var,$1,$(eval $(call default_one,$(var)))) 422a71f163SGovindraj Rajaendef 432a71f163SGovindraj Raja 44*116d2c09SLauren Wehrmeister# Convenience function for creating a build definition 45*116d2c09SLauren Wehrmeister# $(call make_define,FOO) will have: 46*116d2c09SLauren Wehrmeister# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise 47*116d2c09SLauren Wehrmeistermake_define = -D$(1)$(if $($(1)),=$($(1))) 48*116d2c09SLauren Wehrmeister 49*116d2c09SLauren Wehrmeister# Convenience function for creating multiple build definitions 50*116d2c09SLauren Wehrmeister# For BL1, BL1_CPPFLAGS += $(call make_defines,FOO BOO) 51*116d2c09SLauren Wehrmeistermake_defines = $(foreach def,$(1),$(call make_define,$(def))) 52*116d2c09SLauren Wehrmeister 5373c99d4eSJuan Castillo# Convenience function for adding build definitions 5473c99d4eSJuan Castillo# $(eval $(call add_define,FOO)) will have: 5573c99d4eSJuan Castillo# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise 5673c99d4eSJuan Castillodefine add_define 5773c99d4eSJuan Castillo DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) 5873c99d4eSJuan Castilloendef 5973c99d4eSJuan Castillo 60327131c4SLeonardo Sandoval# Convenience function for addding multiple build definitions 61327131c4SLeonardo Sandoval# $(eval $(call add_defines,FOO BOO)) 62327131c4SLeonardo Sandovaldefine add_defines 63327131c4SLeonardo Sandoval $(foreach def,$1,$(eval $(call add_define,$(def)))) 64327131c4SLeonardo Sandovalendef 65327131c4SLeonardo Sandoval 668eadeb4aSSoren Brinkmann# Convenience function for adding build definitions 678eadeb4aSSoren Brinkmann# $(eval $(call add_define_val,FOO,BAR)) will have: 688eadeb4aSSoren Brinkmann# -DFOO=BAR 698eadeb4aSSoren Brinkmanndefine add_define_val 708eadeb4aSSoren Brinkmann DEFINES += -D$(1)=$(2) 718eadeb4aSSoren Brinkmannendef 728eadeb4aSSoren Brinkmann 7373c99d4eSJuan Castillo# Convenience function for verifying option has a boolean value 7473c99d4eSJuan Castillo# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 7573c99d4eSJuan Castillodefine assert_boolean 761369fb82SYann Gautier $(if $($(1)),,$(error $(1) must not be empty)) 77be4cd40eSMasahiro Yamada $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean)) 7873c99d4eSJuan Castilloendef 7973c99d4eSJuan Castillo 80327131c4SLeonardo Sandoval# Convenience function for verifying options have boolean values 81327131c4SLeonardo Sandoval# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values 82327131c4SLeonardo Sandovaldefine assert_booleans 83327131c4SLeonardo Sandoval $(foreach bool,$1,$(eval $(call assert_boolean,$(bool)))) 84327131c4SLeonardo Sandovalendef 85327131c4SLeonardo Sandoval 86c877b414SJeenu Viswambharan0-9 := 0 1 2 3 4 5 6 7 8 9 87c877b414SJeenu Viswambharan 88c877b414SJeenu Viswambharan# Function to verify that a given option $(1) contains a numeric value 89c877b414SJeenu Viswambharandefine assert_numeric 90c877b414SJeenu Viswambharan$(if $($(1)),,$(error $(1) must not be empty)) 91c877b414SJeenu Viswambharan$(eval __numeric := $($(1))) 92c877b414SJeenu Viswambharan$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) 93c877b414SJeenu Viswambharan$(if $(__numeric),$(error $(1) must be numeric)) 94c877b414SJeenu Viswambharanendef 95c877b414SJeenu Viswambharan 96327131c4SLeonardo Sandoval# Convenience function for verifying options have numeric values 97327131c4SLeonardo Sandoval# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values 98327131c4SLeonardo Sandovaldefine assert_numerics 99327131c4SLeonardo Sandoval $(foreach num,$1,$(eval $(call assert_numeric,$(num)))) 100327131c4SLeonardo Sandovalendef 101327131c4SLeonardo Sandoval 102b45fc164SBoyan Karatotev# Convenience function to check for a given linker option. A call to 103b45fc164SBoyan Karatotev# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker, 104b45fc164SBoyan Karatotev# prefixed appropriately for the linker in use 105b45fc164SBoyan Karatotevld_option = $(call toolchain-ld-option,$(ARCH),$(1)) 106a5f09cf7SMarco Felsch 1076c2e5bf6SBoyan Karatotev# Convenience function to add a prefix to a linker flag if necessary. Useful 1086c2e5bf6SBoyan Karatotev# when the flag is known to be supported and it just needs to be prefixed 1096c2e5bf6SBoyan Karatotev# correctly. 1106c2e5bf6SBoyan Karatotevld_prefix = $(toolchain-ld-prefix-$($(ARCH)-ld-id)) 1118c7b944aSVijayenthiran Subramaniam 112dea23e24SGovindraj Raja# Convenience function to check for a given compiler option. A call to 113dea23e24SGovindraj Raja# $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler 114316f5c97SBoyan Karatotev# NOTE: consider assigning to an immediately expanded temporary variable before 115316f5c97SBoyan Karatotev# assigning. This is because variables like TF_CFLAGS are recursively expanded 116316f5c97SBoyan Karatotev# and assigning this directly will cause it to be expanded every time the 117316f5c97SBoyan Karatotev# variable is used, potentially thrashing multicore performance. 118dea23e24SGovindraj Rajadefine cc_option 119ffb77421SChris Kay $(shell if $($(ARCH)-cc) $(1) -c -x c /dev/null -o /dev/null >/dev/null 2>&1; then echo $(1); fi ) 120dea23e24SGovindraj Rajaendef 121dea23e24SGovindraj Raja 1228c7b944aSVijayenthiran Subramaniam# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to 1238c7b944aSVijayenthiran Subramaniam# $(2) and assign the sequence to $(1) 1248c7b944aSVijayenthiran Subramaniamdefine CREATE_SEQ 1258c7b944aSVijayenthiran Subramaniam$(if $(word $(2), $($(1))),\ 1268c7b944aSVijayenthiran Subramaniam $(eval $(1) += $(words $($(1))))\ 1278c7b944aSVijayenthiran Subramaniam $(eval $(1) := $(filter-out 0,$($(1)))),\ 1288c7b944aSVijayenthiran Subramaniam $(eval $(1) += $(words $($(1))))\ 1298c7b944aSVijayenthiran Subramaniam $(call CREATE_SEQ,$(1),$(2))\ 1308c7b944aSVijayenthiran Subramaniam) 1318c7b944aSVijayenthiran Subramaniamendef 1328c7b944aSVijayenthiran Subramaniam 13373c99d4eSJuan Castillo# IMG_MAPFILE defines the output file describing the memory map corresponding 13473c99d4eSJuan Castillo# to a BL stage 135434d0491SZelalem Aweke# $(1) = BL stage 13673c99d4eSJuan Castillodefine IMG_MAPFILE 137434d0491SZelalem Aweke ${BUILD_DIR}/$(1).map 13873c99d4eSJuan Castilloendef 13973c99d4eSJuan Castillo 14073c99d4eSJuan Castillo# IMG_ELF defines the elf file corresponding to a BL stage 141434d0491SZelalem Aweke# $(1) = BL stage 14273c99d4eSJuan Castillodefine IMG_ELF 143434d0491SZelalem Aweke ${BUILD_DIR}/$(1).elf 14473c99d4eSJuan Castilloendef 14573c99d4eSJuan Castillo 14673c99d4eSJuan Castillo# IMG_DUMP defines the symbols dump file corresponding to a BL stage 147434d0491SZelalem Aweke# $(1) = BL stage 14873c99d4eSJuan Castillodefine IMG_DUMP 149434d0491SZelalem Aweke ${BUILD_DIR}/$(1).dump 15073c99d4eSJuan Castilloendef 15173c99d4eSJuan Castillo 15273c99d4eSJuan Castillo# IMG_BIN defines the default image file corresponding to a BL stage 153434d0491SZelalem Aweke# $(1) = BL stage 15473c99d4eSJuan Castillodefine IMG_BIN 155434d0491SZelalem Aweke ${BUILD_PLAT}/$(1).bin 15673c99d4eSJuan Castilloendef 15773c99d4eSJuan Castillo 158c6ba9b45SSumit Garg# IMG_ENC_BIN defines the default encrypted image file corresponding to a 159c6ba9b45SSumit Garg# BL stage 160434d0491SZelalem Aweke# $(1) = BL stage 161c6ba9b45SSumit Gargdefine IMG_ENC_BIN 162434d0491SZelalem Aweke ${BUILD_PLAT}/$(1)_enc.bin 163c6ba9b45SSumit Gargendef 164c6ba9b45SSumit Garg 165c6ba9b45SSumit Garg# ENCRYPT_FW invokes enctool to encrypt firmware binary 166c6ba9b45SSumit Garg# $(1) = input firmware binary 167c6ba9b45SSumit Garg# $(2) = output encrypted firmware binary 168c6ba9b45SSumit Gargdefine ENCRYPT_FW 169c6ba9b45SSumit Garg$(2): $(1) enctool 1707c4e1eeaSChris Kay $$(s)echo " ENC $$<" 1717c4e1eeaSChris Kay $$(q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@ 172c6ba9b45SSumit Gargendef 173c6ba9b45SSumit Garg 17410cea934SMasahiro Yamada# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to 17510cea934SMasahiro Yamada# package a new payload and/or by cert_create to generate certificate. 17610cea934SMasahiro Yamada# Optionally, it adds the dependency on this payload 17773c99d4eSJuan Castillo# $(1) = payload filename (i.e. bl31.bin) 1781e0c0784SMasahiro Yamada# $(2) = command line option for the specified payload (i.e. --soc-fw) 17936af3455SMasahiro Yamada# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 1801dc0714fSMasahiro Yamada# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 181c6ba9b45SSumit Garg# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 18210cea934SMasahiro Yamadadefine TOOL_ADD_PAYLOAD 183c6ba9b45SSumit Gargifneq ($(5),) 184c6ba9b45SSumit Garg $(4)FIP_ARGS += $(2) $(5) 185c6ba9b45SSumit Garg $(if $(3),$(4)CRT_DEPS += $(1)) 186c6ba9b45SSumit Gargelse 187945b316fSMasahiro Yamada $(4)FIP_ARGS += $(2) $(1) 188c6ba9b45SSumit Garg $(if $(3),$(4)CRT_DEPS += $(3)) 189c6ba9b45SSumit Gargendif 190945b316fSMasahiro Yamada $(if $(3),$(4)FIP_DEPS += $(3)) 191f30ee0b9SMasahiro Yamada $(4)CRT_ARGS += $(2) $(1) 19273c99d4eSJuan Castilloendef 19373c99d4eSJuan Castillo 1942da522bbSMasahiro Yamada# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters 1952da522bbSMasahiro Yamada# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined. 1962da522bbSMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 1972da522bbSMasahiro Yamada# $(2) = payload filepath (ex. build/fvp/release/bl31.bin) 1982da522bbSMasahiro Yamada# $(3) = command line option for the specified payload (ex. --soc-fw) 1992da522bbSMasahiro Yamada# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 2002da522bbSMasahiro Yamada# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 201c6ba9b45SSumit Garg# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 2022da522bbSMasahiro Yamada 2032da522bbSMasahiro Yamadadefine TOOL_ADD_IMG_PAYLOAD 2042da522bbSMasahiro Yamada 205f7a41fb4SBoyan Karatotev$(eval PRE_TOOL_FILTER := $($(1)_PRE_TOOL_FILTER)) 2062da522bbSMasahiro Yamada 2072da522bbSMasahiro Yamadaifneq ($(PRE_TOOL_FILTER),) 2082da522bbSMasahiro Yamada 2092da522bbSMasahiro Yamada$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX)) 2102da522bbSMasahiro Yamada 2112da522bbSMasahiro Yamada$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2)) 2122da522bbSMasahiro Yamada 2132da522bbSMasahiro Yamada$(PROCESSED_PATH): $(4) 2142da522bbSMasahiro Yamada 215c6ba9b45SSumit Garg$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6)) 2162da522bbSMasahiro Yamada 2172da522bbSMasahiro Yamadaelse 218c6ba9b45SSumit Garg$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6)) 2192da522bbSMasahiro Yamadaendif 2202da522bbSMasahiro Yamadaendef 2212da522bbSMasahiro Yamada 2220191262dSYatharth Kochar# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation 22373c99d4eSJuan Castillo# $(1) = parameter filename 22473c99d4eSJuan Castillo# $(2) = cert_create command line option for the specified parameter 22591704d9dSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 22673c99d4eSJuan Castillodefine CERT_ADD_CMD_OPT 22791704d9dSMasahiro Yamada $(3)CRT_ARGS += $(2) $(1) 22873c99d4eSJuan Castilloendef 22973c99d4eSJuan Castillo 230c939d13aSMasahiro Yamada# TOOL_ADD_IMG allows the platform to specify an external image to be packed 231c939d13aSMasahiro Yamada# in the FIP and/or for which certificate is generated. It also adds a 232c939d13aSMasahiro Yamada# dependency on the image file, aborting the build if the file does not exist. 23333950dd8SMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 2341e0c0784SMasahiro Yamada# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc) 2351dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 236c6ba9b45SSumit Garg# $(4) = Image encryption flag (optional) (0, 1) 23773c99d4eSJuan Castillo# Example: 23833950dd8SMasahiro Yamada# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 239c939d13aSMasahiro Yamadadefine TOOL_ADD_IMG 24033950dd8SMasahiro Yamada # Build option to specify the image filename (SCP_BL2, BL33, etc) 24133950dd8SMasahiro Yamada # This is the uppercase form of the first parameter 242f7a41fb4SBoyan Karatotev $(eval BL := $(call uppercase,$(1))) 243f7a41fb4SBoyan Karatotev $(eval _V := $(BL)) 24433950dd8SMasahiro Yamada 2454727fd13SPali Rohár # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also 2464727fd13SPali Rohár # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the 2474727fd13SPali Rohár # target ${BUILD_PLAT}/${$(3)FIP_NAME}. 2484727fd13SPali Rohár $(eval check_$(1)_cmd := \ 2494727fd13SPali Rohár $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \ 2504727fd13SPali Rohár $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \ 2514727fd13SPali Rohár ) 2524727fd13SPali Rohár 253945b316fSMasahiro Yamada $(3)CRT_DEPS += check_$(1) 2544727fd13SPali Rohár CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd) 255c6ba9b45SSumit Gargifeq ($(4),1) 256c6ba9b45SSumit Garg $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin) 257c6ba9b45SSumit Garg $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN)) 258f7a41fb4SBoyan Karatotev $(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(value $(_V)),$(2),$(ENC_BIN),$(3), \ 259c6ba9b45SSumit Garg $(ENC_BIN)) 260c6ba9b45SSumit Gargelse 261f7a41fb4SBoyan Karatotev $(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3)) 262c6ba9b45SSumit Gargendif 2630191262dSYatharth Kochar 26487ebd20dSMasahiro Yamada.PHONY: check_$(1) 2650191262dSYatharth Kocharcheck_$(1): 2664727fd13SPali Rohár $(check_$(1)_cmd) 2670191262dSYatharth Kocharendef 26873c99d4eSJuan Castillo 269cf2dd17dSJuan Pablo Conde# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to 270cf2dd17dSJuan Pablo Conde# build the host tools by checking the version of OpenSSL located under 271cf2dd17dSJuan Pablo Conde# the path defined by the OPENSSL_DIR variable. It receives no parameters. 272cf2dd17dSJuan Pablo Condedefine SELECT_OPENSSL_API_VERSION 273cf2dd17dSJuan Pablo Conde # Set default value for USING_OPENSSL3 macro to 0 274cf2dd17dSJuan Pablo Conde $(eval USING_OPENSSL3 = 0) 275cf2dd17dSJuan Pablo Conde # Obtain the OpenSSL version for the build located under OPENSSL_DIR 276cf2dd17dSJuan Pablo Conde $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version)) 277cf2dd17dSJuan Pablo Conde $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO})) 278cf2dd17dSJuan Pablo Conde $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER)))) 279cf2dd17dSJuan Pablo Conde # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1 280cf2dd17dSJuan Pablo Conde $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1)) 281cf2dd17dSJuan Pablo Condeendef 282cf2dd17dSJuan Pablo Conde 28373c99d4eSJuan Castillo################################################################################ 28414db8908SMasahiro Yamada# Generic image processing filters 28514db8908SMasahiro Yamada################################################################################ 28614db8908SMasahiro Yamada 28714db8908SMasahiro Yamada# GZIP 28814db8908SMasahiro Yamadadefine GZIP_RULE 28914db8908SMasahiro Yamada$(1): $(2) 2907c4e1eeaSChris Kay $(s)echo " GZIP $$@" 2917c4e1eeaSChris Kay $(q)gzip -n -f -9 $$< --stdout > $$@ 29214db8908SMasahiro Yamadaendef 29314db8908SMasahiro Yamada 29414db8908SMasahiro YamadaGZIP_SUFFIX := .gz 29514db8908SMasahiro Yamada 29614db8908SMasahiro Yamada################################################################################ 29773c99d4eSJuan Castillo# Auxiliary macros to build TF images from sources 29873c99d4eSJuan Castillo################################################################################ 29973c99d4eSJuan Castillo 300a7bbd8e7SChris KayMAKE_DEP = -Wp,-MD,$1 -MT $2 -MP 30173c99d4eSJuan Castillo 302cbd6cec3SBoyan Karatotev# MAKE_TOOL_C builds a C source file and generates the dependency file 303cbd6cec3SBoyan Karatotev# $(1) = output directory 304cbd6cec3SBoyan Karatotev# $(2) = source file (%.c) 305cbd6cec3SBoyan Karatotev# $(3) = lowercase name of the tool 306cbd6cec3SBoyan Karatotev# $(4) = uppercase name of the tool 307cbd6cec3SBoyan Karatotevdefine MAKE_TOOL_C 308cbd6cec3SBoyan Karatotev 309cbd6cec3SBoyan Karatotev$(eval SRC := $(2)) 310cbd6cec3SBoyan Karatotev$(eval OBJ := $(patsubst %.c,$(1)/$(3)/%.o,$(SRC))) 311cbd6cec3SBoyan Karatotev$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 312cbd6cec3SBoyan Karatotev 313cbd6cec3SBoyan Karatotev$(eval TOOL_DEFINES := $($(4)_DEFINES)) 314cbd6cec3SBoyan Karatotev$(eval TOOL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS)) 315cbd6cec3SBoyan Karatotev$(eval TOOL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(TOOL_DEFINES)) $(addprefix -I,$(TOOL_INCLUDE_DIRS))) 316cbd6cec3SBoyan Karatotev$(eval TOOL_CFLAGS := $($(4)_CFLAGS)) 317cbd6cec3SBoyan Karatotev 318cbd6cec3SBoyan Karatotev$(OBJ): $(SRC) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 319cbd6cec3SBoyan Karatotev $$(s)echo " HOSTCC $$<" 320cbd6cec3SBoyan Karatotev $$(q)$(host-cc) $$(HOSTCCFLAGS) $(TOOL_CPPFLAGS) $(TOOL_CFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 321cbd6cec3SBoyan Karatotev 322cbd6cec3SBoyan Karatotev-include $(DEP) 323cbd6cec3SBoyan Karatotev 324cbd6cec3SBoyan Karatotevendef 325cbd6cec3SBoyan Karatotev 326cbd6cec3SBoyan Karatotev# MAKE_TOOL 327cbd6cec3SBoyan Karatotev# $(1) = output directory 328cbd6cec3SBoyan Karatotev# $(2) = lowercase name of the tool 329cbd6cec3SBoyan Karatotev# $(3) = uppercase name of the tool 330cbd6cec3SBoyan Karatotevdefine MAKE_TOOL 331cbd6cec3SBoyan Karatotev$(eval SRCS := $($(3)_SOURCES)) 332cbd6cec3SBoyan Karatotev$(eval OBJS := $(patsubst %.c,$(1)/$(2)/%.o,$(SRCS))) 333cbd6cec3SBoyan Karatotev$(eval DST := $(1)/$(2)/$(2)$(.exe)) 334cbd6cec3SBoyan Karatotev$(eval $(foreach src,$(SRCS),$(call MAKE_TOOL_C,$(1),$(src),$(2),$(3)))) 335cbd6cec3SBoyan Karatotev 336774fb379SBoyan Karatotev$(DST): $(OBJS) $(filter-out %.d,$(MAKEFILE_LIST)) | $(1) 337cbd6cec3SBoyan Karatotev $$(s)echo " HOSTLD $$@" 338cbd6cec3SBoyan Karatotev $$(q)$(host-cc) $${OBJS} -o $$@ $($(3)_LDFLAGS) 339cbd6cec3SBoyan Karatotev $$(s)echo 340cbd6cec3SBoyan Karatotev $$(s)echo "Built $$@ successfully" 341cbd6cec3SBoyan Karatotev $$(s)echo 342cbd6cec3SBoyan Karatotev 343cbd6cec3SBoyan Karatotevall: $(DST) 344cbd6cec3SBoyan Karatotevendef 3455fee0287SRoberto Vargas 3465fee0287SRoberto Vargas# MAKE_C_LIB builds a C source file and generates the dependency file 3475fee0287SRoberto Vargas# $(1) = output directory 3485fee0287SRoberto Vargas# $(2) = source file (%.c) 3495fee0287SRoberto Vargas# $(3) = library name 350f7a41fb4SBoyan Karatotev# $(4) = uppercase name of the library 3515fee0287SRoberto Vargasdefine MAKE_C_LIB 3525fee0287SRoberto Vargas$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 3535fee0287SRoberto Vargas$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 354f7a41fb4SBoyan Karatotev$(eval LIB := $(notdir $(1))) 3555fee0287SRoberto Vargas 356f4dd18c2SChris Kay$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 3577c4e1eeaSChris Kay $$(s)echo " CC $$<" 358d8a23ecdSSlava Andrianov $$(q)$($(ARCH)-cc) $$(LIB$(4)_CFLAGS) $$(TF_CFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 3595fee0287SRoberto Vargas 3605fee0287SRoberto Vargas-include $(DEP) 3615fee0287SRoberto Vargas 3625fee0287SRoberto Vargasendef 3635fee0287SRoberto Vargas 36470b0f278SAntonio Nino Diaz# MAKE_S_LIB builds an assembly source file and generates the dependency file 36570b0f278SAntonio Nino Diaz# $(1) = output directory 36670b0f278SAntonio Nino Diaz# $(2) = source file (%.S) 36770b0f278SAntonio Nino Diaz# $(3) = library name 368f7a41fb4SBoyan Karatotev# $(4) = uppercase name of the library 36970b0f278SAntonio Nino Diazdefine MAKE_S_LIB 37070b0f278SAntonio Nino Diaz$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 37170b0f278SAntonio Nino Diaz$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 37270b0f278SAntonio Nino Diaz 373f4dd18c2SChris Kay$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 3747c4e1eeaSChris Kay $$(s)echo " AS $$<" 3757416eb2fSBoyan Karatotev $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS) $$(ASFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 37670b0f278SAntonio Nino Diaz 37770b0f278SAntonio Nino Diaz-include $(DEP) 37870b0f278SAntonio Nino Diaz 37970b0f278SAntonio Nino Diazendef 38070b0f278SAntonio Nino Diaz 3815fee0287SRoberto Vargas 38273c99d4eSJuan Castillo# MAKE_C builds a C source file and generates the dependency file 38373c99d4eSJuan Castillo# $(1) = output directory 38473c99d4eSJuan Castillo# $(2) = source file (%.c) 385434d0491SZelalem Aweke# $(3) = BL stage 386f7a41fb4SBoyan Karatotev# $(4) = uppercase BL stage 38773c99d4eSJuan Castillodefine MAKE_C 38873c99d4eSJuan Castillo 38973c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 390710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 391a123cb14SChris Kay 392500927efSBoyan Karatotev$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES)) 393500927efSBoyan Karatotev$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS)) 394500927efSBoyan Karatotev$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS))) 395500927efSBoyan Karatotev$(eval BL_CFLAGS := $($(4)_CFLAGS)) 39673c99d4eSJuan Castillo 397f4dd18c2SChris Kay$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 3987c4e1eeaSChris Kay $$(s)echo " CC $$<" 3996bb9f053SBoyan Karatotev $$(q)$($(ARCH)-cc) $$(LTO_CFLAGS) $$(TF_CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 40073c99d4eSJuan Castillo 401710ea1d0SMasahiro Yamada-include $(DEP) 40273c99d4eSJuan Castillo 40373c99d4eSJuan Castilloendef 40473c99d4eSJuan Castillo 40573c99d4eSJuan Castillo 40673c99d4eSJuan Castillo# MAKE_S builds an assembly source file and generates the dependency file 40773c99d4eSJuan Castillo# $(1) = output directory 40873c99d4eSJuan Castillo# $(2) = assembly file (%.S) 409434d0491SZelalem Aweke# $(3) = BL stage 410f7a41fb4SBoyan Karatotev# $(4) = uppercase BL stage 41173c99d4eSJuan Castillodefine MAKE_S 41273c99d4eSJuan Castillo 41373c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 414710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 415a123cb14SChris Kay 416500927efSBoyan Karatotev$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES)) 417500927efSBoyan Karatotev$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS)) 418500927efSBoyan Karatotev$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS))) 419500927efSBoyan Karatotev$(eval BL_ASFLAGS := $($(4)_ASFLAGS)) 42073c99d4eSJuan Castillo 421f4dd18c2SChris Kay$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 4227c4e1eeaSChris Kay $$(s)echo " AS $$<" 4237416eb2fSBoyan Karatotev $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 42473c99d4eSJuan Castillo 425710ea1d0SMasahiro Yamada-include $(DEP) 42673c99d4eSJuan Castillo 42773c99d4eSJuan Castilloendef 42873c99d4eSJuan Castillo 4291e8b5354SBoyan Karatotev# MAKE_PRE run the C preprocessor on a file 4301e8b5354SBoyan Karatotev# $(1) = output file 4311e8b5354SBoyan Karatotev# $(2) = list of input files 4321e8b5354SBoyan Karatotev# $(3) = dep file 4331e8b5354SBoyan Karatotev# $(4) = list of rule-specific flags to pass 4341e8b5354SBoyan Karatotevdefine MAKE_PRE 4351e8b5354SBoyan Karatotev$(eval OUT := $(1)) 4361e8b5354SBoyan Karatotev$(eval SRC := $(2)) 4371e8b5354SBoyan Karatotev$(eval DEP := $(3)) 4381e8b5354SBoyan Karatotev$(eval CUSTOM_FLAGS := $(4)) 4391e8b5354SBoyan Karatotev$(OUT): $(SRC) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 4401e8b5354SBoyan Karatotev $$(s)echo " CPP $$<" 4411e8b5354SBoyan Karatotev $$(q)$($(ARCH)-cpp) -E -P -x assembler-with-cpp $$(TF_CFLAGS) $(CUSTOM_FLAGS) $(call MAKE_DEP,$(DEP),$(OUT)) -o $$@ $$< 4421e8b5354SBoyan Karatotevendef 44373c99d4eSJuan Castillo 44473c99d4eSJuan Castillo# MAKE_LD generate the linker script using the C preprocessor 44573c99d4eSJuan Castillo# $(1) = output linker script 44673c99d4eSJuan Castillo# $(2) = input template 447434d0491SZelalem Aweke# $(3) = BL stage 448f7a41fb4SBoyan Karatotev# $(4) = uppercase BL stage 44973c99d4eSJuan Castillodefine MAKE_LD 45073c99d4eSJuan Castillo 451710ea1d0SMasahiro Yamada$(eval DEP := $(1).d) 452a123cb14SChris Kay 453500927efSBoyan Karatotev$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES)) 454500927efSBoyan Karatotev$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS)) 455500927efSBoyan Karatotev$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS))) 4561e8b5354SBoyan Karatotev$(eval FLAGS := -D__LINKER__ $(BL_CPPFLAGS)) 45773c99d4eSJuan Castillo 4581e8b5354SBoyan Karatotev$(eval $(call MAKE_PRE,$(1),$(2),$(DEP),$(FLAGS))) 459710ea1d0SMasahiro Yamada-include $(DEP) 46073c99d4eSJuan Castillo 46173c99d4eSJuan Castilloendef 46273c99d4eSJuan Castillo 46370b0f278SAntonio Nino Diaz# MAKE_LIB_OBJS builds both C and assembly source files 4645fee0287SRoberto Vargas# $(1) = output directory 4655fee0287SRoberto Vargas# $(2) = list of source files 4665fee0287SRoberto Vargas# $(3) = name of the library 467f7a41fb4SBoyan Karatotev# $(4) = uppercase name of the library 4685fee0287SRoberto Vargasdefine MAKE_LIB_OBJS 4695fee0287SRoberto Vargas $(eval C_OBJS := $(filter %.c,$(2))) 4705fee0287SRoberto Vargas $(eval REMAIN := $(filter-out %.c,$(2))) 471f7a41fb4SBoyan Karatotev $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3),$(4)))) 4725fee0287SRoberto Vargas 47370b0f278SAntonio Nino Diaz $(eval S_OBJS := $(filter %.S,$(REMAIN))) 47470b0f278SAntonio Nino Diaz $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 475f7a41fb4SBoyan Karatotev $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3),$(4)))) 47670b0f278SAntonio Nino Diaz 4775fee0287SRoberto Vargas $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 4785fee0287SRoberto Vargasendef 4795fee0287SRoberto Vargas 48073c99d4eSJuan Castillo 48173c99d4eSJuan Castillo# MAKE_OBJS builds both C and assembly source files 48273c99d4eSJuan Castillo# $(1) = output directory 48373c99d4eSJuan Castillo# $(2) = list of source files (both C and assembly) 484434d0491SZelalem Aweke# $(3) = BL stage 485f7a41fb4SBoyan Karatotev# $(4) = uppercase BL stage 48673c99d4eSJuan Castillodefine MAKE_OBJS 48773c99d4eSJuan Castillo $(eval C_OBJS := $(filter %.c,$(2))) 48873c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.c,$(2))) 489f7a41fb4SBoyan Karatotev $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3),$(4)))) 49073c99d4eSJuan Castillo 49173c99d4eSJuan Castillo $(eval S_OBJS := $(filter %.S,$(REMAIN))) 49273c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 493f7a41fb4SBoyan Karatotev $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3),$(4)))) 49473c99d4eSJuan Castillo 49573c99d4eSJuan Castillo $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 49673c99d4eSJuan Castilloendef 49773c99d4eSJuan Castillo 49873c99d4eSJuan Castillo 49973c99d4eSJuan Castillo# NOTE: The line continuation '\' is required in the next define otherwise we 50073c99d4eSJuan Castillo# end up with a line-feed characer at the end of the last c filename. 501e7f54dbdSEvan Lloyd# Also bear this issue in mind if extending the list of supported filetypes. 50273c99d4eSJuan Castillodefine SOURCES_TO_OBJS 50373c99d4eSJuan Castillo $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ 50473c99d4eSJuan Castillo $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) 50573c99d4eSJuan Castilloendef 50673c99d4eSJuan Castillo 5075fee0287SRoberto Vargas.PHONY: libraries 5085fee0287SRoberto Vargas 5095fee0287SRoberto Vargas# MAKE_LIB macro defines the targets and options to build each BL image. 5105fee0287SRoberto Vargas# Arguments: 5115fee0287SRoberto Vargas# $(1) = Library name 5125fee0287SRoberto Vargasdefine MAKE_LIB 513f7a41fb4SBoyan Karatotev $(eval BL := $(call uppercase,$(1))) 5145fee0287SRoberto Vargas $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1)) 5155fee0287SRoberto Vargas $(eval LIB_DIR := ${BUILD_PLAT}/lib) 5165accce5bSRoberto Vargas $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 517f7a41fb4SBoyan Karatotev $(eval SOURCES := $(LIB$(BL)_SRCS)) 5185fee0287SRoberto Vargas $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 5195fee0287SRoberto Vargas 520f7a41fb4SBoyan Karatotev$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1),$(BL))) 5215fee0287SRoberto Vargas 5225fee0287SRoberto Vargaslibraries: ${LIB_DIR}/lib$(1).a 5238620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link) 524c2ad38ceSVarun WadekarLDPATHS = --userlibpath=${LIB_DIR} 525c2ad38ceSVarun WadekarLDLIBS += --library=$(1) 526c2ad38ceSVarun Wadekarelse 5275fee0287SRoberto VargasLDPATHS = -L${LIB_DIR} 5285fee0287SRoberto VargasLDLIBS += -l$(1) 529c2ad38ceSVarun Wadekarendif 5305fee0287SRoberto Vargas 5315accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 5326baf85b3SSathees BalyaLIBWRAPPER = -lwrappers 5335accce5bSRoberto Vargasendif 5345accce5bSRoberto Vargas 5355fee0287SRoberto Vargasall: ${LIB_DIR}/lib$(1).a 5365fee0287SRoberto Vargas 537f4dd18c2SChris Kay${LIB_DIR}/lib$(1).a: $(OBJS) | $$$$(@D)/ 5387c4e1eeaSChris Kay $$(s)echo " AR $$@" 5397c4e1eeaSChris Kay $$(q)$($(ARCH)-ar) cr $$@ $$? 5405fee0287SRoberto Vargasendef 5415fee0287SRoberto Vargas 54282274936SChris Kay# Generate the path to one or more preprocessed linker scripts given the paths 54382274936SChris Kay# of their sources. 54482274936SChris Kay# 54582274936SChris Kay# Arguments: 54682274936SChris Kay# $(1) = path to one or more linker script sources 54782274936SChris Kaydefine linker_script_path 54882274936SChris Kay $(patsubst %.S,$(BUILD_DIR)/%,$(1)) 54982274936SChris Kayendef 55082274936SChris Kay 55173c99d4eSJuan Castillo# MAKE_BL macro defines the targets and options to build each BL image. 55273c99d4eSJuan Castillo# Arguments: 553434d0491SZelalem Aweke# $(1) = BL stage 5548f0617efSJuan Castillo# $(2) = FIP command line option (if empty, image will not be included in the FIP) 5551dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 556c6ba9b45SSumit Garg# $(4) = BL encryption flag (optional) (0, 1) 55773c99d4eSJuan Castillodefine MAKE_BL 558f7a41fb4SBoyan Karatotev $(eval BL := $(call uppercase,$(1))) 559434d0491SZelalem Aweke $(eval BUILD_DIR := ${BUILD_PLAT}/$(1)) 560f7a41fb4SBoyan Karatotev $(eval BL_SOURCES := $($(BL)_SOURCES)) 561bb22fb84SChris Kay $(eval SOURCES := $(sort $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))) 56273c99d4eSJuan Castillo $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 56373c99d4eSJuan Castillo $(eval MAPFILE := $(call IMG_MAPFILE,$(1))) 56473c99d4eSJuan Castillo $(eval ELF := $(call IMG_ELF,$(1))) 56573c99d4eSJuan Castillo $(eval DUMP := $(call IMG_DUMP,$(1))) 56673c99d4eSJuan Castillo $(eval BIN := $(call IMG_BIN,$(1))) 567c6ba9b45SSumit Garg $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1))) 568f7a41fb4SBoyan Karatotev $(eval BL_LIBS := $($(BL)_LIBS)) 56982274936SChris Kay 570f7a41fb4SBoyan Karatotev $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(BL)_DEFAULT_LINKER_SCRIPT_SOURCE)) 57182274936SChris Kay $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE))) 57282274936SChris Kay 573f7a41fb4SBoyan Karatotev $(eval LINKER_SCRIPT_SOURCES := $($(BL)_LINKER_SCRIPT_SOURCES)) 574a6ff0067SChris Kay $(eval LINKER_SCRIPTS := $(call linker_script_path,$(LINKER_SCRIPT_SOURCES))) 5756c2e5bf6SBoyan Karatotev $(eval GNU_LINKER_ARGS := $(call ld_prefix,-Map=$(MAPFILE)) $(foreach script,$(LINKER_SCRIPTS) $(DEFAULT_LINKER_SCRIPT), $(call ld_prefix,--script $(script)))) 576a6ff0067SChris Kay 577f7a41fb4SBoyan Karatotev$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1),$(BL))) 578a6ff0067SChris Kay 579a6ff0067SChris Kay# Generate targets to preprocess each required linker script 580a6ff0067SChris Kay$(eval $(foreach source,$(DEFAULT_LINKER_SCRIPT_SOURCE) $(LINKER_SCRIPT_SOURCES), \ 581f7a41fb4SBoyan Karatotev $(call MAKE_LD,$(call linker_script_path,$(source)),$(source),$(1),$(BL)))) 582a6ff0067SChris Kay 583f7a41fb4SBoyan Karatotev$(eval BL_LDFLAGS := $($(BL)_LDFLAGS)) 58473c99d4eSJuan Castillo 5855accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 5866e622818SChris Kay$(ELF): $(BUILD_PLAT)/romlib/romlib.bin | $$$$(@D)/ 5875accce5bSRoberto Vargasendif 5885accce5bSRoberto Vargas 5898dccddc7SLeon Chen# MODULE_OBJS can be assigned by vendors with different compiled 5908dccddc7SLeon Chen# object file path, and prebuilt object file path. 5918dccddc7SLeon Chen$(eval OBJS += $(MODULE_OBJS)) 5928dccddc7SLeon Chen 593f4dd18c2SChris Kay$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) $(LINKER_SCRIPTS) | $$$$(@D)/ libraries $(BL_LIBS) 5947c4e1eeaSChris Kay $$(s)echo " LD $$@" 5958620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link) 5967c4e1eeaSChris Kay $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \ 597df52e260SChris Kay --predefine=$(call escape-shell,-D__LINKER__=$(__LINKER__)) \ 598df52e260SChris Kay --predefine=$(call escape-shell,-DTF_CFLAGS=$(TF_CFLAGS)) \ 599434d0491SZelalem Aweke --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \ 600758ccb80SChris Kay $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS) 601c2ad38ceSVarun Wadekarelse 6027cdbbea4SBoyan Karatotev $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) $(GNU_LINKER_ARGS) \ 6036baf85b3SSathees Balya $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) 604c2ad38ceSVarun Wadekarendif 6059e4609f1SChristoph Müllnerifeq ($(DISABLE_BIN_GENERATION),1) 6067c4e1eeaSChris Kay $(s)echo 6077c4e1eeaSChris Kay $(s)echo "Built $$@ successfully" 6087c4e1eeaSChris Kay $(s)echo 6099e4609f1SChristoph Müllnerendif 61073c99d4eSJuan Castillo 611f4dd18c2SChris Kay$(DUMP): $(ELF) | $$$$(@D)/ 6127c4e1eeaSChris Kay $$(s)echo " OD $$@" 6137c4e1eeaSChris Kay $$(q)$($(ARCH)-od) -dx $$< > $$@ 61473c99d4eSJuan Castillo 615f4dd18c2SChris Kay$(BIN): $(ELF) | $$$$(@D)/ 6167c4e1eeaSChris Kay $$(s)echo " BIN $$@" 6177c4e1eeaSChris Kay $$(q)$($(ARCH)-oc) -O binary $$< $$@ 6187c4e1eeaSChris Kay $(s)echo 6197c4e1eeaSChris Kay $(s)echo "Built $$@ successfully" 6207c4e1eeaSChris Kay $(s)echo 62173c99d4eSJuan Castillo 622434d0491SZelalem Aweke.PHONY: $(1) 6239e4609f1SChristoph Müllnerifeq ($(DISABLE_BIN_GENERATION),1) 624434d0491SZelalem Aweke$(1): $(ELF) $(DUMP) 6259e4609f1SChristoph Müllnerelse 626434d0491SZelalem Aweke$(1): $(BIN) $(DUMP) 6279e4609f1SChristoph Müllnerendif 62873c99d4eSJuan Castillo 629434d0491SZelalem Awekeall: $(1) 63073c99d4eSJuan Castillo 631c6ba9b45SSumit Gargifeq ($(4),1) 632c6ba9b45SSumit Garg$(call ENCRYPT_FW,$(BIN),$(ENC_BIN)) 633f7a41fb4SBoyan Karatotev$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(BIN),--$(2),$(ENC_BIN),$(3), \ 634c6ba9b45SSumit Garg $(ENC_BIN))) 635c6ba9b45SSumit Gargelse 636f7a41fb4SBoyan Karatotev$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(BIN),--$(2),$(BIN),$(3))) 637c6ba9b45SSumit Gargendif 63873c99d4eSJuan Castillo 63973c99d4eSJuan Castilloendef 64073c99d4eSJuan Castillo 64138c14d88SSoby Mathew# Convert device tree source file names to matching blobs 64238c14d88SSoby Mathew# $(1) = input dts 64303b397a8SNishanth Menondefine SOURCES_TO_DTBS 64403b397a8SNishanth Menon $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1)))) 64503b397a8SNishanth Menonendef 64603b397a8SNishanth Menon 64738c14d88SSoby Mathew# MAKE_DTB generate the Flattened device tree binary 64803b397a8SNishanth Menon# $(1) = output directory 64903b397a8SNishanth Menon# $(2) = input dts 65003b397a8SNishanth Menondefine MAKE_DTB 65103b397a8SNishanth Menon 652077b3e9aSYann Gautier# List of DTB file(s) to generate, based on DTS file basename list 65338c14d88SSoby Mathew$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 654077b3e9aSYann Gautier# List of the pre-compiled DTS file(s) 65501d237cbSYann Gautier$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2))))) 656077b3e9aSYann Gautier# Dependencies of the pre-compiled DTS file(s) on its source and included files 657077b3e9aSYann Gautier$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ))) 658077b3e9aSYann Gautier# Dependencies of the DT compilation on its pre-compiled DTS 659077b3e9aSYann Gautier$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ))) 66003b397a8SNishanth Menon 6611e8b5354SBoyan Karatotev$(eval $(call MAKE_PRE,$(DPRE),$(2),$(DTSDEP),$(DTC_CPPFLAGS))) 6627b453526SChris Kay 663f4dd18c2SChris Kay$(DOBJ): $(DPRE) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 6647c4e1eeaSChris Kay $$(s)echo " DTC $$<" 6657c4e1eeaSChris Kay $$(q)$($(ARCH)-dtc) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $$< 6661c08ff32SSalman Nabi $$($$@-after) 66703b397a8SNishanth Menon 668077b3e9aSYann Gautier-include $(DTBDEP) 669077b3e9aSYann Gautier-include $(DTSDEP) 67003b397a8SNishanth Menon 67103b397a8SNishanth Menonendef 67203b397a8SNishanth Menon 67303b397a8SNishanth Menon# MAKE_DTBS builds flattened device tree sources 67403b397a8SNishanth Menon# $(1) = output directory 67503b397a8SNishanth Menon# $(2) = list of flattened device tree source files 67603b397a8SNishanth Menondefine MAKE_DTBS 67703b397a8SNishanth Menon $(eval DOBJS := $(filter %.dts,$(2))) 67803b397a8SNishanth Menon $(eval REMAIN := $(filter-out %.dts,$(2))) 67938c14d88SSoby Mathew $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN))) 68003b397a8SNishanth Menon $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj)))) 68103b397a8SNishanth Menon 682f4dd18c2SChris Kaydtbs: $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))) 68338c14d88SSoby Mathewall: dtbs 68403b397a8SNishanth Menonendef 685