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