ARM Compiler toolchain Using the Linker - ARM Information Center
ARM Compiler toolchain Using the Linker - ARM Information Center
ARM Compiler toolchain Using the Linker - ARM Information Center
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Using</strong> scatter files<br />
RAM 0x200000 (0x1FF00-0x2000) ; RW & ZI data to be placed at 0x200000<br />
{<br />
*(+RW, +ZI)<br />
}<br />
<strong>ARM</strong>_LIB_STACK 0x800000 EMPTY -0x10000<br />
{<br />
}<br />
<strong>ARM</strong>_LIB_HEAP +0 EMPTY 0x10000<br />
{<br />
}<br />
}<br />
The <strong>ARM</strong>_LIB_STACK and <strong>ARM</strong>_LIB_HEAP regions are required because <strong>the</strong> program is being<br />
linked with <strong>the</strong> semihosting libraries.<br />
4. Compile and link <strong>the</strong> sources:<br />
armcc -c -g function.c<br />
armcc -c -g main.c<br />
armlink --map --scatter=scatter.scat function.o main.o -o squared.axf<br />
The --map option displays <strong>the</strong> memory map of <strong>the</strong> image. Also, --autoat is <strong>the</strong> default.<br />
In this example, __attribute__((section("foo"))) specifies that <strong>the</strong> global variable gSquared is<br />
to be placed in a section called foo. The scatter file specifies that <strong>the</strong> section foo is to be placed<br />
in <strong>the</strong> ER3 execution region.<br />
The memory map shows:<br />
Load Region LR1 (Base: 0x00000000, Size: 0x00001778, Max: 0x00020000, ABSOLUTE)<br />
...<br />
Execution Region ER3 (Base: 0x00010000, Size: 0x00000004, Max: 0x00002000, ABSOLUTE)<br />
Base Addr Size Type Attr Idx E Section Name Object<br />
0x00010000 0x00000004 Data RW 15 foo main.o<br />
...<br />
Note<br />
If you omit *(foo) from <strong>the</strong> scatter file, <strong>the</strong> section is placed in <strong>the</strong> region of <strong>the</strong> same type. That<br />
is RAM in this example.<br />
8.11.3 Example of placing a variable at a specific address with scatter-loading<br />
This example shows how to modify your source code to place code and data at a specific address<br />
using a scatter file:<br />
1. Create <strong>the</strong> source file main.c containing <strong>the</strong> following code:<br />
#include <br />
extern int sqr(int n1);<br />
// Place at address 0x10000<br />
const int gValue __attribute__((section(".<strong>ARM</strong>.__at_0x10000"))) = 3;<br />
int main()<br />
{<br />
int squared;<br />
squared=sqr(gValue);<br />
printf("Value squared is: %d\n", squared);<br />
}<br />
<strong>ARM</strong> DUI 0474C Copyright © 2010-2011 <strong>ARM</strong>. All rights reserved. 8-20<br />
ID080411 Non-Confidential