blob: 4a62504cca4715ba0c3bdcc504a299afe52d5503 [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)))
Govindraj Rajae0124e12023-01-27 10:08:54 +0000305$(eval LIB := $(call uppercase, $(notdir $(1))))
Roberto Vargas5fee0282018-05-08 10:27:10 +0100306
307$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100308 $$(ECHO) " CC $$<"
Govindraj Rajae0124e12023-01-27 10:08:54 +0000309 $$(Q)$$(CC) $$($(LIB)_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@
Roberto Vargas5fee0282018-05-08 10:27:10 +0100310
311-include $(DEP)
312
313endef
314
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000315# MAKE_S_LIB builds an assembly source file and generates the dependency file
316# $(1) = output directory
317# $(2) = source file (%.S)
318# $(3) = library name
319define MAKE_S_LIB
320$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
321$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
322
323$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
324 $$(ECHO) " AS $$<"
325 $$(Q)$$(AS) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
326
327-include $(DEP)
328
329endef
330
Roberto Vargas5fee0282018-05-08 10:27:10 +0100331
Juan Castillo73c99d42015-08-18 14:23:04 +0100332# MAKE_C builds a C source file and generates the dependency file
333# $(1) = output directory
334# $(2) = source file (%.c)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500335# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100336define MAKE_C
337
338$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900339$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500340$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
341$(eval BL_CFLAGS := $($(call uppercase,$(3))_CFLAGS))
Juan Castillo73c99d42015-08-18 14:23:04 +0100342
Zelalem Aweke434d0492021-07-11 17:25:48 -0500343$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100344 $$(ECHO) " CC $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900345 $$(Q)$$(CC) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castillo73c99d42015-08-18 14:23:04 +0100346
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900347-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100348
349endef
350
351
352# MAKE_S builds an assembly source file and generates the dependency file
353# $(1) = output directory
354# $(2) = assembly file (%.S)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500355# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100356define MAKE_S
357
358$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900359$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500360$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
361$(eval BL_ASFLAGS := $($(call uppercase,$(3))_ASFLAGS))
Juan Castillo73c99d42015-08-18 14:23:04 +0100362
Zelalem Aweke434d0492021-07-11 17:25:48 -0500363$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100364 $$(ECHO) " AS $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900365 $$(Q)$$(AS) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castillo73c99d42015-08-18 14:23:04 +0100366
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900367-include $(DEP)
Juan Castillo73c99d42015-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 Aweke434d0492021-07-11 17:25:48 -0500375# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100376define MAKE_LD
377
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900378$(eval DEP := $(1).d)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500379$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100380
Zelalem Aweke434d0492021-07-11 17:25:48 -0500381$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100382 $$(ECHO) " PP $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900383 $$(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 +0100384
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900385-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100386
387endef
388
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000389# MAKE_LIB_OBJS builds both C and assembly source files
Roberto Vargas5fee0282018-05-08 10:27:10 +0100390# $(1) = output directory
391# $(2) = list of source files
392# $(3) = name of the library
393define MAKE_LIB_OBJS
394 $(eval C_OBJS := $(filter %.c,$(2)))
395 $(eval REMAIN := $(filter-out %.c,$(2)))
396 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3))))
397
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000398 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
399 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
400 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3))))
401
Roberto Vargas5fee0282018-05-08 10:27:10 +0100402 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
403endef
404
Juan Castillo73c99d42015-08-18 14:23:04 +0100405
406# MAKE_OBJS builds both C and assembly source files
407# $(1) = output directory
408# $(2) = list of source files (both C and assembly)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500409# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100410define MAKE_OBJS
411 $(eval C_OBJS := $(filter %.c,$(2)))
412 $(eval REMAIN := $(filter-out %.c,$(2)))
413 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
414
415 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
416 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
417 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
418
419 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
420endef
421
422
423# NOTE: The line continuation '\' is required in the next define otherwise we
424# end up with a line-feed characer at the end of the last c filename.
Evan Lloyde7f54db2015-12-02 18:56:06 +0000425# Also bear this issue in mind if extending the list of supported filetypes.
Juan Castillo73c99d42015-08-18 14:23:04 +0100426define SOURCES_TO_OBJS
427 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
428 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
429endef
430
Patrick Georgi2f5d4a42016-01-28 14:46:18 +0100431# Allow overriding the timestamp, for example for reproducible builds, or to
432# synchronize timestamps across multiple projects.
433# This must be set to a C string (including quotes where applicable).
434BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
Juan Castillo73c99d42015-08-18 14:23:04 +0100435
Roberto Vargas5fee0282018-05-08 10:27:10 +0100436.PHONY: libraries
437
Roberto Vargas5accce52018-05-22 16:05:42 +0100438# MAKE_LIB_DIRS macro defines the target for the directory where
Roberto Vargas5fee0282018-05-08 10:27:10 +0100439# libraries are created
Roberto Vargas5accce52018-05-22 16:05:42 +0100440define MAKE_LIB_DIRS
Roberto Vargas5fee0282018-05-08 10:27:10 +0100441 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargas5accce52018-05-22 16:05:42 +0100442 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
443 $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper)
444 $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT}))
445 $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT}))
446 $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT}))
Roberto Vargas5fee0282018-05-08 10:27:10 +0100447endef
448
449# MAKE_LIB macro defines the targets and options to build each BL image.
450# Arguments:
451# $(1) = Library name
452define MAKE_LIB
453 $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1))
454 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargas5accce52018-05-22 16:05:42 +0100455 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
Roberto Vargas5fee0282018-05-08 10:27:10 +0100456 $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS))
457 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
458
459$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
460$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
461
462.PHONY : lib${1}_dirs
Roberto Vargas5accce52018-05-22 16:05:42 +0100463lib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR}
Roberto Vargas5fee0282018-05-08 10:27:10 +0100464libraries: ${LIB_DIR}/lib$(1).a
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800465ifneq ($(findstring armlink,$(notdir $(LD))),)
466LDPATHS = --userlibpath=${LIB_DIR}
467LDLIBS += --library=$(1)
468else
Roberto Vargas5fee0282018-05-08 10:27:10 +0100469LDPATHS = -L${LIB_DIR}
470LDLIBS += -l$(1)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800471endif
Roberto Vargas5fee0282018-05-08 10:27:10 +0100472
Roberto Vargas5accce52018-05-22 16:05:42 +0100473ifeq ($(USE_ROMLIB),1)
Sathees Balya6baf85b2018-10-18 19:14:21 +0100474LIBWRAPPER = -lwrappers
Roberto Vargas5accce52018-05-22 16:05:42 +0100475endif
476
Roberto Vargas5fee0282018-05-08 10:27:10 +0100477all: ${LIB_DIR}/lib$(1).a
478
479${LIB_DIR}/lib$(1).a: $(OBJS)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100480 $$(ECHO) " AR $$@"
Roberto Vargas5fee0282018-05-08 10:27:10 +0100481 $$(Q)$$(AR) cr $$@ $$?
482endef
483
Juan Castillo73c99d42015-08-18 14:23:04 +0100484# MAKE_BL macro defines the targets and options to build each BL image.
485# Arguments:
Zelalem Aweke434d0492021-07-11 17:25:48 -0500486# $(1) = BL stage
Juan Castillo8f0617e2016-01-05 11:55:36 +0000487# $(2) = FIP command line option (if empty, image will not be included in the FIP)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900488# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530489# $(4) = BL encryption flag (optional) (0, 1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100490define MAKE_BL
Zelalem Aweke434d0492021-07-11 17:25:48 -0500491 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
492 $(eval BL_SOURCES := $($(call uppercase,$(1))_SOURCES))
Yatharth Kochar5ba8f662015-10-02 13:58:52 +0100493 $(eval SOURCES := $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))
Juan Castillo73c99d42015-08-18 14:23:04 +0100494 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
495 $(eval LINKERFILE := $(call IMG_LINKERFILE,$(1)))
496 $(eval MAPFILE := $(call IMG_MAPFILE,$(1)))
497 $(eval ELF := $(call IMG_ELF,$(1)))
498 $(eval DUMP := $(call IMG_DUMP,$(1)))
499 $(eval BIN := $(call IMG_BIN,$(1)))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530500 $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500501 $(eval BL_LINKERFILE := $($(call uppercase,$(1))_LINKERFILE))
502 $(eval BL_LIBS := $($(call uppercase,$(1))_LIBS))
Evan Lloyd51b27702015-12-03 12:19:30 +0000503 # We use sort only to get a list of unique object directory names.
504 # ordering is not relevant but sort removes duplicates.
Evan Lloyd6ba7d272017-04-07 16:58:57 +0100505 $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${LINKERFILE})))
Evan Lloyd51b27702015-12-03 12:19:30 +0000506 # The $(dir ) function leaves a trailing / on the directory names
Masahiro Yamadad014ea62017-01-19 19:31:00 +0900507 # Rip off the / to match directory names with make rule targets.
508 $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100509
Evan Lloyd51b27702015-12-03 12:19:30 +0000510# Create generators for object directory structure
Juan Castillo73c99d42015-08-18 14:23:04 +0100511
Masahiro Yamada8012cc52017-11-04 03:12:28 +0900512$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
Evan Lloyd6ba7d272017-04-07 16:58:57 +0100513
514$(eval $(foreach objd,${OBJ_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
Juan Castillo73c99d42015-08-18 14:23:04 +0100515
Zelalem Aweke434d0492021-07-11 17:25:48 -0500516.PHONY : ${1}_dirs
Evan Lloyd51b27702015-12-03 12:19:30 +0000517
518# We use order-only prerequisites to ensure that directories are created,
519# but do not cause re-builds every time a file is written.
Zelalem Aweke434d0492021-07-11 17:25:48 -0500520${1}_dirs: | ${OBJ_DIRS}
Evan Lloyd51b27702015-12-03 12:19:30 +0000521
522$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
Masahiro Yamadaa6ca7882017-01-12 10:48:22 +0900523$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500524$(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS))
Evan Lloyd51b27702015-12-03 12:19:30 +0000525
Roberto Vargas5accce52018-05-22 16:05:42 +0100526ifeq ($(USE_ROMLIB),1)
527$(ELF): romlib.bin
528endif
529
Leon Chen8dccddc2022-03-23 18:51:48 +0800530# MODULE_OBJS can be assigned by vendors with different compiled
531# object file path, and prebuilt object file path.
532$(eval OBJS += $(MODULE_OBJS))
533
Zelalem Aweke434d0492021-07-11 17:25:48 -0500534$(ELF): $(OBJS) $(LINKERFILE) | $(1)_dirs libraries $(BL_LIBS)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100535 $$(ECHO) " LD $$@"
Evan Lloyd414ab852015-12-03 12:58:52 +0000536ifdef MAKE_BUILD_STRINGS
537 $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o)
538else
Patrick Georgi2f5d4a42016-01-28 14:46:18 +0100539 @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \
laurenw-armdddf4282022-07-12 10:12:05 -0500540 const char version_string[] = "${VERSION_STRING}"; \
541 const char version[] = "${VERSION}";' | \
Masahiro Yamadaf2e1d572016-12-22 12:39:55 +0900542 $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o
Evan Lloyd414ab852015-12-03 12:58:52 +0000543endif
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800544ifneq ($(findstring armlink,$(notdir $(LD))),)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500545 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800546 --predefine="-D__LINKER__=$(__LINKER__)" \
547 --predefine="-DTF_CFLAGS=$(TF_CFLAGS)" \
Zelalem Aweke434d0492021-07-11 17:25:48 -0500548 --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800549 $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) \
550 $(BUILD_DIR)/build_message.o $(OBJS)
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600551else ifneq ($(findstring gcc,$(notdir $(LD))),)
552 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Wl,-Map=$(MAPFILE) \
Leon Chen8dccddc2022-03-23 18:51:48 +0800553 -Wl,-dT $(LINKERFILE) $(EXTRA_LINKERFILE) $(BUILD_DIR)/build_message.o \
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600554 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800555else
Masahiro Yamadad986bae2020-01-17 13:44:20 +0900556 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
Roberto Vargas5fee0282018-05-08 10:27:10 +0100557 --script $(LINKERFILE) $(BUILD_DIR)/build_message.o \
Sathees Balya6baf85b2018-10-18 19:14:21 +0100558 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800559endif
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200560ifeq ($(DISABLE_BIN_GENERATION),1)
561 @${ECHO_BLANK_LINE}
562 @echo "Built $$@ successfully"
563 @${ECHO_BLANK_LINE}
564endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100565
566$(DUMP): $(ELF)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100567 $${ECHO} " OD $$@"
Juan Castillo73c99d42015-08-18 14:23:04 +0100568 $${Q}$${OD} -dx $$< > $$@
569
570$(BIN): $(ELF)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100571 $${ECHO} " BIN $$@"
Juan Castillo73c99d42015-08-18 14:23:04 +0100572 $$(Q)$$(OC) -O binary $$< $$@
Evan Lloyd052ab522017-04-11 16:52:00 +0100573 @${ECHO_BLANK_LINE}
Juan Castillo73c99d42015-08-18 14:23:04 +0100574 @echo "Built $$@ successfully"
Evan Lloyd052ab522017-04-11 16:52:00 +0100575 @${ECHO_BLANK_LINE}
Juan Castillo73c99d42015-08-18 14:23:04 +0100576
Zelalem Aweke434d0492021-07-11 17:25:48 -0500577.PHONY: $(1)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200578ifeq ($(DISABLE_BIN_GENERATION),1)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500579$(1): $(ELF) $(DUMP)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200580else
Zelalem Aweke434d0492021-07-11 17:25:48 -0500581$(1): $(BIN) $(DUMP)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200582endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100583
Zelalem Aweke434d0492021-07-11 17:25:48 -0500584all: $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100585
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530586ifeq ($(4),1)
587$(call ENCRYPT_FW,$(BIN),$(ENC_BIN))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500588$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(ENC_BIN),$(3), \
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530589 $(ENC_BIN)))
590else
Zelalem Aweke434d0492021-07-11 17:25:48 -0500591$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(BIN),$(3)))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530592endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100593
594endef
595
Soby Mathew38c14d82017-12-14 17:44:56 +0000596# Convert device tree source file names to matching blobs
597# $(1) = input dts
Nishanth Menon03b397a2016-10-14 01:13:57 +0000598define SOURCES_TO_DTBS
599 $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1))))
600endef
601
Soby Mathew38c14d82017-12-14 17:44:56 +0000602# MAKE_FDT_DIRS macro creates the prerequisite directories that host the
603# FDT binaries
604# $(1) = output directory
605# $(2) = input dts
606define MAKE_FDT_DIRS
607 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000608 $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS})))
609 # The $(dir ) function leaves a trailing / on the directory names
610 # Rip off the / to match directory names with make rule targets.
611 $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS)))
612
613$(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
614
615fdt_dirs: ${DTB_DIRS}
Nishanth Menon03b397a2016-10-14 01:13:57 +0000616endef
617
Soby Mathew38c14d82017-12-14 17:44:56 +0000618# MAKE_DTB generate the Flattened device tree binary
Nishanth Menon03b397a2016-10-14 01:13:57 +0000619# $(1) = output directory
620# $(2) = input dts
621define MAKE_DTB
622
Yann Gautier077b3e92018-09-04 10:44:00 +0200623# List of DTB file(s) to generate, based on DTS file basename list
Soby Mathew38c14d82017-12-14 17:44:56 +0000624$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Yann Gautier077b3e92018-09-04 10:44:00 +0200625# List of the pre-compiled DTS file(s)
Yann Gautier01d237c2018-06-18 16:00:23 +0200626$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2)))))
Yann Gautier077b3e92018-09-04 10:44:00 +0200627# Dependencies of the pre-compiled DTS file(s) on its source and included files
628$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ)))
629# Dependencies of the DT compilation on its pre-compiled DTS
630$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ)))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000631
Stephen Warren6bc1a302018-02-21 17:13:50 -0700632$(DOBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100633 $${ECHO} " CPP $$<"
Yann Gautier077b3e92018-09-04 10:44:00 +0200634 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Manish Pandey7e94a692019-01-21 14:50:10 +0000635 $$(Q)$$(PP) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$<
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100636 $${ECHO} " DTC $$<"
Balint Dobszay2d51b552020-01-10 17:16:27 +0100637 $$(Q)$$(DTC) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $(DPRE)
Nishanth Menon03b397a2016-10-14 01:13:57 +0000638
Yann Gautier077b3e92018-09-04 10:44:00 +0200639-include $(DTBDEP)
640-include $(DTSDEP)
Nishanth Menon03b397a2016-10-14 01:13:57 +0000641
642endef
643
644# MAKE_DTBS builds flattened device tree sources
645# $(1) = output directory
646# $(2) = list of flattened device tree source files
647define MAKE_DTBS
648 $(eval DOBJS := $(filter %.dts,$(2)))
649 $(eval REMAIN := $(filter-out %.dts,$(2)))
Soby Mathew38c14d82017-12-14 17:44:56 +0000650 $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN)))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000651 $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj))))
652
Soby Mathew38c14d82017-12-14 17:44:56 +0000653 $(eval $(call MAKE_FDT_DIRS,$(1),$(2)))
654
655dtbs: $(DTBS)
656all: dtbs
Nishanth Menon03b397a2016-10-14 01:13:57 +0000657endef