blob: d454efd903c23a2abe07b9ca916657edcc4456f3 [file] [log] [blame]
Juan Castilloa3487d12015-08-18 14:23:04 +01001#
Chris Kayc7ea3472024-01-15 18:45:07 +00002# Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
Juan Castilloa3487d12015-08-18 14:23:04 +01003#
dp-armfa3cf0b2017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Juan Castilloa3487d12015-08-18 14:23:04 +01005#
6
Evan Lloyd870a18c2015-12-02 18:41:22 +00007# Report an error if the eval make function is not available.
8$(eval eval_available := T)
9ifneq (${eval_available},T)
10 $(error This makefile only works with a Make program that supports $$(eval))
11endif
12
Evan Lloydf2697142015-12-02 18:17:37 +000013# A user defined function to recursively search for a filename below a directory
14# $1 is the directory root of the recursive search (blank for current directory).
15# $2 is the file name to search for.
16define rwildcard
17$(strip $(foreach d,$(wildcard ${1}*),$(call rwildcard,${d}/,${2}) $(filter $(subst *,%,%${2}),${d})))
18endef
19
Boyan Karatotevb4f25db2022-11-17 12:01:29 +000020# Convenience function for setting a variable to 0 if not previously set
21# $(eval $(call default_zero,FOO))
22define default_zero
23 $(eval $(1) ?= 0)
24endef
25
26# Convenience function for setting a list of variables to 0 if not previously set
27# $(eval $(call default_zeros,FOO BAR))
28define default_zeros
29 $(foreach var,$1,$(eval $(call default_zero,$(var))))
30endef
31
Govindraj Raja7dc5f1b2024-01-23 14:20:52 -060032# Convenience function for setting a variable to 1 if not previously set
33# $(eval $(call default_one,FOO))
34define default_one
35 $(eval $(1) ?= 1)
36endef
37
38# Convenience function for setting a list of variables to 1 if not previously set
39# $(eval $(call default_ones,FOO BAR))
40define default_ones
41 $(foreach var,$1,$(eval $(call default_one,$(var))))
42endef
43
Juan Castilloa3487d12015-08-18 14:23:04 +010044# Convenience function for adding build definitions
45# $(eval $(call add_define,FOO)) will have:
46# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
47define add_define
48 DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),)
49endef
50
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -050051# Convenience function for addding multiple build definitions
52# $(eval $(call add_defines,FOO BOO))
53define add_defines
54 $(foreach def,$1,$(eval $(call add_define,$(def))))
55endef
56
Soren Brinkmann9efe6572016-06-09 13:36:27 -070057# Convenience function for adding build definitions
58# $(eval $(call add_define_val,FOO,BAR)) will have:
59# -DFOO=BAR
60define add_define_val
61 DEFINES += -D$(1)=$(2)
62endef
63
Juan Castilloa3487d12015-08-18 14:23:04 +010064# Convenience function for verifying option has a boolean value
65# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
66define assert_boolean
Yann Gautierdbf0a162023-04-24 13:38:12 +020067 $(if $($(1)),,$(error $(1) must not be empty))
Masahiro Yamada1ab9e922017-05-23 23:45:01 +090068 $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean))
Juan Castilloa3487d12015-08-18 14:23:04 +010069endef
70
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -050071# Convenience function for verifying options have boolean values
72# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values
73define assert_booleans
74 $(foreach bool,$1,$(eval $(call assert_boolean,$(bool))))
75endef
76
Jeenu Viswambharanfca76802017-01-16 16:52:35 +0000770-9 := 0 1 2 3 4 5 6 7 8 9
78
79# Function to verify that a given option $(1) contains a numeric value
80define assert_numeric
81$(if $($(1)),,$(error $(1) must not be empty))
82$(eval __numeric := $($(1)))
83$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric))))
84$(if $(__numeric),$(error $(1) must be numeric))
85endef
86
Leonardo Sandoval65fca7c2020-09-10 12:18:27 -050087# Convenience function for verifying options have numeric values
88# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values
89define assert_numerics
90 $(foreach num,$1,$(eval $(call assert_numeric,$(num))))
91endef
92
Marco Felschdf646b52022-11-24 11:02:05 +010093# Convenience function to check for a given linker option. An call to
94# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker
Chris Kay523e8642023-12-04 12:03:51 +000095ld_option = $(shell $($(ARCH)-ld) $(1) -Wl,--version >/dev/null 2>&1 || $($(ARCH)-ld) $(1) -v >/dev/null 2>&1 && echo $(1))
Marco Felschdf646b52022-11-24 11:02:05 +010096
Govindraj Rajaaa8ef3f2023-05-05 09:09:36 -050097# Convenience function to check for a given compiler option. A call to
98# $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler
Boyan Karatoteve9f127f2024-10-10 13:54:37 +010099# NOTE: consider assigning to an immediately expanded temporary variable before
100# assigning. This is because variables like TF_CFLAGS are recursively expanded
101# and assigning this directly will cause it to be expanded every time the
102# variable is used, potentially thrashing multicore performance.
Govindraj Rajaaa8ef3f2023-05-05 09:09:36 -0500103define cc_option
Chris Kay523e8642023-12-04 12:03:51 +0000104 $(shell if $($(ARCH)-cc) $(1) -c -x c /dev/null -o /dev/null >/dev/null 2>&1; then echo $(1); fi )
Govindraj Rajaaa8ef3f2023-05-05 09:09:36 -0500105endef
106
Vijayenthiran Subramaniam3414e3a2020-02-08 21:27:30 +0530107# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to
108# $(2) and assign the sequence to $(1)
109define CREATE_SEQ
110$(if $(word $(2), $($(1))),\
111 $(eval $(1) += $(words $($(1))))\
112 $(eval $(1) := $(filter-out 0,$($(1)))),\
113 $(eval $(1) += $(words $($(1))))\
114 $(call CREATE_SEQ,$(1),$(2))\
115)
116endef
117
Juan Castilloa3487d12015-08-18 14:23:04 +0100118# IMG_MAPFILE defines the output file describing the memory map corresponding
119# to a BL stage
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500120# $(1) = BL stage
Juan Castilloa3487d12015-08-18 14:23:04 +0100121define IMG_MAPFILE
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500122 ${BUILD_DIR}/$(1).map
Juan Castilloa3487d12015-08-18 14:23:04 +0100123endef
124
125# IMG_ELF defines the elf file corresponding to a BL stage
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500126# $(1) = BL stage
Juan Castilloa3487d12015-08-18 14:23:04 +0100127define IMG_ELF
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500128 ${BUILD_DIR}/$(1).elf
Juan Castilloa3487d12015-08-18 14:23:04 +0100129endef
130
131# IMG_DUMP defines the symbols dump file corresponding to a BL stage
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500132# $(1) = BL stage
Juan Castilloa3487d12015-08-18 14:23:04 +0100133define IMG_DUMP
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500134 ${BUILD_DIR}/$(1).dump
Juan Castilloa3487d12015-08-18 14:23:04 +0100135endef
136
137# IMG_BIN defines the default image file corresponding to a BL stage
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500138# $(1) = BL stage
Juan Castilloa3487d12015-08-18 14:23:04 +0100139define IMG_BIN
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500140 ${BUILD_PLAT}/$(1).bin
Juan Castilloa3487d12015-08-18 14:23:04 +0100141endef
142
Sumit Gargeec52442019-11-14 16:33:45 +0530143# IMG_ENC_BIN defines the default encrypted image file corresponding to a
144# BL stage
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500145# $(1) = BL stage
Sumit Gargeec52442019-11-14 16:33:45 +0530146define IMG_ENC_BIN
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500147 ${BUILD_PLAT}/$(1)_enc.bin
Sumit Gargeec52442019-11-14 16:33:45 +0530148endef
149
150# ENCRYPT_FW invokes enctool to encrypt firmware binary
151# $(1) = input firmware binary
152# $(2) = output encrypted firmware binary
153define ENCRYPT_FW
154$(2): $(1) enctool
Chris Kay1870c722024-05-02 17:52:37 +0000155 $$(s)echo " ENC $$<"
156 $$(q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@
Sumit Gargeec52442019-11-14 16:33:45 +0530157endef
158
Masahiro Yamada6c2b4592018-01-26 11:42:01 +0900159# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to
160# package a new payload and/or by cert_create to generate certificate.
161# Optionally, it adds the dependency on this payload
Juan Castilloa3487d12015-08-18 14:23:04 +0100162# $(1) = payload filename (i.e. bl31.bin)
Masahiro Yamadac85deee2017-12-23 23:56:18 +0900163# $(2) = command line option for the specified payload (i.e. --soc-fw)
Masahiro Yamada5c3ae332018-01-26 11:42:01 +0900164# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin)
Masahiro Yamadacd7711d2018-01-26 11:42:01 +0900165# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargeec52442019-11-14 16:33:45 +0530166# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin)
Masahiro Yamada6c2b4592018-01-26 11:42:01 +0900167define TOOL_ADD_PAYLOAD
Sumit Gargeec52442019-11-14 16:33:45 +0530168ifneq ($(5),)
169 $(4)FIP_ARGS += $(2) $(5)
170 $(if $(3),$(4)CRT_DEPS += $(1))
171else
Masahiro Yamada714a6922018-01-26 11:42:01 +0900172 $(4)FIP_ARGS += $(2) $(1)
Sumit Gargeec52442019-11-14 16:33:45 +0530173 $(if $(3),$(4)CRT_DEPS += $(3))
174endif
Masahiro Yamada714a6922018-01-26 11:42:01 +0900175 $(if $(3),$(4)FIP_DEPS += $(3))
Masahiro Yamadaec154ad2018-01-26 11:42:01 +0900176 $(4)CRT_ARGS += $(2) $(1)
Juan Castilloa3487d12015-08-18 14:23:04 +0100177endef
178
Masahiro Yamadabfb64ac2018-02-01 16:31:09 +0900179# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters
180# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined.
181# $(1) = image_type (scp_bl2, bl33, etc.)
182# $(2) = payload filepath (ex. build/fvp/release/bl31.bin)
183# $(3) = command line option for the specified payload (ex. --soc-fw)
184# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin)
185# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargeec52442019-11-14 16:33:45 +0530186# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin)
Masahiro Yamadabfb64ac2018-02-01 16:31:09 +0900187
188define TOOL_ADD_IMG_PAYLOAD
189
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100190$(eval PRE_TOOL_FILTER := $($(1)_PRE_TOOL_FILTER))
Masahiro Yamadabfb64ac2018-02-01 16:31:09 +0900191
192ifneq ($(PRE_TOOL_FILTER),)
193
194$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX))
195
196$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2))
197
198$(PROCESSED_PATH): $(4)
199
Sumit Gargeec52442019-11-14 16:33:45 +0530200$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6))
Masahiro Yamadabfb64ac2018-02-01 16:31:09 +0900201
202else
Sumit Gargeec52442019-11-14 16:33:45 +0530203$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6))
Masahiro Yamadabfb64ac2018-02-01 16:31:09 +0900204endif
205endef
206
Yatharth Kochard1a93432015-10-12 12:33:47 +0100207# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation
Juan Castilloa3487d12015-08-18 14:23:04 +0100208# $(1) = parameter filename
209# $(2) = cert_create command line option for the specified parameter
Masahiro Yamada5ebfda32018-01-26 11:42:01 +0900210# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Juan Castilloa3487d12015-08-18 14:23:04 +0100211define CERT_ADD_CMD_OPT
Masahiro Yamada5ebfda32018-01-26 11:42:01 +0900212 $(3)CRT_ARGS += $(2) $(1)
Juan Castilloa3487d12015-08-18 14:23:04 +0100213endef
214
Masahiro Yamada4d156802018-01-26 11:42:01 +0900215# TOOL_ADD_IMG allows the platform to specify an external image to be packed
216# in the FIP and/or for which certificate is generated. It also adds a
217# dependency on the image file, aborting the build if the file does not exist.
Masahiro Yamada9c5ca522018-01-26 11:42:01 +0900218# $(1) = image_type (scp_bl2, bl33, etc.)
Masahiro Yamadac85deee2017-12-23 23:56:18 +0900219# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc)
Masahiro Yamadacd7711d2018-01-26 11:42:01 +0900220# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargeec52442019-11-14 16:33:45 +0530221# $(4) = Image encryption flag (optional) (0, 1)
Juan Castilloa3487d12015-08-18 14:23:04 +0100222# Example:
Masahiro Yamada9c5ca522018-01-26 11:42:01 +0900223# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Masahiro Yamada4d156802018-01-26 11:42:01 +0900224define TOOL_ADD_IMG
Masahiro Yamada9c5ca522018-01-26 11:42:01 +0900225 # Build option to specify the image filename (SCP_BL2, BL33, etc)
226 # This is the uppercase form of the first parameter
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100227 $(eval BL := $(call uppercase,$(1)))
228 $(eval _V := $(BL))
Masahiro Yamada9c5ca522018-01-26 11:42:01 +0900229
Pali Rohára5416ab2020-11-24 16:53:04 +0100230 # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also
231 # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the
232 # target ${BUILD_PLAT}/${$(3)FIP_NAME}.
233 $(eval check_$(1)_cmd := \
234 $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \
235 $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \
236 )
237
Masahiro Yamada714a6922018-01-26 11:42:01 +0900238 $(3)CRT_DEPS += check_$(1)
Pali Rohára5416ab2020-11-24 16:53:04 +0100239 CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd)
Sumit Gargeec52442019-11-14 16:33:45 +0530240ifeq ($(4),1)
241 $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin)
242 $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100243 $(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(value $(_V)),$(2),$(ENC_BIN),$(3), \
Sumit Gargeec52442019-11-14 16:33:45 +0530244 $(ENC_BIN))
245else
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100246 $(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3))
Sumit Gargeec52442019-11-14 16:33:45 +0530247endif
Juan Castilloa3487d12015-08-18 14:23:04 +0100248
Masahiro Yamada9dff1562017-12-24 13:08:00 +0900249.PHONY: check_$(1)
Juan Castilloa3487d12015-08-18 14:23:04 +0100250check_$(1):
Pali Rohára5416ab2020-11-24 16:53:04 +0100251 $(check_$(1)_cmd)
Juan Castilloa3487d12015-08-18 14:23:04 +0100252endef
253
Juan Pablo Conde3539c742022-10-25 19:41:02 -0400254# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to
255# build the host tools by checking the version of OpenSSL located under
256# the path defined by the OPENSSL_DIR variable. It receives no parameters.
257define SELECT_OPENSSL_API_VERSION
258 # Set default value for USING_OPENSSL3 macro to 0
259 $(eval USING_OPENSSL3 = 0)
260 # Obtain the OpenSSL version for the build located under OPENSSL_DIR
261 $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version))
262 $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO}))
263 $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER))))
264 # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1
265 $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1))
266endef
267
Juan Castilloa3487d12015-08-18 14:23:04 +0100268################################################################################
Masahiro Yamadaeff36a92018-01-26 11:42:01 +0900269# Generic image processing filters
270################################################################################
271
272# GZIP
273define GZIP_RULE
274$(1): $(2)
Chris Kay1870c722024-05-02 17:52:37 +0000275 $(s)echo " GZIP $$@"
276 $(q)gzip -n -f -9 $$< --stdout > $$@
Masahiro Yamadaeff36a92018-01-26 11:42:01 +0900277endef
278
279GZIP_SUFFIX := .gz
280
281################################################################################
Juan Castilloa3487d12015-08-18 14:23:04 +0100282# Auxiliary macros to build TF images from sources
283################################################################################
284
Masahiro Yamadae487bb62016-12-22 15:23:05 +0900285MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP
Juan Castilloa3487d12015-08-18 14:23:04 +0100286
Roberto Vargas21360f32018-05-08 10:27:10 +0100287
288# MAKE_C_LIB builds a C source file and generates the dependency file
289# $(1) = output directory
290# $(2) = source file (%.c)
291# $(3) = library name
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100292# $(4) = uppercase name of the library
Roberto Vargas21360f32018-05-08 10:27:10 +0100293define MAKE_C_LIB
294$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
295$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100296$(eval LIB := $(notdir $(1)))
Roberto Vargas21360f32018-05-08 10:27:10 +0100297
Chris Kay1559f642024-06-04 00:04:48 +0000298$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000299 $$(s)echo " CC $$<"
300 $$(q)$($(ARCH)-cc) $$($(LIB)_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@
Roberto Vargas21360f32018-05-08 10:27:10 +0100301
302-include $(DEP)
303
304endef
305
Antonio Nino Diaza884dfb2019-02-08 13:20:37 +0000306# MAKE_S_LIB builds an assembly source file and generates the dependency file
307# $(1) = output directory
308# $(2) = source file (%.S)
309# $(3) = library name
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100310# $(4) = uppercase name of the library
Antonio Nino Diaza884dfb2019-02-08 13:20:37 +0000311define MAKE_S_LIB
312$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
313$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
314
Chris Kay1559f642024-06-04 00:04:48 +0000315$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000316 $$(s)echo " AS $$<"
317 $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS_$(ARCH)) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
Antonio Nino Diaza884dfb2019-02-08 13:20:37 +0000318
319-include $(DEP)
320
321endef
322
Roberto Vargas21360f32018-05-08 10:27:10 +0100323
Juan Castilloa3487d12015-08-18 14:23:04 +0100324# MAKE_C builds a C source file and generates the dependency file
325# $(1) = output directory
326# $(2) = source file (%.c)
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500327# $(3) = BL stage
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100328# $(4) = uppercase BL stage
Juan Castilloa3487d12015-08-18 14:23:04 +0100329define MAKE_C
330
331$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
Masahiro Yamada56c53f62016-12-22 14:02:27 +0900332$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Chris Kay2a8e4242023-03-22 15:42:32 +0000333
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100334$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES) $(PLAT_BL_COMMON_DEFINES))
335$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS))
336$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS))
337$(eval BL_CFLAGS := $($(4)_CFLAGS) $(PLAT_BL_COMMON_CFLAGS))
Juan Castilloa3487d12015-08-18 14:23:04 +0100338
Chris Kay1559f642024-06-04 00:04:48 +0000339$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000340 $$(s)echo " CC $$<"
341 $$(q)$($(ARCH)-cc) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castilloa3487d12015-08-18 14:23:04 +0100342
Masahiro Yamada56c53f62016-12-22 14:02:27 +0900343-include $(DEP)
Juan Castilloa3487d12015-08-18 14:23:04 +0100344
345endef
346
347
348# MAKE_S builds an assembly source file and generates the dependency file
349# $(1) = output directory
350# $(2) = assembly file (%.S)
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500351# $(3) = BL stage
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100352# $(4) = uppercase BL stage
Juan Castilloa3487d12015-08-18 14:23:04 +0100353define MAKE_S
354
355$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
Masahiro Yamada56c53f62016-12-22 14:02:27 +0900356$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Chris Kay2a8e4242023-03-22 15:42:32 +0000357
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100358$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES) $(PLAT_BL_COMMON_DEFINES))
359$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS))
360$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS))
361$(eval BL_ASFLAGS := $($(4)_ASFLAGS) $(PLAT_BL_COMMON_ASFLAGS))
Juan Castilloa3487d12015-08-18 14:23:04 +0100362
Chris Kay1559f642024-06-04 00:04:48 +0000363$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000364 $$(s)echo " AS $$<"
365 $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS_$(ARCH)) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castilloa3487d12015-08-18 14:23:04 +0100366
Masahiro Yamada56c53f62016-12-22 14:02:27 +0900367-include $(DEP)
Juan Castilloa3487d12015-08-18 14:23:04 +0100368
369endef
370
371
372# MAKE_LD generate the linker script using the C preprocessor
373# $(1) = output linker script
374# $(2) = input template
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500375# $(3) = BL stage
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100376# $(4) = uppercase BL stage
Juan Castilloa3487d12015-08-18 14:23:04 +0100377define MAKE_LD
378
Masahiro Yamada56c53f62016-12-22 14:02:27 +0900379$(eval DEP := $(1).d)
Chris Kay2a8e4242023-03-22 15:42:32 +0000380
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100381$(eval BL_DEFINES := IMAGE_$(4) $($(4)_DEFINES) $(PLAT_BL_COMMON_DEFINES))
382$(eval BL_INCLUDE_DIRS := $($(4)_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS))
383$(eval BL_CPPFLAGS := $($(4)_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS))
Juan Castilloa3487d12015-08-18 14:23:04 +0100384
Chris Kay1559f642024-06-04 00:04:48 +0000385$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000386 $$(s)echo " PP $$<"
387 $$(q)$($(ARCH)-cpp) -E $$(CPPFLAGS) $(BL_CPPFLAGS) $(TF_CFLAGS_$(ARCH)) -P -x assembler-with-cpp -D__LINKER__ $(MAKE_DEP) -o $$@ $$<
Juan Castilloa3487d12015-08-18 14:23:04 +0100388
Masahiro Yamada56c53f62016-12-22 14:02:27 +0900389-include $(DEP)
Juan Castilloa3487d12015-08-18 14:23:04 +0100390
391endef
392
Antonio Nino Diaza884dfb2019-02-08 13:20:37 +0000393# MAKE_LIB_OBJS builds both C and assembly source files
Roberto Vargas21360f32018-05-08 10:27:10 +0100394# $(1) = output directory
395# $(2) = list of source files
396# $(3) = name of the library
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100397# $(4) = uppercase name of the library
Roberto Vargas21360f32018-05-08 10:27:10 +0100398define MAKE_LIB_OBJS
399 $(eval C_OBJS := $(filter %.c,$(2)))
400 $(eval REMAIN := $(filter-out %.c,$(2)))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100401 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3),$(4))))
Roberto Vargas21360f32018-05-08 10:27:10 +0100402
Antonio Nino Diaza884dfb2019-02-08 13:20:37 +0000403 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
404 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100405 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3),$(4))))
Antonio Nino Diaza884dfb2019-02-08 13:20:37 +0000406
Roberto Vargas21360f32018-05-08 10:27:10 +0100407 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
408endef
409
Juan Castilloa3487d12015-08-18 14:23:04 +0100410
411# MAKE_OBJS builds both C and assembly source files
412# $(1) = output directory
413# $(2) = list of source files (both C and assembly)
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500414# $(3) = BL stage
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100415# $(4) = uppercase BL stage
Juan Castilloa3487d12015-08-18 14:23:04 +0100416define MAKE_OBJS
417 $(eval C_OBJS := $(filter %.c,$(2)))
418 $(eval REMAIN := $(filter-out %.c,$(2)))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100419 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3),$(4))))
Juan Castilloa3487d12015-08-18 14:23:04 +0100420
421 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
422 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100423 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3),$(4))))
Juan Castilloa3487d12015-08-18 14:23:04 +0100424
425 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
426endef
427
428
429# NOTE: The line continuation '\' is required in the next define otherwise we
430# end up with a line-feed characer at the end of the last c filename.
Evan Lloyda71d2592015-12-02 18:56:06 +0000431# Also bear this issue in mind if extending the list of supported filetypes.
Juan Castilloa3487d12015-08-18 14:23:04 +0100432define SOURCES_TO_OBJS
433 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
434 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
435endef
436
Roberto Vargas21360f32018-05-08 10:27:10 +0100437.PHONY: libraries
438
Roberto Vargas21360f32018-05-08 10:27:10 +0100439# MAKE_LIB macro defines the targets and options to build each BL image.
440# Arguments:
441# $(1) = Library name
442define MAKE_LIB
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100443 $(eval BL := $(call uppercase,$(1)))
Roberto Vargas21360f32018-05-08 10:27:10 +0100444 $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1))
445 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargase92111a2018-05-22 16:05:42 +0100446 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100447 $(eval SOURCES := $(LIB$(BL)_SRCS))
Roberto Vargas21360f32018-05-08 10:27:10 +0100448 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
449
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100450$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1),$(BL)))
Roberto Vargas21360f32018-05-08 10:27:10 +0100451
Roberto Vargas21360f32018-05-08 10:27:10 +0100452libraries: ${LIB_DIR}/lib$(1).a
Chris Kaycfba6452023-12-04 09:55:50 +0000453ifeq ($($(ARCH)-ld-id),arm-link)
Varun Wadekar4d034c52019-01-11 14:47:48 -0800454LDPATHS = --userlibpath=${LIB_DIR}
455LDLIBS += --library=$(1)
456else
Roberto Vargas21360f32018-05-08 10:27:10 +0100457LDPATHS = -L${LIB_DIR}
458LDLIBS += -l$(1)
Varun Wadekar4d034c52019-01-11 14:47:48 -0800459endif
Roberto Vargas21360f32018-05-08 10:27:10 +0100460
Roberto Vargase92111a2018-05-22 16:05:42 +0100461ifeq ($(USE_ROMLIB),1)
Sathees Balyaf5ec5002018-10-18 19:14:21 +0100462LIBWRAPPER = -lwrappers
Roberto Vargase92111a2018-05-22 16:05:42 +0100463endif
464
Roberto Vargas21360f32018-05-08 10:27:10 +0100465all: ${LIB_DIR}/lib$(1).a
466
Chris Kay1559f642024-06-04 00:04:48 +0000467${LIB_DIR}/lib$(1).a: $(OBJS) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000468 $$(s)echo " AR $$@"
469 $$(q)$($(ARCH)-ar) cr $$@ $$?
Roberto Vargas21360f32018-05-08 10:27:10 +0100470endef
471
Chris Kay68d28362023-01-16 16:53:45 +0000472# Generate the path to one or more preprocessed linker scripts given the paths
473# of their sources.
474#
475# Arguments:
476# $(1) = path to one or more linker script sources
477define linker_script_path
478 $(patsubst %.S,$(BUILD_DIR)/%,$(1))
479endef
480
Jimmy Brisson1dfa2712024-07-22 12:55:43 -0500481ifeq ($(USE_ROMLIB),1)
482WRAPPER_FLAGS := @${BUILD_PLAT}/romlib/romlib.ldflags
483endif
484
Juan Castilloa3487d12015-08-18 14:23:04 +0100485# MAKE_BL macro defines the targets and options to build each BL image.
486# Arguments:
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500487# $(1) = BL stage
Juan Castillo8e04dec2016-01-05 11:55:36 +0000488# $(2) = FIP command line option (if empty, image will not be included in the FIP)
Masahiro Yamadacd7711d2018-01-26 11:42:01 +0900489# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargeec52442019-11-14 16:33:45 +0530490# $(4) = BL encryption flag (optional) (0, 1)
Juan Castilloa3487d12015-08-18 14:23:04 +0100491define MAKE_BL
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100492 $(eval BL := $(call uppercase,$(1)))
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500493 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100494 $(eval BL_SOURCES := $($(BL)_SOURCES))
Chris Kaya7492ee2023-05-05 12:33:23 +0200495 $(eval SOURCES := $(sort $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES)))
Juan Castilloa3487d12015-08-18 14:23:04 +0100496 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Juan Castilloa3487d12015-08-18 14:23:04 +0100497 $(eval MAPFILE := $(call IMG_MAPFILE,$(1)))
498 $(eval ELF := $(call IMG_ELF,$(1)))
499 $(eval DUMP := $(call IMG_DUMP,$(1)))
500 $(eval BIN := $(call IMG_BIN,$(1)))
Sumit Gargeec52442019-11-14 16:33:45 +0530501 $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1)))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100502 $(eval BL_LIBS := $($(BL)_LIBS))
Chris Kay68d28362023-01-16 16:53:45 +0000503
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100504 $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(BL)_DEFAULT_LINKER_SCRIPT_SOURCE))
Chris Kay68d28362023-01-16 16:53:45 +0000505 $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE)))
506
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100507 $(eval LINKER_SCRIPT_SOURCES := $($(BL)_LINKER_SCRIPT_SOURCES))
Chris Kay0c0007b2023-01-16 18:57:26 +0000508 $(eval LINKER_SCRIPTS := $(call linker_script_path,$(LINKER_SCRIPT_SOURCES)))
509
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100510$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1),$(BL)))
Chris Kay0c0007b2023-01-16 18:57:26 +0000511
512# Generate targets to preprocess each required linker script
513$(eval $(foreach source,$(DEFAULT_LINKER_SCRIPT_SOURCE) $(LINKER_SCRIPT_SOURCES), \
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100514 $(call MAKE_LD,$(call linker_script_path,$(source)),$(source),$(1),$(BL))))
Chris Kay0c0007b2023-01-16 18:57:26 +0000515
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100516$(eval BL_LDFLAGS := $($(BL)_LDFLAGS))
Evan Lloyd93d3b702015-12-03 12:19:30 +0000517
Roberto Vargase92111a2018-05-22 16:05:42 +0100518ifeq ($(USE_ROMLIB),1)
Chris Kay1559f642024-06-04 00:04:48 +0000519$(ELF): romlib.bin | $$$$(@D)/
Roberto Vargase92111a2018-05-22 16:05:42 +0100520endif
521
developer09f3e982022-03-23 18:51:48 +0800522# MODULE_OBJS can be assigned by vendors with different compiled
523# object file path, and prebuilt object file path.
524$(eval OBJS += $(MODULE_OBJS))
525
Chris Kay1559f642024-06-04 00:04:48 +0000526$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) $(LINKER_SCRIPTS) | $$$$(@D)/ libraries $(BL_LIBS)
Chris Kay1870c722024-05-02 17:52:37 +0000527 $$(s)echo " LD $$@"
Chris Kaycfba6452023-12-04 09:55:50 +0000528ifeq ($($(ARCH)-ld-id),arm-link)
Chris Kay1870c722024-05-02 17:52:37 +0000529 $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \
Chris Kay6e1c3fd2024-05-29 20:37:33 +0000530 --predefine=$(call escape-shell,-D__LINKER__=$(__LINKER__)) \
531 --predefine=$(call escape-shell,-DTF_CFLAGS=$(TF_CFLAGS)) \
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500532 --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \
Chris Kay99b5b2e2024-03-08 16:08:31 +0000533 $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS)
Chris Kaycfba6452023-12-04 09:55:50 +0000534else ifeq ($($(ARCH)-ld-id),gnu-gcc)
Jimmy Brisson1dfa2712024-07-22 12:55:43 -0500535 $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $$(WRAPPER_FLAGS) $(BL_LDFLAGS) -Wl,-Map=$(MAPFILE) \
Chris Kay0c0007b2023-01-16 18:57:26 +0000536 $(addprefix -Wl$(comma)--script$(comma),$(LINKER_SCRIPTS)) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) \
zelalem-aweked5f45272019-11-12 16:20:17 -0600537 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekar4d034c52019-01-11 14:47:48 -0800538else
Jimmy Brisson1dfa2712024-07-22 12:55:43 -0500539 $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $$(WRAPPER_FLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
Chris Kay0c0007b2023-01-16 18:57:26 +0000540 $(addprefix -T ,$(LINKER_SCRIPTS)) --script $(DEFAULT_LINKER_SCRIPT) \
Sathees Balyaf5ec5002018-10-18 19:14:21 +0100541 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekar4d034c52019-01-11 14:47:48 -0800542endif
Christoph Müllner4f088e42019-04-24 09:45:30 +0200543ifeq ($(DISABLE_BIN_GENERATION),1)
Chris Kay1870c722024-05-02 17:52:37 +0000544 $(s)echo
545 $(s)echo "Built $$@ successfully"
546 $(s)echo
Christoph Müllner4f088e42019-04-24 09:45:30 +0200547endif
Juan Castilloa3487d12015-08-18 14:23:04 +0100548
Chris Kay1559f642024-06-04 00:04:48 +0000549$(DUMP): $(ELF) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000550 $$(s)echo " OD $$@"
551 $$(q)$($(ARCH)-od) -dx $$< > $$@
Juan Castilloa3487d12015-08-18 14:23:04 +0100552
Chris Kay1559f642024-06-04 00:04:48 +0000553$(BIN): $(ELF) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000554 $$(s)echo " BIN $$@"
555 $$(q)$($(ARCH)-oc) -O binary $$< $$@
556 $(s)echo
557 $(s)echo "Built $$@ successfully"
558 $(s)echo
Juan Castilloa3487d12015-08-18 14:23:04 +0100559
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500560.PHONY: $(1)
Christoph Müllner4f088e42019-04-24 09:45:30 +0200561ifeq ($(DISABLE_BIN_GENERATION),1)
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500562$(1): $(ELF) $(DUMP)
Christoph Müllner4f088e42019-04-24 09:45:30 +0200563else
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500564$(1): $(BIN) $(DUMP)
Christoph Müllner4f088e42019-04-24 09:45:30 +0200565endif
Juan Castilloa3487d12015-08-18 14:23:04 +0100566
Zelalem Awekeb44dec12021-07-11 17:25:48 -0500567all: $(1)
Juan Castilloa3487d12015-08-18 14:23:04 +0100568
Sumit Gargeec52442019-11-14 16:33:45 +0530569ifeq ($(4),1)
570$(call ENCRYPT_FW,$(BIN),$(ENC_BIN))
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100571$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(BIN),--$(2),$(ENC_BIN),$(3), \
Sumit Gargeec52442019-11-14 16:33:45 +0530572 $(ENC_BIN)))
573else
Boyan Karatotevebbb9ac2024-10-10 13:37:00 +0100574$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(BL),$(BIN),--$(2),$(BIN),$(3)))
Sumit Gargeec52442019-11-14 16:33:45 +0530575endif
Juan Castilloa3487d12015-08-18 14:23:04 +0100576
577endef
578
Soby Mathewab4181d2017-12-14 17:44:56 +0000579# Convert device tree source file names to matching blobs
580# $(1) = input dts
Nishanth Menon4ac02ba2016-10-14 01:13:57 +0000581define SOURCES_TO_DTBS
582 $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1))))
583endef
584
Soby Mathewab4181d2017-12-14 17:44:56 +0000585# MAKE_DTB generate the Flattened device tree binary
Nishanth Menon4ac02ba2016-10-14 01:13:57 +0000586# $(1) = output directory
587# $(2) = input dts
588define MAKE_DTB
589
Yann Gautierf3831802018-09-04 10:44:00 +0200590# List of DTB file(s) to generate, based on DTS file basename list
Soby Mathewab4181d2017-12-14 17:44:56 +0000591$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Yann Gautierf3831802018-09-04 10:44:00 +0200592# List of the pre-compiled DTS file(s)
Yann Gautier2cf1dbc2018-06-18 16:00:23 +0200593$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2)))))
Yann Gautierf3831802018-09-04 10:44:00 +0200594# Dependencies of the pre-compiled DTS file(s) on its source and included files
595$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ)))
596# Dependencies of the DT compilation on its pre-compiled DTS
597$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ)))
Nishanth Menon4ac02ba2016-10-14 01:13:57 +0000598
Chris Kay1559f642024-06-04 00:04:48 +0000599$(DPRE): $(2) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000600 $$(s)echo " CPP $$<"
Yann Gautierf3831802018-09-04 10:44:00 +0200601 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Chris Kay1870c722024-05-02 17:52:37 +0000602 $$(q)$($(ARCH)-cpp) -E $$(TF_CFLAGS_$(ARCH)) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$<
Chris Kaya6a8bc72024-03-08 16:26:53 +0000603
Chris Kay1559f642024-06-04 00:04:48 +0000604$(DOBJ): $(DPRE) $(filter-out %.d,$(MAKEFILE_LIST)) | $$$$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +0000605 $$(s)echo " DTC $$<"
606 $$(q)$($(ARCH)-dtc) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $$<
Nishanth Menon4ac02ba2016-10-14 01:13:57 +0000607
Yann Gautierf3831802018-09-04 10:44:00 +0200608-include $(DTBDEP)
609-include $(DTSDEP)
Nishanth Menon4ac02ba2016-10-14 01:13:57 +0000610
611endef
612
613# MAKE_DTBS builds flattened device tree sources
614# $(1) = output directory
615# $(2) = list of flattened device tree source files
616define MAKE_DTBS
617 $(eval DOBJS := $(filter %.dts,$(2)))
618 $(eval REMAIN := $(filter-out %.dts,$(2)))
Soby Mathewab4181d2017-12-14 17:44:56 +0000619 $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN)))
Nishanth Menon4ac02ba2016-10-14 01:13:57 +0000620 $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj))))
621
Chris Kay1559f642024-06-04 00:04:48 +0000622dtbs: $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))
Soby Mathewab4181d2017-12-14 17:44:56 +0000623all: dtbs
Nishanth Menon4ac02ba2016-10-14 01:13:57 +0000624endef