This is a small library to help decode Intel HEX records. This file format is frequently used for firmware images on microcontrollers.
The main interface returns a lowlevel view of the records:
iex> records = IntelHex.decode_file!("test/test.hex")
[
%IntelHex.Record{address: 0, data: [0, 0], type: :extended_linear_address},
%IntelHex.Record{
address: 0,
data: [2, 24, 0, 2, 24, 3, 8, 253, 9, 2, 0, 2, 24, 11, 11, 50],
type: :data
},
%IntelHex.Record{
address: 16,
data: [11, 60, 34, 2, 24, 19, 10, 236, 11, 0],
type: :data
},
...
%IntelHex.Record{address: 0, data: [], type: :eof}
]
If you'd like the records to be flattened back into a memory image, you can run IntelHex.flatten_to_list/2
against the records:
iex(2)> IntelHex.flatten_to_list(records)
[2, 24, 0, 2, 24, 3, 8, 253, 9, 2, 0, 2, 24, 11, 11, 50, 11, 60, 34, 2, 24, 19,
10, 236, 11, 0, 255, 2, 24, 27, 70, 154, 2, 29, 225, 2, 24, 35, 228, 255, 225,
64, 255, 2, 24, 43, 127, 7, 34, 211, ...]
IntelHex.flatten_to_list/2
takes keyword parameters to specify start offsets and default fill bytes for skipped locations. The default filler byte is 255 which can be seen in the above examples if you squint hard enough.
If available in Hex, the package can be installed
by adding intel_hex
to your list of dependencies in mix.exs
:
def deps do
[
{:intel_hex, "~> 0.1.0"}
]
end
The library has a couple major missing features:
- Support for anything besides 16-bit Intel Hex files
- Encoder support
I don't currently have a use case for those, but if you do, I'd certainly work with you to get these included.