We have a binary of the application, but how do we get it into the processor? Most (if not all) programmers will not accept a GNU executable as an input file, so we need to do a little more processing. The next step is to extract portions of the binary and save the information into .hex files. The GNU utility that does this is called avr-objcopy.

The ROM contents can be pulled from our project's binary and put into the file demo.hex using the following command:

$ avr-objcopy -j .text -j .data -O ihex demo.elf demo.hex

The resulting demo.hex file contains:

:1000000020E0A0E6B0E001C01D92A336B207E1F700 :100010001F920F920FB60F9211242F938F939F93DD :1000200080916200882301F1813081F48091600029 :100030009091610001979093610080936000009718 :1000400049F41092620080E090E004C0809160006A :10005000909161009BBD8ABD9F918F912F910F90D0 :100060000FBE0F901F9018958091600090916100D5 :10007000019690936100809360008F3F23E0920788 :1000800049F781E0809362008FEF93E0E3CF83E84C :100090008FBD8EB581608EBD1BBC1ABC82E087BB54 :1000A00084E089BF7894089583E88FBD8EB5816020 :1000B0008EBD1BBC1ABC82E087BB84E089BF7894EC :1000C00085B7806885BF889585B78F7785BFF8CF5E :0800D000F89400C0F894FFCF82 :00000001FF

The -j option indicates that we want the information from the .text and .data segment extracted. If we specify the EEPROM segment, we can generate a .hex file that can be used to program the EEPROM:

$ avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex demo.elf demo_eeprom.hex

There is no demo_eeprom.hex file written, as that file would be empty.

Starting with version 2.17 of the GNU binutils, the avr-objcopy command that used to generate the empty EEPROM files now aborts because of the empty input section .eeprom, so these empty files are not generated. It also signals an error to the Makefile which will be caught there, and makes it print a message about the empty file not being generated.