altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / src / lpc / altos-loader.ld
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 __flash = 0x300;
20 __flash_size = 4K - 0x300;
21 __ram = 0x10000000;
22 __ram_size = 4k;
23 __stack_size = 128;
24
25 INCLUDE registers.ld
26 /*
27  * SPDX-License-Identifier: BSD-3-Clause
28  *
29  * Copyright © 2019 Keith Packard
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions
33  * are met:
34  *
35  * 1. Redistributions of source code must retain the above copyright
36  *    notice, this list of conditions and the following disclaimer.
37  *
38  * 2. Redistributions in binary form must reproduce the above
39  *    copyright notice, this list of conditions and the following
40  *    disclaimer in the documentation and/or other materials provided
41  *    with the distribution.
42  *
43  * 3. Neither the name of the copyright holder nor the names of its
44  *    contributors may be used to endorse or promote products derived
45  *    from this software without specific prior written permission.
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
50  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
51  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
52  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
53  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
54  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
56  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
58  * OF THE POSSIBILITY OF SUCH DAMAGE.
59  */
60
61 ENTRY(_start)
62
63 /*
64  * These values should be provided by the application. We'll include
65  * some phony values here to make things link for testing
66  */
67
68 MEMORY
69 {
70         low (rxai!w)   : ORIGIN = 0x0, LENGTH = 0x2fc
71         no_isp (rxai!w): ORIGIN = 0x2fc, LENGTH = 4
72         flash (rxai!w) : ORIGIN = DEFINED(__flash) ? __flash : 0x10000000, LENGTH = DEFINED(__flash_size) ? __flash_size : 0x10000
73         ram (wxa!ri)   : ORIGIN = DEFINED(__ram  ) ? __ram   : 0x20000000, LENGTH = DEFINED(__ram_size  ) ? __ram_size   : 0x08000
74 }
75
76 PHDRS
77 {
78         text PT_LOAD;
79         ram PT_LOAD;
80         ram_init PT_LOAD;
81         tls PT_TLS;
82 }
83
84 SECTIONS
85 {
86         PROVIDE(__stack = ORIGIN(ram) + LENGTH(ram));
87
88         .init : {
89                 KEEP (*(.text.init.enter))
90                 KEEP (*(.data.init.enter))
91                 KEEP (*(SORT_BY_NAME(.init) SORT_BY_NAME(.init.*)))
92         } >low AT>low :text
93
94         .text.low : {
95                 ao_boot_chain.o(.text .text.*)
96                 ao_boot_pin.o(.text .text.*)
97                 ao_flash_loader_lpc.o(.text .text.*)
98                 ao_notask.o(*.text .text.*)
99                 ao_product.o(.rodata .rodata.*)
100         } >low AT>low :text
101
102         .no_isp : {
103                 *(.no_isp)
104         } > no_isp AT>no_isp :text
105
106         .text : {
107
108                 /* code */
109                 *(.text.unlikely .text.unlikely.*)
110                 *(.text.startup .text.startup.*)
111                 *(.text .text.*)
112                 *(.gnu.linkonce.t.*)
113                 KEEP (*(.fini .fini.*))
114                 __text_end = .;
115
116                 PROVIDE (__etext = __text_end);
117                 PROVIDE (_etext = __text_end);
118                 PROVIDE (etext = __text_end);
119
120                 /* read-only data */
121                 *(.rdata)
122                 *(.rodata .rodata.*)
123                 *(.gnu.linkonce.r.*)
124
125                 *(.srodata.cst16)
126                 *(.srodata.cst8)
127                 *(.srodata.cst4)
128                 *(.srodata.cst2)
129                 *(.srodata .srodata.*)
130                 *(.data.rel.ro .data.rel.ro.*)
131                 *(.got .got.*)
132
133                 /* Need to pre-align so that the symbols come after padding */
134                 . = ALIGN(8);
135
136                 /* lists of constructors and destructors */
137                 PROVIDE_HIDDEN ( __preinit_array_start = . );
138                 KEEP (*(.preinit_array))
139                 PROVIDE_HIDDEN ( __preinit_array_end = . );
140
141                 PROVIDE_HIDDEN ( __init_array_start = . );
142                 KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
143                 KEEP (*(.init_array .ctors))
144                 PROVIDE_HIDDEN ( __init_array_end = . );
145
146                 PROVIDE_HIDDEN ( __fini_array_start = . );
147                 KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
148                 KEEP (*(.fini_array .dtors))
149                 PROVIDE_HIDDEN ( __fini_array_end = . );
150         } >flash AT>flash :text
151
152         /* additional sections when compiling with C++ exception support */
153         /*
154         .except_ordered : {
155                 *(.gcc_except_table *.gcc_except_table.*)
156                 KEEP (*(.eh_frame .eh_frame.*))
157                 *(.ARM.extab* .gnu.linkonce.armextab.*)
158         } >flash AT>flash :text
159
160         .except_unordered : {
161                 . = ALIGN(8);
162
163                 PROVIDE(__exidx_start = .);
164                 *(.ARM.exidx*)
165                 PROVIDE(__exidx_end = .);
166         } >flash AT>flash :text
167         */
168
169         /*
170          * Data values which are preserved across reset
171          */
172         .preserve (NOLOAD) : {
173                 PROVIDE(__preserve_start__ = .);
174                 KEEP(*(SORT_BY_NAME(.preserve.*)))
175                 KEEP(*(.preserve))
176                 PROVIDE(__preserve_end__ = .);
177         } >ram AT>ram :ram
178
179         .data : ALIGN_WITH_INPUT {
180                 *(.data .data.*)
181                 *(.gnu.linkonce.d.*)
182
183                 /* Need to pre-align so that the symbols come after padding */
184                 . = ALIGN(8);
185
186                 PROVIDE( __global_pointer$ = . + 0x800 );
187                 *(.sdata .sdata.* .sdata2.*)
188                 *(.gnu.linkonce.s.*)
189         } >ram AT>flash :ram_init
190         PROVIDE(__data_start = ADDR(.data));
191         PROVIDE(__data_source = LOADADDR(.data));
192
193         /* Thread local initialized data. This gets
194          * space allocated as it is expected to be placed
195          * in ram to be used as a template for TLS data blocks
196          * allocated at runtime. We're slightly abusing that
197          * by placing the data in flash where it will be copied
198          * into the allocate ram addresses by the existing
199          * data initialization code in crt0
200          */
201         .tdata : ALIGN_WITH_INPUT {
202                 *(.tdata .tdata.* .gnu.linkonce.td.*)
203                 PROVIDE(__data_end = .);
204                 PROVIDE(__tdata_end = .);
205         } >ram AT>flash :tls :ram_init
206         PROVIDE( __tls_base = ADDR(.tdata));
207         PROVIDE( __tdata_start = ADDR(.tdata));
208         PROVIDE( __tdata_source = LOADADDR(.tdata) );
209         PROVIDE( __tdata_source_end = LOADADDR(.tdata) + SIZEOF(.tdata) );
210         PROVIDE( __tdata_size = SIZEOF(.tdata) );
211
212         PROVIDE( __edata = __data_end );
213         PROVIDE( _edata = __data_end );
214         PROVIDE( edata = __data_end );
215         PROVIDE( __data_size = __data_end - __data_start );
216
217         .tbss (NOLOAD) : {
218                 *(.tbss .tbss.* .gnu.linkonce.tb.*)
219                 *(.tcommon)
220                 PROVIDE( __tls_end = . );
221                 PROVIDE( __tbss_end = . );
222         } >ram AT>ram :tls :ram
223         PROVIDE( __bss_start = ADDR(.tbss));
224         PROVIDE( __tbss_start = ADDR(.tbss));
225         PROVIDE( __tbss_size = SIZEOF(.tbss) );
226         PROVIDE( __tls_size = __tls_end - __tls_base );
227
228         /*
229          * The linker special cases .tbss segments which are
230          * identified as segments which are not loaded and are
231          * thread_local.
232          *
233          * For these segments, the linker does not advance 'dot'
234          * across them.  We actually need memory allocated for tbss,
235          * so we create a special segment here just to make room
236          */
237         .tbss_space (NOLOAD) : {
238                 . = . + SIZEOF(.tbss);
239         } >ram AT>ram :ram
240
241         .bss (NOLOAD) : {
242                 *(.sbss*)
243                 *(.gnu.linkonce.sb.*)
244                 *(.bss .bss.*)
245                 *(.gnu.linkonce.b.*)
246                 *(COMMON)
247
248                 /* Align the heap */
249                 . = ALIGN(8);
250                 __bss_end = .;
251         } >ram AT>ram :ram
252         PROVIDE( __end = __bss_end );
253         PROVIDE( _end = __bss_end );
254         PROVIDE( end = __bss_end );
255         PROVIDE( __bss_size = __bss_end - __bss_start );
256
257         /* Make the rest of memory available for heap storage */
258         PROVIDE (__heap_start = __end);
259         PROVIDE (__heap_end = __stack - (DEFINED(__stack_size) ? __stack_size : 0x800));
260         PROVIDE (__heap_size = __heap_end - __heap_start);
261
262         /* Define a stack region to make sure it fits in memory */
263         .stack (NOLOAD) : {
264                 . += (DEFINED(__stack_size) ? __stack_size : 0x800);
265         } >ram :ram
266
267         /* Throw away C++ exception handling information */
268
269         
270
271         /DISCARD/ : {
272                 *(.note .note.*)
273                 *(.eh_frame .eh_frame.*)
274                 *(.ARM.extab* .gnu.linkonce.armextab.*)
275                 *(.ARM.exidx*)
276         }
277
278         
279 }