blob: 840714dde052b0113190a2c54fcba81d4d3e83a5 [file] [log] [blame]
Juan Castillo73c99d42015-08-18 14:23:04 +01001#
Juan Pablo Condecf2dd172022-10-25 19:41:02 -04002# Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved.
Juan Castillo73c99d42015-08-18 14:23:04 +01003#
dp-arm82cb2c12017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Juan Castillo73c99d42015-08-18 14:23:04 +01005#
6
Evan Lloyd1670d9d2015-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 Lloyd231c1472015-12-02 18:17:37 +000013# Some utility macros for manipulating awkward (whitespace) characters.
14blank :=
15space :=${blank} ${blank}
16
17# A user defined function to recursively search for a filename below a directory
18# $1 is the directory root of the recursive search (blank for current directory).
19# $2 is the file name to search for.
20define rwildcard
21$(strip $(foreach d,$(wildcard ${1}*),$(call rwildcard,${d}/,${2}) $(filter $(subst *,%,%${2}),${d})))
22endef
23
Yatharth Kochar5ba8f662015-10-02 13:58:52 +010024# This table is used in converting lower case to upper case.
25uppercase_table:=a,A b,B c,C d,D e,E f,F g,G h,H i,I j,J k,K l,L m,M n,N o,O p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z
26
27# Internal macro used for converting lower case to upper case.
28# $(1) = upper case table
29# $(2) = String to convert
30define uppercase_internal
31$(if $(1),$$(subst $(firstword $(1)),$(call uppercase_internal,$(wordlist 2,$(words $(1)),$(1)),$(2))),$(2))
32endef
33
34# A macro for converting a string to upper case
35# $(1) = String to convert
36define uppercase
37$(eval uppercase_result:=$(call uppercase_internal,$(uppercase_table),$(1)))$(uppercase_result)
38endef
39
Boyan Karatoteve31060c2022-11-17 12:01:29 +000040# Convenience function for setting a variable to 0 if not previously set
41# $(eval $(call default_zero,FOO))
42define default_zero
43 $(eval $(1) ?= 0)
44endef
45
46# Convenience function for setting a list of variables to 0 if not previously set
47# $(eval $(call default_zeros,FOO BAR))
48define default_zeros
49 $(foreach var,$1,$(eval $(call default_zero,$(var))))
50endef
51
Juan Castillo73c99d42015-08-18 14:23:04 +010052# Convenience function for adding build definitions
53# $(eval $(call add_define,FOO)) will have:
54# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
55define add_define
56 DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),)
57endef
58
Leonardo Sandoval327131c2020-09-10 12:18:27 -050059# Convenience function for addding multiple build definitions
60# $(eval $(call add_defines,FOO BOO))
61define add_defines
62 $(foreach def,$1,$(eval $(call add_define,$(def))))
63endef
64
Soren Brinkmann8eadeb42016-06-09 13:36:27 -070065# Convenience function for adding build definitions
66# $(eval $(call add_define_val,FOO,BAR)) will have:
67# -DFOO=BAR
68define add_define_val
69 DEFINES += -D$(1)=$(2)
70endef
71
Juan Castillo73c99d42015-08-18 14:23:04 +010072# Convenience function for verifying option has a boolean value
73# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
74define assert_boolean
Masahiro Yamadabe4cd402017-05-23 23:45:01 +090075 $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean))
Juan Castillo73c99d42015-08-18 14:23:04 +010076endef
77
Leonardo Sandoval327131c2020-09-10 12:18:27 -050078# Convenience function for verifying options have boolean values
79# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values
80define assert_booleans
81 $(foreach bool,$1,$(eval $(call assert_boolean,$(bool))))
82endef
83
Jeenu Viswambharanc877b412017-01-16 16:52:35 +0000840-9 := 0 1 2 3 4 5 6 7 8 9
85
86# Function to verify that a given option $(1) contains a numeric value
87define assert_numeric
88$(if $($(1)),,$(error $(1) must not be empty))
89$(eval __numeric := $($(1)))
90$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric))))
91$(if $(__numeric),$(error $(1) must be numeric))
92endef
93
Leonardo Sandoval327131c2020-09-10 12:18:27 -050094# Convenience function for verifying options have numeric values
95# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values
96define assert_numerics
97 $(foreach num,$1,$(eval $(call assert_numeric,$(num))))
98endef
99
Marco Felsch8782b882022-11-24 11:02:05 +0100100# Convenience function to check for a given linker option. An call to
101# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker
102define ld_option
103 $(shell if $(LD) $(1) -v >/dev/null 2>&1; then echo $(1); fi )
104endef
105
Govindraj Raja8c1c54e2023-05-05 09:09:36 -0500106# Convenience function to check for a given compiler option. A call to
107# $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler
108define cc_option
109 $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null >/dev/null 2>&1; then echo $(1); fi )
110endef
111
Vijayenthiran Subramaniam8c7b9442020-02-08 21:27:30 +0530112# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to
113# $(2) and assign the sequence to $(1)
114define CREATE_SEQ
115$(if $(word $(2), $($(1))),\
116 $(eval $(1) += $(words $($(1))))\
117 $(eval $(1) := $(filter-out 0,$($(1)))),\
118 $(eval $(1) += $(words $($(1))))\
119 $(call CREATE_SEQ,$(1),$(2))\
120)
121endef
122
Juan Castillo73c99d42015-08-18 14:23:04 +0100123# IMG_LINKERFILE defines the linker script corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500124# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100125define IMG_LINKERFILE
Zelalem Aweke434d0492021-07-11 17:25:48 -0500126 ${BUILD_DIR}/$(1).ld
Juan Castillo73c99d42015-08-18 14:23:04 +0100127endef
128
129# IMG_MAPFILE defines the output file describing the memory map corresponding
130# to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500131# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100132define IMG_MAPFILE
Zelalem Aweke434d0492021-07-11 17:25:48 -0500133 ${BUILD_DIR}/$(1).map
Juan Castillo73c99d42015-08-18 14:23:04 +0100134endef
135
136# IMG_ELF defines the elf file corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500137# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100138define IMG_ELF
Zelalem Aweke434d0492021-07-11 17:25:48 -0500139 ${BUILD_DIR}/$(1).elf
Juan Castillo73c99d42015-08-18 14:23:04 +0100140endef
141
142# IMG_DUMP defines the symbols dump file corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500143# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100144define IMG_DUMP
Zelalem Aweke434d0492021-07-11 17:25:48 -0500145 ${BUILD_DIR}/$(1).dump
Juan Castillo73c99d42015-08-18 14:23:04 +0100146endef
147
148# IMG_BIN defines the default image file corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500149# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100150define IMG_BIN
Zelalem Aweke434d0492021-07-11 17:25:48 -0500151 ${BUILD_PLAT}/$(1).bin
Juan Castillo73c99d42015-08-18 14:23:04 +0100152endef
153
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530154# IMG_ENC_BIN defines the default encrypted image file corresponding to a
155# BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500156# $(1) = BL stage
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530157define IMG_ENC_BIN
Zelalem Aweke434d0492021-07-11 17:25:48 -0500158 ${BUILD_PLAT}/$(1)_enc.bin
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530159endef
160
161# ENCRYPT_FW invokes enctool to encrypt firmware binary
162# $(1) = input firmware binary
163# $(2) = output encrypted firmware binary
164define ENCRYPT_FW
165$(2): $(1) enctool
166 $$(ECHO) " ENC $$<"
167 $$(Q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@
168endef
169
Masahiro Yamada10cea932018-01-26 11:42:01 +0900170# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to
171# package a new payload and/or by cert_create to generate certificate.
172# Optionally, it adds the dependency on this payload
Juan Castillo73c99d42015-08-18 14:23:04 +0100173# $(1) = payload filename (i.e. bl31.bin)
Masahiro Yamada1e0c0782017-12-23 23:56:18 +0900174# $(2) = command line option for the specified payload (i.e. --soc-fw)
Masahiro Yamada36af3452018-01-26 11:42:01 +0900175# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900176# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530177# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin)
Masahiro Yamada10cea932018-01-26 11:42:01 +0900178define TOOL_ADD_PAYLOAD
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530179ifneq ($(5),)
180 $(4)FIP_ARGS += $(2) $(5)
181 $(if $(3),$(4)CRT_DEPS += $(1))
182else
Masahiro Yamada945b3162018-01-26 11:42:01 +0900183 $(4)FIP_ARGS += $(2) $(1)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530184 $(if $(3),$(4)CRT_DEPS += $(3))
185endif
Masahiro Yamada945b3162018-01-26 11:42:01 +0900186 $(if $(3),$(4)FIP_DEPS += $(3))
Masahiro Yamadaf30ee0b2018-01-26 11:42:01 +0900187 $(4)CRT_ARGS += $(2) $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100188endef
189
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900190# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters
191# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined.
192# $(1) = image_type (scp_bl2, bl33, etc.)
193# $(2) = payload filepath (ex. build/fvp/release/bl31.bin)
194# $(3) = command line option for the specified payload (ex. --soc-fw)
195# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin)
196# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530197# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin)
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900198
199define TOOL_ADD_IMG_PAYLOAD
200
201$(eval PRE_TOOL_FILTER := $($(call uppercase,$(1))_PRE_TOOL_FILTER))
202
203ifneq ($(PRE_TOOL_FILTER),)
204
205$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX))
206
207$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2))
208
209$(PROCESSED_PATH): $(4)
210
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530211$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6))
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900212
213else
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530214$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6))
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900215endif
216endef
217
Yatharth Kochar01912622015-10-12 12:33:47 +0100218# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation
Juan Castillo73c99d42015-08-18 14:23:04 +0100219# $(1) = parameter filename
220# $(2) = cert_create command line option for the specified parameter
Masahiro Yamada91704d92018-01-26 11:42:01 +0900221# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Juan Castillo73c99d42015-08-18 14:23:04 +0100222define CERT_ADD_CMD_OPT
Masahiro Yamada91704d92018-01-26 11:42:01 +0900223 $(3)CRT_ARGS += $(2) $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100224endef
225
Masahiro Yamadac939d132018-01-26 11:42:01 +0900226# TOOL_ADD_IMG allows the platform to specify an external image to be packed
227# in the FIP and/or for which certificate is generated. It also adds a
228# dependency on the image file, aborting the build if the file does not exist.
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900229# $(1) = image_type (scp_bl2, bl33, etc.)
Masahiro Yamada1e0c0782017-12-23 23:56:18 +0900230# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900231# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530232# $(4) = Image encryption flag (optional) (0, 1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100233# Example:
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900234# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Masahiro Yamadac939d132018-01-26 11:42:01 +0900235define TOOL_ADD_IMG
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900236 # Build option to specify the image filename (SCP_BL2, BL33, etc)
237 # This is the uppercase form of the first parameter
238 $(eval _V := $(call uppercase,$(1)))
239
Pali Rohár4727fd12020-11-24 16:53:04 +0100240 # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also
241 # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the
242 # target ${BUILD_PLAT}/${$(3)FIP_NAME}.
243 $(eval check_$(1)_cmd := \
244 $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \
245 $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \
246 )
247
Masahiro Yamada945b3162018-01-26 11:42:01 +0900248 $(3)CRT_DEPS += check_$(1)
Pali Rohár4727fd12020-11-24 16:53:04 +0100249 CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530250ifeq ($(4),1)
251 $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin)
252 $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN))
253 $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(ENC_BIN),$(3), \
254 $(ENC_BIN))
255else
Pali Rohár4727fd12020-11-24 16:53:04 +0100256 $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530257endif
Yatharth Kochar01912622015-10-12 12:33:47 +0100258
Masahiro Yamada87ebd202017-12-24 13:08:00 +0900259.PHONY: check_$(1)
Yatharth Kochar01912622015-10-12 12:33:47 +0100260check_$(1):
Pali Rohár4727fd12020-11-24 16:53:04 +0100261 $(check_$(1)_cmd)
Yatharth Kochar01912622015-10-12 12:33:47 +0100262endef
Juan Castillo73c99d42015-08-18 14:23:04 +0100263
Juan Pablo Condecf2dd172022-10-25 19:41:02 -0400264# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to
265# build the host tools by checking the version of OpenSSL located under
266# the path defined by the OPENSSL_DIR variable. It receives no parameters.
267define SELECT_OPENSSL_API_VERSION
268 # Set default value for USING_OPENSSL3 macro to 0
269 $(eval USING_OPENSSL3 = 0)
270 # Obtain the OpenSSL version for the build located under OPENSSL_DIR
271 $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version))
272 $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO}))
273 $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER))))
274 # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1
275 $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1))
276endef
277
Juan Castillo73c99d42015-08-18 14:23:04 +0100278################################################################################
Masahiro Yamada14db8902018-01-26 11:42:01 +0900279# Generic image processing filters
280################################################################################
281
282# GZIP
283define GZIP_RULE
284$(1): $(2)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100285 $(ECHO) " GZIP $$@"
Masahiro Yamada14db8902018-01-26 11:42:01 +0900286 $(Q)gzip -n -f -9 $$< --stdout > $$@
287endef
288
289GZIP_SUFFIX := .gz
290
291################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100292# Auxiliary macros to build TF images from sources
293################################################################################
294
Masahiro Yamada1d274ab2016-12-22 15:23:05 +0900295MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP
Juan Castillo73c99d42015-08-18 14:23:04 +0100296
Roberto Vargas5fee0282018-05-08 10:27:10 +0100297
298# MAKE_C_LIB builds a C source file and generates the dependency file
299# $(1) = output directory
300# $(2) = source file (%.c)
301# $(3) = library name
302define MAKE_C_LIB
303$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
304$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
305
306$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100307 $$(ECHO) " CC $$<"
Roberto Vargas5fee0282018-05-08 10:27:10 +0100308 $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@
309
310-include $(DEP)
311
312endef
313
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000314# MAKE_S_LIB builds an assembly source file and generates the dependency file
315# $(1) = output directory
316# $(2) = source file (%.S)
317# $(3) = library name
318define MAKE_S_LIB
319$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
320$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
321
322$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
323 $$(ECHO) " AS $$<"
324 $$(Q)$$(AS) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
325
326-include $(DEP)
327
328endef
329
Roberto Vargas5fee0282018-05-08 10:27:10 +0100330
Juan Castillo73c99d42015-08-18 14:23:04 +0100331# MAKE_C builds a C source file and generates the dependency file
332# $(1) = output directory
333# $(2) = source file (%.c)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500334# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100335define MAKE_C
336
337$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900338$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500339$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
340$(eval BL_CFLAGS := $($(call uppercase,$(3))_CFLAGS))
Juan Castillo73c99d42015-08-18 14:23:04 +0100341
Zelalem Aweke434d0492021-07-11 17:25:48 -0500342$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100343 $$(ECHO) " CC $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900344 $$(Q)$$(CC) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castillo73c99d42015-08-18 14:23:04 +0100345
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900346-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100347
348endef
349
350
351# MAKE_S builds an assembly source file and generates the dependency file
352# $(1) = output directory
353# $(2) = assembly file (%.S)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500354# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100355define MAKE_S
356
357$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900358$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500359$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
360$(eval BL_ASFLAGS := $($(call uppercase,$(3))_ASFLAGS))
Juan Castillo73c99d42015-08-18 14:23:04 +0100361
Zelalem Aweke434d0492021-07-11 17:25:48 -0500362$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100363 $$(ECHO) " AS $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900364 $$(Q)$$(AS) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castillo73c99d42015-08-18 14:23:04 +0100365
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900366-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100367
368endef
369
370
371# MAKE_LD generate the linker script using the C preprocessor
372# $(1) = output linker script
373# $(2) = input template
Zelalem Aweke434d0492021-07-11 17:25:48 -0500374# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100375define MAKE_LD
376
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900377$(eval DEP := $(1).d)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500378$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100379
Zelalem Aweke434d0492021-07-11 17:25:48 -0500380$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100381 $$(ECHO) " PP $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900382 $$(Q)$$(CPP) $$(CPPFLAGS) $(BL_CPPFLAGS) $(TF_CFLAGS_$(ARCH)) -P -x assembler-with-cpp -D__LINKER__ $(MAKE_DEP) -o $$@ $$<
Juan Castillo73c99d42015-08-18 14:23:04 +0100383
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900384-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100385
386endef
387
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000388# MAKE_LIB_OBJS builds both C and assembly source files
Roberto Vargas5fee0282018-05-08 10:27:10 +0100389# $(1) = output directory
390# $(2) = list of source files
391# $(3) = name of the library
392define MAKE_LIB_OBJS
393 $(eval C_OBJS := $(filter %.c,$(2)))
394 $(eval REMAIN := $(filter-out %.c,$(2)))
395 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3))))
396
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000397 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
398 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
399 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3))))
400
Roberto Vargas5fee0282018-05-08 10:27:10 +0100401 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
402endef
403
Juan Castillo73c99d42015-08-18 14:23:04 +0100404
405# MAKE_OBJS builds both C and assembly source files
406# $(1) = output directory
407# $(2) = list of source files (both C and assembly)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500408# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100409define MAKE_OBJS
410 $(eval C_OBJS := $(filter %.c,$(2)))
411 $(eval REMAIN := $(filter-out %.c,$(2)))
412 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
413
414 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
415 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
416 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
417
418 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
419endef
420
421
422# NOTE: The line continuation '\' is required in the next define otherwise we
423# end up with a line-feed characer at the end of the last c filename.
Evan Lloyde7f54db2015-12-02 18:56:06 +0000424# Also bear this issue in mind if extending the list of supported filetypes.
Juan Castillo73c99d42015-08-18 14:23:04 +0100425define SOURCES_TO_OBJS
426 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
427 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
428endef
429
Patrick Georgi2f5d4a42016-01-28 14:46:18 +0100430# Allow overriding the timestamp, for example for reproducible builds, or to
431# synchronize timestamps across multiple projects.
432# This must be set to a C string (including quotes where applicable).
433BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
Juan Castillo73c99d42015-08-18 14:23:04 +0100434
Roberto Vargas5fee0282018-05-08 10:27:10 +0100435.PHONY: libraries
436
Roberto Vargas5accce52018-05-22 16:05:42 +0100437# MAKE_LIB_DIRS macro defines the target for the directory where
Roberto Vargas5fee0282018-05-08 10:27:10 +0100438# libraries are created
Roberto Vargas5accce52018-05-22 16:05:42 +0100439define MAKE_LIB_DIRS
Roberto Vargas5fee0282018-05-08 10:27:10 +0100440 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargas5accce52018-05-22 16:05:42 +0100441 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
442 $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper)
443 $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT}))
444 $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT}))
445 $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT}))
Roberto Vargas5fee0282018-05-08 10:27:10 +0100446endef
447
448# MAKE_LIB macro defines the targets and options to build each BL image.
449# Arguments:
450# $(1) = Library name
451define MAKE_LIB
452 $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1))
453 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargas5accce52018-05-22 16:05:42 +0100454 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
Roberto Vargas5fee0282018-05-08 10:27:10 +0100455 $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS))
456 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
457
458$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
459$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
460
461.PHONY : lib${1}_dirs
Roberto Vargas5accce52018-05-22 16:05:42 +0100462lib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR}
Roberto Vargas5fee0282018-05-08 10:27:10 +0100463libraries: ${LIB_DIR}/lib$(1).a
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800464ifneq ($(findstring armlink,$(notdir $(LD))),)
465LDPATHS = --userlibpath=${LIB_DIR}
466LDLIBS += --library=$(1)
467else
Roberto Vargas5fee0282018-05-08 10:27:10 +0100468LDPATHS = -L${LIB_DIR}
469LDLIBS += -l$(1)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800470endif
Roberto Vargas5fee0282018-05-08 10:27:10 +0100471
Roberto Vargas5accce52018-05-22 16:05:42 +0100472ifeq ($(USE_ROMLIB),1)
Sathees Balya6baf85b2018-10-18 19:14:21 +0100473LIBWRAPPER = -lwrappers
Roberto Vargas5accce52018-05-22 16:05:42 +0100474endif
475
Roberto Vargas5fee0282018-05-08 10:27:10 +0100476all: ${LIB_DIR}/lib$(1).a
477
478${LIB_DIR}/lib$(1).a: $(OBJS)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100479 $$(ECHO) " AR $$@"
Roberto Vargas5fee0282018-05-08 10:27:10 +0100480 $$(Q)$$(AR) cr $$@ $$?
481endef
482
Juan Castillo73c99d42015-08-18 14:23:04 +0100483# MAKE_BL macro defines the targets and options to build each BL image.
484# Arguments:
Zelalem Aweke434d0492021-07-11 17:25:48 -0500485# $(1) = BL stage
Juan Castillo8f0617e2016-01-05 11:55:36 +0000486# $(2) = FIP command line option (if empty, image will not be included in the FIP)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900487# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530488# $(4) = BL encryption flag (optional) (0, 1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100489define MAKE_BL
Zelalem Aweke434d0492021-07-11 17:25:48 -0500490 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
491 $(eval BL_SOURCES := $($(call uppercase,$(1))_SOURCES))
Yatharth Kochar5ba8f662015-10-02 13:58:52 +0100492 $(eval SOURCES := $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))
Juan Castillo73c99d42015-08-18 14:23:04 +0100493 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
494 $(eval LINKERFILE := $(call IMG_LINKERFILE,$(1)))
495 $(eval MAPFILE := $(call IMG_MAPFILE,$(1)))
496 $(eval ELF := $(call IMG_ELF,$(1)))
497 $(eval DUMP := $(call IMG_DUMP,$(1)))
498 $(eval BIN := $(call IMG_BIN,$(1)))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530499 $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500500 $(eval BL_LINKERFILE := $($(call uppercase,$(1))_LINKERFILE))
501 $(eval BL_LIBS := $($(call uppercase,$(1))_LIBS))
Evan Lloyd51b27702015-12-03 12:19:30 +0000502 # We use sort only to get a list of unique object directory names.
503 # ordering is not relevant but sort removes duplicates.
Evan Lloyd6ba7d272017-04-07 16:58:57 +0100504 $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${LINKERFILE})))
Evan Lloyd51b27702015-12-03 12:19:30 +0000505 # The $(dir ) function leaves a trailing / on the directory names
Masahiro Yamadad014ea62017-01-19 19:31:00 +0900506 # Rip off the / to match directory names with make rule targets.
507 $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100508
Evan Lloyd51b27702015-12-03 12:19:30 +0000509# Create generators for object directory structure
Juan Castillo73c99d42015-08-18 14:23:04 +0100510
Masahiro Yamada8012cc52017-11-04 03:12:28 +0900511$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
Evan Lloyd6ba7d272017-04-07 16:58:57 +0100512
513$(eval $(foreach objd,${OBJ_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
Juan Castillo73c99d42015-08-18 14:23:04 +0100514
Zelalem Aweke434d0492021-07-11 17:25:48 -0500515.PHONY : ${1}_dirs
Evan Lloyd51b27702015-12-03 12:19:30 +0000516
517# We use order-only prerequisites to ensure that directories are created,
518# but do not cause re-builds every time a file is written.
Zelalem Aweke434d0492021-07-11 17:25:48 -0500519${1}_dirs: | ${OBJ_DIRS}
Evan Lloyd51b27702015-12-03 12:19:30 +0000520
521$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
Masahiro Yamadaa6ca7882017-01-12 10:48:22 +0900522$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500523$(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS))
Evan Lloyd51b27702015-12-03 12:19:30 +0000524
Roberto Vargas5accce52018-05-22 16:05:42 +0100525ifeq ($(USE_ROMLIB),1)
526$(ELF): romlib.bin
527endif
528
Leon Chen8dccddc2022-03-23 18:51:48 +0800529# MODULE_OBJS can be assigned by vendors with different compiled
530# object file path, and prebuilt object file path.
531$(eval OBJS += $(MODULE_OBJS))
532
Zelalem Aweke434d0492021-07-11 17:25:48 -0500533$(ELF): $(OBJS) $(LINKERFILE) | $(1)_dirs libraries $(BL_LIBS)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100534 $$(ECHO) " LD $$@"
Evan Lloyd414ab852015-12-03 12:58:52 +0000535ifdef MAKE_BUILD_STRINGS
536 $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o)
537else
Patrick Georgi2f5d4a42016-01-28 14:46:18 +0100538 @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \
laurenw-armdddf4282022-07-12 10:12:05 -0500539 const char version_string[] = "${VERSION_STRING}"; \
540 const char version[] = "${VERSION}";' | \
Masahiro Yamadaf2e1d572016-12-22 12:39:55 +0900541 $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o
Evan Lloyd414ab852015-12-03 12:58:52 +0000542endif
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800543ifneq ($(findstring armlink,$(notdir $(LD))),)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500544 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800545 --predefine="-D__LINKER__=$(__LINKER__)" \
546 --predefine="-DTF_CFLAGS=$(TF_CFLAGS)" \
Zelalem Aweke434d0492021-07-11 17:25:48 -0500547 --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800548 $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) \
549 $(BUILD_DIR)/build_message.o $(OBJS)
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600550else ifneq ($(findstring gcc,$(notdir $(LD))),)
551 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Wl,-Map=$(MAPFILE) \
Leon Chen8dccddc2022-03-23 18:51:48 +0800552 -Wl,-dT $(LINKERFILE) $(EXTRA_LINKERFILE) $(BUILD_DIR)/build_message.o \
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600553 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800554else
Masahiro Yamadad986bae2020-01-17 13:44:20 +0900555 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
Roberto Vargas5fee0282018-05-08 10:27:10 +0100556 --script $(LINKERFILE) $(BUILD_DIR)/build_message.o \
Sathees Balya6baf85b2018-10-18 19:14:21 +0100557 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800558endif
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200559ifeq ($(DISABLE_BIN_GENERATION),1)
560 @${ECHO_BLANK_LINE}
561 @echo "Built $$@ successfully"
562 @${ECHO_BLANK_LINE}
563endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100564
565$(DUMP): $(ELF)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100566 $${ECHO} " OD $$@"
Juan Castillo73c99d42015-08-18 14:23:04 +0100567 $${Q}$${OD} -dx $$< > $$@
568
569$(BIN): $(ELF)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100570 $${ECHO} " BIN $$@"
Juan Castillo73c99d42015-08-18 14:23:04 +0100571 $$(Q)$$(OC) -O binary $$< $$@
Evan Lloyd052ab522017-04-11 16:52:00 +0100572 @${ECHO_BLANK_LINE}
Juan Castillo73c99d42015-08-18 14:23:04 +0100573 @echo "Built $$@ successfully"
Evan Lloyd052ab522017-04-11 16:52:00 +0100574 @${ECHO_BLANK_LINE}
Juan Castillo73c99d42015-08-18 14:23:04 +0100575
Zelalem Aweke434d0492021-07-11 17:25:48 -0500576.PHONY: $(1)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200577ifeq ($(DISABLE_BIN_GENERATION),1)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500578$(1): $(ELF) $(DUMP)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200579else
Zelalem Aweke434d0492021-07-11 17:25:48 -0500580$(1): $(BIN) $(DUMP)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200581endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100582
Zelalem Aweke434d0492021-07-11 17:25:48 -0500583all: $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100584
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530585ifeq ($(4),1)
586$(call ENCRYPT_FW,$(BIN),$(ENC_BIN))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500587$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(ENC_BIN),$(3), \
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530588 $(ENC_BIN)))
589else
Zelalem Aweke434d0492021-07-11 17:25:48 -0500590$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(BIN),$(3)))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530591endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100592
593endef
594
Soby Mathew38c14d82017-12-14 17:44:56 +0000595# Convert device tree source file names to matching blobs
596# $(1) = input dts
Nishanth Menon03b397a2016-10-14 01:13:57 +0000597define SOURCES_TO_DTBS
598 $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1))))
599endef
600
Soby Mathew38c14d82017-12-14 17:44:56 +0000601# MAKE_FDT_DIRS macro creates the prerequisite directories that host the
602# FDT binaries
603# $(1) = output directory
604# $(2) = input dts
605define MAKE_FDT_DIRS
606 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000607 $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS})))
608 # The $(dir ) function leaves a trailing / on the directory names
609 # Rip off the / to match directory names with make rule targets.
610 $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS)))
611
612$(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
613
614fdt_dirs: ${DTB_DIRS}
Nishanth Menon03b397a2016-10-14 01:13:57 +0000615endef
616
Soby Mathew38c14d82017-12-14 17:44:56 +0000617# MAKE_DTB generate the Flattened device tree binary
Nishanth Menon03b397a2016-10-14 01:13:57 +0000618# $(1) = output directory
619# $(2) = input dts
620define MAKE_DTB
621
Yann Gautier077b3e92018-09-04 10:44:00 +0200622# List of DTB file(s) to generate, based on DTS file basename list
Soby Mathew38c14d82017-12-14 17:44:56 +0000623$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Yann Gautier077b3e92018-09-04 10:44:00 +0200624# List of the pre-compiled DTS file(s)
Yann Gautier01d237c2018-06-18 16:00:23 +0200625$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2)))))
Yann Gautier077b3e92018-09-04 10:44:00 +0200626# Dependencies of the pre-compiled DTS file(s) on its source and included files
627$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ)))
628# Dependencies of the DT compilation on its pre-compiled DTS
629$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ)))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000630
Stephen Warren6bc1a302018-02-21 17:13:50 -0700631$(DOBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100632 $${ECHO} " CPP $$<"
Yann Gautier077b3e92018-09-04 10:44:00 +0200633 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Manish Pandey7e94a692019-01-21 14:50:10 +0000634 $$(Q)$$(PP) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$<
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100635 $${ECHO} " DTC $$<"
Balint Dobszay2d51b552020-01-10 17:16:27 +0100636 $$(Q)$$(DTC) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $(DPRE)
Nishanth Menon03b397a2016-10-14 01:13:57 +0000637
Yann Gautier077b3e92018-09-04 10:44:00 +0200638-include $(DTBDEP)
639-include $(DTSDEP)
Nishanth Menon03b397a2016-10-14 01:13:57 +0000640
641endef
642
643# MAKE_DTBS builds flattened device tree sources
644# $(1) = output directory
645# $(2) = list of flattened device tree source files
646define MAKE_DTBS
647 $(eval DOBJS := $(filter %.dts,$(2)))
648 $(eval REMAIN := $(filter-out %.dts,$(2)))
Soby Mathew38c14d82017-12-14 17:44:56 +0000649 $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN)))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000650 $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj))))
651
Soby Mathew38c14d82017-12-14 17:44:56 +0000652 $(eval $(call MAKE_FDT_DIRS,$(1),$(2)))
653
654dtbs: $(DTBS)
655all: dtbs
Nishanth Menon03b397a2016-10-14 01:13:57 +0000656endef