Implement UF2 device type id extension tag (#21029)

This commit is contained in:
Joel Challis 2023-05-25 23:07:47 +01:00 committed by GitHub
parent ed69d78f27
commit 873922d98f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -152,6 +152,7 @@ endif
# To produce a UF2 file in your build, add to your keyboard's rules.mk: # To produce a UF2 file in your build, add to your keyboard's rules.mk:
# FIRMWARE_FORMAT = uf2 # FIRMWARE_FORMAT = uf2
UF2CONV = $(TOP_DIR)/util/uf2conv.py UF2CONV = $(TOP_DIR)/util/uf2conv.py
UF2CONV_ARGS ?=
UF2_FAMILY ?= 0x0 UF2_FAMILY ?= 0x0
# Compiler flags to generate dependency files. # Compiler flags to generate dependency files.
@ -219,7 +220,7 @@ gccversion :
@$(BUILD_CMD) @$(BUILD_CMD)
%.uf2: %.elf %.uf2: %.elf
$(eval CMD=$(HEX) $< $(BUILD_DIR)/$(TARGET).tmp && $(UF2CONV) $(BUILD_DIR)/$(TARGET).tmp --output $@ --convert --family $(UF2_FAMILY) >/dev/null 2>&1) $(eval CMD=$(HEX) $< $(BUILD_DIR)/$(TARGET).tmp && $(UF2CONV) $(UF2CONV_ARGS) $(BUILD_DIR)/$(TARGET).tmp --output $@ --convert --family $(UF2_FAMILY) >/dev/null 2>&1)
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n" #@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
@$(SILENT) || printf "$(MSG_UF2) $@" | $(AWK_CMD) @$(SILENT) || printf "$(MSG_UF2) $@" | $(AWK_CMD)
@$(BUILD_CMD) @$(BUILD_CMD)

View File

@ -151,10 +151,15 @@ class Block:
flags = 0x0 flags = 0x0
if familyid: if familyid:
flags |= 0x2000 flags |= 0x2000
if devicetype:
flags |= 0x8000
hd = struct.pack("<IIIIIIII", hd = struct.pack("<IIIIIIII",
UF2_MAGIC_START0, UF2_MAGIC_START1, UF2_MAGIC_START0, UF2_MAGIC_START1,
flags, self.addr, 256, blockno, numblocks, familyid) flags, self.addr, 256, blockno, numblocks, familyid)
hd += self.bytes[0:256] hd += self.bytes[0:256]
if devicetype:
hd += bytearray(b'\x08\x29\xa7\xc8')
hd += bytearray(devicetype.to_bytes(4, 'little'))
while len(hd) < 512 - 4: while len(hd) < 512 - 4:
hd += b"\x00" hd += b"\x00"
hd += struct.pack("<I", UF2_MAGIC_END) hd += struct.pack("<I", UF2_MAGIC_END)
@ -283,6 +288,8 @@ def main():
parser.add_argument('-f', '--family', dest='family', type=str, parser.add_argument('-f', '--family', dest='family', type=str,
default="0x0", default="0x0",
help='specify familyID - number or name (default: 0x0)') help='specify familyID - number or name (default: 0x0)')
parser.add_argument('-t' , '--device-type', dest='devicetype', type=str,
help='specify deviceTypeID extension tag - number')
parser.add_argument('-o', '--output', metavar="FILE", dest='output', type=str, parser.add_argument('-o', '--output', metavar="FILE", dest='output', type=str,
help='write output to named file; defaults to "flash.uf2" or "flash.bin" where sensible') help='write output to named file; defaults to "flash.uf2" or "flash.bin" where sensible')
parser.add_argument('-d', '--device', dest="device_path", parser.add_argument('-d', '--device', dest="device_path",
@ -312,6 +319,9 @@ def main():
except ValueError: except ValueError:
error("Family ID needs to be a number or one of: " + ", ".join(families.keys())) error("Family ID needs to be a number or one of: " + ", ".join(families.keys()))
global devicetype
devicetype = int(args.devicetype, 0) if args.devicetype else None
if args.list: if args.list:
list_drives() list_drives()
else: else: