diff options
| author | Joel Challis <git@zvecr.com> | 2023-05-25 23:07:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-25 23:07:47 +0100 |
| commit | 873922d98fea19f872ed8c5c79a20ed575ccff44 (patch) | |
| tree | 6c9817d35e7a0d7b9f4f93007c47629b5c8f3ea0 /util/uf2conv.py | |
| parent | ed69d78f27a384bca11f2d815224083120941580 (diff) | |
Implement UF2 device type id extension tag (#21029)
Diffstat (limited to 'util/uf2conv.py')
| -rwxr-xr-x | util/uf2conv.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/util/uf2conv.py b/util/uf2conv.py index 52d3861cba..578b2b4977 100755 --- a/util/uf2conv.py +++ b/util/uf2conv.py | |||
| @@ -151,10 +151,15 @@ class Block: | |||
| 151 | flags = 0x0 | 151 | flags = 0x0 |
| 152 | if familyid: | 152 | if familyid: |
| 153 | flags |= 0x2000 | 153 | flags |= 0x2000 |
| 154 | if devicetype: | ||
| 155 | flags |= 0x8000 | ||
| 154 | hd = struct.pack("<IIIIIIII", | 156 | hd = struct.pack("<IIIIIIII", |
| 155 | UF2_MAGIC_START0, UF2_MAGIC_START1, | 157 | UF2_MAGIC_START0, UF2_MAGIC_START1, |
| 156 | flags, self.addr, 256, blockno, numblocks, familyid) | 158 | flags, self.addr, 256, blockno, numblocks, familyid) |
| 157 | hd += self.bytes[0:256] | 159 | hd += self.bytes[0:256] |
| 160 | if devicetype: | ||
| 161 | hd += bytearray(b'\x08\x29\xa7\xc8') | ||
| 162 | hd += bytearray(devicetype.to_bytes(4, 'little')) | ||
| 158 | while len(hd) < 512 - 4: | 163 | while len(hd) < 512 - 4: |
| 159 | hd += b"\x00" | 164 | hd += b"\x00" |
| 160 | hd += struct.pack("<I", UF2_MAGIC_END) | 165 | hd += struct.pack("<I", UF2_MAGIC_END) |
| @@ -283,6 +288,8 @@ def main(): | |||
| 283 | parser.add_argument('-f', '--family', dest='family', type=str, | 288 | parser.add_argument('-f', '--family', dest='family', type=str, |
| 284 | default="0x0", | 289 | default="0x0", |
| 285 | help='specify familyID - number or name (default: 0x0)') | 290 | help='specify familyID - number or name (default: 0x0)') |
| 291 | parser.add_argument('-t' , '--device-type', dest='devicetype', type=str, | ||
| 292 | help='specify deviceTypeID extension tag - number') | ||
| 286 | parser.add_argument('-o', '--output', metavar="FILE", dest='output', type=str, | 293 | parser.add_argument('-o', '--output', metavar="FILE", dest='output', type=str, |
| 287 | help='write output to named file; defaults to "flash.uf2" or "flash.bin" where sensible') | 294 | help='write output to named file; defaults to "flash.uf2" or "flash.bin" where sensible') |
| 288 | parser.add_argument('-d', '--device', dest="device_path", | 295 | parser.add_argument('-d', '--device', dest="device_path", |
| @@ -312,6 +319,9 @@ def main(): | |||
| 312 | except ValueError: | 319 | except ValueError: |
| 313 | error("Family ID needs to be a number or one of: " + ", ".join(families.keys())) | 320 | error("Family ID needs to be a number or one of: " + ", ".join(families.keys())) |
| 314 | 321 | ||
| 322 | global devicetype | ||
| 323 | devicetype = int(args.devicetype, 0) if args.devicetype else None | ||
| 324 | |||
| 315 | if args.list: | 325 | if args.list: |
| 316 | list_drives() | 326 | list_drives() |
| 317 | else: | 327 | else: |
