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*6e2fe623SLauren Wehrmeister# Convenience function for setting CRYPTO_SUPPORT per component based on build flags 45*6e2fe623SLauren Wehrmeister# $(eval $(call set_crypto_support,NEED_AUTH,NEED_HASH)) 46*6e2fe623SLauren Wehrmeister# $(1) = NEED_AUTH, determines need for authentication verification support 47*6e2fe623SLauren Wehrmeister# $(2) = NEED_HASH, determines need for hash calculation support 48*6e2fe623SLauren Wehrmeister# CRYPTO_SUPPORT is set to 0 (default), 1 (authentication only), 2 (hash only), or 49*6e2fe623SLauren Wehrmeister# 3 (both) based on what support is required. 50*6e2fe623SLauren Wehrmeisterdefine set_crypto_support 51*6e2fe623SLauren Wehrmeister ifeq ($($1)-$($2),1-1) 52*6e2fe623SLauren Wehrmeister CRYPTO_SUPPORT := 3 53*6e2fe623SLauren Wehrmeister else ifeq ($($2),1) 54*6e2fe623SLauren Wehrmeister CRYPTO_SUPPORT := 2 55*6e2fe623SLauren Wehrmeister else ifeq ($($1),1) 56*6e2fe623SLauren Wehrmeister CRYPTO_SUPPORT := 1 57*6e2fe623SLauren Wehrmeister else 58*6e2fe623SLauren Wehrmeister CRYPTO_SUPPORT := 0 59*6e2fe623SLauren Wehrmeister endif 60*6e2fe623SLauren Wehrmeisterendef 61*6e2fe623SLauren Wehrmeister 62116d2c09SLauren Wehrmeister# Convenience function for creating a build definition 63116d2c09SLauren Wehrmeister# $(call make_define,FOO) will have: 64116d2c09SLauren Wehrmeister# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise 65116d2c09SLauren Wehrmeistermake_define = -D$(1)$(if $($(1)),=$($(1))) 66116d2c09SLauren Wehrmeister 67116d2c09SLauren Wehrmeister# Convenience function for creating multiple build definitions 68116d2c09SLauren Wehrmeister# For BL1, BL1_CPPFLAGS += $(call make_defines,FOO BOO) 69116d2c09SLauren Wehrmeistermake_defines = $(foreach def,$(1),$(call make_define,$(def))) 70116d2c09SLauren Wehrmeister 7173c99d4eSJuan Castillo# Convenience function for adding build definitions 7273c99d4eSJuan Castillo# $(eval $(call add_define,FOO)) will have: 7373c99d4eSJuan Castillo# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise 7473c99d4eSJuan Castillodefine add_define 7573c99d4eSJuan Castillo DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) 7673c99d4eSJuan Castilloendef 7773c99d4eSJuan Castillo 78327131c4SLeonardo Sandoval# Convenience function for addding multiple build definitions 79327131c4SLeonardo Sandoval# $(eval $(call add_defines,FOO BOO)) 80327131c4SLeonardo Sandovaldefine add_defines 81327131c4SLeonardo Sandoval $(foreach def,$1,$(eval $(call add_define,$(def)))) 82327131c4SLeonardo Sandovalendef 83327131c4SLeonardo Sandoval 848eadeb4aSSoren Brinkmann# Convenience function for adding build definitions 858eadeb4aSSoren Brinkmann# $(eval $(call add_define_val,FOO,BAR)) will have: 868eadeb4aSSoren Brinkmann# -DFOO=BAR 878eadeb4aSSoren Brinkmanndefine add_define_val 888eadeb4aSSoren Brinkmann DEFINES += -D$(1)=$(2) 898eadeb4aSSoren Brinkmannendef 908eadeb4aSSoren Brinkmann 9173c99d4eSJuan Castillo# Convenience function for verifying option has a boolean value 9273c99d4eSJuan Castillo# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 9373c99d4eSJuan Castillodefine assert_boolean 941369fb82SYann Gautier $(if $($(1)),,$(error $(1) must not be empty)) 95be4cd40eSMasahiro Yamada $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean)) 9673c99d4eSJuan Castilloendef 9773c99d4eSJuan Castillo 98327131c4SLeonardo Sandoval# Convenience function for verifying options have boolean values 99327131c4SLeonardo Sandoval# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values 100327131c4SLeonardo Sandovaldefine assert_booleans 101327131c4SLeonardo Sandoval $(foreach bool,$1,$(eval $(call assert_boolean,$(bool)))) 102327131c4SLeonardo Sandovalendef 103327131c4SLeonardo Sandoval 104c877b414SJeenu Viswambharan0-9 := 0 1 2 3 4 5 6 7 8 9 105c877b414SJeenu Viswambharan 106c877b414SJeenu Viswambharan# Function to verify that a given option $(1) contains a numeric value 107c877b414SJeenu Viswambharandefine assert_numeric 108c877b414SJeenu Viswambharan$(if $($(1)),,$(error $(1) must not be empty)) 109c877b414SJeenu Viswambharan$(eval __numeric := $($(1))) 110c877b414SJeenu Viswambharan$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) 111c877b414SJeenu Viswambharan$(if $(__numeric),$(error $(1) must be numeric)) 112c877b414SJeenu Viswambharanendef 113c877b414SJeenu Viswambharan 114327131c4SLeonardo Sandoval# Convenience function for verifying options have numeric values 115327131c4SLeonardo Sandoval# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values 116327131c4SLeonardo Sandovaldefine assert_numerics 117327131c4SLeonardo Sandoval $(foreach num,$1,$(eval $(call assert_numeric,$(num)))) 118327131c4SLeonardo Sandovalendef 119327131c4SLeonardo Sandoval 120b45fc164SBoyan Karatotev# Convenience function to check for a given linker option. A call to 121b45fc164SBoyan Karatotev# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker, 122b45fc164SBoyan Karatotev# prefixed appropriately for the linker in use 123b45fc164SBoyan Karatotevld_option = $(call toolchain-ld-option,$(ARCH),$(1)) 124a5f09cf7SMarco Felsch 1256c2e5bf6SBoyan Karatotev# Convenience function to add a prefix to a linker flag if necessary. Useful 1266c2e5bf6SBoyan Karatotev# when the flag is known to be supported and it just needs to be prefixed 1276c2e5bf6SBoyan Karatotev# correctly. 1286c2e5bf6SBoyan Karatotevld_prefix = $(toolchain-ld-prefix-$($(ARCH)-ld-id)) 1298c7b944aSVijayenthiran Subramaniam 130dea23e24SGovindraj Raja# Convenience function to check for a given compiler option. A call to 131dea23e24SGovindraj Raja# $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler 132316f5c97SBoyan Karatotev# NOTE: consider assigning to an immediately expanded temporary variable before 133316f5c97SBoyan Karatotev# assigning. This is because variables like TF_CFLAGS are recursively expanded 134316f5c97SBoyan Karatotev# and assigning this directly will cause it to be expanded every time the 135316f5c97SBoyan Karatotev# variable is used, potentially thrashing multicore performance. 136dea23e24SGovindraj Rajadefine cc_option 137ffb77421SChris Kay $(shell if $($(ARCH)-cc) $(1) -c -x c /dev/null -o /dev/null >/dev/null 2>&1; then echo $(1); fi ) 138dea23e24SGovindraj Rajaendef 139dea23e24SGovindraj Raja 1408c7b944aSVijayenthiran Subramaniam# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to 1418c7b944aSVijayenthiran Subramaniam# $(2) and assign the sequence to $(1) 1428c7b944aSVijayenthiran Subramaniamdefine CREATE_SEQ 1438c7b944aSVijayenthiran Subramaniam$(if $(word $(2), $($(1))),\ 1448c7b944aSVijayenthiran Subramaniam $(eval $(1) += $(words $($(1))))\ 1458c7b944aSVijayenthiran Subramaniam $(eval $(1) := $(filter-out 0,$($(1)))),\ 1468c7b944aSVijayenthiran Subramaniam $(eval $(1) += $(words $($(1))))\ 1478c7b944aSVijayenthiran Subramaniam $(call CREATE_SEQ,$(1),$(2))\ 1488c7b944aSVijayenthiran Subramaniam) 1498c7b944aSVijayenthiran Subramaniamendef 1508c7b944aSVijayenthiran Subramaniam 15173c99d4eSJuan Castillo# IMG_MAPFILE defines the output file describing the memory map corresponding 15273c99d4eSJuan Castillo# to a BL stage 153434d0491SZelalem Aweke# $(1) = BL stage 15473c99d4eSJuan Castillodefine IMG_MAPFILE 155434d0491SZelalem Aweke ${BUILD_DIR}/$(1).map 15673c99d4eSJuan Castilloendef 15773c99d4eSJuan Castillo 15873c99d4eSJuan Castillo# IMG_ELF defines the elf file corresponding to a BL stage 159434d0491SZelalem Aweke# $(1) = BL stage 16073c99d4eSJuan Castillodefine IMG_ELF 161434d0491SZelalem Aweke ${BUILD_DIR}/$(1).elf 16273c99d4eSJuan Castilloendef 16373c99d4eSJuan Castillo 16473c99d4eSJuan Castillo# IMG_DUMP defines the symbols dump file corresponding to a BL stage 165434d0491SZelalem Aweke# $(1) = BL stage 16673c99d4eSJuan Castillodefine IMG_DUMP 167434d0491SZelalem Aweke ${BUILD_DIR}/$(1).dump 16873c99d4eSJuan Castilloendef 16973c99d4eSJuan Castillo 17073c99d4eSJuan Castillo# IMG_BIN defines the default image file corresponding to a BL stage 171434d0491SZelalem Aweke# $(1) = BL stage 17273c99d4eSJuan Castillodefine IMG_BIN 173434d0491SZelalem Aweke ${BUILD_PLAT}/$(1).bin 17473c99d4eSJuan Castilloendef 17573c99d4eSJuan Castillo 176c6ba9b45SSumit Garg# IMG_ENC_BIN defines the default encrypted image file corresponding to a 177c6ba9b45SSumit Garg# BL stage 178434d0491SZelalem Aweke# $(1) = BL stage 179c6ba9b45SSumit Gargdefine IMG_ENC_BIN 180434d0491SZelalem Aweke ${BUILD_PLAT}/$(1)_enc.bin 181c6ba9b45SSumit Gargendef 182c6ba9b45SSumit Garg 183c6ba9b45SSumit Garg# ENCRYPT_FW invokes enctool to encrypt firmware binary 184c6ba9b45SSumit Garg# $(1) = input firmware binary 185c6ba9b45SSumit Garg# $(2) = output encrypted firmware binary 186c6ba9b45SSumit Gargdefine ENCRYPT_FW 187c6ba9b45SSumit Garg$(2): $(1) enctool 1887c4e1eeaSChris Kay $$(s)echo " ENC $$<" 1897c4e1eeaSChris Kay $$(q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@ 190c6ba9b45SSumit Gargendef 191c6ba9b45SSumit Garg 19210cea934SMasahiro Yamada# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to 19310cea934SMasahiro Yamada# package a new payload and/or by cert_create to generate certificate. 19410cea934SMasahiro Yamada# Optionally, it adds the dependency on this payload 19573c99d4eSJuan Castillo# $(1) = payload filename (i.e. bl31.bin) 1961e0c0784SMasahiro Yamada# $(2) = command line option for the specified payload (i.e. --soc-fw) 19736af3455SMasahiro Yamada# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 1981dc0714fSMasahiro Yamada# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 199c6ba9b45SSumit Garg# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 20010cea934SMasahiro Yamadadefine TOOL_ADD_PAYLOAD 201c6ba9b45SSumit Gargifneq ($(5),) 202c6ba9b45SSumit Garg $(4)FIP_ARGS += $(2) $(5) 203c6ba9b45SSumit Garg $(if $(3),$(4)CRT_DEPS += $(1)) 204c6ba9b45SSumit Gargelse 205945b316fSMasahiro Yamada $(4)FIP_ARGS += $(2) $(1) 206c6ba9b45SSumit Garg $(if $(3),$(4)CRT_DEPS += $(3)) 207c6ba9b45SSumit Gargendif 208945b316fSMasahiro Yamada $(if $(3),$(4)FIP_DEPS += $(3)) 209f30ee0b9SMasahiro Yamada $(4)CRT_ARGS += $(2) $(1) 21073c99d4eSJuan Castilloendef 21173c99d4eSJuan Castillo 2122da522bbSMasahiro Yamada# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters 2132da522bbSMasahiro Yamada# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined. 2142da522bbSMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 2152da522bbSMasahiro Yamada# $(2) = payload filepath (ex. build/fvp/release/bl31.bin) 2162da522bbSMasahiro Yamada# $(3) = command line option for the specified payload (ex. --soc-fw) 2172da522bbSMasahiro Yamada# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 2182da522bbSMasahiro Yamada# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 219c6ba9b45SSumit Garg# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) 2202da522bbSMasahiro Yamada 2212da522bbSMasahiro Yamadadefine TOOL_ADD_IMG_PAYLOAD 2222da522bbSMasahiro Yamada 223f7a41fb4SBoyan Karatotev$(eval PRE_TOOL_FILTER := $($(1)_PRE_TOOL_FILTER)) 2242da522bbSMasahiro Yamada 2252da522bbSMasahiro Yamadaifneq ($(PRE_TOOL_FILTER),) 2262da522bbSMasahiro Yamada 2272da522bbSMasahiro Yamada$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX)) 2282da522bbSMasahiro Yamada 2292da522bbSMasahiro Yamada$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2)) 2302da522bbSMasahiro Yamada 2312da522bbSMasahiro Yamada$(PROCESSED_PATH): $(4) 2322da522bbSMasahiro Yamada 233c6ba9b45SSumit Garg$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6)) 2342da522bbSMasahiro Yamada 2352da522bbSMasahiro Yamadaelse 236c6ba9b45SSumit Garg$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6)) 2372da522bbSMasahiro Yamadaendif 2382da522bbSMasahiro Yamadaendef 2392da522bbSMasahiro Yamada 2400191262dSYatharth Kochar# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation 24173c99d4eSJuan Castillo# $(1) = parameter filename 24273c99d4eSJuan Castillo# $(2) = cert_create command line option for the specified parameter 24391704d9dSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 24473c99d4eSJuan Castillodefine CERT_ADD_CMD_OPT 24591704d9dSMasahiro Yamada $(3)CRT_ARGS += $(2) $(1) 24673c99d4eSJuan Castilloendef 24773c99d4eSJuan Castillo 248c939d13aSMasahiro Yamada# TOOL_ADD_IMG allows the platform to specify an external image to be packed 249c939d13aSMasahiro Yamada# in the FIP and/or for which certificate is generated. It also adds a 250c939d13aSMasahiro Yamada# dependency on the image file, aborting the build if the file does not exist. 25133950dd8SMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 2521e0c0784SMasahiro Yamada# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc) 2531dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 254c6ba9b45SSumit Garg# $(4) = Image encryption flag (optional) (0, 1) 25573c99d4eSJuan Castillo# Example: 25633950dd8SMasahiro Yamada# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 257c939d13aSMasahiro Yamadadefine TOOL_ADD_IMG 25833950dd8SMasahiro Yamada # Build option to specify the image filename (SCP_BL2, BL33, etc) 25933950dd8SMasahiro Yamada # This is the uppercase form of the first parameter 260f7a41fb4SBoyan Karatotev $(eval BL := $(call uppercase,$(1))) 261f7a41fb4SBoyan Karatotev $(eval _V := $(BL)) 26233950dd8SMasahiro Yamada 2634727fd13SPali Rohár # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also 2644727fd13SPali Rohár # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the 2654727fd13SPali Rohár # target ${BUILD_PLAT}/${$(3)FIP_NAME}. 2664727fd13SPali Rohár $(eval check_$(1)_cmd := \ 2674727fd13SPali Rohár $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \ 2684727fd13SPali Rohár $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \ 2694727fd13SPali Rohár ) 2704727fd13SPali Rohár 271945b316fSMasahiro Yamada $(3)CRT_DEPS += check_$(1) 2724727fd13SPali Rohár CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd) 273c6ba9b45SSumit Gargifeq ($(4),1) 274c6ba9b45SSumit Garg $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin) 275c6ba9b45SSumit Garg $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN)) 276f7a41fb4SBoyan Karatotev $(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(value $(_V)),$(2),$(ENC_BIN),$(3), \ 277c6ba9b45SSumit Garg $(ENC_BIN)) 278c6ba9b45SSumit Gargelse 279f7a41fb4SBoyan Karatotev $(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3)) 280c6ba9b45SSumit Gargendif 2810191262dSYatharth Kochar 28287ebd20dSMasahiro Yamada.PHONY: check_$(1) 2830191262dSYatharth Kocharcheck_$(1): 2844727fd13SPali Rohár $(check_$(1)_cmd) 2850191262dSYatharth Kocharendef 28673c99d4eSJuan Castillo 287cf2dd17dSJuan Pablo Conde# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to 288cf2dd17dSJuan Pablo Conde# build the host tools by checking the version of OpenSSL located under 289cf2dd17dSJuan Pablo Conde# the path defined by the OPENSSL_DIR variable. It receives no parameters. 290cf2dd17dSJuan Pablo Condedefine SELECT_OPENSSL_API_VERSION 291cf2dd17dSJuan Pablo Conde # Set default value for USING_OPENSSL3 macro to 0 292cf2dd17dSJuan Pablo Conde $(eval USING_OPENSSL3 = 0) 293cf2dd17dSJuan Pablo Conde # Obtain the OpenSSL version for the build located under OPENSSL_DIR 294cf2dd17dSJuan Pablo Conde $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version)) 295cf2dd17dSJuan Pablo Conde $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO})) 296cf2dd17dSJuan Pablo Conde $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER)))) 297cf2dd17dSJuan Pablo Conde # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1 298cf2dd17dSJuan Pablo Conde $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1)) 299cf2dd17dSJuan Pablo Condeendef 300cf2dd17dSJuan Pablo Conde 30173c99d4eSJuan Castillo################################################################################ 30214db8908SMasahiro Yamada# Generic image processing filters 30314db8908SMasahiro Yamada################################################################################ 30414db8908SMasahiro Yamada 30514db8908SMasahiro Yamada# GZIP 30614db8908SMasahiro Yamadadefine GZIP_RULE 30714db8908SMasahiro Yamada$(1): $(2) 3087c4e1eeaSChris Kay $(s)echo " GZIP $$@" 3097c4e1eeaSChris Kay $(q)gzip -n -f -9 $$< --stdout > $$@ 31014db8908SMasahiro Yamadaendef 31114db8908SMasahiro Yamada 31214db8908SMasahiro YamadaGZIP_SUFFIX := .gz 31314db8908SMasahiro Yamada 31414db8908SMasahiro Yamada################################################################################ 31573c99d4eSJuan Castillo# Auxiliary macros to build TF images from sources 31673c99d4eSJuan Castillo################################################################################ 31773c99d4eSJuan Castillo 318a7bbd8e7SChris KayMAKE_DEP = -Wp,-MD,$1 -MT $2 -MP 31973c99d4eSJuan Castillo 320cbd6cec3SBoyan Karatotev# MAKE_TOOL_C builds a C source file and generates the dependency file 321cbd6cec3SBoyan Karatotev# $(1) = output directory 322cbd6cec3SBoyan Karatotev# $(2) = source file (%.c) 323cbd6cec3SBoyan Karatotev# $(3) = lowercase name of the tool 324cbd6cec3SBoyan Karatotev# $(4) = uppercase name of the tool 325cbd6cec3SBoyan Karatotevdefine MAKE_TOOL_C 326cbd6cec3SBoyan Karatotev 327cbd6cec3SBoyan Karatotev$(eval SRC := $(2)) 328cbd6cec3SBoyan Karatotev$(eval OBJ := $(patsubst %.c,$(1)/$(3)/%.o,$(SRC))) 329cbd6cec3SBoyan Karatotev$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 330cbd6cec3SBoyan Karatotev 331cbd6cec3SBoyan Karatotev$(eval TOOL_DEFINES := $($(4)_DEFINES)) 332cbd6cec3SBoyan Karatotev$(eval TOOL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS)) 333cbd6cec3SBoyan Karatotev$(eval TOOL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(TOOL_DEFINES)) $(addprefix -I,$(TOOL_INCLUDE_DIRS))) 334cbd6cec3SBoyan Karatotev$(eval TOOL_CFLAGS := $($(4)_CFLAGS)) 335cbd6cec3SBoyan Karatotev 336cbd6cec3SBoyan Karatotev$(OBJ): $(SRC) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 337cbd6cec3SBoyan Karatotev $$(s)echo " HOSTCC $$<" 338cbd6cec3SBoyan Karatotev $$(q)$(host-cc) $$(HOSTCCFLAGS) $(TOOL_CPPFLAGS) $(TOOL_CFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 339cbd6cec3SBoyan Karatotev 340cbd6cec3SBoyan Karatotev-include $(DEP) 341cbd6cec3SBoyan Karatotev 342cbd6cec3SBoyan Karatotevendef 343cbd6cec3SBoyan Karatotev 344cbd6cec3SBoyan Karatotev# MAKE_TOOL 345cbd6cec3SBoyan Karatotev# $(1) = output directory 346cbd6cec3SBoyan Karatotev# $(2) = lowercase name of the tool 347cbd6cec3SBoyan Karatotev# $(3) = uppercase name of the tool 348cbd6cec3SBoyan Karatotevdefine MAKE_TOOL 349cbd6cec3SBoyan Karatotev$(eval SRCS := $($(3)_SOURCES)) 350cbd6cec3SBoyan Karatotev$(eval OBJS := $(patsubst %.c,$(1)/$(2)/%.o,$(SRCS))) 351cbd6cec3SBoyan Karatotev$(eval DST := $(1)/$(2)/$(2)$(.exe)) 352cbd6cec3SBoyan Karatotev$(eval $(foreach src,$(SRCS),$(call MAKE_TOOL_C,$(1),$(src),$(2),$(3)))) 353cbd6cec3SBoyan Karatotev 354774fb379SBoyan Karatotev$(DST): $(OBJS) $(filter-out %.d,$(MAKEFILE_LIST)) | $(1) 355cbd6cec3SBoyan Karatotev $$(s)echo " HOSTLD $$@" 356cbd6cec3SBoyan Karatotev $$(q)$(host-cc) $${OBJS} -o $$@ $($(3)_LDFLAGS) 357cbd6cec3SBoyan Karatotev $$(s)echo 358cbd6cec3SBoyan Karatotev $$(s)echo "Built $$@ successfully" 359cbd6cec3SBoyan Karatotev $$(s)echo 360cbd6cec3SBoyan Karatotev 361cbd6cec3SBoyan Karatotevall: $(DST) 362cbd6cec3SBoyan Karatotevendef 3635fee0287SRoberto Vargas 3645fee0287SRoberto Vargas# MAKE_C_LIB builds a C source file and generates the dependency file 3655fee0287SRoberto Vargas# $(1) = output directory 3665fee0287SRoberto Vargas# $(2) = source file (%.c) 3675fee0287SRoberto Vargas# $(3) = library name 368f7a41fb4SBoyan Karatotev# $(4) = uppercase name of the library 3695fee0287SRoberto Vargasdefine MAKE_C_LIB 3705fee0287SRoberto Vargas$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 3715fee0287SRoberto Vargas$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 372f7a41fb4SBoyan Karatotev$(eval LIB := $(notdir $(1))) 3735fee0287SRoberto Vargas 374f4dd18c2SChris Kay$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 3757c4e1eeaSChris Kay $$(s)echo " CC $$<" 376d8a23ecdSSlava Andrianov $$(q)$($(ARCH)-cc) $$(LIB$(4)_CFLAGS) $$(TF_CFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 3775fee0287SRoberto Vargas 3785fee0287SRoberto Vargas-include $(DEP) 3795fee0287SRoberto Vargas 3805fee0287SRoberto Vargasendef 3815fee0287SRoberto Vargas 38270b0f278SAntonio Nino Diaz# MAKE_S_LIB builds an assembly source file and generates the dependency file 38370b0f278SAntonio Nino Diaz# $(1) = output directory 38470b0f278SAntonio Nino Diaz# $(2) = source file (%.S) 38570b0f278SAntonio Nino Diaz# $(3) = library name 386f7a41fb4SBoyan Karatotev# $(4) = uppercase name of the library 38770b0f278SAntonio Nino Diazdefine MAKE_S_LIB 38870b0f278SAntonio Nino Diaz$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 38970b0f278SAntonio Nino Diaz$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 39070b0f278SAntonio Nino Diaz 391f4dd18c2SChris Kay$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 3927c4e1eeaSChris Kay $$(s)echo " AS $$<" 3937416eb2fSBoyan Karatotev $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS) $$(ASFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 39470b0f278SAntonio Nino Diaz 39570b0f278SAntonio Nino Diaz-include $(DEP) 39670b0f278SAntonio Nino Diaz 39770b0f278SAntonio Nino Diazendef 39870b0f278SAntonio Nino Diaz 3995fee0287SRoberto Vargas 40073c99d4eSJuan Castillo# MAKE_C builds a C source file and generates the dependency file 40173c99d4eSJuan Castillo# $(1) = output directory 40273c99d4eSJuan Castillo# $(2) = source file (%.c) 403434d0491SZelalem Aweke# $(3) = BL stage 404f7a41fb4SBoyan Karatotev# $(4) = uppercase BL stage 40573c99d4eSJuan Castillodefine MAKE_C 40673c99d4eSJuan Castillo 40773c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 408710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 409a123cb14SChris Kay 410500927efSBoyan Karatotev$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES)) 411500927efSBoyan Karatotev$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS)) 412500927efSBoyan Karatotev$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS))) 413500927efSBoyan Karatotev$(eval BL_CFLAGS := $($(4)_CFLAGS)) 41473c99d4eSJuan Castillo 415f4dd18c2SChris Kay$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 4167c4e1eeaSChris Kay $$(s)echo " CC $$<" 4176bb9f053SBoyan Karatotev $$(q)$($(ARCH)-cc) $$(LTO_CFLAGS) $$(TF_CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 41873c99d4eSJuan Castillo 419710ea1d0SMasahiro Yamada-include $(DEP) 42073c99d4eSJuan Castillo 42173c99d4eSJuan Castilloendef 42273c99d4eSJuan Castillo 42373c99d4eSJuan Castillo 42473c99d4eSJuan Castillo# MAKE_S builds an assembly source file and generates the dependency file 42573c99d4eSJuan Castillo# $(1) = output directory 42673c99d4eSJuan Castillo# $(2) = assembly file (%.S) 427434d0491SZelalem Aweke# $(3) = BL stage 428f7a41fb4SBoyan Karatotev# $(4) = uppercase BL stage 42973c99d4eSJuan Castillodefine MAKE_S 43073c99d4eSJuan Castillo 43173c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 432710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 433a123cb14SChris Kay 434500927efSBoyan Karatotev$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES)) 435500927efSBoyan Karatotev$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS)) 436500927efSBoyan Karatotev$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS))) 437500927efSBoyan Karatotev$(eval BL_ASFLAGS := $($(4)_ASFLAGS)) 43873c99d4eSJuan Castillo 439f4dd18c2SChris Kay$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 4407c4e1eeaSChris Kay $$(s)echo " AS $$<" 4417416eb2fSBoyan Karatotev $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(call MAKE_DEP,$(DEP),$(OBJ)) -c $$< -o $$@ 44273c99d4eSJuan Castillo 443710ea1d0SMasahiro Yamada-include $(DEP) 44473c99d4eSJuan Castillo 44573c99d4eSJuan Castilloendef 44673c99d4eSJuan Castillo 4471e8b5354SBoyan Karatotev# MAKE_PRE run the C preprocessor on a file 4481e8b5354SBoyan Karatotev# $(1) = output file 4491e8b5354SBoyan Karatotev# $(2) = list of input files 4501e8b5354SBoyan Karatotev# $(3) = dep file 4511e8b5354SBoyan Karatotev# $(4) = list of rule-specific flags to pass 4521e8b5354SBoyan Karatotevdefine MAKE_PRE 4531e8b5354SBoyan Karatotev$(eval OUT := $(1)) 4541e8b5354SBoyan Karatotev$(eval SRC := $(2)) 4551e8b5354SBoyan Karatotev$(eval DEP := $(3)) 4561e8b5354SBoyan Karatotev$(eval CUSTOM_FLAGS := $(4)) 4571e8b5354SBoyan Karatotev$(OUT): $(SRC) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 4581e8b5354SBoyan Karatotev $$(s)echo " CPP $$<" 4591e8b5354SBoyan Karatotev $$(q)$($(ARCH)-cpp) -E -P -x assembler-with-cpp $$(TF_CFLAGS) $(CUSTOM_FLAGS) $(call MAKE_DEP,$(DEP),$(OUT)) -o $$@ $$< 4601e8b5354SBoyan Karatotevendef 46173c99d4eSJuan Castillo 46273c99d4eSJuan Castillo# MAKE_LD generate the linker script using the C preprocessor 46373c99d4eSJuan Castillo# $(1) = output linker script 46473c99d4eSJuan Castillo# $(2) = input template 465434d0491SZelalem Aweke# $(3) = BL stage 466f7a41fb4SBoyan Karatotev# $(4) = uppercase BL stage 46773c99d4eSJuan Castillodefine MAKE_LD 46873c99d4eSJuan Castillo 469710ea1d0SMasahiro Yamada$(eval DEP := $(1).d) 470a123cb14SChris Kay 471500927efSBoyan Karatotev$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES)) 472500927efSBoyan Karatotev$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS)) 473500927efSBoyan Karatotev$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS))) 4741e8b5354SBoyan Karatotev$(eval FLAGS := -D__LINKER__ $(BL_CPPFLAGS)) 47573c99d4eSJuan Castillo 4761e8b5354SBoyan Karatotev$(eval $(call MAKE_PRE,$(1),$(2),$(DEP),$(FLAGS))) 477710ea1d0SMasahiro Yamada-include $(DEP) 47873c99d4eSJuan Castillo 47973c99d4eSJuan Castilloendef 48073c99d4eSJuan Castillo 48170b0f278SAntonio Nino Diaz# MAKE_LIB_OBJS builds both C and assembly source files 4825fee0287SRoberto Vargas# $(1) = output directory 4835fee0287SRoberto Vargas# $(2) = list of source files 4845fee0287SRoberto Vargas# $(3) = name of the library 485f7a41fb4SBoyan Karatotev# $(4) = uppercase name of the library 4865fee0287SRoberto Vargasdefine MAKE_LIB_OBJS 4875fee0287SRoberto Vargas $(eval C_OBJS := $(filter %.c,$(2))) 4885fee0287SRoberto Vargas $(eval REMAIN := $(filter-out %.c,$(2))) 489f7a41fb4SBoyan Karatotev $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3),$(4)))) 4905fee0287SRoberto Vargas 49170b0f278SAntonio Nino Diaz $(eval S_OBJS := $(filter %.S,$(REMAIN))) 49270b0f278SAntonio Nino Diaz $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 493f7a41fb4SBoyan Karatotev $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3),$(4)))) 49470b0f278SAntonio Nino Diaz 4955fee0287SRoberto Vargas $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 4965fee0287SRoberto Vargasendef 4975fee0287SRoberto Vargas 49873c99d4eSJuan Castillo 49973c99d4eSJuan Castillo# MAKE_OBJS builds both C and assembly source files 50073c99d4eSJuan Castillo# $(1) = output directory 50173c99d4eSJuan Castillo# $(2) = list of source files (both C and assembly) 502434d0491SZelalem Aweke# $(3) = BL stage 503f7a41fb4SBoyan Karatotev# $(4) = uppercase BL stage 50473c99d4eSJuan Castillodefine MAKE_OBJS 50573c99d4eSJuan Castillo $(eval C_OBJS := $(filter %.c,$(2))) 50673c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.c,$(2))) 507f7a41fb4SBoyan Karatotev $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3),$(4)))) 50873c99d4eSJuan Castillo 50973c99d4eSJuan Castillo $(eval S_OBJS := $(filter %.S,$(REMAIN))) 51073c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 511f7a41fb4SBoyan Karatotev $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3),$(4)))) 51273c99d4eSJuan Castillo 51373c99d4eSJuan Castillo $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 51473c99d4eSJuan Castilloendef 51573c99d4eSJuan Castillo 51673c99d4eSJuan Castillo 51773c99d4eSJuan Castillo# NOTE: The line continuation '\' is required in the next define otherwise we 51873c99d4eSJuan Castillo# end up with a line-feed characer at the end of the last c filename. 519e7f54dbdSEvan Lloyd# Also bear this issue in mind if extending the list of supported filetypes. 52073c99d4eSJuan Castillodefine SOURCES_TO_OBJS 52173c99d4eSJuan Castillo $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ 52273c99d4eSJuan Castillo $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) 52373c99d4eSJuan Castilloendef 52473c99d4eSJuan Castillo 5255fee0287SRoberto Vargas.PHONY: libraries 5265fee0287SRoberto Vargas 5275fee0287SRoberto Vargas# MAKE_LIB macro defines the targets and options to build each BL image. 5285fee0287SRoberto Vargas# Arguments: 5295fee0287SRoberto Vargas# $(1) = Library name 5305fee0287SRoberto Vargasdefine MAKE_LIB 531f7a41fb4SBoyan Karatotev $(eval BL := $(call uppercase,$(1))) 5325fee0287SRoberto Vargas $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1)) 5335fee0287SRoberto Vargas $(eval LIB_DIR := ${BUILD_PLAT}/lib) 5345accce5bSRoberto Vargas $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 535f7a41fb4SBoyan Karatotev $(eval SOURCES := $(LIB$(BL)_SRCS)) 5365fee0287SRoberto Vargas $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 5375fee0287SRoberto Vargas 538f7a41fb4SBoyan Karatotev$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1),$(BL))) 5395fee0287SRoberto Vargas 5405fee0287SRoberto Vargaslibraries: ${LIB_DIR}/lib$(1).a 5418620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link) 542c2ad38ceSVarun WadekarLDPATHS = --userlibpath=${LIB_DIR} 543c2ad38ceSVarun WadekarLDLIBS += --library=$(1) 544c2ad38ceSVarun Wadekarelse 5455fee0287SRoberto VargasLDPATHS = -L${LIB_DIR} 5465fee0287SRoberto VargasLDLIBS += -l$(1) 547c2ad38ceSVarun Wadekarendif 5485fee0287SRoberto Vargas 5495accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 5506baf85b3SSathees BalyaLIBWRAPPER = -lwrappers 5515accce5bSRoberto Vargasendif 5525accce5bSRoberto Vargas 5535fee0287SRoberto Vargasall: ${LIB_DIR}/lib$(1).a 5545fee0287SRoberto Vargas 555f4dd18c2SChris Kay${LIB_DIR}/lib$(1).a: $(OBJS) | $$$$(@D)/ 5567c4e1eeaSChris Kay $$(s)echo " AR $$@" 5577c4e1eeaSChris Kay $$(q)$($(ARCH)-ar) cr $$@ $$? 5585fee0287SRoberto Vargasendef 5595fee0287SRoberto Vargas 56082274936SChris Kay# Generate the path to one or more preprocessed linker scripts given the paths 56182274936SChris Kay# of their sources. 56282274936SChris Kay# 56382274936SChris Kay# Arguments: 56482274936SChris Kay# $(1) = path to one or more linker script sources 56582274936SChris Kaydefine linker_script_path 56682274936SChris Kay $(patsubst %.S,$(BUILD_DIR)/%,$(1)) 56782274936SChris Kayendef 56882274936SChris Kay 56973c99d4eSJuan Castillo# MAKE_BL macro defines the targets and options to build each BL image. 57073c99d4eSJuan Castillo# Arguments: 571434d0491SZelalem Aweke# $(1) = BL stage 5728f0617efSJuan Castillo# $(2) = FIP command line option (if empty, image will not be included in the FIP) 5731dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 574c6ba9b45SSumit Garg# $(4) = BL encryption flag (optional) (0, 1) 57573c99d4eSJuan Castillodefine MAKE_BL 576f7a41fb4SBoyan Karatotev $(eval BL := $(call uppercase,$(1))) 577434d0491SZelalem Aweke $(eval BUILD_DIR := ${BUILD_PLAT}/$(1)) 578f7a41fb4SBoyan Karatotev $(eval BL_SOURCES := $($(BL)_SOURCES)) 579bb22fb84SChris Kay $(eval SOURCES := $(sort $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))) 58073c99d4eSJuan Castillo $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 58173c99d4eSJuan Castillo $(eval MAPFILE := $(call IMG_MAPFILE,$(1))) 58273c99d4eSJuan Castillo $(eval ELF := $(call IMG_ELF,$(1))) 58373c99d4eSJuan Castillo $(eval DUMP := $(call IMG_DUMP,$(1))) 58473c99d4eSJuan Castillo $(eval BIN := $(call IMG_BIN,$(1))) 585c6ba9b45SSumit Garg $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1))) 586f7a41fb4SBoyan Karatotev $(eval BL_LIBS := $($(BL)_LIBS)) 58782274936SChris Kay 588f7a41fb4SBoyan Karatotev $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(BL)_DEFAULT_LINKER_SCRIPT_SOURCE)) 58982274936SChris Kay $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE))) 59082274936SChris Kay 591f7a41fb4SBoyan Karatotev $(eval LINKER_SCRIPT_SOURCES := $($(BL)_LINKER_SCRIPT_SOURCES)) 592a6ff0067SChris Kay $(eval LINKER_SCRIPTS := $(call linker_script_path,$(LINKER_SCRIPT_SOURCES))) 5936c2e5bf6SBoyan Karatotev $(eval GNU_LINKER_ARGS := $(call ld_prefix,-Map=$(MAPFILE)) $(foreach script,$(LINKER_SCRIPTS) $(DEFAULT_LINKER_SCRIPT), $(call ld_prefix,--script $(script)))) 594a6ff0067SChris Kay 595f7a41fb4SBoyan Karatotev$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1),$(BL))) 596a6ff0067SChris Kay 597a6ff0067SChris Kay# Generate targets to preprocess each required linker script 598a6ff0067SChris Kay$(eval $(foreach source,$(DEFAULT_LINKER_SCRIPT_SOURCE) $(LINKER_SCRIPT_SOURCES), \ 599f7a41fb4SBoyan Karatotev $(call MAKE_LD,$(call linker_script_path,$(source)),$(source),$(1),$(BL)))) 600a6ff0067SChris Kay 601f7a41fb4SBoyan Karatotev$(eval BL_LDFLAGS := $($(BL)_LDFLAGS)) 60273c99d4eSJuan Castillo 6035accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 6046e622818SChris Kay$(ELF): $(BUILD_PLAT)/romlib/romlib.bin | $$$$(@D)/ 6055accce5bSRoberto Vargasendif 6065accce5bSRoberto Vargas 6078dccddc7SLeon Chen# MODULE_OBJS can be assigned by vendors with different compiled 6088dccddc7SLeon Chen# object file path, and prebuilt object file path. 6098dccddc7SLeon Chen$(eval OBJS += $(MODULE_OBJS)) 6108dccddc7SLeon Chen 611f4dd18c2SChris Kay$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) $(LINKER_SCRIPTS) | $$$$(@D)/ libraries $(BL_LIBS) 6127c4e1eeaSChris Kay $$(s)echo " LD $$@" 6138620bd0bSChris Kayifeq ($($(ARCH)-ld-id),arm-link) 6147c4e1eeaSChris Kay $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \ 615df52e260SChris Kay --predefine=$(call escape-shell,-D__LINKER__=$(__LINKER__)) \ 616df52e260SChris Kay --predefine=$(call escape-shell,-DTF_CFLAGS=$(TF_CFLAGS)) \ 617434d0491SZelalem Aweke --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \ 618758ccb80SChris Kay $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS) 619c2ad38ceSVarun Wadekarelse 6207cdbbea4SBoyan Karatotev $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) $(GNU_LINKER_ARGS) \ 6216baf85b3SSathees Balya $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) 622c2ad38ceSVarun Wadekarendif 6239e4609f1SChristoph Müllnerifeq ($(DISABLE_BIN_GENERATION),1) 6247c4e1eeaSChris Kay $(s)echo 6257c4e1eeaSChris Kay $(s)echo "Built $$@ successfully" 6267c4e1eeaSChris Kay $(s)echo 6279e4609f1SChristoph Müllnerendif 62873c99d4eSJuan Castillo 629f4dd18c2SChris Kay$(DUMP): $(ELF) | $$$$(@D)/ 6307c4e1eeaSChris Kay $$(s)echo " OD $$@" 6317c4e1eeaSChris Kay $$(q)$($(ARCH)-od) -dx $$< > $$@ 63273c99d4eSJuan Castillo 633f4dd18c2SChris Kay$(BIN): $(ELF) | $$$$(@D)/ 6347c4e1eeaSChris Kay $$(s)echo " BIN $$@" 6357c4e1eeaSChris Kay $$(q)$($(ARCH)-oc) -O binary $$< $$@ 6367c4e1eeaSChris Kay $(s)echo 6377c4e1eeaSChris Kay $(s)echo "Built $$@ successfully" 6387c4e1eeaSChris Kay $(s)echo 63973c99d4eSJuan Castillo 640434d0491SZelalem Aweke.PHONY: $(1) 6419e4609f1SChristoph Müllnerifeq ($(DISABLE_BIN_GENERATION),1) 642434d0491SZelalem Aweke$(1): $(ELF) $(DUMP) 6439e4609f1SChristoph Müllnerelse 644434d0491SZelalem Aweke$(1): $(BIN) $(DUMP) 6459e4609f1SChristoph Müllnerendif 64673c99d4eSJuan Castillo 647434d0491SZelalem Awekeall: $(1) 64873c99d4eSJuan Castillo 649c6ba9b45SSumit Gargifeq ($(4),1) 650c6ba9b45SSumit Garg$(call ENCRYPT_FW,$(BIN),$(ENC_BIN)) 651f7a41fb4SBoyan Karatotev$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(BIN),--$(2),$(ENC_BIN),$(3), \ 652c6ba9b45SSumit Garg $(ENC_BIN))) 653c6ba9b45SSumit Gargelse 654f7a41fb4SBoyan Karatotev$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(BIN),--$(2),$(BIN),$(3))) 655c6ba9b45SSumit Gargendif 65673c99d4eSJuan Castillo 65773c99d4eSJuan Castilloendef 65873c99d4eSJuan Castillo 65938c14d88SSoby Mathew# Convert device tree source file names to matching blobs 66038c14d88SSoby Mathew# $(1) = input dts 66103b397a8SNishanth Menondefine SOURCES_TO_DTBS 66203b397a8SNishanth Menon $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1)))) 66303b397a8SNishanth Menonendef 66403b397a8SNishanth Menon 66538c14d88SSoby Mathew# MAKE_DTB generate the Flattened device tree binary 66603b397a8SNishanth Menon# $(1) = output directory 66703b397a8SNishanth Menon# $(2) = input dts 66803b397a8SNishanth Menondefine MAKE_DTB 66903b397a8SNishanth Menon 670077b3e9aSYann Gautier# List of DTB file(s) to generate, based on DTS file basename list 67138c14d88SSoby Mathew$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 672077b3e9aSYann Gautier# List of the pre-compiled DTS file(s) 67301d237cbSYann Gautier$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2))))) 674077b3e9aSYann Gautier# Dependencies of the pre-compiled DTS file(s) on its source and included files 675077b3e9aSYann Gautier$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ))) 676077b3e9aSYann Gautier# Dependencies of the DT compilation on its pre-compiled DTS 677077b3e9aSYann Gautier$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ))) 67803b397a8SNishanth Menon 6791e8b5354SBoyan Karatotev$(eval $(call MAKE_PRE,$(DPRE),$(2),$(DTSDEP),$(DTC_CPPFLAGS))) 6807b453526SChris Kay 681f4dd18c2SChris Kay$(DOBJ): $(DPRE) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/ 6827c4e1eeaSChris Kay $$(s)echo " DTC $$<" 6837c4e1eeaSChris Kay $$(q)$($(ARCH)-dtc) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $$< 6841c08ff32SSalman Nabi $$($$@-after) 68503b397a8SNishanth Menon 686077b3e9aSYann Gautier-include $(DTBDEP) 687077b3e9aSYann Gautier-include $(DTSDEP) 68803b397a8SNishanth Menon 68903b397a8SNishanth Menonendef 69003b397a8SNishanth Menon 69103b397a8SNishanth Menon# MAKE_DTBS builds flattened device tree sources 69203b397a8SNishanth Menon# $(1) = output directory 69303b397a8SNishanth Menon# $(2) = list of flattened device tree source files 69403b397a8SNishanth Menondefine MAKE_DTBS 69503b397a8SNishanth Menon $(eval DOBJS := $(filter %.dts,$(2))) 69603b397a8SNishanth Menon $(eval REMAIN := $(filter-out %.dts,$(2))) 69738c14d88SSoby Mathew $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN))) 69803b397a8SNishanth Menon $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj)))) 69903b397a8SNishanth Menon 700f4dd18c2SChris Kaydtbs: $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))) 70138c14d88SSoby Mathewall: dtbs 70203b397a8SNishanth Menonendef 703