This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Intel HEX file and map file

Hello everybody.
I would know if a way exixts to find a match between the map file (where the memory allocation is illustrated) produced at the end of the compilation and the HEX file (that I download on my target).
I mean, the HEX file is composed by HEX records (each line of it) where the 4 hex digits, after the two representing the length, stand for the address.
But I am not able to find a match between these addresses and the one on the map file.
Could anyone help?

I can put the question in a different way, explaining what I should do, in order to have alternative suggestions.
I would edit the HEX file (for example running a script file) generating n-HEX files starting from it, where each one of it has modified a specific variable (for example representing the Identifier of the system where downloading the HEX file). But to do so, I was thinking to put the variable that represents this Identifier in a fixed and known location, then searching it on the HEX file and modifying according to my needs.
But, how I told before, I find the variable on the map file of course, but I am not able to find it on the HEX file.
Thanks to all.

  • First off, you can't do it with a normal variable, since a variable is not represented in the hex file. The hex file only covers the address range of data placed in the flash (or, for some chips also data stored in EEPROM).

    You must declare your variable as const and stored in the code segment.

    Then you have to realize that each hex line only mentions the address of the first byte on the line. Another thing is that each HEX line only has a 16-bit offset. For processors with more than 64kB of code, there will be special records that points to the start of a code segment to allow the hex file to address more than 64kB.

  • You could create a variable/string/section located at a certain location, using the linker, perhaps with default information inside it, and use your scripts to overwrite the specific information with your custom data. I.e. reserve a memory buffer at a specific memory location and modify it at HEX level. Not sure how to do this for ARM though, sorry.

    The srecord tool might be useful to manipulate the HEX files, see srecord.sourceforge.net/.

  • If you can compromise on the requirement to do the modification at the end of the build, you can make your life so much easier by writing the flash while your program is running (IAP), maybe based on data coming in via a communication port...?

  • In other words:

    - Have a variable point to a buffer at a certain location, possibly with default info, generate the application HEX file.

    - Create a module/"app" with a linker file that says it will be placed in the memory slot, generate the HEX file. You can do this for each custom piece of data.

    - Use scripts to merge the application HEX file with the custom data HEX file and create the final image you can flash.

  • Thanks all! I appreciate it very much.
    I am going to analyze all the suggestions you are giving.

  • In a number of projects, I have placed special data absolutely last in the flash. For example a crc32 of the image together with a version string an possibly a serial number.

    This allows a transfer program to dynamically produce the downloaded image for each individual unit. When running, the application may compute the crc32 value for the full flash minus (for example) the last 32 bytes and then compare with the stored value at the end. Of the crc32 value may instead be augmented so that a crc32 of the full flash should always evaluate to 0.