1# 2# Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are met: 6# 7# Redistributions of source code must retain the above copyright notice, this 8# list of conditions and the following disclaimer. 9# 10# Redistributions in binary form must reproduce the above copyright notice, 11# this list of conditions and the following disclaimer in the documentation 12# and/or other materials provided with the distribution. 13# 14# Neither the name of ARM nor the names of its contributors may be used 15# to endorse or promote products derived from this software without specific 16# prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28# POSSIBILITY OF SUCH DAMAGE. 29# 30 31# Decrease the verbosity of the make script 32# can be made verbose by passing V=1 at the make command line 33ifdef V 34 KBUILD_VERBOSE = ${V} 35else 36 KBUILD_VERBOSE = 0 37endif 38 39# Checkpatch ignores 40CHECK_IGNORE = --ignore COMPLEX_MACRO 41 42CHECKPATCH_ARGS = --no-tree --no-signoff ${CHECK_IGNORE} 43CHECKCODE_ARGS = --no-patch --no-tree --no-signoff ${CHECK_IGNORE} 44 45ifeq "${KBUILD_VERBOSE}" "0" 46 Q=@ 47 CHECKCODE_ARGS += --no-summary --terse 48else 49 Q= 50endif 51 52export Q 53 54DEBUG ?= 0 55 56ifneq (${DEBUG}, 0) 57 BUILD_TYPE := debug 58else 59 BUILD_TYPE := release 60endif 61 62BL_COMMON_SOURCES := misc_helpers.S \ 63 cache_helpers.S \ 64 tlb_helpers.S \ 65 xlat_helpers.c \ 66 std.c \ 67 bl_common.c \ 68 platform_helpers.S \ 69 io_storage.c 70 71ARCH ?= aarch64 72 73# By default, build all platforms available 74PLAT ?= all 75# By default, build no SPD component 76SPD ?= none 77 78BUILD_BASE := ./build 79BUILD_PLAT := ${BUILD_BASE}/${PLAT}/${BUILD_TYPE} 80 81PLATFORMS := $(shell ls -I common plat/) 82SPDS := $(shell ls -I none services/spd) 83HELP_PLATFORMS := $(shell echo ${PLATFORMS} | sed 's/ /|/g') 84 85ifeq (${PLAT},) 86 $(error "Error: Unknown platform. Please use PLAT=<platform name> to specify the platform.") 87endif 88ifeq ($(findstring ${PLAT},${PLATFORMS} all),) 89 $(error "Error: Invalid platform. The following platforms are available: ${PLATFORMS}") 90endif 91 92ifeq (${PLAT},all) 93all: ${PLATFORMS} 94else 95all: msg_start fip 96endif 97 98msg_start: 99 @echo "Building ${PLAT}" 100 101${PLATFORMS}: 102 ${MAKE} PLAT=$@ all 103 104ifneq (${PLAT},all) 105 $(info Including ${PLAT}/platform.mk) 106 include plat/${PLAT}/platform.mk 107 $(info Including bl1.mk) 108 include bl1/bl1.mk 109 $(info Including bl2.mk) 110 include bl2/bl2.mk 111 $(info Including bl31.mk) 112 include bl31/bl31.mk 113endif 114 115# Include SPD Makefile if one has been specified 116ifneq (${SPD},none) 117 # We expect to locate an spd.mk under the specified SPD directory 118 SPD_MAKE := $(shell m="services/spd/${SPD}/${SPD}.mk"; [ -f "$$m" ] && echo "$$m") 119 120 ifeq (${SPD_MAKE},) 121 $(error Error: No services/spd/${SPD}/${SPD}.mk located) 122 endif 123 $(info Including ${SPD_MAKE}) 124 include ${SPD_MAKE} 125 126 # If there's BL32 companion for the chosen SPD, and the SPD wants to build the 127 # BL2 from source, we expect that the SPD's Makefile would set NEED_BL32 128 # variable to "yes" 129endif 130 131.PHONY: all msg_start ${PLATFORMS} clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool fip locate-bl33 132.SUFFIXES: 133 134 135INCLUDES += -Ilib/include/ \ 136 -Idrivers/io \ 137 -Iinclude/${ARCH}/ \ 138 -Iinclude/ \ 139 -Iarch/system/gic \ 140 -Iservices/psci \ 141 -Iinclude/stdlib \ 142 -Iinclude/stdlib/sys \ 143 -Iplat/${PLAT} \ 144 ${PLAT_INCLUDES} \ 145 ${SPD_INCLUDES} 146 147ASFLAGS += -nostdinc -ffreestanding -Wa,--fatal-warnings \ 148 -mgeneral-regs-only -D__ASSEMBLY__ ${INCLUDES} \ 149 -DDEBUG=${DEBUG} 150CFLAGS := -nostdinc -pedantic -ffreestanding -Wall \ 151 -Werror -mgeneral-regs-only -std=c99 -c -Os \ 152 -DDEBUG=${DEBUG} ${INCLUDES} ${CFLAGS} 153 154LDFLAGS += --fatal-warnings -O1 155 156 157vpath %.ld.S bl1:bl2:bl31 158vpath %.c bl1:bl2:bl31 159vpath %.c bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH} 160vpath %.S bl1/${ARCH}:bl2/${ARCH}:bl31/${ARCH} 161 162 163ifneq (${DEBUG}, 0) 164#CFLAGS += -g -O0 165CFLAGS += -g 166# -save-temps -fverbose-asm 167ASFLAGS += -g -Wa,--gdwarf-2 168else 169CFLAGS += -DNDEBUG=1 170endif 171 172 173CC := ${CROSS_COMPILE}gcc 174CPP := ${CROSS_COMPILE}cpp 175AS := ${CROSS_COMPILE}gcc 176AR := ${CROSS_COMPILE}ar 177LD := ${CROSS_COMPILE}ld 178OC := ${CROSS_COMPILE}objcopy 179OD := ${CROSS_COMPILE}objdump 180NM := ${CROSS_COMPILE}nm 181PP := ${CROSS_COMPILE}gcc -E ${CFLAGS} 182 183BASE_COMMIT ?= origin/master 184 185# Variables for use with Firmware Image Package 186FIPTOOLPATH ?= tools/fip_create 187FIPTOOL ?= ${FIPTOOLPATH}/fip_create 188fiptool: ${FIPTOOL} 189fip: ${BUILD_PLAT}/fip.bin 190 191ifeq (${PLAT},all) 192 ifeq (${MAKECMDGOALS},clean) 193 $(error "Please select a platform with PLAT=<platform>. You can use 'make distclean' to clean up all platform builds") 194 endif 195endif 196 197locate-checkpatch: 198ifndef CHECKPATCH 199 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/script/checkpatch.pl") 200else 201ifeq (,$(wildcard ${CHECKPATCH})) 202 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/script/checkpatch.pl") 203endif 204endif 205 206locate-bl33: 207ifndef BL33 208 $(error "Please set BL33 to point to the Normal World binary, eg: BL33=../uefi/FVP_AARCH64_EFI.fd") 209else 210ifeq (,$(wildcard ${BL33})) 211 $(error "The file BL33 points to cannot be found (${BL33})") 212endif 213FIP_DEPS += ${BL33} 214endif 215 216 217clean: 218 @echo " CLEAN" 219 ${Q}rm -rf ${BUILD_PLAT} 220 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean 221 222realclean distclean: 223 @echo " REALCLEAN" 224 ${Q}rm -rf ${BUILD_BASE} 225 ${Q}rm -f ${CURDIR}/cscope.* 226 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean 227 228checkcodebase: locate-checkpatch 229 @echo " CHECKING STYLE" 230 @if test -d .git ; then \ 231 git ls-files | while read GIT_FILE ; do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; done ; \ 232 else \ 233 find . -type f -not -iwholename "*.git*" -not -iwholename "*build*" -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \ 234 fi 235 236checkpatch: locate-checkpatch 237 @echo " CHECKING STYLE" 238 @git format-patch --stdout ${BASE_COMMIT} | ${CHECKPATCH} ${CHECKPATCH_ARGS} - || true 239 240${FIPTOOL}: 241 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} 242 @echo 243 @echo "Built $@ successfully" 244 @echo 245 246define match_goals 247$(strip $(foreach goal,$(1),$(filter $(goal),$(MAKECMDGOALS)))) 248endef 249 250 251CLEANING := $(call match_goals,clean realclean distclean) 252 253 254define MAKE_C 255 256$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 257$(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ))) 258 259$(OBJ) : $(2) 260 @echo " CC $$<" 261 $$(Q)$$(CC) $$(CFLAGS) -c $$< -o $$@ 262 263 264$(PREREQUISITES) : $(2) 265 @echo " DEPS $$@" 266 @mkdir -p $(1) 267 $$(Q)$$(CC) $$(CFLAGS) -M -MT $(OBJ) -MF $$@ $$< 268 269ifeq "$(CLEANING)" "" 270-include $(PREREQUISITES) 271endif 272 273endef 274 275 276define MAKE_S 277 278$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 279$(eval PREREQUISITES := $(patsubst %.o,%.d,$(OBJ))) 280 281$(OBJ) : $(2) 282 @echo " AS $$<" 283 $$(Q)$$(AS) $$(ASFLAGS) -c $$< -o $$@ 284 285$(PREREQUISITES) : $(2) 286 @echo " DEPS $$@" 287 @mkdir -p $(1) 288 $$(Q)$$(AS) $$(ASFLAGS) -M -MT $(OBJ) -MF $$@ $$< 289 290ifeq "$(CLEANING)" "" 291-include $(PREREQUISITES) 292endif 293 294endef 295 296 297define MAKE_LD 298 299$(eval PREREQUISITES := $(1).d) 300 301$(1) : $(2) 302 @echo " PP $$<" 303 $$(Q)$$(AS) $$(ASFLAGS) -P -E -o $$@ $$< 304 305$(PREREQUISITES) : $(2) 306 @echo " DEPS $$@" 307 @mkdir -p $$(dir $$@) 308 $$(Q)$$(AS) $$(ASFLAGS) -M -MT $(1) -MF $$@ $$< 309 310ifeq "$(CLEANING)" "" 311-include $(PREREQUISITES) 312endif 313 314endef 315 316 317define MAKE_OBJS 318 $(eval C_OBJS := $(filter %.c,$(2))) 319 $(eval REMAIN := $(filter-out %.c,$(2))) 320 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj)))) 321 322 $(eval S_OBJS := $(filter %.S,$(REMAIN))) 323 $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 324 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj)))) 325 326 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 327endef 328 329 330# NOTE: The line continuation '\' is required in the next define otherwise we 331# end up with a line-feed characer at the end of the last c filename. 332# Also bare this issue in mind if extending the list of supported filetypes. 333define SOURCES_TO_OBJS 334 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ 335 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) 336endef 337 338define MAKE_BL 339 $(eval BUILD_DIR := ${BUILD_PLAT}/bl$(1)) 340 $(eval SOURCES := $(BL$(1)_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES)) 341 $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 342 $(eval LINKERFILE := $(BUILD_DIR)/bl$(1).ld) 343 $(eval MAPFILE := $(BUILD_DIR)/bl$(1).map) 344 $(eval ELF := $(BUILD_DIR)/bl$(1).elf) 345 $(eval DUMP := $(BUILD_DIR)/bl$(1).dump) 346 $(eval BIN := $(BUILD_PLAT)/bl$(1).bin) 347 348 $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES))) 349 $(eval $(call MAKE_LD,$(LINKERFILE),$(BL$(1)_LINKERFILE))) 350 351$(BUILD_DIR) : 352 $$(Q)mkdir -p "$$@" 353 354$(ELF) : $(OBJS) $(LINKERFILE) 355 @echo " LD $$@" 356 $$(Q)$$(LD) -o $$@ $$(LDFLAGS) -Map=$(MAPFILE) --script $(LINKERFILE) \ 357 --entry=$(BL$(1)_ENTRY_POINT) $(OBJS) 358 359$(DUMP) : $(ELF) 360 @echo " OD $$@" 361 $${Q}$${OD} -dx $$< > $$@ 362 363$(BIN) : $(ELF) 364 @echo " BIN $$@" 365 $$(Q)$$(OC) -O binary $$< $$@ 366 @echo 367 @echo "Built $$@ successfully" 368 @echo 369 370.PHONY : bl$(1) 371bl$(1) : $(BUILD_DIR) $(BIN) $(DUMP) 372 373all : bl$(1) 374 375$(eval FIP_DEPS += $(if $2,$(BIN),)) 376$(eval FIP_ARGS += $(if $2,--bl$(1) $(BIN),)) 377 378endef 379 380 381$(eval $(call MAKE_BL,1)) 382 383$(eval $(call MAKE_BL,2,in_fip)) 384 385BL31_SOURCES += ${SPD_SOURCES} 386$(eval $(call MAKE_BL,31,in_fip)) 387 388ifeq (${NEED_BL32},yes) 389$(eval $(call MAKE_BL,32,in_fip)) 390endif 391 392${BUILD_PLAT}/fip.bin: locate-bl33 ${FIP_DEPS} ${FIPTOOL} 393 ${Q}${FIPTOOL} --dump \ 394 ${FIP_ARGS} \ 395 --bl33 ${BL33} \ 396 $@ 397 @echo 398 @echo "Built $@ successfully" 399 @echo 400 401 402cscope: 403 @echo " CSCOPE" 404 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files 405 ${Q}cscope -b -q -k 406 407help: 408 @echo "usage: ${MAKE} PLAT=<all|${HELP_PLATFORMS}> <all|bl1|bl2|bl31|distclean|clean|checkcodebase|checkpatch>" 409 @echo "" 410 @echo "PLAT is used to specify which platform you wish to build." 411 @echo "" 412 @echo "Supported Targets:" 413 @echo " all Build the BL1, BL2 and BL31 binaries" 414 @echo " bl1 Build the BL1 binary" 415 @echo " bl2 Build the BL2 binary" 416 @echo " bl31 Build the BL31 binary" 417 @echo " checkcodebase Check the coding style of the entire source tree" 418 @echo " checkpatch Check the coding style on changes in the current" 419 @echo " branch against BASE_COMMIT (default origin/master)" 420 @echo " clean Clean the build for the selected platform" 421 @echo " cscope Generate cscope index" 422 @echo " distclean Remove all build artifacts for all platforms" 423 @echo " fiptool Build the Firmware Image Package(FIP) creation tool" 424 @echo "" 425 @echo "note: most build targets require PLAT to be set to a specific platform." 426 @echo "" 427 @echo "example: build all targets for the FVP platform:" 428 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all" 429