-
Notifications
You must be signed in to change notification settings - Fork 518
/
Copy patharm-tools.mk
149 lines (113 loc) · 4.46 KB
/
arm-tools.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# Define ARM tools
#
# Define the compiler/tools prefix
GCC_PREFIX ?= arm-none-eabi-
include $(COMMON_BUILD)/common-tools.mk
AR = $(GCC_ARM_PATH)$(GCC_PREFIX)gcc-ar
# Newlib has a bug in fake stdin/stdout/stderr implementation and leaks memory
# Stub printf/fprintf out, override printf/scanf for 64-bit int/unsigned support
CFLAGS += -fno-builtin-puts -fno-builtin-printf -Wl,--wrap=puts -Wl,--wrap=printf
CFLAGS += -Wl,--wrap=_printf_i -Wl,--wrap=_svfprintf_r
CFLAGS += -Wl,--wrap=_scanf_i -Wl,--wrap=__ssvfscanf_r
#
# default flags for targeting ARM Cortex-M3
#
ifeq ("$(ARM_CPU)","cortex-m3")
# C compiler flags
CFLAGS += -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb
# C++ specific flags
CPPFLAGS += -fno-exceptions -fno-rtti -fcheck-new
CONLYFLAGS +=
ASFLAGS += -g3 -gdwarf-2 -mcpu=cortex-m3 -mthumb
LDFLAGS += -nostartfiles -Xlinker --gc-sections
endif
#
# default flags for targeting ARM Cortex-M4
#
ifeq ("$(ARM_CPU)","cortex-m4")
CFLAGS += -g3 -gdwarf-2 -Os -mcpu=cortex-m4 -mthumb -mabi=aapcs
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# C++ specific flags
CPPFLAGS += -fno-exceptions -fno-rtti -fcheck-new
CONLYFLAGS +=
ASFLAGS += -g3 -gdwarf-2 -mcpu=cortex-m4 -mthumb -mabi=aapcs
ASFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
LDFLAGS += -nostartfiles -Xlinker --gc-sections
#enable the build-id GCC feature
LDFLAGS += -Wl,--build-id
endif
#
# default flags for targeting ARM Cortex-M33
#
ifeq ("$(ARM_CPU)","cortex-m33")
CFLAGS += -g3 -gdwarf-2 -Os -mcpu=cortex-m33 -march=armv8-m.main+dsp -mthumb
CFLAGS += -mcmse -mfloat-abi=hard -mfpu=fpv5-sp-d16
# C++ specific flags
CPPFLAGS += -fno-exceptions -fno-rtti -fcheck-new
CONLYFLAGS +=
ASFLAGS += -g3 -gdwarf-2 -mcpu=cortex-m33 -march=armv8-m.main+dsp -mthumb
ASFLAGS += -mcmse -mfloat-abi=hard -mfpu=fpv5-sp-d16
LDFLAGS += -nostartfiles -Xlinker --gc-sections
endif
#
# default flags for targeting ARM Cortex-M23
#
ifeq ("$(ARM_CPU)","cortex-m23")
CFLAGS += -g3 -gdwarf-2 -Os -mcpu=cortex-m23 -march=armv8-m.base -mthumb -D__ARM_FEATURE_DSP=0
# C++ specific flags
CPPFLAGS += -fno-exceptions -fno-rtti -fcheck-new
CONLYFLAGS +=
ASFLAGS += -g3 -gdwarf-2 -mcpu=cortex-m23 -march=armv8-m.base -mthumb -D__ARM_FEATURE_DSP=0
LDFLAGS += -nostartfiles -Xlinker --gc-sections
endif
CFLAGS += -DARM_CPU_$(shell echo $(ARM_CPU) | tr '-' '_' | tr 'a-z' 'A-Z')
# NOTE: this does not enable LTO! This allows to build object files
# that can be linked with LTO enabled and disabled (https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html)
# If LTO is disabled, LTO information is simply discarded. These parameters
# are only applied when compiling the sources. A separate setting during linking stage
# would control whether LTO is enabled or not.
#
# -fno-use-cxa-atexit makes sure that destructors for statically created C++ objects are never called,
# which saves us some flash space.
LTO_FLAGS = -flto -ffat-lto-objects -DPARTICLE_COMPILE_LTO_FAT
CPPFLAGS += $(LTO_FLAGS) -fno-use-cxa-atexit
CONLYFLAGS += $(LTO_FLAGS)
LDFLAGS += -fno-use-cxa-atexit
USE_LTO=0
ifneq ($(FORCE_LTO),)
USE_LTO=1
endif
ifeq ($(COMPILE_LTO),y)
USE_LTO=1
endif
ifeq ($(USE_LTO),1)
LDFLAGS += -flto -Os -fuse-linker-plugin
CFLAGS += -fuse-linker-plugin
else
# Be explicit and disable LTO
LDFLAGS += -fno-lto
endif
# We are using newlib-nano for all the platforms
CFLAGS += --specs=nano.specs
ifneq ($(LTO_EXTRA_OPTIMIZATIONS),)
CFLAGS += -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -flto-partition=balanced -fmerge-all-constants
LDFLAGS += -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -flto-partition=balanced -fmerge-all-constants
endif
# Check if the compiler version is the minimum required
version_to_number=$(shell v=$1; v=($${v//./ }); echo $$((v[0] * 10000 + v[1] * 100 + v[2])))
get_major_version=$(shell v=$1; v=($${v//./ }); echo $${v[0]})
arm_gcc_version_str:=$(shell $(CC) -dumpversion)
arm_gcc_version:=$(call version_to_number,$(arm_gcc_version_str))
expected_version_str:=10.2.1
ifeq ($(shell test $(arm_gcc_version) -lt $(call version_to_number,$(expected_version_str)); echo $$?),0)
$(error "ARM gcc version $(expected_version_str) or later required, but found $(arm_gcc_version_str)")
endif
ifeq ($(shell test $(arm_gcc_version) -lt $(call version_to_number,4.9.0); echo $$?),0)
NANO_SUFFIX=_s
endif
# GCC 8 linker is broken and doesn't support LENGTH(region) when defining another memory region within
# MEMORY block
ifeq ($(call get_major_version,$(arm_gcc_version_str)),8)
LDFLAGS += -Wl,--defsym=GCC_LD_BROKEN=1
endif