Anatomy of AVR hex file

The eventual output of any AVR compiler like Arduino, GCC, AVR studio is an ‘Intel Hex file’ that gets loaded into the AVR flash memory by the ISP tool. So understanding this hex file is good if you are trying to debug some deeper AVR issues.

Lets take a line from the new Arduino Optiboot bootloader hex code.

:107E000011E0A0E0B1E0E0E1F0E802C005900D92E1

Lets add some delimiters to improve our understanding

:[10] [7E00] [00] 11E0A0E0B1E0E0E1F0E802C005900D92 [E1]

The first identifier is the “:” indicating the start of the record

Then comes [10] which is 0x10 indicating the number of bytes for the record. In this case it is 16bytes

Next is starting address [7E00] or 0x7E00. At first glance you would think that this exceeds the range of
say Atmega328p whose address range is 0x0000-0x3FFF. But its data width is 16-bits or 2-bytes. And intel hex
record is always byte addressed. So 0x7E00/2 = 0x3F00 which is the starting address of the bootloader section
(if you programmed the fuse bits for 512bytes).

The next is data type record. [00] indicates data. You can also have other record types.

The last field [E1] is the checksum.

The string in the middle represents the actual data that gets programmed into the flash memory…

0x7E00 = 0x11
0x7E01 = 0xE0
0x7E02 = 0xA0
0x7E03 = 0xE0

Now AVR is ‘little endian’ achitecture. And instruction width is 16-bits. So in the above case,
first instruction at 3F00 would be 0xE011 and next instruction at 3F01 would be 0xE0A0

Advertisements
About

I am a computer engineer living in the beautiful city of Austin,TX. While my day job is designing computer chips, I love to dabble in woodworking, metalworking, r/c and electronics.

Tagged with: , ,
Posted in Electronics

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
Categories
%d bloggers like this: