Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / platform / k32w / app / ldscripts / chip-k32w061-linker.ld
1 /*
2  *  Copyright (c) 2019, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 /**
30  * @file
31  *   GCC linker script for K32W061.
32  */
33
34 OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
35
36 /*
37  * stack size for the boot rom during warm boot and application
38  * 256 is sufficient (pwrm_test) but keep it large to 1024
39  */
40 BOOT_RESUME_STACK_SIZE = 1024;
41
42 /* Set Stack size to 4K minus 32Bytes reserved for ROM code at end of BANK7 so
43    the stack fits in BANK7. In practice the active stack size at the time of
44    going to sleep is more important than the total available stack size */
45 STACK_SIZE             = (4096 - 32);
46
47 MEM_RAM0_BASE = 0x4000400;
48 MEM_RAM0_SIZE = 0x0015c00;
49
50 MEMORY
51 {
52   /* Define each memory region. RAM0 definition leaves the first 1kB for the
53      boot code */
54   Flash640 (rx) : ORIGIN = 0, LENGTH = 0x00a0000            /* 640K bytes (alias Flash) */
55   RAM0 (rwx)    : ORIGIN = 0x4000400,  LENGTH = 0x0015c00   /* 87K bytes (alias RAM) */
56   RAM1 (rwx)    : ORIGIN = 0x4020000,  LENGTH = 0x10000     /* 64K bytes (alias RAM2) */
57 }
58
59 /* Define a symbol for the top of each memory region */
60 __top_RAM0      = MEM_RAM0_BASE + MEM_RAM0_SIZE; /* 87K bytes */
61
62 /* To be improved. At this moment the second RAM bank is dedicated entirely to heap. */
63 HEAP_SIZE = DEFINED(HEAP_SIZE) ? HEAP_SIZE : 0xF000;
64
65 /*** flash memory characteristics definitions required for OTA ***/
66 m_flash_start   = 0x00000000;
67 m_flash_end     = 0x0009FFFF;
68 m_flash_size    = 0x000A0000;
69 m_sector_size   = 512;
70 m_fsl_prodInfo_size = m_sector_size;
71
72 m_fsl_prodInfo_end                             = m_flash_size - 17 * m_sector_size - 1;
73 m_fsl_prodInfo_start                           = m_fsl_prodInfo_end - m_fsl_prodInfo_size + 1;
74
75 NV_STORAGE_MAX_SECTORS                         = 16;
76 NV_STORAGE_SIZE                                = NV_STORAGE_MAX_SECTORS * m_sector_size;
77 NV_STORAGE_START_ADDRESS                       = m_fsl_prodInfo_start - 1;
78 NV_STORAGE_END_ADDRESS                         = NV_STORAGE_START_ADDRESS - NV_STORAGE_SIZE + 1;
79
80 INT_STORAGE_END                                = NV_STORAGE_START_ADDRESS - 1;
81 INT_STORAGE_START                              = 0x48000;
82 INT_STORAGE_SIZE                               = INT_STORAGE_END - INT_STORAGE_START;
83
84 FREESCALE_PROD_DATA_BASE_ADDR                  = m_fsl_prodInfo_start;
85 INT_STORAGE_SECTOR_SIZE                        = m_sector_size;
86 m_app_size                                     = 0xA0000; /* 640K: to accommodate all libs in debug */
87
88 __ram_vector_table__                           = 1;
89 vector_table_size                              = 0x120;
90 M_VECTOR_RAM_SIZE                              = DEFINED(__ram_vector_table__) ? vector_table_size : 0x0;
91
92 ENTRY(ResetISR)
93
94 SECTIONS
95 {
96     /* MAIN TEXT SECTION */
97     .header : ALIGN(4)
98     {
99         _flash_start = ABSOLUTE(.);
100         _flash_beg = ABSOLUTE(.);
101
102         FILL(0xff)
103         __vectors_start__ = ABSOLUTE(.) ;
104         __VECTOR_TABLE = .;
105         __Vectors = .;
106         KEEP(*(.isr_vector))
107         /* Global Section Table */
108         . = ALIGN(4) ;
109         __section_table_start = .;
110         __data_section_table = .;
111         LONG(LOADADDR(.data));
112         LONG(    ADDR(.data));
113         LONG(  SIZEOF(.data));
114         __data_section_table_end = .;
115         __bss_section_table = .;
116         LONG(    ADDR(.bss));
117         LONG(  SIZEOF(.bss));
118         __bss_section_table_end = .;
119         __section_table_end = . ;
120         /* End of Global Section Table */
121
122         FILL(0xff)
123         . = ALIGN (0x10);
124     } >Flash640
125
126     .ro_nonce : ALIGN(0x10)
127     {
128         _FlsNonceStart = ABSOLUTE(.);
129         *(.ro_nonce) /* nonce value is 16 bytes.*/
130         FILL(0xff)
131         . = ALIGN (0x10);
132     } > Flash640
133
134     .ro_ota_header : ALIGN(0x10)
135     {
136         _enc_start = ABSOLUTE(.);
137         _enc_offset = (_enc_start & 0x0000000F);
138         _FlsOtaHeader = ABSOLUTE(.);
139         *(.ro_ota_header) /* Ota Header 69 bytes*/
140         FILL(0xff)
141         . = ALIGN (0x10);
142     } > Flash640
143
144     .ro_se_lnkKey (ALIGN((. - _enc_offset), 16) + _enc_offset):
145     {
146         _FlsLinkKey = ABSOLUTE(.);
147         *(.ro_se_lnkKey)  /* Link Key 16 bytes*/
148         FILL(0xff)
149         . = ALIGN (0x10);
150     } > Flash640
151
152     .filler :
153     {
154         BYTE(0xff);
155         FILL(0xff);
156         . = ALIGN(0x40);
157     } > Flash640
158
159     .text : ALIGN(0x40)
160     {
161         FILL(0xff)
162
163        *(.after_vectors*)
164        *(.text*)
165
166         KEEP(*(.init))
167         KEEP(*(.fini))
168
169          /* .ctors */
170         *crtbegin.o(.ctors)
171         *crtbegin?.o(.ctors)
172         *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
173         *(SORT(.ctors.*))
174         *(.ctors)
175
176         /* .dtors */
177         *crtbegin.o(.dtors)
178         *crtbegin?.o(.dtors)
179         *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
180         *(SORT(.dtors.*))
181         *(.dtors)
182
183         *(.rodata .rodata.* .constdata .constdata.*)
184
185         . = ALIGN(4);
186     } > Flash640
187     /*
188      * for exception handling/unwind - some Newlib functions (in common
189      * with C++ and STDC++) use this.
190      */
191     .ARM.extab : ALIGN(4)
192     {
193        FILL(0xff)
194         *(.ARM.extab* .gnu.linkonce.armextab.*)
195     } > Flash640
196     __exidx_start = .;
197
198     .ARM.exidx : ALIGN(4)
199     {
200        FILL(0xff)
201         *(.ARM.exidx* .gnu.linkonce.armexidx.*)
202     } > Flash640
203     __exidx_end = .;
204
205     _etext = .;
206
207     .heap (COPY):
208     {
209         __HeapBase = .;
210          _heap = .;
211         KEEP(*(.heap*))
212         PROVIDE(end = .);
213          . = ALIGN(4);
214         __end__ = .;
215          _end_heap = .;
216         __HeapLimit = .;
217     } > RAM1
218
219     .interrupts_ram : ALIGN(0x200)
220     {
221         . = ALIGN(4);
222         __VECTOR_RAM__ = .;
223         __interrupts_ram_start__ = .;   /* Create a global symbol at data start */
224         *(.m_interrupts_ram)            /* This is a user defined section */
225         . += M_VECTOR_RAM_SIZE;
226         . = ALIGN(4);
227         __interrupts_ram_end__ = .;     /* Define a global symbol at data end */
228     } > RAM0
229
230     /* MAIN DATA SECTION */
231     .uninit_RESERVED : ALIGN(4)
232     {
233         KEEP(*(.bss.$RESERVED*))
234         . = ALIGN(4) ;
235         _end_uninit_RESERVED = .;
236     } > RAM0
237
238     /* Main DATA section (RAM0) */
239     .data : ALIGN(4)
240     {
241        FILL(0xff)
242        _data = . ;
243        *(vtable)
244        *(.ramfunc*)
245        *(.data*)
246
247         . = ALIGN(4);
248         /* preinit data */
249         PROVIDE_HIDDEN (__preinit_array_start = .);
250         KEEP(*(.preinit_array))
251         PROVIDE_HIDDEN (__preinit_array_end = .);
252
253         . = ALIGN(4);
254         /* init data */
255         __init_array_start = . ;
256         KEEP(*(SORT(.init_array.*)))
257         KEEP(*(.init_array))
258         __init_array_end = . ;
259
260         . = ALIGN(4);
261         /* finit data */
262         PROVIDE_HIDDEN (__fini_array_start = .);
263         KEEP(*(SORT(.fini_array.*)))
264         KEEP(*(.fini_array))
265         PROVIDE_HIDDEN (__fini_array_end = .);
266
267         KEEP(*(.jcr*))
268
269        . = ALIGN(4) ;
270        _edata = . ;
271     } > RAM0 AT>Flash640
272
273     __VECTOR_RAM = __VECTOR_RAM__;
274     __RAM_VECTOR_TABLE_SIZE_BYTES = DEFINED(__ram_vector_table__) ? (__interrupts_ram_end__ - __interrupts_ram_start__) : 0x0;
275
276     /* MAIN BSS SECTION */
277     .bss (NOLOAD) : ALIGN(4)
278     {
279         _bss = .;
280         *(.bss*)
281         *(COMMON)
282         *(g_u32NwkFrameCounter)
283         . = ALIGN(4) ;
284         _ebss = .;
285
286         PROVIDE(end = .);
287     } > RAM0
288
289     /* BSS section for MAC buffers */
290     .bss_MAC (NOLOAD) : ALIGN(4)
291     {
292        /* MAC buffer section: must be within 128kB block. __mac_buffer_base is
293           defined further down to be on 128kB alignment */
294         __mac_buffer_start = .;
295        *(.mac_buffer)
296
297         . = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */
298     } > RAM0
299
300     /* DEFAULT NOINIT SECTION */
301     .noinit (NOLOAD): ALIGN(4)
302     {
303         _noinit = .;
304         *(.noinit*)
305         . = ALIGN(4) ;
306         _end_noinit = .;
307     } > RAM0
308
309     /* stack for rom boot during warm resume */
310     .boot_resume_stack (NOLOAD): ALIGN(4)
311     {
312         _boot_resume_stack = .;
313         *(.boot_resume_stack*)
314         . += BOOT_RESUME_STACK_SIZE;
315         . = ALIGN(4) ;
316         _end_boot_resume_stack = .;
317     } > RAM0
318
319     __nv_storage_end_address = NV_STORAGE_END_ADDRESS;
320     __nv_storage_start_address = NV_STORAGE_START_ADDRESS;
321
322     PROVIDE(_vStackTop = __top_RAM0 - 32);
323     PROVIDE(__mac_buffer_base = (__mac_buffer_start & 0xfffe0000));
324     PROVIDE(BOOT_GetStartPowerMode = 0x03000e9d);
325     PROVIDE(ROM_GetFlash = 0x03000e0d);
326     PROVIDE(pmc_reset_get_cause = 0x030046e9);
327     PROVIDE(psector_ReadIeee802_15_4_MacId1 = 0x030053b1);
328     PROVIDE(Chip_LOWPOWER_ChipSoftwareReset = 0x03003fa1);
329
330     __StackLimit = _vStackTop - STACK_SIZE;
331     ASSERT(__StackLimit >= _end_boot_resume_stack, "Possible stack corruption with data/bss/boot_stack")
332 }