The initialization code/data from within the C library that does the copying from load to execution addresses must be placed in a root region (i.e. one which executes at its load address). This is because this code/data cannot itself be copied. This means that the scatter description file must have at least one root region that must contain:
- The copying code from the library member called __main.o.
- Sections named Region$$Table and ZISection$$Table which contain the addresses of the code/data to be copied. These sections are generated by the linker so they do not have a corresponding object file (so * must be used when placing these in a scatter file).
If these sections named Region$$Table and ZISection$$Table are not placed in a root region then the linker will report:
Error: L6202E: Section Region$$Table cannot be assigned to a non-root region. Error: L6202E: Section ZISection$$Table cannot be assigned to a non-root region.
In many cases this code/data may be placed in a root region by use of a wildcard *(+RO) that gathers all non-explicitly placed code/data. However in some circumstances, this wildcard may need to be placed in a non-root region, in which case a scatter file similar to the one below may be used.
Example scatter file for ADS and RVCT 2.0:
LOAD_FLASH 0x04000000 0x80000 ;start address and length { EXEC_FLASH 0x04000000 0x80000 { init.o (Init,+FIRST) ; remap & init code __main.o (+RO) ; copy code * (Region$$Table) ; RO/RW addresses to copy * (ZISection$$Table) ; ZI addresses to zero } EXEC_32bitRAM 0x0000 0x2000 { vectors.o (Vect,+FIRST) ; vector table int_handler.o (+RO) ; interrupt handler } EXEC_16bitRAM 0x2000 0x80000 { * (+RO) ; ## all other RO areas ## * (+RW,+ZI) ; program variables } }
For RVCT 2.1 and later, an alternative way is to specify these sections using
InRoot$$Sections
:LOAD_FLASH 0x04000000 0x80000 ;start address and length { EXEC_FLASH 0x04000000 0x80000 { init.o (Init,+FIRST) ; remap & init code * (InRoot$$Sections) ; using InRoot$$Sections } ... }
An application's initial entry point must also be rooted. If the initial entry point is not in a root region, the link will fail with an error such as:
Error: L6203E: Entry point (0x08000000) lies within non-root region EXE_FLASH.
Reference:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0474g/BABEJHII.html
http://www.keil.com/support/man/docs/armlink/armlink_pge1362065974588.htm
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3552.html