Context: After bootloading a .hex file into our microcontroller, I want to use a CRC to verify that the program memory was properly written. Therefore, I need to compute the CRC on the host computer prior to downloading the .hex file into the microcontroller.
The goal: given a program on the host computer that takes as inputs:
* a well-defined CRC algorithm (the actual choice of CRC is not important for this question)
* a .hex file that contains binary data to be loaded into the microcontroller, with possibly discontinuous address segments
* a starting address and number of bytes over which to run the CRC algo
... compute the CRC for that memory range.
The question: Are there any techniques or utilities that will help me compute the CRC over that address range from the .hex file?
I initially thought this would be easy: just decode each data byte in the .hex file, if it is within the address range, pass it to the CRC algo.
But then I realized that .hex files can have discontinuous sections, and since the CRC algorithms are sensitive to the order in which bytes are fed to them, out-of-order sections would spoil the computation.
The best idea I've come up with is to allocate an array on the host computer, parse the .hex file and write only those bytes within the target address range into the array. After the entire .hex file is read, then run the CRC algo other the array.
How would you handle this?