blob: 429dda08a790bcce424eebde5ae3c061bdccf98f [file] [log] [blame]
Boyan Karatotev3df79ae2025-04-09 14:26:17 +01001#
2# Copyright (c) 2025, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7GCC_V_OUTPUT := $(if $($(ARCH)-cc),$(shell $($(ARCH)-cc) -v 2>&1))
8PIE_FOUND := $(findstring --enable-default-pie,${GCC_V_OUTPUT})
9
10################################################################################
11# Compiler Configuration based on ARCH_MAJOR and ARCH_MINOR flags
12################################################################################
13ifeq (${ARM_ARCH_MAJOR},7)
14 target32-directive = -target arm-none-eabi
15# Will set march-directive from platform configuration
16else
17 target32-directive = -target armv8a-none-eabi
18endif #(ARM_ARCH_MAJOR)
19
20ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
21 ifeq ($($(ARCH)-cc-id),arm-clang)
22 TF_CFLAGS_aarch32 := -target arm-arm-none-eabi
23 TF_CFLAGS_aarch64 := -target aarch64-arm-none-eabi
24 else
25 TF_CFLAGS_aarch32 = $(target32-directive)
26 TF_CFLAGS_aarch64 := -target aarch64-elf
27 endif
28endif #(clang)
29
30# Process Debug flag
31ifneq (${DEBUG}, 0)
32 TF_CFLAGS += -g -gdwarf-4
33 ASFLAGS += -g -Wa,-gdwarf-4
34endif #(Debug)
35
36ifeq (${AARCH32_INSTRUCTION_SET},A32)
37 TF_CFLAGS_aarch32 += -marm
38else ifeq (${AARCH32_INSTRUCTION_SET},T32)
39 TF_CFLAGS_aarch32 += -mthumb
40endif #(AARCH32_INSTRUCTION_SET)
41
42TF_CFLAGS_aarch32 += -mno-unaligned-access
43TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align
44
45##############################################################################
46# WARNINGS Configuration
47###############################################################################
48# General warnings
49WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
50 -Wdisabled-optimization -Wvla -Wshadow \
51 -Wredundant-decls
52# stricter warnings
53WARNINGS += -Wextra -Wno-trigraphs
54# too verbose for generic build
55WARNINGS += -Wno-missing-field-initializers \
56 -Wno-type-limits -Wno-sign-compare \
57# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
58WARNINGS += -Wno-unused-parameter
59
60# Additional warnings
61# Level 1 - infrequent warnings we should have none of
62# full -Wextra
63WARNING1 += -Wsign-compare
64WARNING1 += -Wtype-limits
65WARNING1 += -Wmissing-field-initializers
66
67# Level 2 - problematic warnings that we want
68# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
69# TODO: disable just for them and move into default build
70WARNING2 += -Wold-style-definition
71WARNING2 += -Wmissing-prototypes
72WARNING2 += -Wmissing-format-attribute
73# TF-A aims to comply with this eventually. Effort too large at present
74WARNING2 += -Wundef
75# currently very involved and many platforms set this off
76WARNING2 += -Wunused-const-variable=2
77
78# Level 3 - very pedantic, frequently ignored
79WARNING3 := -Wbad-function-cast
80WARNING3 += -Waggregate-return
81WARNING3 += -Wnested-externs
82WARNING3 += -Wcast-align
83WARNING3 += -Wcast-qual
84WARNING3 += -Wconversion
85WARNING3 += -Wpacked
86WARNING3 += -Wpointer-arith
87WARNING3 += -Wswitch-default
88
89ifeq (${W},1)
90 WARNINGS += $(WARNING1)
91else ifeq (${W},2)
92 WARNINGS += $(WARNING1) $(WARNING2)
93else ifeq (${W},3)
94 WARNINGS += $(WARNING1) $(WARNING2) $(WARNING3)
95endif #(W)
96
97ifneq (${E},0)
98 ERRORS := -Werror
99endif #(E)
100
101# Compiler specific warnings
102ifeq ($(filter %-clang,$($(ARCH)-cc-id)),)
103# not using clang
104# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
105TF_CFLAGS_MIN_PAGE_SIZE := $(call cc_option, --param=min-pagesize=0)
106TF_CFLAGS += $(TF_CFLAGS_MIN_PAGE_SIZE)
107
108ifeq ($(HARDEN_SLS), 1)
109 TF_CFLAGS_MHARDEN_SLS := $(call cc_option, -mharden-sls=all)
110 TF_CFLAGS_aarch64 += $(TF_CFLAGS_MHARDEN_SLS)
111endif
112
113WARNINGS += -Wunused-but-set-variable -Wmaybe-uninitialized \
114 -Wpacked-bitfield-compat -Wshift-overflow=2 \
115 -Wlogical-op
116
117else
118# using clang
119WARNINGS += -Wshift-overflow -Wshift-sign-overflow \
120 -Wlogical-op-parentheses
121endif #(Clang Warning)
122
123CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \
124 $(ERRORS) $(WARNINGS)
125
126
127TF_CFLAGS += -ffunction-sections -fdata-sections \
128 -ffreestanding -fno-common \
129 -Os -std=gnu99
130
131ifneq (${BP_OPTION},none)
132 TF_CFLAGS_aarch64 += -mbranch-protection=${BP_OPTION}
133endif #(BP_OPTION)
134
135ifeq (${SANITIZE_UB},on)
136 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover
137endif #(${SANITIZE_UB},on)
138
139ifeq (${SANITIZE_UB},trap)
140 TF_CFLAGS += -fsanitize=undefined -fno-sanitize-recover \
141 -fsanitize-undefined-trap-on-error
142endif #(${SANITIZE_UB},trap)
143
144ifeq ($($(ARCH)-cc-id),gnu-gcc)
145 # Enable LTO only for aarch64
146 LTO_CFLAGS = $(if $(filter-out 0,$(ENABLE_LTO)),-flto)
147endif #(gnu-gcc)
148
149ifeq (${ERROR_DEPRECATED},0)
150# Check if deprecated declarations and cpp warnings should be treated as error or not.
151ifneq ($(filter %-clang,$($(ARCH)-cc-id)),)
152 CPPFLAGS += -Wno-error=deprecated-declarations
153else
154 CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp
155endif
156endif #(!ERROR_DEPRECATED)
157
158################################################################################
159# Platform specific Makefile might provide us ARCH_MAJOR/MINOR use that to come
160# up with appropriate march values for compiler.
161################################################################################
162include ${MAKE_HELPERS_DIRECTORY}march.mk
163ifeq (${ARM_ARCH_MAJOR},7)
164include make_helpers/armv7-a-cpus.mk
165endif
166
167TF_CFLAGS += $(march-directive)
168ASFLAGS += $(march-directive)
169
170ifneq ($(PIE_FOUND),)
171 TF_CFLAGS += -fno-PIE
172endif
173
174TF_CFLAGS += $(CPPFLAGS) $(TF_CFLAGS_$(ARCH))
Boyan Karatotev6bb9f052025-04-25 13:25:50 +0100175TF_CFLAGS += $(CFLAGS)
Boyan Karatotev3df79ae2025-04-09 14:26:17 +0100176ASFLAGS += $(CPPFLAGS) \
177 -ffreestanding -Wa,--fatal-warnings
178TF_LDFLAGS += -z noexecstack
179
180# LD = armlink
181ifeq ($($(ARCH)-ld-id),arm-link)
182 TF_LDFLAGS += --diag_error=warning --lto_level=O1
183 TF_LDFLAGS += --remove --info=unused,unusedsymbols
184 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH))
185
186# LD = gcc (used when GCC LTO is enabled)
187else ifeq ($($(ARCH)-ld-id),gnu-gcc)
188 # Pass ld options with Wl or Xlinker switches
189 TF_LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments)
190 TF_LDFLAGS += -Wl,--fatal-warnings -O1
191 TF_LDFLAGS += -Wl,--gc-sections
192
193 TF_LDFLAGS += -Wl,-z,common-page-size=4096 #Configure page size constants
194 TF_LDFLAGS += -Wl,-z,max-page-size=4096
195 TF_LDFLAGS += -Wl,--build-id=none
196
197 ifeq ($(ENABLE_LTO),1)
198 TF_LDFLAGS += -flto -fuse-linker-plugin
199 TF_LDFLAGS += -flto-partition=one
200 endif #(ENABLE_LTO)
201
202# GCC automatically adds fix-cortex-a53-843419 flag when used to link
203# which breaks some builds, so disable if errata fix is not explicitly enabled
204 ifeq (${ARCH},aarch64)
205 ifneq (${ERRATA_A53_843419},1)
206 TF_LDFLAGS += -mno-fix-cortex-a53-843419
207 endif
208 endif
209 TF_LDFLAGS += -nostdlib
210 TF_LDFLAGS += $(subst --,-Xlinker --,$(TF_LDFLAGS_$(ARCH)))
211
212# LD = gcc-ld (ld) or llvm-ld (ld.lld) or other
213else
214# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
215# are not loaded by a elf loader.
216 TF_LDFLAGS += $(call ld_option, --no-warn-rwx-segments)
217 TF_LDFLAGS += -O1
218 TF_LDFLAGS += --gc-sections
219
220 TF_LDFLAGS += -z common-page-size=4096 # Configure page size constants
221 TF_LDFLAGS += -z max-page-size=4096
222 TF_LDFLAGS += --build-id=none
223
224# ld.lld doesn't recognize the errata flags,
225# therefore don't add those in that case.
226# ld.lld reports section type mismatch warnings,
227# therefore don't add --fatal-warnings to it.
228 ifneq ($($(ARCH)-ld-id),llvm-lld)
229 TF_LDFLAGS += $(TF_LDFLAGS_$(ARCH)) --fatal-warnings
230 endif
231
232endif #(LD = armlink)
233
234ifneq ($(PIE_FOUND),)
235ifeq ($($(ARCH)-ld-id),gnu-gcc)
236 TF_LDFLAGS += -no-pie
237endif
238endif #(PIE_FOUND)
239
240ifeq ($($(ARCH)-ld-id),gnu-gcc)
241 PIE_LDFLAGS += -Wl,-pie -Wl,--no-dynamic-linker
242else
243 PIE_LDFLAGS += -pie --no-dynamic-linker
244endif
245
246ifeq ($(ENABLE_PIE),1)
247 ifeq ($(RESET_TO_BL2),1)
248 ifneq ($(BL2_IN_XIP_MEM),1)
249 BL2_CPPFLAGS += -fpie
250 BL2_CFLAGS += -fpie
251 BL2_LDFLAGS += $(PIE_LDFLAGS)
252 endif #(BL2_IN_XIP_MEM)
253 endif #(RESET_TO_BL2)
254 BL31_CPPFLAGS += -fpie
255 BL31_CFLAGS += -fpie
256 BL31_LDFLAGS += $(PIE_LDFLAGS)
257
258 BL32_CPPFLAGS += -fpie
259 BL32_CFLAGS += -fpie
260 BL32_LDFLAGS += $(PIE_LDFLAGS)
261endif #(ENABLE_PIE)
262
263BL1_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
264BL31_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
265BL32_CPPFLAGS += -DREPORT_ERRATA=${DEBUG}
266
267BL1_CPPFLAGS += -DIMAGE_AT_EL3
268ifeq ($(RESET_TO_BL2),1)
269 BL2_CPPFLAGS += -DIMAGE_AT_EL3
270else
271 BL2_CPPFLAGS += -DIMAGE_AT_EL1
272endif #(RESET_TO_BL2)
273
274ifeq (${ARCH},aarch64)
275 BL2U_CPPFLAGS += -DIMAGE_AT_EL1
276 BL31_CPPFLAGS += -DIMAGE_AT_EL3
277 BL32_CPPFLAGS += -DIMAGE_AT_EL1
278else
279 BL32_CPPFLAGS += -DIMAGE_AT_EL3
280endif
281
282ifeq (${SPD},spmd)
283 ifeq ($(findstring optee_sp,$(ARM_SPMC_MANIFEST_DTS)),optee_sp)
284 DTC_CPPFLAGS += -DOPTEE_SP_FW_CONFIG
285 endif
286
287 ifeq ($(findstring trusty_sp,$(ARM_SPMC_MANIFEST_DTS)),trusty_sp)
288 DTC_CPPFLAGS += -DTRUSTY_SP_FW_CONFIG
289 endif
290
291 ifeq ($(TS_SP_FW_CONFIG),1)
292 DTC_CPPFLAGS += -DTS_SP_FW_CONFIG
293 endif
294
295 ifneq ($(ARM_BL2_SP_LIST_DTS),)
296 DTC_CPPFLAGS += -DARM_BL2_SP_LIST_DTS=$(ARM_BL2_SP_LIST_DTS)
297 endif
298endif
299
300
301DTC_FLAGS += -I dts -O dtb
Boyan Karatotev1e8b5352025-04-29 09:32:12 +0100302DTC_CPPFLAGS += -Ifdts -undef
Boyan Karatotev3df79ae2025-04-09 14:26:17 +0100303