Creating ELF Files with Other Memory Types

ELF files that contain data for all memory types can be made with the GCC compiler. The data sections are specified in code as shown in following code examples.

Creating ELF Files for tinyAVR, megaAVR, and XMEGA devices

This code shows how to add memory sections for tinyAVR, megaAVR, and XMEGA devices (except ATtiny4/5/9/10). This example is for an ATxmega128A1 device. For other devices, it has to be modified accordingly.

#include <avr/io.h>
  
// Example data for ATxmega128A1
const char eeprdata[] __attribute__ ((section (".eeprom"))) = 
    "Hello EEPROM";
// The order of the fuse values is from low to high. 0xA2 is written to Fuse byte 0, 0x00 to byte 1...
const uint8_t fusedata[] __attribute__ ((section (".fuse"))) = 
    {0xA2, 0x00, 0xFF, 0xFF, 0xFF, 0xF5};
const uint8_t lockbits[] __attribute__ ((section (".lockbits"))) = 
    {0xFC};
const char userdata[] __attribute__ ((section (".user_signatures"))) = 
    "Hello User Signatures";
      
// Remember to set the following Toolchain project options, 
// under AVR/GNU -> Miscellaneous:
//
//   -Wl,--section-start,.user_signatures=0x00850000
      
int main(void) 
{
    while(1)
    {
        // TODO:: Please write your application code
    }
 }

Linker setup for User Signature section

The User Signatures section must have a specific Linker Setup, as shown below. This is necessary to get the correct address offset for the User Signature section in the elf file. Other memory sections get the correct address automatically.

Figure 1. Linker Setup for User Signature Section

Creating ELF Files for ATtiny4/5/9/10

This code shows how to add memory sections for ATtiny10.

#include <avr/io.h>

typedef struct _tagConfig
{
    unsigned char f1;
} Config;

typedef struct _tagLock
{
    unsigned char f1;
} Lock;

typedef struct _tagSig
{
    unsigned char f1;
    unsigned char f2;
    unsigned char f3;
} Signature;

Config __config __attribute__((section(".config"))) =
{
    f1 : 0xfb, // Set CKOUT
};

Lock __lock __attribute__((section(".lock"))) =
{
    f1 : 0xfc, // Further programming and verification disabled
};

Signature __sig __attribute__((section(".signature"))) =
{
    f1 : 0x03,
    f2 : 0x90,
    f3 : 0x1e,
};

int main(void)
{
    while(1)
    {
        // TODO:: Write your application code
    }
}

Creating ELF Files for UC3

The example below shows how to add data for the user page in UC3 devices.

#include <avr/io.h>

const char userdata[] __attribute__((section(".userpage"))) = "Hello Page";

int main(void)
{
    while(1)
    {
        //TODO:: Write your application code
    }
}

Project Properties

If the memory sections are defined but not referenced in the application code, the 'Garbage collect unused sections' option in Project Properties → Linker → Optimization must be unchecked. Otherwise, the linker will not include the sections in the .elf file.

Figure 2. Project Properties