3.1 Configuring a Bootloader Application

The standard start files used by the AVR GCC contain the interrupt vector table, initialize the AVR CPU and memory, and jump to main(). The current implementation of the bootloader does not use interrupts, so the start files are removed in order to keep the code as small as possible.

In this case, the main() is not called, so a function needs to be defined as entry point for the device to start execution properly.

The following code snippet shows an example of the boot() function which has all the needed attributes to be placed in the constructors section (.ctors) of the AVR GCC code project:

__attribute__((naked)) __attribute__((section(".ctors"))) void boot(void){ 
    /* Initialize system for C support */ 
    asm volatile("clr r1"); 
    /* Replace with bootloader code */ 
    while (1) 
    { 
        ;
    } 
}

As the function is not called using CALL/RET instructions but entered at start-up, the compiler is instructed by the naked attribute to omit the function prologue and epilogue. See the AVR GCC documentation for more details.

With AVR GCC, the standard start files are disabled by setting the linker flag -nostartfiles when compiling the project.

In Atmel Studio 7.0 this can be found in Project Properties (Alt+F7) → Toolchain → AVR/GNU Linker → General, as shown in the figure below.

Figure 3-1. Disabling Standard Files, Atmel Studio 7.0

In MPLAB X, this can be found in File → Project Properties → Conf → Avr GCC (Global Options) → avr-ld → General, as shown in the figure below.

Figure 3-2. Disabling Standard Files, MPLAB® X
Note: