1# 2# Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved. 3# 4# SPDX-License-Identifier: BSD-3-Clause 5# 6 7# 8# Trusted Firmware Version 9# 10VERSION_MAJOR := 2 11VERSION_MINOR := 6 12 13# Default goal is build all images 14.DEFAULT_GOAL := all 15 16# Avoid any implicit propagation of command line variable definitions to 17# sub-Makefiles, like CFLAGS that we reserved for the firmware images' 18# usage. Other command line options like "-s" are still propagated as usual. 19MAKEOVERRIDES = 20 21MAKE_HELPERS_DIRECTORY := make_helpers/ 22include ${MAKE_HELPERS_DIRECTORY}build_macros.mk 23include ${MAKE_HELPERS_DIRECTORY}build_env.mk 24 25################################################################################ 26# Default values for build configurations, and their dependencies 27################################################################################ 28 29include ${MAKE_HELPERS_DIRECTORY}defaults.mk 30 31# Assertions enabled for DEBUG builds by default 32ENABLE_ASSERTIONS := ${DEBUG} 33ENABLE_PMF := ${ENABLE_RUNTIME_INSTRUMENTATION} 34PLAT := ${DEFAULT_PLAT} 35 36################################################################################ 37# Checkpatch script options 38################################################################################ 39 40CHECKCODE_ARGS := --no-patch 41# Do not check the coding style on imported library files or documentation files 42INC_ARM_DIRS_TO_CHECK := $(sort $(filter-out \ 43 include/drivers/arm/cryptocell, \ 44 $(wildcard include/drivers/arm/*))) 45INC_ARM_DIRS_TO_CHECK += include/drivers/arm/cryptocell/*.h 46INC_DRV_DIRS_TO_CHECK := $(sort $(filter-out \ 47 include/drivers/arm, \ 48 $(wildcard include/drivers/*))) 49INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \ 50 include/lib/libfdt \ 51 include/lib/libc, \ 52 $(wildcard include/lib/*))) 53INC_DIRS_TO_CHECK := $(sort $(filter-out \ 54 include/lib \ 55 include/drivers, \ 56 $(wildcard include/*))) 57LIB_DIRS_TO_CHECK := $(sort $(filter-out \ 58 lib/compiler-rt \ 59 lib/libfdt% \ 60 lib/libc, \ 61 $(wildcard lib/*))) 62ROOT_DIRS_TO_CHECK := $(sort $(filter-out \ 63 lib \ 64 include \ 65 docs \ 66 %.rst, \ 67 $(wildcard *))) 68CHECK_PATHS := ${ROOT_DIRS_TO_CHECK} \ 69 ${INC_DIRS_TO_CHECK} \ 70 ${INC_LIB_DIRS_TO_CHECK} \ 71 ${LIB_DIRS_TO_CHECK} \ 72 ${INC_DRV_DIRS_TO_CHECK} \ 73 ${INC_ARM_DIRS_TO_CHECK} 74 75 76################################################################################ 77# Process build options 78################################################################################ 79 80# Verbose flag 81ifeq (${V},0) 82 Q:=@ 83 ECHO:=@echo 84 CHECKCODE_ARGS += --no-summary --terse 85else 86 Q:= 87 ECHO:=$(ECHO_QUIET) 88endif 89 90ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),) 91 Q:=@ 92 ECHO:=$(ECHO_QUIET) 93endif 94 95export Q ECHO 96 97# The cert_create tool cannot generate certificates individually, so we use the 98# target 'certificates' to create them all 99ifneq (${GENERATE_COT},0) 100 FIP_DEPS += certificates 101 FWU_FIP_DEPS += fwu_certificates 102endif 103 104# Process BRANCH_PROTECTION value and set 105# Pointer Authentication and Branch Target Identification flags 106ifeq (${BRANCH_PROTECTION},0) 107 # Default value turns off all types of branch protection 108 BP_OPTION := none 109else ifneq (${ARCH},aarch64) 110 $(error BRANCH_PROTECTION requires AArch64) 111else ifeq (${BRANCH_PROTECTION},1) 112 # Enables all types of branch protection features 113 BP_OPTION := standard 114 ENABLE_BTI := 1 115 ENABLE_PAUTH := 1 116else ifeq (${BRANCH_PROTECTION},2) 117 # Return address signing to its standard level 118 BP_OPTION := pac-ret 119 ENABLE_PAUTH := 1 120else ifeq (${BRANCH_PROTECTION},3) 121 # Extend the signing to include leaf functions 122 BP_OPTION := pac-ret+leaf 123 ENABLE_PAUTH := 1 124else ifeq (${BRANCH_PROTECTION},4) 125 # Turn on branch target identification mechanism 126 BP_OPTION := bti 127 ENABLE_BTI := 1 128else 129 $(error Unknown BRANCH_PROTECTION value ${BRANCH_PROTECTION}) 130endif 131 132# FEAT_RME 133ifeq (${ENABLE_RME},1) 134# RME doesn't support PIE 135ifneq (${ENABLE_PIE},0) 136 $(error ENABLE_RME does not support PIE) 137endif 138# RME requires AARCH64 139ifneq (${ARCH},aarch64) 140 $(error ENABLE_RME requires AArch64) 141endif 142# RME requires el2 context to be saved for now. 143CTX_INCLUDE_EL2_REGS := 1 144CTX_INCLUDE_AARCH32_REGS := 0 145ARM_ARCH_MAJOR := 8 146ARM_ARCH_MINOR := 6 147endif 148 149# USE_SPINLOCK_CAS requires AArch64 build 150ifeq (${USE_SPINLOCK_CAS},1) 151ifneq (${ARCH},aarch64) 152 $(error USE_SPINLOCK_CAS requires AArch64) 153endif 154endif 155 156# USE_DEBUGFS experimental feature recommended only in debug builds 157ifeq (${USE_DEBUGFS},1) 158ifeq (${DEBUG},1) 159 $(warning DEBUGFS experimental feature is enabled.) 160else 161 $(warning DEBUGFS experimental, recommended in DEBUG builds ONLY) 162endif 163endif 164 165ifneq (${DECRYPTION_SUPPORT},none) 166ENC_ARGS += -f ${FW_ENC_STATUS} 167ENC_ARGS += -k ${ENC_KEY} 168ENC_ARGS += -n ${ENC_NONCE} 169FIP_DEPS += enctool 170FWU_FIP_DEPS += enctool 171endif 172 173################################################################################ 174# Toolchain 175################################################################################ 176 177HOSTCC := gcc 178export HOSTCC 179 180CC := ${CROSS_COMPILE}gcc 181CPP := ${CROSS_COMPILE}cpp 182AS := ${CROSS_COMPILE}gcc 183AR := ${CROSS_COMPILE}ar 184LINKER := ${CROSS_COMPILE}ld 185OC := ${CROSS_COMPILE}objcopy 186OD := ${CROSS_COMPILE}objdump 187NM := ${CROSS_COMPILE}nm 188PP := ${CROSS_COMPILE}gcc -E 189DTC := dtc 190 191# Use ${LD}.bfd instead if it exists (as absolute path or together with $PATH). 192ifneq ($(strip $(wildcard ${LD}.bfd) \ 193 $(foreach dir,$(subst :, ,${PATH}),$(wildcard ${dir}/${LINKER}.bfd))),) 194LINKER := ${LINKER}.bfd 195endif 196 197ifeq (${ARM_ARCH_MAJOR},7) 198target32-directive = -target arm-none-eabi 199# Will set march32-directive from platform configuration 200else 201target32-directive = -target armv8a-none-eabi 202 203# Set the compiler's target architecture profile based on 204# ARM_ARCH_MAJOR ARM_ARCH_MINOR options 205ifeq (${ARM_ARCH_MINOR},0) 206march32-directive = -march=armv${ARM_ARCH_MAJOR}-a 207march64-directive = -march=armv${ARM_ARCH_MAJOR}-a 208else 209march32-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a 210march64-directive = -march=armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a 211endif 212endif 213 214# Memory tagging is supported in architecture Armv8.5-A AArch64 and onwards 215ifeq ($(ARCH), aarch64) 216# Check if revision is greater than or equal to 8.5 217ifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))" 218mem_tag_arch_support = yes 219endif 220endif 221 222# Get architecture feature modifiers 223arch-features = ${ARM_ARCH_FEATURE} 224 225# Enable required options for memory stack tagging. 226# Currently, these options are enabled only for clang and armclang compiler. 227ifeq (${SUPPORT_STACK_MEMTAG},yes) 228ifdef mem_tag_arch_support 229# Check for armclang and clang compilers 230ifneq ( ,$(filter $(notdir $(CC)),armclang clang)) 231# Add "memtag" architecture feature modifier if not specified 232ifeq ( ,$(findstring memtag,$(arch-features))) 233arch-features := $(arch-features)+memtag 234endif # memtag 235ifeq ($(notdir $(CC)),armclang) 236TF_CFLAGS += -mmemtag-stack 237else ifeq ($(notdir $(CC)),clang) 238TF_CFLAGS += -fsanitize=memtag 239endif # armclang 240endif # armclang clang 241else 242$(error "Error: stack memory tagging is not supported for architecture \ 243 ${ARCH},armv${ARM_ARCH_MAJOR}.${ARM_ARCH_MINOR}-a") 244endif # mem_tag_arch_support 245endif # SUPPORT_STACK_MEMTAG 246 247# Set the compiler's architecture feature modifiers 248ifneq ($(arch-features), none) 249# Strip "none+" from arch-features 250arch-features := $(subst none+,,$(arch-features)) 251ifeq ($(ARCH), aarch32) 252march32-directive := $(march32-directive)+$(arch-features) 253else 254march64-directive := $(march64-directive)+$(arch-features) 255endif 256# Print features 257$(info Arm Architecture Features specified: $(subst +, ,$(arch-features))) 258endif # arch-features 259 260# Determine if FEAT_RNG is supported 261ENABLE_FEAT_RNG = $(if $(findstring rng,${arch-features}),1,0) 262 263# Determine if FEAT_SB is supported 264ENABLE_FEAT_SB = $(if $(findstring sb,${arch-features}),1,0) 265 266ifeq "8.5" "$(word 1, $(sort 8.5 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))" 267ENABLE_FEAT_SB = 1 268endif 269 270# Determine and enable FEAT_FGT to access HDFGRTR_EL2 register for v8.6 and higher versions. 271ifeq "8.6" "$(word 1, $(sort 8.6 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))" 272ENABLE_FEAT_FGT = 1 273endif 274 275# Determine and enable FEAT_ECV to access CNTPOFF_EL2 register for v8.6 and higher versions. 276ifeq "8.6" "$(word 1, $(sort 8.6 $(ARM_ARCH_MAJOR).$(ARM_ARCH_MINOR)))" 277ENABLE_FEAT_ECV = 1 278endif 279 280ifneq ($(findstring armclang,$(notdir $(CC))),) 281TF_CFLAGS_aarch32 = -target arm-arm-none-eabi $(march32-directive) 282TF_CFLAGS_aarch64 = -target aarch64-arm-none-eabi $(march64-directive) 283LD = $(LINKER) 284AS = $(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH)) 285CPP = $(CC) -E $(TF_CFLAGS_$(ARCH)) 286PP = $(CC) -E $(TF_CFLAGS_$(ARCH)) 287else ifneq ($(findstring clang,$(notdir $(CC))),) 288CLANG_CCDIR = $(if $(filter-out ./,$(dir $(CC))),$(dir $(CC)),) 289TF_CFLAGS_aarch32 = $(target32-directive) $(march32-directive) 290TF_CFLAGS_aarch64 = -target aarch64-elf $(march64-directive) 291LD = $(CLANG_CCDIR)ld.lld 292ifeq (, $(shell which $(LD))) 293$(error "No $(LD) in PATH, make sure it is installed or set LD to a different linker") 294endif 295AS = $(CC) -c -x assembler-with-cpp $(TF_CFLAGS_$(ARCH)) 296CPP = $(CC) -E 297PP = $(CC) -E 298else ifneq ($(findstring gcc,$(notdir $(CC))),) 299TF_CFLAGS_aarch32 = $(march32-directive) 300TF_CFLAGS_aarch64 = $(march64-directive) 301ifeq ($(ENABLE_LTO),1) 302 # Enable LTO only for aarch64 303 ifeq (${ARCH},aarch64) 304 LTO_CFLAGS = -flto 305 # Use gcc as a wrapper for the ld, recommended for LTO 306 LINKER := ${CROSS_COMPILE}gcc 307 endif 308endif 309LD = $(LINKER) 310else 311TF_CFLAGS_aarch32 = $(march32-directive) 312TF_CFLAGS_aarch64 = $(march64-directive) 313LD = $(LINKER) 314endif 315 316# Process Debug flag 317$(eval $(call add_define,DEBUG)) 318ifneq (${DEBUG}, 0) 319 BUILD_TYPE := debug 320 TF_CFLAGS += -g 321 322 ifneq ($(findstring clang,$(notdir $(CC))),) 323 ASFLAGS += -g 324 else 325 ASFLAGS += -g -Wa,--gdwarf-2 326 endif 327 328 # Use LOG_LEVEL_INFO by default for debug builds 329 LOG_LEVEL := 40 330else 331 BUILD_TYPE := release 332 # Use LOG_LEVEL_NOTICE by default for release builds 333 LOG_LEVEL := 20 334endif 335 336# Default build string (git branch and commit) 337ifeq (${BUILD_STRING},) 338 BUILD_STRING := $(shell git describe --always --dirty --tags 2> /dev/null) 339endif 340VERSION_STRING := v${VERSION_MAJOR}.${VERSION_MINOR}(${BUILD_TYPE}):${BUILD_STRING} 341 342ifeq (${AARCH32_INSTRUCTION_SET},A32) 343TF_CFLAGS_aarch32 += -marm 344else ifeq (${AARCH32_INSTRUCTION_SET},T32) 345TF_CFLAGS_aarch32 += -mthumb 346else 347$(error Error: Unknown AArch32 instruction set ${AARCH32_INSTRUCTION_SET}) 348endif 349 350TF_CFLAGS_aarch32 += -mno-unaligned-access 351TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align 352 353ifneq (${BP_OPTION},none) 354TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION} 355endif 356 357ASFLAGS_aarch32 = $(march32-directive) 358ASFLAGS_aarch64 = $(march64-directive) 359 360# General warnings 361WARNINGS := -Wall -Wmissing-include-dirs -Wunused \ 362 -Wdisabled-optimization -Wvla -Wshadow \ 363 -Wno-unused-parameter -Wredundant-decls 364 365# Additional warnings 366# Level 1 367WARNING1 := -Wextra 368WARNING1 += -Wmissing-format-attribute 369WARNING1 += -Wmissing-prototypes 370WARNING1 += -Wold-style-definition 371 372# Level 2 373WARNING2 := -Waggregate-return 374WARNING2 += -Wcast-align 375WARNING2 += -Wnested-externs 376 377WARNING3 := -Wbad-function-cast 378WARNING3 += -Wcast-qual 379WARNING3 += -Wconversion 380WARNING3 += -Wpacked 381WARNING3 += -Wpointer-arith 382WARNING3 += -Wswitch-default 383 384ifeq (${W},1) 385WARNINGS += $(WARNING1) 386else ifeq (${W},2) 387WARNINGS += $(WARNING1) $(WARNING2) 388else ifeq (${W},3) 389WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3) 390endif 391 392# Compiler specific warnings 393ifeq ($(findstring clang,$(notdir $(CC))),) 394# not using clang 395WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \ 396 -Wpacked-bitfield-compat -Wshift-overflow=2 \ 397 -Wlogical-op 398else 399# using clang 400WARNINGS += -Wshift-overflow -Wshift-sign-overflow \ 401 -Wlogical-op-parentheses 402endif 403 404ifneq (${E},0) 405ERRORS := -Werror 406endif 407 408CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \ 409 $(ERRORS) $(WARNINGS) 410ASFLAGS += $(CPPFLAGS) $(ASFLAGS_$(ARCH)) \ 411 -ffreestanding -Wa,--fatal-warnings 412TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH)) \ 413 -ffunction-sections -fdata-sections \ 414 -ffreestanding -fno-builtin -fno-common \ 415 -Os -std=gnu99 416 417ifeq (${SANITIZE_UB},on) 418TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover 419endif 420ifeq (${SANITIZE_UB},trap) 421TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \ 422 -fsanitize-undefined-trap-on-error 423endif 424 425GCC_V_OUTPUT := $(shell $(CC) -v 2>&1) 426 427# LD = armlink 428ifneq ($(findstring armlink,$(notdir $(LD))),) 429TF_LDFLAGS += --diag_error=warning --lto_level=O1 430TF_LDFLAGS += --remove --info=unused,unusedsymbols 431TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) 432 433# LD = gcc (used when GCC LTO is enabled) 434else ifneq ($(findstring gcc,$(notdir $(LD))),) 435# Pass ld options with Wl or Xlinker switches 436TF_LDFLAGS += -Wl,--fatal-warnings -O1 437TF_LDFLAGS += -Wl,--gc-sections 438ifeq ($(ENABLE_LTO),1) 439 ifeq (${ARCH},aarch64) 440 TF_LDFLAGS += -flto -fuse-linker-plugin 441 endif 442endif 443# GCC automatically adds fix-cortex-a53-843419 flag when used to link 444# which breaks some builds, so disable if errata fix is not explicitly enabled 445ifneq (${ERRATA_A53_843419},1) 446 TF_LDFLAGS += -mno-fix-cortex-a53-843419 447endif 448TF_LDFLAGS += -nostdlib 449TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH))) 450 451# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other 452else 453TF_LDFLAGS += --fatal-warnings -O1 454TF_LDFLAGS += --gc-sections 455# ld.lld doesn't recognize the errata flags, 456# therefore don't add those in that case 457ifeq ($(findstring ld.lld,$(notdir $(LD))),) 458TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) 459endif 460endif 461 462DTC_FLAGS += -I dts -O dtb 463DTC_CPPFLAGS += -P -nostdinc -Iinclude -Ifdts -undef \ 464 -x assembler-with-cpp $(DEFINES) 465 466ifeq ($(MEASURED_BOOT),1) 467DTC_CPPFLAGS += -DMEASURED_BOOT -DBL2_HASH_SIZE=${TCG_DIGEST_SIZE} 468endif 469 470################################################################################ 471# Common sources and include directories 472################################################################################ 473include lib/compiler-rt/compiler-rt.mk 474 475BL_COMMON_SOURCES += common/bl_common.c \ 476 common/tf_log.c \ 477 common/${ARCH}/debug.S \ 478 drivers/console/multi_console.c \ 479 lib/${ARCH}/cache_helpers.S \ 480 lib/${ARCH}/misc_helpers.S \ 481 plat/common/plat_bl_common.c \ 482 plat/common/plat_log_common.c \ 483 plat/common/${ARCH}/plat_common.c \ 484 plat/common/${ARCH}/platform_helpers.S \ 485 ${COMPILER_RT_SRCS} 486 487ifeq ($(notdir $(CC)),armclang) 488BL_COMMON_SOURCES += lib/${ARCH}/armclang_printf.S 489endif 490 491ifeq (${SANITIZE_UB},on) 492BL_COMMON_SOURCES += plat/common/ubsan.c 493endif 494 495INCLUDES += -Iinclude \ 496 -Iinclude/arch/${ARCH} \ 497 -Iinclude/lib/cpus/${ARCH} \ 498 -Iinclude/lib/el3_runtime/${ARCH} \ 499 ${PLAT_INCLUDES} \ 500 ${SPD_INCLUDES} 501 502include common/backtrace/backtrace.mk 503 504################################################################################ 505# Generic definitions 506################################################################################ 507 508include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk 509 510ifeq (${BUILD_BASE},) 511 BUILD_BASE := ./build 512endif 513BUILD_PLAT := $(abspath ${BUILD_BASE})/${PLAT}/${BUILD_TYPE} 514 515SPDS := $(sort $(filter-out none, $(patsubst services/spd/%,%,$(wildcard services/spd/*)))) 516 517# Platforms providing their own TBB makefile may override this value 518INCLUDE_TBBR_MK := 1 519 520 521################################################################################ 522# Include SPD Makefile if one has been specified 523################################################################################ 524 525ifneq (${SPD},none) 526 ifeq (${ARCH},aarch32) 527 $(error "Error: SPD is incompatible with AArch32.") 528 endif 529 530 ifdef EL3_PAYLOAD_BASE 531 $(warning "SPD and EL3_PAYLOAD_BASE are incompatible build options.") 532 $(warning "The SPD and its BL32 companion will be present but ignored.") 533 endif 534 535 ifeq (${SPD},spmd) 536 # SPMD is located in std_svc directory 537 SPD_DIR := std_svc 538 539 ifeq ($(SPMD_SPM_AT_SEL2),1) 540 ifeq ($(CTX_INCLUDE_EL2_REGS),0) 541 $(error SPMD with SPM at S-EL2 requires CTX_INCLUDE_EL2_REGS option) 542 endif 543 endif 544 545 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp) 546 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG 547 endif 548 549 ifeq ($(TS_SP_FW_CONFIG),1) 550 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG 551 endif 552 553 ifneq ($(ARM_BL2_SP_LIST_DTS),) 554 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS) 555 endif 556 557 ifneq ($(SP_LAYOUT_FILE),) 558 BL2_ENABLE_SP_LOAD := 1 559 endif 560 else 561 # All other SPDs in spd directory 562 SPD_DIR := spd 563 endif 564 565 # We expect to locate an spd.mk under the specified SPD directory 566 SPD_MAKE := $(wildcard services/${SPD_DIR}/${SPD}/${SPD}.mk) 567 568 ifeq (${SPD_MAKE},) 569 $(error Error: No services/${SPD_DIR}/${SPD}/${SPD}.mk located) 570 endif 571 $(info Including ${SPD_MAKE}) 572 include ${SPD_MAKE} 573 574 # If there's BL32 companion for the chosen SPD, we expect that the SPD's 575 # Makefile would set NEED_BL32 to "yes". In this case, the build system 576 # supports two mutually exclusive options: 577 # * BL32 is built from source: then BL32_SOURCES must contain the list 578 # of source files to build BL32 579 # * BL32 is a prebuilt binary: then BL32 must point to the image file 580 # that will be included in the FIP 581 # If both BL32_SOURCES and BL32 are defined, the binary takes precedence 582 # over the sources. 583endif 584 585################################################################################ 586# Include rmmd Makefile if RME is enabled 587################################################################################ 588 589ifneq (${ENABLE_RME},0) 590ifneq (${ARCH},aarch64) 591 $(error ENABLE_RME requires AArch64) 592endif 593include services/std_svc/rmmd/rmmd.mk 594$(warning "RME is an experimental feature") 595endif 596 597################################################################################ 598# Include the platform specific Makefile after the SPD Makefile (the platform 599# makefile may use all previous definitions in this file) 600################################################################################ 601 602include ${PLAT_MAKEFILE_FULL} 603 604$(eval $(call MAKE_PREREQ_DIR,${BUILD_PLAT})) 605 606ifeq (${ARM_ARCH_MAJOR},7) 607include make_helpers/armv7-a-cpus.mk 608endif 609 610PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT}) 611ifneq ($(PIE_FOUND),) 612 TF_CFLAGS += -fno-PIE 613endif 614 615ifneq ($(findstring gcc,$(notdir $(LD))),) 616 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker 617else 618 PIE_LDFLAGS += -pie --no-dynamic-linker 619endif 620 621ifeq ($(ENABLE_PIE),1) 622ifeq ($(BL2_AT_EL3),1) 623ifneq ($(BL2_IN_XIP_MEM),1) 624 BL2_CFLAGS += -fpie 625 BL2_LDFLAGS += $(PIE_LDFLAGS) 626endif 627endif 628 BL31_CFLAGS += -fpie 629 BL31_LDFLAGS += $(PIE_LDFLAGS) 630 BL32_CFLAGS += -fpie 631 BL32_LDFLAGS += $(PIE_LDFLAGS) 632endif 633 634ifeq (${ARCH},aarch64) 635BL1_CPPFLAGS += -DIMAGE_AT_EL3 636ifeq ($(BL2_AT_EL3),1) 637BL2_CPPFLAGS += -DIMAGE_AT_EL3 638else 639BL2_CPPFLAGS += -DIMAGE_AT_EL1 640endif 641BL2U_CPPFLAGS += -DIMAGE_AT_EL1 642BL31_CPPFLAGS += -DIMAGE_AT_EL3 643BL32_CPPFLAGS += -DIMAGE_AT_EL1 644endif 645 646# Include the CPU specific operations makefile, which provides default 647# values for all CPU errata workarounds and CPU specific optimisations. 648# This can be overridden by the platform. 649include lib/cpus/cpu-ops.mk 650 651ifeq (${ARCH},aarch32) 652NEED_BL32 := yes 653 654################################################################################ 655# Build `AARCH32_SP` as BL32 image for AArch32 656################################################################################ 657ifneq (${AARCH32_SP},none) 658# We expect to locate an sp.mk under the specified AARCH32_SP directory 659AARCH32_SP_MAKE := $(wildcard bl32/${AARCH32_SP}/${AARCH32_SP}.mk) 660 661ifeq (${AARCH32_SP_MAKE},) 662 $(error Error: No bl32/${AARCH32_SP}/${AARCH32_SP}.mk located) 663endif 664 665$(info Including ${AARCH32_SP_MAKE}) 666include ${AARCH32_SP_MAKE} 667endif 668 669endif 670 671################################################################################ 672# Include libc if not overridden 673################################################################################ 674ifeq (${OVERRIDE_LIBC},0) 675include lib/libc/libc.mk 676endif 677 678################################################################################ 679# Check incompatible options 680################################################################################ 681 682ifdef EL3_PAYLOAD_BASE 683 ifdef PRELOADED_BL33_BASE 684 $(warning "PRELOADED_BL33_BASE and EL3_PAYLOAD_BASE are \ 685 incompatible build options. EL3_PAYLOAD_BASE has priority.") 686 endif 687 ifneq (${GENERATE_COT},0) 688 $(error "GENERATE_COT and EL3_PAYLOAD_BASE are incompatible build options.") 689 endif 690 ifneq (${TRUSTED_BOARD_BOOT},0) 691 $(error "TRUSTED_BOARD_BOOT and EL3_PAYLOAD_BASE are incompatible build options.") 692 endif 693endif 694 695ifeq (${NEED_BL33},yes) 696 ifdef EL3_PAYLOAD_BASE 697 $(warning "BL33 image is not needed when option \ 698 BL33_PAYLOAD_BASE is used and won't be added to the FIP file.") 699 endif 700 ifdef PRELOADED_BL33_BASE 701 $(warning "BL33 image is not needed when option \ 702 PRELOADED_BL33_BASE is used and won't be added to the FIP \ 703 file.") 704 endif 705endif 706 707# When building for systems with hardware-assisted coherency, there's no need to 708# use USE_COHERENT_MEM. Require that USE_COHERENT_MEM must be set to 0 too. 709ifeq ($(HW_ASSISTED_COHERENCY)-$(USE_COHERENT_MEM),1-1) 710$(error USE_COHERENT_MEM cannot be enabled with HW_ASSISTED_COHERENCY) 711endif 712 713#For now, BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is 1. 714ifeq ($(BL2_AT_EL3)-$(BL2_IN_XIP_MEM),0-1) 715$(error "BL2_IN_XIP_MEM is only supported when BL2_AT_EL3 is enabled") 716endif 717 718# For RAS_EXTENSION, require that EAs are handled in EL3 first 719ifeq ($(RAS_EXTENSION),1) 720 ifneq ($(HANDLE_EA_EL3_FIRST),1) 721 $(error For RAS_EXTENSION, HANDLE_EA_EL3_FIRST must also be 1) 722 endif 723endif 724 725# When FAULT_INJECTION_SUPPORT is used, require that RAS_EXTENSION is enabled 726ifeq ($(FAULT_INJECTION_SUPPORT),1) 727 ifneq ($(RAS_EXTENSION),1) 728 $(error For FAULT_INJECTION_SUPPORT, RAS_EXTENSION must also be 1) 729 endif 730endif 731 732# DYN_DISABLE_AUTH can be set only when TRUSTED_BOARD_BOOT=1 733ifeq ($(DYN_DISABLE_AUTH), 1) 734 ifeq (${TRUSTED_BOARD_BOOT}, 0) 735 $(error "TRUSTED_BOARD_BOOT must be enabled for DYN_DISABLE_AUTH to be set.") 736 endif 737endif 738 739ifneq ($(filter 1,${MEASURED_BOOT} ${TRUSTED_BOARD_BOOT}),) 740 CRYPTO_SUPPORT := 1 741else 742 CRYPTO_SUPPORT := 0 743endif 744 745# SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled. 746ifeq ($(SDEI_SUPPORT)-$(SDEI_IN_FCONF),0-1) 747$(error "SDEI_IN_FCONF is only supported when SDEI_SUPPORT is enabled") 748endif 749 750# If pointer authentication is used in the firmware, make sure that all the 751# registers associated to it are also saved and restored. 752# Not doing it would leak the value of the keys used by EL3 to EL1 and S-EL1. 753ifeq ($(ENABLE_PAUTH),1) 754 ifeq ($(CTX_INCLUDE_PAUTH_REGS),0) 755 $(error Pointer Authentication requires CTX_INCLUDE_PAUTH_REGS=1) 756 endif 757endif 758 759ifeq ($(CTX_INCLUDE_PAUTH_REGS),1) 760 ifneq (${ARCH},aarch64) 761 $(error CTX_INCLUDE_PAUTH_REGS requires AArch64) 762 endif 763endif 764 765ifeq ($(CTX_INCLUDE_MTE_REGS),1) 766 ifneq (${ARCH},aarch64) 767 $(error CTX_INCLUDE_MTE_REGS requires AArch64) 768 endif 769endif 770 771# Trusted Boot is a prerequisite for Measured Boot. It provides trust that the 772# code taking the measurements and recording them has not been tampered 773# with. This is referred to as the Root of Trust for Measurement. 774ifeq ($(MEASURED_BOOT),1) 775 ifneq (${TRUSTED_BOARD_BOOT},1) 776 $(error MEASURED_BOOT requires TRUSTED_BOARD_BOOT=1) 777 endif 778endif 779 780ifeq ($(PSA_FWU_SUPPORT),1) 781 $(info PSA_FWU_SUPPORT is an experimental feature) 782endif 783 784ifeq (${ARM_XLAT_TABLES_LIB_V1}, 1) 785 ifeq (${ALLOW_RO_XLAT_TABLES}, 1) 786 $(error "ALLOW_RO_XLAT_TABLES requires translation tables library v2") 787 endif 788endif 789 790ifneq (${DECRYPTION_SUPPORT},none) 791 ifeq (${TRUSTED_BOARD_BOOT}, 0) 792 $(error TRUSTED_BOARD_BOOT must be enabled for DECRYPTION_SUPPORT to be set) 793 endif 794endif 795 796# SME/SVE only supported on AArch64 797ifeq (${ARCH},aarch32) 798 ifeq (${ENABLE_SME_FOR_NS},1) 799 $(error "ENABLE_SME_FOR_NS cannot be used with ARCH=aarch32") 800 endif 801 ifeq (${ENABLE_SVE_FOR_NS},1) 802 # Warning instead of error due to CI dependency on this 803 $(error "ENABLE_SVE_FOR_NS cannot be used with ARCH=aarch32") 804 endif 805endif 806 807# Ensure ENABLE_RME is not used with SME 808ifeq (${ENABLE_RME},1) 809 ifeq (${ENABLE_SME_FOR_NS},1) 810 $(error "ENABLE_SME_FOR_NS cannot be used with ENABLE_RME") 811 endif 812endif 813 814# Secure SME/SVE requires the non-secure component as well 815ifeq (${ENABLE_SME_FOR_SWD},1) 816 ifeq (${ENABLE_SME_FOR_NS},0) 817 $(error "ENABLE_SME_FOR_SWD requires ENABLE_SME_FOR_NS") 818 endif 819endif 820ifeq (${ENABLE_SVE_FOR_SWD},1) 821 ifeq (${ENABLE_SVE_FOR_NS},0) 822 $(error "ENABLE_SVE_FOR_SWD requires ENABLE_SVE_FOR_NS") 823 endif 824endif 825 826# SVE and SME cannot be used with CTX_INCLUDE_FPREGS since secure manager does 827# its own context management including FPU registers. 828ifeq (${CTX_INCLUDE_FPREGS},1) 829 ifeq (${ENABLE_SME_FOR_NS},1) 830 $(error "ENABLE_SME_FOR_NS cannot be used with CTX_INCLUDE_FPREGS") 831 endif 832 ifeq (${ENABLE_SVE_FOR_NS},1) 833 # Warning instead of error due to CI dependency on this 834 $(warning "ENABLE_SVE_FOR_NS cannot be used with CTX_INCLUDE_FPREGS") 835 $(warning "Forced ENABLE_SVE_FOR_NS=0") 836 override ENABLE_SVE_FOR_NS := 0 837 endif 838endif 839 840################################################################################ 841# Process platform overrideable behaviour 842################################################################################ 843 844ifdef BL1_SOURCES 845NEED_BL1 := yes 846endif 847 848ifdef BL2_SOURCES 849 NEED_BL2 := yes 850 851 # Using BL2 implies that a BL33 image also needs to be supplied for the FIP and 852 # Certificate generation tools. This flag can be overridden by the platform. 853 ifdef EL3_PAYLOAD_BASE 854 # If booting an EL3 payload there is no need for a BL33 image 855 # in the FIP file. 856 NEED_BL33 := no 857 else 858 ifdef PRELOADED_BL33_BASE 859 # If booting a BL33 preloaded image there is no need of 860 # another one in the FIP file. 861 NEED_BL33 := no 862 else 863 NEED_BL33 ?= yes 864 endif 865 endif 866endif 867 868ifdef BL2U_SOURCES 869NEED_BL2U := yes 870endif 871 872# If SCP_BL2 is given, we always want FIP to include it. 873ifdef SCP_BL2 874 NEED_SCP_BL2 := yes 875endif 876 877# For AArch32, BL31 is not currently supported. 878ifneq (${ARCH},aarch32) 879 ifdef BL31_SOURCES 880 # When booting an EL3 payload, there is no need to compile the BL31 image nor 881 # put it in the FIP. 882 ifndef EL3_PAYLOAD_BASE 883 NEED_BL31 := yes 884 endif 885 endif 886endif 887 888# Process TBB related flags 889ifneq (${GENERATE_COT},0) 890 # Common cert_create options 891 ifneq (${CREATE_KEYS},0) 892 $(eval CRT_ARGS += -n) 893 $(eval FWU_CRT_ARGS += -n) 894 ifneq (${SAVE_KEYS},0) 895 $(eval CRT_ARGS += -k) 896 $(eval FWU_CRT_ARGS += -k) 897 endif 898 endif 899 # Include TBBR makefile (unless the platform indicates otherwise) 900 ifeq (${INCLUDE_TBBR_MK},1) 901 include make_helpers/tbbr/tbbr_tools.mk 902 endif 903endif 904 905ifneq (${FIP_ALIGN},0) 906FIP_ARGS += --align ${FIP_ALIGN} 907endif 908 909ifdef FDT_SOURCES 910NEED_FDT := yes 911endif 912 913################################################################################ 914# Include libraries' Makefile that are used in all BL 915################################################################################ 916 917include lib/stack_protector/stack_protector.mk 918 919################################################################################ 920# Auxiliary tools (fiptool, cert_create, etc) 921################################################################################ 922 923# Variables for use with Certificate Generation Tool 924CRTTOOLPATH ?= tools/cert_create 925CRTTOOL ?= ${CRTTOOLPATH}/cert_create${BIN_EXT} 926 927# Variables for use with Firmware Encryption Tool 928ENCTOOLPATH ?= tools/encrypt_fw 929ENCTOOL ?= ${ENCTOOLPATH}/encrypt_fw${BIN_EXT} 930 931# Variables for use with Firmware Image Package 932FIPTOOLPATH ?= tools/fiptool 933FIPTOOL ?= ${FIPTOOLPATH}/fiptool${BIN_EXT} 934 935# Variables for use with sptool 936SPTOOLPATH ?= tools/sptool 937SPTOOL ?= ${SPTOOLPATH}/sptool${BIN_EXT} 938SP_MK_GEN ?= ${SPTOOLPATH}/sp_mk_generator.py 939 940# Variables for use with ROMLIB 941ROMLIBPATH ?= lib/romlib 942 943# Variable for use with Python 944PYTHON ?= python3 945 946# Variables for use with PRINT_MEMORY_MAP 947PRINT_MEMORY_MAP_PATH ?= tools/memory 948PRINT_MEMORY_MAP ?= ${PRINT_MEMORY_MAP_PATH}/print_memory_map.py 949 950# Variables for use with documentation build using Sphinx tool 951DOCS_PATH ?= docs 952 953################################################################################ 954# Include BL specific makefiles 955################################################################################ 956 957ifeq (${NEED_BL1},yes) 958include bl1/bl1.mk 959endif 960 961ifeq (${NEED_BL2},yes) 962include bl2/bl2.mk 963endif 964 965ifeq (${NEED_BL2U},yes) 966include bl2u/bl2u.mk 967endif 968 969ifeq (${NEED_BL31},yes) 970include bl31/bl31.mk 971endif 972 973################################################################################ 974# Build options checks 975################################################################################ 976 977$(eval $(call assert_booleans,\ 978 $(sort \ 979 ALLOW_RO_XLAT_TABLES \ 980 BL2_ENABLE_SP_LOAD \ 981 COLD_BOOT_SINGLE_CPU \ 982 CREATE_KEYS \ 983 CTX_INCLUDE_AARCH32_REGS \ 984 CTX_INCLUDE_FPREGS \ 985 CTX_INCLUDE_PAUTH_REGS \ 986 CTX_INCLUDE_MTE_REGS \ 987 CTX_INCLUDE_EL2_REGS \ 988 CTX_INCLUDE_NEVE_REGS \ 989 DEBUG \ 990 DISABLE_MTPMU \ 991 DYN_DISABLE_AUTH \ 992 EL3_EXCEPTION_HANDLING \ 993 ENABLE_AMU \ 994 ENABLE_AMU_AUXILIARY_COUNTERS \ 995 ENABLE_AMU_FCONF \ 996 AMU_RESTRICT_COUNTERS \ 997 ENABLE_ASSERTIONS \ 998 ENABLE_MPAM_FOR_LOWER_ELS \ 999 ENABLE_PIE \ 1000 ENABLE_PMF \ 1001 ENABLE_PSCI_STAT \ 1002 ENABLE_RME \ 1003 ENABLE_RUNTIME_INSTRUMENTATION \ 1004 ENABLE_SME_FOR_NS \ 1005 ENABLE_SME_FOR_SWD \ 1006 ENABLE_SPE_FOR_LOWER_ELS \ 1007 ENABLE_SVE_FOR_NS \ 1008 ENABLE_SVE_FOR_SWD \ 1009 ERROR_DEPRECATED \ 1010 FAULT_INJECTION_SUPPORT \ 1011 GENERATE_COT \ 1012 GICV2_G0_FOR_EL3 \ 1013 HANDLE_EA_EL3_FIRST \ 1014 HW_ASSISTED_COHERENCY \ 1015 INVERTED_MEMMAP \ 1016 MEASURED_BOOT \ 1017 NS_TIMER_SWITCH \ 1018 OVERRIDE_LIBC \ 1019 PL011_GENERIC_UART \ 1020 PROGRAMMABLE_RESET_ADDRESS \ 1021 PSCI_EXTENDED_STATE_ID \ 1022 RAS_EXTENSION \ 1023 RESET_TO_BL31 \ 1024 SAVE_KEYS \ 1025 SEPARATE_CODE_AND_RODATA \ 1026 SEPARATE_NOBITS_REGION \ 1027 SPIN_ON_BL1_EXIT \ 1028 SPM_MM \ 1029 SPMD_SPM_AT_SEL2 \ 1030 TRUSTED_BOARD_BOOT \ 1031 CRYPTO_SUPPORT \ 1032 USE_COHERENT_MEM \ 1033 USE_DEBUGFS \ 1034 ARM_IO_IN_DTB \ 1035 SDEI_IN_FCONF \ 1036 SEC_INT_DESC_IN_FCONF \ 1037 USE_ROMLIB \ 1038 USE_TBBR_DEFS \ 1039 WARMBOOT_ENABLE_DCACHE_EARLY \ 1040 BL2_AT_EL3 \ 1041 BL2_IN_XIP_MEM \ 1042 BL2_INV_DCACHE \ 1043 USE_SPINLOCK_CAS \ 1044 ENCRYPT_BL31 \ 1045 ENCRYPT_BL32 \ 1046 ERRATA_SPECULATIVE_AT \ 1047 RAS_TRAP_LOWER_EL_ERR_ACCESS \ 1048 COT_DESC_IN_DTB \ 1049 USE_SP804_TIMER \ 1050 ENABLE_FEAT_RNG \ 1051 ENABLE_FEAT_SB \ 1052 PSA_FWU_SUPPORT \ 1053 ENABLE_TRBE_FOR_NS \ 1054 ENABLE_SYS_REG_TRACE_FOR_NS \ 1055 ENABLE_TRF_FOR_NS \ 1056 ENABLE_FEAT_HCX \ 1057 ENABLE_MPMM \ 1058 ENABLE_MPMM_FCONF \ 1059 ENABLE_FEAT_FGT \ 1060 ENABLE_FEAT_AMUv1 \ 1061 ENABLE_FEAT_ECV \ 1062))) 1063 1064$(eval $(call assert_numerics,\ 1065 $(sort \ 1066 ARM_ARCH_MAJOR \ 1067 ARM_ARCH_MINOR \ 1068 BRANCH_PROTECTION \ 1069 FW_ENC_STATUS \ 1070 NR_OF_FW_BANKS \ 1071 NR_OF_IMAGES_IN_FW_BANK \ 1072))) 1073 1074ifdef KEY_SIZE 1075 $(eval $(call assert_numeric,KEY_SIZE)) 1076endif 1077 1078ifeq ($(filter $(SANITIZE_UB), on off trap),) 1079 $(error "Invalid value for SANITIZE_UB: can be one of on, off, trap") 1080endif 1081 1082################################################################################ 1083# Add definitions to the cpp preprocessor based on the current build options. 1084# This is done after including the platform specific makefile to allow the 1085# platform to overwrite the default options 1086################################################################################ 1087 1088$(eval $(call add_defines,\ 1089 $(sort \ 1090 ALLOW_RO_XLAT_TABLES \ 1091 ARM_ARCH_MAJOR \ 1092 ARM_ARCH_MINOR \ 1093 BL2_ENABLE_SP_LOAD \ 1094 COLD_BOOT_SINGLE_CPU \ 1095 CTX_INCLUDE_AARCH32_REGS \ 1096 CTX_INCLUDE_FPREGS \ 1097 CTX_INCLUDE_PAUTH_REGS \ 1098 EL3_EXCEPTION_HANDLING \ 1099 CTX_INCLUDE_MTE_REGS \ 1100 CTX_INCLUDE_EL2_REGS \ 1101 CTX_INCLUDE_NEVE_REGS \ 1102 DECRYPTION_SUPPORT_${DECRYPTION_SUPPORT} \ 1103 DISABLE_MTPMU \ 1104 ENABLE_AMU \ 1105 ENABLE_AMU_AUXILIARY_COUNTERS \ 1106 ENABLE_AMU_FCONF \ 1107 AMU_RESTRICT_COUNTERS \ 1108 ENABLE_ASSERTIONS \ 1109 ENABLE_BTI \ 1110 ENABLE_MPAM_FOR_LOWER_ELS \ 1111 ENABLE_PAUTH \ 1112 ENABLE_PIE \ 1113 ENABLE_PMF \ 1114 ENABLE_PSCI_STAT \ 1115 ENABLE_RME \ 1116 ENABLE_RUNTIME_INSTRUMENTATION \ 1117 ENABLE_SME_FOR_NS \ 1118 ENABLE_SME_FOR_SWD \ 1119 ENABLE_SPE_FOR_LOWER_ELS \ 1120 ENABLE_SVE_FOR_NS \ 1121 ENABLE_SVE_FOR_SWD \ 1122 ENCRYPT_BL31 \ 1123 ENCRYPT_BL32 \ 1124 ERROR_DEPRECATED \ 1125 FAULT_INJECTION_SUPPORT \ 1126 GICV2_G0_FOR_EL3 \ 1127 HANDLE_EA_EL3_FIRST \ 1128 HW_ASSISTED_COHERENCY \ 1129 LOG_LEVEL \ 1130 MEASURED_BOOT \ 1131 NS_TIMER_SWITCH \ 1132 PL011_GENERIC_UART \ 1133 PLAT_${PLAT} \ 1134 PROGRAMMABLE_RESET_ADDRESS \ 1135 PSCI_EXTENDED_STATE_ID \ 1136 RAS_EXTENSION \ 1137 RESET_TO_BL31 \ 1138 SEPARATE_CODE_AND_RODATA \ 1139 SEPARATE_NOBITS_REGION \ 1140 RECLAIM_INIT_CODE \ 1141 SPD_${SPD} \ 1142 SPIN_ON_BL1_EXIT \ 1143 SPM_MM \ 1144 SPMD_SPM_AT_SEL2 \ 1145 TRUSTED_BOARD_BOOT \ 1146 CRYPTO_SUPPORT \ 1147 TRNG_SUPPORT \ 1148 USE_COHERENT_MEM \ 1149 USE_DEBUGFS \ 1150 ARM_IO_IN_DTB \ 1151 SDEI_IN_FCONF \ 1152 SEC_INT_DESC_IN_FCONF \ 1153 USE_ROMLIB \ 1154 USE_TBBR_DEFS \ 1155 WARMBOOT_ENABLE_DCACHE_EARLY \ 1156 BL2_AT_EL3 \ 1157 BL2_IN_XIP_MEM \ 1158 BL2_INV_DCACHE \ 1159 USE_SPINLOCK_CAS \ 1160 ERRATA_SPECULATIVE_AT \ 1161 RAS_TRAP_LOWER_EL_ERR_ACCESS \ 1162 COT_DESC_IN_DTB \ 1163 USE_SP804_TIMER \ 1164 ENABLE_FEAT_RNG \ 1165 ENABLE_FEAT_SB \ 1166 NR_OF_FW_BANKS \ 1167 NR_OF_IMAGES_IN_FW_BANK \ 1168 PSA_FWU_SUPPORT \ 1169 ENABLE_TRBE_FOR_NS \ 1170 ENABLE_SYS_REG_TRACE_FOR_NS \ 1171 ENABLE_TRF_FOR_NS \ 1172 ENABLE_FEAT_HCX \ 1173 ENABLE_MPMM \ 1174 ENABLE_MPMM_FCONF \ 1175 ENABLE_FEAT_FGT \ 1176 ENABLE_FEAT_AMUv1 \ 1177 ENABLE_FEAT_ECV \ 1178))) 1179 1180ifeq (${SANITIZE_UB},trap) 1181 $(eval $(call add_define,MONITOR_TRAPS)) 1182endif 1183 1184# Define the EL3_PAYLOAD_BASE flag only if it is provided. 1185ifdef EL3_PAYLOAD_BASE 1186 $(eval $(call add_define,EL3_PAYLOAD_BASE)) 1187else 1188 # Define the PRELOADED_BL33_BASE flag only if it is provided and 1189 # EL3_PAYLOAD_BASE is not defined, as it has priority. 1190 ifdef PRELOADED_BL33_BASE 1191 $(eval $(call add_define,PRELOADED_BL33_BASE)) 1192 endif 1193endif 1194 1195# Define the DYN_DISABLE_AUTH flag only if set. 1196ifeq (${DYN_DISABLE_AUTH},1) 1197$(eval $(call add_define,DYN_DISABLE_AUTH)) 1198endif 1199 1200ifneq ($(findstring armlink,$(notdir $(LD))),) 1201$(eval $(call add_define,USE_ARM_LINK)) 1202endif 1203 1204# Generate and include sp_gen.mk if SPD is spmd and SP_LAYOUT_FILE is defined 1205ifeq (${SPD},spmd) 1206ifdef SP_LAYOUT_FILE 1207 -include $(BUILD_PLAT)/sp_gen.mk 1208 FIP_DEPS += sp 1209 CRT_DEPS += sp 1210 NEED_SP_PKG := yes 1211else 1212 ifeq (${SPMD_SPM_AT_SEL2},1) 1213 $(error "SPMD with SPM at S-EL2 require SP_LAYOUT_FILE") 1214 endif 1215endif 1216endif 1217 1218################################################################################ 1219# Build targets 1220################################################################################ 1221 1222.PHONY: all msg_start clean realclean distclean cscope locate-checkpatch checkcodebase checkpatch fiptool sptool fip sp fwu_fip certtool dtbs memmap doc enctool 1223.SUFFIXES: 1224 1225all: msg_start 1226 1227msg_start: 1228 @echo "Building ${PLAT}" 1229 1230ifeq (${ERROR_DEPRECATED},0) 1231# Check if deprecated declarations and cpp warnings should be treated as error or not. 1232ifneq ($(findstring clang,$(notdir $(CC))),) 1233 CPPFLAGS += -Wno-error=deprecated-declarations 1234else 1235 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp 1236endif 1237endif # !ERROR_DEPRECATED 1238 1239$(eval $(call MAKE_LIB_DIRS)) 1240$(eval $(call MAKE_LIB,c)) 1241 1242# Expand build macros for the different images 1243ifeq (${NEED_BL1},yes) 1244BL1_SOURCES := $(sort ${BL1_SOURCES}) 1245 1246$(eval $(call MAKE_BL,bl1)) 1247endif 1248 1249ifeq (${NEED_BL2},yes) 1250ifeq (${BL2_AT_EL3}, 0) 1251FIP_BL2_ARGS := tb-fw 1252endif 1253 1254BL2_SOURCES := $(sort ${BL2_SOURCES}) 1255 1256$(if ${BL2}, $(eval $(call TOOL_ADD_IMG,bl2,--${FIP_BL2_ARGS})),\ 1257 $(eval $(call MAKE_BL,bl2,${FIP_BL2_ARGS}))) 1258endif 1259 1260ifeq (${NEED_SCP_BL2},yes) 1261$(eval $(call TOOL_ADD_IMG,scp_bl2,--scp-fw)) 1262endif 1263 1264ifeq (${NEED_BL31},yes) 1265BL31_SOURCES += ${SPD_SOURCES} 1266# Sort BL31 source files to remove duplicates 1267BL31_SOURCES := $(sort ${BL31_SOURCES}) 1268ifneq (${DECRYPTION_SUPPORT},none) 1269$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw,,$(ENCRYPT_BL31))),\ 1270 $(eval $(call MAKE_BL,bl31,soc-fw,,$(ENCRYPT_BL31)))) 1271else 1272$(if ${BL31}, $(eval $(call TOOL_ADD_IMG,bl31,--soc-fw)),\ 1273 $(eval $(call MAKE_BL,bl31,soc-fw))) 1274endif 1275endif 1276 1277# If a BL32 image is needed but neither BL32 nor BL32_SOURCES is defined, the 1278# build system will call TOOL_ADD_IMG to print a warning message and abort the 1279# process. Note that the dependency on BL32 applies to the FIP only. 1280ifeq (${NEED_BL32},yes) 1281# Sort BL32 source files to remove duplicates 1282BL32_SOURCES := $(sort ${BL32_SOURCES}) 1283BUILD_BL32 := $(if $(BL32),,$(if $(BL32_SOURCES),1)) 1284 1285ifneq (${DECRYPTION_SUPPORT},none) 1286$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw,,$(ENCRYPT_BL32))),\ 1287 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw,,$(ENCRYPT_BL32)))) 1288else 1289$(if ${BUILD_BL32}, $(eval $(call MAKE_BL,bl32,tos-fw)),\ 1290 $(eval $(call TOOL_ADD_IMG,bl32,--tos-fw))) 1291endif 1292endif 1293 1294# If RMM image is needed but RMM is not defined, Test Realm Payload (TRP) 1295# needs to be built from RMM_SOURCES. 1296ifeq (${NEED_RMM},yes) 1297# Sort RMM source files to remove duplicates 1298RMM_SOURCES := $(sort ${RMM_SOURCES}) 1299BUILD_RMM := $(if $(RMM),,$(if $(RMM_SOURCES),1)) 1300 1301$(if ${BUILD_RMM}, $(eval $(call MAKE_BL,rmm,rmm-fw)),\ 1302 $(eval $(call TOOL_ADD_IMG,rmm,--rmm-fw))) 1303endif 1304 1305# Add the BL33 image if required by the platform 1306ifeq (${NEED_BL33},yes) 1307$(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 1308endif 1309 1310ifeq (${NEED_BL2U},yes) 1311$(if ${BL2U}, $(eval $(call TOOL_ADD_IMG,bl2u,--ap-fwu-cfg,FWU_)),\ 1312 $(eval $(call MAKE_BL,bl2u,ap-fwu-cfg,FWU_))) 1313endif 1314 1315# Expand build macros for the different images 1316ifeq (${NEED_FDT},yes) 1317 $(eval $(call MAKE_DTBS,$(BUILD_PLAT)/fdts,$(FDT_SOURCES))) 1318endif 1319 1320# Add Secure Partition packages 1321ifeq (${NEED_SP_PKG},yes) 1322$(BUILD_PLAT)/sp_gen.mk: ${SP_MK_GEN} ${SP_LAYOUT_FILE} | ${BUILD_PLAT} 1323 ${Q}${PYTHON} "$<" "$@" $(filter-out $<,$^) $(BUILD_PLAT) ${COT} 1324sp: $(SPTOOL) $(DTBS) $(BUILD_PLAT)/sp_gen.mk 1325 ${Q}$(SPTOOL) $(SPTOOL_ARGS) 1326 @${ECHO_BLANK_LINE} 1327 @echo "Built SP Images successfully" 1328 @${ECHO_BLANK_LINE} 1329endif 1330 1331locate-checkpatch: 1332ifndef CHECKPATCH 1333 $(error "Please set CHECKPATCH to point to the Linux checkpatch.pl file, eg: CHECKPATCH=../linux/scripts/checkpatch.pl") 1334else 1335ifeq (,$(wildcard ${CHECKPATCH})) 1336 $(error "The file CHECKPATCH points to cannot be found, use eg: CHECKPATCH=../linux/scripts/checkpatch.pl") 1337endif 1338endif 1339 1340clean: 1341 @echo " CLEAN" 1342 $(call SHELL_REMOVE_DIR,${BUILD_PLAT}) 1343ifdef UNIX_MK 1344 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean 1345else 1346# Clear the MAKEFLAGS as we do not want 1347# to pass the gnumake flags to nmake. 1348 ${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) clean 1349endif 1350 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean 1351 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} clean 1352 ${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean 1353 1354realclean distclean: 1355 @echo " REALCLEAN" 1356 $(call SHELL_REMOVE_DIR,${BUILD_BASE}) 1357 $(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*) 1358ifdef UNIX_MK 1359 ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean 1360else 1361# Clear the MAKEFLAGS as we do not want 1362# to pass the gnumake flags to nmake. 1363 ${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) realclean 1364endif 1365 ${Q}${MAKE} --no-print-directory -C ${SPTOOLPATH} clean 1366 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean 1367 ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${ENCTOOLPATH} realclean 1368 ${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean 1369 1370checkcodebase: locate-checkpatch 1371 @echo " CHECKING STYLE" 1372 @if test -d .git ; then \ 1373 git ls-files | grep -E -v 'libfdt|libc|docs|\.rst' | \ 1374 while read GIT_FILE ; \ 1375 do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \ 1376 done ; \ 1377 else \ 1378 find . -type f -not -iwholename "*.git*" \ 1379 -not -iwholename "*build*" \ 1380 -not -iwholename "*libfdt*" \ 1381 -not -iwholename "*libc*" \ 1382 -not -iwholename "*docs*" \ 1383 -not -iwholename "*.rst" \ 1384 -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \ 1385 fi 1386 1387checkpatch: locate-checkpatch 1388 @echo " CHECKING STYLE" 1389 @if test -n "${CHECKPATCH_OPTS}"; then \ 1390 echo " with ${CHECKPATCH_OPTS} option(s)"; \ 1391 fi 1392 ${Q}COMMON_COMMIT=$$(git merge-base HEAD ${BASE_COMMIT}); \ 1393 for commit in `git rev-list --no-merges $$COMMON_COMMIT..HEAD`; \ 1394 do \ 1395 printf "\n[*] Checking style of '$$commit'\n\n"; \ 1396 git log --format=email "$$commit~..$$commit" \ 1397 -- ${CHECK_PATHS} | \ 1398 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \ 1399 git diff --format=email "$$commit~..$$commit" \ 1400 -- ${CHECK_PATHS} | \ 1401 ${CHECKPATCH} ${CHECKPATCH_OPTS} - || true; \ 1402 done 1403 1404certtool: ${CRTTOOL} 1405 1406${CRTTOOL}: FORCE 1407 ${Q}${MAKE} PLAT=${PLAT} USE_TBBR_DEFS=${USE_TBBR_DEFS} COT=${COT} OPENSSL_DIR=${OPENSSL_DIR} CRTTOOL=${CRTTOOL} --no-print-directory -C ${CRTTOOLPATH} 1408 @${ECHO_BLANK_LINE} 1409 @echo "Built $@ successfully" 1410 @${ECHO_BLANK_LINE} 1411 1412ifneq (${GENERATE_COT},0) 1413certificates: ${CRT_DEPS} ${CRTTOOL} 1414 ${Q}${CRTTOOL} ${CRT_ARGS} 1415 @${ECHO_BLANK_LINE} 1416 @echo "Built $@ successfully" 1417 @echo "Certificates can be found in ${BUILD_PLAT}" 1418 @${ECHO_BLANK_LINE} 1419endif 1420 1421${BUILD_PLAT}/${FIP_NAME}: ${FIP_DEPS} ${FIPTOOL} 1422 $(eval ${CHECK_FIP_CMD}) 1423 ${Q}${FIPTOOL} create ${FIP_ARGS} $@ 1424 ${Q}${FIPTOOL} info $@ 1425 @${ECHO_BLANK_LINE} 1426 @echo "Built $@ successfully" 1427 @${ECHO_BLANK_LINE} 1428 1429ifneq (${GENERATE_COT},0) 1430fwu_certificates: ${FWU_CRT_DEPS} ${CRTTOOL} 1431 ${Q}${CRTTOOL} ${FWU_CRT_ARGS} 1432 @${ECHO_BLANK_LINE} 1433 @echo "Built $@ successfully" 1434 @echo "FWU certificates can be found in ${BUILD_PLAT}" 1435 @${ECHO_BLANK_LINE} 1436endif 1437 1438${BUILD_PLAT}/${FWU_FIP_NAME}: ${FWU_FIP_DEPS} ${FIPTOOL} 1439 $(eval ${CHECK_FWU_FIP_CMD}) 1440 ${Q}${FIPTOOL} create ${FWU_FIP_ARGS} $@ 1441 ${Q}${FIPTOOL} info $@ 1442 @${ECHO_BLANK_LINE} 1443 @echo "Built $@ successfully" 1444 @${ECHO_BLANK_LINE} 1445 1446fiptool: ${FIPTOOL} 1447fip: ${BUILD_PLAT}/${FIP_NAME} 1448fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME} 1449 1450${FIPTOOL}: FORCE 1451ifdef UNIX_MK 1452 ${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" FIPTOOL=${FIPTOOL} OPENSSL_DIR=${OPENSSL_DIR} --no-print-directory -C ${FIPTOOLPATH} 1453else 1454# Clear the MAKEFLAGS as we do not want 1455# to pass the gnumake flags to nmake. 1456 ${Q}set MAKEFLAGS= && ${MSVC_NMAKE} /nologo /f ${FIPTOOLPATH}/Makefile.msvc FIPTOOLPATH=$(subst /,\,$(FIPTOOLPATH)) FIPTOOL=$(subst /,\,$(FIPTOOL)) 1457endif 1458 1459sptool: ${SPTOOL} 1460${SPTOOL}: FORCE 1461 ${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" SPTOOL=${SPTOOL} --no-print-directory -C ${SPTOOLPATH} 1462 1463romlib.bin: libraries FORCE 1464 ${Q}${MAKE} PLAT_DIR=${PLAT_DIR} BUILD_PLAT=${BUILD_PLAT} ENABLE_BTI=${ENABLE_BTI} ARM_ARCH_MINOR=${ARM_ARCH_MINOR} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all 1465 1466# Call print_memory_map tool 1467memmap: all 1468 ${Q}${PYTHON} ${PRINT_MEMORY_MAP} ${BUILD_PLAT} ${INVERTED_MEMMAP} 1469 1470doc: 1471 @echo " BUILD DOCUMENTATION" 1472 ${Q}${MAKE} --no-print-directory -C ${DOCS_PATH} html 1473 1474enctool: ${ENCTOOL} 1475 1476${ENCTOOL}: FORCE 1477 ${Q}${MAKE} PLAT=${PLAT} BUILD_INFO=0 OPENSSL_DIR=${OPENSSL_DIR} ENCTOOL=${ENCTOOL} --no-print-directory -C ${ENCTOOLPATH} 1478 @${ECHO_BLANK_LINE} 1479 @echo "Built $@ successfully" 1480 @${ECHO_BLANK_LINE} 1481 1482cscope: 1483 @echo " CSCOPE" 1484 ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files 1485 ${Q}cscope -b -q -k 1486 1487help: 1488 @echo "usage: ${MAKE} [PLAT=<platform>] [OPTIONS] [TARGET]" 1489 @echo "" 1490 @echo "PLAT is used to specify which platform you wish to build." 1491 @echo "If no platform is specified, PLAT defaults to: ${DEFAULT_PLAT}" 1492 @echo "" 1493 @echo "platform = ${PLATFORM_LIST}" 1494 @echo "" 1495 @echo "Please refer to the User Guide for a list of all supported options." 1496 @echo "Note that the build system doesn't track dependencies for build " 1497 @echo "options. Therefore, if any of the build options are changed " 1498 @echo "from a previous build, a clean build must be performed." 1499 @echo "" 1500 @echo "Supported Targets:" 1501 @echo " all Build all individual bootloader binaries" 1502 @echo " bl1 Build the BL1 binary" 1503 @echo " bl2 Build the BL2 binary" 1504 @echo " bl2u Build the BL2U binary" 1505 @echo " bl31 Build the BL31 binary" 1506 @echo " bl32 Build the BL32 binary. If ARCH=aarch32, then " 1507 @echo " this builds secure payload specified by AARCH32_SP" 1508 @echo " certificates Build the certificates (requires 'GENERATE_COT=1')" 1509 @echo " fip Build the Firmware Image Package (FIP)" 1510 @echo " fwu_fip Build the FWU Firmware Image Package (FIP)" 1511 @echo " checkcodebase Check the coding style of the entire source tree" 1512 @echo " checkpatch Check the coding style on changes in the current" 1513 @echo " branch against BASE_COMMIT (default origin/master)" 1514 @echo " clean Clean the build for the selected platform" 1515 @echo " cscope Generate cscope index" 1516 @echo " distclean Remove all build artifacts for all platforms" 1517 @echo " certtool Build the Certificate generation tool" 1518 @echo " enctool Build the Firmware encryption tool" 1519 @echo " fiptool Build the Firmware Image Package (FIP) creation tool" 1520 @echo " sp Build the Secure Partition Packages" 1521 @echo " sptool Build the Secure Partition Package creation tool" 1522 @echo " dtbs Build the Device Tree Blobs (if required for the platform)" 1523 @echo " memmap Print the memory map of the built binaries" 1524 @echo " doc Build html based documentation using Sphinx tool" 1525 @echo "" 1526 @echo "Note: most build targets require PLAT to be set to a specific platform." 1527 @echo "" 1528 @echo "example: build all targets for the FVP platform:" 1529 @echo " CROSS_COMPILE=aarch64-none-elf- make PLAT=fvp all" 1530 1531.PHONY: FORCE 1532FORCE:; 1533