-
Notifications
You must be signed in to change notification settings - Fork 311
/
Makefile
183 lines (146 loc) · 5.06 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
BOARD=zero
-include Makefile.user
include boards/$(BOARD)/board.mk
CC=arm-none-eabi-gcc
ifeq ($(CHIP_FAMILY), samd21)
COMMON_FLAGS = -mthumb -mcpu=cortex-m0plus -Os -g
endif
ifeq ($(CHIP_FAMILY), samd51)
COMMON_FLAGS = -mthumb -mcpu=cortex-m4 -O2 -g
endif
WFLAGS = \
-Wall -Wstrict-prototypes \
-Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 \
-ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 \
-Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch \
-Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wno-undef \
-Wbad-function-cast -Wwrite-strings -Waggregate-return \
-Wformat -Wmissing-format-attribute \
-Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs \
-Wlong-long -Wunreachable-code -Wcast-align \
-Wno-missing-braces -Wno-overflow -Wno-shadow -Wno-attributes -Wno-packed -Wno-pointer-sign
CFLAGS = $(COMMON_FLAGS) \
-x c -c -pipe -nostdlib \
--param max-inline-insns-single=500 \
-fno-strict-aliasing -fdata-sections -ffunction-sections -mlong-calls \
-D__$(CHIP_VARIANT)__ \
$(WFLAGS)
ifeq ($(CHIP_FAMILY), samd21)
LINKER_SCRIPT=./lib/samd21/samd21a/gcc/gcc/samd21j18a_flash.ld
endif
ifeq ($(CHIP_FAMILY), samd51)
LINKER_SCRIPT=./lib/samd51/gcc/gcc/samd51j18a_flash.ld
endif
LDFLAGS= $(COMMON_FLAGS) \
-Wall -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common \
-Wl,--warn-section-align -Wl,--warn-unresolved-symbols \
-save-temps \
--specs=nano.specs --specs=nosys.specs
BUILD_PATH=build/$(BOARD)
INCLUDES = -I. -I./inc -I./inc/preprocessor
INCLUDES += -I./boards/$(BOARD) -Ilib/cmsis/CMSIS/Include -Ilib/usb_msc
ifeq ($(CHIP_FAMILY), samd21)
INCLUDES += -Ilib/samd21/samd21a/include/
endif
ifeq ($(CHIP_FAMILY), samd51)
INCLUDES += -I
endif
COMMON_SRC = \
src/flash.c \
src/init.c \
src/startup_$(CHIP_FAMILY).c \
src/usart_sam_ba.c \
src/utils.c
SOURCES = $(COMMON_SRC) \
src/cdc_enumerate.c \
src/fat.c \
src/main.c \
src/msc.c \
src/sam_ba_monitor.c \
src/uart_driver.c \
src/hid.c \
SELF_SOURCES = $(COMMON_SRC) \
src/selfmain.c
OBJECTS = $(patsubst src/%.c,$(BUILD_PATH)/%.o,$(SOURCES))
SELF_OBJECTS = $(patsubst src/%.c,$(BUILD_PATH)/%.o,$(SELF_SOURCES)) $(BUILD_PATH)/selfdata.o
NAME=bootloader
EXECUTABLE=$(BUILD_PATH)/$(NAME).bin
SELF_EXECUTABLE=$(BUILD_PATH)/update-$(NAME).uf2
all: dirs $(EXECUTABLE) $(SELF_EXECUTABLE)
r: run
b: burn
l: logs
burn: all
node scripts/dbgtool.js fuses
node scripts/dbgtool.js $(BUILD_PATH)/$(NAME).bin
run: burn wait logs
wait:
sleep 5
logs:
node scripts/dbgtool.js $(BUILD_PATH)/$(NAME).map
selflogs:
node scripts/dbgtool.js $(BUILD_PATH)/update-$(NAME).map
dirs:
@echo "Building $(BOARD)"
-@mkdir -p $(BUILD_PATH)
$(EXECUTABLE): $(OBJECTS)
$(CC) -L$(BUILD_PATH) $(LDFLAGS) \
-T$(LINKER_SCRIPT) \
-Wl,-Map,$(BUILD_PATH)/$(NAME).map -o $(BUILD_PATH)/$(NAME).elf $(OBJECTS)
arm-none-eabi-objcopy -O binary $(BUILD_PATH)/$(NAME).elf $@
@echo
-@arm-none-eabi-size $(BUILD_PATH)/$(NAME).elf | awk '{ s=$$1+$$2; print } END { print ""; print "Space left: " (8192-s) }'
@echo
$(SELF_EXECUTABLE): $(SELF_OBJECTS)
$(CC) -L$(BUILD_PATH) $(LDFLAGS) \
-T./scripts/samd21j18a_self.ld \
-Wl,-Map,$(BUILD_PATH)/update-$(NAME).map -o $(BUILD_PATH)/update-$(NAME).elf $(SELF_OBJECTS)
arm-none-eabi-objcopy -O binary $(BUILD_PATH)/update-$(NAME).elf $(BUILD_PATH)/update-$(NAME).bin
node scripts/bin2uf2.js $(BUILD_PATH)/update-$(NAME).bin $@
$(BUILD_PATH)/%.o: src/%.c $(wildcard inc/*.h boards/*/*.h)
echo "$<"
$(CC) $(CFLAGS) $(BLD_EXTA_FLAGS) $(INCLUDES) $< -o $@
$(BUILD_PATH)/%.o: $(BUILD_PATH)/%.c
$(CC) $(CFLAGS) $(BLD_EXTA_FLAGS) $(INCLUDES) $< -o $@
$(BUILD_PATH)/selfdata.c: $(EXECUTABLE) scripts/gendata.js src/sketch.cpp
node scripts/gendata.js $(BUILD_PATH) $(NAME).bin
clean:
rm -rf build
gdb:
arm-none-eabi-gdb $(BUILD_PATH)/$(NAME).elf
tui:
arm-none-eabi-gdb -tui $(BUILD_PATH)/$(NAME).elf
%.asmdump: %.o
arm-none-eabi-objdump -d $< > $@
applet0: $(BUILD_PATH)/flash.asmdump
node scripts/genapplet.js $< flash_write
applet1: $(BUILD_PATH)/utils.asmdump
node scripts/genapplet.js $< resetIntoApp
drop-board: all
@echo "*** Copy files for $(BOARD)"
mkdir -p build/drop
rm -rf build/drop/$(BOARD)
mkdir -p build/drop/$(BOARD)
cp $(SELF_EXECUTABLE) build/drop/$(BOARD)/
cp $(EXECUTABLE) build/drop/$(BOARD)/
cp $(BUILD_PATH)/update-bootloader.ino build/drop/$(BOARD)/
cp boards/$(BOARD)/board_config.h build/drop/$(BOARD)/
drop-pkg:
mv build/drop build/uf2-samd21-$(VERSION)
cp bin-README.md build/uf2-samd21-$(VERSION)/README.md
cd build; 7z a uf2-samd21-$(VERSION).zip uf2-samd21-$(VERSION)
rm -rf build/uf2-samd21-$(VERSION)
tag:
$(MAKE) VERSION=`awk '/define UF2_VERSION_BASE/ { gsub(/"v?/, ""); print $$3 }' inc/uf2.h` do-tag
do-tag:
git add inc/uf2.h
git diff --exit-code
git commit -m "v$(VERSION)"
git tag "v$(VERSION)"
git push
git push --tag
$(MAKE) drop
all-boards:
for f in `cd boards; ls` ; do $(MAKE) BOARD=$$f drop-board ; done
drop: all-boards
$(MAKE) VERSION=`awk '/define UF2_VERSION_BASE/ { gsub(/"v?/, ""); print $$3 }' inc/uf2.h` drop-pkg