-
Notifications
You must be signed in to change notification settings - Fork 67
/
Makefile
433 lines (350 loc) · 16.1 KB
/
Makefile
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
OUTDIR ?= build
FWNAME ?= firmware
SWNAME ?= fwcrypt
FWTOOLS ?= arm-none-eabi-
CMSIS ?= $(abspath ../CMSIS)
CMSISDEV ?= $(CMSIS)/Device
ifeq ($(OS),Windows_NT)
RM = del /Q
FixPath = $(subst /,\, $1)
SWTOOLS ?= mingw32-
SWFLAGS ?=
else
RM = rm -f
FixPath = $1
SWTOOLS ?=
SWFLAGS ?=
endif
#default CPU target
FWCPU ?= -mcpu=cortex-m0plus -mfloat-abi=soft
FWDEFS ?= STM32L0 STM32L052xx
FWSTARTUP ?= mcu/stm32l0xx.S
FWSCRIPT ?= mcu/stm32l0xxx8.ld
#sources
CRYPT_SRC = src/arc4.c src/chacha.c src/gost.c src/raiden.c src/rc5.c src/speck.c src/xtea.c
FW_SRC = $(CRYPT_SRC) $(FWSTARTUP) src/descriptors.c src/bootloader.c src/rc5a.S src/chacha_a.S
SW_SRC = $(CRYPT_SRC) src/encrypter.c
#folders
FWODIR = $(OUTDIR)/objfw
SWODIR = $(OUTDIR)/objsw
SRCPATH = $(sort $(dir $(FW_SRC)))
vpath %.c $(SRCPATH)
vpath %.S $(SRCPATH)
#includes
CMSISINC = $(CMSISDEV)/ST $(CMSIS)/CMSIS/Include $(CMSIS)/CMSIS/Core/Include
FWINCS = $(CMSISINC) inc $(addsuffix /inc, $(MODULES)) .
SWINCS = inc .
#objects
FWOBJ = $(addprefix $(FWODIR)/, $(addsuffix .o, $(notdir $(basename $(FW_SRC)))))
SWOBJ = $(addprefix $(SWODIR)/, $(addsuffix .o, $(notdir $(basename $(SW_SRC)))))
#modules
MODULES = usb
MLIBS = $(addprefix $(FWODIR)/lib, $(addsuffix .a, $(MODULES)))
MDEFS = USBD_SOF_DISABLED
#compiler flags
FWCFLAGS = -mthumb -Os -Wall -std=gnu99
FWXFLAGS = -flto
#linker flags
FWLDFLAGS = -specs=nano.specs -nostartfiles -Wl,--gc-sections -Wl,-Map=$(OUTDIR)/$(FWNAME).map
SWLDFLAGS = -libstd
all: bootloader crypter
program: $(OUTDIR)/$(FWNAME).hex
st-flash --reset --format ihex write $(OUTDIR)/$(FWNAME).hex
crypter: $(SWOBJ)
@echo creating crypter
@$(SWTOOLS)gcc $(SWCFLAGS) $(SWOBJ) -o $(OUTDIR)/$(SWNAME)
bootloader: $(OUTDIR)/$(FWNAME).hex $(OUTDIR)/$(FWNAME).bin
$(OUTDIR)/$(FWNAME).hex: $(OUTDIR)/$(FWNAME).elf
@echo creating $@
@$(FWTOOLS)objcopy -O ihex $< $@
$(OUTDIR)/$(FWNAME).bin: $(OUTDIR)/$(FWNAME).elf
@echo creating $@
@$(FWTOOLS)objcopy -O binary $< $@
.SECONDARY $(OUTDIR)/$(FWNAME).elf: $(FWOBJ) $(MLIBS)
@echo building bootloader
@$(FWTOOLS)gcc $(FWCPU) $(FWCFLAGS) $(FWLDFLAGS) -Wl,--script=$(FWSCRIPT) $(FWOBJ) $(addprefix -l, $(MODULES)) -L$(FWODIR) -o $@
$(FWODIR)/lib%.a: %
@echo building module $<
@$(MAKE) module -C $< MODULE=$(abspath $@) DEFINES='$(FWDEFS) $(MDEFS)' CFLAGS='$(FWXFLAGS) $(FWCPU)' CMSIS='$(CMSIS)'
$(SWOBJ): | $(SWODIR)
$(FWOBJ): | $(FWODIR)
$(OUTDIR):
@mkdir $@
$(FWODIR) $(SWODIR): | $(OUTDIR)
@cd $(OUTDIR) && mkdir $(lastword $(subst /, ,$@)) && cd ..
$(SWODIR)/%.o: %.c
@echo compiling $<
@$(SWTOOLS)gcc $(SWCFLAGS) $(addprefix -D,$(SWDEFS)) $(addprefix -I,$(SWINCS)) -c $< -o $@
$(FWODIR)/%.o: %.c
@echo compiling $<
@$(FWTOOLS)gcc $(FWCPU) $(FWCFLAGS) $(FWXFLAGS) $(addprefix -D,$(FWDEFS)) $(addprefix -I,$(FWINCS)) -c $< -o $@
$(FWODIR)/%.o: %.S
@echo assembling $<
@$(FWTOOLS)gcc $(FWCFLAGS) $(addprefix -D,$(FWDEFS)) $(addprefix -I,$(FWINCS)) -c $< -o $@
fwclean: | $(FWODIR)
@$(RM) $(call FixPath, $(FWODIR)/*.*)
@$(RM) $(call FixPath, $(OUTDIR)/$(FWNAME)*)
swclean: | $(SWODIR)
@$(RM) $(call FixPath, $(SWODIR)/*.*)
@$(RM) $(call FixPath, $(OUTDIR)/$(SWNAME)*)
clean: swclean fwclean
FWTARGETS = stm32l100x6a stm32l100x8a stm32l100xba stm32l100xc
FWTARGETS += stm32l151x6a stm32l151x8a stm32l151xba stm32l151xc stm32l151xd stm32l151xe
FWTARGETS += stm32l152x6a stm32l152x8a stm32l152xba stm32l152xc stm32l152xd stm32l152xe
FWTARGETS += stm32l152xc stm32l162xc stm32l162xd stm32l162xe
FWTARGETS += stm32l052x6 stm32l052x8 stm32l053x6 stm32l053x8
FWTARGETS += stm32l062x8 stm32l063x8
FWTARGETS += stm32l072v8 stm32l072xb stm32l072xc
FWTARGETS += stm32l073v8 stm32l073xb stm32l073xc
FWTARGETS += stm32l476xc stm32l476xe stm32l476xg
FWTARGETS += stm32f103x4 stm32f103x6 stm32f103x8 stm32f103xb
FWTARGETS += stm32f303xb stm32f303xc stm32f303xd stm32f303xe
FWTARGETS += stm32f429xe stm32f429xg stm32f429xi
FWTARGETS += stm32f105xb stm32f107xb
FWTARGETS += stm32l433xb stm32l433xc
stm32l100x6a :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L100xBA USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32l100x6a.ld'
stm32l100x8a :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L100xBA USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32l100x8a.ld'
stm32l100xba :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L100xBA USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32l100xba.ld'
stm32l100xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L100xC USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32l100xc.ld'
stm32l151x6a :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L151xBA' \
FWSCRIPT='mcu/stm32l1xxx6a.ld'
stm32l151x8a :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L151xBA' \
FWSCRIPT='mcu/stm32l1xxx8a.ld'
stm32l151xba :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L151xBA' \
FWSCRIPT='mcu/stm32l1xxxba.ld'
stm32l151xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L151xC' \
FWSCRIPT='mcu/stm32l1xxxc.ld'
stm32l151xd :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L151xD' \
FWSCRIPT='mcu/stm32l1xxxd.ld'
stm32l151xe :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L151xE' \
FWSCRIPT='mcu/stm32l1xxxe.ld'
stm32l152x6a :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L152xBA' \
FWSCRIPT='mcu/stm32l1xxx6a.ld'
stm32l152x8a :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L152xBA' \
FWSCRIPT='mcu/stm32l1xxx8a.ld'
stm32l152xba :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L152xBA' \
FWSCRIPT='mcu/stm32l1xxxba.ld'
stm32l152xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L152xC' \
FWSCRIPT='mcu/stm32l1xxxc.ld'
stm32l152xd :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L152xD' \
FWSCRIPT='mcu/stm32l1xxxd.ld'
stm32l152xe :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L152xE' \
FWSCRIPT='mcu/stm32l1xxxe.ld'
stm32l162xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L162xC' \
FWSCRIPT='mcu/stm32l1xxxc.ld'
stm32l162xd :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L162xD' \
FWSCRIPT='mcu/stm32l1xxxd.ld'
stm32l162xe :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32l1xx.S' \
FWDEFS='STM32L1 STM32L162xE' \
FWSCRIPT='mcu/stm32l1xxxe.ld'
stm32l052x6 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L052xx USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32l0xxx6.ld'
stm32l052x8 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L052xx USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32l0xxx8.ld'
stm32l053x6 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L053xx' \
FWSCRIPT='mcu/stm32l0xxx6.ld'
stm32l053x8 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L053xx' \
FWSCRIPT='mcu/stm32l0xxx8.ld'
stm32l062x8 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L062xx' \
FWSCRIPT='mcu/stm32l0xxx8.ld'
stm32l063x8 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L063xx' \
FWSCRIPT='mcu/stm32l0xxx8.ld'
stm32l072v8 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L072xx' \
FWSCRIPT='mcu/stm32l0xxv8.ld'
stm32l072xb :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L072xx' \
FWSCRIPT='mcu/stm32l0xxxb.ld'
stm32l072xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L072xx' \
FWSCRIPT='mcu/stm32l0xxxc.ld'
stm32l073v8 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L073xx' \
FWSCRIPT='mcu/stm32l0xxv8.ld'
stm32l073xb :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L073xx' \
FWSCRIPT='mcu/stm32l0xxxb.ld'
stm32l073xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m0plus' \
FWSTARTUP='mcu/stm32l0xx.S' \
FWDEFS='STM32L0 STM32L073xx' \
FWSCRIPT='mcu/stm32l0xxxc.ld'
stm32l476xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m4' \
FWSTARTUP='mcu/stm32l4xx.S' \
FWDEFS='STM32L4 STM32L476xx' \
FWSCRIPT='mcu/stm32l4xxxc.ld'
stm32l476xe :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m4' \
FWSTARTUP='mcu/stm32l4xx.S' \
FWDEFS='STM32L4 STM32L476xx' \
FWSCRIPT='mcu/stm32l4xxxe.ld'
stm32l476xg :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m4' \
FWSTARTUP='mcu/stm32l4xx.S' \
FWDEFS='STM32L4 STM32L476xx' \
FWSCRIPT='mcu/stm32l4xxxg.ld'
stm32f103x4 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f103.S' \
FWDEFS='STM32F1 STM32F103x6 USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32f1xxx4.ld'
stm32f103x6 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f103.S' \
FWDEFS='STM32F1 STM32F103x6 USBD_ASM_DRIVER'\
FWSCRIPT='mcu/stm32f1xxx6.ld'
stm32f103x8 :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f103.S' \
FWDEFS='STM32F1 STM32F103x6 USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32f1xxx8.ld'
stm32f103xb :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f103.S' \
FWDEFS='STM32F1 STM32F103x6 USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32f1xxxb.ld'
stm32f303xb :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f303.S' \
FWDEFS='STM32F3 STM32F303xB USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32f3xxxb.ld'
stm32f303xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f303.S' \
FWDEFS='STM32F3 STM32F303xB USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32f3xxxc.ld'
stm32f303xd :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f303.S' \
FWDEFS='STM32F3 STM32F303xE USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32f3xxxd.ld'
stm32f303xe :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f303.S' \
FWDEFS='STM32F3 STM32F303xE USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32f3xxxe.ld'
stm32f429xe :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m4' \
FWSTARTUP='mcu/stm32f4xx.S' \
FWDEFS='STM32F4 STM32F429xx' \
FWSCRIPT='mcu/stm32f4xxxg.ld'
stm32f429xg :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m4' \
FWSTARTUP='mcu/stm32f4xx.S' \
FWDEFS='STM32F4 STM32F429xx' \
FWSCRIPT='mcu/stm32f4xxxg.ld'
stm32f429xi :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m4' \
FWSTARTUP='mcu/stm32f4xx.S' \
FWDEFS='STM32F4 STM32F429xx' \
FWSCRIPT='mcu/stm32f4xxxi.ld'
stm32f105xb :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f105.S' \
FWDEFS='STM32F1 STM32F105xC USBD_VBUS_DETECT' \
FWSCRIPT='mcu/stm32f1xxxb.ld'
stm32f107xb :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m3' \
FWSTARTUP='mcu/stm32f105.S' \
FWDEFS='STM32F1 STM32F107xC HSE_25MHZ USBD_VBUS_DETECT' \
FWSCRIPT='mcu/stm32f1xxxb.ld'
stm32l433xb :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m4' \
FWSTARTUP='mcu/stm32l4xx.S' \
FWDEFS='STM32L4 STM32L433xx USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32l433xb.ld'
stm32l433xc :
$(MAKE) fwclean bootloader FWCPU='-mcpu=cortex-m4' \
FWSTARTUP='mcu/stm32l4xx.S' \
FWDEFS='STM32L4 STM32L433xx USBD_ASM_DRIVER' \
FWSCRIPT='mcu/stm32l433xc.ld'
.PHONY: clean bootloader crypter all program rebuild fwclean $(FWTARGETS)