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