Add a universal flash command for cli (#6224)

* Add universal flash command

* Add bootloader info to I:C boards

* Add support for ATSAM

* Add messages for flash target

* Message cleanup

* Add USB ASP Flashing target

* Make usbasp target more universal

* Add phoney target for usbasp

* Clarify error message when bootloader isn't matched
This commit is contained in:
Drashna Jaelre 2019-08-20 15:39:24 -07:00 committed by Yan-Fa Li
parent 91ee6a1dbb
commit 4003d077ce
10 changed files with 93 additions and 44 deletions

View File

@ -54,6 +54,8 @@ ARMV = 7
# The CORTEX_VTOR... is needed only for MCHCK/Infinity KB
OPT_DEFS += -DCORTEX_VTOR_INIT=0x00002000
BOOTLOADER = dfu
# Build Options
# comment out to disable the options.
#

View File

@ -54,6 +54,8 @@ ARMV = 7
# The CORTEX_VTOR... is needed only for MCHCK/Infinity KB
OPT_DEFS += -DCORTEX_VTOR_INIT=0x00002000
BOOTLOADER = dfu
# Build Options
# comment out to disable the options.
#

View File

@ -53,6 +53,8 @@ ARMV = 7
# The CORTEX_VTOR... is needed only for MCHCK/Infinity KB
OPT_DEFS = -DCORTEX_VTOR_INIT=0x00001000
BOOTLOADER = dfu
# Build Options
# comment out to disable the options.
#

View File

@ -59,6 +59,8 @@ OPT_DEFS =
DFU_ARGS = -d 1c11:b007
DFU_SUFFIX_ARGS = -p b007 -v 1c11
BOOTLOADER = dfu
# Build Options
# comment out to disable the options.
#

View File

@ -57,6 +57,8 @@ OPT_DEFS =
DFU_ARGS = -d 1c11:b007
DFU_SUFFIX_ARGS = -p b007 -v 1c11
BOOTLOADER = dfu
# Build Options
# comment out to disable the options.
#

View File

@ -85,3 +85,5 @@ MSG_PYTHON_MISSING = $(WARN_COLOR)WARNING:$(NO_COLOR)\n \
Python 3 is not installed. It will be required by a future version\n\
of qmk_firmware.\n\n\
Please run $(BOLD)util/qmk_install.sh$(NO_COLOR) to install all the dependencies QMK requires.\n\n
MSG_FLASH_BOOTLOADER = $(WARN_COLOR)WARNING:$(NO_COLOR) This board's bootloader is not specified or is not supported by the \":flash\" target at this time.\n\n
MSG_FLASH_ARCH = $(WARN_COLOR)WARNING:$(NO_COLOR) This board's architecture is not supported by the \":flash\" target at this time.\n\n

View File

@ -54,3 +54,6 @@ EXTRALIBDIRS =
bin: $(BUILD_DIR)/$(TARGET).hex
$(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
$(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
flash: bin
$(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_ARCH)"

View File

@ -124,8 +124,12 @@ qmk: $(BUILD_DIR)/$(TARGET).hex
program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep check-size
$(PROGRAM_CMD)
teensy: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
define EXEC_TEENSY
$(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
endef
teensy: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_TEENSY)
BATCHISP ?= batchisp
@ -137,18 +141,32 @@ flip: $(BUILD_DIR)/$(TARGET).hex check-size
DFU_PROGRAMMER ?= dfu-programmer
GREP ?= grep
dfu: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
define EXEC_DFU
if [ "$(1)" ]; then \
echo "Flashing '$(1)' for EE_HANDS split keyboard support." ;\
fi; \
until $(DFU_PROGRAMMER) $(MCU) get bootloader-version; do\
echo "Error: Bootloader not found. Trying again in 5s." ;\
sleep 5 ;\
done
done; \
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) erase --force;\
else\
$(DFU_PROGRAMMER) $(MCU) erase;\
fi
$(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
$(DFU_PROGRAMMER) $(MCU) erase --force; \
if [ "$(1)" ]; then \
$(DFU_PROGRAMMER) $(MCU) flash --eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
else \
$(DFU_PROGRAMMER) $(MCU) erase; \
if [ "$(1)" ]; then \
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
fi; \
$(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex;\
$(DFU_PROGRAMMER) $(MCU) reset
endef
dfu: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
$(call EXEC_DFU)
dfu-start:
$(DFU_PROGRAMMER) $(MCU) reset
@ -170,34 +188,10 @@ dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
$(DFU_PROGRAMMER) $(MCU) reset
dfu-split-left: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
until $(DFU_PROGRAMMER) $(MCU) get bootloader-version; do\
echo "Error: Bootloader not found. Trying again in 5s." ;\
sleep 5 ;\
done
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) erase --force;\
$(DFU_PROGRAMMER) $(MCU) flash --eeprom $(QUANTUM_PATH)/split_common/eeprom-lefthand.eep;\
else\
$(DFU_PROGRAMMER) $(MCU) erase;\
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/eeprom-lefthand.eep;\
fi
$(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
$(DFU_PROGRAMMER) $(MCU) reset
$(call EXEC_DFU,eeprom-lefthand.eep)
dfu-split-right: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
until $(DFU_PROGRAMMER) $(MCU) get bootloader-version; do\
echo "Error: Bootloader not found. Trying again in 5s." ;\
sleep 5 ;\
done
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) erase --force;\
$(DFU_PROGRAMMER) $(MCU) flash --eeprom $(QUANTUM_PATH)/split_common/eeprom-righthand.eep;\
else\
$(DFU_PROGRAMMER) $(MCU) erase;\
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/eeprom-righthand.eep;\
fi
$(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
$(DFU_PROGRAMMER) $(MCU) reset
$(call EXEC_DFU,eeprom-righthand.eep)
define EXEC_AVRDUDE
USB= ;\
@ -245,8 +239,12 @@ avrdude-split-left: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
avrdude-split-right: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_AVRDUDE,eeprom-righthand.eep)
usbasp: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
define EXEC_USBASP
avrdude -p $(MCU) -c usbasp -U flash:w:$(BUILD_DIR)/$(TARGET).hex
endef
usbasp: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_USBASP)
# Convert hex to bin.
@ -323,3 +321,16 @@ production: $(BUILD_DIR)/$(TARGET).hex bootloader cpfirmware
@cat $(TARGET)_bootloader.hex >> $(TARGET)_production.hex
echo "File sizes:"
$(SIZE) $(TARGET).hex $(TARGET)_bootloader.hex $(TARGET)_production.hex
flash: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
ifeq ($(strip $(BOOTLOADER)), caterina)
$(call EXEC_AVRDUDE)
else ifeq ($(strip $(BOOTLOADER)), halfkay)
$(call EXEC_TEENSY)
else ifeq (dfu,$(findstring dfu,$(BOOTLOADER)))
$(call EXEC_DFU)
else ifeq ($(strip $(BOOTLOADER)), USBasp)
$(call EXEC_USBASP)
else
$(PRINT_OK); $(SILENT) || printf "&(MSG_FLASH_BOOTLOADER)"
endif

View File

@ -234,9 +234,12 @@ qmk: $(BUILD_DIR)/$(TARGET).bin
zip $(TARGET).qmk -urj $(BUILD_DIR)/$(TARGET).json
printf "@ $(TARGET).json\n@=info.json\n" | zipnote -w $(TARGET).qmk
dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
define EXEC_DFU_UTIL
$(DFU_UTIL) $(DFU_ARGS) -D $(BUILD_DIR)/$(TARGET).bin
endef
dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
$(call EXEC_DFU_UTIL)
ifneq ($(strip $(TIME_DELAY)),)
TIME_DELAY = $(strip $(TIME_DELAY))
@ -253,7 +256,7 @@ dfu-util-wait: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
done; \
echo "Flashing $(TARGET).bin" ;\
sleep 1 ;\
$(DFU_UTIL) $(DFU_ARGS) -D $(BUILD_DIR)/$(TARGET).bin
$(call EXEC_DFU_UTIL)
st-link-cli: $(BUILD_DIR)/$(TARGET).hex sizeafter
$(ST_LINK_CLI) $(ST_LINK_ARGS) -q -c SWD -p $(BUILD_DIR)/$(TARGET).hex -Rst
@ -268,7 +271,24 @@ ifndef TEENSY_LOADER_CLI
endif
endif
teensy: $(BUILD_DIR)/$(TARGET).hex cpfirmware sizeafter
define EXEC_TEENSY
$(TEENSY_LOADER_CLI) -mmcu=$(MCU_LDSCRIPT) -w -v $(BUILD_DIR)/$(TARGET).hex
endef
teensy: $(BUILD_DIR)/$(TARGET).hex cpfirmware sizeafter
$(call EXEC_TEENSY)
bin: $(BUILD_DIR)/$(TARGET).bin sizeafter
$(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
flash: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
ifeq ($(strip $(BOOTLOADER)),dfu)
$(call EXEC_DFU_UTIL)
else ifeq ($(strip $(MCU_FAMILY)),KINETIS)
$(call EXEC_TEENSY)
else ifeq ($(strip $(MCU_FAMILY)),STM32)
$(call EXEC_DFU_UTIL)
else
$(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)"
endif

View File

@ -433,4 +433,7 @@ $(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null)))
.PHONY : all finish sizebefore sizeafter qmkversion \
gccversion build elf hex eep lss sym coff extcoff \
clean clean_list debug gdb-config show_path \
program teensy dfu flip dfu-ee flip-ee dfu-start
program teensy dfu flip dfu-ee flip-ee dfu-start \
flash dfu-split-left dfu-split-right \
avrdude-split-left avrdude-split-right \
avrdude-loop usbasp