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 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 4473c99d4eSJuan Castillo# Convenience function for adding build definitions 4573c99d4eSJuan Castillo# $(eval $(call add_define,FOO)) will have: 4673c99d4eSJuan Castillo# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise 4773c99d4eSJuan Castillodefine add_define 4873c99d4eSJuan Castillo DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) 4973c99d4eSJuan Castilloendef 5073c99d4eSJuan Castillo 51327131c4SLeonardo Sandoval# Convenience function for addding multiple build definitions 52327131c4SLeonardo Sandoval# $(eval $(call add_defines,FOO BOO)) 53327131c4SLeonardo Sandovaldefine add_defines 54327131c4SLeonardo Sandoval $(foreach def,$1,$(eval $(call add_define,$(def)))) 55327131c4SLeonardo Sandovalendef 56327131c4SLeonardo Sandoval 578eadeb4aSSoren Brinkmann# Convenience function for adding build definitions 588eadeb4aSSoren Brinkmann# $(eval $(call add_define_val,FOO,BAR)) will have: 598eadeb4aSSoren Brinkmann# -DFOO=BAR 608eadeb4aSSoren Brinkmanndefine add_define_val 618eadeb4aSSoren Brinkmann DEFINES += -D$(1)=$(2) 628eadeb4aSSoren Brinkmannendef 638eadeb4aSSoren Brinkmann 6473c99d4eSJuan Castillo# Convenience function for verifying option has a boolean value 6573c99d4eSJuan Castillo# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 6673c99d4eSJuan Castillodefine assert_boolean 671369fb82SYann Gautier $(if $($(1)),,$(error $(1) must not be empty)) 68be4cd40eSMasahiro Yamada $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean)) 6973c99d4eSJuan Castilloendef 7073c99d4eSJuan Castillo 71327131c4SLeonardo Sandoval# Convenience function for verifying options have boolean values 72327131c4SLeonardo Sandoval# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values 73327131c4SLeonardo Sandovaldefine assert_booleans 74327131c4SLeonardo Sandoval $(foreach bool,$1,$(eval $(call assert_boolean,$(bool)))) 75327131c4SLeonardo Sandovalendef 76327131c4SLeonardo Sandoval 77c877b414SJeenu Viswambharan0-9 := 0 1 2 3 4 5 6 7 8 9 78c877b414SJeenu Viswambharan 79c877b414SJeenu Viswambharan# Function to verify that a given option $(1) contains a numeric value 80c877b414SJeenu Viswambharandefine assert_numeric 81c877b414SJeenu Viswambharan$(if $($(1)),,$(error $(1) must not be empty)) 82c877b414SJeenu Viswambharan$(eval __numeric := $($(1))) 83c877b414SJeenu Viswambharan$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) 84c877b414SJeenu Viswambharan$(if $(__numeric),$(error $(1) must be numeric)) 85c877b414SJeenu Viswambharanendef 86c877b414SJeenu Viswambharan 87327131c4SLeonardo Sandoval# Convenience function for verifying options have numeric values 88327131c4SLeonardo Sandoval# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values 89327131c4SLeonardo Sandovaldefine assert_numerics 90327131c4SLeonardo Sandoval $(foreach num,$1,$(eval $(call assert_numeric,$(num)))) 91327131c4SLeonardo Sandovalendef 92327131c4SLeonardo Sandoval 93a5f09cf7SMarco Felsch# Convenience function to check for a given linker option. An call to 94a5f09cf7SMarco Felsch# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker 95ffb77421SChris Kayld_option = $(shell $($(ARCH)-ld) $(1) -Wl,--version >/dev/null 2>&1 || $($(ARCH)-ld) $(1) -v >/dev/null 2>&1 && echo $(1)) 96a5f09cf7SMarco Felsch 97dea23e24SGovindraj Raja# Convenience function to check for a given compiler option. A call to 98dea23e24SGovindraj Raja# $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler 99dea23e24SGovindraj Rajadefine cc_option 100ffb77421SChris Kay $(shell if $($(ARCH)-cc) $(1) -c -x c /dev/null -o /dev/null >/dev/null 2>&1; then echo $(1); fi ) 101dea23e24SGovindraj Rajaendef 102dea23e24SGovindraj Raja 1038c7b944aSVijayenthiran Subramaniam# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to 1048c7b944aSVijayenthiran Subramaniam# $(2) and assign the sequence to $(1) 1058c7b944aSVijayenthiran Subramaniamdefine CREATE_SEQ 1068c7b944aSVijayenthiran Subramaniam$(if $(word $(2), $($(1))),\ 1078c7b944aSVijayenthiran Subramaniam $(eval $(1) += $(words $($(1))))\ 1088c7b944aSVijayenthiran Subramaniam $(eval $(1) := $(filter-out 0,$($(1)))),\ 1098c7b944aSVijayenthiran Subramaniam $(eval $(1) += $(words $($(1))))\ 1108c7b944aSVijayenthiran Subramaniam $(call CREATE_SEQ,$(1),$(2))\ 1118c7b944aSVijayenthiran Subramaniam) 1128c7b944aSVijayenthiran Subramaniamendef 1138c7b944aSVijayenthiran Subramaniam 11473c99d4eSJuan Castillo# IMG_MAPFILE defines the output file describing the memory map corresponding 11573c99d4eSJuan Castillo# to a BL stage 116434d0491SZelalem Aweke# $(1) = BL stage 11773c99d4eSJuan Castillodefine IMG_MAPFILE 118434d0491SZelalem Aweke ${BUILD_DIR}/$(1).map 11973c99d4eSJuan Castilloendef 12073c99d4eSJuan Castillo 12173c99d4eSJuan Castillo# IMG_ELF defines the elf file corresponding to a BL stage 122434d0491SZelalem Aweke# $(1) = BL stage 12373c99d4eSJuan Castillodefine IMG_ELF 124434d0491SZelalem Aweke ${BUILD_DIR}/$(1).elf 12573c99d4eSJuan Castilloendef 12673c99d4eSJuan Castillo 12773c99d4eSJuan Castillo# IMG_DUMP defines the symbols dump file corresponding to a BL stage 128434d0491SZelalem Aweke# $(1) = BL stage 12973c99d4eSJuan Castillodefine IMG_DUMP 130434d0491SZelalem Aweke ${BUILD_DIR}/$(1).dump 13173c99d4eSJuan Castilloendef 13273c99d4eSJuan Castillo 13373c99d4eSJuan Castillo# IMG_BIN defines the default image file corresponding to a BL stage 134434d0491SZelalem Aweke# $(1) = BL stage 13573c99d4eSJuan Castillodefine IMG_BIN 136434d0491SZelalem Aweke ${BUILD_PLAT}/$(1).bin 13773c99d4eSJuan Castilloendef 13873c99d4eSJuan Castillo 139c6ba9b45SSumit Garg# IMG_ENC_BIN defines the default encrypted image file corresponding to a 140c6ba9b45SSumit Garg# BL stage 141434d0491SZelalem Aweke# $(1) = BL stage 142c6ba9b45SSumit Gargdefine IMG_ENC_BIN 143434d0491SZelalem Aweke ${BUILD_PLAT}/$(1)_enc.bin 144c6ba9b45SSumit Gargendef 145c6ba9b45SSumit Garg 146c6ba9b45SSumit Garg# ENCRYPT_FW invokes enctool to encrypt firmware binary 147c6ba9b45SSumit Garg# $(1) = input firmware binary 148c6ba9b45SSumit Garg# $(2) = output encrypted firmware binary 149c6ba9b45SSumit Gargdefine ENCRYPT_FW 150c6ba9b45SSumit Garg$(2): $(1) enctool 1517c4e1eeaSChris Kay $$(s)echo " ENC $$<" 1527c4e1eeaSChris Kay $$(q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@ 153c6ba9b45SSumit Gargendef 154c6ba9b45SSumit Garg 15510cea934SMasahiro Yamada# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to 15610cea934SMasahiro Yamada# package a new payload and/or by cert_create to generate certificate. 15710cea934SMasahiro Yamada# Optionally, it adds the dependency on this payload 15873c99d4eSJuan Castillo# $(1) = payload filename (i.e. bl31.bin) 1591e0c0784SMasahiro Yamada# $(2) = command line option for the specified payload (i.e. --soc-fw) 16036af3455SMasahiro Yamada# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 1611dc0714fSMasahiro Yamada# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 162c6ba9b45SSumit Garg# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 16310cea934SMasahiro Yamadadefine TOOL_ADD_PAYLOAD 164c6ba9b45SSumit Gargifneq ($(5),) 165c6ba9b45SSumit Garg $(4)FIP_ARGS += $(2) $(5) 166c6ba9b45SSumit Garg $(if $(3),$(4)CRT_DEPS += $(1)) 167c6ba9b45SSumit Gargelse 168945b316fSMasahiro Yamada $(4)FIP_ARGS += $(2) $(1) 169c6ba9b45SSumit Garg $(if $(3),$(4)CRT_DEPS += $(3)) 170c6ba9b45SSumit Gargendif 171945b316fSMasahiro Yamada $(if $(3),$(4)FIP_DEPS += $(3)) 172f30ee0b9SMasahiro Yamada $(4)CRT_ARGS += $(2) $(1) 17373c99d4eSJuan Castilloendef 17473c99d4eSJuan Castillo 1752da522bbSMasahiro Yamada# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters 1762da522bbSMasahiro Yamada# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined. 1772da522bbSMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 1782da522bbSMasahiro Yamada# $(2) = payload filepath (ex. build/fvp/release/bl31.bin) 1792da522bbSMasahiro Yamada# $(3) = command line option for the specified payload (ex. --soc-fw) 1802da522bbSMasahiro Yamada# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 1812da522bbSMasahiro Yamada# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 182c6ba9b45SSumit Garg# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 1832da522bbSMasahiro Yamada 1842da522bbSMasahiro Yamadadefine TOOL_ADD_IMG_PAYLOAD 1852da522bbSMasahiro Yamada 1862da522bbSMasahiro Yamada$(eval PRE_TOOL_FILTER := $($(call uppercase,$(1))_PRE_TOOL_FILTER)) 1872da522bbSMasahiro Yamada 1882da522bbSMasahiro Yamadaifneq ($(PRE_TOOL_FILTER),) 1892da522bbSMasahiro Yamada 1902da522bbSMasahiro Yamada$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX)) 1912da522bbSMasahiro Yamada 1922da522bbSMasahiro Yamada$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2)) 1932da522bbSMasahiro Yamada 1942da522bbSMasahiro Yamada$(PROCESSED_PATH): $(4) 1952da522bbSMasahiro Yamada 196c6ba9b45SSumit Garg$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6)) 1972da522bbSMasahiro Yamada 1982da522bbSMasahiro Yamadaelse 199c6ba9b45SSumit Garg$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6)) 2002da522bbSMasahiro Yamadaendif 2012da522bbSMasahiro Yamadaendef 2022da522bbSMasahiro Yamada 2030191262dSYatharth Kochar# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation 20473c99d4eSJuan Castillo# $(1) = parameter filename 20573c99d4eSJuan Castillo# $(2) = cert_create command line option for the specified parameter 20691704d9dSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 20773c99d4eSJuan Castillodefine CERT_ADD_CMD_OPT 20891704d9dSMasahiro Yamada $(3)CRT_ARGS += $(2) $(1) 20973c99d4eSJuan Castilloendef 21073c99d4eSJuan Castillo 211c939d13aSMasahiro Yamada# TOOL_ADD_IMG allows the platform to specify an external image to be packed 212c939d13aSMasahiro Yamada# in the FIP and/or for which certificate is generated. It also adds a 213c939d13aSMasahiro Yamada# dependency on the image file, aborting the build if the file does not exist. 21433950dd8SMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 2151e0c0784SMasahiro Yamada# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc) 2161dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 217c6ba9b45SSumit Garg# $(4) = Image encryption flag (optional) (0, 1) 21873c99d4eSJuan Castillo# Example: 21933950dd8SMasahiro Yamada# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 220c939d13aSMasahiro Yamadadefine TOOL_ADD_IMG 22133950dd8SMasahiro Yamada # Build option to specify the image filename (SCP_BL2, BL33, etc) 22233950dd8SMasahiro Yamada # This is the uppercase form of the first parameter 22333950dd8SMasahiro Yamada $(eval _V := $(call uppercase,$(1))) 22433950dd8SMasahiro Yamada 2254727fd13SPali Rohár # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also 2264727fd13SPali Rohár # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the 2274727fd13SPali Rohár # target ${BUILD_PLAT}/${$(3)FIP_NAME}. 2284727fd13SPali Rohár $(eval check_$(1)_cmd := \ 2294727fd13SPali Rohár $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \ 2304727fd13SPali Rohár $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \ 2314727fd13SPali Rohár ) 2324727fd13SPali Rohár 233945b316fSMasahiro Yamada $(3)CRT_DEPS += check_$(1) 2344727fd13SPali Rohár CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd) 235c6ba9b45SSumit Gargifeq ($(4),1) 236c6ba9b45SSumit Garg $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin) 237c6ba9b45SSumit Garg $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN)) 238c6ba9b45SSumit Garg $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(ENC_BIN),$(3), \ 239c6ba9b45SSumit Garg $(ENC_BIN)) 240c6ba9b45SSumit Gargelse 2414727fd13SPali Rohár $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3)) 242c6ba9b45SSumit Gargendif 2430191262dSYatharth Kochar 24487ebd20dSMasahiro Yamada.PHONY: check_$(1) 2450191262dSYatharth Kocharcheck_$(1): 2464727fd13SPali Rohár $(check_$(1)_cmd) 2470191262dSYatharth Kocharendef 24873c99d4eSJuan Castillo 249cf2dd17dSJuan Pablo Conde# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to 250cf2dd17dSJuan Pablo Conde# build the host tools by checking the version of OpenSSL located under 251cf2dd17dSJuan Pablo Conde# the path defined by the OPENSSL_DIR variable. It receives no parameters. 252cf2dd17dSJuan Pablo Condedefine SELECT_OPENSSL_API_VERSION 253cf2dd17dSJuan Pablo Conde # Set default value for USING_OPENSSL3 macro to 0 254cf2dd17dSJuan Pablo Conde $(eval USING_OPENSSL3 = 0) 255cf2dd17dSJuan Pablo Conde # Obtain the OpenSSL version for the build located under OPENSSL_DIR 256cf2dd17dSJuan Pablo Conde $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version)) 257cf2dd17dSJuan Pablo Conde $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO})) 258cf2dd17dSJuan Pablo Conde $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER)))) 259cf2dd17dSJuan Pablo Conde # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1 260cf2dd17dSJuan Pablo Conde $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1)) 261cf2dd17dSJuan Pablo Condeendef 262cf2dd17dSJuan Pablo Conde 26373c99d4eSJuan Castillo################################################################################ 26414db8908SMasahiro Yamada# Generic image processing filters 26514db8908SMasahiro Yamada################################################################################ 26614db8908SMasahiro Yamada 26714db8908SMasahiro Yamada# GZIP 26814db8908SMasahiro Yamadadefine GZIP_RULE 26914db8908SMasahiro Yamada$(1): $(2) 2707c4e1eeaSChris Kay $(s)echo " GZIP $$@" 2717c4e1eeaSChris Kay $(q)gzip -n -f -9 $$< --stdout > $$@ 27214db8908SMasahiro Yamadaendef 27314db8908SMasahiro Yamada 27414db8908SMasahiro YamadaGZIP_SUFFIX := .gz 27514db8908SMasahiro Yamada 27614db8908SMasahiro Yamada################################################################################ 27773c99d4eSJuan Castillo# Auxiliary macros to build TF images from sources 27873c99d4eSJuan Castillo################################################################################ 27973c99d4eSJuan Castillo 2801d274ab0SMasahiro YamadaMAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP 28173c99d4eSJuan Castillo 2825fee0287SRoberto Vargas 2835fee0287SRoberto Vargas# MAKE_C_LIB builds a C source file and generates the dependency file 2845fee0287SRoberto Vargas# $(1) = output directory 2855fee0287SRoberto Vargas# $(2) = source file (%.c) 2865fee0287SRoberto Vargas# $(3) = library name 2875fee0287SRoberto Vargasdefine MAKE_C_LIB 2885fee0287SRoberto Vargas$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 2895fee0287SRoberto Vargas$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 2905a65fcd5SGovindraj Raja$(eval LIB := $(call uppercase, $(notdir $(1)))) 2915fee0287SRoberto Vargas 2925fee0287SRoberto Vargas$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs 2937c4e1eeaSChris Kay $$(s)echo " CC $$<" 2947c4e1eeaSChris Kay $$(q)$($(ARCH)-cc) $$($(LIB)_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@ 2955fee0287SRoberto Vargas 2965fee0287SRoberto Vargas-include $(DEP) 2975fee0287SRoberto Vargas 2985fee0287SRoberto Vargasendef 2995fee0287SRoberto Vargas 30070b0f278SAntonio Nino Diaz# MAKE_S_LIB builds an assembly source file and generates the dependency file 30170b0f278SAntonio Nino Diaz# $(1) = output directory 30270b0f278SAntonio Nino Diaz# $(2) = source file (%.S) 30370b0f278SAntonio Nino Diaz# $(3) = library name 30470b0f278SAntonio Nino Diazdefine MAKE_S_LIB 30570b0f278SAntonio Nino Diaz$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 30670b0f278SAntonio Nino Diaz$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 30770b0f278SAntonio Nino Diaz 30870b0f278SAntonio Nino Diaz$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs 3097c4e1eeaSChris Kay $$(s)echo " AS $$<" 3107c4e1eeaSChris Kay $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS_$(ARCH)) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@ 31170b0f278SAntonio Nino Diaz 31270b0f278SAntonio Nino Diaz-include $(DEP) 31370b0f278SAntonio Nino Diaz 31470b0f278SAntonio Nino Diazendef 31570b0f278SAntonio Nino Diaz 3165fee0287SRoberto Vargas 31773c99d4eSJuan Castillo# MAKE_C builds a C source file and generates the dependency file 31873c99d4eSJuan Castillo# $(1) = output directory 31973c99d4eSJuan Castillo# $(2) = source file (%.c) 320434d0491SZelalem Aweke# $(3) = BL stage 32173c99d4eSJuan Castillodefine MAKE_C 32273c99d4eSJuan Castillo 32373c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 324710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 325a123cb14SChris Kay 3261ab8c109SChris Kay$(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) 3271ab8c109SChris Kay$(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) 3281ab8c109SChris Kay$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) 3291ab8c109SChris Kay$(eval BL_CFLAGS := $($(call uppercase,$(3))_CFLAGS) $(PLAT_BL_COMMON_CFLAGS)) 33073c99d4eSJuan Castillo 331434d0491SZelalem Aweke$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 3327c4e1eeaSChris Kay $$(s)echo " CC $$<" 3337c4e1eeaSChris Kay $$(q)$($(ARCH)-cc) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@ 33473c99d4eSJuan Castillo 335710ea1d0SMasahiro Yamada-include $(DEP) 33673c99d4eSJuan Castillo 33773c99d4eSJuan Castilloendef 33873c99d4eSJuan Castillo 33973c99d4eSJuan Castillo 34073c99d4eSJuan Castillo# MAKE_S builds an assembly source file and generates the dependency file 34173c99d4eSJuan Castillo# $(1) = output directory 34273c99d4eSJuan Castillo# $(2) = assembly file (%.S) 343434d0491SZelalem Aweke# $(3) = BL stage 34473c99d4eSJuan Castillodefine MAKE_S 34573c99d4eSJuan Castillo 34673c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 347710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 348a123cb14SChris Kay 3491ab8c109SChris Kay$(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) 3501ab8c109SChris Kay$(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) 3511ab8c109SChris Kay$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) 3521ab8c109SChris Kay$(eval BL_ASFLAGS := $($(call uppercase,$(3))_ASFLAGS) $(PLAT_BL_COMMON_ASFLAGS)) 35373c99d4eSJuan Castillo 354434d0491SZelalem Aweke$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 3557c4e1eeaSChris Kay $$(s)echo " AS $$<" 3567c4e1eeaSChris Kay $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS_$(ARCH)) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@ 35773c99d4eSJuan Castillo 358710ea1d0SMasahiro Yamada-include $(DEP) 35973c99d4eSJuan Castillo 36073c99d4eSJuan Castilloendef 36173c99d4eSJuan Castillo 36273c99d4eSJuan Castillo 36373c99d4eSJuan Castillo# MAKE_LD generate the linker script using the C preprocessor 36473c99d4eSJuan Castillo# $(1) = output linker script 36573c99d4eSJuan Castillo# $(2) = input template 366434d0491SZelalem Aweke# $(3) = BL stage 36773c99d4eSJuan Castillodefine MAKE_LD 36873c99d4eSJuan Castillo 369710ea1d0SMasahiro Yamada$(eval DEP := $(1).d) 370a123cb14SChris Kay 3711ab8c109SChris Kay$(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) 3721ab8c109SChris Kay$(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) 3731ab8c109SChris Kay$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) 37473c99d4eSJuan Castillo 375434d0491SZelalem Aweke$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs 3767c4e1eeaSChris Kay $$(s)echo " PP $$<" 3777c4e1eeaSChris Kay $$(q)$($(ARCH)-cpp) -E $$(CPPFLAGS) $(BL_CPPFLAGS) $(TF_CFLAGS_$(ARCH)) -P -x assembler-with-cpp -D__LINKER__ $(MAKE_DEP) -o $$@ $$< 37873c99d4eSJuan Castillo 379710ea1d0SMasahiro Yamada-include $(DEP) 38073c99d4eSJuan Castillo 38173c99d4eSJuan Castilloendef 38273c99d4eSJuan Castillo 38370b0f278SAntonio Nino Diaz# MAKE_LIB_OBJS builds both C and assembly source files 3845fee0287SRoberto Vargas# $(1) = output directory 3855fee0287SRoberto Vargas# $(2) = list of source files 3865fee0287SRoberto Vargas# $(3) = name of the library 3875fee0287SRoberto Vargasdefine MAKE_LIB_OBJS 3885fee0287SRoberto Vargas $(eval C_OBJS := $(filter %.c,$(2))) 3895fee0287SRoberto Vargas $(eval REMAIN := $(filter-out %.c,$(2))) 3905fee0287SRoberto Vargas $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3)))) 3915fee0287SRoberto Vargas 39270b0f278SAntonio Nino Diaz $(eval S_OBJS := $(filter %.S,$(REMAIN))) 39370b0f278SAntonio Nino Diaz $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 39470b0f278SAntonio Nino Diaz $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3)))) 39570b0f278SAntonio Nino Diaz 3965fee0287SRoberto Vargas $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 3975fee0287SRoberto Vargasendef 3985fee0287SRoberto Vargas 39973c99d4eSJuan Castillo 40073c99d4eSJuan Castillo# MAKE_OBJS builds both C and assembly source files 40173c99d4eSJuan Castillo# $(1) = output directory 40273c99d4eSJuan Castillo# $(2) = list of source files (both C and assembly) 403434d0491SZelalem Aweke# $(3) = BL stage 40473c99d4eSJuan Castillodefine MAKE_OBJS 40573c99d4eSJuan Castillo $(eval C_OBJS := $(filter %.c,$(2))) 40673c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.c,$(2))) 40773c99d4eSJuan Castillo $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3)))) 40873c99d4eSJuan Castillo 40973c99d4eSJuan Castillo $(eval S_OBJS := $(filter %.S,$(REMAIN))) 41073c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 41173c99d4eSJuan Castillo $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3)))) 41273c99d4eSJuan Castillo 41373c99d4eSJuan Castillo $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 41473c99d4eSJuan Castilloendef 41573c99d4eSJuan Castillo 41673c99d4eSJuan Castillo 41773c99d4eSJuan Castillo# NOTE: The line continuation '\' is required in the next define otherwise we 41873c99d4eSJuan Castillo# end up with a line-feed characer at the end of the last c filename. 419e7f54dbdSEvan Lloyd# Also bear this issue in mind if extending the list of supported filetypes. 42073c99d4eSJuan Castillodefine SOURCES_TO_OBJS 42173c99d4eSJuan Castillo $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ 42273c99d4eSJuan Castillo $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) 42373c99d4eSJuan Castilloendef 42473c99d4eSJuan Castillo 4255fee0287SRoberto Vargas.PHONY: libraries 4265fee0287SRoberto Vargas 4275accce5bSRoberto Vargas# MAKE_LIB_DIRS macro defines the target for the directory where 4285fee0287SRoberto Vargas# libraries are created 4295accce5bSRoberto Vargasdefine MAKE_LIB_DIRS 4305fee0287SRoberto Vargas $(eval LIB_DIR := ${BUILD_PLAT}/lib) 4315accce5bSRoberto Vargas $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 4325accce5bSRoberto Vargas $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper) 4335fee0287SRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT})) 4345accce5bSRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT})) 4355accce5bSRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT})) 4365fee0287SRoberto Vargasendef 4375fee0287SRoberto Vargas 4385fee0287SRoberto Vargas# MAKE_LIB macro defines the targets and options to build each BL image. 4395fee0287SRoberto Vargas# Arguments: 4405fee0287SRoberto Vargas# $(1) = Library name 4415fee0287SRoberto Vargasdefine MAKE_LIB 4425fee0287SRoberto Vargas $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1)) 4435fee0287SRoberto Vargas $(eval LIB_DIR := ${BUILD_PLAT}/lib) 4445accce5bSRoberto Vargas $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 4455fee0287SRoberto Vargas $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS)) 4465fee0287SRoberto Vargas $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 4475fee0287SRoberto Vargas 4485fee0287SRoberto Vargas$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) 4495fee0287SRoberto Vargas$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) 4505fee0287SRoberto Vargas 4515fee0287SRoberto Vargas.PHONY : lib${1}_dirs 4525accce5bSRoberto Vargaslib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR} 4535fee0287SRoberto Vargaslibraries: ${LIB_DIR}/lib$(1).a 4548620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link) 455c2ad38ceSVarun WadekarLDPATHS = --userlibpath=${LIB_DIR} 456c2ad38ceSVarun WadekarLDLIBS += --library=$(1) 457c2ad38ceSVarun Wadekarelse 4585fee0287SRoberto VargasLDPATHS = -L${LIB_DIR} 4595fee0287SRoberto VargasLDLIBS += -l$(1) 460c2ad38ceSVarun Wadekarendif 4615fee0287SRoberto Vargas 4625accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 4636baf85b3SSathees BalyaLIBWRAPPER = -lwrappers 4645accce5bSRoberto Vargasendif 4655accce5bSRoberto Vargas 4665fee0287SRoberto Vargasall: ${LIB_DIR}/lib$(1).a 4675fee0287SRoberto Vargas 4685fee0287SRoberto Vargas${LIB_DIR}/lib$(1).a: $(OBJS) 4697c4e1eeaSChris Kay $$(s)echo " AR $$@" 4707c4e1eeaSChris Kay $$(q)$($(ARCH)-ar) cr $$@ $$? 4715fee0287SRoberto Vargasendef 4725fee0287SRoberto Vargas 47382274936SChris Kay# Generate the path to one or more preprocessed linker scripts given the paths 47482274936SChris Kay# of their sources. 47582274936SChris Kay# 47682274936SChris Kay# Arguments: 47782274936SChris Kay# $(1) = path to one or more linker script sources 47882274936SChris Kaydefine linker_script_path 47982274936SChris Kay $(patsubst %.S,$(BUILD_DIR)/%,$(1)) 48082274936SChris Kayendef 48182274936SChris Kay 482*d95d56bdSJimmy Brissonifeq ($(USE_ROMLIB),1) 483*d95d56bdSJimmy BrissonWRAPPER_FLAGS := @${BUILD_PLAT}/romlib/romlib.ldflags 484*d95d56bdSJimmy Brissonendif 485*d95d56bdSJimmy Brisson 48673c99d4eSJuan Castillo# MAKE_BL macro defines the targets and options to build each BL image. 48773c99d4eSJuan Castillo# Arguments: 488434d0491SZelalem Aweke# $(1) = BL stage 4898f0617efSJuan Castillo# $(2) = FIP command line option (if empty, image will not be included in the FIP) 4901dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 491c6ba9b45SSumit Garg# $(4) = BL encryption flag (optional) (0, 1) 49273c99d4eSJuan Castillodefine MAKE_BL 493434d0491SZelalem Aweke $(eval BUILD_DIR := ${BUILD_PLAT}/$(1)) 494434d0491SZelalem Aweke $(eval BL_SOURCES := $($(call uppercase,$(1))_SOURCES)) 495bb22fb84SChris Kay $(eval SOURCES := $(sort $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))) 49673c99d4eSJuan Castillo $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 49773c99d4eSJuan Castillo $(eval MAPFILE := $(call IMG_MAPFILE,$(1))) 49873c99d4eSJuan Castillo $(eval ELF := $(call IMG_ELF,$(1))) 49973c99d4eSJuan Castillo $(eval DUMP := $(call IMG_DUMP,$(1))) 50073c99d4eSJuan Castillo $(eval BIN := $(call IMG_BIN,$(1))) 501c6ba9b45SSumit Garg $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1))) 502434d0491SZelalem Aweke $(eval BL_LIBS := $($(call uppercase,$(1))_LIBS)) 50382274936SChris Kay 50482274936SChris Kay $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(call uppercase,$(1))_DEFAULT_LINKER_SCRIPT_SOURCE)) 50582274936SChris Kay $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE))) 50682274936SChris Kay 507a6ff0067SChris Kay $(eval LINKER_SCRIPT_SOURCES := $($(call uppercase,$(1))_LINKER_SCRIPT_SOURCES)) 508a6ff0067SChris Kay $(eval LINKER_SCRIPTS := $(call linker_script_path,$(LINKER_SCRIPT_SOURCES))) 509a6ff0067SChris Kay 51051b27702SEvan Lloyd # We use sort only to get a list of unique object directory names. 51151b27702SEvan Lloyd # ordering is not relevant but sort removes duplicates. 512a6ff0067SChris Kay $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${DEFAULT_LINKER_SCRIPT} ${LINKER_SCRIPTS}))) 51351b27702SEvan Lloyd # The $(dir ) function leaves a trailing / on the directory names 514d014ea6cSMasahiro Yamada # Rip off the / to match directory names with make rule targets. 515d014ea6cSMasahiro Yamada $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS))) 51651b27702SEvan Lloyd 51751b27702SEvan Lloyd# Create generators for object directory structure 51851b27702SEvan Lloyd 5198012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) 5206ba7d274SEvan Lloyd 52182274936SChris Kay$(eval $(foreach objd,${OBJ_DIRS}, 52282274936SChris Kay $(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) 52351b27702SEvan Lloyd 524434d0491SZelalem Aweke.PHONY : ${1}_dirs 52551b27702SEvan Lloyd 52651b27702SEvan Lloyd# We use order-only prerequisites to ensure that directories are created, 52751b27702SEvan Lloyd# but do not cause re-builds every time a file is written. 528434d0491SZelalem Aweke${1}_dirs: | ${OBJ_DIRS} 52973c99d4eSJuan Castillo 53073c99d4eSJuan Castillo$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) 531a6ff0067SChris Kay 532a6ff0067SChris Kay# Generate targets to preprocess each required linker script 533a6ff0067SChris Kay$(eval $(foreach source,$(DEFAULT_LINKER_SCRIPT_SOURCE) $(LINKER_SCRIPT_SOURCES), \ 534a6ff0067SChris Kay $(call MAKE_LD,$(call linker_script_path,$(source)),$(source),$(1)))) 535a6ff0067SChris Kay 536434d0491SZelalem Aweke$(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS)) 53773c99d4eSJuan Castillo 5385accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 5395accce5bSRoberto Vargas$(ELF): romlib.bin 5405accce5bSRoberto Vargasendif 5415accce5bSRoberto Vargas 5428dccddc7SLeon Chen# MODULE_OBJS can be assigned by vendors with different compiled 5438dccddc7SLeon Chen# object file path, and prebuilt object file path. 5448dccddc7SLeon Chen$(eval OBJS += $(MODULE_OBJS)) 5458dccddc7SLeon Chen 546a6ff0067SChris Kay$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) $(LINKER_SCRIPTS) | $(1)_dirs libraries $(BL_LIBS) 5477c4e1eeaSChris Kay $$(s)echo " LD $$@" 5488620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link) 5497c4e1eeaSChris Kay $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \ 550df52e260SChris Kay --predefine=$(call escape-shell,-D__LINKER__=$(__LINKER__)) \ 551df52e260SChris Kay --predefine=$(call escape-shell,-DTF_CFLAGS=$(TF_CFLAGS)) \ 552434d0491SZelalem Aweke --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \ 553758ccb80SChris Kay $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS) 5548620bd0bSChris Kayelse ifeq ($($(ARCH)-ld-id),gnu-gcc) 555*d95d56bdSJimmy Brisson $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $$(WRAPPER_FLAGS) $(BL_LDFLAGS) -Wl,-Map=$(MAPFILE) \ 556a6ff0067SChris Kay $(addprefix -Wl$(comma)--script$(comma),$(LINKER_SCRIPTS)) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) \ 557edbce9aaSzelalem-aweke $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) 558c2ad38ceSVarun Wadekarelse 559*d95d56bdSJimmy Brisson $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $$(WRAPPER_FLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \ 560a6ff0067SChris Kay $(addprefix -T ,$(LINKER_SCRIPTS)) --script $(DEFAULT_LINKER_SCRIPT) \ 5616baf85b3SSathees Balya $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) 562c2ad38ceSVarun Wadekarendif 5639e4609f1SChristoph Müllnerifeq ($(DISABLE_BIN_GENERATION),1) 5647c4e1eeaSChris Kay $(s)echo 5657c4e1eeaSChris Kay $(s)echo "Built $$@ successfully" 5667c4e1eeaSChris Kay $(s)echo 5679e4609f1SChristoph Müllnerendif 56873c99d4eSJuan Castillo 56973c99d4eSJuan Castillo$(DUMP): $(ELF) 5707c4e1eeaSChris Kay $$(s)echo " OD $$@" 5717c4e1eeaSChris Kay $$(q)$($(ARCH)-od) -dx $$< > $$@ 57273c99d4eSJuan Castillo 57373c99d4eSJuan Castillo$(BIN): $(ELF) 5747c4e1eeaSChris Kay $$(s)echo " BIN $$@" 5757c4e1eeaSChris Kay $$(q)$($(ARCH)-oc) -O binary $$< $$@ 5767c4e1eeaSChris Kay $(s)echo 5777c4e1eeaSChris Kay $(s)echo "Built $$@ successfully" 5787c4e1eeaSChris Kay $(s)echo 57973c99d4eSJuan Castillo 580434d0491SZelalem Aweke.PHONY: $(1) 5819e4609f1SChristoph Müllnerifeq ($(DISABLE_BIN_GENERATION),1) 582434d0491SZelalem Aweke$(1): $(ELF) $(DUMP) 5839e4609f1SChristoph Müllnerelse 584434d0491SZelalem Aweke$(1): $(BIN) $(DUMP) 5859e4609f1SChristoph Müllnerendif 58673c99d4eSJuan Castillo 587434d0491SZelalem Awekeall: $(1) 58873c99d4eSJuan Castillo 589c6ba9b45SSumit Gargifeq ($(4),1) 590c6ba9b45SSumit Garg$(call ENCRYPT_FW,$(BIN),$(ENC_BIN)) 591434d0491SZelalem Aweke$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(ENC_BIN),$(3), \ 592c6ba9b45SSumit Garg $(ENC_BIN))) 593c6ba9b45SSumit Gargelse 594434d0491SZelalem Aweke$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(BIN),$(3))) 595c6ba9b45SSumit Gargendif 59673c99d4eSJuan Castillo 59773c99d4eSJuan Castilloendef 59873c99d4eSJuan Castillo 59938c14d88SSoby Mathew# Convert device tree source file names to matching blobs 60038c14d88SSoby Mathew# $(1) = input dts 60103b397a8SNishanth Menondefine SOURCES_TO_DTBS 60203b397a8SNishanth Menon $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1)))) 60303b397a8SNishanth Menonendef 60403b397a8SNishanth Menon 60538c14d88SSoby Mathew# MAKE_FDT_DIRS macro creates the prerequisite directories that host the 60638c14d88SSoby Mathew# FDT binaries 60738c14d88SSoby Mathew# $(1) = output directory 60838c14d88SSoby Mathew# $(2) = input dts 60938c14d88SSoby Mathewdefine MAKE_FDT_DIRS 61038c14d88SSoby Mathew $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 61103b397a8SNishanth Menon $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS}))) 61203b397a8SNishanth Menon # The $(dir ) function leaves a trailing / on the directory names 61303b397a8SNishanth Menon # Rip off the / to match directory names with make rule targets. 61403b397a8SNishanth Menon $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS))) 61503b397a8SNishanth Menon 61603b397a8SNishanth Menon$(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) 61703b397a8SNishanth Menon 61803b397a8SNishanth Menonfdt_dirs: ${DTB_DIRS} 61903b397a8SNishanth Menonendef 62003b397a8SNishanth Menon 62138c14d88SSoby Mathew# MAKE_DTB generate the Flattened device tree binary 62203b397a8SNishanth Menon# $(1) = output directory 62303b397a8SNishanth Menon# $(2) = input dts 62403b397a8SNishanth Menondefine MAKE_DTB 62503b397a8SNishanth Menon 626077b3e9aSYann Gautier# List of DTB file(s) to generate, based on DTS file basename list 62738c14d88SSoby Mathew$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 628077b3e9aSYann Gautier# List of the pre-compiled DTS file(s) 62901d237cbSYann Gautier$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2))))) 630077b3e9aSYann Gautier# Dependencies of the pre-compiled DTS file(s) on its source and included files 631077b3e9aSYann Gautier$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ))) 632077b3e9aSYann Gautier# Dependencies of the DT compilation on its pre-compiled DTS 633077b3e9aSYann Gautier$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ))) 63403b397a8SNishanth Menon 6357b453526SChris Kay$(DPRE): $(2) | fdt_dirs 6367c4e1eeaSChris Kay $$(s)echo " CPP $$<" 637077b3e9aSYann Gautier $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 6387c4e1eeaSChris Kay $$(q)$($(ARCH)-cpp) -E $$(TF_CFLAGS_$(ARCH)) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$< 6397b453526SChris Kay 6407b453526SChris Kay$(DOBJ): $(DPRE) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs 6417c4e1eeaSChris Kay $$(s)echo " DTC $$<" 6427c4e1eeaSChris Kay $$(q)$($(ARCH)-dtc) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $$< 64303b397a8SNishanth Menon 644077b3e9aSYann Gautier-include $(DTBDEP) 645077b3e9aSYann Gautier-include $(DTSDEP) 64603b397a8SNishanth Menon 64703b397a8SNishanth Menonendef 64803b397a8SNishanth Menon 64903b397a8SNishanth Menon# MAKE_DTBS builds flattened device tree sources 65003b397a8SNishanth Menon# $(1) = output directory 65103b397a8SNishanth Menon# $(2) = list of flattened device tree source files 65203b397a8SNishanth Menondefine MAKE_DTBS 65303b397a8SNishanth Menon $(eval DOBJS := $(filter %.dts,$(2))) 65403b397a8SNishanth Menon $(eval REMAIN := $(filter-out %.dts,$(2))) 65538c14d88SSoby Mathew $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN))) 65603b397a8SNishanth Menon $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj)))) 65703b397a8SNishanth Menon 65838c14d88SSoby Mathew $(eval $(call MAKE_FDT_DIRS,$(1),$(2))) 65938c14d88SSoby Mathew 66038c14d88SSoby Mathewdtbs: $(DTBS) 66138c14d88SSoby Mathewall: dtbs 66203b397a8SNishanth Menonendef 663