2.2.1 Standard Start Files in the Bootloader
The standard start files used by AVR GCC contain the interrupt vector table,
initialize the AVR CPU and memory, and jump to ‘main()
’. If interrupts
are not used by the bootloader, the start files can be removed to keep the code as small
as possible.
main()
’ is not
called, so a function needs to be defined and entered as the device starts executing.
The following code snippet shows an example ‘boot()
’ function with
needed initialization 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 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 seen in Figure 2-3.