xref: /rk3399_ARM-atf/Makefile (revision ee580c2d110971370e80b124dfb63f0e9176c4b7)
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			?=	${CRTTOOLPATH}/cert_create$(.exe)
103
104# Variables for use with Firmware Encryption Tool
105ENCTOOLPATH		?=	tools/encrypt_fw
106ENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw$(.exe)
107
108# Variables for use with Firmware Image Package
109FIPTOOLPATH		?=	tools/fiptool
110FIPTOOL			?=	${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
140################################################################################
141# Get Architecture Feature Modifiers
142################################################################################
143arch-features		=	${ARM_ARCH_FEATURE}
144
145ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
146	ifeq ($($(ARCH)-cc-id),arm-clang)
147		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
148		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
149	else
150		TF_CFLAGS_aarch32	=	$(target32-directive)
151		TF_CFLAGS_aarch64	:=	-target aarch64-unknown-none-elf
152	endif
153
154else ifeq ($($(ARCH)-cc-id),gnu-gcc)
155	# Enable LTO only for aarch64
156	ifeq (${ARCH},aarch64)
157		LTO_CFLAGS	=	$(if $(filter-out 0,$(ENABLE_LTO)),-flto)
158	endif
159endif #(clang)
160
161# Process Debug flag
162ifneq (${DEBUG}, 0)
163	BUILD_TYPE	:=	debug
164	TF_CFLAGS	+=	-g -gdwarf-4
165	ASFLAGS		+=	-g -Wa,-gdwarf-4
166
167	# Use LOG_LEVEL_INFO by default for debug builds
168	LOG_LEVEL	:=	40
169else
170	BUILD_TYPE	:=	release
171	# Use LOG_LEVEL_NOTICE by default for release builds
172	LOG_LEVEL	:=	20
173endif #(Debug)
174
175# Default build string (git branch and commit)
176ifeq (${BUILD_STRING},)
177	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
178endif
179VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
180
181ifeq (${AARCH32_INSTRUCTION_SET},A32)
182	TF_CFLAGS_aarch32	+=	-marm
183else ifeq (${AARCH32_INSTRUCTION_SET},T32)
184	TF_CFLAGS_aarch32	+=	-mthumb
185endif #(AARCH32_INSTRUCTION_SET)
186
187TF_CFLAGS_aarch32	+=	-mno-unaligned-access
188TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
189
190##############################################################################
191# WARNINGS Configuration
192###############################################################################
193# General warnings
194WARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
195				-Wdisabled-optimization -Wvla -Wshadow	\
196				-Wredundant-decls
197# stricter warnings
198WARNINGS		+=	-Wextra -Wno-trigraphs
199# too verbose for generic build
200WARNINGS		+=	-Wno-missing-field-initializers \
201				-Wno-type-limits -Wno-sign-compare \
202# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
203WARNINGS		+=	-Wno-unused-parameter
204
205# Additional warnings
206# Level 1 - infrequent warnings we should have none of
207# full -Wextra
208WARNING1 += -Wsign-compare
209WARNING1 += -Wtype-limits
210WARNING1 += -Wmissing-field-initializers
211
212# Level 2 - problematic warnings that we want
213# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
214# TODO: disable just for them and move into default build
215WARNING2 += -Wold-style-definition
216WARNING2 += -Wmissing-prototypes
217WARNING2 += -Wmissing-format-attribute
218# TF-A aims to comply with this eventually. Effort too large at present
219WARNING2 += -Wundef
220# currently very involved and many platforms set this off
221WARNING2 += -Wunused-const-variable=2
222
223# Level 3 - very pedantic, frequently ignored
224WARNING3 := -Wbad-function-cast
225WARNING3 += -Waggregate-return
226WARNING3 += -Wnested-externs
227WARNING3 += -Wcast-align
228WARNING3 += -Wcast-qual
229WARNING3 += -Wconversion
230WARNING3 += -Wpacked
231WARNING3 += -Wpointer-arith
232WARNING3 += -Wswitch-default
233
234# Setting W is quite verbose and most warnings will be pre-existing issues
235# outside of the contributor's control. Don't fail the build on them so warnings
236# can be seen and hopefully addressed
237ifdef W
238	ifneq (${W},0)
239		E	 ?= 0
240	endif
241endif
242
243ifeq (${W},1)
244	WARNINGS += $(WARNING1)
245else ifeq (${W},2)
246	WARNINGS += $(WARNING1) $(WARNING2)
247else ifeq (${W},3)
248	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
249endif #(W)
250
251# Compiler specific warnings
252ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
253# not using clang
254WARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
255				-Wpacked-bitfield-compat -Wshift-overflow=2 \
256				-Wlogical-op
257
258# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
259TF_CFLAGS_MIN_PAGE_SIZE	:=	$(call cc_option, --param=min-pagesize=0)
260TF_CFLAGS		+=	$(TF_CFLAGS_MIN_PAGE_SIZE)
261
262ifeq ($(HARDEN_SLS), 1)
263        TF_CFLAGS_MHARDEN_SLS	:=      $(call cc_option, -mharden-sls=all)
264        TF_CFLAGS_aarch64	+=      $(TF_CFLAGS_MHARDEN_SLS)
265endif
266
267else
268# using clang
269WARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
270				-Wlogical-op-parentheses
271endif #(Clang Warning)
272
273ifneq (${E},0)
274	ERRORS := -Werror
275endif #(E)
276
277################################################################################
278# Compiler and Linker Directives
279################################################################################
280CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
281				$(ERRORS) $(WARNINGS)
282ASFLAGS			+=	$(CPPFLAGS)                 			\
283				-ffreestanding -Wa,--fatal-warnings
284TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
285				-ffunction-sections -fdata-sections		\
286				-ffreestanding -fno-common			\
287				-Os -std=gnu99
288
289ifeq (${SANITIZE_UB},on)
290	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
291endif #(${SANITIZE_UB},on)
292
293ifeq (${SANITIZE_UB},trap)
294	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
295				-fsanitize-undefined-trap-on-error
296endif #(${SANITIZE_UB},trap)
297
298GCC_V_OUTPUT		:=	$(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
299
300TF_LDFLAGS		+=	-z noexecstack
301
302# LD = armlink
303ifeq ($($(ARCH)-ld-id),arm-link)
304	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
305	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
306	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
307
308# LD = gcc (used when GCC LTO is enabled)
309else ifeq ($($(ARCH)-ld-id),gnu-gcc)
310	# Pass ld options with Wl or Xlinker switches
311	TF_LDFLAGS		+=	$(call ld_option,-Xlinker --no-warn-rwx-segments)
312	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
313	TF_LDFLAGS		+=	-Wl,--gc-sections
314
315	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
316	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
317	TF_LDFLAGS		+=	-Wl,--build-id=none
318
319	ifeq ($(ENABLE_LTO),1)
320		ifeq (${ARCH},aarch64)
321			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
322			TF_LDFLAGS      +=	-flto-partition=one
323		endif
324	endif #(ENABLE_LTO)
325
326# GCC automatically adds fix-cortex-a53-843419 flag when used to link
327# which breaks some builds, so disable if errata fix is not explicitly enabled
328	ifeq (${ARCH},aarch64)
329		ifneq (${ERRATA_A53_843419},1)
330			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
331		endif
332	endif
333	TF_LDFLAGS		+= 	-nostdlib
334	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
335
336# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
337else
338# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
339# are not loaded by a elf loader.
340	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
341	TF_LDFLAGS		+=	-O1
342	TF_LDFLAGS		+=	--gc-sections
343
344	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
345	TF_LDFLAGS		+=	-z max-page-size=4096
346	TF_LDFLAGS		+=	--build-id=none
347
348# ld.lld doesn't recognize the errata flags,
349# therefore don't add those in that case.
350# ld.lld reports section type mismatch warnings,
351# therefore don't add --fatal-warnings to it.
352	ifneq ($($(ARCH)-ld-id),llvm-lld)
353		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
354	endif
355
356endif #(LD = armlink)
357
358################################################################################
359# Setup ARCH_MAJOR/MINOR before parsing arch_features.
360################################################################################
361ifeq (${ENABLE_RME},1)
362	ARM_ARCH_MAJOR := 9
363	ARM_ARCH_MINOR := 2
364endif
365
366################################################################################
367# Common sources and include directories
368################################################################################
369include lib/compiler-rt/compiler-rt.mk
370
371# Allow overriding the timestamp, for example for reproducible builds, or to
372# synchronize timestamps across multiple projects.
373# This must be set to a C string (including quotes where applicable).
374BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
375
376DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
377DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
378DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
379
380BL_COMMON_SOURCES	+=	common/bl_common.c			\
381				common/tf_log.c				\
382				common/${ARCH}/debug.S			\
383				drivers/console/multi_console.c		\
384				lib/${ARCH}/cache_helpers.S		\
385				lib/${ARCH}/misc_helpers.S		\
386				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
387				plat/common/plat_bl_common.c		\
388				plat/common/plat_log_common.c		\
389				plat/common/${ARCH}/plat_common.c	\
390				plat/common/${ARCH}/platform_helpers.S	\
391				${COMPILER_RT_SRCS}
392
393ifeq ($($(ARCH)-cc-id),arm-clang)
394	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
395endif
396
397ifeq (${SANITIZE_UB},on)
398	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
399endif
400
401INCLUDES		+=	-Iinclude				\
402				-Iinclude/arch/${ARCH}			\
403				-Iinclude/lib/cpus/${ARCH}		\
404				-Iinclude/lib/el3_runtime/${ARCH}	\
405				${PLAT_INCLUDES}			\
406				${SPD_INCLUDES}
407
408DTC_FLAGS		+=	-I dts -O dtb
409DTC_CPPFLAGS		+=	-P -nostdinc $(INCLUDES) -Ifdts -undef \
410				-x assembler-with-cpp $(DEFINES)
411
412include common/backtrace/backtrace.mk
413
414################################################################################
415# Generic definitions
416################################################################################
417
418ifeq (${BUILD_BASE},)
419     BUILD_BASE		:=	./build
420endif
421BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
422
423SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
424
425# Platforms providing their own TBB makefile may override this value
426INCLUDE_TBBR_MK		:=	1
427
428################################################################################
429# Include SPD Makefile if one has been specified
430################################################################################
431
432ifneq (${SPD},none)
433	ifeq (${SPD},spmd)
434	# SPMD is located in std_svc directory
435		SPD_DIR := std_svc
436
437		ifeq ($(SPMD_SPM_AT_SEL2),1)
438			CTX_INCLUDE_EL2_REGS := 1
439		endif
440
441		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
442			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
443		endif
444
445		ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
446			DTC_CPPFLAGS	+=	-DTRUSTY_SP_FW_CONFIG
447		endif
448
449		ifeq ($(TS_SP_FW_CONFIG),1)
450			DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
451		endif
452
453		ifneq ($(ARM_BL2_SP_LIST_DTS),)
454		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
455		endif
456
457		ifneq ($(SP_LAYOUT_FILE),)
458		BL2_ENABLE_SP_LOAD := 1
459		endif
460	else
461		# All other SPDs in spd directory
462		SPD_DIR := spd
463	endif #(SPD)
464
465	# We expect to locate an spd.mk under the specified SPD directory
466	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
467
468	ifeq (${SPD_MAKE},)
469                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
470	endif
471        $(info Including ${SPD_MAKE})
472        include ${SPD_MAKE}
473
474	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
475	# Makefile would set NEED_BL32 to "yes". In this case, the build system
476	# supports two mutually exclusive options:
477	# * BL32 is built from source: then BL32_SOURCES must contain the list
478	#   of source files to build BL32
479	# * BL32 is a prebuilt binary: then BL32 must point to the image file
480	#   that will be included in the FIP
481	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
482	# over the sources.
483endif #(SPD=none)
484
485################################################################################
486# Include the platform specific Makefile after the SPD Makefile (the platform
487# makefile may use all previous definitions in this file)
488################################################################################
489include ${PLAT_MAKEFILE_FULL}
490
491################################################################################
492# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
493# platform.
494################################################################################
495
496include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
497################################################################################
498# Process BRANCH_PROTECTION value and set
499# Pointer Authentication and Branch Target Identification flags
500################################################################################
501ifeq (${BRANCH_PROTECTION},0)
502	# Default value turns off all types of branch protection
503	BP_OPTION := none
504else ifneq (${ARCH},aarch64)
505        $(error BRANCH_PROTECTION requires AArch64)
506else ifeq (${BRANCH_PROTECTION},1)
507	# Enables all types of branch protection features
508	BP_OPTION := standard
509	ENABLE_BTI := 1
510	ENABLE_PAUTH := 1
511else ifeq (${BRANCH_PROTECTION},2)
512	# Return address signing to its standard level
513	BP_OPTION := pac-ret
514	ENABLE_PAUTH := 1
515else ifeq (${BRANCH_PROTECTION},3)
516	# Extend the signing to include leaf functions
517	BP_OPTION := pac-ret+leaf
518	ENABLE_PAUTH := 1
519else ifeq (${BRANCH_PROTECTION},4)
520	# Turn on branch target identification mechanism
521	BP_OPTION := bti
522	ENABLE_BTI := 1
523else ifeq (${BRANCH_PROTECTION},5)
524	# Turn on branch target identification mechanism
525	BP_OPTION := standard
526	ENABLE_BTI := 2
527	ENABLE_PAUTH := 2
528else
529        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
530endif #(BRANCH_PROTECTION)
531
532ifneq ($(ENABLE_PAUTH),0)
533	CTX_INCLUDE_PAUTH_REGS	:= ${ENABLE_PAUTH}
534endif
535ifneq (${BP_OPTION},none)
536	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
537endif #(BP_OPTION)
538
539# Pointer Authentication sources
540ifneq (${ENABLE_PAUTH},0)
541# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
542# Pauth support. As it's not secure, it must be reimplemented for real platforms
543	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth.c
544endif
545#
546ifneq (${ENABLE_FEAT_PAUTH_LR},0)
547# Currently, FEAT_PAUTH_LR is only supported by arm/clang compilers
548# TODO implement for GCC when support is added
549ifeq ($($(ARCH)-cc-id),arm-clang)
550	arch-features	:= $(arch-features)+pauth-lr
551else
552	$(error Error: ENABLE_FEAT_PAUTH_LR not supported for GCC compiler)
553endif
554endif
555
556################################################################################
557# RME dependent flags configuration, Enable optional features for RME.
558################################################################################
559# FEAT_RME
560ifeq (${ENABLE_RME},1)
561	# RME requires el2 context to be saved for now.
562	CTX_INCLUDE_EL2_REGS := 1
563	CTX_INCLUDE_AARCH32_REGS := 0
564	CTX_INCLUDE_PAUTH_REGS := 1
565
566	ifneq ($(ENABLE_FEAT_MPAM), 0)
567		CTX_INCLUDE_MPAM_REGS := 1
568	endif
569
570	# RME enables CSV2_2 extension by default.
571	ENABLE_FEAT_CSV2_2 = 1
572endif #(FEAT_RME)
573
574################################################################################
575# Include rmmd Makefile if RME is enabled
576################################################################################
577ifneq (${ENABLE_RME},0)
578include services/std_svc/rmmd/rmmd.mk
579$(warning "RME is an experimental feature")
580endif
581
582################################################################################
583# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
584################################################################################
585ifneq (${ENABLE_FEAT_D128}, 0)
586        BL_COMMON_SOURCES       +=      lib/extensions/sysreg128/sysreg128.S
587endif
588
589################################################################################
590# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
591# up with appropriate march values for compiler.
592################################################################################
593include ${MAKE_HELPERS_DIRECTORY}march.mk
594
595TF_CFLAGS	+=	$(march-directive)
596ASFLAGS		+=	$(march-directive)
597
598# This internal flag is common option which is set to 1 for scenarios
599# when the BL2 is running in EL3 level. This occurs in two scenarios -
600# 4 world system running BL2 at EL3 and two world system without BL1 running
601# BL2 in EL3
602
603ifeq (${RESET_TO_BL2},1)
604	BL2_RUNS_AT_EL3	:=	1
605	ifeq (${ENABLE_RME},1)
606                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
607                supported at the moment.)
608	endif
609else ifeq (${ENABLE_RME},1)
610	BL2_RUNS_AT_EL3	:=	1
611else
612	BL2_RUNS_AT_EL3	:=	0
613endif
614
615# This internal flag is set to 1 when Firmware First handling of External aborts
616# is required by lowe ELs. Currently only NS requires this support.
617ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
618	FFH_SUPPORT := 1
619else
620	FFH_SUPPORT := 0
621endif
622
623ifeq (${ARM_ARCH_MAJOR},7)
624include make_helpers/armv7-a-cpus.mk
625endif
626
627PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
628ifneq ($(PIE_FOUND),)
629	TF_CFLAGS	+=	-fno-PIE
630ifeq ($($(ARCH)-ld-id),gnu-gcc)
631	TF_LDFLAGS	+=	-no-pie
632endif
633endif #(PIE_FOUND)
634
635ifeq ($($(ARCH)-ld-id),gnu-gcc)
636	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
637else
638	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
639endif
640
641ifeq ($(ENABLE_PIE),1)
642	ifeq ($(RESET_TO_BL2),1)
643		ifneq ($(BL2_IN_XIP_MEM),1)
644			BL2_CPPFLAGS	+=	-fpie
645			BL2_CFLAGS	+=	-fpie
646			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
647		endif #(BL2_IN_XIP_MEM)
648	endif #(RESET_TO_BL2)
649	BL31_CPPFLAGS	+=	-fpie
650	BL31_CFLAGS 	+=	-fpie
651	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
652
653	BL32_CPPFLAGS	+=	-fpie
654	BL32_CFLAGS	+=	-fpie
655	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
656endif #(ENABLE_PIE)
657
658BL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
659BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
660BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
661
662BL1_CPPFLAGS += -DIMAGE_AT_EL3
663ifeq ($(RESET_TO_BL2),1)
664	BL2_CPPFLAGS += -DIMAGE_AT_EL3
665else
666	BL2_CPPFLAGS += -DIMAGE_AT_EL1
667endif #(RESET_TO_BL2)
668
669ifeq (${ARCH},aarch64)
670	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
671	BL31_CPPFLAGS += -DIMAGE_AT_EL3
672	BL32_CPPFLAGS += -DIMAGE_AT_EL1
673else
674	BL32_CPPFLAGS += -DIMAGE_AT_EL3
675endif
676
677# Include the CPU specific operations makefile, which provides default
678# values for all CPU errata workarounds and CPU specific optimisations.
679# This can be overridden by the platform.
680include lib/cpus/cpu-ops.mk
681
682################################################################################
683# Build `AARCH32_SP` as BL32 image for AArch32
684################################################################################
685ifeq (${ARCH},aarch32)
686        NEED_BL32 := yes
687
688        ifneq (${AARCH32_SP},none)
689        # We expect to locate an sp.mk under the specified AARCH32_SP directory
690		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
691
692                ifeq (${AARCH32_SP_MAKE},)
693                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
694                endif
695                $(info Including ${AARCH32_SP_MAKE})
696                include ${AARCH32_SP_MAKE}
697        endif
698endif #(ARCH=aarch32)
699
700################################################################################
701# Include libc if not overridden
702################################################################################
703ifeq (${OVERRIDE_LIBC},0)
704include lib/libc/libc.mk
705endif
706
707ifneq (${USE_GIC_DRIVER},0)
708include drivers/arm/gic/gic.mk
709endif
710
711################################################################################
712# Check incompatible options and dependencies
713################################################################################
714include ${MAKE_HELPERS_DIRECTORY}constraints.mk
715
716# The cert_create tool cannot generate certificates individually, so we use the
717# target 'certificates' to create them all
718ifneq (${GENERATE_COT},0)
719        FIP_DEPS += certificates
720        FWU_FIP_DEPS += fwu_certificates
721endif
722
723ifneq (${DECRYPTION_SUPPORT},none)
724	ENC_ARGS += -f ${FW_ENC_STATUS}
725	ENC_ARGS += -k ${ENC_KEY}
726	ENC_ARGS += -n ${ENC_NONCE}
727	FIP_DEPS += enctool
728	FWU_FIP_DEPS += enctool
729endif #(DECRYPTION_SUPPORT)
730
731ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
732# Support authentication verification and hash calculation
733	CRYPTO_SUPPORT := 3
734else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
735# Support authentication verification and hash calculation
736	CRYPTO_SUPPORT := 3
737else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
738# Support hash calculation only
739	CRYPTO_SUPPORT := 2
740else ifeq (${TRUSTED_BOARD_BOOT},1)
741# Support authentication verification only
742	CRYPTO_SUPPORT := 1
743else
744	CRYPTO_SUPPORT := 0
745endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
746
747ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
748CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
749endif
750
751################################################################################
752# Process platform overrideable behaviour
753################################################################################
754
755ifdef BL1_SOURCES
756	NEED_BL1 := yes
757endif #(BL1_SOURCES)
758
759ifdef BL2_SOURCES
760	NEED_BL2 := yes
761
762	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
763	# Certificate generation tools. This flag can be overridden by the platform.
764	ifdef EL3_PAYLOAD_BASE
765		# If booting an EL3 payload there is no need for a BL33 image
766		# in the FIP file.
767		NEED_BL33		:=	no
768	else
769		ifdef PRELOADED_BL33_BASE
770			# If booting a BL33 preloaded image there is no need of
771			# another one in the FIP file.
772			NEED_BL33		:=	no
773		else
774			NEED_BL33		?=	yes
775		endif
776	endif
777endif #(BL2_SOURCES)
778
779ifdef BL2U_SOURCES
780	NEED_BL2U := yes
781endif #(BL2U_SOURCES)
782
783# If SCP_BL2 is given, we always want FIP to include it.
784ifdef SCP_BL2
785	NEED_SCP_BL2		:=	yes
786endif #(SCP_BL2)
787
788# For AArch32, BL31 is not currently supported.
789ifneq (${ARCH},aarch32)
790	ifdef BL31_SOURCES
791	# When booting an EL3 payload, there is no need to compile the BL31
792	# image nor put it in the FIP.
793		ifndef EL3_PAYLOAD_BASE
794			NEED_BL31 := yes
795		endif
796	endif
797endif #(ARCH=aarch64)
798
799# Process TBB related flags
800ifneq (${GENERATE_COT},0)
801	# Common cert_create options
802	ifneq (${CREATE_KEYS},0)
803                $(eval CRT_ARGS += -n)
804                $(eval FWU_CRT_ARGS += -n)
805		ifneq (${SAVE_KEYS},0)
806                        $(eval CRT_ARGS += -k)
807                        $(eval FWU_CRT_ARGS += -k)
808		endif
809	endif
810	# Include TBBR makefile (unless the platform indicates otherwise)
811	ifeq (${INCLUDE_TBBR_MK},1)
812                include make_helpers/tbbr/tbbr_tools.mk
813	endif
814endif #(GENERATE_COT)
815
816ifneq (${FIP_ALIGN},0)
817	FIP_ARGS += --align ${FIP_ALIGN}
818endif #(FIP_ALIGN)
819
820ifdef FDT_SOURCES
821	NEED_FDT := yes
822endif #(FDT_SOURCES)
823
824################################################################################
825# Include libraries' Makefile that are used in all BL
826################################################################################
827
828include lib/stack_protector/stack_protector.mk
829
830################################################################################
831# Include BL specific makefiles
832################################################################################
833
834ifeq (${NEED_BL1},yes)
835include bl1/bl1.mk
836endif
837
838ifeq (${NEED_BL2},yes)
839include bl2/bl2.mk
840endif
841
842ifeq (${NEED_BL2U},yes)
843include bl2u/bl2u.mk
844endif
845
846ifeq (${NEED_BL31},yes)
847include bl31/bl31.mk
848endif
849
850################################################################################
851# Build options checks
852################################################################################
853
854# Boolean_Flags
855$(eval $(call assert_booleans,\
856    $(sort \
857	ALLOW_RO_XLAT_TABLES \
858	BL2_ENABLE_SP_LOAD \
859	COLD_BOOT_SINGLE_CPU \
860	CREATE_KEYS \
861	CTX_INCLUDE_AARCH32_REGS \
862	CTX_INCLUDE_FPREGS \
863	CTX_INCLUDE_SVE_REGS \
864	CTX_INCLUDE_EL2_REGS \
865	CTX_INCLUDE_MPAM_REGS \
866	DEBUG \
867	DYN_DISABLE_AUTH \
868	EL3_EXCEPTION_HANDLING \
869	ENABLE_AMU_AUXILIARY_COUNTERS \
870	AMU_RESTRICT_COUNTERS \
871	ENABLE_ASSERTIONS \
872	ENABLE_PIE \
873	ENABLE_PMF \
874	ENABLE_PSCI_STAT \
875	ENABLE_RUNTIME_INSTRUMENTATION \
876	ENABLE_SME_FOR_SWD \
877	ENABLE_SVE_FOR_SWD \
878	ENABLE_FEAT_GCIE \
879	ENABLE_FEAT_RAS	\
880	FFH_SUPPORT	\
881	ERROR_DEPRECATED \
882	FAULT_INJECTION_SUPPORT \
883	GENERATE_COT \
884	GICV2_G0_FOR_EL3 \
885	HANDLE_EA_EL3_FIRST_NS \
886	HARDEN_SLS \
887	HW_ASSISTED_COHERENCY \
888	MEASURED_BOOT \
889	DISCRETE_TPM \
890	DICE_PROTECTION_ENVIRONMENT \
891	RMMD_ENABLE_EL3_TOKEN_SIGN \
892	RMMD_ENABLE_IDE_KEY_PROG \
893	DRTM_SUPPORT \
894	NS_TIMER_SWITCH \
895	OVERRIDE_LIBC \
896	PL011_GENERIC_UART \
897	PROGRAMMABLE_RESET_ADDRESS \
898	PSCI_EXTENDED_STATE_ID \
899	PSCI_OS_INIT_MODE \
900	ARCH_FEATURE_AVAILABILITY \
901	RESET_TO_BL31 \
902	SAVE_KEYS \
903	SEPARATE_CODE_AND_RODATA \
904	SEPARATE_BL2_NOLOAD_REGION \
905	SEPARATE_NOBITS_REGION \
906	SEPARATE_RWDATA_REGION \
907	SEPARATE_SIMD_SECTION \
908	SPIN_ON_BL1_EXIT \
909	SPM_MM \
910	SPMC_AT_EL3 \
911	SPMC_AT_EL3_SEL0_SP \
912	SPMD_SPM_AT_SEL2 \
913	ENABLE_SPMD_LP \
914	TRANSFER_LIST \
915	TRUSTED_BOARD_BOOT \
916	USE_COHERENT_MEM \
917	USE_DEBUGFS \
918	ARM_IO_IN_DTB \
919	SDEI_IN_FCONF \
920	SEC_INT_DESC_IN_FCONF \
921	USE_ROMLIB \
922	USE_TBBR_DEFS \
923	WARMBOOT_ENABLE_DCACHE_EARLY \
924	RESET_TO_BL2 \
925	BL2_IN_XIP_MEM \
926	BL2_INV_DCACHE \
927	USE_SPINLOCK_CAS \
928	ENCRYPT_BL31 \
929	ENCRYPT_BL32 \
930	ERRATA_SPECULATIVE_AT \
931	ERRATA_SME_POWER_DOWN \
932	RAS_TRAP_NS_ERR_REC_ACCESS \
933	COT_DESC_IN_DTB \
934	USE_SP804_TIMER \
935	PSA_FWU_SUPPORT \
936	PSA_FWU_METADATA_FW_STORE_DESC \
937	ENABLE_MPMM \
938	FEAT_PABANDON \
939	FEATURE_DETECTION \
940	TRNG_SUPPORT \
941	ENABLE_ERRATA_ALL \
942	ERRATA_ABI_SUPPORT \
943	ERRATA_NON_ARM_INTERCONNECT \
944	CONDITIONAL_CMO \
945	PSA_CRYPTO	\
946	ENABLE_CONSOLE_GETC \
947	INIT_UNUSED_NS_EL2	\
948	PLATFORM_REPORT_CTX_MEM_USE \
949	EARLY_CONSOLE \
950	PRESERVE_DSU_PMU_REGS \
951	HOB_LIST \
952	LFA_SUPPORT \
953)))
954
955# Numeric_Flags
956$(eval $(call assert_numerics,\
957    $(sort \
958	ARM_ARCH_MAJOR \
959	ARM_ARCH_MINOR \
960	BRANCH_PROTECTION \
961	CTX_INCLUDE_PAUTH_REGS \
962	CTX_INCLUDE_NEVE_REGS \
963	CRYPTO_SUPPORT \
964	DISABLE_MTPMU \
965	ENABLE_BRBE_FOR_NS \
966	ENABLE_TRBE_FOR_NS \
967	ENABLE_BTI \
968	ENABLE_PAUTH \
969	ENABLE_FEAT_PAUTH_LR \
970	ENABLE_FEAT_AMU \
971	ENABLE_FEAT_AMUv1p1 \
972	ENABLE_FEAT_CSV2_2 \
973	ENABLE_FEAT_CSV2_3 \
974	ENABLE_FEAT_DEBUGV8P9 \
975	ENABLE_FEAT_DIT \
976	ENABLE_FEAT_ECV \
977	ENABLE_FEAT_FGT \
978	ENABLE_FEAT_FGT2 \
979	ENABLE_FEAT_FPMR \
980	ENABLE_FEAT_HCX \
981	ENABLE_FEAT_LS64_ACCDATA \
982	ENABLE_FEAT_MEC \
983	ENABLE_FEAT_MOPS \
984	ENABLE_FEAT_MTE2 \
985	ENABLE_FEAT_PAN \
986	ENABLE_FEAT_RNG \
987	ENABLE_FEAT_RNG_TRAP \
988	ENABLE_FEAT_SEL2 \
989	ENABLE_FEAT_TCR2 \
990	ENABLE_FEAT_THE \
991	ENABLE_FEAT_SB \
992	ENABLE_FEAT_S2PIE \
993	ENABLE_FEAT_S1PIE \
994	ENABLE_FEAT_S2POE \
995	ENABLE_FEAT_S1POE \
996	ENABLE_FEAT_SCTLR2 \
997	ENABLE_FEAT_D128 \
998	ENABLE_FEAT_GCS \
999	ENABLE_FEAT_VHE \
1000	ENABLE_FEAT_MPAM \
1001	ENABLE_RME \
1002	ENABLE_SPE_FOR_NS \
1003	ENABLE_SYS_REG_TRACE_FOR_NS \
1004	ENABLE_SME_FOR_NS \
1005	ENABLE_SME2_FOR_NS \
1006	ENABLE_SVE_FOR_NS \
1007	ENABLE_TRF_FOR_NS \
1008	FW_ENC_STATUS \
1009	NR_OF_FW_BANKS \
1010	NR_OF_IMAGES_IN_FW_BANK \
1011	TWED_DELAY \
1012	ENABLE_FEAT_TWED \
1013	SVE_VECTOR_LEN \
1014	IMPDEF_SYSREG_TRAP \
1015	W \
1016)))
1017
1018ifdef KEY_SIZE
1019        $(eval $(call assert_numeric,KEY_SIZE))
1020endif
1021
1022ifeq ($(filter $(SANITIZE_UB), on off trap),)
1023        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1024endif
1025
1026################################################################################
1027# Add definitions to the cpp preprocessor based on the current build options.
1028# This is done after including the platform specific makefile to allow the
1029# platform to overwrite the default options
1030################################################################################
1031
1032$(eval $(call add_defines,\
1033    $(sort \
1034	ALLOW_RO_XLAT_TABLES \
1035	ARM_ARCH_MAJOR \
1036	ARM_ARCH_MINOR \
1037	BL2_ENABLE_SP_LOAD \
1038	COLD_BOOT_SINGLE_CPU \
1039	CTX_INCLUDE_AARCH32_REGS \
1040	CTX_INCLUDE_FPREGS \
1041	CTX_INCLUDE_SVE_REGS \
1042	CTX_INCLUDE_PAUTH_REGS \
1043	CTX_INCLUDE_MPAM_REGS \
1044	EL3_EXCEPTION_HANDLING \
1045	CTX_INCLUDE_EL2_REGS \
1046	CTX_INCLUDE_NEVE_REGS \
1047	DEBUG \
1048	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1049	DISABLE_MTPMU \
1050	ENABLE_FEAT_AMU \
1051	ENABLE_AMU_AUXILIARY_COUNTERS \
1052	AMU_RESTRICT_COUNTERS \
1053	ENABLE_ASSERTIONS \
1054	ENABLE_BTI \
1055	ENABLE_FEAT_DEBUGV8P9 \
1056	ENABLE_FEAT_MPAM \
1057	ENABLE_PAUTH \
1058	ENABLE_FEAT_PAUTH_LR \
1059	ENABLE_PIE \
1060	ENABLE_PMF \
1061	ENABLE_PSCI_STAT \
1062	ENABLE_RME \
1063	RMMD_ENABLE_EL3_TOKEN_SIGN \
1064	RMMD_ENABLE_IDE_KEY_PROG \
1065	ENABLE_RUNTIME_INSTRUMENTATION \
1066	ENABLE_SME_FOR_NS \
1067	ENABLE_SME2_FOR_NS \
1068	ENABLE_SME_FOR_SWD \
1069	ENABLE_SPE_FOR_NS \
1070	ENABLE_SVE_FOR_NS \
1071	ENABLE_SVE_FOR_SWD \
1072	ENABLE_FEAT_RAS \
1073	FFH_SUPPORT \
1074	ENCRYPT_BL31 \
1075	ENCRYPT_BL32 \
1076	ERROR_DEPRECATED \
1077	FAULT_INJECTION_SUPPORT \
1078	GICV2_G0_FOR_EL3 \
1079	HANDLE_EA_EL3_FIRST_NS \
1080	HW_ASSISTED_COHERENCY \
1081	LOG_LEVEL \
1082	MEASURED_BOOT \
1083	DISCRETE_TPM \
1084	DICE_PROTECTION_ENVIRONMENT \
1085	DRTM_SUPPORT \
1086	NS_TIMER_SWITCH \
1087	PL011_GENERIC_UART \
1088	PLAT_${PLAT} \
1089	PROGRAMMABLE_RESET_ADDRESS \
1090	PSCI_EXTENDED_STATE_ID \
1091	PSCI_OS_INIT_MODE \
1092	ARCH_FEATURE_AVAILABILITY \
1093	RESET_TO_BL31 \
1094	RME_GPT_BITLOCK_BLOCK \
1095	RME_GPT_MAX_BLOCK \
1096	SEPARATE_CODE_AND_RODATA \
1097	SEPARATE_BL2_NOLOAD_REGION \
1098	SEPARATE_NOBITS_REGION \
1099	SEPARATE_RWDATA_REGION \
1100	SEPARATE_SIMD_SECTION \
1101	RECLAIM_INIT_CODE \
1102	SPD_${SPD} \
1103	SPIN_ON_BL1_EXIT \
1104	SPM_MM \
1105	SPMC_AT_EL3 \
1106	SPMC_AT_EL3_SEL0_SP \
1107	SPMD_SPM_AT_SEL2 \
1108	TRANSFER_LIST \
1109	TRUSTED_BOARD_BOOT \
1110	CRYPTO_SUPPORT \
1111	TRNG_SUPPORT \
1112	ERRATA_ABI_SUPPORT \
1113	ERRATA_NON_ARM_INTERCONNECT \
1114	USE_COHERENT_MEM \
1115	USE_DEBUGFS \
1116	ARM_IO_IN_DTB \
1117	SDEI_IN_FCONF \
1118	SEC_INT_DESC_IN_FCONF \
1119	USE_ROMLIB \
1120	USE_TBBR_DEFS \
1121	WARMBOOT_ENABLE_DCACHE_EARLY \
1122	RESET_TO_BL2 \
1123	BL2_RUNS_AT_EL3	\
1124	BL2_IN_XIP_MEM \
1125	BL2_INV_DCACHE \
1126	USE_SPINLOCK_CAS \
1127	ERRATA_SPECULATIVE_AT \
1128	ERRATA_SME_POWER_DOWN \
1129	RAS_TRAP_NS_ERR_REC_ACCESS \
1130	COT_DESC_IN_DTB \
1131	USE_SP804_TIMER \
1132	ENABLE_FEAT_RNG \
1133	ENABLE_FEAT_RNG_TRAP \
1134	ENABLE_FEAT_SB \
1135	ENABLE_FEAT_DIT \
1136	NR_OF_FW_BANKS \
1137	NR_OF_IMAGES_IN_FW_BANK \
1138	PSA_FWU_SUPPORT \
1139	PSA_FWU_METADATA_FW_STORE_DESC \
1140	ENABLE_BRBE_FOR_NS \
1141	ENABLE_TRBE_FOR_NS \
1142	ENABLE_SYS_REG_TRACE_FOR_NS \
1143	ENABLE_TRF_FOR_NS \
1144	ENABLE_FEAT_HCX \
1145	ENABLE_MPMM \
1146	FEAT_PABANDON \
1147	ENABLE_FEAT_FGT \
1148	ENABLE_FEAT_FGT2 \
1149	ENABLE_FEAT_FPMR \
1150	ENABLE_FEAT_ECV \
1151	ENABLE_FEAT_AMUv1p1 \
1152	ENABLE_FEAT_SEL2 \
1153	ENABLE_FEAT_VHE \
1154	ENABLE_FEAT_CSV2_2 \
1155	ENABLE_FEAT_CSV2_3 \
1156	ENABLE_FEAT_LS64_ACCDATA \
1157	ENABLE_FEAT_MEC \
1158	ENABLE_FEAT_PAN \
1159	ENABLE_FEAT_TCR2 \
1160	ENABLE_FEAT_THE \
1161	ENABLE_FEAT_S2PIE \
1162	ENABLE_FEAT_S1PIE \
1163	ENABLE_FEAT_S2POE \
1164	ENABLE_FEAT_S1POE \
1165	ENABLE_FEAT_SCTLR2 \
1166	ENABLE_FEAT_D128 \
1167	ENABLE_FEAT_GCS \
1168	ENABLE_FEAT_MOPS \
1169	ENABLE_FEAT_GCIE \
1170	ENABLE_FEAT_MTE2 \
1171	FEATURE_DETECTION \
1172	TWED_DELAY \
1173	ENABLE_FEAT_TWED \
1174	CONDITIONAL_CMO \
1175	IMPDEF_SYSREG_TRAP \
1176	SVE_VECTOR_LEN \
1177	ENABLE_SPMD_LP \
1178	PSA_CRYPTO	\
1179	ENABLE_CONSOLE_GETC \
1180	INIT_UNUSED_NS_EL2	\
1181	PLATFORM_REPORT_CTX_MEM_USE \
1182	EARLY_CONSOLE \
1183	PRESERVE_DSU_PMU_REGS \
1184	HOB_LIST \
1185	LFA_SUPPORT \
1186)))
1187
1188ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1189ifeq (${DEBUG}, 0)
1190        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1191        override PLATFORM_REPORT_CTX_MEM_USE := 0
1192endif
1193endif
1194
1195ifeq (${SANITIZE_UB},trap)
1196        $(eval $(call add_define,MONITOR_TRAPS))
1197endif #(SANITIZE_UB)
1198
1199# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1200ifdef EL3_PAYLOAD_BASE
1201        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1202else
1203# Define the PRELOADED_BL33_BASE flag only if it is provided and
1204# EL3_PAYLOAD_BASE is not defined, as it has priority.
1205	ifdef PRELOADED_BL33_BASE
1206                $(eval $(call add_define,PRELOADED_BL33_BASE))
1207	endif
1208endif #(EL3_PAYLOAD_BASE)
1209
1210# Define the DYN_DISABLE_AUTH flag only if set.
1211ifeq (${DYN_DISABLE_AUTH},1)
1212        $(eval $(call add_define,DYN_DISABLE_AUTH))
1213endif
1214
1215ifeq ($($(ARCH)-ld-id),arm-link)
1216        $(eval $(call add_define,USE_ARM_LINK))
1217endif
1218
1219# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1220ifeq (${SPD},spmd)
1221ifdef SP_LAYOUT_FILE
1222	-include $(BUILD_PLAT)/sp_gen.mk
1223	FIP_DEPS += sp
1224	CRT_DEPS += sp
1225	NEED_SP_PKG := yes
1226else
1227	ifeq (${SPMD_SPM_AT_SEL2},1)
1228                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1229	endif
1230endif #(SP_LAYOUT_FILE)
1231endif #(SPD)
1232
1233################################################################################
1234# Build targets
1235################################################################################
1236
1237.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
1238
1239all: msg_start
1240
1241msg_start:
1242	$(s)echo "Building ${PLAT}"
1243
1244ifeq (${ERROR_DEPRECATED},0)
1245# Check if deprecated declarations and cpp warnings should be treated as error or not.
1246ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
1247    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1248else
1249    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1250endif
1251endif #(!ERROR_DEPRECATED)
1252
1253$(eval $(call MAKE_LIB,c))
1254
1255# Expand build macros for the different images
1256ifeq (${NEED_BL1},yes)
1257BL1_SOURCES := $(sort ${BL1_SOURCES})
1258$(eval $(call MAKE_BL,bl1))
1259endif #(NEED_BL1)
1260
1261ifeq (${NEED_BL2},yes)
1262
1263ifeq (${RESET_TO_BL2}, 0)
1264FIP_BL2_ARGS := tb-fw
1265endif
1266
1267BL2_SOURCES := $(sort ${BL2_SOURCES})
1268
1269$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1270	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1271
1272endif #(NEED_BL2)
1273
1274ifeq (${NEED_SCP_BL2},yes)
1275$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1276endif #(NEED_SCP_BL2)
1277
1278ifeq (${NEED_BL31},yes)
1279BL31_SOURCES += ${SPD_SOURCES}
1280# Sort BL31 source files to remove duplicates
1281BL31_SOURCES := $(sort ${BL31_SOURCES})
1282ifneq (${DECRYPTION_SUPPORT},none)
1283$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1284	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1285else
1286$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1287	$(eval $(call MAKE_BL,bl31,soc-fw)))
1288endif #(DECRYPTION_SUPPORT)
1289endif #(NEED_BL31)
1290
1291# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1292# build system will call TOOL_ADD_IMG to print a warning message and abort the
1293# process. Note that the dependency on BL32 applies to the FIP only.
1294ifeq (${NEED_BL32},yes)
1295# Sort BL32 source files to remove duplicates
1296BL32_SOURCES := $(sort ${BL32_SOURCES})
1297BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1298
1299ifneq (${DECRYPTION_SUPPORT},none)
1300$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1301	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1302else
1303$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1304	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1305endif #(DECRYPTION_SUPPORT)
1306endif #(NEED_BL32)
1307
1308# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1309# needs to be built from RMM_SOURCES.
1310ifeq (${NEED_RMM},yes)
1311# Sort RMM source files to remove duplicates
1312RMM_SOURCES := $(sort ${RMM_SOURCES})
1313BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1314
1315$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1316	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1317endif #(NEED_RMM)
1318
1319# Add the BL33 image if required by the platform
1320ifeq (${NEED_BL33},yes)
1321$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1322endif #(NEED_BL33)
1323
1324ifeq (${NEED_BL2U},yes)
1325$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1326	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1327endif #(NEED_BL2U)
1328
1329# Expand build macros for the different images
1330ifeq (${NEED_FDT},yes)
1331    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1332
1333    ifneq (${INITRD_SIZE}${INITRD_PATH},)
1334        ifndef INITRD_BASE
1335            $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1336        endif
1337
1338        INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1339        initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1340
1341        define $(HW_CONFIG)-after +=
1342            $(s)echo "  INITRD  $(HW_CONFIG)"
1343            $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1344            $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1345        endef
1346    endif
1347endif #(NEED_FDT)
1348
1349# Add Secure Partition packages
1350ifeq (${NEED_SP_PKG},yes)
1351$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1352	$(if $(host-poetry),$(q)poetry -q install --no-root)
1353	$(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1354sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1355	$(s)echo
1356	$(s)echo "Built SP Images successfully"
1357	$(s)echo
1358endif #(NEED_SP_PKG)
1359
1360locate-checkpatch:
1361ifndef CHECKPATCH
1362	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1363else
1364ifeq (,$(wildcard ${CHECKPATCH}))
1365	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1366endif
1367endif #(CHECKPATCH)
1368
1369clean:
1370	$(s)echo "  CLEAN"
1371	$(q)rm -rf $(BUILD_PLAT)
1372	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1373	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1374	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1375	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1376
1377realclean distclean:
1378	$(s)echo "  REALCLEAN"
1379	$(q)rm -rf $(BUILD_BASE)
1380	$(q)rm -rf $(CURDIR)/cscope.*
1381	$(q)${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1382	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1383	$(q)${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1384	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1385
1386checkcodebase:		locate-checkpatch
1387	$(s)echo "  CHECKING STYLE"
1388	$(q)if test -d .git ; then						\
1389		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1390		while read GIT_FILE ;					\
1391		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1392		done ;							\
1393	else								\
1394		 find . -type f -not -iwholename "*.git*"		\
1395		 -not -iwholename "*build*"				\
1396		 -not -iwholename "*libfdt*"				\
1397		 -not -iwholename "*libc*"				\
1398		 -not -iwholename "*docs*"				\
1399		 -not -iwholename "*.rst"				\
1400		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1401	fi
1402
1403checkpatch:		locate-checkpatch
1404	$(s)echo "  CHECKING STYLE"
1405	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1406		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1407	fi
1408	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1409	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1410	do								\
1411		printf "\n[*] Checking style of '$$commit'\n\n";	\
1412		( git log --format=email "$$commit~..$$commit"		\
1413			-- ${CHECK_PATHS} ;				\
1414		  git diff --format=email "$$commit~..$$commit"		\
1415			-- ${CHECK_PATHS}; ) |				\
1416			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1417	done
1418
1419certtool: ${CRTTOOL}
1420
1421${CRTTOOL}: FORCE
1422	$(q)${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1423	$(s)echo
1424	$(s)echo "Built $@ successfully"
1425	$(s)echo
1426
1427ifneq (${GENERATE_COT},0)
1428certificates: ${CRT_DEPS} ${CRTTOOL}
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${FIPTOOL}: FORCE
1466	$(q)${MAKE} PLAT=${PLAT} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1467
1468$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB)
1469	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_SUPPORT=${CRYPTO_SUPPORT} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
1470
1471memmap: all
1472	$(if $(host-poetry),$(q)poetry -q install --no-root)
1473	$(q)$(if $(host-poetry),poetry run )memory symbols --root ${BUILD_PLAT}
1474
1475tl: ${BUILD_PLAT}/tl.bin
1476${BUILD_PLAT}/tl.bin: ${HW_CONFIG}
1477	$(if $(host-poetry),$(q)poetry -q install --no-root)
1478	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1479
1480doc:
1481	$(s)echo "  BUILD DOCUMENTATION"
1482	$(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1483	$(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} html
1484
1485enctool: ${ENCTOOL}
1486
1487${ENCTOOL}: FORCE
1488	$(q)${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1489	$(s)echo
1490	$(s)echo "Built $@ successfully"
1491	$(s)echo
1492
1493cscope:
1494	$(s)echo "  CSCOPE"
1495	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1496	$(q)cscope -b -q -k
1497
1498help:
1499	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1500	$(s)echo ""
1501	$(s)echo "PLAT is used to specify which platform you wish to build."
1502	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1503	$(s)echo ""
1504	$(s)echo "platform = ${PLATFORM_LIST}"
1505	$(s)echo ""
1506	$(s)echo "Please refer to the User Guide for a list of all supported options."
1507	$(s)echo "Note that the build system doesn't track dependencies for build "
1508	$(s)echo "options. Therefore, if any of the build options are changed "
1509	$(s)echo "from a previous build, a clean build must be performed."
1510	$(s)echo ""
1511	$(s)echo "Supported Targets:"
1512	$(s)echo "  all            Build all individual bootloader binaries"
1513	$(s)echo "  bl1            Build the BL1 binary"
1514	$(s)echo "  bl2            Build the BL2 binary"
1515	$(s)echo "  bl2u           Build the BL2U binary"
1516	$(s)echo "  bl31           Build the BL31 binary"
1517	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1518	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
1519	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1520	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
1521	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1522	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
1523	$(s)echo "  checkpatch     Check the coding style on changes in the current"
1524	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
1525	$(s)echo "  clean          Clean the build for the selected platform"
1526	$(s)echo "  cscope         Generate cscope index"
1527	$(s)echo "  distclean      Remove all build artifacts for all platforms"
1528	$(s)echo "  certtool       Build the Certificate generation tool"
1529	$(s)echo "  enctool        Build the Firmware encryption tool"
1530	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1531	$(s)echo "  sp             Build the Secure Partition Packages"
1532	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
1533	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1534	$(s)echo "  memmap         Print the memory map of the built binaries"
1535	$(s)echo "  doc            Build html based documentation using Sphinx tool"
1536	$(s)echo ""
1537	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1538	$(s)echo ""
1539	$(s)echo "example: build all targets for the FVP platform:"
1540	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1541
1542.PHONY: FORCE
1543FORCE:;
1544