blob: a2a94ef9b9491b5ff198a018518ffc3398c4dbb0 [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
Vijayenthiran Subramaniam8c7b9442020-02-08 21:27:30 +0530106# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to
107# $(2) and assign the sequence to $(1)
108define CREATE_SEQ
109$(if $(word $(2), $($(1))),\
110 $(eval $(1) += $(words $($(1))))\
111 $(eval $(1) := $(filter-out 0,$($(1)))),\
112 $(eval $(1) += $(words $($(1))))\
113 $(call CREATE_SEQ,$(1),$(2))\
114)
115endef
116
Juan Castillo73c99d42015-08-18 14:23:04 +0100117# IMG_LINKERFILE defines the linker script corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500118# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100119define IMG_LINKERFILE
Zelalem Aweke434d0492021-07-11 17:25:48 -0500120 ${BUILD_DIR}/$(1).ld
Juan Castillo73c99d42015-08-18 14:23:04 +0100121endef
122
123# IMG_MAPFILE defines the output file describing the memory map corresponding
124# to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500125# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100126define IMG_MAPFILE
Zelalem Aweke434d0492021-07-11 17:25:48 -0500127 ${BUILD_DIR}/$(1).map
Juan Castillo73c99d42015-08-18 14:23:04 +0100128endef
129
130# IMG_ELF defines the elf file corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500131# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100132define IMG_ELF
Zelalem Aweke434d0492021-07-11 17:25:48 -0500133 ${BUILD_DIR}/$(1).elf
Juan Castillo73c99d42015-08-18 14:23:04 +0100134endef
135
136# IMG_DUMP defines the symbols dump 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_DUMP
Zelalem Aweke434d0492021-07-11 17:25:48 -0500139 ${BUILD_DIR}/$(1).dump
Juan Castillo73c99d42015-08-18 14:23:04 +0100140endef
141
142# IMG_BIN defines the default image 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_BIN
Zelalem Aweke434d0492021-07-11 17:25:48 -0500145 ${BUILD_PLAT}/$(1).bin
Juan Castillo73c99d42015-08-18 14:23:04 +0100146endef
147
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530148# IMG_ENC_BIN defines the default encrypted image file corresponding to a
149# BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500150# $(1) = BL stage
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530151define IMG_ENC_BIN
Zelalem Aweke434d0492021-07-11 17:25:48 -0500152 ${BUILD_PLAT}/$(1)_enc.bin
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530153endef
154
155# ENCRYPT_FW invokes enctool to encrypt firmware binary
156# $(1) = input firmware binary
157# $(2) = output encrypted firmware binary
158define ENCRYPT_FW
159$(2): $(1) enctool
160 $$(ECHO) " ENC $$<"
161 $$(Q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@
162endef
163
Masahiro Yamada10cea932018-01-26 11:42:01 +0900164# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to
165# package a new payload and/or by cert_create to generate certificate.
166# Optionally, it adds the dependency on this payload
Juan Castillo73c99d42015-08-18 14:23:04 +0100167# $(1) = payload filename (i.e. bl31.bin)
Masahiro Yamada1e0c0782017-12-23 23:56:18 +0900168# $(2) = command line option for the specified payload (i.e. --soc-fw)
Masahiro Yamada36af3452018-01-26 11:42:01 +0900169# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900170# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530171# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin)
Masahiro Yamada10cea932018-01-26 11:42:01 +0900172define TOOL_ADD_PAYLOAD
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530173ifneq ($(5),)
174 $(4)FIP_ARGS += $(2) $(5)
175 $(if $(3),$(4)CRT_DEPS += $(1))
176else
Masahiro Yamada945b3162018-01-26 11:42:01 +0900177 $(4)FIP_ARGS += $(2) $(1)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530178 $(if $(3),$(4)CRT_DEPS += $(3))
179endif
Masahiro Yamada945b3162018-01-26 11:42:01 +0900180 $(if $(3),$(4)FIP_DEPS += $(3))
Masahiro Yamadaf30ee0b2018-01-26 11:42:01 +0900181 $(4)CRT_ARGS += $(2) $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100182endef
183
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900184# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters
185# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined.
186# $(1) = image_type (scp_bl2, bl33, etc.)
187# $(2) = payload filepath (ex. build/fvp/release/bl31.bin)
188# $(3) = command line option for the specified payload (ex. --soc-fw)
189# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin)
190# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530191# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin)
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900192
193define TOOL_ADD_IMG_PAYLOAD
194
195$(eval PRE_TOOL_FILTER := $($(call uppercase,$(1))_PRE_TOOL_FILTER))
196
197ifneq ($(PRE_TOOL_FILTER),)
198
199$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX))
200
201$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2))
202
203$(PROCESSED_PATH): $(4)
204
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530205$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6))
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900206
207else
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530208$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6))
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900209endif
210endef
211
Yatharth Kochar01912622015-10-12 12:33:47 +0100212# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation
Juan Castillo73c99d42015-08-18 14:23:04 +0100213# $(1) = parameter filename
214# $(2) = cert_create command line option for the specified parameter
Masahiro Yamada91704d92018-01-26 11:42:01 +0900215# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Juan Castillo73c99d42015-08-18 14:23:04 +0100216define CERT_ADD_CMD_OPT
Masahiro Yamada91704d92018-01-26 11:42:01 +0900217 $(3)CRT_ARGS += $(2) $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100218endef
219
Masahiro Yamadac939d132018-01-26 11:42:01 +0900220# TOOL_ADD_IMG allows the platform to specify an external image to be packed
221# in the FIP and/or for which certificate is generated. It also adds a
222# dependency on the image file, aborting the build if the file does not exist.
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900223# $(1) = image_type (scp_bl2, bl33, etc.)
Masahiro Yamada1e0c0782017-12-23 23:56:18 +0900224# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900225# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530226# $(4) = Image encryption flag (optional) (0, 1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100227# Example:
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900228# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Masahiro Yamadac939d132018-01-26 11:42:01 +0900229define TOOL_ADD_IMG
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900230 # Build option to specify the image filename (SCP_BL2, BL33, etc)
231 # This is the uppercase form of the first parameter
232 $(eval _V := $(call uppercase,$(1)))
233
Pali Rohár4727fd12020-11-24 16:53:04 +0100234 # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also
235 # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the
236 # target ${BUILD_PLAT}/${$(3)FIP_NAME}.
237 $(eval check_$(1)_cmd := \
238 $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \
239 $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \
240 )
241
Masahiro Yamada945b3162018-01-26 11:42:01 +0900242 $(3)CRT_DEPS += check_$(1)
Pali Rohár4727fd12020-11-24 16:53:04 +0100243 CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530244ifeq ($(4),1)
245 $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin)
246 $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN))
247 $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(ENC_BIN),$(3), \
248 $(ENC_BIN))
249else
Pali Rohár4727fd12020-11-24 16:53:04 +0100250 $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530251endif
Yatharth Kochar01912622015-10-12 12:33:47 +0100252
Masahiro Yamada87ebd202017-12-24 13:08:00 +0900253.PHONY: check_$(1)
Yatharth Kochar01912622015-10-12 12:33:47 +0100254check_$(1):
Pali Rohár4727fd12020-11-24 16:53:04 +0100255 $(check_$(1)_cmd)
Yatharth Kochar01912622015-10-12 12:33:47 +0100256endef
Juan Castillo73c99d42015-08-18 14:23:04 +0100257
Juan Pablo Condecf2dd172022-10-25 19:41:02 -0400258# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to
259# build the host tools by checking the version of OpenSSL located under
260# the path defined by the OPENSSL_DIR variable. It receives no parameters.
261define SELECT_OPENSSL_API_VERSION
262 # Set default value for USING_OPENSSL3 macro to 0
263 $(eval USING_OPENSSL3 = 0)
264 # Obtain the OpenSSL version for the build located under OPENSSL_DIR
265 $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version))
266 $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO}))
267 $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER))))
268 # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1
269 $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1))
270endef
271
Juan Castillo73c99d42015-08-18 14:23:04 +0100272################################################################################
Masahiro Yamada14db8902018-01-26 11:42:01 +0900273# Generic image processing filters
274################################################################################
275
276# GZIP
277define GZIP_RULE
278$(1): $(2)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100279 $(ECHO) " GZIP $$@"
Masahiro Yamada14db8902018-01-26 11:42:01 +0900280 $(Q)gzip -n -f -9 $$< --stdout > $$@
281endef
282
283GZIP_SUFFIX := .gz
284
285################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100286# Auxiliary macros to build TF images from sources
287################################################################################
288
Masahiro Yamada1d274ab2016-12-22 15:23:05 +0900289MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP
Juan Castillo73c99d42015-08-18 14:23:04 +0100290
Roberto Vargas5fee0282018-05-08 10:27:10 +0100291
292# MAKE_C_LIB builds a C source file and generates the dependency file
293# $(1) = output directory
294# $(2) = source file (%.c)
295# $(3) = library name
296define MAKE_C_LIB
297$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
298$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
299
300$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100301 $$(ECHO) " CC $$<"
Roberto Vargas5fee0282018-05-08 10:27:10 +0100302 $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@
303
304-include $(DEP)
305
306endef
307
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000308# MAKE_S_LIB builds an assembly source file and generates the dependency file
309# $(1) = output directory
310# $(2) = source file (%.S)
311# $(3) = library name
312define MAKE_S_LIB
313$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
314$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
315
316$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
317 $$(ECHO) " AS $$<"
318 $$(Q)$$(AS) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
319
320-include $(DEP)
321
322endef
323
Roberto Vargas5fee0282018-05-08 10:27:10 +0100324
Juan Castillo73c99d42015-08-18 14:23:04 +0100325# MAKE_C builds a C source file and generates the dependency file
326# $(1) = output directory
327# $(2) = source file (%.c)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500328# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100329define MAKE_C
330
331$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900332$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500333$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
334$(eval BL_CFLAGS := $($(call uppercase,$(3))_CFLAGS))
Juan Castillo73c99d42015-08-18 14:23:04 +0100335
Zelalem Aweke434d0492021-07-11 17:25:48 -0500336$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100337 $$(ECHO) " CC $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900338 $$(Q)$$(CC) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castillo73c99d42015-08-18 14:23:04 +0100339
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900340-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100341
342endef
343
344
345# MAKE_S builds an assembly source file and generates the dependency file
346# $(1) = output directory
347# $(2) = assembly file (%.S)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500348# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100349define MAKE_S
350
351$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900352$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500353$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
354$(eval BL_ASFLAGS := $($(call uppercase,$(3))_ASFLAGS))
Juan Castillo73c99d42015-08-18 14:23:04 +0100355
Zelalem Aweke434d0492021-07-11 17:25:48 -0500356$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100357 $$(ECHO) " AS $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900358 $$(Q)$$(AS) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castillo73c99d42015-08-18 14:23:04 +0100359
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900360-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100361
362endef
363
364
365# MAKE_LD generate the linker script using the C preprocessor
366# $(1) = output linker script
367# $(2) = input template
Zelalem Aweke434d0492021-07-11 17:25:48 -0500368# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100369define MAKE_LD
370
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900371$(eval DEP := $(1).d)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500372$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100373
Zelalem Aweke434d0492021-07-11 17:25:48 -0500374$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100375 $$(ECHO) " PP $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900376 $$(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 +0100377
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900378-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100379
380endef
381
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000382# MAKE_LIB_OBJS builds both C and assembly source files
Roberto Vargas5fee0282018-05-08 10:27:10 +0100383# $(1) = output directory
384# $(2) = list of source files
385# $(3) = name of the library
386define MAKE_LIB_OBJS
387 $(eval C_OBJS := $(filter %.c,$(2)))
388 $(eval REMAIN := $(filter-out %.c,$(2)))
389 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3))))
390
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000391 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
392 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
393 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3))))
394
Roberto Vargas5fee0282018-05-08 10:27:10 +0100395 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
396endef
397
Juan Castillo73c99d42015-08-18 14:23:04 +0100398
399# MAKE_OBJS builds both C and assembly source files
400# $(1) = output directory
401# $(2) = list of source files (both C and assembly)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500402# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100403define MAKE_OBJS
404 $(eval C_OBJS := $(filter %.c,$(2)))
405 $(eval REMAIN := $(filter-out %.c,$(2)))
406 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
407
408 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
409 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
410 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
411
412 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
413endef
414
415
416# NOTE: The line continuation '\' is required in the next define otherwise we
417# end up with a line-feed characer at the end of the last c filename.
Evan Lloyde7f54db2015-12-02 18:56:06 +0000418# Also bear this issue in mind if extending the list of supported filetypes.
Juan Castillo73c99d42015-08-18 14:23:04 +0100419define SOURCES_TO_OBJS
420 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
421 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
422endef
423
Patrick Georgi2f5d4a42016-01-28 14:46:18 +0100424# Allow overriding the timestamp, for example for reproducible builds, or to
425# synchronize timestamps across multiple projects.
426# This must be set to a C string (including quotes where applicable).
427BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
Juan Castillo73c99d42015-08-18 14:23:04 +0100428
Roberto Vargas5fee0282018-05-08 10:27:10 +0100429.PHONY: libraries
430
Roberto Vargas5accce52018-05-22 16:05:42 +0100431# MAKE_LIB_DIRS macro defines the target for the directory where
Roberto Vargas5fee0282018-05-08 10:27:10 +0100432# libraries are created
Roberto Vargas5accce52018-05-22 16:05:42 +0100433define MAKE_LIB_DIRS
Roberto Vargas5fee0282018-05-08 10:27:10 +0100434 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargas5accce52018-05-22 16:05:42 +0100435 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
436 $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper)
437 $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT}))
438 $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT}))
439 $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT}))
Roberto Vargas5fee0282018-05-08 10:27:10 +0100440endef
441
442# MAKE_LIB macro defines the targets and options to build each BL image.
443# Arguments:
444# $(1) = Library name
445define MAKE_LIB
446 $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1))
447 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargas5accce52018-05-22 16:05:42 +0100448 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
Roberto Vargas5fee0282018-05-08 10:27:10 +0100449 $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS))
450 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
451
452$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
453$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
454
455.PHONY : lib${1}_dirs
Roberto Vargas5accce52018-05-22 16:05:42 +0100456lib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR}
Roberto Vargas5fee0282018-05-08 10:27:10 +0100457libraries: ${LIB_DIR}/lib$(1).a
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800458ifneq ($(findstring armlink,$(notdir $(LD))),)
459LDPATHS = --userlibpath=${LIB_DIR}
460LDLIBS += --library=$(1)
461else
Roberto Vargas5fee0282018-05-08 10:27:10 +0100462LDPATHS = -L${LIB_DIR}
463LDLIBS += -l$(1)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800464endif
Roberto Vargas5fee0282018-05-08 10:27:10 +0100465
Roberto Vargas5accce52018-05-22 16:05:42 +0100466ifeq ($(USE_ROMLIB),1)
Sathees Balya6baf85b2018-10-18 19:14:21 +0100467LIBWRAPPER = -lwrappers
Roberto Vargas5accce52018-05-22 16:05:42 +0100468endif
469
Roberto Vargas5fee0282018-05-08 10:27:10 +0100470all: ${LIB_DIR}/lib$(1).a
471
472${LIB_DIR}/lib$(1).a: $(OBJS)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100473 $$(ECHO) " AR $$@"
Roberto Vargas5fee0282018-05-08 10:27:10 +0100474 $$(Q)$$(AR) cr $$@ $$?
475endef
476
Juan Castillo73c99d42015-08-18 14:23:04 +0100477# MAKE_BL macro defines the targets and options to build each BL image.
478# Arguments:
Zelalem Aweke434d0492021-07-11 17:25:48 -0500479# $(1) = BL stage
Juan Castillo8f0617e2016-01-05 11:55:36 +0000480# $(2) = FIP command line option (if empty, image will not be included in the FIP)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900481# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530482# $(4) = BL encryption flag (optional) (0, 1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100483define MAKE_BL
Zelalem Aweke434d0492021-07-11 17:25:48 -0500484 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
485 $(eval BL_SOURCES := $($(call uppercase,$(1))_SOURCES))
Yatharth Kochar5ba8f662015-10-02 13:58:52 +0100486 $(eval SOURCES := $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))
Juan Castillo73c99d42015-08-18 14:23:04 +0100487 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
488 $(eval LINKERFILE := $(call IMG_LINKERFILE,$(1)))
489 $(eval MAPFILE := $(call IMG_MAPFILE,$(1)))
490 $(eval ELF := $(call IMG_ELF,$(1)))
491 $(eval DUMP := $(call IMG_DUMP,$(1)))
492 $(eval BIN := $(call IMG_BIN,$(1)))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530493 $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500494 $(eval BL_LINKERFILE := $($(call uppercase,$(1))_LINKERFILE))
495 $(eval BL_LIBS := $($(call uppercase,$(1))_LIBS))
Evan Lloyd51b27702015-12-03 12:19:30 +0000496 # We use sort only to get a list of unique object directory names.
497 # ordering is not relevant but sort removes duplicates.
Evan Lloyd6ba7d272017-04-07 16:58:57 +0100498 $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${LINKERFILE})))
Evan Lloyd51b27702015-12-03 12:19:30 +0000499 # The $(dir ) function leaves a trailing / on the directory names
Masahiro Yamadad014ea62017-01-19 19:31:00 +0900500 # Rip off the / to match directory names with make rule targets.
501 $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100502
Evan Lloyd51b27702015-12-03 12:19:30 +0000503# Create generators for object directory structure
Juan Castillo73c99d42015-08-18 14:23:04 +0100504
Masahiro Yamada8012cc52017-11-04 03:12:28 +0900505$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
Evan Lloyd6ba7d272017-04-07 16:58:57 +0100506
507$(eval $(foreach objd,${OBJ_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
Juan Castillo73c99d42015-08-18 14:23:04 +0100508
Zelalem Aweke434d0492021-07-11 17:25:48 -0500509.PHONY : ${1}_dirs
Evan Lloyd51b27702015-12-03 12:19:30 +0000510
511# We use order-only prerequisites to ensure that directories are created,
512# but do not cause re-builds every time a file is written.
Zelalem Aweke434d0492021-07-11 17:25:48 -0500513${1}_dirs: | ${OBJ_DIRS}
Evan Lloyd51b27702015-12-03 12:19:30 +0000514
515$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
Masahiro Yamadaa6ca7882017-01-12 10:48:22 +0900516$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500517$(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS))
Evan Lloyd51b27702015-12-03 12:19:30 +0000518
Roberto Vargas5accce52018-05-22 16:05:42 +0100519ifeq ($(USE_ROMLIB),1)
520$(ELF): romlib.bin
521endif
522
Leon Chen8dccddc2022-03-23 18:51:48 +0800523# MODULE_OBJS can be assigned by vendors with different compiled
524# object file path, and prebuilt object file path.
525$(eval OBJS += $(MODULE_OBJS))
526
Zelalem Aweke434d0492021-07-11 17:25:48 -0500527$(ELF): $(OBJS) $(LINKERFILE) | $(1)_dirs libraries $(BL_LIBS)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100528 $$(ECHO) " LD $$@"
Evan Lloyd414ab852015-12-03 12:58:52 +0000529ifdef MAKE_BUILD_STRINGS
530 $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o)
531else
Patrick Georgi2f5d4a42016-01-28 14:46:18 +0100532 @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \
laurenw-armdddf4282022-07-12 10:12:05 -0500533 const char version_string[] = "${VERSION_STRING}"; \
534 const char version[] = "${VERSION}";' | \
Masahiro Yamadaf2e1d572016-12-22 12:39:55 +0900535 $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o
Evan Lloyd414ab852015-12-03 12:58:52 +0000536endif
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800537ifneq ($(findstring armlink,$(notdir $(LD))),)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500538 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800539 --predefine="-D__LINKER__=$(__LINKER__)" \
540 --predefine="-DTF_CFLAGS=$(TF_CFLAGS)" \
Zelalem Aweke434d0492021-07-11 17:25:48 -0500541 --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800542 $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) \
543 $(BUILD_DIR)/build_message.o $(OBJS)
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600544else ifneq ($(findstring gcc,$(notdir $(LD))),)
545 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Wl,-Map=$(MAPFILE) \
Leon Chen8dccddc2022-03-23 18:51:48 +0800546 -Wl,-dT $(LINKERFILE) $(EXTRA_LINKERFILE) $(BUILD_DIR)/build_message.o \
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600547 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800548else
Masahiro Yamadad986bae2020-01-17 13:44:20 +0900549 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
Roberto Vargas5fee0282018-05-08 10:27:10 +0100550 --script $(LINKERFILE) $(BUILD_DIR)/build_message.o \
Sathees Balya6baf85b2018-10-18 19:14:21 +0100551 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800552endif
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200553ifeq ($(DISABLE_BIN_GENERATION),1)
554 @${ECHO_BLANK_LINE}
555 @echo "Built $$@ successfully"
556 @${ECHO_BLANK_LINE}
557endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100558
559$(DUMP): $(ELF)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100560 $${ECHO} " OD $$@"
Juan Castillo73c99d42015-08-18 14:23:04 +0100561 $${Q}$${OD} -dx $$< > $$@
562
563$(BIN): $(ELF)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100564 $${ECHO} " BIN $$@"
Juan Castillo73c99d42015-08-18 14:23:04 +0100565 $$(Q)$$(OC) -O binary $$< $$@
Evan Lloyd052ab522017-04-11 16:52:00 +0100566 @${ECHO_BLANK_LINE}
Juan Castillo73c99d42015-08-18 14:23:04 +0100567 @echo "Built $$@ successfully"
Evan Lloyd052ab522017-04-11 16:52:00 +0100568 @${ECHO_BLANK_LINE}
Juan Castillo73c99d42015-08-18 14:23:04 +0100569
Zelalem Aweke434d0492021-07-11 17:25:48 -0500570.PHONY: $(1)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200571ifeq ($(DISABLE_BIN_GENERATION),1)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500572$(1): $(ELF) $(DUMP)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200573else
Zelalem Aweke434d0492021-07-11 17:25:48 -0500574$(1): $(BIN) $(DUMP)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200575endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100576
Zelalem Aweke434d0492021-07-11 17:25:48 -0500577all: $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100578
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530579ifeq ($(4),1)
580$(call ENCRYPT_FW,$(BIN),$(ENC_BIN))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500581$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(ENC_BIN),$(3), \
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530582 $(ENC_BIN)))
583else
Zelalem Aweke434d0492021-07-11 17:25:48 -0500584$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(BIN),$(3)))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530585endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100586
587endef
588
Soby Mathew38c14d82017-12-14 17:44:56 +0000589# Convert device tree source file names to matching blobs
590# $(1) = input dts
Nishanth Menon03b397a2016-10-14 01:13:57 +0000591define SOURCES_TO_DTBS
592 $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1))))
593endef
594
Soby Mathew38c14d82017-12-14 17:44:56 +0000595# MAKE_FDT_DIRS macro creates the prerequisite directories that host the
596# FDT binaries
597# $(1) = output directory
598# $(2) = input dts
599define MAKE_FDT_DIRS
600 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000601 $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS})))
602 # The $(dir ) function leaves a trailing / on the directory names
603 # Rip off the / to match directory names with make rule targets.
604 $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS)))
605
606$(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
607
608fdt_dirs: ${DTB_DIRS}
Nishanth Menon03b397a2016-10-14 01:13:57 +0000609endef
610
Soby Mathew38c14d82017-12-14 17:44:56 +0000611# MAKE_DTB generate the Flattened device tree binary
Nishanth Menon03b397a2016-10-14 01:13:57 +0000612# $(1) = output directory
613# $(2) = input dts
614define MAKE_DTB
615
Yann Gautier077b3e92018-09-04 10:44:00 +0200616# List of DTB file(s) to generate, based on DTS file basename list
Soby Mathew38c14d82017-12-14 17:44:56 +0000617$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Yann Gautier077b3e92018-09-04 10:44:00 +0200618# List of the pre-compiled DTS file(s)
Yann Gautier01d237c2018-06-18 16:00:23 +0200619$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2)))))
Yann Gautier077b3e92018-09-04 10:44:00 +0200620# Dependencies of the pre-compiled DTS file(s) on its source and included files
621$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ)))
622# Dependencies of the DT compilation on its pre-compiled DTS
623$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ)))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000624
Stephen Warren6bc1a302018-02-21 17:13:50 -0700625$(DOBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100626 $${ECHO} " CPP $$<"
Yann Gautier077b3e92018-09-04 10:44:00 +0200627 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Manish Pandey7e94a692019-01-21 14:50:10 +0000628 $$(Q)$$(PP) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$<
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100629 $${ECHO} " DTC $$<"
Balint Dobszay2d51b552020-01-10 17:16:27 +0100630 $$(Q)$$(DTC) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $(DPRE)
Nishanth Menon03b397a2016-10-14 01:13:57 +0000631
Yann Gautier077b3e92018-09-04 10:44:00 +0200632-include $(DTBDEP)
633-include $(DTSDEP)
Nishanth Menon03b397a2016-10-14 01:13:57 +0000634
635endef
636
637# MAKE_DTBS builds flattened device tree sources
638# $(1) = output directory
639# $(2) = list of flattened device tree source files
640define MAKE_DTBS
641 $(eval DOBJS := $(filter %.dts,$(2)))
642 $(eval REMAIN := $(filter-out %.dts,$(2)))
Soby Mathew38c14d82017-12-14 17:44:56 +0000643 $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN)))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000644 $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj))))
645
Soby Mathew38c14d82017-12-14 17:44:56 +0000646 $(eval $(call MAKE_FDT_DIRS,$(1),$(2)))
647
648dtbs: $(DTBS)
649all: dtbs
Nishanth Menon03b397a2016-10-14 01:13:57 +0000650endef