What are HEX file?
I have been programming microcontroller for the past 6 years and I was always curious what is happening at the lowest level. They are ofcourse they hold some of binary content in them and modern IDEs takes care them. I honestly never really bothered to look into their significance. But recently I had to dissect the hex file and look for some important information.
Firstly, to resolve the confusion, binary files are different from hex files. Seriously, I used to think they were the same all this time. There are some tools which can convert HEX files to Binary format.
Binary files are the file that contain the flash content that needs to be written into onto the flash. They contain NO OTHER information other than that. However, HEX files are a bit different in terms of what they contain, though they contain the same information that a binary files would.
Hex files are formated in a specific way that all the information needed to flash the microcontroller is stored in it. For example, content that needs to be flashed at a certain region in the memory.
HEX File Format
: NN AAAA TT DDD… CC
NN - number of bytes present in the line AAAA - address of the first byte present in the data field TT - type (shown below in detail) DD… - number of data bytes specified by NN (content) CC - check bits (calculation is shown below)
TT Field:
00 - content is data 01 - EOF line 02 - extended segment address
:02 xxxx 02 yyyy CC
xxxx
yyyy
--------
yyyyxxxx -> absolute memory address
--------
04 - extended linear address
:02 xxxx 04 yyyy CC
xxxx
yyyy
--------
ykkkk -> absolute memory address
--------
05 - start linear address record
Reference
http://www.keil.com/support/docs/1584/