-
Notifications
You must be signed in to change notification settings - Fork 62
/
Makefile
156 lines (119 loc) · 3.19 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
#
# Common Makefile for the PX4 bootloaders
#
-include Makefile.user
#
# Paths to common dependencies
#
export BL_BASE ?= $(wildcard .)
export LIBOPENCM3 ?= $(wildcard libopencm3)
#
# Tools
#
export CC = arm-none-eabi-gcc
export OBJCOPY = arm-none-eabi-objcopy
export OPENOCD ?= openocd
JTAGCONFIG ?= interface/stlink-v2.cfg
export BOARD ?= f401
-include boards/$(BOARD)/board.mk
# Default to F401; override in board.mk if needed
FN ?= f4
CPUTYPE ?= STM32F401
CPUTYPE_SHORT ?= STM32F4
CPUFLAGS ?= -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
# f1: -mcpu=cortex-m3
# f3: as f4
# f7: -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16
LINKER_FILE ?= linker/stm32$(FN).ld
ifeq ($(origin EXTRAFLAGS), undefined)
EXTRAFLAGS ?= -D$(CPUTYPE)
else
EXTRAFLAGS += -D$(CPUTYPE)
endif
#
# Common configuration
#
export FLAGS = -std=gnu99 \
-Os \
-g \
-Wundef \
-Wall \
-fno-builtin \
-I$(LIBOPENCM3)/include \
-Iboards/$(BOARD) \
-ffunction-sections \
-nostartfiles \
-lnosys \
-Wl,-gc-sections \
-Wl,-g \
-Wno-unused \
-Werror
export COMMON_SRCS = bl.c usb.c usb_msc.c ghostfat.c dmesg.c screen.c images.c settings.c hf2.c support.c webusb.c winusb.c util.c flashwarning.c
SRCS = $(COMMON_SRCS) main_$(FN).c
OBJS := $(patsubst %.c,%.o,$(SRCS))
DEPS := $(OBJS:.o=.d)
FLAGS += -mthumb $(CPUFLAGS) \
-D$(CPUTYPE_SHORT) \
-T$(LINKER_FILE) \
-L$(LIBOPENCM3)/lib \
-lopencm3_stm32$(FN) \
$(EXTRAFLAGS)
OPENOCDALL = $(OPENOCD) -f $(JTAGCONFIG) -f target/stm32$(FN)x.cfg
#
# Bootloaders to build
#
all: build-bl sizes
clean:
cd libopencm3 && make --no-print-directory clean && cd ..
rm -f *.elf *.bin # Remove any elf or bin files contained directly in the Bootloader directory
rm -rf build # Remove build directories
# any file generated during libopencm3 build
OCM3FILE = libopencm3/include/libopencm3/stm32/f4/nvic.h
build-bl: $(MAKEFILE_LIST) $(OCM3FILE) do-build
#
# General rules for making dependency and object files
# This is where the compiler is called
#
include rules.mk
flash: upload
burn: upload
b: burn
f: flash
upload: build-bl flash-bootloader
BMP = $(shell ls -1 /dev/cu.usbmodem*1 | head -1)
BMP_ARGS = -ex "target extended-remote $(BMP)" -ex "mon tpwr enable" -ex "mon swdp_scan" -ex "attach 1"
GDB = arm-none-eabi-gdb
flash-ocd: all
$(OPENOCDALL) -c "program build/$(BOARD)/bootloader.elf verify reset exit "
flash-bootloader:
$(GDB) $(BMP_ARGS) -ex "load" -ex "quit" build/$(BOARD)/bootloader.elf
gdb:
$(GDB) $(BMP_ARGS) build/$(BOARD)/bootloader.elf
#
# Show sizes
#
.PHONY: sizes
sizes:
@-find build/*/ -name '*.elf' -type f | xargs size 2> /dev/null || :
drop:
for f in `cd boards; ls` ; do $(MAKE) BOARD=$$f ; done
cd build; 7z a uf2-stm32f.zip */bootloader.elf */bootloader.bin */flasher.uf2
#
# Binary management
#
.PHONY: deploy
deploy:
zip -j Bootloader.zip build/*/*.bin
#
# Submodule management
#
$(OCM3FILE):
${MAKE} checksubmodules
${MAKE} -C $(LIBOPENCM3) -j10 lib
.PHONY: checksubmodules
checksubmodules: updatesubmodules
$(Q) ($(BL_BASE)/Tools/check_submodules.sh)
.PHONY: updatesubmodules
updatesubmodules:
$(Q) (git submodule init)
$(Q) (git submodule update)