11.4 Locating and Reserving Program Memory

In this example, a block of program memory is reserved for a special purpose, such as a bootloader. An arbitrary sized function is allocated in the block, with the remaining space reserved for expansion or other purposes.

The following output section definition is added to a custom linker script:
BOOT_START = 0x9d00A200;
BOOT_LEN = 0x400;
my_boot BOOT_START :
{
*(my_boot);
. = BOOT_LEN; /* advance dot to the maximum length */
} > kseg0_program_mem

Note the “dot assignment” (.=) that appears inside the section definition after the input sections. Dot is a special variable that represents the location counter, or next fill point, in the current section. It is an offset relative to the start of the section. The statement in effect says “no matter how big the input sections are, make sure the output section is full size.”

The following C function will be allocated in the reserved block:
void __attribute__((section("my_boot"))) func1()
{
  /* etc. */
}
The equivalent assembly language would be:
.section        my_boot,code
         .align  2
         .globl  func1
func1:
         ...