xref: /rk3399_ARM-atf/Makefile (revision 436cc702799adb6ac2ac5fb15d2c4e67bb8cdbd2)
1#
2# Copyright (c) 2013-2025, 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			:= 13
12# VERSION_PATCH is only used for LTS releases
13VERSION_PATCH			:= 0
14VERSION				:= ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
15
16# Default goal is build all images
17.DEFAULT_GOAL			:= all
18
19# Avoid any implicit propagation of command line variable definitions to
20# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
21# usage. Other command line options like "-s" are still propagated as usual.
22MAKEOVERRIDES =
23
24MAKE_HELPERS_DIRECTORY := make_helpers/
25include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
26include ${MAKE_HELPERS_DIRECTORY}build-rules.mk
27include ${MAKE_HELPERS_DIRECTORY}common.mk
28
29################################################################################
30# Default values for build configurations, and their dependencies
31################################################################################
32
33include ${MAKE_HELPERS_DIRECTORY}defaults.mk
34PLAT				:= ${DEFAULT_PLAT}
35include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
36
37# To be able to set platform specific defaults
38ifneq ($(PLAT_DEFAULTS_MAKEFILE_FULL),)
39include ${PLAT_DEFAULTS_MAKEFILE_FULL}
40endif
41
42################################################################################
43# Configure the toolchains used to build TF-A and its tools
44################################################################################
45
46include ${MAKE_HELPERS_DIRECTORY}toolchain.mk
47
48# Assertions enabled for DEBUG builds by default
49ENABLE_ASSERTIONS		:= ${DEBUG}
50ENABLE_PMF			:= ${ENABLE_RUNTIME_INSTRUMENTATION}
51
52################################################################################
53# Checkpatch script options
54################################################################################
55
56CHECKCODE_ARGS		:=	--no-patch
57# Do not check the coding style on imported library files or documentation files
58INC_DRV_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
59					include/drivers/arm,		\
60					$(wildcard include/drivers/*)))
61INC_LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
62					include/lib/libfdt		\
63					include/lib/libc,		\
64					$(wildcard include/lib/*)))
65INC_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
66					include/lib			\
67					include/drivers,		\
68					$(wildcard include/*)))
69LIB_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
70					lib/compiler-rt			\
71					lib/libfdt%			\
72					lib/libc,			\
73					lib/zlib			\
74					$(wildcard lib/*)))
75ROOT_DIRS_TO_CHECK	:=	$(sort $(filter-out			\
76					lib				\
77					include				\
78					docs				\
79					%.rst,				\
80					$(wildcard *)))
81CHECK_PATHS		:=	${ROOT_DIRS_TO_CHECK}			\
82				${INC_DIRS_TO_CHECK}			\
83				${INC_LIB_DIRS_TO_CHECK}		\
84				${LIB_DIRS_TO_CHECK}			\
85				${INC_DRV_DIRS_TO_CHECK}		\
86				${INC_ARM_DIRS_TO_CHECK}
87
88################################################################################
89# Process build options
90################################################################################
91
92ifeq ($(verbose),)
93	CHECKCODE_ARGS	+=	--no-summary --terse
94endif
95
96################################################################################
97# Auxiliary tools (fiptool, cert_create, etc)
98################################################################################
99
100# Variables for use with Certificate Generation Tool
101CRTTOOLPATH		?=	tools/cert_create
102CRTTOOL			?=	${BUILD_PLAT}/${CRTTOOLPATH}/cert_create$(.exe)
103
104# Variables for use with Firmware Encryption Tool
105ENCTOOLPATH		?=	tools/encrypt_fw
106ENCTOOL			?=	${BUILD_PLAT}/${ENCTOOLPATH}/encrypt_fw$(.exe)
107
108# Variables for use with Firmware Image Package
109FIPTOOLPATH		?=	tools/fiptool
110FIPTOOL			?=	${BUILD_PLAT}/${FIPTOOLPATH}/fiptool$(.exe)
111
112# Variables for use with sptool
113SPTOOLPATH		?=	tools/sptool
114SPTOOL			?=	${SPTOOLPATH}/sptool.py
115SP_MK_GEN		?=	${SPTOOLPATH}/sp_mk_generator.py
116SP_DTS_LIST_FRAGMENT	?=	${BUILD_PLAT}/sp_list_fragment.dts
117
118# Variables for use with sptool
119TLCTOOL 		?=	poetry run tlc
120
121# Variables for use with ROMLIB
122ROMLIBPATH		?=	lib/romlib
123
124# Variable for use with Python
125PYTHON			?=	python3
126
127# Variables for use with documentation build using Sphinx tool
128DOCS_PATH		?=	docs
129
130# Process Debug flag
131ifneq (${DEBUG}, 0)
132	BUILD_TYPE	:=	debug
133	# Use LOG_LEVEL_INFO by default for debug builds
134	LOG_LEVEL	:=	40
135else
136	BUILD_TYPE	:=	release
137	# Use LOG_LEVEL_NOTICE by default for release builds
138	LOG_LEVEL	:=	20
139endif #(Debug)
140
141# Default build string (git branch and commit)
142ifeq (${BUILD_STRING},)
143	BUILD_STRING  :=  $(shell git describe --always --dirty --tags 2> /dev/null)
144endif
145VERSION_STRING    :=  v${VERSION}(${BUILD_TYPE}):${BUILD_STRING}
146
147# Setting W is quite verbose and most warnings will be pre-existing issues
148# outside of the contributor's control. Don't fail the build on them so warnings
149# can be seen and hopefully addressed
150ifdef W
151	ifneq (${W},0)
152		E	 ?= 0
153	endif
154endif
155
156################################################################################
157# Setup ARCH_MAJOR/MINOR before parsing arch_features.
158################################################################################
159ifeq (${ENABLE_RME},1)
160	ARM_ARCH_MAJOR := 9
161	ARM_ARCH_MINOR := 2
162endif
163
164################################################################################
165# Common sources and include directories
166################################################################################
167include lib/compiler-rt/compiler-rt.mk
168
169# Allow overriding the timestamp, for example for reproducible builds, or to
170# synchronize timestamps across multiple projects.
171# This must be set to a C string (including quotes where applicable).
172BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
173
174DEFINES += -DBUILD_MESSAGE_TIMESTAMP='$(BUILD_MESSAGE_TIMESTAMP)'
175DEFINES += -DBUILD_MESSAGE_VERSION_STRING='"$(VERSION_STRING)"'
176DEFINES += -DBUILD_MESSAGE_VERSION='"$(VERSION)"'
177
178BL_COMMON_SOURCES	+=	common/bl_common.c			\
179				common/tf_log.c				\
180				common/${ARCH}/debug.S			\
181				drivers/console/multi_console.c		\
182				lib/${ARCH}/cache_helpers.S		\
183				lib/${ARCH}/misc_helpers.S		\
184				lib/extensions/pmuv3/${ARCH}/pmuv3.c	\
185				plat/common/plat_bl_common.c		\
186				plat/common/plat_log_common.c		\
187				plat/common/${ARCH}/plat_common.c	\
188				plat/common/${ARCH}/platform_helpers.S	\
189				${COMPILER_RT_SRCS}
190
191ifeq ($($(ARCH)-cc-id),arm-clang)
192	BL_COMMON_SOURCES	+=	lib/${ARCH}/armclang_printf.S
193endif
194
195ifeq (${SANITIZE_UB},on)
196	BL_COMMON_SOURCES	+=	plat/common/ubsan.c
197endif
198
199INCLUDES		+=	-Iinclude				\
200				-Iinclude/arch/${ARCH}			\
201				-Iinclude/lib/cpus/${ARCH}		\
202				-Iinclude/lib/el3_runtime/${ARCH}	\
203				${PLAT_INCLUDES}			\
204				${SPD_INCLUDES}
205
206include common/backtrace/backtrace.mk
207
208################################################################################
209# Generic definitions
210################################################################################
211
212ifeq (${BUILD_BASE},)
213     BUILD_BASE		:=	./build
214endif
215BUILD_PLAT		:=	$(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE}
216
217SPDS			:=	$(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*))))
218
219# Platforms providing their own TBB makefile may override this value
220INCLUDE_TBBR_MK		:=	1
221
222################################################################################
223# Include SPD Makefile if one has been specified
224################################################################################
225
226ifneq (${SPD},none)
227	ifeq (${SPD},spmd)
228	# SPMD is located in std_svc directory
229		SPD_DIR := std_svc
230
231		ifeq ($(SPMD_SPM_AT_SEL2),1)
232			CTX_INCLUDE_EL2_REGS := 1
233		endif
234
235		ifneq ($(SP_LAYOUT_FILE),)
236		BL2_ENABLE_SP_LOAD := 1
237		endif
238	else
239		# All other SPDs in spd directory
240		SPD_DIR := spd
241	endif #(SPD)
242
243	# We expect to locate an spd.mk under the specified SPD directory
244	SPD_MAKE	:=	$(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk)
245
246	ifeq (${SPD_MAKE},)
247                $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located)
248	endif
249        $(info Including ${SPD_MAKE})
250        include ${SPD_MAKE}
251
252	# If there's BL32 companion for the chosen SPD, we expect that the SPD's
253	# Makefile would set NEED_BL32 to "yes". In this case, the build system
254	# supports two mutually exclusive options:
255	# * BL32 is built from source: then BL32_SOURCES must contain the list
256	#   of source files to build BL32
257	# * BL32 is a prebuilt binary: then BL32 must point to the image file
258	#   that will be included in the FIP
259	# If both BL32_SOURCES and BL32 are defined, the binary takes precedence
260	# over the sources.
261endif #(SPD=none)
262
263################################################################################
264# Include the platform specific Makefile after the SPD Makefile (the platform
265# makefile may use all previous definitions in this file)
266################################################################################
267include ${PLAT_MAKEFILE_FULL}
268
269################################################################################
270# Setup arch_features based on ARM_ARCH_MAJOR, ARM_ARCH_MINOR provided from
271# platform.
272################################################################################
273
274include ${MAKE_HELPERS_DIRECTORY}arch_features.mk
275################################################################################
276# Process BRANCH_PROTECTION value and set
277# Pointer Authentication and Branch Target Identification flags
278################################################################################
279ifeq (${BRANCH_PROTECTION},0)
280	# Default value turns off all types of branch protection
281	BP_OPTION := none
282else ifneq (${ARCH},aarch64)
283        $(error BRANCH_PROTECTION requires AArch64)
284else ifeq (${BRANCH_PROTECTION},1)
285	# Enables all types of branch protection features
286	BP_OPTION := standard
287	ENABLE_BTI := 1
288	ENABLE_PAUTH := 1
289else ifeq (${BRANCH_PROTECTION},2)
290	# Return address signing to its standard level
291	BP_OPTION := pac-ret
292	ENABLE_PAUTH := 1
293else ifeq (${BRANCH_PROTECTION},3)
294	# Extend the signing to include leaf functions
295	BP_OPTION := pac-ret+leaf
296	ENABLE_PAUTH := 1
297else ifeq (${BRANCH_PROTECTION},4)
298	# Turn on branch target identification mechanism
299	BP_OPTION := bti
300	ENABLE_BTI := 1
301else ifeq (${BRANCH_PROTECTION},5)
302	# Turn on branch target identification mechanism
303	BP_OPTION := standard
304	ENABLE_BTI := 2
305	ENABLE_PAUTH := 2
306else
307        $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION})
308endif #(BRANCH_PROTECTION)
309
310ifneq ($(ENABLE_PAUTH),0)
311	CTX_INCLUDE_PAUTH_REGS	:= ${ENABLE_PAUTH}
312endif
313
314# Pointer Authentication sources
315ifneq (${ENABLE_PAUTH},0)
316# arm/common/aarch64/arm_pauth.c contains a sample platform hook to complete the
317# Pauth support. As it's not secure, it must be reimplemented for real platforms
318	BL_COMMON_SOURCES	+=	lib/extensions/pauth/pauth.c
319endif
320#
321ifneq (${ENABLE_FEAT_PAUTH_LR},0)
322# Currently, FEAT_PAUTH_LR is only supported by arm/clang compilers
323# TODO implement for GCC when support is added
324ifeq ($($(ARCH)-cc-id),arm-clang)
325	arch-features	:= $(arch-features)+pauth-lr
326else
327	$(error Error: ENABLE_FEAT_PAUTH_LR not supported for GCC compiler)
328endif
329endif
330
331################################################################################
332# RME dependent flags configuration, Enable optional features for RME.
333################################################################################
334# FEAT_RME
335ifeq (${ENABLE_RME},1)
336	# RME requires el2 context to be saved for now.
337	CTX_INCLUDE_EL2_REGS := 1
338	CTX_INCLUDE_AARCH32_REGS := 0
339	CTX_INCLUDE_PAUTH_REGS := 1
340
341	ifneq ($(ENABLE_FEAT_MPAM), 0)
342		CTX_INCLUDE_MPAM_REGS := 1
343	endif
344
345	# RME enables CSV2_2 extension by default.
346	ENABLE_FEAT_CSV2_2 = 1
347endif #(FEAT_RME)
348
349################################################################################
350# Include rmmd Makefile if RME is enabled
351################################################################################
352ifneq (${ENABLE_RME},0)
353include services/std_svc/rmmd/rmmd.mk
354$(warning "RME is an experimental feature")
355endif
356
357################################################################################
358# Make 128-Bit sysreg read/writes availabe when FEAT_D128 is enabled.
359################################################################################
360ifneq (${ENABLE_FEAT_D128}, 0)
361        BL_COMMON_SOURCES       +=      lib/extensions/sysreg128/sysreg128.S
362endif
363
364# This internal flag is common option which is set to 1 for scenarios
365# when the BL2 is running in EL3 level. This occurs in two scenarios -
366# 4 world system running BL2 at EL3 and two world system without BL1 running
367# BL2 in EL3
368
369ifeq (${RESET_TO_BL2},1)
370	BL2_RUNS_AT_EL3	:=	1
371	ifeq (${ENABLE_RME},1)
372                $(error RESET_TO_BL2=1 and ENABLE_RME=1 configuration is not \
373                supported at the moment.)
374	endif
375else ifeq (${ENABLE_RME},1)
376	BL2_RUNS_AT_EL3	:=	1
377else
378	BL2_RUNS_AT_EL3	:=	0
379endif
380
381# This internal flag is set to 1 when Firmware First handling of External aborts
382# is required by lowe ELs. Currently only NS requires this support.
383ifeq ($(HANDLE_EA_EL3_FIRST_NS),1)
384	FFH_SUPPORT := 1
385else
386	FFH_SUPPORT := 0
387endif
388
389# Include the CPU specific operations makefile, which provides default
390# values for all CPU errata workarounds and CPU specific optimisations.
391# This can be overridden by the platform.
392include lib/cpus/cpu-ops.mk
393
394################################################################################
395# Build `AARCH32_SP` as BL32 image for AArch32
396################################################################################
397ifeq (${ARCH},aarch32)
398        NEED_BL32 := yes
399
400        ifneq (${AARCH32_SP},none)
401        # We expect to locate an sp.mk under the specified AARCH32_SP directory
402		AARCH32_SP_MAKE	:=	$(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk)
403
404                ifeq (${AARCH32_SP_MAKE},)
405                        $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located)
406                endif
407                $(info Including ${AARCH32_SP_MAKE})
408                include ${AARCH32_SP_MAKE}
409        endif
410endif #(ARCH=aarch32)
411
412################################################################################
413# Include libc if not overridden
414################################################################################
415ifeq (${OVERRIDE_LIBC},0)
416include lib/libc/libc.mk
417endif
418
419ifneq (${USE_GIC_DRIVER},0)
420include drivers/arm/gic/gic.mk
421endif
422
423################################################################################
424# Check incompatible options and dependencies
425################################################################################
426include ${MAKE_HELPERS_DIRECTORY}constraints.mk
427
428# The cert_create tool cannot generate certificates individually, so we use the
429# target 'certificates' to create them all
430ifneq (${GENERATE_COT},0)
431    FIP_DEPS += certificates
432    FWU_FIP_DEPS += fwu_certificates
433    BL2_FIP_DEPS += bl2_certificates
434endif
435
436ifneq (${DECRYPTION_SUPPORT},none)
437	ENC_ARGS += -f ${FW_ENC_STATUS}
438	ENC_ARGS += -k ${ENC_KEY}
439	ENC_ARGS += -n ${ENC_NONCE}
440	FIP_DEPS += enctool
441	FWU_FIP_DEPS += enctool
442	BL2_FIP_DEPS += enctool
443endif #(DECRYPTION_SUPPORT)
444
445ifeq ($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT),1-1)
446# Support authentication verification and hash calculation
447	CRYPTO_SUPPORT := 3
448else ifeq ($(DRTM_SUPPORT)-$(TRUSTED_BOARD_BOOT),1-1)
449# Support authentication verification and hash calculation
450	CRYPTO_SUPPORT := 3
451else ifneq ($(filter 1,${MEASURED_BOOT} ${DRTM_SUPPORT}),)
452# Support hash calculation only
453	CRYPTO_SUPPORT := 2
454else ifeq (${TRUSTED_BOARD_BOOT},1)
455# Support authentication verification only
456	CRYPTO_SUPPORT := 1
457else
458	CRYPTO_SUPPORT := 0
459endif #($(MEASURED_BOOT)-$(TRUSTED_BOARD_BOOT))
460
461ifneq ($(filter 1 2 3,$(CRYPTO_SUPPORT)),)
462CRYPTO_LIB := $(BUILD_PLAT)/lib/libmbedtls.a
463endif
464
465################################################################################
466# Process platform overrideable behaviour
467################################################################################
468
469ifdef BL1_SOURCES
470	NEED_BL1 := yes
471endif #(BL1_SOURCES)
472
473ifdef BL2_SOURCES
474	NEED_BL2 := yes
475
476	# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
477	# Certificate generation tools. This flag can be overridden by the platform.
478	ifdef EL3_PAYLOAD_BASE
479		# If booting an EL3 payload there is no need for a BL33 image
480		# in the FIP file.
481		NEED_BL33		:=	no
482	else
483		ifdef PRELOADED_BL33_BASE
484			# If booting a BL33 preloaded image there is no need of
485			# another one in the FIP file.
486			NEED_BL33		:=	no
487		else
488			NEED_BL33		?=	yes
489		endif
490	endif
491endif #(BL2_SOURCES)
492
493ifdef BL2U_SOURCES
494	NEED_BL2U := yes
495endif #(BL2U_SOURCES)
496
497# If SCP_BL2 is given, we always want FIP to include it.
498ifdef SCP_BL2
499	NEED_SCP_BL2		:=	yes
500endif #(SCP_BL2)
501
502# For AArch32, BL31 is not currently supported.
503ifneq (${ARCH},aarch32)
504	ifdef BL31_SOURCES
505	# When booting an EL3 payload, there is no need to compile the BL31
506	# image nor put it in the FIP.
507		ifndef EL3_PAYLOAD_BASE
508			NEED_BL31 := yes
509		endif
510	endif
511endif #(ARCH=aarch64)
512
513# Process TBB related flags
514ifneq (${GENERATE_COT},0)
515    # Common cert_create options
516    ifneq (${CREATE_KEYS},0)
517        $(eval CRT_ARGS += -n)
518        $(eval FWU_CRT_ARGS += -n)
519        $(eval BL2_CRT_ARGS += -n)
520        ifneq (${SAVE_KEYS},0)
521            $(eval CRT_ARGS += -k)
522            $(eval FWU_CRT_ARGS += -k)
523            $(eval BL2_CRT_ARGS += -k)
524        endif
525    endif
526    # Include TBBR makefile (unless the platform indicates otherwise)
527    ifeq (${INCLUDE_TBBR_MK},1)
528        include make_helpers/tbbr/tbbr_tools.mk
529    endif
530endif #(GENERATE_COT)
531
532ifneq (${FIP_ALIGN},0)
533	FIP_ARGS += --align ${FIP_ALIGN}
534endif #(FIP_ALIGN)
535
536ifdef FDT_SOURCES
537	NEED_FDT := yes
538endif #(FDT_SOURCES)
539
540################################################################################
541# Include libraries' Makefile that are used in all BL
542################################################################################
543
544include lib/stack_protector/stack_protector.mk
545
546################################################################################
547# Include BL specific makefiles
548################################################################################
549
550ifeq (${NEED_BL1},yes)
551include bl1/bl1.mk
552endif
553
554ifeq (${NEED_BL2},yes)
555include bl2/bl2.mk
556endif
557
558ifeq (${NEED_BL2U},yes)
559include bl2u/bl2u.mk
560endif
561
562ifeq (${NEED_BL31},yes)
563include bl31/bl31.mk
564endif
565
566################################################################################
567# Build options checks
568################################################################################
569
570# Boolean_Flags
571$(eval $(call assert_booleans,\
572    $(sort \
573	ALLOW_RO_XLAT_TABLES \
574	BL2_ENABLE_SP_LOAD \
575	COLD_BOOT_SINGLE_CPU \
576	CREATE_KEYS \
577	CTX_INCLUDE_AARCH32_REGS \
578	CTX_INCLUDE_FPREGS \
579	CTX_INCLUDE_SVE_REGS \
580	CTX_INCLUDE_EL2_REGS \
581	CTX_INCLUDE_MPAM_REGS \
582	DEBUG \
583	DYN_DISABLE_AUTH \
584	EL3_EXCEPTION_HANDLING \
585	ENABLE_AMU_AUXILIARY_COUNTERS \
586	AMU_RESTRICT_COUNTERS \
587	ENABLE_ASSERTIONS \
588	ENABLE_PIE \
589	ENABLE_PMF \
590	ENABLE_PSCI_STAT \
591	ENABLE_RUNTIME_INSTRUMENTATION \
592	ENABLE_SME_FOR_SWD \
593	ENABLE_SVE_FOR_SWD \
594	ENABLE_FEAT_GCIE \
595	ENABLE_FEAT_RAS	\
596	FFH_SUPPORT	\
597	ERROR_DEPRECATED \
598	FAULT_INJECTION_SUPPORT \
599	GENERATE_COT \
600	GICV2_G0_FOR_EL3 \
601	HANDLE_EA_EL3_FIRST_NS \
602	HARDEN_SLS \
603	HW_ASSISTED_COHERENCY \
604	MEASURED_BOOT \
605	DISCRETE_TPM \
606	DICE_PROTECTION_ENVIRONMENT \
607	RMMD_ENABLE_EL3_TOKEN_SIGN \
608	RMMD_ENABLE_IDE_KEY_PROG \
609	DRTM_SUPPORT \
610	NS_TIMER_SWITCH \
611	OVERRIDE_LIBC \
612	PL011_GENERIC_UART \
613	PLAT_EXTRA_LD_SCRIPT \
614	PROGRAMMABLE_RESET_ADDRESS \
615	PSCI_EXTENDED_STATE_ID \
616	PSCI_OS_INIT_MODE \
617	ARCH_FEATURE_AVAILABILITY \
618	RESET_TO_BL31 \
619	SAVE_KEYS \
620	SEPARATE_CODE_AND_RODATA \
621	SEPARATE_BL2_NOLOAD_REGION \
622	SEPARATE_NOBITS_REGION \
623	SEPARATE_RWDATA_REGION \
624	SEPARATE_SIMD_SECTION \
625	SPIN_ON_BL1_EXIT \
626	SPM_MM \
627	SPMC_AT_EL3 \
628	SPMC_AT_EL3_SEL0_SP \
629	SPMD_SPM_AT_SEL2 \
630	ENABLE_SPMD_LP \
631	TRANSFER_LIST \
632	TRUSTED_BOARD_BOOT \
633	USE_COHERENT_MEM \
634	USE_DEBUGFS \
635	USE_KERNEL_DT_CONVENTION \
636	ARM_IO_IN_DTB \
637	SDEI_IN_FCONF \
638	SEC_INT_DESC_IN_FCONF \
639	USE_ROMLIB \
640	USE_TBBR_DEFS \
641	WARMBOOT_ENABLE_DCACHE_EARLY \
642	RESET_TO_BL2 \
643	BL2_IN_XIP_MEM \
644	BL2_INV_DCACHE \
645	USE_SPINLOCK_CAS \
646	ENCRYPT_BL31 \
647	ENCRYPT_BL32 \
648	ERRATA_SPECULATIVE_AT \
649	ERRATA_SME_POWER_DOWN \
650	RAS_TRAP_NS_ERR_REC_ACCESS \
651	COT_DESC_IN_DTB \
652	USE_SP804_TIMER \
653	PSA_FWU_SUPPORT \
654	PSA_FWU_METADATA_FW_STORE_DESC \
655	ENABLE_MPMM \
656	FEATURE_DETECTION \
657	TRNG_SUPPORT \
658	ENABLE_ERRATA_ALL \
659	ERRATA_ABI_SUPPORT \
660	ERRATA_NON_ARM_INTERCONNECT \
661	CONDITIONAL_CMO \
662	PSA_CRYPTO	\
663	ENABLE_CONSOLE_GETC \
664	INIT_UNUSED_NS_EL2	\
665	PLATFORM_REPORT_CTX_MEM_USE \
666	EARLY_CONSOLE \
667	PRESERVE_DSU_PMU_REGS \
668	HOB_LIST \
669	LFA_SUPPORT \
670)))
671
672# Numeric_Flags
673$(eval $(call assert_numerics,\
674    $(sort \
675	ARM_ARCH_MAJOR \
676	ARM_ARCH_MINOR \
677	BRANCH_PROTECTION \
678	CTX_INCLUDE_PAUTH_REGS \
679	CTX_INCLUDE_NEVE_REGS \
680	CRYPTO_SUPPORT \
681	DISABLE_MTPMU \
682	ENABLE_BRBE_FOR_NS \
683	ENABLE_TRBE_FOR_NS \
684	ENABLE_BTI \
685	ENABLE_PAUTH \
686	ENABLE_FEAT_PAUTH_LR \
687	ENABLE_FEAT_AMU \
688	ENABLE_FEAT_AMUv1p1 \
689	ENABLE_FEAT_CPA2 \
690	ENABLE_FEAT_CSV2_2 \
691	ENABLE_FEAT_CSV2_3 \
692	ENABLE_FEAT_DEBUGV8P9 \
693	ENABLE_FEAT_DIT \
694	ENABLE_FEAT_ECV \
695	ENABLE_FEAT_FGT \
696	ENABLE_FEAT_FGT2 \
697	ENABLE_FEAT_FGWTE3 \
698	ENABLE_FEAT_FPMR \
699	ENABLE_FEAT_HCX \
700	ENABLE_FEAT_LS64_ACCDATA \
701	ENABLE_FEAT_MEC \
702	ENABLE_FEAT_MOPS \
703	ENABLE_FEAT_MTE2 \
704	ENABLE_FEAT_PAN \
705	ENABLE_FEAT_RNG \
706	ENABLE_FEAT_RNG_TRAP \
707	ENABLE_FEAT_SEL2 \
708	ENABLE_FEAT_TCR2 \
709	ENABLE_FEAT_THE \
710	ENABLE_FEAT_SB \
711	ENABLE_FEAT_S2PIE \
712	ENABLE_FEAT_S1PIE \
713	ENABLE_FEAT_S2POE \
714	ENABLE_FEAT_S1POE \
715	ENABLE_FEAT_SCTLR2 \
716	ENABLE_FEAT_D128 \
717	ENABLE_FEAT_GCS \
718	ENABLE_FEAT_VHE \
719	ENABLE_FEAT_MPAM \
720	ENABLE_FEAT_MPAM_PE_BW_CTRL \
721	ENABLE_RME \
722	ENABLE_SPE_FOR_NS \
723	ENABLE_SYS_REG_TRACE_FOR_NS \
724	ENABLE_SME_FOR_NS \
725	ENABLE_SME2_FOR_NS \
726	ENABLE_SVE_FOR_NS \
727	ENABLE_TRF_FOR_NS \
728	FW_ENC_STATUS \
729	NR_OF_FW_BANKS \
730	NR_OF_IMAGES_IN_FW_BANK \
731	TWED_DELAY \
732	ENABLE_FEAT_TWED \
733	SVE_VECTOR_LEN \
734	IMPDEF_SYSREG_TRAP \
735	W \
736)))
737
738ifdef KEY_SIZE
739        $(eval $(call assert_numeric,KEY_SIZE))
740endif
741
742ifeq ($(filter $(SANITIZE_UB), on off trap),)
743        $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap")
744endif
745
746################################################################################
747# Add definitions to the cpp preprocessor based on the current build options.
748# This is done after including the platform specific makefile to allow the
749# platform to overwrite the default options
750################################################################################
751
752$(eval $(call add_defines,\
753    $(sort \
754	ALLOW_RO_XLAT_TABLES \
755	ARM_ARCH_MAJOR \
756	ARM_ARCH_MINOR \
757	BL2_ENABLE_SP_LOAD \
758	COLD_BOOT_SINGLE_CPU \
759	CTX_INCLUDE_AARCH32_REGS \
760	CTX_INCLUDE_FPREGS \
761	CTX_INCLUDE_SVE_REGS \
762	CTX_INCLUDE_PAUTH_REGS \
763	CTX_INCLUDE_MPAM_REGS \
764	EL3_EXCEPTION_HANDLING \
765	CTX_INCLUDE_EL2_REGS \
766	CTX_INCLUDE_NEVE_REGS \
767	DEBUG \
768	DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \
769	DISABLE_MTPMU \
770	ENABLE_FEAT_AMU \
771	ENABLE_AMU_AUXILIARY_COUNTERS \
772	AMU_RESTRICT_COUNTERS \
773	ENABLE_ASSERTIONS \
774	ENABLE_BTI \
775	ENABLE_FEAT_DEBUGV8P9 \
776	ENABLE_FEAT_MPAM \
777	ENABLE_FEAT_MPAM_PE_BW_CTRL \
778	ENABLE_PAUTH \
779	ENABLE_FEAT_PAUTH_LR \
780	ENABLE_PIE \
781	ENABLE_PMF \
782	ENABLE_PSCI_STAT \
783	ENABLE_RME \
784	RMMD_ENABLE_EL3_TOKEN_SIGN \
785	RMMD_ENABLE_IDE_KEY_PROG \
786	ENABLE_RUNTIME_INSTRUMENTATION \
787	ENABLE_SME_FOR_NS \
788	ENABLE_SME2_FOR_NS \
789	ENABLE_SME_FOR_SWD \
790	ENABLE_SPE_FOR_NS \
791	ENABLE_SVE_FOR_NS \
792	ENABLE_SVE_FOR_SWD \
793	ENABLE_FEAT_RAS \
794	FFH_SUPPORT \
795	ENCRYPT_BL31 \
796	ENCRYPT_BL32 \
797	ERROR_DEPRECATED \
798	FAULT_INJECTION_SUPPORT \
799	GICV2_G0_FOR_EL3 \
800	HANDLE_EA_EL3_FIRST_NS \
801	HW_ASSISTED_COHERENCY \
802	LOG_LEVEL \
803	MEASURED_BOOT \
804	DISCRETE_TPM \
805	DICE_PROTECTION_ENVIRONMENT \
806	DRTM_SUPPORT \
807	NS_TIMER_SWITCH \
808	PL011_GENERIC_UART \
809	PLAT_EXTRA_LD_SCRIPT \
810	PLAT_${PLAT} \
811	PROGRAMMABLE_RESET_ADDRESS \
812	PSCI_EXTENDED_STATE_ID \
813	PSCI_OS_INIT_MODE \
814	ARCH_FEATURE_AVAILABILITY \
815	RESET_TO_BL31 \
816	RME_GPT_BITLOCK_BLOCK \
817	RME_GPT_MAX_BLOCK \
818	SEPARATE_CODE_AND_RODATA \
819	SEPARATE_BL2_FIP \
820	SEPARATE_BL2_NOLOAD_REGION \
821	SEPARATE_NOBITS_REGION \
822	SEPARATE_RWDATA_REGION \
823	SEPARATE_SIMD_SECTION \
824	RECLAIM_INIT_CODE \
825	SPD_${SPD} \
826	SPIN_ON_BL1_EXIT \
827	SPM_MM \
828	SPMC_AT_EL3 \
829	SPMC_AT_EL3_SEL0_SP \
830	SPMD_SPM_AT_SEL2 \
831	TRANSFER_LIST \
832	TRUSTED_BOARD_BOOT \
833	CRYPTO_SUPPORT \
834	TRNG_SUPPORT \
835	ERRATA_ABI_SUPPORT \
836	ERRATA_NON_ARM_INTERCONNECT \
837	USE_COHERENT_MEM \
838	USE_DEBUGFS \
839	ARM_IO_IN_DTB \
840	SDEI_IN_FCONF \
841	SEC_INT_DESC_IN_FCONF \
842	USE_ROMLIB \
843	USE_TBBR_DEFS \
844	USE_KERNEL_DT_CONVENTION \
845	WARMBOOT_ENABLE_DCACHE_EARLY \
846	RESET_TO_BL2 \
847	BL2_RUNS_AT_EL3	\
848	BL2_IN_XIP_MEM \
849	BL2_INV_DCACHE \
850	USE_SPINLOCK_CAS \
851	ERRATA_SPECULATIVE_AT \
852	ERRATA_SME_POWER_DOWN \
853	RAS_TRAP_NS_ERR_REC_ACCESS \
854	COT_DESC_IN_DTB \
855	USE_SP804_TIMER \
856	ENABLE_FEAT_RNG \
857	ENABLE_FEAT_RNG_TRAP \
858	ENABLE_FEAT_SB \
859	ENABLE_FEAT_DIT \
860	NR_OF_FW_BANKS \
861	NR_OF_IMAGES_IN_FW_BANK \
862	PSA_FWU_SUPPORT \
863	PSA_FWU_METADATA_FW_STORE_DESC \
864	ENABLE_BRBE_FOR_NS \
865	ENABLE_TRBE_FOR_NS \
866	ENABLE_SYS_REG_TRACE_FOR_NS \
867	ENABLE_TRF_FOR_NS \
868	ENABLE_FEAT_HCX \
869	ENABLE_MPMM \
870	ENABLE_FEAT_FGT \
871	ENABLE_FEAT_FGT2 \
872	ENABLE_FEAT_FGWTE3 \
873	ENABLE_FEAT_FPMR \
874	ENABLE_FEAT_ECV \
875	ENABLE_FEAT_AMUv1p1 \
876	ENABLE_FEAT_SEL2 \
877	ENABLE_FEAT_VHE \
878	ENABLE_FEAT_CPA2 \
879	ENABLE_FEAT_CSV2_2 \
880	ENABLE_FEAT_CSV2_3 \
881	ENABLE_FEAT_LS64_ACCDATA \
882	ENABLE_FEAT_MEC \
883	ENABLE_FEAT_PAN \
884	ENABLE_FEAT_TCR2 \
885	ENABLE_FEAT_THE \
886	ENABLE_FEAT_S2PIE \
887	ENABLE_FEAT_S1PIE \
888	ENABLE_FEAT_S2POE \
889	ENABLE_FEAT_S1POE \
890	ENABLE_FEAT_SCTLR2 \
891	ENABLE_FEAT_D128 \
892	ENABLE_FEAT_GCS \
893	ENABLE_FEAT_MOPS \
894	ENABLE_FEAT_GCIE \
895	ENABLE_FEAT_MTE2 \
896	FEATURE_DETECTION \
897	TWED_DELAY \
898	ENABLE_FEAT_TWED \
899	CONDITIONAL_CMO \
900	IMPDEF_SYSREG_TRAP \
901	SVE_VECTOR_LEN \
902	ENABLE_SPMD_LP \
903	PSA_CRYPTO	\
904	ENABLE_CONSOLE_GETC \
905	INIT_UNUSED_NS_EL2	\
906	PLATFORM_REPORT_CTX_MEM_USE \
907	EARLY_CONSOLE \
908	PRESERVE_DSU_PMU_REGS \
909	HOB_LIST \
910	HW_CONFIG_BASE \
911	LFA_SUPPORT \
912)))
913
914ifeq (${PLATFORM_REPORT_CTX_MEM_USE}, 1)
915ifeq (${DEBUG}, 0)
916        $(warning "PLATFORM_REPORT_CTX_MEM_USE can be applied when DEBUG=1 only")
917        override PLATFORM_REPORT_CTX_MEM_USE := 0
918endif
919endif
920
921ifeq (${SANITIZE_UB},trap)
922        $(eval $(call add_define,MONITOR_TRAPS))
923endif #(SANITIZE_UB)
924
925# Define the EL3_PAYLOAD_BASE flag only if it is provided.
926ifdef EL3_PAYLOAD_BASE
927        $(eval $(call add_define,EL3_PAYLOAD_BASE))
928else
929# Define the PRELOADED_BL33_BASE flag only if it is provided and
930# EL3_PAYLOAD_BASE is not defined, as it has priority.
931	ifdef PRELOADED_BL33_BASE
932                $(eval $(call add_define,PRELOADED_BL33_BASE))
933	endif
934endif #(EL3_PAYLOAD_BASE)
935
936# Define the DYN_DISABLE_AUTH flag only if set.
937ifeq (${DYN_DISABLE_AUTH},1)
938        $(eval $(call add_define,DYN_DISABLE_AUTH))
939endif
940
941ifeq ($($(ARCH)-ld-id),arm-link)
942        $(eval $(call add_define,USE_ARM_LINK))
943endif
944
945# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined
946ifeq (${SPD},spmd)
947ifdef SP_LAYOUT_FILE
948	-include $(BUILD_PLAT)/sp_gen.mk
949	FIP_DEPS += sp
950	CRT_DEPS += sp
951	NEED_SP_PKG := yes
952else
953	ifeq (${SPMD_SPM_AT_SEL2},1)
954                $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE")
955	endif
956endif #(SP_LAYOUT_FILE)
957endif #(SPD)
958
959################################################################################
960# Configure the flags for the specified compiler and linker
961################################################################################
962include ${MAKE_HELPERS_DIRECTORY}cflags.mk
963
964################################################################################
965# Build targets
966################################################################################
967
968.PHONY:	all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp tl fwu_fip certtool dtbs memmap doc enctool
969
970all: msg_start
971
972msg_start:
973	$(s)echo "Building ${PLAT}"
974
975$(eval $(call MAKE_LIB,c))
976
977# Expand build macros for the different images
978ifeq (${NEED_BL1},yes)
979BL1_SOURCES := $(sort ${BL1_SOURCES})
980$(eval $(call MAKE_BL,bl1))
981endif #(NEED_BL1)
982
983ifeq (${NEED_BL2},yes)
984
985ifeq (${RESET_TO_BL2}, 0)
986FIP_BL2_ARGS := tb-fw
987endif
988
989BL2_SOURCES := $(sort ${BL2_SOURCES})
990
991ifeq (${SEPARATE_BL2_FIP},1)
992$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS},BL2_)), \
993	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS},BL2_)))
994else
995$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})), \
996	$(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS})))
997endif #(SEPARATE_BL2_FIP)
998
999endif #(NEED_BL2)
1000
1001ifeq (${NEED_SCP_BL2},yes)
1002$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw))
1003endif #(NEED_SCP_BL2)
1004
1005ifeq (${NEED_BL31},yes)
1006BL31_SOURCES += ${SPD_SOURCES}
1007# Sort BL31 source files to remove duplicates
1008BL31_SOURCES := $(sort ${BL31_SOURCES})
1009ifneq (${DECRYPTION_SUPPORT},none)
1010$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\
1011	$(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31))))
1012else
1013$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\
1014	$(eval $(call MAKE_BL,bl31,soc-fw)))
1015endif #(DECRYPTION_SUPPORT)
1016endif #(NEED_BL31)
1017
1018# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the
1019# build system will call TOOL_ADD_IMG to print a warning message and abort the
1020# process. Note that the dependency on BL32 applies to the FIP only.
1021ifeq (${NEED_BL32},yes)
1022# Sort BL32 source files to remove duplicates
1023BL32_SOURCES := $(sort ${BL32_SOURCES})
1024BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1))
1025
1026ifneq (${DECRYPTION_SUPPORT},none)
1027$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\
1028	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32))))
1029else
1030$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\
1031	$(eval $(call TOOL_ADD_IMG,bl32,--tos-fw)))
1032endif #(DECRYPTION_SUPPORT)
1033endif #(NEED_BL32)
1034
1035# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP)
1036# needs to be built from RMM_SOURCES.
1037ifeq (${NEED_RMM},yes)
1038# Sort RMM source files to remove duplicates
1039RMM_SOURCES := $(sort ${RMM_SOURCES})
1040BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1))
1041
1042$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\
1043	 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw)))
1044endif #(NEED_RMM)
1045
1046# Add the BL33 image if required by the platform
1047ifeq (${NEED_BL33},yes)
1048$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw))
1049endif #(NEED_BL33)
1050
1051ifeq (${NEED_BL2U},yes)
1052$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\
1053	$(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_)))
1054endif #(NEED_BL2U)
1055
1056# Expand build macros for the different images
1057ifeq (${NEED_FDT},yes)
1058    $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES)))
1059
1060    ifneq (${INITRD_SIZE}${INITRD_PATH},)
1061        ifndef INITRD_BASE
1062            $(error INITRD_BASE must be set when inserting initrd properties to the DTB.)
1063        endif
1064
1065        INITRD_SIZE ?= $(shell printf "0x%x\n" $$(stat -Lc %s $(INITRD_PATH)))
1066        initrd_end = $(shell printf "0x%x\n" $$(expr $$(($(INITRD_BASE) + $(INITRD_SIZE)))))
1067
1068        define $(HW_CONFIG)-after +=
1069            $(s)echo "  INITRD  $(HW_CONFIG)"
1070            $(q)fdtput -t x $@ /chosen linux,initrd-start $(INITRD_BASE)
1071            $(q)fdtput -t x $@ /chosen linux,initrd-end $(initrd_end)
1072        endef
1073    endif
1074endif #(NEED_FDT)
1075
1076# Add Secure Partition packages
1077ifeq (${NEED_SP_PKG},yes)
1078$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | $$(@D)/
1079	$(if $(host-poetry),$(q)poetry -q install --no-root)
1080	$(q)$(if $(host-poetry),poetry run )${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} ${SP_DTS_LIST_FRAGMENT}
1081sp: $(DTBS) $(BUILD_PLAT)/sp_gen.mk $(SP_PKGS)
1082	$(s)echo
1083	$(s)echo "Built SP Images successfully"
1084	$(s)echo
1085endif #(NEED_SP_PKG)
1086
1087locate-checkpatch:
1088ifndef CHECKPATCH
1089	$(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1090else
1091ifeq (,$(wildcard ${CHECKPATCH}))
1092	$(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl")
1093endif
1094endif #(CHECKPATCH)
1095
1096clean:
1097	$(s)echo "  CLEAN"
1098	$(q)rm -rf $(BUILD_PLAT)
1099	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1100	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1101	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1102	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1103	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1104	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1105
1106realclean distclean:
1107	$(s)echo "  REALCLEAN"
1108	$(q)rm -rf $(BUILD_BASE)
1109	$(q)rm -rf $(CURDIR)/cscope.*
1110	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${FIPTOOLPATH} clean
1111	$(q)rm -rf ${FIPTOOLPATH}/fiptool
1112	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${CRTTOOLPATH} clean
1113	$(q)rm -rf ${CRTTOOLPATH}/cert_create
1114	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=${BUILD_PLAT} --no-print-directory -C ${ENCTOOLPATH} clean
1115	$(q)${MAKE} --no-print-directory -C ${ROMLIBPATH} clean
1116
1117checkcodebase:		locate-checkpatch
1118	$(s)echo "  CHECKING STYLE"
1119	$(q)if test -d .git ; then						\
1120		git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' |	\
1121		while read GIT_FILE ;					\
1122		do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ;	\
1123		done ;							\
1124	else								\
1125		 find . -type f -not -iwholename "*.git*"		\
1126		 -not -iwholename "*build*"				\
1127		 -not -iwholename "*libfdt*"				\
1128		 -not -iwholename "*libc*"				\
1129		 -not -iwholename "*docs*"				\
1130		 -not -iwholename "*.rst"				\
1131		 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ;	\
1132	fi
1133
1134checkpatch:		locate-checkpatch
1135	$(s)echo "  CHECKING STYLE"
1136	$(q)if test -n "${CHECKPATCH_OPTS}"; then				\
1137		echo "    with ${CHECKPATCH_OPTS} option(s)";		\
1138	fi
1139	$(q)COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT});	\
1140	for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`;	\
1141	do								\
1142		printf "\n[*] Checking style of '$$commit'\n\n";	\
1143		( git log --format=email "$$commit~..$$commit"		\
1144			-- ${CHECK_PATHS} ;				\
1145		  git diff --format=email "$$commit~..$$commit"		\
1146			-- ${CHECK_PATHS}; ) |				\
1147			${CHECKPATCH}  ${CHECKPATCH_OPTS} - || true;	\
1148	done
1149
1150certtool: ${CRTTOOL}
1151
1152${CRTTOOL}: FORCE | $$(@D)/
1153	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${CRTTOOLPATH} all
1154	$(q)ln -sf ${CRTTOOL} ${CRTTOOLPATH}/cert_create
1155	$(s)echo
1156	$(s)echo "Built $@ successfully"
1157	$(s)echo
1158
1159ifneq (${GENERATE_COT},0)
1160certificates: ${CRT_DEPS} ${CRTTOOL} ${DTBS}
1161	$(q)${CRTTOOL} ${CRT_ARGS}
1162	$(s)echo
1163	$(s)echo "Built $@ successfully"
1164	$(s)echo "Certificates can be found in ${BUILD_PLAT}"
1165	$(s)echo
1166endif #(GENERATE_COT)
1167
1168ifeq (${SEPARATE_BL2_FIP},1)
1169${BUILD_PLAT}/${BL2_FIP_NAME}: ${BL2_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1170	$(eval ${CHECK_BL2_FIP_CMD})
1171	$(q)${FIPTOOL} create ${BL2_FIP_ARGS} $@
1172	$(q)${FIPTOOL} info $@
1173	$(s)echo
1174	$(s)echo "Built $@ successfully"
1175	$(s)echo
1176endif #(SEPARATE_BL2_FIP)
1177
1178${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} | $$(@D)/
1179	$(eval ${CHECK_FIP_CMD})
1180	$(q)${FIPTOOL} create ${FIP_ARGS} $@
1181	$(q)${FIPTOOL} info $@
1182	$(s)echo
1183	$(s)echo "Built $@ successfully"
1184	$(s)echo
1185
1186ifneq (${GENERATE_COT},0)
1187fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL}
1188	$(q)${CRTTOOL} ${FWU_CRT_ARGS}
1189	$(s)echo
1190	$(s)echo "Built $@ successfully"
1191	$(s)echo "FWU certificates can be found in ${BUILD_PLAT}"
1192	$(s)echo
1193endif #(GENERATE_COT)
1194
1195ifneq (${GENERATE_COT},0)
1196bl2_certificates: ${BUILD_PLAT}/${FIP_NAME} ${BL2_CRT_DEPS} ${CRTTOOL} | ${BUILD_PLAT}/
1197	$(q)${CRTTOOL} ${BL2_CRT_ARGS}
1198	$(s)echo
1199	$(s)echo "Built $@ successfully"
1200	$(s)echo "BL2 certificates can be found in ${BUILD_PLAT}"
1201	$(s)echo
1202endif #(GENERATE_COT)
1203
1204${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL} | $$(@D)/
1205	$(eval ${CHECK_FWU_FIP_CMD})
1206	$(q)${FIPTOOL} create ${FWU_FIP_ARGS} $@
1207	$(q)${FIPTOOL} info $@
1208	$(s)echo
1209	$(s)echo "Built $@ successfully"
1210	$(s)echo
1211
1212fiptool: ${FIPTOOL}
1213ifeq (${SEPARATE_BL2_FIP},1)
1214bl2_fip: ${BUILD_PLAT}/${BL2_FIP_NAME}
1215fip: bl2_fip
1216else
1217fip: ${BUILD_PLAT}/${FIP_NAME}
1218endif #(SEPARATE_BL2_FIP)
1219fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME}
1220
1221# symlink for compatibility before tools were in the build directory
1222${FIPTOOL}: FORCE | $$(@D)/
1223	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${FIPTOOLPATH} all
1224	$(q)ln -sf ${FIPTOOL} ${FIPTOOLPATH}/fiptool
1225
1226$(BUILD_PLAT)/romlib/romlib.bin $(BUILD_PLAT)/lib/libwrappers.a $&: $(BUILD_PLAT)/lib/libfdt.a $(BUILD_PLAT)/lib/libc.a $(CRYPTO_LIB) | $$(@D)/
1227	$(q)${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} CRYPTO_SUPPORT=${CRYPTO_SUPPORT} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES=$(call escape-shell,$(INCLUDES)) DEFINES=$(call escape-shell,$(DEFINES)) --no-print-directory -C ${ROMLIBPATH} all
1228
1229memmap: all
1230	$(if $(host-poetry),$(q)poetry -q install --no-root)
1231	$(q)$(if $(host-poetry),poetry run )memory --root ${BUILD_PLAT} symbols
1232
1233tl: ${BUILD_PLAT}/tl.bin
1234${BUILD_PLAT}/tl.bin: ${HW_CONFIG} | $$(@D)/
1235	$(if $(host-poetry),$(q)poetry -q install --no-root)
1236	$(q)$(if $(host-poetry),poetry run )tlc create --fdt $< -s ${FW_HANDOFF_SIZE} $@
1237
1238doc:
1239	$(s)echo "  BUILD DOCUMENTATION"
1240	$(if $(host-poetry),$(q)poetry -q install --with docs --no-root)
1241	$(q)$(if $(host-poetry),poetry run )${MAKE} --no-print-directory -C ${DOCS_PATH} BUILDDIR=$(abspath ${BUILD_BASE}/docs) html
1242
1243enctool: ${ENCTOOL}
1244
1245${ENCTOOL}: FORCE | $$(@D)/
1246	$(q)${MAKE} PLAT=${PLAT} BUILD_PLAT=$(abspath ${BUILD_PLAT}) BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} DEBUG=${DEBUG} --no-print-directory -C ${ENCTOOLPATH} all
1247	$(s)echo
1248	$(s)echo "Built $@ successfully"
1249	$(s)echo
1250
1251cscope:
1252	$(s)echo "  CSCOPE"
1253	$(q)find ${CURDIR} -name "*.[chsS]" > cscope.files
1254	$(q)cscope -b -q -k
1255
1256help:
1257	$(s)echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]"
1258	$(s)echo ""
1259	$(s)echo "PLAT is used to specify which platform you wish to build."
1260	$(s)echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
1261	$(s)echo ""
1262	$(s)echo "platform = ${PLATFORM_LIST}"
1263	$(s)echo ""
1264	$(s)echo "Please refer to the User Guide for a list of all supported options."
1265	$(s)echo "Note that the build system doesn't track dependencies for build "
1266	$(s)echo "options. Therefore, if any of the build options are changed "
1267	$(s)echo "from a previous build, a clean build must be performed."
1268	$(s)echo ""
1269	$(s)echo "Supported Targets:"
1270	$(s)echo "  all            Build all individual bootloader binaries"
1271	$(s)echo "  bl1            Build the BL1 binary"
1272	$(s)echo "  bl2            Build the BL2 binary"
1273	$(s)echo "  bl2u           Build the BL2U binary"
1274	$(s)echo "  bl31           Build the BL31 binary"
1275	$(s)echo "  bl32           Build the BL32 binary. If ARCH=aarch32, then "
1276	$(s)echo "                 this builds secure payload specified by AARCH32_SP"
1277	$(s)echo "  certificates   Build the certificates (requires 'GENERATE_COT=1')"
1278	$(s)echo "  fip            Build the Firmware Image Package (FIP)"
1279	$(s)echo "  fwu_fip        Build the FWU Firmware Image Package (FIP)"
1280	$(s)echo "  checkcodebase  Check the coding style of the entire source tree"
1281	$(s)echo "  checkpatch     Check the coding style on changes in the current"
1282	$(s)echo "                 branch against BASE_COMMIT (default origin/master)"
1283	$(s)echo "  clean          Clean the build for the selected platform"
1284	$(s)echo "  cscope         Generate cscope index"
1285	$(s)echo "  distclean      Remove all build artifacts for all platforms"
1286	$(s)echo "  certtool       Build the Certificate generation tool"
1287	$(s)echo "  enctool        Build the Firmware encryption tool"
1288	$(s)echo "  fiptool        Build the Firmware Image Package (FIP) creation tool"
1289	$(s)echo "  sp             Build the Secure Partition Packages"
1290	$(s)echo "  sptool         Build the Secure Partition Package creation tool"
1291	$(s)echo "  dtbs           Build the Device Tree Blobs (if required for the platform)"
1292	$(s)echo "  memmap         Print the memory map of the built binaries"
1293	$(s)echo "  doc            Build html based documentation using Sphinx tool"
1294	$(s)echo ""
1295	$(s)echo "Note: most build targets require PLAT to be set to a specific platform."
1296	$(s)echo ""
1297	$(s)echo "example: build all targets for the FVP platform:"
1298	$(s)echo "  CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"
1299
1300.PHONY: FORCE
1301FORCE:;
1302