forked from libhal/SJSU-Dev2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
320 lines (272 loc) · 9.95 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
# Allow settiing a project name from the environment, default to firmware.
# Only affects the name of the generated binary.
# TODO: Set this from the directory this makefile is stored in
PROJ ?= firmware
# Affects what DBC is generated for SJSUOne board
ENTITY ?= DBG
# IMPORTANT: Must be accessible via the PATH variable!!!
CC = arm-none-eabi-gcc
CPPC = arm-none-eabi-g++
OBJDUMP = arm-none-eabi-objdump
SIZEC = arm-none-eabi-size
OBJCOPY = arm-none-eabi-objcopy
NM = arm-none-eabi-nm
# Internal build directories
OBJ_DIR = compiled
BIN_DIR = binaries
DBC_DIR = can-dbc
LIB_DIR = $(SJLIBDIR)
define n
endef
ifndef SJDEV
$(error $n$n=============================================$nSJSUOne environment variables not set.$nPLEASE run "source env.sh"$n=============================================$n$n)
endif
# FLAGS
#CORTEX_M4F = -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
CORTEX_M4F = -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb
OPTIMIZE = -O0 -fmessage-length=0 -ffunction-sections -fdata-sections -fno-exceptions \
-fsingle-precision-constant -fno-rtti
DEBUG = -g
WARNINGS = -Wall -Wextra -Wpedantic -Wshadow -Wlogical-op -Wfloat-equal \
-Wdouble-promotion -Wduplicated-cond -Wlogical-op -Wswitch \
-Wnull-dereference -Wold-style-cast -Wuseless-cast -Wformat=2 \
-Wundef -Wconversion -Woverloaded-virtual \
-Wsuggest-attribute=const -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override \
-Wframe-larger-than=1024
#-Walloc-zero -Walloc-size-larger-than=8kB -Walloca-larger-than=1
DISABLED_WARNINGS = -Wno-main
DEFINES = -DARM_MATH_CM4=1 -D__FPU_PRESENT=1U
# end FLAGS
COMMON_FLAGS = $(CORTEX_M4F) $(OPTIMIZE) $(DEBUG) $(WARNINGS) $(DISABLED_WARNINGS) $(DEFINES)
CFLAGS = $(COMMON_FLAGS) \
-fabi-version=0 \
-I"$(LIB_DIR)/" \
-I"$(LIB_DIR)/newlib" \
-I"$(LIB_DIR)/third-party/fat" \
-I"$(LIB_DIR)/third-party/FreeRTOS" \
-I"$(LIB_DIR)/third-party/FreeRTOS/trace" \
-I"$(LIB_DIR)/third-party/FreeRTOS/include" \
-I"$(LIB_DIR)/third-party/FreeRTOS/portable" \
-I"$(LIB_DIR)/third-party/FreeRTOS/portable/no_mpu" \
-I"$(DBC_DIR)" \
-MMD -MP -c
#-nostartfiles
LINKFLAGS = $(COMMON_FLAGS) \
-T $(LIB_DIR)/LPC4078_Breakout_Debug.ld \
-Xlinker \
--gc-sections -Wl,-Map,"$(MAP)" \
-specs=nano.specs
DBC_BUILD = $(DBC_DIR)/generated_can.h
LIBRARIES = $(shell find "$(LIB_DIR)" -name '*.c' -o -name '*.cpp')
SOURCES = $(shell find source \
-name '*.c' -o\
-name '*.s' -o \
-name '*.S' -o \
-name '*.cpp' \
-not -path './test/*' \
2> /dev/null)
COMPILABLES = $(LIBRARIES) $(SOURCES)
# $(patsubst %.cpp,%.o, LIST) : Replace .cpp -> .o
# $(patsubst %.c,%.o, LIST) : Replace .c -> .o
# $(patsubst src/%,%, LIST) : Replace src/path/file.o -> path/file.o
# $(addprefix $(OBJ_DIR)/, LIST) : Add OBJ DIR to path (path/file.o -> obj/path/file.o)
OBJECT_FILES = $(addprefix $(OBJ_DIR)/, \
$(patsubst %.S,%.o, \
$(patsubst %.s,%.o, \
$(patsubst %.c,%.o, \
$(patsubst %.cpp,%.o, \
$(COMPILABLES) \
) \
) \
) \
) \
)
EXECUTABLE = $(BIN_DIR)/$(PROJ).elf
SYMBOL_TABLE = $(BIN_DIR)/symbol-table.c
BINARY = $(EXECUTABLE:.elf=.bin)
HEX = $(EXECUTABLE:.elf=.hex)
SYMBOLS_HEX = $(EXECUTABLE:.elf=.symbols.hex)
LIST = $(EXECUTABLE:.elf=.lst)
SYMBOLS_LIST = $(EXECUTABLE:.elf=.symbols.lst)
SIZE = $(EXECUTABLE:.elf=.siz)
SYMBOLS_SIZE = $(EXECUTABLE:.elf=.symbols.siz)
MAP = $(EXECUTABLE:.elf=.map)
SYMBOLS_MAP = $(EXECUTABLE:.elf=.symbols.map)
SYMBOLS = $(EXECUTABLE:.elf=.sym)
SYMBOLS_EXECUTABLE = $(EXECUTABLE:.elf=.symbols.elf)
SYMBOLS_OBJECT = $(SYMBOLS).o
# Will cause dependency rebuild if header file changes
DEPENDENCIES = $(OBJECT_FILES:.o=.d)
-include $(DEPENDENCIES)
.DELETE_ON_ERROR:
.PHONY: sym-build build cleaninstall telemetry monitor show-obj-list clean sym-flash flash telemetry
default:
@echo "List of available targets:"
@echo " build - builds firmware project"
@echo " sym-build - builds firmware project with embeddeding symbol table"
@echo " flash - builds and installs firmware on to SJOne board"
@echo " sym-flash - builds and installs firmware on to SJOne board without embeddeding symbol table"
@echo " telemetry - will launch telemetry interface"
@echo " clean - cleans project folder"
@echo " cleaninstall - cleans, builds and installs firmware"
@echo " show-obj-list - Shows all object files that will be compiled"
build: $(DBC_DIR) $(OBJ_DIR) $(BIN_DIR) $(SIZE) $(LIST) $(HEX) $(BINARY)
sym-build: $(DBC_DIR) $(OBJ_DIR) $(BIN_DIR) $(SYMBOLS_SIZE) $(SYMBOLS_LIST) $(SYMBOLS_HEX)
cleaninstall: clean build flash
show-obj-list:
@echo $(OBJECT_FILES)
print-% : ; @echo $* = $($*)
$(SYMBOLS_HEX): $(SYMBOLS_EXECUTABLE)
@echo ' '
@echo 'Invoking: Cross ARM GNU Create Symbol Linked Flash Image'
@$(OBJCOPY) -O ihex "$<" "$@"
@echo 'Finished building: $@'
@echo ' '
$(HEX): $(EXECUTABLE)
@echo ' '
@echo 'Invoking: Cross ARM GNU Create Flash Image'
@$(OBJCOPY) -O ihex "$<" "$@"
@echo 'Finished building: $@'
@echo ' '
$(BINARY): $(EXECUTABLE)
@echo ' '
@echo 'Invoking: Cross ARM GNU Create Flash Binary Image'
@$(OBJCOPY) -O binary "$<" "$@"
@echo 'Finished building: $@'
@echo ' '
$(SYMBOLS_SIZE): $(SYMBOLS_EXECUTABLE)
@echo ' '
@echo 'Invoking: Cross ARM GNU Print Size'
@$(SIZEC) --format=berkeley "$<"
@echo 'Finished building: $@'
@echo ' '
$(SIZE): $(EXECUTABLE)
@echo ' '
@echo 'Invoking: Cross ARM GNU Print Size'
@$(SIZEC) --format=berkeley "$<"
@echo 'Finished building: $@'
@echo ' '
$(SYMBOLS_LIST): $(SYMBOLS_EXECUTABLE)
@echo ' '
@echo 'Invoking: Cross ARM GNU Create Assembly Listing'
@$(OBJDUMP) --source --all-headers --demangle --line-numbers --wide "$<" > "$@"
@echo 'Finished building: $@'
@echo ' '
$(LIST): $(EXECUTABLE)
@echo ' '
@echo 'Invoking: Cross ARM GNU Create Assembly Listing'
@$(OBJDUMP) --source --all-headers --demangle --line-numbers --wide "$<" > "$@"
@echo 'Finished building: $@'
@echo ' '
$(SYMBOLS_EXECUTABLE): $(SYMBOLS_OBJECT)
@echo ' '
@echo 'Linking: FINAL Symbol Table Linked EXECUTABLE'
@mkdir -p "$(dir $@)"
@$(CPPC) $(LINKFLAGS) -o "$@" $(SYMBOLS_OBJECT) $(OBJECT_FILES)
@echo 'Finished building target: $@'
@echo ' '
$(SYMBOLS_OBJECT): $(SYMBOL_TABLE)
@echo 'Invoking: Cross ARM GNU Generating Symbol Table Object File'
@$(CC) $(CFLAGS) -std=gnu11 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $@'
@echo ' '
$(SYMBOL_TABLE): $(SYMBOLS)
@echo 'Generating: Symbol Table C file'
# Copying firmware.sym to .c file
@echo '________' > "$@"
@cat "$<" >> "$@"
# Remove everything that is not a function (text/code) symbols
@perl -p -i -e 's;^.* [^T] .*\n;;' "$@"
@perl -p -i -e 's;^.* T __.*\n;;' "$@"
@perl -p -i -e 's;^.* T _.*\n;;' "$@"
@perl -p -i -e 's;^.* T operator .*\n;;' "$@"
@perl -p -i -e 's;^.* T typeinfo for.*\n;;' "$@"
@perl -p -i -e 's;^.* T typeinfo name for .*\n;;' "$@"
@perl -p -i -e 's;^.* T typeinfo name for .*\n;;' "$@"
@perl -p -i -e 's;^.* T vtable for .*\n;;' "$@"
@perl -p -i -e 's;^.* T vtable for .*\n;;' "$@"
# Prepend " to each line
@perl -p -i -e 's;^;\t";' "$@"
# Append " to each line
@perl -p -i -e 's;$$;\\n\";' "$@"
# Append variable declaration
@perl -p -i -e 's;^.*________.*;__attribute__((section(".symbol_table"))) const char APP_SYM_TABLE[] =;' "$@"
# append it with a curly brace and semicolon
@echo ";" >> "$@"
@echo ' '
$(SYMBOLS): $(EXECUTABLE)
@echo 'Generating: Cross ARM GNU NM Generate Symbol Table'
@$(NM) -C "$<" > "$@"
@echo 'Finished building: $@'
@echo ' '
$(EXECUTABLE): $(OBJECT_FILES)
@echo 'Invoking: Cross ARM C++ Linker'
@mkdir -p "$(dir $@)"
@$(CPPC) $(LINKFLAGS) -o "$@" $(OBJECT_FILES)
@echo 'Finished building target: $@'
$(OBJ_DIR)/%.o: %.cpp
@echo 'Building file: $<'
@echo 'Invoking: Cross ARM C++ Compiler'
@mkdir -p "$(dir $@)"
@$(CPPC) $(CFLAGS) -std=gnu++17 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(OBJ_DIR)/%.o: %.c
@echo 'Building file: $<'
@echo 'Invoking: Cross ARM C Compiler'
@mkdir -p "$(dir $@)"
@$(CC) $(CFLAGS) -std=gnu11 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(OBJ_DIR)/%.o: %.s
@echo 'Building Assembly file: $<'
@echo 'Invoking: Cross ARM C Compiler'
@mkdir -p "$(dir $@)"
@$(CC) $(CFLAGS) -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(OBJ_DIR)/%.o: %.S
@echo 'Building Assembly file: $<'
@echo 'Invoking: Cross ARM C Compiler'
@mkdir -p "$(dir $@)"
@$(CC) $(CFLAGS) -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(OBJ_DIR)/%.o: $(LIB_DIR)/%.cpp
@echo 'Building C++ file: $<'
@echo 'Invoking: Cross ARM C++ Compiler'
@mkdir -p "$(dir $@)"
@$(CPPC) $(CFLAGS) -std=gnu++17 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(OBJ_DIR)/%.o: $(LIB_DIR)/%.c
@echo 'Building C file: $<'
@echo 'Invoking: Cross ARM C Compiler'
@mkdir -p "$(dir $@)"
@$(CC) $(CFLAGS) -std=gnu11 -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(DBC_BUILD):
python "$(LIB_DIR)/$(DBC_DIR)/dbc_parse.py" -i "$(LIB_DIR)/$(DBC_DIR)/243.dbc" -s $(ENTITY) > $(DBC_BUILD)
$(DBC_DIR):
mkdir -p $(DBC_DIR)
$(OBJ_DIR):
@echo 'Creating Objects Folder: $<'
mkdir $(OBJ_DIR)
$(BIN_DIR):
@echo 'Creating Binary Folder: $<'
mkdir $(BIN_DIR)
clean:
rm -fR $(OBJ_DIR) $(BIN_DIR) $(DBC_DIR)
sym-flash: sym-build
@bash -c "\
source $(SJBASE)/tools/Hyperload/modules/bin/activate && \
python $(SJBASE)/tools/Hyperload/hyperload.py $(SJDEV) $(HEX)"
flash: build
@bash -c "\
source $(SJBASE)/tools/Hyperload/modules/bin/activate && \
python $(SJBASE)/tools/Hyperload/hyperload.py $(SJDEV) $(SYMBOLS_HEX)"
telemetry:
@bash -c "\
source $(SJBASE)/tools/Telemetry/modules/bin/activate && \
python $(SJBASE)/tools/Telemetry/telemetry.py"