xref: /optee_os/core/arch/arm/arm.mk (revision cb5f271c1eaed4c18fd26873f152afc0590b0413)
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
14# Size of emulated TrustZone protected SRAM, 448 kB.
15# Only applicable when paging is enabled.
16CFG_CORE_TZSRAM_EMUL_SIZE ?= 458752
17
18ifneq ($(CFG_LPAE_ADDR_SPACE_SIZE),)
19$(warning Error: CFG_LPAE_ADDR_SPACE_SIZE is not supported any longer)
20$(error Error: Please use CFG_LPAE_ADDR_SPACE_BITS instead)
21endif
22
23CFG_LPAE_ADDR_SPACE_BITS ?= 32
24
25CFG_MMAP_REGIONS ?= 13
26CFG_RESERVED_VASPACE_SIZE ?= (1024 * 1024 * 10)
27
28ifeq ($(CFG_ARM64_core),y)
29ifeq ($(CFG_ARM32_core),y)
30$(error CFG_ARM64_core and CFG_ARM32_core cannot be both 'y')
31endif
32CFG_KERN_LINKER_FORMAT ?= elf64-littleaarch64
33CFG_KERN_LINKER_ARCH ?= aarch64
34# TCR_EL1.IPS needs to be initialized according to the largest physical
35# address that we need to map.
36# Physical address size
37# 32 bits, 4GB.
38# 36 bits, 64GB.
39# (etc.)
40CFG_CORE_ARM64_PA_BITS ?= 32
41$(call force,CFG_WITH_LPAE,y)
42else
43$(call force,CFG_ARM32_core,y)
44CFG_KERN_LINKER_FORMAT ?= elf32-littlearm
45CFG_KERN_LINKER_ARCH ?= arm
46endif
47
48ifeq ($(CFG_TA_FLOAT_SUPPORT),y)
49# Use hard-float for floating point support in user TAs instead of
50# soft-float
51CFG_WITH_VFP ?= y
52ifeq ($(CFG_ARM64_core),y)
53# AArch64 has no fallback to soft-float
54$(call force,CFG_WITH_VFP,y)
55endif
56ifeq ($(CFG_WITH_VFP),y)
57arm64-platform-hard-float-enabled := y
58ifneq ($(CFG_TA_ARM32_NO_HARD_FLOAT_SUPPORT),y)
59arm32-platform-hard-float-enabled := y
60endif
61endif
62endif
63
64# Adds protection against CVE-2017-5715 also know as Spectre
65# (https://spectreattack.com)
66# See also https://developer.arm.com/-/media/Files/pdf/Cache_Speculation_Side-channels.pdf
67# Variant 2
68CFG_CORE_WORKAROUND_SPECTRE_BP ?= y
69# Same as CFG_CORE_WORKAROUND_SPECTRE_BP but targeting exceptions from
70# secure EL0 instead of non-secure world, including mitigation for
71# CVE-2022-23960.
72CFG_CORE_WORKAROUND_SPECTRE_BP_SEC ?= $(CFG_CORE_WORKAROUND_SPECTRE_BP)
73
74# Adds protection against a tool like Cachegrab
75# (https://github.com/nccgroup/cachegrab), which uses non-secure interrupts
76# to prime and later analyze the L1D, L1I and BTB caches to gain
77# information from secure world execution.
78CFG_CORE_WORKAROUND_NSITR_CACHE_PRIME ?= y
79ifeq ($(CFG_CORE_WORKAROUND_NSITR_CACHE_PRIME),y)
80$(call force,CFG_CORE_WORKAROUND_SPECTRE_BP,y,Required by CFG_CORE_WORKAROUND_NSITR_CACHE_PRIME)
81endif
82
83# Adds workarounds against if ARM core is configured with Non-maskable FIQ
84# (NMFI) support. This is indicated by SCTLR.NMFI being true. NMFI cannot be
85# disabled by software and as it affects atomic context end result will be
86# prohibiting FIQ signal usage in OP-TEE and applying some tweaks to make sure
87# FIQ is enabled in critical places.
88CFG_CORE_WORKAROUND_ARM_NMFI ?= n
89
90CFG_CORE_RWDATA_NOEXEC ?= y
91CFG_CORE_RODATA_NOEXEC ?= n
92ifeq ($(CFG_CORE_RODATA_NOEXEC),y)
93$(call force,CFG_CORE_RWDATA_NOEXEC,y)
94endif
95# 'y' to set the Alignment Check Enable bit in SCTLR/SCTLR_EL1, 'n' to clear it
96CFG_SCTLR_ALIGNMENT_CHECK ?= n
97
98ifeq ($(CFG_CORE_LARGE_PHYS_ADDR),y)
99$(call force,CFG_WITH_LPAE,y)
100endif
101
102# SPMC configuration "S-EL1 SPMC" where SPM Core is implemented at S-EL1,
103# that is, OP-TEE.
104ifeq ($(CFG_CORE_SEL1_SPMC),y)
105$(call force,CFG_CORE_FFA,y)
106$(call force,CFG_CORE_SEL2_SPMC,n)
107$(call force,CFG_CORE_EL3_SPMC,n)
108endif
109# SPMC configuration "S-EL2 SPMC" where SPM Core is implemented at S-EL2,
110# that is, the hypervisor sandboxing OP-TEE
111ifeq ($(CFG_CORE_SEL2_SPMC),y)
112$(call force,CFG_CORE_FFA,y)
113$(call force,CFG_CORE_SEL1_SPMC,n)
114$(call force,CFG_CORE_EL3_SPMC,n)
115CFG_CORE_HAFNIUM_INTC ?= y
116endif
117# SPMC configuration "EL3 SPMC" where SPM Core is implemented at EL3, that
118# is, in TF-A
119ifeq ($(CFG_CORE_EL3_SPMC),y)
120$(call force,CFG_CORE_FFA,y)
121$(call force,CFG_CORE_SEL2_SPMC,n)
122$(call force,CFG_CORE_SEL1_SPMC,n)
123endif
124
125ifeq ($(CFG_CORE_FFA)-$(CFG_WITH_PAGER),y-y)
126$(error CFG_CORE_FFA and CFG_WITH_PAGER are not compatible)
127endif
128ifeq ($(CFG_GIC),y)
129ifeq ($(CFG_ARM_GICV3),y)
130$(call force,CFG_CORE_IRQ_IS_NATIVE_INTR,y)
131else
132$(call force,CFG_CORE_IRQ_IS_NATIVE_INTR,n)
133endif
134endif
135
136CFG_CORE_HAFNIUM_INTC ?= n
137ifeq ($(CFG_CORE_HAFNIUM_INTC),y)
138$(call force,CFG_CORE_IRQ_IS_NATIVE_INTR,y)
139endif
140
141# Selects if IRQ is used to signal native interrupt
142# if CFG_CORE_IRQ_IS_NATIVE_INTR == y:
143#   IRQ signals a native interrupt pending
144#   FIQ signals a foreign non-secure interrupt or a managed exit pending
145# else: (vice versa)
146#   IRQ signals a foreign non-secure interrupt or a managed exit pending
147#   FIQ signals a native interrupt pending
148CFG_CORE_IRQ_IS_NATIVE_INTR ?= n
149
150# Unmaps all kernel mode code except the code needed to take exceptions
151# from user space and restore kernel mode mapping again. This gives more
152# strict control over what is accessible while in user mode.
153# Addresses CVE-2017-5715 (aka Meltdown) known to affect Arm Cortex-A75
154CFG_CORE_UNMAP_CORE_AT_EL0 ?= y
155
156# Initialize PMCR.DP to 1 to prohibit cycle counting in secure state, and
157# save/restore PMCR during world switch.
158CFG_SM_NO_CYCLE_COUNTING ?= y
159
160
161# CFG_CORE_ASYNC_NOTIF_GIC_INTID is defined by the platform to some free
162# interrupt. Setting it to a non-zero number enables support for using an
163# Arm-GIC to notify normal world. This config variable should use a value
164# larger the 32 to make it of the type SPI.
165# Note that asynchronous notifactions must be enabled with
166# CFG_CORE_ASYNC_NOTIF=y for this variable to be used.
167CFG_CORE_ASYNC_NOTIF_GIC_INTID ?= 0
168
169ifeq ($(CFG_ARM32_core),y)
170# Configration directive related to ARMv7 optee boot arguments.
171# CFG_PAGEABLE_ADDR: if defined, forces pageable data physical address.
172# CFG_NS_ENTRY_ADDR: if defined, forces NS World physical entry address.
173# CFG_DT_ADDR:       if defined, forces Device Tree data physical address.
174endif
175
176# CFG_MAX_CACHE_LINE_SHIFT is used to define platform specific maximum cache
177# line size in address lines. This must cover all inner and outer cache levels.
178# When data is aligned with this and cache operations are performed then those
179# only affect correct data.
180#
181# Default value (6 lines or 64 bytes) should cover most architectures, override
182# this in platform config if different.
183CFG_MAX_CACHE_LINE_SHIFT ?= 6
184
185core-platform-cppflags	+= -I$(arch-dir)/include
186core-platform-subdirs += \
187	$(addprefix $(arch-dir)/, kernel crypto mm tee) $(platform-dir)
188
189ifneq ($(CFG_WITH_ARM_TRUSTED_FW),y)
190core-platform-subdirs += $(arch-dir)/sm
191endif
192
193arm64-platform-cppflags += -DARM64=1 -D__LP64__=1
194arm32-platform-cppflags += -DARM32=1 -D__ILP32__=1
195
196platform-cflags-generic ?= -ffunction-sections -fdata-sections -pipe
197platform-aflags-generic ?= -pipe
198
199arm32-platform-aflags += -marm
200
201arm32-platform-cflags-no-hard-float ?= -mfloat-abi=soft
202arm32-platform-cflags-hard-float ?= -mfloat-abi=hard -funsafe-math-optimizations
203arm32-platform-cflags-generic-thumb ?= -mthumb \
204			-fno-short-enums -fno-common -mno-unaligned-access
205arm32-platform-cflags-generic-arm ?= -marm -fno-omit-frame-pointer -mapcs \
206			-fno-short-enums -fno-common -mno-unaligned-access
207arm32-platform-aflags-no-hard-float ?=
208
209arm64-platform-cflags-no-hard-float ?= -mgeneral-regs-only
210arm64-platform-cflags-hard-float ?=
211arm64-platform-cflags-generic := -mstrict-align $(call cc-option,-mno-outline-atomics,)
212
213ifeq ($(CFG_MEMTAG),y)
214arm64-platform-cflags += -march=armv8.5-a+memtag
215arm64-platform-aflags += -march=armv8.5-a+memtag
216endif
217
218platform-cflags-optimization ?= -O$(CFG_CC_OPT_LEVEL)
219
220ifeq ($(CFG_DEBUG_INFO),y)
221platform-cflags-debug-info ?= -g3
222platform-aflags-debug-info ?= -g
223endif
224
225core-platform-cflags += $(platform-cflags-optimization)
226core-platform-cflags += $(platform-cflags-generic)
227core-platform-cflags += $(platform-cflags-debug-info)
228
229core-platform-aflags += $(platform-aflags-generic)
230core-platform-aflags += $(platform-aflags-debug-info)
231
232ifeq ($(CFG_CORE_ASLR),y)
233core-platform-cflags += -fpie
234endif
235
236ifeq ($(CFG_CORE_PAUTH),y)
237bp-core-opt := $(call cc-option,-mbranch-protection=pac-ret+leaf)
238endif
239
240ifeq ($(CFG_CORE_BTI),y)
241bp-core-opt := $(call cc-option,-mbranch-protection=bti)
242endif
243
244ifeq (y-y,$(CFG_CORE_PAUTH)-$(CFG_CORE_BTI))
245bp-core-opt := $(call cc-option,-mbranch-protection=pac-ret+leaf+bti)
246endif
247
248ifeq (y,$(filter $(CFG_CORE_BTI) $(CFG_CORE_PAUTH),y))
249ifeq (,$(bp-core-opt))
250$(error -mbranch-protection not supported)
251endif
252core-platform-cflags += $(bp-core-opt)
253endif
254
255ifeq ($(CFG_ARM64_core),y)
256core-platform-cppflags += $(arm64-platform-cppflags)
257core-platform-cflags += $(arm64-platform-cflags)
258core-platform-cflags += $(arm64-platform-cflags-generic)
259core-platform-cflags += $(arm64-platform-cflags-no-hard-float)
260core-platform-aflags += $(arm64-platform-aflags)
261else
262core-platform-cppflags += $(arm32-platform-cppflags)
263core-platform-cflags += $(arm32-platform-cflags)
264core-platform-cflags += $(arm32-platform-cflags-no-hard-float)
265ifeq ($(CFG_UNWIND),y)
266core-platform-cflags += -funwind-tables
267endif
268ifeq ($(CFG_SYSCALL_FTRACE),y)
269core-platform-cflags += $(arm32-platform-cflags-generic-arm)
270else
271core-platform-cflags += $(arm32-platform-cflags-generic-thumb)
272endif
273core-platform-aflags += $(core_arm32-platform-aflags)
274core-platform-aflags += $(arm32-platform-aflags)
275endif
276
277# Provide default supported-ta-targets if not set by the platform config
278ifeq (,$(supported-ta-targets))
279supported-ta-targets = ta_arm32
280ifeq ($(CFG_ARM64_core),y)
281supported-ta-targets += ta_arm64
282endif
283endif
284
285ta-targets := $(if $(CFG_USER_TA_TARGETS),$(filter $(supported-ta-targets),$(CFG_USER_TA_TARGETS)),$(supported-ta-targets))
286unsup-targets := $(filter-out $(ta-targets),$(CFG_USER_TA_TARGETS))
287ifneq (,$(unsup-targets))
288$(error CFG_USER_TA_TARGETS contains unsupported value(s): $(unsup-targets). Valid values: $(supported-ta-targets))
289endif
290
291ifneq ($(filter ta_arm32,$(ta-targets)),)
292# Variables for ta-target/sm "ta_arm32"
293CFG_ARM32_ta_arm32 := y
294arch-bits-ta_arm32 := 32
295ta_arm32-platform-cppflags += $(arm32-platform-cppflags)
296ta_arm32-platform-cflags += $(arm32-platform-cflags)
297ta_arm32-platform-cflags += $(platform-cflags-optimization)
298ta_arm32-platform-cflags += $(platform-cflags-debug-info)
299ta_arm32-platform-cflags += -fpic
300
301# Thumb mode doesn't support function graph tracing due to missing
302# frame pointer support required to trace function call chain. So
303# rather compile in ARM mode if function tracing is enabled.
304ifeq ($(CFG_FTRACE_SUPPORT),y)
305ta_arm32-platform-cflags += $(arm32-platform-cflags-generic-arm)
306else
307ta_arm32-platform-cflags += $(arm32-platform-cflags-generic-thumb)
308endif
309
310ifeq ($(arm32-platform-hard-float-enabled),y)
311ta_arm32-platform-cflags += $(arm32-platform-cflags-hard-float)
312else
313ta_arm32-platform-cflags += $(arm32-platform-cflags-no-hard-float)
314endif
315ifeq ($(CFG_UNWIND),y)
316ta_arm32-platform-cflags += -funwind-tables
317endif
318ta_arm32-platform-aflags += $(platform-aflags-generic)
319ta_arm32-platform-aflags += $(platform-aflags-debug-info)
320ta_arm32-platform-aflags += $(arm32-platform-aflags)
321
322ta_arm32-platform-cxxflags += -fpic
323ta_arm32-platform-cxxflags += $(arm32-platform-cxxflags)
324ta_arm32-platform-cxxflags += $(platform-cflags-optimization)
325ta_arm32-platform-cxxflags += $(platform-cflags-debug-info)
326
327ifeq ($(arm32-platform-hard-float-enabled),y)
328ta_arm32-platform-cxxflags += $(arm32-platform-cflags-hard-float)
329else
330ta_arm32-platform-cxxflags += $(arm32-platform-cflags-no-hard-float)
331endif
332
333ta-mk-file-export-vars-ta_arm32 += CFG_ARM32_ta_arm32
334ta-mk-file-export-vars-ta_arm32 += ta_arm32-platform-cppflags
335ta-mk-file-export-vars-ta_arm32 += ta_arm32-platform-cflags
336ta-mk-file-export-vars-ta_arm32 += ta_arm32-platform-aflags
337ta-mk-file-export-vars-ta_arm32 += ta_arm32-platform-cxxflags
338
339ta-mk-file-export-add-ta_arm32 += CROSS_COMPILE ?= arm-linux-gnueabihf-_nl_
340ta-mk-file-export-add-ta_arm32 += CROSS_COMPILE32 ?= $$(CROSS_COMPILE)_nl_
341ta-mk-file-export-add-ta_arm32 += CROSS_COMPILE_ta_arm32 ?= $$(CROSS_COMPILE32)_nl_
342ta-mk-file-export-add-ta_arm32 += COMPILER ?= gcc_nl_
343ta-mk-file-export-add-ta_arm32 += COMPILER_ta_arm32 ?= $$(COMPILER)_nl_
344ta-mk-file-export-add-ta_arm32 += PYTHON3 ?= python3_nl_
345endif
346
347ifneq ($(filter ta_arm64,$(ta-targets)),)
348# Variables for ta-target/sm "ta_arm64"
349CFG_ARM64_ta_arm64 := y
350arch-bits-ta_arm64 := 64
351ta_arm64-platform-cppflags += $(arm64-platform-cppflags)
352ta_arm64-platform-cflags += $(arm64-platform-cflags)
353ta_arm64-platform-cflags += $(platform-cflags-optimization)
354ta_arm64-platform-cflags += $(platform-cflags-debug-info)
355ta_arm64-platform-cflags += -fpic
356ta_arm64-platform-cflags += $(arm64-platform-cflags-generic)
357ifeq ($(arm64-platform-hard-float-enabled),y)
358ta_arm64-platform-cflags += $(arm64-platform-cflags-hard-float)
359else
360ta_arm64-platform-cflags += $(arm64-platform-cflags-no-hard-float)
361endif
362ta_arm64-platform-aflags += $(platform-aflags-generic)
363ta_arm64-platform-aflags += $(platform-aflags-debug-info)
364ta_arm64-platform-aflags += $(arm64-platform-aflags)
365
366ta_arm64-platform-cxxflags += -fpic
367ta_arm64-platform-cxxflags += $(platform-cflags-optimization)
368ta_arm64-platform-cxxflags += $(platform-cflags-debug-info)
369
370ifeq ($(CFG_TA_PAUTH),y)
371bp-ta-opt := $(call cc-option,-mbranch-protection=pac-ret+leaf)
372endif
373
374ifeq ($(CFG_TA_BTI),y)
375bp-ta-opt := $(call cc-option,-mbranch-protection=bti)
376endif
377
378ifeq (y-y,$(CFG_TA_PAUTH)-$(CFG_TA_BTI))
379bp-ta-opt := $(call cc-option,-mbranch-protection=pac-ret+leaf+bti)
380endif
381
382ifeq (y,$(filter $(CFG_TA_BTI) $(CFG_TA_PAUTH),y))
383ifeq (,$(bp-ta-opt))
384$(error -mbranch-protection not supported)
385endif
386ta_arm64-platform-cflags += $(bp-ta-opt)
387endif
388
389ta-mk-file-export-vars-ta_arm64 += CFG_ARM64_ta_arm64
390ta-mk-file-export-vars-ta_arm64 += ta_arm64-platform-cppflags
391ta-mk-file-export-vars-ta_arm64 += ta_arm64-platform-cflags
392ta-mk-file-export-vars-ta_arm64 += ta_arm64-platform-aflags
393ta-mk-file-export-vars-ta_arm64 += ta_arm64-platform-cxxflags
394
395ta-mk-file-export-add-ta_arm64 += CROSS_COMPILE64 ?= $$(CROSS_COMPILE)_nl_
396ta-mk-file-export-add-ta_arm64 += CROSS_COMPILE_ta_arm64 ?= $$(CROSS_COMPILE64)_nl_
397ta-mk-file-export-add-ta_arm64 += COMPILER ?= gcc_nl_
398ta-mk-file-export-add-ta_arm64 += COMPILER_ta_arm64 ?= $$(COMPILER)_nl_
399ta-mk-file-export-add-ta_arm64 += PYTHON3 ?= python3_nl_
400endif
401
402# Set cross compiler prefix for each TA target
403$(foreach sm, $(ta-targets), $(eval CROSS_COMPILE_$(sm) ?= $(CROSS_COMPILE$(arch-bits-$(sm)))))
404
405arm32-sysreg-txt = core/arch/arm/kernel/arm32_sysreg.txt
406arm32-sysregs-$(arm32-sysreg-txt)-h := arm32_sysreg.h
407arm32-sysregs-$(arm32-sysreg-txt)-s := arm32_sysreg.S
408arm32-sysregs += $(arm32-sysreg-txt)
409
410ifeq ($(CFG_ARM_GICV3),y)
411arm32-gicv3-sysreg-txt = core/arch/arm/kernel/arm32_gicv3_sysreg.txt
412arm32-sysregs-$(arm32-gicv3-sysreg-txt)-h := arm32_gicv3_sysreg.h
413arm32-sysregs-$(arm32-gicv3-sysreg-txt)-s := arm32_gicv3_sysreg.S
414arm32-sysregs += $(arm32-gicv3-sysreg-txt)
415endif
416
417arm32-sysregs-out := $(out-dir)/$(sm)/include/generated
418
419define process-arm32-sysreg
420FORCE-GENSRC$(sm): $$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-h)
421cleanfiles := $$(cleanfiles) $$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-h)
422
423$$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-h): $(1) scripts/arm32_sysreg.py
424	@$(cmd-echo-silent) '  GEN     $$@'
425	$(q)mkdir -p $$(dir $$@)
426	$(q)scripts/arm32_sysreg.py --guard __$$(arm32-sysregs-$(1)-h) \
427		< $$< > $$@
428
429FORCE-GENSRC$(sm): $$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-s)
430cleanfiles := $$(cleanfiles) $$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-s)
431
432$$(arm32-sysregs-out)/$$(arm32-sysregs-$(1)-s): $(1) scripts/arm32_sysreg.py
433	@$(cmd-echo-silent) '  GEN     $$@'
434	$(q)mkdir -p $$(dir $$@)
435	$(q)scripts/arm32_sysreg.py --s_file < $$< > $$@
436endef #process-arm32-sysreg
437
438$(foreach sr, $(arm32-sysregs), $(eval $(call process-arm32-sysreg,$(sr))))
439