Linking a ROM Image

The table below compares the differences between the linker's default RAM image layout and how you should configure your program for loading into and running from ROM.

Table 1. Comparing RAM and ROM images
RAM image properties ROM image properties
The S record file contains executable code, constants, and initialization values for data. One or more memory areas defined in the linker's .lcf file specifies where store the program image in the target system's memory map.
Executable code, constants, and data are loaded for execution by the debugger or the program loader. Initialization values for data are copied from the ROM image to RAM at program startup. Executable code and constant data may also be copied to RAM to improve performance (while requiring more RAM space).

The linker's output ELF file for a ROM image contains a segment named .PPC.EMB.seginfo. This segment describes which segments in the image will be copied from ROM to RAM at runtime. The linker uses this non-loadable segment to generate a data structure named _rom_copy_info . At startup, the program uses the _rom_copy_info structure to determine which segments to move from ROM to RAM.

Example of segments to copy to RAM at startup shows the part of an example disassembly that lists the contents of segment .PPC.EMB.seginfo. When is_rom_copy is set to 1, the corresponding segment is copied from ROM to its final destination during startup. In this example, these sections will be copied from ROM to RAM at startup:

.bss, .data, .sdata, .sbss, .sdata2.
  
Figure 1. Example of segments to copy to RAM at startup
    entry  is_rom_copy  name            ram index
    [   0] 0            .abs.00010000   0 
    [   1] 0            .reset          0 
    [   2] 0            .init           0 
    [   3] 0            .text           0 
    [   4] 0            .rodata         0 
    [   5] 0            .dtors          0 
    [   6] 1            .bss            7 
    [   7] 0            .bss            0 
    [   8] 1            .data           9 
    [   9] 0            .data           0 
    [  10] 1            .sdata         11 
    [  11] 0            .sdata          0 
    [  12] 1            .sbss          13 
    [  13] 0            .sbss           0 
    [  14] 1            .sdata2        15 
    [  15] 0            .sdata2         0