Skip to content

Commit

Permalink
tools: Update makecombinedhex to put script between MicroPython and UICR
Browse files Browse the repository at this point in the history
Newer versions of DAPLink (since 0241) require addresses in a .hex to be
sequential.
  • Loading branch information
carlosperate authored and dpgeorge committed Sep 19, 2018
1 parent 60e5e3d commit 418b60a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tools/makecombinedhex.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def get_largest_addr(hexfile):
largest_addr = max(largest_addr, page + addr + count)
return largest_addr

def find_uicr_line(hexfile):
for i, line in enumerate(hexfile):
# UICR from 0x10001000 so we expect an extended linear address record
if ':020000041000EA' in line:
return i
return None

if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(description='Produce combined hex firmware for the micro:bit.')
arg_parser.add_argument('-o', '--output', default=sys.stdout, type=argparse.FileType('wt'), help='output file (default is stdout)')
Expand All @@ -46,13 +53,14 @@ def get_largest_addr(hexfile):
with open(args.script[0], 'rb') as f:
script = hexlifyscript.hexlify_script(f.read())

# print head of firmware
for line in firmware[:-2]:
# print lines until UICR area or the start linear address record
firmware_end = find_uicr_line(firmware) or len(firmware) - 2
for line in firmware[:firmware_end]:
print(line, end='', file=args.output)

# print script
print(script, file=args.output)

# print tail of firmware
print(firmware[-2], end='', file=args.output)
print(firmware[-1], end='', file=args.output)
# print rest of hex file
for line in firmware[firmware_end:]:
print(line, end='', file=args.output)

0 comments on commit 418b60a

Please sign in to comment.