Modifying the memory layout

Each eCos platform package is supplied with linker script fragments which describe the location of memory regions on the evaluation board and the location of memory sections within these regions. The correct linker script fragment for a particular combination of target architecture, platform and start-up type is selected by pkgconf.tcl and is included in the eCos linker script target.ld when eCos is built.

It is not necessary to modify the default memory layouts in order to start development with eCos. However, it will be necessary to edit a linker script fragment when the memory map of the evaluation board is changed. For example, if additional memory is added, the linker must be notified that the new memory is available for use. As a minimum, this would involve modifying the length of the corresponding memory region. Where the available memory is non-contiguous, it may be necessary to declare a new memory region and reassign certain linker output sections to the new region.

Linker script fragments should be edited within the eCos build tree. They are located at pkgconf/*.ldi. For example, the fragment for ROM start-up is located at pkgconf/rom.ldi. Where multiple start-up types are in use, it will be necessary to edit multiple linker script fragments. A typical fragment is shown below:

Example 7-1. eCos linker script fragment

MEMORY
{
 rom : ORIGIN = 0x40000000, LENGTH = 0x80000
 ram : ORIGIN = 0x48000000, LENGTH = 0x200000
}

SECTIONS
{
 SECTIONS_BEGIN
 SECTION_rom_vectors (rom, 0x40000000, LMA_EQ_VMA)
 SECTION_text (rom, ALIGN (0x1), LMA_EQ_VMA)
 SECTION_fini (rom, ALIGN (0x1), LMA_EQ_VMA)
 SECTION_rodata (rom, ALIGN (0x1), LMA_EQ_VMA)
 SECTION_rodata1 (rom, ALIGN (0x1), LMA_EQ_VMA)
 SECTION_fixup (rom, ALIGN (0x1), LMA_EQ_VMA)
 SECTION_gcc_except_table (rom, ALIGN (0x1), LMA_EQ_VMA)
 SECTION_data (ram, 0x48000000, FOLLOWING (.gcc_except_table))
 SECTION_bss (ram, ALIGN (0x4), LMA_EQ_VMA)
 SECTIONS_END
}

The file consists of two blocks, the MEMORY block contains lines describing the address (ORIGIN) and the size (LENGTH) of each memory region. The MEMORY block is followed by the SECTIONS block which contains lines describing each of the linker output sections. Each section is represented by a macro call. The arguments of these macros are ordered as follows:

  1. The memory region in which the section will finally reside.

  2. The final address (VMA) of the section. This is expressed using one of the following forms:

    n

    at the absolute address specified by the unsigned integer n

    ALIGN (n)

    following the final location of the previous section with alignment to the next n-byte boundary

  3. The initial address (LMA) of the section. This is expressed using one of the following forms:

    LMA_EQ_VMA

    the LMA equals the VMA (no relocation)

    AT (n)

    at the absolute address specified by the unsigned integer n

    FOLLOWING (.name)

    following the initial location of section name

In order to maintain compatibility with linker script fragments exported by the eCos Configuration Tool, the use of other expressions within linker script fragments is not recommended.

Note that the names of the linker output sections will vary between target architectures. A description of these sections can be found in the specific GNUPro Toolkit Reference manual for your architecture.