blob: 6b7e37447235124c16700e9ca3bd33282ad44d06 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001#
Chris Kayc3273702025-01-13 15:57:32 +00002# Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003#
dp-arm82cb2c12017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005#
6
Jeenu Viswambharane35c4042014-05-15 14:40:58 +01007#
Juan Castilloaaa3e722014-06-30 11:41:46 +01008# Trusted Firmware Version
9#
Soby Mathew1a0f1122018-10-01 16:16:34 +010010VERSION_MAJOR := 2
Govindraj Raja97a6de92025-05-07 13:51:45 -050011VERSION_MINOR := 13
Yann Gautierc25d1cc2024-02-08 18:40:27 +010012# VERSION_PATCH is only used for LTS releases
13VERSION_PATCH := 0
Yann Gautier055ebec2023-10-03 11:09:07 +020014VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
Juan Castilloaaa3e722014-06-30 11:41:46 +010015
Juan Castillo88154672015-10-22 11:34:44 +010016# Default goal is build all images
17.DEFAULT_GOAL := all
18
Douglas Raillard72fc70e2016-12-28 14:47:50 +000019# Avoid any implicit propagation of command line variable definitions to
20# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
21# usage. Other command line options like "-s" are still propagated as usual.
22MAKEOVERRIDES =
23
Evan Lloyd231c1472015-12-02 18:17:37 +000024MAKE_HELPERS_DIRECTORY := make_helpers/
25include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
Chris Kayf4dd18c2024-06-04 00:04:48 +000026include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
Chris Kay7c4e1ee2024-05-02 17:52:37 +000027include ${MAKE_HELPERS_DIRECTORY}common.mk
Juan Castillo73c99d42015-08-18 14:23:04 +010028
29################################################################################
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010030# Default values for build configurations, and their dependencies
Juan Castillo73c99d42015-08-18 14:23:04 +010031################################################################################
Jeenu Viswambharane35c4042014-05-15 14:40:58 +010032
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010033include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Yann Gautier422b1812025-01-17 11:02:50 +010034PLAT := ${DEFAULT_PLAT}
Andrey Skvortsov1b2fb6a2024-02-18 11:43:12 +030035include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
36
37# To be able to set platform specific defaults
38ifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
39include ${PLAT_DEFAULTS_MAKEFILE_FULL}
40endif
dp-arm872be882016-09-19 11:18:44 +010041
Chris Kaycc277de2023-10-20 09:17:33 +000042################################################################################
43# Configure the toolchains used to build TF-A and its tools
44################################################################################
45
46include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
47
Antonio Nino Diazcc8b5632017-04-18 15:16:05 +010048# Assertions enabled for DEBUG builds by default
Antonio Nino Diazcc8b5632017-04-18 15:16:05 +010049ENABLE_ASSERTIONS := ${DEBUG}
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +010050ENABLE_PMF := ${ENABLE_RUNTIME_INSTRUMENTATION}
Juan Castillo73c99d42015-08-18 14:23:04 +010051
52################################################################################
53# Checkpatch script options
54################################################################################
55
Sandrine Bailleuxf6077392016-06-02 11:19:59 +010056CHECKCODE_ARGS := --no-patch
Dan Handleyf0b489c2016-06-02 17:15:13 +010057# Do not check the coding style on imported library files or documentation files
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030058INC_DRV_DIRS_TO_CHECK := $(sort $(filter-out \
59 include/drivers/arm, \
60 $(wildcard include/drivers/*)))
Dan Handleyf0b489c2016-06-02 17:15:13 +010061INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Dan Handley1a41e8c2016-06-02 18:21:02 +010062 include/lib/libfdt \
Roberto Vargas61f72a32018-05-08 10:27:10 +010063 include/lib/libc, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010064 $(wildcard include/lib/*)))
65INC_DIRS_TO_CHECK := $(sort $(filter-out \
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030066 include/lib \
67 include/drivers, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010068 $(wildcard include/*)))
69LIB_DIRS_TO_CHECK := $(sort $(filter-out \
dp-armd801fbb2017-05-04 12:15:35 +010070 lib/compiler-rt \
Antonio Nino Diaz55cdcf72017-01-16 17:20:45 +000071 lib/libfdt% \
Roberto Vargas61f72a32018-05-08 10:27:10 +010072 lib/libc, \
Daniel Boulbya1942552022-10-05 11:05:22 +010073 lib/zlib \
Dan Handleyf0b489c2016-06-02 17:15:13 +010074 $(wildcard lib/*)))
75ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
76 lib \
77 include \
78 docs \
Paul Beesley1ef35512019-03-07 16:42:31 +000079 %.rst, \
Dan Handleyf0b489c2016-06-02 17:15:13 +010080 $(wildcard *)))
81CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
82 ${INC_DIRS_TO_CHECK} \
83 ${INC_LIB_DIRS_TO_CHECK} \
Gilad Ben-Yossef45018432019-05-15 09:24:04 +030084 ${LIB_DIRS_TO_CHECK} \
85 ${INC_DRV_DIRS_TO_CHECK} \
86 ${INC_ARM_DIRS_TO_CHECK}
Ian Spray36eaaf32014-01-30 17:25:28 +000087
Juan Castillo73c99d42015-08-18 14:23:04 +010088################################################################################
89# Process build options
90################################################################################
91
Chris Kay7c4e1ee2024-05-02 17:52:37 +000092ifeq ($(verbose),)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +010093 CHECKCODE_ARGS += --no-summary --terse
Achin Gupta4f6ad662013-10-25 09:08:21 +010094endif
Andre Przywaraee1ba6d2018-09-27 10:56:05 +010095
Juan Castillo73c99d42015-08-18 14:23:04 +010096################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +010097# Auxiliary tools (fiptool, cert_create, etc)
98################################################################################
99
100# Variables for use with Certificate Generation Tool
101CRTTOOLPATH ?= tools/cert_create
Boyan Karatotevf4595e62025-05-06 17:11:29 +0100102CRTTOOL ?= ${BUILD_PLAT}/${CRTTOOLPATH}/cert_create$(.exe)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100103
104# Variables for use with Firmware Encryption Tool
105ENCTOOLPATH ?= tools/encrypt_fw
Boyan Karatotev96fbe882025-05-02 16:40:40 +0100106ENCTOOL ?= ${BUILD_PLAT}/${ENCTOOLPATH}/encrypt_fw$(.exe)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100107
108# Variables for use with Firmware Image Package
109FIPTOOLPATH ?= tools/fiptool
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +0100110FIPTOOL ?= ${BUILD_PLAT}/${FIPTOOLPATH}/fiptool$(.exe)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100111
112# Variables for use with sptool
113SPTOOLPATH ?= tools/sptool
114SPTOOL ?= ${SPTOOLPATH}/sptool.py
115SP_MK_GEN ?= ${SPTOOLPATH}/sp_mk_generator.py
Karl Meakin20629b32023-02-14 11:56:02 +0000116SP_DTS_LIST_FRAGMENT ?= ${BUILD_PLAT}/sp_list_fragment.dts
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100117
J-Alves0fe374e2024-11-18 17:49:53 +0000118# Variables for use with sptool
119TLCTOOL ?= poetry run tlc
120
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100121# Variables for use with ROMLIB
122ROMLIBPATH ?= lib/romlib
123
124# Variable for use with Python
125PYTHON ?= python3
126
127# Variables for use with documentation build using Sphinx tool
128DOCS_PATH ?= docs
129
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
Chris Kay8620bd02023-12-04 09:55:50 +0000140ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
141 ifeq ($($(ARCH)-cc-id),arm-clang)
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500142 TF_CFLAGS_aarch32 := -target arm-arm-none-eabi
143 TF_CFLAGS_aarch64 := -target aarch64-arm-none-eabi
originc8a992f2022-01-19 16:30:14 +0000144 else
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500145 TF_CFLAGS_aarch32 = $(target32-directive)
Yann Gautieraf8947f2025-01-22 09:43:47 +0100146 TF_CFLAGS_aarch64 := -target aarch64-unknown-none-elf
originc8a992f2022-01-19 16:30:14 +0000147 endif
148
Chris Kay8620bd02023-12-04 09:55:50 +0000149else ifeq ($($(ARCH)-cc-id),gnu-gcc)
Chris Kayfa402f32024-02-20 16:19:54 +0000150 # Enable LTO only for aarch64
151 ifeq (${ARCH},aarch64)
152 LTO_CFLAGS = $(if $(filter-out 0,$(ENABLE_LTO)),-flto)
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600153 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100154endif #(clang)
dp-armd5461852017-05-02 12:00:08 +0100155
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100156# Process Debug flag
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100157ifneq (${DEBUG}, 0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100158 BUILD_TYPE := debug
159 TF_CFLAGS += -g -gdwarf-4
160 ASFLAGS += -g -Wa,-gdwarf-4
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100161
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100162 # Use LOG_LEVEL_INFO by default for debug builds
163 LOG_LEVEL := 40
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100164else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100165 BUILD_TYPE := release
166 # Use LOG_LEVEL_NOTICE by default for release builds
167 LOG_LEVEL := 20
168endif #(Debug)
Ahmad Fatoum32b209b2020-02-25 11:25:08 +0100169
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800170# Default build string (git branch and commit)
171ifeq (${BUILD_STRING},)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100172 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800173endif
laurenw-armdddf4282022-07-12 10:12:05 -0500174VERSION_STRING := v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
Peiyuan Songf1de4c82020-04-25 16:53:43 +0800175
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100176ifeq (${AARCH32_INSTRUCTION_SET},A32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100177 TF_CFLAGS_aarch32 += -marm
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100178else ifeq (${AARCH32_INSTRUCTION_SET},T32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100179 TF_CFLAGS_aarch32 += -mthumb
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100180endif #(AARCH32_INSTRUCTION_SET)
Antonio Nino Diaz8fd9d4d2018-08-08 16:28:43 +0100181
Sandrine Bailleuxa9c4dde2018-07-03 09:14:45 +0200182TF_CFLAGS_aarch32 += -mno-unaligned-access
dp-armd5461852017-05-02 12:00:08 +0100183TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align
Soby Mathew9d29c222016-05-05 14:33:33 +0100184
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100185##############################################################################
186# WARNINGS Configuration
187###############################################################################
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100188# General warnings
189WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
Yann Gautier34b508b2021-05-20 13:18:14 +0200190 -Wdisabled-optimization -Wvla -Wshadow \
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000191 -Wredundant-decls
192# stricter warnings
193WARNINGS += -Wextra -Wno-trigraphs
194# too verbose for generic build
195WARNINGS += -Wno-missing-field-initializers \
196 -Wno-type-limits -Wno-sign-compare \
197# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
198WARNINGS += -Wno-unused-parameter
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100199
200# Additional warnings
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000201# Level 1 - infrequent warnings we should have none of
202# full -Wextra
203WARNING1 += -Wsign-compare
204WARNING1 += -Wtype-limits
205WARNING1 += -Wmissing-field-initializers
Yann Gautiere7c645b2018-12-10 18:00:26 +0100206
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000207# Level 2 - problematic warnings that we want
208# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
209# TODO: disable just for them and move into default build
210WARNING2 += -Wold-style-definition
211WARNING2 += -Wmissing-prototypes
212WARNING2 += -Wmissing-format-attribute
213# TF-A aims to comply with this eventually. Effort too large at present
214WARNING2 += -Wundef
Boyan Karatotevd141e632022-11-21 14:49:05 +0000215# currently very involved and many platforms set this off
216WARNING2 += -Wunused-const-variable=2
Yann Gautiere7c645b2018-12-10 18:00:26 +0100217
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000218# Level 3 - very pedantic, frequently ignored
Yann Gautiere7c645b2018-12-10 18:00:26 +0100219WARNING3 := -Wbad-function-cast
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000220WARNING3 += -Waggregate-return
221WARNING3 += -Wnested-externs
222WARNING3 += -Wcast-align
Yann Gautiere7c645b2018-12-10 18:00:26 +0100223WARNING3 += -Wcast-qual
224WARNING3 += -Wconversion
225WARNING3 += -Wpacked
Yann Gautiere7c645b2018-12-10 18:00:26 +0100226WARNING3 += -Wpointer-arith
Yann Gautiere7c645b2018-12-10 18:00:26 +0100227WARNING3 += -Wswitch-default
Yann Gautiere7c645b2018-12-10 18:00:26 +0100228
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000229# Setting W is quite verbose and most warnings will be pre-existing issues
230# outside of the contributor's control. Don't fail the build on them so warnings
231# can be seen and hopefully addressed
232ifdef W
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100233 ifneq (${W},0)
234 E ?= 0
235 endif
Boyan Karatotevd75a9ec2022-11-21 14:16:43 +0000236endif
237
Yann Gautiere7c645b2018-12-10 18:00:26 +0100238ifeq (${W},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100239 WARNINGS += $(WARNING1)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100240else ifeq (${W},2)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100241 WARNINGS += $(WARNING1) $(WARNING2)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100242else ifeq (${W},3)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100243 WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
244endif #(W)
Yann Gautiere7c645b2018-12-10 18:00:26 +0100245
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100246# Compiler specific warnings
Chris Kay8620bd02023-12-04 09:55:50 +0000247ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
Justin Chadwell93c690e2019-07-03 14:15:56 +0100248# not using clang
Justin Chadwelld7b4cd42019-09-18 14:13:42 +0100249WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \
250 -Wpacked-bitfield-compat -Wshift-overflow=2 \
251 -Wlogical-op
Govindraj Rajadea23e22023-05-05 09:09:36 -0500252
253# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
Boyan Karatotev316f5c92024-10-10 13:54:37 +0100254TF_CFLAGS_MIN_PAGE_SIZE := $(call cc_option, --param=min-pagesize=0)
255TF_CFLAGS += $(TF_CFLAGS_MIN_PAGE_SIZE)
Govindraj Rajadea23e22023-05-05 09:09:36 -0500256
Bipin Ravi538516f2023-09-28 13:17:24 -0500257ifeq ($(HARDEN_SLS), 1)
Boyan Karatotev316f5c92024-10-10 13:54:37 +0100258 TF_CFLAGS_MHARDEN_SLS := $(call cc_option, -mharden-sls=all)
259 TF_CFLAGS_aarch64 += $(TF_CFLAGS_MHARDEN_SLS)
Bipin Ravi538516f2023-09-28 13:17:24 -0500260endif
261
Justin Chadwell93c690e2019-07-03 14:15:56 +0100262else
263# using clang
Justin Chadwelld7b4cd42019-09-18 14:13:42 +0100264WARNINGS += -Wshift-overflow -Wshift-sign-overflow \
265 -Wlogical-op-parentheses
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100266endif #(Clang Warning)
Ambroise Vincent00296572019-05-24 12:47:43 +0100267
Yann Gautier6336b072018-12-10 18:08:53 +0100268ifneq (${E},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100269 ERRORS := -Werror
270endif #(E)
Yann Gautier6336b072018-12-10 18:08:53 +0100271
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100272################################################################################
273# Compiler and Linker Directives
274################################################################################
Justin Chadwell9ab81b52019-07-31 11:36:41 +0100275CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \
276 $(ERRORS) $(WARNINGS)
Govindraj Rajad4089fb2023-05-30 16:52:15 -0500277ASFLAGS += $(CPPFLAGS) \
Julius Wernerd5dfdeb2019-07-09 13:49:11 -0700278 -ffreestanding -Wa,--fatal-warnings
Masahiro Yamada59de5092016-12-22 12:51:53 +0900279TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \
Samuel Hollandebd6efa2019-10-20 16:11:25 -0500280 -ffunction-sections -fdata-sections \
Boyan Karatotevee0c5b82024-12-09 08:24:12 +0000281 -ffreestanding -fno-common \
Samuel Hollandebd6efa2019-10-20 16:11:25 -0500282 -Os -std=gnu99
Juan Castillo73c99d42015-08-18 14:23:04 +0100283
Justin Chadwell1f461972019-08-20 11:01:52 +0100284ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100285 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover
286endif #(${SANITIZE_UB},on)
287
Justin Chadwell1f461972019-08-20 11:01:52 +0100288ifeq (${SANITIZE_UB},trap)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100289 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \
Justin Chadwell1f461972019-08-20 11:01:52 +0100290 -fsanitize-undefined-trap-on-error
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100291endif #(${SANITIZE_UB},trap)
Justin Chadwell1f461972019-08-20 11:01:52 +0100292
Chris Kay291e7182024-05-14 13:08:31 +0000293GCC_V_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
david cunadof7ec31d2017-11-30 21:58:01 +0000294
Marco Felsch1f49db52022-11-09 12:59:09 +0100295TF_LDFLAGS += -z noexecstack
296
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100297# LD = armlink
Chris Kay8620bd02023-12-04 09:55:50 +0000298ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100299 TF_LDFLAGS += --diag_error=warning --lto_level=O1
300 TF_LDFLAGS += --remove --info=unused,unusedsymbols
301 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH))
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100302
303# LD = gcc (used when GCC LTO is enabled)
Chris Kay8620bd02023-12-04 09:55:50 +0000304else ifeq ($($(ARCH)-ld-id),gnu-gcc)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100305 # Pass ld options with Wl or Xlinker switches
Chris Kay86e489c2024-01-16 11:53:35 +0000306 TF_LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100307 TF_LDFLAGS += -Wl,--fatal-warnings -O1
308 TF_LDFLAGS += -Wl,--gc-sections
Chris Kayac98b822022-12-22 13:26:37 +0000309
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100310 TF_LDFLAGS += -Wl,-z,common-page-size=4096 #Configure page size constants
311 TF_LDFLAGS += -Wl,-z,max-page-size=4096
Andrey Skvortsov304ad942023-09-05 23:06:29 +0300312 TF_LDFLAGS += -Wl,--build-id=none
Chris Kayac98b822022-12-22 13:26:37 +0000313
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100314 ifeq ($(ENABLE_LTO),1)
315 ifeq (${ARCH},aarch64)
316 TF_LDFLAGS += -flto -fuse-linker-plugin
Andrey Skvortsov31f80ef2023-12-08 18:04:51 +0300317 TF_LDFLAGS += -flto-partition=one
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100318 endif
319 endif #(ENABLE_LTO)
320
zelalem-awekeedbce9a2019-11-12 16:20:17 -0600321# GCC automatically adds fix-cortex-a53-843419 flag when used to link
322# which breaks some builds, so disable if errata fix is not explicitly enabled
Yann Gautiercfe67672023-03-15 16:18:16 +0100323 ifeq (${ARCH},aarch64)
324 ifneq (${ERRATA_A53_843419},1)
325 TF_LDFLAGS += -mno-fix-cortex-a53-843419
326 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100327 endif
328 TF_LDFLAGS += -nostdlib
329 TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100330
331# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
Varun Wadekarc2ad38c2019-01-11 14:47:48 -0800332else
Marco Felsch1f49db52022-11-09 12:59:09 +0100333# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
334# are not loaded by a elf loader.
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100335 TF_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
336 TF_LDFLAGS += -O1
337 TF_LDFLAGS += --gc-sections
Chris Kayac98b822022-12-22 13:26:37 +0000338
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100339 TF_LDFLAGS += -z common-page-size=4096 # Configure page size constants
340 TF_LDFLAGS += -z max-page-size=4096
Andrey Skvortsov304ad942023-09-05 23:06:29 +0300341 TF_LDFLAGS += --build-id=none
Chris Kayac98b822022-12-22 13:26:37 +0000342
Ambroise Vincent641f16e2019-07-17 11:08:38 +0100343# ld.lld doesn't recognize the errata flags,
Yabin Cuiebac6922023-01-19 20:06:04 +0000344# therefore don't add those in that case.
345# ld.lld reports section type mismatch warnings,
346# therefore don't add --fatal-warnings to it.
Chris Kay8620bd02023-12-04 09:55:50 +0000347 ifneq ($($(ARCH)-ld-id),llvm-lld)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100348 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) --fatal-warnings
349 endif
350
351endif #(LD = armlink)
Juan Castillo73c99d42015-08-18 14:23:04 +0100352
353################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500354# Setup ARCH_MAJOR/MINOR before parsing arch_features.
355################################################################################
356ifeq (${ENABLE_RME},1)
AlexeiFedorov7d5fc982024-03-13 11:53:44 +0000357 ARM_ARCH_MAJOR := 9
358 ARM_ARCH_MINOR := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500359endif
360
361################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100362# Common sources and include directories
363################################################################################
dp-armd801fbb2017-05-04 12:15:35 +0100364include lib/compiler-rt/compiler-rt.mk
Juan Castillo73c99d42015-08-18 14:23:04 +0100365
Chris Kay758ccb82024-03-08 16:08:31 +0000366# Allow overriding the timestamp, for example for reproducible builds, or to
367# synchronize timestamps across multiple projects.
368# This must be set to a C string (including quotes where applicable).
369BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
370
371DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
372DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
373DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
374
Juan Castillo73c99d42015-08-18 14:23:04 +0100375BL_COMMON_SOURCES += common/bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100376 common/tf_log.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100377 common/${ARCH}/debug.S \
Julius Werner91b48c92018-11-27 22:10:56 -0800378 drivers/console/multi_console.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100379 lib/${ARCH}/cache_helpers.S \
380 lib/${ARCH}/misc_helpers.S \
Boyan Karatotevc73686a2023-02-15 13:21:50 +0000381 lib/extensions/pmuv3/${ARCH}/pmuv3.c \
Soby Mathew566034f2018-02-08 17:45:12 +0000382 plat/common/plat_bl_common.c \
Soby Mathew7f56e9a2017-09-04 11:49:29 +0100383 plat/common/plat_log_common.c \
dp-arm75311202017-03-07 11:02:47 +0000384 plat/common/${ARCH}/plat_common.c \
Soby Mathew9d29c222016-05-05 14:33:33 +0100385 plat/common/${ARCH}/platform_helpers.S \
Roberto Vargas61f72a32018-05-08 10:27:10 +0100386 ${COMPILER_RT_SRCS}
Ryan Harkind7a6b0f2014-01-13 14:40:13 +0000387
Chris Kay8620bd02023-12-04 09:55:50 +0000388ifeq ($($(ARCH)-cc-id),arm-clang)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100389 BL_COMMON_SOURCES += lib/${ARCH}/armclang_printf.S
Antonio Nino Diaz8422a842018-08-16 15:42:44 +0100390endif
391
Justin Chadwell1f461972019-08-20 11:01:52 +0100392ifeq (${SANITIZE_UB},on)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100393 BL_COMMON_SOURCES += plat/common/ubsan.c
Justin Chadwell1f461972019-08-20 11:01:52 +0100394endif
395
Yann Gautier01d237c2018-06-18 16:00:23 +0200396INCLUDES += -Iinclude \
Antonio Nino Diazf5478de2018-12-17 17:20:57 +0000397 -Iinclude/arch/${ARCH} \
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +0000398 -Iinclude/lib/cpus/${ARCH} \
399 -Iinclude/lib/el3_runtime/${ARCH} \
400 ${PLAT_INCLUDES} \
401 ${SPD_INCLUDES}
402
Nishant Sharmae03dcc82022-08-15 16:37:07 +0100403DTC_FLAGS += -I dts -O dtb
404DTC_CPPFLAGS += -P -nostdinc $(INCLUDES) -Ifdts -undef \
405 -x assembler-with-cpp $(DEFINES)
406
Antonio Nino Diaz9c6d1c52018-11-19 11:48:30 +0000407include common/backtrace/backtrace.mk
408
Juan Castillo73c99d42015-08-18 14:23:04 +0100409################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500410# Generic definitions
411################################################################################
Govindraj Raja35472702023-09-20 14:32:24 -0500412
413ifeq (${BUILD_BASE},)
414 BUILD_BASE := ./build
415endif
416BUILD_PLAT := $(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
417
418SPDS := $(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
419
420# Platforms providing their own TBB makefile may override this value
421INCLUDE_TBBR_MK := 1
422
423################################################################################
424# Include SPD Makefile if one has been specified
425################################################################################
426
427ifneq (${SPD},none)
Govindraj Raja35472702023-09-20 14:32:24 -0500428 ifeq (${SPD},spmd)
429 # SPMD is located in std_svc directory
430 SPD_DIR := std_svc
431
432 ifeq ($(SPMD_SPM_AT_SEL2),1)
433 CTX_INCLUDE_EL2_REGS := 1
Govindraj Raja35472702023-09-20 14:32:24 -0500434 endif
435
436 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
437 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG
438 endif
439
Arunachalam Ganapathy0686a012022-04-11 14:36:54 +0100440 ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
441 DTC_CPPFLAGS += -DTRUSTY_SP_FW_CONFIG
442 endif
443
Govindraj Raja35472702023-09-20 14:32:24 -0500444 ifeq ($(TS_SP_FW_CONFIG),1)
Arunachalam Ganapathy0686a012022-04-11 14:36:54 +0100445 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG
Govindraj Raja35472702023-09-20 14:32:24 -0500446 endif
447
448 ifneq ($(ARM_BL2_SP_LIST_DTS),)
449 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
450 endif
451
452 ifneq ($(SP_LAYOUT_FILE),)
453 BL2_ENABLE_SP_LOAD := 1
454 endif
455 else
456 # All other SPDs in spd directory
457 SPD_DIR := spd
458 endif #(SPD)
459
460 # We expect to locate an spd.mk under the specified SPD directory
461 SPD_MAKE := $(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
462
463 ifeq (${SPD_MAKE},)
464 $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
465 endif
466 $(info Including ${SPD_MAKE})
467 include ${SPD_MAKE}
468
469 # If there's BL32 companion for the chosen SPD, we expect that the SPD's
470 # Makefile would set NEED_BL32 to "yes". In this case, the build system
471 # supports two mutually exclusive options:
472 # * BL32 is built from source: then BL32_SOURCES must contain the list
473 # of source files to build BL32
474 # * BL32 is a prebuilt binary: then BL32 must point to the image file
475 # that will be included in the FIP
476 # If both BL32_SOURCES and BL32 are defined, the binary takes precedence
477 # over the sources.
478endif #(SPD=none)
479
Govindraj Raja35472702023-09-20 14:32:24 -0500480################################################################################
Olivier Deprez696ed162025-01-03 13:38:50 +0100481# Include the platform specific Makefile after the SPD Makefile (the platform
482# makefile may use all previous definitions in this file)
483################################################################################
484include ${PLAT_MAKEFILE_FULL}
485
486################################################################################
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100487# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
488# platform.
489################################################################################
490
491include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
492################################################################################
Govindraj Rajaf5211422023-08-17 10:41:48 -0500493# Process BRANCH_PROTECTION value and set
494# Pointer Authentication and Branch Target Identification flags
495################################################################################
496ifeq (${BRANCH_PROTECTION},0)
497 # Default value turns off all types of branch protection
498 BP_OPTION := none
499else ifneq (${ARCH},aarch64)
500 $(error BRANCH_PROTECTION requires AArch64)
501else ifeq (${BRANCH_PROTECTION},1)
502 # Enables all types of branch protection features
503 BP_OPTION := standard
504 ENABLE_BTI := 1
505 ENABLE_PAUTH := 1
506else ifeq (${BRANCH_PROTECTION},2)
507 # Return address signing to its standard level
508 BP_OPTION := pac-ret
509 ENABLE_PAUTH := 1
510else ifeq (${BRANCH_PROTECTION},3)
511 # Extend the signing to include leaf functions
512 BP_OPTION := pac-ret+leaf
513 ENABLE_PAUTH := 1
514else ifeq (${BRANCH_PROTECTION},4)
515 # Turn on branch target identification mechanism
516 BP_OPTION := bti
517 ENABLE_BTI := 1
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100518else ifeq (${BRANCH_PROTECTION},5)
519 # Turn on branch target identification mechanism
520 BP_OPTION := standard
521 ENABLE_BTI := 2
522 ENABLE_PAUTH := 2
Govindraj Rajaf5211422023-08-17 10:41:48 -0500523else
524 $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
525endif #(BRANCH_PROTECTION)
526
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100527ifneq ($(ENABLE_PAUTH),0)
528 CTX_INCLUDE_PAUTH_REGS := ${ENABLE_PAUTH}
Govindraj Rajaf5211422023-08-17 10:41:48 -0500529endif
530ifneq (${BP_OPTION},none)
531 TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION}
532endif #(BP_OPTION)
533
534# Pointer Authentication sources
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100535ifneq (${ENABLE_PAUTH},0)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500536# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
537# Pauth support. As it's not secure, it must be reimplemented for real platforms
Boyan Karatotev8d9f5f22025-04-02 11:16:18 +0100538 BL_COMMON_SOURCES += lib/extensions/pauth/pauth.c
Govindraj Rajaf5211422023-08-17 10:41:48 -0500539endif
Boyan Karatotevb14987c2025-04-09 14:41:58 +0100540#
541ifneq (${ENABLE_FEAT_PAUTH_LR},0)
542# Currently, FEAT_PAUTH_LR is only supported by arm/clang compilers
543# TODO implement for GCC when support is added
544ifeq ($($(ARCH)-cc-id),arm-clang)
545 arch-features := $(arch-features)+pauth-lr
546else
547 $(error Error: ENABLE_FEAT_PAUTH_LR not supported for GCC compiler)
548endif
549endif
Govindraj Rajaf5211422023-08-17 10:41:48 -0500550
Govindraj Rajaf5211422023-08-17 10:41:48 -0500551################################################################################
552# RME dependent flags configuration, Enable optional features for RME.
553################################################################################
554# FEAT_RME
555ifeq (${ENABLE_RME},1)
Govindraj Rajaf5211422023-08-17 10:41:48 -0500556 # RME requires el2 context to be saved for now.
557 CTX_INCLUDE_EL2_REGS := 1
558 CTX_INCLUDE_AARCH32_REGS := 0
559 CTX_INCLUDE_PAUTH_REGS := 1
560
Javier Almansa Sobrinod048af02025-03-21 18:32:10 +0000561 ifneq ($(ENABLE_FEAT_MPAM), 0)
562 CTX_INCLUDE_MPAM_REGS := 1
563 endif
564
Govindraj Rajaf5211422023-08-17 10:41:48 -0500565 # RME enables CSV2_2 extension by default.
566 ENABLE_FEAT_CSV2_2 = 1
567endif #(FEAT_RME)
568
569################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500570# Include rmmd Makefile if RME is enabled
571################################################################################
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500572ifneq (${ENABLE_RME},0)
Zelalem Aweke5b18de02021-07-11 18:33:20 -0500573include services/std_svc/rmmd/rmmd.mk
574$(warning "RME is an experimental feature")
575endif
576
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000577################################################################################
Govindraj Raja30655132024-09-06 15:43:43 +0100578# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
579################################################################################
580ifneq (${ENABLE_FEAT_D128}, 0)
581 BL_COMMON_SOURCES += lib/extensions/sysreg128/sysreg128.S
582endif
583
584################################################################################
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500585# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
586# up with appropriate march values for compiler.
587################################################################################
588include ${MAKE_HELPERS_DIRECTORY}march.mk
589
John Powell025b1b82025-03-10 20:09:03 -0500590TF_CFLAGS += $(march-directive)
Govindraj Raja7275ac22024-01-23 16:00:19 -0600591ASFLAGS += $(march-directive)
Govindraj Raja7794d6c2023-06-01 16:29:16 -0500592
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600593# This internal flag is common option which is set to 1 for scenarios
594# when the BL2 is running in EL3 level. This occurs in two scenarios -
595# 4 world system running BL2 at EL3 and two world system without BL1 running
596# BL2 in EL3
597
598ifeq (${RESET_TO_BL2},1)
599 BL2_RUNS_AT_EL3 := 1
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100600 ifeq (${ENABLE_RME},1)
601 $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
602 supported at the moment.)
603 endif
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600604else ifeq (${ENABLE_RME},1)
605 BL2_RUNS_AT_EL3 := 1
606else
607 BL2_RUNS_AT_EL3 := 0
608endif
609
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100610# This internal flag is set to 1 when Firmware First handling of External aborts
611# is required by lowe ELs. Currently only NS requires this support.
612ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
613 FFH_SUPPORT := 1
614else
615 FFH_SUPPORT := 0
616endif
617
Etienne Carriere26e63c42017-11-08 13:48:40 +0100618ifeq (${ARM_ARCH_MAJOR},7)
619include make_helpers/armv7-a-cpus.mk
620endif
621
Masahiro Yamada320920c2020-01-17 13:44:37 +0900622PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
623ifneq ($(PIE_FOUND),)
624 TF_CFLAGS += -fno-PIE
Chris Kay8620bd02023-12-04 09:55:50 +0000625ifeq ($($(ARCH)-ld-id),gnu-gcc)
Samuel Holland7b592412022-04-08 21:56:02 -0500626 TF_LDFLAGS += -no-pie
627endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100628endif #(PIE_FOUND)
Masahiro Yamada320920c2020-01-17 13:44:37 +0900629
Chris Kay8620bd02023-12-04 09:55:50 +0000630ifeq ($($(ARCH)-ld-id),gnu-gcc)
Masahiro Yamada320920c2020-01-17 13:44:37 +0900631 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
Soby Mathew3bd17c02018-08-28 11:13:55 +0100632else
Masahiro Yamada320920c2020-01-17 13:44:37 +0900633 PIE_LDFLAGS += -pie --no-dynamic-linker
634endif
635
636ifeq ($(ENABLE_PIE),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100637 ifeq ($(RESET_TO_BL2),1)
638 ifneq ($(BL2_IN_XIP_MEM),1)
639 BL2_CPPFLAGS += -fpie
640 BL2_CFLAGS += -fpie
641 BL2_LDFLAGS += $(PIE_LDFLAGS)
642 endif #(BL2_IN_XIP_MEM)
643 endif #(RESET_TO_BL2)
Chris Kay966660e2023-02-02 14:39:03 +0000644 BL31_CPPFLAGS += -fpie
645 BL31_CFLAGS += -fpie
Masahiro Yamada320920c2020-01-17 13:44:37 +0900646 BL31_LDFLAGS += $(PIE_LDFLAGS)
Chris Kay966660e2023-02-02 14:39:03 +0000647
648 BL32_CPPFLAGS += -fpie
Masahiro Yamadad9743012020-01-17 13:45:14 +0900649 BL32_CFLAGS += -fpie
650 BL32_LDFLAGS += $(PIE_LDFLAGS)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100651endif #(ENABLE_PIE)
Soby Mathew3bd17c02018-08-28 11:13:55 +0100652
Boyan Karatotev007433d2023-01-25 16:55:18 +0000653BL1_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
654BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
655BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
656
Masahiro Yamada9cefb4b2020-04-01 14:20:58 +0900657BL1_CPPFLAGS += -DIMAGE_AT_EL3
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -0600658ifeq ($(RESET_TO_BL2),1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100659 BL2_CPPFLAGS += -DIMAGE_AT_EL3
Masahiro Yamadad5e97a12020-03-26 13:18:48 +0900660else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100661 BL2_CPPFLAGS += -DIMAGE_AT_EL1
662endif #(RESET_TO_BL2)
Boyan Karatotev007433d2023-01-25 16:55:18 +0000663
664ifeq (${ARCH},aarch64)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100665 BL2U_CPPFLAGS += -DIMAGE_AT_EL1
666 BL31_CPPFLAGS += -DIMAGE_AT_EL3
667 BL32_CPPFLAGS += -DIMAGE_AT_EL1
Boyan Karatotev007433d2023-01-25 16:55:18 +0000668else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100669 BL32_CPPFLAGS += -DIMAGE_AT_EL3
Masahiro Yamadad5e97a12020-03-26 13:18:48 +0900670endif
671
Sandrine Bailleux54035fc2016-01-13 14:57:38 +0000672# Include the CPU specific operations makefile, which provides default
673# values for all CPU errata workarounds and CPU specific optimisations.
674# This can be overridden by the platform.
Juan Castillo73c99d42015-08-18 14:23:04 +0100675include lib/cpus/cpu-ops.mk
Achin Gupta4f6ad662013-10-25 09:08:21 +0100676
dp-arma4409002017-02-15 11:07:55 +0000677################################################################################
678# Build `AARCH32_SP` as BL32 image for AArch32
679################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100680ifeq (${ARCH},aarch32)
681 NEED_BL32 := yes
dp-arma4409002017-02-15 11:07:55 +0000682
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100683 ifneq (${AARCH32_SP},none)
684 # We expect to locate an sp.mk under the specified AARCH32_SP directory
685 AARCH32_SP_MAKE := $(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
dp-arma4409002017-02-15 11:07:55 +0000686
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100687 ifeq (${AARCH32_SP_MAKE},)
688 $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
689 endif
Juan Pablo Conde043f38f2023-08-09 13:19:21 -0500690 $(info Including ${AARCH32_SP_MAKE})
691 include ${AARCH32_SP_MAKE}
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100692 endif
693endif #(ARCH=aarch32)
Achin Gupta4f6ad662013-10-25 09:08:21 +0100694
Juan Castillo73c99d42015-08-18 14:23:04 +0100695################################################################################
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800696# Include libc if not overridden
697################################################################################
698ifeq (${OVERRIDE_LIBC},0)
699include lib/libc/libc.mk
700endif
701
Boyan Karatotev5d893412025-01-07 11:00:03 +0000702ifneq (${USE_GIC_DRIVER},0)
703include drivers/arm/gic/gic.mk
704endif
705
Varun Wadekar77f1f7a2019-01-31 09:22:30 -0800706################################################################################
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100707# Check incompatible options and dependencies
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000708################################################################################
Boyan Karatotevb14987c2025-04-09 14:41:58 +0100709include ${MAKE_HELPERS_DIRECTORY}constraints.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100710
711# The cert_create tool cannot generate certificates individually, so we use the
712# target 'certificates' to create them all
713ifneq (${GENERATE_COT},0)
714 FIP_DEPS += certificates
715 FWU_FIP_DEPS += fwu_certificates
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000716endif
717
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100718ifneq (${DECRYPTION_SUPPORT},none)
719 ENC_ARGS += -f ${FW_ENC_STATUS}
720 ENC_ARGS += -k ${ENC_KEY}
721 ENC_ARGS += -n ${ENC_NONCE}
722 FIP_DEPS += enctool
723 FWU_FIP_DEPS += enctool
724endif #(DECRYPTION_SUPPORT)
725
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100726ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
727# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100728 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100729else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
730# Support authentication verification and hash calculation
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100731 CRYPTO_SUPPORT := 3
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100732else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
733# Support hash calculation only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100734 CRYPTO_SUPPORT := 2
Manish V Badarkhe2bf4f272022-06-20 15:32:38 +0100735else ifeq (${TRUSTED_BOARD_BOOT},1)
736# Support authentication verification only
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100737 CRYPTO_SUPPORT := 1
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000738else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100739 CRYPTO_SUPPORT := 0
740endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
Manish V Badarkhec9c56f62022-01-08 22:56:06 +0000741
Manish V Badarkhee4a070e2024-12-03 21:46:51 +0000742ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
743CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
744endif
745
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +0000746################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +0100747# Process platform overrideable behaviour
748################################################################################
Achin Gupta4f6ad662013-10-25 09:08:21 +0100749
Manish Pandey5f24ce92021-10-06 10:59:52 +0100750ifdef BL1_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100751 NEED_BL1 := yes
752endif #(BL1_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100753
Juan Castillo73c99d42015-08-18 14:23:04 +0100754ifdef BL2_SOURCES
Manish Pandey5f24ce92021-10-06 10:59:52 +0100755 NEED_BL2 := yes
756
757 # Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
758 # Certificate generation tools. This flag can be overridden by the platform.
759 ifdef EL3_PAYLOAD_BASE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100760 # If booting an EL3 payload there is no need for a BL33 image
761 # in the FIP file.
762 NEED_BL33 := no
763 else
764 ifdef PRELOADED_BL33_BASE
765 # If booting a BL33 preloaded image there is no need of
766 # another one in the FIP file.
767 NEED_BL33 := no
768 else
769 NEED_BL33 ?= yes
770 endif
771 endif
772endif #(BL2_SOURCES)
Juan Castillo73c99d42015-08-18 14:23:04 +0100773
Manish Pandey5f24ce92021-10-06 10:59:52 +0100774ifdef BL2U_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100775 NEED_BL2U := yes
776endif #(BL2U_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100777
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900778# If SCP_BL2 is given, we always want FIP to include it.
779ifdef SCP_BL2
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100780 NEED_SCP_BL2 := yes
781endif #(SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +0900782
Soby Mathew5744e872017-11-14 14:10:10 +0000783# For AArch32, BL31 is not currently supported.
784ifneq (${ARCH},aarch32)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100785 ifdef BL31_SOURCES
786 # When booting an EL3 payload, there is no need to compile the BL31
787 # image nor put it in the FIP.
788 ifndef EL3_PAYLOAD_BASE
789 NEED_BL31 := yes
790 endif
791 endif
792endif #(ARCH=aarch64)
Soby Mathew5744e872017-11-14 14:10:10 +0000793
Juan Castillo73c99d42015-08-18 14:23:04 +0100794# Process TBB related flags
795ifneq (${GENERATE_COT},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100796 # Common cert_create options
797 ifneq (${CREATE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +0100798 $(eval CRT_ARGS += -n)
Yatharth Kochar01912622015-10-12 12:33:47 +0100799 $(eval FWU_CRT_ARGS += -n)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100800 ifneq (${SAVE_KEYS},0)
Juan Castillo73c99d42015-08-18 14:23:04 +0100801 $(eval CRT_ARGS += -k)
Yatharth Kochar01912622015-10-12 12:33:47 +0100802 $(eval FWU_CRT_ARGS += -k)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100803 endif
804 endif
805 # Include TBBR makefile (unless the platform indicates otherwise)
806 ifeq (${INCLUDE_TBBR_MK},1)
Juan Castillo73c99d42015-08-18 14:23:04 +0100807 include make_helpers/tbbr/tbbr_tools.mk
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100808 endif
809endif #(GENERATE_COT)
Juan Castillo73c99d42015-08-18 14:23:04 +0100810
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +0900811ifneq (${FIP_ALIGN},0)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100812 FIP_ARGS += --align ${FIP_ALIGN}
813endif #(FIP_ALIGN)
Masahiro Yamada1c75d5d2016-12-25 13:52:22 +0900814
Manish Pandey5f24ce92021-10-06 10:59:52 +0100815ifdef FDT_SOURCES
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100816 NEED_FDT := yes
817endif #(FDT_SOURCES)
Manish Pandey5f24ce92021-10-06 10:59:52 +0100818
Juan Castillo73c99d42015-08-18 14:23:04 +0100819################################################################################
Michalis Pappas46e5e032018-03-20 13:01:27 +0800820# Include libraries' Makefile that are used in all BL
821################################################################################
822
823include lib/stack_protector/stack_protector.mk
824
825################################################################################
Soby Mathew8a860522017-02-14 10:05:07 +0000826# Include BL specific makefiles
827################################################################################
Manish Pandey5f24ce92021-10-06 10:59:52 +0100828
829ifeq (${NEED_BL1},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000830include bl1/bl1.mk
831endif
832
Manish Pandey5f24ce92021-10-06 10:59:52 +0100833ifeq (${NEED_BL2},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000834include bl2/bl2.mk
835endif
836
Manish Pandey5f24ce92021-10-06 10:59:52 +0100837ifeq (${NEED_BL2U},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000838include bl2u/bl2u.mk
839endif
840
Soby Mathew5744e872017-11-14 14:10:10 +0000841ifeq (${NEED_BL31},yes)
Soby Mathew8a860522017-02-14 10:05:07 +0000842include bl31/bl31.mk
843endif
Nishanth Menon03b397a2016-10-14 01:13:57 +0000844
Juan Castillo73c99d42015-08-18 14:23:04 +0100845################################################################################
846# Build options checks
847################################################################################
Juan Castillob7124ea2014-11-04 17:36:40 +0000848
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100849# Boolean_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500850$(eval $(call assert_booleans,\
851 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100852 ALLOW_RO_XLAT_TABLES \
853 BL2_ENABLE_SP_LOAD \
854 COLD_BOOT_SINGLE_CPU \
855 CREATE_KEYS \
856 CTX_INCLUDE_AARCH32_REGS \
857 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -0500858 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100859 CTX_INCLUDE_EL2_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -0500860 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100861 DEBUG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100862 DYN_DISABLE_AUTH \
863 EL3_EXCEPTION_HANDLING \
864 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100865 AMU_RESTRICT_COUNTERS \
866 ENABLE_ASSERTIONS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100867 ENABLE_PIE \
868 ENABLE_PMF \
869 ENABLE_PSCI_STAT \
870 ENABLE_RUNTIME_INSTRUMENTATION \
871 ENABLE_SME_FOR_SWD \
872 ENABLE_SVE_FOR_SWD \
Boyan Karatotev8cef63d2025-01-07 11:26:56 +0000873 ENABLE_FEAT_GCIE \
Manish Pandey970a4a82023-10-10 13:53:25 +0100874 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +0100875 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100876 ERROR_DEPRECATED \
877 FAULT_INJECTION_SUPPORT \
878 GENERATE_COT \
879 GICV2_G0_FOR_EL3 \
880 HANDLE_EA_EL3_FIRST_NS \
Bipin Ravi538516f2023-09-28 13:17:24 -0500881 HARDEN_SLS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100882 HW_ASSISTED_COHERENCY \
883 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -0500884 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +0200885 DICE_PROTECTION_ENVIRONMENT \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -0700886 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -0500887 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100888 DRTM_SUPPORT \
889 NS_TIMER_SWITCH \
890 OVERRIDE_LIBC \
891 PL011_GENERIC_UART \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100892 PROGRAMMABLE_RESET_ADDRESS \
893 PSCI_EXTENDED_STATE_ID \
894 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +0100895 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100896 RESET_TO_BL31 \
897 SAVE_KEYS \
898 SEPARATE_CODE_AND_RODATA \
899 SEPARATE_BL2_NOLOAD_REGION \
900 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +0800901 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -0500902 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100903 SPIN_ON_BL1_EXIT \
904 SPM_MM \
905 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +0100906 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100907 SPMD_SPM_AT_SEL2 \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -0800908 ENABLE_SPMD_LP \
Raymond Mao3ba2c152023-07-25 07:53:35 -0700909 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100910 TRUSTED_BOARD_BOOT \
911 USE_COHERENT_MEM \
912 USE_DEBUGFS \
913 ARM_IO_IN_DTB \
914 SDEI_IN_FCONF \
915 SEC_INT_DESC_IN_FCONF \
916 USE_ROMLIB \
917 USE_TBBR_DEFS \
918 WARMBOOT_ENABLE_DCACHE_EARLY \
919 RESET_TO_BL2 \
920 BL2_IN_XIP_MEM \
921 BL2_INV_DCACHE \
922 USE_SPINLOCK_CAS \
923 ENCRYPT_BL31 \
924 ENCRYPT_BL32 \
925 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +0100926 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100927 RAS_TRAP_NS_ERR_REC_ACCESS \
928 COT_DESC_IN_DTB \
929 USE_SP804_TIMER \
930 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +0530931 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100932 ENABLE_MPMM \
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +0000933 FEAT_PABANDON \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100934 FEATURE_DETECTION \
Jayanth Dodderi Chidanand0b22e592022-10-11 17:16:07 +0100935 TRNG_SUPPORT \
Boyan Karatotev593ae352023-03-22 15:55:36 +0000936 ENABLE_ERRATA_ALL \
Sona Mathewffea3842022-11-18 18:05:38 -0600937 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -0500938 ERRATA_NON_ARM_INTERCONNECT \
Okash Khawaja04c73032022-11-04 12:38:01 +0000939 CONDITIONAL_CMO \
Manish V Badarkhe5782b892023-09-06 09:08:28 +0100940 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +0200941 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -0500942 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -0600943 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +0100944 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -0600945 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +0100946 HOB_LIST \
Manish V Badarkhecf48f492025-04-15 20:16:32 +0100947 LFA_SUPPORT \
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500948)))
Juan Castillo73c99d42015-08-18 14:23:04 +0100949
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100950# Numeric_Flags
Leonardo Sandoval327131c2020-09-10 12:18:27 -0500951$(eval $(call assert_numerics,\
952 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100953 ARM_ARCH_MAJOR \
954 ARM_ARCH_MINOR \
955 BRANCH_PROTECTION \
956 CTX_INCLUDE_PAUTH_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100957 CTX_INCLUDE_NEVE_REGS \
958 CRYPTO_SUPPORT \
Boyan Karatotev83a4dae2023-02-16 09:45:29 +0000959 DISABLE_MTPMU \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100960 ENABLE_BRBE_FOR_NS \
961 ENABLE_TRBE_FOR_NS \
962 ENABLE_BTI \
963 ENABLE_PAUTH \
John Powell025b1b82025-03-10 20:09:03 -0500964 ENABLE_FEAT_PAUTH_LR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100965 ENABLE_FEAT_AMU \
966 ENABLE_FEAT_AMUv1p1 \
967 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -0500968 ENABLE_FEAT_CSV2_3 \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -0500969 ENABLE_FEAT_DEBUGV8P9 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100970 ENABLE_FEAT_DIT \
971 ENABLE_FEAT_ECV \
972 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -0500973 ENABLE_FEAT_FGT2 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -0600974 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100975 ENABLE_FEAT_HCX \
Andre Przywara19d52a82024-08-09 17:04:22 +0100976 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +0000977 ENABLE_FEAT_MEC \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -0600978 ENABLE_FEAT_MOPS \
Govindraj Raja8e397882024-01-26 10:08:37 -0600979 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100980 ENABLE_FEAT_PAN \
981 ENABLE_FEAT_RNG \
982 ENABLE_FEAT_RNG_TRAP \
983 ENABLE_FEAT_SEL2 \
984 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +0100985 ENABLE_FEAT_THE \
Govindraj Raja0e4daed2024-01-23 16:03:53 -0600986 ENABLE_FEAT_SB \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100987 ENABLE_FEAT_S2PIE \
988 ENABLE_FEAT_S1PIE \
989 ENABLE_FEAT_S2POE \
990 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +0100991 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +0100992 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100993 ENABLE_FEAT_GCS \
994 ENABLE_FEAT_VHE \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -0500995 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +0100996 ENABLE_RME \
997 ENABLE_SPE_FOR_NS \
998 ENABLE_SYS_REG_TRACE_FOR_NS \
999 ENABLE_SME_FOR_NS \
1000 ENABLE_SME2_FOR_NS \
1001 ENABLE_SVE_FOR_NS \
1002 ENABLE_TRF_FOR_NS \
1003 FW_ENC_STATUS \
1004 NR_OF_FW_BANKS \
1005 NR_OF_IMAGES_IN_FW_BANK \
1006 TWED_DELAY \
1007 ENABLE_FEAT_TWED \
1008 SVE_VECTOR_LEN \
Varun Wadekar0ed3be62023-04-13 21:06:18 +01001009 IMPDEF_SYSREG_TRAP \
Boyan Karatotevee580c22025-04-11 14:27:55 +01001010 W \
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001011)))
Jeenu Viswambharanc877b412017-01-16 16:52:35 +00001012
Justin Chadwellaacff742019-07-29 17:13:10 +01001013ifdef KEY_SIZE
1014 $(eval $(call assert_numeric,KEY_SIZE))
1015endif
1016
Justin Chadwell1f461972019-08-20 11:01:52 +01001017ifeq ($(filter $(SANITIZE_UB), on off trap),)
1018 $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1019endif
1020
Juan Castillo73c99d42015-08-18 14:23:04 +01001021################################################################################
1022# Add definitions to the cpp preprocessor based on the current build options.
1023# This is done after including the platform specific makefile to allow the
1024# platform to overwrite the default options
1025################################################################################
1026
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001027$(eval $(call add_defines,\
1028 $(sort \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001029 ALLOW_RO_XLAT_TABLES \
1030 ARM_ARCH_MAJOR \
1031 ARM_ARCH_MINOR \
1032 BL2_ENABLE_SP_LOAD \
1033 COLD_BOOT_SINGLE_CPU \
1034 CTX_INCLUDE_AARCH32_REGS \
1035 CTX_INCLUDE_FPREGS \
Madhukar Pappireddy42422622024-06-17 15:17:03 -05001036 CTX_INCLUDE_SVE_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001037 CTX_INCLUDE_PAUTH_REGS \
Arvind Ram Prakash9acff282023-10-06 14:35:21 -05001038 CTX_INCLUDE_MPAM_REGS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001039 EL3_EXCEPTION_HANDLING \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001040 CTX_INCLUDE_EL2_REGS \
1041 CTX_INCLUDE_NEVE_REGS \
Boyan Karatotevee580c22025-04-11 14:27:55 +01001042 DEBUG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001043 DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1044 DISABLE_MTPMU \
1045 ENABLE_FEAT_AMU \
1046 ENABLE_AMU_AUXILIARY_COUNTERS \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001047 AMU_RESTRICT_COUNTERS \
1048 ENABLE_ASSERTIONS \
1049 ENABLE_BTI \
Arvind Ram Prakash83271d52024-05-22 15:24:00 -05001050 ENABLE_FEAT_DEBUGV8P9 \
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -05001051 ENABLE_FEAT_MPAM \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001052 ENABLE_PAUTH \
John Powell025b1b82025-03-10 20:09:03 -05001053 ENABLE_FEAT_PAUTH_LR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001054 ENABLE_PIE \
1055 ENABLE_PMF \
1056 ENABLE_PSCI_STAT \
1057 ENABLE_RME \
Raghu Krishnamurthy6a88ec82024-06-03 19:02:29 -07001058 RMMD_ENABLE_EL3_TOKEN_SIGN \
Sona Mathew2132c702025-03-14 01:27:11 -05001059 RMMD_ENABLE_IDE_KEY_PROG \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001060 ENABLE_RUNTIME_INSTRUMENTATION \
1061 ENABLE_SME_FOR_NS \
1062 ENABLE_SME2_FOR_NS \
1063 ENABLE_SME_FOR_SWD \
1064 ENABLE_SPE_FOR_NS \
1065 ENABLE_SVE_FOR_NS \
1066 ENABLE_SVE_FOR_SWD \
Manish Pandey970a4a82023-10-10 13:53:25 +01001067 ENABLE_FEAT_RAS \
Manish Pandeyf87e54f2023-10-10 15:42:19 +01001068 FFH_SUPPORT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001069 ENCRYPT_BL31 \
1070 ENCRYPT_BL32 \
1071 ERROR_DEPRECATED \
1072 FAULT_INJECTION_SUPPORT \
1073 GICV2_G0_FOR_EL3 \
1074 HANDLE_EA_EL3_FIRST_NS \
1075 HW_ASSISTED_COHERENCY \
1076 LOG_LEVEL \
1077 MEASURED_BOOT \
Abhi.Singh36e3d872024-08-28 14:17:52 -05001078 DISCRETE_TPM \
Tamas Bane7f11812023-06-07 13:35:04 +02001079 DICE_PROTECTION_ENVIRONMENT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001080 DRTM_SUPPORT \
1081 NS_TIMER_SWITCH \
1082 PL011_GENERIC_UART \
1083 PLAT_${PLAT} \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001084 PROGRAMMABLE_RESET_ADDRESS \
1085 PSCI_EXTENDED_STATE_ID \
1086 PSCI_OS_INIT_MODE \
Boyan Karatotev8db17052024-10-25 11:38:41 +01001087 ARCH_FEATURE_AVAILABILITY \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001088 RESET_TO_BL31 \
AlexeiFedorovd7660842024-05-13 15:35:54 +01001089 RME_GPT_BITLOCK_BLOCK \
AlexeiFedorovec0088b2024-03-13 17:07:03 +00001090 RME_GPT_MAX_BLOCK \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001091 SEPARATE_CODE_AND_RODATA \
1092 SEPARATE_BL2_NOLOAD_REGION \
1093 SEPARATE_NOBITS_REGION \
Ye Li86acbbe2022-08-26 13:48:31 +08001094 SEPARATE_RWDATA_REGION \
Madhukar Pappireddy308ebfa2024-06-17 15:26:00 -05001095 SEPARATE_SIMD_SECTION \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001096 RECLAIM_INIT_CODE \
1097 SPD_${SPD} \
1098 SPIN_ON_BL1_EXIT \
1099 SPM_MM \
1100 SPMC_AT_EL3 \
Nishant Sharma801cd3c2023-06-27 00:36:01 +01001101 SPMC_AT_EL3_SEL0_SP \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001102 SPMD_SPM_AT_SEL2 \
Raymond Mao3ba2c152023-07-25 07:53:35 -07001103 TRANSFER_LIST \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001104 TRUSTED_BOARD_BOOT \
1105 CRYPTO_SUPPORT \
1106 TRNG_SUPPORT \
1107 ERRATA_ABI_SUPPORT \
Sona Mathewef63f5b2023-03-14 14:02:03 -05001108 ERRATA_NON_ARM_INTERCONNECT \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001109 USE_COHERENT_MEM \
1110 USE_DEBUGFS \
1111 ARM_IO_IN_DTB \
1112 SDEI_IN_FCONF \
1113 SEC_INT_DESC_IN_FCONF \
1114 USE_ROMLIB \
1115 USE_TBBR_DEFS \
1116 WARMBOOT_ENABLE_DCACHE_EARLY \
1117 RESET_TO_BL2 \
1118 BL2_RUNS_AT_EL3 \
1119 BL2_IN_XIP_MEM \
1120 BL2_INV_DCACHE \
1121 USE_SPINLOCK_CAS \
1122 ERRATA_SPECULATIVE_AT \
Boyan Karatotev45c73282024-09-20 13:37:51 +01001123 ERRATA_SME_POWER_DOWN \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001124 RAS_TRAP_NS_ERR_REC_ACCESS \
1125 COT_DESC_IN_DTB \
1126 USE_SP804_TIMER \
1127 ENABLE_FEAT_RNG \
1128 ENABLE_FEAT_RNG_TRAP \
1129 ENABLE_FEAT_SB \
1130 ENABLE_FEAT_DIT \
1131 NR_OF_FW_BANKS \
1132 NR_OF_IMAGES_IN_FW_BANK \
1133 PSA_FWU_SUPPORT \
Sughosh Ganu11d05a72024-02-01 12:51:20 +05301134 PSA_FWU_METADATA_FW_STORE_DESC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001135 ENABLE_BRBE_FOR_NS \
1136 ENABLE_TRBE_FOR_NS \
1137 ENABLE_SYS_REG_TRACE_FOR_NS \
1138 ENABLE_TRF_FOR_NS \
1139 ENABLE_FEAT_HCX \
1140 ENABLE_MPMM \
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +00001141 FEAT_PABANDON \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001142 ENABLE_FEAT_FGT \
Arvind Ram Prakash33e6aaa2024-06-06 11:33:37 -05001143 ENABLE_FEAT_FGT2 \
Arvind Ram Prakasha57e18e2024-11-11 14:32:37 -06001144 ENABLE_FEAT_FPMR \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001145 ENABLE_FEAT_ECV \
1146 ENABLE_FEAT_AMUv1p1 \
1147 ENABLE_FEAT_SEL2 \
1148 ENABLE_FEAT_VHE \
1149 ENABLE_FEAT_CSV2_2 \
Sona Mathew30019d82023-10-25 16:48:19 -05001150 ENABLE_FEAT_CSV2_3 \
Andre Przywara19d52a82024-08-09 17:04:22 +01001151 ENABLE_FEAT_LS64_ACCDATA \
Tushar Khandelwal7e84f3c2024-03-15 15:00:29 +00001152 ENABLE_FEAT_MEC \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001153 ENABLE_FEAT_PAN \
1154 ENABLE_FEAT_TCR2 \
Jayanth Dodderi Chidanand6d0433f2024-09-05 22:24:04 +01001155 ENABLE_FEAT_THE \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001156 ENABLE_FEAT_S2PIE \
1157 ENABLE_FEAT_S1PIE \
1158 ENABLE_FEAT_S2POE \
1159 ENABLE_FEAT_S1POE \
Jayanth Dodderi Chidanand4ec4e542024-09-06 13:49:31 +01001160 ENABLE_FEAT_SCTLR2 \
Govindraj Raja30655132024-09-06 15:43:43 +01001161 ENABLE_FEAT_D128 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001162 ENABLE_FEAT_GCS \
Arvind Ram Prakash6b8df7b2025-01-09 17:18:30 -06001163 ENABLE_FEAT_MOPS \
Boyan Karatotev8cef63d2025-01-07 11:26:56 +00001164 ENABLE_FEAT_GCIE \
Govindraj Raja8e397882024-01-26 10:08:37 -06001165 ENABLE_FEAT_MTE2 \
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001166 FEATURE_DETECTION \
1167 TWED_DELAY \
1168 ENABLE_FEAT_TWED \
Okash Khawaja04c73032022-11-04 12:38:01 +00001169 CONDITIONAL_CMO \
Varun Wadekar0ed3be62023-04-13 21:06:18 +01001170 IMPDEF_SYSREG_TRAP \
Jayanth Dodderi Chidananda8cf6fa2023-04-26 15:57:30 +01001171 SVE_VECTOR_LEN \
Raghu Krishnamurthy890b5082023-02-25 13:26:10 -08001172 ENABLE_SPMD_LP \
Manish V Badarkhe5782b892023-09-06 09:08:28 +01001173 PSA_CRYPTO \
Sandrine Bailleux85bebe12023-10-11 08:38:00 +02001174 ENABLE_CONSOLE_GETC \
Arvind Ram Prakash183329a2023-08-15 16:28:06 -05001175 INIT_UNUSED_NS_EL2 \
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001176 PLATFORM_REPORT_CTX_MEM_USE \
Yann Gautierae770fe2024-01-16 19:39:31 +01001177 EARLY_CONSOLE \
Arvind Ram Prakashf99a69c2023-12-21 00:25:52 -06001178 PRESERVE_DSU_PMU_REGS \
Levi Yun89535682024-05-13 10:24:31 +01001179 HOB_LIST \
Manish V Badarkhecf48f492025-04-15 20:16:32 +01001180 LFA_SUPPORT \
Leonardo Sandoval327131c2020-09-10 12:18:27 -05001181)))
Jeenu Viswambharan2fae4b12016-10-24 14:31:51 +01001182
Juan Pablo Condebfef8b92023-11-08 16:14:28 -06001183ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1184ifeq (${DEBUG}, 0)
1185 $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1186 override PLATFORM_REPORT_CTX_MEM_USE := 0
1187endif
1188endif
1189
Justin Chadwell1f461972019-08-20 11:01:52 +01001190ifeq (${SANITIZE_UB},trap)
1191 $(eval $(call add_define,MONITOR_TRAPS))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001192endif #(SANITIZE_UB)
Justin Chadwell1f461972019-08-20 11:01:52 +01001193
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001194# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1195ifdef EL3_PAYLOAD_BASE
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001196 $(eval $(call add_define,EL3_PAYLOAD_BASE))
1197else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001198# Define the PRELOADED_BL33_BASE flag only if it is provided and
1199# EL3_PAYLOAD_BASE is not defined, as it has priority.
1200 ifdef PRELOADED_BL33_BASE
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01001201 $(eval $(call add_define,PRELOADED_BL33_BASE))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001202 endif
1203endif #(EL3_PAYLOAD_BASE)
Juan Castillo73c99d42015-08-18 14:23:04 +01001204
Soby Mathew209a60c2018-03-26 12:43:37 +01001205# Define the DYN_DISABLE_AUTH flag only if set.
1206ifeq (${DYN_DISABLE_AUTH},1)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001207 $(eval $(call add_define,DYN_DISABLE_AUTH))
Soby Mathew209a60c2018-03-26 12:43:37 +01001208endif
1209
Chris Kay8620bd02023-12-04 09:55:50 +00001210ifeq ($($(ARCH)-ld-id),arm-link)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001211 $(eval $(call add_define,USE_ARM_LINK))
Varun Wadekarc2ad38c2019-01-11 14:47:48 -08001212endif
1213
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001214# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001215ifeq (${SPD},spmd)
Olivier Deprezc33ff192020-03-19 09:27:11 +01001216ifdef SP_LAYOUT_FILE
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001217 -include $(BUILD_PLAT)/sp_gen.mk
1218 FIP_DEPS += sp
1219 CRT_DEPS += sp
1220 NEED_SP_PKG := yes
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001221else
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001222 ifeq (${SPMD_SPM_AT_SEL2},1)
1223 $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1224 endif
1225endif #(SP_LAYOUT_FILE)
1226endif #(SPD)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001227
Juan Castillo73c99d42015-08-18 14:23:04 +01001228################################################################################
Juan Castillo73c99d42015-08-18 14:23:04 +01001229# Build targets
1230################################################################################
1231
Harrison Mutai2329e222024-08-28 13:27:19 +00001232.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 +01001233
1234all: msg_start
1235
1236msg_start:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001237 $(s)echo "Building ${PLAT}"
Juan Castillo73c99d42015-08-18 14:23:04 +01001238
Soby Mathew7a24cba2015-10-26 14:29:21 +00001239ifeq (${ERROR_DEPRECATED},0)
Julius Wernerd5dfdeb2019-07-09 13:49:11 -07001240# Check if deprecated declarations and cpp warnings should be treated as error or not.
Chris Kay8620bd02023-12-04 09:55:50 +00001241ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
Varun Wadekarc2ad38c2019-01-11 14:47:48 -08001242 CPPFLAGS += -Wno-error=deprecated-declarations
1243else
Dan Handleybc1a03c2018-02-27 16:03:58 +00001244 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp
Soby Mathew7a24cba2015-10-26 14:29:21 +00001245endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001246endif #(!ERROR_DEPRECATED)
Soby Mathew7a24cba2015-10-26 14:29:21 +00001247
Roberto Vargas61f72a32018-05-08 10:27:10 +01001248$(eval $(call MAKE_LIB,c))
Roberto Vargas5fee0282018-05-08 10:27:10 +01001249
Juan Castillo73c99d42015-08-18 14:23:04 +01001250# Expand build macros for the different images
1251ifeq (${NEED_BL1},yes)
Chris Kayb34635a2021-09-28 15:44:19 +01001252BL1_SOURCES := $(sort ${BL1_SOURCES})
Zelalem Aweke434d0492021-07-11 17:25:48 -05001253$(eval $(call MAKE_BL,bl1))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001254endif #(NEED_BL1)
Juan Castillo73c99d42015-08-18 14:23:04 +01001255
1256ifeq (${NEED_BL2},yes)
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001257
Arvind Ram Prakash42d4d3b2022-11-22 14:41:00 -06001258ifeq (${RESET_TO_BL2}, 0)
Roberto Vargasc9b31ae2018-01-02 11:23:41 +00001259FIP_BL2_ARGS := tb-fw
1260endif
1261
Chris Kayeb1acfb2021-09-28 15:44:37 +01001262BL2_SOURCES := $(sort ${BL2_SOURCES})
1263
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001264$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001265 $(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001266
1267endif #(NEED_BL2)
Juan Castillo73c99d42015-08-18 14:23:04 +01001268
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001269ifeq (${NEED_SCP_BL2},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001270$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001271endif #(NEED_SCP_BL2)
Masahiro Yamada4d045d02017-04-05 19:11:41 +09001272
Juan Castillo73c99d42015-08-18 14:23:04 +01001273ifeq (${NEED_BL31},yes)
1274BL31_SOURCES += ${SPD_SOURCES}
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001275# Sort BL31 source files to remove duplicates
1276BL31_SOURCES := $(sort ${BL31_SOURCES})
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301277ifneq (${DECRYPTION_SUPPORT},none)
1278$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001279 $(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301280else
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001281$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001282 $(eval $(call MAKE_BL,bl31,soc-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001283endif #(DECRYPTION_SUPPORT)
1284endif #(NEED_BL31)
Juan Castillo73c99d42015-08-18 14:23:04 +01001285
Juan Castillo70d1fc52015-11-12 10:59:26 +00001286# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
Masahiro Yamadac939d132018-01-26 11:42:01 +09001287# build system will call TOOL_ADD_IMG to print a warning message and abort the
Juan Castillo70d1fc52015-11-12 10:59:26 +00001288# process. Note that the dependency on BL32 applies to the FIP only.
Juan Castillo73c99d42015-08-18 14:23:04 +01001289ifeq (${NEED_BL32},yes)
Madhukar Pappireddy26d1e0c2020-01-27 13:37:51 -06001290# Sort BL32 source files to remove duplicates
1291BL32_SOURCES := $(sort ${BL32_SOURCES})
Masahiro Yamada9cd15232018-01-26 11:42:01 +09001292BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1293
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301294ifneq (${DECRYPTION_SUPPORT},none)
Zelalem Aweke434d0492021-07-11 17:25:48 -05001295$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
Sumit Gargc6ba9b42019-11-14 16:33:45 +05301296 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1297else
Zelalem Aweke434d0492021-07-11 17:25:48 -05001298$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001299 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001300endif #(DECRYPTION_SUPPORT)
1301endif #(NEED_BL32)
Juan Castillo73c99d42015-08-18 14:23:04 +01001302
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001303# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1304# needs to be built from RMM_SOURCES.
1305ifeq (${NEED_RMM},yes)
1306# Sort RMM source files to remove duplicates
1307RMM_SOURCES := $(sort ${RMM_SOURCES})
1308BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1309
1310$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001311 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1312endif #(NEED_RMM)
Zelalem Aweke5b18de02021-07-11 18:33:20 -05001313
Juan Castillo73c99d42015-08-18 14:23:04 +01001314# Add the BL33 image if required by the platform
1315ifeq (${NEED_BL33},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001316$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001317endif #(NEED_BL33)
Juan Castillodb6071c2015-01-13 12:21:04 +00001318
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001319ifeq (${NEED_BL2U},yes)
Masahiro Yamada33950dd2018-01-26 11:42:01 +09001320$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
Zelalem Aweke434d0492021-07-11 17:25:48 -05001321 $(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001322endif #(NEED_BL2U)
Yatharth Kochar9003fa02015-10-14 15:27:24 +01001323
Nishanth Menon03b397a2016-10-14 01:13:57 +00001324# Expand build macros for the different images
1325ifeq (${NEED_FDT},yes)
Soby Mathew38c14d82017-12-14 17:44:56 +00001326 $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
Salman Nabi1c08ff32024-12-12 17:38:54 +00001327
1328 ifneq (${INITRD_SIZE}${INITRD_PATH},)
1329 ifndef INITRD_BASE
1330 $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1331 endif
1332
1333 INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1334 initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1335
1336 define $(HW_CONFIG)-after +=
1337 $(s)echo " INITRD $(HW_CONFIG)"
1338 $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1339 $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1340 endef
1341 endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001342endif #(NEED_FDT)
Nishanth Menon03b397a2016-10-14 01:13:57 +00001343
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001344# Add Secure Partition packages
1345ifeq (${NEED_SP_PKG},yes)
Chris Kayfd74ca02024-07-30 13:33:56 +00001346$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
Chris Kay679e27c2025-03-19 15:04:47 +00001347 $(if $(host-poetry),$(q)poetry -q install --no-root)
Kathleen Capelladd816232025-02-13 17:34:21 -06001348 $(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
J-Alves822c7272022-03-22 16:28:51 +00001349sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001350 $(s)echo
1351 $(s)echo "Built SP Images successfully"
1352 $(s)echo
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001353endif #(NEED_SP_PKG)
Manish Pandeyce2b1ec2020-01-14 11:52:05 +00001354
Ian Spray36eaaf32014-01-30 17:25:28 +00001355locate-checkpatch:
1356ifndef CHECKPATCH
Etienne Carriere66079b02017-08-23 15:44:01 +02001357 $(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 +00001358else
1359ifeq (,$(wildcard ${CHECKPATCH}))
Etienne Carriere66079b02017-08-23 15:44:01 +02001360 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
Ian Spray36eaaf32014-01-30 17:25:28 +00001361endif
Jayanth Dodderi Chidanandc5e1da82023-04-24 15:57:05 +01001362endif #(CHECKPATCH)
Ian Spray36eaaf32014-01-30 17:25:28 +00001363
Achin Gupta4f6ad662013-10-25 09:08:21 +01001364clean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001365 $(s)echo " CLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001366 $(q)rm -rf $(BUILD_PLAT)
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +01001367 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1368 $(q)rm -rf ${FIPTOOLPATH}/fiptool
Boyan Karatotevf4595e62025-05-06 17:11:29 +01001369 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1370 $(q)rm -rf ${CRTTOOLPATH}/cert_create
Boyan Karatotev96fbe882025-05-02 16:40:40 +01001371 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001372 $(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
Achin Gupta4f6ad662013-10-25 09:08:21 +01001373
James Morrisseyeaaeece2013-11-01 13:56:59 +00001374realclean distclean:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001375 $(s)echo " REALCLEAN"
Chris Kayc3273702025-01-13 15:57:32 +00001376 $(q)rm -rf $(BUILD_BASE)
1377 $(q)rm -rf $(CURDIR)/cscope.*
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +01001378 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1379 $(q)rm -rf ${FIPTOOLPATH}/fiptool
Boyan Karatotevf4595e62025-05-06 17:11:29 +01001380 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1381 $(q)rm -rf ${CRTTOOLPATH}/cert_create
Boyan Karatotev96fbe882025-05-02 16:40:40 +01001382 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001383 $(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
Boyan Karatotevf4595e62025-05-06 17:11:29 +01001421 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1422 $(q)ln -sf ${CRTTOOL} ${CRTTOOLPATH}/cert_create
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001423 $(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
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +01001465# symlink for compatibility before tools were in the build directory
Pali Rohára9812202020-11-24 15:38:08 +01001466${FIPTOOL}: FORCE
Boyan Karatotevcbd6cec2025-05-02 15:08:24 +01001467 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1468 $(q)ln -sf ${FIPTOOL} ${FIPTOOLPATH}/fiptool
Harry Liebelf58ad362014-01-10 18:00:33 +00001469
Manish V Badarkhee4a070e2024-12-03 21:46:51 +00001470$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB)
1471 $(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 +01001472
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001473memmap: all
Chris Kayc25405d2025-03-10 09:24:34 +00001474 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kay8daebef2025-04-15 14:00:50 +01001475 $(q)$(if $(host-poetry),poetry run )memory symbols --root ${BUILD_PLAT}
Louis Mayencourtcfe83912019-10-16 14:30:51 +01001476
Harrison Mutai2329e222024-08-28 13:27:19 +00001477tl: ${BUILD_PLAT}/tl.bin
1478${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
Chris Kayc25405d2025-03-10 09:24:34 +00001479 $(if $(host-poetry),$(q)poetry -q install --no-root)
Chris Kayd2867392024-09-26 14:18:04 +00001480 $(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
Harrison Mutai2329e222024-08-28 13:27:19 +00001481
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001482doc:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001483 $(s)echo " BUILD DOCUMENTATION"
Harrison Mutaic61c9a32025-05-15 08:47:34 +00001484 $(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1485 $(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} html
Madhukar Pappireddy6de32372020-01-28 12:41:20 -06001486
Sumit Garg90aa9012019-11-11 18:46:36 +05301487enctool: ${ENCTOOL}
1488
Pali Rohára9812202020-11-24 15:38:08 +01001489${ENCTOOL}: FORCE
Boyan Karatotev96fbe882025-05-02 16:40:40 +01001490 $(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001491 $(s)echo
1492 $(s)echo "Built $@ successfully"
1493 $(s)echo
Sumit Garg90aa9012019-11-11 18:46:36 +05301494
Joakim Bech35fab8c2014-01-23 14:51:49 +01001495cscope:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001496 $(s)echo " CSCOPE"
1497 $(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1498 $(q)cscope -b -q -k
Joakim Bech35fab8c2014-01-23 14:51:49 +01001499
Ryan Harkin72ee3312014-01-15 16:55:07 +00001500help:
Chris Kay7c4e1ee2024-05-02 17:52:37 +00001501 $(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1502 $(s)echo ""
1503 $(s)echo "PLAT is used to specify which platform you wish to build."
1504 $(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1505 $(s)echo ""
1506 $(s)echo "platform = ${PLATFORM_LIST}"
1507 $(s)echo ""
1508 $(s)echo "Please refer to the User Guide for a list of all supported options."
1509 $(s)echo "Note that the build system doesn't track dependencies for build "
1510 $(s)echo "options. Therefore, if any of the build options are changed "
1511 $(s)echo "from a previous build, a clean build must be performed."
1512 $(s)echo ""
1513 $(s)echo "Supported Targets:"
1514 $(s)echo " all Build all individual bootloader binaries"
1515 $(s)echo " bl1 Build the BL1 binary"
1516 $(s)echo " bl2 Build the BL2 binary"
1517 $(s)echo " bl2u Build the BL2U binary"
1518 $(s)echo " bl31 Build the BL31 binary"
1519 $(s)echo " bl32 Build the BL32 binary. If ARCH=aarch32, then "
1520 $(s)echo " this builds secure payload specified by AARCH32_SP"
1521 $(s)echo " certificates Build the certificates (requires 'GENERATE_COT=1')"
1522 $(s)echo " fip Build the Firmware Image Package (FIP)"
1523 $(s)echo " fwu_fip Build the FWU Firmware Image Package (FIP)"
1524 $(s)echo " checkcodebase Check the coding style of the entire source tree"
1525 $(s)echo " checkpatch Check the coding style on changes in the current"
1526 $(s)echo " branch against BASE_COMMIT (default origin/master)"
1527 $(s)echo " clean Clean the build for the selected platform"
1528 $(s)echo " cscope Generate cscope index"
1529 $(s)echo " distclean Remove all build artifacts for all platforms"
1530 $(s)echo " certtool Build the Certificate generation tool"
1531 $(s)echo " enctool Build the Firmware encryption tool"
1532 $(s)echo " fiptool Build the Firmware Image Package (FIP) creation tool"
1533 $(s)echo " sp Build the Secure Partition Packages"
1534 $(s)echo " sptool Build the Secure Partition Package creation tool"
1535 $(s)echo " dtbs Build the Device Tree Blobs (if required for the platform)"
1536 $(s)echo " memmap Print the memory map of the built binaries"
1537 $(s)echo " doc Build html based documentation using Sphinx tool"
1538 $(s)echo ""
1539 $(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1540 $(s)echo ""
1541 $(s)echo "example: build all targets for the FVP platform:"
1542 $(s)echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
Pali Rohára9812202020-11-24 15:38:08 +01001543
1544.PHONY: FORCE
1545FORCE:;