-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile.include
238 lines (211 loc) · 5.53 KB
/
Makefile.include
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
TOP_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/
TOOLCHAIN_DIR ?= $(TOP_DIR)vendor/libopencm3
UNAME_S ?= $(shell uname -s)
DEBUG ?= 1
CFLAGS+=-DVERSION_MAJOR=$(VERSION_MAJOR)
CFLAGS+=-DVERSION_MINOR=$(VERSION_MINOR)
CFLAGS+=-DVERSION_PATCH=$(VERSION_PATCH)
CFLAGS+=-DVERSION_IS_SEMANTIC_COMPLIANT=$(VERSION_IS_SEMANTIC_COMPLIANT)
ifeq ($(VERSION_IS_SEMANTIC_COMPLIANT),0)
ifeq ($(BOOTLOADER),0)
$(warning "firmware version $(VERSION_FIRMWARE)...")
CFLAGS+=-DAPPVER=0X$(VERSION_FIRMWARE)
endif
endif
ifneq ($(BOOTLOADER),1)
ifeq ($(DEBUG),1)
OPTFLAGS ?= -Og
DBGFLAGS ?= -g3 -ggdb3
else
OPTFLAGS ?= -O3
DBGFLAGS ?= -DDNDEBUG
endif
endif
ifeq ($(EMULATOR),1)
PYTHON ?= python
CC ?= gcc
LD := $(CC)
ifneq ($(UNAME_S),Darwin)
OBJCOPY := objcopy
endif
OBJDUMP := objdump
AR := ar
AS := as
CPUFLAGS ?=
FPUFLAGS ?=
ifeq ($(UNAME_S),Darwin)
CFLAGS += -DCONFIDENTIAL=
else
CFLAGS += -DCONFIDENTIAL='__attribute__((section("confidential")))'
endif
else
PREFIX ?= arm-none-eabi-
CC := $(PREFIX)gcc
LD := $(PREFIX)gcc
OBJCOPY := $(PREFIX)objcopy
OBJDUMP := $(PREFIX)objdump
AR := $(PREFIX)ar
AS := $(PREFIX)as
OPENOCD := openocd -f interface/stlink-v2.cfg -c "transport select hla_swd" -f target/stm32f2x.cfg
ifeq ($(DEBUG),1)
OPTFLAGS ?= -Og
DBGFLAGS ?= -g
else
OPTFLAGS ?= -O3
DBGFLAGS ?= -DNDEBUG
endif
CPUFLAGS ?= -mcpu=cortex-m3 -mthumb
FPUFLAGS ?= -msoft-float
LDFLAGS += --static \
-Wl,--start-group \
-lc \
-lgcc \
-lnosys \
-Wl,--end-group \
-L$(TOOLCHAIN_DIR)/lib \
-T$(LDSCRIPT) \
-nostartfiles \
-Wl,--gc-sections
CFLAGS += -DCONFIDENTIAL='__attribute__((section("confidential")))'
endif
CFLAGS += -DDISABLE_GETENTROPY_CONFIRM=$(DISABLE_GETENTROPY_CONFIRM)
CFLAGS += -DENABLE_GETENTROPY=$(ENABLE_GETENTROPY)
CFLAGS += $(OPTFLAGS) \
$(DBGFLAGS) \
-std=gnu99 \
-W \
-Wall \
-Wextra \
-Wimplicit-function-declaration \
-Wredundant-decls \
-Wstrict-prototypes \
-Wundef \
-Wshadow \
-Wpointer-arith \
-Wformat \
-Wreturn-type \
-Wsign-compare \
-Wmultichar \
-Wformat-nonliteral \
-Winit-self \
-Wuninitialized \
-Wformat-security \
-Werror \
-fno-common \
-fno-exceptions \
-fvisibility=internal \
-ffunction-sections \
-fdata-sections \
-fstack-protector-all \
$(CPUFLAGS) \
$(FPUFLAGS) \
-DSTM32F2 \
-DRAND_PLATFORM_INDEPENDENT=1 \
-I$(TOOLCHAIN_DIR)/include \
-I$(TOP_DIR) \
-I$(TOP_DIR)gen \
-I$(TOP_DIR)vendor/skycoin-crypto \
-I$(TOP_DIR)vendor/skycoin-crypto/tools \
-I$(TOP_DIR)vendor/skycoin-crypto/tools/aes
LDFLAGS += -L$(TOP_DIR) \
$(DBGFLAGS) \
$(CPUFLAGS) \
$(FPUFLAGS)
CFLAGS += -DFASTFLASH=0
ifeq ($(REVERSE_SCREEN),1)
CFLAGS += -DREVERSE_SCREEN=1
else
CFLAGS += -DREVERSE_SCREEN=0
endif
ifeq ($(REVERSE_BUTTONS),1)
CFLAGS += -DREVERSE_BUTTONS=1
else
CFLAGS += -DREVERSE_BUTTONS=0
endif
ifeq ($(EMULATOR),1)
CFLAGS += -DEMULATOR=1
else
CFLAGS += -DEMULATOR=0
endif
ifeq ($(BOOTLOADER),1)
ifeq ($(MEMORY_PROTECT),1)
CFLAGS += -DMEMORY_PROTECT=1
else
CFLAGS += -DMEMORY_PROTECT=0
endif
endif
CFLAGS+=-DVERSION_IS_SEMANTIC_COMPLIANT=$(VERSION_IS_SEMANTIC_COMPLIANT)
ifeq ($(VERSION_IS_SEMANTIC_COMPLIANT),0)
$(warning "firmware version $(VERSION_FIRMWARE)...")
CFLAGS+=-DAPPVER=0X$(VERSION_FIRMWARE)
endif
CFLAGS += -DDEBUG_RNG=0
ifneq ($(BOOTLOADER),1)
lib$(NAME).a: $(OBJS) $(LIBDEPS)
$(AR) rcs lib$(NAME).a $(OBJS) $(LIBDEPS)
endif
ifeq ($(EMULATOR),1)
$(NAME): $(OBJS) $(LDSCRIPT) $(LIBDEPS) firmware/main.o
$(LD) -o $(NAME) firmware/main.o $(OBJS) $(LDLIBS) $(LDFLAGS)
ifneq ($(CHECK_PATH),)
ifeq ($(UNAME_S), Linux)
TESTINC += -isystem $(CHECK_PATH)/src
TESTINC += -isystem $(CHECK_PATH)
endif
ifeq ($(UNAME_S), Darwin)
TESTINC+=-isystem $(CHECK_PATH)/include
endif
CFLAGS += $(TESTINC)
endif
LIBS_DARWIN +=
TESTLIBS_DARWIN += -L$(CHECK_PATH)/lib -lcheck
LIBS_LINUX += -L/usr/local/lib/ -lm -lrt
TESTLIBS_LINUX += -L$(CHECK_PATH)/src -lcheck
ifeq ($(UNAME_S), Linux)
LIBS=$(LIBS_LINUX)
TESTLIBS=$(TESTLIBS_LINUX)
endif
ifeq ($(UNAME_S), Darwin)
LIBS=$(LIBS_DARWIN)
TESTLIBS=$(TESTLIBS_DARWIN)
endif
test_$(NAME): proto lib$(NAME).a $(TEST_OBJS)
$(LD) -o test_$(NAME) $(TEST_OBJS) $(OBJS) $(LDLIBS) $(LDFLAGS) $(TESTLIBS)
test: test_$(NAME) ## Run test suite for tiny-firmware.
./test_$(NAME)
else
$(NAME).bin: $(NAME).elf
$(OBJCOPY) -Obinary $(NAME).elf $(NAME).bin
ifeq ($(BOOTLOADER),1)
$(NAME).elf: $(OBJS) $(LDSCRIPT)
$(LD) -o $(NAME).elf $(OBJS) $(LDLIBS) $(LDFLAGS)
else
$(NAME).elf: lib$(NAME).a firmware/main.o $(LDSCRIPT) $(LIBDEPS)
$(LD) -o $(NAME).elf firmware/main.o -l$(NAME) $(LDLIBS) $(LDFLAGS)
endif
endif
ifeq ($(BOOTLOADER),1)
%.o: %.c Makefile pub_keys.h
$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
else
%.o: %.c Makefile
$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
endif
%.small.o: %.c Makefile
$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
%.d: %.c Makefile
@$(CC) $(CFLAGS) -MM -MP -MG -o $@ $<
%.small.d: %.c Makefile
@$(CC) $(CFLAGS) -MM -MP -MG -o $@ $<
%.o: %.s Makefile
$(AS) $(CPUFLAGS) -o $@ $<
clean::
rm -f $(OBJS)
rm -f *.a
rm -f *.bin
rm -f *.d
rm -f *.elf
rm -f *.hex
rm -f *.list
rm -f *.log
rm -f *.srec