blob: fa48787c87b655c2fa2c154cc1273414d9d265a9 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Daniel Boulbyed1f9512022-05-03 16:36:51 +01002# Copyright (c) 2018-2022, 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 Conde47e64d42022-11-16 18:33:40 -05009VERSION_MINOR := 8
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
58ifneq (${DEBUG}, 0)
59 BUILD_TYPE := debug
60 # Use LOG_LEVEL_INFO by default for debug builds
61 LOG_LEVEL := 40
62else
63 BUILD_TYPE := release
64 # Use LOG_LEVEL_ERROR by default for release builds
65 LOG_LEVEL := 20
66endif
67
68# Default build string (git branch and commit)
69ifeq (${BUILD_STRING},)
Manish V Badarkhece149412022-05-24 22:54:45 +010070 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020071endif
72
73VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
74
75BUILD_BASE := ./build
76BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
77
78PLAT_MAKEFILE := platform.mk
79# Generate the platforms list by recursively searching for all directories
80# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
81# char and strip out the final '|'.
82PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
83 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
84 sed -r 's/\|$$//')
85
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +020086DOCS_PATH := docs
87
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020088ifeq (${PLAT},)
89 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
90endif
91PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
92PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
93ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
94 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
95endif
96
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -050097
98EL3_PAYLOAD_PLAT_PATH := $(shell find el3_payload/plat/ -wholename '*/${PLAT}')
99EL3_PAYLOAD_PLAT_MAKEFILE_FULL := ${EL3_PAYLOAD_PLAT_PATH}/${PLAT_MAKEFILE}
100
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200101.PHONY: all
102all: msg_start
103
104.PHONY: msg_start
105msg_start:
106 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200107 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200108
109# Include test images makefiles.
110include tftf/framework/framework.mk
111include tftf/tests/tests.mk
112include fwu/ns_bl1u/ns_bl1u.mk
113include fwu/ns_bl2u/ns_bl2u.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100114
Daniel Boulbyf6c288e2022-07-25 14:07:57 +0100115# List of secure partitions present.
116SECURE_PARTITIONS :=
117
Olivier Deprez40777f82022-11-09 10:15:28 +0100118# Only platform fvp supports cactus_mm
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100119ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000120include spm/cactus_mm/cactus_mm.mk
nabkah01002e5692022-10-10 12:36:46 +0100121include realm/realm.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100122endif
123
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100124# cactus and ivy are supported on platforms: fvp, tc0
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100125ifeq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
126include spm/cactus/cactus.mk
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100127include spm/ivy/ivy.mk
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100128endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200129
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000130################################################################################
131# Include libc
132################################################################################
133include lib/libc/libc.mk
134
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200135# Include platform specific makefile last because:
136# - the platform makefile may use all previous definitions in this file.
137# - the platform makefile may wish overwriting some of them.
138include ${PLAT_MAKEFILE_FULL}
139
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200140.SUFFIXES:
141
142################################################################################
143# Build options checks
144################################################################################
145$(eval $(call assert_boolean,DEBUG))
146$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
147$(eval $(call assert_boolean,FIRMWARE_UPDATE))
148$(eval $(call assert_boolean,FWU_BL_TEST))
149$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200150$(eval $(call assert_boolean,USE_NVM))
151
152################################################################################
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100153# Process build options
154################################################################################
155
156# Process BRANCH_PROTECTION value and set
157# Pointer Authentication and Branch Target Identification flags
158include branch_protection.mk
159
160################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200161# Add definitions to the cpp preprocessor based on the current build options.
162# This is done after including the platform specific makefile to allow the
163# platform to overwrite the default options
164################################################################################
165$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
166$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
167$(eval $(call add_define,TFTF_DEFINES,DEBUG))
168$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100169$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000170$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200171$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
172$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
173$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200174$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
175
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200176################################################################################
177
178# Assembler, compiler and linker flags shared across all test images.
179COMMON_ASFLAGS :=
180COMMON_CFLAGS :=
181COMMON_LDFLAGS :=
182
183ifeq (${DEBUG},1)
Daniel Boulbyed1f9512022-05-03 16:36:51 +0100184COMMON_CFLAGS += -g -gdwarf-4
185COMMON_ASFLAGS += -g -Wa,--gdwarf-4
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200186endif
187
Joel Hutton6a6f4832019-04-08 15:46:36 +0100188# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
189ifeq (${ARM_ARCH_MINOR},0)
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000190march32-directive = -march=armv${ARM_ARCH_MAJOR}-a
191march64-directive = -march=armv${ARM_ARCH_MAJOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100192else
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000193march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
194march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a
Joel Hutton6a6f4832019-04-08 15:46:36 +0100195endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200196
Alexei Fedorovd92f4ce2020-12-07 18:13:28 +0000197# Get architecture feature modifiers
198arch-features = ${ARM_ARCH_FEATURE}
199
200# Set the compiler's architecture feature modifiers
201ifneq ($(arch-features), none)
202ifeq ($(ARCH), aarch32)
203march32-directive := $(march32-directive)+$(arch-features)
204else
205march64-directive := $(march64-directive)+$(arch-features)
206endif
207# Print features
208$(info Arm Architecture Features specified: $(subst +, ,$(arch-features)))
209endif # arch-features
210
Joel Hutton6a6f4832019-04-08 15:46:36 +0100211COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
212COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
213
214COMMON_ASFLAGS_aarch32 := ${march32-directive}
215COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200216
217COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
218 -Werror -Wmissing-include-dirs \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000219 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
220 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200221COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
222 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
223 -std=gnu99 -Os
224COMMON_CFLAGS += -ffunction-sections -fdata-sections
225
226# Get the content of CFLAGS user defined value last so they are appended after
227# the options defined in the Makefile
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000228COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200229
230COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
231
232CC := ${CROSS_COMPILE}gcc
233CPP := ${CROSS_COMPILE}cpp
234AS := ${CROSS_COMPILE}gcc
235AR := ${CROSS_COMPILE}ar
236LD := ${CROSS_COMPILE}ld
237OC := ${CROSS_COMPILE}objcopy
238OD := ${CROSS_COMPILE}objdump
239NM := ${CROSS_COMPILE}nm
240PP := ${CROSS_COMPILE}gcc
241
242################################################################################
243
Mark Dykese7810b52020-06-03 15:46:55 -0500244TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200245TFTF_INCLUDES += ${PLAT_INCLUDES}
246TFTF_CFLAGS += ${COMMON_CFLAGS}
247TFTF_ASFLAGS += ${COMMON_ASFLAGS}
248TFTF_LDFLAGS += ${COMMON_LDFLAGS}
Mark Dykese7810b52020-06-03 15:46:55 -0500249TFTF_EXTRA_OBJS :=
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200250
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100251ifneq (${BP_OPTION},none)
252TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
253NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
254NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
255CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
256CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
257IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000258endif
259
Mark Dykese7810b52020-06-03 15:46:55 -0500260ifeq ($(SMC_FUZZING), 1)
261TFTF_EXTRA_OBJS += ${BUILD_PLAT}/smcf/dtb.o
262endif
263
Olivier Deprez231115d2020-02-03 11:27:01 +0100264#####################################################################################
265ifneq ($(findstring gcc,$(notdir $(LD))),)
266 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
267else
268 PIE_LDFLAGS += -pie --no-dynamic-linker
269endif
270
271#####################################################################################
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000272NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200273NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
274NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
275NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
276NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
277
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000278NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200279NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
280NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
281NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
282NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
283
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000284CACTUS_MM_SOURCES += ${LIBC_SRCS}
285CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
286CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
287CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
288CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
289
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000290CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200291CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprez231115d2020-02-03 11:27:01 +0100292CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200293CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprez231115d2020-02-03 11:27:01 +0100294CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200295
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000296IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000297IVY_INCLUDES += ${PLAT_INCLUDES}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100298IVY_CFLAGS += ${COMMON_CFLAGS} -fpie
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000299IVY_ASFLAGS += ${COMMON_ASFLAGS}
Ruari Phipps9f1952c2020-08-24 11:32:32 +0100300IVY_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000301
nabkah01002e5692022-10-10 12:36:46 +0100302REALM_SOURCES += ${LIBC_SRCS}
303REALM_CFLAGS += ${COMMON_CFLAGS} -fpie
304REALM_ASFLAGS += ${COMMON_ASFLAGS}
305REALM_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
306
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200307.PHONY: locate-checkpatch
308locate-checkpatch:
309ifndef CHECKPATCH
310 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
311else
312ifeq (,$(wildcard ${CHECKPATCH}))
313 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
314endif
315endif
316
317.PHONY: clean
318clean:
319 @echo " CLEAN"
320 ${Q}rm -rf ${BUILD_PLAT}
Shriram K86879852022-09-15 15:45:05 +0530321ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200322 ${MAKE} -C el3_payload clean
Shriram K86879852022-09-15 15:45:05 +0530323endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200324
325.PHONY: realclean distclean
326realclean distclean:
327 @echo " REALCLEAN"
328 ${Q}rm -rf ${BUILD_BASE}
329 ${Q}rm -f ${CURDIR}/cscope.*
Shriram K86879852022-09-15 15:45:05 +0530330ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200331 ${MAKE} -C el3_payload distclean
Shriram K86879852022-09-15 15:45:05 +0530332endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200333
334.PHONY: checkcodebase
335checkcodebase: locate-checkpatch
336 @echo " CHECKING STYLE"
337 @if test -d .git ; then \
Mark Dykese7810b52020-06-03 15:46:55 -0500338 git ls-files | grep -E -v 'libfdt|libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200339 while read GIT_FILE ; \
340 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
341 done ; \
342 else \
343 find . -type f -not -iwholename "*.git*" \
344 -not -iwholename "*build*" \
Mark Dykese7810b52020-06-03 15:46:55 -0500345 -not -iwholename "*libfdt*" \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000346 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200347 -not -iwholename "*docs*" \
348 -not -iwholename "*.md" \
349 -not -iwholename "*.rst" \
350 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
351 fi
352
353.PHONY: checkpatch
354checkpatch: locate-checkpatch
355 @echo " CHECKING STYLE"
356 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
357 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
358 printf "\n[*] Checking style of '$$commit'\n\n"; \
359 git log --format=email "$$commit~..$$commit" \
360 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
361 git diff --format=email "$$commit~..$$commit" \
362 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
363 done
364
365ifneq (${FIRMWARE_UPDATE},1)
366.PHONY: ns_bl1u ns_bl2u
367ns_bl1u ns_bl2u:
368 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
369 on this platform."
370 @exit 1
371endif
372
373ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000374.PHONY: cactus_mm
375cactus_mm:
376 @echo "ERROR: $@ is supported only on AArch64 FVP."
377 @exit 1
378
nabkah01002e5692022-10-10 12:36:46 +0100379.PHONY: realm
380realm:
381 @echo "ERROR: $@ is supported only on AArch64 FVP."
382 @exit 1
383
384.PHONY: pack_realm
385pack_realm:
386 @echo "Nothing to be done"
387 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200388endif
389
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100390ifneq (${ARCH}-${PLAT},$(filter ${ARCH}-${PLAT},aarch64-fvp aarch64-tc0))
391.PHONY: cactus
392cactus:
393 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
394 @exit 1
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100395
396.PHONY: ivy
397ivy:
398 @echo "ERROR: $@ is supported only on AArch64 FVP or TC0."
399 @exit 1
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100400endif
401
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200402MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
403
404define MAKE_C
405
406$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
407$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
408
Bence Szépkúti537b3582019-11-29 18:23:56 +0100409$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200410 @echo " CC $$<"
411 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
412
413-include $(DEP)
414endef
415
416
417define MAKE_S
418
419$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
420$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
421
Bence Szépkúti537b3582019-11-29 18:23:56 +0100422$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200423 @echo " AS $$<"
424 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
425
426-include $(DEP)
427endef
428
429
430define MAKE_LD
431
432$(eval DEP := $(1).d)
433
Bence Szépkúti537b3582019-11-29 18:23:56 +0100434$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200435 @echo " PP $$<"
436 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
437
438-include $(DEP)
439endef
440
441
442define MAKE_OBJS
443 $(eval C_OBJS := $(filter %.c,$(2)))
444 $(eval REMAIN := $(filter-out %.c,$(2)))
445 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
446
447 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
448 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
449 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
450
451 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
452endef
453
454
455# NOTE: The line continuation '\' is required in the next define otherwise we
456# end up with a line-feed characer at the end of the last c filename.
457# Also bare this issue in mind if extending the list of supported filetypes.
458define SOURCES_TO_OBJS
459 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
460 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
461endef
462
463define uppercase
464$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
465endef
466
467define MAKE_IMG
468 $(eval IMG_PREFIX := $(call uppercase, $(1)))
469 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
470 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
471 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
Mark Dykese7810b52020-06-03 15:46:55 -0500472 $(eval OBJS += $(${IMG_PREFIX}_EXTRA_OBJS))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200473 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
474 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
475 $(eval ELF := $(BUILD_DIR)/$(1).elf)
476 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
477 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
478
479 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
480 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
481
482$(BUILD_DIR) :
483 $$(Q)mkdir -p "$$@"
484
485$(ELF) : $(OBJS) $(LINKERFILE)
486 @echo " LD $$@"
487 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
488 const char version_string[] = "${VERSION_STRING}";' | \
489 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
490 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
491 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
492
493$(DUMP) : $(ELF)
494 @echo " OD $$@"
495 $${Q}$${OD} -dx $$< > $$@
496
497$(BIN) : $(ELF)
498 @echo " BIN $$@"
499 $$(Q)$$(OC) -O binary $$< $$@
500 @echo
501 @echo "Built $$@ successfully"
502 @echo
503
504.PHONY : $(1)
505$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
506
507all : $(1)
508
509endef
510
511$(AUTOGEN_DIR):
512 $(Q)mkdir -p "$@"
513
514$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
515 @echo " AUTOGEN $@"
516 tools/generate_test_list/generate_test_list.pl $(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} $(PLAT_TESTS_SKIP_LIST)
Mark Dykese7810b52020-06-03 15:46:55 -0500517ifeq ($(SMC_FUZZING), 1)
518 $(Q)mkdir -p ${BUILD_PLAT}/smcf
519 dtc ${SMC_FUZZ_DTS} >> ${BUILD_PLAT}/smcf/dtb
520 $(OC) -I binary -O elf64-littleaarch64 -B aarch64 ${BUILD_PLAT}/smcf/dtb ${BUILD_PLAT}/smcf/dtb.o \
johpow01d5c79cc2021-06-23 16:10:22 -0500521 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_start=_binary___dtb_start \
522 --redefine-sym _binary___build_$(PLAT)_$(BUILD_TYPE)_smcf_dtb_end=_binary___dtb_end
Mark Dykese7810b52020-06-03 15:46:55 -0500523endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200524
525$(eval $(call MAKE_IMG,tftf))
526
527ifeq ($(FIRMWARE_UPDATE), 1)
528 $(eval $(call MAKE_IMG,ns_bl1u))
529 $(eval $(call MAKE_IMG,ns_bl2u))
530endif
531
532ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000533 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200534 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000535 $(eval $(call MAKE_IMG,ivy))
nabkah01002e5692022-10-10 12:36:46 +0100536 $(eval $(call MAKE_IMG,realm))
537endif
538
539ifeq (${ARCH}-${PLAT},aarch64-fvp)
540.PHONY : pack_realm
541pack_realm: realm tftf
542 @echo " PACK REALM PAYLOAD"
543 $(shell dd if=$(BUILD_PLAT)/realm.bin of=$(BUILD_PLAT)/tftf.bin obs=1 \
544 seek=$(TFTF_MAX_IMAGE_SIZE))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200545endif
546
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100547ifeq (${ARCH}-${PLAT},aarch64-tc0)
548 $(eval $(call MAKE_IMG,cactus))
Olivier Deprez2765ebf2020-12-16 15:46:14 +0100549 $(eval $(call MAKE_IMG,ivy))
Arunachalam Ganapathy1e51c2f2020-09-22 13:28:29 +0100550endif
551
Daniel Boulbyf6c288e2022-07-25 14:07:57 +0100552SP_LAYOUT:
553 ${Q}tools/generate_json/generate_json.sh \
554 $(BUILD_PLAT) $(SECURE_PARTITIONS)
555
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200556# The EL3 test payload is only supported in AArch64. It has an independent build
557# system.
558.PHONY: el3_payload
559ifneq (${ARCH},aarch32)
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500560ifneq ($(wildcard ${EL3_PAYLOAD_PLAT_MAKEFILE_FULL}),)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200561el3_payload: $(BUILD_DIR)
562 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
563 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
564
565all: el3_payload
566endif
Arvind Ram Prakash2e1264d2022-05-20 12:27:40 -0500567endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200568
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200569doc:
570 @echo " BUILD DOCUMENTATION"
571 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
572
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200573.PHONY: cscope
574cscope:
575 @echo " CSCOPE"
576 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
577 ${Q}cscope -b -q -k
578
579.PHONY: help
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500580.SILENT: help
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200581help:
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500582 echo "usage: ${MAKE} PLAT=<${PLATFORMS}> \
Olivier Deprez40777f82022-11-09 10:15:28 +0100583<all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|realm|pack_realm|el3_payload|distclean|clean|checkcodebase|checkpatch|help_tests>"
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500584 echo ""
585 echo "PLAT is used to specify which platform you wish to build."
586 echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
587 echo ""
588 echo "Supported Targets:"
589 echo " all Build all supported binaries for this platform"
590 echo " (i.e. TFTF and FWU images)"
591 echo " tftf Build the TFTF image"
592 echo " ns_bl1u Build the NS_BL1U image"
593 echo " ns_bl2u Build the NS_BL2U image"
nabkah01002e5692022-10-10 12:36:46 +0100594 echo " realm Build the Realm image (Test R-EL1 payload)."
595 echo " pack_realm Pack the realm image to tftf.bin."
Olivier Deprez40777f82022-11-09 10:15:28 +0100596 echo " cactus Build the Cactus image (FF-A S-EL1 test payload)."
597 echo " cactus_mm Build the Cactus-MM image (SPM-MM S-EL0 test payload)."
598 echo " ivy Build the Ivy image (FF-A S-EL0 test payload)."
Leonardo Sandoval770b4312020-09-11 14:44:40 -0500599 echo " el3_payload Build the EL3 test payload"
600 echo " checkcodebase Check the coding style of the entire source tree"
601 echo " checkpatch Check the coding style on changes in the current"
602 echo " branch against BASE_COMMIT (default origin/master)"
603 echo " doc Build html based documentation using Sphinx tool"
604 echo " clean Clean the build for the selected platform"
605 echo " cscope Generate cscope index"
606 echo " distclean Remove all build artifacts for all platforms"
607 echo " help_tests List all possible sets of tests"
608 echo ""
609 echo "note: most build targets require PLAT to be set to a specific platform."
610 echo ""
611 echo "example: build all targets for the FVP platform:"
612 echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"