blob: d8c979a6c0708108c3ed1f16975d1ec4d036e7ee [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Yann Gautier4a8d7582024-04-05 09:55:25 +02002# Copyright (c) 2018-2024, 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
Juan Pablo Conde67fc3702023-11-13 17:46:50 -06009VERSION_MINOR := 10
Yann Gautier4a8d7582024-04-05 09:55:25 +020010VERSION_PATCH := 3
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020011
Leonardo Sandoval667fd722020-09-11 12:50:19 -050012MAKE_HELPERS_DIRECTORY := make_helpers/
13include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
14
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020015################################################################################
16# Default values for build configurations, and their dependencies
17################################################################################
18
Leonardo Sandoval667fd722020-09-11 12:50:19 -050019include ${MAKE_HELPERS_DIRECTORY}defaults.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020020
21PLAT := ${DEFAULT_PLAT}
22
23# Assertions enabled for DEBUG builds by default
24ENABLE_ASSERTIONS := ${DEBUG}
25
26################################################################################
27# Checkpatch script options
28################################################################################
29
30CHECKCODE_ARGS := --no-patch
31# Do not check the coding style on imported library files or documentation files
32INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Mark Dykese7810b52020-06-03 15:46:55 -050033 include/lib/libfdt \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000034 include/lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020035 $(wildcard include/lib/*)))
36LIB_DIRS_TO_CHECK := $(sort $(filter-out \
37 lib/compiler-rt \
Mark Dykese7810b52020-06-03 15:46:55 -050038 lib/libfdt% \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000039 lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020040 $(wildcard lib/*)))
41ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
42 lib \
43 include \
44 docs \
45 %.md \
46 %.rst, \
47 $(wildcard *)))
48CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
49 ${INC_LIB_DIRS_TO_CHECK} \
50 ${LIB_DIRS_TO_CHECK}
51
52ifeq (${V},0)
53 Q=@
54else
55 Q=
56endif
57export Q
58
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +010059################################################################################
60# Toolchain configs
61################################################################################
62CC := ${CROSS_COMPILE}gcc
63CPP := ${CROSS_COMPILE}cpp
64AS := ${CROSS_COMPILE}gcc
65AR := ${CROSS_COMPILE}ar
66LD := ${CROSS_COMPILE}ld
67OC := ${CROSS_COMPILE}objcopy
68OD := ${CROSS_COMPILE}objdump
69NM := ${CROSS_COMPILE}nm
70PP := ${CROSS_COMPILE}gcc
71
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020072ifneq (${DEBUG}, 0)
73 BUILD_TYPE := debug
74 # Use LOG_LEVEL_INFO by default for debug builds
75 LOG_LEVEL := 40
76else
77 BUILD_TYPE := release
78 # Use LOG_LEVEL_ERROR by default for release builds
79 LOG_LEVEL := 20
80endif
81
82# Default build string (git branch and commit)
83ifeq (${BUILD_STRING},)
Manish V Badarkhece149412022-05-24 22:54:45 +010084 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020085endif
86
87VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
88
89BUILD_BASE := ./build
90BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
91
92PLAT_MAKEFILE := platform.mk
93# Generate the platforms list by recursively searching for all directories
94# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
95# char and strip out the final '|'.
96PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
97 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
98 sed -r 's/\|$$//')
99
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200100DOCS_PATH := docs
101
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200102ifeq (${PLAT},)
103 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
104endif
105PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
106PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
107ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
108 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
109endif
110
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500111
112EL3_PAYLOAD_PLAT_PATH := $(shell find el3_payload/plat/ -wholename '*/${PLAT}')
113EL3_PAYLOAD_PLAT_MAKEFILE_FULL := ${EL3_PAYLOAD_PLAT_PATH}/${PLAT_MAKEFILE}
114
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200115.PHONY: all
116all: msg_start
117
118.PHONY: msg_start
119msg_start:
120 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200121 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200122
Shruti Guptac973b2a2023-07-12 12:10:54 +0100123# Set flags for Realm Payload Tests
124ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
Shruti Gupta24597d12023-10-02 10:40:19 +0100125ARM_ARCH_MINOR := 5
Shruti Guptac973b2a2023-07-12 12:10:54 +0100126BRANCH_PROTECTION := 2
127endif
128
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200129# Include test images makefiles.
130include tftf/framework/framework.mk
131include tftf/tests/tests.mk
132include fwu/ns_bl1u/ns_bl1u.mk
133include fwu/ns_bl2u/ns_bl2u.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100134
Daniel Boulbyf6c288e2022-07-25 14:07:57 +0100135# List of secure partitions present.
136SECURE_PARTITIONS :=
137
Olivier Deprez40777f82022-11-09 10:15:28 +0100138# Only platform fvp supports cactus_mm
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100139ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000140include spm/cactus_mm/cactus_mm.mk
nabkah01002e5692022-10-10 12:36:46 +0100141include realm/realm.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100142endif
143
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100144# cactus and ivy are supported on platforms: fvp, tc
145ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100146include spm/cactus/cactus.mk
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100147include spm/ivy/ivy.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100148endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200149
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000150################################################################################
151# Include libc
152################################################################################
153include lib/libc/libc.mk
154
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200155# Include platform specific makefile last because:
156# - the platform makefile may use all previous definitions in this file.
157# - the platform makefile may wish overwriting some of them.
158include ${PLAT_MAKEFILE_FULL}
159
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200160.SUFFIXES:
161
162################################################################################
163# Build options checks
164################################################################################
165$(eval $(call assert_boolean,DEBUG))
166$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
167$(eval $(call assert_boolean,FIRMWARE_UPDATE))
168$(eval $(call assert_boolean,FWU_BL_TEST))
169$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200170$(eval $(call assert_boolean,USE_NVM))
Shruti Guptac973b2a2023-07-12 12:10:54 +0100171$(eval $(call assert_numeric,BRANCH_PROTECTION))
172$(eval $(call assert_boolean,ENABLE_REALM_PAYLOAD_TESTS))
Harrison Mutai6e011642023-09-22 17:17:35 +0100173$(eval $(call assert_boolean,TRANSFER_LIST))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200174
175################################################################################
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100176# Process build options
177################################################################################
178
179# Process BRANCH_PROTECTION value and set
180# Pointer Authentication and Branch Target Identification flags
181include branch_protection.mk
182
183################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200184# Add definitions to the cpp preprocessor based on the current build options.
185# This is done after including the platform specific makefile to allow the
186# platform to overwrite the default options
187################################################################################
188$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
189$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
190$(eval $(call add_define,TFTF_DEFINES,DEBUG))
191$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100192$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000193$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200194$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
195$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
196$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200197$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
Soby Mathew6e5c9962023-10-06 16:38:13 +0100198$(eval $(call add_define,TFTF_DEFINES,ENABLE_REALM_PAYLOAD_TESTS))
Harrison Mutai6e011642023-09-22 17:17:35 +0100199$(eval $(call add_define,TFTF_DEFINES,TRANSFER_LIST))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200200
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200201################################################################################
202
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100203################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200204# Assembler, compiler and linker flags shared across all test images.
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100205################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200206COMMON_ASFLAGS :=
207COMMON_CFLAGS :=
208COMMON_LDFLAGS :=
209
210ifeq (${DEBUG},1)
Daniel Boulbyed1f9512022-05-03 16:36:51 +0100211COMMON_CFLAGS += -g -gdwarf-4
212COMMON_ASFLAGS += -g -Wa,--gdwarf-4
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200213endif
214
Joel Hutton6a6f4832019-04-08 15:46:36 +0100215# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
216ifeq (${ARM_ARCH_MINOR},0)
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000217march32-directive = -march=armv${ARM_ARCH_MAJOR}-a
218march64-directive = -march=armv${ARM_ARCH_MAJOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100219else
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000220march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
221march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100222endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200223
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000224# Get architecture feature modifiers
225arch-features = ${ARM_ARCH_FEATURE}
226
227# Set the compiler's architecture feature modifiers
228ifneq ($(arch-features), none)
229ifeq ($(ARCH), aarch32)
230march32-directive := $(march32-directive)+$(arch-features)
231else
232march64-directive := $(march64-directive)+$(arch-features)
233endif
234# Print features
235$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
236endif # arch-features
237
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100238################################################################################
239# Compiler settings
240################################################################################
241ifneq ($(findstring clang,$(notdir $(CC))),)
242CLANG_CFLAGS_aarch64 := -target aarch64-elf
Joel Hutton6a6f4832019-04-08 15:46:36 +0100243
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100244CPP := $(CC) -E $(COMMON_CFLAGS_$(ARCH))
245PP := $(CC) -E $(COMMON_CFLAGS_$(ARCH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200246
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100247CLANG_WARNINGS += -nostdinc -ffreestanding -Wall \
248 -Wmissing-include-dirs $(CLANG_CFLAGS_$(ARCH)) \
249 -Wlogical-op-parentheses \
250 -Wno-initializer-overrides \
251 -Wno-sometimes-uninitialized \
252 -Wno-unused-function \
253 -Wno-unused-variable \
254 -Wno-unused-parameter \
255 -Wno-tautological-compare \
256 -Wno-memset-transposed-args \
257 -Wno-parentheses
258
259CLANG_CFLAGS += -Wno-error=deprecated-declarations \
260 -Wno-error=cpp \
261 $(CLANG_WARNINGS)
262endif #(clang)
263
264ifneq ($(findstring gcc,$(notdir $(CC))),)
265GCC_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
266GCC_CFLAGS_aarch64 := -mgeneral-regs-only
267
268GCC_ASFLAGS_aarch32 := ${march32-directive}
269GCC_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
270
271GCC_WARNINGS += -nostdinc -ffreestanding -Wall -Werror \
272 -Wmissing-include-dirs $(GCC_CFLAGS_$(ARCH)) \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200273 -std=gnu99 -Os
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100274
275# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
276GCC_CFLAGS += $(call cc_option, --param=min-pagesize=0)
277GCC_CFLAGS += $(GCC_WARNINGS)
278endif #(gcc)
279
280COMMON_CFLAGS_aarch64 += ${march64-directive} -mstrict-align \
281 $(CLANG_CFLAGS_$(ARCH)) $(GCC_CFLAGS_$(ARCH))
282
283COMMON_CFLAGS += $(COMMON_CFLAGS_$(ARCH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200284COMMON_CFLAGS += -ffunction-sections -fdata-sections
285
286# Get the content of CFLAGS user defined value last so they are appended after
287# the options defined in the Makefile
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100288COMMON_CFLAGS += ${CLANG_CFLAGS} ${GCC_CFLAGS} ${INCLUDES}
289
290COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
291 -Werror -Wmissing-include-dirs \
292 -D__ASSEMBLY__ $(GCC_ASFLAGS_$(ARCH)) \
293 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200294
Karl Meakine69d1282023-03-07 17:10:07 +0000295COMMON_LDFLAGS += ${LDFLAGS} --fatal-warnings -O1 --gc-sections --build-id=none
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200296
Soby Mathew25d9e2f2023-05-05 10:51:57 +0100297# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
298# are not loaded by a elf loader.
299COMMON_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
300
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200301################################################################################
302
Mark Dykese7810b52020-06-03 15:46:55 -0500303TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200304TFTF_INCLUDES += ${PLAT_INCLUDES}
305TFTF_CFLAGS += ${COMMON_CFLAGS}
306TFTF_ASFLAGS += ${COMMON_ASFLAGS}
307TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykese7810b52020-06-03 15:46:55 -0500308TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200309
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100310ifneq (${BP_OPTION},none)
311TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
312NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
313NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
314CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
315CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
316IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
AlexeiFedorov193b3562022-12-22 16:50:08 +0000317REALM_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000318endif
319
Mark Dykese7810b52020-06-03 15:46:55 -0500320ifeq ($(SMC_FUZZING), 1)
321TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
322endif
323
Olivier Deprez231115d2020-02-03 11:27:01 +0100324#####################################################################################
325ifneq ($(findstring gcc,$(notdir $(LD))),)
326 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
327else
328 PIE_LDFLAGS += -pie --no-dynamic-linker
329endif
330
331#####################################################################################
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000332NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200333NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
334NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
335NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
336NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
337
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000338NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200339NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
340NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
341NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
342NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
343
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000344CACTUS_MM_SOURCES += ${LIBC_SRCS}
345CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
346CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
347CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
348CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
349
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000350CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200351CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprez231115d2020-02-03 11:27:01 +0100352CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200353CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprez231115d2020-02-03 11:27:01 +0100354CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200355
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000356IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000357IVY_INCLUDES += ${PLAT_INCLUDES}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100358IVY_CFLAGS += ${COMMON_CFLAGS} -fpie
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000359IVY_ASFLAGS += ${COMMON_ASFLAGS}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100360IVY_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000361
nabkah01002e5692022-10-10 12:36:46 +0100362REALM_SOURCES += ${LIBC_SRCS}
363REALM_CFLAGS += ${COMMON_CFLAGS} -fpie
364REALM_ASFLAGS += ${COMMON_ASFLAGS}
365REALM_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
366
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200367.PHONY: locate-checkpatch
368locate-checkpatch:
369ifndef CHECKPATCH
370 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
371else
372ifeq (,$(wildcard ${CHECKPATCH}))
373 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
374endif
375endif
376
377.PHONY: clean
378clean:
379 @echo " CLEAN"
380 ${Q}rm -rf ${BUILD_PLAT}
Shriram K86879852022-09-15 15:45:05 +0530381ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200382 ${MAKE} -C el3_payload clean
Shriram K86879852022-09-15 15:45:05 +0530383endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200384
385.PHONY: realclean distclean
386realclean distclean:
387 @echo " REALCLEAN"
388 ${Q}rm -rf ${BUILD_BASE}
389 ${Q}rm -f ${CURDIR}/cscope.*
Shriram K86879852022-09-15 15:45:05 +0530390ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200391 ${MAKE} -C el3_payload distclean
Shriram K86879852022-09-15 15:45:05 +0530392endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200393
394.PHONY: checkcodebase
395checkcodebase: locate-checkpatch
396 @echo " CHECKING STYLE"
397 @if test -d .git ; then \
Mark Dykese7810b52020-06-03 15:46:55 -0500398 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200399 while read GIT_FILE ; \
400 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
401 done ; \
402 else \
403 find . -type f -not -iwholename "*.git*" \
404 -not -iwholename "*build*" \
Mark Dykese7810b52020-06-03 15:46:55 -0500405 -not -iwholename "*libfdt*" \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000406 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200407 -not -iwholename "*docs*" \
408 -not -iwholename "*.md" \
409 -not -iwholename "*.rst" \
410 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
411 fi
412
413.PHONY: checkpatch
414checkpatch: locate-checkpatch
415 @echo " CHECKING STYLE"
416 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
417 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
418 printf "\n[*] Checking style of '$$commit'\n\n"; \
419 git log --format=email "$$commit~..$$commit" \
420 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
421 git diff --format=email "$$commit~..$$commit" \
422 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
423 done
424
425ifneq (${FIRMWARE_UPDATE},1)
426.PHONY: ns_bl1u ns_bl2u
427ns_bl1u ns_bl2u:
428 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
429 on this platform."
430 @exit 1
431endif
432
433ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000434.PHONY: cactus_mm
435cactus_mm:
436 @echo "ERROR: $@ is supported only on AArch64 FVP."
437 @exit 1
438
nabkah01002e5692022-10-10 12:36:46 +0100439.PHONY: realm
440realm:
441 @echo "ERROR: $@ is supported only on AArch64 FVP."
442 @exit 1
443
444.PHONY: pack_realm
445pack_realm:
446 @echo "Nothing to be done"
447 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200448endif
449
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100450ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100451.PHONY: cactus
452cactus:
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100453 @echo "ERROR: $@ is supported only on AArch64 FVP or TC."
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100454 @exit 1
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100455
456.PHONY: ivy
457ivy:
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100458 @echo "ERROR: $@ is supported only on AArch64 FVP or TC."
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100459 @exit 1
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100460endif
461
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200462MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
463
464define MAKE_C
465
466$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
467$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
468
Bence Szépkúti537b3582019-11-29 18:23:56 +0100469$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200470 @echo " CC $$<"
471 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
472
473-include $(DEP)
474endef
475
476
477define MAKE_S
478
479$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
480$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
481
Bence Szépkúti537b3582019-11-29 18:23:56 +0100482$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200483 @echo " AS $$<"
484 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
485
486-include $(DEP)
487endef
488
489
490define MAKE_LD
491
492$(eval DEP := $(1).d)
493
Bence Szépkúti537b3582019-11-29 18:23:56 +0100494$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200495 @echo " PP $$<"
496 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
497
498-include $(DEP)
499endef
500
501
502define MAKE_OBJS
503 $(eval C_OBJS := $(filter %.c,$(2)))
504 $(eval REMAIN := $(filter-out %.c,$(2)))
505 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
506
507 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
508 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
509 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
510
511 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
512endef
513
514
515# NOTE: The line continuation '\' is required in the next define otherwise we
516# end up with a line-feed characer at the end of the last c filename.
517# Also bare this issue in mind if extending the list of supported filetypes.
518define SOURCES_TO_OBJS
519 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
520 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
521endef
522
523define uppercase
524$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
525endef
526
527define MAKE_IMG
528 $(eval IMG_PREFIX := $(call uppercase, $(1)))
529 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
530 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
531 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykese7810b52020-06-03 15:46:55 -0500532 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200533 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
534 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
535 $(eval ELF := $(BUILD_DIR)/$(1).elf)
536 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
537 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
538
539 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
540 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
541
542$(BUILD_DIR) :
543 $$(Q)mkdir -p "$$@"
544
545$(ELF) : $(OBJS) $(LINKERFILE)
546 @echo " LD $$@"
547 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
548 const char version_string[] = "${VERSION_STRING}";' | \
549 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
550 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
551 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
552
553$(DUMP) : $(ELF)
554 @echo " OD $$@"
555 $${Q}$${OD} -dx $$< > $$@
556
557$(BIN) : $(ELF)
558 @echo " BIN $$@"
559 $$(Q)$$(OC) -O binary $$< $$@
560 @echo
561 @echo "Built $$@ successfully"
562 @echo
563
564.PHONY : $(1)
565$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
566
567all : $(1)
568
569endef
570
Shruti Gupta2eb601b2023-03-29 21:35:17 +0100571ifeq (${ARCH},aarch32)
572 ARCH_TESTS_SKIP_LIST := tftf/tests/aarch32_tests_to_skip.txt
573endif
574
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200575$(AUTOGEN_DIR):
576 $(Q)mkdir -p "$@"
577
Shruti Gupta2eb601b2023-03-29 21:35:17 +0100578$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST} $(ARCH_TESTS_SKIP_LIST)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200579 @echo " AUTOGEN $@"
Jim Ray7ba27bf2023-05-25 14:11:51 -0700580 tools/generate_test_list/generate_test_list.py $(AUTOGEN_DIR)/tests_list.c \
581 $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} \
582 --plat-skip-file=$(PLAT_TESTS_SKIP_LIST) \
583 --arch-skip-file=$(ARCH_TESTS_SKIP_LIST)
Mark Dykese7810b52020-06-03 15:46:55 -0500584ifeq ($(SMC_FUZZING), 1)
585 $(Q)mkdir -p ${BUILD_PLAT}/smcf
586 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
587 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
johpow01d5c79cc2021-06-23 16:10:22 -0500588 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_start=_binary___dtb_start \
589 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_end=_binary___dtb_end
Mark Dykese7810b52020-06-03 15:46:55 -0500590endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200591
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200592ifeq ($(FIRMWARE_UPDATE), 1)
593 $(eval $(call MAKE_IMG,ns_bl1u))
594 $(eval $(call MAKE_IMG,ns_bl2u))
595endif
596
597ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000598 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200599 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000600 $(eval $(call MAKE_IMG,ivy))
Shruti Guptac973b2a2023-07-12 12:10:54 +0100601endif
602
Shruti Guptac973b2a2023-07-12 12:10:54 +0100603.PHONY : tftf
604 $(eval $(call MAKE_IMG,tftf))
605
Arunachalam Ganapathy292a48a2023-10-27 16:46:36 +0100606# Build flag 'ENABLE_REALM_PAYLOAD_TESTS=1' builds and pack Realm Payload Tests
607# (preferred method). The else part contains the deprecated `pack_realm` build
608# target and it will be removed in future commit.
Shruti Guptac973b2a2023-07-12 12:10:54 +0100609ifeq (${ENABLE_REALM_PAYLOAD_TESTS},1)
Arunachalam Ganapathy292a48a2023-10-27 16:46:36 +0100610 $(eval $(call MAKE_IMG,realm))
611
612# This forces to rebuild tftf.bin. For incremental build this re-creates tftf.bin
613# and removes the old realm payload packed by the last build.
614.PHONY : $(BUILD_PLAT)/tftf.bin
615
Shruti Guptac973b2a2023-07-12 12:10:54 +0100616tftf: realm
617 @echo " PACK REALM PAYLOAD"
618 $(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
Soby Mathew6e5c9962023-10-06 16:38:13 +0100619 oflag=append conv=notrunc)
Arunachalam Ganapathy292a48a2023-10-27 16:46:36 +0100620else ifeq (${ARCH}-${PLAT},aarch64-fvp)
nabkah01002e5692022-10-10 12:36:46 +0100621.PHONY : pack_realm
Arunachalam Ganapathy292a48a2023-10-27 16:46:36 +0100622 $(eval $(call MAKE_IMG,realm))
623
624.PHONY : $(BUILD_PLAT)/tftf.bin
625
nabkah01002e5692022-10-10 12:36:46 +0100626pack_realm: realm tftf
Arunachalam Ganapathy292a48a2023-10-27 16:46:36 +0100627 @echo " PACK REALM PAYLOAD (pack_realm method deprecated)"
nabkah01002e5692022-10-10 12:36:46 +0100628 $(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
Soby Mathew6e5c9962023-10-06 16:38:13 +0100629 oflag=append conv=notrunc)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200630endif
631
Daniel Boulbyc19215a2023-05-17 13:50:36 +0100632ifeq (${ARCH}-${PLAT},aarch64-tc)
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100633 $(eval $(call MAKE_IMG,cactus))
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100634 $(eval $(call MAKE_IMG,ivy))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100635endif
636
Daniel Boulbyf6c288e2022-07-25 14:07:57 +0100637SP_LAYOUT:
638 ${Q}tools/generate_json/generate_json.sh \
639 $(BUILD_PLAT) $(SECURE_PARTITIONS)
640
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200641# The EL3 test payload is only supported in AArch64. It has an independent build
642# system.
643.PHONY: el3_payload
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100644# TODO: EL3 test payload currently is supported for GCC only. It has an independent
645# build system and support for Clang to be added.
646ifneq ($(findstring gcc,$(notdir $(CC))),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200647ifneq (${ARCH},aarch32)
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500648ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200649el3_payload: $(BUILD_DIR)
650 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
651 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
652
653all: el3_payload
654endif
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500655endif
Jayanth Dodderi Chidanandd2a63642023-06-06 09:03:53 +0100656endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200657
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200658doc:
659 @echo " BUILD DOCUMENTATION"
660 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
661
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200662.PHONY: cscope
663cscope:
664 @echo " CSCOPE"
665 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
666 ${Q}cscope -b -q -k
667
668.PHONY: help
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500669.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200670help:
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500671 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Shruti Guptac973b2a2023-07-12 12:10:54 +0100672<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500673 echo ""
674 echo "PLAT is used to specify which platform you wish to build."
675 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
676 echo ""
677 echo "Supported Targets:"
678 echo " all Build all supported binaries for this platform"
679 echo " (i.e. TFTF and FWU images)"
680 echo " tftf Build the TFTF image"
681 echo " ns_bl1u Build the NS_BL1U image"
682 echo " ns_bl2u Build the NS_BL2U image"
Olivier Deprez40777f82022-11-09 10:15:28 +0100683 echo " cactus Build the Cactus image (FF-A S-EL1 test payload)."
684 echo " cactus_mm Build the Cactus-MM image (SPM-MM S-EL0 test payload)."
685 echo " ivy Build the Ivy image (FF-A S-EL0 test payload)."
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500686 echo " el3_payload Build the EL3 test payload"
687 echo " checkcodebase Check the coding style of the entire source tree"
688 echo " checkpatch Check the coding style on changes in the current"
689 echo " branch against BASE_COMMIT (default origin/master)"
690 echo " doc Build html based documentation using Sphinx tool"
691 echo " clean Clean the build for the selected platform"
692 echo " cscope Generate cscope index"
693 echo " distclean Remove all build artifacts for all platforms"
694 echo " help_tests List all possible sets of tests"
695 echo ""
696 echo "note: most build targets require PLAT to be set to a specific platform."
697 echo ""
698 echo "example: build all targets for the FVP platform:"
699 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"