From e230d683ca5ebda82da66935daa91661ad97c662 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 26 Jan 2021 21:19:14 +0700 Subject: [PATCH] add copy-artifact target, and add uf2 for all family board --- examples/make.mk | 6 ++++-- examples/rules.mk | 43 +++++++++++++++++++++++++++++++--------- hw/bsp/imxrt/family.mk | 2 ++ hw/bsp/nrf/family.mk | 5 ++--- hw/bsp/samd21/family.mk | 2 ++ hw/bsp/samd51/family.mk | 2 ++ hw/bsp/stm32f4/family.mk | 2 ++ hw/bsp/stm32f7/family.mk | 2 ++ tools/build_family.py | 1 + 9 files changed, 51 insertions(+), 14 deletions(-) diff --git a/examples/make.mk b/examples/make.mk index 329efa77..e820989b 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -3,8 +3,10 @@ # --------------------------------------- # Build directory -BUILD = _build/$(BOARD) -PROJECT = $(BOARD)-$(notdir $(CURDIR)) +BUILD := _build/$(BOARD) + +PROJECT := $(BOARD)-$(notdir $(CURDIR)) +BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR)) # Handy check parameter function check_defined = \ diff --git a/examples/rules.mk b/examples/rules.mk index 12ec3504..07bf9a7d 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -2,11 +2,13 @@ # Common make rules for all examples # --------------------------------------- +# Set all as default goal +.DEFAULT_GOAL := all + ifeq ($(FAMILY),esp32s2) # Espressif IDF use CMake build system, this add wrapper target to call idf.py .PHONY: all clean flash -.DEFAULT_GOAL := all all: idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) build @@ -34,6 +36,11 @@ erase: monitor: idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) monitor +UF2_FAMILY_ID = 0xbfdd4eee +$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).hex + @echo CREATE $@ + $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $^ + else ifeq ($(FAMILY),rp2040) all: @@ -43,9 +50,6 @@ all: clean: $(RM) -rf $(BUILD) -#copy-artifact: -# @$(CP) - else # GNU Make build system @@ -101,8 +105,6 @@ $(info LDFLAGS $(LDFLAGS)) $(info ) $(info ASFLAGS $(ASFLAGS)) $(info ) endif -# Set all as default goal -.DEFAULT_GOAL := all all: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex size uf2: $(BUILD)/$(PROJECT).uf2 @@ -128,10 +130,19 @@ $(BUILD)/$(PROJECT).hex: $(BUILD)/$(PROJECT).elf @echo CREATE $@ @$(OBJCOPY) -O ihex $^ $@ -UF2_FAMILY ?= 0x00 +# UF2 generation, iMXRT need to strip to text only before conversion +ifeq ($(FAMILY),imxrt) +$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).elf + @echo CREATE $@ + @$(OBJCOPY) -O ihex -R .flash_config -R .ivt $^ $(BUILD)/$(PROJECT)-textonly.hex + $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $(BUILD)/$(PROJECT)-textonly.hex +else $(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).hex @echo CREATE $@ - $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY) -c -o $@ $^ + $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $^ +endif + +copy-artifact: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex $(BUILD)/$(PROJECT).uf2 # We set vpath to point to the top of the tree so that the source files # can be located. By following this scheme, it allows a single build rule @@ -199,4 +210,18 @@ flash-pyocd: $(BUILD)/$(PROJECT).hex pyocd flash -t $(PYOCD_TARGET) $< pyocd reset -t $(PYOCD_TARGET) -endif # Make target +endif # GNU Make + +#-------------- Artifacts -------------- + +# Create binary directory +$(BIN): + @$(MKDIR) -p $@ + +# Copy binaries .elf, .bin, .hex, .uf2 to BIN for upload +copy-artifact: $(BIN) + @$(CP) $(BUILD)/$(PROJECT).elf $(BIN) + @$(CP) $(BUILD)/$(PROJECT).bin $(BIN) + @$(CP) $(BUILD)/$(PROJECT).hex $(BIN) + @$(CP) $(BUILD)/$(PROJECT).uf2 $(BIN) + diff --git a/hw/bsp/imxrt/family.mk b/hw/bsp/imxrt/family.mk index 47d40306..3311768b 100644 --- a/hw/bsp/imxrt/family.mk +++ b/hw/bsp/imxrt/family.mk @@ -1,3 +1,5 @@ +UF2_FAMILY_ID = 0x4fb2d5bd + include $(TOP)/$(BOARD_PATH)/board.mk CFLAGS += \ diff --git a/hw/bsp/nrf/family.mk b/hw/bsp/nrf/family.mk index 7d8f1095..c7dff1d0 100644 --- a/hw/bsp/nrf/family.mk +++ b/hw/bsp/nrf/family.mk @@ -1,3 +1,5 @@ +UF2_FAMILY_ID = 0xADA52840 + include $(TOP)/$(BOARD_PATH)/board.mk CFLAGS += \ @@ -58,6 +60,3 @@ FREERTOS_PORT = ARM_CM4F # For flash-jlink target JLINK_DEVICE = $(MCU_VARIANT)_xxaa - -# For uf2 conversion -UF2_FAMILY = 0xADA52840 diff --git a/hw/bsp/samd21/family.mk b/hw/bsp/samd21/family.mk index 76929f74..e2bba494 100644 --- a/hw/bsp/samd21/family.mk +++ b/hw/bsp/samd21/family.mk @@ -1,3 +1,5 @@ +UF2_FAMILY_ID = 0x68ed2b88 + include $(TOP)/$(BOARD_PATH)/board.mk CFLAGS += \ diff --git a/hw/bsp/samd51/family.mk b/hw/bsp/samd51/family.mk index dbb0a103..bb895dfc 100644 --- a/hw/bsp/samd51/family.mk +++ b/hw/bsp/samd51/family.mk @@ -1,3 +1,5 @@ +UF2_FAMILY_ID = 0x55114460 + include $(TOP)/$(BOARD_PATH)/board.mk CFLAGS += \ diff --git a/hw/bsp/stm32f4/family.mk b/hw/bsp/stm32f4/family.mk index 89e28174..332d6ee0 100644 --- a/hw/bsp/stm32f4/family.mk +++ b/hw/bsp/stm32f4/family.mk @@ -1,3 +1,5 @@ +UF2_FAMILY_ID = 0x57755a57 + include $(TOP)/$(BOARD_PATH)/board.mk CFLAGS += \ diff --git a/hw/bsp/stm32f7/family.mk b/hw/bsp/stm32f7/family.mk index b5f58cf9..b09d8143 100644 --- a/hw/bsp/stm32f7/family.mk +++ b/hw/bsp/stm32f7/family.mk @@ -1,3 +1,5 @@ +UF2_FAMILY_ID = 0x53b80f00 + include $(TOP)/$(BOARD_PATH)/board.mk CFLAGS += \ diff --git a/tools/build_family.py b/tools/build_family.py index 4ef7201e..9828ab8c 100644 --- a/tools/build_family.py +++ b/tools/build_family.py @@ -73,6 +73,7 @@ def build_board(example, board): success = SUCCEEDED success_count += 1 (flash_size, sram_size) = build_size(example, board) + subprocess.run("make -j -C examples/{} BOARD={} copy-artifact".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) else: exit_status = build_result.returncode success = FAILED