blob: 74568582715b96b9df73af332e8064ff6b08f1b7 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001#
2# Copyright (c) 2018, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7# TFTF Version
8VERSION_MAJOR := 2
9VERSION_MINOR := 0
10
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 \
29 include/lib/stdlib, \
30 $(wildcard include/lib/*)))
31LIB_DIRS_TO_CHECK := $(sort $(filter-out \
32 lib/compiler-rt \
33 lib/stdlib, \
34 $(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
81# Convenience function for adding build definitions
82# $(eval $(call add_define,BAR_DEFINES,FOO)) will have:
83# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise
84# inside the BAR_DEFINES variable.
85define add_define
86$(1) += -D$(2)$(if $(value $(2)),=$(value $(2)),)
87endef
88
89# Convenience function for verifying option has a boolean value
90# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1
91define assert_boolean
92$(and $(patsubst 0,,$(value $(1))),$(patsubst 1,,$(value $(1))),$(error $(1) must be boolean))
93endef
94
95ifeq (${PLAT},)
96 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform")
97endif
98PLAT_PATH := $(shell find plat/ -wholename '*/${PLAT}')
99PLAT_MAKEFILE_FULL := ${PLAT_PATH}/${PLAT_MAKEFILE}
100ifeq ($(wildcard ${PLAT_MAKEFILE_FULL}),)
101 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}")
102endif
103
104.PHONY: all
105all: msg_start
106
107.PHONY: msg_start
108msg_start:
109 @echo "Building ${PLAT}"
Sandrine Bailleux043d5362018-10-03 17:05:59 +0200110 @echo "Selected set of tests: ${TESTS}"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200111
112# Include test images makefiles.
113include tftf/framework/framework.mk
114include tftf/tests/tests.mk
115include fwu/ns_bl1u/ns_bl1u.mk
116include fwu/ns_bl2u/ns_bl2u.mk
117include spm/cactus/cactus.mk
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000118include spm/ivy/ivy.mk
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200119
120# Include platform specific makefile last because:
121# - the platform makefile may use all previous definitions in this file.
122# - the platform makefile may wish overwriting some of them.
123include ${PLAT_MAKEFILE_FULL}
124
125
126.SUFFIXES:
127
128################################################################################
129# Build options checks
130################################################################################
131$(eval $(call assert_boolean,DEBUG))
132$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
133$(eval $(call assert_boolean,FIRMWARE_UPDATE))
134$(eval $(call assert_boolean,FWU_BL_TEST))
135$(eval $(call assert_boolean,NEW_TEST_SESSION))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200136$(eval $(call assert_boolean,USE_NVM))
137
138################################################################################
139# Add definitions to the cpp preprocessor based on the current build options.
140# This is done after including the platform specific makefile to allow the
141# platform to overwrite the default options
142################################################################################
143$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MAJOR))
144$(eval $(call add_define,TFTF_DEFINES,ARM_ARCH_MINOR))
145$(eval $(call add_define,TFTF_DEFINES,DEBUG))
146$(eval $(call add_define,TFTF_DEFINES,ENABLE_ASSERTIONS))
147$(eval $(call add_define,TFTF_DEFINES,LOG_LEVEL))
148$(eval $(call add_define,TFTF_DEFINES,NEW_TEST_SESSION))
149$(eval $(call add_define,TFTF_DEFINES,PLAT_${PLAT}))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200150$(eval $(call add_define,TFTF_DEFINES,USE_NVM))
151
152ifeq (${ARCH},aarch32)
153 $(eval $(call add_define,TFTF_DEFINES,AARCH32))
154else
155 $(eval $(call add_define,TFTF_DEFINES,AARCH64))
156endif
157
158################################################################################
159
160# Assembler, compiler and linker flags shared across all test images.
161COMMON_ASFLAGS :=
162COMMON_CFLAGS :=
163COMMON_LDFLAGS :=
164
165ifeq (${DEBUG},1)
166COMMON_CFLAGS += -g
167COMMON_ASFLAGS += -g -Wa,--gdwarf-2
168endif
169
170COMMON_ASFLAGS_aarch64 := -mgeneral-regs-only
171COMMON_CFLAGS_aarch64 := -mgeneral-regs-only
172
173COMMON_ASFLAGS_aarch32 := -march=armv8-a
174COMMON_CFLAGS_aarch32 := -march=armv8-a
175
176COMMON_ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \
177 -Werror -Wmissing-include-dirs \
178 -D__ASSEMBLY__ $(COMMON_ASFLAGS_$(ARCH))
179COMMON_CFLAGS += -nostdinc -ffreestanding -Wall -Werror \
180 -Wmissing-include-dirs $(COMMON_CFLAGS_$(ARCH)) \
181 -std=gnu99 -Os
182COMMON_CFLAGS += -ffunction-sections -fdata-sections
183
184# Get the content of CFLAGS user defined value last so they are appended after
185# the options defined in the Makefile
186COMMON_CFLAGS += ${CFLAGS}
187
188COMMON_LDFLAGS += --fatal-warnings -O1 --gc-sections --build-id=none
189
190CC := ${CROSS_COMPILE}gcc
191CPP := ${CROSS_COMPILE}cpp
192AS := ${CROSS_COMPILE}gcc
193AR := ${CROSS_COMPILE}ar
194LD := ${CROSS_COMPILE}ld
195OC := ${CROSS_COMPILE}objcopy
196OD := ${CROSS_COMPILE}objdump
197NM := ${CROSS_COMPILE}nm
198PP := ${CROSS_COMPILE}gcc
199
200################################################################################
201
202TFTF_SOURCES := ${FRAMEWORK_SOURCES} ${TESTS_SOURCES} ${PLAT_SOURCES}
203TFTF_INCLUDES += ${PLAT_INCLUDES}
204TFTF_CFLAGS += ${COMMON_CFLAGS}
205TFTF_ASFLAGS += ${COMMON_ASFLAGS}
206TFTF_LDFLAGS += ${COMMON_LDFLAGS}
207
208NS_BL1U_SOURCES += ${PLAT_SOURCES}
209NS_BL1U_INCLUDES += ${PLAT_INCLUDES}
210NS_BL1U_CFLAGS += ${COMMON_CFLAGS}
211NS_BL1U_ASFLAGS += ${COMMON_ASFLAGS}
212NS_BL1U_LDFLAGS += ${COMMON_LDFLAGS}
213
214NS_BL2U_SOURCES += ${PLAT_SOURCES}
215NS_BL2U_INCLUDES += ${PLAT_INCLUDES}
216NS_BL2U_CFLAGS += ${COMMON_CFLAGS}
217NS_BL2U_ASFLAGS += ${COMMON_ASFLAGS}
218NS_BL2U_LDFLAGS += ${COMMON_LDFLAGS}
219
220CACTUS_INCLUDES += ${PLAT_INCLUDES}
221CACTUS_CFLAGS += ${COMMON_CFLAGS}
222CACTUS_ASFLAGS += ${COMMON_ASFLAGS}
223CACTUS_LDFLAGS += ${COMMON_LDFLAGS}
224
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000225IVY_INCLUDES += ${PLAT_INCLUDES}
226IVY_CFLAGS += ${COMMON_CFLAGS}
227IVY_ASFLAGS += ${COMMON_ASFLAGS}
228IVY_LDFLAGS += ${COMMON_LDFLAGS}
229
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200230.PHONY: locate-checkpatch
231locate-checkpatch:
232ifndef CHECKPATCH
233 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl")
234else
235ifeq (,$(wildcard ${CHECKPATCH}))
236 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl")
237endif
238endif
239
240.PHONY: clean
241clean:
242 @echo " CLEAN"
243 ${Q}rm -rf ${BUILD_PLAT}
244 ${MAKE} -C el3_payload clean
245
246.PHONY: realclean distclean
247realclean distclean:
248 @echo " REALCLEAN"
249 ${Q}rm -rf ${BUILD_BASE}
250 ${Q}rm -f ${CURDIR}/cscope.*
251 ${MAKE} -C el3_payload distclean
252
253.PHONY: checkcodebase
254checkcodebase: locate-checkpatch
255 @echo " CHECKING STYLE"
256 @if test -d .git ; then \
257 git ls-files | grep -E -v 'stdlib|docs|\.md|\.rst' | \
258 while read GIT_FILE ; \
259 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \
260 done ; \
261 else \
262 find . -type f -not -iwholename "*.git*" \
263 -not -iwholename "*build*" \
264 -not -iwholename "*stdlib*" \
265 -not -iwholename "*docs*" \
266 -not -iwholename "*.md" \
267 -not -iwholename "*.rst" \
268 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \
269 fi
270
271.PHONY: checkpatch
272checkpatch: locate-checkpatch
273 @echo " CHECKING STYLE"
274 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \
275 for commit in `git rev-list $$COMMON_COMMIT..HEAD`; do \
276 printf "\n[*] Checking style of '$$commit'\n\n"; \
277 git log --format=email "$$commit~..$$commit" \
278 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
279 git diff --format=email "$$commit~..$$commit" \
280 -- ${CHECK_PATHS} | ${CHECKPATCH} - || true; \
281 done
282
283ifneq (${FIRMWARE_UPDATE},1)
284.PHONY: ns_bl1u ns_bl2u
285ns_bl1u ns_bl2u:
286 @echo "ERROR: Can't build $@ because Firmware Update is not supported \
287 on this platform."
288 @exit 1
289endif
290
291ifneq (${ARCH}-${PLAT},aarch64-fvp)
292.PHONY: cactus
293cactus:
294 @echo "ERROR: $@ is supported only on AArch64 FVP."
295 @exit 1
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000296
297.PHONY: ivy
298ivy:
299 @echo "ERROR: $@ is supported only on AArch64 FVP."
300 @exit 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200301endif
302
303MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@
304
305define MAKE_C
306
307$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
308$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
309
310$(OBJ) : $(2)
311 @echo " CC $$<"
312 $$(Q)$$(CC) $$($(3)_CFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
313
314-include $(DEP)
315endef
316
317
318define MAKE_S
319
320$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
321$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
322
323$(OBJ) : $(2)
324 @echo " AS $$<"
325 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -DIMAGE_$(3) $(MAKE_DEP) -c $$< -o $$@
326
327-include $(DEP)
328endef
329
330
331define MAKE_LD
332
333$(eval DEP := $(1).d)
334
335$(1) : $(2)
336 @echo " PP $$<"
337 $$(Q)$$(AS) $$($(3)_ASFLAGS) ${$(3)_INCLUDES} ${$(3)_DEFINES} -P -E $(MAKE_DEP) -o $$@ $$<
338
339-include $(DEP)
340endef
341
342
343define MAKE_OBJS
344 $(eval C_OBJS := $(filter %.c,$(2)))
345 $(eval REMAIN := $(filter-out %.c,$(2)))
346 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
347
348 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
349 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
350 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
351
352 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
353endef
354
355
356# NOTE: The line continuation '\' is required in the next define otherwise we
357# end up with a line-feed characer at the end of the last c filename.
358# Also bare this issue in mind if extending the list of supported filetypes.
359define SOURCES_TO_OBJS
360 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
361 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
362endef
363
364define uppercase
365$(shell echo $(1) | tr '[:lower:]' '[:upper:]')
366endef
367
368define MAKE_IMG
369 $(eval IMG_PREFIX := $(call uppercase, $(1)))
370 $(eval BUILD_DIR := ${BUILD_PLAT}/$(1))
371 $(eval SOURCES := $(${IMG_PREFIX}_SOURCES))
372 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
373 $(eval LINKERFILE := $(BUILD_DIR)/$(1).ld)
374 $(eval MAPFILE := $(BUILD_DIR)/$(1).map)
375 $(eval ELF := $(BUILD_DIR)/$(1).elf)
376 $(eval DUMP := $(BUILD_DIR)/$(1).dump)
377 $(eval BIN := $(BUILD_PLAT)/$(1).bin)
378
379 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),${IMG_PREFIX}))
380 $(eval $(call MAKE_LD,$(LINKERFILE),$(${IMG_PREFIX}_LINKERFILE),${IMG_PREFIX}))
381
382$(BUILD_DIR) :
383 $$(Q)mkdir -p "$$@"
384
385$(ELF) : $(OBJS) $(LINKERFILE)
386 @echo " LD $$@"
387 @echo 'const char build_message[] = "Built : "__TIME__", "__DATE__; \
388 const char version_string[] = "${VERSION_STRING}";' | \
389 $$(CC) $$(${IMG_PREFIX}_CFLAGS) ${${IMG_PREFIX}_INCLUDES} ${${IMG_PREFIX}_DEFINES} -c -xc - -o $(BUILD_DIR)/build_message.o
390 $$(Q)$$(LD) -o $$@ $$(${IMG_PREFIX}_LDFLAGS) -Map=$(MAPFILE) \
391 -T $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS)
392
393$(DUMP) : $(ELF)
394 @echo " OD $$@"
395 $${Q}$${OD} -dx $$< > $$@
396
397$(BIN) : $(ELF)
398 @echo " BIN $$@"
399 $$(Q)$$(OC) -O binary $$< $$@
400 @echo
401 @echo "Built $$@ successfully"
402 @echo
403
404.PHONY : $(1)
405$(1) : $(BUILD_DIR) $(BIN) $(DUMP)
406
407all : $(1)
408
409endef
410
411$(AUTOGEN_DIR):
412 $(Q)mkdir -p "$@"
413
414$(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h: $(AUTOGEN_DIR) ${TESTS_FILE} ${PLAT_TESTS_SKIP_LIST}
415 @echo " AUTOGEN $@"
416 tools/generate_test_list/generate_test_list.pl $(AUTOGEN_DIR)/tests_list.c $(AUTOGEN_DIR)/tests_list.h ${TESTS_FILE} $(PLAT_TESTS_SKIP_LIST)
417
418$(eval $(call MAKE_IMG,tftf))
419
420ifeq ($(FIRMWARE_UPDATE), 1)
421 $(eval $(call MAKE_IMG,ns_bl1u))
422 $(eval $(call MAKE_IMG,ns_bl2u))
423endif
424
425ifeq (${ARCH}-${PLAT},aarch64-fvp)
426 $(eval $(call MAKE_IMG,cactus))
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000427 $(eval $(call MAKE_IMG,ivy))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200428endif
429
430# The EL3 test payload is only supported in AArch64. It has an independent build
431# system.
432.PHONY: el3_payload
433ifneq (${ARCH},aarch32)
434el3_payload: $(BUILD_DIR)
435 ${Q}${MAKE} -C el3_payload PLAT=${PLAT}
436 ${Q}find "el3_payload/build/${PLAT}" -name '*.bin' -exec cp {} "${BUILD_PLAT}" \;
437
438all: el3_payload
439endif
440
441.PHONY: cscope
442cscope:
443 @echo " CSCOPE"
444 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files
445 ${Q}cscope -b -q -k
446
447.PHONY: help
448help:
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +0000449 @echo "usage: ${MAKE} PLAT=<${PLATFORMS}> <all|tftf|ns_bl1u|ns_bl2u|cactus|ivy|el3_payload|distclean|clean|checkcodebase|checkpatch>"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200450 @echo ""
451 @echo "PLAT is used to specify which platform you wish to build."
452 @echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}"
453 @echo ""
454 @echo "Supported Targets:"
455 @echo " all Build all supported binaries for this platform"
456 @echo " (i.e. TFTF and FWU images)"
457 @echo " tftf Build the TFTF image"
458 @echo " ns_bl1u Build the NS_BL1U image"
459 @echo " ns_bl2u Build the NS_BL2U image"
Antonio Nino Diaz0c697f92018-11-30 10:51:26 +0000460 @echo " cactus Build the Cactus image (Test S-EL0 payload) and resource description."
461 @echo " ivy Build the Ivy image (Test S-EL0 payload) and resource description."
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200462 @echo " el3_payload Build the EL3 test payload"
463 @echo " checkcodebase Check the coding style of the entire source tree"
464 @echo " checkpatch Check the coding style on changes in the current"
465 @echo " branch against BASE_COMMIT (default origin/master)"
466 @echo " clean Clean the build for the selected platform"
467 @echo " cscope Generate cscope index"
468 @echo " distclean Remove all build artifacts for all platforms"
469 @echo ""
470 @echo "note: most build targets require PLAT to be set to a specific platform."
471 @echo ""
472 @echo "example: build all targets for the FVP platform:"
473 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all"