summaryrefslogtreecommitdiff
path: root/util/uf2conv.py
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2023-05-29 06:17:24 +1000
committerNick Brassel <nick@tzarc.org>2023-05-29 06:17:24 +1000
commit5024370dd0b441e86ace3089193e84c5b050d892 (patch)
treeb661d5b154be987f9c3dba3a526b70e0b63f9fef /util/uf2conv.py
parent16767e4d59c2334fcd2d5e6556a68d5ff60ffd7b (diff)
parent8b1d86eabf399e82af7738fb675b9c74195d0f98 (diff)
Merge branch 'develop'
Diffstat (limited to 'util/uf2conv.py')
-rwxr-xr-xutil/uf2conv.py54
1 files changed, 35 insertions, 19 deletions
diff --git a/util/uf2conv.py b/util/uf2conv.py
index 7f5645414a..578b2b4977 100755
--- a/util/uf2conv.py
+++ b/util/uf2conv.py
@@ -8,6 +8,7 @@ import os
import os.path
import argparse
import json
+from time import sleep
UF2_MAGIC_START0 = 0x0A324655 # "UF2\n"
@@ -150,10 +151,15 @@ class Block:
flags = 0x0
if familyid:
flags |= 0x2000
+ if devicetype:
+ flags |= 0x8000
hd = struct.pack("<IIIIIIII",
UF2_MAGIC_START0, UF2_MAGIC_START1,
flags, self.addr, 256, blockno, numblocks, familyid)
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:
hd += b"\x00"
hd += struct.pack("<I", UF2_MAGIC_END)
@@ -276,23 +282,27 @@ def main():
parser = argparse.ArgumentParser(description='Convert to UF2 or flash directly.')
parser.add_argument('input', metavar='INPUT', type=str, nargs='?',
help='input file (HEX, BIN or UF2)')
- parser.add_argument('-b' , '--base', dest='base', type=str,
+ parser.add_argument('-b', '--base', dest='base', type=str,
default="0x2000",
help='set base address of application for BIN format (default: 0x2000)')
- parser.add_argument('-o' , '--output', metavar="FILE", dest='output', type=str,
+ parser.add_argument('-f', '--family', dest='family', type=str,
+ 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,
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",
help='select a device path to flash')
- parser.add_argument('-l' , '--list', action='store_true',
+ parser.add_argument('-l', '--list', action='store_true',
help='list connected devices')
- parser.add_argument('-c' , '--convert', action='store_true',
+ parser.add_argument('-c', '--convert', action='store_true',
help='do not flash, just convert')
- parser.add_argument('-D' , '--deploy', action='store_true',
+ parser.add_argument('-D', '--deploy', action='store_true',
help='just flash, do not convert')
- parser.add_argument('-f' , '--family', dest='family', type=str,
- default="0x0",
- help='specify familyID - number or name (default: 0x0)')
- parser.add_argument('-C' , '--carray', action='store_true',
+ parser.add_argument('-w', '--wait', action='store_true',
+ help='wait for device to flash')
+ parser.add_argument('-C', '--carray', action='store_true',
help='convert binary file to a C array, not UF2')
parser.add_argument('-i', '--info', action='store_true',
help='display header information from UF2, do not convert')
@@ -309,6 +319,9 @@ def main():
except ValueError:
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:
list_drives()
else:
@@ -337,20 +350,23 @@ def main():
print("Converted to %s, output size: %d, start address: 0x%x" %
(ext, len(outbuf), appstartaddr))
if args.convert or ext != "uf2":
- drives = []
if args.output == None:
args.output = "flash." + ext
- else:
- drives = get_drives()
-
if args.output:
write_file(args.output, outbuf)
- else:
+ if ext == "uf2" and not args.convert and not args.info:
+ drives = get_drives()
if len(drives) == 0:
- error("No drive to deploy.")
- for d in drives:
- print("Flashing %s (%s)" % (d, board_id(d)))
- write_file(d + "/NEW.UF2", outbuf)
+ if args.wait:
+ print("Waiting for drive to deploy...")
+ while len(drives) == 0:
+ sleep(0.1)
+ drives = get_drives()
+ elif not args.output:
+ error("No drive to deploy.")
+ for d in drives:
+ print("Flashing %s (%s)" % (d, board_id(d)))
+ write_file(d + "/NEW.UF2", outbuf)
if __name__ == "__main__":