blob: f916d016dabe04f8f2e741a54e240ed0f676a7c1 [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
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
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100186endif #(AARCH32_INSTRUCTION_SET)
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100187
Sandrine Bailleuxa9c4dde2018-07-03 09:14:45 +0200188TF_CFLAGS_aarch32 += -mno-unaligned-access
dp-armd5461852017-05-02 12:00:08 +0100189TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align
Soby Mathew9d29c222016-05-05 14:33:33 +0100190
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100191##############################################################################
192# WARNINGS Configuration
193###############################################################################
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100194# General warnings
195WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
Yann Gautier34b508b2021-05-20 13:18:14 +0200196 -Wdisabled-optimization -Wvla -Wshadow \
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000197 -Wredundant-decls
198# stricter warnings
199WARNINGS += -Wextra -Wno-trigraphs
200# too verbose for generic build
201WARNINGS += -Wno-missing-field-initializers \
202 -Wno-type-limits -Wno-sign-compare \
203# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
204WARNINGS += -Wno-unused-parameter
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100205
206# Additional warnings
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000207# Level 1 - infrequent warnings we should have none of
208# full -Wextra
209WARNING1 += -Wsign-compare
210WARNING1 += -Wtype-limits
211WARNING1 += -Wmissing-field-initializers
Yann Gautiere7c645b2018-12-10 18:00:26 +0100212
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000213# Level 2 - problematic warnings that we want
214# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
215# TODO: disable just for them and move into default build
216WARNING2 += -Wold-style-definition
217WARNING2 += -Wmissing-prototypes
218WARNING2 += -Wmissing-format-attribute
219# TF-A aims to comply with this eventually. Effort too large at present
220WARNING2 += -Wundef
Boyan Karatotevd141e632022-11-21 14:49:05 +0000221# currently very involved and many platforms set this off
222WARNING2 += -Wunused-const-variable=2
Yann Gautiere7c645b2018-12-10 18:00:26 +0100223
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000224# Level 3 - very pedantic, frequently ignored
Yann Gautiere7c645b2018-12-10 18:00:26 +0100225WARNING3 := -Wbad-function-cast
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000226WARNING3 += -Waggregate-return
227WARNING3 += -Wnested-externs
228WARNING3 += -Wcast-align
Yann Gautiere7c645b2018-12-10 18:00:26 +0100229WARNING3 += -Wcast-qual
230WARNING3 += -Wconversion
231WARNING3 += -Wpacked
Yann Gautiere7c645b2018-12-10 18:00:26 +0100232WARNING3 += -Wpointer-arith
Yann Gautiere7c645b2018-12-10 18:00:26 +0100233WARNING3 += -Wswitch-default
Yann Gautiere7c645b2018-12-10 18:00:26 +0100234
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000235# Setting W is quite verbose and most warnings will be pre-existing issues
236# outside of the contributor's control. Don't fail the build on them so warnings
237# can be seen and hopefully addressed
238ifdef W
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100239 ifneq (${W},0)
240 E ?= 0
241 endif
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000242endif
243
Yann Gautiere7c645b2018-12-10 18:00:26 +0100244ifeq (${W},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100245 WARNINGS += $(WARNING1)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100246else ifeq (${W},2)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100247 WARNINGS += $(WARNING1) $(WARNING2)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100248else ifeq (${W},3)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100249 WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
250endif #(W)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100251
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100252# Compiler specific warnings
Chris Kay8620bd02023-12-04 09:55:50 +0000253ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
Justin Chadwell93c690e2019-07-03 14:15:56 +0100254# not using clang
Justin Chadwelld7b4cd42019-09-18 14:13:42 +0100255WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \
256 -Wpacked-bitfield-compat -Wshift-overflow=2 \
257 -Wlogical-op
Govindraj Rajadea23e22023-05-05 09:09:36 -0500258
259# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
Boyan Karatotev316f5c92024-10-10 13:54:37 +0100260TF_CFLAGS_MIN_PAGE_SIZE := $(call cc_option, --param=min-pagesize=0)
261TF_CFLAGS += $(TF_CFLAGS_MIN_PAGE_SIZE)
Govindraj Rajadea23e22023-05-05 09:09:36 -0500262
Bipin Ravi538516f2023-09-28 13:17:24 -0500263ifeq ($(HARDEN_SLS), 1)
Boyan Karatotev316f5c92024-10-10 13:54:37 +0100264 TF_CFLAGS_MHARDEN_SLS := $(call cc_option, -mharden-sls=all)
265 TF_CFLAGS_aarch64 += $(TF_CFLAGS_MHARDEN_SLS)
Bipin Ravi538516f2023-09-28 13:17:24 -0500266endif
267
Justin Chadwell93c690e2019-07-03 14:15:56 +0100268else
269# using clang
Justin Chadwelld7b4cd42019-09-18 14:13:42 +0100270WARNINGS += -Wshift-overflow -Wshift-sign-overflow \
271 -Wlogical-op-parentheses
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100272endif #(Clang Warning)
Ambroise Vincent00296572019-05-24 12:47:43 +0100273
Yann Gautier6336b072018-12-10 18:08:53 +0100274ifneq (${E},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100275 ERRORS := -Werror
276endif #(E)
Yann Gautier6336b072018-12-10 18:08:53 +0100277
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100278################################################################################
279# Compiler and Linker Directives
280################################################################################
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100281CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \
282 $(ERRORS) $(WARNINGS)
Govindraj Rajad4089fb2023-05-30 16:52:15 -0500283ASFLAGS += $(CPPFLAGS) \
Julius Wernerd5dfdeb2019-07-09 13:49:11 -0700284 -ffreestanding -Wa,--fatal-warnings
Masahiro Yamada59de5092016-12-22 12:51:53 +0900285TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \
Samuel Hollandebd6efa2019-10-20 16:11:25 -0500286 -ffunction-sections -fdata-sections \
Boyan Karatotevee0c5b82024-12-09 08:24:12 +0000287 -ffreestanding -fno-common \
Samuel Hollandebd6efa2019-10-20 16:11:25 -0500288 -Os -std=gnu99
Juan Castillo73c99d42015-08-18 14:23:04 +0100289
Justin Chadwell1f461972019-08-20 11:01:52 +0100290ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100291 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover
292endif #(${SANITIZE_UB},on)
293
Justin Chadwell1f461972019-08-20 11:01:52 +0100294ifeq (${SANITIZE_UB},trap)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100295 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \
Justin Chadwell1f461972019-08-20 11:01:52 +0100296 -fsanitize-undefined-trap-on-error
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100297endif #(${SANITIZE_UB},trap)
Justin Chadwell1f461972019-08-20 11:01:52 +0100298
Chris Kay291e7182024-05-14 13:08:31 +0000299GCC_V_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
david cunadof7ec31d2017-11-30 21:58:01 +0000300
Marco Felsch1f49db52022-11-09 12:59:09 +0100301TF_LDFLAGS += -z noexecstack
302
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100303# LD = armlink
Chris Kay8620bd02023-12-04 09:55:50 +0000304ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100305 TF_LDFLAGS += --diag_error=warning --lto_level=O1
306 TF_LDFLAGS += --remove --info=unused,unusedsymbols
307 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH))
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100308
309# LD = gcc (used when GCC LTO is enabled)
Chris Kay8620bd02023-12-04 09:55:50 +0000310else ifeq ($($(ARCH)-ld-id),gnu-gcc)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100311 # Pass ld options with Wl or Xlinker switches
Chris Kay86e489c2024-01-16 11:53:35 +0000312 TF_LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100313 TF_LDFLAGS += -Wl,--fatal-warnings -O1
314 TF_LDFLAGS += -Wl,--gc-sections
Chris Kayac98b822022-12-22 13:26:37 +0000315
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100316 TF_LDFLAGS += -Wl,-z,common-page-size=4096 #Configure page size constants
317 TF_LDFLAGS += -Wl,-z,max-page-size=4096
Andrey Skvortsov304ad942023-09-05 23:06:29 +0300318 TF_LDFLAGS += -Wl,--build-id=none
Chris Kayac98b822022-12-22 13:26:37 +0000319
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100320 ifeq ($(ENABLE_LTO),1)
321 ifeq (${ARCH},aarch64)
322 TF_LDFLAGS += -flto -fuse-linker-plugin
Andrey Skvortsov31f80ef2023-12-08 18:04:51 +0300323 TF_LDFLAGS += -flto-partition=one
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100324 endif
325 endif #(ENABLE_LTO)
326
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600327# GCC automatically adds fix-cortex-a53-843419 flag when used to link
328# which breaks some builds, so disable if errata fix is not explicitly enabled
Yann Gautiercfe67672023-03-15 16:18:16 +0100329 ifeq (${ARCH},aarch64)
330 ifneq (${ERRATA_A53_843419},1)
331 TF_LDFLAGS += -mno-fix-cortex-a53-843419
332 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100333 endif
334 TF_LDFLAGS += -nostdlib
335 TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100336
337# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800338else
Marco Felsch1f49db52022-11-09 12:59:09 +0100339# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
340# are not loaded by a elf loader.
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100341 TF_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
342 TF_LDFLAGS += -O1
343 TF_LDFLAGS += --gc-sections
Chris Kayac98b822022-12-22 13:26:37 +0000344
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100345 TF_LDFLAGS += -z common-page-size=4096 # Configure page size constants
346 TF_LDFLAGS += -z max-page-size=4096
Andrey Skvortsov304ad942023-09-05 23:06:29 +0300347 TF_LDFLAGS += --build-id=none
Chris Kayac98b822022-12-22 13:26:37 +0000348
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100349# ld.lld doesn't recognize the errata flags,
Yabin Cuiebac6922023-01-19 20:06:04 +0000350# therefore don't add those in that case.
351# ld.lld reports section type mismatch warnings,
352# therefore don't add --fatal-warnings to it.
Chris Kay8620bd02023-12-04 09:55:50 +0000353 ifneq ($($(ARCH)-ld-id),llvm-lld)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100354 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) --fatal-warnings
355 endif
356
357endif #(LD = armlink)
Juan Castillo73c99d42015-08-18 14:23:04 +0100358
359################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500360# Setup ARCH_MAJOR/MINOR before parsing arch_features.
361################################################################################
362ifeq (${ENABLE_RME},1)
AlexeiFedorov7d5fc982024-03-13 11:53:44 +0000363 ARM_ARCH_MAJOR := 9
364 ARM_ARCH_MINOR := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500365endif
366
367################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100368# Common sources and include directories
369################################################################################
dp-armd801fbb2017-05-04 12:15:35 +0100370include lib/compiler-rt/compiler-rt.mk
Juan Castillo73c99d42015-08-18 14:23:04 +0100371
Chris Kay758ccb82024-03-08 16:08:31 +0000372# Allow overriding the timestamp, for example for reproducible builds, or to
373# synchronize timestamps across multiple projects.
374# This must be set to a C string (including quotes where applicable).
375BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
376
377DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
378DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
379DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
380
Juan Castillo73c99d42015-08-18 14:23:04 +0100381BL_COMMON_SOURCES += common/bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100382 common/tf_log.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100383 common/${ARCH}/debug.S \
Julius Werner91b48c92018-11-27 22:10:56 -0800384 drivers/console/multi_console.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100385 lib/${ARCH}/cache_helpers.S \
386 lib/${ARCH}/misc_helpers.S \
Boyan Karatotevc73686a2023-02-15 13:21:50 +0000387 lib/extensions/pmuv3/${ARCH}/pmuv3.c \
Soby Mathew566034f2018-02-08 17:45:12 +0000388 plat/common/plat_bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100389 plat/common/plat_log_common.c \
dp-arm75311202017-03-07 11:02:47 +0000390 plat/common/${ARCH}/plat_common.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100391 plat/common/${ARCH}/platform_helpers.S \
Roberto Vargas61f72a32018-05-08 10:27:10 +0100392 ${COMPILER_RT_SRCS}
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000393
Chris Kay8620bd02023-12-04 09:55:50 +0000394ifeq ($($(ARCH)-cc-id),arm-clang)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100395 BL_COMMON_SOURCES += lib/${ARCH}/armclang_printf.S
Antonio Nino Diaz8422a842018-08-16 15:42:44 +0100396endif
397
Justin Chadwell1f461972019-08-20 11:01:52 +0100398ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100399 BL_COMMON_SOURCES += plat/common/ubsan.c
Justin Chadwell1f461972019-08-20 11:01:52 +0100400endif
401
Yann Gautier01d237c2018-06-18 16:00:23 +0200402INCLUDES += -Iinclude \
Antonio Nino Diazf5478de2018-12-17 17:20:57 +0000403 -Iinclude/arch/${ARCH} \
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +0000404 -Iinclude/lib/cpus/${ARCH} \
405 -Iinclude/lib/el3_runtime/${ARCH} \
406 ${PLAT_INCLUDES} \
407 ${SPD_INCLUDES}
408
Nishant Sharmae03dcc82022-08-15 16:37:07 +0100409DTC_FLAGS += -I dts -O dtb
410DTC_CPPFLAGS += -P -nostdinc $(INCLUDES) -Ifdts -undef \
411 -x assembler-with-cpp $(DEFINES)
412
Antonio Nino Diaz9c6d1c52018-11-19 11:48:30 +0000413include common/backtrace/backtrace.mk
414
Juan Castillo73c99d42015-08-18 14:23:04 +0100415################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500416# Generic definitions
417################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500418
419ifeq (${BUILD_BASE},)
420 BUILD_BASE := ./build
421endif
422BUILD_PLAT := $(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
423
424SPDS := $(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
425
426# Platforms providing their own TBB makefile may override this value
427INCLUDE_TBBR_MK := 1
428
429################################################################################
430# Include SPD Makefile if one has been specified
431################################################################################
432
433ifneq (${SPD},none)
Govindraj Raja35472702023-09-20 14:32:24 -0500434 ifeq (${SPD},spmd)
435 # SPMD is located in std_svc directory
436 SPD_DIR := std_svc
437
438 ifeq ($(SPMD_SPM_AT_SEL2),1)
439 CTX_INCLUDE_EL2_REGS := 1
Govindraj Raja35472702023-09-20 14:32:24 -0500440 endif
441
442 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
443 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG
444 endif
445
Arunachalam Ganapathy0686a012022-04-11 14:36:54 +0100446 ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
447 DTC_CPPFLAGS += -DTRUSTY_SP_FW_CONFIG
448 endif
449
Govindraj Raja35472702023-09-20 14:32:24 -0500450 ifeq ($(TS_SP_FW_CONFIG),1)
Arunachalam Ganapathy0686a012022-04-11 14:36:54 +0100451 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG
Govindraj Raja35472702023-09-20 14:32:24 -0500452 endif
453
454 ifneq ($(ARM_BL2_SP_LIST_DTS),)
455 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
456 endif
457
458 ifneq ($(SP_LAYOUT_FILE),)
459 BL2_ENABLE_SP_LOAD := 1
460 endif
461 else
462 # All other SPDs in spd directory
463 SPD_DIR := spd
464 endif #(SPD)
465
466 # We expect to locate an spd.mk under the specified SPD directory
467 SPD_MAKE := $(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
468
469 ifeq (${SPD_MAKE},)
470 $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
471 endif
472 $(info Including ${SPD_MAKE})
473 include ${SPD_MAKE}
474
475 # If there's BL32 companion for the chosen SPD, we expect that the SPD's
476 # Makefile would set NEED_BL32 to "yes". In this case, the build system
477 # supports two mutually exclusive options:
478 # * BL32 is built from source: then BL32_SOURCES must contain the list
479 # of source files to build BL32
480 # * BL32 is a prebuilt binary: then BL32 must point to the image file
481 # that will be included in the FIP
482 # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
483 # over the sources.
484endif #(SPD=none)
485
Govindraj Raja35472702023-09-20 14:32:24 -0500486################################################################################
Olivier Deprez696ed162025-01-03 13:38:50 +0100487# Include the platform specific Makefile after the SPD Makefile (the platform
488# makefile may use all previous definitions in this file)
489################################################################################
490include ${PLAT_MAKEFILE_FULL}
491
492################################################################################
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100493# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
494# platform.
495################################################################################
496
497include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
498################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500499# Process BRANCH_PROTECTION value and set
500# Pointer Authentication and Branch Target Identification flags
501################################################################################
502ifeq (${BRANCH_PROTECTION},0)
503 # Default value turns off all types of branch protection
504 BP_OPTION := none
505else ifneq (${ARCH},aarch64)
506 $(error BRANCH_PROTECTION requires AArch64)
507else ifeq (${BRANCH_PROTECTION},1)
508 # Enables all types of branch protection features
509 BP_OPTION := standard
510 ENABLE_BTI := 1
511 ENABLE_PAUTH := 1
512else ifeq (${BRANCH_PROTECTION},2)
513 # Return address signing to its standard level
514 BP_OPTION := pac-ret
515 ENABLE_PAUTH := 1
516else ifeq (${BRANCH_PROTECTION},3)
517 # Extend the signing to include leaf functions
518 BP_OPTION := pac-ret+leaf
519 ENABLE_PAUTH := 1
520else ifeq (${BRANCH_PROTECTION},4)
521 # Turn on branch target identification mechanism
522 BP_OPTION := bti
523 ENABLE_BTI := 1
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100524else ifeq (${BRANCH_PROTECTION},5)
525 # Turn on branch target identification mechanism
526 BP_OPTION := standard
527 ENABLE_BTI := 2
528 ENABLE_PAUTH := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500529else
530 $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
531endif #(BRANCH_PROTECTION)
532
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100533ifneq ($(ENABLE_PAUTH),0)
534 CTX_INCLUDE_PAUTH_REGS := ${ENABLE_PAUTH}
Govindraj Rajaf5211422023-08-17 10:41:48 -0500535endif
536ifneq (${BP_OPTION},none)
537 TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION}
538endif #(BP_OPTION)
539
540# Pointer Authentication sources
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100541ifneq (${ENABLE_PAUTH},0)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500542# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
543# Pauth support. As it's not secure, it must be reimplemented for real platforms
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100544 BL_COMMON_SOURCES += lib/extensions/pauth/pauth.c
Govindraj Rajaf5211422023-08-17 10:41:48 -0500545endif
Boyan Karatotevb14987c2025-04-09 14:41:58 +0100546#
547ifneq (${ENABLE_FEAT_PAUTH_LR},0)
548# Currently, FEAT_PAUTH_LR is only supported by arm/clang compilers
549# TODO implement for GCC when support is added
550ifeq ($($(ARCH)-cc-id),arm-clang)
551 arch-features := $(arch-features)+pauth-lr
552else
553 $(error Error: ENABLE_FEAT_PAUTH_LR not supported for GCC compiler)
554endif
555endif
Govindraj Rajaf5211422023-08-17 10:41:48 -0500556
Govindraj Rajaf5211422023-08-17 10:41:48 -0500557################################################################################
558# RME dependent flags configuration, Enable optional features for RME.
559################################################################################
560# FEAT_RME
561ifeq (${ENABLE_RME},1)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500562 # RME requires el2 context to be saved for now.
563 CTX_INCLUDE_EL2_REGS := 1
564 CTX_INCLUDE_AARCH32_REGS := 0
565 CTX_INCLUDE_PAUTH_REGS := 1
566
Javier Almansa Sobrinod048af02025-03-21 18:32:10 +0000567 ifneq ($(ENABLE_FEAT_MPAM), 0)
568 CTX_INCLUDE_MPAM_REGS := 1
569 endif
570
Govindraj Rajaf5211422023-08-17 10:41:48 -0500571 # RME enables CSV2_2 extension by default.
572 ENABLE_FEAT_CSV2_2 = 1
573endif #(FEAT_RME)
574
575################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500576# Include rmmd Makefile if RME is enabled
577################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500578ifneq (${ENABLE_RME},0)
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500579include services/std_svc/rmmd/rmmd.mk
580$(warning "RME is an experimental feature")
581endif
582
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000583################################################################################
Govindraj Raja30655132024-09-06 15:43:43 +0100584# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
585################################################################################
586ifneq (${ENABLE_FEAT_D128}, 0)
587 BL_COMMON_SOURCES += lib/extensions/sysreg128/sysreg128.S
588endif
589
590################################################################################
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500591# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
592# up with appropriate march values for compiler.
593################################################################################
594include ${MAKE_HELPERS_DIRECTORY}march.mk
595
John Powell025b1b82025-03-10 20:09:03 -0500596TF_CFLAGS += $(march-directive)
Govindraj Raja7275ac22024-01-23 16:00:19 -0600597ASFLAGS += $(march-directive)
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500598
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600599# This internal flag is common option which is set to 1 for scenarios
600# when the BL2 is running in EL3 level. This occurs in two scenarios -
601# 4 world system running BL2 at EL3 and two world system without BL1 running
602# BL2 in EL3
603
604ifeq (${RESET_TO_BL2},1)
605 BL2_RUNS_AT_EL3 := 1
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100606 ifeq (${ENABLE_RME},1)
607 $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
608 supported at the moment.)
609 endif
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600610else ifeq (${ENABLE_RME},1)
611 BL2_RUNS_AT_EL3 := 1
612else
613 BL2_RUNS_AT_EL3 := 0
614endif
615
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100616# This internal flag is set to 1 when Firmware First handling of External aborts
617# is required by lowe ELs. Currently only NS requires this support.
618ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
619 FFH_SUPPORT := 1
620else
621 FFH_SUPPORT := 0
622endif
623
Etienne Carriere26e63c42017-11-08 13:48:40 +0100624ifeq (${ARM_ARCH_MAJOR},7)
625include make_helpers/armv7-a-cpus.mk
626endif
627
Masahiro Yamada320920c2020-01-17 13:44:37 +0900628PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
629ifneq ($(PIE_FOUND),)
630 TF_CFLAGS += -fno-PIE
Chris Kay8620bd02023-12-04 09:55:50 +0000631ifeq ($($(ARCH)-ld-id),gnu-gcc)
Samuel Holland7b592412022-04-08 21:56:02 -0500632 TF_LDFLAGS += -no-pie
633endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100634endif #(PIE_FOUND)
Masahiro Yamada320920c2020-01-17 13:44:37 +0900635
Chris Kay8620bd02023-12-04 09:55:50 +0000636ifeq ($($(ARCH)-ld-id),gnu-gcc)
Masahiro Yamada320920c2020-01-17 13:44:37 +0900637 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
Soby Mathew3bd17c02018-08-28 11:13:55 +0100638else
Masahiro Yamada320920c2020-01-17 13:44:37 +0900639 PIE_LDFLAGS += -pie --no-dynamic-linker
640endif
641
642ifeq ($(ENABLE_PIE),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100643 ifeq ($(RESET_TO_BL2),1)
644 ifneq ($(BL2_IN_XIP_MEM),1)
645 BL2_CPPFLAGS += -fpie
646 BL2_CFLAGS += -fpie
647 BL2_LDFLAGS += $(PIE_LDFLAGS)
648 endif #(BL2_IN_XIP_MEM)
649 endif #(RESET_TO_BL2)
Chris Kay966660e2023-02-02 14:39:03 +0000650 BL31_CPPFLAGS += -fpie
651 BL31_CFLAGS += -fpie
Masahiro Yamada320920c2020-01-17 13:44:37 +0900652 BL31_LDFLAGS += $(PIE_LDFLAGS)
Chris Kay966660e2023-02-02 14:39:03 +0000653
654 BL32_CPPFLAGS += -fpie
Masahiro Yamadad9743012020-01-17 13:45:14 +0900655 BL32_CFLAGS += -fpie
656 BL32_LDFLAGS += $(PIE_LDFLAGS)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100657endif #(ENABLE_PIE)
Soby Mathew3bd17c02018-08-28 11:13:55 +0100658
Boyan Karatotev007433d2023-01-25 16:55:18 +0000659BL1_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
660BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
661BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
662
Masahiro Yamada9cefb4b2020-04-01 14:20:58 +0900663BL1_CPPFLAGS += -DIMAGE_AT_EL3
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600664ifeq ($(RESET_TO_BL2),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100665 BL2_CPPFLAGS += -DIMAGE_AT_EL3
Masahiro Yamadad5e97a12020-03-26 13:18:48 +0900666else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100667 BL2_CPPFLAGS += -DIMAGE_AT_EL1
668endif #(RESET_TO_BL2)
Boyan Karatotev007433d2023-01-25 16:55:18 +0000669
670ifeq (${ARCH},aarch64)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100671 BL2U_CPPFLAGS += -DIMAGE_AT_EL1
672 BL31_CPPFLAGS += -DIMAGE_AT_EL3
673 BL32_CPPFLAGS += -DIMAGE_AT_EL1
Boyan Karatotev007433d2023-01-25 16:55:18 +0000674else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100675 BL32_CPPFLAGS += -DIMAGE_AT_EL3
Masahiro Yamadad5e97a12020-03-26 13:18:48 +0900676endif
677
Sandrine Bailleux54035fc2016-01-13 14:57:38 +0000678# Include the CPU specific operations makefile, which provides default
679# values for all CPU errata workarounds and CPU specific optimisations.
680# This can be overridden by the platform.
Juan Castillo73c99d42015-08-18 14:23:04 +0100681include lib/cpus/cpu-ops.mk
Achin Gupta4f6ad662013-10-25 09:08:21 +0100682
dp-arma4409002017-02-15 11:07:55 +0000683################################################################################
684# Build `AARCH32_SP` as BL32 image for AArch32
685################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100686ifeq (${ARCH},aarch32)
687 NEED_BL32 := yes
dp-arma4409002017-02-15 11:07:55 +0000688
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100689 ifneq (${AARCH32_SP},none)
690 # We expect to locate an sp.mk under the specified AARCH32_SP directory
691 AARCH32_SP_MAKE := $(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
dp-arma4409002017-02-15 11:07:55 +0000692
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100693 ifeq (${AARCH32_SP_MAKE},)
694 $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
695 endif
Juan Pablo Conde043f38f2023-08-09 13:19:21 -0500696 $(info Including ${AARCH32_SP_MAKE})
697 include ${AARCH32_SP_MAKE}
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100698 endif
699endif #(ARCH=aarch32)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100700
Juan Castillo73c99d42015-08-18 14:23:04 +0100701################################################################################
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800702# Include libc if not overridden
703################################################################################
704ifeq (${OVERRIDE_LIBC},0)
705include lib/libc/libc.mk
706endif
707
Boyan Karatotev5d893412025-01-07 11:00:03 +0000708ifneq (${USE_GIC_DRIVER},0)
709include drivers/arm/gic/gic.mk
710endif
711
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800712################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100713# Check incompatible options and dependencies
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000714################################################################################
Boyan Karatotevb14987c2025-04-09 14:41:58 +0100715include ${MAKE_HELPERS_DIRECTORY}constraints.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100716
717# The cert_create tool cannot generate certificates individually, so we use the
718# target 'certificates' to create them all
719ifneq (${GENERATE_COT},0)
720 FIP_DEPS += certificates
721 FWU_FIP_DEPS += fwu_certificates
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000722endif
723
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100724ifneq (${DECRYPTION_SUPPORT},none)
725 ENC_ARGS += -f ${FW_ENC_STATUS}
726 ENC_ARGS += -k ${ENC_KEY}
727 ENC_ARGS += -n ${ENC_NONCE}
728 FIP_DEPS += enctool
729 FWU_FIP_DEPS += enctool
730endif #(DECRYPTION_SUPPORT)
731
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100732ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
733# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100734 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100735else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
736# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100737 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100738else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
739# Support hash calculation only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100740 CRYPTO_SUPPORT := 2
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100741else ifeq (${TRUSTED_BOARD_BOOT},1)
742# Support authentication verification only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100743 CRYPTO_SUPPORT := 1
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000744else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100745 CRYPTO_SUPPORT := 0
746endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000747
Manish V Badarkhee4a070e2024-12-03 21:46:51 +0000748ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
749CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
750endif
751
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000752################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100753# Process platform overrideable behaviour
754################################################################################
Achin Gupta4f6ad662013-10-25 09:08:21 +0100755
Manish Pandey5f24ce92021-10-06 10:59:52 +0100756ifdef BL1_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100757 NEED_BL1 := yes
758endif #(BL1_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100759
Juan Castillo73c99d42015-08-18 14:23:04 +0100760ifdef BL2_SOURCES
Manish Pandey5f24ce92021-10-06 10:59:52 +0100761 NEED_BL2 := yes
762
763 # Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
764 # Certificate generation tools. This flag can be overridden by the platform.
765 ifdef EL3_PAYLOAD_BASE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100766 # If booting an EL3 payload there is no need for a BL33 image
767 # in the FIP file.
768 NEED_BL33 := no
769 else
770 ifdef PRELOADED_BL33_BASE
771 # If booting a BL33 preloaded image there is no need of
772 # another one in the FIP file.
773 NEED_BL33 := no
774 else
775 NEED_BL33 ?= yes
776 endif
777 endif
778endif #(BL2_SOURCES)
Juan Castillo73c99d42015-08-18 14:23:04 +0100779
Manish Pandey5f24ce92021-10-06 10:59:52 +0100780ifdef BL2U_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100781 NEED_BL2U := yes
782endif #(BL2U_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100783
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900784# If SCP_BL2 is given, we always want FIP to include it.
785ifdef SCP_BL2
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100786 NEED_SCP_BL2 := yes
787endif #(SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900788
Soby Mathew5744e872017-11-14 14:10:10 +0000789# For AArch32, BL31 is not currently supported.
790ifneq (${ARCH},aarch32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100791 ifdef BL31_SOURCES
792 # When booting an EL3 payload, there is no need to compile the BL31
793 # image nor put it in the FIP.
794 ifndef EL3_PAYLOAD_BASE
795 NEED_BL31 := yes
796 endif
797 endif
798endif #(ARCH=aarch64)
Soby Mathew5744e872017-11-14 14:10:10 +0000799
Juan Castillo73c99d42015-08-18 14:23:04 +0100800# Process TBB related flags
801ifneq (${GENERATE_COT},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100802 # Common cert_create options
803 ifneq (${CREATE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +0100804 $(eval CRT_ARGS += -n)
Yatharth Kochar01912622015-10-12 12:33:47 +0100805 $(eval FWU_CRT_ARGS += -n)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100806 ifneq (${SAVE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +0100807 $(eval CRT_ARGS += -k)
Yatharth Kochar01912622015-10-12 12:33:47 +0100808 $(eval FWU_CRT_ARGS += -k)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100809 endif
810 endif
811 # Include TBBR makefile (unless the platform indicates otherwise)
812 ifeq (${INCLUDE_TBBR_MK},1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100813 include make_helpers/tbbr/tbbr_tools.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100814 endif
815endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +0100816
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +0900817ifneq (${FIP_ALIGN},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100818 FIP_ARGS += --align ${FIP_ALIGN}
819endif #(FIP_ALIGN)
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +0900820
Manish Pandey5f24ce92021-10-06 10:59:52 +0100821ifdef FDT_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100822 NEED_FDT := yes
823endif #(FDT_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100824
Juan Castillo73c99d42015-08-18 14:23:04 +0100825################################################################################
Michalis Pappas46e5e032018-03-20 13:01:27 +0800826# Include libraries' Makefile that are used in all BL
827################################################################################
828
829include lib/stack_protector/stack_protector.mk
830
831################################################################################
Soby Mathew8a860522017-02-14 10:05:07 +0000832# Include BL specific makefiles
833################################################################################
Manish Pandey5f24ce92021-10-06 10:59:52 +0100834
835ifeq (${NEED_BL1},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000836include bl1/bl1.mk
837endif
838
Manish Pandey5f24ce92021-10-06 10:59:52 +0100839ifeq (${NEED_BL2},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000840include bl2/bl2.mk
841endif
842
Manish Pandey5f24ce92021-10-06 10:59:52 +0100843ifeq (${NEED_BL2U},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000844include bl2u/bl2u.mk
845endif
846
Soby Mathew5744e872017-11-14 14:10:10 +0000847ifeq (${NEED_BL31},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000848include bl31/bl31.mk
849endif
Nishanth Menon03b397a2016-10-14 01:13:57 +0000850
Juan Castillo73c99d42015-08-18 14:23:04 +0100851################################################################################
852# Build options checks
853################################################################################
Juan Castillob7124ea2014-11-04 17:36:40 +0000854
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100855# Boolean_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500856$(eval $(call assert_booleans,\
857 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100858 ALLOW_RO_XLAT_TABLES \
859 BL2_ENABLE_SP_LOAD \
860 COLD_BOOT_SINGLE_CPU \
861 CREATE_KEYS \
862 CTX_INCLUDE_AARCH32_REGS \
863 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -0500864 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100865 CTX_INCLUDE_EL2_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -0500866 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100867 DEBUG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100868 DYN_DISABLE_AUTH \
869 EL3_EXCEPTION_HANDLING \
870 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100871 AMU_RESTRICT_COUNTERS \
872 ENABLE_ASSERTIONS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100873 ENABLE_PIE \
874 ENABLE_PMF \
875 ENABLE_PSCI_STAT \
876 ENABLE_RUNTIME_INSTRUMENTATION \
877 ENABLE_SME_FOR_SWD \
878 ENABLE_SVE_FOR_SWD \
Boyan Karatotev8cef63d2025-01-07 11:26:56 +0000879 ENABLE_FEAT_GCIE \
Manish Pandey970a4a82023-10-10 13:53:25 +0100880 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100881 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100882 ERROR_DEPRECATED \
883 FAULT_INJECTION_SUPPORT \
884 GENERATE_COT \
885 GICV2_G0_FOR_EL3 \
886 HANDLE_EA_EL3_FIRST_NS \
Bipin Ravi538516f2023-09-28 13:17:24 -0500887 HARDEN_SLS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100888 HW_ASSISTED_COHERENCY \
889 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -0500890 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +0200891 DICE_PROTECTION_ENVIRONMENT \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -0700892 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -0500893 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100894 DRTM_SUPPORT \
895 NS_TIMER_SWITCH \
896 OVERRIDE_LIBC \
897 PL011_GENERIC_UART \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100898 PROGRAMMABLE_RESET_ADDRESS \
899 PSCI_EXTENDED_STATE_ID \
900 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +0100901 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100902 RESET_TO_BL31 \
903 SAVE_KEYS \
904 SEPARATE_CODE_AND_RODATA \
905 SEPARATE_BL2_NOLOAD_REGION \
906 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +0800907 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -0500908 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100909 SPIN_ON_BL1_EXIT \
910 SPM_MM \
911 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +0100912 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100913 SPMD_SPM_AT_SEL2 \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -0800914 ENABLE_SPMD_LP \
Raymond Mao3ba2c152023-07-25 07:53:35 -0700915 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100916 TRUSTED_BOARD_BOOT \
917 USE_COHERENT_MEM \
918 USE_DEBUGFS \
919 ARM_IO_IN_DTB \
920 SDEI_IN_FCONF \
921 SEC_INT_DESC_IN_FCONF \
922 USE_ROMLIB \
923 USE_TBBR_DEFS \
924 WARMBOOT_ENABLE_DCACHE_EARLY \
925 RESET_TO_BL2 \
926 BL2_IN_XIP_MEM \
927 BL2_INV_DCACHE \
928 USE_SPINLOCK_CAS \
929 ENCRYPT_BL31 \
930 ENCRYPT_BL32 \
931 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +0100932 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100933 RAS_TRAP_NS_ERR_REC_ACCESS \
934 COT_DESC_IN_DTB \
935 USE_SP804_TIMER \
936 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +0530937 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100938 ENABLE_MPMM \
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +0000939 FEAT_PABANDON \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100940 FEATURE_DETECTION \
Jayanth Dodderi Chidanand0b22e592022-10-11 17:16:07 +0100941 TRNG_SUPPORT \
Boyan Karatotev593ae352023-03-22 15:55:36 +0000942 ENABLE_ERRATA_ALL \
Sona Mathewffea3842022-11-18 18:05:38 -0600943 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -0500944 ERRATA_NON_ARM_INTERCONNECT \
Okash Khawaja04c73032022-11-04 12:38:01 +0000945 CONDITIONAL_CMO \
Manish V Badarkhe5782b892023-09-06 09:08:28 +0100946 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +0200947 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -0500948 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -0600949 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +0100950 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -0600951 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +0100952 HOB_LIST \
Manish V Badarkhecf48f492025-04-15 20:16:32 +0100953 LFA_SUPPORT \
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500954)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100955
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100956# Numeric_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500957$(eval $(call assert_numerics,\
958 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100959 ARM_ARCH_MAJOR \
960 ARM_ARCH_MINOR \
961 BRANCH_PROTECTION \
962 CTX_INCLUDE_PAUTH_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100963 CTX_INCLUDE_NEVE_REGS \
964 CRYPTO_SUPPORT \
Boyan Karatotev83a4dae2023-02-16 09:45:29 +0000965 DISABLE_MTPMU \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100966 ENABLE_BRBE_FOR_NS \
967 ENABLE_TRBE_FOR_NS \
968 ENABLE_BTI \
969 ENABLE_PAUTH \
John Powell025b1b82025-03-10 20:09:03 -0500970 ENABLE_FEAT_PAUTH_LR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100971 ENABLE_FEAT_AMU \
972 ENABLE_FEAT_AMUv1p1 \
973 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -0500974 ENABLE_FEAT_CSV2_3 \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -0500975 ENABLE_FEAT_DEBUGV8P9 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100976 ENABLE_FEAT_DIT \
977 ENABLE_FEAT_ECV \
978 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -0500979 ENABLE_FEAT_FGT2 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600980 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100981 ENABLE_FEAT_HCX \
Andre Przywara19d52a82024-08-09 17:04:22 +0100982 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000983 ENABLE_FEAT_MEC \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -0600984 ENABLE_FEAT_MOPS \
Govindraj Raja8e397882024-01-26 10:08:37 -0600985 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100986 ENABLE_FEAT_PAN \
987 ENABLE_FEAT_RNG \
988 ENABLE_FEAT_RNG_TRAP \
989 ENABLE_FEAT_SEL2 \
990 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +0100991 ENABLE_FEAT_THE \
Govindraj Raja0e4daed2024-01-23 16:03:53 -0600992 ENABLE_FEAT_SB \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100993 ENABLE_FEAT_S2PIE \
994 ENABLE_FEAT_S1PIE \
995 ENABLE_FEAT_S2POE \
996 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +0100997 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +0100998 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100999 ENABLE_FEAT_GCS \
1000 ENABLE_FEAT_VHE \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -05001001 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001002 ENABLE_RME \
1003 ENABLE_SPE_FOR_NS \
1004 ENABLE_SYS_REG_TRACE_FOR_NS \
1005 ENABLE_SME_FOR_NS \
1006 ENABLE_SME2_FOR_NS \
1007 ENABLE_SVE_FOR_NS \
1008 ENABLE_TRF_FOR_NS \
1009 FW_ENC_STATUS \
1010 NR_OF_FW_BANKS \
1011 NR_OF_IMAGES_IN_FW_BANK \
1012 TWED_DELAY \
1013 ENABLE_FEAT_TWED \
1014 SVE_VECTOR_LEN \
Varun Wadekar0ed3be62023-04-13 21:06:18 +01001015 IMPDEF_SYSREG_TRAP \
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 \
1047 DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1048 DISABLE_MTPMU \
1049 ENABLE_FEAT_AMU \
1050 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001051 AMU_RESTRICT_COUNTERS \
1052 ENABLE_ASSERTIONS \
1053 ENABLE_BTI \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -05001054 ENABLE_FEAT_DEBUGV8P9 \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -05001055 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001056 ENABLE_PAUTH \
John Powell025b1b82025-03-10 20:09:03 -05001057 ENABLE_FEAT_PAUTH_LR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001058 ENABLE_PIE \
1059 ENABLE_PMF \
1060 ENABLE_PSCI_STAT \
1061 ENABLE_RME \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -07001062 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -05001063 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001064 ENABLE_RUNTIME_INSTRUMENTATION \
1065 ENABLE_SME_FOR_NS \
1066 ENABLE_SME2_FOR_NS \
1067 ENABLE_SME_FOR_SWD \
1068 ENABLE_SPE_FOR_NS \
1069 ENABLE_SVE_FOR_NS \
1070 ENABLE_SVE_FOR_SWD \
Manish Pandey970a4a82023-10-10 13:53:25 +01001071 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +01001072 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001073 ENCRYPT_BL31 \
1074 ENCRYPT_BL32 \
1075 ERROR_DEPRECATED \
1076 FAULT_INJECTION_SUPPORT \
1077 GICV2_G0_FOR_EL3 \
1078 HANDLE_EA_EL3_FIRST_NS \
1079 HW_ASSISTED_COHERENCY \
1080 LOG_LEVEL \
1081 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -05001082 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +02001083 DICE_PROTECTION_ENVIRONMENT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001084 DRTM_SUPPORT \
1085 NS_TIMER_SWITCH \
1086 PL011_GENERIC_UART \
1087 PLAT_${PLAT} \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001088 PROGRAMMABLE_RESET_ADDRESS \
1089 PSCI_EXTENDED_STATE_ID \
1090 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +01001091 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001092 RESET_TO_BL31 \
AlexeiFedorovd7660842024-05-13 15:35:54 +01001093 RME_GPT_BITLOCK_BLOCK \
AlexeiFedorovec0088b2024-03-13 17:07:03 +00001094 RME_GPT_MAX_BLOCK \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001095 SEPARATE_CODE_AND_RODATA \
1096 SEPARATE_BL2_NOLOAD_REGION \
1097 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +08001098 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -05001099 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001100 RECLAIM_INIT_CODE \
1101 SPD_${SPD} \
1102 SPIN_ON_BL1_EXIT \
1103 SPM_MM \
1104 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +01001105 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001106 SPMD_SPM_AT_SEL2 \
Raymond Mao3ba2c152023-07-25 07:53:35 -07001107 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001108 TRUSTED_BOARD_BOOT \
1109 CRYPTO_SUPPORT \
1110 TRNG_SUPPORT \
1111 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -05001112 ERRATA_NON_ARM_INTERCONNECT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001113 USE_COHERENT_MEM \
1114 USE_DEBUGFS \
1115 ARM_IO_IN_DTB \
1116 SDEI_IN_FCONF \
1117 SEC_INT_DESC_IN_FCONF \
1118 USE_ROMLIB \
1119 USE_TBBR_DEFS \
1120 WARMBOOT_ENABLE_DCACHE_EARLY \
1121 RESET_TO_BL2 \
1122 BL2_RUNS_AT_EL3 \
1123 BL2_IN_XIP_MEM \
1124 BL2_INV_DCACHE \
1125 USE_SPINLOCK_CAS \
1126 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +01001127 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001128 RAS_TRAP_NS_ERR_REC_ACCESS \
1129 COT_DESC_IN_DTB \
1130 USE_SP804_TIMER \
1131 ENABLE_FEAT_RNG \
1132 ENABLE_FEAT_RNG_TRAP \
1133 ENABLE_FEAT_SB \
1134 ENABLE_FEAT_DIT \
1135 NR_OF_FW_BANKS \
1136 NR_OF_IMAGES_IN_FW_BANK \
1137 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +05301138 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001139 ENABLE_BRBE_FOR_NS \
1140 ENABLE_TRBE_FOR_NS \
1141 ENABLE_SYS_REG_TRACE_FOR_NS \
1142 ENABLE_TRF_FOR_NS \
1143 ENABLE_FEAT_HCX \
1144 ENABLE_MPMM \
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +00001145 FEAT_PABANDON \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001146 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -05001147 ENABLE_FEAT_FGT2 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -06001148 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001149 ENABLE_FEAT_ECV \
1150 ENABLE_FEAT_AMUv1p1 \
1151 ENABLE_FEAT_SEL2 \
1152 ENABLE_FEAT_VHE \
1153 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -05001154 ENABLE_FEAT_CSV2_3 \
Andre Przywara19d52a82024-08-09 17:04:22 +01001155 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +00001156 ENABLE_FEAT_MEC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001157 ENABLE_FEAT_PAN \
1158 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +01001159 ENABLE_FEAT_THE \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001160 ENABLE_FEAT_S2PIE \
1161 ENABLE_FEAT_S1PIE \
1162 ENABLE_FEAT_S2POE \
1163 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +01001164 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +01001165 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001166 ENABLE_FEAT_GCS \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -06001167 ENABLE_FEAT_MOPS \
Boyan Karatotev8cef63d2025-01-07 11:26:56 +00001168 ENABLE_FEAT_GCIE \
Govindraj Raja8e397882024-01-26 10:08:37 -06001169 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001170 FEATURE_DETECTION \
1171 TWED_DELAY \
1172 ENABLE_FEAT_TWED \
Okash Khawaja04c73032022-11-04 12:38:01 +00001173 CONDITIONAL_CMO \
Varun Wadekar0ed3be62023-04-13 21:06:18 +01001174 IMPDEF_SYSREG_TRAP \
Jayanth Dodderi Chidananda8cf6fa2023-04-26 15:57:30 +01001175 SVE_VECTOR_LEN \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -08001176 ENABLE_SPMD_LP \
Manish V Badarkhe5782b892023-09-06 09:08:28 +01001177 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +02001178 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -05001179 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001180 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +01001181 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -06001182 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +01001183 HOB_LIST \
Manish V Badarkhecf48f492025-04-15 20:16:32 +01001184 LFA_SUPPORT \
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001185)))
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +01001186
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001187ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1188ifeq (${DEBUG}, 0)
1189 $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1190 override PLATFORM_REPORT_CTX_MEM_USE := 0
1191endif
1192endif
1193
Justin Chadwell1f461972019-08-20 11:01:52 +01001194ifeq (${SANITIZE_UB},trap)
1195 $(eval $(call add_define,MONITOR_TRAPS))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001196endif #(SANITIZE_UB)
Justin Chadwell1f461972019-08-20 11:01:52 +01001197
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001198# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1199ifdef EL3_PAYLOAD_BASE
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001200 $(eval $(call add_define,EL3_PAYLOAD_BASE))
1201else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001202# Define the PRELOADED_BL33_BASE flag only if it is provided and
1203# EL3_PAYLOAD_BASE is not defined, as it has priority.
1204 ifdef PRELOADED_BL33_BASE
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01001205 $(eval $(call add_define,PRELOADED_BL33_BASE))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001206 endif
1207endif #(EL3_PAYLOAD_BASE)
Juan Castillo73c99d42015-08-18 14:23:04 +01001208
Soby Mathew209a60c2018-03-26 12:43:37 +01001209# Define the DYN_DISABLE_AUTH flag only if set.
1210ifeq (${DYN_DISABLE_AUTH},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001211 $(eval $(call add_define,DYN_DISABLE_AUTH))
Soby Mathew209a60c2018-03-26 12:43:37 +01001212endif
1213
Chris Kay8620bd02023-12-04 09:55:50 +00001214ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001215 $(eval $(call add_define,USE_ARM_LINK))
Varun Wadekarc2ad38c2019-01-11 14:47:48 -08001216endif
1217
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001218# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001219ifeq (${SPD},spmd)
Olivier Deprezc33ff192020-03-19 09:27:11 +01001220ifdef SP_LAYOUT_FILE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001221 -include $(BUILD_PLAT)/sp_gen.mk
1222 FIP_DEPS += sp
1223 CRT_DEPS += sp
1224 NEED_SP_PKG := yes
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001225else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001226 ifeq (${SPMD_SPM_AT_SEL2},1)
1227 $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1228 endif
1229endif #(SP_LAYOUT_FILE)
1230endif #(SPD)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001231
Juan Castillo73c99d42015-08-18 14:23:04 +01001232################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +01001233# Build targets
1234################################################################################
1235
Harrison Mutai2329e222024-08-28 13:27:19 +00001236.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 +01001237
1238all: msg_start
1239
1240msg_start:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001241 $(s)echo "Building ${PLAT}"
Juan Castillo73c99d42015-08-18 14:23:04 +01001242
Soby Mathew7a24cba2015-10-26 14:29:21 +00001243ifeq (${ERROR_DEPRECATED},0)
Julius Wernerd5dfdeb2019-07-09 13:49:11 -07001244# Check if deprecated declarations and cpp warnings should be treated as error or not.
Chris Kay8620bd02023-12-04 09:55:50 +00001245ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -08001246 CPPFLAGS += -Wno-error=deprecated-declarations
1247else
Dan Handleybc1a03c2018-02-27 16:03:58 +00001248 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp
Soby Mathew7a24cba2015-10-26 14:29:21 +00001249endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001250endif #(!ERROR_DEPRECATED)
Soby Mathew7a24cba2015-10-26 14:29:21 +00001251
Roberto Vargas61f72a32018-05-08 10:27:10 +01001252$(eval $(call MAKE_LIB,c))
Roberto Vargas5fee0282018-05-08 10:27:10 +01001253
Juan Castillo73c99d42015-08-18 14:23:04 +01001254# Expand build macros for the different images
1255ifeq (${NEED_BL1},yes)
Chris Kayb34635a2021-09-28 15:44:19 +01001256BL1_SOURCES := $(sort ${BL1_SOURCES})
Zelalem Aweke434d0492021-07-11 17:25:48 -05001257$(eval $(call MAKE_BL,bl1))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001258endif #(NEED_BL1)
Juan Castillo73c99d42015-08-18 14:23:04 +01001259
1260ifeq (${NEED_BL2},yes)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001261
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -06001262ifeq (${RESET_TO_BL2}, 0)
Roberto Vargasc9b31ae2018-01-02 11:23:41 +00001263FIP_BL2_ARGS := tb-fw
1264endif
1265
Chris Kayeb1acfb2021-09-28 15:44:37 +01001266BL2_SOURCES := $(sort ${BL2_SOURCES})
1267
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001268$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001269 $(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001270
1271endif #(NEED_BL2)
Juan Castillo73c99d42015-08-18 14:23:04 +01001272
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001273ifeq (${NEED_SCP_BL2},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001274$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001275endif #(NEED_SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001276
Juan Castillo73c99d42015-08-18 14:23:04 +01001277ifeq (${NEED_BL31},yes)
1278BL31_SOURCES += ${SPD_SOURCES}
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001279# Sort BL31 source files to remove duplicates
1280BL31_SOURCES := $(sort ${BL31_SOURCES})
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301281ifneq (${DECRYPTION_SUPPORT},none)
1282$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001283 $(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301284else
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001285$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001286 $(eval $(call MAKE_BL,bl31,soc-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001287endif #(DECRYPTION_SUPPORT)
1288endif #(NEED_BL31)
Juan Castillo73c99d42015-08-18 14:23:04 +01001289
Juan Castillo70d1fc52015-11-12 10:59:26 +00001290# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
Masahiro Yamadac939d132018-01-26 11:42:01 +09001291# build system will call TOOL_ADD_IMG to print a warning message and abort the
Juan Castillo70d1fc52015-11-12 10:59:26 +00001292# process. Note that the dependency on BL32 applies to the FIP only.
Juan Castillo73c99d42015-08-18 14:23:04 +01001293ifeq (${NEED_BL32},yes)
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001294# Sort BL32 source files to remove duplicates
1295BL32_SOURCES := $(sort ${BL32_SOURCES})
Masahiro Yamada9cd15232018-01-26 11:42:01 +09001296BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1297
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301298ifneq (${DECRYPTION_SUPPORT},none)
Zelalem Aweke434d0492021-07-11 17:25:48 -05001299$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301300 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1301else
Zelalem Aweke434d0492021-07-11 17:25:48 -05001302$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001303 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001304endif #(DECRYPTION_SUPPORT)
1305endif #(NEED_BL32)
Juan Castillo73c99d42015-08-18 14:23:04 +01001306
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001307# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1308# needs to be built from RMM_SOURCES.
1309ifeq (${NEED_RMM},yes)
1310# Sort RMM source files to remove duplicates
1311RMM_SOURCES := $(sort ${RMM_SOURCES})
1312BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1313
1314$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001315 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1316endif #(NEED_RMM)
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001317
Juan Castillo73c99d42015-08-18 14:23:04 +01001318# Add the BL33 image if required by the platform
1319ifeq (${NEED_BL33},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001320$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001321endif #(NEED_BL33)
Juan Castillodb6071c2015-01-13 12:21:04 +00001322
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001323ifeq (${NEED_BL2U},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001324$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001325 $(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001326endif #(NEED_BL2U)
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001327
Nishanth Menon03b397a2016-10-14 01:13:57 +00001328# Expand build macros for the different images
1329ifeq (${NEED_FDT},yes)
Soby Mathew38c14d82017-12-14 17:44:56 +00001330 $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
Salman Nabi1c08ff32024-12-12 17:38:54 +00001331
1332 ifneq (${INITRD_SIZE}${INITRD_PATH},)
1333 ifndef INITRD_BASE
1334 $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1335 endif
1336
1337 INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1338 initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1339
1340 define $(HW_CONFIG)-after +=
1341 $(s)echo " INITRD $(HW_CONFIG)"
1342 $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1343 $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1344 endef
1345 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001346endif #(NEED_FDT)
Nishanth Menon03b397a2016-10-14 01:13:57 +00001347
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001348# Add Secure Partition packages
1349ifeq (${NEED_SP_PKG},yes)
Chris Kayfd74ca02024-07-30 13:33:56 +00001350$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
Chris Kay679e27c2025-03-19 15:04:47 +00001351 $(if $(host-poetry),$(q)poetry -q install --no-root)
Kathleen Capelladd816232025-02-13 17:34:21 -06001352 $(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
J-Alves822c7272022-03-22 16:28:51 +00001353sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001354 $(s)echo
1355 $(s)echo "Built SP Images successfully"
1356 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001357endif #(NEED_SP_PKG)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001358
Ian Spray36eaaf32014-01-30 17:25:28 +00001359locate-checkpatch:
1360ifndef CHECKPATCH
Etienne Carriere66079b02017-08-23 15:44:01 +02001361 $(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 +00001362else
1363ifeq (,$(wildcard ${CHECKPATCH}))
Etienne Carriere66079b02017-08-23 15:44:01 +02001364 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
Ian Spray36eaaf32014-01-30 17:25:28 +00001365endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001366endif #(CHECKPATCH)
Ian Spray36eaaf32014-01-30 17:25:28 +00001367
Achin Gupta4f6ad662013-10-25 09:08:21 +01001368clean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001369 $(s)echo " CLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001370 $(q)rm -rf $(BUILD_PLAT)
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001371 $(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001372 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1373 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1374 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001375
James Morrisseyeaaeece2013-11-01 13:56:59 +00001376realclean distclean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001377 $(s)echo " REALCLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001378 $(q)rm -rf $(BUILD_BASE)
1379 $(q)rm -rf $(CURDIR)/cscope.*
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001380 $(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001381 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1382 $(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1383 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001384
Ian Spray36eaaf32014-01-30 17:25:28 +00001385checkcodebase: locate-checkpatch
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001386 $(s)echo " CHECKING STYLE"
1387 $(q)if test -d .git ; then \
Paul Beesley1ef35512019-03-07 16:42:31 +00001388 git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' | \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001389 while read GIT_FILE ; \
1390 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
1391 done ; \
1392 else \
1393 find . -type f -not -iwholename "*.git*" \
1394 -not -iwholename "*build*" \
1395 -not -iwholename "*libfdt*" \
Roberto Vargas61f72a32018-05-08 10:27:10 +01001396 -not -iwholename "*libc*" \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001397 -not -iwholename "*docs*" \
Paul Beesley1ef35512019-03-07 16:42:31 +00001398 -not -iwholename "*.rst" \
Dan Handley1a41e8c2016-06-02 18:21:02 +01001399 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
1400 fi
Ian Spray36eaaf32014-01-30 17:25:28 +00001401
1402checkpatch: locate-checkpatch
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001403 $(s)echo " CHECKING STYLE"
1404 $(q)if test -n "${CHECKPATCH_OPTS}"; then \
Yann Gautier02a76d52019-03-08 15:44:00 +01001405 echo " with ${CHECKPATCH_OPTS} option(s)"; \
1406 fi
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001407 $(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
Yann Gautier77a0a7f2021-11-02 18:03:31 +01001408 for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`; \
1409 do \
Antonio Nino Diaz51d28932018-01-29 12:00:31 +00001410 printf "\n[*] Checking style of '$$commit'\n\n"; \
Yann Gautier1a721742024-08-09 11:52:03 +02001411 ( git log --format=email "$$commit~..$$commit" \
1412 -- ${CHECK_PATHS} ; \
1413 git diff --format=email "$$commit~..$$commit" \
1414 -- ${CHECK_PATHS}; ) | \
Yann Gautier02a76d52019-03-08 15:44:00 +01001415 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \
Antonio Nino Diaz51d28932018-01-29 12:00:31 +00001416 done
Juan Castillo73c99d42015-08-18 14:23:04 +01001417
1418certtool: ${CRTTOOL}
Ian Spray36eaaf32014-01-30 17:25:28 +00001419
Pali Rohára9812202020-11-24 15:38:08 +01001420${CRTTOOL}: FORCE
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001421 $(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
1422 $(s)echo
1423 $(s)echo "Built $@ successfully"
1424 $(s)echo
Juan Castillo73c99d42015-08-18 14:23:04 +01001425
1426ifneq (${GENERATE_COT},0)
1427certificates: ${CRT_DEPS} ${CRTTOOL}
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001428 $(q)${CRTTOOL} ${CRT_ARGS}
1429 $(s)echo
1430 $(s)echo "Built $@ successfully"
1431 $(s)echo "Certificates can be found in ${BUILD_PLAT}"
1432 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001433endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +01001434
1435${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
Pali Rohár4727fd12020-11-24 16:53:04 +01001436 $(eval ${CHECK_FIP_CMD})
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001437 $(q)${FIPTOOL} create ${FIP_ARGS} $@
1438 $(q)${FIPTOOL} info $@
1439 $(s)echo
1440 $(s)echo "Built $@ successfully"
1441 $(s)echo
Juan Castillo73c99d42015-08-18 14:23:04 +01001442
Yatharth Kochar01912622015-10-12 12:33:47 +01001443ifneq (${GENERATE_COT},0)
1444fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001445 $(q)${CRTTOOL} ${FWU_CRT_ARGS}
1446 $(s)echo
1447 $(s)echo "Built $@ successfully"
1448 $(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1449 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001450endif #(GENERATE_COT)
Yatharth Kochar01912622015-10-12 12:33:47 +01001451
1452${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
Pali Rohár4727fd12020-11-24 16:53:04 +01001453 $(eval ${CHECK_FWU_FIP_CMD})
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001454 $(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1455 $(q)${FIPTOOL} info $@
1456 $(s)echo
1457 $(s)echo "Built $@ successfully"
1458 $(s)echo
Yatharth Kochar01912622015-10-12 12:33:47 +01001459
Juan Castillo73c99d42015-08-18 14:23:04 +01001460fiptool: ${FIPTOOL}
1461fip: ${BUILD_PLAT}/${FIP_NAME}
Yatharth Kochar01912622015-10-12 12:33:47 +01001462fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
Juan Castillo6f971622014-10-21 11:30:42 +01001463
Pali Rohára9812202020-11-24 15:38:08 +01001464${FIPTOOL}: FORCE
Manish V Badarkhe40469bf2024-10-03 20:50:04 +01001465 $(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 +00001466
Manish V Badarkhee4a070e2024-12-03 21:46:51 +00001467$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB)
1468 $(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 +01001469
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001470memmap: all
Chris Kayc25405d2025-03-10 09:24:34 +00001471 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kay8daebef2025-04-15 14:00:50 +01001472 $(q)$(if $(host-poetry),poetry run )memory symbols --root ${BUILD_PLAT}
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001473
Harrison Mutai2329e222024-08-28 13:27:19 +00001474tl: ${BUILD_PLAT}/tl.bin
1475${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
Chris Kayc25405d2025-03-10 09:24:34 +00001476 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kayd2867392024-09-26 14:18:04 +00001477 $(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
Harrison Mutai2329e222024-08-28 13:27:19 +00001478
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001479doc:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001480 $(s)echo " BUILD DOCUMENTATION"
Harrison Mutaic61c9a32025-05-15 08:47:34 +00001481 $(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1482 $(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} html
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001483
Sumit Garg90aa9012019-11-11 18:46:36 +05301484enctool: ${ENCTOOL}
1485
Pali Rohára9812202020-11-24 15:38:08 +01001486${ENCTOOL}: FORCE
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001487 $(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1488 $(s)echo
1489 $(s)echo "Built $@ successfully"
1490 $(s)echo
Sumit Garg90aa9012019-11-11 18:46:36 +05301491
Joakim Bech35fab8c2014-01-23 14:51:49 +01001492cscope:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001493 $(s)echo " CSCOPE"
1494 $(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1495 $(q)cscope -b -q -k
Joakim Bech35fab8c2014-01-23 14:51:49 +01001496
Ryan Harkin72ee3312014-01-15 16:55:07 +00001497help:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001498 $(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1499 $(s)echo ""
1500 $(s)echo "PLAT is used to specify which platform you wish to build."
1501 $(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1502 $(s)echo ""
1503 $(s)echo "platform = ${PLATFORM_LIST}"
1504 $(s)echo ""
1505 $(s)echo "Please refer to the User Guide for a list of all supported options."
1506 $(s)echo "Note that the build system doesn't track dependencies for build "
1507 $(s)echo "options. Therefore, if any of the build options are changed "
1508 $(s)echo "from a previous build, a clean build must be performed."
1509 $(s)echo ""
1510 $(s)echo "Supported Targets:"
1511 $(s)echo " all Build all individual bootloader binaries"
1512 $(s)echo " bl1 Build the BL1 binary"
1513 $(s)echo " bl2 Build the BL2 binary"
1514 $(s)echo " bl2u Build the BL2U binary"
1515 $(s)echo " bl31 Build the BL31 binary"
1516 $(s)echo " bl32 Build the BL32 binary. If ARCH=aarch32, then "
1517 $(s)echo " this builds secure payload specified by AARCH32_SP"
1518 $(s)echo " certificates Build the certificates (requires 'GENERATE_COT=1')"
1519 $(s)echo " fip Build the Firmware Image Package (FIP)"
1520 $(s)echo " fwu_fip Build the FWU Firmware Image Package (FIP)"
1521 $(s)echo " checkcodebase Check the coding style of the entire source tree"
1522 $(s)echo " checkpatch Check the coding style on changes in the current"
1523 $(s)echo " branch against BASE_COMMIT (default origin/master)"
1524 $(s)echo " clean Clean the build for the selected platform"
1525 $(s)echo " cscope Generate cscope index"
1526 $(s)echo " distclean Remove all build artifacts for all platforms"
1527 $(s)echo " certtool Build the Certificate generation tool"
1528 $(s)echo " enctool Build the Firmware encryption tool"
1529 $(s)echo " fiptool Build the Firmware Image Package (FIP) creation tool"
1530 $(s)echo " sp Build the Secure Partition Packages"
1531 $(s)echo " sptool Build the Secure Partition Package creation tool"
1532 $(s)echo " dtbs Build the Device Tree Blobs (if required for the platform)"
1533 $(s)echo " memmap Print the memory map of the built binaries"
1534 $(s)echo " doc Build html based documentation using Sphinx tool"
1535 $(s)echo ""
1536 $(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1537 $(s)echo ""
1538 $(s)echo "example: build all targets for the FVP platform:"
1539 $(s)echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
Pali Rohára9812202020-11-24 15:38:08 +01001540
1541.PHONY: FORCE
1542FORCE:;