8.4 Creating ROM Images

This section gives an outline of the creation of ROM images that are required for embedded applications.

External and static variables defined in applications are allocated to sections in RAM. If these variables have been initialized, their initial values must be present in RAM when the corresponding application is started.

On the other hand, values in RAM are undefined when the hardware is started up or following a reset. For this reason, the initial values of variables need to have been stored in RAM by the time an application is started after the hardware has been reset.

CC-RL allows the creation of a ROM image that defines how the program code and initial values are allocated to ROM. When the program is run, the initial values in the ROM image are copied to RAM within the startup routine. This initializes the RAM.

Program code in ROM may also have to be placed in RAM in the case of self-programming code. Copying of the program code to RAM is to be done within the startup routine in the same manner as the copying of initial values.

 

When data are to be copied from ROM to RAM, use the -rom option of the optimizing linker.

-rom=name of the initial-value section=name of the destination section

 

When the function to automatically allocate sections is not specified in the linker, the addresses of the initial-value section and destination section need to be specified by the -start option. When the function to automatically allocate sections is specified in the linker, addresses do not have to be specified by the -start option.

-start=section-name[,section-name]/destination-address

 

It is assumed that the user program contains sections .text, .textf, .RLIB, .SLIB, .const, .constf, .data, .sdata, .stack_bss, .bss, and .sbss. When locating .text at address 0x100, .const at address 0x2000, reallocation attribute DATA and BSS sections at address 0xfe000, reallocation attribute SDATA and SBSS sections at address 0xffe20 at program execution, the code will be as follows.

-start=.text/100
-start=.const,.RLIB,.SLIB,.textf,.constf,.data,.sdata/2000
-start=.dataR,.bss,.stack_bss/FE000
-start=.sdataR,.sbss/FFE20
-rom=.data=.dataR,.sdata=.sdataR

 

The section names .dataR and .sdataR to which data is to be copied can be different names but they need to match the code in the startup routine. At program execution, data is copied from .data to .dataR and from .sdata to .sdataR, and .bss and .sbss are initialized before they are used.

 

An image of this operation is shown below.

Figure 8.1

Image before and after Copying