Skip to content

Commit 7c9a0eb

Browse files
author
Emilie Gillet
committed
Hexfile reader handles files >= 64kb
1 parent f84119a commit 7c9a0eb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/hexfile/hexfile.py

100644100755
+10-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
def LoadHexFile(lines):
2929
"""Loads a Hex file."""
30-
30+
base_address = None
31+
offset = 0
3132
data = []
3233
for line_number, line in enumerate(lines):
3334
line = line.strip()
@@ -55,11 +56,18 @@ def LoadHexFile(lines):
5556
else:
5657
break
5758
elif bytes[3] == 0:
58-
address = bytes[1] << 8 | bytes[2]
59+
address = offset << 16 | bytes[1] << 8 | bytes[2]
5960
padding_size = address + bytes[0] - len(data)
6061
if padding_size > 0:
6162
data += [0] * padding_size
6263
data[address:address + bytes[0]] = bytes[4:-1]
64+
elif bytes[3] == 4:
65+
address = bytes[4] << 8 | bytes[5]
66+
if base_address is None:
67+
base_address = address
68+
offset = 0
69+
else:
70+
offset = address - base_address
6371
return data
6472

6573

0 commit comments

Comments
 (0)