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