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