AT32F435 SD card support (#14018)
[betaflight.git] / mk / tools.mk
blob3dc42ab47a5fdeb3752198bc7540433add76f8bf
1 ###############################################################
3 # Installers for tools
5 # NOTE: These are not tied to the default goals and must be invoked manually
7 # ARM SDK Version: 13.3.Rel1
9 # Release date: July 04, 2024
11 ###############################################################
13 ##############################
15 # Check that environmental variables are sane
17 ##############################
19 # Set up ARM (STM32) SDK
20 # Checked below, Should match the output of $(shell arm-none-eabi-gcc -dumpversion)
21 # must match arm-none-eabi-gcc-<version> file in arm sdk distribution
22 GCC_REQUIRED_VERSION ?= 13.3.1
24 ## arm_sdk_install : Install Arm SDK
25 .PHONY: arm_sdk_install
27 # source: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
28 ifeq ($(OSFAMILY)-$(ARCHFAMILY), linux-x86_64)
29 ARM_SDK_URL := https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz
30 DL_CHECKSUM = 0601a9588bc5b9c99ad2b56133b7f118
31 else ifeq ($(OSFAMILY)-$(ARCHFAMILY), macosx-x86_64)
32 ARM_SDK_URL := https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-darwin-x86_64-arm-none-eabi.tar.xz
33 DL_CHECKSUM = 4bb141e44b831635fde4e8139d470f1f
34 else ifeq ($(OSFAMILY)-$(ARCHFAMILY), macosx-arm64)
35 ARM_SDK_URL := https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-darwin-arm64-arm-none-eabi.tar.xz
36 DL_CHECKSUM = f1c18320bb3121fa89dca11399273f4e
37 else ifeq ($(OSFAMILY), windows)
38 ARM_SDK_URL := https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-mingw-w64-i686-arm-none-eabi.zip
39 DL_CHECKSUM = 39d9882ca0eb475e81170ae826c1435d
40 else
41 $(error No toolchain URL defined for $(OSFAMILY)-$(ARCHFAMILY))
42 endif
44 ARM_SDK_FILE := $(notdir $(ARM_SDK_URL))
45 # remove compression suffixes
46 ARM_SDK_DIR := $(TOOLS_DIR)/$(patsubst %.zip,%, \
47 $(patsubst %.tar.xz,%, \
48 $(notdir $(ARM_SDK_URL))))
50 SDK_INSTALL_MARKER := $(ARM_SDK_DIR)/.installed
52 .PHONY: arm_sdk_version
54 arm_sdk_version: | $(ARM_SDK_DIR)
55 $(V1) $(ARM_SDK_DIR)/bin/arm-none-eabi-gcc --version
57 # order-only prereq on directory existance:
58 arm_sdk_install: | $(TOOLS_DIR)
59 arm_sdk_install: arm_sdk_download $(SDK_INSTALL_MARKER)
61 $(SDK_INSTALL_MARKER): $(DL_DIR)/$(ARM_SDK_FILE)
62 # verify ckecksum first
63 @checksum=$$(md5sum "$<" | awk '{print $$1}'); \
64 if [ "$$checksum" != "$(DL_CHECKSUM)" ]; then \
65 echo "$@ Checksum mismatch! Expected $(DL_CHECKSUM), got $$checksum."; \
66 exit 1; \
68 ifeq ($(OSFAMILY), windows)
69 $(V1) unzip -q -d $(TOOLS_DIR) "$<"
70 else
71 # binary only release so just extract it
72 $(V1) tar -C $(TOOLS_DIR) -xf "$<"
73 endif
74 $(V1) touch $(SDK_INSTALL_MARKER)
76 .PHONY: arm_sdk_download
77 arm_sdk_download: | $(DL_DIR)
78 arm_sdk_download: $(DL_DIR)/$(ARM_SDK_FILE)
79 $(DL_DIR)/$(ARM_SDK_FILE):
80 # download the source only if it's newer than what we already have
81 $(V1) curl -L -k -o "$@" $(if $(wildcard $@), -z "$@",) "$(ARM_SDK_URL)"
83 ## arm_sdk_clean : Uninstall Arm SDK
84 .PHONY: arm_sdk_clean
85 arm_sdk_clean:
86 $(V1) [ ! -d "$(ARM_SDK_DIR)" ] || $(RM) -r $(ARM_SDK_DIR)
87 $(V1) [ ! -d "$(DL_DIR)" ] || $(RM) -r $(DL_DIR)
89 .PHONY: openocd_win_install
91 openocd_win_install: | $(DL_DIR) $(TOOLS_DIR)
92 openocd_win_install: OPENOCD_URL := git://git.code.sf.net/p/openocd/code
93 openocd_win_install: OPENOCD_REV := cf1418e9a85013bbf8dbcc2d2e9985695993d9f4
94 openocd_win_install: OPENOCD_OPTIONS :=
96 ifeq ($(OPENOCD_FTDI), yes)
97 openocd_win_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=$(FTD2XX_DIR)
98 endif
100 openocd_win_install: openocd_win_clean libusb_win_install ftd2xx_install
101 # download the source
102 @echo " DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_REV)"
103 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
104 $(V1) mkdir -p "$(OPENOCD_BUILD_DIR)"
105 $(V1) git clone --no-checkout $(OPENOCD_URL) "$(DL_DIR)/openocd-build"
106 $(V1) ( \
107 cd $(OPENOCD_BUILD_DIR) ; \
108 git checkout -q $(OPENOCD_REV) ; \
111 # apply patches
112 @echo " PATCH $(OPENOCD_BUILD_DIR)"
113 $(V1) ( \
114 cd $(OPENOCD_BUILD_DIR) ; \
115 git apply < $(ROOT_DIR)/flight/Project/OpenOCD/0003-freertos-cm4f-fpu-support.patch ; \
116 git apply < $(ROOT_DIR)/flight/Project/OpenOCD/0004-st-icdi-disable.patch ; \
119 # build and install
120 @echo " BUILD $(OPENOCD_WIN_DIR)"
121 $(V1) mkdir -p "$(OPENOCD_WIN_DIR)"
122 $(V1) ( \
123 cd $(OPENOCD_BUILD_DIR) ; \
124 ./bootstrap ; \
125 ./configure --enable-maintainer-mode --prefix="$(OPENOCD_WIN_DIR)" \
126 --build=i686-pc-linux-gnu --host=i586-mingw32msvc \
127 CPPFLAGS=-I$(LIBUSB_WIN_DIR)/include \
128 LDFLAGS=-L$(LIBUSB_WIN_DIR)/lib/gcc \
129 $(OPENOCD_OPTIONS) \
130 --disable-werror \
131 --enable-stlink ; \
132 $(MAKE) ; \
133 $(MAKE) install ; \
136 # delete the extracted source when we're done
137 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
139 .PHONY: openocd_win_clean
140 openocd_win_clean:
141 @echo " CLEAN $(OPENOCD_WIN_DIR)"
142 $(V1) [ ! -d "$(OPENOCD_WIN_DIR)" ] || $(RM) -r "$(OPENOCD_WIN_DIR)"
144 # Set up openocd tools
145 OPENOCD_DIR := $(TOOLS_DIR)/openocd
146 OPENOCD_WIN_DIR := $(TOOLS_DIR)/openocd_win
147 OPENOCD_BUILD_DIR := $(DL_DIR)/openocd-build
149 .PHONY: openocd_install
151 openocd_install: | $(DL_DIR) $(TOOLS_DIR)
152 openocd_install: OPENOCD_URL := git://git.code.sf.net/p/openocd/code
153 openocd_install: OPENOCD_TAG := v0.9.0
154 openocd_install: OPENOCD_OPTIONS := --enable-maintainer-mode --prefix="$(OPENOCD_DIR)" --enable-buspirate --enable-stlink
156 ifeq ($(OPENOCD_FTDI), yes)
157 openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ftdi
158 endif
160 ifeq ($(UNAME), Darwin)
161 openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --disable-option-checking
162 endif
164 openocd_install: openocd_clean
165 # download the source
166 @echo " DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_TAG)"
167 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
168 $(V1) mkdir -p "$(OPENOCD_BUILD_DIR)"
169 $(V1) git clone --no-checkout $(OPENOCD_URL) "$(OPENOCD_BUILD_DIR)"
170 $(V1) ( \
171 cd $(OPENOCD_BUILD_DIR) ; \
172 git checkout -q tags/$(OPENOCD_TAG) ; \
175 # build and install
176 @echo " BUILD $(OPENOCD_DIR)"
177 $(V1) mkdir -p "$(OPENOCD_DIR)"
178 $(V1) ( \
179 cd $(OPENOCD_BUILD_DIR) ; \
180 ./bootstrap ; \
181 ./configure $(OPENOCD_OPTIONS) ; \
182 $(MAKE) ; \
183 $(MAKE) install ; \
186 # delete the extracted source when we're done
187 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
189 .PHONY: openocd_clean
190 openocd_clean:
191 @echo " CLEAN $(OPENOCD_DIR)"
192 $(V1) [ ! -d "$(OPENOCD_DIR)" ] || $(RM) -r "$(OPENOCD_DIR)"
194 STM32FLASH_DIR := $(TOOLS_DIR)/stm32flash
196 .PHONY: stm32flash_install
197 stm32flash_install: STM32FLASH_URL := http://stm32flash.googlecode.com/svn/trunk
198 stm32flash_install: STM32FLASH_REV := 61
199 stm32flash_install: stm32flash_clean
200 # download the source
201 @echo " DOWNLOAD $(STM32FLASH_URL) @ r$(STM32FLASH_REV)"
202 $(V1) svn export -q -r "$(STM32FLASH_REV)" "$(STM32FLASH_URL)" "$(STM32FLASH_DIR)"
204 # build
205 @echo " BUILD $(STM32FLASH_DIR)"
206 $(V1) $(MAKE) --silent -C $(STM32FLASH_DIR) all
208 .PHONY: stm32flash_clean
209 stm32flash_clean:
210 @echo " CLEAN $(STM32FLASH_DIR)"
211 $(V1) [ ! -d "$(STM32FLASH_DIR)" ] || $(RM) -r "$(STM32FLASH_DIR)"
213 # Set up uncrustify tools
214 UNCRUSTIFY_DIR := $(TOOLS_DIR)/uncrustify-0.61
215 UNCRUSTIFY_BUILD_DIR := $(DL_DIR)/uncrustify
217 .PHONY: uncrustify_install
218 uncrustify_install: | $(DL_DIR) $(TOOLS_DIR)
219 uncrustify_install: UNCRUSTIFY_URL := http://downloads.sourceforge.net/project/uncrustify/uncrustify/uncrustify-0.61/uncrustify-0.61.tar.gz
220 uncrustify_install: UNCRUSTIFY_FILE := uncrustify-0.61.tar.gz
221 uncrustify_install: UNCRUSTIFY_OPTIONS := prefix=$(UNCRUSTIFY_DIR)
222 uncrustify_install: uncrustify_clean
223 ifneq ($(OSFAMILY), windows)
224 @echo " DOWNLOAD $(UNCRUSTIFY_URL)"
225 $(V1) curl -L -k -o "$(DL_DIR)/$(UNCRUSTIFY_FILE)" "$(UNCRUSTIFY_URL)"
226 endif
227 # extract the src
228 @echo " EXTRACT $(UNCRUSTIFY_FILE)"
229 $(V1) tar -C $(TOOLS_DIR) -xf "$(DL_DIR)/$(UNCRUSTIFY_FILE)"
231 @echo " BUILD $(UNCRUSTIFY_DIR)"
232 $(V1) ( \
233 cd $(UNCRUSTIFY_DIR) ; \
234 ./configure --prefix="$(UNCRUSTIFY_DIR)" ; \
235 $(MAKE) ; \
236 $(MAKE) install ; \
238 # delete the extracted source when we're done
239 $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)"
241 .PHONY: uncrustify_clean
242 uncrustify_clean:
243 @echo " CLEAN $(UNCRUSTIFY_DIR)"
244 $(V1) [ ! -d "$(UNCRUSTIFY_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_DIR)"
245 @echo " CLEAN $(UNCRUSTIFY_BUILD_DIR)"
246 $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)"
248 # ZIP download URL
249 zip_install: ZIP_URL := http://pkgs.fedoraproject.org/repo/pkgs/zip/zip30.tar.gz/7b74551e63f8ee6aab6fbc86676c0d37/zip30.tar.gz
251 zip_install: ZIP_FILE := $(notdir $(ZIP_URL))
253 ZIP_DIR = $(TOOLS_DIR)/zip30
255 # order-only prereq on directory existance:
256 zip_install : | $(DL_DIR) $(TOOLS_DIR)
257 zip_install: zip_clean
258 $(V1) curl -L -k -o "$(DL_DIR)/$(ZIP_FILE)" "$(ZIP_URL)"
259 $(V1) tar --force-local -C $(TOOLS_DIR) -xzf "$(DL_DIR)/$(ZIP_FILE)"
260 ifneq ($(OSFAMILY), windows)
261 $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f unix/Makefile generic_gcc
262 else
263 $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f win32/makefile.gcc
264 endif
266 .PHONY: zip_clean
267 zip_clean:
268 $(V1) [ ! -d "$(ZIP_DIR)" ] || $(RM) -rf $(ZIP_DIR)
270 ##############################
272 # Set up paths to tools
274 ##############################
276 ifeq ($(shell [ -d "$(ARM_SDK_DIR)" ] && echo "exists"), exists)
277 ARM_SDK_PREFIX := $(ARM_SDK_DIR)/bin/arm-none-eabi-
278 else ifeq (,$(filter %_install test% clean% %-print checks help configs, $(MAKECMDGOALS)))
279 GCC_VERSION = $(shell arm-none-eabi-gcc -dumpversion)
280 ifeq ($(GCC_VERSION),)
281 $(error **ERROR** arm-none-eabi-gcc not in the PATH. Run 'make arm_sdk_install' to install automatically in the tools folder of this repo)
282 else ifneq ($(GCC_VERSION), $(GCC_REQUIRED_VERSION))
283 $(error **ERROR** your arm-none-eabi-gcc is '$(GCC_VERSION)', but '$(GCC_REQUIRED_VERSION)' is expected. Override with 'GCC_REQUIRED_VERSION' in mk/local.mk or run 'make arm_sdk_install' to install the right version automatically in the tools folder of this repo)
284 endif
286 # ARM toolchain is in the path, and the version is what's required.
287 ARM_SDK_PREFIX ?= arm-none-eabi-
288 endif
290 ifeq ($(shell [ -d "$(ZIP_DIR)" ] && echo "exists"), exists)
291 export ZIPBIN := $(ZIP_DIR)/zip
292 else
293 export ZIPBIN := zip
294 endif
296 ifeq ($(shell [ -d "$(OPENOCD_DIR)" ] && echo "exists"), exists)
297 OPENOCD := $(OPENOCD_DIR)/bin/openocd
298 else
299 # not installed, hope it's in the path...
300 OPENOCD ?= openocd
301 endif
303 ifeq ($(shell [ -d "$(UNCRUSTIFY_DIR)" ] && echo "exists"), exists)
304 UNCRUSTIFY := $(UNCRUSTIFY_DIR)/bin/uncrustify
305 else
306 # not installed, hope it's in the path...
307 UNCRUSTIFY ?= uncrustify
308 endif
310 # Google Breakpad
311 DUMP_SYMBOLS_TOOL := $(TOOLS_DIR)/breakpad/$(OSFAMILY)-$(ARCHFAMILY)/dump_syms
312 BREAKPAD_URL := http://dronin.tracer.nz/tools/breakpad.zip
313 BREAKPAD_DL_FILE := $(DL_DIR)/$(notdir $(BREAKPAD_URL))
314 BREAKPAD_DIR := $(TOOLS_DIR)/breakpad
316 .PHONY: breakpad_install
317 breakpad_install: | $(DL_DIR) $(TOOLS_DIR)
318 breakpad_install: breakpad_clean
319 @echo " DOWNLOAD $(BREAKPAD_URL)"
320 $(V1) $(V1) curl -L -k -z "$(BREAKPAD_DL_FILE)" -o "$(BREAKPAD_DL_FILE)" "$(BREAKPAD_URL)"
321 @echo " EXTRACT $(notdir $(BREAKPAD_DL_FILE))"
322 $(V1) mkdir -p "$(BREAKPAD_DIR)"
323 $(V1) unzip -q -d $(BREAKPAD_DIR) "$(BREAKPAD_DL_FILE)"
324 ifeq ($(OSFAMILY), windows)
325 $(V1) ln -s "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-i686" "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-x86_64"
326 endif
328 .PHONY: breakpad_clean
329 breakpad_clean:
330 @echo " CLEAN $(BREAKPAD_DIR)"
331 $(V1) [ ! -d "$(BREAKPAD_DIR)" ] || $(RM) -rf $(BREAKPAD_DIR)
332 @echo " CLEAN $(BREAKPAD_DL_FILE)"
333 $(V1) $(RM) -f $(BREAKPAD_DL_FILE)