forked from vedderb/bldc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
256 lines (208 loc) · 7.87 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
# Makefile for Rootloader project
.DEFAULT_GOAL := help
WHEREAMI := $(dir $(lastword $(MAKEFILE_LIST)))
ROOT_DIR := $(realpath $(WHEREAMI)/ )
TARGET_PATHS := $(wildcard $(ROOT_DIR)/hwconf/hw_*.h)
# Strip the paths down to just the names. Do this by first removing the prefix (PATH/hw_), and then the suffic (.h)
ALL_BOARD_NAMES := $(subst .h,,$(subst $(ROOT_DIR)/hwconf/hw_,,$(TARGET_PATHS)))
# configure some directories that are relative to wherever ROOT_DIR is located
TOOLS_DIR := $(ROOT_DIR)/tools
MAKE_DIR := $(ROOT_DIR)/make
BUILD_DIR := $(ROOT_DIR)/build
DL_DIR := $(ROOT_DIR)/downloads
# import macros common to all supported build systems
include $(ROOT_DIR)/make/system-id.mk
# import macros that are OS specific
include $(ROOT_DIR)/make/$(OSFAMILY).mk
# include the tools makefile
include $(ROOT_DIR)/make/tools.mk
# Clean out undesirable variables from the environment and command-line
# to remove the chance that they will cause problems with our build
define SANITIZE_VAR
$(if $(filter-out undefined,$(origin $(1))),
$(info *NOTE* Sanitized $(2) variable '$(1)' from $(origin $(1)))
MAKEOVERRIDES = $(filter-out $(1)=%,$(MAKEOVERRIDES))
override $(1) :=
unexport $(1)
)
endef
# These specific variables can influence gcc in unexpected (and undesirable) ways
SANITIZE_GCC_VARS := TMPDIR GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH
SANITIZE_GCC_VARS += CFLAGS CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH DEPENDENCIES_OUTPUT
SANITIZE_GCC_VARS += ARCHFLAGS
$(foreach var, $(SANITIZE_GCC_VARS), $(eval $(call SANITIZE_VAR,$(var),disallowed)))
# These specific variables used to be valid but now they make no sense
SANITIZE_DEPRECATED_VARS := FOO_BAR
$(foreach var, $(SANITIZE_DEPRECATED_VARS), $(eval $(call SANITIZE_VAR,$(var),deprecated)))
# Decide on a verbosity level based on the V= parameter
export AT := @
ifndef V
export V0 :=
export V1 := $(AT)
else ifeq ($(V), 0)
export V0 := $(AT)
export V1 := $(AT)
else ifeq ($(V), 1)
endif
# Get the git commit hash
GIT_HASH := $(shell git rev-parse --short HEAD)
GIT_DIRTY_LABEL := $(shell git diff --quiet || echo -dirty)
##############################
#
# Help instructions
#
##############################
.PHONY: help
help:
@echo
@echo " This Makefile is known to work on Linux and Mac in a standard shell environment."
@echo
@echo " Here is a summary of the available targets:"
@echo
@echo " [Tool Installers]"
@echo " arm_sdk_install - Install the GNU ARM gcc toolchain"
@echo " qt_install - Install the all tools for Qt"
@echo
@echo " [Big Hammer]"
@echo " all_fw - Build firmware for all boards"
@echo
@echo " [Unit Tests]"
@echo " all_ut - Build all unit tests"
@echo " all_ut_xml - Run all unit tests and capture all XML output to files"
@echo " all_ut_run - Run all unit tests and dump XML output to console"
@echo
@echo " [Firmware]"
@echo " fw - Build firmware for default target"
@echo " supported boards are: $(ALL_BOARD_NAMES)"
@echo " fw_<board> - Build firmware for target <board>"
@echo " PROJECT=<target> fw - Build firmware for <target>"
@echo " fw_<board>_clean - Remove firmware for <board>"
@echo " fw_<board>_flash - Use OpenOCD + SWD/JTAG to write firmware to <target>"
@echo
@echo " Hint: Add V=1 to your command line to see verbose build output."
@echo
@echo " Note: All tools will be installed into $(TOOLS_DIR)"
@echo " All build output will be placed in $(BUILD_DIR)"
@echo
$(DL_DIR):
$(V1) $(MKDIR) $@
$(TOOLS_DIR):
$(V1) $(MKDIR) $@
##############################
#
# Build and Upload
#
##############################
# $(1) = Canonical board name all in lower case (e.g. 100_250)
# $(2) = firmware build directory
# $(3) = firmware name
define FW_TEMPLATE
.PHONY: $(1) fw_$(1)
$(1): fw_$(1)_vescfw
fw_$(1): fw_$(1)_vescfw
fw_$(1)_vescfw:
@echo "********* BUILD: $(1) **********"
$(V1) $(MKDIR) $(BUILD_DIR)/$(1)
$(V1) make -f $(MAKE_DIR)/fw.mk \
TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \
BUILDDIR="$(2)" \
PROJECT="$(3)" \
build_args='-DHW_SOURCE=\"hw_$(1).c\" -DHW_HEADER=\"hw_$(1).h\"' USE_VERBOSE_COMPILE=no
$(1)_flash: fw_$(1)_flash
fw_$(1)_flash: fw_$(1)_vescfw fw_$(1)_flash_only
$(1)_flash_only: fw_$(1)_flash_only
fw_$(1)_flash_only:
@echo "********* PROGRAM: $(1) **********"
$(V1) openocd -f board/stm32f4discovery.cfg -c "reset_config trst_only combined" -c "program $(2)/$(3).elf verify reset exit"
.PHONY: $(1)_clean
$(1)_clean: fw_$(1)_clean
fw_$(1)_clean: TARGET=fw_$(1)
fw_$(1)_clean: OUTDIR=$(BUILD_DIR)/$$(TARGET)
fw_$(1)_clean:
$(V0) @echo " CLEAN $$@"
ifneq ($(OSFAMILY), windows)
$(V1) [ ! -d "$(BUILD_DIR)/$(1)" ] || $(RM) -r "$(BUILD_DIR)/$(1)"
else
$(V1) pwsh -noprofile -command if (Test-Path $(BUILD_DIR)/$(1)) {Remove-Item -Recurse $(BUILD_DIR)/$(1)}
endif
endef
clear_option_bytes:
$(V1) openocd -f board/stm32f4discovery.cfg -c "init" -c "stm32f2x unlock 0" -c "mww 0x40023C08 0x08192A3B; mww 0x40023C08 0x4C5D6E7F; mww 0x40023C14 0x0fffaaed" -c "exit"
#program with olimex arm-usb-tiny-h and jtag-swd adapter board. needs openocd>=0.9
upload-olimex: fw
$(V1) openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f interface/ftdi/olimex-arm-jtag-swd.cfg -c "set WORKAREASIZE 0x2000" -f target/stm32f4x.cfg -c "program build/$(PROJECT).elf verify reset"
upload-pi: fw
$(V1) openocd -f pi_stm32.cfg -c "reset_config trst_only combined" -c "program build/$(PROJECT).elf verify reset exit"
upload-pi-remote: fw
$(V1) ./upload_remote_pi build/$(PROJECT).elf ted 10.42.0.199 22
debug-start:
$(V1) openocd -f stm32-bv_openocd.cfg
size: build/$(PROJECT).elf
@$(SZ) $<
# Generate the targets for whatever boards are in each list
FW_TARGETS := $(addprefix fw_, $(ALL_BOARD_NAMES))
.PHONY: all_fw all_fw_clean
all_fw: $(addsuffix _vescfw, $(FW_TARGETS))
all_fw_clean: $(addsuffix _clean, $(FW_TARGETS))
# Expand the firmware rules
$(foreach board, $(ALL_BOARD_NAMES), $(eval $(call FW_TEMPLATE,$(board),$(BUILD_DIR)/$(board),$(board)-$(GIT_HASH)$(GIT_DIRTY_LABEL))))
##############################
#
# Unit Tests
#
##############################
ALL_UNITTESTS := utils
UT_OUT_DIR := $(BUILD_DIR)/unit_tests
$(UT_OUT_DIR):
$(V1) mkdir -p $@
.PHONY: all_ut
all_ut: $(addsuffix _elf, $(addprefix ut_, $(ALL_UNITTESTS))) $(ALL_PYTHON_UNITTESTS)
.PHONY: all_ut_xml
all_ut_xml: $(addsuffix _xml, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_run
all_ut_run: $(addsuffix _run, $(addprefix ut_, $(ALL_UNITTESTS))) $(ALL_PYTHON_UNITTESTS)
.PHONY: all_ut_gcov
all_ut_gcov: | $(addsuffix _gcov, $(addprefix ut_, $(ALL_UNITTESTS)))
.PHONY: all_ut_clean
all_ut_clean:
$(V0) @echo " CLEAN $@"
$(V1) [ ! -d "$(UT_OUT_DIR)" ] || $(RM) -r "$(UT_OUT_DIR)"
# $(1) = Unit test name
define UT_TEMPLATE
.PHONY: ut_$(1)
ut_$(1): ut_$(1)_run
ut_$(1)_gcov: | ut_$(1)_xml
ut_$(1)_%: TARGET=$(1)
ut_$(1)_%: OUTDIR=$(UT_OUT_DIR)/$$(TARGET)
ut_$(1)_%: UT_ROOT_DIR=$(ROOT_DIR)/tests/$(1)
ut_$(1)_%: $$(UT_OUT_DIR)
$(V1) mkdir -p $(UT_OUT_DIR)/$(1)
$(V1) cd $$(UT_ROOT_DIR) && \
$$(MAKE) -r --no-print-directory \
BUILD_TYPE=ut \
TCHAIN_PREFIX="" \
REMOVE_CMD="$(RM)" \
\
MAKE_INC_DIR=$(MAKE_INC_DIR) \
ROOT_DIR=$(ROOT_DIR) \
TARGET=$$(TARGET) \
OUTDIR=$$(OUTDIR) \
\
GTEST_DIR=$(GTEST_DIR) \
\
$$*
.PHONY: ut_$(1)_clean
ut_$(1)_clean: TARGET=$(1)
ut_$(1)_clean: OUTDIR=$(UT_OUT_DIR)/$$(TARGET)
ut_$(1)_clean:
$(V0) @echo " CLEAN $(1)"
$(V1) [ ! -d "$$(OUTDIR)" ] || $(RM) -r "$$(OUTDIR)"
endef
# Expand the unittest rules
$(foreach ut, $(ALL_UNITTESTS), $(eval $(call UT_TEMPLATE,$(ut))))
# Disable parallel make when the all_ut_run target is requested otherwise the TAP/XML
# output is interleaved with the rest of the make output.
ifneq ($(strip $(filter all_ut_run,$(MAKECMDGOALS))),)
.NOTPARALLEL:
$(info *NOTE* Parallel make disabled by all_ut_run target so we have sane console output)
endif