From 63231b7017847df62c0521f683a98d8199f102f0 Mon Sep 17 00:00:00 2001 From: Michael Corcoran Date: Sun, 6 Dec 2015 23:31:13 +1300 Subject: [PATCH 1/3] Make: Add ef target for Naze, make hex of ef image This allows a complete Naze32 hex, suitable for flashing with utilities like baseflight configurator --- Makefile | 65 ++++++++++++++++++++++------- flight/targets/EntireFlash/Makefile | 18 +++++++- 2 files changed, 67 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 88bde6983a..7b81f2923e 100644 --- a/Makefile +++ b/Makefile @@ -758,20 +758,36 @@ bu_$(1)_clean: endef # $(1) = Canonical board name all in lower case (e.g. coptercontrol) +# $(2) = Friendly board name +# $(3) = Short board name +# $(4) = BL for bootloader or NOBL for no bootloader define EF_TEMPLATE .PHONY: ef_$(1) -ef_$(1): ef_$(1)_bin +ef_$(1): ef_$(1)_bin ef_$(1)_hex ef_$(1)_%: TARGET=ef_$(1) ef_$(1)_%: OUTDIR=$(BUILD_DIR)/$$(TARGET) ef_$(1)_%: BOARD_ROOT_DIR=$(ROOT_DIR)/flight/targets/$(1) -ef_$(1)_%: bl_$(1)_bin fw_$(1)_tlfw +$(eval $(call EF_TEMPLATE_$(4),$(1),$(2),$(3))) + +.PHONY: ef_$(1)_clean +ef_$(1)_clean: TARGET=ef_$(1) +ef_$(1)_clean: OUTDIR=$(BUILD_DIR)/$$(TARGET) +ef_$(1)_clean: + $(V0) @echo " CLEAN $$@" + $(V1) [ ! -d "$$(OUTDIR)" ] || $(RM) -r "$$(OUTDIR)" +endef + +# $(1) = Canonical board name all in lower case (e.g. coptercontrol) +define EF_TEMPLATE_NOBL +ef_$(1)_%: fw_$(1)_tlfw $(V1) mkdir -p $$(OUTDIR)/dep $(V1) cd $(ROOT_DIR)/flight/targets/EntireFlash && \ $$(MAKE) -r --no-print-directory \ BOARD_NAME=$(1) \ BOARD_SHORT_NAME=$(3) \ BUILD_TYPE=ef \ + INCLUDE_BOOTLOADER=no \ TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \ REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \ DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \ @@ -784,13 +800,30 @@ ef_$(1)_%: bl_$(1)_bin fw_$(1)_tlfw OUTDIR=$$(OUTDIR) \ \ $$* +endef -.PHONY: ef_$(1)_clean -ef_$(1)_clean: TARGET=ef_$(1) -ef_$(1)_clean: OUTDIR=$(BUILD_DIR)/$$(TARGET) -ef_$(1)_clean: - $(V0) @echo " CLEAN $$@" - $(V1) [ ! -d "$$(OUTDIR)" ] || $(RM) -r "$$(OUTDIR)" +# $(1) = Canonical board name all in lower case (e.g. coptercontrol) +define EF_TEMPLATE_BL +ef_$(1)_%: bl_$(1)_bin fw_$(1)_tlfw + $(V1) mkdir -p $$(OUTDIR)/dep + $(V1) cd $(ROOT_DIR)/flight/targets/EntireFlash && \ + $$(MAKE) -r --no-print-directory \ + BOARD_NAME=$(1) \ + BOARD_SHORT_NAME=$(3) \ + BUILD_TYPE=ef \ + INCLUDE_BOOTLOADER=yes \ + TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \ + REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \ + DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \ + \ + MAKE_INC_DIR=$(MAKE_INC_DIR) \ + ROOT_DIR=$(ROOT_DIR) \ + BOARD_ROOT_DIR=$$(BOARD_ROOT_DIR) \ + BOARD_INFO_DIR=$$(BOARD_ROOT_DIR)/board-info \ + TARGET=$$(TARGET) \ + OUTDIR=$$(OUTDIR) \ + \ + $$* endef # When building any of the "all_*" targets, tell all sub makefiles to display @@ -863,11 +896,14 @@ all_$(1)_clean: $$(addsuffix _clean, $$(filter bu_$(1), $$(BU_TARGETS))) all_$(1)_clean: $$(addsuffix _clean, $$(filter ef_$(1), $$(EF_TARGETS))) endef -# Start out assuming that we'll build fw, bl and bu for all boards -FW_BOARDS := $(ALL_BOARDS) -BL_BOARDS := $(filter-out naze32, $(ALL_BOARDS)) -BU_BOARDS := $(BL_BOARDS) -EF_BOARDS := $(filter-out naze32, $(ALL_BOARDS)) +# Some boards don't use the bootloader +NOBL_BOARDS := naze32 +FW_BOARDS := $(ALL_BOARDS) +BL_BOARDS := $(filter-out $(NOBL_BOARDS), $(ALL_BOARDS)) +BU_BOARDS := $(BL_BOARDS) +EF_BOARDS_NOBL := $(NOBL_BOARDS) +EF_BOARDS_BL := $(BL_BOARDS) +EF_BOARDS := $(EF_BOARDS_BL) $(EF_BOARDS_NOBL) # Sim targets are different for each host OS ifeq ($(UNAME), Linux) @@ -923,7 +959,8 @@ $(foreach board, $(FW_BOARDS), $(eval $(call FW_TEMPLATE,$(board),$($(board)_fri $(foreach board, $(BL_BOARDS), $(eval $(call BL_TEMPLATE,$(board),$($(board)_cpuarch),$($(board)_short)))) # Expand the entire-flash rules -$(foreach board, $(EF_BOARDS), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short)))) +$(foreach board, $(EF_BOARDS_BL), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short),BL))) +$(foreach board, $(EF_BOARDS_NOBL), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short),NOBL))) # Expand the available simulator rules $(eval $(call SIM_TEMPLATE,simulation,Simulation,'sim ',posix,elf)) diff --git a/flight/targets/EntireFlash/Makefile b/flight/targets/EntireFlash/Makefile index 82e00d7072..1cb90cfc6e 100644 --- a/flight/targets/EntireFlash/Makefile +++ b/flight/targets/EntireFlash/Makefile @@ -38,13 +38,22 @@ FORCE: .PHONY: bin bin: $(OUTDIR)/$(TARGET).bin +hex: $(OUTDIR)/$(TARGET).hex -BL_BIN := $(ROOT_DIR)/build/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin FW_BIN := $(ROOT_DIR)/build/fw_$(BOARD_NAME)/fw_$(BOARD_NAME).bin FWINFO_BIN := $(FW_BIN).firmwareinfo.bin +INCLUDE_BOOTLOADER ?= yes -# force this target as FW_PRE_PAD could have been changed without us knowing +ifeq ($(INCLUDE_BOOTLOADER),yes) +BL_BIN := $(ROOT_DIR)/build/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin FW_PRE_PAD := $(shell echo $$[$(FW_BANK_BASE)-$(BL_BANK_BASE)-$(BL_BANK_SIZE)]) +else +# no bootloader for this board +BL_BIN := +FW_PRE_PAD := $(shell echo $$[$(FW_BANK_BASE)-$(EF_BANK_BASE)]) +endif # INCLUDE_BOOTLOADER + +# force this target as FW_PRE_PAD could have been changed without us knowing $(OUTDIR)/$(TARGET).fw_pre.pad: FORCE $(V0) @echo $(MSG_PADDING) $(call toprel, $@) $(V1) dd if=/dev/zero count=$(FW_PRE_PAD) bs=1 2> /dev/null | LC_CTYPE=c tr '\000' '\377' > $@ && [ $${PIPESTATUS[0]} -eq "0" ] @@ -61,6 +70,11 @@ $(OUTDIR)/$(TARGET).bin: $(BL_BIN) $(FW_BIN) $(OUTDIR)/$(TARGET).fw_pre.pad $(OU $(V0) @echo $(MSG_FLASH_IMG) $(call toprel, $@) $(V1) cat $(BL_BIN) $(OUTDIR)/$(TARGET).fw_pre.pad $(FW_BIN) $(FWINFO_BIN) $(OUTDIR)/$(TARGET).fw_post.pad $(FWINFO_BIN) > $@ +$(OUTDIR)/$(TARGET).hex: $(OUTDIR)/$(TARGET).bin + $(V0) @echo $(MSG_FLASH_IMG) $(call toprel, $@) + $(V1) $(OBJCOPY) --change-addresses=$(EF_BANK_BASE) -I binary -O ihex $^ $@ + + .PHONY: dfu dfu: $(OUTDIR)/$(TARGET).bin $(V0) @echo " DFU RESCUE $<" From 8a5fd81ef0aa42e303ff81f755d5e3e9f0504fa8 Mon Sep 17 00:00:00 2001 From: Michael Corcoran Date: Mon, 7 Dec 2015 00:49:36 +1300 Subject: [PATCH 2/3] Make: Move no bootloader option to target target-defs.mk --- Makefile | 2 +- flight/targets/naze32/target-defs.mk | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7b81f2923e..a693380625 100644 --- a/Makefile +++ b/Makefile @@ -897,8 +897,8 @@ all_$(1)_clean: $$(addsuffix _clean, $$(filter ef_$(1), $$(EF_TARGETS))) endef # Some boards don't use the bootloader -NOBL_BOARDS := naze32 FW_BOARDS := $(ALL_BOARDS) +NOBL_BOARDS := $(strip $(foreach BOARD, $(ALL_BOARDS),$(if $(filter no,$($(BOARD)_bootloader)),$(BOARD)))) BL_BOARDS := $(filter-out $(NOBL_BOARDS), $(ALL_BOARDS)) BU_BOARDS := $(BL_BOARDS) EF_BOARDS_NOBL := $(NOBL_BOARDS) diff --git a/flight/targets/naze32/target-defs.mk b/flight/targets/naze32/target-defs.mk index 7bf7522392..7979aca0c0 100644 --- a/flight/targets/naze32/target-defs.mk +++ b/flight/targets/naze32/target-defs.mk @@ -8,3 +8,6 @@ naze32_cpuarch := f1 # Short name of this board (used to display board name in parallel builds) # Should be exactly 4 characters long. naze32_short := 'naze' + +# Whether the board uses the bootloader or not (some use the ST bootloader in ROM) +naze32_bootloader := no From 5dab284510748b5d07a53f64ded9683b34924a8e Mon Sep 17 00:00:00 2001 From: Michael Corcoran Date: Mon, 7 Dec 2015 02:52:05 +1300 Subject: [PATCH 3/3] Make: de-duplicate some code --- Makefile | 54 ++++++----------------------- flight/targets/EntireFlash/Makefile | 9 +++-- 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index a693380625..a2182ae759 100644 --- a/Makefile +++ b/Makefile @@ -760,7 +760,7 @@ endef # $(1) = Canonical board name all in lower case (e.g. coptercontrol) # $(2) = Friendly board name # $(3) = Short board name -# $(4) = BL for bootloader or NOBL for no bootloader +# $(4) = yes for bootloader, no for no bootloader define EF_TEMPLATE .PHONY: ef_$(1) ef_$(1): ef_$(1)_bin ef_$(1)_hex @@ -768,26 +768,14 @@ ef_$(1): ef_$(1)_bin ef_$(1)_hex ef_$(1)_%: TARGET=ef_$(1) ef_$(1)_%: OUTDIR=$(BUILD_DIR)/$$(TARGET) ef_$(1)_%: BOARD_ROOT_DIR=$(ROOT_DIR)/flight/targets/$(1) -$(eval $(call EF_TEMPLATE_$(4),$(1),$(2),$(3))) - -.PHONY: ef_$(1)_clean -ef_$(1)_clean: TARGET=ef_$(1) -ef_$(1)_clean: OUTDIR=$(BUILD_DIR)/$$(TARGET) -ef_$(1)_clean: - $(V0) @echo " CLEAN $$@" - $(V1) [ ! -d "$$(OUTDIR)" ] || $(RM) -r "$$(OUTDIR)" -endef - -# $(1) = Canonical board name all in lower case (e.g. coptercontrol) -define EF_TEMPLATE_NOBL -ef_$(1)_%: fw_$(1)_tlfw +ef_$(1)_%: $(if filter(no,$(4)),fw_$(1)_tlfw,bl_$(1)_bin fw_$(1)_tlfw) $(V1) mkdir -p $$(OUTDIR)/dep $(V1) cd $(ROOT_DIR)/flight/targets/EntireFlash && \ $$(MAKE) -r --no-print-directory \ BOARD_NAME=$(1) \ BOARD_SHORT_NAME=$(3) \ BUILD_TYPE=ef \ - INCLUDE_BOOTLOADER=no \ + INCLUDE_BOOTLOADER=$(4) \ TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \ REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \ DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \ @@ -800,30 +788,13 @@ ef_$(1)_%: fw_$(1)_tlfw OUTDIR=$$(OUTDIR) \ \ $$* -endef -# $(1) = Canonical board name all in lower case (e.g. coptercontrol) -define EF_TEMPLATE_BL -ef_$(1)_%: bl_$(1)_bin fw_$(1)_tlfw - $(V1) mkdir -p $$(OUTDIR)/dep - $(V1) cd $(ROOT_DIR)/flight/targets/EntireFlash && \ - $$(MAKE) -r --no-print-directory \ - BOARD_NAME=$(1) \ - BOARD_SHORT_NAME=$(3) \ - BUILD_TYPE=ef \ - INCLUDE_BOOTLOADER=yes \ - TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \ - REMOVE_CMD="$(RM)" OOCD_EXE="$(OPENOCD)" \ - DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \ - \ - MAKE_INC_DIR=$(MAKE_INC_DIR) \ - ROOT_DIR=$(ROOT_DIR) \ - BOARD_ROOT_DIR=$$(BOARD_ROOT_DIR) \ - BOARD_INFO_DIR=$$(BOARD_ROOT_DIR)/board-info \ - TARGET=$$(TARGET) \ - OUTDIR=$$(OUTDIR) \ - \ - $$* +.PHONY: ef_$(1)_clean +ef_$(1)_clean: TARGET=ef_$(1) +ef_$(1)_clean: OUTDIR=$(BUILD_DIR)/$$(TARGET) +ef_$(1)_clean: + $(V0) @echo " CLEAN $$@" + $(V1) [ ! -d "$$(OUTDIR)" ] || $(RM) -r "$$(OUTDIR)" endef # When building any of the "all_*" targets, tell all sub makefiles to display @@ -901,9 +872,7 @@ FW_BOARDS := $(ALL_BOARDS) NOBL_BOARDS := $(strip $(foreach BOARD, $(ALL_BOARDS),$(if $(filter no,$($(BOARD)_bootloader)),$(BOARD)))) BL_BOARDS := $(filter-out $(NOBL_BOARDS), $(ALL_BOARDS)) BU_BOARDS := $(BL_BOARDS) -EF_BOARDS_NOBL := $(NOBL_BOARDS) -EF_BOARDS_BL := $(BL_BOARDS) -EF_BOARDS := $(EF_BOARDS_BL) $(EF_BOARDS_NOBL) +EF_BOARDS := $(ALL_BOARDS) # Sim targets are different for each host OS ifeq ($(UNAME), Linux) @@ -959,8 +928,7 @@ $(foreach board, $(FW_BOARDS), $(eval $(call FW_TEMPLATE,$(board),$($(board)_fri $(foreach board, $(BL_BOARDS), $(eval $(call BL_TEMPLATE,$(board),$($(board)_cpuarch),$($(board)_short)))) # Expand the entire-flash rules -$(foreach board, $(EF_BOARDS_BL), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short),BL))) -$(foreach board, $(EF_BOARDS_NOBL), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short),NOBL))) +$(foreach board, $(EF_BOARDS), $(eval $(call EF_TEMPLATE,$(board),$($(board)_friendly),$($(board)_short),$($(board)_bootloader)))) # Expand the available simulator rules $(eval $(call SIM_TEMPLATE,simulation,Simulation,'sim ',posix,elf)) diff --git a/flight/targets/EntireFlash/Makefile b/flight/targets/EntireFlash/Makefile index 1cb90cfc6e..5e38d94ed0 100644 --- a/flight/targets/EntireFlash/Makefile +++ b/flight/targets/EntireFlash/Makefile @@ -44,13 +44,12 @@ FW_BIN := $(ROOT_DIR)/build/fw_$(BOARD_NAME)/fw_$(BOARD_NAME).bin FWINFO_BIN := $(FW_BIN).firmwareinfo.bin INCLUDE_BOOTLOADER ?= yes -ifeq ($(INCLUDE_BOOTLOADER),yes) -BL_BIN := $(ROOT_DIR)/build/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin -FW_PRE_PAD := $(shell echo $$[$(FW_BANK_BASE)-$(BL_BANK_BASE)-$(BL_BANK_SIZE)]) -else -# no bootloader for this board +ifeq ($(INCLUDE_BOOTLOADER),no) BL_BIN := FW_PRE_PAD := $(shell echo $$[$(FW_BANK_BASE)-$(EF_BANK_BASE)]) +else +BL_BIN := $(ROOT_DIR)/build/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin +FW_PRE_PAD := $(shell echo $$[$(FW_BANK_BASE)-$(BL_BANK_BASE)-$(BL_BANK_SIZE)]) endif # INCLUDE_BOOTLOADER # force this target as FW_PRE_PAD could have been changed without us knowing