xref: /rk3399_ARM-atf/Makefile (revision c925867ec1be039abb72a7d65bff1b6a85b3d67a)
1#
2# Copyright (c) 2013-2024, 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			:= 10
12VERSION_PATCH			:= 0	# Only used for LTS releases
13VERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
14
15# Default goal is build all images
16.DEFAULT_GOAL			:= all
17
18# Avoid any implicit propagation of command line variable definitions to
19# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
20# usage. Other command line options like "-s" are still propagated as usual.
21MAKEOVERRIDES =
22
23MAKE_HELPERS_DIRECTORY := make_helpers/
24include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
25include ${MAKE_HELPERS_DIRECTORY}build_env.mk
26
27################################################################################
28# Default values for build configurations, and their dependencies
29################################################################################
30
31include ${MAKE_HELPERS_DIRECTORY}defaults.mk
32
33# Assertions enabled for DEBUG builds by default
34ENABLE_ASSERTIONS		:= ${DEBUG}
35ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
36PLAT				:= ${DEFAULT_PLAT}
37
38################################################################################
39# Checkpatch script options
40################################################################################
41
42CHECKCODE_ARGS		:=	--no-patch
43# Do not check the coding style on imported library files or documentation files
44INC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
45					include/drivers/arm,		\
46					$(wildcard include/drivers/*)))
47INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
48					include/lib/libfdt		\
49					include/lib/libc,		\
50					$(wildcard include/lib/*)))
51INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
52					include/lib			\
53					include/drivers,		\
54					$(wildcard include/*)))
55LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
56					lib/compiler-rt			\
57					lib/libfdt%			\
58					lib/libc,			\
59					lib/zlib			\
60					$(wildcard lib/*)))
61ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
62					lib				\
63					include				\
64					docs				\
65					%.rst,				\
66					$(wildcard *)))
67CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
68				${INC_DIRS_TO_CHECK}			\
69				${INC_LIB_DIRS_TO_CHECK}		\
70				${LIB_DIRS_TO_CHECK}			\
71				${INC_DRV_DIRS_TO_CHECK}		\
72				${INC_ARM_DIRS_TO_CHECK}
73
74################################################################################
75# Process build options
76################################################################################
77
78# Verbose flag
79ifeq (${V},0)
80	Q:=@
81	ECHO:=@echo
82	CHECKCODE_ARGS	+=	--no-summary --terse
83else
84	Q:=
85	ECHO:=$(ECHO_QUIET)
86endif
87
88ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
89	Q:=@
90	ECHO:=$(ECHO_QUIET)
91endif
92
93export Q ECHO
94
95################################################################################
96# Toolchain
97################################################################################
98
99HOSTCC			:=	gcc
100export HOSTCC
101
102CC			:=	${CROSS_COMPILE}gcc
103CPP			:=	${CROSS_COMPILE}gcc -E
104AS			:=	${CROSS_COMPILE}gcc
105AR			:=	${CROSS_COMPILE}gcc-ar
106LINKER			:=	${CROSS_COMPILE}ld
107OC			:=	${CROSS_COMPILE}objcopy
108OD			:=	${CROSS_COMPILE}objdump
109DTC			:=	dtc
110
111# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH).
112ifneq ($(strip $(wildcard ${LD}.bfd) \
113	$(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),)
114LINKER			:=	${LINKER}.bfd
115endif
116
117################################################################################
118# Auxiliary tools (fiptool, cert_create, etc)
119################################################################################
120
121# Variables for use with Certificate Generation Tool
122CRTTOOLPATH		?=	tools/cert_create
123CRTTOOL			?=	${CRTTOOLPATH}/cert_create${BIN_EXT}
124
125# Variables for use with Firmware Encryption Tool
126ENCTOOLPATH		?=	tools/encrypt_fw
127ENCTOOL			?=	${ENCTOOLPATH}/encrypt_fw${BIN_EXT}
128
129# Variables for use with Firmware Image Package
130FIPTOOLPATH		?=	tools/fiptool
131FIPTOOL			?=	${FIPTOOLPATH}/fiptool${BIN_EXT}
132
133# Variables for use with sptool
134SPTOOLPATH		?=	tools/sptool
135SPTOOL			?=	${SPTOOLPATH}/sptool.py
136SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
137SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
138
139# Variables for use with ROMLIB
140ROMLIBPATH		?=	lib/romlib
141
142# Variable for use with Python
143PYTHON			?=	python3
144
145# Variables for use with documentation build using Sphinx tool
146DOCS_PATH		?=	docs
147
148################################################################################
149# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
150################################################################################
151ifeq (${ARM_ARCH_MAJOR},7)
152	target32-directive	= 	-target arm-none-eabi
153# Will set march-directive from platform configuration
154else
155	target32-directive	= 	-target armv8a-none-eabi
156endif #(ARM_ARCH_MAJOR)
157
158################################################################################
159# Get Architecture Feature Modifiers
160################################################################################
161arch-features		=	${ARM_ARCH_FEATURE}
162
163ifneq ($(findstring clang,$(notdir $(CC))),)
164	ifneq ($(findstring armclang,$(notdir $(CC))),)
165		TF_CFLAGS_aarch32	:=	-target arm-arm-none-eabi
166		TF_CFLAGS_aarch64	:=	-target aarch64-arm-none-eabi
167		LD			:=	$(LINKER)
168	else
169		TF_CFLAGS_aarch32	=	$(target32-directive)
170		TF_CFLAGS_aarch64	:=	-target aarch64-elf
171		LD			:=	$(shell $(CC) --print-prog-name ld.lld)
172
173		AR			:=	$(shell $(CC) --print-prog-name llvm-ar)
174		OD			:=	$(shell $(CC) --print-prog-name llvm-objdump)
175		OC			:=	$(shell $(CC) --print-prog-name llvm-objcopy)
176	endif
177
178	CPP		:=	$(CC) -E $(TF_CFLAGS_$(ARCH))
179	AS		:=	$(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH))
180else ifneq ($(findstring gcc,$(notdir $(CC))),)
181	ifeq ($(ENABLE_LTO),1)
182		# Enable LTO only for aarch64
183		ifeq (${ARCH},aarch64)
184			LTO_CFLAGS	=	-flto
185			# Use gcc as a wrapper for the ld, recommended for LTO
186			LINKER		:=	${CROSS_COMPILE}gcc
187		endif
188	endif
189	LD			=	$(LINKER)
190else
191	LD			=	$(LINKER)
192endif #(clang)
193
194# Process Debug flag
195$(eval $(call add_define,DEBUG))
196ifneq (${DEBUG}, 0)
197	BUILD_TYPE	:=	debug
198	TF_CFLAGS	+=	-g -gdwarf-4
199	ASFLAGS		+=	-g -Wa,-gdwarf-4
200
201	# Use LOG_LEVEL_INFO by default for debug builds
202	LOG_LEVEL	:=	40
203else
204	BUILD_TYPE	:=	release
205	# Use LOG_LEVEL_NOTICE by default for release builds
206	LOG_LEVEL	:=	20
207endif #(Debug)
208
209# Default build string (git branch and commit)
210ifeq (${BUILD_STRING},)
211	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
212endif
213VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
214
215ifeq (${AARCH32_INSTRUCTION_SET},A32)
216	TF_CFLAGS_aarch32	+=	-marm
217else ifeq (${AARCH32_INSTRUCTION_SET},T32)
218	TF_CFLAGS_aarch32	+=	-mthumb
219else
220        $(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET})
221endif #(AARCH32_INSTRUCTION_SET)
222
223TF_CFLAGS_aarch32	+=	-mno-unaligned-access
224TF_CFLAGS_aarch64	+=	-mgeneral-regs-only -mstrict-align
225
226##############################################################################
227# WARNINGS Configuration
228###############################################################################
229# General warnings
230WARNINGS		:=	-Wall -Wmissing-include-dirs -Wunused	\
231				-Wdisabled-optimization -Wvla -Wshadow	\
232				-Wredundant-decls
233# stricter warnings
234WARNINGS		+=	-Wextra -Wno-trigraphs
235# too verbose for generic build
236WARNINGS		+=	-Wno-missing-field-initializers \
237				-Wno-type-limits -Wno-sign-compare \
238# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
239WARNINGS		+=	-Wno-unused-parameter
240
241# Additional warnings
242# Level 1 - infrequent warnings we should have none of
243# full -Wextra
244WARNING1 += -Wsign-compare
245WARNING1 += -Wtype-limits
246WARNING1 += -Wmissing-field-initializers
247
248# Level 2 - problematic warnings that we want
249# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
250# TODO: disable just for them and move into default build
251WARNING2 += -Wold-style-definition
252WARNING2 += -Wmissing-prototypes
253WARNING2 += -Wmissing-format-attribute
254# TF-A aims to comply with this eventually. Effort too large at present
255WARNING2 += -Wundef
256# currently very involved and many platforms set this off
257WARNING2 += -Wunused-const-variable=2
258
259# Level 3 - very pedantic, frequently ignored
260WARNING3 := -Wbad-function-cast
261WARNING3 += -Waggregate-return
262WARNING3 += -Wnested-externs
263WARNING3 += -Wcast-align
264WARNING3 += -Wcast-qual
265WARNING3 += -Wconversion
266WARNING3 += -Wpacked
267WARNING3 += -Wpointer-arith
268WARNING3 += -Wswitch-default
269
270# Setting W is quite verbose and most warnings will be pre-existing issues
271# outside of the contributor's control. Don't fail the build on them so warnings
272# can be seen and hopefully addressed
273ifdef W
274	ifneq (${W},0)
275		E	 ?= 0
276	endif
277endif
278
279ifeq (${W},1)
280	WARNINGS += $(WARNING1)
281else ifeq (${W},2)
282	WARNINGS += $(WARNING1) $(WARNING2)
283else ifeq (${W},3)
284	WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
285endif #(W)
286
287# Compiler specific warnings
288ifeq ($(findstring clang,$(notdir $(CC))),)
289# not using clang
290WARNINGS	+=		-Wunused-but-set-variable -Wmaybe-uninitialized	\
291				-Wpacked-bitfield-compat -Wshift-overflow=2 \
292				-Wlogical-op
293
294# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
295TF_CFLAGS		+= 	$(call cc_option, --param=min-pagesize=0)
296
297ifeq ($(HARDEN_SLS), 1)
298        TF_CFLAGS_aarch64       +=      $(call cc_option, -mharden-sls=all)
299endif
300
301else
302# using clang
303WARNINGS	+=		-Wshift-overflow -Wshift-sign-overflow \
304				-Wlogical-op-parentheses
305endif #(Clang Warning)
306
307ifneq (${E},0)
308	ERRORS := -Werror
309endif #(E)
310
311################################################################################
312# Compiler and Linker Directives
313################################################################################
314CPPFLAGS		=	${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc	\
315				$(ERRORS) $(WARNINGS)
316ASFLAGS			+=	$(CPPFLAGS)                 			\
317				-ffreestanding -Wa,--fatal-warnings
318TF_CFLAGS		+=	$(CPPFLAGS) $(TF_CFLAGS_$(ARCH))		\
319				-ffunction-sections -fdata-sections		\
320				-ffreestanding -fno-builtin -fno-common		\
321				-Os -std=gnu99
322
323ifeq (${SANITIZE_UB},on)
324	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover
325endif #(${SANITIZE_UB},on)
326
327ifeq (${SANITIZE_UB},trap)
328	TF_CFLAGS	+=	-fsanitize=undefined -fno-sanitize-recover	\
329				-fsanitize-undefined-trap-on-error
330endif #(${SANITIZE_UB},trap)
331
332GCC_V_OUTPUT		:=	$(shell $(CC) -v 2>&1)
333
334TF_LDFLAGS		+=	-z noexecstack
335
336# LD = armlink
337ifneq ($(findstring armlink,$(notdir $(LD))),)
338	TF_LDFLAGS		+=	--diag_error=warning --lto_level=O1
339	TF_LDFLAGS		+=	--remove --info=unused,unusedsymbols
340	TF_LDFLAGS		+=	$(TF_LDFLAGS_$(ARCH))
341
342# LD = gcc (used when GCC LTO is enabled)
343else ifneq ($(findstring gcc,$(notdir $(LD))),)
344	# Pass ld options with Wl or Xlinker switches
345	TF_LDFLAGS		+=	$(call ld_option,-Xlinker --no-warn-rwx-segments)
346	TF_LDFLAGS		+=	-Wl,--fatal-warnings -O1
347	TF_LDFLAGS		+=	-Wl,--gc-sections
348
349	TF_LDFLAGS		+=	-Wl,-z,common-page-size=4096 #Configure page size constants
350	TF_LDFLAGS		+=	-Wl,-z,max-page-size=4096
351	TF_LDFLAGS		+=	-Wl,--build-id=none
352
353	ifeq ($(ENABLE_LTO),1)
354		ifeq (${ARCH},aarch64)
355			TF_LDFLAGS	+=	-flto -fuse-linker-plugin
356		endif
357	endif #(ENABLE_LTO)
358
359# GCC automatically adds fix-cortex-a53-843419 flag when used to link
360# which breaks some builds, so disable if errata fix is not explicitly enabled
361	ifeq (${ARCH},aarch64)
362		ifneq (${ERRATA_A53_843419},1)
363			TF_LDFLAGS	+= 	-mno-fix-cortex-a53-843419
364		endif
365	endif
366	TF_LDFLAGS		+= 	-nostdlib
367	TF_LDFLAGS		+=	$(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
368
369# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
370else
371# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
372# are not loaded by a elf loader.
373	TF_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
374	TF_LDFLAGS		+=	-O1
375	TF_LDFLAGS		+=	--gc-sections
376
377	TF_LDFLAGS		+=	-z common-page-size=4096 # Configure page size constants
378	TF_LDFLAGS		+=	-z max-page-size=4096
379	TF_LDFLAGS		+=	--build-id=none
380
381# ld.lld doesn't recognize the errata flags,
382# therefore don't add those in that case.
383# ld.lld reports section type mismatch warnings,
384# therefore don't add --fatal-warnings to it.
385	ifeq ($(findstring ld.lld,$(notdir $(LD))),)
386		TF_LDFLAGS	+=	$(TF_LDFLAGS_$(ARCH)) --fatal-warnings
387	endif
388
389endif #(LD = armlink)
390
391################################################################################
392# Setup ARCH_MAJOR/MINOR before parsing arch_features.
393################################################################################
394ifeq (${ENABLE_RME},1)
395	ARM_ARCH_MAJOR := 8
396	ARM_ARCH_MINOR := 6
397endif
398
399################################################################################
400# Common sources and include directories
401################################################################################
402include lib/compiler-rt/compiler-rt.mk
403
404BL_COMMON_SOURCES	+=	common/bl_common.c			\
405				common/tf_log.c				\
406				common/${ARCH}/debug.S			\
407				drivers/console/multi_console.c		\
408				lib/${ARCH}/cache_helpers.S		\
409				lib/${ARCH}/misc_helpers.S		\
410				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
411				plat/common/plat_bl_common.c		\
412				plat/common/plat_log_common.c		\
413				plat/common/${ARCH}/plat_common.c	\
414				plat/common/${ARCH}/platform_helpers.S	\
415				${COMPILER_RT_SRCS}
416
417ifeq ($(notdir $(CC)),armclang)
418	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
419endif
420
421ifeq (${SANITIZE_UB},on)
422	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
423endif
424
425INCLUDES		+=	-Iinclude				\
426				-Iinclude/arch/${ARCH}			\
427				-Iinclude/lib/cpus/${ARCH}		\
428				-Iinclude/lib/el3_runtime/${ARCH}	\
429				${PLAT_INCLUDES}			\
430				${SPD_INCLUDES}
431
432DTC_FLAGS		+=	-I dts -O dtb
433DTC_CPPFLAGS		+=	-P -nostdinc $(INCLUDES) -Ifdts -undef \
434				-x assembler-with-cpp $(DEFINES)
435
436include common/backtrace/backtrace.mk
437
438################################################################################
439# Generic definitions
440################################################################################
441include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
442
443ifeq (${BUILD_BASE},)
444     BUILD_BASE		:=	./build
445endif
446BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
447
448SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
449
450# Platforms providing their own TBB makefile may override this value
451INCLUDE_TBBR_MK		:=	1
452
453################################################################################
454# Include SPD Makefile if one has been specified
455################################################################################
456
457ifneq (${SPD},none)
458	ifeq (${ARCH},aarch32)
459                $(error "Error: SPD is incompatible with AArch32.")
460	endif
461
462	ifdef EL3_PAYLOAD_BASE
463                $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.")
464                $(warning "The SPD and its BL32 companion will be present but \
465                ignored.")
466	endif
467
468	ifeq (${SPD},spmd)
469	# SPMD is located in std_svc directory
470		SPD_DIR := std_svc
471
472		ifeq ($(SPMD_SPM_AT_SEL2),1)
473			CTX_INCLUDE_EL2_REGS := 1
474			ifeq ($(SPMC_AT_EL3),1)
475                                $(error SPM cannot be enabled in both S-EL2 and EL3.)
476			endif
477		endif
478
479		ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
480			DTC_CPPFLAGS	+=	-DOPTEE_SP_FW_CONFIG
481		endif
482
483		ifeq ($(TS_SP_FW_CONFIG),1)
484		DTC_CPPFLAGS	+=	-DTS_SP_FW_CONFIG
485		endif
486
487		ifneq ($(ARM_BL2_SP_LIST_DTS),)
488		DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
489		endif
490
491		ifneq ($(SP_LAYOUT_FILE),)
492		BL2_ENABLE_SP_LOAD := 1
493		endif
494
495		ifeq ($(SPMC_AT_EL3_SEL0_SP),1)
496			ifneq ($(SPMC_AT_EL3),1)
497			$(error SEL0 SP cannot be enabled without SPMC at EL3)
498			endif
499		endif
500	else
501		# All other SPDs in spd directory
502		SPD_DIR := spd
503	endif #(SPD)
504
505	# We expect to locate an spd.mk under the specified SPD directory
506	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
507
508	ifeq (${SPD_MAKE},)
509                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
510	endif
511        $(info Including ${SPD_MAKE})
512        include ${SPD_MAKE}
513
514	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
515	# Makefile would set NEED_BL32 to "yes". In this case, the build system
516	# supports two mutually exclusive options:
517	# * BL32 is built from source: then BL32_SOURCES must contain the list
518	#   of source files to build BL32
519	# * BL32 is a prebuilt binary: then BL32 must point to the image file
520	#   that will be included in the FIP
521	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
522	# over the sources.
523endif #(SPD=none)
524
525ifeq (${ENABLE_SPMD_LP}, 1)
526ifneq (${SPD},spmd)
527        $(error Error: ENABLE_SPMD_LP requires SPD=spmd.)
528endif
529ifeq ($(SPMC_AT_EL3),1)
530        $(error SPMC at EL3 not supported when enabling SPMD Logical partitions.)
531endif
532endif
533
534################################################################################
535# Process BRANCH_PROTECTION value and set
536# Pointer Authentication and Branch Target Identification flags
537################################################################################
538ifeq (${BRANCH_PROTECTION},0)
539	# Default value turns off all types of branch protection
540	BP_OPTION := none
541else ifneq (${ARCH},aarch64)
542        $(error BRANCH_PROTECTION requires AArch64)
543else ifeq (${BRANCH_PROTECTION},1)
544	# Enables all types of branch protection features
545	BP_OPTION := standard
546	ENABLE_BTI := 1
547	ENABLE_PAUTH := 1
548else ifeq (${BRANCH_PROTECTION},2)
549	# Return address signing to its standard level
550	BP_OPTION := pac-ret
551	ENABLE_PAUTH := 1
552else ifeq (${BRANCH_PROTECTION},3)
553	# Extend the signing to include leaf functions
554	BP_OPTION := pac-ret+leaf
555	ENABLE_PAUTH := 1
556else ifeq (${BRANCH_PROTECTION},4)
557	# Turn on branch target identification mechanism
558	BP_OPTION := bti
559	ENABLE_BTI := 1
560else
561        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
562endif #(BRANCH_PROTECTION)
563
564ifeq ($(ENABLE_PAUTH),1)
565	CTX_INCLUDE_PAUTH_REGS := 1
566endif
567ifneq (${BP_OPTION},none)
568	TF_CFLAGS_aarch64	+=	-mbranch-protection=${BP_OPTION}
569endif #(BP_OPTION)
570
571# Pointer Authentication sources
572ifeq (${ENABLE_PAUTH}, 1)
573# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
574# Pauth support. As it's not secure, it must be reimplemented for real platforms
575	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth_helpers.S
576endif
577
578################################################################################
579# Include the platform specific Makefile after the SPD Makefile (the platform
580# makefile may use all previous definitions in this file)
581################################################################################
582include ${PLAT_MAKEFILE_FULL}
583
584################################################################################
585# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
586# platform.
587################################################################################
588include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
589
590####################################################
591# Enable required options for Memory Stack Tagging.
592####################################################
593
594# Currently, these options are enabled only for clang and armclang compiler.
595ifeq (${SUPPORT_STACK_MEMTAG},yes)
596    ifdef mem_tag_arch_support
597        # Check for armclang and clang compilers
598        ifneq ( ,$(filter $(notdir $(CC)),armclang clang))
599        # Add "memtag" architecture feature modifier if not specified
600            ifeq ( ,$(findstring memtag,$(arch-features)))
601                arch-features	:=	$(arch-features)+memtag
602            endif	# memtag
603            ifeq ($(notdir $(CC)),armclang)
604                TF_CFLAGS	+=	-mmemtag-stack
605            else ifeq ($(notdir $(CC)),clang)
606                TF_CFLAGS	+=	-fsanitize=memtag
607            endif	# armclang
608        endif
609    else
610        $(error "Error: stack memory tagging is not supported for  \
611        architecture ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a")
612	endif #(mem_tag_arch_support)
613endif #(SUPPORT_STACK_MEMTAG)
614
615################################################################################
616# RME dependent flags configuration, Enable optional features for RME.
617################################################################################
618# FEAT_RME
619ifeq (${ENABLE_RME},1)
620	# RME doesn't support BRBE
621	ENABLE_BRBE_FOR_NS := 0
622
623	# RME doesn't support PIE
624	ifneq (${ENABLE_PIE},0)
625                $(error ENABLE_RME does not support PIE)
626	endif
627
628	# RME doesn't support BRBE
629	ifneq (${ENABLE_BRBE_FOR_NS},0)
630                $(error ENABLE_RME does not support BRBE.)
631	endif
632
633	# RME requires AARCH64
634	ifneq (${ARCH},aarch64)
635                $(error ENABLE_RME requires AArch64)
636	endif
637
638	# RME requires el2 context to be saved for now.
639	CTX_INCLUDE_EL2_REGS := 1
640	CTX_INCLUDE_AARCH32_REGS := 0
641	CTX_INCLUDE_PAUTH_REGS := 1
642
643	# RME enables CSV2_2 extension by default.
644	ENABLE_FEAT_CSV2_2 = 1
645endif #(FEAT_RME)
646
647################################################################################
648# Include rmmd Makefile if RME is enabled
649################################################################################
650ifneq (${ENABLE_RME},0)
651	ifneq (${ARCH},aarch64)
652                $(error ENABLE_RME requires AArch64)
653	endif
654	ifeq ($(SPMC_AT_EL3),1)
655                $(error SPMC_AT_EL3 and ENABLE_RME cannot both be enabled.)
656	endif
657
658	ifneq (${SPD}, none)
659		ifneq (${SPD}, spmd)
660                        $(error ENABLE_RME is incompatible with SPD=${SPD}. Use SPD=spmd)
661		endif
662	endif
663include services/std_svc/rmmd/rmmd.mk
664$(warning "RME is an experimental feature")
665endif
666
667ifeq (${CTX_INCLUDE_EL2_REGS}, 1)
668	ifeq (${SPD},none)
669		ifeq (${ENABLE_RME},0)
670                        $(error CTX_INCLUDE_EL2_REGS is available only when SPD \
671                        or RME is enabled)
672		endif
673	endif
674endif
675
676################################################################################
677# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
678# up with appropriate march values for compiler.
679################################################################################
680include ${MAKE_HELPERS_DIRECTORY}march.mk
681
682TF_CFLAGS   +=	$(march-directive)
683ASFLAGS		+=	$(march-directive)
684
685# This internal flag is common option which is set to 1 for scenarios
686# when the BL2 is running in EL3 level. This occurs in two scenarios -
687# 4 world system running BL2 at EL3 and two world system without BL1 running
688# BL2 in EL3
689
690ifeq (${RESET_TO_BL2},1)
691	BL2_RUNS_AT_EL3	:=	1
692	ifeq (${ENABLE_RME},1)
693                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
694                supported at the moment.)
695	endif
696else ifeq (${ENABLE_RME},1)
697	BL2_RUNS_AT_EL3	:=	1
698else
699	BL2_RUNS_AT_EL3	:=	0
700endif
701
702# This internal flag is set to 1 when Firmware First handling of External aborts
703# is required by lowe ELs. Currently only NS requires this support.
704ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
705	FFH_SUPPORT := 1
706else
707	FFH_SUPPORT := 0
708endif
709
710$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT}))
711
712ifeq (${ARM_ARCH_MAJOR},7)
713include make_helpers/armv7-a-cpus.mk
714endif
715
716PIE_FOUND		:=	$(findstring --enable-default-pie,${GCC_V_OUTPUT})
717ifneq ($(PIE_FOUND),)
718	TF_CFLAGS	+=	-fno-PIE
719ifneq ($(findstring gcc,$(notdir $(LD))),)
720	TF_LDFLAGS	+=	-no-pie
721endif
722endif #(PIE_FOUND)
723
724ifneq ($(findstring gcc,$(notdir $(LD))),)
725	PIE_LDFLAGS	+=	-Wl,-pie -Wl,--no-dynamic-linker
726else
727	PIE_LDFLAGS	+=	-pie --no-dynamic-linker
728endif
729
730ifeq ($(ENABLE_PIE),1)
731	ifeq ($(RESET_TO_BL2),1)
732		ifneq ($(BL2_IN_XIP_MEM),1)
733			BL2_CPPFLAGS	+=	-fpie
734			BL2_CFLAGS	+=	-fpie
735			BL2_LDFLAGS	+=	$(PIE_LDFLAGS)
736		endif #(BL2_IN_XIP_MEM)
737	endif #(RESET_TO_BL2)
738	BL31_CPPFLAGS	+=	-fpie
739	BL31_CFLAGS 	+=	-fpie
740	BL31_LDFLAGS	+=	$(PIE_LDFLAGS)
741
742	BL32_CPPFLAGS	+=	-fpie
743	BL32_CFLAGS	+=	-fpie
744	BL32_LDFLAGS	+=	$(PIE_LDFLAGS)
745endif #(ENABLE_PIE)
746
747BL1_CPPFLAGS  += -DREPORT_ERRATA=${DEBUG}
748BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
749BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
750
751BL1_CPPFLAGS += -DIMAGE_AT_EL3
752ifeq ($(RESET_TO_BL2),1)
753	BL2_CPPFLAGS += -DIMAGE_AT_EL3
754else
755	BL2_CPPFLAGS += -DIMAGE_AT_EL1
756endif #(RESET_TO_BL2)
757
758ifeq (${ARCH},aarch64)
759	BL2U_CPPFLAGS += -DIMAGE_AT_EL1
760	BL31_CPPFLAGS += -DIMAGE_AT_EL3
761	BL32_CPPFLAGS += -DIMAGE_AT_EL1
762else
763	BL32_CPPFLAGS += -DIMAGE_AT_EL3
764endif
765
766# Include the CPU specific operations makefile, which provides default
767# values for all CPU errata workarounds and CPU specific optimisations.
768# This can be overridden by the platform.
769include lib/cpus/cpu-ops.mk
770
771################################################################################
772# Build `AARCH32_SP` as BL32 image for AArch32
773################################################################################
774ifeq (${ARCH},aarch32)
775        NEED_BL32 := yes
776
777        ifneq (${AARCH32_SP},none)
778        # We expect to locate an sp.mk under the specified AARCH32_SP directory
779		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
780
781                ifeq (${AARCH32_SP_MAKE},)
782                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
783                endif
784                $(info Including ${AARCH32_SP_MAKE})
785                include ${AARCH32_SP_MAKE}
786        endif
787endif #(ARCH=aarch32)
788
789################################################################################
790# Include libc if not overridden
791################################################################################
792ifeq (${OVERRIDE_LIBC},0)
793include lib/libc/libc.mk
794endif
795
796################################################################################
797# Check incompatible options and dependencies
798################################################################################
799
800# USE_DEBUGFS experimental feature recommended only in debug builds
801ifeq (${USE_DEBUGFS},1)
802        ifeq (${DEBUG},1)
803                $(warning DEBUGFS experimental feature is enabled.)
804        else
805                $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY)
806        endif
807endif #(USE_DEBUGFS)
808
809# USE_SPINLOCK_CAS requires AArch64 build
810ifeq (${USE_SPINLOCK_CAS},1)
811        ifneq (${ARCH},aarch64)
812               $(error USE_SPINLOCK_CAS requires AArch64)
813        endif
814endif #(USE_SPINLOCK_CAS)
815
816# The cert_create tool cannot generate certificates individually, so we use the
817# target 'certificates' to create them all
818ifneq (${GENERATE_COT},0)
819        FIP_DEPS += certificates
820        FWU_FIP_DEPS += fwu_certificates
821endif
822
823ifneq (${DECRYPTION_SUPPORT},none)
824	ENC_ARGS += -f ${FW_ENC_STATUS}
825	ENC_ARGS += -k ${ENC_KEY}
826	ENC_ARGS += -n ${ENC_NONCE}
827	FIP_DEPS += enctool
828	FWU_FIP_DEPS += enctool
829endif #(DECRYPTION_SUPPORT)
830
831ifdef EL3_PAYLOAD_BASE
832	ifdef PRELOADED_BL33_BASE
833                $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \
834		incompatible build options. EL3_PAYLOAD_BASE has priority.")
835	endif
836	ifneq (${GENERATE_COT},0)
837                $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible \
838                build options.")
839	endif
840	ifneq (${TRUSTED_BOARD_BOOT},0)
841                $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are \
842                incompatible \ build options.")
843	endif
844endif #(EL3_PAYLOAD_BASE)
845
846ifeq (${NEED_BL33},yes)
847	ifdef EL3_PAYLOAD_BASE
848                $(warning "BL33 image is not needed when option \
849                BL33_PAYLOAD_BASE is used and won't be added to the FIP file.")
850	endif
851	ifdef PRELOADED_BL33_BASE
852                $(warning "BL33 image is not needed when option \
853                PRELOADED_BL33_BASE is used and won't be added to the FIP file.")
854	endif
855endif #(NEED_BL33)
856
857# When building for systems with hardware-assisted coherency, there's no need to
858# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too.
859ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1)
860        $(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY)
861endif
862
863#For now, BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is 1.
864ifeq ($(RESET_TO_BL2)-$(BL2_IN_XIP_MEM),0-1)
865        $(error "BL2_IN_XIP_MEM is only supported when RESET_TO_BL2 is enabled")
866endif
867
868# RAS_EXTENSION is deprecated, provide alternate build options
869ifeq ($(RAS_EXTENSION),1)
870        $(error "RAS_EXTENSION is now deprecated, please use ENABLE_FEAT_RAS \
871        and HANDLE_EA_EL3_FIRST_NS instead")
872endif
873
874
875# When FAULT_INJECTION_SUPPORT is used, require that FEAT_RAS is enabled
876ifeq ($(FAULT_INJECTION_SUPPORT),1)
877	ifeq ($(ENABLE_FEAT_RAS),0)
878                $(error For FAULT_INJECTION_SUPPORT, ENABLE_FEAT_RAS must not be 0)
879	endif
880endif #(FAULT_INJECTION_SUPPORT)
881
882# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1
883ifeq ($(DYN_DISABLE_AUTH), 1)
884	ifeq (${TRUSTED_BOARD_BOOT}, 0)
885                $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH \
886                to be set.")
887	endif
888endif #(DYN_DISABLE_AUTH)
889
890ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
891# Support authentication verification and hash calculation
892	CRYPTO_SUPPORT := 3
893else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
894# Support authentication verification and hash calculation
895	CRYPTO_SUPPORT := 3
896else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
897# Support hash calculation only
898	CRYPTO_SUPPORT := 2
899else ifeq (${TRUSTED_BOARD_BOOT},1)
900# Support authentication verification only
901	CRYPTO_SUPPORT := 1
902else
903	CRYPTO_SUPPORT := 0
904endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
905
906# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled.
907ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1)
908        $(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled")
909endif
910
911# If pointer authentication is used in the firmware, make sure that all the
912# registers associated to it are also saved and restored.
913# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1.
914ifeq ($(ENABLE_PAUTH),1)
915	ifeq ($(CTX_INCLUDE_PAUTH_REGS),0)
916                $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1)
917	endif
918endif #(ENABLE_PAUTH)
919
920ifeq ($(CTX_INCLUDE_PAUTH_REGS),1)
921	ifneq (${ARCH},aarch64)
922                $(error CTX_INCLUDE_PAUTH_REGS requires AArch64)
923	endif
924endif #(CTX_INCLUDE_PAUTH_REGS)
925
926ifeq ($(PSA_FWU_SUPPORT),1)
927        $(info PSA_FWU_SUPPORT is an experimental feature)
928endif #(PSA_FWU_SUPPORT)
929
930ifeq ($(FEATURE_DETECTION),1)
931        $(info FEATURE_DETECTION is an experimental feature)
932endif #(FEATURE_DETECTION)
933
934ifneq ($(ENABLE_SME2_FOR_NS), 0)
935	ifeq (${ENABLE_SME_FOR_NS}, 0)
936                $(warning "ENABLE_SME2_FOR_NS requires ENABLE_SME_FOR_NS also \
937                to be set")
938                $(warning "Forced ENABLE_SME_FOR_NS=1")
939		override ENABLE_SME_FOR_NS	:= 1
940	endif
941endif #(ENABLE_SME2_FOR_NS)
942
943ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1)
944	ifeq (${ALLOW_RO_XLAT_TABLES}, 1)
945                $(error "ALLOW_RO_XLAT_TABLES requires translation tables \
946                library v2")
947	endif
948endif #(ARM_XLAT_TABLES_LIB_V1)
949
950ifneq (${DECRYPTION_SUPPORT},none)
951	ifeq (${TRUSTED_BOARD_BOOT}, 0)
952                $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT \
953                to be set)
954	endif
955endif #(DECRYPTION_SUPPORT)
956
957# Ensure that no Aarch64-only features are enabled in Aarch32 build
958ifeq (${ARCH},aarch32)
959
960	# SME/SVE only supported on AArch64
961	ifneq (${ENABLE_SME_FOR_NS},0)
962                $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32")
963	endif
964
965	ifeq (${ENABLE_SVE_FOR_NS},1)
966		# Warning instead of error due to CI dependency on this
967                $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32")
968	endif
969
970	# BRBE is not supported in AArch32
971	ifeq (${ENABLE_BRBE_FOR_NS},1)
972                $(error "ENABLE_BRBE_FOR_NS cannot be used with ARCH=aarch32")
973	endif
974
975	# FEAT_RNG_TRAP is not supported in AArch32
976	ifeq (${ENABLE_FEAT_RNG_TRAP},1)
977                $(error "ENABLE_FEAT_RNG_TRAP cannot be used with ARCH=aarch32")
978	endif
979endif #(ARCH=aarch32)
980
981ifneq (${ENABLE_SME_FOR_NS},0)
982	ifeq (${ENABLE_SVE_FOR_NS},0)
983                $(error "ENABLE_SME_FOR_NS requires ENABLE_SVE_FOR_NS")
984	endif
985endif #(ENABLE_SME_FOR_NS)
986
987# Secure SME/SVE requires the non-secure component as well
988ifeq (${ENABLE_SME_FOR_SWD},1)
989	ifeq (${ENABLE_SME_FOR_NS},0)
990                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS")
991	endif
992	ifeq (${ENABLE_SVE_FOR_SWD},0)
993                $(error "ENABLE_SME_FOR_SWD requires ENABLE_SVE_FOR_SWD")
994	endif
995endif #(ENABLE_SME_FOR_SWD)
996
997ifeq (${ENABLE_SVE_FOR_SWD},1)
998	ifeq (${ENABLE_SVE_FOR_NS},0)
999                $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS")
1000	endif
1001endif #(ENABLE_SVE_FOR_SWD)
1002
1003# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does
1004# its own context management including FPU registers.
1005ifeq (${CTX_INCLUDE_FPREGS},1)
1006	ifneq (${ENABLE_SME_FOR_NS},0)
1007                $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1008	endif
1009
1010	ifeq (${ENABLE_SVE_FOR_NS},1)
1011		# Warning instead of error due to CI dependency on this
1012                $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS")
1013                $(warning "Forced ENABLE_SVE_FOR_NS=0")
1014		override ENABLE_SVE_FOR_NS	:= 0
1015	endif
1016endif #(CTX_INCLUDE_FPREGS)
1017
1018ifeq ($(DRTM_SUPPORT),1)
1019        $(info DRTM_SUPPORT is an experimental feature)
1020endif
1021
1022ifeq (${TRANSFER_LIST},1)
1023        $(info TRANSFER_LIST is an experimental feature)
1024endif
1025
1026ifeq (${ENABLE_RME},1)
1027	ifneq (${SEPARATE_CODE_AND_RODATA},1)
1028                $(error `ENABLE_RME=1` requires `SEPARATE_CODE_AND_RODATA=1`)
1029	endif
1030endif
1031
1032ifeq ($(PSA_CRYPTO),1)
1033        $(info PSA_CRYPTO is an experimental feature)
1034endif
1035
1036################################################################################
1037# Process platform overrideable behaviour
1038################################################################################
1039
1040ifdef BL1_SOURCES
1041	NEED_BL1 := yes
1042endif #(BL1_SOURCES)
1043
1044ifdef BL2_SOURCES
1045	NEED_BL2 := yes
1046
1047	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
1048	# Certificate generation tools. This flag can be overridden by the platform.
1049	ifdef EL3_PAYLOAD_BASE
1050		# If booting an EL3 payload there is no need for a BL33 image
1051		# in the FIP file.
1052		NEED_BL33		:=	no
1053	else
1054		ifdef PRELOADED_BL33_BASE
1055			# If booting a BL33 preloaded image there is no need of
1056			# another one in the FIP file.
1057			NEED_BL33		:=	no
1058		else
1059			NEED_BL33		?=	yes
1060		endif
1061	endif
1062endif #(BL2_SOURCES)
1063
1064ifdef BL2U_SOURCES
1065	NEED_BL2U := yes
1066endif #(BL2U_SOURCES)
1067
1068# If SCP_BL2 is given, we always want FIP to include it.
1069ifdef SCP_BL2
1070	NEED_SCP_BL2		:=	yes
1071endif #(SCP_BL2)
1072
1073# For AArch32, BL31 is not currently supported.
1074ifneq (${ARCH},aarch32)
1075	ifdef BL31_SOURCES
1076	# When booting an EL3 payload, there is no need to compile the BL31
1077	# image nor put it in the FIP.
1078		ifndef EL3_PAYLOAD_BASE
1079			NEED_BL31 := yes
1080		endif
1081	endif
1082endif #(ARCH=aarch64)
1083
1084# Process TBB related flags
1085ifneq (${GENERATE_COT},0)
1086	# Common cert_create options
1087	ifneq (${CREATE_KEYS},0)
1088                $(eval CRT_ARGS += -n)
1089                $(eval FWU_CRT_ARGS += -n)
1090		ifneq (${SAVE_KEYS},0)
1091                        $(eval CRT_ARGS += -k)
1092                        $(eval FWU_CRT_ARGS += -k)
1093		endif
1094	endif
1095	# Include TBBR makefile (unless the platform indicates otherwise)
1096	ifeq (${INCLUDE_TBBR_MK},1)
1097                include make_helpers/tbbr/tbbr_tools.mk
1098	endif
1099endif #(GENERATE_COT)
1100
1101ifneq (${FIP_ALIGN},0)
1102	FIP_ARGS += --align ${FIP_ALIGN}
1103endif #(FIP_ALIGN)
1104
1105ifdef FDT_SOURCES
1106	NEED_FDT := yes
1107endif #(FDT_SOURCES)
1108
1109################################################################################
1110# Include libraries' Makefile that are used in all BL
1111################################################################################
1112
1113include lib/stack_protector/stack_protector.mk
1114
1115################################################################################
1116# Include BL specific makefiles
1117################################################################################
1118
1119ifeq (${NEED_BL1},yes)
1120include bl1/bl1.mk
1121endif
1122
1123ifeq (${NEED_BL2},yes)
1124include bl2/bl2.mk
1125endif
1126
1127ifeq (${NEED_BL2U},yes)
1128include bl2u/bl2u.mk
1129endif
1130
1131ifeq (${NEED_BL31},yes)
1132include bl31/bl31.mk
1133endif
1134
1135################################################################################
1136# Build options checks
1137################################################################################
1138
1139# Boolean_Flags
1140$(eval $(call assert_booleans,\
1141    $(sort \
1142	ALLOW_RO_XLAT_TABLES \
1143	BL2_ENABLE_SP_LOAD \
1144	COLD_BOOT_SINGLE_CPU \
1145	CREATE_KEYS \
1146	CTX_INCLUDE_AARCH32_REGS \
1147	CTX_INCLUDE_FPREGS \
1148	CTX_INCLUDE_EL2_REGS \
1149	CTX_INCLUDE_MPAM_REGS \
1150	DEBUG \
1151	DYN_DISABLE_AUTH \
1152	EL3_EXCEPTION_HANDLING \
1153	ENABLE_AMU_AUXILIARY_COUNTERS \
1154	ENABLE_AMU_FCONF \
1155	AMU_RESTRICT_COUNTERS \
1156	ENABLE_ASSERTIONS \
1157	ENABLE_PIE \
1158	ENABLE_PMF \
1159	ENABLE_PSCI_STAT \
1160	ENABLE_RUNTIME_INSTRUMENTATION \
1161	ENABLE_SME_FOR_SWD \
1162	ENABLE_SVE_FOR_SWD \
1163	ENABLE_FEAT_RAS	\
1164	FFH_SUPPORT	\
1165	ERROR_DEPRECATED \
1166	FAULT_INJECTION_SUPPORT \
1167	GENERATE_COT \
1168	GICV2_G0_FOR_EL3 \
1169	HANDLE_EA_EL3_FIRST_NS \
1170	HARDEN_SLS \
1171	HW_ASSISTED_COHERENCY \
1172	MEASURED_BOOT \
1173	DRTM_SUPPORT \
1174	NS_TIMER_SWITCH \
1175	OVERRIDE_LIBC \
1176	PL011_GENERIC_UART \
1177	PROGRAMMABLE_RESET_ADDRESS \
1178	PSCI_EXTENDED_STATE_ID \
1179	PSCI_OS_INIT_MODE \
1180	RESET_TO_BL31 \
1181	SAVE_KEYS \
1182	SEPARATE_CODE_AND_RODATA \
1183	SEPARATE_BL2_NOLOAD_REGION \
1184	SEPARATE_NOBITS_REGION \
1185	SPIN_ON_BL1_EXIT \
1186	SPM_MM \
1187	SPMC_AT_EL3 \
1188	SPMC_AT_EL3_SEL0_SP \
1189	SPMD_SPM_AT_SEL2 \
1190	ENABLE_SPMD_LP \
1191	TRANSFER_LIST \
1192	TRUSTED_BOARD_BOOT \
1193	USE_COHERENT_MEM \
1194	USE_DEBUGFS \
1195	ARM_IO_IN_DTB \
1196	SDEI_IN_FCONF \
1197	SEC_INT_DESC_IN_FCONF \
1198	USE_ROMLIB \
1199	USE_TBBR_DEFS \
1200	WARMBOOT_ENABLE_DCACHE_EARLY \
1201	RESET_TO_BL2 \
1202	BL2_IN_XIP_MEM \
1203	BL2_INV_DCACHE \
1204	USE_SPINLOCK_CAS \
1205	ENCRYPT_BL31 \
1206	ENCRYPT_BL32 \
1207	ERRATA_SPECULATIVE_AT \
1208	RAS_TRAP_NS_ERR_REC_ACCESS \
1209	COT_DESC_IN_DTB \
1210	USE_SP804_TIMER \
1211	PSA_FWU_SUPPORT \
1212	ENABLE_MPMM \
1213	ENABLE_MPMM_FCONF \
1214	FEATURE_DETECTION \
1215	TRNG_SUPPORT \
1216	ERRATA_ABI_SUPPORT \
1217	ERRATA_NON_ARM_INTERCONNECT \
1218	CONDITIONAL_CMO \
1219	PSA_CRYPTO	\
1220	ENABLE_CONSOLE_GETC \
1221	INIT_UNUSED_NS_EL2	\
1222	PLATFORM_REPORT_CTX_MEM_USE \
1223)))
1224
1225# Numeric_Flags
1226$(eval $(call assert_numerics,\
1227    $(sort \
1228	ARM_ARCH_MAJOR \
1229	ARM_ARCH_MINOR \
1230	BRANCH_PROTECTION \
1231	CTX_INCLUDE_PAUTH_REGS \
1232	CTX_INCLUDE_NEVE_REGS \
1233	CRYPTO_SUPPORT \
1234	DISABLE_MTPMU \
1235	ENABLE_BRBE_FOR_NS \
1236	ENABLE_TRBE_FOR_NS \
1237	ENABLE_BTI \
1238	ENABLE_PAUTH \
1239	ENABLE_FEAT_AMU \
1240	ENABLE_FEAT_AMUv1p1 \
1241	ENABLE_FEAT_CSV2_2 \
1242	ENABLE_FEAT_CSV2_3 \
1243	ENABLE_FEAT_DIT \
1244	ENABLE_FEAT_ECV \
1245	ENABLE_FEAT_FGT \
1246	ENABLE_FEAT_HCX \
1247	ENABLE_FEAT_MTE \
1248	ENABLE_FEAT_PAN \
1249	ENABLE_FEAT_RNG \
1250	ENABLE_FEAT_RNG_TRAP \
1251	ENABLE_FEAT_SEL2 \
1252	ENABLE_FEAT_TCR2 \
1253	ENABLE_FEAT_SB \
1254	ENABLE_FEAT_S2PIE \
1255	ENABLE_FEAT_S1PIE \
1256	ENABLE_FEAT_S2POE \
1257	ENABLE_FEAT_S1POE \
1258	ENABLE_FEAT_GCS \
1259	ENABLE_FEAT_VHE \
1260	ENABLE_FEAT_MTE_PERM \
1261	ENABLE_FEAT_MPAM \
1262	ENABLE_RME \
1263	ENABLE_SPE_FOR_NS \
1264	ENABLE_SYS_REG_TRACE_FOR_NS \
1265	ENABLE_SME_FOR_NS \
1266	ENABLE_SME2_FOR_NS \
1267	ENABLE_SVE_FOR_NS \
1268	ENABLE_TRF_FOR_NS \
1269	FW_ENC_STATUS \
1270	NR_OF_FW_BANKS \
1271	NR_OF_IMAGES_IN_FW_BANK \
1272	TWED_DELAY \
1273	ENABLE_FEAT_TWED \
1274	SVE_VECTOR_LEN \
1275	IMPDEF_SYSREG_TRAP \
1276)))
1277
1278ifdef KEY_SIZE
1279        $(eval $(call assert_numeric,KEY_SIZE))
1280endif
1281
1282ifeq ($(filter $(SANITIZE_UB), on off trap),)
1283        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
1284endif
1285
1286################################################################################
1287# Add definitions to the cpp preprocessor based on the current build options.
1288# This is done after including the platform specific makefile to allow the
1289# platform to overwrite the default options
1290################################################################################
1291
1292$(eval $(call add_defines,\
1293    $(sort \
1294	ALLOW_RO_XLAT_TABLES \
1295	ARM_ARCH_MAJOR \
1296	ARM_ARCH_MINOR \
1297	BL2_ENABLE_SP_LOAD \
1298	COLD_BOOT_SINGLE_CPU \
1299	CTX_INCLUDE_AARCH32_REGS \
1300	CTX_INCLUDE_FPREGS \
1301	CTX_INCLUDE_PAUTH_REGS \
1302	CTX_INCLUDE_MPAM_REGS \
1303	EL3_EXCEPTION_HANDLING \
1304	CTX_INCLUDE_EL2_REGS \
1305	CTX_INCLUDE_NEVE_REGS \
1306	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
1307	DISABLE_MTPMU \
1308	ENABLE_FEAT_AMU \
1309	ENABLE_AMU_AUXILIARY_COUNTERS \
1310	ENABLE_AMU_FCONF \
1311	AMU_RESTRICT_COUNTERS \
1312	ENABLE_ASSERTIONS \
1313	ENABLE_BTI \
1314	ENABLE_FEAT_MPAM \
1315	ENABLE_PAUTH \
1316	ENABLE_PIE \
1317	ENABLE_PMF \
1318	ENABLE_PSCI_STAT \
1319	ENABLE_RME \
1320	ENABLE_RUNTIME_INSTRUMENTATION \
1321	ENABLE_SME_FOR_NS \
1322	ENABLE_SME2_FOR_NS \
1323	ENABLE_SME_FOR_SWD \
1324	ENABLE_SPE_FOR_NS \
1325	ENABLE_SVE_FOR_NS \
1326	ENABLE_SVE_FOR_SWD \
1327	ENABLE_FEAT_RAS \
1328	FFH_SUPPORT \
1329	ENCRYPT_BL31 \
1330	ENCRYPT_BL32 \
1331	ERROR_DEPRECATED \
1332	FAULT_INJECTION_SUPPORT \
1333	GICV2_G0_FOR_EL3 \
1334	HANDLE_EA_EL3_FIRST_NS \
1335	HW_ASSISTED_COHERENCY \
1336	LOG_LEVEL \
1337	MEASURED_BOOT \
1338	DRTM_SUPPORT \
1339	NS_TIMER_SWITCH \
1340	PL011_GENERIC_UART \
1341	PLAT_${PLAT} \
1342	PROGRAMMABLE_RESET_ADDRESS \
1343	PSCI_EXTENDED_STATE_ID \
1344	PSCI_OS_INIT_MODE \
1345	RESET_TO_BL31 \
1346	SEPARATE_CODE_AND_RODATA \
1347	SEPARATE_BL2_NOLOAD_REGION \
1348	SEPARATE_NOBITS_REGION \
1349	RECLAIM_INIT_CODE \
1350	SPD_${SPD} \
1351	SPIN_ON_BL1_EXIT \
1352	SPM_MM \
1353	SPMC_AT_EL3 \
1354	SPMC_AT_EL3_SEL0_SP \
1355	SPMD_SPM_AT_SEL2 \
1356	TRANSFER_LIST \
1357	TRUSTED_BOARD_BOOT \
1358	CRYPTO_SUPPORT \
1359	TRNG_SUPPORT \
1360	ERRATA_ABI_SUPPORT \
1361	ERRATA_NON_ARM_INTERCONNECT \
1362	USE_COHERENT_MEM \
1363	USE_DEBUGFS \
1364	ARM_IO_IN_DTB \
1365	SDEI_IN_FCONF \
1366	SEC_INT_DESC_IN_FCONF \
1367	USE_ROMLIB \
1368	USE_TBBR_DEFS \
1369	WARMBOOT_ENABLE_DCACHE_EARLY \
1370	RESET_TO_BL2 \
1371	BL2_RUNS_AT_EL3	\
1372	BL2_IN_XIP_MEM \
1373	BL2_INV_DCACHE \
1374	USE_SPINLOCK_CAS \
1375	ERRATA_SPECULATIVE_AT \
1376	RAS_TRAP_NS_ERR_REC_ACCESS \
1377	COT_DESC_IN_DTB \
1378	USE_SP804_TIMER \
1379	ENABLE_FEAT_RNG \
1380	ENABLE_FEAT_RNG_TRAP \
1381	ENABLE_FEAT_SB \
1382	ENABLE_FEAT_DIT \
1383	NR_OF_FW_BANKS \
1384	NR_OF_IMAGES_IN_FW_BANK \
1385	PSA_FWU_SUPPORT \
1386	ENABLE_BRBE_FOR_NS \
1387	ENABLE_TRBE_FOR_NS \
1388	ENABLE_SYS_REG_TRACE_FOR_NS \
1389	ENABLE_TRF_FOR_NS \
1390	ENABLE_FEAT_HCX \
1391	ENABLE_MPMM \
1392	ENABLE_MPMM_FCONF \
1393	ENABLE_FEAT_FGT \
1394	ENABLE_FEAT_ECV \
1395	ENABLE_FEAT_AMUv1p1 \
1396	ENABLE_FEAT_SEL2 \
1397	ENABLE_FEAT_VHE \
1398	ENABLE_FEAT_CSV2_2 \
1399	ENABLE_FEAT_CSV2_3 \
1400	ENABLE_FEAT_PAN \
1401	ENABLE_FEAT_TCR2 \
1402	ENABLE_FEAT_S2PIE \
1403	ENABLE_FEAT_S1PIE \
1404	ENABLE_FEAT_S2POE \
1405	ENABLE_FEAT_S1POE \
1406	ENABLE_FEAT_GCS \
1407	ENABLE_FEAT_MTE \
1408	ENABLE_FEAT_MTE_PERM \
1409	FEATURE_DETECTION \
1410	TWED_DELAY \
1411	ENABLE_FEAT_TWED \
1412	CONDITIONAL_CMO \
1413	IMPDEF_SYSREG_TRAP \
1414	SVE_VECTOR_LEN \
1415	ENABLE_SPMD_LP \
1416	PSA_CRYPTO	\
1417	ENABLE_CONSOLE_GETC \
1418	INIT_UNUSED_NS_EL2	\
1419	PLATFORM_REPORT_CTX_MEM_USE \
1420)))
1421
1422ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
1423ifeq (${DEBUG}, 0)
1424        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
1425        override PLATFORM_REPORT_CTX_MEM_USE := 0
1426endif
1427endif
1428
1429ifeq (${SANITIZE_UB},trap)
1430        $(eval $(call add_define,MONITOR_TRAPS))
1431endif #(SANITIZE_UB)
1432
1433# Define the EL3_PAYLOAD_BASE flag only if it is provided.
1434ifdef EL3_PAYLOAD_BASE
1435        $(eval $(call add_define,EL3_PAYLOAD_BASE))
1436else
1437# Define the PRELOADED_BL33_BASE flag only if it is provided and
1438# EL3_PAYLOAD_BASE is not defined, as it has priority.
1439	ifdef PRELOADED_BL33_BASE
1440                $(eval $(call add_define,PRELOADED_BL33_BASE))
1441	endif
1442endif #(EL3_PAYLOAD_BASE)
1443
1444# Define the DYN_DISABLE_AUTH flag only if set.
1445ifeq (${DYN_DISABLE_AUTH},1)
1446        $(eval $(call add_define,DYN_DISABLE_AUTH))
1447endif
1448
1449ifneq ($(findstring armlink,$(notdir $(LD))),)
1450        $(eval $(call add_define,USE_ARM_LINK))
1451endif
1452
1453# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
1454ifeq (${SPD},spmd)
1455ifdef SP_LAYOUT_FILE
1456	-include $(BUILD_PLAT)/sp_gen.mk
1457	FIP_DEPS += sp
1458	CRT_DEPS += sp
1459	NEED_SP_PKG := yes
1460else
1461	ifeq (${SPMD_SPM_AT_SEL2},1)
1462                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
1463	endif
1464endif #(SP_LAYOUT_FILE)
1465endif #(SPD)
1466
1467################################################################################
1468# Build targets
1469################################################################################
1470
1471.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool
1472.SUFFIXES:
1473
1474all: msg_start
1475
1476msg_start:
1477	@echo "Building ${PLAT}"
1478
1479ifeq (${ERROR_DEPRECATED},0)
1480# Check if deprecated declarations and cpp warnings should be treated as error or not.
1481ifneq ($(findstring clang,$(notdir $(CC))),)
1482    CPPFLAGS		+= 	-Wno-error=deprecated-declarations
1483else
1484    CPPFLAGS		+= 	-Wno-error=deprecated-declarations -Wno-error=cpp
1485endif
1486endif #(!ERROR_DEPRECATED)
1487
1488$(eval $(call MAKE_LIB_DIRS))
1489$(eval $(call MAKE_LIB,c))
1490
1491# Expand build macros for the different images
1492ifeq (${NEED_BL1},yes)
1493BL1_SOURCES := $(sort ${BL1_SOURCES})
1494$(eval $(call MAKE_BL,bl1))
1495endif #(NEED_BL1)
1496
1497ifeq (${NEED_BL2},yes)
1498
1499ifeq (${RESET_TO_BL2}, 0)
1500FIP_BL2_ARGS := tb-fw
1501endif
1502
1503BL2_SOURCES := $(sort ${BL2_SOURCES})
1504
1505$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\
1506	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
1507
1508endif #(NEED_BL2)
1509
1510ifeq (${NEED_SCP_BL2},yes)
1511$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1512endif #(NEED_SCP_BL2)
1513
1514ifeq (${NEED_BL31},yes)
1515BL31_SOURCES += ${SPD_SOURCES}
1516# Sort BL31 source files to remove duplicates
1517BL31_SOURCES := $(sort ${BL31_SOURCES})
1518ifneq (${DECRYPTION_SUPPORT},none)
1519$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1520	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1521else
1522$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1523	$(eval $(call MAKE_BL,bl31,soc-fw)))
1524endif #(DECRYPTION_SUPPORT)
1525endif #(NEED_BL31)
1526
1527# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1528# build system will call TOOL_ADD_IMG to print a warning message and abort the
1529# process. Note that the dependency on BL32 applies to the FIP only.
1530ifeq (${NEED_BL32},yes)
1531# Sort BL32 source files to remove duplicates
1532BL32_SOURCES := $(sort ${BL32_SOURCES})
1533BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1534
1535ifneq (${DECRYPTION_SUPPORT},none)
1536$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1537	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1538else
1539$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1540	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1541endif #(DECRYPTION_SUPPORT)
1542endif #(NEED_BL32)
1543
1544# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1545# needs to be built from RMM_SOURCES.
1546ifeq (${NEED_RMM},yes)
1547# Sort RMM source files to remove duplicates
1548RMM_SOURCES := $(sort ${RMM_SOURCES})
1549BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1550
1551$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1552	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1553endif #(NEED_RMM)
1554
1555# Add the BL33 image if required by the platform
1556ifeq (${NEED_BL33},yes)
1557$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1558endif #(NEED_BL33)
1559
1560ifeq (${NEED_BL2U},yes)
1561$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1562	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1563endif #(NEED_BL2U)
1564
1565# Expand build macros for the different images
1566ifeq (${NEED_FDT},yes)
1567    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1568endif #(NEED_FDT)
1569
1570# Add Secure Partition packages
1571ifeq (${NEED_SP_PKG},yes)
1572$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT}
1573	@${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1574sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1575	@${ECHO_BLANK_LINE}
1576	@echo "Built SP Images successfully"
1577	@${ECHO_BLANK_LINE}
1578endif #(NEED_SP_PKG)
1579
1580locate-checkpatch:
1581ifndef CHECKPATCH
1582	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1583else
1584ifeq (,$(wildcard ${CHECKPATCH}))
1585	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1586endif
1587endif #(CHECKPATCH)
1588
1589clean:
1590	@echo "  CLEAN"
1591	$(call SHELL_REMOVE_DIR,${BUILD_PLAT})
1592ifdef UNIX_MK
1593	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1594else
1595# Clear the MAKEFLAGS as we do not want
1596# to pass the gnumake flags to nmake.
1597	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean
1598endif #(UNIX_MK)
1599	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1600	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1601	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1602
1603realclean distclean:
1604	@echo "  REALCLEAN"
1605	$(call SHELL_REMOVE_DIR,${BUILD_BASE})
1606	$(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*)
1607ifdef UNIX_MK
1608	${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean
1609else
1610# Clear the MAKEFLAGS as we do not want
1611# to pass the gnumake flags to nmake.
1612	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean
1613endif #(UNIX_MK)
1614	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} realclean
1615	${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean
1616	${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1617
1618checkcodebase:		locate-checkpatch
1619	@echo "  CHECKING STYLE"
1620	@if test -d .git ; then						\
1621		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1622		while read GIT_FILE ;					\
1623		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1624		done ;							\
1625	else								\
1626		 find . -type f -not -iwholename "*.git*"		\
1627		 -not -iwholename "*build*"				\
1628		 -not -iwholename "*libfdt*"				\
1629		 -not -iwholename "*libc*"				\
1630		 -not -iwholename "*docs*"				\
1631		 -not -iwholename "*.rst"				\
1632		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1633	fi
1634
1635checkpatch:		locate-checkpatch
1636	@echo "  CHECKING STYLE"
1637	@if test -n "${CHECKPATCH_OPTS}"; then				\
1638		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1639	fi
1640	${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1641	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1642	do								\
1643		printf "\n[*] Checking style of '$$commit'\n\n";	\
1644		git log --format=email "$$commit~..$$commit"		\
1645			-- ${CHECK_PATHS} |				\
1646			${CHECKPATCH} ${CHECKPATCH_OPTS} - || true;	\
1647		git diff --format=email "$$commit~..$$commit"		\
1648			-- ${CHECK_PATHS} |				\
1649			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1650	done
1651
1652certtool: ${CRTTOOL}
1653
1654${CRTTOOL}: FORCE
1655	${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${CRTTOOLPATH} all
1656	@${ECHO_BLANK_LINE}
1657	@echo "Built $@ successfully"
1658	@${ECHO_BLANK_LINE}
1659
1660ifneq (${GENERATE_COT},0)
1661certificates: ${CRT_DEPS} ${CRTTOOL}
1662	${Q}${CRTTOOL} ${CRT_ARGS}
1663	@${ECHO_BLANK_LINE}
1664	@echo "Built $@ successfully"
1665	@echo "Certificates can be found in ${BUILD_PLAT}"
1666	@${ECHO_BLANK_LINE}
1667endif #(GENERATE_COT)
1668
1669${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL}
1670	$(eval ${CHECK_FIP_CMD})
1671	${Q}${FIPTOOL} create ${FIP_ARGS} $@
1672	${Q}${FIPTOOL} info $@
1673	@${ECHO_BLANK_LINE}
1674	@echo "Built $@ successfully"
1675	@${ECHO_BLANK_LINE}
1676
1677ifneq (${GENERATE_COT},0)
1678fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1679	${Q}${CRTTOOL} ${FWU_CRT_ARGS}
1680	@${ECHO_BLANK_LINE}
1681	@echo "Built $@ successfully"
1682	@echo "FWU certificates can be found in ${BUILD_PLAT}"
1683	@${ECHO_BLANK_LINE}
1684endif #(GENERATE_COT)
1685
1686${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL}
1687	$(eval ${CHECK_FWU_FIP_CMD})
1688	${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@
1689	${Q}${FIPTOOL} info $@
1690	@${ECHO_BLANK_LINE}
1691	@echo "Built $@ successfully"
1692	@${ECHO_BLANK_LINE}
1693
1694fiptool: ${FIPTOOL}
1695fip: ${BUILD_PLAT}/${FIP_NAME}
1696fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1697
1698${FIPTOOL}: FORCE
1699ifdef UNIX_MK
1700	${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${FIPTOOLPATH} all
1701else
1702# Clear the MAKEFLAGS as we do not want
1703# to pass the gnumake flags to nmake.
1704	${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL))
1705endif #(UNIX_MK)
1706
1707romlib.bin: libraries FORCE
1708	${Q}${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all
1709
1710memmap: all
1711ifdef UNIX_MK
1712	${Q}PYTHONPATH=${CURDIR}/tools/memory \
1713		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1714else
1715	${Q}set PYTHONPATH=${CURDIR}/tools/memory && \
1716		${PYTHON} -m memory.memmap -sr ${BUILD_PLAT}
1717endif
1718
1719doc:
1720	@echo "  BUILD DOCUMENTATION"
1721	${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
1722
1723enctool: ${ENCTOOL}
1724
1725${ENCTOOL}: FORCE
1726	${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} DEBUG=${DEBUG} V=${V} --no-print-directory -C ${ENCTOOLPATH} all
1727	@${ECHO_BLANK_LINE}
1728	@echo "Built $@ successfully"
1729	@${ECHO_BLANK_LINE}
1730
1731cscope:
1732	@echo "  CSCOPE"
1733	${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
1734	${Q}cscope -b -q -k
1735
1736help:
1737	@echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1738	@echo ""
1739	@echo "PLAT is used to specify which platform you wish to build."
1740	@echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1741	@echo ""
1742	@echo "platform = ${PLATFORM_LIST}"
1743	@echo ""
1744	@echo "Please refer to the User Guide for a list of all supported options."
1745	@echo "Note that the build system doesn't track dependencies for build "
1746	@echo "options. Therefore, if any of the build options are changed "
1747	@echo "from a previous build, a clean build must be performed."
1748	@echo ""
1749	@echo "Supported Targets:"
1750	@echo "  all            Build all individual bootloader binaries"
1751	@echo "  bl1            Build the BL1 binary"
1752	@echo "  bl2            Build the BL2 binary"
1753	@echo "  bl2u           Build the BL2U binary"
1754	@echo "  bl31           Build the BL31 binary"
1755	@echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1756	@echo "                 this builds secure payload specified by AARCH32_SP"
1757	@echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1758	@echo "  fip            Build the Firmware Image Package (FIP)"
1759	@echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1760	@echo "  checkcodebase  Check the coding style of the entire source tree"
1761	@echo "  checkpatch     Check the coding style on changes in the current"
1762	@echo "                 branch against BASE_COMMIT (default origin/master)"
1763	@echo "  clean          Clean the build for the selected platform"
1764	@echo "  cscope         Generate cscope index"
1765	@echo "  distclean      Remove all build artifacts for all platforms"
1766	@echo "  certtool       Build the Certificate generation tool"
1767	@echo "  enctool        Build the Firmware encryption tool"
1768	@echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1769	@echo "  sp             Build the Secure Partition Packages"
1770	@echo "  sptool         Build the Secure Partition Package creation tool"
1771	@echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1772	@echo "  memmap         Print the memory map of the built binaries"
1773	@echo "  doc            Build html based documentation using Sphinx tool"
1774	@echo ""
1775	@echo "Note: most build targets require PLAT to be set to a specific platform."
1776	@echo ""
1777	@echo "example: build all targets for the FVP platform:"
1778	@echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1779
1780.PHONY: FORCE
1781FORCE:;
1782