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 DEFAULT_TARGET ?
= STM32F405
23 # Compile-time options
26 # compile for External Storage Bootloader support
29 # compile for target loaded into RAM
32 # reserve space for custom defaults
33 CUSTOM_DEFAULTS_EXTENDED ?
= no
36 # empty - ordinary build with all optimizations enabled
37 # INFO - ordinary build with debug symbols and all optimizations enabled
38 # GDB - debug build with minimum number of optimizations
41 # Insert the debugging hardfault debugger
42 # releases should not be built with this flag as it does not disable pwm output
45 # Serial port/Device for flashing
46 SERIAL_DEVICE ?
= $(firstword $(wildcard /dev
/ttyACM
*) $(firstword $(wildcard /dev
/ttyUSB
*) no-port-found
))
48 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
51 ###############################################################################
52 # Things that need to be maintained as the source changes
58 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
59 SRC_DIR
:= $(ROOT
)/src
/main
60 OBJECT_DIR
:= $(ROOT
)/obj
/main
61 BIN_DIR
:= $(ROOT
)/obj
62 CMSIS_DIR
:= $(ROOT
)/lib
/main
/CMSIS
63 INCLUDE_DIRS
:= $(SRC_DIR
) \
64 $(ROOT
)/src
/main
/target \
65 $(ROOT
)/src
/main
/startup
66 LINKER_DIR
:= $(ROOT
)/src
/link
68 ## V : Set verbosity level based on the V= parameter
71 include $(ROOT
)/make
/build_verbosity.mk
73 # Build tools, so we all share the same versions
74 # import macros common to all supported build systems
75 include $(ROOT
)/make
/system-id.mk
77 # developer preferences, edit these at will, they'll be gitignored
78 -include $(ROOT
)/make
/local.mk
80 # pre-build sanity checks
81 include $(ROOT
)/make
/checks.mk
83 # configure some directories that are relative to wherever ROOT_DIR is located
84 TOOLS_DIR ?
= $(ROOT
)/tools
85 DL_DIR
:= $(ROOT
)/downloads
86 CONFIG_DIR ?
= $(ROOT
)/src
/config
90 # import macros that are OS specific
91 include $(ROOT
)/make
/$(OSFAMILY
).mk
93 # include the tools makefile
94 include $(ROOT
)/make
/tools.mk
96 # default xtal value for F4 targets
99 # used for turning on features like VCP and SDCARD
105 $(error TARGET or CONFIG should be specified. Not both.
)
108 INCLUDE_DIRS
+= $(CONFIG_DIR
)/$(CONFIG
)
109 CONFIG_FILE
:= $(CONFIG_DIR
)/$(CONFIG
)/config.h
111 ifeq ($(wildcard $(CONFIG_FILE
)),)
112 $(error Config file not found
: $(CONFIG_FILE
))
115 TARGET
:= $(shell grep
" FC_TARGET_MCU" $(CONFIG_FILE
) | awk
'{print $$3}' )
118 $(error No TARGET identified. Is the config.h valid for
$(CONFIG
)?
)
123 TARGET
:= $(DEFAULT_TARGET
)
127 include $(ROOT
)/make
/targets.mk
129 BASE_CONFIGS
= $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(ROOT
)/src
/config
/*/config.h
)))))
131 REVISION
:= norevision
132 ifeq ($(shell git diff
--shortstat
),)
133 REVISION
:= $(shell git log
-1 --format
="%h")
136 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
137 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
138 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
140 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
142 # Search path for sources
143 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
144 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
145 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
147 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
153 # Default Tool options - can be overridden in {mcu}.mk files.
156 OPTIMISE_DEFAULT
:= -Og
158 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
159 DEBUG_FLAGS
= -ggdb3
-gdwarf-5
-DDEBUG
164 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
-fmerge-all-constants
165 OPTIMISE_DEFAULT
:= -O2
166 OPTIMISE_SPEED
:= -Ofast
169 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
172 VPATH
:= $(VPATH
):$(ROOT
)/make
/mcu
173 VPATH
:= $(VPATH
):$(ROOT
)/make
175 # start specific includes
176 include $(ROOT
)/make
/mcu
/$(TARGET_MCU
).mk
179 TARGET_FLAGS
+= -DUSE_CONFIG
182 # openocd specific includes
183 include $(ROOT
)/make
/openocd.mk
185 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
186 ifeq ($(TARGET_FLASH_SIZE
),)
187 ifneq ($(MCU_FLASH_SIZE
),)
188 TARGET_FLASH_SIZE
:= $(MCU_FLASH_SIZE
)
190 $(error MCU_FLASH_SIZE not configured for target
$(TARGET
))
194 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DTARGET_FLASH_SIZE
=$(TARGET_FLASH_SIZE
)
196 ifneq ($(HSE_VALUE
),)
197 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
200 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(TARGET
)
201 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
205 ifeq ($(CUSTOM_DEFAULTS_EXTENDED
),yes
)
206 TARGET_FLAGS
+= -DUSE_CUSTOM_DEFAULTS
=
207 EXTRA_LD_FLAGS
+= -Wl
,--defsym
=USE_CUSTOM_DEFAULTS_EXTENDED
=1
210 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
211 $(ROOT
)/lib
/main
/MAVLink
213 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
216 VPATH
:= $(VPATH
):$(TARGET_DIR
)
218 include $(ROOT
)/make
/source.mk
220 ###############################################################################
221 # Things that might need changing to use different tools
224 # Find out if ccache is installed on the system
226 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
232 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
233 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
234 CROSS_GDB
:= $(ARM_SDK_PREFIX
)gdb
235 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
236 OBJDUMP
:= $(ARM_SDK_PREFIX
)objdump
237 READELF
:= $(ARM_SDK_PREFIX
)readelf
238 SIZE
:= $(ARM_SDK_PREFIX
)size
239 DFUSE-PACK
:= src
/utils
/dfuse-pack.py
244 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
245 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
246 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
247 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
248 CC_NO_OPTIMISATION
:=
251 # Added after GCC version update, remove once the warnings have been fixed
255 EXTRA_WARNING_FLAGS
:= -Wold-style-definition
257 CFLAGS
+= $(ARCH_FLAGS
) \
258 $(addprefix -D
,$(OPTIONS
)) \
259 $(addprefix -I
,$(INCLUDE_DIRS
)) \
262 -Wall
-Wextra
-Werror
-Wpedantic
-Wunsafe-loop-optimizations
-Wdouble-promotion \
263 $(EXTRA_WARNING_FLAGS
) \
264 -ffunction-sections \
270 -DUSE_STDPERIPH_DRIVER \
273 -D
'__FORKNAME__="$(FORKNAME)"' \
274 -D
'__TARGET__="$(TARGET)"' \
275 -D
'__REVISION__="$(REVISION)"' \
280 ASFLAGS
= $(ARCH_FLAGS
) \
282 -x assembler-with-cpp \
283 $(addprefix -I
,$(INCLUDE_DIRS
)) \
296 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
297 -Wl
,-L
$(LINKER_DIR
) \
299 -Wl
,--no-wchar-size-warning \
300 -Wl
,--print-memory-usage \
305 ###############################################################################
306 # No user-serviceable parts below
307 ###############################################################################
309 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
310 --std
=c99
--inline-suppr
--quiet
--force \
311 $(addprefix -I
,$(INCLUDE_DIRS
)) \
312 -I
/usr
/include -I
/usr
/include/linux
314 TARGET_NAME
:= $(TARGET
)
317 TARGET_NAME
:= $(TARGET_NAME
)_
$(CONFIG
)
321 TARGET_NAME
:= $(TARGET_NAME
)_
$(REVISION
)
324 TARGET_FULLNAME
= $(FORKNAME
)_
$(FC_VER
)_
$(TARGET_NAME
)
327 # Things we will build
329 TARGET_BIN
= $(BIN_DIR
)/$(TARGET_FULLNAME
).bin
330 TARGET_HEX
= $(BIN_DIR
)/$(TARGET_FULLNAME
).hex
331 TARGET_DFU
= $(BIN_DIR
)/$(TARGET_FULLNAME
).dfu
332 TARGET_ZIP
= $(BIN_DIR
)/$(TARGET_FULLNAME
).zip
333 TARGET_OBJ_DIR
= $(OBJECT_DIR
)/$(TARGET_NAME
)
334 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
).elf
335 TARGET_EXST_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
)_EXST.elf
336 TARGET_UNPATCHED_BIN
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
)_UNPATCHED.bin
337 TARGET_LST
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
).lst
338 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(TARGET_OBJ_DIR
)/,$(basename $(SRC
))))
339 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(TARGET_OBJ_DIR
)/,$(basename $(SRC
))))
340 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
).map
342 TARGET_EXST_HASH_SECTION_FILE
= $(TARGET_OBJ_DIR
)/exst_hash_section.bin
344 TARGET_EF_HASH
:= $(shell echo
-n
"$(EXTRA_FLAGS)" | openssl dgst
-md5 | awk
'{print $$2;}')
345 TARGET_EF_HASH_FILE
:= $(TARGET_OBJ_DIR
)/.efhash_
$(TARGET_EF_HASH
)
347 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
348 CLEAN_ARTIFACTS
+= $(TARGET_HEX_REV
) $(TARGET_HEX
)
349 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
350 CLEAN_ARTIFACTS
+= $(TARGET_LST
)
351 CLEAN_ARTIFACTS
+= $(TARGET_DFU
)
353 # Make sure build date and revision is updated on every incremental build
354 $(TARGET_OBJ_DIR
)/build
/version.o
: $(SRC
)
356 # List of buildable ELF files and their object dependencies.
357 # It would be nice to compute these lists, but that seems to be just beyond make.
359 $(TARGET_LST
): $(TARGET_ELF
)
360 $(V0
) $(OBJDUMP
) -S
--disassemble
$< > $@
363 $(TARGET_BIN
): $(TARGET_ELF
)
364 @echo
"Creating BIN $(TARGET_BIN)" "$(STDOUT)"
365 $(V1
) $(OBJCOPY
) -O binary
$< $@
367 $(TARGET_HEX
): $(TARGET_ELF
)
368 @echo
"Creating HEX $(TARGET_HEX)" "$(STDOUT)"
369 $(V1
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
371 $(TARGET_DFU
): $(TARGET_HEX
)
372 @echo
"Creating DFU $(TARGET_DFU)" "$(STDOUT)"
373 $(V1
) $(PYTHON
) $(DFUSE-PACK
) -i
$< $@
376 CLEAN_ARTIFACTS
+= $(TARGET_UNPATCHED_BIN
) $(TARGET_EXST_HASH_SECTION_FILE
) $(TARGET_EXST_ELF
)
378 $(TARGET_UNPATCHED_BIN
): $(TARGET_ELF
)
379 @echo
"Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
380 $(V1
) $(OBJCOPY
) -O binary
$< $@
382 $(TARGET_BIN
): $(TARGET_UNPATCHED_BIN
)
383 @echo
"Creating EXST $(TARGET_BIN)" "$(STDOUT)"
384 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
385 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
386 $(V1
) dd if
=/dev
/zero ibs
=1k count
=$(FIRMWARE_SIZE
) of
=$(TARGET_BIN
)
387 $(V1
) dd if
=$(TARGET_UNPATCHED_BIN
) of
=$(TARGET_BIN
) conv
=notrunc
389 @echo
"Generating MD5 hash of binary" "$(STDOUT)"
390 $(V1
) openssl dgst
-md5
$(TARGET_BIN
) > $(TARGET_UNPATCHED_BIN
).md5
392 @echo
"Patching MD5 hash into binary" "$(STDOUT)"
393 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd
-r
- $(TARGET_BIN
)
394 $(V1
) echo
$(FIRMWARE_SIZE
) | awk
'{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
396 # 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"
397 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
398 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
399 # a) regeneration of $(TARGET_BIN), and
400 # b) the results of $(TARGET_BIN) will not be as expected.
401 @echo
"Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
402 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
).tmp
--dump-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
) -j .exst_hash
403 rm $(TARGET_EXST_ELF
).tmp
405 @echo
"Patching MD5 hash into HASH section" "$(STDOUT)"
406 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",64-16,$$2);}' | xxd
-r
- $(TARGET_EXST_HASH_SECTION_FILE
)
408 $(V1
) @echo
"Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
409 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
) --update-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
)
411 $(V1
) $(READELF
) -S
$(TARGET_EXST_ELF
)
412 $(V1
) $(READELF
) -l
$(TARGET_EXST_ELF
)
414 $(TARGET_HEX
): $(TARGET_BIN
)
415 $(if
$(EXST_ADJUST_VMA
),,$(error
"EXST_ADJUST_VMA not specified"))
417 @echo
"Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
418 $(V1
) $(OBJCOPY
) -I binary
-O ihex
--adjust-vma
=$(EXST_ADJUST_VMA
) $(TARGET_BIN
) $@
422 $(TARGET_ELF
): $(TARGET_OBJS
) $(LD_SCRIPT
) $(LD_SCRIPTS
)
423 @echo
"Linking $(TARGET_NAME)" "$(STDOUT)"
424 $(V1
) $(CROSS_CC
) -o
$@
$(filter-out %.
ld,$^
) $(LD_FLAGS
)
425 $(V1
) $(SIZE
) $(TARGET_ELF
)
429 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
431 echo
"%% ($(1)) $<" "$(STDOUT)" && \
432 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(2) $<
436 $(TARGET_OBJ_DIR
)/%.o
: %.c
437 $(V1
) mkdir
-p
$(dir $@
)
438 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
439 $(call compile_file
,not optimised
, $(CC_NO_OPTIMISATION
)) \
441 $(call compile_file
,debug
,$(CC_DEBUG_OPTIMISATION
)) \
444 $(TARGET_OBJ_DIR
)/%.o
: %.c
445 $(V1
) mkdir
-p
$(dir $@
)
446 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
447 $(call compile_file
,not optimised
,$(CC_NO_OPTIMISATION
)) \
449 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
450 $(call compile_file
,speed optimised
,$(CC_SPEED_OPTIMISATION
)) \
452 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
453 $(call compile_file
,size optimised
,$(CC_SIZE_OPTIMISATION
)) \
455 $(call compile_file
,optimised
,$(CC_DEFAULT_OPTIMISATION
)) \
462 $(TARGET_OBJ_DIR
)/%.o
: %.s
463 $(V1
) mkdir
-p
$(dir $@
)
464 @echo
"%% $(notdir $<)" "$(STDOUT)"
465 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
467 $(TARGET_OBJ_DIR
)/%.o
: %.S
468 $(V1
) mkdir
-p
$(dir $@
)
469 @echo
"%% $(notdir $<)" "$(STDOUT)"
470 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
473 ## all : Build all currently built targets
476 ## all_all : Build all targets (including legacy / unsupported)
477 all_all
: $(VALID_TARGETS
)
480 $(V0
) @echo
"Building $@" && \
481 $(MAKE
) hex TARGET
=$@
&& \
482 echo
"Building $@ succeeded."
485 $(V0
) @echo
"Building config $@" && \
486 $(MAKE
) hex CONFIG
=$@
&& \
487 echo
"Building config $@ succeeded."
492 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
))
493 CONFIGS_CLEAN
= $(addsuffix _clean
,$(BASE_CONFIGS
))
495 ## clean : clean up temporary / machine-generated files
497 @echo
"Cleaning $(TARGET_NAME)"
498 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
499 $(V0
) rm -rf
$(TARGET_OBJ_DIR
)
500 @echo
"Cleaning $(TARGET_NAME) succeeded."
502 ## test_clean : clean up temporary / machine-generated files (tests)
507 $(V0
) cd src
/test && $(MAKE
) clean || true
509 ## <TARGET>_clean : clean up one specific target (alias for above)
511 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
513 ## <CONFIG>_clean : clean up one specific config (alias for above)
515 $(V0
) $(MAKE
) -j CONFIG
=$(subst _clean
,,$@
) clean
517 ## clean_all : clean all valid targets
518 clean_all
: $(TARGETS_CLEAN
) test_clean
520 TARGETS_FLASH
= $(addsuffix _flash
,$(VALID_TARGETS
))
522 ## <TARGET>_flash : build and flash a target
524 $(V0
) $(MAKE
) hex TARGET
=$(subst _flash
,,$@
)
525 ifneq (,$(findstring /dev
/ttyUSB
,$(SERIAL_DEVICE
)))
526 $(V0
) $(MAKE
) tty_flash TARGET
=$(subst _flash
,,$@
)
528 $(V0
) $(MAKE
) dfu_flash TARGET
=$(subst _flash
,,$@
)
531 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
533 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
534 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
535 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
537 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
539 ifneq (no-port-found
,$(SERIAL_DEVICE
))
540 # potentially this is because the MCU already is in DFU mode, try anyway
541 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
544 $(V0
) $(MAKE
) $(TARGET_DFU
)
545 $(V0
) dfu-util
-a
0 -D
$(TARGET_DFU
) -s
:leave
547 st-flash_
$(TARGET
): $(TARGET_BIN
)
548 $(V0
) st-flash
--reset write
$< 0x08000000
550 ## st-flash : flash firmware (.bin) onto flight controller
551 st-flash
: st-flash_
$(TARGET
)
553 ifneq ($(OPENOCD_COMMAND
),)
554 openocd-gdb
: $(TARGET_ELF
)
555 $(V0
) $(OPENOCD_COMMAND
) & $(CROSS_GDB
) $(TARGET_ELF
) -ex
"target remote localhost:3333" -ex
"load"
558 TARGETS_ZIP
= $(addsuffix _zip
,$(VALID_TARGETS
))
560 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
562 $(V0
) $(MAKE
) hex TARGET
=$(subst _zip
,,$@
)
563 $(V0
) $(MAKE
) zip TARGET
=$(subst _zip
,,$@
)
566 $(V0
) zip
$(TARGET_ZIP
) $(TARGET_HEX
)
569 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
572 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
574 TARGETS_REVISION
= $(addsuffix _rev
,$(VALID_TARGETS
))
575 ## <TARGET>_rev : build target and add revision to filename
577 $(V0
) $(MAKE
) hex REV
=yes TARGET
=$(subst _rev
,,$@
)
579 all_rev
: $(addsuffix _rev
,$(CI_TARGETS
))
581 unbrick_
$(TARGET
): $(TARGET_HEX
)
582 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
583 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
585 ## unbrick : unbrick flight controller
586 unbrick
: unbrick_
$(TARGET
)
588 ## cppcheck : run static analysis on C source code
589 cppcheck
: $(CSOURCES
)
592 cppcheck-result.xml
: $(CSOURCES
)
593 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
602 ## version : print firmware version
606 ## help : print this help message and exit
607 help
: Makefile make
/tools.mk
609 @echo
"Makefile for the $(FORKNAME) firmware"
612 @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
614 @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
616 @echo
"Valid TARGET values are: $(VALID_TARGETS)"
618 @sed
-n
's/^## //p' $?
620 ## targets : print a list of all valid target platforms (for consumption by scripts)
622 @echo
"Valid targets: $(VALID_TARGETS)"
623 @echo
"Built targets: $(CI_TARGETS)"
624 @echo
"Default target: $(TARGET)"
627 @echo
"Valid configs: $(BASE_CONFIGS)"
632 ## target-mcu : print the MCU type of the target
636 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
638 $(V1
) for target in
$${TARGETS}; do \
639 TARGET_MCU_TYPE
=$$($(MAKE
) -s TARGET
=$${target} target-mcu
); \
640 if
[ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
641 if
[ "$${DO_BUILD}" = 1 ]; then \
642 echo
"Building target $${target}..."; \
643 $(MAKE
) TARGET
=$${target}; \
644 if
[ $$?
-ne
0 ]; then \
645 echo
"Building target $${target} failed, aborting."; \
649 echo
-n
"$${target} "; \
655 ## targets-f4 : make all F4 targets
657 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
660 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)"
663 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(CI_TARGETS)"
665 ## targets-f7 : make all F7 targets
667 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
670 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)"
673 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(CI_TARGETS)"
675 ## test : run the Betaflight test suite
676 ## junittest : run the Betaflight test suite, producing Junit XML result files.
677 ## 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)
678 ## test-all: run the Betaflight test suite including all per-target expanded tests
679 test junittest test-all test-representative
:
680 $(V0
) cd src
/test && $(MAKE
) $@
682 ## test_help : print the help message for the test suite (including a list of the available tests)
684 $(V0
) cd src
/test && $(MAKE
) help
686 ## test_versions : print the compiler versions used for the test suite
688 $(V0
) cd src
/test && $(MAKE
) versions
690 ## test_% : run test 'test_%' from the test suite
692 $(V0
) cd src
/test && $(MAKE
) $@
694 $(TARGET_EF_HASH_FILE
):
695 $(V1
) mkdir
-p
$(dir $@
)
696 $(V0
) rm -f
$(TARGET_OBJ_DIR
)/.efhash_
*
697 @echo
"EF HASH -> $(TARGET_EF_HASH_FILE)"
698 $(V1
) touch
$(TARGET_EF_HASH_FILE
)
700 # rebuild everything when makefile changes or the extra flags have changed
701 $(TARGET_OBJS
): $(TARGET_EF_HASH_FILE
) Makefile
$(TARGET_DIR
)/target.mk
$(wildcard make
/*) $(CONFIG_FILE
)
703 # include auto-generated dependencies
704 -include $(TARGET_DEPS
)