Add support for producing UF2-format binaries. (#12435)
* First stab at enabling builds of UF2-format binaries. * Add description on producing a UF2 file.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@
|
||||
*.eep
|
||||
*.elf
|
||||
*.hex
|
||||
*.uf2
|
||||
*.qmk
|
||||
!util/bootloader.hex
|
||||
!quantum/tools/eeprom_reset.hex
|
||||
|
4
Makefile
4
Makefile
@ -93,8 +93,8 @@ clean:
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
echo -n 'Deleting *.bin and *.hex ... '
|
||||
rm -f *.bin *.hex
|
||||
echo -n 'Deleting *.bin, *.hex, and *.uf2 ... '
|
||||
rm -f *.bin *.hex *.uf2
|
||||
echo 'done.'
|
||||
|
||||
#Compatibility with the old make variables, anything you specify directly on the command line
|
||||
|
@ -47,10 +47,12 @@ MSG_SIZE_AFTER = Size after:
|
||||
MSG_COFF = Converting to AVR COFF:
|
||||
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
|
||||
MSG_FLASH = Creating load file for flashing:
|
||||
MSG_UF2 = Creating UF2 file for deployment:
|
||||
MSG_EEPROM = Creating load file for EEPROM:
|
||||
MSG_BIN = Creating binary load file for flashing:
|
||||
MSG_EXTENDED_LISTING = Creating Extended Listing:
|
||||
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
||||
MSG_EXECUTING = Executing:
|
||||
MSG_LINKING = Linking:
|
||||
MSG_COMPILING = Compiling:
|
||||
MSG_COMPILING_CXX = Compiling:
|
||||
|
@ -139,6 +139,9 @@ ifneq ($(findstring STM32F042, $(MCU)),)
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
|
||||
|
||||
# UF2 settings
|
||||
UF2_FAMILY ?= STM32F0
|
||||
endif
|
||||
|
||||
ifneq ($(findstring STM32F072, $(MCU)),)
|
||||
@ -172,6 +175,9 @@ ifneq ($(findstring STM32F072, $(MCU)),)
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
|
||||
|
||||
# UF2 settings
|
||||
UF2_FAMILY ?= STM32F0
|
||||
endif
|
||||
|
||||
ifneq ($(findstring STM32F103, $(MCU)),)
|
||||
@ -205,6 +211,9 @@ ifneq ($(findstring STM32F103, $(MCU)),)
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
|
||||
|
||||
# UF2 settings
|
||||
UF2_FAMILY ?= STM32F1
|
||||
endif
|
||||
|
||||
ifneq ($(findstring STM32F303, $(MCU)),)
|
||||
@ -238,6 +247,9 @@ ifneq ($(findstring STM32F303, $(MCU)),)
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
|
||||
|
||||
# UF2 settings
|
||||
UF2_FAMILY ?= STM32F3
|
||||
endif
|
||||
|
||||
ifneq ($(findstring STM32F401, $(MCU)),)
|
||||
@ -271,6 +283,9 @@ ifneq ($(findstring STM32F401, $(MCU)),)
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
|
||||
|
||||
# UF2 settings
|
||||
UF2_FAMILY ?= STM32F4
|
||||
endif
|
||||
|
||||
ifneq ($(findstring STM32F411, $(MCU)),)
|
||||
@ -304,6 +319,9 @@ ifneq ($(findstring STM32F411, $(MCU)),)
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
|
||||
|
||||
# UF2 settings
|
||||
UF2_FAMILY ?= STM32F4
|
||||
endif
|
||||
|
||||
ifneq ($(findstring STM32G431, $(MCU)),)
|
||||
@ -337,6 +355,9 @@ ifneq ($(findstring STM32G431, $(MCU)),)
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
|
||||
|
||||
# UF2 settings
|
||||
UF2_FAMILY ?= STM32G4
|
||||
endif
|
||||
|
||||
ifneq ($(findstring STM32G474, $(MCU)),)
|
||||
@ -370,6 +391,9 @@ ifneq ($(findstring STM32G474, $(MCU)),)
|
||||
# Options to pass to dfu-util when flashing
|
||||
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
|
||||
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11
|
||||
|
||||
# UF2 settings
|
||||
UF2_FAMILY ?= STM32G4
|
||||
endif
|
||||
|
||||
ifneq (,$(filter $(MCU),at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647 at90usb1286 at90usb1287))
|
||||
|
@ -223,6 +223,12 @@ ifneq ($(filter Darwin FreeBSD,$(shell uname -s)),)
|
||||
MD5SUM = md5
|
||||
endif
|
||||
|
||||
# UF2 format settings
|
||||
# To produce a UF2 file in your build, add to your keyboard's rules.mk:
|
||||
# FIRMWARE_FORMAT = uf2
|
||||
UF2CONV = $(TOP_DIR)/util/uf2conv.py
|
||||
UF2_FAMILY ?= 0x0
|
||||
|
||||
# Compiler flags to generate dependency files.
|
||||
#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
|
||||
GENDEPFLAGS = -MMD -MP -MF $(patsubst %.o,%.td,$@)
|
||||
@ -255,6 +261,7 @@ DFU_SUFFIX_ARGS ?=
|
||||
|
||||
elf: $(BUILD_DIR)/$(TARGET).elf
|
||||
hex: $(BUILD_DIR)/$(TARGET).hex
|
||||
uf2: $(BUILD_DIR)/$(TARGET).uf2
|
||||
cpfirmware: $(FIRMWARE_FORMAT)
|
||||
$(SILENT) || printf "Copying $(TARGET).$(FIRMWARE_FORMAT) to qmk_firmware folder" | $(AWK_CMD)
|
||||
$(COPY) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) $(TARGET).$(FIRMWARE_FORMAT) && $(PRINT_OK)
|
||||
@ -283,32 +290,44 @@ gccversion :
|
||||
|
||||
# Create final output files (.hex, .eep) from ELF output file.
|
||||
%.hex: %.elf
|
||||
@$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
|
||||
$(eval CMD=$(HEX) $< $@)
|
||||
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
|
||||
@$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
|
||||
@$(BUILD_CMD)
|
||||
|
||||
%.uf2: %.hex
|
||||
$(eval CMD=$(UF2CONV) $(BUILD_DIR)/$(TARGET).hex -o $(BUILD_DIR)/$(TARGET).uf2 -c -f $(UF2_FAMILY) >/dev/null 2>&1)
|
||||
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
|
||||
@$(SILENT) || printf "$(MSG_UF2) $@" | $(AWK_CMD)
|
||||
@$(BUILD_CMD)
|
||||
|
||||
%.eep: %.elf
|
||||
@$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
|
||||
$(eval CMD=$(EEP) $< $@ || exit 0)
|
||||
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
|
||||
@$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
|
||||
@$(BUILD_CMD)
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
%.lss: %.elf
|
||||
@$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
|
||||
$(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
|
||||
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
|
||||
@$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
|
||||
@$(BUILD_CMD)
|
||||
|
||||
# Create a symbol table from ELF output file.
|
||||
%.sym: %.elf
|
||||
@$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
|
||||
$(eval CMD=$(NM) -n $< > $@ )
|
||||
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
|
||||
@$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
|
||||
@$(BUILD_CMD)
|
||||
|
||||
%.bin: %.elf
|
||||
@$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
|
||||
$(eval CMD=$(BIN) $< $@ || exit 0)
|
||||
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
|
||||
@$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
|
||||
@$(BUILD_CMD)
|
||||
if [ ! -z "$(DFU_SUFFIX_ARGS)" ]; then \
|
||||
#$(SILENT) || printf "$(MSG_EXECUTING) '$(DFU_SUFFIX) $(DFU_SUFFIX_ARGS) -a $(BUILD_DIR)/$(TARGET).bin 1>/dev/null':\n" ;\
|
||||
$(DFU_SUFFIX) $(DFU_SUFFIX_ARGS) -a $(BUILD_DIR)/$(TARGET).bin 1>/dev/null ;\
|
||||
fi
|
||||
$(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
|
||||
@ -476,7 +495,7 @@ $(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null)))
|
||||
|
||||
# Listing of phony targets.
|
||||
.PHONY : all dump_vars finish sizebefore sizeafter qmkversion \
|
||||
gccversion build elf hex eep lss sym coff extcoff \
|
||||
gccversion build elf hex uf2 eep lss sym coff extcoff \
|
||||
clean clean_list debug gdb-config show_path \
|
||||
program teensy dfu dfu-ee dfu-start \
|
||||
flash dfu-split-left dfu-split-right \
|
||||
|
319
util/uf2conv.py
Executable file
319
util/uf2conv.py
Executable file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user