173c99d4eSJuan Castillo# 2781cb314SChris Kay# Copyright (c) 2015-2024, 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 205ba8f669SYatharth Kochar# This table is used in converting lower case to upper case. 215ba8f669SYatharth Kocharuppercase_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 225ba8f669SYatharth Kochar 235ba8f669SYatharth Kochar# Internal macro used for converting lower case to upper case. 245ba8f669SYatharth Kochar# $(1) = upper case table 255ba8f669SYatharth Kochar# $(2) = String to convert 265ba8f669SYatharth Kochardefine uppercase_internal 275ba8f669SYatharth Kochar$(if $(1),$$(subst $(firstword $(1)),$(call uppercase_internal,$(wordlist 2,$(words $(1)),$(1)),$(2))),$(2)) 285ba8f669SYatharth Kocharendef 295ba8f669SYatharth Kochar 305ba8f669SYatharth Kochar# A macro for converting a string to upper case 315ba8f669SYatharth Kochar# $(1) = String to convert 325ba8f669SYatharth Kochardefine uppercase 335ba8f669SYatharth Kochar$(eval uppercase_result:=$(call uppercase_internal,$(uppercase_table),$(1)))$(uppercase_result) 345ba8f669SYatharth Kocharendef 355ba8f669SYatharth Kochar 36e444763dSBoyan Karatotev# Convenience function for setting a variable to 0 if not previously set 37e444763dSBoyan Karatotev# $(eval $(call default_zero,FOO)) 38e444763dSBoyan Karatotevdefine default_zero 39e444763dSBoyan Karatotev $(eval $(1) ?= 0) 40e444763dSBoyan Karatotevendef 41e444763dSBoyan Karatotev 42e444763dSBoyan Karatotev# Convenience function for setting a list of variables to 0 if not previously set 43e444763dSBoyan Karatotev# $(eval $(call default_zeros,FOO BAR)) 44e444763dSBoyan Karatotevdefine default_zeros 45e444763dSBoyan Karatotev $(foreach var,$1,$(eval $(call default_zero,$(var)))) 46e444763dSBoyan Karatotevendef 47e444763dSBoyan Karatotev 482a71f163SGovindraj Raja# Convenience function for setting a variable to 1 if not previously set 492a71f163SGovindraj Raja# $(eval $(call default_one,FOO)) 502a71f163SGovindraj Rajadefine default_one 512a71f163SGovindraj Raja $(eval $(1) ?= 1) 522a71f163SGovindraj Rajaendef 532a71f163SGovindraj Raja 542a71f163SGovindraj Raja# Convenience function for setting a list of variables to 1 if not previously set 552a71f163SGovindraj Raja# $(eval $(call default_ones,FOO BAR)) 562a71f163SGovindraj Rajadefine default_ones 572a71f163SGovindraj Raja $(foreach var,$1,$(eval $(call default_one,$(var)))) 582a71f163SGovindraj Rajaendef 592a71f163SGovindraj Raja 6073c99d4eSJuan Castillo# Convenience function for adding build definitions 6173c99d4eSJuan Castillo# $(eval $(call add_define,FOO)) will have: 6273c99d4eSJuan Castillo# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise 6373c99d4eSJuan Castillodefine add_define 6473c99d4eSJuan Castillo DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) 6573c99d4eSJuan Castilloendef 6673c99d4eSJuan Castillo 67327131c4SLeonardo Sandoval# Convenience function for addding multiple build definitions 68327131c4SLeonardo Sandoval# $(eval $(call add_defines,FOO BOO)) 69327131c4SLeonardo Sandovaldefine add_defines 70327131c4SLeonardo Sandoval $(foreach def,$1,$(eval $(call add_define,$(def)))) 71327131c4SLeonardo Sandovalendef 72327131c4SLeonardo Sandoval 738eadeb4aSSoren Brinkmann# Convenience function for adding build definitions 748eadeb4aSSoren Brinkmann# $(eval $(call add_define_val,FOO,BAR)) will have: 758eadeb4aSSoren Brinkmann# -DFOO=BAR 768eadeb4aSSoren Brinkmanndefine add_define_val 778eadeb4aSSoren Brinkmann DEFINES += -D$(1)=$(2) 788eadeb4aSSoren Brinkmannendef 798eadeb4aSSoren Brinkmann 8073c99d4eSJuan Castillo# Convenience function for verifying option has a boolean value 8173c99d4eSJuan Castillo# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 8273c99d4eSJuan Castillodefine assert_boolean 831369fb82SYann Gautier $(if $($(1)),,$(error $(1) must not be empty)) 84be4cd40eSMasahiro Yamada $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean)) 8573c99d4eSJuan Castilloendef 8673c99d4eSJuan Castillo 87327131c4SLeonardo Sandoval# Convenience function for verifying options have boolean values 88327131c4SLeonardo Sandoval# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values 89327131c4SLeonardo Sandovaldefine assert_booleans 90327131c4SLeonardo Sandoval $(foreach bool,$1,$(eval $(call assert_boolean,$(bool)))) 91327131c4SLeonardo Sandovalendef 92327131c4SLeonardo Sandoval 93c877b414SJeenu Viswambharan0-9 := 0 1 2 3 4 5 6 7 8 9 94c877b414SJeenu Viswambharan 95c877b414SJeenu Viswambharan# Function to verify that a given option $(1) contains a numeric value 96c877b414SJeenu Viswambharandefine assert_numeric 97c877b414SJeenu Viswambharan$(if $($(1)),,$(error $(1) must not be empty)) 98c877b414SJeenu Viswambharan$(eval __numeric := $($(1))) 99c877b414SJeenu Viswambharan$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) 100c877b414SJeenu Viswambharan$(if $(__numeric),$(error $(1) must be numeric)) 101c877b414SJeenu Viswambharanendef 102c877b414SJeenu Viswambharan 103327131c4SLeonardo Sandoval# Convenience function for verifying options have numeric values 104327131c4SLeonardo Sandoval# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values 105327131c4SLeonardo Sandovaldefine assert_numerics 106327131c4SLeonardo Sandoval $(foreach num,$1,$(eval $(call assert_numeric,$(num)))) 107327131c4SLeonardo Sandovalendef 108327131c4SLeonardo Sandoval 109a5f09cf7SMarco Felsch# Convenience function to check for a given linker option. An call to 110a5f09cf7SMarco Felsch# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker 111ffb77421SChris Kayld_option = $(shell $($(ARCH)-ld) $(1) -Wl,--version >/dev/null 2>&1 || $($(ARCH)-ld) $(1) -v >/dev/null 2>&1 && echo $(1)) 112a5f09cf7SMarco Felsch 113dea23e24SGovindraj Raja# Convenience function to check for a given compiler option. A call to 114dea23e24SGovindraj Raja# $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler 115dea23e24SGovindraj Rajadefine cc_option 116ffb77421SChris Kay $(shell if $($(ARCH)-cc) $(1) -c -x c /dev/null -o /dev/null >/dev/null 2>&1; then echo $(1); fi ) 117dea23e24SGovindraj Rajaendef 118dea23e24SGovindraj Raja 1198c7b944aSVijayenthiran Subramaniam# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to 1208c7b944aSVijayenthiran Subramaniam# $(2) and assign the sequence to $(1) 1218c7b944aSVijayenthiran Subramaniamdefine CREATE_SEQ 1228c7b944aSVijayenthiran Subramaniam$(if $(word $(2), $($(1))),\ 1238c7b944aSVijayenthiran Subramaniam $(eval $(1) += $(words $($(1))))\ 1248c7b944aSVijayenthiran Subramaniam $(eval $(1) := $(filter-out 0,$($(1)))),\ 1258c7b944aSVijayenthiran Subramaniam $(eval $(1) += $(words $($(1))))\ 1268c7b944aSVijayenthiran Subramaniam $(call CREATE_SEQ,$(1),$(2))\ 1278c7b944aSVijayenthiran Subramaniam) 1288c7b944aSVijayenthiran Subramaniamendef 1298c7b944aSVijayenthiran Subramaniam 13073c99d4eSJuan Castillo# IMG_MAPFILE defines the output file describing the memory map corresponding 13173c99d4eSJuan Castillo# to a BL stage 132434d0491SZelalem Aweke# $(1) = BL stage 13373c99d4eSJuan Castillodefine IMG_MAPFILE 134434d0491SZelalem Aweke ${BUILD_DIR}/$(1).map 13573c99d4eSJuan Castilloendef 13673c99d4eSJuan Castillo 13773c99d4eSJuan Castillo# IMG_ELF defines the elf file corresponding to a BL stage 138434d0491SZelalem Aweke# $(1) = BL stage 13973c99d4eSJuan Castillodefine IMG_ELF 140434d0491SZelalem Aweke ${BUILD_DIR}/$(1).elf 14173c99d4eSJuan Castilloendef 14273c99d4eSJuan Castillo 14373c99d4eSJuan Castillo# IMG_DUMP defines the symbols dump file corresponding to a BL stage 144434d0491SZelalem Aweke# $(1) = BL stage 14573c99d4eSJuan Castillodefine IMG_DUMP 146434d0491SZelalem Aweke ${BUILD_DIR}/$(1).dump 14773c99d4eSJuan Castilloendef 14873c99d4eSJuan Castillo 14973c99d4eSJuan Castillo# IMG_BIN defines the default image file corresponding to a BL stage 150434d0491SZelalem Aweke# $(1) = BL stage 15173c99d4eSJuan Castillodefine IMG_BIN 152434d0491SZelalem Aweke ${BUILD_PLAT}/$(1).bin 15373c99d4eSJuan Castilloendef 15473c99d4eSJuan Castillo 155c6ba9b45SSumit Garg# IMG_ENC_BIN defines the default encrypted image file corresponding to a 156c6ba9b45SSumit Garg# BL stage 157434d0491SZelalem Aweke# $(1) = BL stage 158c6ba9b45SSumit Gargdefine IMG_ENC_BIN 159434d0491SZelalem Aweke ${BUILD_PLAT}/$(1)_enc.bin 160c6ba9b45SSumit Gargendef 161c6ba9b45SSumit Garg 162c6ba9b45SSumit Garg# ENCRYPT_FW invokes enctool to encrypt firmware binary 163c6ba9b45SSumit Garg# $(1) = input firmware binary 164c6ba9b45SSumit Garg# $(2) = output encrypted firmware binary 165c6ba9b45SSumit Gargdefine ENCRYPT_FW 166c6ba9b45SSumit Garg$(2): $(1) enctool 167c6ba9b45SSumit Garg $$(ECHO) " ENC $$<" 168c6ba9b45SSumit Garg $$(Q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@ 169c6ba9b45SSumit Gargendef 170c6ba9b45SSumit Garg 17110cea934SMasahiro Yamada# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to 17210cea934SMasahiro Yamada# package a new payload and/or by cert_create to generate certificate. 17310cea934SMasahiro Yamada# Optionally, it adds the dependency on this payload 17473c99d4eSJuan Castillo# $(1) = payload filename (i.e. bl31.bin) 1751e0c0784SMasahiro Yamada# $(2) = command line option for the specified payload (i.e. --soc-fw) 17636af3455SMasahiro Yamada# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 1771dc0714fSMasahiro Yamada# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 178c6ba9b45SSumit Garg# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 17910cea934SMasahiro Yamadadefine TOOL_ADD_PAYLOAD 180c6ba9b45SSumit Gargifneq ($(5),) 181c6ba9b45SSumit Garg $(4)FIP_ARGS += $(2) $(5) 182c6ba9b45SSumit Garg $(if $(3),$(4)CRT_DEPS += $(1)) 183c6ba9b45SSumit Gargelse 184945b316fSMasahiro Yamada $(4)FIP_ARGS += $(2) $(1) 185c6ba9b45SSumit Garg $(if $(3),$(4)CRT_DEPS += $(3)) 186c6ba9b45SSumit Gargendif 187945b316fSMasahiro Yamada $(if $(3),$(4)FIP_DEPS += $(3)) 188f30ee0b9SMasahiro Yamada $(4)CRT_ARGS += $(2) $(1) 18973c99d4eSJuan Castilloendef 19073c99d4eSJuan Castillo 1912da522bbSMasahiro Yamada# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters 1922da522bbSMasahiro Yamada# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined. 1932da522bbSMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 1942da522bbSMasahiro Yamada# $(2) = payload filepath (ex. build/fvp/release/bl31.bin) 1952da522bbSMasahiro Yamada# $(3) = command line option for the specified payload (ex. --soc-fw) 1962da522bbSMasahiro Yamada# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 1972da522bbSMasahiro Yamada# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 198c6ba9b45SSumit Garg# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 1992da522bbSMasahiro Yamada 2002da522bbSMasahiro Yamadadefine TOOL_ADD_IMG_PAYLOAD 2012da522bbSMasahiro Yamada 2022da522bbSMasahiro Yamada$(eval PRE_TOOL_FILTER := $($(call uppercase,$(1))_PRE_TOOL_FILTER)) 2032da522bbSMasahiro Yamada 2042da522bbSMasahiro Yamadaifneq ($(PRE_TOOL_FILTER),) 2052da522bbSMasahiro Yamada 2062da522bbSMasahiro Yamada$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX)) 2072da522bbSMasahiro Yamada 2082da522bbSMasahiro Yamada$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2)) 2092da522bbSMasahiro Yamada 2102da522bbSMasahiro Yamada$(PROCESSED_PATH): $(4) 2112da522bbSMasahiro Yamada 212c6ba9b45SSumit Garg$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6)) 2132da522bbSMasahiro Yamada 2142da522bbSMasahiro Yamadaelse 215c6ba9b45SSumit Garg$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6)) 2162da522bbSMasahiro Yamadaendif 2172da522bbSMasahiro Yamadaendef 2182da522bbSMasahiro Yamada 2190191262dSYatharth Kochar# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation 22073c99d4eSJuan Castillo# $(1) = parameter filename 22173c99d4eSJuan Castillo# $(2) = cert_create command line option for the specified parameter 22291704d9dSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 22373c99d4eSJuan Castillodefine CERT_ADD_CMD_OPT 22491704d9dSMasahiro Yamada $(3)CRT_ARGS += $(2) $(1) 22573c99d4eSJuan Castilloendef 22673c99d4eSJuan Castillo 227c939d13aSMasahiro Yamada# TOOL_ADD_IMG allows the platform to specify an external image to be packed 228c939d13aSMasahiro Yamada# in the FIP and/or for which certificate is generated. It also adds a 229c939d13aSMasahiro Yamada# dependency on the image file, aborting the build if the file does not exist. 23033950dd8SMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 2311e0c0784SMasahiro Yamada# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc) 2321dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 233c6ba9b45SSumit Garg# $(4) = Image encryption flag (optional) (0, 1) 23473c99d4eSJuan Castillo# Example: 23533950dd8SMasahiro Yamada# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 236c939d13aSMasahiro Yamadadefine TOOL_ADD_IMG 23733950dd8SMasahiro Yamada # Build option to specify the image filename (SCP_BL2, BL33, etc) 23833950dd8SMasahiro Yamada # This is the uppercase form of the first parameter 23933950dd8SMasahiro Yamada $(eval _V := $(call uppercase,$(1))) 24033950dd8SMasahiro Yamada 2414727fd13SPali Rohár # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also 2424727fd13SPali Rohár # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the 2434727fd13SPali Rohár # target ${BUILD_PLAT}/${$(3)FIP_NAME}. 2444727fd13SPali Rohár $(eval check_$(1)_cmd := \ 2454727fd13SPali Rohár $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \ 2464727fd13SPali Rohár $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \ 2474727fd13SPali Rohár ) 2484727fd13SPali Rohár 249945b316fSMasahiro Yamada $(3)CRT_DEPS += check_$(1) 2504727fd13SPali Rohár CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd) 251c6ba9b45SSumit Gargifeq ($(4),1) 252c6ba9b45SSumit Garg $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin) 253c6ba9b45SSumit Garg $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN)) 254c6ba9b45SSumit Garg $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(ENC_BIN),$(3), \ 255c6ba9b45SSumit Garg $(ENC_BIN)) 256c6ba9b45SSumit Gargelse 2574727fd13SPali Rohár $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3)) 258c6ba9b45SSumit Gargendif 2590191262dSYatharth Kochar 26087ebd20dSMasahiro Yamada.PHONY: check_$(1) 2610191262dSYatharth Kocharcheck_$(1): 2624727fd13SPali Rohár $(check_$(1)_cmd) 2630191262dSYatharth Kocharendef 26473c99d4eSJuan Castillo 265cf2dd17dSJuan Pablo Conde# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to 266cf2dd17dSJuan Pablo Conde# build the host tools by checking the version of OpenSSL located under 267cf2dd17dSJuan Pablo Conde# the path defined by the OPENSSL_DIR variable. It receives no parameters. 268cf2dd17dSJuan Pablo Condedefine SELECT_OPENSSL_API_VERSION 269cf2dd17dSJuan Pablo Conde # Set default value for USING_OPENSSL3 macro to 0 270cf2dd17dSJuan Pablo Conde $(eval USING_OPENSSL3 = 0) 271cf2dd17dSJuan Pablo Conde # Obtain the OpenSSL version for the build located under OPENSSL_DIR 272cf2dd17dSJuan Pablo Conde $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version)) 273cf2dd17dSJuan Pablo Conde $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO})) 274cf2dd17dSJuan Pablo Conde $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER)))) 275cf2dd17dSJuan Pablo Conde # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1 276cf2dd17dSJuan Pablo Conde $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1)) 277cf2dd17dSJuan Pablo Condeendef 278cf2dd17dSJuan Pablo Conde 27973c99d4eSJuan Castillo################################################################################ 28014db8908SMasahiro Yamada# Generic image processing filters 28114db8908SMasahiro Yamada################################################################################ 28214db8908SMasahiro Yamada 28314db8908SMasahiro Yamada# GZIP 28414db8908SMasahiro Yamadadefine GZIP_RULE 28514db8908SMasahiro Yamada$(1): $(2) 286ee1ba6d4SAndre Przywara $(ECHO) " GZIP $$@" 28714db8908SMasahiro Yamada $(Q)gzip -n -f -9 $$< --stdout > $$@ 28814db8908SMasahiro Yamadaendef 28914db8908SMasahiro Yamada 29014db8908SMasahiro YamadaGZIP_SUFFIX := .gz 29114db8908SMasahiro Yamada 29214db8908SMasahiro Yamada################################################################################ 29373c99d4eSJuan Castillo# Auxiliary macros to build TF images from sources 29473c99d4eSJuan Castillo################################################################################ 29573c99d4eSJuan Castillo 2961d274ab0SMasahiro YamadaMAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP 29773c99d4eSJuan Castillo 2985fee0287SRoberto Vargas 2995fee0287SRoberto Vargas# MAKE_C_LIB builds a C source file and generates the dependency file 3005fee0287SRoberto Vargas# $(1) = output directory 3015fee0287SRoberto Vargas# $(2) = source file (%.c) 3025fee0287SRoberto Vargas# $(3) = library name 3035fee0287SRoberto Vargasdefine MAKE_C_LIB 3045fee0287SRoberto Vargas$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 3055fee0287SRoberto Vargas$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 3065a65fcd5SGovindraj Raja$(eval LIB := $(call uppercase, $(notdir $(1)))) 3075fee0287SRoberto Vargas 3085fee0287SRoberto Vargas$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs 309ee1ba6d4SAndre Przywara $$(ECHO) " CC $$<" 310ffb77421SChris Kay $$(Q)$($(ARCH)-cc) $$($(LIB)_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@ 3115fee0287SRoberto Vargas 3125fee0287SRoberto Vargas-include $(DEP) 3135fee0287SRoberto Vargas 3145fee0287SRoberto Vargasendef 3155fee0287SRoberto Vargas 31670b0f278SAntonio Nino Diaz# MAKE_S_LIB builds an assembly source file and generates the dependency file 31770b0f278SAntonio Nino Diaz# $(1) = output directory 31870b0f278SAntonio Nino Diaz# $(2) = source file (%.S) 31970b0f278SAntonio Nino Diaz# $(3) = library name 32070b0f278SAntonio Nino Diazdefine MAKE_S_LIB 32170b0f278SAntonio Nino Diaz$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 32270b0f278SAntonio Nino Diaz$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 32370b0f278SAntonio Nino Diaz 32470b0f278SAntonio Nino Diaz$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs 32570b0f278SAntonio Nino Diaz $$(ECHO) " AS $$<" 326ffb77421SChris Kay $$(Q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS_$(ARCH)) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@ 32770b0f278SAntonio Nino Diaz 32870b0f278SAntonio Nino Diaz-include $(DEP) 32970b0f278SAntonio Nino Diaz 33070b0f278SAntonio Nino Diazendef 33170b0f278SAntonio Nino Diaz 3325fee0287SRoberto Vargas 33373c99d4eSJuan Castillo# MAKE_C builds a C source file and generates the dependency file 33473c99d4eSJuan Castillo# $(1) = output directory 33573c99d4eSJuan Castillo# $(2) = source file (%.c) 336434d0491SZelalem Aweke# $(3) = BL stage 33773c99d4eSJuan Castillodefine MAKE_C 33873c99d4eSJuan Castillo 33973c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 340710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 341a123cb14SChris Kay 3421ab8c109SChris Kay$(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) 3431ab8c109SChris Kay$(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) 3441ab8c109SChris Kay$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) 3451ab8c109SChris Kay$(eval BL_CFLAGS := $($(call uppercase,$(3))_CFLAGS) $(PLAT_BL_COMMON_CFLAGS)) 34673c99d4eSJuan Castillo 347434d0491SZelalem Aweke$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 348ee1ba6d4SAndre Przywara $$(ECHO) " CC $$<" 349ffb77421SChris Kay $$(Q)$($(ARCH)-cc) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@ 35073c99d4eSJuan Castillo 351710ea1d0SMasahiro Yamada-include $(DEP) 35273c99d4eSJuan Castillo 35373c99d4eSJuan Castilloendef 35473c99d4eSJuan Castillo 35573c99d4eSJuan Castillo 35673c99d4eSJuan Castillo# MAKE_S builds an assembly source file and generates the dependency file 35773c99d4eSJuan Castillo# $(1) = output directory 35873c99d4eSJuan Castillo# $(2) = assembly file (%.S) 359434d0491SZelalem Aweke# $(3) = BL stage 36073c99d4eSJuan Castillodefine MAKE_S 36173c99d4eSJuan Castillo 36273c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 363710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 364a123cb14SChris Kay 3651ab8c109SChris Kay$(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) 3661ab8c109SChris Kay$(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) 3671ab8c109SChris Kay$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) 3681ab8c109SChris Kay$(eval BL_ASFLAGS := $($(call uppercase,$(3))_ASFLAGS) $(PLAT_BL_COMMON_ASFLAGS)) 36973c99d4eSJuan Castillo 370434d0491SZelalem Aweke$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 371ee1ba6d4SAndre Przywara $$(ECHO) " AS $$<" 372ffb77421SChris Kay $$(Q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS_$(ARCH)) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@ 37373c99d4eSJuan Castillo 374710ea1d0SMasahiro Yamada-include $(DEP) 37573c99d4eSJuan Castillo 37673c99d4eSJuan Castilloendef 37773c99d4eSJuan Castillo 37873c99d4eSJuan Castillo 37973c99d4eSJuan Castillo# MAKE_LD generate the linker script using the C preprocessor 38073c99d4eSJuan Castillo# $(1) = output linker script 38173c99d4eSJuan Castillo# $(2) = input template 382434d0491SZelalem Aweke# $(3) = BL stage 38373c99d4eSJuan Castillodefine MAKE_LD 38473c99d4eSJuan Castillo 385710ea1d0SMasahiro Yamada$(eval DEP := $(1).d) 386a123cb14SChris Kay 3871ab8c109SChris Kay$(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) 3881ab8c109SChris Kay$(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) 3891ab8c109SChris Kay$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) 39073c99d4eSJuan Castillo 391434d0491SZelalem Aweke$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 392ee1ba6d4SAndre Przywara $$(ECHO) " PP $$<" 393ffb77421SChris Kay $$(Q)$($(ARCH)-cpp) -E $$(CPPFLAGS) $(BL_CPPFLAGS) $(TF_CFLAGS_$(ARCH)) -P -x assembler-with-cpp -D__LINKER__ $(MAKE_DEP) -o $$@ $$< 39473c99d4eSJuan Castillo 395710ea1d0SMasahiro Yamada-include $(DEP) 39673c99d4eSJuan Castillo 39773c99d4eSJuan Castilloendef 39873c99d4eSJuan Castillo 39970b0f278SAntonio Nino Diaz# MAKE_LIB_OBJS builds both C and assembly source files 4005fee0287SRoberto Vargas# $(1) = output directory 4015fee0287SRoberto Vargas# $(2) = list of source files 4025fee0287SRoberto Vargas# $(3) = name of the library 4035fee0287SRoberto Vargasdefine MAKE_LIB_OBJS 4045fee0287SRoberto Vargas $(eval C_OBJS := $(filter %.c,$(2))) 4055fee0287SRoberto Vargas $(eval REMAIN := $(filter-out %.c,$(2))) 4065fee0287SRoberto Vargas $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3)))) 4075fee0287SRoberto Vargas 40870b0f278SAntonio Nino Diaz $(eval S_OBJS := $(filter %.S,$(REMAIN))) 40970b0f278SAntonio Nino Diaz $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 41070b0f278SAntonio Nino Diaz $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3)))) 41170b0f278SAntonio Nino Diaz 4125fee0287SRoberto Vargas $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 4135fee0287SRoberto Vargasendef 4145fee0287SRoberto Vargas 41573c99d4eSJuan Castillo 41673c99d4eSJuan Castillo# MAKE_OBJS builds both C and assembly source files 41773c99d4eSJuan Castillo# $(1) = output directory 41873c99d4eSJuan Castillo# $(2) = list of source files (both C and assembly) 419434d0491SZelalem Aweke# $(3) = BL stage 42073c99d4eSJuan Castillodefine MAKE_OBJS 42173c99d4eSJuan Castillo $(eval C_OBJS := $(filter %.c,$(2))) 42273c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.c,$(2))) 42373c99d4eSJuan Castillo $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3)))) 42473c99d4eSJuan Castillo 42573c99d4eSJuan Castillo $(eval S_OBJS := $(filter %.S,$(REMAIN))) 42673c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 42773c99d4eSJuan Castillo $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3)))) 42873c99d4eSJuan Castillo 42973c99d4eSJuan Castillo $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 43073c99d4eSJuan Castilloendef 43173c99d4eSJuan Castillo 43273c99d4eSJuan Castillo 43373c99d4eSJuan Castillo# NOTE: The line continuation '\' is required in the next define otherwise we 43473c99d4eSJuan Castillo# end up with a line-feed characer at the end of the last c filename. 435e7f54dbdSEvan Lloyd# Also bear this issue in mind if extending the list of supported filetypes. 43673c99d4eSJuan Castillodefine SOURCES_TO_OBJS 43773c99d4eSJuan Castillo $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ 43873c99d4eSJuan Castillo $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) 43973c99d4eSJuan Castilloendef 44073c99d4eSJuan Castillo 4415fee0287SRoberto Vargas.PHONY: libraries 4425fee0287SRoberto Vargas 4435accce5bSRoberto Vargas# MAKE_LIB_DIRS macro defines the target for the directory where 4445fee0287SRoberto Vargas# libraries are created 4455accce5bSRoberto Vargasdefine MAKE_LIB_DIRS 4465fee0287SRoberto Vargas $(eval LIB_DIR := ${BUILD_PLAT}/lib) 4475accce5bSRoberto Vargas $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 4485accce5bSRoberto Vargas $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper) 4495fee0287SRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT})) 4505accce5bSRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT})) 4515accce5bSRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT})) 4525fee0287SRoberto Vargasendef 4535fee0287SRoberto Vargas 4545fee0287SRoberto Vargas# MAKE_LIB macro defines the targets and options to build each BL image. 4555fee0287SRoberto Vargas# Arguments: 4565fee0287SRoberto Vargas# $(1) = Library name 4575fee0287SRoberto Vargasdefine MAKE_LIB 4585fee0287SRoberto Vargas $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1)) 4595fee0287SRoberto Vargas $(eval LIB_DIR := ${BUILD_PLAT}/lib) 4605accce5bSRoberto Vargas $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 4615fee0287SRoberto Vargas $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS)) 4625fee0287SRoberto Vargas $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 4635fee0287SRoberto Vargas 4645fee0287SRoberto Vargas$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) 4655fee0287SRoberto Vargas$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) 4665fee0287SRoberto Vargas 4675fee0287SRoberto Vargas.PHONY : lib${1}_dirs 4685accce5bSRoberto Vargaslib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR} 4695fee0287SRoberto Vargaslibraries: ${LIB_DIR}/lib$(1).a 4708620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link) 471c2ad38ceSVarun WadekarLDPATHS = --userlibpath=${LIB_DIR} 472c2ad38ceSVarun WadekarLDLIBS += --library=$(1) 473c2ad38ceSVarun Wadekarelse 4745fee0287SRoberto VargasLDPATHS = -L${LIB_DIR} 4755fee0287SRoberto VargasLDLIBS += -l$(1) 476c2ad38ceSVarun Wadekarendif 4775fee0287SRoberto Vargas 4785accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 4796baf85b3SSathees BalyaLIBWRAPPER = -lwrappers 4805accce5bSRoberto Vargasendif 4815accce5bSRoberto Vargas 4825fee0287SRoberto Vargasall: ${LIB_DIR}/lib$(1).a 4835fee0287SRoberto Vargas 4845fee0287SRoberto Vargas${LIB_DIR}/lib$(1).a: $(OBJS) 485ee1ba6d4SAndre Przywara $$(ECHO) " AR $$@" 486ffb77421SChris Kay $$(Q)$($(ARCH)-ar) cr $$@ $$? 4875fee0287SRoberto Vargasendef 4885fee0287SRoberto Vargas 48982274936SChris Kay# Generate the path to one or more preprocessed linker scripts given the paths 49082274936SChris Kay# of their sources. 49182274936SChris Kay# 49282274936SChris Kay# Arguments: 49382274936SChris Kay# $(1) = path to one or more linker script sources 49482274936SChris Kaydefine linker_script_path 49582274936SChris Kay $(patsubst %.S,$(BUILD_DIR)/%,$(1)) 49682274936SChris Kayendef 49782274936SChris Kay 49873c99d4eSJuan Castillo# MAKE_BL macro defines the targets and options to build each BL image. 49973c99d4eSJuan Castillo# Arguments: 500434d0491SZelalem Aweke# $(1) = BL stage 5018f0617efSJuan Castillo# $(2) = FIP command line option (if empty, image will not be included in the FIP) 5021dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 503c6ba9b45SSumit Garg# $(4) = BL encryption flag (optional) (0, 1) 50473c99d4eSJuan Castillodefine MAKE_BL 505434d0491SZelalem Aweke $(eval BUILD_DIR := ${BUILD_PLAT}/$(1)) 506434d0491SZelalem Aweke $(eval BL_SOURCES := $($(call uppercase,$(1))_SOURCES)) 507bb22fb84SChris Kay $(eval SOURCES := $(sort $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))) 50873c99d4eSJuan Castillo $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 50973c99d4eSJuan Castillo $(eval MAPFILE := $(call IMG_MAPFILE,$(1))) 51073c99d4eSJuan Castillo $(eval ELF := $(call IMG_ELF,$(1))) 51173c99d4eSJuan Castillo $(eval DUMP := $(call IMG_DUMP,$(1))) 51273c99d4eSJuan Castillo $(eval BIN := $(call IMG_BIN,$(1))) 513c6ba9b45SSumit Garg $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1))) 514434d0491SZelalem Aweke $(eval BL_LIBS := $($(call uppercase,$(1))_LIBS)) 51582274936SChris Kay 51682274936SChris Kay $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(call uppercase,$(1))_DEFAULT_LINKER_SCRIPT_SOURCE)) 51782274936SChris Kay $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE))) 51882274936SChris Kay 519a6ff0067SChris Kay $(eval LINKER_SCRIPT_SOURCES := $($(call uppercase,$(1))_LINKER_SCRIPT_SOURCES)) 520a6ff0067SChris Kay $(eval LINKER_SCRIPTS := $(call linker_script_path,$(LINKER_SCRIPT_SOURCES))) 521a6ff0067SChris Kay 52251b27702SEvan Lloyd # We use sort only to get a list of unique object directory names. 52351b27702SEvan Lloyd # ordering is not relevant but sort removes duplicates. 524a6ff0067SChris Kay $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${DEFAULT_LINKER_SCRIPT} ${LINKER_SCRIPTS}))) 52551b27702SEvan Lloyd # The $(dir ) function leaves a trailing / on the directory names 526d014ea6cSMasahiro Yamada # Rip off the / to match directory names with make rule targets. 527d014ea6cSMasahiro Yamada $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS))) 52851b27702SEvan Lloyd 52951b27702SEvan Lloyd# Create generators for object directory structure 53051b27702SEvan Lloyd 5318012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) 5326ba7d274SEvan Lloyd 53382274936SChris Kay$(eval $(foreach objd,${OBJ_DIRS}, 53482274936SChris Kay $(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) 53551b27702SEvan Lloyd 536434d0491SZelalem Aweke.PHONY : ${1}_dirs 53751b27702SEvan Lloyd 53851b27702SEvan Lloyd# We use order-only prerequisites to ensure that directories are created, 53951b27702SEvan Lloyd# but do not cause re-builds every time a file is written. 540434d0491SZelalem Aweke${1}_dirs: | ${OBJ_DIRS} 54173c99d4eSJuan Castillo 54273c99d4eSJuan Castillo$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) 543a6ff0067SChris Kay 544a6ff0067SChris Kay# Generate targets to preprocess each required linker script 545a6ff0067SChris Kay$(eval $(foreach source,$(DEFAULT_LINKER_SCRIPT_SOURCE) $(LINKER_SCRIPT_SOURCES), \ 546a6ff0067SChris Kay $(call MAKE_LD,$(call linker_script_path,$(source)),$(source),$(1)))) 547a6ff0067SChris Kay 548434d0491SZelalem Aweke$(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS)) 54973c99d4eSJuan Castillo 5505accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 5515accce5bSRoberto Vargas$(ELF): romlib.bin 5525accce5bSRoberto Vargasendif 5535accce5bSRoberto Vargas 5548dccddc7SLeon Chen# MODULE_OBJS can be assigned by vendors with different compiled 5558dccddc7SLeon Chen# object file path, and prebuilt object file path. 5568dccddc7SLeon Chen$(eval OBJS += $(MODULE_OBJS)) 5578dccddc7SLeon Chen 558a6ff0067SChris Kay$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) $(LINKER_SCRIPTS) | $(1)_dirs libraries $(BL_LIBS) 559ee1ba6d4SAndre Przywara $$(ECHO) " LD $$@" 5608620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link) 561ffb77421SChris Kay $$(Q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \ 562*df52e260SChris Kay --predefine=$(call escape-shell,-D__LINKER__=$(__LINKER__)) \ 563*df52e260SChris Kay --predefine=$(call escape-shell,-DTF_CFLAGS=$(TF_CFLAGS)) \ 564434d0491SZelalem Aweke --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \ 565758ccb80SChris Kay $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS) 5668620bd0bSChris Kayelse ifeq ($($(ARCH)-ld-id),gnu-gcc) 567ffb77421SChris Kay $$(Q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Wl,-Map=$(MAPFILE) \ 568a6ff0067SChris Kay $(addprefix -Wl$(comma)--script$(comma),$(LINKER_SCRIPTS)) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) \ 569edbce9aaSzelalem-aweke $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) 570c2ad38ceSVarun Wadekarelse 571ffb77421SChris Kay $$(Q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \ 572a6ff0067SChris Kay $(addprefix -T ,$(LINKER_SCRIPTS)) --script $(DEFAULT_LINKER_SCRIPT) \ 5736baf85b3SSathees Balya $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) 574c2ad38ceSVarun Wadekarendif 5759e4609f1SChristoph Müllnerifeq ($(DISABLE_BIN_GENERATION),1) 5769e4609f1SChristoph Müllner @${ECHO_BLANK_LINE} 5779e4609f1SChristoph Müllner @echo "Built $$@ successfully" 5789e4609f1SChristoph Müllner @${ECHO_BLANK_LINE} 5799e4609f1SChristoph Müllnerendif 58073c99d4eSJuan Castillo 58173c99d4eSJuan Castillo$(DUMP): $(ELF) 582ee1ba6d4SAndre Przywara $${ECHO} " OD $$@" 583ffb77421SChris Kay $${Q}$($(ARCH)-od) -dx $$< > $$@ 58473c99d4eSJuan Castillo 58573c99d4eSJuan Castillo$(BIN): $(ELF) 586ee1ba6d4SAndre Przywara $${ECHO} " BIN $$@" 587ffb77421SChris Kay $$(Q)$($(ARCH)-oc) -O binary $$< $$@ 588052ab529SEvan Lloyd @${ECHO_BLANK_LINE} 58973c99d4eSJuan Castillo @echo "Built $$@ successfully" 590052ab529SEvan Lloyd @${ECHO_BLANK_LINE} 59173c99d4eSJuan Castillo 592434d0491SZelalem Aweke.PHONY: $(1) 5939e4609f1SChristoph Müllnerifeq ($(DISABLE_BIN_GENERATION),1) 594434d0491SZelalem Aweke$(1): $(ELF) $(DUMP) 5959e4609f1SChristoph Müllnerelse 596434d0491SZelalem Aweke$(1): $(BIN) $(DUMP) 5979e4609f1SChristoph Müllnerendif 59873c99d4eSJuan Castillo 599434d0491SZelalem Awekeall: $(1) 60073c99d4eSJuan Castillo 601c6ba9b45SSumit Gargifeq ($(4),1) 602c6ba9b45SSumit Garg$(call ENCRYPT_FW,$(BIN),$(ENC_BIN)) 603434d0491SZelalem Aweke$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(ENC_BIN),$(3), \ 604c6ba9b45SSumit Garg $(ENC_BIN))) 605c6ba9b45SSumit Gargelse 606434d0491SZelalem Aweke$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(BIN),$(3))) 607c6ba9b45SSumit Gargendif 60873c99d4eSJuan Castillo 60973c99d4eSJuan Castilloendef 61073c99d4eSJuan Castillo 61138c14d88SSoby Mathew# Convert device tree source file names to matching blobs 61238c14d88SSoby Mathew# $(1) = input dts 61303b397a8SNishanth Menondefine SOURCES_TO_DTBS 61403b397a8SNishanth Menon $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1)))) 61503b397a8SNishanth Menonendef 61603b397a8SNishanth Menon 61738c14d88SSoby Mathew# MAKE_FDT_DIRS macro creates the prerequisite directories that host the 61838c14d88SSoby Mathew# FDT binaries 61938c14d88SSoby Mathew# $(1) = output directory 62038c14d88SSoby Mathew# $(2) = input dts 62138c14d88SSoby Mathewdefine MAKE_FDT_DIRS 62238c14d88SSoby Mathew $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 62303b397a8SNishanth Menon $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS}))) 62403b397a8SNishanth Menon # The $(dir ) function leaves a trailing / on the directory names 62503b397a8SNishanth Menon # Rip off the / to match directory names with make rule targets. 62603b397a8SNishanth Menon $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS))) 62703b397a8SNishanth Menon 62803b397a8SNishanth Menon$(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) 62903b397a8SNishanth Menon 63003b397a8SNishanth Menonfdt_dirs: ${DTB_DIRS} 63103b397a8SNishanth Menonendef 63203b397a8SNishanth Menon 63338c14d88SSoby Mathew# MAKE_DTB generate the Flattened device tree binary 63403b397a8SNishanth Menon# $(1) = output directory 63503b397a8SNishanth Menon# $(2) = input dts 63603b397a8SNishanth Menondefine MAKE_DTB 63703b397a8SNishanth Menon 638077b3e9aSYann Gautier# List of DTB file(s) to generate, based on DTS file basename list 63938c14d88SSoby Mathew$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 640077b3e9aSYann Gautier# List of the pre-compiled DTS file(s) 64101d237cbSYann Gautier$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2))))) 642077b3e9aSYann Gautier# Dependencies of the pre-compiled DTS file(s) on its source and included files 643077b3e9aSYann Gautier$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ))) 644077b3e9aSYann Gautier# Dependencies of the DT compilation on its pre-compiled DTS 645077b3e9aSYann Gautier$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ))) 64603b397a8SNishanth Menon 6477b453526SChris Kay$(DPRE): $(2) | fdt_dirs 648ee1ba6d4SAndre Przywara $${ECHO} " CPP $$<" 649077b3e9aSYann Gautier $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 650ffb77421SChris Kay $$(Q)$($(ARCH)-cpp) -E $$(TF_CFLAGS_$(ARCH)) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$< 6517b453526SChris Kay 6527b453526SChris Kay$(DOBJ): $(DPRE) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs 653ee1ba6d4SAndre Przywara $${ECHO} " DTC $$<" 6547b453526SChris Kay $$(Q)$($(ARCH)-dtc) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $$< 65503b397a8SNishanth Menon 656077b3e9aSYann Gautier-include $(DTBDEP) 657077b3e9aSYann Gautier-include $(DTSDEP) 65803b397a8SNishanth Menon 65903b397a8SNishanth Menonendef 66003b397a8SNishanth Menon 66103b397a8SNishanth Menon# MAKE_DTBS builds flattened device tree sources 66203b397a8SNishanth Menon# $(1) = output directory 66303b397a8SNishanth Menon# $(2) = list of flattened device tree source files 66403b397a8SNishanth Menondefine MAKE_DTBS 66503b397a8SNishanth Menon $(eval DOBJS := $(filter %.dts,$(2))) 66603b397a8SNishanth Menon $(eval REMAIN := $(filter-out %.dts,$(2))) 66738c14d88SSoby Mathew $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN))) 66803b397a8SNishanth Menon $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj)))) 66903b397a8SNishanth Menon 67038c14d88SSoby Mathew $(eval $(call MAKE_FDT_DIRS,$(1),$(2))) 67138c14d88SSoby Mathew 67238c14d88SSoby Mathewdtbs: $(DTBS) 67338c14d88SSoby Mathewall: dtbs 67403b397a8SNishanth Menonendef 675