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