blob: cb204a824ad7667d3cfe1bf5d7da44edaa778727 [file] [log] [blame]
Juan Castillo73c99d42015-08-18 14:23:04 +01001#
Chris Kay82274932023-01-16 16:53:45 +00002# Copyright (c) 2015-2023, 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}
Chris Kaya6ff0062023-01-16 18:57:26 +000016comma := ,
Evan Lloyd231c1472015-12-02 18:17:37 +000017
18# A user defined function to recursively search for a filename below a directory
19# $1 is the directory root of the recursive search (blank for current directory).
20# $2 is the file name to search for.
21define rwildcard
22$(strip $(foreach d,$(wildcard ${1}*),$(call rwildcard,${d}/,${2}) $(filter $(subst *,%,%${2}),${d})))
23endef
24
Yatharth Kochar5ba8f662015-10-02 13:58:52 +010025# This table is used in converting lower case to upper case.
26uppercase_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
27
28# Internal macro used for converting lower case to upper case.
29# $(1) = upper case table
30# $(2) = String to convert
31define uppercase_internal
32$(if $(1),$$(subst $(firstword $(1)),$(call uppercase_internal,$(wordlist 2,$(words $(1)),$(1)),$(2))),$(2))
33endef
34
35# A macro for converting a string to upper case
36# $(1) = String to convert
37define uppercase
38$(eval uppercase_result:=$(call uppercase_internal,$(uppercase_table),$(1)))$(uppercase_result)
39endef
40
Boyan Karatoteve4447632022-11-17 12:01:29 +000041# Convenience function for setting a variable to 0 if not previously set
42# $(eval $(call default_zero,FOO))
43define default_zero
44 $(eval $(1) ?= 0)
45endef
46
47# Convenience function for setting a list of variables to 0 if not previously set
48# $(eval $(call default_zeros,FOO BAR))
49define default_zeros
50 $(foreach var,$1,$(eval $(call default_zero,$(var))))
51endef
52
Juan Castillo73c99d42015-08-18 14:23:04 +010053# Convenience function for adding build definitions
54# $(eval $(call add_define,FOO)) will have:
55# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
56define add_define
57 DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),)
58endef
59
Leonardo Sandoval327131c2020-09-10 12:18:27 -050060# Convenience function for addding multiple build definitions
61# $(eval $(call add_defines,FOO BOO))
62define add_defines
63 $(foreach def,$1,$(eval $(call add_define,$(def))))
64endef
65
Soren Brinkmann8eadeb42016-06-09 13:36:27 -070066# Convenience function for adding build definitions
67# $(eval $(call add_define_val,FOO,BAR)) will have:
68# -DFOO=BAR
69define add_define_val
70 DEFINES += -D$(1)=$(2)
71endef
72
Juan Castillo73c99d42015-08-18 14:23:04 +010073# Convenience function for verifying option has a boolean value
74# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
75define assert_boolean
Yann Gautier1369fb82023-04-24 13:38:12 +020076 $(if $($(1)),,$(error $(1) must not be empty))
Masahiro Yamadabe4cd402017-05-23 23:45:01 +090077 $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean))
Juan Castillo73c99d42015-08-18 14:23:04 +010078endef
79
Leonardo Sandoval327131c2020-09-10 12:18:27 -050080# Convenience function for verifying options have boolean values
81# $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values
82define assert_booleans
83 $(foreach bool,$1,$(eval $(call assert_boolean,$(bool))))
84endef
85
Jeenu Viswambharanc877b412017-01-16 16:52:35 +0000860-9 := 0 1 2 3 4 5 6 7 8 9
87
88# Function to verify that a given option $(1) contains a numeric value
89define assert_numeric
90$(if $($(1)),,$(error $(1) must not be empty))
91$(eval __numeric := $($(1)))
92$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric))))
93$(if $(__numeric),$(error $(1) must be numeric))
94endef
95
Leonardo Sandoval327131c2020-09-10 12:18:27 -050096# Convenience function for verifying options have numeric values
97# $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values
98define assert_numerics
99 $(foreach num,$1,$(eval $(call assert_numeric,$(num))))
100endef
101
Marco Felscha5f09cf2022-11-24 11:02:05 +0100102# Convenience function to check for a given linker option. An call to
103# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker
104define ld_option
105 $(shell if $(LD) $(1) -v >/dev/null 2>&1; then echo $(1); fi )
106endef
107
Vijayenthiran Subramaniam8c7b9442020-02-08 21:27:30 +0530108# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to
109# $(2) and assign the sequence to $(1)
110define CREATE_SEQ
111$(if $(word $(2), $($(1))),\
112 $(eval $(1) += $(words $($(1))))\
113 $(eval $(1) := $(filter-out 0,$($(1)))),\
114 $(eval $(1) += $(words $($(1))))\
115 $(call CREATE_SEQ,$(1),$(2))\
116)
117endef
118
Juan Castillo73c99d42015-08-18 14:23:04 +0100119# IMG_MAPFILE defines the output file describing the memory map corresponding
120# to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500121# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100122define IMG_MAPFILE
Zelalem Aweke434d0492021-07-11 17:25:48 -0500123 ${BUILD_DIR}/$(1).map
Juan Castillo73c99d42015-08-18 14:23:04 +0100124endef
125
126# IMG_ELF defines the elf file corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500127# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100128define IMG_ELF
Zelalem Aweke434d0492021-07-11 17:25:48 -0500129 ${BUILD_DIR}/$(1).elf
Juan Castillo73c99d42015-08-18 14:23:04 +0100130endef
131
132# IMG_DUMP defines the symbols dump file corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500133# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100134define IMG_DUMP
Zelalem Aweke434d0492021-07-11 17:25:48 -0500135 ${BUILD_DIR}/$(1).dump
Juan Castillo73c99d42015-08-18 14:23:04 +0100136endef
137
138# IMG_BIN defines the default image file corresponding to a BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500139# $(1) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100140define IMG_BIN
Zelalem Aweke434d0492021-07-11 17:25:48 -0500141 ${BUILD_PLAT}/$(1).bin
Juan Castillo73c99d42015-08-18 14:23:04 +0100142endef
143
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530144# IMG_ENC_BIN defines the default encrypted image file corresponding to a
145# BL stage
Zelalem Aweke434d0492021-07-11 17:25:48 -0500146# $(1) = BL stage
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530147define IMG_ENC_BIN
Zelalem Aweke434d0492021-07-11 17:25:48 -0500148 ${BUILD_PLAT}/$(1)_enc.bin
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530149endef
150
151# ENCRYPT_FW invokes enctool to encrypt firmware binary
152# $(1) = input firmware binary
153# $(2) = output encrypted firmware binary
154define ENCRYPT_FW
155$(2): $(1) enctool
156 $$(ECHO) " ENC $$<"
157 $$(Q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@
158endef
159
Masahiro Yamada10cea932018-01-26 11:42:01 +0900160# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to
161# package a new payload and/or by cert_create to generate certificate.
162# Optionally, it adds the dependency on this payload
Juan Castillo73c99d42015-08-18 14:23:04 +0100163# $(1) = payload filename (i.e. bl31.bin)
Masahiro Yamada1e0c0782017-12-23 23:56:18 +0900164# $(2) = command line option for the specified payload (i.e. --soc-fw)
Masahiro Yamada36af3452018-01-26 11:42:01 +0900165# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900166# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530167# $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin)
Masahiro Yamada10cea932018-01-26 11:42:01 +0900168define TOOL_ADD_PAYLOAD
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530169ifneq ($(5),)
170 $(4)FIP_ARGS += $(2) $(5)
171 $(if $(3),$(4)CRT_DEPS += $(1))
172else
Masahiro Yamada945b3162018-01-26 11:42:01 +0900173 $(4)FIP_ARGS += $(2) $(1)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530174 $(if $(3),$(4)CRT_DEPS += $(3))
175endif
Masahiro Yamada945b3162018-01-26 11:42:01 +0900176 $(if $(3),$(4)FIP_DEPS += $(3))
Masahiro Yamadaf30ee0b2018-01-26 11:42:01 +0900177 $(4)CRT_ARGS += $(2) $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100178endef
179
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900180# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters
181# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined.
182# $(1) = image_type (scp_bl2, bl33, etc.)
183# $(2) = payload filepath (ex. build/fvp/release/bl31.bin)
184# $(3) = command line option for the specified payload (ex. --soc-fw)
185# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin)
186# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530187# $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin)
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900188
189define TOOL_ADD_IMG_PAYLOAD
190
191$(eval PRE_TOOL_FILTER := $($(call uppercase,$(1))_PRE_TOOL_FILTER))
192
193ifneq ($(PRE_TOOL_FILTER),)
194
195$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX))
196
197$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2))
198
199$(PROCESSED_PATH): $(4)
200
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530201$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6))
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900202
203else
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530204$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6))
Masahiro Yamada2da522b2018-02-01 16:31:09 +0900205endif
206endef
207
Yatharth Kochar01912622015-10-12 12:33:47 +0100208# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation
Juan Castillo73c99d42015-08-18 14:23:04 +0100209# $(1) = parameter filename
210# $(2) = cert_create command line option for the specified parameter
Masahiro Yamada91704d92018-01-26 11:42:01 +0900211# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Juan Castillo73c99d42015-08-18 14:23:04 +0100212define CERT_ADD_CMD_OPT
Masahiro Yamada91704d92018-01-26 11:42:01 +0900213 $(3)CRT_ARGS += $(2) $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100214endef
215
Masahiro Yamadac939d132018-01-26 11:42:01 +0900216# TOOL_ADD_IMG allows the platform to specify an external image to be packed
217# in the FIP and/or for which certificate is generated. It also adds a
218# dependency on the image file, aborting the build if the file does not exist.
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900219# $(1) = image_type (scp_bl2, bl33, etc.)
Masahiro Yamada1e0c0782017-12-23 23:56:18 +0900220# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc)
Masahiro Yamada1dc07142018-01-26 11:42:01 +0900221# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530222# $(4) = Image encryption flag (optional) (0, 1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100223# Example:
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900224# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Masahiro Yamadac939d132018-01-26 11:42:01 +0900225define TOOL_ADD_IMG
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900226 # Build option to specify the image filename (SCP_BL2, BL33, etc)
227 # This is the uppercase form of the first parameter
228 $(eval _V := $(call uppercase,$(1)))
229
Pali Rohár4727fd12020-11-24 16:53:04 +0100230 # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also
231 # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the
232 # target ${BUILD_PLAT}/${$(3)FIP_NAME}.
233 $(eval check_$(1)_cmd := \
234 $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \
235 $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \
236 )
237
Masahiro Yamada945b3162018-01-26 11:42:01 +0900238 $(3)CRT_DEPS += check_$(1)
Pali Rohár4727fd12020-11-24 16:53:04 +0100239 CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd)
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530240ifeq ($(4),1)
241 $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin)
242 $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN))
243 $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(ENC_BIN),$(3), \
244 $(ENC_BIN))
245else
Pali Rohár4727fd12020-11-24 16:53:04 +0100246 $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530247endif
Yatharth Kochar01912622015-10-12 12:33:47 +0100248
Masahiro Yamada87ebd202017-12-24 13:08:00 +0900249.PHONY: check_$(1)
Yatharth Kochar01912622015-10-12 12:33:47 +0100250check_$(1):
Pali Rohár4727fd12020-11-24 16:53:04 +0100251 $(check_$(1)_cmd)
Yatharth Kochar01912622015-10-12 12:33:47 +0100252endef
Juan Castillo73c99d42015-08-18 14:23:04 +0100253
Juan Pablo Condecf2dd172022-10-25 19:41:02 -0400254# SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to
255# build the host tools by checking the version of OpenSSL located under
256# the path defined by the OPENSSL_DIR variable. It receives no parameters.
257define SELECT_OPENSSL_API_VERSION
258 # Set default value for USING_OPENSSL3 macro to 0
259 $(eval USING_OPENSSL3 = 0)
260 # Obtain the OpenSSL version for the build located under OPENSSL_DIR
261 $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version))
262 $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO}))
263 $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER))))
264 # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1
265 $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1))
266endef
267
Juan Castillo73c99d42015-08-18 14:23:04 +0100268################################################################################
Masahiro Yamada14db8902018-01-26 11:42:01 +0900269# Generic image processing filters
270################################################################################
271
272# GZIP
273define GZIP_RULE
274$(1): $(2)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100275 $(ECHO) " GZIP $$@"
Masahiro Yamada14db8902018-01-26 11:42:01 +0900276 $(Q)gzip -n -f -9 $$< --stdout > $$@
277endef
278
279GZIP_SUFFIX := .gz
280
281################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100282# Auxiliary macros to build TF images from sources
283################################################################################
284
Masahiro Yamada1d274ab2016-12-22 15:23:05 +0900285MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP
Juan Castillo73c99d42015-08-18 14:23:04 +0100286
Roberto Vargas5fee0282018-05-08 10:27:10 +0100287
288# MAKE_C_LIB builds a C source file and generates the dependency file
289# $(1) = output directory
290# $(2) = source file (%.c)
291# $(3) = library name
292define MAKE_C_LIB
293$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
294$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Govindraj Raja5a65fcd2023-01-27 10:08:54 +0000295$(eval LIB := $(call uppercase, $(notdir $(1))))
Roberto Vargas5fee0282018-05-08 10:27:10 +0100296
297$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100298 $$(ECHO) " CC $$<"
Govindraj Raja5a65fcd2023-01-27 10:08:54 +0000299 $$(Q)$$(CC) $$($(LIB)_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@
Roberto Vargas5fee0282018-05-08 10:27:10 +0100300
301-include $(DEP)
302
303endef
304
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000305# MAKE_S_LIB builds an assembly source file and generates the dependency file
306# $(1) = output directory
307# $(2) = source file (%.S)
308# $(3) = library name
309define MAKE_S_LIB
310$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
311$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
312
313$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
314 $$(ECHO) " AS $$<"
315 $$(Q)$$(AS) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
316
317-include $(DEP)
318
319endef
320
Roberto Vargas5fee0282018-05-08 10:27:10 +0100321
Juan Castillo73c99d42015-08-18 14:23:04 +0100322# MAKE_C builds a C source file and generates the dependency file
323# $(1) = output directory
324# $(2) = source file (%.c)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500325# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100326define MAKE_C
327
328$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900329$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500330$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
331$(eval BL_CFLAGS := $($(call uppercase,$(3))_CFLAGS))
Juan Castillo73c99d42015-08-18 14:23:04 +0100332
Zelalem Aweke434d0492021-07-11 17:25:48 -0500333$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100334 $$(ECHO) " CC $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900335 $$(Q)$$(CC) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castillo73c99d42015-08-18 14:23:04 +0100336
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900337-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100338
339endef
340
341
342# MAKE_S builds an assembly source file and generates the dependency file
343# $(1) = output directory
344# $(2) = assembly file (%.S)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500345# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100346define MAKE_S
347
348$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900349$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500350$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
351$(eval BL_ASFLAGS := $($(call uppercase,$(3))_ASFLAGS))
Juan Castillo73c99d42015-08-18 14:23:04 +0100352
Zelalem Aweke434d0492021-07-11 17:25:48 -0500353$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100354 $$(ECHO) " AS $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900355 $$(Q)$$(AS) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@
Juan Castillo73c99d42015-08-18 14:23:04 +0100356
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900357-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100358
359endef
360
361
362# MAKE_LD generate the linker script using the C preprocessor
363# $(1) = output linker script
364# $(2) = input template
Zelalem Aweke434d0492021-07-11 17:25:48 -0500365# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100366define MAKE_LD
367
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900368$(eval DEP := $(1).d)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500369$(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) -DIMAGE_$(call uppercase,$(3)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100370
Zelalem Aweke434d0492021-07-11 17:25:48 -0500371$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100372 $$(ECHO) " PP $$<"
Masahiro Yamada848a7e82020-03-25 16:55:28 +0900373 $$(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 +0100374
Masahiro Yamada710ea1d2016-12-22 14:02:27 +0900375-include $(DEP)
Juan Castillo73c99d42015-08-18 14:23:04 +0100376
377endef
378
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000379# MAKE_LIB_OBJS builds both C and assembly source files
Roberto Vargas5fee0282018-05-08 10:27:10 +0100380# $(1) = output directory
381# $(2) = list of source files
382# $(3) = name of the library
383define MAKE_LIB_OBJS
384 $(eval C_OBJS := $(filter %.c,$(2)))
385 $(eval REMAIN := $(filter-out %.c,$(2)))
386 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3))))
387
Antonio Nino Diaz70b0f272019-02-08 13:20:37 +0000388 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
389 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
390 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3))))
391
Roberto Vargas5fee0282018-05-08 10:27:10 +0100392 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
393endef
394
Juan Castillo73c99d42015-08-18 14:23:04 +0100395
396# MAKE_OBJS builds both C and assembly source files
397# $(1) = output directory
398# $(2) = list of source files (both C and assembly)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500399# $(3) = BL stage
Juan Castillo73c99d42015-08-18 14:23:04 +0100400define MAKE_OBJS
401 $(eval C_OBJS := $(filter %.c,$(2)))
402 $(eval REMAIN := $(filter-out %.c,$(2)))
403 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
404
405 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
406 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
407 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
408
409 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
410endef
411
412
413# NOTE: The line continuation '\' is required in the next define otherwise we
414# end up with a line-feed characer at the end of the last c filename.
Evan Lloyde7f54db2015-12-02 18:56:06 +0000415# Also bear this issue in mind if extending the list of supported filetypes.
Juan Castillo73c99d42015-08-18 14:23:04 +0100416define SOURCES_TO_OBJS
417 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
418 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
419endef
420
Patrick Georgi2f5d4a42016-01-28 14:46:18 +0100421# Allow overriding the timestamp, for example for reproducible builds, or to
422# synchronize timestamps across multiple projects.
423# This must be set to a C string (including quotes where applicable).
424BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
Juan Castillo73c99d42015-08-18 14:23:04 +0100425
Roberto Vargas5fee0282018-05-08 10:27:10 +0100426.PHONY: libraries
427
Roberto Vargas5accce52018-05-22 16:05:42 +0100428# MAKE_LIB_DIRS macro defines the target for the directory where
Roberto Vargas5fee0282018-05-08 10:27:10 +0100429# libraries are created
Roberto Vargas5accce52018-05-22 16:05:42 +0100430define MAKE_LIB_DIRS
Roberto Vargas5fee0282018-05-08 10:27:10 +0100431 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargas5accce52018-05-22 16:05:42 +0100432 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
433 $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper)
434 $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT}))
435 $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT}))
436 $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT}))
Roberto Vargas5fee0282018-05-08 10:27:10 +0100437endef
438
439# MAKE_LIB macro defines the targets and options to build each BL image.
440# Arguments:
441# $(1) = Library name
442define MAKE_LIB
443 $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1))
444 $(eval LIB_DIR := ${BUILD_PLAT}/lib)
Roberto Vargas5accce52018-05-22 16:05:42 +0100445 $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
Roberto Vargas5fee0282018-05-08 10:27:10 +0100446 $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS))
447 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
448
449$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
450$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
451
452.PHONY : lib${1}_dirs
Roberto Vargas5accce52018-05-22 16:05:42 +0100453lib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR}
Roberto Vargas5fee0282018-05-08 10:27:10 +0100454libraries: ${LIB_DIR}/lib$(1).a
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800455ifneq ($(findstring armlink,$(notdir $(LD))),)
456LDPATHS = --userlibpath=${LIB_DIR}
457LDLIBS += --library=$(1)
458else
Roberto Vargas5fee0282018-05-08 10:27:10 +0100459LDPATHS = -L${LIB_DIR}
460LDLIBS += -l$(1)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800461endif
Roberto Vargas5fee0282018-05-08 10:27:10 +0100462
Roberto Vargas5accce52018-05-22 16:05:42 +0100463ifeq ($(USE_ROMLIB),1)
Sathees Balya6baf85b2018-10-18 19:14:21 +0100464LIBWRAPPER = -lwrappers
Roberto Vargas5accce52018-05-22 16:05:42 +0100465endif
466
Roberto Vargas5fee0282018-05-08 10:27:10 +0100467all: ${LIB_DIR}/lib$(1).a
468
469${LIB_DIR}/lib$(1).a: $(OBJS)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100470 $$(ECHO) " AR $$@"
Roberto Vargas5fee0282018-05-08 10:27:10 +0100471 $$(Q)$$(AR) cr $$@ $$?
472endef
473
Chris Kay82274932023-01-16 16:53:45 +0000474# Generate the path to one or more preprocessed linker scripts given the paths
475# of their sources.
476#
477# Arguments:
478# $(1) = path to one or more linker script sources
479define linker_script_path
480 $(patsubst %.S,$(BUILD_DIR)/%,$(1))
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))))
Juan Castillo73c99d42015-08-18 14:23:04 +0100494 $(eval MAPFILE := $(call IMG_MAPFILE,$(1)))
495 $(eval ELF := $(call IMG_ELF,$(1)))
496 $(eval DUMP := $(call IMG_DUMP,$(1)))
497 $(eval BIN := $(call IMG_BIN,$(1)))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530498 $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1)))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500499 $(eval BL_LIBS := $($(call uppercase,$(1))_LIBS))
Chris Kay82274932023-01-16 16:53:45 +0000500
501 $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(call uppercase,$(1))_DEFAULT_LINKER_SCRIPT_SOURCE))
502 $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE)))
503
Chris Kaya6ff0062023-01-16 18:57:26 +0000504 $(eval LINKER_SCRIPT_SOURCES := $($(call uppercase,$(1))_LINKER_SCRIPT_SOURCES))
505 $(eval LINKER_SCRIPTS := $(call linker_script_path,$(LINKER_SCRIPT_SOURCES)))
506
Evan Lloyd51b27702015-12-03 12:19:30 +0000507 # We use sort only to get a list of unique object directory names.
508 # ordering is not relevant but sort removes duplicates.
Chris Kaya6ff0062023-01-16 18:57:26 +0000509 $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${DEFAULT_LINKER_SCRIPT} ${LINKER_SCRIPTS})))
Evan Lloyd51b27702015-12-03 12:19:30 +0000510 # The $(dir ) function leaves a trailing / on the directory names
Masahiro Yamadad014ea62017-01-19 19:31:00 +0900511 # Rip off the / to match directory names with make rule targets.
512 $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100513
Evan Lloyd51b27702015-12-03 12:19:30 +0000514# Create generators for object directory structure
Juan Castillo73c99d42015-08-18 14:23:04 +0100515
Masahiro Yamada8012cc52017-11-04 03:12:28 +0900516$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
Evan Lloyd6ba7d272017-04-07 16:58:57 +0100517
Chris Kay82274932023-01-16 16:53:45 +0000518$(eval $(foreach objd,${OBJ_DIRS},
519 $(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
Juan Castillo73c99d42015-08-18 14:23:04 +0100520
Zelalem Aweke434d0492021-07-11 17:25:48 -0500521.PHONY : ${1}_dirs
Evan Lloyd51b27702015-12-03 12:19:30 +0000522
523# We use order-only prerequisites to ensure that directories are created,
524# but do not cause re-builds every time a file is written.
Zelalem Aweke434d0492021-07-11 17:25:48 -0500525${1}_dirs: | ${OBJ_DIRS}
Evan Lloyd51b27702015-12-03 12:19:30 +0000526
527$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
Chris Kaya6ff0062023-01-16 18:57:26 +0000528
529# Generate targets to preprocess each required linker script
530$(eval $(foreach source,$(DEFAULT_LINKER_SCRIPT_SOURCE) $(LINKER_SCRIPT_SOURCES), \
531 $(call MAKE_LD,$(call linker_script_path,$(source)),$(source),$(1))))
532
Zelalem Aweke434d0492021-07-11 17:25:48 -0500533$(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS))
Evan Lloyd51b27702015-12-03 12:19:30 +0000534
Roberto Vargas5accce52018-05-22 16:05:42 +0100535ifeq ($(USE_ROMLIB),1)
536$(ELF): romlib.bin
537endif
538
Leon Chen8dccddc2022-03-23 18:51:48 +0800539# MODULE_OBJS can be assigned by vendors with different compiled
540# object file path, and prebuilt object file path.
541$(eval OBJS += $(MODULE_OBJS))
542
Chris Kaya6ff0062023-01-16 18:57:26 +0000543$(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) $(LINKER_SCRIPTS) | $(1)_dirs libraries $(BL_LIBS)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100544 $$(ECHO) " LD $$@"
Evan Lloyd414ab852015-12-03 12:58:52 +0000545ifdef MAKE_BUILD_STRINGS
546 $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o)
547else
Patrick Georgi2f5d4a42016-01-28 14:46:18 +0100548 @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \
laurenw-armdddf4282022-07-12 10:12:05 -0500549 const char version_string[] = "${VERSION_STRING}"; \
550 const char version[] = "${VERSION}";' | \
Masahiro Yamadaf2e1d572016-12-22 12:39:55 +0900551 $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o
Evan Lloyd414ab852015-12-03 12:58:52 +0000552endif
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800553ifneq ($(findstring armlink,$(notdir $(LD))),)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500554 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800555 --predefine="-D__LINKER__=$(__LINKER__)" \
556 --predefine="-DTF_CFLAGS=$(TF_CFLAGS)" \
Zelalem Aweke434d0492021-07-11 17:25:48 -0500557 --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800558 $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) \
559 $(BUILD_DIR)/build_message.o $(OBJS)
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600560else ifneq ($(findstring gcc,$(notdir $(LD))),)
561 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Wl,-Map=$(MAPFILE) \
Chris Kaya6ff0062023-01-16 18:57:26 +0000562 $(addprefix -Wl$(comma)--script$(comma),$(LINKER_SCRIPTS)) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) \
563 $(BUILD_DIR)/build_message.o \
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600564 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800565else
Masahiro Yamadad986bae2020-01-17 13:44:20 +0900566 $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \
Chris Kaya6ff0062023-01-16 18:57:26 +0000567 $(addprefix -T ,$(LINKER_SCRIPTS)) --script $(DEFAULT_LINKER_SCRIPT) \
568 $(BUILD_DIR)/build_message.o \
Sathees Balya6baf85b2018-10-18 19:14:21 +0100569 $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800570endif
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200571ifeq ($(DISABLE_BIN_GENERATION),1)
572 @${ECHO_BLANK_LINE}
573 @echo "Built $$@ successfully"
574 @${ECHO_BLANK_LINE}
575endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100576
577$(DUMP): $(ELF)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100578 $${ECHO} " OD $$@"
Juan Castillo73c99d42015-08-18 14:23:04 +0100579 $${Q}$${OD} -dx $$< > $$@
580
581$(BIN): $(ELF)
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100582 $${ECHO} " BIN $$@"
Juan Castillo73c99d42015-08-18 14:23:04 +0100583 $$(Q)$$(OC) -O binary $$< $$@
Evan Lloyd052ab522017-04-11 16:52:00 +0100584 @${ECHO_BLANK_LINE}
Juan Castillo73c99d42015-08-18 14:23:04 +0100585 @echo "Built $$@ successfully"
Evan Lloyd052ab522017-04-11 16:52:00 +0100586 @${ECHO_BLANK_LINE}
Juan Castillo73c99d42015-08-18 14:23:04 +0100587
Zelalem Aweke434d0492021-07-11 17:25:48 -0500588.PHONY: $(1)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200589ifeq ($(DISABLE_BIN_GENERATION),1)
Zelalem Aweke434d0492021-07-11 17:25:48 -0500590$(1): $(ELF) $(DUMP)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200591else
Zelalem Aweke434d0492021-07-11 17:25:48 -0500592$(1): $(BIN) $(DUMP)
Christoph Müllner9e4609f2019-04-24 09:45:30 +0200593endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100594
Zelalem Aweke434d0492021-07-11 17:25:48 -0500595all: $(1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100596
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530597ifeq ($(4),1)
598$(call ENCRYPT_FW,$(BIN),$(ENC_BIN))
Zelalem Aweke434d0492021-07-11 17:25:48 -0500599$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(ENC_BIN),$(3), \
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530600 $(ENC_BIN)))
601else
Zelalem Aweke434d0492021-07-11 17:25:48 -0500602$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(BIN),$(3)))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530603endif
Juan Castillo73c99d42015-08-18 14:23:04 +0100604
605endef
606
Soby Mathew38c14d82017-12-14 17:44:56 +0000607# Convert device tree source file names to matching blobs
608# $(1) = input dts
Nishanth Menon03b397a2016-10-14 01:13:57 +0000609define SOURCES_TO_DTBS
610 $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1))))
611endef
612
Soby Mathew38c14d82017-12-14 17:44:56 +0000613# MAKE_FDT_DIRS macro creates the prerequisite directories that host the
614# FDT binaries
615# $(1) = output directory
616# $(2) = input dts
617define MAKE_FDT_DIRS
618 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000619 $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS})))
620 # The $(dir ) function leaves a trailing / on the directory names
621 # Rip off the / to match directory names with make rule targets.
622 $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS)))
623
624$(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
625
626fdt_dirs: ${DTB_DIRS}
Nishanth Menon03b397a2016-10-14 01:13:57 +0000627endef
628
Soby Mathew38c14d82017-12-14 17:44:56 +0000629# MAKE_DTB generate the Flattened device tree binary
Nishanth Menon03b397a2016-10-14 01:13:57 +0000630# $(1) = output directory
631# $(2) = input dts
632define MAKE_DTB
633
Yann Gautier077b3e92018-09-04 10:44:00 +0200634# List of DTB file(s) to generate, based on DTS file basename list
Soby Mathew38c14d82017-12-14 17:44:56 +0000635$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Yann Gautier077b3e92018-09-04 10:44:00 +0200636# List of the pre-compiled DTS file(s)
Yann Gautier01d237c2018-06-18 16:00:23 +0200637$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2)))))
Yann Gautier077b3e92018-09-04 10:44:00 +0200638# Dependencies of the pre-compiled DTS file(s) on its source and included files
639$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ)))
640# Dependencies of the DT compilation on its pre-compiled DTS
641$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ)))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000642
Stephen Warren6bc1a302018-02-21 17:13:50 -0700643$(DOBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100644 $${ECHO} " CPP $$<"
Yann Gautier077b3e92018-09-04 10:44:00 +0200645 $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2))))
Manish Pandey7e94a692019-01-21 14:50:10 +0000646 $$(Q)$$(PP) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$<
Andre Przywaraee1ba6d2018-09-27 10:56:05 +0100647 $${ECHO} " DTC $$<"
Balint Dobszay2d51b552020-01-10 17:16:27 +0100648 $$(Q)$$(DTC) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $(DPRE)
Nishanth Menon03b397a2016-10-14 01:13:57 +0000649
Yann Gautier077b3e92018-09-04 10:44:00 +0200650-include $(DTBDEP)
651-include $(DTSDEP)
Nishanth Menon03b397a2016-10-14 01:13:57 +0000652
653endef
654
655# MAKE_DTBS builds flattened device tree sources
656# $(1) = output directory
657# $(2) = list of flattened device tree source files
658define MAKE_DTBS
659 $(eval DOBJS := $(filter %.dts,$(2)))
660 $(eval REMAIN := $(filter-out %.dts,$(2)))
Soby Mathew38c14d82017-12-14 17:44:56 +0000661 $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN)))
Nishanth Menon03b397a2016-10-14 01:13:57 +0000662 $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj))))
663
Soby Mathew38c14d82017-12-14 17:44:56 +0000664 $(eval $(call MAKE_FDT_DIRS,$(1),$(2)))
665
666dtbs: $(DTBS)
667all: dtbs
Nishanth Menon03b397a2016-10-14 01:13:57 +0000668endef