blob: b147b030567639630da55334f37ce67ce1b5fdac [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001#
Chris Kayc3273702025-01-13 15:57:32 +00002# Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003#
dp-arm82cb2c12017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005#
6
Jeenu Viswambharane35c4042014-05-15 14:40:58 +01007#
Juan Castilloaaa3e722014-06-30 11:41:46 +01008# Trusted Firmware Version
9#
Soby Mathew1a0f1122018-10-01 16:16:34 +010010VERSION_MAJOR := 2
Govindraj Raja97a6de92025-05-07 13:51:45 -050011VERSION_MINOR := 13
Yann Gautierc25d1cc2024-02-08 18:40:27 +010012# VERSION_PATCH is only used for LTS releases
13VERSION_PATCH := 0
Yann Gautier055ebec2023-10-03 11:09:07 +020014VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
Juan Castilloaaa3e722014-06-30 11:41:46 +010015
Juan Castillo88154672015-10-22 11:34:44 +010016# Default goal is build all images
17.DEFAULT_GOAL := all
18
Douglas Raillard72fc70e2016-12-28 14:47:50 +000019# Avoid any implicit propagation of command line variable definitions to
20# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
21# usage. Other command line options like "-s" are still propagated as usual.
22MAKEOVERRIDES =
23
Evan Lloyd231c1472015-12-02 18:17:37 +000024MAKE_HELPERS_DIRECTORY := make_helpers/
25include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
Chris Kayf4dd18c2024-06-04 00:04:48 +000026include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
Chris Kay7c4e1ee2024-05-02 17:52:37 +000027include ${MAKE_HELPERS_DIRECTORY}common.mk
Juan Castillo73c99d42015-08-18 14:23:04 +010028
29################################################################################
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010030# Default values for build configurations, and their dependencies
Juan Castillo73c99d42015-08-18 14:23:04 +010031################################################################################
Jeenu Viswambharane35c4042014-05-15 14:40:58 +010032
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010033include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Yann Gautier422b1812025-01-17 11:02:50 +010034PLAT := ${DEFAULT_PLAT}
Andrey Skvortsov1b2fb6a2024-02-18 11:43:12 +030035include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
36
37# To be able to set platform specific defaults
38ifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
39include ${PLAT_DEFAULTS_MAKEFILE_FULL}
40endif
dp-arm872be882016-09-19 11:18:44 +010041
Chris Kaycc277de2023-10-20 09:17:33 +000042################################################################################
43# Configure the toolchains used to build TF-A and its tools
44################################################################################
45
46include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
47
Antonio Nino Diazcc8b5632017-04-18 15:16:05 +010048# Assertions enabled for DEBUG builds by default
Antonio Nino Diazcc8b5632017-04-18 15:16:05 +010049ENABLE_ASSERTIONS := ${DEBUG}
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010050ENABLE_PMF := ${ENABLE_RUNTIME_INSTRUMENTATION}
Juan Castillo73c99d42015-08-18 14:23:04 +010051
52################################################################################
53# Checkpatch script options
54################################################################################
55
Sandrine Bailleuxf6077392016-06-02 11:19:59 +010056CHECKCODE_ARGS := --no-patch
Dan Handleyf0b489c2016-06-02 17:15:13 +010057# Do not check the coding style on imported library files or documentation files
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030058INC_DRV_DIRS_TO_CHECK := $(sort $(filter-out \
59 include/drivers/arm, \
60 $(wildcard include/drivers/*)))
Dan Handleyf0b489c2016-06-02 17:15:13 +010061INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Dan Handley1a41e8c2016-06-02 18:21:02 +010062 include/lib/libfdt \
Roberto Vargas61f72a32018-05-08 10:27:10 +010063 include/lib/libc, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010064 $(wildcard include/lib/*)))
65INC_DIRS_TO_CHECK := $(sort $(filter-out \
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030066 include/lib \
67 include/drivers, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010068 $(wildcard include/*)))
69LIB_DIRS_TO_CHECK := $(sort $(filter-out \
dp-armd801fbb2017-05-04 12:15:35 +010070 lib/compiler-rt \
Antonio Nino Diaz55cdcf72017-01-16 17:20:45 +000071 lib/libfdt% \
Roberto Vargas61f72a32018-05-08 10:27:10 +010072 lib/libc, \
Daniel Boulbya1942552022-10-05 11:05:22 +010073 lib/zlib \
Dan Handleyf0b489c2016-06-02 17:15:13 +010074 $(wildcard lib/*)))
75ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
76 lib \
77 include \
78 docs \
Paul Beesley1ef35512019-03-07 16:42:31 +000079 %.rst, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010080 $(wildcard *)))
81CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
82 ${INC_DIRS_TO_CHECK} \
83 ${INC_LIB_DIRS_TO_CHECK} \
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030084 ${LIB_DIRS_TO_CHECK} \
85 ${INC_DRV_DIRS_TO_CHECK} \
86 ${INC_ARM_DIRS_TO_CHECK}
Ian Spray36eaaf32014-01-30 17:25:28 +000087
Juan Castillo73c99d42015-08-18 14:23:04 +010088################################################################################
89# Process build options
90################################################################################
91
Chris Kay7c4e1ee2024-05-02 17:52:37 +000092ifeq ($(verbose),)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +010093 CHECKCODE_ARGS += --no-summary --terse
Achin Gupta4f6ad662013-10-25 09:08:21 +010094endif
Andre Przywaraee1ba6d2018-09-27 10:56:05 +010095
Juan Castillo73c99d42015-08-18 14:23:04 +010096################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +010097# Auxiliary tools (fiptool, cert_create, etc)
98################################################################################
99
100# Variables for use with Certificate Generation Tool
101CRTTOOLPATH ?= tools/cert_create
Boyan Karatotevf4595e62025-05-06 17:11:29 +0100102CRTTOOL ?= ${BUILD_PLAT}/${CRTTOOLPATH}/cert_create$(.exe)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100103
104# Variables for use with Firmware Encryption Tool
105ENCTOOLPATH ?= tools/encrypt_fw
Boyan Karatotev96fbe882025-05-02 16:40:40 +0100106ENCTOOL ?= ${BUILD_PLAT}/${ENCTOOLPATH}/encrypt_fw$(.exe)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100107
108# Variables for use with Firmware Image Package
109FIPTOOLPATH ?= tools/fiptool
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +0100110FIPTOOL ?= ${BUILD_PLAT}/${FIPTOOLPATH}/fiptool$(.exe)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100111
112# Variables for use with sptool
113SPTOOLPATH ?= tools/sptool
114SPTOOL ?= ${SPTOOLPATH}/sptool.py
115SP_MK_GEN ?= ${SPTOOLPATH}/sp_mk_generator.py
Karl Meakin20629b32023-02-14 11:56:02 +0000116SP_DTS_LIST_FRAGMENT ?= ${BUILD_PLAT}/sp_list_fragment.dts
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100117
J-Alves0fe374e2024-11-18 17:49:53 +0000118# Variables for use with sptool
119TLCTOOL ?= poetry run tlc
120
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100121# Variables for use with ROMLIB
122ROMLIBPATH ?= lib/romlib
123
124# Variable for use with Python
125PYTHON ?= python3
126
127# Variables for use with documentation build using Sphinx tool
128DOCS_PATH ?= docs
129
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100130# Process Debug flag
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100131ifneq (${DEBUG}, 0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100132 BUILD_TYPE := debug
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100133 # Use LOG_LEVEL_INFO by default for debug builds
134 LOG_LEVEL := 40
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100135else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100136 BUILD_TYPE := release
137 # Use LOG_LEVEL_NOTICE by default for release builds
138 LOG_LEVEL := 20
139endif #(Debug)
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100140
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800141# Default build string (git branch and commit)
142ifeq (${BUILD_STRING},)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100143 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800144endif
laurenw-armdddf4282022-07-12 10:12:05 -0500145VERSION_STRING := v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800146
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000147# Setting W is quite verbose and most warnings will be pre-existing issues
148# outside of the contributor's control. Don't fail the build on them so warnings
149# can be seen and hopefully addressed
150ifdef W
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100151 ifneq (${W},0)
152 E ?= 0
153 endif
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000154endif
155
Juan Castillo73c99d42015-08-18 14:23:04 +0100156################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500157# Setup ARCH_MAJOR/MINOR before parsing arch_features.
158################################################################################
159ifeq (${ENABLE_RME},1)
AlexeiFedorov7d5fc982024-03-13 11:53:44 +0000160 ARM_ARCH_MAJOR := 9
161 ARM_ARCH_MINOR := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500162endif
163
164################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100165# Common sources and include directories
166################################################################################
dp-armd801fbb2017-05-04 12:15:35 +0100167include lib/compiler-rt/compiler-rt.mk
Juan Castillo73c99d42015-08-18 14:23:04 +0100168
Chris Kay758ccb82024-03-08 16:08:31 +0000169# Allow overriding the timestamp, for example for reproducible builds, or to
170# synchronize timestamps across multiple projects.
171# This must be set to a C string (including quotes where applicable).
172BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
173
174DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
175DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
176DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
177
Juan Castillo73c99d42015-08-18 14:23:04 +0100178BL_COMMON_SOURCES += common/bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100179 common/tf_log.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100180 common/${ARCH}/debug.S \
Julius Werner91b48c92018-11-27 22:10:56 -0800181 drivers/console/multi_console.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100182 lib/${ARCH}/cache_helpers.S \
183 lib/${ARCH}/misc_helpers.S \
Boyan Karatotevc73686a2023-02-15 13:21:50 +0000184 lib/extensions/pmuv3/${ARCH}/pmuv3.c \
Soby Mathew566034f2018-02-08 17:45:12 +0000185 plat/common/plat_bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100186 plat/common/plat_log_common.c \
dp-arm75311202017-03-07 11:02:47 +0000187 plat/common/${ARCH}/plat_common.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100188 plat/common/${ARCH}/platform_helpers.S \
Roberto Vargas61f72a32018-05-08 10:27:10 +0100189 ${COMPILER_RT_SRCS}
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000190
Chris Kay8620bd02023-12-04 09:55:50 +0000191ifeq ($($(ARCH)-cc-id),arm-clang)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100192 BL_COMMON_SOURCES += lib/${ARCH}/armclang_printf.S
Antonio Nino Diaz8422a842018-08-16 15:42:44 +0100193endif
194
Justin Chadwell1f461972019-08-20 11:01:52 +0100195ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100196 BL_COMMON_SOURCES += plat/common/ubsan.c
Justin Chadwell1f461972019-08-20 11:01:52 +0100197endif
198
Yann Gautier01d237c2018-06-18 16:00:23 +0200199INCLUDES += -Iinclude \
Antonio Nino Diazf5478de2018-12-17 17:20:57 +0000200 -Iinclude/arch/${ARCH} \
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +0000201 -Iinclude/lib/cpus/${ARCH} \
202 -Iinclude/lib/el3_runtime/${ARCH} \
203 ${PLAT_INCLUDES} \
204 ${SPD_INCLUDES}
205
Antonio Nino Diaz9c6d1c52018-11-19 11:48:30 +0000206include common/backtrace/backtrace.mk
207
Juan Castillo73c99d42015-08-18 14:23:04 +0100208################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500209# Generic definitions
210################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500211
212ifeq (${BUILD_BASE},)
213 BUILD_BASE := ./build
214endif
215BUILD_PLAT := $(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
216
217SPDS := $(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
218
219# Platforms providing their own TBB makefile may override this value
220INCLUDE_TBBR_MK := 1
221
222################################################################################
223# Include SPD Makefile if one has been specified
224################################################################################
225
226ifneq (${SPD},none)
Govindraj Raja35472702023-09-20 14:32:24 -0500227 ifeq (${SPD},spmd)
228 # SPMD is located in std_svc directory
229 SPD_DIR := std_svc
230
231 ifeq ($(SPMD_SPM_AT_SEL2),1)
232 CTX_INCLUDE_EL2_REGS := 1
Govindraj Raja35472702023-09-20 14:32:24 -0500233 endif
234
Govindraj Raja35472702023-09-20 14:32:24 -0500235 ifneq ($(SP_LAYOUT_FILE),)
236 BL2_ENABLE_SP_LOAD := 1
237 endif
238 else
239 # All other SPDs in spd directory
240 SPD_DIR := spd
241 endif #(SPD)
242
243 # We expect to locate an spd.mk under the specified SPD directory
244 SPD_MAKE := $(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
245
246 ifeq (${SPD_MAKE},)
247 $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
248 endif
249 $(info Including ${SPD_MAKE})
250 include ${SPD_MAKE}
251
252 # If there's BL32 companion for the chosen SPD, we expect that the SPD's
253 # Makefile would set NEED_BL32 to "yes". In this case, the build system
254 # supports two mutually exclusive options:
255 # * BL32 is built from source: then BL32_SOURCES must contain the list
256 # of source files to build BL32
257 # * BL32 is a prebuilt binary: then BL32 must point to the image file
258 # that will be included in the FIP
259 # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
260 # over the sources.
261endif #(SPD=none)
262
Govindraj Raja35472702023-09-20 14:32:24 -0500263################################################################################
Olivier Deprez696ed162025-01-03 13:38:50 +0100264# Include the platform specific Makefile after the SPD Makefile (the platform
265# makefile may use all previous definitions in this file)
266################################################################################
267include ${PLAT_MAKEFILE_FULL}
268
269################################################################################
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100270# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
271# platform.
272################################################################################
273
274include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
275################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500276# Process BRANCH_PROTECTION value and set
277# Pointer Authentication and Branch Target Identification flags
278################################################################################
279ifeq (${BRANCH_PROTECTION},0)
280 # Default value turns off all types of branch protection
281 BP_OPTION := none
282else ifneq (${ARCH},aarch64)
283 $(error BRANCH_PROTECTION requires AArch64)
284else ifeq (${BRANCH_PROTECTION},1)
285 # Enables all types of branch protection features
286 BP_OPTION := standard
287 ENABLE_BTI := 1
288 ENABLE_PAUTH := 1
289else ifeq (${BRANCH_PROTECTION},2)
290 # Return address signing to its standard level
291 BP_OPTION := pac-ret
292 ENABLE_PAUTH := 1
293else ifeq (${BRANCH_PROTECTION},3)
294 # Extend the signing to include leaf functions
295 BP_OPTION := pac-ret+leaf
296 ENABLE_PAUTH := 1
297else ifeq (${BRANCH_PROTECTION},4)
298 # Turn on branch target identification mechanism
299 BP_OPTION := bti
300 ENABLE_BTI := 1
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100301else ifeq (${BRANCH_PROTECTION},5)
302 # Turn on branch target identification mechanism
303 BP_OPTION := standard
304 ENABLE_BTI := 2
305 ENABLE_PAUTH := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500306else
307 $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
308endif #(BRANCH_PROTECTION)
309
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100310ifneq ($(ENABLE_PAUTH),0)
311 CTX_INCLUDE_PAUTH_REGS := ${ENABLE_PAUTH}
Govindraj Rajaf5211422023-08-17 10:41:48 -0500312endif
Govindraj Rajaf5211422023-08-17 10:41:48 -0500313
314# Pointer Authentication sources
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100315ifneq (${ENABLE_PAUTH},0)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500316# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
317# Pauth support. As it's not secure, it must be reimplemented for real platforms
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100318 BL_COMMON_SOURCES += lib/extensions/pauth/pauth.c
Govindraj Rajaf5211422023-08-17 10:41:48 -0500319endif
Boyan Karatotevb14987c2025-04-09 14:41:58 +0100320#
321ifneq (${ENABLE_FEAT_PAUTH_LR},0)
322# Currently, FEAT_PAUTH_LR is only supported by arm/clang compilers
323# TODO implement for GCC when support is added
324ifeq ($($(ARCH)-cc-id),arm-clang)
325 arch-features := $(arch-features)+pauth-lr
326else
327 $(error Error: ENABLE_FEAT_PAUTH_LR not supported for GCC compiler)
328endif
329endif
Govindraj Rajaf5211422023-08-17 10:41:48 -0500330
Govindraj Rajaf5211422023-08-17 10:41:48 -0500331################################################################################
332# RME dependent flags configuration, Enable optional features for RME.
333################################################################################
334# FEAT_RME
335ifeq (${ENABLE_RME},1)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500336 # RME requires el2 context to be saved for now.
337 CTX_INCLUDE_EL2_REGS := 1
338 CTX_INCLUDE_AARCH32_REGS := 0
339 CTX_INCLUDE_PAUTH_REGS := 1
340
Javier Almansa Sobrinod048af02025-03-21 18:32:10 +0000341 ifneq ($(ENABLE_FEAT_MPAM), 0)
342 CTX_INCLUDE_MPAM_REGS := 1
343 endif
344
Govindraj Rajaf5211422023-08-17 10:41:48 -0500345 # RME enables CSV2_2 extension by default.
346 ENABLE_FEAT_CSV2_2 = 1
347endif #(FEAT_RME)
348
349################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500350# Include rmmd Makefile if RME is enabled
351################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500352ifneq (${ENABLE_RME},0)
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500353include services/std_svc/rmmd/rmmd.mk
354$(warning "RME is an experimental feature")
355endif
356
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000357################################################################################
Govindraj Raja30655132024-09-06 15:43:43 +0100358# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
359################################################################################
360ifneq (${ENABLE_FEAT_D128}, 0)
361 BL_COMMON_SOURCES += lib/extensions/sysreg128/sysreg128.S
362endif
363
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600364# This internal flag is common option which is set to 1 for scenarios
365# when the BL2 is running in EL3 level. This occurs in two scenarios -
366# 4 world system running BL2 at EL3 and two world system without BL1 running
367# BL2 in EL3
368
369ifeq (${RESET_TO_BL2},1)
370 BL2_RUNS_AT_EL3 := 1
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100371 ifeq (${ENABLE_RME},1)
372 $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
373 supported at the moment.)
374 endif
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600375else ifeq (${ENABLE_RME},1)
376 BL2_RUNS_AT_EL3 := 1
377else
378 BL2_RUNS_AT_EL3 := 0
379endif
380
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100381# This internal flag is set to 1 when Firmware First handling of External aborts
382# is required by lowe ELs. Currently only NS requires this support.
383ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
384 FFH_SUPPORT := 1
385else
386 FFH_SUPPORT := 0
387endif
388
Sandrine Bailleux54035fc2016-01-13 14:57:38 +0000389# Include the CPU specific operations makefile, which provides default
390# values for all CPU errata workarounds and CPU specific optimisations.
391# This can be overridden by the platform.
Juan Castillo73c99d42015-08-18 14:23:04 +0100392include lib/cpus/cpu-ops.mk
Achin Gupta4f6ad662013-10-25 09:08:21 +0100393
dp-arma4409002017-02-15 11:07:55 +0000394################################################################################
395# Build `AARCH32_SP` as BL32 image for AArch32
396################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100397ifeq (${ARCH},aarch32)
398 NEED_BL32 := yes
dp-arma4409002017-02-15 11:07:55 +0000399
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100400 ifneq (${AARCH32_SP},none)
401 # We expect to locate an sp.mk under the specified AARCH32_SP directory
402 AARCH32_SP_MAKE := $(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
dp-arma4409002017-02-15 11:07:55 +0000403
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100404 ifeq (${AARCH32_SP_MAKE},)
405 $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
406 endif
Juan Pablo Conde043f38f2023-08-09 13:19:21 -0500407 $(info Including ${AARCH32_SP_MAKE})
408 include ${AARCH32_SP_MAKE}
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100409 endif
410endif #(ARCH=aarch32)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100411
Juan Castillo73c99d42015-08-18 14:23:04 +0100412################################################################################
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800413# Include libc if not overridden
414################################################################################
415ifeq (${OVERRIDE_LIBC},0)
416include lib/libc/libc.mk
417endif
418
Boyan Karatotev5d893412025-01-07 11:00:03 +0000419ifneq (${USE_GIC_DRIVER},0)
420include drivers/arm/gic/gic.mk
421endif
422
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800423################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100424# Check incompatible options and dependencies
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000425################################################################################
Boyan Karatotevb14987c2025-04-09 14:41:58 +0100426include ${MAKE_HELPERS_DIRECTORY}constraints.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100427
428# The cert_create tool cannot generate certificates individually, so we use the
429# target 'certificates' to create them all
430ifneq (${GENERATE_COT},0)
431 FIP_DEPS += certificates
432 FWU_FIP_DEPS += fwu_certificates
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000433endif
434
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100435ifneq (${DECRYPTION_SUPPORT},none)
436 ENC_ARGS += -f ${FW_ENC_STATUS}
437 ENC_ARGS += -k ${ENC_KEY}
438 ENC_ARGS += -n ${ENC_NONCE}
439 FIP_DEPS += enctool
440 FWU_FIP_DEPS += enctool
441endif #(DECRYPTION_SUPPORT)
442
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100443ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
444# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100445 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100446else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
447# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100448 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100449else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
450# Support hash calculation only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100451 CRYPTO_SUPPORT := 2
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100452else ifeq (${TRUSTED_BOARD_BOOT},1)
453# Support authentication verification only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100454 CRYPTO_SUPPORT := 1
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000455else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100456 CRYPTO_SUPPORT := 0
457endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000458
Manish V Badarkhee4a070e2024-12-03 21:46:51 +0000459ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
460CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
461endif
462
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000463################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100464# Process platform overrideable behaviour
465################################################################################
Achin Gupta4f6ad662013-10-25 09:08:21 +0100466
Manish Pandey5f24ce92021-10-06 10:59:52 +0100467ifdef BL1_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100468 NEED_BL1 := yes
469endif #(BL1_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100470
Juan Castillo73c99d42015-08-18 14:23:04 +0100471ifdef BL2_SOURCES
Manish Pandey5f24ce92021-10-06 10:59:52 +0100472 NEED_BL2 := yes
473
474 # Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
475 # Certificate generation tools. This flag can be overridden by the platform.
476 ifdef EL3_PAYLOAD_BASE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100477 # If booting an EL3 payload there is no need for a BL33 image
478 # in the FIP file.
479 NEED_BL33 := no
480 else
481 ifdef PRELOADED_BL33_BASE
482 # If booting a BL33 preloaded image there is no need of
483 # another one in the FIP file.
484 NEED_BL33 := no
485 else
486 NEED_BL33 ?= yes
487 endif
488 endif
489endif #(BL2_SOURCES)
Juan Castillo73c99d42015-08-18 14:23:04 +0100490
Manish Pandey5f24ce92021-10-06 10:59:52 +0100491ifdef BL2U_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100492 NEED_BL2U := yes
493endif #(BL2U_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100494
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900495# If SCP_BL2 is given, we always want FIP to include it.
496ifdef SCP_BL2
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100497 NEED_SCP_BL2 := yes
498endif #(SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900499
Soby Mathew5744e872017-11-14 14:10:10 +0000500# For AArch32, BL31 is not currently supported.
501ifneq (${ARCH},aarch32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100502 ifdef BL31_SOURCES
503 # When booting an EL3 payload, there is no need to compile the BL31
504 # image nor put it in the FIP.
505 ifndef EL3_PAYLOAD_BASE
506 NEED_BL31 := yes
507 endif
508 endif
509endif #(ARCH=aarch64)
Soby Mathew5744e872017-11-14 14:10:10 +0000510
Juan Castillo73c99d42015-08-18 14:23:04 +0100511# Process TBB related flags
512ifneq (${GENERATE_COT},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100513 # Common cert_create options
514 ifneq (${CREATE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +0100515 $(eval CRT_ARGS += -n)
Yatharth Kochar01912622015-10-12 12:33:47 +0100516 $(eval FWU_CRT_ARGS += -n)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100517 ifneq (${SAVE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +0100518 $(eval CRT_ARGS += -k)
Yatharth Kochar01912622015-10-12 12:33:47 +0100519 $(eval FWU_CRT_ARGS += -k)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100520 endif
521 endif
522 # Include TBBR makefile (unless the platform indicates otherwise)
523 ifeq (${INCLUDE_TBBR_MK},1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100524 include make_helpers/tbbr/tbbr_tools.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100525 endif
526endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +0100527
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +0900528ifneq (${FIP_ALIGN},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100529 FIP_ARGS += --align ${FIP_ALIGN}
530endif #(FIP_ALIGN)
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +0900531
Manish Pandey5f24ce92021-10-06 10:59:52 +0100532ifdef FDT_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100533 NEED_FDT := yes
534endif #(FDT_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100535
Juan Castillo73c99d42015-08-18 14:23:04 +0100536################################################################################
Michalis Pappas46e5e032018-03-20 13:01:27 +0800537# Include libraries' Makefile that are used in all BL
538################################################################################
539
540include lib/stack_protector/stack_protector.mk
541
542################################################################################
Soby Mathew8a860522017-02-14 10:05:07 +0000543# Include BL specific makefiles
544################################################################################
Manish Pandey5f24ce92021-10-06 10:59:52 +0100545
546ifeq (${NEED_BL1},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000547include bl1/bl1.mk
548endif
549
Manish Pandey5f24ce92021-10-06 10:59:52 +0100550ifeq (${NEED_BL2},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000551include bl2/bl2.mk
552endif
553
Manish Pandey5f24ce92021-10-06 10:59:52 +0100554ifeq (${NEED_BL2U},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000555include bl2u/bl2u.mk
556endif
557
Soby Mathew5744e872017-11-14 14:10:10 +0000558ifeq (${NEED_BL31},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000559include bl31/bl31.mk
560endif
Nishanth Menon03b397a2016-10-14 01:13:57 +0000561
Juan Castillo73c99d42015-08-18 14:23:04 +0100562################################################################################
563# Build options checks
564################################################################################
Juan Castillob7124ea2014-11-04 17:36:40 +0000565
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100566# Boolean_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500567$(eval $(call assert_booleans,\
568 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100569 ALLOW_RO_XLAT_TABLES \
570 BL2_ENABLE_SP_LOAD \
571 COLD_BOOT_SINGLE_CPU \
572 CREATE_KEYS \
573 CTX_INCLUDE_AARCH32_REGS \
574 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -0500575 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100576 CTX_INCLUDE_EL2_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -0500577 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100578 DEBUG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100579 DYN_DISABLE_AUTH \
580 EL3_EXCEPTION_HANDLING \
581 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100582 AMU_RESTRICT_COUNTERS \
583 ENABLE_ASSERTIONS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100584 ENABLE_PIE \
585 ENABLE_PMF \
586 ENABLE_PSCI_STAT \
587 ENABLE_RUNTIME_INSTRUMENTATION \
588 ENABLE_SME_FOR_SWD \
589 ENABLE_SVE_FOR_SWD \
Boyan Karatotev8cef63d2025-01-07 11:26:56 +0000590 ENABLE_FEAT_GCIE \
Manish Pandey970a4a82023-10-10 13:53:25 +0100591 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100592 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100593 ERROR_DEPRECATED \
594 FAULT_INJECTION_SUPPORT \
595 GENERATE_COT \
596 GICV2_G0_FOR_EL3 \
597 HANDLE_EA_EL3_FIRST_NS \
Bipin Ravi538516f2023-09-28 13:17:24 -0500598 HARDEN_SLS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100599 HW_ASSISTED_COHERENCY \
600 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -0500601 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +0200602 DICE_PROTECTION_ENVIRONMENT \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -0700603 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -0500604 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100605 DRTM_SUPPORT \
606 NS_TIMER_SWITCH \
607 OVERRIDE_LIBC \
608 PL011_GENERIC_UART \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100609 PROGRAMMABLE_RESET_ADDRESS \
610 PSCI_EXTENDED_STATE_ID \
611 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +0100612 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100613 RESET_TO_BL31 \
614 SAVE_KEYS \
615 SEPARATE_CODE_AND_RODATA \
616 SEPARATE_BL2_NOLOAD_REGION \
617 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +0800618 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -0500619 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100620 SPIN_ON_BL1_EXIT \
621 SPM_MM \
622 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +0100623 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100624 SPMD_SPM_AT_SEL2 \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -0800625 ENABLE_SPMD_LP \
Raymond Mao3ba2c152023-07-25 07:53:35 -0700626 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100627 TRUSTED_BOARD_BOOT \
628 USE_COHERENT_MEM \
629 USE_DEBUGFS \
630 ARM_IO_IN_DTB \
631 SDEI_IN_FCONF \
632 SEC_INT_DESC_IN_FCONF \
633 USE_ROMLIB \
634 USE_TBBR_DEFS \
635 WARMBOOT_ENABLE_DCACHE_EARLY \
636 RESET_TO_BL2 \
637 BL2_IN_XIP_MEM \
638 BL2_INV_DCACHE \
639 USE_SPINLOCK_CAS \
640 ENCRYPT_BL31 \
641 ENCRYPT_BL32 \
642 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +0100643 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100644 RAS_TRAP_NS_ERR_REC_ACCESS \
645 COT_DESC_IN_DTB \
646 USE_SP804_TIMER \
647 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +0530648 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100649 ENABLE_MPMM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100650 FEATURE_DETECTION \
Jayanth Dodderi Chidanand0b22e592022-10-11 17:16:07 +0100651 TRNG_SUPPORT \
Boyan Karatotev593ae352023-03-22 15:55:36 +0000652 ENABLE_ERRATA_ALL \
Sona Mathewffea3842022-11-18 18:05:38 -0600653 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -0500654 ERRATA_NON_ARM_INTERCONNECT \
Okash Khawaja04c73032022-11-04 12:38:01 +0000655 CONDITIONAL_CMO \
Manish V Badarkhe5782b892023-09-06 09:08:28 +0100656 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +0200657 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -0500658 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -0600659 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +0100660 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -0600661 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +0100662 HOB_LIST \
Manish V Badarkhecf48f492025-04-15 20:16:32 +0100663 LFA_SUPPORT \
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500664)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100665
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100666# Numeric_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500667$(eval $(call assert_numerics,\
668 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100669 ARM_ARCH_MAJOR \
670 ARM_ARCH_MINOR \
671 BRANCH_PROTECTION \
672 CTX_INCLUDE_PAUTH_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100673 CTX_INCLUDE_NEVE_REGS \
674 CRYPTO_SUPPORT \
Boyan Karatotev83a4dae2023-02-16 09:45:29 +0000675 DISABLE_MTPMU \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100676 ENABLE_BRBE_FOR_NS \
677 ENABLE_TRBE_FOR_NS \
678 ENABLE_BTI \
679 ENABLE_PAUTH \
John Powell025b1b82025-03-10 20:09:03 -0500680 ENABLE_FEAT_PAUTH_LR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100681 ENABLE_FEAT_AMU \
682 ENABLE_FEAT_AMUv1p1 \
683 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -0500684 ENABLE_FEAT_CSV2_3 \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -0500685 ENABLE_FEAT_DEBUGV8P9 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100686 ENABLE_FEAT_DIT \
687 ENABLE_FEAT_ECV \
688 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -0500689 ENABLE_FEAT_FGT2 \
Arvind Ram Prakash4274b522025-06-23 15:21:44 -0500690 ENABLE_FEAT_FGWTE3 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600691 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100692 ENABLE_FEAT_HCX \
Andre Przywara19d52a82024-08-09 17:04:22 +0100693 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000694 ENABLE_FEAT_MEC \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -0600695 ENABLE_FEAT_MOPS \
Govindraj Raja8e397882024-01-26 10:08:37 -0600696 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100697 ENABLE_FEAT_PAN \
698 ENABLE_FEAT_RNG \
699 ENABLE_FEAT_RNG_TRAP \
700 ENABLE_FEAT_SEL2 \
701 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +0100702 ENABLE_FEAT_THE \
Govindraj Raja0e4daed2024-01-23 16:03:53 -0600703 ENABLE_FEAT_SB \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100704 ENABLE_FEAT_S2PIE \
705 ENABLE_FEAT_S1PIE \
706 ENABLE_FEAT_S2POE \
707 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +0100708 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +0100709 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100710 ENABLE_FEAT_GCS \
711 ENABLE_FEAT_VHE \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -0500712 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100713 ENABLE_RME \
714 ENABLE_SPE_FOR_NS \
715 ENABLE_SYS_REG_TRACE_FOR_NS \
716 ENABLE_SME_FOR_NS \
717 ENABLE_SME2_FOR_NS \
718 ENABLE_SVE_FOR_NS \
719 ENABLE_TRF_FOR_NS \
720 FW_ENC_STATUS \
721 NR_OF_FW_BANKS \
722 NR_OF_IMAGES_IN_FW_BANK \
723 TWED_DELAY \
724 ENABLE_FEAT_TWED \
725 SVE_VECTOR_LEN \
Varun Wadekar0ed3be62023-04-13 21:06:18 +0100726 IMPDEF_SYSREG_TRAP \
Boyan Karatotevee580c22025-04-11 14:27:55 +0100727 W \
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500728)))
Jeenu Viswambharanc877b412017-01-16 16:52:35 +0000729
Justin Chadwellaacff742019-07-29 17:13:10 +0100730ifdef KEY_SIZE
731 $(eval $(call assert_numeric,KEY_SIZE))
732endif
733
Justin Chadwell1f461972019-08-20 11:01:52 +0100734ifeq ($(filter $(SANITIZE_UB), on off trap),)
735 $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
736endif
737
Juan Castillo73c99d42015-08-18 14:23:04 +0100738################################################################################
739# Add definitions to the cpp preprocessor based on the current build options.
740# This is done after including the platform specific makefile to allow the
741# platform to overwrite the default options
742################################################################################
743
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500744$(eval $(call add_defines,\
745 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100746 ALLOW_RO_XLAT_TABLES \
747 ARM_ARCH_MAJOR \
748 ARM_ARCH_MINOR \
749 BL2_ENABLE_SP_LOAD \
750 COLD_BOOT_SINGLE_CPU \
751 CTX_INCLUDE_AARCH32_REGS \
752 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -0500753 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100754 CTX_INCLUDE_PAUTH_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -0500755 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100756 EL3_EXCEPTION_HANDLING \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100757 CTX_INCLUDE_EL2_REGS \
758 CTX_INCLUDE_NEVE_REGS \
Boyan Karatotevee580c22025-04-11 14:27:55 +0100759 DEBUG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100760 DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
761 DISABLE_MTPMU \
762 ENABLE_FEAT_AMU \
763 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100764 AMU_RESTRICT_COUNTERS \
765 ENABLE_ASSERTIONS \
766 ENABLE_BTI \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -0500767 ENABLE_FEAT_DEBUGV8P9 \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -0500768 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100769 ENABLE_PAUTH \
John Powell025b1b82025-03-10 20:09:03 -0500770 ENABLE_FEAT_PAUTH_LR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100771 ENABLE_PIE \
772 ENABLE_PMF \
773 ENABLE_PSCI_STAT \
774 ENABLE_RME \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -0700775 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -0500776 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100777 ENABLE_RUNTIME_INSTRUMENTATION \
778 ENABLE_SME_FOR_NS \
779 ENABLE_SME2_FOR_NS \
780 ENABLE_SME_FOR_SWD \
781 ENABLE_SPE_FOR_NS \
782 ENABLE_SVE_FOR_NS \
783 ENABLE_SVE_FOR_SWD \
Manish Pandey970a4a82023-10-10 13:53:25 +0100784 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100785 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100786 ENCRYPT_BL31 \
787 ENCRYPT_BL32 \
788 ERROR_DEPRECATED \
789 FAULT_INJECTION_SUPPORT \
790 GICV2_G0_FOR_EL3 \
791 HANDLE_EA_EL3_FIRST_NS \
792 HW_ASSISTED_COHERENCY \
793 LOG_LEVEL \
794 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -0500795 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +0200796 DICE_PROTECTION_ENVIRONMENT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100797 DRTM_SUPPORT \
798 NS_TIMER_SWITCH \
799 PL011_GENERIC_UART \
800 PLAT_${PLAT} \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100801 PROGRAMMABLE_RESET_ADDRESS \
802 PSCI_EXTENDED_STATE_ID \
803 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +0100804 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100805 RESET_TO_BL31 \
AlexeiFedorovd7660842024-05-13 15:35:54 +0100806 RME_GPT_BITLOCK_BLOCK \
AlexeiFedorovec0088b2024-03-13 17:07:03 +0000807 RME_GPT_MAX_BLOCK \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100808 SEPARATE_CODE_AND_RODATA \
809 SEPARATE_BL2_NOLOAD_REGION \
810 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +0800811 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -0500812 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100813 RECLAIM_INIT_CODE \
814 SPD_${SPD} \
815 SPIN_ON_BL1_EXIT \
816 SPM_MM \
817 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +0100818 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100819 SPMD_SPM_AT_SEL2 \
Raymond Mao3ba2c152023-07-25 07:53:35 -0700820 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100821 TRUSTED_BOARD_BOOT \
822 CRYPTO_SUPPORT \
823 TRNG_SUPPORT \
824 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -0500825 ERRATA_NON_ARM_INTERCONNECT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100826 USE_COHERENT_MEM \
827 USE_DEBUGFS \
828 ARM_IO_IN_DTB \
829 SDEI_IN_FCONF \
830 SEC_INT_DESC_IN_FCONF \
831 USE_ROMLIB \
832 USE_TBBR_DEFS \
833 WARMBOOT_ENABLE_DCACHE_EARLY \
834 RESET_TO_BL2 \
835 BL2_RUNS_AT_EL3 \
836 BL2_IN_XIP_MEM \
837 BL2_INV_DCACHE \
838 USE_SPINLOCK_CAS \
839 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +0100840 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100841 RAS_TRAP_NS_ERR_REC_ACCESS \
842 COT_DESC_IN_DTB \
843 USE_SP804_TIMER \
844 ENABLE_FEAT_RNG \
845 ENABLE_FEAT_RNG_TRAP \
846 ENABLE_FEAT_SB \
847 ENABLE_FEAT_DIT \
848 NR_OF_FW_BANKS \
849 NR_OF_IMAGES_IN_FW_BANK \
850 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +0530851 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100852 ENABLE_BRBE_FOR_NS \
853 ENABLE_TRBE_FOR_NS \
854 ENABLE_SYS_REG_TRACE_FOR_NS \
855 ENABLE_TRF_FOR_NS \
856 ENABLE_FEAT_HCX \
857 ENABLE_MPMM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100858 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -0500859 ENABLE_FEAT_FGT2 \
Arvind Ram Prakash4274b522025-06-23 15:21:44 -0500860 ENABLE_FEAT_FGWTE3 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600861 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100862 ENABLE_FEAT_ECV \
863 ENABLE_FEAT_AMUv1p1 \
864 ENABLE_FEAT_SEL2 \
865 ENABLE_FEAT_VHE \
866 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -0500867 ENABLE_FEAT_CSV2_3 \
Andre Przywara19d52a82024-08-09 17:04:22 +0100868 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000869 ENABLE_FEAT_MEC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100870 ENABLE_FEAT_PAN \
871 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +0100872 ENABLE_FEAT_THE \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100873 ENABLE_FEAT_S2PIE \
874 ENABLE_FEAT_S1PIE \
875 ENABLE_FEAT_S2POE \
876 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +0100877 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +0100878 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100879 ENABLE_FEAT_GCS \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -0600880 ENABLE_FEAT_MOPS \
Boyan Karatotev8cef63d2025-01-07 11:26:56 +0000881 ENABLE_FEAT_GCIE \
Govindraj Raja8e397882024-01-26 10:08:37 -0600882 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100883 FEATURE_DETECTION \
884 TWED_DELAY \
885 ENABLE_FEAT_TWED \
Okash Khawaja04c73032022-11-04 12:38:01 +0000886 CONDITIONAL_CMO \
Varun Wadekar0ed3be62023-04-13 21:06:18 +0100887 IMPDEF_SYSREG_TRAP \
Jayanth Dodderi Chidananda8cf6fa2023-04-26 15:57:30 +0100888 SVE_VECTOR_LEN \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -0800889 ENABLE_SPMD_LP \
Manish V Badarkhe5782b892023-09-06 09:08:28 +0100890 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +0200891 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -0500892 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -0600893 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +0100894 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -0600895 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +0100896 HOB_LIST \
Manish V Badarkhecf48f492025-04-15 20:16:32 +0100897 LFA_SUPPORT \
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500898)))
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +0100899
Juan Pablo Condebfef8b92023-11-08 16:14:28 -0600900ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
901ifeq (${DEBUG}, 0)
902 $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
903 override PLATFORM_REPORT_CTX_MEM_USE := 0
904endif
905endif
906
Justin Chadwell1f461972019-08-20 11:01:52 +0100907ifeq (${SANITIZE_UB},trap)
908 $(eval $(call add_define,MONITOR_TRAPS))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100909endif #(SANITIZE_UB)
Justin Chadwell1f461972019-08-20 11:01:52 +0100910
Sandrine Bailleux4c117f62015-11-26 16:31:34 +0000911# Define the EL3_PAYLOAD_BASE flag only if it is provided.
912ifdef EL3_PAYLOAD_BASE
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000913 $(eval $(call add_define,EL3_PAYLOAD_BASE))
914else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100915# Define the PRELOADED_BL33_BASE flag only if it is provided and
916# EL3_PAYLOAD_BASE is not defined, as it has priority.
917 ifdef PRELOADED_BL33_BASE
Antonio Nino Diaz68450a62016-04-06 17:31:57 +0100918 $(eval $(call add_define,PRELOADED_BL33_BASE))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100919 endif
920endif #(EL3_PAYLOAD_BASE)
Juan Castillo73c99d42015-08-18 14:23:04 +0100921
Soby Mathew209a60c2018-03-26 12:43:37 +0100922# Define the DYN_DISABLE_AUTH flag only if set.
923ifeq (${DYN_DISABLE_AUTH},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100924 $(eval $(call add_define,DYN_DISABLE_AUTH))
Soby Mathew209a60c2018-03-26 12:43:37 +0100925endif
926
Chris Kay8620bd02023-12-04 09:55:50 +0000927ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100928 $(eval $(call add_define,USE_ARM_LINK))
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800929endif
930
Manish Pandeyce2b1ec2020-01-14 11:52:05 +0000931# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
Manish Pandeyce2b1ec2020-01-14 11:52:05 +0000932ifeq (${SPD},spmd)
Olivier Deprezc33ff192020-03-19 09:27:11 +0100933ifdef SP_LAYOUT_FILE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100934 -include $(BUILD_PLAT)/sp_gen.mk
935 FIP_DEPS += sp
936 CRT_DEPS += sp
937 NEED_SP_PKG := yes
Manish Pandeyce2b1ec2020-01-14 11:52:05 +0000938else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100939 ifeq (${SPMD_SPM_AT_SEL2},1)
940 $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
941 endif
942endif #(SP_LAYOUT_FILE)
943endif #(SPD)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +0000944
Juan Castillo73c99d42015-08-18 14:23:04 +0100945################################################################################
Boyan Karatotev3df79ae2025-04-09 14:26:17 +0100946# Configure the flags for the specified compiler and linker
947################################################################################
948include ${MAKE_HELPERS_DIRECTORY}cflags.mk
949
950################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100951# Build targets
952################################################################################
953
Harrison Mutai2329e222024-08-28 13:27:19 +0000954.PHONY: all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
Juan Castillo73c99d42015-08-18 14:23:04 +0100955
956all: msg_start
957
958msg_start:
Chris Kay7c4e1ee2024-05-02 17:52:37 +0000959 $(s)echo "Building ${PLAT}"
Juan Castillo73c99d42015-08-18 14:23:04 +0100960
Roberto Vargas61f72a32018-05-08 10:27:10 +0100961$(eval $(call MAKE_LIB,c))
Roberto Vargas5fee0282018-05-08 10:27:10 +0100962
Juan Castillo73c99d42015-08-18 14:23:04 +0100963# Expand build macros for the different images
964ifeq (${NEED_BL1},yes)
Chris Kayb34635a2021-09-28 15:44:19 +0100965BL1_SOURCES := $(sort ${BL1_SOURCES})
Zelalem Aweke434d0492021-07-11 17:25:48 -0500966$(eval $(call MAKE_BL,bl1))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100967endif #(NEED_BL1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100968
969ifeq (${NEED_BL2},yes)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100970
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600971ifeq (${RESET_TO_BL2}, 0)
Roberto Vargasc9b31ae2018-01-02 11:23:41 +0000972FIP_BL2_ARGS := tb-fw
973endif
974
Chris Kayeb1acfb2021-09-28 15:44:37 +0100975BL2_SOURCES := $(sort ${BL2_SOURCES})
976
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900977$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
Zelalem Aweke434d0492021-07-11 17:25:48 -0500978 $(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100979
980endif #(NEED_BL2)
Juan Castillo73c99d42015-08-18 14:23:04 +0100981
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900982ifeq (${NEED_SCP_BL2},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900983$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100984endif #(NEED_SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900985
Juan Castillo73c99d42015-08-18 14:23:04 +0100986ifeq (${NEED_BL31},yes)
987BL31_SOURCES += ${SPD_SOURCES}
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -0600988# Sort BL31 source files to remove duplicates
989BL31_SOURCES := $(sort ${BL31_SOURCES})
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530990ifneq (${DECRYPTION_SUPPORT},none)
991$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
Zelalem Aweke434d0492021-07-11 17:25:48 -0500992 $(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
Sumit Gargc6ba9b42019-11-14 16:33:45 +0530993else
Masahiro Yamada33950dd2018-01-26 11:42:01 +0900994$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -0500995 $(eval $(call MAKE_BL,bl31,soc-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100996endif #(DECRYPTION_SUPPORT)
997endif #(NEED_BL31)
Juan Castillo73c99d42015-08-18 14:23:04 +0100998
Juan Castillo70d1fc52015-11-12 10:59:26 +0000999# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
Masahiro Yamadac939d132018-01-26 11:42:01 +09001000# build system will call TOOL_ADD_IMG to print a warning message and abort the
Juan Castillo70d1fc52015-11-12 10:59:26 +00001001# process. Note that the dependency on BL32 applies to the FIP only.
Juan Castillo73c99d42015-08-18 14:23:04 +01001002ifeq (${NEED_BL32},yes)
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001003# Sort BL32 source files to remove duplicates
1004BL32_SOURCES := $(sort ${BL32_SOURCES})
Masahiro Yamada9cd15232018-01-26 11:42:01 +09001005BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1006
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301007ifneq (${DECRYPTION_SUPPORT},none)
Zelalem Aweke434d0492021-07-11 17:25:48 -05001008$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301009 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1010else
Zelalem Aweke434d0492021-07-11 17:25:48 -05001011$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001012 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001013endif #(DECRYPTION_SUPPORT)
1014endif #(NEED_BL32)
Juan Castillo73c99d42015-08-18 14:23:04 +01001015
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001016# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1017# needs to be built from RMM_SOURCES.
1018ifeq (${NEED_RMM},yes)
1019# Sort RMM source files to remove duplicates
1020RMM_SOURCES := $(sort ${RMM_SOURCES})
1021BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1022
1023$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001024 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1025endif #(NEED_RMM)
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001026
Juan Castillo73c99d42015-08-18 14:23:04 +01001027# Add the BL33 image if required by the platform
1028ifeq (${NEED_BL33},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001029$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001030endif #(NEED_BL33)
Juan Castillodb6071c2015-01-13 12:21:04 +00001031
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001032ifeq (${NEED_BL2U},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001033$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001034 $(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001035endif #(NEED_BL2U)
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001036
Nishanth Menon03b397a2016-10-14 01:13:57 +00001037# Expand build macros for the different images
1038ifeq (${NEED_FDT},yes)
Soby Mathew38c14d82017-12-14 17:44:56 +00001039 $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
Salman Nabi1c08ff32024-12-12 17:38:54 +00001040
1041 ifneq (${INITRD_SIZE}${INITRD_PATH},)
1042 ifndef INITRD_BASE
1043 $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1044 endif
1045
1046 INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1047 initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1048
1049 define $(HW_CONFIG)-after +=
1050 $(s)echo " INITRD $(HW_CONFIG)"
1051 $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1052 $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1053 endef
1054 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001055endif #(NEED_FDT)
Nishanth Menon03b397a2016-10-14 01:13:57 +00001056
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001057# Add Secure Partition packages
1058ifeq (${NEED_SP_PKG},yes)
Chris Kayfd74ca02024-07-30 13:33:56 +00001059$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
Chris Kay679e27c2025-03-19 15:04:47 +00001060 $(if $(host-poetry),$(q)poetry -q install --no-root)
Kathleen Capelladd816232025-02-13 17:34:21 -06001061 $(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
J-Alves822c7272022-03-22 16:28:51 +00001062sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001063 $(s)echo
1064 $(s)echo "Built SP Images successfully"
1065 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001066endif #(NEED_SP_PKG)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001067
Ian Spray36eaaf32014-01-30 17:25:28 +00001068locate-checkpatch:
1069ifndef CHECKPATCH
Etienne Carriere66079b02017-08-23 15:44:01 +02001070 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
Ian Spray36eaaf32014-01-30 17:25:28 +00001071else
1072ifeq (,$(wildcard ${CHECKPATCH}))
Etienne Carriere66079b02017-08-23 15:44:01 +02001073 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
Ian Spray36eaaf32014-01-30 17:25:28 +00001074endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001075endif #(CHECKPATCH)
Ian Spray36eaaf32014-01-30 17:25:28 +00001076
Achin Gupta4f6ad662013-10-25 09:08:21 +01001077clean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001078 $(s)echo " CLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001079 $(q)rm -rf $(BUILD_PLAT)
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +01001080 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1081 $(q)rm -rf ${FIPTOOLPATH}/fiptool
Boyan Karatotevf4595e62025-05-06 17:11:29 +01001082 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1083 $(q)rm -rf ${CRTTOOLPATH}/cert_create
Boyan Karatotev96fbe882025-05-02 16:40:40 +01001084 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001085 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001086
James Morrisseyeaaeece2013-11-01 13:56:59 +00001087realclean distclean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001088 $(s)echo " REALCLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001089 $(q)rm -rf $(BUILD_BASE)
1090 $(q)rm -rf $(CURDIR)/cscope.*
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +01001091 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1092 $(q)rm -rf ${FIPTOOLPATH}/fiptool
Boyan Karatotevf4595e62025-05-06 17:11:29 +01001093 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1094 $(q)rm -rf ${CRTTOOLPATH}/cert_create
Boyan Karatotev96fbe882025-05-02 16:40:40 +01001095 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001096 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001097
Ian Spray36eaaf32014-01-30 17:25:28 +00001098checkcodebase: locate-checkpatch
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001099 $(s)echo " CHECKING STYLE"
1100 $(q)if test -d .git ; then \
Paul Beesley1ef35512019-03-07 16:42:31 +00001101 git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' | \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001102 while read GIT_FILE ; \
1103 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
1104 done ; \
1105 else \
1106 find . -type f -not -iwholename "*.git*" \
1107 -not -iwholename "*build*" \
1108 -not -iwholename "*libfdt*" \
Roberto Vargas61f72a32018-05-08 10:27:10 +01001109 -not -iwholename "*libc*" \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001110 -not -iwholename "*docs*" \
Paul Beesley1ef35512019-03-07 16:42:31 +00001111 -not -iwholename "*.rst" \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001112 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
1113 fi
Ian Spray36eaaf32014-01-30 17:25:28 +00001114
1115checkpatch: locate-checkpatch
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001116 $(s)echo " CHECKING STYLE"
1117 $(q)if test -n "${CHECKPATCH_OPTS}"; then \
Yann Gautier02a76d52019-03-08 15:44:00 +01001118 echo " with ${CHECKPATCH_OPTS} option(s)"; \
1119 fi
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001120 $(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
Yann Gautier77a0a7f2021-11-02 18:03:31 +01001121 for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`; \
1122 do \
Antonio Nino Diaz51d28932018-01-29 12:00:31 +00001123 printf "\n[*] Checking style of '$$commit'\n\n"; \
Yann Gautier1a721742024-08-09 11:52:03 +02001124 ( git log --format=email "$$commit~..$$commit" \
1125 -- ${CHECK_PATHS} ; \
1126 git diff --format=email "$$commit~..$$commit" \
1127 -- ${CHECK_PATHS}; ) | \
Yann Gautier02a76d52019-03-08 15:44:00 +01001128 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \
Antonio Nino Diaz51d28932018-01-29 12:00:31 +00001129 done
Juan Castillo73c99d42015-08-18 14:23:04 +01001130
1131certtool: ${CRTTOOL}
Ian Spray36eaaf32014-01-30 17:25:28 +00001132
Pali Rohára9812202020-11-24 15:38:08 +01001133${CRTTOOL}: FORCE
Boyan Karatotevf4595e62025-05-06 17:11:29 +01001134 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1135 $(q)ln -sf ${CRTTOOL} ${CRTTOOLPATH}/cert_create
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001136 $(s)echo
1137 $(s)echo "Built $@ successfully"
1138 $(s)echo
Juan Castillo73c99d42015-08-18 14:23:04 +01001139
1140ifneq (${GENERATE_COT},0)
Fabien Lehousself02135a2025-06-27 14:36:55 +02001141certificates: ${CRT_DEPS} ${CRTTOOL} ${DTBS}
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001142 $(q)${CRTTOOL} ${CRT_ARGS}
1143 $(s)echo
1144 $(s)echo "Built $@ successfully"
1145 $(s)echo "Certificates can be found in ${BUILD_PLAT}"
1146 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001147endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +01001148
1149${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
Pali Rohár4727fd12020-11-24 16:53:04 +01001150 $(eval ${CHECK_FIP_CMD})
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001151 $(q)${FIPTOOL} create ${FIP_ARGS} $@
1152 $(q)${FIPTOOL} info $@
1153 $(s)echo
1154 $(s)echo "Built $@ successfully"
1155 $(s)echo
Juan Castillo73c99d42015-08-18 14:23:04 +01001156
Yatharth Kochar01912622015-10-12 12:33:47 +01001157ifneq (${GENERATE_COT},0)
1158fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001159 $(q)${CRTTOOL} ${FWU_CRT_ARGS}
1160 $(s)echo
1161 $(s)echo "Built $@ successfully"
1162 $(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1163 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001164endif #(GENERATE_COT)
Yatharth Kochar01912622015-10-12 12:33:47 +01001165
1166${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
Pali Rohár4727fd12020-11-24 16:53:04 +01001167 $(eval ${CHECK_FWU_FIP_CMD})
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001168 $(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1169 $(q)${FIPTOOL} info $@
1170 $(s)echo
1171 $(s)echo "Built $@ successfully"
1172 $(s)echo
Yatharth Kochar01912622015-10-12 12:33:47 +01001173
Juan Castillo73c99d42015-08-18 14:23:04 +01001174fiptool: ${FIPTOOL}
1175fip: ${BUILD_PLAT}/${FIP_NAME}
Yatharth Kochar01912622015-10-12 12:33:47 +01001176fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
Juan Castillo6f971622014-10-21 11:30:42 +01001177
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +01001178# symlink for compatibility before tools were in the build directory
Pali Rohára9812202020-11-24 15:38:08 +01001179${FIPTOOL}: FORCE
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +01001180 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1181 $(q)ln -sf ${FIPTOOL} ${FIPTOOLPATH}/fiptool
Harry Liebelf58ad362014-01-10 18:00:33 +00001182
Manish V Badarkhee4a070e2024-12-03 21:46:51 +00001183$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB)
1184 $(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_SUPPORT=${CRYPTO_SUPPORT} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
Roberto Vargas5accce52018-05-22 16:05:42 +01001185
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001186memmap: all
Chris Kayc25405d2025-03-10 09:24:34 +00001187 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kay4aa3f182025-07-01 15:17:00 +01001188 $(q)$(if $(host-poetry),poetry run )memory --root ${BUILD_PLAT} symbols
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001189
Harrison Mutai2329e222024-08-28 13:27:19 +00001190tl: ${BUILD_PLAT}/tl.bin
1191${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
Chris Kayc25405d2025-03-10 09:24:34 +00001192 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kayd2867392024-09-26 14:18:04 +00001193 $(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
Harrison Mutai2329e222024-08-28 13:27:19 +00001194
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001195doc:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001196 $(s)echo " BUILD DOCUMENTATION"
Harrison Mutaic61c9a32025-05-15 08:47:34 +00001197 $(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1198 $(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} html
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001199
Sumit Garg90aa9012019-11-11 18:46:36 +05301200enctool: ${ENCTOOL}
1201
Pali Rohára9812202020-11-24 15:38:08 +01001202${ENCTOOL}: FORCE
Boyan Karatotev96fbe882025-05-02 16:40:40 +01001203 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001204 $(s)echo
1205 $(s)echo "Built $@ successfully"
1206 $(s)echo
Sumit Garg90aa9012019-11-11 18:46:36 +05301207
Joakim Bech35fab8c2014-01-23 14:51:49 +01001208cscope:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001209 $(s)echo " CSCOPE"
1210 $(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1211 $(q)cscope -b -q -k
Joakim Bech35fab8c2014-01-23 14:51:49 +01001212
Ryan Harkin72ee3312014-01-15 16:55:07 +00001213help:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001214 $(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1215 $(s)echo ""
1216 $(s)echo "PLAT is used to specify which platform you wish to build."
1217 $(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1218 $(s)echo ""
1219 $(s)echo "platform = ${PLATFORM_LIST}"
1220 $(s)echo ""
1221 $(s)echo "Please refer to the User Guide for a list of all supported options."
1222 $(s)echo "Note that the build system doesn't track dependencies for build "
1223 $(s)echo "options. Therefore, if any of the build options are changed "
1224 $(s)echo "from a previous build, a clean build must be performed."
1225 $(s)echo ""
1226 $(s)echo "Supported Targets:"
1227 $(s)echo " all Build all individual bootloader binaries"
1228 $(s)echo " bl1 Build the BL1 binary"
1229 $(s)echo " bl2 Build the BL2 binary"
1230 $(s)echo " bl2u Build the BL2U binary"
1231 $(s)echo " bl31 Build the BL31 binary"
1232 $(s)echo " bl32 Build the BL32 binary. If ARCH=aarch32, then "
1233 $(s)echo " this builds secure payload specified by AARCH32_SP"
1234 $(s)echo " certificates Build the certificates (requires 'GENERATE_COT=1')"
1235 $(s)echo " fip Build the Firmware Image Package (FIP)"
1236 $(s)echo " fwu_fip Build the FWU Firmware Image Package (FIP)"
1237 $(s)echo " checkcodebase Check the coding style of the entire source tree"
1238 $(s)echo " checkpatch Check the coding style on changes in the current"
1239 $(s)echo " branch against BASE_COMMIT (default origin/master)"
1240 $(s)echo " clean Clean the build for the selected platform"
1241 $(s)echo " cscope Generate cscope index"
1242 $(s)echo " distclean Remove all build artifacts for all platforms"
1243 $(s)echo " certtool Build the Certificate generation tool"
1244 $(s)echo " enctool Build the Firmware encryption tool"
1245 $(s)echo " fiptool Build the Firmware Image Package (FIP) creation tool"
1246 $(s)echo " sp Build the Secure Partition Packages"
1247 $(s)echo " sptool Build the Secure Partition Package creation tool"
1248 $(s)echo " dtbs Build the Device Tree Blobs (if required for the platform)"
1249 $(s)echo " memmap Print the memory map of the built binaries"
1250 $(s)echo " doc Build html based documentation using Sphinx tool"
1251 $(s)echo ""
1252 $(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1253 $(s)echo ""
1254 $(s)echo "example: build all targets for the FVP platform:"
1255 $(s)echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
Pali Rohára9812202020-11-24 15:38:08 +01001256
1257.PHONY: FORCE
1258FORCE:;