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