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
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 ifneq ($(wildcard $(ROOT
)/make
/local.mk
),)
79 include $(ROOT
)/make
/local.mk
82 # pre-build sanity checks
83 include $(ROOT
)/make
/checks.mk
86 BASE_TARGETS
:= $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard $(ROOT
)/src
/main
/target
/*/target.mk
)))))
88 # configure some directories that are relative to wherever ROOT_DIR is located
89 TOOLS_DIR ?
= $(ROOT
)/tools
90 DL_DIR
:= $(ROOT
)/downloads
91 CONFIG_DIR ?
= $(BETAFLIGHT_CONFIG
)
93 CONFIG_DIR
:= $(ROOT
)/src
/config
95 DIRECTORIES
:= $(DL_DIR
) $(TOOLS_DIR
)
99 # import macros that are OS specific
100 include $(ROOT
)/make
/$(OSFAMILY
).mk
102 # include the tools makefile
103 include $(ROOT
)/make
/tools.mk
105 # Search path for sources
106 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
107 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
108 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
109 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
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 # import config handling
118 include $(ROOT
)/make
/config.mk
122 TARGET
:= $(DEFAULT_TARGET
)
129 CI_TARGETS
:= $(BASE_TARGETS
) $(filter CRAZYBEEF4SX1280 CRAZYBEEF4FR IFLIGHT_BLITZ_F722
, $(BASE_CONFIGS
))
130 include $(ROOT
)/src
/main
/target
/$(TARGET
)/target.mk
132 REVISION
:= norevision
133 ifeq ($(shell git diff
--shortstat
),)
134 REVISION
:= $(shell git log
-1 --format
="%h")
141 # Default Tool options - can be overridden in {mcu}.mk files.
144 OPTIMISE_DEFAULT
:= -Og
146 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
147 DEBUG_FLAGS
= -ggdb3
-gdwarf-5
-DDEBUG
152 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
-fmerge-all-constants
153 OPTIMISE_DEFAULT
:= -O2
154 OPTIMISE_SPEED
:= -Ofast
157 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
160 VPATH
:= $(VPATH
):$(ROOT
)/make
/mcu
161 VPATH
:= $(VPATH
):$(ROOT
)/make
163 # start specific includes
164 ifeq ($(TARGET_MCU
),)
165 $(error No TARGET_MCU specified. Is the target.mk valid for
$(TARGET
)?
)
168 ifeq ($(TARGET_MCU_FAMILY
),)
169 $(error No TARGET_MCU_FAMILY specified. Is the target.mk valid for
$(TARGET
)?
)
172 TARGET_FLAGS
:= -D
$(TARGET
) -D
$(TARGET_MCU_FAMILY
) $(TARGET_FLAGS
)
175 TARGET_FLAGS
:= $(TARGET_FLAGS
) -DUSE_CONFIG
178 include $(ROOT
)/make
/mcu
/$(TARGET_MCU_FAMILY
).mk
180 # openocd specific includes
181 include $(ROOT
)/make
/openocd.mk
183 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
184 ifeq ($(TARGET_FLASH_SIZE
),)
185 ifneq ($(MCU_FLASH_SIZE
),)
186 TARGET_FLASH_SIZE
:= $(MCU_FLASH_SIZE
)
188 $(error MCU_FLASH_SIZE not configured for target
$(TARGET
))
192 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DTARGET_FLASH_SIZE
=$(TARGET_FLASH_SIZE
)
194 ifneq ($(HSE_VALUE
),)
195 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
198 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(TARGET
)
199 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
203 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
204 $(ROOT
)/lib
/main
/MAVLink
206 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
209 VPATH
:= $(VPATH
):$(TARGET_DIR
)
211 include $(ROOT
)/make
/source.mk
213 ###############################################################################
214 # Things that might need changing to use different tools
217 # Find out if ccache is installed on the system
219 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
225 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
226 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
227 CROSS_GDB
:= $(ARM_SDK_PREFIX
)gdb
228 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
229 OBJDUMP
:= $(ARM_SDK_PREFIX
)objdump
230 READELF
:= $(ARM_SDK_PREFIX
)readelf
231 SIZE
:= $(ARM_SDK_PREFIX
)size
232 DFUSE-PACK
:= src
/utils
/dfuse-pack.py
237 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
238 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
239 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
240 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
241 CC_NO_OPTIMISATION
:=
244 # Added after GCC version update, remove once the warnings have been fixed
248 EXTRA_WARNING_FLAGS
:= -Wold-style-definition
250 CFLAGS
+= $(ARCH_FLAGS
) \
251 $(addprefix -D
,$(OPTIONS
)) \
252 $(addprefix -I
,$(INCLUDE_DIRS
)) \
255 -Wall
-Wextra
-Werror
-Wpedantic
-Wunsafe-loop-optimizations
-Wdouble-promotion \
256 $(EXTRA_WARNING_FLAGS
) \
257 -ffunction-sections \
263 -DUSE_STDPERIPH_DRIVER \
266 -D
'__FORKNAME__="$(FORKNAME)"' \
267 -D
'__TARGET__="$(TARGET)"' \
268 -D
'__REVISION__="$(REVISION)"' \
269 $(CONFIG_REVISION_DEFINE
) \
274 ASFLAGS
= $(ARCH_FLAGS
) \
276 -x assembler-with-cpp \
277 $(addprefix -I
,$(INCLUDE_DIRS
)) \
290 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
291 -Wl
,-L
$(LINKER_DIR
) \
293 -Wl
,--no-wchar-size-warning \
294 -Wl
,--print-memory-usage \
299 ###############################################################################
300 # No user-serviceable parts below
301 ###############################################################################
303 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
304 --std
=c99
--inline-suppr
--quiet
--force \
305 $(addprefix -I
,$(INCLUDE_DIRS
)) \
306 -I
/usr
/include -I
/usr
/include/linux
308 TARGET_NAME
:= $(TARGET
)
311 TARGET_NAME
:= $(TARGET_NAME
)_
$(CONFIG
)
315 TARGET_NAME
:= $(TARGET_NAME
)_
$(REVISION
)
318 TARGET_FULLNAME
= $(FORKNAME
)_
$(FC_VER
)_
$(TARGET_NAME
)
320 # Things we will build
322 TARGET_BIN
= $(BIN_DIR
)/$(TARGET_FULLNAME
).bin
323 TARGET_HEX
= $(BIN_DIR
)/$(TARGET_FULLNAME
).hex
324 TARGET_DFU
= $(BIN_DIR
)/$(TARGET_FULLNAME
).dfu
325 TARGET_ZIP
= $(BIN_DIR
)/$(TARGET_FULLNAME
).zip
326 TARGET_OBJ_DIR
= $(OBJECT_DIR
)/$(TARGET_NAME
)
327 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
).elf
328 TARGET_EXST_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
)_EXST.elf
329 TARGET_UNPATCHED_BIN
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
)_UNPATCHED.bin
330 TARGET_LST
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
).lst
331 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(TARGET_OBJ_DIR
)/,$(basename $(SRC
))))
332 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(TARGET_OBJ_DIR
)/,$(basename $(SRC
))))
333 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET_NAME
).map
335 TARGET_EXST_HASH_SECTION_FILE
= $(TARGET_OBJ_DIR
)/exst_hash_section.bin
337 TARGET_EF_HASH
:= $(shell echo
-n
"$(EXTRA_FLAGS)" | openssl dgst
-md5 | awk
'{print $$2;}')
338 TARGET_EF_HASH_FILE
:= $(TARGET_OBJ_DIR
)/.efhash_
$(TARGET_EF_HASH
)
340 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
341 CLEAN_ARTIFACTS
+= $(TARGET_HEX_REV
) $(TARGET_HEX
)
342 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
343 CLEAN_ARTIFACTS
+= $(TARGET_LST
)
344 CLEAN_ARTIFACTS
+= $(TARGET_DFU
)
346 # Make sure build date and revision is updated on every incremental build
347 $(TARGET_OBJ_DIR
)/build
/version.o
: $(SRC
)
349 # List of buildable ELF files and their object dependencies.
350 # It would be nice to compute these lists, but that seems to be just beyond make.
352 $(TARGET_LST
): $(TARGET_ELF
)
353 $(V0
) $(OBJDUMP
) -S
--disassemble
$< > $@
356 $(TARGET_BIN
): $(TARGET_ELF
)
357 @echo
"Creating BIN $(TARGET_BIN)" "$(STDOUT)"
358 $(V1
) $(OBJCOPY
) -O binary
$< $@
360 $(TARGET_HEX
): $(TARGET_ELF
)
361 @echo
"Creating HEX $(TARGET_HEX)" "$(STDOUT)"
362 $(V1
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
364 $(TARGET_DFU
): $(TARGET_HEX
)
365 @echo
"Creating DFU $(TARGET_DFU)" "$(STDOUT)"
366 $(V1
) $(PYTHON
) $(DFUSE-PACK
) -i
$< $@
369 CLEAN_ARTIFACTS
+= $(TARGET_UNPATCHED_BIN
) $(TARGET_EXST_HASH_SECTION_FILE
) $(TARGET_EXST_ELF
)
371 $(TARGET_UNPATCHED_BIN
): $(TARGET_ELF
)
372 @echo
"Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
373 $(V1
) $(OBJCOPY
) -O binary
$< $@
375 $(TARGET_BIN
): $(TARGET_UNPATCHED_BIN
)
376 @echo
"Creating EXST $(TARGET_BIN)" "$(STDOUT)"
377 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
378 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
379 $(V1
) dd if
=/dev
/zero ibs
=1k count
=$(FIRMWARE_SIZE
) of
=$(TARGET_BIN
)
380 $(V1
) dd if
=$(TARGET_UNPATCHED_BIN
) of
=$(TARGET_BIN
) conv
=notrunc
382 @echo
"Generating MD5 hash of binary" "$(STDOUT)"
383 $(V1
) openssl dgst
-md5
$(TARGET_BIN
) > $(TARGET_UNPATCHED_BIN
).md5
385 @echo
"Patching MD5 hash into binary" "$(STDOUT)"
386 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd
-r
- $(TARGET_BIN
)
387 $(V1
) echo
$(FIRMWARE_SIZE
) | awk
'{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
389 # 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"
390 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
391 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
392 # a) regeneration of $(TARGET_BIN), and
393 # b) the results of $(TARGET_BIN) will not be as expected.
394 @echo
"Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
395 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
).tmp
--dump-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
) -j .exst_hash
396 rm $(TARGET_EXST_ELF
).tmp
398 @echo
"Patching MD5 hash into HASH section" "$(STDOUT)"
399 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",64-16,$$2);}' | xxd
-r
- $(TARGET_EXST_HASH_SECTION_FILE
)
401 $(V1
) @echo
"Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
402 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
) --update-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
)
404 $(V1
) $(READELF
) -S
$(TARGET_EXST_ELF
)
405 $(V1
) $(READELF
) -l
$(TARGET_EXST_ELF
)
407 $(TARGET_HEX
): $(TARGET_BIN
)
408 $(if
$(EXST_ADJUST_VMA
),,$(error
"EXST_ADJUST_VMA not specified"))
410 @echo
"Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
411 $(V1
) $(OBJCOPY
) -I binary
-O ihex
--adjust-vma
=$(EXST_ADJUST_VMA
) $(TARGET_BIN
) $@
415 $(TARGET_ELF
): $(TARGET_OBJS
) $(LD_SCRIPT
) $(LD_SCRIPTS
)
416 @echo
"Linking $(TARGET_NAME)" "$(STDOUT)"
417 $(V1
) $(CROSS_CC
) -o
$@
$(filter-out %.
ld,$^
) $(LD_FLAGS
)
418 $(V1
) $(SIZE
) $(TARGET_ELF
)
422 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
424 echo
"%% ($(1)) $<" "$(STDOUT)" && \
425 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(2) $<
429 $(TARGET_OBJ_DIR
)/%.o
: %.c
430 $(V1
) mkdir
-p
$(dir $@
)
431 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
432 $(call compile_file
,not optimised
, $(CC_NO_OPTIMISATION
)) \
434 $(call compile_file
,debug
,$(CC_DEBUG_OPTIMISATION
)) \
437 $(TARGET_OBJ_DIR
)/%.o
: %.c
438 $(V1
) mkdir
-p
$(dir $@
)
439 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
440 $(call compile_file
,not optimised
,$(CC_NO_OPTIMISATION
)) \
442 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
443 $(call compile_file
,speed optimised
,$(CC_SPEED_OPTIMISATION
)) \
445 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
446 $(call compile_file
,size optimised
,$(CC_SIZE_OPTIMISATION
)) \
448 $(call compile_file
,optimised
,$(CC_DEFAULT_OPTIMISATION
)) \
455 $(TARGET_OBJ_DIR
)/%.o
: %.s
456 $(V1
) mkdir
-p
$(dir $@
)
457 @echo
"%% $(notdir $<)" "$(STDOUT)"
458 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
460 $(TARGET_OBJ_DIR
)/%.o
: %.S
461 $(V1
) mkdir
-p
$(dir $@
)
462 @echo
"%% $(notdir $<)" "$(STDOUT)"
463 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
466 ## all : Build all currently built targets
470 $(V0
) @echo
"Building target $@" && \
471 $(MAKE
) hex TARGET
=$@
&& \
472 echo
"Building $@ succeeded."
474 TARGETS_CLEAN
= $(addsuffix _clean
,$(BASE_TARGETS
))
476 ## clean : clean up temporary / machine-generated files
478 @echo
"Cleaning $(TARGET_NAME)"
479 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
480 $(V0
) rm -rf
$(TARGET_OBJ_DIR
)
481 @echo
"Cleaning $(TARGET_NAME) succeeded."
483 ## test_clean : clean up temporary / machine-generated files (tests)
488 $(V0
) cd src
/test && $(MAKE
) clean || true
490 ## <TARGET>_clean : clean up one specific target (alias for above)
492 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
494 ## clean_all : clean all targets
495 clean_all
: $(TARGETS_CLEAN
) test_clean
497 TARGETS_FLASH
= $(addsuffix _flash
,$(BASE_TARGETS
))
499 ## <TARGET>_flash : build and flash a target
501 $(V0
) $(MAKE
) hex TARGET
=$(subst _flash
,,$@
)
502 ifneq (,$(findstring /dev
/ttyUSB
,$(SERIAL_DEVICE
)))
503 $(V0
) $(MAKE
) tty_flash TARGET
=$(subst _flash
,,$@
)
505 $(V0
) $(MAKE
) dfu_flash TARGET
=$(subst _flash
,,$@
)
508 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
510 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
511 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
512 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
514 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
516 ifneq (no-port-found
,$(SERIAL_DEVICE
))
517 # potentially this is because the MCU already is in DFU mode, try anyway
518 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
521 $(V0
) $(MAKE
) $(TARGET_DFU
)
522 $(V0
) dfu-util
-a
0 -D
$(TARGET_DFU
) -s
:leave
524 st-flash_
$(TARGET
): $(TARGET_BIN
)
525 $(V0
) st-flash
--reset write
$< 0x08000000
527 ## st-flash : flash firmware (.bin) onto flight controller
528 st-flash
: st-flash_
$(TARGET
)
530 ifneq ($(OPENOCD_COMMAND
),)
531 openocd-gdb
: $(TARGET_ELF
)
532 $(V0
) $(OPENOCD_COMMAND
) & $(CROSS_GDB
) $(TARGET_ELF
) -ex
"target remote localhost:3333" -ex
"load"
535 TARGETS_ZIP
= $(addsuffix _zip
,$(BASE_TARGETS
))
537 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
539 $(V0
) $(MAKE
) hex TARGET
=$(subst _zip
,,$@
)
540 $(V0
) $(MAKE
) zip TARGET
=$(subst _zip
,,$@
)
543 $(V0
) zip
$(TARGET_ZIP
) $(TARGET_HEX
)
546 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
549 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
551 TARGETS_REVISION
= $(addsuffix _rev
,$(BASE_TARGETS
))
552 ## <TARGET>_rev : build target and add revision to filename
554 $(V0
) $(MAKE
) hex REV
=yes TARGET
=$(subst _rev
,,$@
)
556 all_rev
: $(addsuffix _rev
,$(CI_TARGETS
))
558 unbrick_
$(TARGET
): $(TARGET_HEX
)
559 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
560 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
562 ## unbrick : unbrick flight controller
563 unbrick
: unbrick_
$(TARGET
)
565 ## cppcheck : run static analysis on C source code
566 cppcheck
: $(CSOURCES
)
569 cppcheck-result.xml
: $(CSOURCES
)
570 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
576 ## version : print firmware version
580 ## help : print this help message and exit
581 help
: Makefile make
/tools.mk
583 @echo
"Makefile for the $(FORKNAME) firmware"
586 @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"] [EXTRA_FLAGS=\"<extra_flags>\"]"
588 @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"] [EXTRA_FLAGS=\"<extra_flags>\"]"
590 @echo
" make <config-target> [V=<verbosity>] [OPTIONS=\"<options>\"] [EXTRA_FLAGS=\"<extra_flags>\"]"
592 @echo
"To pupulate configuration targets:"
593 @echo
" make configs"
595 @echo
"Valid TARGET values are: $(BASE_TARGETS)"
597 @sed
-n
's/^## //p' $?
599 ## targets : print a list of all valid target platforms (for consumption by scripts)
601 @echo
"Valid targets: $(BASE_TARGETS)"
602 @echo
"Built targets: $(CI_TARGETS)"
603 @echo
"Default target: $(TARGET)"
608 ## target-mcu : print the MCU type of the target
610 @echo
"$(TARGET_MCU_FAMILY) : $(TARGET_MCU)"
612 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
614 $(V1
) for target in
$${TARGETS}; do \
615 TARGET_MCU_TYPE
=$$($(MAKE
) -s TARGET
=$${target} target-mcu
); \
616 if
[ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
617 if
[ "$${DO_BUILD}" = 1 ]; then \
618 echo
"Building target $${target}..."; \
619 $(MAKE
) TARGET
=$${target}; \
620 if
[ $$?
-ne
0 ]; then \
621 echo
"Building target $${target} failed, aborting."; \
625 echo
-n
"$${target} "; \
631 ## test : run the Betaflight test suite
632 ## junittest : run the Betaflight test suite, producing Junit XML result files.
633 ## 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)
634 ## test-all: run the Betaflight test suite including all per-target expanded tests
635 test junittest test-all test-representative
:
636 $(V0
) cd src
/test && $(MAKE
) $@
638 ## test_help : print the help message for the test suite (including a list of the available tests)
640 $(V0
) cd src
/test && $(MAKE
) help
642 ## test_versions : print the compiler versions used for the test suite
644 $(V0
) cd src
/test && $(MAKE
) versions
646 ## test_% : run test 'test_%' from the test suite
648 $(V0
) cd src
/test && $(MAKE
) $@
650 $(TARGET_EF_HASH_FILE
):
651 $(V1
) mkdir
-p
$(dir $@
)
652 $(V0
) rm -f
$(TARGET_OBJ_DIR
)/.efhash_
*
653 @echo
"EF HASH -> $(TARGET_EF_HASH_FILE)"
654 $(V1
) touch
$(TARGET_EF_HASH_FILE
)
656 # rebuild everything when makefile changes or the extra flags have changed
657 $(TARGET_OBJS
): $(TARGET_EF_HASH_FILE
) Makefile
$(TARGET_DIR
)/target.mk
$(wildcard make
/*) $(CONFIG_FILE
)
659 # include auto-generated dependencies
660 -include $(TARGET_DEPS
)