1# Setup compiler for the core module 2ifeq ($(CFG_ARM64_core),y) 3arch-bits-core := 64 4else 5arch-bits-core := 32 6endif 7CROSS_COMPILE_core := $(CROSS_COMPILE$(arch-bits-core)) 8COMPILER_core := $(COMPILER) 9include mk/$(COMPILER_core).mk 10 11# Defines the cc-option macro using the compiler set for the core module 12include mk/cc-option.mk 13 14CFG_LTC_OPTEE_THREAD ?= y 15# Size of emulated TrustZone protected SRAM, 448 kB. 16# Only applicable when paging is enabled. 17CFG_CORE_TZSRAM_EMUL_SIZE ?= 458752 18CFG_LPAE_ADDR_SPACE_SIZE ?= (1ull << 32) 19 20CFG_MMAP_REGIONS ?= 13 21CFG_RESERVED_VASPACE_SIZE ?= (1024 * 1024 * 10) 22 23ifeq ($(CFG_ARM64_core),y) 24CFG_KERN_LINKER_FORMAT ?= elf64-littleaarch64 25CFG_KERN_LINKER_ARCH ?= aarch64 26# TCR_EL1.IPS needs to be initialized according to the largest physical 27# address that we need to map. 28# Physical address size 29# 32 bits, 4GB. 30# 36 bits, 64GB. 31# (etc.) 32CFG_CORE_ARM64_PA_BITS ?= 32 33else 34ifeq ($(CFG_ARM32_core),y) 35CFG_KERN_LINKER_FORMAT ?= elf32-littlearm 36CFG_KERN_LINKER_ARCH ?= arm 37else 38$(error Error: CFG_ARM64_core or CFG_ARM32_core should be defined) 39endif 40endif 41 42ifeq ($(CFG_TA_FLOAT_SUPPORT),y) 43# Use hard-float for floating point support in user TAs instead of 44# soft-float 45CFG_WITH_VFP ?= y 46ifeq ($(CFG_ARM64_core),y) 47# AArch64 has no fallback to soft-float 48$(call force,CFG_WITH_VFP,y) 49endif 50ifeq ($(CFG_WITH_VFP),y) 51arm64-platform-hard-float-enabled := y 52ifneq ($(CFG_TA_ARM32_NO_HARD_FLOAT_SUPPORT),y) 53arm32-platform-hard-float-enabled := y 54endif 55endif 56endif 57 58# Adds protection against CVE-2017-5715 also know as Spectre 59# (https://spectreattack.com) 60# See also https://developer.arm.com/-/media/Files/pdf/Cache_Speculation_Side-channels.pdf 61# Variant 2 62CFG_CORE_WORKAROUND_SPECTRE_BP ?= y 63# Same as CFG_CORE_WORKAROUND_SPECTRE_BP but targeting exceptions from 64# secure EL0 instead of non-secure world. 65CFG_CORE_WORKAROUND_SPECTRE_BP_SEC ?= $(CFG_CORE_WORKAROUND_SPECTRE_BP) 66 67# Adds protection against a tool like Cachegrab 68# (https://github.com/nccgroup/cachegrab), which uses non-secure interrupts 69# to prime and later analyze the L1D, L1I and BTB caches to gain 70# information from secure world execution. 71CFG_CORE_WORKAROUND_NSITR_CACHE_PRIME ?= y 72ifeq ($(CFG_CORE_WORKAROUND_NSITR_CACHE_PRIME),y) 73$(call force,CFG_CORE_WORKAROUND_SPECTRE_BP,y,Required by CFG_CORE_WORKAROUND_NSITR_CACHE_PRIME) 74endif 75 76CFG_CORE_RWDATA_NOEXEC ?= y 77CFG_CORE_RODATA_NOEXEC ?= n 78ifeq ($(CFG_CORE_RODATA_NOEXEC),y) 79$(call force,CFG_CORE_RWDATA_NOEXEC,y) 80endif 81# 'y' to set the Alignment Check Enable bit in SCTLR/SCTLR_EL1, 'n' to clear it 82CFG_SCTLR_ALIGNMENT_CHECK ?= n 83 84ifeq ($(CFG_CORE_LARGE_PHYS_ADDR),y) 85$(call force,CFG_WITH_LPAE,y) 86endif 87 88# SPMC configuration "S-EL1 SPMC" where SPM Core is implemented at S-EL1, 89# that is, OP-TEE. 90# Note that this is an experimental feature, ABIs etc may have incompatible 91# changes 92ifeq ($(CFG_CORE_SEL1_SPMC),y) 93$(call force,CFG_CORE_FFA,y) 94endif 95 96# Unmaps all kernel mode code except the code needed to take exceptions 97# from user space and restore kernel mode mapping again. This gives more 98# strict control over what is accessible while in user mode. 99# Addresses CVE-2017-5715 (aka Meltdown) known to affect Arm Cortex-A75 100CFG_CORE_UNMAP_CORE_AT_EL0 ?= y 101 102# Initialize PMCR.DP to 1 to prohibit cycle counting in secure state, and 103# save/restore PMCR during world switch. 104CFG_SM_NO_CYCLE_COUNTING ?= y 105 106ifeq ($(CFG_ARM32_core),y) 107# Configration directive related to ARMv7 optee boot arguments. 108# CFG_PAGEABLE_ADDR: if defined, forces pageable data physical address. 109# CFG_NS_ENTRY_ADDR: if defined, forces NS World physical entry address. 110# CFG_DT_ADDR: if defined, forces Device Tree data physical address. 111endif 112 113core-platform-cppflags += -I$(arch-dir)/include 114core-platform-subdirs += \ 115 $(addprefix $(arch-dir)/, kernel crypto mm tee) $(platform-dir) 116 117ifneq ($(CFG_WITH_ARM_TRUSTED_FW),y) 118core-platform-subdirs += $(arch-dir)/sm 119endif 120 121arm64-platform-cppflags += -DARM64=1 -D__LP64__=1 122arm32-platform-cppflags += -DARM32=1 -D__ILP32__=1 123 124platform-cflags-generic ?= -ffunction-sections -fdata-sections -pipe 125platform-aflags-generic ?= -pipe 126 127arm32-platform-aflags += -marm 128 129arm32-platform-cflags-no-hard-float ?= -mfloat-abi=soft 130arm32-platform-cflags-hard-float ?= -mfloat-abi=hard -funsafe-math-optimizations 131arm32-platform-cflags-generic-thumb ?= -mthumb \ 132 -fno-short-enums -fno-common -mno-unaligned-access 133arm32-platform-cflags-generic-arm ?= -marm -fno-omit-frame-pointer -mapcs \ 134 -fno-short-enums -fno-common -mno-unaligned-access 135arm32-platform-aflags-no-hard-float ?= 136 137arm64-platform-cflags-no-hard-float ?= -mgeneral-regs-only 138arm64-platform-cflags-hard-float ?= 139arm64-platform-cflags-generic := -mstrict-align $(call cc-option,-mno-outline-atomics,) 140 141ifeq ($(DEBUG),1) 142# For backwards compatibility 143$(call force,CFG_CC_OPTIMIZE_FOR_SIZE,n) 144$(call force,CFG_DEBUG_INFO,y) 145endif 146 147CFG_CC_OPTIMIZE_FOR_SIZE ?= y 148ifeq ($(CFG_CC_OPTIMIZE_FOR_SIZE),y) 149platform-cflags-optimization ?= -Os 150else 151platform-cflags-optimization ?= -O0 152endif 153 154CFG_DEBUG_INFO ?= y 155ifeq ($(CFG_DEBUG_INFO),y) 156platform-cflags-debug-info ?= -g3 157platform-aflags-debug-info ?= -g 158endif 159 160core-platform-cflags += $(platform-cflags-optimization) 161core-platform-cflags += $(platform-cflags-generic) 162core-platform-cflags += $(platform-cflags-debug-info) 163 164core-platform-aflags += $(platform-aflags-generic) 165core-platform-aflags += $(platform-aflags-debug-info) 166 167ifeq ($(CFG_CORE_ASLR),y) 168core-platform-cflags += -fpie 169endif 170 171ifeq ($(CFG_ARM64_core),y) 172core-platform-cppflags += $(arm64-platform-cppflags) 173core-platform-cflags += $(arm64-platform-cflags) 174core-platform-cflags += $(arm64-platform-cflags-generic) 175core-platform-cflags += $(arm64-platform-cflags-no-hard-float) 176core-platform-aflags += $(arm64-platform-aflags) 177else 178core-platform-cppflags += $(arm32-platform-cppflags) 179core-platform-cflags += $(arm32-platform-cflags) 180core-platform-cflags += $(arm32-platform-cflags-no-hard-float) 181ifeq ($(CFG_UNWIND),y) 182core-platform-cflags += -funwind-tables 183endif 184ifeq ($(CFG_SYSCALL_FTRACE),y) 185core-platform-cflags += $(arm32-platform-cflags-generic-arm) 186else 187core-platform-cflags += $(arm32-platform-cflags-generic-thumb) 188endif 189core-platform-aflags += $(core_arm32-platform-aflags) 190core-platform-aflags += $(arm32-platform-aflags) 191endif 192 193# Provide default supported-ta-targets if not set by the platform config 194ifeq (,$(supported-ta-targets)) 195supported-ta-targets = ta_arm32 196ifeq ($(CFG_ARM64_core),y) 197supported-ta-targets += ta_arm64 198endif 199endif 200 201ta-targets := $(if $(CFG_USER_TA_TARGETS),$(filter $(supported-ta-targets),$(CFG_USER_TA_TARGETS)),$(supported-ta-targets)) 202unsup-targets := $(filter-out $(ta-targets),$(CFG_USER_TA_TARGETS)) 203ifneq (,$(unsup-targets)) 204$(error CFG_USER_TA_TARGETS contains unsupported value(s): $(unsup-targets). Valid values: $(supported-ta-targets)) 205endif 206 207ifneq ($(filter ta_arm32,$(ta-targets)),) 208# Variables for ta-target/sm "ta_arm32" 209CFG_ARM32_ta_arm32 := y 210arch-bits-ta_arm32 := 32 211ta_arm32-platform-cppflags += $(arm32-platform-cppflags) 212ta_arm32-platform-cflags += $(arm32-platform-cflags) 213ta_arm32-platform-cflags += $(platform-cflags-optimization) 214ta_arm32-platform-cflags += $(platform-cflags-debug-info) 215ta_arm32-platform-cflags += -fpic 216 217# Thumb mode doesn't support function graph tracing due to missing 218# frame pointer support required to trace function call chain. So 219# rather compile in ARM mode if function tracing is enabled. 220ifeq ($(CFG_FTRACE_SUPPORT),y) 221ta_arm32-platform-cflags += $(arm32-platform-cflags-generic-arm) 222else 223ta_arm32-platform-cflags += $(arm32-platform-cflags-generic-thumb) 224endif 225 226ifeq ($(arm32-platform-hard-float-enabled),y) 227ta_arm32-platform-cflags += $(arm32-platform-cflags-hard-float) 228else 229ta_arm32-platform-cflags += $(arm32-platform-cflags-no-hard-float) 230endif 231ifeq ($(CFG_UNWIND),y) 232ta_arm32-platform-cflags += -funwind-tables 233endif 234ta_arm32-platform-aflags += $(platform-aflags-generic) 235ta_arm32-platform-aflags += $(platform-aflags-debug-info) 236ta_arm32-platform-aflags += $(arm32-platform-aflags) 237 238ta_arm32-platform-cxxflags += -fpic 239 240ta-mk-file-export-vars-ta_arm32 += CFG_ARM32_ta_arm32 241ta-mk-file-export-vars-ta_arm32 += ta_arm32-platform-cppflags 242ta-mk-file-export-vars-ta_arm32 += ta_arm32-platform-cflags 243ta-mk-file-export-vars-ta_arm32 += ta_arm32-platform-aflags 244ta-mk-file-export-vars-ta_arm32 += ta_arm32-platform-cxxflags 245 246ta-mk-file-export-add-ta_arm32 += CROSS_COMPILE ?= arm-linux-gnueabihf-_nl_ 247ta-mk-file-export-add-ta_arm32 += CROSS_COMPILE32 ?= $$(CROSS_COMPILE)_nl_ 248ta-mk-file-export-add-ta_arm32 += CROSS_COMPILE_ta_arm32 ?= $$(CROSS_COMPILE32)_nl_ 249ta-mk-file-export-add-ta_arm32 += COMPILER ?= gcc_nl_ 250ta-mk-file-export-add-ta_arm32 += COMPILER_ta_arm32 ?= $$(COMPILER)_nl_ 251ta-mk-file-export-add-ta_arm32 += PYTHON3 ?= python3_nl_ 252endif 253 254ifneq ($(filter ta_arm64,$(ta-targets)),) 255# Variables for ta-target/sm "ta_arm64" 256CFG_ARM64_ta_arm64 := y 257arch-bits-ta_arm64 := 64 258ta_arm64-platform-cppflags += $(arm64-platform-cppflags) 259ta_arm64-platform-cflags += $(arm64-platform-cflags) 260ta_arm64-platform-cflags += $(platform-cflags-optimization) 261ta_arm64-platform-cflags += $(platform-cflags-debug-info) 262ta_arm64-platform-cflags += -fpic 263ta_arm64-platform-cflags += $(arm64-platform-cflags-generic) 264ifeq ($(arm64-platform-hard-float-enabled),y) 265ta_arm64-platform-cflags += $(arm64-platform-cflags-hard-float) 266else 267ta_arm64-platform-cflags += $(arm64-platform-cflags-no-hard-float) 268endif 269ta_arm64-platform-aflags += $(platform-aflags-generic) 270ta_arm64-platform-aflags += $(platform-aflags-debug-info) 271ta_arm64-platform-aflags += $(arm64-platform-aflags) 272 273ta_arm64-platform-cxxflags += -fpic 274 275ta-mk-file-export-vars-ta_arm64 += CFG_ARM64_ta_arm64 276ta-mk-file-export-vars-ta_arm64 += ta_arm64-platform-cppflags 277ta-mk-file-export-vars-ta_arm64 += ta_arm64-platform-cflags 278ta-mk-file-export-vars-ta_arm64 += ta_arm64-platform-aflags 279ta-mk-file-export-vars-ta_arm64 += ta_arm64-platform-cxxflags 280 281ta-mk-file-export-add-ta_arm64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_ 282ta-mk-file-export-add-ta_arm64 += CROSS_COMPILE_ta_arm64 ?= $$(CROSS_COMPILE64)_nl_ 283ta-mk-file-export-add-ta_arm64 += COMPILER ?= gcc_nl_ 284ta-mk-file-export-add-ta_arm64 += COMPILER_ta_arm64 ?= $$(COMPILER)_nl_ 285ta-mk-file-export-add-ta_arm64 += PYTHON3 ?= python3_nl_ 286endif 287 288# Set cross compiler prefix for each TA target 289$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm))))) 290 291arm32-sysreg-txt = core/arch/arm/kernel/arm32_sysreg.txt 292arm32-sysregs-$(arm32-sysreg-txt)-h := arm32_sysreg.h 293arm32-sysregs-$(arm32-sysreg-txt)-s := arm32_sysreg.S 294arm32-sysregs += $(arm32-sysreg-txt) 295 296ifeq ($(CFG_ARM_GICV3),y) 297arm32-gicv3-sysreg-txt = core/arch/arm/kernel/arm32_gicv3_sysreg.txt 298arm32-sysregs-$(arm32-gicv3-sysreg-txt)-h := arm32_gicv3_sysreg.h 299arm32-sysregs-$(arm32-gicv3-sysreg-txt)-s := arm32_gicv3_sysreg.S 300arm32-sysregs += $(arm32-gicv3-sysreg-txt) 301endif 302 303arm32-sysregs-out := $(out-dir)/$(sm)/include/generated 304 305define process-arm32-sysreg 306FORCE-GENSRC$(sm): $$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-h) 307cleanfiles := $$(cleanfiles) $$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-h) 308 309$$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-h): $(1) scripts/arm32_sysreg.py 310 @$(cmd-echo-silent) ' GEN $$@' 311 $(q)mkdir -p $$(dir $$@) 312 $(q)scripts/arm32_sysreg.py --guard __$$(arm32-sysregs-$(1)-h) \ 313 < $$< > $$@ 314 315FORCE-GENSRC$(sm): $$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-s) 316cleanfiles := $$(cleanfiles) $$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-s) 317 318$$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-s): $(1) scripts/arm32_sysreg.py 319 @$(cmd-echo-silent) ' GEN $$@' 320 $(q)mkdir -p $$(dir $$@) 321 $(q)scripts/arm32_sysreg.py --s_file < $$< > $$@ 322endef #process-arm32-sysreg 323 324$(foreach sr, $(arm32-sysregs), $(eval $(call process-arm32-sysreg,$(sr)))) 325