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