xref: /rk3399_ARM-atf/Makefile (revision 1dd3b6565da16dda3d4aa33a41b552816b7539f2)
1#
2# Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7#
8# Trusted Firmware Version
9#
10VERSION_MAJOR			:= 2
11VERSION_MINOR			:= 13
12# VERSION_PATCH is only used for LTS releases
13VERSION_PATCH			:= 0
14VERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
15
16# Default goal is build all images
17.DEFAULT_GOAL			:= all
18
19# 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
24MAKE_HELPERS_DIRECTORY := make_helpers/
25include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
26include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
27include ${MAKE_HELPERS_DIRECTORY}common.mk
28
29################################################################################
30# Default values for build configurations, and their dependencies
31################################################################################
32
33include ${MAKE_HELPERS_DIRECTORY}defaults.mk
34PLAT				:= ${DEFAULT_PLAT}
35include ${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
41
42################################################################################
43# Configure the toolchains used to build TF-A and its tools
44################################################################################
45
46include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
47
48# Assertions enabled for DEBUG builds by default
49ENABLE_ASSERTIONS		:= ${DEBUG}
50ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
51
52################################################################################
53# Checkpatch script options
54################################################################################
55
56CHECKCODE_ARGS		:=	--no-patch
57# Do not check the coding style on imported library files or documentation files
58INC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
59					include/drivers/arm,		\
60					$(wildcard include/drivers/*)))
61INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
62					include/lib/libfdt		\
63					include/lib/libc,		\
64					$(wildcard include/lib/*)))
65INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
66					include/lib			\
67					include/drivers,		\
68					$(wildcard include/*)))
69LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
70					lib/compiler-rt			\
71					lib/libfdt%			\
72					lib/libc,			\
73					lib/zlib			\
74					$(wildcard lib/*)))
75ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
76					lib				\
77					include				\
78					docs				\
79					%.rst,				\
80					$(wildcard *)))
81CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
82				${INC_DIRS_TO_CHECK}			\
83				${INC_LIB_DIRS_TO_CHECK}		\
84				${LIB_DIRS_TO_CHECK}			\
85				${INC_DRV_DIRS_TO_CHECK}		\
86				${INC_ARM_DIRS_TO_CHECK}
87
88################################################################################
89# Process build options
90################################################################################
91
92ifeq ($(verbose),)
93	CHECKCODE_ARGS	+=	--no-summary --terse
94endif
95
96################################################################################
97# Auxiliary tools (fiptool, cert_create, etc)
98################################################################################
99
100# Variables for use with Certificate Generation Tool
101CRTTOOLPATH		?=	tools/cert_create
102CRTTOOL			?=	${BUILD_PLAT}/${CRTTOOLPATH}/cert_create$(.exe)
103
104# Variables for use with Firmware Encryption Tool
105ENCTOOLPATH		?=	tools/encrypt_fw
106ENCTOOL			?=	${BUILD_PLAT}/${ENCTOOLPATH}/encrypt_fw$(.exe)
107
108# Variables for use with Firmware Image Package
109FIPTOOLPATH		?=	tools/fiptool
110FIPTOOL			?=	${BUILD_PLAT}/${FIPTOOLPATH}/fiptool$(.exe)
111
112# Variables for use with sptool
113SPTOOLPATH		?=	tools/sptool
114SPTOOL			?=	${SPTOOLPATH}/sptool.py
115SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
116SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
117
118# Variables for use with sptool
119TLCTOOL 		?=	poetry run tlc
120
121# 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################################################################################
131# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
132################################################################################
133ifeq (${ARM_ARCH_MAJOR},7)
134	target32-directive	= 	-target arm-none-eabi
135# Will set march-directive from platform configuration
136else
137	target32-directive	= 	-target armv8a-none-eabi
138endif #(ARM_ARCH_MAJOR)
139
140ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
141	ifeq ($($(ARCH)-cc-id),arm-clang)
142		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
143		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
144	else
145		TF_CFLAGS_aarch32	=	$(target32-directive)
146		TF_CFLAGS_aarch64	:=	-target aarch64-unknown-none-elf
147	endif
148
149else ifeq ($($(ARCH)-cc-id),gnu-gcc)
150	# Enable LTO only for aarch64
151	ifeq (${ARCH},aarch64)
152		LTO_CFLAGS	=	$(if $(filter-out 0,$(ENABLE_LTO)),-flto)
153	endif
154endif #(clang)
155
156# Process Debug flag
157ifneq (${DEBUG}, 0)
158	BUILD_TYPE	:=	debug
159	TF_CFLAGS	+=	-g -gdwarf-4
160	ASFLAGS		+=	-g -Wa,-gdwarf-4
161
162	# Use LOG_LEVEL_INFO by default for debug builds
163	LOG_LEVEL	:=	40
164else
165	BUILD_TYPE	:=	release
166	# Use LOG_LEVEL_NOTICE by default for release builds
167	LOG_LEVEL	:=	20
168endif #(Debug)
169
170# Default build string (git branch and commit)
171ifeq (${BUILD_STRING},)
172	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
173endif
174VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
175
176ifeq (${AARCH32_INSTRUCTION_SET},A32)
177	TF_CFLAGS_aarch32	+=	-marm
178else ifeq (${AARCH32_INSTRUCTION_SET},T32)
179	TF_CFLAGS_aarch32	+=	-mthumb
180endif #(AARCH32_INSTRUCTION_SET)
181
182TF_CFLAGS_aarch32	+=	-mno-unaligned-access
183TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
184
185##############################################################################
186# WARNINGS Configuration
187###############################################################################
188# General warnings
189WARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
190				-Wdisabled-optimization -Wvla -Wshadow	\
191				-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
199
200# Additional warnings
201# Level 1 - infrequent warnings we should have none of
202# full -Wextra
203WARNING1 += -Wsign-compare
204WARNING1 += -Wtype-limits
205WARNING1 += -Wmissing-field-initializers
206
207# 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
215# currently very involved and many platforms set this off
216WARNING2 += -Wunused-const-variable=2
217
218# Level 3 - very pedantic, frequently ignored
219WARNING3 := -Wbad-function-cast
220WARNING3 += -Waggregate-return
221WARNING3 += -Wnested-externs
222WARNING3 += -Wcast-align
223WARNING3 += -Wcast-qual
224WARNING3 += -Wconversion
225WARNING3 += -Wpacked
226WARNING3 += -Wpointer-arith
227WARNING3 += -Wswitch-default
228
229# 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
233	ifneq (${W},0)
234		E	 ?= 0
235	endif
236endif
237
238ifeq (${W},1)
239	WARNINGS += $(WARNING1)
240else ifeq (${W},2)
241	WARNINGS += $(WARNING1) $(WARNING2)
242else ifeq (${W},3)
243	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
244endif #(W)
245
246# Compiler specific warnings
247ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
248# not using clang
249WARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
250				-Wpacked-bitfield-compat -Wshift-overflow=2 \
251				-Wlogical-op
252
253# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
254TF_CFLAGS_MIN_PAGE_SIZE	:=	$(call cc_option, --param=min-pagesize=0)
255TF_CFLAGS		+=	$(TF_CFLAGS_MIN_PAGE_SIZE)
256
257ifeq ($(HARDEN_SLS), 1)
258        TF_CFLAGS_MHARDEN_SLS	:=      $(call cc_option, -mharden-sls=all)
259        TF_CFLAGS_aarch64	+=      $(TF_CFLAGS_MHARDEN_SLS)
260endif
261
262else
263# using clang
264WARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
265				-Wlogical-op-parentheses
266endif #(Clang Warning)
267
268ifneq (${E},0)
269	ERRORS := -Werror
270endif #(E)
271
272################################################################################
273# Compiler and Linker Directives
274################################################################################
275CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
276				$(ERRORS) $(WARNINGS)
277ASFLAGS			+=	$(CPPFLAGS)                 			\
278				-ffreestanding -Wa,--fatal-warnings
279TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
280				-ffunction-sections -fdata-sections		\
281				-ffreestanding -fno-common			\
282				-Os -std=gnu99
283
284ifeq (${SANITIZE_UB},on)
285	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
286endif #(${SANITIZE_UB},on)
287
288ifeq (${SANITIZE_UB},trap)
289	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
290				-fsanitize-undefined-trap-on-error
291endif #(${SANITIZE_UB},trap)
292
293GCC_V_OUTPUT		:=	$(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
294
295TF_LDFLAGS		+=	-z noexecstack
296
297# LD = armlink
298ifeq ($($(ARCH)-ld-id),arm-link)
299	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
300	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
301	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
302
303# LD = gcc (used when GCC LTO is enabled)
304else ifeq ($($(ARCH)-ld-id),gnu-gcc)
305	# Pass ld options with Wl or Xlinker switches
306	TF_LDFLAGS		+=	$(call ld_option,-Xlinker --no-warn-rwx-segments)
307	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
308	TF_LDFLAGS		+=	-Wl,--gc-sections
309
310	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
311	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
312	TF_LDFLAGS		+=	-Wl,--build-id=none
313
314	ifeq ($(ENABLE_LTO),1)
315		ifeq (${ARCH},aarch64)
316			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
317			TF_LDFLAGS      +=	-flto-partition=one
318		endif
319	endif #(ENABLE_LTO)
320
321# 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
323	ifeq (${ARCH},aarch64)
324		ifneq (${ERRATA_A53_843419},1)
325			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
326		endif
327	endif
328	TF_LDFLAGS		+= 	-nostdlib
329	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
330
331# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
332else
333# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
334# are not loaded by a elf loader.
335	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
336	TF_LDFLAGS		+=	-O1
337	TF_LDFLAGS		+=	--gc-sections
338
339	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
340	TF_LDFLAGS		+=	-z max-page-size=4096
341	TF_LDFLAGS		+=	--build-id=none
342
343# ld.lld doesn't recognize the errata flags,
344# 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.
347	ifneq ($($(ARCH)-ld-id),llvm-lld)
348		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
349	endif
350
351endif #(LD = armlink)
352
353################################################################################
354# Setup ARCH_MAJOR/MINOR before parsing arch_features.
355################################################################################
356ifeq (${ENABLE_RME},1)
357	ARM_ARCH_MAJOR := 9
358	ARM_ARCH_MINOR := 2
359endif
360
361################################################################################
362# Common sources and include directories
363################################################################################
364include lib/compiler-rt/compiler-rt.mk
365
366# 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
375BL_COMMON_SOURCES	+=	common/bl_common.c			\
376				common/tf_log.c				\
377				common/${ARCH}/debug.S			\
378				drivers/console/multi_console.c		\
379				lib/${ARCH}/cache_helpers.S		\
380				lib/${ARCH}/misc_helpers.S		\
381				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
382				plat/common/plat_bl_common.c		\
383				plat/common/plat_log_common.c		\
384				plat/common/${ARCH}/plat_common.c	\
385				plat/common/${ARCH}/platform_helpers.S	\
386				${COMPILER_RT_SRCS}
387
388ifeq ($($(ARCH)-cc-id),arm-clang)
389	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
390endif
391
392ifeq (${SANITIZE_UB},on)
393	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
394endif
395
396INCLUDES		+=	-Iinclude				\
397				-Iinclude/arch/${ARCH}			\
398				-Iinclude/lib/cpus/${ARCH}		\
399				-Iinclude/lib/el3_runtime/${ARCH}	\
400				${PLAT_INCLUDES}			\
401				${SPD_INCLUDES}
402
403DTC_FLAGS		+=	-I dts -O dtb
404DTC_CPPFLAGS		+=	-P -nostdinc $(INCLUDES) -Ifdts -undef \
405				-x assembler-with-cpp $(DEFINES)
406
407include common/backtrace/backtrace.mk
408
409################################################################################
410# Generic definitions
411################################################################################
412
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)
428	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
434		endif
435
436		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
437			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
438		endif
439
440		ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
441			DTC_CPPFLAGS	+=	-DTRUSTY_SP_FW_CONFIG
442		endif
443
444		ifeq ($(TS_SP_FW_CONFIG),1)
445			DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
446		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
480################################################################################
481# 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################################################################################
487# 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################################################################################
493# 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
518else ifeq (${BRANCH_PROTECTION},5)
519	# Turn on branch target identification mechanism
520	BP_OPTION := standard
521	ENABLE_BTI := 2
522	ENABLE_PAUTH := 2
523else
524        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
525endif #(BRANCH_PROTECTION)
526
527ifneq ($(ENABLE_PAUTH),0)
528	CTX_INCLUDE_PAUTH_REGS	:= ${ENABLE_PAUTH}
529endif
530ifneq (${BP_OPTION},none)
531	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
532endif #(BP_OPTION)
533
534# Pointer Authentication sources
535ifneq (${ENABLE_PAUTH},0)
536# 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
538	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth.c
539endif
540#
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
550
551################################################################################
552# RME dependent flags configuration, Enable optional features for RME.
553################################################################################
554# FEAT_RME
555ifeq (${ENABLE_RME},1)
556	# 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
561	ifneq ($(ENABLE_FEAT_MPAM), 0)
562		CTX_INCLUDE_MPAM_REGS := 1
563	endif
564
565	# RME enables CSV2_2 extension by default.
566	ENABLE_FEAT_CSV2_2 = 1
567endif #(FEAT_RME)
568
569################################################################################
570# Include rmmd Makefile if RME is enabled
571################################################################################
572ifneq (${ENABLE_RME},0)
573include services/std_svc/rmmd/rmmd.mk
574$(warning "RME is an experimental feature")
575endif
576
577################################################################################
578# 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################################################################################
585# 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
590TF_CFLAGS	+=	$(march-directive)
591ASFLAGS		+=	$(march-directive)
592
593# 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
600	ifeq (${ENABLE_RME},1)
601                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
602                supported at the moment.)
603	endif
604else ifeq (${ENABLE_RME},1)
605	BL2_RUNS_AT_EL3	:=	1
606else
607	BL2_RUNS_AT_EL3	:=	0
608endif
609
610# 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
618ifeq (${ARM_ARCH_MAJOR},7)
619include make_helpers/armv7-a-cpus.mk
620endif
621
622PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
623ifneq ($(PIE_FOUND),)
624	TF_CFLAGS	+=	-fno-PIE
625ifeq ($($(ARCH)-ld-id),gnu-gcc)
626	TF_LDFLAGS	+=	-no-pie
627endif
628endif #(PIE_FOUND)
629
630ifeq ($($(ARCH)-ld-id),gnu-gcc)
631	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
632else
633	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
634endif
635
636ifeq ($(ENABLE_PIE),1)
637	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)
644	BL31_CPPFLAGS	+=	-fpie
645	BL31_CFLAGS 	+=	-fpie
646	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
647
648	BL32_CPPFLAGS	+=	-fpie
649	BL32_CFLAGS	+=	-fpie
650	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
651endif #(ENABLE_PIE)
652
653BL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
654BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
655BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
656
657BL1_CPPFLAGS += -DIMAGE_AT_EL3
658ifeq ($(RESET_TO_BL2),1)
659	BL2_CPPFLAGS += -DIMAGE_AT_EL3
660else
661	BL2_CPPFLAGS += -DIMAGE_AT_EL1
662endif #(RESET_TO_BL2)
663
664ifeq (${ARCH},aarch64)
665	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
666	BL31_CPPFLAGS += -DIMAGE_AT_EL3
667	BL32_CPPFLAGS += -DIMAGE_AT_EL1
668else
669	BL32_CPPFLAGS += -DIMAGE_AT_EL3
670endif
671
672# 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.
675include lib/cpus/cpu-ops.mk
676
677################################################################################
678# Build `AARCH32_SP` as BL32 image for AArch32
679################################################################################
680ifeq (${ARCH},aarch32)
681        NEED_BL32 := yes
682
683        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)
686
687                ifeq (${AARCH32_SP_MAKE},)
688                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
689                endif
690                $(info Including ${AARCH32_SP_MAKE})
691                include ${AARCH32_SP_MAKE}
692        endif
693endif #(ARCH=aarch32)
694
695################################################################################
696# Include libc if not overridden
697################################################################################
698ifeq (${OVERRIDE_LIBC},0)
699include lib/libc/libc.mk
700endif
701
702ifneq (${USE_GIC_DRIVER},0)
703include drivers/arm/gic/gic.mk
704endif
705
706################################################################################
707# Check incompatible options and dependencies
708################################################################################
709include ${MAKE_HELPERS_DIRECTORY}constraints.mk
710
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
716endif
717
718ifneq (${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
726ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
727# Support authentication verification and hash calculation
728	CRYPTO_SUPPORT := 3
729else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
730# Support authentication verification and hash calculation
731	CRYPTO_SUPPORT := 3
732else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
733# Support hash calculation only
734	CRYPTO_SUPPORT := 2
735else ifeq (${TRUSTED_BOARD_BOOT},1)
736# Support authentication verification only
737	CRYPTO_SUPPORT := 1
738else
739	CRYPTO_SUPPORT := 0
740endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
741
742ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
743CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
744endif
745
746################################################################################
747# Process platform overrideable behaviour
748################################################################################
749
750ifdef BL1_SOURCES
751	NEED_BL1 := yes
752endif #(BL1_SOURCES)
753
754ifdef BL2_SOURCES
755	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
760		# 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)
773
774ifdef BL2U_SOURCES
775	NEED_BL2U := yes
776endif #(BL2U_SOURCES)
777
778# If SCP_BL2 is given, we always want FIP to include it.
779ifdef SCP_BL2
780	NEED_SCP_BL2		:=	yes
781endif #(SCP_BL2)
782
783# For AArch32, BL31 is not currently supported.
784ifneq (${ARCH},aarch32)
785	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)
793
794# Process TBB related flags
795ifneq (${GENERATE_COT},0)
796	# Common cert_create options
797	ifneq (${CREATE_KEYS},0)
798                $(eval CRT_ARGS += -n)
799                $(eval FWU_CRT_ARGS += -n)
800		ifneq (${SAVE_KEYS},0)
801                        $(eval CRT_ARGS += -k)
802                        $(eval FWU_CRT_ARGS += -k)
803		endif
804	endif
805	# Include TBBR makefile (unless the platform indicates otherwise)
806	ifeq (${INCLUDE_TBBR_MK},1)
807                include make_helpers/tbbr/tbbr_tools.mk
808	endif
809endif #(GENERATE_COT)
810
811ifneq (${FIP_ALIGN},0)
812	FIP_ARGS += --align ${FIP_ALIGN}
813endif #(FIP_ALIGN)
814
815ifdef FDT_SOURCES
816	NEED_FDT := yes
817endif #(FDT_SOURCES)
818
819################################################################################
820# Include libraries' Makefile that are used in all BL
821################################################################################
822
823include lib/stack_protector/stack_protector.mk
824
825################################################################################
826# Include BL specific makefiles
827################################################################################
828
829ifeq (${NEED_BL1},yes)
830include bl1/bl1.mk
831endif
832
833ifeq (${NEED_BL2},yes)
834include bl2/bl2.mk
835endif
836
837ifeq (${NEED_BL2U},yes)
838include bl2u/bl2u.mk
839endif
840
841ifeq (${NEED_BL31},yes)
842include bl31/bl31.mk
843endif
844
845################################################################################
846# Build options checks
847################################################################################
848
849# Boolean_Flags
850$(eval $(call assert_booleans,\
851    $(sort \
852	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 \
858	CTX_INCLUDE_SVE_REGS \
859	CTX_INCLUDE_EL2_REGS \
860	CTX_INCLUDE_MPAM_REGS \
861	DEBUG \
862	DYN_DISABLE_AUTH \
863	EL3_EXCEPTION_HANDLING \
864	ENABLE_AMU_AUXILIARY_COUNTERS \
865	AMU_RESTRICT_COUNTERS \
866	ENABLE_ASSERTIONS \
867	ENABLE_PIE \
868	ENABLE_PMF \
869	ENABLE_PSCI_STAT \
870	ENABLE_RUNTIME_INSTRUMENTATION \
871	ENABLE_SME_FOR_SWD \
872	ENABLE_SVE_FOR_SWD \
873	ENABLE_FEAT_GCIE \
874	ENABLE_FEAT_RAS	\
875	FFH_SUPPORT	\
876	ERROR_DEPRECATED \
877	FAULT_INJECTION_SUPPORT \
878	GENERATE_COT \
879	GICV2_G0_FOR_EL3 \
880	HANDLE_EA_EL3_FIRST_NS \
881	HARDEN_SLS \
882	HW_ASSISTED_COHERENCY \
883	MEASURED_BOOT \
884	DISCRETE_TPM \
885	DICE_PROTECTION_ENVIRONMENT \
886	RMMD_ENABLE_EL3_TOKEN_SIGN \
887	RMMD_ENABLE_IDE_KEY_PROG \
888	DRTM_SUPPORT \
889	NS_TIMER_SWITCH \
890	OVERRIDE_LIBC \
891	PL011_GENERIC_UART \
892	PROGRAMMABLE_RESET_ADDRESS \
893	PSCI_EXTENDED_STATE_ID \
894	PSCI_OS_INIT_MODE \
895	ARCH_FEATURE_AVAILABILITY \
896	RESET_TO_BL31 \
897	SAVE_KEYS \
898	SEPARATE_CODE_AND_RODATA \
899	SEPARATE_BL2_NOLOAD_REGION \
900	SEPARATE_NOBITS_REGION \
901	SEPARATE_RWDATA_REGION \
902	SEPARATE_SIMD_SECTION \
903	SPIN_ON_BL1_EXIT \
904	SPM_MM \
905	SPMC_AT_EL3 \
906	SPMC_AT_EL3_SEL0_SP \
907	SPMD_SPM_AT_SEL2 \
908	ENABLE_SPMD_LP \
909	TRANSFER_LIST \
910	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 \
926	ERRATA_SME_POWER_DOWN \
927	RAS_TRAP_NS_ERR_REC_ACCESS \
928	COT_DESC_IN_DTB \
929	USE_SP804_TIMER \
930	PSA_FWU_SUPPORT \
931	PSA_FWU_METADATA_FW_STORE_DESC \
932	ENABLE_MPMM \
933	FEAT_PABANDON \
934	FEATURE_DETECTION \
935	TRNG_SUPPORT \
936	ENABLE_ERRATA_ALL \
937	ERRATA_ABI_SUPPORT \
938	ERRATA_NON_ARM_INTERCONNECT \
939	CONDITIONAL_CMO \
940	PSA_CRYPTO	\
941	ENABLE_CONSOLE_GETC \
942	INIT_UNUSED_NS_EL2	\
943	PLATFORM_REPORT_CTX_MEM_USE \
944	EARLY_CONSOLE \
945	PRESERVE_DSU_PMU_REGS \
946	HOB_LIST \
947	LFA_SUPPORT \
948)))
949
950# Numeric_Flags
951$(eval $(call assert_numerics,\
952    $(sort \
953	ARM_ARCH_MAJOR \
954	ARM_ARCH_MINOR \
955	BRANCH_PROTECTION \
956	CTX_INCLUDE_PAUTH_REGS \
957	CTX_INCLUDE_NEVE_REGS \
958	CRYPTO_SUPPORT \
959	DISABLE_MTPMU \
960	ENABLE_BRBE_FOR_NS \
961	ENABLE_TRBE_FOR_NS \
962	ENABLE_BTI \
963	ENABLE_PAUTH \
964	ENABLE_FEAT_PAUTH_LR \
965	ENABLE_FEAT_AMU \
966	ENABLE_FEAT_AMUv1p1 \
967	ENABLE_FEAT_CSV2_2 \
968	ENABLE_FEAT_CSV2_3 \
969	ENABLE_FEAT_DEBUGV8P9 \
970	ENABLE_FEAT_DIT \
971	ENABLE_FEAT_ECV \
972	ENABLE_FEAT_FGT \
973	ENABLE_FEAT_FGT2 \
974	ENABLE_FEAT_FPMR \
975	ENABLE_FEAT_HCX \
976	ENABLE_FEAT_LS64_ACCDATA \
977	ENABLE_FEAT_MEC \
978	ENABLE_FEAT_MOPS \
979	ENABLE_FEAT_MTE2 \
980	ENABLE_FEAT_PAN \
981	ENABLE_FEAT_RNG \
982	ENABLE_FEAT_RNG_TRAP \
983	ENABLE_FEAT_SEL2 \
984	ENABLE_FEAT_TCR2 \
985	ENABLE_FEAT_THE \
986	ENABLE_FEAT_SB \
987	ENABLE_FEAT_S2PIE \
988	ENABLE_FEAT_S1PIE \
989	ENABLE_FEAT_S2POE \
990	ENABLE_FEAT_S1POE \
991	ENABLE_FEAT_SCTLR2 \
992	ENABLE_FEAT_D128 \
993	ENABLE_FEAT_GCS \
994	ENABLE_FEAT_VHE \
995	ENABLE_FEAT_MPAM \
996	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 \
1009	IMPDEF_SYSREG_TRAP \
1010	W \
1011)))
1012
1013ifdef KEY_SIZE
1014        $(eval $(call assert_numeric,KEY_SIZE))
1015endif
1016
1017ifeq ($(filter $(SANITIZE_UB), on off trap),)
1018        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1019endif
1020
1021################################################################################
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
1027$(eval $(call add_defines,\
1028    $(sort \
1029	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 \
1036	CTX_INCLUDE_SVE_REGS \
1037	CTX_INCLUDE_PAUTH_REGS \
1038	CTX_INCLUDE_MPAM_REGS \
1039	EL3_EXCEPTION_HANDLING \
1040	CTX_INCLUDE_EL2_REGS \
1041	CTX_INCLUDE_NEVE_REGS \
1042	DEBUG \
1043	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1044	DISABLE_MTPMU \
1045	ENABLE_FEAT_AMU \
1046	ENABLE_AMU_AUXILIARY_COUNTERS \
1047	AMU_RESTRICT_COUNTERS \
1048	ENABLE_ASSERTIONS \
1049	ENABLE_BTI \
1050	ENABLE_FEAT_DEBUGV8P9 \
1051	ENABLE_FEAT_MPAM \
1052	ENABLE_PAUTH \
1053	ENABLE_FEAT_PAUTH_LR \
1054	ENABLE_PIE \
1055	ENABLE_PMF \
1056	ENABLE_PSCI_STAT \
1057	ENABLE_RME \
1058	RMMD_ENABLE_EL3_TOKEN_SIGN \
1059	RMMD_ENABLE_IDE_KEY_PROG \
1060	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 \
1067	ENABLE_FEAT_RAS \
1068	FFH_SUPPORT \
1069	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 \
1078	DISCRETE_TPM \
1079	DICE_PROTECTION_ENVIRONMENT \
1080	DRTM_SUPPORT \
1081	NS_TIMER_SWITCH \
1082	PL011_GENERIC_UART \
1083	PLAT_${PLAT} \
1084	PROGRAMMABLE_RESET_ADDRESS \
1085	PSCI_EXTENDED_STATE_ID \
1086	PSCI_OS_INIT_MODE \
1087	ARCH_FEATURE_AVAILABILITY \
1088	RESET_TO_BL31 \
1089	RME_GPT_BITLOCK_BLOCK \
1090	RME_GPT_MAX_BLOCK \
1091	SEPARATE_CODE_AND_RODATA \
1092	SEPARATE_BL2_NOLOAD_REGION \
1093	SEPARATE_NOBITS_REGION \
1094	SEPARATE_RWDATA_REGION \
1095	SEPARATE_SIMD_SECTION \
1096	RECLAIM_INIT_CODE \
1097	SPD_${SPD} \
1098	SPIN_ON_BL1_EXIT \
1099	SPM_MM \
1100	SPMC_AT_EL3 \
1101	SPMC_AT_EL3_SEL0_SP \
1102	SPMD_SPM_AT_SEL2 \
1103	TRANSFER_LIST \
1104	TRUSTED_BOARD_BOOT \
1105	CRYPTO_SUPPORT \
1106	TRNG_SUPPORT \
1107	ERRATA_ABI_SUPPORT \
1108	ERRATA_NON_ARM_INTERCONNECT \
1109	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 \
1123	ERRATA_SME_POWER_DOWN \
1124	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 \
1134	PSA_FWU_METADATA_FW_STORE_DESC \
1135	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 \
1141	FEAT_PABANDON \
1142	ENABLE_FEAT_FGT \
1143	ENABLE_FEAT_FGT2 \
1144	ENABLE_FEAT_FPMR \
1145	ENABLE_FEAT_ECV \
1146	ENABLE_FEAT_AMUv1p1 \
1147	ENABLE_FEAT_SEL2 \
1148	ENABLE_FEAT_VHE \
1149	ENABLE_FEAT_CSV2_2 \
1150	ENABLE_FEAT_CSV2_3 \
1151	ENABLE_FEAT_LS64_ACCDATA \
1152	ENABLE_FEAT_MEC \
1153	ENABLE_FEAT_PAN \
1154	ENABLE_FEAT_TCR2 \
1155	ENABLE_FEAT_THE \
1156	ENABLE_FEAT_S2PIE \
1157	ENABLE_FEAT_S1PIE \
1158	ENABLE_FEAT_S2POE \
1159	ENABLE_FEAT_S1POE \
1160	ENABLE_FEAT_SCTLR2 \
1161	ENABLE_FEAT_D128 \
1162	ENABLE_FEAT_GCS \
1163	ENABLE_FEAT_MOPS \
1164	ENABLE_FEAT_GCIE \
1165	ENABLE_FEAT_MTE2 \
1166	FEATURE_DETECTION \
1167	TWED_DELAY \
1168	ENABLE_FEAT_TWED \
1169	CONDITIONAL_CMO \
1170	IMPDEF_SYSREG_TRAP \
1171	SVE_VECTOR_LEN \
1172	ENABLE_SPMD_LP \
1173	PSA_CRYPTO	\
1174	ENABLE_CONSOLE_GETC \
1175	INIT_UNUSED_NS_EL2	\
1176	PLATFORM_REPORT_CTX_MEM_USE \
1177	EARLY_CONSOLE \
1178	PRESERVE_DSU_PMU_REGS \
1179	HOB_LIST \
1180	LFA_SUPPORT \
1181)))
1182
1183ifeq (${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
1190ifeq (${SANITIZE_UB},trap)
1191        $(eval $(call add_define,MONITOR_TRAPS))
1192endif #(SANITIZE_UB)
1193
1194# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1195ifdef EL3_PAYLOAD_BASE
1196        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1197else
1198# 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
1201                $(eval $(call add_define,PRELOADED_BL33_BASE))
1202	endif
1203endif #(EL3_PAYLOAD_BASE)
1204
1205# Define the DYN_DISABLE_AUTH flag only if set.
1206ifeq (${DYN_DISABLE_AUTH},1)
1207        $(eval $(call add_define,DYN_DISABLE_AUTH))
1208endif
1209
1210ifeq ($($(ARCH)-ld-id),arm-link)
1211        $(eval $(call add_define,USE_ARM_LINK))
1212endif
1213
1214# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1215ifeq (${SPD},spmd)
1216ifdef SP_LAYOUT_FILE
1217	-include $(BUILD_PLAT)/sp_gen.mk
1218	FIP_DEPS += sp
1219	CRT_DEPS += sp
1220	NEED_SP_PKG := yes
1221else
1222	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)
1227
1228################################################################################
1229# Build targets
1230################################################################################
1231
1232.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
1233
1234all: msg_start
1235
1236msg_start:
1237	$(s)echo "Building ${PLAT}"
1238
1239ifeq (${ERROR_DEPRECATED},0)
1240# Check if deprecated declarations and cpp warnings should be treated as error or not.
1241ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1242    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1243else
1244    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1245endif
1246endif #(!ERROR_DEPRECATED)
1247
1248$(eval $(call MAKE_LIB,c))
1249
1250# Expand build macros for the different images
1251ifeq (${NEED_BL1},yes)
1252BL1_SOURCES := $(sort ${BL1_SOURCES})
1253$(eval $(call MAKE_BL,bl1))
1254endif #(NEED_BL1)
1255
1256ifeq (${NEED_BL2},yes)
1257
1258ifeq (${RESET_TO_BL2}, 0)
1259FIP_BL2_ARGS := tb-fw
1260endif
1261
1262BL2_SOURCES := $(sort ${BL2_SOURCES})
1263
1264$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1265	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1266
1267endif #(NEED_BL2)
1268
1269ifeq (${NEED_SCP_BL2},yes)
1270$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1271endif #(NEED_SCP_BL2)
1272
1273ifeq (${NEED_BL31},yes)
1274BL31_SOURCES += ${SPD_SOURCES}
1275# Sort BL31 source files to remove duplicates
1276BL31_SOURCES := $(sort ${BL31_SOURCES})
1277ifneq (${DECRYPTION_SUPPORT},none)
1278$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1279	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1280else
1281$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1282	$(eval $(call MAKE_BL,bl31,soc-fw)))
1283endif #(DECRYPTION_SUPPORT)
1284endif #(NEED_BL31)
1285
1286# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1287# build system will call TOOL_ADD_IMG to print a warning message and abort the
1288# process. Note that the dependency on BL32 applies to the FIP only.
1289ifeq (${NEED_BL32},yes)
1290# Sort BL32 source files to remove duplicates
1291BL32_SOURCES := $(sort ${BL32_SOURCES})
1292BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1293
1294ifneq (${DECRYPTION_SUPPORT},none)
1295$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1296	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1297else
1298$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1299	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1300endif #(DECRYPTION_SUPPORT)
1301endif #(NEED_BL32)
1302
1303# 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)),\
1311	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1312endif #(NEED_RMM)
1313
1314# Add the BL33 image if required by the platform
1315ifeq (${NEED_BL33},yes)
1316$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1317endif #(NEED_BL33)
1318
1319ifeq (${NEED_BL2U},yes)
1320$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1321	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1322endif #(NEED_BL2U)
1323
1324# Expand build macros for the different images
1325ifeq (${NEED_FDT},yes)
1326    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1327
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
1342endif #(NEED_FDT)
1343
1344# Add Secure Partition packages
1345ifeq (${NEED_SP_PKG},yes)
1346$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1347	$(if $(host-poetry),$(q)poetry -q install --no-root)
1348	$(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1349sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1350	$(s)echo
1351	$(s)echo "Built SP Images successfully"
1352	$(s)echo
1353endif #(NEED_SP_PKG)
1354
1355locate-checkpatch:
1356ifndef CHECKPATCH
1357	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1358else
1359ifeq (,$(wildcard ${CHECKPATCH}))
1360	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1361endif
1362endif #(CHECKPATCH)
1363
1364clean:
1365	$(s)echo "  CLEAN"
1366	$(q)rm -rf $(BUILD_PLAT)
1367	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1368	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1369	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1370	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1371	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1372	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1373
1374realclean distclean:
1375	$(s)echo "  REALCLEAN"
1376	$(q)rm -rf $(BUILD_BASE)
1377	$(q)rm -rf $(CURDIR)/cscope.*
1378	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1379	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1380	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1381	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1382	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1383	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1384
1385checkcodebase:		locate-checkpatch
1386	$(s)echo "  CHECKING STYLE"
1387	$(q)if test -d .git ; then						\
1388		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1389		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*"				\
1396		 -not -iwholename "*libc*"				\
1397		 -not -iwholename "*docs*"				\
1398		 -not -iwholename "*.rst"				\
1399		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1400	fi
1401
1402checkpatch:		locate-checkpatch
1403	$(s)echo "  CHECKING STYLE"
1404	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1405		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1406	fi
1407	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1408	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1409	do								\
1410		printf "\n[*] Checking style of '$$commit'\n\n";	\
1411		( git log --format=email "$$commit~..$$commit"		\
1412			-- ${CHECK_PATHS} ;				\
1413		  git diff --format=email "$$commit~..$$commit"		\
1414			-- ${CHECK_PATHS}; ) |				\
1415			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1416	done
1417
1418certtool: ${CRTTOOL}
1419
1420${CRTTOOL}: FORCE
1421	$(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
1423	$(s)echo
1424	$(s)echo "Built $@ successfully"
1425	$(s)echo
1426
1427ifneq (${GENERATE_COT},0)
1428certificates: ${CRT_DEPS} ${CRTTOOL} ${DTBS}
1429	$(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
1434endif #(GENERATE_COT)
1435
1436${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1437	$(eval ${CHECK_FIP_CMD})
1438	$(q)${FIPTOOL} create ${FIP_ARGS} $@
1439	$(q)${FIPTOOL} info $@
1440	$(s)echo
1441	$(s)echo "Built $@ successfully"
1442	$(s)echo
1443
1444ifneq (${GENERATE_COT},0)
1445fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1446	$(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
1451endif #(GENERATE_COT)
1452
1453${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1454	$(eval ${CHECK_FWU_FIP_CMD})
1455	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1456	$(q)${FIPTOOL} info $@
1457	$(s)echo
1458	$(s)echo "Built $@ successfully"
1459	$(s)echo
1460
1461fiptool: ${FIPTOOL}
1462fip: ${BUILD_PLAT}/${FIP_NAME}
1463fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1464
1465# symlink for compatibility before tools were in the build directory
1466${FIPTOOL}: FORCE
1467	$(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
1469
1470$(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
1472
1473memmap: all
1474	$(if $(host-poetry),$(q)poetry -q install --no-root)
1475	$(q)$(if $(host-poetry),poetry run )memory symbols --root ${BUILD_PLAT}
1476
1477tl: ${BUILD_PLAT}/tl.bin
1478${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
1479	$(if $(host-poetry),$(q)poetry -q install --no-root)
1480	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1481
1482doc:
1483	$(s)echo "  BUILD DOCUMENTATION"
1484	$(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
1486
1487enctool: ${ENCTOOL}
1488
1489${ENCTOOL}: FORCE
1490	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1491	$(s)echo
1492	$(s)echo "Built $@ successfully"
1493	$(s)echo
1494
1495cscope:
1496	$(s)echo "  CSCOPE"
1497	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1498	$(q)cscope -b -q -k
1499
1500help:
1501	$(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"
1543
1544.PHONY: FORCE
1545FORCE:;
1546