blob: bf45090223d80a710766fd9a9ae63c2d3137c62b [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001#
Chris Kayc3273702025-01-13 15:57:32 +00002# Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003#
dp-arm82cb2c12017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005#
6
Jeenu Viswambharane35c4042014-05-15 14:40:58 +01007#
Juan Castilloaaa3e722014-06-30 11:41:46 +01008# Trusted Firmware Version
9#
Soby Mathew1a0f1122018-10-01 16:16:34 +010010VERSION_MAJOR := 2
Govindraj Raja97a6de92025-05-07 13:51:45 -050011VERSION_MINOR := 13
Yann Gautierc25d1cc2024-02-08 18:40:27 +010012# VERSION_PATCH is only used for LTS releases
13VERSION_PATCH := 0
Yann Gautier055ebec2023-10-03 11:09:07 +020014VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
Juan Castilloaaa3e722014-06-30 11:41:46 +010015
Juan Castillo88154672015-10-22 11:34:44 +010016# Default goal is build all images
17.DEFAULT_GOAL := all
18
Douglas Raillard72fc70e2016-12-28 14:47:50 +000019# Avoid any implicit propagation of command line variable definitions to
20# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
21# usage. Other command line options like "-s" are still propagated as usual.
22MAKEOVERRIDES =
23
Evan Lloyd231c1472015-12-02 18:17:37 +000024MAKE_HELPERS_DIRECTORY := make_helpers/
25include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
Chris Kayf4dd18c2024-06-04 00:04:48 +000026include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
Chris Kay7c4e1ee2024-05-02 17:52:37 +000027include ${MAKE_HELPERS_DIRECTORY}common.mk
Juan Castillo73c99d42015-08-18 14:23:04 +010028
29################################################################################
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010030# Default values for build configurations, and their dependencies
Juan Castillo73c99d42015-08-18 14:23:04 +010031################################################################################
Jeenu Viswambharane35c4042014-05-15 14:40:58 +010032
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010033include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Yann Gautier422b1812025-01-17 11:02:50 +010034PLAT := ${DEFAULT_PLAT}
Andrey Skvortsov1b2fb6a2024-02-18 11:43:12 +030035include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
36
37# To be able to set platform specific defaults
38ifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
39include ${PLAT_DEFAULTS_MAKEFILE_FULL}
40endif
dp-arm872be882016-09-19 11:18:44 +010041
Chris Kaycc277de2023-10-20 09:17:33 +000042################################################################################
43# Configure the toolchains used to build TF-A and its tools
44################################################################################
45
46include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
47
Antonio Nino Diazcc8b5632017-04-18 15:16:05 +010048# Assertions enabled for DEBUG builds by default
Antonio Nino Diazcc8b5632017-04-18 15:16:05 +010049ENABLE_ASSERTIONS := ${DEBUG}
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010050ENABLE_PMF := ${ENABLE_RUNTIME_INSTRUMENTATION}
Juan Castillo73c99d42015-08-18 14:23:04 +010051
52################################################################################
53# Checkpatch script options
54################################################################################
55
Sandrine Bailleuxf6077392016-06-02 11:19:59 +010056CHECKCODE_ARGS := --no-patch
Dan Handleyf0b489c2016-06-02 17:15:13 +010057# Do not check the coding style on imported library files or documentation files
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030058INC_DRV_DIRS_TO_CHECK := $(sort $(filter-out \
59 include/drivers/arm, \
60 $(wildcard include/drivers/*)))
Dan Handleyf0b489c2016-06-02 17:15:13 +010061INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Dan Handley1a41e8c2016-06-02 18:21:02 +010062 include/lib/libfdt \
Roberto Vargas61f72a32018-05-08 10:27:10 +010063 include/lib/libc, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010064 $(wildcard include/lib/*)))
65INC_DIRS_TO_CHECK := $(sort $(filter-out \
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030066 include/lib \
67 include/drivers, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010068 $(wildcard include/*)))
69LIB_DIRS_TO_CHECK := $(sort $(filter-out \
dp-armd801fbb2017-05-04 12:15:35 +010070 lib/compiler-rt \
Antonio Nino Diaz55cdcf72017-01-16 17:20:45 +000071 lib/libfdt% \
Roberto Vargas61f72a32018-05-08 10:27:10 +010072 lib/libc, \
Daniel Boulbya1942552022-10-05 11:05:22 +010073 lib/zlib \
Dan Handleyf0b489c2016-06-02 17:15:13 +010074 $(wildcard lib/*)))
75ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
76 lib \
77 include \
78 docs \
Paul Beesley1ef35512019-03-07 16:42:31 +000079 %.rst, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010080 $(wildcard *)))
81CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
82 ${INC_DIRS_TO_CHECK} \
83 ${INC_LIB_DIRS_TO_CHECK} \
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030084 ${LIB_DIRS_TO_CHECK} \
85 ${INC_DRV_DIRS_TO_CHECK} \
86 ${INC_ARM_DIRS_TO_CHECK}
Ian Spray36eaaf32014-01-30 17:25:28 +000087
Juan Castillo73c99d42015-08-18 14:23:04 +010088################################################################################
89# Process build options
90################################################################################
91
Chris Kay7c4e1ee2024-05-02 17:52:37 +000092ifeq ($(verbose),)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +010093 CHECKCODE_ARGS += --no-summary --terse
Achin Gupta4f6ad662013-10-25 09:08:21 +010094endif
Andre Przywaraee1ba6d2018-09-27 10:56:05 +010095
Juan Castillo73c99d42015-08-18 14:23:04 +010096################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +010097# Auxiliary tools (fiptool, cert_create, etc)
98################################################################################
99
100# Variables for use with Certificate Generation Tool
101CRTTOOLPATH ?= tools/cert_create
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
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100162ifneq (${DEBUG}, 0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100163 BUILD_TYPE := debug
164 TF_CFLAGS += -g -gdwarf-4
165 ASFLAGS += -g -Wa,-gdwarf-4
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100166
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100167 # Use LOG_LEVEL_INFO by default for debug builds
168 LOG_LEVEL := 40
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100169else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100170 BUILD_TYPE := release
171 # Use LOG_LEVEL_NOTICE by default for release builds
172 LOG_LEVEL := 20
173endif #(Debug)
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100174
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800175# Default build string (git branch and commit)
176ifeq (${BUILD_STRING},)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100177 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800178endif
laurenw-armdddf4282022-07-12 10:12:05 -0500179VERSION_STRING := v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800180
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100181ifeq (${AARCH32_INSTRUCTION_SET},A32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100182 TF_CFLAGS_aarch32 += -marm
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100183else ifeq (${AARCH32_INSTRUCTION_SET},T32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100184 TF_CFLAGS_aarch32 += -mthumb
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100185endif #(AARCH32_INSTRUCTION_SET)
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100186
Sandrine Bailleuxa9c4dde2018-07-03 09:14:45 +0200187TF_CFLAGS_aarch32 += -mno-unaligned-access
dp-armd5461852017-05-02 12:00:08 +0100188TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align
Soby Mathew9d29c222016-05-05 14:33:33 +0100189
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100190##############################################################################
191# WARNINGS Configuration
192###############################################################################
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100193# General warnings
194WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
Yann Gautier34b508b2021-05-20 13:18:14 +0200195 -Wdisabled-optimization -Wvla -Wshadow \
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000196 -Wredundant-decls
197# stricter warnings
198WARNINGS += -Wextra -Wno-trigraphs
199# too verbose for generic build
200WARNINGS += -Wno-missing-field-initializers \
201 -Wno-type-limits -Wno-sign-compare \
202# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
203WARNINGS += -Wno-unused-parameter
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100204
205# Additional warnings
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000206# Level 1 - infrequent warnings we should have none of
207# full -Wextra
208WARNING1 += -Wsign-compare
209WARNING1 += -Wtype-limits
210WARNING1 += -Wmissing-field-initializers
Yann Gautiere7c645b2018-12-10 18:00:26 +0100211
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000212# Level 2 - problematic warnings that we want
213# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
214# TODO: disable just for them and move into default build
215WARNING2 += -Wold-style-definition
216WARNING2 += -Wmissing-prototypes
217WARNING2 += -Wmissing-format-attribute
218# TF-A aims to comply with this eventually. Effort too large at present
219WARNING2 += -Wundef
Boyan Karatotevd141e632022-11-21 14:49:05 +0000220# currently very involved and many platforms set this off
221WARNING2 += -Wunused-const-variable=2
Yann Gautiere7c645b2018-12-10 18:00:26 +0100222
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000223# Level 3 - very pedantic, frequently ignored
Yann Gautiere7c645b2018-12-10 18:00:26 +0100224WARNING3 := -Wbad-function-cast
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000225WARNING3 += -Waggregate-return
226WARNING3 += -Wnested-externs
227WARNING3 += -Wcast-align
Yann Gautiere7c645b2018-12-10 18:00:26 +0100228WARNING3 += -Wcast-qual
229WARNING3 += -Wconversion
230WARNING3 += -Wpacked
Yann Gautiere7c645b2018-12-10 18:00:26 +0100231WARNING3 += -Wpointer-arith
Yann Gautiere7c645b2018-12-10 18:00:26 +0100232WARNING3 += -Wswitch-default
Yann Gautiere7c645b2018-12-10 18:00:26 +0100233
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000234# Setting W is quite verbose and most warnings will be pre-existing issues
235# outside of the contributor's control. Don't fail the build on them so warnings
236# can be seen and hopefully addressed
237ifdef W
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100238 ifneq (${W},0)
239 E ?= 0
240 endif
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000241endif
242
Yann Gautiere7c645b2018-12-10 18:00:26 +0100243ifeq (${W},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100244 WARNINGS += $(WARNING1)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100245else ifeq (${W},2)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100246 WARNINGS += $(WARNING1) $(WARNING2)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100247else ifeq (${W},3)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100248 WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
249endif #(W)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100250
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100251# Compiler specific warnings
Chris Kay8620bd02023-12-04 09:55:50 +0000252ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
Justin Chadwell93c690e2019-07-03 14:15:56 +0100253# not using clang
Justin Chadwelld7b4cd42019-09-18 14:13:42 +0100254WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \
255 -Wpacked-bitfield-compat -Wshift-overflow=2 \
256 -Wlogical-op
Govindraj Rajadea23e22023-05-05 09:09:36 -0500257
258# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
Boyan Karatotev316f5c92024-10-10 13:54:37 +0100259TF_CFLAGS_MIN_PAGE_SIZE := $(call cc_option, --param=min-pagesize=0)
260TF_CFLAGS += $(TF_CFLAGS_MIN_PAGE_SIZE)
Govindraj Rajadea23e22023-05-05 09:09:36 -0500261
Bipin Ravi538516f2023-09-28 13:17:24 -0500262ifeq ($(HARDEN_SLS), 1)
Boyan Karatotev316f5c92024-10-10 13:54:37 +0100263 TF_CFLAGS_MHARDEN_SLS := $(call cc_option, -mharden-sls=all)
264 TF_CFLAGS_aarch64 += $(TF_CFLAGS_MHARDEN_SLS)
Bipin Ravi538516f2023-09-28 13:17:24 -0500265endif
266
Justin Chadwell93c690e2019-07-03 14:15:56 +0100267else
268# using clang
Justin Chadwelld7b4cd42019-09-18 14:13:42 +0100269WARNINGS += -Wshift-overflow -Wshift-sign-overflow \
270 -Wlogical-op-parentheses
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100271endif #(Clang Warning)
Ambroise Vincent00296572019-05-24 12:47:43 +0100272
Yann Gautier6336b072018-12-10 18:08:53 +0100273ifneq (${E},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100274 ERRORS := -Werror
275endif #(E)
Yann Gautier6336b072018-12-10 18:08:53 +0100276
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100277################################################################################
278# Compiler and Linker Directives
279################################################################################
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100280CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \
281 $(ERRORS) $(WARNINGS)
Govindraj Rajad4089fb2023-05-30 16:52:15 -0500282ASFLAGS += $(CPPFLAGS) \
Julius Wernerd5dfdeb2019-07-09 13:49:11 -0700283 -ffreestanding -Wa,--fatal-warnings
Masahiro Yamada59de5092016-12-22 12:51:53 +0900284TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \
Samuel Hollandebd6efa2019-10-20 16:11:25 -0500285 -ffunction-sections -fdata-sections \
Boyan Karatotevee0c5b82024-12-09 08:24:12 +0000286 -ffreestanding -fno-common \
Samuel Hollandebd6efa2019-10-20 16:11:25 -0500287 -Os -std=gnu99
Juan Castillo73c99d42015-08-18 14:23:04 +0100288
Justin Chadwell1f461972019-08-20 11:01:52 +0100289ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100290 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover
291endif #(${SANITIZE_UB},on)
292
Justin Chadwell1f461972019-08-20 11:01:52 +0100293ifeq (${SANITIZE_UB},trap)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100294 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \
Justin Chadwell1f461972019-08-20 11:01:52 +0100295 -fsanitize-undefined-trap-on-error
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100296endif #(${SANITIZE_UB},trap)
Justin Chadwell1f461972019-08-20 11:01:52 +0100297
Chris Kay291e7182024-05-14 13:08:31 +0000298GCC_V_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
david cunadof7ec31d2017-11-30 21:58:01 +0000299
Marco Felsch1f49db52022-11-09 12:59:09 +0100300TF_LDFLAGS += -z noexecstack
301
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100302# LD = armlink
Chris Kay8620bd02023-12-04 09:55:50 +0000303ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100304 TF_LDFLAGS += --diag_error=warning --lto_level=O1
305 TF_LDFLAGS += --remove --info=unused,unusedsymbols
306 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH))
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100307
308# LD = gcc (used when GCC LTO is enabled)
Chris Kay8620bd02023-12-04 09:55:50 +0000309else ifeq ($($(ARCH)-ld-id),gnu-gcc)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100310 # Pass ld options with Wl or Xlinker switches
Chris Kay86e489c2024-01-16 11:53:35 +0000311 TF_LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100312 TF_LDFLAGS += -Wl,--fatal-warnings -O1
313 TF_LDFLAGS += -Wl,--gc-sections
Chris Kayac98b822022-12-22 13:26:37 +0000314
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100315 TF_LDFLAGS += -Wl,-z,common-page-size=4096 #Configure page size constants
316 TF_LDFLAGS += -Wl,-z,max-page-size=4096
Andrey Skvortsov304ad942023-09-05 23:06:29 +0300317 TF_LDFLAGS += -Wl,--build-id=none
Chris Kayac98b822022-12-22 13:26:37 +0000318
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100319 ifeq ($(ENABLE_LTO),1)
320 ifeq (${ARCH},aarch64)
321 TF_LDFLAGS += -flto -fuse-linker-plugin
Andrey Skvortsov31f80ef2023-12-08 18:04:51 +0300322 TF_LDFLAGS += -flto-partition=one
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100323 endif
324 endif #(ENABLE_LTO)
325
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600326# GCC automatically adds fix-cortex-a53-843419 flag when used to link
327# which breaks some builds, so disable if errata fix is not explicitly enabled
Yann Gautiercfe67672023-03-15 16:18:16 +0100328 ifeq (${ARCH},aarch64)
329 ifneq (${ERRATA_A53_843419},1)
330 TF_LDFLAGS += -mno-fix-cortex-a53-843419
331 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100332 endif
333 TF_LDFLAGS += -nostdlib
334 TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100335
336# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800337else
Marco Felsch1f49db52022-11-09 12:59:09 +0100338# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
339# are not loaded by a elf loader.
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100340 TF_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
341 TF_LDFLAGS += -O1
342 TF_LDFLAGS += --gc-sections
Chris Kayac98b822022-12-22 13:26:37 +0000343
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100344 TF_LDFLAGS += -z common-page-size=4096 # Configure page size constants
345 TF_LDFLAGS += -z max-page-size=4096
Andrey Skvortsov304ad942023-09-05 23:06:29 +0300346 TF_LDFLAGS += --build-id=none
Chris Kayac98b822022-12-22 13:26:37 +0000347
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100348# ld.lld doesn't recognize the errata flags,
Yabin Cuiebac6922023-01-19 20:06:04 +0000349# therefore don't add those in that case.
350# ld.lld reports section type mismatch warnings,
351# therefore don't add --fatal-warnings to it.
Chris Kay8620bd02023-12-04 09:55:50 +0000352 ifneq ($($(ARCH)-ld-id),llvm-lld)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100353 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) --fatal-warnings
354 endif
355
356endif #(LD = armlink)
Juan Castillo73c99d42015-08-18 14:23:04 +0100357
358################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500359# Setup ARCH_MAJOR/MINOR before parsing arch_features.
360################################################################################
361ifeq (${ENABLE_RME},1)
AlexeiFedorov7d5fc982024-03-13 11:53:44 +0000362 ARM_ARCH_MAJOR := 9
363 ARM_ARCH_MINOR := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500364endif
365
366################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100367# Common sources and include directories
368################################################################################
dp-armd801fbb2017-05-04 12:15:35 +0100369include lib/compiler-rt/compiler-rt.mk
Juan Castillo73c99d42015-08-18 14:23:04 +0100370
Chris Kay758ccb82024-03-08 16:08:31 +0000371# Allow overriding the timestamp, for example for reproducible builds, or to
372# synchronize timestamps across multiple projects.
373# This must be set to a C string (including quotes where applicable).
374BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
375
376DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
377DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
378DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
379
Juan Castillo73c99d42015-08-18 14:23:04 +0100380BL_COMMON_SOURCES += common/bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100381 common/tf_log.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100382 common/${ARCH}/debug.S \
Julius Werner91b48c92018-11-27 22:10:56 -0800383 drivers/console/multi_console.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100384 lib/${ARCH}/cache_helpers.S \
385 lib/${ARCH}/misc_helpers.S \
Boyan Karatotevc73686a2023-02-15 13:21:50 +0000386 lib/extensions/pmuv3/${ARCH}/pmuv3.c \
Soby Mathew566034f2018-02-08 17:45:12 +0000387 plat/common/plat_bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100388 plat/common/plat_log_common.c \
dp-arm75311202017-03-07 11:02:47 +0000389 plat/common/${ARCH}/plat_common.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100390 plat/common/${ARCH}/platform_helpers.S \
Roberto Vargas61f72a32018-05-08 10:27:10 +0100391 ${COMPILER_RT_SRCS}
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000392
Chris Kay8620bd02023-12-04 09:55:50 +0000393ifeq ($($(ARCH)-cc-id),arm-clang)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100394 BL_COMMON_SOURCES += lib/${ARCH}/armclang_printf.S
Antonio Nino Diaz8422a842018-08-16 15:42:44 +0100395endif
396
Justin Chadwell1f461972019-08-20 11:01:52 +0100397ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100398 BL_COMMON_SOURCES += plat/common/ubsan.c
Justin Chadwell1f461972019-08-20 11:01:52 +0100399endif
400
Yann Gautier01d237c2018-06-18 16:00:23 +0200401INCLUDES += -Iinclude \
Antonio Nino Diazf5478de2018-12-17 17:20:57 +0000402 -Iinclude/arch/${ARCH} \
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +0000403 -Iinclude/lib/cpus/${ARCH} \
404 -Iinclude/lib/el3_runtime/${ARCH} \
405 ${PLAT_INCLUDES} \
406 ${SPD_INCLUDES}
407
Nishant Sharmae03dcc82022-08-15 16:37:07 +0100408DTC_FLAGS += -I dts -O dtb
409DTC_CPPFLAGS += -P -nostdinc $(INCLUDES) -Ifdts -undef \
410 -x assembler-with-cpp $(DEFINES)
411
Antonio Nino Diaz9c6d1c52018-11-19 11:48:30 +0000412include common/backtrace/backtrace.mk
413
Juan Castillo73c99d42015-08-18 14:23:04 +0100414################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500415# Generic definitions
416################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500417
418ifeq (${BUILD_BASE},)
419 BUILD_BASE := ./build
420endif
421BUILD_PLAT := $(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
422
423SPDS := $(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
424
425# Platforms providing their own TBB makefile may override this value
426INCLUDE_TBBR_MK := 1
427
428################################################################################
429# Include SPD Makefile if one has been specified
430################################################################################
431
432ifneq (${SPD},none)
Govindraj Raja35472702023-09-20 14:32:24 -0500433 ifeq (${SPD},spmd)
434 # SPMD is located in std_svc directory
435 SPD_DIR := std_svc
436
437 ifeq ($(SPMD_SPM_AT_SEL2),1)
438 CTX_INCLUDE_EL2_REGS := 1
Govindraj Raja35472702023-09-20 14:32:24 -0500439 endif
440
441 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
442 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG
443 endif
444
Arunachalam Ganapathy0686a012022-04-11 14:36:54 +0100445 ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
446 DTC_CPPFLAGS += -DTRUSTY_SP_FW_CONFIG
447 endif
448
Govindraj Raja35472702023-09-20 14:32:24 -0500449 ifeq ($(TS_SP_FW_CONFIG),1)
Arunachalam Ganapathy0686a012022-04-11 14:36:54 +0100450 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG
Govindraj Raja35472702023-09-20 14:32:24 -0500451 endif
452
453 ifneq ($(ARM_BL2_SP_LIST_DTS),)
454 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
455 endif
456
457 ifneq ($(SP_LAYOUT_FILE),)
458 BL2_ENABLE_SP_LOAD := 1
459 endif
460 else
461 # All other SPDs in spd directory
462 SPD_DIR := spd
463 endif #(SPD)
464
465 # We expect to locate an spd.mk under the specified SPD directory
466 SPD_MAKE := $(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
467
468 ifeq (${SPD_MAKE},)
469 $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
470 endif
471 $(info Including ${SPD_MAKE})
472 include ${SPD_MAKE}
473
474 # If there's BL32 companion for the chosen SPD, we expect that the SPD's
475 # Makefile would set NEED_BL32 to "yes". In this case, the build system
476 # supports two mutually exclusive options:
477 # * BL32 is built from source: then BL32_SOURCES must contain the list
478 # of source files to build BL32
479 # * BL32 is a prebuilt binary: then BL32 must point to the image file
480 # that will be included in the FIP
481 # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
482 # over the sources.
483endif #(SPD=none)
484
Govindraj Raja35472702023-09-20 14:32:24 -0500485################################################################################
Olivier Deprez696ed162025-01-03 13:38:50 +0100486# Include the platform specific Makefile after the SPD Makefile (the platform
487# makefile may use all previous definitions in this file)
488################################################################################
489include ${PLAT_MAKEFILE_FULL}
490
491################################################################################
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100492# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
493# platform.
494################################################################################
495
496include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
497################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500498# Process BRANCH_PROTECTION value and set
499# Pointer Authentication and Branch Target Identification flags
500################################################################################
501ifeq (${BRANCH_PROTECTION},0)
502 # Default value turns off all types of branch protection
503 BP_OPTION := none
504else ifneq (${ARCH},aarch64)
505 $(error BRANCH_PROTECTION requires AArch64)
506else ifeq (${BRANCH_PROTECTION},1)
507 # Enables all types of branch protection features
508 BP_OPTION := standard
509 ENABLE_BTI := 1
510 ENABLE_PAUTH := 1
511else ifeq (${BRANCH_PROTECTION},2)
512 # Return address signing to its standard level
513 BP_OPTION := pac-ret
514 ENABLE_PAUTH := 1
515else ifeq (${BRANCH_PROTECTION},3)
516 # Extend the signing to include leaf functions
517 BP_OPTION := pac-ret+leaf
518 ENABLE_PAUTH := 1
519else ifeq (${BRANCH_PROTECTION},4)
520 # Turn on branch target identification mechanism
521 BP_OPTION := bti
522 ENABLE_BTI := 1
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100523else ifeq (${BRANCH_PROTECTION},5)
524 # Turn on branch target identification mechanism
525 BP_OPTION := standard
526 ENABLE_BTI := 2
527 ENABLE_PAUTH := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500528else
529 $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
530endif #(BRANCH_PROTECTION)
531
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100532ifneq ($(ENABLE_PAUTH),0)
533 CTX_INCLUDE_PAUTH_REGS := ${ENABLE_PAUTH}
Govindraj Rajaf5211422023-08-17 10:41:48 -0500534endif
535ifneq (${BP_OPTION},none)
536 TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION}
537endif #(BP_OPTION)
538
539# Pointer Authentication sources
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100540ifneq (${ENABLE_PAUTH},0)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500541# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
542# Pauth support. As it's not secure, it must be reimplemented for real platforms
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100543 BL_COMMON_SOURCES += lib/extensions/pauth/pauth.c
Govindraj Rajaf5211422023-08-17 10:41:48 -0500544endif
Boyan Karatotevb14987c2025-04-09 14:41:58 +0100545#
546ifneq (${ENABLE_FEAT_PAUTH_LR},0)
547# Currently, FEAT_PAUTH_LR is only supported by arm/clang compilers
548# TODO implement for GCC when support is added
549ifeq ($($(ARCH)-cc-id),arm-clang)
550 arch-features := $(arch-features)+pauth-lr
551else
552 $(error Error: ENABLE_FEAT_PAUTH_LR not supported for GCC compiler)
553endif
554endif
Govindraj Rajaf5211422023-08-17 10:41:48 -0500555
Govindraj Rajaf5211422023-08-17 10:41:48 -0500556################################################################################
557# RME dependent flags configuration, Enable optional features for RME.
558################################################################################
559# FEAT_RME
560ifeq (${ENABLE_RME},1)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500561 # RME requires el2 context to be saved for now.
562 CTX_INCLUDE_EL2_REGS := 1
563 CTX_INCLUDE_AARCH32_REGS := 0
564 CTX_INCLUDE_PAUTH_REGS := 1
565
Javier Almansa Sobrinod048af02025-03-21 18:32:10 +0000566 ifneq ($(ENABLE_FEAT_MPAM), 0)
567 CTX_INCLUDE_MPAM_REGS := 1
568 endif
569
Govindraj Rajaf5211422023-08-17 10:41:48 -0500570 # RME enables CSV2_2 extension by default.
571 ENABLE_FEAT_CSV2_2 = 1
572endif #(FEAT_RME)
573
574################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500575# Include rmmd Makefile if RME is enabled
576################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500577ifneq (${ENABLE_RME},0)
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500578include services/std_svc/rmmd/rmmd.mk
579$(warning "RME is an experimental feature")
580endif
581
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000582################################################################################
Govindraj Raja30655132024-09-06 15:43:43 +0100583# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
584################################################################################
585ifneq (${ENABLE_FEAT_D128}, 0)
586 BL_COMMON_SOURCES += lib/extensions/sysreg128/sysreg128.S
587endif
588
589################################################################################
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500590# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
591# up with appropriate march values for compiler.
592################################################################################
593include ${MAKE_HELPERS_DIRECTORY}march.mk
594
John Powell025b1b82025-03-10 20:09:03 -0500595TF_CFLAGS += $(march-directive)
Govindraj Raja7275ac22024-01-23 16:00:19 -0600596ASFLAGS += $(march-directive)
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500597
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600598# This internal flag is common option which is set to 1 for scenarios
599# when the BL2 is running in EL3 level. This occurs in two scenarios -
600# 4 world system running BL2 at EL3 and two world system without BL1 running
601# BL2 in EL3
602
603ifeq (${RESET_TO_BL2},1)
604 BL2_RUNS_AT_EL3 := 1
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100605 ifeq (${ENABLE_RME},1)
606 $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
607 supported at the moment.)
608 endif
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600609else ifeq (${ENABLE_RME},1)
610 BL2_RUNS_AT_EL3 := 1
611else
612 BL2_RUNS_AT_EL3 := 0
613endif
614
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100615# This internal flag is set to 1 when Firmware First handling of External aborts
616# is required by lowe ELs. Currently only NS requires this support.
617ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
618 FFH_SUPPORT := 1
619else
620 FFH_SUPPORT := 0
621endif
622
Etienne Carriere26e63c42017-11-08 13:48:40 +0100623ifeq (${ARM_ARCH_MAJOR},7)
624include make_helpers/armv7-a-cpus.mk
625endif
626
Masahiro Yamada320920c2020-01-17 13:44:37 +0900627PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
628ifneq ($(PIE_FOUND),)
629 TF_CFLAGS += -fno-PIE
Chris Kay8620bd02023-12-04 09:55:50 +0000630ifeq ($($(ARCH)-ld-id),gnu-gcc)
Samuel Holland7b592412022-04-08 21:56:02 -0500631 TF_LDFLAGS += -no-pie
632endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100633endif #(PIE_FOUND)
Masahiro Yamada320920c2020-01-17 13:44:37 +0900634
Chris Kay8620bd02023-12-04 09:55:50 +0000635ifeq ($($(ARCH)-ld-id),gnu-gcc)
Masahiro Yamada320920c2020-01-17 13:44:37 +0900636 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
Soby Mathew3bd17c02018-08-28 11:13:55 +0100637else
Masahiro Yamada320920c2020-01-17 13:44:37 +0900638 PIE_LDFLAGS += -pie --no-dynamic-linker
639endif
640
641ifeq ($(ENABLE_PIE),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100642 ifeq ($(RESET_TO_BL2),1)
643 ifneq ($(BL2_IN_XIP_MEM),1)
644 BL2_CPPFLAGS += -fpie
645 BL2_CFLAGS += -fpie
646 BL2_LDFLAGS += $(PIE_LDFLAGS)
647 endif #(BL2_IN_XIP_MEM)
648 endif #(RESET_TO_BL2)
Chris Kay966660e2023-02-02 14:39:03 +0000649 BL31_CPPFLAGS += -fpie
650 BL31_CFLAGS += -fpie
Masahiro Yamada320920c2020-01-17 13:44:37 +0900651 BL31_LDFLAGS += $(PIE_LDFLAGS)
Chris Kay966660e2023-02-02 14:39:03 +0000652
653 BL32_CPPFLAGS += -fpie
Masahiro Yamadad9743012020-01-17 13:45:14 +0900654 BL32_CFLAGS += -fpie
655 BL32_LDFLAGS += $(PIE_LDFLAGS)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100656endif #(ENABLE_PIE)
Soby Mathew3bd17c02018-08-28 11:13:55 +0100657
Boyan Karatotev007433d2023-01-25 16:55:18 +0000658BL1_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
659BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
660BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
661
Masahiro Yamada9cefb4b2020-04-01 14:20:58 +0900662BL1_CPPFLAGS += -DIMAGE_AT_EL3
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600663ifeq ($(RESET_TO_BL2),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100664 BL2_CPPFLAGS += -DIMAGE_AT_EL3
Masahiro Yamadad5e97a12020-03-26 13:18:48 +0900665else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100666 BL2_CPPFLAGS += -DIMAGE_AT_EL1
667endif #(RESET_TO_BL2)
Boyan Karatotev007433d2023-01-25 16:55:18 +0000668
669ifeq (${ARCH},aarch64)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100670 BL2U_CPPFLAGS += -DIMAGE_AT_EL1
671 BL31_CPPFLAGS += -DIMAGE_AT_EL3
672 BL32_CPPFLAGS += -DIMAGE_AT_EL1
Boyan Karatotev007433d2023-01-25 16:55:18 +0000673else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100674 BL32_CPPFLAGS += -DIMAGE_AT_EL3
Masahiro Yamadad5e97a12020-03-26 13:18:48 +0900675endif
676
Sandrine Bailleux54035fc2016-01-13 14:57:38 +0000677# Include the CPU specific operations makefile, which provides default
678# values for all CPU errata workarounds and CPU specific optimisations.
679# This can be overridden by the platform.
Juan Castillo73c99d42015-08-18 14:23:04 +0100680include lib/cpus/cpu-ops.mk
Achin Gupta4f6ad662013-10-25 09:08:21 +0100681
dp-arma4409002017-02-15 11:07:55 +0000682################################################################################
683# Build `AARCH32_SP` as BL32 image for AArch32
684################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100685ifeq (${ARCH},aarch32)
686 NEED_BL32 := yes
dp-arma4409002017-02-15 11:07:55 +0000687
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100688 ifneq (${AARCH32_SP},none)
689 # We expect to locate an sp.mk under the specified AARCH32_SP directory
690 AARCH32_SP_MAKE := $(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
dp-arma4409002017-02-15 11:07:55 +0000691
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100692 ifeq (${AARCH32_SP_MAKE},)
693 $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
694 endif
Juan Pablo Conde043f38f2023-08-09 13:19:21 -0500695 $(info Including ${AARCH32_SP_MAKE})
696 include ${AARCH32_SP_MAKE}
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100697 endif
698endif #(ARCH=aarch32)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100699
Juan Castillo73c99d42015-08-18 14:23:04 +0100700################################################################################
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800701# Include libc if not overridden
702################################################################################
703ifeq (${OVERRIDE_LIBC},0)
704include lib/libc/libc.mk
705endif
706
Boyan Karatotev5d893412025-01-07 11:00:03 +0000707ifneq (${USE_GIC_DRIVER},0)
708include drivers/arm/gic/gic.mk
709endif
710
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800711################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100712# Check incompatible options and dependencies
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000713################################################################################
Boyan Karatotevb14987c2025-04-09 14:41:58 +0100714include ${MAKE_HELPERS_DIRECTORY}constraints.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100715
716# The cert_create tool cannot generate certificates individually, so we use the
717# target 'certificates' to create them all
718ifneq (${GENERATE_COT},0)
719 FIP_DEPS += certificates
720 FWU_FIP_DEPS += fwu_certificates
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000721endif
722
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100723ifneq (${DECRYPTION_SUPPORT},none)
724 ENC_ARGS += -f ${FW_ENC_STATUS}
725 ENC_ARGS += -k ${ENC_KEY}
726 ENC_ARGS += -n ${ENC_NONCE}
727 FIP_DEPS += enctool
728 FWU_FIP_DEPS += enctool
729endif #(DECRYPTION_SUPPORT)
730
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100731ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
732# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100733 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100734else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
735# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100736 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100737else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
738# Support hash calculation only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100739 CRYPTO_SUPPORT := 2
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100740else ifeq (${TRUSTED_BOARD_BOOT},1)
741# Support authentication verification only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100742 CRYPTO_SUPPORT := 1
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000743else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100744 CRYPTO_SUPPORT := 0
745endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000746
Manish V Badarkhee4a070e2024-12-03 21:46:51 +0000747ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
748CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
749endif
750
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000751################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100752# Process platform overrideable behaviour
753################################################################################
Achin Gupta4f6ad662013-10-25 09:08:21 +0100754
Manish Pandey5f24ce92021-10-06 10:59:52 +0100755ifdef BL1_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100756 NEED_BL1 := yes
757endif #(BL1_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100758
Juan Castillo73c99d42015-08-18 14:23:04 +0100759ifdef BL2_SOURCES
Manish Pandey5f24ce92021-10-06 10:59:52 +0100760 NEED_BL2 := yes
761
762 # Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
763 # Certificate generation tools. This flag can be overridden by the platform.
764 ifdef EL3_PAYLOAD_BASE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100765 # If booting an EL3 payload there is no need for a BL33 image
766 # in the FIP file.
767 NEED_BL33 := no
768 else
769 ifdef PRELOADED_BL33_BASE
770 # If booting a BL33 preloaded image there is no need of
771 # another one in the FIP file.
772 NEED_BL33 := no
773 else
774 NEED_BL33 ?= yes
775 endif
776 endif
777endif #(BL2_SOURCES)
Juan Castillo73c99d42015-08-18 14:23:04 +0100778
Manish Pandey5f24ce92021-10-06 10:59:52 +0100779ifdef BL2U_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100780 NEED_BL2U := yes
781endif #(BL2U_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100782
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900783# If SCP_BL2 is given, we always want FIP to include it.
784ifdef SCP_BL2
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100785 NEED_SCP_BL2 := yes
786endif #(SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900787
Soby Mathew5744e872017-11-14 14:10:10 +0000788# For AArch32, BL31 is not currently supported.
789ifneq (${ARCH},aarch32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100790 ifdef BL31_SOURCES
791 # When booting an EL3 payload, there is no need to compile the BL31
792 # image nor put it in the FIP.
793 ifndef EL3_PAYLOAD_BASE
794 NEED_BL31 := yes
795 endif
796 endif
797endif #(ARCH=aarch64)
Soby Mathew5744e872017-11-14 14:10:10 +0000798
Juan Castillo73c99d42015-08-18 14:23:04 +0100799# Process TBB related flags
800ifneq (${GENERATE_COT},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100801 # Common cert_create options
802 ifneq (${CREATE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +0100803 $(eval CRT_ARGS += -n)
Yatharth Kochar01912622015-10-12 12:33:47 +0100804 $(eval FWU_CRT_ARGS += -n)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100805 ifneq (${SAVE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +0100806 $(eval CRT_ARGS += -k)
Yatharth Kochar01912622015-10-12 12:33:47 +0100807 $(eval FWU_CRT_ARGS += -k)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100808 endif
809 endif
810 # Include TBBR makefile (unless the platform indicates otherwise)
811 ifeq (${INCLUDE_TBBR_MK},1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100812 include make_helpers/tbbr/tbbr_tools.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100813 endif
814endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +0100815
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +0900816ifneq (${FIP_ALIGN},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100817 FIP_ARGS += --align ${FIP_ALIGN}
818endif #(FIP_ALIGN)
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +0900819
Manish Pandey5f24ce92021-10-06 10:59:52 +0100820ifdef FDT_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100821 NEED_FDT := yes
822endif #(FDT_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100823
Juan Castillo73c99d42015-08-18 14:23:04 +0100824################################################################################
Michalis Pappas46e5e032018-03-20 13:01:27 +0800825# Include libraries' Makefile that are used in all BL
826################################################################################
827
828include lib/stack_protector/stack_protector.mk
829
830################################################################################
Soby Mathew8a860522017-02-14 10:05:07 +0000831# Include BL specific makefiles
832################################################################################
Manish Pandey5f24ce92021-10-06 10:59:52 +0100833
834ifeq (${NEED_BL1},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000835include bl1/bl1.mk
836endif
837
Manish Pandey5f24ce92021-10-06 10:59:52 +0100838ifeq (${NEED_BL2},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000839include bl2/bl2.mk
840endif
841
Manish Pandey5f24ce92021-10-06 10:59:52 +0100842ifeq (${NEED_BL2U},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000843include bl2u/bl2u.mk
844endif
845
Soby Mathew5744e872017-11-14 14:10:10 +0000846ifeq (${NEED_BL31},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000847include bl31/bl31.mk
848endif
Nishanth Menon03b397a2016-10-14 01:13:57 +0000849
Juan Castillo73c99d42015-08-18 14:23:04 +0100850################################################################################
851# Build options checks
852################################################################################
Juan Castillob7124ea2014-11-04 17:36:40 +0000853
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100854# Boolean_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500855$(eval $(call assert_booleans,\
856 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100857 ALLOW_RO_XLAT_TABLES \
858 BL2_ENABLE_SP_LOAD \
859 COLD_BOOT_SINGLE_CPU \
860 CREATE_KEYS \
861 CTX_INCLUDE_AARCH32_REGS \
862 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -0500863 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100864 CTX_INCLUDE_EL2_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -0500865 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100866 DEBUG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100867 DYN_DISABLE_AUTH \
868 EL3_EXCEPTION_HANDLING \
869 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100870 AMU_RESTRICT_COUNTERS \
871 ENABLE_ASSERTIONS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100872 ENABLE_PIE \
873 ENABLE_PMF \
874 ENABLE_PSCI_STAT \
875 ENABLE_RUNTIME_INSTRUMENTATION \
876 ENABLE_SME_FOR_SWD \
877 ENABLE_SVE_FOR_SWD \
Boyan Karatotev8cef63d2025-01-07 11:26:56 +0000878 ENABLE_FEAT_GCIE \
Manish Pandey970a4a82023-10-10 13:53:25 +0100879 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100880 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100881 ERROR_DEPRECATED \
882 FAULT_INJECTION_SUPPORT \
883 GENERATE_COT \
884 GICV2_G0_FOR_EL3 \
885 HANDLE_EA_EL3_FIRST_NS \
Bipin Ravi538516f2023-09-28 13:17:24 -0500886 HARDEN_SLS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100887 HW_ASSISTED_COHERENCY \
888 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -0500889 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +0200890 DICE_PROTECTION_ENVIRONMENT \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -0700891 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -0500892 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100893 DRTM_SUPPORT \
894 NS_TIMER_SWITCH \
895 OVERRIDE_LIBC \
896 PL011_GENERIC_UART \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100897 PROGRAMMABLE_RESET_ADDRESS \
898 PSCI_EXTENDED_STATE_ID \
899 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +0100900 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100901 RESET_TO_BL31 \
902 SAVE_KEYS \
903 SEPARATE_CODE_AND_RODATA \
904 SEPARATE_BL2_NOLOAD_REGION \
905 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +0800906 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -0500907 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100908 SPIN_ON_BL1_EXIT \
909 SPM_MM \
910 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +0100911 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100912 SPMD_SPM_AT_SEL2 \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -0800913 ENABLE_SPMD_LP \
Raymond Mao3ba2c152023-07-25 07:53:35 -0700914 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100915 TRUSTED_BOARD_BOOT \
916 USE_COHERENT_MEM \
917 USE_DEBUGFS \
918 ARM_IO_IN_DTB \
919 SDEI_IN_FCONF \
920 SEC_INT_DESC_IN_FCONF \
921 USE_ROMLIB \
922 USE_TBBR_DEFS \
923 WARMBOOT_ENABLE_DCACHE_EARLY \
924 RESET_TO_BL2 \
925 BL2_IN_XIP_MEM \
926 BL2_INV_DCACHE \
927 USE_SPINLOCK_CAS \
928 ENCRYPT_BL31 \
929 ENCRYPT_BL32 \
930 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +0100931 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100932 RAS_TRAP_NS_ERR_REC_ACCESS \
933 COT_DESC_IN_DTB \
934 USE_SP804_TIMER \
935 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +0530936 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100937 ENABLE_MPMM \
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +0000938 FEAT_PABANDON \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100939 FEATURE_DETECTION \
Jayanth Dodderi Chidanand0b22e592022-10-11 17:16:07 +0100940 TRNG_SUPPORT \
Boyan Karatotev593ae352023-03-22 15:55:36 +0000941 ENABLE_ERRATA_ALL \
Sona Mathewffea3842022-11-18 18:05:38 -0600942 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -0500943 ERRATA_NON_ARM_INTERCONNECT \
Okash Khawaja04c73032022-11-04 12:38:01 +0000944 CONDITIONAL_CMO \
Manish V Badarkhe5782b892023-09-06 09:08:28 +0100945 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +0200946 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -0500947 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -0600948 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +0100949 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -0600950 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +0100951 HOB_LIST \
Manish V Badarkhecf48f492025-04-15 20:16:32 +0100952 LFA_SUPPORT \
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500953)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100954
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100955# Numeric_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500956$(eval $(call assert_numerics,\
957 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100958 ARM_ARCH_MAJOR \
959 ARM_ARCH_MINOR \
960 BRANCH_PROTECTION \
961 CTX_INCLUDE_PAUTH_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100962 CTX_INCLUDE_NEVE_REGS \
963 CRYPTO_SUPPORT \
Boyan Karatotev83a4dae2023-02-16 09:45:29 +0000964 DISABLE_MTPMU \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100965 ENABLE_BRBE_FOR_NS \
966 ENABLE_TRBE_FOR_NS \
967 ENABLE_BTI \
968 ENABLE_PAUTH \
John Powell025b1b82025-03-10 20:09:03 -0500969 ENABLE_FEAT_PAUTH_LR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100970 ENABLE_FEAT_AMU \
971 ENABLE_FEAT_AMUv1p1 \
972 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -0500973 ENABLE_FEAT_CSV2_3 \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -0500974 ENABLE_FEAT_DEBUGV8P9 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100975 ENABLE_FEAT_DIT \
976 ENABLE_FEAT_ECV \
977 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -0500978 ENABLE_FEAT_FGT2 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600979 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100980 ENABLE_FEAT_HCX \
Andre Przywara19d52a82024-08-09 17:04:22 +0100981 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000982 ENABLE_FEAT_MEC \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -0600983 ENABLE_FEAT_MOPS \
Govindraj Raja8e397882024-01-26 10:08:37 -0600984 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100985 ENABLE_FEAT_PAN \
986 ENABLE_FEAT_RNG \
987 ENABLE_FEAT_RNG_TRAP \
988 ENABLE_FEAT_SEL2 \
989 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +0100990 ENABLE_FEAT_THE \
Govindraj Raja0e4daed2024-01-23 16:03:53 -0600991 ENABLE_FEAT_SB \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100992 ENABLE_FEAT_S2PIE \
993 ENABLE_FEAT_S1PIE \
994 ENABLE_FEAT_S2POE \
995 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +0100996 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +0100997 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100998 ENABLE_FEAT_GCS \
999 ENABLE_FEAT_VHE \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -05001000 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001001 ENABLE_RME \
1002 ENABLE_SPE_FOR_NS \
1003 ENABLE_SYS_REG_TRACE_FOR_NS \
1004 ENABLE_SME_FOR_NS \
1005 ENABLE_SME2_FOR_NS \
1006 ENABLE_SVE_FOR_NS \
1007 ENABLE_TRF_FOR_NS \
1008 FW_ENC_STATUS \
1009 NR_OF_FW_BANKS \
1010 NR_OF_IMAGES_IN_FW_BANK \
1011 TWED_DELAY \
1012 ENABLE_FEAT_TWED \
1013 SVE_VECTOR_LEN \
Varun Wadekar0ed3be62023-04-13 21:06:18 +01001014 IMPDEF_SYSREG_TRAP \
Boyan Karatotevee580c22025-04-11 14:27:55 +01001015 W \
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001016)))
Jeenu Viswambharanc877b412017-01-16 16:52:35 +00001017
Justin Chadwellaacff742019-07-29 17:13:10 +01001018ifdef KEY_SIZE
1019 $(eval $(call assert_numeric,KEY_SIZE))
1020endif
1021
Justin Chadwell1f461972019-08-20 11:01:52 +01001022ifeq ($(filter $(SANITIZE_UB), on off trap),)
1023 $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1024endif
1025
Juan Castillo73c99d42015-08-18 14:23:04 +01001026################################################################################
1027# Add definitions to the cpp preprocessor based on the current build options.
1028# This is done after including the platform specific makefile to allow the
1029# platform to overwrite the default options
1030################################################################################
1031
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001032$(eval $(call add_defines,\
1033 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001034 ALLOW_RO_XLAT_TABLES \
1035 ARM_ARCH_MAJOR \
1036 ARM_ARCH_MINOR \
1037 BL2_ENABLE_SP_LOAD \
1038 COLD_BOOT_SINGLE_CPU \
1039 CTX_INCLUDE_AARCH32_REGS \
1040 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -05001041 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001042 CTX_INCLUDE_PAUTH_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -05001043 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001044 EL3_EXCEPTION_HANDLING \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001045 CTX_INCLUDE_EL2_REGS \
1046 CTX_INCLUDE_NEVE_REGS \
Boyan Karatotevee580c22025-04-11 14:27:55 +01001047 DEBUG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001048 DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1049 DISABLE_MTPMU \
1050 ENABLE_FEAT_AMU \
1051 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001052 AMU_RESTRICT_COUNTERS \
1053 ENABLE_ASSERTIONS \
1054 ENABLE_BTI \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -05001055 ENABLE_FEAT_DEBUGV8P9 \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -05001056 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001057 ENABLE_PAUTH \
John Powell025b1b82025-03-10 20:09:03 -05001058 ENABLE_FEAT_PAUTH_LR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001059 ENABLE_PIE \
1060 ENABLE_PMF \
1061 ENABLE_PSCI_STAT \
1062 ENABLE_RME \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -07001063 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -05001064 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001065 ENABLE_RUNTIME_INSTRUMENTATION \
1066 ENABLE_SME_FOR_NS \
1067 ENABLE_SME2_FOR_NS \
1068 ENABLE_SME_FOR_SWD \
1069 ENABLE_SPE_FOR_NS \
1070 ENABLE_SVE_FOR_NS \
1071 ENABLE_SVE_FOR_SWD \
Manish Pandey970a4a82023-10-10 13:53:25 +01001072 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +01001073 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001074 ENCRYPT_BL31 \
1075 ENCRYPT_BL32 \
1076 ERROR_DEPRECATED \
1077 FAULT_INJECTION_SUPPORT \
1078 GICV2_G0_FOR_EL3 \
1079 HANDLE_EA_EL3_FIRST_NS \
1080 HW_ASSISTED_COHERENCY \
1081 LOG_LEVEL \
1082 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -05001083 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +02001084 DICE_PROTECTION_ENVIRONMENT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001085 DRTM_SUPPORT \
1086 NS_TIMER_SWITCH \
1087 PL011_GENERIC_UART \
1088 PLAT_${PLAT} \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001089 PROGRAMMABLE_RESET_ADDRESS \
1090 PSCI_EXTENDED_STATE_ID \
1091 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +01001092 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001093 RESET_TO_BL31 \
AlexeiFedorovd7660842024-05-13 15:35:54 +01001094 RME_GPT_BITLOCK_BLOCK \
AlexeiFedorovec0088b2024-03-13 17:07:03 +00001095 RME_GPT_MAX_BLOCK \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001096 SEPARATE_CODE_AND_RODATA \
1097 SEPARATE_BL2_NOLOAD_REGION \
1098 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +08001099 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -05001100 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001101 RECLAIM_INIT_CODE \
1102 SPD_${SPD} \
1103 SPIN_ON_BL1_EXIT \
1104 SPM_MM \
1105 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +01001106 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001107 SPMD_SPM_AT_SEL2 \
Raymond Mao3ba2c152023-07-25 07:53:35 -07001108 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001109 TRUSTED_BOARD_BOOT \
1110 CRYPTO_SUPPORT \
1111 TRNG_SUPPORT \
1112 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -05001113 ERRATA_NON_ARM_INTERCONNECT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001114 USE_COHERENT_MEM \
1115 USE_DEBUGFS \
1116 ARM_IO_IN_DTB \
1117 SDEI_IN_FCONF \
1118 SEC_INT_DESC_IN_FCONF \
1119 USE_ROMLIB \
1120 USE_TBBR_DEFS \
1121 WARMBOOT_ENABLE_DCACHE_EARLY \
1122 RESET_TO_BL2 \
1123 BL2_RUNS_AT_EL3 \
1124 BL2_IN_XIP_MEM \
1125 BL2_INV_DCACHE \
1126 USE_SPINLOCK_CAS \
1127 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +01001128 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001129 RAS_TRAP_NS_ERR_REC_ACCESS \
1130 COT_DESC_IN_DTB \
1131 USE_SP804_TIMER \
1132 ENABLE_FEAT_RNG \
1133 ENABLE_FEAT_RNG_TRAP \
1134 ENABLE_FEAT_SB \
1135 ENABLE_FEAT_DIT \
1136 NR_OF_FW_BANKS \
1137 NR_OF_IMAGES_IN_FW_BANK \
1138 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +05301139 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001140 ENABLE_BRBE_FOR_NS \
1141 ENABLE_TRBE_FOR_NS \
1142 ENABLE_SYS_REG_TRACE_FOR_NS \
1143 ENABLE_TRF_FOR_NS \
1144 ENABLE_FEAT_HCX \
1145 ENABLE_MPMM \
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +00001146 FEAT_PABANDON \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001147 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -05001148 ENABLE_FEAT_FGT2 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -06001149 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001150 ENABLE_FEAT_ECV \
1151 ENABLE_FEAT_AMUv1p1 \
1152 ENABLE_FEAT_SEL2 \
1153 ENABLE_FEAT_VHE \
1154 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -05001155 ENABLE_FEAT_CSV2_3 \
Andre Przywara19d52a82024-08-09 17:04:22 +01001156 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +00001157 ENABLE_FEAT_MEC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001158 ENABLE_FEAT_PAN \
1159 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +01001160 ENABLE_FEAT_THE \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001161 ENABLE_FEAT_S2PIE \
1162 ENABLE_FEAT_S1PIE \
1163 ENABLE_FEAT_S2POE \
1164 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +01001165 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +01001166 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001167 ENABLE_FEAT_GCS \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -06001168 ENABLE_FEAT_MOPS \
Boyan Karatotev8cef63d2025-01-07 11:26:56 +00001169 ENABLE_FEAT_GCIE \
Govindraj Raja8e397882024-01-26 10:08:37 -06001170 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001171 FEATURE_DETECTION \
1172 TWED_DELAY \
1173 ENABLE_FEAT_TWED \
Okash Khawaja04c73032022-11-04 12:38:01 +00001174 CONDITIONAL_CMO \
Varun Wadekar0ed3be62023-04-13 21:06:18 +01001175 IMPDEF_SYSREG_TRAP \
Jayanth Dodderi Chidananda8cf6fa2023-04-26 15:57:30 +01001176 SVE_VECTOR_LEN \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -08001177 ENABLE_SPMD_LP \
Manish V Badarkhe5782b892023-09-06 09:08:28 +01001178 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +02001179 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -05001180 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001181 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +01001182 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -06001183 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +01001184 HOB_LIST \
Manish V Badarkhecf48f492025-04-15 20:16:32 +01001185 LFA_SUPPORT \
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001186)))
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +01001187
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001188ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1189ifeq (${DEBUG}, 0)
1190 $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1191 override PLATFORM_REPORT_CTX_MEM_USE := 0
1192endif
1193endif
1194
Justin Chadwell1f461972019-08-20 11:01:52 +01001195ifeq (${SANITIZE_UB},trap)
1196 $(eval $(call add_define,MONITOR_TRAPS))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001197endif #(SANITIZE_UB)
Justin Chadwell1f461972019-08-20 11:01:52 +01001198
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001199# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1200ifdef EL3_PAYLOAD_BASE
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001201 $(eval $(call add_define,EL3_PAYLOAD_BASE))
1202else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001203# Define the PRELOADED_BL33_BASE flag only if it is provided and
1204# EL3_PAYLOAD_BASE is not defined, as it has priority.
1205 ifdef PRELOADED_BL33_BASE
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01001206 $(eval $(call add_define,PRELOADED_BL33_BASE))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001207 endif
1208endif #(EL3_PAYLOAD_BASE)
Juan Castillo73c99d42015-08-18 14:23:04 +01001209
Soby Mathew209a60c2018-03-26 12:43:37 +01001210# Define the DYN_DISABLE_AUTH flag only if set.
1211ifeq (${DYN_DISABLE_AUTH},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001212 $(eval $(call add_define,DYN_DISABLE_AUTH))
Soby Mathew209a60c2018-03-26 12:43:37 +01001213endif
1214
Chris Kay8620bd02023-12-04 09:55:50 +00001215ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001216 $(eval $(call add_define,USE_ARM_LINK))
Varun Wadekarc2ad38c2019-01-11 14:47:48 -08001217endif
1218
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001219# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001220ifeq (${SPD},spmd)
Olivier Deprezc33ff192020-03-19 09:27:11 +01001221ifdef SP_LAYOUT_FILE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001222 -include $(BUILD_PLAT)/sp_gen.mk
1223 FIP_DEPS += sp
1224 CRT_DEPS += sp
1225 NEED_SP_PKG := yes
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001226else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001227 ifeq (${SPMD_SPM_AT_SEL2},1)
1228 $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1229 endif
1230endif #(SP_LAYOUT_FILE)
1231endif #(SPD)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001232
Juan Castillo73c99d42015-08-18 14:23:04 +01001233################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +01001234# Build targets
1235################################################################################
1236
Harrison Mutai2329e222024-08-28 13:27:19 +00001237.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 +01001238
1239all: msg_start
1240
1241msg_start:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001242 $(s)echo "Building ${PLAT}"
Juan Castillo73c99d42015-08-18 14:23:04 +01001243
Soby Mathew7a24cba2015-10-26 14:29:21 +00001244ifeq (${ERROR_DEPRECATED},0)
Julius Wernerd5dfdeb2019-07-09 13:49:11 -07001245# Check if deprecated declarations and cpp warnings should be treated as error or not.
Chris Kay8620bd02023-12-04 09:55:50 +00001246ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -08001247 CPPFLAGS += -Wno-error=deprecated-declarations
1248else
Dan Handleybc1a03c2018-02-27 16:03:58 +00001249 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp
Soby Mathew7a24cba2015-10-26 14:29:21 +00001250endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001251endif #(!ERROR_DEPRECATED)
Soby Mathew7a24cba2015-10-26 14:29:21 +00001252
Roberto Vargas61f72a32018-05-08 10:27:10 +01001253$(eval $(call MAKE_LIB,c))
Roberto Vargas5fee0282018-05-08 10:27:10 +01001254
Juan Castillo73c99d42015-08-18 14:23:04 +01001255# Expand build macros for the different images
1256ifeq (${NEED_BL1},yes)
Chris Kayb34635a2021-09-28 15:44:19 +01001257BL1_SOURCES := $(sort ${BL1_SOURCES})
Zelalem Aweke434d0492021-07-11 17:25:48 -05001258$(eval $(call MAKE_BL,bl1))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001259endif #(NEED_BL1)
Juan Castillo73c99d42015-08-18 14:23:04 +01001260
1261ifeq (${NEED_BL2},yes)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001262
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -06001263ifeq (${RESET_TO_BL2}, 0)
Roberto Vargasc9b31ae2018-01-02 11:23:41 +00001264FIP_BL2_ARGS := tb-fw
1265endif
1266
Chris Kayeb1acfb2021-09-28 15:44:37 +01001267BL2_SOURCES := $(sort ${BL2_SOURCES})
1268
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001269$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001270 $(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001271
1272endif #(NEED_BL2)
Juan Castillo73c99d42015-08-18 14:23:04 +01001273
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001274ifeq (${NEED_SCP_BL2},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001275$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001276endif #(NEED_SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001277
Juan Castillo73c99d42015-08-18 14:23:04 +01001278ifeq (${NEED_BL31},yes)
1279BL31_SOURCES += ${SPD_SOURCES}
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001280# Sort BL31 source files to remove duplicates
1281BL31_SOURCES := $(sort ${BL31_SOURCES})
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301282ifneq (${DECRYPTION_SUPPORT},none)
1283$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001284 $(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301285else
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001286$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001287 $(eval $(call MAKE_BL,bl31,soc-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001288endif #(DECRYPTION_SUPPORT)
1289endif #(NEED_BL31)
Juan Castillo73c99d42015-08-18 14:23:04 +01001290
Juan Castillo70d1fc52015-11-12 10:59:26 +00001291# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
Masahiro Yamadac939d132018-01-26 11:42:01 +09001292# build system will call TOOL_ADD_IMG to print a warning message and abort the
Juan Castillo70d1fc52015-11-12 10:59:26 +00001293# process. Note that the dependency on BL32 applies to the FIP only.
Juan Castillo73c99d42015-08-18 14:23:04 +01001294ifeq (${NEED_BL32},yes)
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001295# Sort BL32 source files to remove duplicates
1296BL32_SOURCES := $(sort ${BL32_SOURCES})
Masahiro Yamada9cd15232018-01-26 11:42:01 +09001297BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1298
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301299ifneq (${DECRYPTION_SUPPORT},none)
Zelalem Aweke434d0492021-07-11 17:25:48 -05001300$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301301 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1302else
Zelalem Aweke434d0492021-07-11 17:25:48 -05001303$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001304 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001305endif #(DECRYPTION_SUPPORT)
1306endif #(NEED_BL32)
Juan Castillo73c99d42015-08-18 14:23:04 +01001307
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001308# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1309# needs to be built from RMM_SOURCES.
1310ifeq (${NEED_RMM},yes)
1311# Sort RMM source files to remove duplicates
1312RMM_SOURCES := $(sort ${RMM_SOURCES})
1313BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1314
1315$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001316 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1317endif #(NEED_RMM)
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001318
Juan Castillo73c99d42015-08-18 14:23:04 +01001319# Add the BL33 image if required by the platform
1320ifeq (${NEED_BL33},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001321$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001322endif #(NEED_BL33)
Juan Castillodb6071c2015-01-13 12:21:04 +00001323
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001324ifeq (${NEED_BL2U},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001325$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001326 $(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001327endif #(NEED_BL2U)
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001328
Nishanth Menon03b397a2016-10-14 01:13:57 +00001329# Expand build macros for the different images
1330ifeq (${NEED_FDT},yes)
Soby Mathew38c14d82017-12-14 17:44:56 +00001331 $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
Salman Nabi1c08ff32024-12-12 17:38:54 +00001332
1333 ifneq (${INITRD_SIZE}${INITRD_PATH},)
1334 ifndef INITRD_BASE
1335 $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1336 endif
1337
1338 INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1339 initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1340
1341 define $(HW_CONFIG)-after +=
1342 $(s)echo " INITRD $(HW_CONFIG)"
1343 $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1344 $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1345 endef
1346 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001347endif #(NEED_FDT)
Nishanth Menon03b397a2016-10-14 01:13:57 +00001348
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001349# Add Secure Partition packages
1350ifeq (${NEED_SP_PKG},yes)
Chris Kayfd74ca02024-07-30 13:33:56 +00001351$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
Chris Kay679e27c2025-03-19 15:04:47 +00001352 $(if $(host-poetry),$(q)poetry -q install --no-root)
Kathleen Capelladd816232025-02-13 17:34:21 -06001353 $(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
J-Alves822c7272022-03-22 16:28:51 +00001354sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001355 $(s)echo
1356 $(s)echo "Built SP Images successfully"
1357 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001358endif #(NEED_SP_PKG)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001359
Ian Spray36eaaf32014-01-30 17:25:28 +00001360locate-checkpatch:
1361ifndef CHECKPATCH
Etienne Carriere66079b02017-08-23 15:44:01 +02001362 $(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 +00001363else
1364ifeq (,$(wildcard ${CHECKPATCH}))
Etienne Carriere66079b02017-08-23 15:44:01 +02001365 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
Ian Spray36eaaf32014-01-30 17:25:28 +00001366endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001367endif #(CHECKPATCH)
Ian Spray36eaaf32014-01-30 17:25:28 +00001368
Achin Gupta4f6ad662013-10-25 09:08:21 +01001369clean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001370 $(s)echo " CLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001371 $(q)rm -rf $(BUILD_PLAT)
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001372 $(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001373 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1374 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1375 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001376
James Morrisseyeaaeece2013-11-01 13:56:59 +00001377realclean distclean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001378 $(s)echo " REALCLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001379 $(q)rm -rf $(BUILD_BASE)
1380 $(q)rm -rf $(CURDIR)/cscope.*
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001381 $(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001382 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1383 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1384 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001385
Ian Spray36eaaf32014-01-30 17:25:28 +00001386checkcodebase: locate-checkpatch
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001387 $(s)echo " CHECKING STYLE"
1388 $(q)if test -d .git ; then \
Paul Beesley1ef35512019-03-07 16:42:31 +00001389 git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' | \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001390 while read GIT_FILE ; \
1391 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
1392 done ; \
1393 else \
1394 find . -type f -not -iwholename "*.git*" \
1395 -not -iwholename "*build*" \
1396 -not -iwholename "*libfdt*" \
Roberto Vargas61f72a32018-05-08 10:27:10 +01001397 -not -iwholename "*libc*" \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001398 -not -iwholename "*docs*" \
Paul Beesley1ef35512019-03-07 16:42:31 +00001399 -not -iwholename "*.rst" \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001400 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
1401 fi
Ian Spray36eaaf32014-01-30 17:25:28 +00001402
1403checkpatch: locate-checkpatch
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001404 $(s)echo " CHECKING STYLE"
1405 $(q)if test -n "${CHECKPATCH_OPTS}"; then \
Yann Gautier02a76d52019-03-08 15:44:00 +01001406 echo " with ${CHECKPATCH_OPTS} option(s)"; \
1407 fi
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001408 $(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
Yann Gautier77a0a7f2021-11-02 18:03:31 +01001409 for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`; \
1410 do \
Antonio Nino Diaz51d28932018-01-29 12:00:31 +00001411 printf "\n[*] Checking style of '$$commit'\n\n"; \
Yann Gautier1a721742024-08-09 11:52:03 +02001412 ( git log --format=email "$$commit~..$$commit" \
1413 -- ${CHECK_PATHS} ; \
1414 git diff --format=email "$$commit~..$$commit" \
1415 -- ${CHECK_PATHS}; ) | \
Yann Gautier02a76d52019-03-08 15:44:00 +01001416 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \
Antonio Nino Diaz51d28932018-01-29 12:00:31 +00001417 done
Juan Castillo73c99d42015-08-18 14:23:04 +01001418
1419certtool: ${CRTTOOL}
Ian Spray36eaaf32014-01-30 17:25:28 +00001420
Pali Rohára9812202020-11-24 15:38:08 +01001421${CRTTOOL}: FORCE
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001422 $(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
1423 $(s)echo
1424 $(s)echo "Built $@ successfully"
1425 $(s)echo
Juan Castillo73c99d42015-08-18 14:23:04 +01001426
1427ifneq (${GENERATE_COT},0)
1428certificates: ${CRT_DEPS} ${CRTTOOL}
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001429 $(q)${CRTTOOL} ${CRT_ARGS}
1430 $(s)echo
1431 $(s)echo "Built $@ successfully"
1432 $(s)echo "Certificates can be found in ${BUILD_PLAT}"
1433 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001434endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +01001435
1436${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
Pali Rohár4727fd12020-11-24 16:53:04 +01001437 $(eval ${CHECK_FIP_CMD})
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001438 $(q)${FIPTOOL} create ${FIP_ARGS} $@
1439 $(q)${FIPTOOL} info $@
1440 $(s)echo
1441 $(s)echo "Built $@ successfully"
1442 $(s)echo
Juan Castillo73c99d42015-08-18 14:23:04 +01001443
Yatharth Kochar01912622015-10-12 12:33:47 +01001444ifneq (${GENERATE_COT},0)
1445fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001446 $(q)${CRTTOOL} ${FWU_CRT_ARGS}
1447 $(s)echo
1448 $(s)echo "Built $@ successfully"
1449 $(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1450 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001451endif #(GENERATE_COT)
Yatharth Kochar01912622015-10-12 12:33:47 +01001452
1453${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
Pali Rohár4727fd12020-11-24 16:53:04 +01001454 $(eval ${CHECK_FWU_FIP_CMD})
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001455 $(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1456 $(q)${FIPTOOL} info $@
1457 $(s)echo
1458 $(s)echo "Built $@ successfully"
1459 $(s)echo
Yatharth Kochar01912622015-10-12 12:33:47 +01001460
Juan Castillo73c99d42015-08-18 14:23:04 +01001461fiptool: ${FIPTOOL}
1462fip: ${BUILD_PLAT}/${FIP_NAME}
Yatharth Kochar01912622015-10-12 12:33:47 +01001463fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
Juan Castillo6f971622014-10-21 11:30:42 +01001464
Pali Rohára9812202020-11-24 15:38:08 +01001465${FIPTOOL}: FORCE
Manish V Badarkhe40469bf2024-10-03 20:50:04 +01001466 $(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 +00001467
Manish V Badarkhee4a070e2024-12-03 21:46:51 +00001468$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB)
1469 $(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 +01001470
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001471memmap: all
Chris Kayc25405d2025-03-10 09:24:34 +00001472 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kay8daebef2025-04-15 14:00:50 +01001473 $(q)$(if $(host-poetry),poetry run )memory symbols --root ${BUILD_PLAT}
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001474
Harrison Mutai2329e222024-08-28 13:27:19 +00001475tl: ${BUILD_PLAT}/tl.bin
1476${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
Chris Kayc25405d2025-03-10 09:24:34 +00001477 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kayd2867392024-09-26 14:18:04 +00001478 $(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
Harrison Mutai2329e222024-08-28 13:27:19 +00001479
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001480doc:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001481 $(s)echo " BUILD DOCUMENTATION"
Harrison Mutaic61c9a32025-05-15 08:47:34 +00001482 $(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1483 $(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} html
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001484
Sumit Garg90aa9012019-11-11 18:46:36 +05301485enctool: ${ENCTOOL}
1486
Pali Rohára9812202020-11-24 15:38:08 +01001487${ENCTOOL}: FORCE
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001488 $(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1489 $(s)echo
1490 $(s)echo "Built $@ successfully"
1491 $(s)echo
Sumit Garg90aa9012019-11-11 18:46:36 +05301492
Joakim Bech35fab8c2014-01-23 14:51:49 +01001493cscope:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001494 $(s)echo " CSCOPE"
1495 $(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1496 $(q)cscope -b -q -k
Joakim Bech35fab8c2014-01-23 14:51:49 +01001497
Ryan Harkin72ee3312014-01-15 16:55:07 +00001498help:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001499 $(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1500 $(s)echo ""
1501 $(s)echo "PLAT is used to specify which platform you wish to build."
1502 $(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1503 $(s)echo ""
1504 $(s)echo "platform = ${PLATFORM_LIST}"
1505 $(s)echo ""
1506 $(s)echo "Please refer to the User Guide for a list of all supported options."
1507 $(s)echo "Note that the build system doesn't track dependencies for build "
1508 $(s)echo "options. Therefore, if any of the build options are changed "
1509 $(s)echo "from a previous build, a clean build must be performed."
1510 $(s)echo ""
1511 $(s)echo "Supported Targets:"
1512 $(s)echo " all Build all individual bootloader binaries"
1513 $(s)echo " bl1 Build the BL1 binary"
1514 $(s)echo " bl2 Build the BL2 binary"
1515 $(s)echo " bl2u Build the BL2U binary"
1516 $(s)echo " bl31 Build the BL31 binary"
1517 $(s)echo " bl32 Build the BL32 binary. If ARCH=aarch32, then "
1518 $(s)echo " this builds secure payload specified by AARCH32_SP"
1519 $(s)echo " certificates Build the certificates (requires 'GENERATE_COT=1')"
1520 $(s)echo " fip Build the Firmware Image Package (FIP)"
1521 $(s)echo " fwu_fip Build the FWU Firmware Image Package (FIP)"
1522 $(s)echo " checkcodebase Check the coding style of the entire source tree"
1523 $(s)echo " checkpatch Check the coding style on changes in the current"
1524 $(s)echo " branch against BASE_COMMIT (default origin/master)"
1525 $(s)echo " clean Clean the build for the selected platform"
1526 $(s)echo " cscope Generate cscope index"
1527 $(s)echo " distclean Remove all build artifacts for all platforms"
1528 $(s)echo " certtool Build the Certificate generation tool"
1529 $(s)echo " enctool Build the Firmware encryption tool"
1530 $(s)echo " fiptool Build the Firmware Image Package (FIP) creation tool"
1531 $(s)echo " sp Build the Secure Partition Packages"
1532 $(s)echo " sptool Build the Secure Partition Package creation tool"
1533 $(s)echo " dtbs Build the Device Tree Blobs (if required for the platform)"
1534 $(s)echo " memmap Print the memory map of the built binaries"
1535 $(s)echo " doc Build html based documentation using Sphinx tool"
1536 $(s)echo ""
1537 $(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1538 $(s)echo ""
1539 $(s)echo "example: build all targets for the FVP platform:"
1540 $(s)echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
Pali Rohára9812202020-11-24 15:38:08 +01001541
1542.PHONY: FORCE
1543FORCE:;