blob: a229d0aa1f3c637e8fd9775240560c06d0ffe2ab [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
Alexei Fedorov52fd7332020-01-08 14:02:18 +00002# Copyright (c) 2018-2020, 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
Madhukar Pappireddy0ab15ae2020-04-19 23:58:39 -05009VERSION_MINOR := 3
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010
11################################################################################
12# Default values for build configurations, and their dependencies
13################################################################################
14
15include defaults.mk
16
17PLAT := ${DEFAULT_PLAT}
18
19# Assertions enabled for DEBUG builds by default
20ENABLE_ASSERTIONS := ${DEBUG}
21
22################################################################################
23# Checkpatch script options
24################################################################################
25
26CHECKCODE_ARGS := --no-patch
27# Do not check the coding style on imported library files or documentation files
28INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000029 include/lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020030 $(wildcard include/lib/*)))
31LIB_DIRS_TO_CHECK := $(sort $(filter-out \
32 lib/compiler-rt \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000033 lib/libc, \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020034 $(wildcard lib/*)))
35ROOT_DIRS_TO_CHECK := $(sort $(filter-out \
36 lib \
37 include \
38 docs \
39 %.md \
40 %.rst, \
41 $(wildcard *)))
42CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \
43 ${INC_LIB_DIRS_TO_CHECK} \
44 ${LIB_DIRS_TO_CHECK}
45
46ifeq (${V},0)
47 Q=@
48else
49 Q=
50endif
51export Q
52
53ifneq (${DEBUG}, 0)
54 BUILD_TYPE := debug
55 # Use LOG_LEVEL_INFO by default for debug builds
56 LOG_LEVEL := 40
57else
58 BUILD_TYPE := release
59 # Use LOG_LEVEL_ERROR by default for release builds
60 LOG_LEVEL := 20
61endif
62
63# Default build string (git branch and commit)
64ifeq (${BUILD_STRING},)
65 BUILD_STRING := $(shell git log -n 1 --pretty=format:"%h")
66endif
67
68VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${PLAT},${BUILD_TYPE}):${BUILD_STRING}
69
70BUILD_BASE := ./build
71BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE}
72
73PLAT_MAKEFILE := platform.mk
74# Generate the platforms list by recursively searching for all directories
75# under /plat containing a PLAT_MAKEFILE. Append each platform with a `|`
76# char and strip out the final '|'.
77PLATFORMS := $(shell find plat/ -name '${PLAT_MAKEFILE}' -print0 | \
78 sed -r 's%[^\x00]*\/([^/]*)\/${PLAT_MAKEFILE}\x00%\1|%g' | \
79 sed -r 's/\|$$//')
80
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +020081DOCS_PATH := docs
82
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020083# Convenience function for adding build definitions
84# $(eval $(call add_define,BAR_DEFINES,FOO)) will have:
85# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
86# inside the BAR_DEFINES variable.
87define add_define
88$(1) += -D$(2)$(if $(value $(2)),=$(value $(2)),)
89endef
90
91# Convenience function for verifying option has a boolean value
92# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
93define assert_boolean
94$(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean))
95endef
96
Alexei Fedorov7cc25872020-06-02 16:35:36 +010097# CREATE_SEQ is a recursive function to create sequence of numbers from 1 to
98# $(2) and assign the sequence to $(1)
99define CREATE_SEQ
100$(if $(word $(2), $($(1))),\
101 $(eval $(1) += $(words $($(1))))\
102 $(eval $(1) := $(filter-out 0,$($(1)))),\
103 $(eval $(1) += $(words $($(1))))\
104 $(call CREATE_SEQ,$(1),$(2))\
105)
106endef
107
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200108ifeq (${PLAT},)
109 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
110endif
111PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
112PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
113ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
114 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
115endif
116
117.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
125# Include test images makefiles.
126include tftf/framework/framework.mk
127include tftf/tests/tests.mk
128include fwu/ns_bl1u/ns_bl1u.mk
129include fwu/ns_bl2u/ns_bl2u.mk
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000130include spm/cactus_mm/cactus_mm.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200131include spm/cactus/cactus.mk
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000132include spm/ivy/ivy.mk
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000133include spm/quark/quark.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200134
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000135################################################################################
136# Include libc
137################################################################################
138include lib/libc/libc.mk
139
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200140# Include platform specific makefile last because:
141# - the platform makefile may use all previous definitions in this file.
142# - the platform makefile may wish overwriting some of them.
143include ${PLAT_MAKEFILE_FULL}
144
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200145.SUFFIXES:
146
147################################################################################
148# Build options checks
149################################################################################
150$(eval $(call assert_boolean,DEBUG))
151$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
152$(eval $(call assert_boolean,FIRMWARE_UPDATE))
153$(eval $(call assert_boolean,FWU_BL_TEST))
154$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200155$(eval $(call assert_boolean,USE_NVM))
156
157################################################################################
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100158# Process build options
159################################################################################
160
161# Process BRANCH_PROTECTION value and set
162# Pointer Authentication and Branch Target Identification flags
163include branch_protection.mk
164
165################################################################################
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200166# Add definitions to the cpp preprocessor based on the current build options.
167# This is done after including the platform specific makefile to allow the
168# platform to overwrite the default options
169################################################################################
170$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
171$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
172$(eval $(call add_define,TFTF_DEFINES,DEBUG))
173$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100174$(eval $(call add_define,TFTF_DEFINES,ENABLE_BTI))
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000175$(eval $(call add_define,TFTF_DEFINES,ENABLE_PAUTH))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200176$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
177$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
178$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200179$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
180
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200181################################################################################
182
183# Assembler, compiler and linker flags shared across all test images.
184COMMON_ASFLAGS :=
185COMMON_CFLAGS :=
186COMMON_LDFLAGS :=
187
188ifeq (${DEBUG},1)
189COMMON_CFLAGS += -g
190COMMON_ASFLAGS += -g -Wa,--gdwarf-2
191endif
192
Joel Hutton6a6f4832019-04-08 15:46:36 +0100193# Set the compiler's target architecture profile based on ARM_ARCH_MINOR option
194ifeq (${ARM_ARCH_MINOR},0)
195march32-directive = -march=armv8-a
196march64-directive = -march=armv8-a
197else
198march32-directive = -march=armv8.${ARM_ARCH_MINOR}-a
199march64-directive = -march=armv8.${ARM_ARCH_MINOR}-a
200endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200201
Joel Hutton6a6f4832019-04-08 15:46:36 +0100202COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only ${march64-directive}
203COMMON_CFLAGS_aarch64 := -mgeneral-regs-only -mstrict-align ${march64-directive}
204
205COMMON_ASFLAGS_aarch32 := ${march32-directive}
206COMMON_CFLAGS_aarch32 := ${march32-directive} -mno-unaligned-access
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200207
208COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
209 -Werror -Wmissing-include-dirs \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000210 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH)) \
211 ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200212COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
213 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
214 -std=gnu99 -Os
215COMMON_CFLAGS += -ffunction-sections -fdata-sections
216
217# Get the content of CFLAGS user defined value last so they are appended after
218# the options defined in the Makefile
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000219COMMON_CFLAGS += ${CFLAGS} ${INCLUDES}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200220
221COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
222
223CC := ${CROSS_COMPILE}gcc
224CPP := ${CROSS_COMPILE}cpp
225AS := ${CROSS_COMPILE}gcc
226AR := ${CROSS_COMPILE}ar
227LD := ${CROSS_COMPILE}ld
228OC := ${CROSS_COMPILE}objcopy
229OD := ${CROSS_COMPILE}objdump
230NM := ${CROSS_COMPILE}nm
231PP := ${CROSS_COMPILE}gcc
232
233################################################################################
234
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000235TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200236TFTF_INCLUDES += ${PLAT_INCLUDES}
237TFTF_CFLAGS += ${COMMON_CFLAGS}
238TFTF_ASFLAGS += ${COMMON_ASFLAGS}
239TFTF_LDFLAGS += ${COMMON_LDFLAGS}
240
Alexei Fedorov7fac1622020-06-19 14:25:43 +0100241ifneq (${BP_OPTION},none)
242TFTF_CFLAGS += -mbranch-protection=${BP_OPTION}
243NS_BL1U_CFLAGS += -mbranch-protection=${BP_OPTION}
244NS_BL2U_CFLAGS += -mbranch-protection=${BP_OPTION}
245CACTUS_MM_CFLAGS += -mbranch-protection=${BP_OPTION}
246CACTUS_CFLAGS += -mbranch-protection=${BP_OPTION}
247IVY_CFLAGS += -mbranch-protection=${BP_OPTION}
248QUARK_CFLAGS += -mbranch-protection=${BP_OPTION}
Antonio Nino Diaz9c9f92c2019-03-13 13:57:39 +0000249endif
250
Olivier Deprez231115d2020-02-03 11:27:01 +0100251#####################################################################################
252ifneq ($(findstring gcc,$(notdir $(LD))),)
253 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
254else
255 PIE_LDFLAGS += -pie --no-dynamic-linker
256endif
257
258#####################################################################################
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000259NS_BL1U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200260NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
261NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
262NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
263NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
264
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000265NS_BL2U_SOURCES += ${PLAT_SOURCES} ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200266NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
267NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
268NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
269NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
270
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000271CACTUS_MM_SOURCES += ${LIBC_SRCS}
272CACTUS_MM_INCLUDES += ${PLAT_INCLUDES}
273CACTUS_MM_CFLAGS += ${COMMON_CFLAGS}
274CACTUS_MM_ASFLAGS += ${COMMON_ASFLAGS}
275CACTUS_MM_LDFLAGS += ${COMMON_LDFLAGS}
276
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000277CACTUS_SOURCES += ${LIBC_SRCS}
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200278CACTUS_INCLUDES += ${PLAT_INCLUDES}
Olivier Deprez231115d2020-02-03 11:27:01 +0100279CACTUS_CFLAGS += ${COMMON_CFLAGS} -fpie
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200280CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
Olivier Deprez231115d2020-02-03 11:27:01 +0100281CACTUS_LDFLAGS += ${COMMON_LDFLAGS} $(PIE_LDFLAGS)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200282
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000283IVY_SOURCES += ${LIBC_SRCS}
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000284IVY_INCLUDES += ${PLAT_INCLUDES}
285IVY_CFLAGS += ${COMMON_CFLAGS}
286IVY_ASFLAGS += ${COMMON_ASFLAGS}
287IVY_LDFLAGS += ${COMMON_LDFLAGS}
288
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000289QUARK_SOURCES += ${LIBC_SRCS}
290QUARK_INCLUDES += ${PLAT_INCLUDES}
291QUARK_CFLAGS += ${COMMON_CFLAGS}
292QUARK_ASFLAGS += ${COMMON_ASFLAGS}
293QUARK_LDFLAGS += ${COMMON_LDFLAGS}
294
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200295.PHONY: locate-checkpatch
296locate-checkpatch:
297ifndef CHECKPATCH
298 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
299else
300ifeq (,$(wildcard ${CHECKPATCH}))
301 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
302endif
303endif
304
305.PHONY: clean
306clean:
307 @echo " CLEAN"
308 ${Q}rm -rf ${BUILD_PLAT}
309 ${MAKE} -C el3_payload clean
310
311.PHONY: realclean distclean
312realclean distclean:
313 @echo " REALCLEAN"
314 ${Q}rm -rf ${BUILD_BASE}
315 ${Q}rm -f ${CURDIR}/cscope.*
316 ${MAKE} -C el3_payload distclean
317
318.PHONY: checkcodebase
319checkcodebase: locate-checkpatch
320 @echo " CHECKING STYLE"
321 @if test -d .git ; then \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000322 git ls-files | grep -E -v 'libc|docs|\.md|\.rst' | \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200323 while read GIT_FILE ; \
324 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
325 done ; \
326 else \
327 find . -type f -not -iwholename "*.git*" \
328 -not -iwholename "*build*" \
Ambroise Vincentd6e806d2019-02-11 14:34:26 +0000329 -not -iwholename "*libc*" \
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200330 -not -iwholename "*docs*" \
331 -not -iwholename "*.md" \
332 -not -iwholename "*.rst" \
333 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
334 fi
335
336.PHONY: checkpatch
337checkpatch: locate-checkpatch
338 @echo " CHECKING STYLE"
339 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
340 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
341 printf "\n[*] Checking style of '$$commit'\n\n"; \
342 git log --format=email "$$commit~..$$commit" \
343 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
344 git diff --format=email "$$commit~..$$commit" \
345 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
346 done
347
348ifneq (${FIRMWARE_UPDATE},1)
349.PHONY: ns_bl1u ns_bl2u
350ns_bl1u ns_bl2u:
351 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
352 on this platform."
353 @exit 1
354endif
355
356ifneq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000357.PHONY: cactus_mm
358cactus_mm:
359 @echo "ERROR: $@ is supported only on AArch64 FVP."
360 @exit 1
361
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200362.PHONY: cactus
363cactus:
364 @echo "ERROR: $@ is supported only on AArch64 FVP."
365 @exit 1
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000366
367.PHONY: ivy
368ivy:
369 @echo "ERROR: $@ is supported only on AArch64 FVP."
370 @exit 1
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000371
372.PHONY: quark
373quark:
374 @echo "ERROR: $@ is supported only on AArch64 FVP."
375 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200376endif
377
378MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
379
380define MAKE_C
381
382$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
383$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
384
Bence Szépkúti537b3582019-11-29 18:23:56 +0100385$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200386 @echo " CC $$<"
387 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
388
389-include $(DEP)
390endef
391
392
393define MAKE_S
394
395$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
396$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
397
Bence Szépkúti537b3582019-11-29 18:23:56 +0100398$(OBJ) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200399 @echo " AS $$<"
400 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
401
402-include $(DEP)
403endef
404
405
406define MAKE_LD
407
408$(eval DEP := $(1).d)
409
Bence Szépkúti537b3582019-11-29 18:23:56 +0100410$(1) : $(2) | $(AUTOGEN_DIR)/tests_list.h
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200411 @echo " PP $$<"
412 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
413
414-include $(DEP)
415endef
416
417
418define MAKE_OBJS
419 $(eval C_OBJS := $(filter %.c,$(2)))
420 $(eval REMAIN := $(filter-out %.c,$(2)))
421 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
422
423 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
424 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
425 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
426
427 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
428endef
429
430
431# NOTE: The line continuation '\' is required in the next define otherwise we
432# end up with a line-feed characer at the end of the last c filename.
433# Also bare this issue in mind if extending the list of supported filetypes.
434define SOURCES_TO_OBJS
435 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
436 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
437endef
438
439define uppercase
440$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
441endef
442
443define MAKE_IMG
444 $(eval IMG_PREFIX := $(call uppercase, $(1)))
445 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
446 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
447 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
448 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
449 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
450 $(eval ELF := $(BUILD_DIR)/$(1).elf)
451 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
452 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
453
454 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
455 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
456
457$(BUILD_DIR) :
458 $$(Q)mkdir -p "$$@"
459
460$(ELF) : $(OBJS) $(LINKERFILE)
461 @echo " LD $$@"
462 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
463 const char version_string[] = "${VERSION_STRING}";' | \
464 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
465 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
466 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
467
468$(DUMP) : $(ELF)
469 @echo " OD $$@"
470 $${Q}$${OD} -dx $$< > $$@
471
472$(BIN) : $(ELF)
473 @echo " BIN $$@"
474 $$(Q)$$(OC) -O binary $$< $$@
475 @echo
476 @echo "Built $$@ successfully"
477 @echo
478
479.PHONY : $(1)
480$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
481
482all : $(1)
483
484endef
485
486$(AUTOGEN_DIR):
487 $(Q)mkdir -p "$@"
488
489$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
490 @echo " AUTOGEN $@"
491 tools/generate_test_list/generate_test_list.pl $(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} $(PLAT_TESTS_SKIP_LIST)
492
493$(eval $(call MAKE_IMG,tftf))
494
495ifeq ($(FIRMWARE_UPDATE), 1)
496 $(eval $(call MAKE_IMG,ns_bl1u))
497 $(eval $(call MAKE_IMG,ns_bl2u))
498endif
499
500ifeq (${ARCH}-${PLAT},aarch64-fvp)
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000501 $(eval $(call MAKE_IMG,cactus_mm))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200502 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000503 $(eval $(call MAKE_IMG,ivy))
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000504 $(eval $(call MAKE_IMG,quark))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200505endif
506
507# The EL3 test payload is only supported in AArch64. It has an independent build
508# system.
509.PHONY: el3_payload
510ifneq (${ARCH},aarch32)
511el3_payload: $(BUILD_DIR)
512 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
513 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
514
515all: el3_payload
516endif
517
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200518doc:
519 @echo " BUILD DOCUMENTATION"
520 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html
521
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200522.PHONY: cscope
523cscope:
524 @echo " CSCOPE"
525 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
526 ${Q}cscope -b -q -k
527
528.PHONY: help
529help:
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000530 @echo "usage: ${MAKE} PLAT=<${PLATFORMS}> <all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|quark|el3_payload|distclean|clean|checkcodebase|checkpatch>"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200531 @echo ""
532 @echo "PLAT is used to specify which platform you wish to build."
533 @echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
534 @echo ""
535 @echo "Supported Targets:"
536 @echo " all Build all supported binaries for this platform"
537 @echo " (i.e. TFTF and FWU images)"
538 @echo " tftf Build the TFTF image"
539 @echo " ns_bl1u Build the NS_BL1U image"
540 @echo " ns_bl2u Build the NS_BL2U image"
Antonio Nino Diaz1451f612018-11-30 10:51:26 +0000541 @echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
Antonio Nino Diazf2218e72019-03-19 10:59:11 +0000542 @echo " cactus_mm Build the Cactus-MM image (Test S-EL0 payload)."
Antonio Nino Diaz1451f612018-11-30 10:51:26 +0000543 @echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
Antonio Nino Diaz26b38642019-03-28 13:16:04 +0000544 @echo " quark Build the Quark image (Test S-EL0 payload) and resource description."
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200545 @echo " el3_payload Build the EL3 test payload"
546 @echo " checkcodebase Check the coding style of the entire source tree"
547 @echo " checkpatch Check the coding style on changes in the current"
548 @echo " branch against BASE_COMMIT (default origin/master)"
Sandrine Bailleuxf8228af2020-04-21 14:45:00 +0200549 @echo " doc Build html based documentation using Sphinx tool"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200550 @echo " clean Clean the build for the selected platform"
551 @echo " cscope Generate cscope index"
552 @echo " distclean Remove all build artifacts for all platforms"
553 @echo ""
554 @echo "note: most build targets require PLAT to be set to a specific platform."
555 @echo ""
556 @echo "example: build all targets for the FVP platform:"
557 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"