ARM Cortex-M Scatter Loading
-Aviral Mittal avimit att yahu dat cam.
https://www.linkedin.com/in/avimit/
SITE HOME

Scatter-Loading:
In the previous section we learned about how the sections of a executable binary file can have different load addresses and execution addresses.
In this section the user will learn how to place the different sections of the code at different (desired locations) in the memory map.
The placement of different sections of the code is typically done using a mechanism called 'Scatter-Loading'. I think the name comes from the fact that the user is now trying to 'scatter' their code all over the memory space.

From the previous section, we also learned that for any C-program to run on an embedded system, there shall be at a bare-minimum
This can be done using what is called 'Scatter-Load File', and example of which is shown below:

scatter.sct file:
1 LR_IROM1 0x00000000 0x00080000  {
2   ER_IROM1 0x00000000 0x00080000  {
3    *.o (RESET, +First)
4    *(InRoot$$Sections)
5    .ANY (+RO)
6   }
7   RW_IRAM1 0x20000000 0x00010000  {  ; RW data
8    .ANY (+RW +ZI)
9   }
10 }

Another Elaborate view of the Scatter-Load file can be found here:

A Scatter load defines 1 or more load regions, and each Load region can contain 1 or more execution regions.

A load region description specifies the region of memory where its child execution regions are to be placed.
In the above shown scatter-load file, the user defines
When the above 'scatter.sct' file is used with ARM command line tools, or by Keil uVision tools, the binary executable file will be produced which will follow or adhere to the rules defined in this scatter load file. That is to say that all the r/w data will be moved/initialized into r/w region at the bare-minimum, and the code will start executing XIP from 0x0.

The above example shows a very simple Scatter-Loading file. The same effect can be achieved by not using a Scatter loading file, and just using -RO and -RW linker options on command line as well. So why use Scatter-Loading mechanism.

When the memory map gets too complex, to be handled just be throwing linker options, the Scatter-load file comes in very handy. Then when the user writes programs for ARM v8.1 Main, with TrustZone, the use of scatter-load files becomes a very convenient way to separate the sections of code into secure and non secure memory regions.

Following is an example arm linker command which uses a scatter load file called 'scatter.sct'
/pkg/ARM/6.13/bin/armlink a.o c.o ns_bin.o --keep=ns_bin.o\(section_ns_bin\) --map --load_addr_map_info --list=image.lst --scatter=scatter.sct --entry Reset_Handler

Time to do some Practicals, Click here:

Click Here to Make Comments or ask Questions
                                                                      
<= PREV  : XIP (Execute-in-Place)                      Next => Scatter Loading Practical Example: