1/***************************************************************************//**
2* \file cy8c6xx7_cm4_dual.ld
3* \version 2.95.1
4*
5* Linker file for the GNU C compiler.
6*
7* The main purpose of the linker script is to describe how the sections in the
8* input files should be mapped into the output file, and to control the memory
9* layout of the output file.
10*
11* \note The entry point location is fixed and starts at 0x10000000. The valid
12* application image should be placed there.
13*
14* \note The linker files included with the PDL template projects must be generic
15* and handle all common use cases. Your project may not use every section
16* defined in the linker files. In that case you may see warnings during the
17* build process. In your project, you can simply comment out or remove the
18* relevant code in the linker file.
19*
20********************************************************************************
21* \copyright
22* Copyright 2016-2021 Cypress Semiconductor Corporation
23* SPDX-License-Identifier: Apache-2.0
24*
25* Licensed under the Apache License, Version 2.0 (the "License");
26* you may not use this file except in compliance with the License.
27* You may obtain a copy of the License at
28*
29*     http://www.apache.org/licenses/LICENSE-2.0
30*
31* Unless required by applicable law or agreed to in writing, software
32* distributed under the License is distributed on an "AS IS" BASIS,
33* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34* See the License for the specific language governing permissions and
35* limitations under the License.
36*******************************************************************************/
37
38OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
39SEARCH_DIR(.)
40GROUP(-lgcc -lc -lnosys)
41ENTRY(Reset_Handler)
42
43/* The size of the stack section at the end of CM4 SRAM */
44STACK_SIZE = 0x1000;
45
46/* By default, the COMPONENT_CM0P_SLEEP prebuilt image is used for the CM0p core.
47* More about CM0+ prebuilt images, see here:
48* https://github.com/Infineon/psoc6cm0p
49*/
50/* The size of the Cortex-M0+ application image at the start of FLASH */
51FLASH_CM0P_SIZE  = 0x2000;
52
53/* Force symbol to be entered in the output file as an undefined symbol. Doing
54* this may, for example, trigger linking of additional modules from standard
55* libraries. You may list several symbols for each EXTERN, and you may use
56* EXTERN multiple times. This command has the same effect as the -u command-line
57* option.
58*/
59EXTERN(Reset_Handler)
60
61/* The MEMORY section below describes the location and size of blocks of memory in the target.
62* Use this section to specify the memory regions available for allocation.
63*/
64MEMORY
65{
66    /* The ram and flash regions control RAM and flash memory allocation for the CM4 core.
67     * You can change the memory allocation by editing the 'ram' and 'flash' regions.
68     * Note that 2 KB of RAM (at the end of the SRAM) are reserved for system use.
69     * Using this memory region for other purposes will lead to unexpected behavior.
70     * Your changes must be aligned with the corresponding memory regions for CM0+ core in 'xx_cm0plus.ld',
71     * where 'xx' is the device group; for example, 'cy8c6xx7_cm0plus.ld'.
72     */
73    ram               (rwx)   : ORIGIN = 0x08002000, LENGTH = 0x45800
74    flash             (rx)    : ORIGIN = 0x10000000, LENGTH = 0x100000
75
76    /* This is a 32K flash region used for EEPROM emulation. This region can also be used as the general purpose flash.
77     * You can assign sections to this memory region for only one of the cores.
78     * Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region.
79     * Therefore, repurposing this memory region will prevent such middleware from operation.
80     */
81    em_eeprom         (rx)    : ORIGIN = 0x14000000, LENGTH = 0x8000       /*  32 KB */
82
83    /* The following regions define device specific memory regions and must not be changed. */
84    sflash_user_data  (rx)    : ORIGIN = 0x16000800, LENGTH = 0x800        /* Supervisory flash: User data */
85    sflash_nar        (rx)    : ORIGIN = 0x16001A00, LENGTH = 0x200        /* Supervisory flash: Normal Access Restrictions (NAR) */
86    sflash_public_key (rx)    : ORIGIN = 0x16005A00, LENGTH = 0xC00        /* Supervisory flash: Public Key */
87    sflash_toc_2      (rx)    : ORIGIN = 0x16007C00, LENGTH = 0x200        /* Supervisory flash: Table of Content # 2 */
88    sflash_rtoc_2     (rx)    : ORIGIN = 0x16007E00, LENGTH = 0x200        /* Supervisory flash: Table of Content # 2 Copy */
89    xip               (rx)    : ORIGIN = 0x18000000, LENGTH = 0x8000000    /* 128 MB */
90    efuse             (r)     : ORIGIN = 0x90700000, LENGTH = 0x100000     /*   1 MB */
91}
92
93/* Library configurations */
94GROUP(libgcc.a libc.a libm.a libnosys.a)
95
96/* Linker script to place sections and symbol values. Should be used together
97 * with other linker script that defines memory regions FLASH and RAM.
98 * It references following symbols, which must be defined in code:
99 *   Reset_Handler : Entry of reset handler
100 *
101 * It defines following symbols, which code can use without definition:
102 *   __exidx_start
103 *   __exidx_end
104 *   __copy_table_start__
105 *   __copy_table_end__
106 *   __zero_table_start__
107 *   __zero_table_end__
108 *   __etext
109 *   __data_start__
110 *   __preinit_array_start
111 *   __preinit_array_end
112 *   __init_array_start
113 *   __init_array_end
114 *   __fini_array_start
115 *   __fini_array_end
116 *   __data_end__
117 *   __bss_start__
118 *   __bss_end__
119 *   __end__
120 *   end
121 *   __HeapLimit
122 *   __StackLimit
123 *   __StackTop
124 *   __stack
125 *   __Vectors_End
126 *   __Vectors_Size
127 */
128
129
130SECTIONS
131{
132     /* Cortex-M0+ application flash image area */
133    .cy_m0p_image ORIGIN(flash) :
134    {
135        . = ALIGN(4);
136        __cy_m0p_code_start = . ;
137        KEEP(*(.cy_m0p_image))
138        __cy_m0p_code_end = . ;
139    } > flash
140
141    /* Check if .cy_m0p_image size exceeds FLASH_CM0P_SIZE */
142    ASSERT(__cy_m0p_code_end <= ORIGIN(flash) + FLASH_CM0P_SIZE, "CM0+ flash image overflows with CM4, increase FLASH_CM0P_SIZE")
143
144    /* Cortex-M4 application flash area */
145    .text ORIGIN(flash) + FLASH_CM0P_SIZE :
146    {
147        . = ALIGN(4);
148        __Vectors = . ;
149        KEEP(*(.vectors))
150        . = ALIGN(4);
151        __Vectors_End = .;
152        __Vectors_Size = __Vectors_End - __Vectors;
153        __end__ = .;
154
155        . = ALIGN(4);
156        *(.text*)
157
158        KEEP(*(.init))
159        KEEP(*(.fini))
160
161        /* .ctors */
162        *crtbegin.o(.ctors)
163        *crtbegin?.o(.ctors)
164        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
165        *(SORT(.ctors.*))
166        *(.ctors)
167
168        /* .dtors */
169        *crtbegin.o(.dtors)
170        *crtbegin?.o(.dtors)
171        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
172        *(SORT(.dtors.*))
173        *(.dtors)
174
175        /* Read-only code (constants). */
176        *(.rodata .rodata.* .constdata .constdata.* .conststring .conststring.*)
177
178        KEEP(*(.eh_frame*))
179    } > flash
180
181
182    .ARM.extab :
183    {
184        *(.ARM.extab* .gnu.linkonce.armextab.*)
185    } > flash
186
187    __exidx_start = .;
188
189    .ARM.exidx :
190    {
191        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
192    } > flash
193    __exidx_end = .;
194
195
196    /* To copy multiple ROM to RAM sections,
197     * uncomment .copy.table section and,
198     * define __STARTUP_COPY_MULTIPLE in startup_psoc6_01_cm4.S */
199    .copy.table :
200    {
201        . = ALIGN(4);
202        __copy_table_start__ = .;
203
204        /* Copy interrupt vectors from flash to RAM */
205        LONG (__Vectors)                                    /* From */
206        LONG (__ram_vectors_start__)                        /* To   */
207        LONG (__Vectors_End - __Vectors)                    /* Size */
208
209        /* Copy data section to RAM */
210        LONG (__etext)                                      /* From */
211        LONG (__data_start__)                               /* To   */
212        LONG (__data_end__ - __data_start__)                /* Size */
213
214        __copy_table_end__ = .;
215    } > flash
216
217
218    /* To clear multiple BSS sections,
219     * uncomment .zero.table section and,
220     * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_psoc6_01_cm4.S */
221    .zero.table :
222    {
223        . = ALIGN(4);
224        __zero_table_start__ = .;
225        LONG (__bss_start__)
226        LONG (__bss_end__ - __bss_start__)
227        __zero_table_end__ = .;
228    } > flash
229
230    __etext =  . ;
231
232
233    .ramVectors (NOLOAD) : ALIGN(8)
234    {
235        __ram_vectors_start__ = .;
236        KEEP(*(.ram_vectors))
237        __ram_vectors_end__   = .;
238    } > ram
239
240
241    .data __ram_vectors_end__ :
242    {
243        . = ALIGN(4);
244        __data_start__ = .;
245
246        *(vtable)
247        *(.data*)
248
249        . = ALIGN(4);
250        /* preinit data */
251        PROVIDE_HIDDEN (__preinit_array_start = .);
252        KEEP(*(.preinit_array))
253        PROVIDE_HIDDEN (__preinit_array_end = .);
254
255        . = ALIGN(4);
256        /* init data */
257        PROVIDE_HIDDEN (__init_array_start = .);
258        KEEP(*(SORT(.init_array.*)))
259        KEEP(*(.init_array))
260        PROVIDE_HIDDEN (__init_array_end = .);
261
262        . = ALIGN(4);
263        /* finit data */
264        PROVIDE_HIDDEN (__fini_array_start = .);
265        KEEP(*(SORT(.fini_array.*)))
266        KEEP(*(.fini_array))
267        PROVIDE_HIDDEN (__fini_array_end = .);
268
269        KEEP(*(.jcr*))
270        . = ALIGN(4);
271
272        KEEP(*(.cy_ramfunc*))
273        . = ALIGN(4);
274
275        __data_end__ = .;
276
277    } > ram AT>flash
278
279
280    /* Place variables in the section that should not be initialized during the
281    *  device startup.
282    */
283    .noinit (NOLOAD) : ALIGN(8)
284    {
285      KEEP(*(.noinit))
286    } > ram
287
288
289    /* The uninitialized global or static variables are placed in this section.
290    *
291    * The NOLOAD attribute tells linker that .bss section does not consume
292    * any space in the image. The NOLOAD attribute changes the .bss type to
293    * NOBITS, and that  makes linker to A) not allocate section in memory, and
294    * A) put information to clear the section with all zeros during application
295    * loading.
296    *
297    * Without the NOLOAD attribute, the .bss section might get PROGBITS type.
298    * This  makes linker to A) allocate zeroed section in memory, and B) copy
299    * this section to RAM during application loading.
300    */
301    .bss (NOLOAD):
302    {
303        . = ALIGN(4);
304        __bss_start__ = .;
305        *(.bss*)
306        *(COMMON)
307        . = ALIGN(4);
308        __bss_end__ = .;
309    } > ram
310
311
312    .heap (NOLOAD):
313    {
314        __HeapBase = .;
315        __end__ = .;
316        end = __end__;
317        KEEP(*(.heap*))
318        . = ORIGIN(ram) + LENGTH(ram) - STACK_SIZE;
319        __HeapLimit = .;
320    } > ram
321
322
323    /* .stack_dummy section doesn't contains any symbols. It is only
324     * used for linker to calculate size of stack sections, and assign
325     * values to stack symbols later */
326    .stack_dummy (NOLOAD):
327    {
328        KEEP(*(.stack*))
329    } > ram
330
331
332    /* Set stack top to end of RAM, and stack limit move down by
333     * size of stack_dummy section */
334    __StackTop = ORIGIN(ram) + LENGTH(ram);
335    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
336    PROVIDE(__stack = __StackTop);
337
338    /* Check if data + heap + stack exceeds RAM limit */
339    ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
340
341
342    /* Used for the digital signature of the secure application and the Bootloader SDK application.
343    * The size of the section depends on the required data size. */
344    .cy_app_signature ORIGIN(flash) + LENGTH(flash) - 256 :
345    {
346        KEEP(*(.cy_app_signature))
347    } > flash
348
349
350    /* Emulated EEPROM Flash area */
351    .cy_em_eeprom :
352    {
353        KEEP(*(.cy_em_eeprom))
354    } > em_eeprom
355
356
357    /* Supervisory Flash: User data */
358    .cy_sflash_user_data :
359    {
360        KEEP(*(.cy_sflash_user_data))
361    } > sflash_user_data
362
363
364    /* Supervisory Flash: Normal Access Restrictions (NAR) */
365    .cy_sflash_nar :
366    {
367        KEEP(*(.cy_sflash_nar))
368    } > sflash_nar
369
370
371    /* Supervisory Flash: Public Key */
372    .cy_sflash_public_key :
373    {
374        KEEP(*(.cy_sflash_public_key))
375    } > sflash_public_key
376
377
378    /* Supervisory Flash: Table of Content # 2 */
379    .cy_toc_part2 :
380    {
381        KEEP(*(.cy_toc_part2))
382    } > sflash_toc_2
383
384
385    /* Supervisory Flash: Table of Content # 2 Copy */
386    .cy_rtoc_part2 :
387    {
388        KEEP(*(.cy_rtoc_part2))
389    } > sflash_rtoc_2
390
391
392    /* Places the code in the Execute in Place (XIP) section. See the smif driver
393    *  documentation for details.
394    */
395    cy_xip :
396    {
397        __cy_xip_start = .;
398        KEEP(*(.cy_xip))
399        __cy_xip_end = .;
400    } > xip
401
402
403    /* eFuse */
404    .cy_efuse :
405    {
406        KEEP(*(.cy_efuse))
407    } > efuse
408
409
410    /* These sections are used for additional metadata (silicon revision,
411    *  Silicon/JTAG ID, etc.) storage.
412    */
413    .cymeta         0x90500000 : { KEEP(*(.cymeta)) } :NONE
414}
415
416
417/* The following symbols used by the cymcuelftool. */
418/* Flash */
419__cy_memory_0_start    = 0x10000000;
420__cy_memory_0_length   = 0x00100000;
421__cy_memory_0_row_size = 0x200;
422
423/* Emulated EEPROM Flash area */
424__cy_memory_1_start    = 0x14000000;
425__cy_memory_1_length   = 0x8000;
426__cy_memory_1_row_size = 0x200;
427
428/* Supervisory Flash */
429__cy_memory_2_start    = 0x16000000;
430__cy_memory_2_length   = 0x8000;
431__cy_memory_2_row_size = 0x200;
432
433/* XIP */
434__cy_memory_3_start    = 0x18000000;
435__cy_memory_3_length   = 0x08000000;
436__cy_memory_3_row_size = 0x200;
437
438/* eFuse */
439__cy_memory_4_start    = 0x90700000;
440__cy_memory_4_length   = 0x100000;
441__cy_memory_4_row_size = 1;
442
443/* EOF */
444