diff --git a/utils/uf2conv.py b/utils/uf2conv.py index c658081..013451d 100755 --- a/utils/uf2conv.py +++ b/utils/uf2conv.py @@ -33,23 +33,52 @@ def is_hex(buf): return True return False +def uf2_blocks(buf): + numblocks = len(buf) // 512 + outp = [] + for blockno in range(numblocks): + ptr = blockno * 512 + block = buf[ptr:ptr + 512] + hd = struct.unpack(b" 1 and familyid == 0x0: - outp = [] - appstartaddr = 0x0 + + print("--- UF2 File Header Info ---") + families = load_families() + for family_hex in families_found.keys(): + family_short_name = "" + for name, value in families.items(): + if value == family_hex: + family_short_name = name + print("Family ID is {:s}, hex value is 0x{:08x}".format(family_short_name,family_hex)) + print("Target Address is 0x{:08x}".format(families_found[family_hex])) + if all_flags_same: + print("All block flag values consistent, 0x{:04x}".format(hd[2])) + else: + print("Flags were not all the same") + print("----------------------------") + if len(families_found) > 1 and familyid == 0x0: + outp = [] + appstartaddr = 0x0 + return b"".join(outp) def convert_to_carray(file_content): @@ -273,7 +303,7 @@ def error(msg): print(msg, file=sys.stderr) sys.exit(1) parser = argparse.ArgumentParser(description='Convert to UF2 or flash directly.') - parser.add_argument('input', metavar='INPUT', type=str, nargs='?', + 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, default="0x2000", @@ -297,6 +327,8 @@ def error(msg): 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') + parser.add_argument('-j', '--join', action='store_true', + help='concatenate multiple UF2 files into one') args = parser.parse_args() appstartaddr = int(args.base, 0) @@ -313,14 +345,20 @@ def error(msg): if args.list: list_drives() else: - if not args.input: - error("Need input file") - with open(args.input, mode='rb') as f: - inpbuf = f.read() + if len(args.input) == 0: + error("Need input file(s)") + inpbuf = b"" + for fn in args.input: + with open(fn, mode='rb') as f: + inpbuf += f.read() from_uf2 = is_uf2(inpbuf) ext = "uf2" if args.deploy: outbuf = inpbuf + elif args.join: + if not from_uf2: + error("--join requires UF2 files") + outbuf = concat_uf2(inpbuf) elif from_uf2 and not args.info: outbuf = convert_from_uf2(inpbuf) ext = "bin"