Skip to content

Commit

Permalink
Hexfile reader handles files >= 64kb
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilie Gillet committed Jun 5, 2019
1 parent f84119a commit 7c9a0eb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tools/hexfile/hexfile.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

def LoadHexFile(lines):
"""Loads a Hex file."""

base_address = None
offset = 0
data = []
for line_number, line in enumerate(lines):
line = line.strip()
Expand Down Expand Up @@ -55,11 +56,18 @@ def LoadHexFile(lines):
else:
break
elif bytes[3] == 0:
address = bytes[1] << 8 | bytes[2]
address = offset << 16 | bytes[1] << 8 | bytes[2]
padding_size = address + bytes[0] - len(data)
if padding_size > 0:
data += [0] * padding_size
data[address:address + bytes[0]] = bytes[4:-1]
elif bytes[3] == 4:
address = bytes[4] << 8 | bytes[5]
if base_address is None:
base_address = address
offset = 0
else:
offset = address - base_address
return data


Expand Down

0 comments on commit 7c9a0eb

Please sign in to comment.