2.4. Generating .hex Files

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 rom.hex using the following command:

    % avr-objcopy -j .text -O ihex demo.out rom.hex

The resulting .hex file contains:

    :100000000AC021C020C01FC01EC01FC01CC01BC012
    :100010001AC019C018C011241FBE20E0A89521BD28
    :1000200020E025BFE4EFF0E0A0E6B0E003C0C89513
    :1000300031960D92A437D9F7A4E7B0E001C01D9224
    :10004000A837E9F750C000C018951F920F920FB65D
    :100050000F9211242F938F939F938091760090910C
    :100060007700009791F0019711F5809174009091BD
    :10007000750001979093750080937400892BB9F4F3
    :1000800080916000909161000EC080917400909109
    :100090007500019690937500809374008F5F934074
    :1000A00031F481E090E09093770080937600809126
    :1000B0007400909175009BBD8ABD9F918F912F9187
    :1000C0000F900FBE0F901F90189583E88FBD81E0B1
    :1000D0008EBD80E090E09BBD8ABD88E087BB80E854
    :1000E00089BF78940895CFEDD0E0DEBFCDBFEDDFBE
    :0400F000FFCFFFCF70
    :00000001FF

The -j option indicates that we want the information from the .text 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 -O ihex demo.out eeprom.hex

The resulting .hex file contains:

    :00000001FF

which is an empty .hex file (which is expected, since we didn't define any EEPROM variables.)