blob: d5a18be5579a625a66d68a164f755758441dfb09 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Harrison Mutai0ed12502025-05-09 08:51:02 +00002# Copyright (c) 2018-2025, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7# TFTF Version
8VERSION_MAJOR := 2
Harrison Mutai0ed12502025-05-09 08:51:02 +00009VERSION_MINOR := 13
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010
Leonardo Sandoval667fd722020-09-11 12:50:19 -050011MAKE_HELPERS_DIRECTORY := make_helpers/
12include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
13
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020014################################################################################
15# Default values for build configurations, and their dependencies
16################################################################################
17
Leonardo Sandoval667fd722020-09-11 12:50:19 -050018include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020019
20PLAT := ${DEFAULT_PLAT}
21
22# Assertions enabled for DEBUG builds by default
23ENABLE_ASSERTIONS := ${DEBUG}
24
25################################################################################
26# Checkpatch script options
27################################################################################
28
29CHECKCODE_ARGS := --no-patch
30# Do not check the coding style on imported library files or documentation files
31INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Mark Dykese7810b52020-06-03 15:46:55 -050032 include/lib/libfdt \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000033 include/lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020034 $(wildcard include/lib/*)))
35LIB_DIRS_TO_CHECK := $(sort $(filter-out \
36 lib/compiler-rt \
Mark Dykese7810b52020-06-03 15:46:55 -050037 lib/libfdt% \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000038 lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020039 $(wildcard lib/*)))
40ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
41 lib \
42 include \
43 docs \
44 %.md \
45 %.rst, \
46 $(wildcard *)))
47CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
48 ${INC_LIB_DIRS_TO_CHECK} \
49 ${LIB_DIRS_TO_CHECK}
50
51ifeq (${V},0)
52 Q=@
53else
54 Q=
55endif
56export Q
57
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010058################################################################################
59# Toolchain configs
60################################################################################
61CC := ${CROSS_COMPILE}gcc
62CPP := ${CROSS_COMPILE}cpp
63AS := ${CROSS_COMPILE}gcc
64AR := ${CROSS_COMPILE}ar
65LD := ${CROSS_COMPILE}ld
66OC := ${CROSS_COMPILE}objcopy
67OD := ${CROSS_COMPILE}objdump
68NM := ${CROSS_COMPILE}nm
69PP := ${CROSS_COMPILE}gcc
70
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020071ifneq (${DEBUG}, 0)
72 BUILD_TYPE := debug
73 # Use LOG_LEVEL_INFO by default for debug builds
74 LOG_LEVEL := 40
75else
76 BUILD_TYPE := release
77 # Use LOG_LEVEL_ERROR by default for release builds
78 LOG_LEVEL := 20
79endif
80
81# Default build string (git branch and commit)
82ifeq (${BUILD_STRING},)
Manish V Badarkhece149412022-05-24 22:54:45 +010083 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020084endif
85
86VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
87
88BUILD_BASE := ./build
89BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
90
91PLAT_MAKEFILE := platform.mk
92# Generate the platforms list by recursively searching for all directories
93# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
94# char and strip out the final '|'.
95PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
96 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
97 sed -r 's/\|$$//')
98
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +020099DOCS_PATH := docs
100
Govindraj Raja51f03332025-06-27 13:47:23 +0000101# Path to Transfer List Library (LibTL)
102LIBTL_PATH := contrib/libtl
103
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200104ifeq (${PLAT},)
105 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
106endif
107PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
108PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
109ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
110 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
111endif
112
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500113
114EL3_PAYLOAD_PLAT_PATH := $(shell find el3_payload/plat/ -wholename '*/${PLAT}')
115EL3_PAYLOAD_PLAT_MAKEFILE_FULL := ${EL3_PAYLOAD_PLAT_PATH}/${PLAT_MAKEFILE}
116
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200117.PHONY: all
118all: msg_start
119
120.PHONY: msg_start
121msg_start:
122 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200123 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200124
Shruti Guptac973b2a2023-07-12 12:10:54 +0100125# Set flags for Realm Payload Tests
126ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
Shruti Gupta24597d12023-10-02 10:40:19 +0100127ARM_ARCH_MINOR := 5
Shruti Guptac973b2a2023-07-12 12:10:54 +0100128BRANCH_PROTECTION := 2
129endif
130
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200131# Include test images makefiles.
132include tftf/framework/framework.mk
133include tftf/tests/tests.mk
134include fwu/ns_bl1u/ns_bl1u.mk
135include fwu/ns_bl2u/ns_bl2u.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100136
Daniel Boulbyf6c288e2022-07-25 14:07:57 +0100137# List of secure partitions present.
138SECURE_PARTITIONS :=
139
Jerry Wangd49873a2024-07-25 13:45:13 +0100140# Only platform fvp and rdv3 supports cactus_mm
141ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-rdv3))
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000142include spm/cactus_mm/cactus_mm.mk
nabkah01002e5692022-10-10 12:36:46 +0100143include realm/realm.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100144endif
145
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100146# cactus and ivy are supported on platforms: fvp, tc
147ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100148include spm/cactus/cactus.mk
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100149include spm/ivy/ivy.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100150endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200151
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000152################################################################################
153# Include libc
154################################################################################
155include lib/libc/libc.mk
156
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200157# Include platform specific makefile last because:
158# - the platform makefile may use all previous definitions in this file.
159# - the platform makefile may wish overwriting some of them.
160include ${PLAT_MAKEFILE_FULL}
161
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200162.SUFFIXES:
163
164################################################################################
165# Build options checks
166################################################################################
167$(eval $(call assert_boolean,DEBUG))
168$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
169$(eval $(call assert_boolean,FIRMWARE_UPDATE))
170$(eval $(call assert_boolean,FWU_BL_TEST))
171$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200172$(eval $(call assert_boolean,USE_NVM))
Shruti Guptac973b2a2023-07-12 12:10:54 +0100173$(eval $(call assert_numeric,BRANCH_PROTECTION))
174$(eval $(call assert_boolean,ENABLE_REALM_PAYLOAD_TESTS))
Harrison Mutai6e011642023-09-22 17:17:35 +0100175$(eval $(call assert_boolean,TRANSFER_LIST))
Madhukar Pappireddy6f7344b2024-07-05 16:21:26 -0500176$(eval $(call assert_boolean,SPMC_AT_EL3))
Madhukar Pappireddya2b6b372025-02-11 15:39:32 -0600177$(eval $(call assert_boolean,CACTUS_PWR_MGMT_SUPPORT))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200178
179################################################################################
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100180# Process build options
181################################################################################
182
183# Process BRANCH_PROTECTION value and set
184# Pointer Authentication and Branch Target Identification flags
185include branch_protection.mk
186
187################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200188# Add definitions to the cpp preprocessor based on the current build options.
189# This is done after including the platform specific makefile to allow the
190# platform to overwrite the default options
191################################################################################
192$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
193$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
194$(eval $(call add_define,TFTF_DEFINES,DEBUG))
195$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100196$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000197$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200198$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
199$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
200$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200201$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
Soby Mathew6e5c9962023-10-06 16:38:13 +0100202$(eval $(call add_define,TFTF_DEFINES,ENABLE_REALM_PAYLOAD_TESTS))
Harrison Mutai6e011642023-09-22 17:17:35 +0100203$(eval $(call add_define,TFTF_DEFINES,TRANSFER_LIST))
Juan Pablo Condec3cf2da2024-04-01 13:57:19 -0500204$(eval $(call add_define,TFTF_DEFINES,PLAT_AMU_GROUP1_COUNTERS_MASK))
Madhukar Pappireddy6f7344b2024-07-05 16:21:26 -0500205$(eval $(call add_define,TFTF_DEFINES,SPMC_AT_EL3))
Madhukar Pappireddya2b6b372025-02-11 15:39:32 -0600206$(eval $(call add_define,TFTF_DEFINES,CACTUS_PWR_MGMT_SUPPORT))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200207
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200208################################################################################
209
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100210################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200211# Assembler, compiler and linker flags shared across all test images.
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100212################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200213COMMON_ASFLAGS :=
214COMMON_CFLAGS :=
215COMMON_LDFLAGS :=
216
217ifeq (${DEBUG},1)
Daniel Boulbyed1f9512022-05-03 16:36:51 +0100218COMMON_CFLAGS += -g -gdwarf-4
219COMMON_ASFLAGS += -g -Wa,--gdwarf-4
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200220endif
221
Joel Hutton6a6f4832019-04-08 15:46:36 +0100222# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
223ifeq (${ARM_ARCH_MINOR},0)
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000224march32-directive = -march=armv${ARM_ARCH_MAJOR}-a
225march64-directive = -march=armv${ARM_ARCH_MAJOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100226else
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000227march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
228march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100229endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200230
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000231# Get architecture feature modifiers
232arch-features = ${ARM_ARCH_FEATURE}
233
234# Set the compiler's architecture feature modifiers
235ifneq ($(arch-features), none)
236ifeq ($(ARCH), aarch32)
237march32-directive := $(march32-directive)+$(arch-features)
238else
239march64-directive := $(march64-directive)+$(arch-features)
240endif
241# Print features
242$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
243endif # arch-features
244
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100245################################################################################
246# Compiler settings
247################################################################################
248ifneq ($(findstring clang,$(notdir $(CC))),)
249CLANG_CFLAGS_aarch64 := -target aarch64-elf
Joel Hutton6a6f4832019-04-08 15:46:36 +0100250
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100251CPP := $(CC) -E $(COMMON_CFLAGS_$(ARCH))
252PP := $(CC) -E $(COMMON_CFLAGS_$(ARCH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200253
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100254CLANG_WARNINGS += -nostdinc -ffreestanding -Wall \
255 -Wmissing-include-dirs $(CLANG_CFLAGS_$(ARCH)) \
256 -Wlogical-op-parentheses \
257 -Wno-initializer-overrides \
258 -Wno-sometimes-uninitialized \
259 -Wno-unused-function \
260 -Wno-unused-variable \
261 -Wno-unused-parameter \
262 -Wno-tautological-compare \
263 -Wno-memset-transposed-args \
264 -Wno-parentheses
265
266CLANG_CFLAGS += -Wno-error=deprecated-declarations \
267 -Wno-error=cpp \
268 $(CLANG_WARNINGS)
269endif #(clang)
270
271ifneq ($(findstring gcc,$(notdir $(CC))),)
272GCC_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
273GCC_CFLAGS_aarch64 := -mgeneral-regs-only
274
275GCC_ASFLAGS_aarch32 := ${march32-directive}
276GCC_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
277
278GCC_WARNINGS += -nostdinc -ffreestanding -Wall -Werror \
279 -Wmissing-include-dirs $(GCC_CFLAGS_$(ARCH)) \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200280 -std=gnu99 -Os
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100281
282# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
283GCC_CFLAGS += $(call cc_option, --param=min-pagesize=0)
284GCC_CFLAGS += $(GCC_WARNINGS)
285endif #(gcc)
286
287COMMON_CFLAGS_aarch64 += ${march64-directive} -mstrict-align \
288 $(CLANG_CFLAGS_$(ARCH)) $(GCC_CFLAGS_$(ARCH))
289
290COMMON_CFLAGS += $(COMMON_CFLAGS_$(ARCH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200291COMMON_CFLAGS += -ffunction-sections -fdata-sections
292
293# Get the content of CFLAGS user defined value last so they are appended after
294# the options defined in the Makefile
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100295COMMON_CFLAGS += ${CLANG_CFLAGS} ${GCC_CFLAGS} ${INCLUDES}
296
297COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
298 -Werror -Wmissing-include-dirs \
299 -D__ASSEMBLY__ $(GCC_ASFLAGS_$(ARCH)) \
300 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200301
Karl Meakine69d1282023-03-07 17:10:07 +0000302COMMON_LDFLAGS += ${LDFLAGS} --fatal-warnings -O1 --gc-sections --build-id=none
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200303
Soby Mathew25d9e2f2023-05-05 10:51:57 +0100304# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
305# are not loaded by a elf loader.
306COMMON_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
307
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200308################################################################################
309
Mark Dykese7810b52020-06-03 15:46:55 -0500310TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200311TFTF_INCLUDES += ${PLAT_INCLUDES}
312TFTF_CFLAGS += ${COMMON_CFLAGS}
313TFTF_ASFLAGS += ${COMMON_ASFLAGS}
314TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykese7810b52020-06-03 15:46:55 -0500315TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200316
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100317ifneq (${BP_OPTION},none)
318TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
319NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
320NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
321CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
322CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
323IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
AlexeiFedorov193b3562022-12-22 16:50:08 +0000324REALM_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000325endif
326
Mark Dykese7810b52020-06-03 15:46:55 -0500327ifeq ($(SMC_FUZZING), 1)
328TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
329endif
330
Olivier Deprez231115d2020-02-03 11:27:01 +0100331#####################################################################################
332ifneq ($(findstring gcc,$(notdir $(LD))),)
333 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
334else
335 PIE_LDFLAGS += -pie --no-dynamic-linker
336endif
337
338#####################################################################################
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000339NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200340NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
341NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
342NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
343NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
344
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000345NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200346NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
347NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
348NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
349NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
350
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000351CACTUS_MM_SOURCES += ${LIBC_SRCS}
352CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
353CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
354CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
355CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
356
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000357CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200358CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprez231115d2020-02-03 11:27:01 +0100359CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200360CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprez231115d2020-02-03 11:27:01 +0100361CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200362
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000363IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000364IVY_INCLUDES += ${PLAT_INCLUDES}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100365IVY_CFLAGS += ${COMMON_CFLAGS} -fpie
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000366IVY_ASFLAGS += ${COMMON_ASFLAGS}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100367IVY_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000368
nabkah01002e5692022-10-10 12:36:46 +0100369REALM_SOURCES += ${LIBC_SRCS}
370REALM_CFLAGS += ${COMMON_CFLAGS} -fpie
371REALM_ASFLAGS += ${COMMON_ASFLAGS}
372REALM_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
373
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200374.PHONY: locate-checkpatch
375locate-checkpatch:
376ifndef CHECKPATCH
377 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
378else
379ifeq (,$(wildcard ${CHECKPATCH}))
380 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
381endif
382endif
383
384.PHONY: clean
385clean:
386 @echo " CLEAN"
387 ${Q}rm -rf ${BUILD_PLAT}
Shriram K86879852022-09-15 15:45:05 +0530388ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200389 ${MAKE} -C el3_payload clean
Shriram K86879852022-09-15 15:45:05 +0530390endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200391
392.PHONY: realclean distclean
393realclean distclean:
394 @echo " REALCLEAN"
395 ${Q}rm -rf ${BUILD_BASE}
396 ${Q}rm -f ${CURDIR}/cscope.*
Shriram K86879852022-09-15 15:45:05 +0530397ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200398 ${MAKE} -C el3_payload distclean
Shriram K86879852022-09-15 15:45:05 +0530399endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200400
401.PHONY: checkcodebase
402checkcodebase: locate-checkpatch
403 @echo " CHECKING STYLE"
404 @if test -d .git ; then \
Mark Dykese7810b52020-06-03 15:46:55 -0500405 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200406 while read GIT_FILE ; \
407 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
408 done ; \
409 else \
410 find . -type f -not -iwholename "*.git*" \
411 -not -iwholename "*build*" \
Mark Dykese7810b52020-06-03 15:46:55 -0500412 -not -iwholename "*libfdt*" \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000413 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200414 -not -iwholename "*docs*" \
415 -not -iwholename "*.md" \
416 -not -iwholename "*.rst" \
417 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
418 fi
419
420.PHONY: checkpatch
421checkpatch: locate-checkpatch
422 @echo " CHECKING STYLE"
423 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
424 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
425 printf "\n[*] Checking style of '$$commit'\n\n"; \
426 git log --format=email "$$commit~..$$commit" \
427 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
428 git diff --format=email "$$commit~..$$commit" \
429 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
430 done
431
432ifneq (${FIRMWARE_UPDATE},1)
433.PHONY: ns_bl1u ns_bl2u
434ns_bl1u ns_bl2u:
435 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
436 on this platform."
437 @exit 1
438endif
439
Jerry Wangd49873a2024-07-25 13:45:13 +0100440ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-rdv3))
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000441.PHONY: cactus_mm
442cactus_mm:
443 @echo "ERROR: $@ is supported only on AArch64 FVP."
444 @exit 1
445
nabkah01002e5692022-10-10 12:36:46 +0100446.PHONY: realm
447realm:
Jerry Wangd49873a2024-07-25 13:45:13 +0100448 @echo "ERROR: $@ is supported only on AArch64 FVP and RD-V3."
nabkah01002e5692022-10-10 12:36:46 +0100449 @exit 1
450
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200451endif
452
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100453ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100454.PHONY: cactus
455cactus:
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100456 @echo "ERROR: $@ is supported only on AArch64 FVP or TC."
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100457 @exit 1
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100458
459.PHONY: ivy
460ivy:
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100461 @echo "ERROR: $@ is supported only on AArch64 FVP or TC."
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100462 @exit 1
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100463endif
464
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200465MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
466
467define MAKE_C
468
469$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
470$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
471
Bence Szépkúti537b3582019-11-29 18:23:56 +0100472$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200473 @echo " CC $$<"
474 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
475
476-include $(DEP)
477endef
478
479
480define MAKE_S
481
482$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
483$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
484
Bence Szépkúti537b3582019-11-29 18:23:56 +0100485$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200486 @echo " AS $$<"
487 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
488
489-include $(DEP)
490endef
491
492
493define MAKE_LD
494
495$(eval DEP := $(1).d)
496
Bence Szépkúti537b3582019-11-29 18:23:56 +0100497$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200498 @echo " PP $$<"
499 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
500
501-include $(DEP)
502endef
503
504
505define MAKE_OBJS
506 $(eval C_OBJS := $(filter %.c,$(2)))
507 $(eval REMAIN := $(filter-out %.c,$(2)))
508 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
509
510 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
511 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
512 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
513
514 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
515endef
516
Boyan Karatotev11221142024-10-21 10:11:29 +0100517${BUILD_PLAT}:
518 $(Q)mkdir -p "$@"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200519
520# NOTE: The line continuation '\' is required in the next define otherwise we
521# end up with a line-feed characer at the end of the last c filename.
522# Also bare this issue in mind if extending the list of supported filetypes.
523define SOURCES_TO_OBJS
524 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
525 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
526endef
527
528define uppercase
529$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
530endef
531
532define MAKE_IMG
533 $(eval IMG_PREFIX := $(call uppercase, $(1)))
534 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
535 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
536 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykese7810b52020-06-03 15:46:55 -0500537 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200538 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
539 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
540 $(eval ELF := $(BUILD_DIR)/$(1).elf)
541 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
542 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
543
544 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
545 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
546
Boyan Karatotev11221142024-10-21 10:11:29 +0100547$(BUILD_DIR) : ${BUILD_PLAT}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200548 $$(Q)mkdir -p "$$@"
549
550$(ELF) : $(OBJS) $(LINKERFILE)
551 @echo " LD $$@"
552 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
553 const char version_string[] = "${VERSION_STRING}";' | \
554 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
555 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
556 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
557
558$(DUMP) : $(ELF)
559 @echo " OD $$@"
560 $${Q}$${OD} -dx $$< > $$@
561
562$(BIN) : $(ELF)
563 @echo " BIN $$@"
564 $$(Q)$$(OC) -O binary $$< $$@
565 @echo
566 @echo "Built $$@ successfully"
567 @echo
568
569.PHONY : $(1)
570$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
571
572all : $(1)
573
574endef
575
Shruti Gupta2eb601b2023-03-29 21:35:17 +0100576ifeq (${ARCH},aarch32)
577 ARCH_TESTS_SKIP_LIST := tftf/tests/aarch32_tests_to_skip.txt
578endif
579
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200580$(AUTOGEN_DIR):
581 $(Q)mkdir -p "$@"
582
Boyan Karatotevada6a862024-10-21 10:06:50 +0100583$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h &: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST} $(ARCH_TESTS_SKIP_LIST)
584 @echo " AUTOGEN $(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h"
Jim Ray7ba27bf2023-05-25 14:11:51 -0700585 tools/generate_test_list/generate_test_list.py $(AUTOGEN_DIR)/tests_list.c \
586 $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} \
587 --plat-skip-file=$(PLAT_TESTS_SKIP_LIST) \
588 --arch-skip-file=$(ARCH_TESTS_SKIP_LIST)
Mark Dykese7810b52020-06-03 15:46:55 -0500589ifeq ($(SMC_FUZZING), 1)
590 $(Q)mkdir -p ${BUILD_PLAT}/smcf
591 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
592 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
johpow01d5c79cc2021-06-23 16:10:22 -0500593 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_start=_binary___dtb_start \
594 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_end=_binary___dtb_end
Mark Dykese7810b52020-06-03 15:46:55 -0500595endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200596
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200597ifeq ($(FIRMWARE_UPDATE), 1)
598 $(eval $(call MAKE_IMG,ns_bl1u))
599 $(eval $(call MAKE_IMG,ns_bl2u))
600endif
601
602ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000603 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200604 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000605 $(eval $(call MAKE_IMG,ivy))
Shruti Guptac973b2a2023-07-12 12:10:54 +0100606endif
607
Shruti Guptac973b2a2023-07-12 12:10:54 +0100608.PHONY : tftf
609 $(eval $(call MAKE_IMG,tftf))
610
Arunachalam Ganapathy292a48a2023-10-27 16:46:36 +0100611# Build flag 'ENABLE_REALM_PAYLOAD_TESTS=1' builds and pack Realm Payload Tests
Shruti Guptac973b2a2023-07-12 12:10:54 +0100612ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
Arunachalam Ganapathy292a48a2023-10-27 16:46:36 +0100613 $(eval $(call MAKE_IMG,realm))
614
615# This forces to rebuild tftf.bin. For incremental build this re-creates tftf.bin
616# and removes the old realm payload packed by the last build.
617.PHONY : $(BUILD_PLAT)/tftf.bin
618
Shruti Guptac973b2a2023-07-12 12:10:54 +0100619tftf: realm
620 @echo " PACK REALM PAYLOAD"
621 $(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
Soby Mathew6e5c9962023-10-06 16:38:13 +0100622 oflag=append conv=notrunc)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200623endif
624
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100625ifeq (${ARCH}-${PLAT},aarch64-tc)
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100626 $(eval $(call MAKE_IMG,cactus))
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100627 $(eval $(call MAKE_IMG,ivy))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100628endif
629
Boyan Karatotev11221142024-10-21 10:11:29 +0100630SP_LAYOUT: ${BUILD_PLAT}
Daniel Boulbyf6c288e2022-07-25 14:07:57 +0100631 ${Q}tools/generate_json/generate_json.sh \
632 $(BUILD_PLAT) $(SECURE_PARTITIONS)
633
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200634# The EL3 test payload is only supported in AArch64. It has an independent build
635# system.
636.PHONY: el3_payload
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100637# TODO: EL3 test payload currently is supported for GCC only. It has an independent
638# build system and support for Clang to be added.
639ifneq ($(findstring gcc,$(notdir $(CC))),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200640ifneq (${ARCH},aarch32)
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500641ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200642el3_payload: $(BUILD_DIR)
643 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
644 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
645
646all: el3_payload
647endif
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500648endif
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100649endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200650
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200651doc:
652 @echo " BUILD DOCUMENTATION"
653 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
654
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200655.PHONY: cscope
656cscope:
657 @echo " CSCOPE"
658 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
659 ${Q}cscope -b -q -k
660
661.PHONY: help
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500662.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200663help:
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500664 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Shruti Guptac973b2a2023-07-12 12:10:54 +0100665<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500666 echo ""
667 echo "PLAT is used to specify which platform you wish to build."
668 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
669 echo ""
670 echo "Supported Targets:"
671 echo " all Build all supported binaries for this platform"
672 echo " (i.e. TFTF and FWU images)"
673 echo " tftf Build the TFTF image"
674 echo " ns_bl1u Build the NS_BL1U image"
675 echo " ns_bl2u Build the NS_BL2U image"
Olivier Deprez40777f82022-11-09 10:15:28 +0100676 echo " cactus Build the Cactus image (FF-A S-EL1 test payload)."
677 echo " cactus_mm Build the Cactus-MM image (SPM-MM S-EL0 test payload)."
678 echo " ivy Build the Ivy image (FF-A S-EL0 test payload)."
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500679 echo " el3_payload Build the EL3 test payload"
680 echo " checkcodebase Check the coding style of the entire source tree"
681 echo " checkpatch Check the coding style on changes in the current"
682 echo " branch against BASE_COMMIT (default origin/master)"
683 echo " doc Build html based documentation using Sphinx tool"
684 echo " clean Clean the build for the selected platform"
685 echo " cscope Generate cscope index"
686 echo " distclean Remove all build artifacts for all platforms"
687 echo " help_tests List all possible sets of tests"
688 echo ""
689 echo "note: most build targets require PLAT to be set to a specific platform."
690 echo ""
691 echo "example: build all targets for the FVP platform:"
692 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"