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 BASE_TARGETS below
22 # Compile-time options
25 # compile for External Storage Bootloader support
28 # compile for target loaded into RAM
31 # reserve space for custom defaults
32 CUSTOM_DEFAULTS_EXTENDED ?
= no
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
40 # Insert the debugging hardfault debugger
41 # releases should not be built with this flag as it does not disable pwm output
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.
50 ###############################################################################
51 # Things that need to be maintained as the source changes
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
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
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
98 # silently ignore if the file is not present. Allows for target defaults.
99 -include $(ROOT
)/src
/main
/board
/$(BOARD
)/board.mk
102 BASE_TARGETS
= $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(ROOT
)/src
/main
/target
/*/target.mk
)))))
103 CI_TARGETS
:= $(BASE_TARGETS
)
104 include $(ROOT
)/src
/main
/target
/$(TARGET
)/target.mk
106 REVISION
:= norevision
107 ifeq ($(shell git diff
--shortstat
),)
108 REVISION
:= $(shell git log
-1 --format
="%h")
111 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
112 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
113 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
115 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
117 # Search path for sources
118 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
119 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
120 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
122 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
128 # Default Tool options - can be overridden in {mcu}.mk files.
131 OPTIMISE_DEFAULT
:= -Og
133 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
134 DEBUG_FLAGS
= -ggdb3
-gdwarf-5
-DDEBUG
139 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
-fmerge-all-constants
140 OPTIMISE_DEFAULT
:= -O2
141 OPTIMISE_SPEED
:= -Ofast
144 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
147 VPATH
:= $(VPATH
):$(ROOT
)/make
/mcu
148 VPATH
:= $(VPATH
):$(ROOT
)/make
150 # start specific includes
151 ifeq ($(TARGET_MCU
),)
152 $(error No TARGET_MCU specified. Is the target.mk valid for
$(TARGET
)?
)
155 ifeq ($(TARGET_MCU_FAMILY
),)
156 $(error No TARGET_MCU_FAMILY specified. Is the target.mk valid for
$(TARGET
)?
)
159 TARGET_FLAGS
:= -D
$(TARGET
) -D
$(TARGET_MCU_FAMILY
) $(TARGET_FLAGS
)
160 include $(ROOT
)/make
/mcu
/$(TARGET_MCU_FAMILY
).mk
162 # openocd specific includes
163 include $(ROOT
)/make
/openocd.mk
165 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
166 ifeq ($(TARGET_FLASH_SIZE
),)
167 ifneq ($(MCU_FLASH_SIZE
),)
168 TARGET_FLASH_SIZE
:= $(MCU_FLASH_SIZE
)
170 $(error MCU_FLASH_SIZE not configured for target
$(TARGET
))
174 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DTARGET_FLASH_SIZE
=$(TARGET_FLASH_SIZE
)
176 ifneq ($(HSE_VALUE
),)
177 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
180 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(TARGET
)
181 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
185 ifeq ($(CUSTOM_DEFAULTS_EXTENDED
),yes
)
186 TARGET_FLAGS
+= -DUSE_CUSTOM_DEFAULTS
=
187 EXTRA_LD_FLAGS
+= -Wl
,--defsym
=USE_CUSTOM_DEFAULTS_EXTENDED
=1
190 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
191 $(ROOT
)/lib
/main
/MAVLink
193 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
196 VPATH
:= $(VPATH
):$(TARGET_DIR
)
198 include $(ROOT
)/make
/source.mk
200 ###############################################################################
201 # Things that might need changing to use different tools
204 # Find out if ccache is installed on the system
206 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
212 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
213 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
214 CROSS_GDB
:= $(ARM_SDK_PREFIX
)gdb
215 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
216 OBJDUMP
:= $(ARM_SDK_PREFIX
)objdump
217 READELF
:= $(ARM_SDK_PREFIX
)readelf
218 SIZE
:= $(ARM_SDK_PREFIX
)size
219 DFUSE-PACK
:= src
/utils
/dfuse-pack.py
224 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
225 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
226 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
227 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
228 CC_NO_OPTIMISATION
:=
231 # Added after GCC version update, remove once the warnings have been fixed
235 EXTRA_WARNING_FLAGS
:= -Wold-style-definition
237 CFLAGS
+= $(ARCH_FLAGS
) \
238 $(addprefix -D
,$(OPTIONS
)) \
239 $(addprefix -I
,$(INCLUDE_DIRS
)) \
242 -Wall
-Wextra
-Werror
-Wpedantic
-Wunsafe-loop-optimizations
-Wdouble-promotion \
243 $(EXTRA_WARNING_FLAGS
) \
244 -ffunction-sections \
250 -DUSE_STDPERIPH_DRIVER \
253 -D
'__FORKNAME__="$(FORKNAME)"' \
254 -D
'__TARGET__="$(TARGET)"' \
255 -D
'__REVISION__="$(REVISION)"' \
260 ASFLAGS
= $(ARCH_FLAGS
) \
262 -x assembler-with-cpp \
263 $(addprefix -I
,$(INCLUDE_DIRS
)) \
276 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
277 -Wl
,-L
$(LINKER_DIR
) \
279 -Wl
,--no-wchar-size-warning \
280 -Wl
,--print-memory-usage \
285 ###############################################################################
286 # No user-serviceable parts below
287 ###############################################################################
289 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
290 --std
=c99
--inline-suppr
--quiet
--force \
291 $(addprefix -I
,$(INCLUDE_DIRS
)) \
292 -I
/usr
/include -I
/usr
/include/linux
294 TARGET_BASENAME
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
)
297 # Things we will build
299 TARGET_BIN
= $(TARGET_BASENAME
).bin
300 TARGET_HEX
= $(TARGET_BASENAME
).hex
301 TARGET_HEX_REV
= $(TARGET_BASENAME
)_
$(REVISION
).hex
302 TARGET_DFU
= $(TARGET_BASENAME
).dfu
303 TARGET_ZIP
= $(TARGET_BASENAME
).zip
304 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
305 TARGET_EXST_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_EXST.elf
306 TARGET_UNPATCHED_BIN
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_UNPATCHED.bin
307 TARGET_LST
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).lst
308 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
309 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
310 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
312 TARGET_EXST_HASH_SECTION_FILE
= $(OBJECT_DIR
)/$(TARGET
)/exst_hash_section.bin
314 TARGET_EF_HASH
:= $(shell echo
-n
"$(EXTRA_FLAGS)" | openssl dgst
-md5 | awk
'{print $$2;}')
315 TARGET_EF_HASH_FILE
:= $(OBJECT_DIR
)/$(TARGET
)/.efhash_
$(TARGET_EF_HASH
)
317 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
318 CLEAN_ARTIFACTS
+= $(TARGET_HEX_REV
) $(TARGET_HEX
)
319 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
320 CLEAN_ARTIFACTS
+= $(TARGET_LST
)
321 CLEAN_ARTIFACTS
+= $(TARGET_DFU
)
323 # Make sure build date and revision is updated on every incremental build
324 $(OBJECT_DIR
)/$(TARGET
)/build
/version.o
: $(SRC
)
326 # List of buildable ELF files and their object dependencies.
327 # It would be nice to compute these lists, but that seems to be just beyond make.
329 $(TARGET_LST
): $(TARGET_ELF
)
330 $(V0
) $(OBJDUMP
) -S
--disassemble
$< > $@
333 $(TARGET_BIN
): $(TARGET_ELF
)
334 @echo
"Creating BIN $(TARGET_BIN)" "$(STDOUT)"
335 $(V1
) $(OBJCOPY
) -O binary
$< $@
337 $(TARGET_HEX
): $(TARGET_ELF
)
338 @echo
"Creating HEX $(TARGET_HEX)" "$(STDOUT)"
339 $(V1
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
341 $(TARGET_DFU
): $(TARGET_HEX
)
342 @echo
"Creating DFU $(TARGET_DFU)" "$(STDOUT)"
343 $(V1
) $(PYTHON
) $(DFUSE-PACK
) -i
$< $@
346 CLEAN_ARTIFACTS
+= $(TARGET_UNPATCHED_BIN
) $(TARGET_EXST_HASH_SECTION_FILE
) $(TARGET_EXST_ELF
)
348 $(TARGET_UNPATCHED_BIN
): $(TARGET_ELF
)
349 @echo
"Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
350 $(V1
) $(OBJCOPY
) -O binary
$< $@
352 $(TARGET_BIN
): $(TARGET_UNPATCHED_BIN
)
353 @echo
"Creating EXST $(TARGET_BIN)" "$(STDOUT)"
354 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
355 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
356 $(V1
) dd if
=/dev
/zero ibs
=1k count
=$(FIRMWARE_SIZE
) of
=$(TARGET_BIN
)
357 $(V1
) dd if
=$(TARGET_UNPATCHED_BIN
) of
=$(TARGET_BIN
) conv
=notrunc
359 @echo
"Generating MD5 hash of binary" "$(STDOUT)"
360 $(V1
) openssl dgst
-md5
$(TARGET_BIN
) > $(TARGET_UNPATCHED_BIN
).md5
362 @echo
"Patching MD5 hash into binary" "$(STDOUT)"
363 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd
-r
- $(TARGET_BIN
)
364 $(V1
) echo
$(FIRMWARE_SIZE
) | awk
'{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
366 # 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"
367 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
368 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
369 # a) regeneration of $(TARGET_BIN), and
370 # b) the results of $(TARGET_BIN) will not be as expected.
371 @echo
"Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
372 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
).tmp
--dump-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
) -j .exst_hash
373 rm $(TARGET_EXST_ELF
).tmp
375 @echo
"Patching MD5 hash into HASH section" "$(STDOUT)"
376 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",64-16,$$2);}' | xxd
-r
- $(TARGET_EXST_HASH_SECTION_FILE
)
378 $(V1
) @echo
"Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
379 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
) --update-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
)
381 $(V1
) $(READELF
) -S
$(TARGET_EXST_ELF
)
382 $(V1
) $(READELF
) -l
$(TARGET_EXST_ELF
)
384 $(TARGET_HEX
): $(TARGET_BIN
)
385 $(if
$(EXST_ADJUST_VMA
),,$(error
"EXST_ADJUST_VMA not specified"))
387 @echo
"Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
388 $(V1
) $(OBJCOPY
) -I binary
-O ihex
--adjust-vma
=$(EXST_ADJUST_VMA
) $(TARGET_BIN
) $@
392 $(TARGET_ELF
): $(TARGET_OBJS
) $(LD_SCRIPT
) $(LD_SCRIPTS
)
393 @echo
"Linking $(TARGET)" "$(STDOUT)"
394 $(V1
) $(CROSS_CC
) -o
$@
$(filter-out %.
ld,$^
) $(LD_FLAGS
)
395 $(V1
) $(SIZE
) $(TARGET_ELF
)
399 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
401 echo
"%% ($(1)) $<" "$(STDOUT)" && \
402 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(2) $<
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 $(call compile_file
,debug
,$(CC_DEBUG_OPTIMISATION
)) \
414 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
415 $(V1
) mkdir
-p
$(dir $@
)
416 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
417 $(call compile_file
,not optimised
,$(CC_NO_OPTIMISATION
)) \
419 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
420 $(call compile_file
,speed optimised
,$(CC_SPEED_OPTIMISATION
)) \
422 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
423 $(call compile_file
,size optimised
,$(CC_SIZE_OPTIMISATION
)) \
425 $(call compile_file
,optimised
,$(CC_DEFAULT_OPTIMISATION
)) \
432 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
433 $(V1
) mkdir
-p
$(dir $@
)
434 @echo
"%% $(notdir $<)" "$(STDOUT)"
435 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
437 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
438 $(V1
) mkdir
-p
$(dir $@
)
439 @echo
"%% $(notdir $<)" "$(STDOUT)"
440 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
443 ## all : Build all currently built targets
447 $(V0
) @echo
"Building $@" && \
448 $(MAKE
) hex TARGET
=$@
&& \
449 echo
"Building $@ succeeded."
452 TARGETS_CLEAN
= $(addsuffix _clean
,$(BASE_TARGETS
))
454 ## clean : clean up temporary / machine-generated files
456 @echo
"Cleaning $(TARGET)"
457 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
458 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
459 @echo
"Cleaning $(TARGET) succeeded."
461 ## test_clean : clean up temporary / machine-generated files (tests)
466 $(V0
) cd src
/test && $(MAKE
) clean || true
468 ## <TARGET>_clean : clean up one specific target (alias for above)
470 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
472 ## clean_all : clean all targets
473 clean_all
: $(TARGETS_CLEAN
) test_clean
475 TARGETS_FLASH
= $(addsuffix _flash
,$(BASE_TARGETS
))
477 ## <TARGET>_flash : build and flash a target
479 $(V0
) $(MAKE
) hex TARGET
=$(subst _flash
,,$@
)
480 ifneq (,$(findstring /dev
/ttyUSB
,$(SERIAL_DEVICE
)))
481 $(V0
) $(MAKE
) tty_flash TARGET
=$(subst _flash
,,$@
)
483 $(V0
) $(MAKE
) dfu_flash TARGET
=$(subst _flash
,,$@
)
486 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
488 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
489 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
490 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
492 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
494 ifneq (no-port-found
,$(SERIAL_DEVICE
))
495 # potentially this is because the MCU already is in DFU mode, try anyway
496 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
499 $(V0
) $(MAKE
) $(TARGET_DFU
)
500 $(V0
) dfu-util
-a
0 -D
$(TARGET_DFU
) -s
:leave
502 st-flash_
$(TARGET
): $(TARGET_BIN
)
503 $(V0
) st-flash
--reset write
$< 0x08000000
505 ## st-flash : flash firmware (.bin) onto flight controller
506 st-flash
: st-flash_
$(TARGET
)
508 ifneq ($(OPENOCD_COMMAND
),)
509 openocd-gdb
: $(TARGET_ELF
)
510 $(V0
) $(OPENOCD_COMMAND
) & $(CROSS_GDB
) $(TARGET_ELF
) -ex
"target remote localhost:3333" -ex
"load"
513 TARGETS_ZIP
= $(addsuffix _zip
,$(BASE_TARGETS
))
515 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
517 $(V0
) $(MAKE
) hex TARGET
=$(subst _zip
,,$@
)
518 $(V0
) $(MAKE
) zip TARGET
=$(subst _zip
,,$@
)
521 $(V0
) zip
$(TARGET_ZIP
) $(TARGET_HEX
)
524 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
527 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
529 TARGETS_REVISION
= $(addsuffix _rev
,$(BASE_TARGETS
))
530 ## <TARGET>_rev : build target and add revision to filename
532 $(V0
) $(MAKE
) hex_rev TARGET
=$(subst _rev
,,$@
)
535 $(V0
) mv
-f
$(TARGET_HEX
) $(TARGET_HEX_REV
)
537 all_rev
: $(addsuffix _rev
,$(CI_TARGETS
))
539 unbrick_
$(TARGET
): $(TARGET_HEX
)
540 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
541 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
543 ## unbrick : unbrick flight controller
544 unbrick
: unbrick_
$(TARGET
)
546 ## cppcheck : run static analysis on C source code
547 cppcheck
: $(CSOURCES
)
550 cppcheck-result.xml
: $(CSOURCES
)
551 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
560 ## version : print firmware version
564 ## help : print this help message and exit
565 help
: Makefile make
/tools.mk
567 @echo
"Makefile for the $(FORKNAME) firmware"
570 @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
572 @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
574 @echo
"Valid TARGET values are: $(BASE_TARGETS)"
576 @sed
-n
's/^## //p' $?
578 ## targets : print a list of all valid target platforms (for consumption by scripts)
580 @echo
"Valid targets: $(BASE_TARGETS)"
581 @echo
"Built targets: $(CI_TARGETS)"
582 @echo
"Default target: $(TARGET)"
587 ## target-mcu : print the MCU type of the target
589 @echo
"$(TARGET_MCU_FAMILY) : $(TARGET_MCU)"
591 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
593 $(V1
) for target in
$${TARGETS}; do \
594 TARGET_MCU_TYPE
=$$($(MAKE
) -s TARGET
=$${target} target-mcu
); \
595 if
[ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
596 if
[ "$${DO_BUILD}" = 1 ]; then \
597 echo
"Building target $${target}..."; \
598 $(MAKE
) TARGET
=$${target}; \
599 if
[ $$?
-ne
0 ]; then \
600 echo
"Building target $${target} failed, aborting."; \
604 echo
-n
"$${target} "; \
610 ## test : run the Betaflight test suite
611 ## junittest : run the Betaflight test suite, producing Junit XML result files.
612 ## 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)
613 ## test-all: run the Betaflight test suite including all per-target expanded tests
614 test junittest test-all test-representative
:
615 $(V0
) cd src
/test && $(MAKE
) $@
617 ## test_help : print the help message for the test suite (including a list of the available tests)
619 $(V0
) cd src
/test && $(MAKE
) help
621 ## test_versions : print the compiler versions used for the test suite
623 $(V0
) cd src
/test && $(MAKE
) versions
625 ## test_% : run test 'test_%' from the test suite
627 $(V0
) cd src
/test && $(MAKE
) $@
629 $(TARGET_EF_HASH_FILE
):
630 $(V1
) mkdir
-p
$(dir $@
)
631 $(V0
) rm -f
$(OBJECT_DIR
)/$(TARGET
)/.efhash_
*
632 @echo
"EF HASH -> $(TARGET_EF_HASH_FILE)"
633 $(V1
) touch
$(TARGET_EF_HASH_FILE
)
635 # rebuild everything when makefile changes or the extra flags have changed
636 $(TARGET_OBJS
): $(TARGET_EF_HASH_FILE
) Makefile
$(TARGET_DIR
)/target.mk
$(wildcard make
/*)
638 # include auto-generated dependencies
639 -include $(TARGET_DEPS
)