Flash - Fix incorrect gating on cli flash commands. (#12013)
[betaflight.git] / Makefile
blob82697d1c8f2762cd3b80c8ca98202785b49e1c7c
1 ###############################################################################
2 # "THE BEER-WARE LICENSE" (Revision 42):
3 # <msmith@FreeBSD.ORG> wrote this file. As long as you retain this notice you
4 # can do whatever you want with this stuff. If we meet some day, and you think
5 # this stuff is worth it, you can buy me a beer in return
6 ###############################################################################
8 # Makefile for building the betaflight firmware.
10 # Invoke this with 'make help' to see the list of supported targets.
12 ###############################################################################
15 # Things that the user might override on the commandline
18 # The target to build, see VALID_TARGETS below
19 TARGET ?= STM32F405
20 BOARD ?=
22 # Compile-time options
23 OPTIONS ?=
25 # compile for External Storage Bootloader support
26 EXST ?= no
28 # compile for target loaded into RAM
29 RAM_BASED ?= no
31 # reserve space for custom defaults
32 CUSTOM_DEFAULTS_EXTENDED ?= no
34 # Debugger optons:
35 # empty - ordinary build with all optimizations enabled
36 # INFO - ordinary build with debug symbols and all optimizations enabled
37 # GDB - debug build with minimum number of optimizations
38 DEBUG ?=
40 # Insert the debugging hardfault debugger
41 # releases should not be built with this flag as it does not disable pwm output
42 DEBUG_HARDFAULTS ?=
44 # Serial port/Device for flashing
45 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyACM*) $(firstword $(wildcard /dev/ttyUSB*) no-port-found))
47 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
48 FLASH_SIZE ?=
50 ###############################################################################
51 # Things that need to be maintained as the source changes
54 FORKNAME = betaflight
56 # Working directories
57 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
58 SRC_DIR := $(ROOT)/src/main
59 OBJECT_DIR := $(ROOT)/obj/main
60 BIN_DIR := $(ROOT)/obj
61 CMSIS_DIR := $(ROOT)/lib/main/CMSIS
62 INCLUDE_DIRS := $(SRC_DIR) \
63 $(ROOT)/src/main/target \
64 $(ROOT)/src/main/startup
65 LINKER_DIR := $(ROOT)/src/link
67 ## V : Set verbosity level based on the V= parameter
68 ## V=0 Low
69 ## V=1 High
70 include $(ROOT)/make/build_verbosity.mk
72 # Build tools, so we all share the same versions
73 # import macros common to all supported build systems
74 include $(ROOT)/make/system-id.mk
76 # developer preferences, edit these at will, they'll be gitignored
77 -include $(ROOT)/make/local.mk
79 # pre-build sanity checks
80 include $(ROOT)/make/checks.mk
82 # configure some directories that are relative to wherever ROOT_DIR is located
83 TOOLS_DIR ?= $(ROOT)/tools
84 DL_DIR := $(ROOT)/downloads
86 export RM := rm
88 # import macros that are OS specific
89 include $(ROOT)/make/$(OSFAMILY).mk
91 # include the tools makefile
92 include $(ROOT)/make/tools.mk
94 # default xtal value for F4 targets
95 HSE_VALUE ?= 8000000
97 # used for turning on features like VCP and SDCARD
98 FEATURES =
100 ifneq ($(BOARD),)
101 # silently ignore if the file is not present. Allows for target defaults.
102 -include $(ROOT)/src/main/board/$(BOARD)/board.mk
103 endif
105 include $(ROOT)/make/targets.mk
107 REVISION := norevision
108 ifeq ($(shell git diff --shortstat),)
109 REVISION := $(shell git log -1 --format="%h")
110 endif
112 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
113 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
114 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
116 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
118 # Search path for sources
119 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
120 FATFS_DIR = $(ROOT)/lib/main/FatFS
121 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
123 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
125 LD_FLAGS :=
126 EXTRA_LD_FLAGS :=
129 # Default Tool options - can be overridden in {mcu}.mk files.
131 ifeq ($(DEBUG),GDB)
132 OPTIMISE_DEFAULT := -Og
134 LTO_FLAGS := $(OPTIMISE_DEFAULT)
135 DEBUG_FLAGS = -ggdb3 -gdwarf-5 -DDEBUG
136 else
137 ifeq ($(DEBUG),INFO)
138 DEBUG_FLAGS = -ggdb3
139 endif
140 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math -fmerge-all-constants
141 OPTIMISE_DEFAULT := -O2
142 OPTIMISE_SPEED := -Ofast
143 OPTIMISE_SIZE := -Os
145 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
146 endif
148 VPATH := $(VPATH):$(ROOT)/make/mcu
149 VPATH := $(VPATH):$(ROOT)/make
151 # start specific includes
152 include $(ROOT)/make/mcu/$(TARGET_MCU).mk
154 # openocd specific includes
155 include $(ROOT)/make/openocd.mk
157 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
158 ifeq ($(TARGET_FLASH_SIZE),)
159 ifneq ($(MCU_FLASH_SIZE),)
160 TARGET_FLASH_SIZE := $(MCU_FLASH_SIZE)
161 else
162 $(error MCU_FLASH_SIZE not configured for target $(TARGET))
163 endif
164 endif
166 DEVICE_FLAGS := $(DEVICE_FLAGS) -DTARGET_FLASH_SIZE=$(TARGET_FLASH_SIZE)
168 ifneq ($(HSE_VALUE),)
169 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
170 endif
172 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
173 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
175 .DEFAULT_GOAL := hex
177 ifeq ($(CUSTOM_DEFAULTS_EXTENDED),yes)
178 TARGET_FLAGS += -DUSE_CUSTOM_DEFAULTS=
179 EXTRA_LD_FLAGS += -Wl,--defsym=USE_CUSTOM_DEFAULTS_EXTENDED=1
180 endif
182 INCLUDE_DIRS := $(INCLUDE_DIRS) \
183 $(ROOT)/lib/main/MAVLink
185 INCLUDE_DIRS := $(INCLUDE_DIRS) \
186 $(TARGET_DIR)
188 VPATH := $(VPATH):$(TARGET_DIR)
190 include $(ROOT)/make/source.mk
192 ###############################################################################
193 # Things that might need changing to use different tools
196 # Find out if ccache is installed on the system
197 CCACHE := ccache
198 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
199 ifneq ($(RESULT),0)
200 CCACHE :=
201 endif
203 # Tool names
204 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
205 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
206 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
207 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
208 OBJDUMP := $(ARM_SDK_PREFIX)objdump
209 READELF := $(ARM_SDK_PREFIX)readelf
210 SIZE := $(ARM_SDK_PREFIX)size
211 DFUSE-PACK := src/utils/dfuse-pack.py
214 # Tool options.
216 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
217 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
218 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
219 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
220 CC_NO_OPTIMISATION :=
223 # Added after GCC version update, remove once the warnings have been fixed
225 TEMPORARY_FLAGS :=
227 EXTRA_WARNING_FLAGS := -Wold-style-definition
229 CFLAGS += $(ARCH_FLAGS) \
230 $(addprefix -D,$(OPTIONS)) \
231 $(addprefix -I,$(INCLUDE_DIRS)) \
232 $(DEBUG_FLAGS) \
233 -std=gnu17 \
234 -Wall -Wextra -Werror -Wpedantic -Wunsafe-loop-optimizations -Wdouble-promotion \
235 $(EXTRA_WARNING_FLAGS) \
236 -ffunction-sections \
237 -fdata-sections \
238 -fno-common \
239 $(TEMPORARY_FLAGS) \
240 $(DEVICE_FLAGS) \
241 -D_GNU_SOURCE \
242 -DUSE_STDPERIPH_DRIVER \
243 -D$(TARGET) \
244 $(TARGET_FLAGS) \
245 -D'__FORKNAME__="$(FORKNAME)"' \
246 -D'__TARGET__="$(TARGET)"' \
247 -D'__REVISION__="$(REVISION)"' \
248 -pipe \
249 -MMD -MP \
250 $(EXTRA_FLAGS)
252 ASFLAGS = $(ARCH_FLAGS) \
253 $(DEBUG_FLAGS) \
254 -x assembler-with-cpp \
255 $(addprefix -I,$(INCLUDE_DIRS)) \
256 -MMD -MP
258 ifeq ($(LD_FLAGS),)
259 LD_FLAGS = -lm \
260 -nostartfiles \
261 --specs=nano.specs \
262 -lc \
263 -lnosys \
264 $(ARCH_FLAGS) \
265 $(LTO_FLAGS) \
266 $(DEBUG_FLAGS) \
267 -static \
268 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
269 -Wl,-L$(LINKER_DIR) \
270 -Wl,--cref \
271 -Wl,--no-wchar-size-warning \
272 -Wl,--print-memory-usage \
273 -T$(LD_SCRIPT) \
274 $(EXTRA_LD_FLAGS)
275 endif
277 ###############################################################################
278 # No user-serviceable parts below
279 ###############################################################################
281 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
282 --std=c99 --inline-suppr --quiet --force \
283 $(addprefix -I,$(INCLUDE_DIRS)) \
284 -I/usr/include -I/usr/include/linux
286 TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)
289 # Things we will build
291 TARGET_BIN = $(TARGET_BASENAME).bin
292 TARGET_HEX = $(TARGET_BASENAME).hex
293 TARGET_HEX_REV = $(TARGET_BASENAME)_$(REVISION).hex
294 TARGET_DFU = $(TARGET_BASENAME).dfu
295 TARGET_ZIP = $(TARGET_BASENAME).zip
296 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
297 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
298 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
299 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
300 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
301 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
302 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
304 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
306 CLEAN_ARTIFACTS := $(TARGET_BIN)
307 CLEAN_ARTIFACTS += $(TARGET_HEX_REV) $(TARGET_HEX)
308 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
309 CLEAN_ARTIFACTS += $(TARGET_LST)
310 CLEAN_ARTIFACTS += $(TARGET_DFU)
312 # Make sure build date and revision is updated on every incremental build
313 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
315 # List of buildable ELF files and their object dependencies.
316 # It would be nice to compute these lists, but that seems to be just beyond make.
318 $(TARGET_LST): $(TARGET_ELF)
319 $(V0) $(OBJDUMP) -S --disassemble $< > $@
321 ifeq ($(EXST),no)
322 $(TARGET_BIN): $(TARGET_ELF)
323 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
324 $(V1) $(OBJCOPY) -O binary $< $@
326 $(TARGET_HEX): $(TARGET_ELF)
327 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
328 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
330 $(TARGET_DFU): $(TARGET_HEX)
331 @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)"
332 $(V1) $(PYTHON) $(DFUSE-PACK) -i $< $@
334 else
335 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
337 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
338 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
339 $(V1) $(OBJCOPY) -O binary $< $@
341 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
342 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
343 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
344 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
345 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
346 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
348 @echo "Generating MD5 hash of binary" "$(STDOUT)"
349 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
351 @echo "Patching MD5 hash into binary" "$(STDOUT)"
352 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
353 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
355 # Note: From the objcopy manual "If you do not specify outfile, objcopy creates a temporary file and destructively renames the result with the name of infile"
356 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
357 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
358 # a) regeneration of $(TARGET_BIN), and
359 # b) the results of $(TARGET_BIN) will not be as expected.
360 @echo "Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
361 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF).tmp --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE) -j .exst_hash
362 rm $(TARGET_EXST_ELF).tmp
364 @echo "Patching MD5 hash into HASH section" "$(STDOUT)"
365 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
367 # For some currently unknown reason, OBJCOPY, with only input/output files, will generate a file around 2GB for the H730 unless we remove an unused-section
368 # As a workaround drop the ._user_heap_stack section, which is only used during build to show errors if there's not enough space for the heap/stack.
369 # The issue can be seen with `readelf -S $(TARGET_EXST_ELF)' vs `readelf -S $(TARGET_ELF)`
370 $(V1) @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
371 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --remove-section ._user_heap_stack --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
373 $(V1) $(READELF) -S $(TARGET_EXST_ELF)
374 $(V1) $(READELF) -l $(TARGET_EXST_ELF)
376 $(TARGET_HEX): $(TARGET_BIN)
377 $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified"))
379 @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
380 $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@
382 endif
384 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT) $(LD_SCRIPTS)
385 @echo "Linking $(TARGET)" "$(STDOUT)"
386 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
387 $(V1) $(SIZE) $(TARGET_ELF)
389 # Compile
391 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
392 define compile_file
393 echo "%% ($(1)) $<" "$(STDOUT)" && \
394 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
395 endef
397 ifeq ($(DEBUG),GDB)
398 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
399 $(V1) mkdir -p $(dir $@)
400 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
401 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
403 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
405 else
406 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
407 $(V1) mkdir -p $(dir $@)
408 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
409 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
411 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
412 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
414 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
415 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
417 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
421 endif
423 # Assemble
424 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
425 $(V1) mkdir -p $(dir $@)
426 @echo "%% $(notdir $<)" "$(STDOUT)"
427 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
429 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
430 $(V1) mkdir -p $(dir $@)
431 @echo "%% $(notdir $<)" "$(STDOUT)"
432 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
435 ## all : Build all currently built targets
436 all: $(CI_TARGETS)
438 ## all_all : Build all targets (including legacy / unsupported)
439 all_all: $(VALID_TARGETS)
441 $(VALID_TARGETS):
442 $(V0) @echo "Building $@" && \
443 $(MAKE) hex TARGET=$@ && \
444 echo "Building $@ succeeded."
446 $(NOBUILD_TARGETS):
447 $(MAKE) TARGET=$@
449 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS))
451 ## clean : clean up temporary / machine-generated files
452 clean:
453 @echo "Cleaning $(TARGET)"
454 $(V0) rm -f $(CLEAN_ARTIFACTS)
455 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
456 @echo "Cleaning $(TARGET) succeeded."
458 ## test_clean : clean up temporary / machine-generated files (tests)
459 test-%_clean:
460 $(MAKE) test_clean
462 test_clean:
463 $(V0) cd src/test && $(MAKE) clean || true
465 ## <TARGET>_clean : clean up one specific target (alias for above)
466 $(TARGETS_CLEAN):
467 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
469 ## clean_all : clean all valid targets
470 clean_all: $(TARGETS_CLEAN) test_clean
472 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS))
474 ## <TARGET>_flash : build and flash a target
475 $(TARGETS_FLASH):
476 $(V0) $(MAKE) hex TARGET=$(subst _flash,,$@)
477 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
478 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
479 else
480 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
481 endif
483 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
484 tty_flash:
485 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
486 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
487 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
489 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
490 dfu_flash:
491 ifneq (no-port-found,$(SERIAL_DEVICE))
492 # potentially this is because the MCU already is in DFU mode, try anyway
493 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
494 $(V0) sleep 1
495 endif
496 $(V0) $(MAKE) $(TARGET_DFU)
497 $(V0) dfu-util -a 0 -D $(TARGET_DFU) -s :leave
499 st-flash_$(TARGET): $(TARGET_BIN)
500 $(V0) st-flash --reset write $< 0x08000000
502 ## st-flash : flash firmware (.bin) onto flight controller
503 st-flash: st-flash_$(TARGET)
505 ifneq ($(OPENOCD_COMMAND),)
506 openocd-gdb: $(TARGET_ELF)
507 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
508 endif
510 TARGETS_ZIP = $(addsuffix _zip,$(VALID_TARGETS))
512 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
513 $(TARGETS_ZIP):
514 $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@)
515 $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@)
517 zip:
518 $(V0) zip $(TARGET_ZIP) $(TARGET_HEX)
520 binary:
521 $(V0) $(MAKE) -j $(TARGET_BIN)
523 hex:
524 $(V0) $(MAKE) -j $(TARGET_HEX)
526 TARGETS_REVISION = $(addsuffix _rev,$(VALID_TARGETS))
527 ## <TARGET>_rev : build target and add revision to filename
528 $(TARGETS_REVISION):
529 $(V0) $(MAKE) hex_rev TARGET=$(subst _rev,,$@)
531 hex_rev: hex
532 $(V0) mv -f $(TARGET_HEX) $(TARGET_HEX_REV)
534 all_rev: $(addsuffix _rev,$(CI_TARGETS))
536 unbrick_$(TARGET): $(TARGET_HEX)
537 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
538 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
540 ## unbrick : unbrick flight controller
541 unbrick: unbrick_$(TARGET)
543 ## cppcheck : run static analysis on C source code
544 cppcheck: $(CSOURCES)
545 $(V0) $(CPPCHECK)
547 cppcheck-result.xml: $(CSOURCES)
548 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
550 # mkdirs
551 $(DL_DIR):
552 mkdir -p $@
554 $(TOOLS_DIR):
555 mkdir -p $@
557 ## version : print firmware version
558 version:
559 @echo $(FC_VER)
561 ## help : print this help message and exit
562 help: Makefile make/tools.mk
563 @echo ""
564 @echo "Makefile for the $(FORKNAME) firmware"
565 @echo ""
566 @echo "Usage:"
567 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
568 @echo "Or:"
569 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
570 @echo ""
571 @echo "Valid TARGET values are: $(VALID_TARGETS)"
572 @echo ""
573 @sed -n 's/^## //p' $?
575 ## targets : print a list of all valid target platforms (for consumption by scripts)
576 targets:
577 @echo "Valid targets: $(VALID_TARGETS)"
578 @echo "Built targets: $(CI_TARGETS)"
579 @echo "Default target: $(TARGET)"
581 targets-ci-print:
582 @echo $(CI_TARGETS)
584 ## target-mcu : print the MCU type of the target
585 target-mcu:
586 @echo $(TARGET_MCU)
588 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
589 targets-by-mcu:
590 $(V1) for target in $${TARGETS}; do \
591 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
592 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
593 if [ "$${DO_BUILD}" = 1 ]; then \
594 echo "Building target $${target}..."; \
595 $(MAKE) TARGET=$${target}; \
596 if [ $$? -ne 0 ]; then \
597 echo "Building target $${target} failed, aborting."; \
598 exit 1; \
599 fi; \
600 else \
601 echo -n "$${target} "; \
602 fi; \
603 fi; \
604 done
605 @echo
607 ## targets-f4 : make all F4 targets
608 targets-f4:
609 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
611 targets-f4-print:
612 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)"
614 targets-ci-f4-print:
615 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(CI_TARGETS)"
617 ## targets-f7 : make all F7 targets
618 targets-f7:
619 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
621 targets-f7-print:
622 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)"
624 targets-ci-f7-print:
625 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(CI_TARGETS)"
627 ## test : run the Betaflight test suite
628 ## junittest : run the Betaflight test suite, producing Junit XML result files.
629 ## test-representative: run a representative subset of the Betaflight test suite (i.e. run all tests, but run each expanded test only for one target)
630 ## test-all: run the Betaflight test suite including all per-target expanded tests
631 test junittest test-all test-representative:
632 $(V0) cd src/test && $(MAKE) $@
634 ## test_help : print the help message for the test suite (including a list of the available tests)
635 test_help:
636 $(V0) cd src/test && $(MAKE) help
638 ## test_versions : print the compiler versions used for the test suite
639 test_versions:
640 $(V0) cd src/test && $(MAKE) versions
642 ## test_% : run test 'test_%' from the test suite
643 test_%:
644 $(V0) cd src/test && $(MAKE) $@
647 # rebuild everything when makefile changes
648 $(TARGET_OBJS): Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
650 # include auto-generated dependencies
651 -include $(TARGET_DEPS)