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