First, the code should be put into a new named section. This is done with a section attribute:

__attribute__ ((section (".bootloader")))

In this example, .bootloader is the name of the new section. This attribute needs to be placed after the prototype of any function to force the function into the new section.

void boot(void) __attribute__ ((section (".bootloader")));

To relocate the section to a fixed address the linker flag --section-start is used. This option can be passed to the linker using the -Wl compiler option:

-Wl,--section-start=.bootloader=0x1E000

The name after section-start is the name of the section to be relocated. The number after the section name is the beginning address of the named section.

Back to FAQ Index.