1/* Linker script for Nordic Semiconductor nRF devices
2 *
3 * Version: Sourcery G++ 4.5-1
4 * Support: https://support.codesourcery.com/GNUToolchain/
5 *
6 * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc.
7 *
8 * The authors hereby grant permission to use, copy, modify, distribute,
9 * and license this software and its documentation for any purpose, provided
10 * that existing copyright notices are retained in all copies and that this
11 * notice is included verbatim in any distributions.  No written agreement,
12 * license, or royalty fee is required for any of the authorized uses.
13 * Modifications to this software may be copyrighted by their authors
14 * and need not follow the licensing terms described here, provided that
15 * the new terms are clearly indicated on the first page of each file where
16 * they apply.
17 */
18OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
19
20/* Linker script to place sections and symbol values. Should be used together
21 * with other linker script that defines memory regions FLASH and RAM.
22 * It references following symbols, which must be defined in code:
23 *   Reset_Handler : Entry of reset handler
24 *
25 * It defines following symbols, which code can use without definition:
26 *   __exidx_start
27 *   __exidx_end
28 *   __etext
29 *   __data_start__
30 *   __preinit_array_start
31 *   __preinit_array_end
32 *   __init_array_start
33 *   __init_array_end
34 *   __fini_array_start
35 *   __fini_array_end
36 *   __data_end__
37 *   __bss_start__
38 *   __bss_end__
39 *   __end__
40 *   end
41 *   __HeapBase
42 *   __HeapLimit
43 *   __StackLimit
44 *   __StackTop
45 *   __stack
46 */
47ENTRY(Reset_Handler)
48
49SECTIONS
50{
51    .text :
52    {
53        KEEP(*(.isr_vector))
54        *(.text*)
55
56        KEEP(*(.init))
57        KEEP(*(.fini))
58
59        /* .ctors */
60        *crtbegin.o(.ctors)
61        *crtbegin?.o(.ctors)
62        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
63        *(SORT(.ctors.*))
64        *(.ctors)
65
66        /* .dtors */
67        *crtbegin.o(.dtors)
68        *crtbegin?.o(.dtors)
69        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
70        *(SORT(.dtors.*))
71        *(.dtors)
72
73        *(.rodata*)
74
75        KEEP(*(.eh_frame*))
76    } > FLASH
77
78    .ARM.extab :
79    {
80        *(.ARM.extab* .gnu.linkonce.armextab.*)
81    } > FLASH
82
83    __exidx_start = .;
84    .ARM.exidx :
85    {
86        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
87    } > FLASH
88    __exidx_end = .;
89
90    . = ALIGN(4);
91    __etext = .;
92
93    .data : AT (__etext)
94    {
95        __data_start__ = .;
96        *(vtable)
97        *(.data*)
98
99        . = ALIGN(4);
100        /* preinit data */
101        PROVIDE_HIDDEN (__preinit_array_start = .);
102        KEEP(*(.preinit_array))
103        PROVIDE_HIDDEN (__preinit_array_end = .);
104
105        . = ALIGN(4);
106        /* init data */
107        PROVIDE_HIDDEN (__init_array_start = .);
108        KEEP(*(SORT(.init_array.*)))
109        KEEP(*(.init_array))
110        PROVIDE_HIDDEN (__init_array_end = .);
111
112
113        . = ALIGN(4);
114        /* finit data */
115        PROVIDE_HIDDEN (__fini_array_start = .);
116        KEEP(*(SORT(.fini_array.*)))
117        KEEP(*(.fini_array))
118        PROVIDE_HIDDEN (__fini_array_end = .);
119
120        KEEP(*(.jcr*))
121        . = ALIGN(4);
122        /* All data end */
123        __data_end__ = .;
124
125    } > RAM
126
127    .bss :
128    {
129        . = ALIGN(4);
130        __bss_start__ = .;
131        *(.bss*)
132        *(COMMON)
133        . = ALIGN(4);
134        __bss_end__ = .;
135    } > RAM
136
137    .heap (COPY):
138    {
139        __HeapBase = .;
140        __end__ = .;
141        PROVIDE(end = .);
142        KEEP(*(.heap*))
143        __HeapLimit = .;
144    } > RAM
145
146    /* .stack_dummy section doesn't contains any symbols. It is only
147     * used for linker to calculate size of stack sections, and assign
148     * values to stack symbols later */
149    .stack_dummy (COPY):
150    {
151        KEEP(*(.stack*))
152    } > RAM
153
154    /* Set stack top to end of RAM, and stack limit move down by
155     * size of stack_dummy section */
156    __StackTop = ORIGIN(RAM) + LENGTH(RAM);
157    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
158    PROVIDE(__stack = __StackTop);
159
160    /* Check if data + heap + stack exceeds RAM limit */
161    ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
162
163    /* Check if text sections + data exceeds FLASH limit */
164    DataInitFlashUsed = __bss_start__ - __data_start__;
165    CodeFlashUsed = __etext - ORIGIN(FLASH);
166    TotalFlashUsed = CodeFlashUsed + DataInitFlashUsed;
167    ASSERT(TotalFlashUsed <= LENGTH(FLASH), "region FLASH overflowed with .data and user data")
168
169}
170