Verified this works fine on Microchip PIC IHEX files previously.
I did not include an equivalent function for emitting record 0x04 because I didn't need it/have time to add it, and I'm not certain in how emitting 0x04 should work.
*output_data function only works with contiguous byte arrays, whereas IHEX would be perfectly fine w/ gaps. The easiest way is to simply delineate 64kb boundaries and add a 0x04 record every time a 64kb boundary is crossed, but this is wasteful. I'd been using the following conversion function in my own scripts to test IHEX gaps. Feel free to adjust to your needs:
# Assumes: Every range of data provided has some discontiguous bytes between
# the regions; input_data should've taken care of this.
def offset_dat_to_list(dat, offset, trim, fill):
out = []
raw_prefix = [fill for i in range(offset)] if not trim else []
prev_o = 0
prev_l = 0
first = True
rec_prefix = []
rec_buf = []
for o, b in sorted(dat, key=lambda d: d[0]):
if first:
# First record will trivially pass assert, and we don't want
# fill bytes- that's offset/trim's job.
first = False
else:
start_fill = prev_o + prev_l
assert o > start_fill, "Contiguous region was marked as discontiguous."
rec_prefix = [fill for i in range(o - start_fill)]
if
rec_buf = rec_prefix + b
out += rec_buf
prev_o = o
prev_l = len(b)
return bytes(raw_prefix + out)
Verified this works fine on Microchip PIC IHEX files previously.
I did not include an equivalent function for emitting record
0x04
because I didn't need it/have time to add it, and I'm not certain in how emitting0x04
should work.*
output_data
function only works with contiguous byte arrays, whereas IHEX would be perfectly fine w/ gaps. The easiest way is to simply delineate 64kb boundaries and add a0x04
record every time a 64kb boundary is crossed, but this is wasteful. I'd been using the following conversion function in my own scripts to test IHEX gaps. Feel free to adjust to your needs: