blob: 6d5a0c35bfae02e0312a07c8e7da84512e7e37dd [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 Raja07a6a652024-11-15 09:56:50 +010011VERSION_MINOR := 12
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
Chris Kayc3273702025-01-13 15:57:32 +0000102CRTTOOL ?= ${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
Chris Kayc3273702025-01-13 15:57:32 +0000106ENCTOOL ?= ${ENCTOOLPATH}/encrypt_fw$(.exe)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100107
108# Variables for use with Firmware Image Package
109FIPTOOLPATH ?= tools/fiptool
Chris Kayc3273702025-01-13 15:57:32 +0000110FIPTOOL ?= ${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
130################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100131# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
132################################################################################
Etienne Carriere26e63c42017-11-08 13:48:40 +0100133ifeq (${ARM_ARCH_MAJOR},7)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100134 target32-directive = -target arm-none-eabi
Govindraj Rajad4089fb2023-05-30 16:52:15 -0500135# Will set march-directive from platform configuration
Etienne Carriere26e63c42017-11-08 13:48:40 +0100136else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100137 target32-directive = -target armv8a-none-eabi
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100138endif #(ARM_ARCH_MAJOR)
139
140################################################################################
141# Get Architecture Feature Modifiers
142################################################################################
143arch-features = ${ARM_ARCH_FEATURE}
144
Chris Kay8620bd02023-12-04 09:55:50 +0000145ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
146 ifeq ($($(ARCH)-cc-id),arm-clang)
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500147 TF_CFLAGS_aarch32 := -target arm-arm-none-eabi
148 TF_CFLAGS_aarch64 := -target aarch64-arm-none-eabi
originc8a992f2022-01-19 16:30:14 +0000149 else
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500150 TF_CFLAGS_aarch32 = $(target32-directive)
Yann Gautieraf8947f2025-01-22 09:43:47 +0100151 TF_CFLAGS_aarch64 := -target aarch64-unknown-none-elf
originc8a992f2022-01-19 16:30:14 +0000152 endif
153
Chris Kay8620bd02023-12-04 09:55:50 +0000154else ifeq ($($(ARCH)-cc-id),gnu-gcc)
Chris Kayfa402f32024-02-20 16:19:54 +0000155 # Enable LTO only for aarch64
156 ifeq (${ARCH},aarch64)
157 LTO_CFLAGS = $(if $(filter-out 0,$(ENABLE_LTO)),-flto)
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600158 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100159endif #(clang)
dp-armd5461852017-05-02 12:00:08 +0100160
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100161# Process Debug flag
162$(eval $(call add_define,DEBUG))
163ifneq (${DEBUG}, 0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100164 BUILD_TYPE := debug
165 TF_CFLAGS += -g -gdwarf-4
166 ASFLAGS += -g -Wa,-gdwarf-4
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100167
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100168 # Use LOG_LEVEL_INFO by default for debug builds
169 LOG_LEVEL := 40
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100170else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100171 BUILD_TYPE := release
172 # Use LOG_LEVEL_NOTICE by default for release builds
173 LOG_LEVEL := 20
174endif #(Debug)
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100175
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800176# Default build string (git branch and commit)
177ifeq (${BUILD_STRING},)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100178 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800179endif
laurenw-armdddf4282022-07-12 10:12:05 -0500180VERSION_STRING := v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800181
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100182ifeq (${AARCH32_INSTRUCTION_SET},A32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100183 TF_CFLAGS_aarch32 += -marm
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100184else ifeq (${AARCH32_INSTRUCTION_SET},T32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100185 TF_CFLAGS_aarch32 += -mthumb
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100186else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100187 $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
188endif #(AARCH32_INSTRUCTION_SET)
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100189
Sandrine Bailleuxa9c4dde2018-07-03 09:14:45 +0200190TF_CFLAGS_aarch32 += -mno-unaligned-access
dp-armd5461852017-05-02 12:00:08 +0100191TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align
Soby Mathew9d29c222016-05-05 14:33:33 +0100192
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100193##############################################################################
194# WARNINGS Configuration
195###############################################################################
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100196# General warnings
197WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
Yann Gautier34b508b2021-05-20 13:18:14 +0200198 -Wdisabled-optimization -Wvla -Wshadow \
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000199 -Wredundant-decls
200# stricter warnings
201WARNINGS += -Wextra -Wno-trigraphs
202# too verbose for generic build
203WARNINGS += -Wno-missing-field-initializers \
204 -Wno-type-limits -Wno-sign-compare \
205# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
206WARNINGS += -Wno-unused-parameter
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100207
208# Additional warnings
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000209# Level 1 - infrequent warnings we should have none of
210# full -Wextra
211WARNING1 += -Wsign-compare
212WARNING1 += -Wtype-limits
213WARNING1 += -Wmissing-field-initializers
Yann Gautiere7c645b2018-12-10 18:00:26 +0100214
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000215# Level 2 - problematic warnings that we want
216# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
217# TODO: disable just for them and move into default build
218WARNING2 += -Wold-style-definition
219WARNING2 += -Wmissing-prototypes
220WARNING2 += -Wmissing-format-attribute
221# TF-A aims to comply with this eventually. Effort too large at present
222WARNING2 += -Wundef
Boyan Karatotevd141e632022-11-21 14:49:05 +0000223# currently very involved and many platforms set this off
224WARNING2 += -Wunused-const-variable=2
Yann Gautiere7c645b2018-12-10 18:00:26 +0100225
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000226# Level 3 - very pedantic, frequently ignored
Yann Gautiere7c645b2018-12-10 18:00:26 +0100227WARNING3 := -Wbad-function-cast
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000228WARNING3 += -Waggregate-return
229WARNING3 += -Wnested-externs
230WARNING3 += -Wcast-align
Yann Gautiere7c645b2018-12-10 18:00:26 +0100231WARNING3 += -Wcast-qual
232WARNING3 += -Wconversion
233WARNING3 += -Wpacked
Yann Gautiere7c645b2018-12-10 18:00:26 +0100234WARNING3 += -Wpointer-arith
Yann Gautiere7c645b2018-12-10 18:00:26 +0100235WARNING3 += -Wswitch-default
Yann Gautiere7c645b2018-12-10 18:00:26 +0100236
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000237# Setting W is quite verbose and most warnings will be pre-existing issues
238# outside of the contributor's control. Don't fail the build on them so warnings
239# can be seen and hopefully addressed
240ifdef W
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100241 ifneq (${W},0)
242 E ?= 0
243 endif
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000244endif
245
Yann Gautiere7c645b2018-12-10 18:00:26 +0100246ifeq (${W},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100247 WARNINGS += $(WARNING1)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100248else ifeq (${W},2)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100249 WARNINGS += $(WARNING1) $(WARNING2)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100250else ifeq (${W},3)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100251 WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
252endif #(W)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100253
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100254# Compiler specific warnings
Chris Kay8620bd02023-12-04 09:55:50 +0000255ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
Justin Chadwell93c690e2019-07-03 14:15:56 +0100256# not using clang
Justin Chadwelld7b4cd42019-09-18 14:13:42 +0100257WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \
258 -Wpacked-bitfield-compat -Wshift-overflow=2 \
259 -Wlogical-op
Govindraj Rajadea23e22023-05-05 09:09:36 -0500260
261# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
Boyan Karatotev316f5c92024-10-10 13:54:37 +0100262TF_CFLAGS_MIN_PAGE_SIZE := $(call cc_option, --param=min-pagesize=0)
263TF_CFLAGS += $(TF_CFLAGS_MIN_PAGE_SIZE)
Govindraj Rajadea23e22023-05-05 09:09:36 -0500264
Bipin Ravi538516f2023-09-28 13:17:24 -0500265ifeq ($(HARDEN_SLS), 1)
Boyan Karatotev316f5c92024-10-10 13:54:37 +0100266 TF_CFLAGS_MHARDEN_SLS := $(call cc_option, -mharden-sls=all)
267 TF_CFLAGS_aarch64 += $(TF_CFLAGS_MHARDEN_SLS)
Bipin Ravi538516f2023-09-28 13:17:24 -0500268endif
269
Justin Chadwell93c690e2019-07-03 14:15:56 +0100270else
271# using clang
Justin Chadwelld7b4cd42019-09-18 14:13:42 +0100272WARNINGS += -Wshift-overflow -Wshift-sign-overflow \
273 -Wlogical-op-parentheses
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100274endif #(Clang Warning)
Ambroise Vincent00296572019-05-24 12:47:43 +0100275
Yann Gautier6336b072018-12-10 18:08:53 +0100276ifneq (${E},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100277 ERRORS := -Werror
278endif #(E)
Yann Gautier6336b072018-12-10 18:08:53 +0100279
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100280################################################################################
281# Compiler and Linker Directives
282################################################################################
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100283CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \
284 $(ERRORS) $(WARNINGS)
Govindraj Rajad4089fb2023-05-30 16:52:15 -0500285ASFLAGS += $(CPPFLAGS) \
Julius Wernerd5dfdeb2019-07-09 13:49:11 -0700286 -ffreestanding -Wa,--fatal-warnings
Masahiro Yamada59de5092016-12-22 12:51:53 +0900287TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \
Samuel Hollandebd6efa2019-10-20 16:11:25 -0500288 -ffunction-sections -fdata-sections \
Boyan Karatotevee0c5b82024-12-09 08:24:12 +0000289 -ffreestanding -fno-common \
Samuel Hollandebd6efa2019-10-20 16:11:25 -0500290 -Os -std=gnu99
Juan Castillo73c99d42015-08-18 14:23:04 +0100291
Justin Chadwell1f461972019-08-20 11:01:52 +0100292ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100293 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover
294endif #(${SANITIZE_UB},on)
295
Justin Chadwell1f461972019-08-20 11:01:52 +0100296ifeq (${SANITIZE_UB},trap)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100297 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \
Justin Chadwell1f461972019-08-20 11:01:52 +0100298 -fsanitize-undefined-trap-on-error
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100299endif #(${SANITIZE_UB},trap)
Justin Chadwell1f461972019-08-20 11:01:52 +0100300
Chris Kay291e7182024-05-14 13:08:31 +0000301GCC_V_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
david cunadof7ec31d2017-11-30 21:58:01 +0000302
Marco Felsch1f49db52022-11-09 12:59:09 +0100303TF_LDFLAGS += -z noexecstack
304
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100305# LD = armlink
Chris Kay8620bd02023-12-04 09:55:50 +0000306ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100307 TF_LDFLAGS += --diag_error=warning --lto_level=O1
308 TF_LDFLAGS += --remove --info=unused,unusedsymbols
309 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH))
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100310
311# LD = gcc (used when GCC LTO is enabled)
Chris Kay8620bd02023-12-04 09:55:50 +0000312else ifeq ($($(ARCH)-ld-id),gnu-gcc)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100313 # Pass ld options with Wl or Xlinker switches
Chris Kay86e489c2024-01-16 11:53:35 +0000314 TF_LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100315 TF_LDFLAGS += -Wl,--fatal-warnings -O1
316 TF_LDFLAGS += -Wl,--gc-sections
Chris Kayac98b822022-12-22 13:26:37 +0000317
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100318 TF_LDFLAGS += -Wl,-z,common-page-size=4096 #Configure page size constants
319 TF_LDFLAGS += -Wl,-z,max-page-size=4096
Andrey Skvortsov304ad942023-09-05 23:06:29 +0300320 TF_LDFLAGS += -Wl,--build-id=none
Chris Kayac98b822022-12-22 13:26:37 +0000321
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100322 ifeq ($(ENABLE_LTO),1)
323 ifeq (${ARCH},aarch64)
324 TF_LDFLAGS += -flto -fuse-linker-plugin
Andrey Skvortsov31f80ef2023-12-08 18:04:51 +0300325 TF_LDFLAGS += -flto-partition=one
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100326 endif
327 endif #(ENABLE_LTO)
328
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600329# GCC automatically adds fix-cortex-a53-843419 flag when used to link
330# which breaks some builds, so disable if errata fix is not explicitly enabled
Yann Gautiercfe67672023-03-15 16:18:16 +0100331 ifeq (${ARCH},aarch64)
332 ifneq (${ERRATA_A53_843419},1)
333 TF_LDFLAGS += -mno-fix-cortex-a53-843419
334 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100335 endif
336 TF_LDFLAGS += -nostdlib
337 TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100338
339# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800340else
Marco Felsch1f49db52022-11-09 12:59:09 +0100341# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
342# are not loaded by a elf loader.
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100343 TF_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
344 TF_LDFLAGS += -O1
345 TF_LDFLAGS += --gc-sections
Chris Kayac98b822022-12-22 13:26:37 +0000346
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100347 TF_LDFLAGS += -z common-page-size=4096 # Configure page size constants
348 TF_LDFLAGS += -z max-page-size=4096
Andrey Skvortsov304ad942023-09-05 23:06:29 +0300349 TF_LDFLAGS += --build-id=none
Chris Kayac98b822022-12-22 13:26:37 +0000350
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100351# ld.lld doesn't recognize the errata flags,
Yabin Cuiebac6922023-01-19 20:06:04 +0000352# therefore don't add those in that case.
353# ld.lld reports section type mismatch warnings,
354# therefore don't add --fatal-warnings to it.
Chris Kay8620bd02023-12-04 09:55:50 +0000355 ifneq ($($(ARCH)-ld-id),llvm-lld)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100356 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) --fatal-warnings
357 endif
358
359endif #(LD = armlink)
Juan Castillo73c99d42015-08-18 14:23:04 +0100360
361################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500362# Setup ARCH_MAJOR/MINOR before parsing arch_features.
363################################################################################
364ifeq (${ENABLE_RME},1)
AlexeiFedorov7d5fc982024-03-13 11:53:44 +0000365 ARM_ARCH_MAJOR := 9
366 ARM_ARCH_MINOR := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500367endif
368
369################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100370# Common sources and include directories
371################################################################################
dp-armd801fbb2017-05-04 12:15:35 +0100372include lib/compiler-rt/compiler-rt.mk
Juan Castillo73c99d42015-08-18 14:23:04 +0100373
Chris Kay758ccb82024-03-08 16:08:31 +0000374# Allow overriding the timestamp, for example for reproducible builds, or to
375# synchronize timestamps across multiple projects.
376# This must be set to a C string (including quotes where applicable).
377BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
378
379DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
380DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
381DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
382
Juan Castillo73c99d42015-08-18 14:23:04 +0100383BL_COMMON_SOURCES += common/bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100384 common/tf_log.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100385 common/${ARCH}/debug.S \
Julius Werner91b48c92018-11-27 22:10:56 -0800386 drivers/console/multi_console.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100387 lib/${ARCH}/cache_helpers.S \
388 lib/${ARCH}/misc_helpers.S \
Boyan Karatotevc73686a2023-02-15 13:21:50 +0000389 lib/extensions/pmuv3/${ARCH}/pmuv3.c \
Soby Mathew566034f2018-02-08 17:45:12 +0000390 plat/common/plat_bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100391 plat/common/plat_log_common.c \
dp-arm75311202017-03-07 11:02:47 +0000392 plat/common/${ARCH}/plat_common.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100393 plat/common/${ARCH}/platform_helpers.S \
Roberto Vargas61f72a32018-05-08 10:27:10 +0100394 ${COMPILER_RT_SRCS}
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000395
Chris Kay8620bd02023-12-04 09:55:50 +0000396ifeq ($($(ARCH)-cc-id),arm-clang)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100397 BL_COMMON_SOURCES += lib/${ARCH}/armclang_printf.S
Antonio Nino Diaz8422a842018-08-16 15:42:44 +0100398endif
399
Justin Chadwell1f461972019-08-20 11:01:52 +0100400ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100401 BL_COMMON_SOURCES += plat/common/ubsan.c
Justin Chadwell1f461972019-08-20 11:01:52 +0100402endif
403
Yann Gautier01d237c2018-06-18 16:00:23 +0200404INCLUDES += -Iinclude \
Antonio Nino Diazf5478de2018-12-17 17:20:57 +0000405 -Iinclude/arch/${ARCH} \
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +0000406 -Iinclude/lib/cpus/${ARCH} \
407 -Iinclude/lib/el3_runtime/${ARCH} \
408 ${PLAT_INCLUDES} \
409 ${SPD_INCLUDES}
410
Nishant Sharmae03dcc82022-08-15 16:37:07 +0100411DTC_FLAGS += -I dts -O dtb
412DTC_CPPFLAGS += -P -nostdinc $(INCLUDES) -Ifdts -undef \
413 -x assembler-with-cpp $(DEFINES)
414
Antonio Nino Diaz9c6d1c52018-11-19 11:48:30 +0000415include common/backtrace/backtrace.mk
416
Juan Castillo73c99d42015-08-18 14:23:04 +0100417################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500418# Generic definitions
419################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500420
421ifeq (${BUILD_BASE},)
422 BUILD_BASE := ./build
423endif
424BUILD_PLAT := $(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
425
426SPDS := $(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
427
428# Platforms providing their own TBB makefile may override this value
429INCLUDE_TBBR_MK := 1
430
431################################################################################
432# Include SPD Makefile if one has been specified
433################################################################################
434
435ifneq (${SPD},none)
Govindraj Raja35472702023-09-20 14:32:24 -0500436 ifeq (${SPD},spmd)
437 # SPMD is located in std_svc directory
438 SPD_DIR := std_svc
439
440 ifeq ($(SPMD_SPM_AT_SEL2),1)
441 CTX_INCLUDE_EL2_REGS := 1
Govindraj Raja35472702023-09-20 14:32:24 -0500442 endif
443
444 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
445 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG
446 endif
447
Arunachalam Ganapathy0686a012022-04-11 14:36:54 +0100448 ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
449 DTC_CPPFLAGS += -DTRUSTY_SP_FW_CONFIG
450 endif
451
Govindraj Raja35472702023-09-20 14:32:24 -0500452 ifeq ($(TS_SP_FW_CONFIG),1)
Arunachalam Ganapathy0686a012022-04-11 14:36:54 +0100453 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG
Govindraj Raja35472702023-09-20 14:32:24 -0500454 endif
455
456 ifneq ($(ARM_BL2_SP_LIST_DTS),)
457 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
458 endif
459
460 ifneq ($(SP_LAYOUT_FILE),)
461 BL2_ENABLE_SP_LOAD := 1
462 endif
463 else
464 # All other SPDs in spd directory
465 SPD_DIR := spd
466 endif #(SPD)
467
468 # We expect to locate an spd.mk under the specified SPD directory
469 SPD_MAKE := $(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
470
471 ifeq (${SPD_MAKE},)
472 $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
473 endif
474 $(info Including ${SPD_MAKE})
475 include ${SPD_MAKE}
476
477 # If there's BL32 companion for the chosen SPD, we expect that the SPD's
478 # Makefile would set NEED_BL32 to "yes". In this case, the build system
479 # supports two mutually exclusive options:
480 # * BL32 is built from source: then BL32_SOURCES must contain the list
481 # of source files to build BL32
482 # * BL32 is a prebuilt binary: then BL32 must point to the image file
483 # that will be included in the FIP
484 # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
485 # over the sources.
486endif #(SPD=none)
487
Govindraj Raja35472702023-09-20 14:32:24 -0500488################################################################################
Olivier Deprez696ed162025-01-03 13:38:50 +0100489# Include the platform specific Makefile after the SPD Makefile (the platform
490# makefile may use all previous definitions in this file)
491################################################################################
492include ${PLAT_MAKEFILE_FULL}
493
494################################################################################
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100495# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
496# platform.
497################################################################################
498
499include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
500################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500501# Process BRANCH_PROTECTION value and set
502# Pointer Authentication and Branch Target Identification flags
503################################################################################
504ifeq (${BRANCH_PROTECTION},0)
505 # Default value turns off all types of branch protection
506 BP_OPTION := none
507else ifneq (${ARCH},aarch64)
508 $(error BRANCH_PROTECTION requires AArch64)
509else ifeq (${BRANCH_PROTECTION},1)
510 # Enables all types of branch protection features
511 BP_OPTION := standard
512 ENABLE_BTI := 1
513 ENABLE_PAUTH := 1
514else ifeq (${BRANCH_PROTECTION},2)
515 # Return address signing to its standard level
516 BP_OPTION := pac-ret
517 ENABLE_PAUTH := 1
518else ifeq (${BRANCH_PROTECTION},3)
519 # Extend the signing to include leaf functions
520 BP_OPTION := pac-ret+leaf
521 ENABLE_PAUTH := 1
522else ifeq (${BRANCH_PROTECTION},4)
523 # Turn on branch target identification mechanism
524 BP_OPTION := bti
525 ENABLE_BTI := 1
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100526else ifeq (${BRANCH_PROTECTION},5)
527 # Turn on branch target identification mechanism
528 BP_OPTION := standard
529 ENABLE_BTI := 2
530 ENABLE_PAUTH := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500531else
532 $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
533endif #(BRANCH_PROTECTION)
534
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100535ifneq ($(ENABLE_PAUTH),0)
536 CTX_INCLUDE_PAUTH_REGS := ${ENABLE_PAUTH}
Govindraj Rajaf5211422023-08-17 10:41:48 -0500537endif
538ifneq (${BP_OPTION},none)
539 TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION}
540endif #(BP_OPTION)
541
542# Pointer Authentication sources
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100543ifneq (${ENABLE_PAUTH},0)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500544# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
545# Pauth support. As it's not secure, it must be reimplemented for real platforms
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100546 BL_COMMON_SOURCES += lib/extensions/pauth/pauth.c
Govindraj Rajaf5211422023-08-17 10:41:48 -0500547endif
548
549####################################################
550# Enable required options for Memory Stack Tagging.
551####################################################
552
553# Currently, these options are enabled only for clang and armclang compiler.
554ifeq (${SUPPORT_STACK_MEMTAG},yes)
555 ifdef mem_tag_arch_support
556 # Check for armclang and clang compilers
Chris Kay8620bd02023-12-04 09:55:50 +0000557 ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500558 # Add "memtag" architecture feature modifier if not specified
559 ifeq ( ,$(findstring memtag,$(arch-features)))
560 arch-features := $(arch-features)+memtag
561 endif # memtag
Chris Kay8620bd02023-12-04 09:55:50 +0000562 ifeq ($($(ARCH)-cc-id),arm-clang)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500563 TF_CFLAGS += -mmemtag-stack
Chris Kay8620bd02023-12-04 09:55:50 +0000564 else ifeq ($($(ARCH)-cc-id),llvm-clang)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500565 TF_CFLAGS += -fsanitize=memtag
566 endif # armclang
567 endif
568 else
569 $(error "Error: stack memory tagging is not supported for \
570 architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
571 endif #(mem_tag_arch_support)
572endif #(SUPPORT_STACK_MEMTAG)
573
574################################################################################
575# RME dependent flags configuration, Enable optional features for RME.
576################################################################################
577# FEAT_RME
578ifeq (${ENABLE_RME},1)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500579 # RME requires AARCH64
580 ifneq (${ARCH},aarch64)
581 $(error ENABLE_RME requires AArch64)
582 endif
583
584 # RME requires el2 context to be saved for now.
585 CTX_INCLUDE_EL2_REGS := 1
586 CTX_INCLUDE_AARCH32_REGS := 0
587 CTX_INCLUDE_PAUTH_REGS := 1
588
Javier Almansa Sobrinod048af02025-03-21 18:32:10 +0000589 ifneq ($(ENABLE_FEAT_MPAM), 0)
590 CTX_INCLUDE_MPAM_REGS := 1
591 endif
592
Govindraj Rajaf5211422023-08-17 10:41:48 -0500593 # RME enables CSV2_2 extension by default.
594 ENABLE_FEAT_CSV2_2 = 1
595endif #(FEAT_RME)
596
597################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500598# Include rmmd Makefile if RME is enabled
599################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500600ifneq (${ENABLE_RME},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100601 ifneq (${ARCH},aarch64)
602 $(error ENABLE_RME requires AArch64)
603 endif
604 ifeq ($(SPMC_AT_EL3),1)
605 $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
606 endif
607
608 ifneq (${SPD}, none)
609 ifneq (${SPD}, spmd)
610 $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
611 endif
612 endif
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500613include services/std_svc/rmmd/rmmd.mk
614$(warning "RME is an experimental feature")
615endif
616
Govindraj Raja35472702023-09-20 14:32:24 -0500617ifeq (${CTX_INCLUDE_EL2_REGS}, 1)
618 ifeq (${SPD},none)
619 ifeq (${ENABLE_RME},0)
620 $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
621 or RME is enabled)
622 endif
623 endif
624endif
Juan Castillo0f21c542014-06-25 17:26:36 +0100625
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500626################################################################################
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000627# Verify FEAT_RME, FEAT_SCTLR2 and FEAT_TCR2 are enabled if FEAT_MEC is enabled.
628################################################################################
629
630ifneq (${ENABLE_FEAT_MEC},0)
631 ifeq (${ENABLE_RME},0)
632 $(error FEAT_RME must be enabled when FEAT_MEC is enabled.)
633 endif
634 ifeq (${ENABLE_FEAT_TCR2},0)
635 $(error FEAT_TCR2 must be enabled when FEAT_MEC is enabled.)
636 endif
637 ifeq (${ENABLE_FEAT_SCTLR2},0)
638 $(error FEAT_SCTLR2 must be enabled when FEAT_MEC is enabled.)
639 endif
640endif
641
642################################################################################
Govindraj Raja30655132024-09-06 15:43:43 +0100643# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
644################################################################################
645ifneq (${ENABLE_FEAT_D128}, 0)
646 BL_COMMON_SOURCES += lib/extensions/sysreg128/sysreg128.S
647endif
648
649################################################################################
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500650# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
651# up with appropriate march values for compiler.
652################################################################################
653include ${MAKE_HELPERS_DIRECTORY}march.mk
654
655TF_CFLAGS += $(march-directive)
Govindraj Raja7275ac22024-01-23 16:00:19 -0600656ASFLAGS += $(march-directive)
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500657
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600658# This internal flag is common option which is set to 1 for scenarios
659# when the BL2 is running in EL3 level. This occurs in two scenarios -
660# 4 world system running BL2 at EL3 and two world system without BL1 running
661# BL2 in EL3
662
663ifeq (${RESET_TO_BL2},1)
664 BL2_RUNS_AT_EL3 := 1
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100665 ifeq (${ENABLE_RME},1)
666 $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
667 supported at the moment.)
668 endif
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600669else ifeq (${ENABLE_RME},1)
670 BL2_RUNS_AT_EL3 := 1
671else
672 BL2_RUNS_AT_EL3 := 0
673endif
674
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100675# This internal flag is set to 1 when Firmware First handling of External aborts
676# is required by lowe ELs. Currently only NS requires this support.
677ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
678 FFH_SUPPORT := 1
679else
680 FFH_SUPPORT := 0
681endif
682
Etienne Carriere26e63c42017-11-08 13:48:40 +0100683ifeq (${ARM_ARCH_MAJOR},7)
684include make_helpers/armv7-a-cpus.mk
685endif
686
Masahiro Yamada320920c2020-01-17 13:44:37 +0900687PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
688ifneq ($(PIE_FOUND),)
689 TF_CFLAGS += -fno-PIE
Chris Kay8620bd02023-12-04 09:55:50 +0000690ifeq ($($(ARCH)-ld-id),gnu-gcc)
Samuel Holland7b592412022-04-08 21:56:02 -0500691 TF_LDFLAGS += -no-pie
692endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100693endif #(PIE_FOUND)
Masahiro Yamada320920c2020-01-17 13:44:37 +0900694
Chris Kay8620bd02023-12-04 09:55:50 +0000695ifeq ($($(ARCH)-ld-id),gnu-gcc)
Masahiro Yamada320920c2020-01-17 13:44:37 +0900696 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
Soby Mathew3bd17c02018-08-28 11:13:55 +0100697else
Masahiro Yamada320920c2020-01-17 13:44:37 +0900698 PIE_LDFLAGS += -pie --no-dynamic-linker
699endif
700
701ifeq ($(ENABLE_PIE),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100702 ifeq ($(RESET_TO_BL2),1)
703 ifneq ($(BL2_IN_XIP_MEM),1)
704 BL2_CPPFLAGS += -fpie
705 BL2_CFLAGS += -fpie
706 BL2_LDFLAGS += $(PIE_LDFLAGS)
707 endif #(BL2_IN_XIP_MEM)
708 endif #(RESET_TO_BL2)
Chris Kay966660e2023-02-02 14:39:03 +0000709 BL31_CPPFLAGS += -fpie
710 BL31_CFLAGS += -fpie
Masahiro Yamada320920c2020-01-17 13:44:37 +0900711 BL31_LDFLAGS += $(PIE_LDFLAGS)
Chris Kay966660e2023-02-02 14:39:03 +0000712
713 BL32_CPPFLAGS += -fpie
Masahiro Yamadad9743012020-01-17 13:45:14 +0900714 BL32_CFLAGS += -fpie
715 BL32_LDFLAGS += $(PIE_LDFLAGS)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100716endif #(ENABLE_PIE)
Soby Mathew3bd17c02018-08-28 11:13:55 +0100717
Boyan Karatotev007433d2023-01-25 16:55:18 +0000718BL1_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
719BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
720BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
721
Masahiro Yamada9cefb4b2020-04-01 14:20:58 +0900722BL1_CPPFLAGS += -DIMAGE_AT_EL3
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600723ifeq ($(RESET_TO_BL2),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100724 BL2_CPPFLAGS += -DIMAGE_AT_EL3
Masahiro Yamadad5e97a12020-03-26 13:18:48 +0900725else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100726 BL2_CPPFLAGS += -DIMAGE_AT_EL1
727endif #(RESET_TO_BL2)
Boyan Karatotev007433d2023-01-25 16:55:18 +0000728
729ifeq (${ARCH},aarch64)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100730 BL2U_CPPFLAGS += -DIMAGE_AT_EL1
731 BL31_CPPFLAGS += -DIMAGE_AT_EL3
732 BL32_CPPFLAGS += -DIMAGE_AT_EL1
Boyan Karatotev007433d2023-01-25 16:55:18 +0000733else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100734 BL32_CPPFLAGS += -DIMAGE_AT_EL3
Masahiro Yamadad5e97a12020-03-26 13:18:48 +0900735endif
736
Sandrine Bailleux54035fc2016-01-13 14:57:38 +0000737# Include the CPU specific operations makefile, which provides default
738# values for all CPU errata workarounds and CPU specific optimisations.
739# This can be overridden by the platform.
Juan Castillo73c99d42015-08-18 14:23:04 +0100740include lib/cpus/cpu-ops.mk
Achin Gupta4f6ad662013-10-25 09:08:21 +0100741
dp-arma4409002017-02-15 11:07:55 +0000742################################################################################
743# Build `AARCH32_SP` as BL32 image for AArch32
744################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100745ifeq (${ARCH},aarch32)
746 NEED_BL32 := yes
dp-arma4409002017-02-15 11:07:55 +0000747
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100748 ifneq (${AARCH32_SP},none)
749 # We expect to locate an sp.mk under the specified AARCH32_SP directory
750 AARCH32_SP_MAKE := $(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
dp-arma4409002017-02-15 11:07:55 +0000751
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100752 ifeq (${AARCH32_SP_MAKE},)
753 $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
754 endif
Juan Pablo Conde043f38f2023-08-09 13:19:21 -0500755 $(info Including ${AARCH32_SP_MAKE})
756 include ${AARCH32_SP_MAKE}
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100757 endif
758endif #(ARCH=aarch32)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100759
Juan Castillo73c99d42015-08-18 14:23:04 +0100760################################################################################
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800761# Include libc if not overridden
762################################################################################
763ifeq (${OVERRIDE_LIBC},0)
764include lib/libc/libc.mk
765endif
766
Boyan Karatotev5d893412025-01-07 11:00:03 +0000767ifneq (${USE_GIC_DRIVER},0)
768include drivers/arm/gic/gic.mk
769endif
770
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800771################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100772# Check incompatible options and dependencies
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000773################################################################################
774
Govindraj Rajaa0effb92025-02-20 17:15:39 -0600775# Handle all invalid build configurations with SPMD usage.
776ifeq (${ENABLE_SPMD_LP}, 1)
777ifneq (${SPD},spmd)
778 $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
779endif
780ifeq ($(SPMC_AT_EL3),1)
781 $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
782endif
783endif
784
785ifneq (${SPD},none)
786ifeq (${ARCH},aarch32)
787 $(error "Error: SPD is incompatible with AArch32.")
788endif
789ifdef EL3_PAYLOAD_BASE
790 $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
791 $(warning "The SPD and its BL32 companion will be present but ignored.")
792endif
793ifeq (${SPD},spmd)
794ifeq ($(SPMD_SPM_AT_SEL2),1)
795 ifeq ($(SPMC_AT_EL3),1)
796 $(error SPM cannot be enabled in both S-EL2 and EL3.)
797 endif
798 ifeq ($(CTX_INCLUDE_SVE_REGS),1)
799 $(error SVE context management not needed with Hafnium SPMC.)
800 endif
801endif
802
803ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
804 ifneq ($(SPMC_AT_EL3),1)
805 $(error SEL0 SP cannot be enabled without SPMC at EL3)
806 endif
807endif
808endif #(SPD=spmd)
809endif #(SPD!=none)
810
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100811# USE_DEBUGFS experimental feature recommended only in debug builds
812ifeq (${USE_DEBUGFS},1)
813 ifeq (${DEBUG},1)
814 $(warning DEBUGFS experimental feature is enabled.)
815 else
816 $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000817 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100818endif #(USE_DEBUGFS)
819
820# USE_SPINLOCK_CAS requires AArch64 build
821ifeq (${USE_SPINLOCK_CAS},1)
822 ifneq (${ARCH},aarch64)
823 $(error USE_SPINLOCK_CAS requires AArch64)
Qixiang Xu76580f32017-08-24 11:03:23 +0800824 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100825endif #(USE_SPINLOCK_CAS)
826
827# The cert_create tool cannot generate certificates individually, so we use the
828# target 'certificates' to create them all
829ifneq (${GENERATE_COT},0)
830 FIP_DEPS += certificates
831 FWU_FIP_DEPS += fwu_certificates
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000832endif
833
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100834ifneq (${DECRYPTION_SUPPORT},none)
835 ENC_ARGS += -f ${FW_ENC_STATUS}
836 ENC_ARGS += -k ${ENC_KEY}
837 ENC_ARGS += -n ${ENC_NONCE}
838 FIP_DEPS += enctool
839 FWU_FIP_DEPS += enctool
840endif #(DECRYPTION_SUPPORT)
841
842ifdef EL3_PAYLOAD_BASE
843 ifdef PRELOADED_BL33_BASE
844 $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
845 incompatible build options. EL3_PAYLOAD_BASE has priority.")
846 endif
847 ifneq (${GENERATE_COT},0)
848 $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
849 build options.")
850 endif
851 ifneq (${TRUSTED_BOARD_BOOT},0)
852 $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
853 incompatible \ build options.")
854 endif
855endif #(EL3_PAYLOAD_BASE)
856
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000857ifeq (${NEED_BL33},yes)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100858 ifdef EL3_PAYLOAD_BASE
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000859 $(warning "BL33 image is not needed when option \
860 BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100861 endif
862 ifdef PRELOADED_BL33_BASE
Antonio Nino Diaz68450a62016-04-06 17:31:57 +0100863 $(warning "BL33 image is not needed when option \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100864 PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
865 endif
866endif #(NEED_BL33)
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000867
Jeenu Viswambharand4593e42017-01-06 16:14:42 +0000868# When building for systems with hardware-assisted coherency, there's no need to
869# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
870ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100871 $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
Jeenu Viswambharand4593e42017-01-06 16:14:42 +0000872endif
Yatharth Kochar1a0a3f02016-06-28 16:58:26 +0100873
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600874#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
875ifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100876 $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
Jiafei Pan7d173fc2018-03-21 07:20:09 +0000877endif
878
Manish Pandey9202d512023-02-13 12:39:17 +0000879# RAS_EXTENSION is deprecated, provide alternate build options
Jeenu Viswambharan14c60162018-04-04 16:07:11 +0100880ifeq ($(RAS_EXTENSION),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100881 $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100882 and HANDLE_EA_EL3_FIRST_NS instead")
Manish Pandey9202d512023-02-13 12:39:17 +0000883endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100884
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100885
Manish Pandey9202d512023-02-13 12:39:17 +0000886# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
Jeenu Viswambharan1a7c1cf2017-12-08 12:13:51 +0000887ifeq ($(FAULT_INJECTION_SUPPORT),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100888 ifeq ($(ENABLE_FEAT_RAS),0)
889 $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
890 endif
891endif #(FAULT_INJECTION_SUPPORT)
Jeenu Viswambharan1a7c1cf2017-12-08 12:13:51 +0000892
Roberto Vargased51b512018-09-24 17:20:48 +0100893# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
Soby Mathew209a60c2018-03-26 12:43:37 +0100894ifeq ($(DYN_DISABLE_AUTH), 1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100895 ifeq (${TRUSTED_BOARD_BOOT}, 0)
896 $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
897 to be set.")
898 endif
899endif #(DYN_DISABLE_AUTH)
Soby Mathew209a60c2018-03-26 12:43:37 +0100900
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100901ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
902# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100903 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100904else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
905# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100906 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100907else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
908# Support hash calculation only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100909 CRYPTO_SUPPORT := 2
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100910else ifeq (${TRUSTED_BOARD_BOOT},1)
911# Support authentication verification only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100912 CRYPTO_SUPPORT := 1
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000913else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100914 CRYPTO_SUPPORT := 0
915endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000916
Manish V Badarkhee4a070e2024-12-03 21:46:51 +0000917ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
918CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
919endif
920
Balint Dobszaycbf9e842019-12-18 15:28:00 +0100921# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
922ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100923 $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
Manish V Badarkhe84ef9cd2020-06-29 10:32:53 +0100924endif
925
Antonio Nino Diazb86048c2019-02-19 11:53:51 +0000926# If pointer authentication is used in the firmware, make sure that all the
Alexei Fedorov9fc59632019-05-24 12:17:09 +0100927# registers associated to it are also saved and restored.
928# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100929ifneq ($(ENABLE_PAUTH),0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100930 ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100931 $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS to be enabled)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100932 endif
933endif #(ENABLE_PAUTH)
Alexei Fedorov9fc59632019-05-24 12:17:09 +0100934
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100935ifneq ($(CTX_INCLUDE_PAUTH_REGS),0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100936 ifneq (${ARCH},aarch64)
937 $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
938 endif
939endif #(CTX_INCLUDE_PAUTH_REGS)
Alexei Fedorov9fc59632019-05-24 12:17:09 +0100940
Jayanth Dodderi Chidanand6a0da732022-01-17 18:57:17 +0000941ifeq ($(FEATURE_DETECTION),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100942 $(info FEATURE_DETECTION is an experimental feature)
943endif #(FEATURE_DETECTION)
Jayanth Dodderi Chidanand6a0da732022-01-17 18:57:17 +0000944
Jayanth Dodderi Chidanand03d3c0d2022-11-08 10:31:07 +0000945ifneq ($(ENABLE_SME2_FOR_NS), 0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100946 ifeq (${ENABLE_SME_FOR_NS}, 0)
947 $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
948 to be set")
949 $(warning "Forced ENABLE_SME_FOR_NS=1")
950 override ENABLE_SME_FOR_NS := 1
951 endif
952endif #(ENABLE_SME2_FOR_NS)
Jayanth Dodderi Chidanand45007ac2023-03-06 23:56:14 +0000953
Petre-Ionut Tudor60e8f3c2019-11-07 15:18:03 +0000954ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100955 ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
956 $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
957 library v2")
958 endif
959endif #(ARM_XLAT_TABLES_LIB_V1)
Petre-Ionut Tudor60e8f3c2019-11-07 15:18:03 +0000960
Sumit Garg7cda17b2019-11-15 10:43:00 +0530961ifneq (${DECRYPTION_SUPPORT},none)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100962 ifeq (${TRUSTED_BOARD_BOOT}, 0)
963 $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
964 to be set)
965 endif
966endif #(DECRYPTION_SUPPORT)
Sumit Garg7cda17b2019-11-15 10:43:00 +0530967
johpow01744ad972022-01-28 17:06:20 -0600968# Ensure that no Aarch64-only features are enabled in Aarch32 build
johpow01dc78e622021-07-08 14:14:00 -0500969ifeq (${ARCH},aarch32)
johpow01744ad972022-01-28 17:06:20 -0600970
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100971 # SME/SVE only supported on AArch64
972 ifneq (${ENABLE_SME_FOR_NS},0)
973 $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
974 endif
Jayanth Dodderi Chidanand03d3c0d2022-11-08 10:31:07 +0000975
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100976 ifeq (${ENABLE_SVE_FOR_NS},1)
977 # Warning instead of error due to CI dependency on this
978 $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
979 endif
johpow01744ad972022-01-28 17:06:20 -0600980
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100981 # BRBE is not supported in AArch32
982 ifeq (${ENABLE_BRBE_FOR_NS},1)
983 $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
984 endif
johpow01744ad972022-01-28 17:06:20 -0600985
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100986 # FEAT_RNG_TRAP is not supported in AArch32
987 ifeq (${ENABLE_FEAT_RNG_TRAP},1)
988 $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
989 endif
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600990
991 ifneq (${ENABLE_FEAT_FPMR},0)
992 $(error "ENABLE_FEAT_FPMR cannot be used with ARCH=aarch32")
993 endif
Boyan Karatotev8db17052024-10-25 11:38:41 +0100994
995 ifeq (${ARCH_FEATURE_AVAILABILITY},1)
996 $(error "ARCH_FEATURE_AVAILABILITY cannot be used with ARCH=aarch32")
997 endif
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -0600998 # FEAT_MOPS is only supported on AArch64
999 ifneq (${ENABLE_FEAT_MOPS},0)
1000 $(error "ENABLE_FEAT_MOPS cannot be used with ARCH=aarch32")
1001 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001002endif #(ARCH=aarch32)
johpow01dc78e622021-07-08 14:14:00 -05001003
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -06001004ifneq (${ENABLE_FEAT_FPMR},0)
1005 ifeq (${ENABLE_FEAT_FGT},0)
1006 $(error "ENABLE_FEAT_FPMR requires ENABLE_FEAT_FGT")
1007 endif
1008 ifeq (${ENABLE_FEAT_HCX},0)
1009 $(error "ENABLE_FEAT_FPMR requires ENABLE_FEAT_HCX")
1010 endif
1011endif #(ENABLE_FEAT_FPMR)
1012
Boyan Karatotev0d122942023-03-08 16:29:26 +00001013ifneq (${ENABLE_SME_FOR_NS},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001014 ifeq (${ENABLE_SVE_FOR_NS},0)
1015 $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
1016 endif
1017endif #(ENABLE_SME_FOR_NS)
Boyan Karatotev0d122942023-03-08 16:29:26 +00001018
johpow01dc78e622021-07-08 14:14:00 -05001019# Secure SME/SVE requires the non-secure component as well
1020ifeq (${ENABLE_SME_FOR_SWD},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001021 ifeq (${ENABLE_SME_FOR_NS},0)
1022 $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
1023 endif
1024 ifeq (${ENABLE_SVE_FOR_SWD},0)
1025 $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
1026 endif
1027endif #(ENABLE_SME_FOR_SWD)
1028
Madhukar Pappireddy3524d072024-06-17 15:28:33 -05001029# Enabling SVE for SWD requires enabling SVE for NWD due to ENABLE_FEAT
1030# mechanism.
johpow01dc78e622021-07-08 14:14:00 -05001031ifeq (${ENABLE_SVE_FOR_SWD},1)
Madhukar Pappireddy3524d072024-06-17 15:28:33 -05001032 ifeq (${ENABLE_SVE_FOR_NS},0)
1033 $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1034 endif
1035endif
johpow01dc78e622021-07-08 14:14:00 -05001036
Arvind Ram Prakash484befb2025-03-12 16:45:05 -05001037# Enabling FEAT_MOPS requires access to hcrx_el2 registers which is
1038# available only when FEAT_HCX is enabled.
1039ifneq (${ENABLE_FEAT_MOPS},0)
1040 ifeq (${ENABLE_FEAT_HCX},0)
1041 $(error "ENABLE_FEAT_MOPS requires ENABLE_FEAT_HCX")
1042 endif
1043endif
1044
Madhukar Pappireddy3524d072024-06-17 15:28:33 -05001045# Enabling SVE for both the worlds typically requires the context
1046# management of SVE registers. The only exception being SPMC at S-EL2.
1047ifeq (${ENABLE_SVE_FOR_SWD}, 1)
1048 ifneq (${ENABLE_SVE_FOR_NS}, 0)
1049 ifeq (${CTX_INCLUDE_SVE_REGS}-$(SPMD_SPM_AT_SEL2),0-0)
1050 $(warning "ENABLE_SVE_FOR_SWD and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
1051 endif
1052 endif
1053endif
1054
1055# Enabling SVE in either world while enabling CTX_INCLUDE_FPREGS requires
1056# CTX_INCLUDE_SVE_REGS to be enabled due to architectural dependency between FP
1057# and SVE registers.
1058ifeq (${CTX_INCLUDE_FPREGS}, 1)
1059 ifneq (${ENABLE_SVE_FOR_NS},0)
1060 ifeq (${CTX_INCLUDE_SVE_REGS},0)
1061 # Warning instead of error due to CI dependency on this
1062 $(warning "CTX_INCLUDE_FPREGS and ENABLE_SVE_FOR_NS together require CTX_INCLUDE_SVE_REGS")
1063 $(warning "Forced ENABLE_SVE_FOR_NS=0")
1064 override ENABLE_SVE_FOR_NS := 0
1065 endif
1066 endif
1067endif #(CTX_INCLUDE_FPREGS)
1068
1069# SVE context management is only required if secure world has access to SVE/FP
1070# functionality.
1071ifeq (${CTX_INCLUDE_SVE_REGS},1)
1072 ifeq (${ENABLE_SVE_FOR_SWD},0)
1073 $(error "CTX_INCLUDE_SVE_REGS requires ENABLE_SVE_FOR_SWD to also be enabled")
1074 endif
1075endif
1076
1077# SME cannot be used with CTX_INCLUDE_FPREGS since SPM does its own context
1078# management including FPU registers.
johpow01dc78e622021-07-08 14:14:00 -05001079ifeq (${CTX_INCLUDE_FPREGS},1)
Madhukar Pappireddy3524d072024-06-17 15:28:33 -05001080 ifneq (${ENABLE_SME_FOR_NS},0)
1081 $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1082 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001083endif #(CTX_INCLUDE_FPREGS)
johpow01dc78e622021-07-08 14:14:00 -05001084
Manish V Badarkhe00e28872022-03-02 12:06:35 +00001085ifeq ($(DRTM_SUPPORT),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001086 $(info DRTM_SUPPORT is an experimental feature)
Manish V Badarkhe00e28872022-03-02 12:06:35 +00001087endif
1088
Levi Yun89535682024-05-13 10:24:31 +01001089ifeq (${HOB_LIST},1)
1090 $(warning HOB_LIST is an experimental feature)
1091endif
1092
Raymond Mao3ba2c152023-07-25 07:53:35 -07001093ifeq (${TRANSFER_LIST},1)
1094 $(info TRANSFER_LIST is an experimental feature)
1095endif
1096
Chris Kay274a69e2022-09-29 16:21:24 +01001097ifeq (${ENABLE_RME},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001098 ifneq (${SEPARATE_CODE_AND_RODATA},1)
1099 $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1100 endif
Chris Kay274a69e2022-09-29 16:21:24 +01001101endif
1102
Manish V Badarkhe5782b892023-09-06 09:08:28 +01001103ifeq ($(PSA_CRYPTO),1)
1104 $(info PSA_CRYPTO is an experimental feature)
1105endif
1106
Manish V Badarkhe82222db2024-05-09 12:14:13 +01001107ifeq ($(DICE_PROTECTION_ENVIRONMENT),1)
1108 $(info DICE_PROTECTION_ENVIRONMENT is an experimental feature)
1109endif
1110
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001111################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +01001112# Process platform overrideable behaviour
1113################################################################################
Achin Gupta4f6ad662013-10-25 09:08:21 +01001114
Manish Pandey5f24ce92021-10-06 10:59:52 +01001115ifdef BL1_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001116 NEED_BL1 := yes
1117endif #(BL1_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +01001118
Juan Castillo73c99d42015-08-18 14:23:04 +01001119ifdef BL2_SOURCES
Manish Pandey5f24ce92021-10-06 10:59:52 +01001120 NEED_BL2 := yes
1121
1122 # Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1123 # Certificate generation tools. This flag can be overridden by the platform.
1124 ifdef EL3_PAYLOAD_BASE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001125 # If booting an EL3 payload there is no need for a BL33 image
1126 # in the FIP file.
1127 NEED_BL33 := no
1128 else
1129 ifdef PRELOADED_BL33_BASE
1130 # If booting a BL33 preloaded image there is no need of
1131 # another one in the FIP file.
1132 NEED_BL33 := no
1133 else
1134 NEED_BL33 ?= yes
1135 endif
1136 endif
1137endif #(BL2_SOURCES)
Juan Castillo73c99d42015-08-18 14:23:04 +01001138
Manish Pandey5f24ce92021-10-06 10:59:52 +01001139ifdef BL2U_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001140 NEED_BL2U := yes
1141endif #(BL2U_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +01001142
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001143# If SCP_BL2 is given, we always want FIP to include it.
1144ifdef SCP_BL2
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001145 NEED_SCP_BL2 := yes
1146endif #(SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001147
Soby Mathew5744e872017-11-14 14:10:10 +00001148# For AArch32, BL31 is not currently supported.
1149ifneq (${ARCH},aarch32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001150 ifdef BL31_SOURCES
1151 # When booting an EL3 payload, there is no need to compile the BL31
1152 # image nor put it in the FIP.
1153 ifndef EL3_PAYLOAD_BASE
1154 NEED_BL31 := yes
1155 endif
1156 endif
1157endif #(ARCH=aarch64)
Soby Mathew5744e872017-11-14 14:10:10 +00001158
Juan Castillo73c99d42015-08-18 14:23:04 +01001159# Process TBB related flags
1160ifneq (${GENERATE_COT},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001161 # Common cert_create options
1162 ifneq (${CREATE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +01001163 $(eval CRT_ARGS += -n)
Yatharth Kochar01912622015-10-12 12:33:47 +01001164 $(eval FWU_CRT_ARGS += -n)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001165 ifneq (${SAVE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +01001166 $(eval CRT_ARGS += -k)
Yatharth Kochar01912622015-10-12 12:33:47 +01001167 $(eval FWU_CRT_ARGS += -k)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001168 endif
1169 endif
1170 # Include TBBR makefile (unless the platform indicates otherwise)
1171 ifeq (${INCLUDE_TBBR_MK},1)
Juan Castillo73c99d42015-08-18 14:23:04 +01001172 include make_helpers/tbbr/tbbr_tools.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001173 endif
1174endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +01001175
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +09001176ifneq (${FIP_ALIGN},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001177 FIP_ARGS += --align ${FIP_ALIGN}
1178endif #(FIP_ALIGN)
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +09001179
Manish Pandey5f24ce92021-10-06 10:59:52 +01001180ifdef FDT_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001181 NEED_FDT := yes
1182endif #(FDT_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +01001183
Juan Castillo73c99d42015-08-18 14:23:04 +01001184################################################################################
Michalis Pappas46e5e032018-03-20 13:01:27 +08001185# Include libraries' Makefile that are used in all BL
1186################################################################################
1187
1188include lib/stack_protector/stack_protector.mk
1189
1190################################################################################
Soby Mathew8a860522017-02-14 10:05:07 +00001191# Include BL specific makefiles
1192################################################################################
Manish Pandey5f24ce92021-10-06 10:59:52 +01001193
1194ifeq (${NEED_BL1},yes)
Soby Mathew8a860522017-02-14 10:05:07 +00001195include bl1/bl1.mk
1196endif
1197
Manish Pandey5f24ce92021-10-06 10:59:52 +01001198ifeq (${NEED_BL2},yes)
Soby Mathew8a860522017-02-14 10:05:07 +00001199include bl2/bl2.mk
1200endif
1201
Manish Pandey5f24ce92021-10-06 10:59:52 +01001202ifeq (${NEED_BL2U},yes)
Soby Mathew8a860522017-02-14 10:05:07 +00001203include bl2u/bl2u.mk
1204endif
1205
Soby Mathew5744e872017-11-14 14:10:10 +00001206ifeq (${NEED_BL31},yes)
Soby Mathew8a860522017-02-14 10:05:07 +00001207include bl31/bl31.mk
1208endif
Nishanth Menon03b397a2016-10-14 01:13:57 +00001209
Juan Castillo73c99d42015-08-18 14:23:04 +01001210################################################################################
1211# Build options checks
1212################################################################################
Juan Castillob7124ea2014-11-04 17:36:40 +00001213
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001214# Boolean_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001215$(eval $(call assert_booleans,\
1216 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001217 ALLOW_RO_XLAT_TABLES \
1218 BL2_ENABLE_SP_LOAD \
1219 COLD_BOOT_SINGLE_CPU \
1220 CREATE_KEYS \
1221 CTX_INCLUDE_AARCH32_REGS \
1222 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -05001223 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001224 CTX_INCLUDE_EL2_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -05001225 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001226 DEBUG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001227 DYN_DISABLE_AUTH \
1228 EL3_EXCEPTION_HANDLING \
1229 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001230 AMU_RESTRICT_COUNTERS \
1231 ENABLE_ASSERTIONS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001232 ENABLE_PIE \
1233 ENABLE_PMF \
1234 ENABLE_PSCI_STAT \
1235 ENABLE_RUNTIME_INSTRUMENTATION \
1236 ENABLE_SME_FOR_SWD \
1237 ENABLE_SVE_FOR_SWD \
Manish Pandey970a4a82023-10-10 13:53:25 +01001238 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +01001239 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001240 ERROR_DEPRECATED \
1241 FAULT_INJECTION_SUPPORT \
1242 GENERATE_COT \
1243 GICV2_G0_FOR_EL3 \
1244 HANDLE_EA_EL3_FIRST_NS \
Bipin Ravi538516f2023-09-28 13:17:24 -05001245 HARDEN_SLS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001246 HW_ASSISTED_COHERENCY \
1247 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -05001248 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +02001249 DICE_PROTECTION_ENVIRONMENT \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -07001250 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -05001251 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001252 DRTM_SUPPORT \
1253 NS_TIMER_SWITCH \
1254 OVERRIDE_LIBC \
1255 PL011_GENERIC_UART \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001256 PROGRAMMABLE_RESET_ADDRESS \
1257 PSCI_EXTENDED_STATE_ID \
1258 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +01001259 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001260 RESET_TO_BL31 \
1261 SAVE_KEYS \
1262 SEPARATE_CODE_AND_RODATA \
1263 SEPARATE_BL2_NOLOAD_REGION \
1264 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +08001265 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -05001266 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001267 SPIN_ON_BL1_EXIT \
1268 SPM_MM \
1269 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +01001270 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001271 SPMD_SPM_AT_SEL2 \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -08001272 ENABLE_SPMD_LP \
Raymond Mao3ba2c152023-07-25 07:53:35 -07001273 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001274 TRUSTED_BOARD_BOOT \
1275 USE_COHERENT_MEM \
1276 USE_DEBUGFS \
1277 ARM_IO_IN_DTB \
1278 SDEI_IN_FCONF \
1279 SEC_INT_DESC_IN_FCONF \
1280 USE_ROMLIB \
1281 USE_TBBR_DEFS \
1282 WARMBOOT_ENABLE_DCACHE_EARLY \
1283 RESET_TO_BL2 \
1284 BL2_IN_XIP_MEM \
1285 BL2_INV_DCACHE \
1286 USE_SPINLOCK_CAS \
1287 ENCRYPT_BL31 \
1288 ENCRYPT_BL32 \
1289 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +01001290 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001291 RAS_TRAP_NS_ERR_REC_ACCESS \
1292 COT_DESC_IN_DTB \
1293 USE_SP804_TIMER \
1294 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +05301295 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001296 ENABLE_MPMM \
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +00001297 FEAT_PABANDON \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001298 FEATURE_DETECTION \
Jayanth Dodderi Chidanand0b22e592022-10-11 17:16:07 +01001299 TRNG_SUPPORT \
Boyan Karatotev593ae352023-03-22 15:55:36 +00001300 ENABLE_ERRATA_ALL \
Sona Mathewffea3842022-11-18 18:05:38 -06001301 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -05001302 ERRATA_NON_ARM_INTERCONNECT \
Okash Khawaja04c73032022-11-04 12:38:01 +00001303 CONDITIONAL_CMO \
Manish V Badarkhe5782b892023-09-06 09:08:28 +01001304 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +02001305 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -05001306 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001307 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +01001308 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -06001309 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +01001310 HOB_LIST \
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001311)))
Juan Castillo73c99d42015-08-18 14:23:04 +01001312
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001313# Numeric_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001314$(eval $(call assert_numerics,\
1315 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001316 ARM_ARCH_MAJOR \
1317 ARM_ARCH_MINOR \
1318 BRANCH_PROTECTION \
1319 CTX_INCLUDE_PAUTH_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001320 CTX_INCLUDE_NEVE_REGS \
1321 CRYPTO_SUPPORT \
Boyan Karatotev83a4dae2023-02-16 09:45:29 +00001322 DISABLE_MTPMU \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001323 ENABLE_BRBE_FOR_NS \
1324 ENABLE_TRBE_FOR_NS \
1325 ENABLE_BTI \
1326 ENABLE_PAUTH \
1327 ENABLE_FEAT_AMU \
1328 ENABLE_FEAT_AMUv1p1 \
1329 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -05001330 ENABLE_FEAT_CSV2_3 \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -05001331 ENABLE_FEAT_DEBUGV8P9 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001332 ENABLE_FEAT_DIT \
1333 ENABLE_FEAT_ECV \
1334 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -05001335 ENABLE_FEAT_FGT2 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -06001336 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001337 ENABLE_FEAT_HCX \
Andre Przywara19d52a82024-08-09 17:04:22 +01001338 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +00001339 ENABLE_FEAT_MEC \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -06001340 ENABLE_FEAT_MOPS \
Govindraj Raja8e397882024-01-26 10:08:37 -06001341 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001342 ENABLE_FEAT_PAN \
1343 ENABLE_FEAT_RNG \
1344 ENABLE_FEAT_RNG_TRAP \
1345 ENABLE_FEAT_SEL2 \
1346 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +01001347 ENABLE_FEAT_THE \
Govindraj Raja0e4daed2024-01-23 16:03:53 -06001348 ENABLE_FEAT_SB \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001349 ENABLE_FEAT_S2PIE \
1350 ENABLE_FEAT_S1PIE \
1351 ENABLE_FEAT_S2POE \
1352 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +01001353 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +01001354 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001355 ENABLE_FEAT_GCS \
1356 ENABLE_FEAT_VHE \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -05001357 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001358 ENABLE_RME \
1359 ENABLE_SPE_FOR_NS \
1360 ENABLE_SYS_REG_TRACE_FOR_NS \
1361 ENABLE_SME_FOR_NS \
1362 ENABLE_SME2_FOR_NS \
1363 ENABLE_SVE_FOR_NS \
1364 ENABLE_TRF_FOR_NS \
1365 FW_ENC_STATUS \
1366 NR_OF_FW_BANKS \
1367 NR_OF_IMAGES_IN_FW_BANK \
1368 TWED_DELAY \
1369 ENABLE_FEAT_TWED \
1370 SVE_VECTOR_LEN \
Varun Wadekar0ed3be62023-04-13 21:06:18 +01001371 IMPDEF_SYSREG_TRAP \
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001372)))
Jeenu Viswambharanc877b412017-01-16 16:52:35 +00001373
Justin Chadwellaacff742019-07-29 17:13:10 +01001374ifdef KEY_SIZE
1375 $(eval $(call assert_numeric,KEY_SIZE))
1376endif
1377
Justin Chadwell1f461972019-08-20 11:01:52 +01001378ifeq ($(filter $(SANITIZE_UB), on off trap),)
1379 $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1380endif
1381
Juan Castillo73c99d42015-08-18 14:23:04 +01001382################################################################################
1383# Add definitions to the cpp preprocessor based on the current build options.
1384# This is done after including the platform specific makefile to allow the
1385# platform to overwrite the default options
1386################################################################################
1387
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001388$(eval $(call add_defines,\
1389 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001390 ALLOW_RO_XLAT_TABLES \
1391 ARM_ARCH_MAJOR \
1392 ARM_ARCH_MINOR \
1393 BL2_ENABLE_SP_LOAD \
1394 COLD_BOOT_SINGLE_CPU \
1395 CTX_INCLUDE_AARCH32_REGS \
1396 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -05001397 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001398 CTX_INCLUDE_PAUTH_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -05001399 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001400 EL3_EXCEPTION_HANDLING \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001401 CTX_INCLUDE_EL2_REGS \
1402 CTX_INCLUDE_NEVE_REGS \
1403 DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1404 DISABLE_MTPMU \
1405 ENABLE_FEAT_AMU \
1406 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001407 AMU_RESTRICT_COUNTERS \
1408 ENABLE_ASSERTIONS \
1409 ENABLE_BTI \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -05001410 ENABLE_FEAT_DEBUGV8P9 \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -05001411 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001412 ENABLE_PAUTH \
1413 ENABLE_PIE \
1414 ENABLE_PMF \
1415 ENABLE_PSCI_STAT \
1416 ENABLE_RME \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -07001417 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -05001418 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001419 ENABLE_RUNTIME_INSTRUMENTATION \
1420 ENABLE_SME_FOR_NS \
1421 ENABLE_SME2_FOR_NS \
1422 ENABLE_SME_FOR_SWD \
1423 ENABLE_SPE_FOR_NS \
1424 ENABLE_SVE_FOR_NS \
1425 ENABLE_SVE_FOR_SWD \
Manish Pandey970a4a82023-10-10 13:53:25 +01001426 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +01001427 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001428 ENCRYPT_BL31 \
1429 ENCRYPT_BL32 \
1430 ERROR_DEPRECATED \
1431 FAULT_INJECTION_SUPPORT \
1432 GICV2_G0_FOR_EL3 \
1433 HANDLE_EA_EL3_FIRST_NS \
1434 HW_ASSISTED_COHERENCY \
1435 LOG_LEVEL \
1436 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -05001437 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +02001438 DICE_PROTECTION_ENVIRONMENT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001439 DRTM_SUPPORT \
1440 NS_TIMER_SWITCH \
1441 PL011_GENERIC_UART \
1442 PLAT_${PLAT} \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001443 PROGRAMMABLE_RESET_ADDRESS \
1444 PSCI_EXTENDED_STATE_ID \
1445 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +01001446 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001447 RESET_TO_BL31 \
AlexeiFedorovd7660842024-05-13 15:35:54 +01001448 RME_GPT_BITLOCK_BLOCK \
AlexeiFedorovec0088b2024-03-13 17:07:03 +00001449 RME_GPT_MAX_BLOCK \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001450 SEPARATE_CODE_AND_RODATA \
1451 SEPARATE_BL2_NOLOAD_REGION \
1452 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +08001453 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -05001454 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001455 RECLAIM_INIT_CODE \
1456 SPD_${SPD} \
1457 SPIN_ON_BL1_EXIT \
1458 SPM_MM \
1459 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +01001460 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001461 SPMD_SPM_AT_SEL2 \
Raymond Mao3ba2c152023-07-25 07:53:35 -07001462 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001463 TRUSTED_BOARD_BOOT \
1464 CRYPTO_SUPPORT \
1465 TRNG_SUPPORT \
1466 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -05001467 ERRATA_NON_ARM_INTERCONNECT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001468 USE_COHERENT_MEM \
1469 USE_DEBUGFS \
1470 ARM_IO_IN_DTB \
1471 SDEI_IN_FCONF \
1472 SEC_INT_DESC_IN_FCONF \
1473 USE_ROMLIB \
1474 USE_TBBR_DEFS \
1475 WARMBOOT_ENABLE_DCACHE_EARLY \
1476 RESET_TO_BL2 \
1477 BL2_RUNS_AT_EL3 \
1478 BL2_IN_XIP_MEM \
1479 BL2_INV_DCACHE \
1480 USE_SPINLOCK_CAS \
1481 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +01001482 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001483 RAS_TRAP_NS_ERR_REC_ACCESS \
1484 COT_DESC_IN_DTB \
1485 USE_SP804_TIMER \
1486 ENABLE_FEAT_RNG \
1487 ENABLE_FEAT_RNG_TRAP \
1488 ENABLE_FEAT_SB \
1489 ENABLE_FEAT_DIT \
1490 NR_OF_FW_BANKS \
1491 NR_OF_IMAGES_IN_FW_BANK \
1492 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +05301493 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001494 ENABLE_BRBE_FOR_NS \
1495 ENABLE_TRBE_FOR_NS \
1496 ENABLE_SYS_REG_TRACE_FOR_NS \
1497 ENABLE_TRF_FOR_NS \
1498 ENABLE_FEAT_HCX \
1499 ENABLE_MPMM \
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +00001500 FEAT_PABANDON \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001501 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -05001502 ENABLE_FEAT_FGT2 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -06001503 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001504 ENABLE_FEAT_ECV \
1505 ENABLE_FEAT_AMUv1p1 \
1506 ENABLE_FEAT_SEL2 \
1507 ENABLE_FEAT_VHE \
1508 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -05001509 ENABLE_FEAT_CSV2_3 \
Andre Przywara19d52a82024-08-09 17:04:22 +01001510 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +00001511 ENABLE_FEAT_MEC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001512 ENABLE_FEAT_PAN \
1513 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +01001514 ENABLE_FEAT_THE \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001515 ENABLE_FEAT_S2PIE \
1516 ENABLE_FEAT_S1PIE \
1517 ENABLE_FEAT_S2POE \
1518 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +01001519 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +01001520 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001521 ENABLE_FEAT_GCS \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -06001522 ENABLE_FEAT_MOPS \
Govindraj Raja8e397882024-01-26 10:08:37 -06001523 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001524 FEATURE_DETECTION \
1525 TWED_DELAY \
1526 ENABLE_FEAT_TWED \
Okash Khawaja04c73032022-11-04 12:38:01 +00001527 CONDITIONAL_CMO \
Varun Wadekar0ed3be62023-04-13 21:06:18 +01001528 IMPDEF_SYSREG_TRAP \
Jayanth Dodderi Chidananda8cf6fa2023-04-26 15:57:30 +01001529 SVE_VECTOR_LEN \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -08001530 ENABLE_SPMD_LP \
Manish V Badarkhe5782b892023-09-06 09:08:28 +01001531 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +02001532 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -05001533 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001534 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +01001535 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -06001536 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +01001537 HOB_LIST \
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001538)))
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +01001539
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001540ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1541ifeq (${DEBUG}, 0)
1542 $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1543 override PLATFORM_REPORT_CTX_MEM_USE := 0
1544endif
1545endif
1546
Justin Chadwell1f461972019-08-20 11:01:52 +01001547ifeq (${SANITIZE_UB},trap)
1548 $(eval $(call add_define,MONITOR_TRAPS))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001549endif #(SANITIZE_UB)
Justin Chadwell1f461972019-08-20 11:01:52 +01001550
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001551# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1552ifdef EL3_PAYLOAD_BASE
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001553 $(eval $(call add_define,EL3_PAYLOAD_BASE))
1554else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001555# Define the PRELOADED_BL33_BASE flag only if it is provided and
1556# EL3_PAYLOAD_BASE is not defined, as it has priority.
1557 ifdef PRELOADED_BL33_BASE
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01001558 $(eval $(call add_define,PRELOADED_BL33_BASE))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001559 endif
1560endif #(EL3_PAYLOAD_BASE)
Juan Castillo73c99d42015-08-18 14:23:04 +01001561
Soby Mathew209a60c2018-03-26 12:43:37 +01001562# Define the DYN_DISABLE_AUTH flag only if set.
1563ifeq (${DYN_DISABLE_AUTH},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001564 $(eval $(call add_define,DYN_DISABLE_AUTH))
Soby Mathew209a60c2018-03-26 12:43:37 +01001565endif
1566
Chris Kay8620bd02023-12-04 09:55:50 +00001567ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001568 $(eval $(call add_define,USE_ARM_LINK))
Varun Wadekarc2ad38c2019-01-11 14:47:48 -08001569endif
1570
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001571# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001572ifeq (${SPD},spmd)
Olivier Deprezc33ff192020-03-19 09:27:11 +01001573ifdef SP_LAYOUT_FILE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001574 -include $(BUILD_PLAT)/sp_gen.mk
1575 FIP_DEPS += sp
1576 CRT_DEPS += sp
1577 NEED_SP_PKG := yes
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001578else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001579 ifeq (${SPMD_SPM_AT_SEL2},1)
1580 $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1581 endif
1582endif #(SP_LAYOUT_FILE)
1583endif #(SPD)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001584
Juan Castillo73c99d42015-08-18 14:23:04 +01001585################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +01001586# Build targets
1587################################################################################
1588
Harrison Mutai2329e222024-08-28 13:27:19 +00001589.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 +01001590
1591all: msg_start
1592
1593msg_start:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001594 $(s)echo "Building ${PLAT}"
Juan Castillo73c99d42015-08-18 14:23:04 +01001595
Soby Mathew7a24cba2015-10-26 14:29:21 +00001596ifeq (${ERROR_DEPRECATED},0)
Julius Wernerd5dfdeb2019-07-09 13:49:11 -07001597# Check if deprecated declarations and cpp warnings should be treated as error or not.
Chris Kay8620bd02023-12-04 09:55:50 +00001598ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -08001599 CPPFLAGS += -Wno-error=deprecated-declarations
1600else
Dan Handleybc1a03c2018-02-27 16:03:58 +00001601 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp
Soby Mathew7a24cba2015-10-26 14:29:21 +00001602endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001603endif #(!ERROR_DEPRECATED)
Soby Mathew7a24cba2015-10-26 14:29:21 +00001604
Roberto Vargas61f72a32018-05-08 10:27:10 +01001605$(eval $(call MAKE_LIB,c))
Roberto Vargas5fee0282018-05-08 10:27:10 +01001606
Juan Castillo73c99d42015-08-18 14:23:04 +01001607# Expand build macros for the different images
1608ifeq (${NEED_BL1},yes)
Chris Kayb34635a2021-09-28 15:44:19 +01001609BL1_SOURCES := $(sort ${BL1_SOURCES})
Zelalem Aweke434d0492021-07-11 17:25:48 -05001610$(eval $(call MAKE_BL,bl1))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001611endif #(NEED_BL1)
Juan Castillo73c99d42015-08-18 14:23:04 +01001612
1613ifeq (${NEED_BL2},yes)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001614
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -06001615ifeq (${RESET_TO_BL2}, 0)
Roberto Vargasc9b31ae2018-01-02 11:23:41 +00001616FIP_BL2_ARGS := tb-fw
1617endif
1618
Chris Kayeb1acfb2021-09-28 15:44:37 +01001619BL2_SOURCES := $(sort ${BL2_SOURCES})
1620
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001621$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001622 $(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001623
1624endif #(NEED_BL2)
Juan Castillo73c99d42015-08-18 14:23:04 +01001625
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001626ifeq (${NEED_SCP_BL2},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001627$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001628endif #(NEED_SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001629
Juan Castillo73c99d42015-08-18 14:23:04 +01001630ifeq (${NEED_BL31},yes)
1631BL31_SOURCES += ${SPD_SOURCES}
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001632# Sort BL31 source files to remove duplicates
1633BL31_SOURCES := $(sort ${BL31_SOURCES})
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301634ifneq (${DECRYPTION_SUPPORT},none)
1635$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001636 $(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301637else
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001638$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001639 $(eval $(call MAKE_BL,bl31,soc-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001640endif #(DECRYPTION_SUPPORT)
1641endif #(NEED_BL31)
Juan Castillo73c99d42015-08-18 14:23:04 +01001642
Juan Castillo70d1fc52015-11-12 10:59:26 +00001643# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
Masahiro Yamadac939d132018-01-26 11:42:01 +09001644# build system will call TOOL_ADD_IMG to print a warning message and abort the
Juan Castillo70d1fc52015-11-12 10:59:26 +00001645# process. Note that the dependency on BL32 applies to the FIP only.
Juan Castillo73c99d42015-08-18 14:23:04 +01001646ifeq (${NEED_BL32},yes)
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001647# Sort BL32 source files to remove duplicates
1648BL32_SOURCES := $(sort ${BL32_SOURCES})
Masahiro Yamada9cd15232018-01-26 11:42:01 +09001649BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1650
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301651ifneq (${DECRYPTION_SUPPORT},none)
Zelalem Aweke434d0492021-07-11 17:25:48 -05001652$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301653 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1654else
Zelalem Aweke434d0492021-07-11 17:25:48 -05001655$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001656 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001657endif #(DECRYPTION_SUPPORT)
1658endif #(NEED_BL32)
Juan Castillo73c99d42015-08-18 14:23:04 +01001659
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001660# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1661# needs to be built from RMM_SOURCES.
1662ifeq (${NEED_RMM},yes)
1663# Sort RMM source files to remove duplicates
1664RMM_SOURCES := $(sort ${RMM_SOURCES})
1665BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1666
1667$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001668 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1669endif #(NEED_RMM)
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001670
Juan Castillo73c99d42015-08-18 14:23:04 +01001671# Add the BL33 image if required by the platform
1672ifeq (${NEED_BL33},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001673$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001674endif #(NEED_BL33)
Juan Castillodb6071c2015-01-13 12:21:04 +00001675
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001676ifeq (${NEED_BL2U},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001677$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001678 $(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001679endif #(NEED_BL2U)
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001680
Nishanth Menon03b397a2016-10-14 01:13:57 +00001681# Expand build macros for the different images
1682ifeq (${NEED_FDT},yes)
Soby Mathew38c14d82017-12-14 17:44:56 +00001683 $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
Salman Nabi1c08ff32024-12-12 17:38:54 +00001684
1685 ifneq (${INITRD_SIZE}${INITRD_PATH},)
1686 ifndef INITRD_BASE
1687 $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1688 endif
1689
1690 INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1691 initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1692
1693 define $(HW_CONFIG)-after +=
1694 $(s)echo " INITRD $(HW_CONFIG)"
1695 $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1696 $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1697 endef
1698 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001699endif #(NEED_FDT)
Nishanth Menon03b397a2016-10-14 01:13:57 +00001700
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001701# Add Secure Partition packages
1702ifeq (${NEED_SP_PKG},yes)
Chris Kayfd74ca02024-07-30 13:33:56 +00001703$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
Chris Kay679e27c2025-03-19 15:04:47 +00001704 $(if $(host-poetry),$(q)poetry -q install --no-root)
Kathleen Capelladd816232025-02-13 17:34:21 -06001705 $(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
J-Alves822c7272022-03-22 16:28:51 +00001706sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001707 $(s)echo
1708 $(s)echo "Built SP Images successfully"
1709 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001710endif #(NEED_SP_PKG)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001711
Ian Spray36eaaf32014-01-30 17:25:28 +00001712locate-checkpatch:
1713ifndef CHECKPATCH
Etienne Carriere66079b02017-08-23 15:44:01 +02001714 $(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 +00001715else
1716ifeq (,$(wildcard ${CHECKPATCH}))
Etienne Carriere66079b02017-08-23 15:44:01 +02001717 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
Ian Spray36eaaf32014-01-30 17:25:28 +00001718endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001719endif #(CHECKPATCH)
Ian Spray36eaaf32014-01-30 17:25:28 +00001720
Achin Gupta4f6ad662013-10-25 09:08:21 +01001721clean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001722 $(s)echo " CLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001723 $(q)rm -rf $(BUILD_PLAT)
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001724 $(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001725 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1726 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1727 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001728
James Morrisseyeaaeece2013-11-01 13:56:59 +00001729realclean distclean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001730 $(s)echo " REALCLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001731 $(q)rm -rf $(BUILD_BASE)
1732 $(q)rm -rf $(CURDIR)/cscope.*
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001733 $(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001734 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1735 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1736 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001737
Ian Spray36eaaf32014-01-30 17:25:28 +00001738checkcodebase: locate-checkpatch
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001739 $(s)echo " CHECKING STYLE"
1740 $(q)if test -d .git ; then \
Paul Beesley1ef35512019-03-07 16:42:31 +00001741 git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' | \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001742 while read GIT_FILE ; \
1743 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
1744 done ; \
1745 else \
1746 find . -type f -not -iwholename "*.git*" \
1747 -not -iwholename "*build*" \
1748 -not -iwholename "*libfdt*" \
Roberto Vargas61f72a32018-05-08 10:27:10 +01001749 -not -iwholename "*libc*" \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001750 -not -iwholename "*docs*" \
Paul Beesley1ef35512019-03-07 16:42:31 +00001751 -not -iwholename "*.rst" \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001752 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
1753 fi
Ian Spray36eaaf32014-01-30 17:25:28 +00001754
1755checkpatch: locate-checkpatch
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001756 $(s)echo " CHECKING STYLE"
1757 $(q)if test -n "${CHECKPATCH_OPTS}"; then \
Yann Gautier02a76d52019-03-08 15:44:00 +01001758 echo " with ${CHECKPATCH_OPTS} option(s)"; \
1759 fi
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001760 $(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
Yann Gautier77a0a7f2021-11-02 18:03:31 +01001761 for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`; \
1762 do \
Antonio Nino Diaz51d28932018-01-29 12:00:31 +00001763 printf "\n[*] Checking style of '$$commit'\n\n"; \
Yann Gautier1a721742024-08-09 11:52:03 +02001764 ( git log --format=email "$$commit~..$$commit" \
1765 -- ${CHECK_PATHS} ; \
1766 git diff --format=email "$$commit~..$$commit" \
1767 -- ${CHECK_PATHS}; ) | \
Yann Gautier02a76d52019-03-08 15:44:00 +01001768 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \
Antonio Nino Diaz51d28932018-01-29 12:00:31 +00001769 done
Juan Castillo73c99d42015-08-18 14:23:04 +01001770
1771certtool: ${CRTTOOL}
Ian Spray36eaaf32014-01-30 17:25:28 +00001772
Pali Rohára9812202020-11-24 15:38:08 +01001773${CRTTOOL}: FORCE
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001774 $(q)${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1775 $(s)echo
1776 $(s)echo "Built $@ successfully"
1777 $(s)echo
Juan Castillo73c99d42015-08-18 14:23:04 +01001778
1779ifneq (${GENERATE_COT},0)
1780certificates: ${CRT_DEPS} ${CRTTOOL}
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001781 $(q)${CRTTOOL} ${CRT_ARGS}
1782 $(s)echo
1783 $(s)echo "Built $@ successfully"
1784 $(s)echo "Certificates can be found in ${BUILD_PLAT}"
1785 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001786endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +01001787
1788${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
Pali Rohár4727fd12020-11-24 16:53:04 +01001789 $(eval ${CHECK_FIP_CMD})
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001790 $(q)${FIPTOOL} create ${FIP_ARGS} $@
1791 $(q)${FIPTOOL} info $@
1792 $(s)echo
1793 $(s)echo "Built $@ successfully"
1794 $(s)echo
Juan Castillo73c99d42015-08-18 14:23:04 +01001795
Yatharth Kochar01912622015-10-12 12:33:47 +01001796ifneq (${GENERATE_COT},0)
1797fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001798 $(q)${CRTTOOL} ${FWU_CRT_ARGS}
1799 $(s)echo
1800 $(s)echo "Built $@ successfully"
1801 $(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1802 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001803endif #(GENERATE_COT)
Yatharth Kochar01912622015-10-12 12:33:47 +01001804
1805${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
Pali Rohár4727fd12020-11-24 16:53:04 +01001806 $(eval ${CHECK_FWU_FIP_CMD})
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001807 $(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1808 $(q)${FIPTOOL} info $@
1809 $(s)echo
1810 $(s)echo "Built $@ successfully"
1811 $(s)echo
Yatharth Kochar01912622015-10-12 12:33:47 +01001812
Juan Castillo73c99d42015-08-18 14:23:04 +01001813fiptool: ${FIPTOOL}
1814fip: ${BUILD_PLAT}/${FIP_NAME}
Yatharth Kochar01912622015-10-12 12:33:47 +01001815fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
Juan Castillo6f971622014-10-21 11:30:42 +01001816
Pali Rohára9812202020-11-24 15:38:08 +01001817${FIPTOOL}: FORCE
Manish V Badarkhe40469bf2024-10-03 20:50:04 +01001818 $(q)${MAKE} PLAT=${PLAT} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
Harry Liebelf58ad362014-01-10 18:00:33 +00001819
Manish V Badarkhee4a070e2024-12-03 21:46:51 +00001820$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB)
1821 $(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 +01001822
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001823memmap: all
Chris Kayc25405d2025-03-10 09:24:34 +00001824 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kayed0c8012025-01-28 18:04:11 +00001825 $(q)$(if $(host-poetry),poetry run )memory -sr ${BUILD_PLAT}
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001826
Harrison Mutai2329e222024-08-28 13:27:19 +00001827tl: ${BUILD_PLAT}/tl.bin
1828${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
Chris Kayc25405d2025-03-10 09:24:34 +00001829 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kayd2867392024-09-26 14:18:04 +00001830 $(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
Harrison Mutai2329e222024-08-28 13:27:19 +00001831
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001832doc:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001833 $(s)echo " BUILD DOCUMENTATION"
1834 $(q)${MAKE} --no-print-directory -C ${DOCS_PATH} html
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001835
Sumit Garg90aa9012019-11-11 18:46:36 +05301836enctool: ${ENCTOOL}
1837
Pali Rohára9812202020-11-24 15:38:08 +01001838${ENCTOOL}: FORCE
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001839 $(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1840 $(s)echo
1841 $(s)echo "Built $@ successfully"
1842 $(s)echo
Sumit Garg90aa9012019-11-11 18:46:36 +05301843
Joakim Bech35fab8c2014-01-23 14:51:49 +01001844cscope:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001845 $(s)echo " CSCOPE"
1846 $(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1847 $(q)cscope -b -q -k
Joakim Bech35fab8c2014-01-23 14:51:49 +01001848
Ryan Harkin72ee3312014-01-15 16:55:07 +00001849help:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001850 $(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1851 $(s)echo ""
1852 $(s)echo "PLAT is used to specify which platform you wish to build."
1853 $(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1854 $(s)echo ""
1855 $(s)echo "platform = ${PLATFORM_LIST}"
1856 $(s)echo ""
1857 $(s)echo "Please refer to the User Guide for a list of all supported options."
1858 $(s)echo "Note that the build system doesn't track dependencies for build "
1859 $(s)echo "options. Therefore, if any of the build options are changed "
1860 $(s)echo "from a previous build, a clean build must be performed."
1861 $(s)echo ""
1862 $(s)echo "Supported Targets:"
1863 $(s)echo " all Build all individual bootloader binaries"
1864 $(s)echo " bl1 Build the BL1 binary"
1865 $(s)echo " bl2 Build the BL2 binary"
1866 $(s)echo " bl2u Build the BL2U binary"
1867 $(s)echo " bl31 Build the BL31 binary"
1868 $(s)echo " bl32 Build the BL32 binary. If ARCH=aarch32, then "
1869 $(s)echo " this builds secure payload specified by AARCH32_SP"
1870 $(s)echo " certificates Build the certificates (requires 'GENERATE_COT=1')"
1871 $(s)echo " fip Build the Firmware Image Package (FIP)"
1872 $(s)echo " fwu_fip Build the FWU Firmware Image Package (FIP)"
1873 $(s)echo " checkcodebase Check the coding style of the entire source tree"
1874 $(s)echo " checkpatch Check the coding style on changes in the current"
1875 $(s)echo " branch against BASE_COMMIT (default origin/master)"
1876 $(s)echo " clean Clean the build for the selected platform"
1877 $(s)echo " cscope Generate cscope index"
1878 $(s)echo " distclean Remove all build artifacts for all platforms"
1879 $(s)echo " certtool Build the Certificate generation tool"
1880 $(s)echo " enctool Build the Firmware encryption tool"
1881 $(s)echo " fiptool Build the Firmware Image Package (FIP) creation tool"
1882 $(s)echo " sp Build the Secure Partition Packages"
1883 $(s)echo " sptool Build the Secure Partition Package creation tool"
1884 $(s)echo " dtbs Build the Device Tree Blobs (if required for the platform)"
1885 $(s)echo " memmap Print the memory map of the built binaries"
1886 $(s)echo " doc Build html based documentation using Sphinx tool"
1887 $(s)echo ""
1888 $(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1889 $(s)echo ""
1890 $(s)echo "example: build all targets for the FVP platform:"
1891 $(s)echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
Pali Rohára9812202020-11-24 15:38:08 +01001892
1893.PHONY: FORCE
1894FORCE:;