1/*
2                  Linker File for Renesas FSP
3*/
4
5INCLUDE memory_regions.ld
6
7/* Uncomment and set XIP_SECONDARY_SLOT_IMAGE to 1 below for the secondary XIP application image.*/
8/*
9 XIP_SECONDARY_SLOT_IMAGE = 1;
10*/
11
12QSPI_FLASH_PRV_LENGTH = DEFINED(QSPI_FLASH_SIZE) ? ABSOLUTE(QSPI_FLASH_SIZE) : ABSOLUTE(QSPI_FLASH_LENGTH);
13OSPI_DEVICE_0_PRV_LENGTH = DEFINED(OSPI_DEVICE_0_SIZE) ? ABSOLUTE(OSPI_DEVICE_0_SIZE) : ABSOLUTE(OSPI_DEVICE_0_LENGTH);
14OSPI_DEVICE_1_PRV_LENGTH = DEFINED(OSPI_DEVICE_1_SIZE) ? ABSOLUTE(OSPI_DEVICE_1_SIZE) : ABSOLUTE(OSPI_DEVICE_1_LENGTH);
15
16/* If a flat (secure) project has DEFINED RAM_NS_BUFFER_LENGTH, then emit IDAU symbols to allocate non-secure RAM. */
17__RESERVE_NS_RAM = !DEFINED(PROJECT_NONSECURE) && DEFINED(RAM_NS_BUFFER_LENGTH) && (OPTION_SETTING_S_LENGTH != 0);
18
19ITCM_START = DEFINED(ITCM_START)? ITCM_START : 0;
20ITCM_LENGTH = DEFINED(ITCM_LENGTH)? ITCM_LENGTH : 0;
21DTCM_START = DEFINED(DTCM_START)? DTCM_START : 0;
22DTCM_LENGTH = DEFINED(DTCM_LENGTH)? DTCM_LENGTH : 0;
23RAM_NS_BUFFER_BLOCK_LENGTH = DEFINED(RAM_NS_BUFFER_LENGTH) ? ALIGN(RAM_NS_BUFFER_LENGTH, 8192) : 0;
24RAM_NS_BUFFER_LENGTH = DEFINED(RAM_NS_BUFFER_LENGTH) ? RAM_NS_BUFFER_LENGTH : 0;
25RAM_NS_BUFFER_START = RAM_START + RAM_LENGTH - RAM_NS_BUFFER_LENGTH;
26RAM_NS_BUFFER_BLOCK_START = RAM_START + RAM_LENGTH - RAM_NS_BUFFER_BLOCK_LENGTH;
27
28OPTION_SETTING_START_NS = DEFINED(PROJECT_NONSECURE) ? OPTION_SETTING_START : OPTION_SETTING_START + 0x80;
29OPTION_SETTING_DATA_FLASH_S_START = DEFINED(OPTION_SETTING_DATA_FLASH_S_START) ? OPTION_SETTING_DATA_FLASH_S_START : 0;
30OPTION_SETTING_DATA_FLASH_S_LENGTH = DEFINED(OPTION_SETTING_DATA_FLASH_S_LENGTH) ? OPTION_SETTING_DATA_FLASH_S_LENGTH : 0;
31
32/* This definition is used to avoid moving the counter in OPTION_SETTING regions for projects that should not configure option settings.
33 * Bootloader images do not configure option settings because they are owned by the bootloader.
34 * FSP_BOOTABLE_IMAGE is only defined in bootloader images. */
35__bl_FSP_BOOTABLE_IMAGE = 1;
36__bln_FSP_BOOTABLE_IMAGE = 1;
37PROJECT_SECURE_OR_FLAT = (!DEFINED(PROJECT_NONSECURE) || DEFINED(PROJECT_SECURE)) && OPTION_SETTING_LENGTH && !DEFINED(FSP_BOOTABLE_IMAGE);
38USE_OPTION_SETTING_NS = DEFINED(PROJECT_NONSECURE) && !DEFINED(FSP_BOOTABLE_IMAGE);
39USE_OPTION_SETTING_DATA_FLASH = PROJECT_SECURE_OR_FLAT && (OPTION_SETTING_DATA_FLASH_S_LENGTH != 0);
40
41__bl_FLASH_IMAGE_START = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
42                         FLASH_APPLICATION_IMAGE_NUMBER == 1 ? FLASH_START + FLASH_BOOTLOADER_LENGTH + FLASH_BOOTLOADER_HEADER_LENGTH :
43                         FLASH_START + FLASH_BOOTLOADER_LENGTH + FLASH_BOOTLOADER_SCRATCH_LENGTH + FLASH_APPLICATION_S_LENGTH + FLASH_BOOTLOADER_HEADER_LENGTH;
44__bl_FLASH_IMAGE_LENGTH = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
45                          FLASH_APPLICATION_S_LENGTH - FLASH_BOOTLOADER_HEADER_LENGTH;
46__bl_FLASH_IMAGE_END    = __bl_FLASH_IMAGE_START + __bl_FLASH_IMAGE_LENGTH;
47__bl_XIP_SECONDARY_FLASH_IMAGE_START = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
48                         FLASH_BOOTLOADER_LENGTH + FLASH_APPLICATION_S_LENGTH + FLASH_BOOTLOADER_HEADER_LENGTH;
49__bl_XIP_SECONDARY_FLASH_IMAGE_END = __bl_XIP_SECONDARY_FLASH_IMAGE_START + __bl_FLASH_IMAGE_LENGTH;
50__bl_FLASH_NS_START = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
51                        FLASH_APPLICATION_NS_LENGTH == 0 ? __bl_FLASH_IMAGE_END :
52                        __bl_FLASH_IMAGE_START - FLASH_BOOTLOADER_HEADER_LENGTH + FLASH_APPLICATION_S_LENGTH;
53__bl_FLASH_NSC_START = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
54                        FLASH_APPLICATION_NS_LENGTH == 0 ? __bl_FLASH_IMAGE_END :
55                        __bl_FLASH_IMAGE_END - FLASH_APPLICATION_NSC_LENGTH;
56__bl_RAM_NS_START    = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
57                       FLASH_APPLICATION_NS_LENGTH == 0 ? RAM_START + RAM_LENGTH :
58                       RAM_START + RAM_LENGTH - RAM_APPLICATION_NS_LENGTH;
59__bl_RAM_NSC_START   = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
60                       FLASH_APPLICATION_NS_LENGTH == 0 ? RAM_START + RAM_LENGTH :
61                       __bl_RAM_NS_START - RAM_APPLICATION_NSC_LENGTH;
62__bl_FLASH_NS_IMAGE_START = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
63                            FLASH_APPLICATION_NS_LENGTH == 0 ? __bl_FLASH_IMAGE_END :
64                            __bl_FLASH_NS_START + FLASH_BOOTLOADER_HEADER_LENGTH_2;
65__bln_FLASH_IMAGE_START = __bl_FLASH_NS_IMAGE_START | (!DEFINED (NS_OFFSET_START) ? 0 : NS_OFFSET_START);
66__bln_FLASH_IMAGE_LENGTH = !DEFINED(FLASH_BOOTLOADER_LENGTH) ? 0 :
67                           FLASH_APPLICATION_NS_LENGTH == 0 ? __bl_FLASH_IMAGE_END :
68                           FLASH_APPLICATION_NS_LENGTH - FLASH_BOOTLOADER_HEADER_LENGTH_2;
69
70XIP_SECONDARY_SLOT_IMAGE = DEFINED(XIP_SECONDARY_SLOT_IMAGE) ? XIP_SECONDARY_SLOT_IMAGE : 0;
71FLASH_ORIGIN = !DEFINED(FLASH_IMAGE_START) ? FLASH_START :
72                XIP_SECONDARY_SLOT_IMAGE == 1 ? XIP_SECONDARY_FLASH_IMAGE_START :
73                FLASH_IMAGE_START;
74LIMITED_FLASH_LENGTH = DEFINED(FLASH_IMAGE_LENGTH) ? FLASH_IMAGE_LENGTH :
75                       DEFINED(FLASH_BOOTLOADER_LENGTH) ? FLASH_BOOTLOADER_LENGTH :
76                       FLASH_LENGTH;
77OPTION_SETTING_SAS_SIZE = 0x34;
78OPTION_SETTING_SAS_LENGTH = !DEFINED(OPTION_SETTING_LENGTH) ? 0 :
79                            OPTION_SETTING_LENGTH == 0 ? 0 :
80                            OPTION_SETTING_LENGTH - OPTION_SETTING_SAS_SIZE;
81
82/* Define memory regions. */
83MEMORY
84{
85  ITCM (rx)                       : ORIGIN = ITCM_START, LENGTH = ITCM_LENGTH
86  DTCM (rwx)                      : ORIGIN = DTCM_START, LENGTH = DTCM_LENGTH
87  FLASH (rx)                      : ORIGIN = FLASH_ORIGIN, LENGTH = LIMITED_FLASH_LENGTH
88  RAM (rwx)                       : ORIGIN = RAM_START, LENGTH = RAM_LENGTH
89  DATA_FLASH (rx)                 : ORIGIN = DATA_FLASH_START, LENGTH = DATA_FLASH_LENGTH
90  QSPI_FLASH (rx)                 : ORIGIN = QSPI_FLASH_START, LENGTH = QSPI_FLASH_PRV_LENGTH
91  OSPI_DEVICE_0 (rx)              : ORIGIN = OSPI_DEVICE_0_START, LENGTH = OSPI_DEVICE_0_PRV_LENGTH
92  OSPI_DEVICE_1 (rx)              : ORIGIN = OSPI_DEVICE_1_START, LENGTH = OSPI_DEVICE_1_PRV_LENGTH
93  OSPI_DEVICE_0_RAM (rwx)         : ORIGIN = OSPI_DEVICE_0_START, LENGTH = OSPI_DEVICE_0_PRV_LENGTH
94  OSPI_DEVICE_1_RAM (rwx)         : ORIGIN = OSPI_DEVICE_1_START, LENGTH = OSPI_DEVICE_1_PRV_LENGTH
95  SDRAM (rwx)                     : ORIGIN = SDRAM_START, LENGTH = SDRAM_LENGTH
96  OPTION_SETTING (r)              : ORIGIN = OPTION_SETTING_START, LENGTH = OPTION_SETTING_LENGTH
97  OPTION_SETTING_OFS (r)          : ORIGIN = OPTION_SETTING_START, LENGTH = 0x18
98  OPTION_SETTING_SAS (r)          : ORIGIN = OPTION_SETTING_START + OPTION_SETTING_SAS_SIZE, LENGTH = OPTION_SETTING_SAS_LENGTH
99  OPTION_SETTING_S (r)            : ORIGIN = OPTION_SETTING_S_START, LENGTH = OPTION_SETTING_S_LENGTH
100  OPTION_SETTING_DATA_FLASH_S (r) : ORIGIN = OPTION_SETTING_DATA_FLASH_S_START, LENGTH = OPTION_SETTING_DATA_FLASH_S_LENGTH
101  ID_CODE (rx)                    : ORIGIN = ID_CODE_START, LENGTH = ID_CODE_LENGTH
102}
103
104/* Library configurations */
105GROUP( libc.a libm.a)
106
107/* Linker script to place sections and symbol values. Should be used together
108 * with other linker script that defines memory regions FLASH and RAM.
109 * It references following symbols, which must be DEFINED in code:
110 *   Reset_Handler : Entry of reset handler
111 *
112 * It defines following symbols, which code can use without definition:
113 *   __exidx_start
114 *   __exidx_end
115 *   __copy_table_start__
116 *   __copy_table_end__
117 *   __zero_table_start__
118 *   __zero_table_end__
119 *   __etext
120 *   __data_start__
121 *   __preinit_array_start
122 *   __preinit_array_end
123 *   __init_array_start
124 *   __init_array_end
125 *   __fini_array_start
126 *   __fini_array_end
127 *   __data_end__
128 *   __bss_start__
129 *   __bss_end__
130 *   __HeapLimit
131 *   __StackLimit
132 *   __StackTop
133 *   __stack
134 *   __Vectors_End
135 *   __Vectors_Size
136 *   __qspi_flash_start__
137 *   __qspi_flash_end__
138 *   __qspi_flash_code_size__
139 *   __qspi_region_max_size__
140 *   __qspi_region_start_address__
141 *   __qspi_region_end_address__
142 *   __ospi_device_0_start__
143 *   __ospi_device_0_end__
144 *   __ospi_device_0_code_size__
145 *   __ospi_device_0_region_max_size__
146 *   __ospi_device_0_region_start_address__
147 *   __ospi_device_0_region_end_address__
148 *   __ospi_device_1_start__
149 *   __ospi_device_1_end__
150 *   __ospi_device_1_code_size__
151 *   __ospi_device_1_region_max_size__
152 *   __ospi_device_1_region_start_address__
153 *   __ospi_device_1_region_end_address__
154 */
155ENTRY(Reset_Handler)
156
157SECTIONS
158{
159    .text :
160    {
161        __tz_FLASH_S = ABSOLUTE(FLASH_START);
162        __ROM_Start = .;
163
164        /* Even though the vector table is not 256 entries (1KB) long, we still allocate that much
165         * space because ROM registers are at address 0x400 and there is very little space
166         * in between. */
167        KEEP(*(.fixed_vectors*))
168        KEEP(*(.application_vectors*))
169        __Vectors_End = .;
170
171        /* ROM Registers start at address 0x00000400 for devices that do not have the OPTION_SETTING region. */
172        . = OPTION_SETTING_LENGTH > 0 ? . : __ROM_Start + 0x400;
173        KEEP(*(.rom_registers*))
174
175        /* Reserving 0x100 bytes of space for ROM registers. */
176        . = OPTION_SETTING_LENGTH > 0 ? . : __ROM_Start + 0x500;
177
178        /* Allocate flash write-boundary-aligned
179         * space for sce9 wrapped public keys for mcuboot if the module is used.
180         */
181		. = ALIGN(128);
182        KEEP(*(.mcuboot_sce9_key*))
183
184        *(.text*)
185
186        KEEP(*(.version))
187        KEEP(*(.init))
188        KEEP(*(.fini))
189
190        /* section information for finsh shell */
191        . = ALIGN(4);
192        __fsymtab_start = .;
193        KEEP(*(FSymTab))
194        __fsymtab_end = .;
195
196        . = ALIGN(4);
197        __vsymtab_start = .;
198        KEEP(*(VSymTab))
199        __vsymtab_end = .;
200
201        /* section information for initial. */
202        . = ALIGN(4);
203        __rt_init_start = .;
204        KEEP(*(SORT(.rti_fn*)))
205        __rt_init_end = .;
206
207        . = ALIGN(4);
208        KEEP(*(FalPartTable))
209
210        /* .ctors */
211        *crtbegin.o(.ctors)
212        *crtbegin?.o(.ctors)
213        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
214        *(SORT(.ctors.*))
215        *(.ctors)
216
217        /* .dtors */
218        *crtbegin.o(.dtors)
219        *crtbegin?.o(.dtors)
220        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
221        *(SORT(.dtors.*))
222        *(.dtors)
223
224        *(.rodata*)
225        __usb_dev_descriptor_start_fs = .;
226        KEEP(*(.usb_device_desc_fs*))
227        __usb_cfg_descriptor_start_fs = .;
228        KEEP(*(.usb_config_desc_fs*))
229        __usb_interface_descriptor_start_fs = .;
230        KEEP(*(.usb_interface_desc_fs*))
231        __usb_descriptor_end_fs = .;
232        __usb_dev_descriptor_start_hs = .;
233        KEEP(*(.usb_device_desc_hs*))
234        __usb_cfg_descriptor_start_hs = .;
235        KEEP(*(.usb_config_desc_hs*))
236        __usb_interface_descriptor_start_hs = .;
237        KEEP(*(.usb_interface_desc_hs*))
238        __usb_descriptor_end_hs = .;
239
240        KEEP(*(.eh_frame*))
241
242        __ROM_End = .;
243    } > FLASH = 0xFF
244
245    __Vectors_Size = __Vectors_End - __Vectors;
246
247    . = .;
248    __itcm_data_pre_location = .;
249
250    /* Initialized ITCM data. */
251    /* Aligned to FCACHE2 for RA8. */
252    .itcm_data : ALIGN(16)
253    {
254        /* Start of ITCM Secure Trustzone region. */
255        __tz_ITCM_S = ABSOLUTE(ITCM_START);
256
257        /* All ITCM data start */
258        __itcm_data_start = .;
259
260        KEEP(*(.itcm_data*))
261
262        /* Pad to eight byte alignment in case of ECC initialization. Fill zero. */
263        . = ALIGN(8);
264
265        /* All ITCM data end */
266        __itcm_data_end = .;
267
268        /*
269         * Start of the ITCM Non-Secure Trustzone region.
270         * ITCM_NS_START can be used to set a fixed address for non-secure ITCM in secure projects or flat projects.
271         */
272        __tz_ITCM_N = DEFINED(ITCM_NS_START) ? ABSOLUTE(ITCM_NS_START) : ALIGN(__itcm_data_end, 8192);
273    } > ITCM AT > FLASH = 0x00
274
275    /* Addresses exported for ITCM initialization. */
276    __itcm_data_init_start = LOADADDR(.itcm_data);
277    __itcm_data_init_end = LOADADDR(.itcm_data) + SIZEOF(.itcm_data);
278
279    ASSERT(ORIGIN(ITCM) % 8 == 0, "ITCM memory region origin must be aligned to 8 bytes.")
280    ASSERT(LENGTH(ITCM) % 8 == 0, "ITCM memory region length must be a multiple of 8 bytes.")
281    ASSERT(LOADADDR(.itcm_data) % 16 == 0, ".itcm_data section must be aligned to 16 bytes.")
282    ASSERT(SIZEOF(.itcm_data) % 8 == 0, ".itcm_data section size must be a multiple of 8 bytes.")
283
284    /* Restore location counter. */
285    /* If ITCM is not present, this will be the address stored in '.' before ALIGN was attempted. */
286    /* If ITCM is present, this will be the absolute address that follows the ITCM ROM location. */
287    . = (SIZEOF(.itcm_data) > 0) ? __itcm_data_init_end : __itcm_data_pre_location;
288
289    __exidx_start = .;
290    /DISCARD/ :
291    {
292        *(.ARM.extab* .gnu.linkonce.armextab.*)
293        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
294    }
295    __exidx_end = .;
296
297    /* To copy multiple ROM to RAM sections,
298     * uncomment .copy.table section and,
299     * define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
300    /*
301    .copy.table :
302    {
303        . = ALIGN(4);
304        __copy_table_start__ = .;
305        LONG (__etext)
306        LONG (__data_start__)
307        LONG (__data_end__ - __data_start__)
308        LONG (__etext2)
309        LONG (__data2_start__)
310        LONG (__data2_end__ - __data2_start__)
311        __copy_table_end__ = .;
312    } > FLASH
313    */
314
315    /* To clear multiple BSS sections,
316     * uncomment .zero.table section and,
317     * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
318    /*
319    .zero.table :
320    {
321        . = ALIGN(4);
322        __zero_table_start__ = .;
323        LONG (__bss_start__)
324        LONG (__bss_end__ - __bss_start__)
325        LONG (__bss2_start__)
326        LONG (__bss2_end__ - __bss2_start__)
327        __zero_table_end__ = .;
328    } > FLASH
329    */
330
331    __etext = .;
332
333    __tz_RAM_S = ORIGIN(RAM);
334
335    /* If DTC is used, put the DTC vector table at the start of SRAM.
336       This avoids memory holes due to 1K alignment required by it. */
337    .fsp_dtc_vector_table (NOLOAD) :
338    {
339        . = ORIGIN(RAM);
340        *(.fsp_dtc_vector_table)
341    } > RAM
342
343    /* Initialized data section. */
344    .data :
345    {
346        __data_start__ = .;
347        . = ALIGN(4);
348
349        __Code_In_RAM_Start = .;
350
351        KEEP(*(.code_in_ram*))
352        __Code_In_RAM_End = .;
353
354        *(vtable)
355        /* Don't use *(.data*) because it will place data meant for .data_flash in this section. */
356        *(.data.*)
357        *(.data)
358
359        . = ALIGN(4);
360        /* preinit data */
361        PROVIDE_HIDDEN (__preinit_array_start = .);
362        KEEP(*(.preinit_array))
363        PROVIDE_HIDDEN (__preinit_array_end = .);
364
365        . = ALIGN(4);
366        /* init data */
367        PROVIDE_HIDDEN (__init_array_start = .);
368        KEEP(*(SORT(.init_array.*)))
369        KEEP(*(.init_array))
370        PROVIDE_HIDDEN (__init_array_end = .);
371
372
373        . = ALIGN(4);
374        /* finit data */
375        PROVIDE_HIDDEN (__fini_array_start = .);
376        KEEP(*(SORT(.fini_array.*)))
377        KEEP(*(.fini_array))
378        PROVIDE_HIDDEN (__fini_array_end = .);
379
380        KEEP(*(.jcr*))
381
382        . = ALIGN(4);
383
384        /* All data end */
385        __data_end__ = .;
386
387    } > RAM AT > FLASH
388
389    . = .;
390    __dtcm_data_pre_location = LOADADDR(.data) + SIZEOF(.data);
391
392    /* Initialized DTCM data. */
393    /* Aligned to FCACHE2 for RA8. */
394    .dtcm_data : ALIGN(16)
395    {
396        /* Start of DTCM Secure Trustzone region. */
397        __tz_DTCM_S = ABSOLUTE(DTCM_START);
398
399        /* Initialized DTCM data start */
400        __dtcm_data_start = .;
401
402        KEEP(*(.dtcm_data*))
403
404        /* Pad to eight byte alignment in case of ECC initialization. Fill zero. */
405        . = ALIGN(8);
406
407        /* Initialized DTCM data end */
408        __dtcm_data_end = .;
409    } > DTCM AT > FLASH = 0x00
410
411    . = __dtcm_data_end;
412    /* Uninitialized DTCM data. */
413    /* ALIGN appears on the left side of the colon because it is being used to assign the VMA directly, as opposed to a right side appearance which would control the LMA. */
414    .dtcm_bss ALIGN(8) (NOLOAD) :
415    {
416        /* Uninitialized DTCM data start */
417        __dtcm_bss_start = .;
418
419        KEEP(*(.dtcm_bss*))
420
421        /* Pad to eight byte alignment in case of ECC initialization. No fill because of NOLOAD. */
422        . = ALIGN(8);
423
424        /* Uninitialized DTCM data end */
425        __dtcm_bss_end = .;
426
427        /*
428         * Start of the DTCM Non-Secure Trustzone region.
429         * DTCM_NS_START can be used to set a fixed address for non-secure DTCM in secure projects or flat projects.
430         */
431        __tz_DTCM_N = DEFINED(DTCM_NS_START) ? ABSOLUTE(DTCM_NS_START) : ALIGN(__dtcm_bss_end, 8192);
432    } > DTCM
433
434    /* Addresses exported for DTCM initialization. */
435    __dtcm_data_init_start = LOADADDR(.dtcm_data);
436    __dtcm_data_init_end = LOADADDR(.dtcm_data) + SIZEOF(.dtcm_data);
437
438    ASSERT(ORIGIN(DTCM) % 8 == 0, "DTCM memory region origin must be aligned to 8 bytes.")
439    ASSERT(LENGTH(DTCM) % 8 == 0, "DTCM memory region length must be a multiple of 8 bytes.")
440    ASSERT(LOADADDR(.dtcm_bss) == ADDR(.dtcm_bss), ".dtcm_bss has (VMA != LMA) but should be NOLOAD (VMA == LMA).")
441    ASSERT(LOADADDR(.dtcm_data) % 16 == 0, ".dtcm_data section must be aligned to 16 bytes.")
442    ASSERT(SIZEOF(.dtcm_data) % 8 == 0, ".dtcm_data section size must be a multiple of 8 bytes.")
443    ASSERT(LOADADDR(.dtcm_bss) % 8 == 0, ".dtcm_bss section must be aligned to 8 bytes.")
444    ASSERT(SIZEOF(.dtcm_bss) % 8 == 0, ".dtcm_bss section size must be a multiple of 8 bytes.")
445    ASSERT(__dtcm_bss_start == __dtcm_data_end, ".dtcm_bss section is not adjacent to .dtcm_data section.")
446
447    /* Restore location counter. */
448    /* If DTCM is not present, this will be the address stored in '.' before ALIGN was attempted. */
449    /* If DTCM is present, this will be the absolute address that follows the DTCM ROM location. */
450    . = (SIZEOF(.dtcm_data) > 0) ? __dtcm_data_init_end : __dtcm_data_pre_location;
451
452    /* TrustZone Secure Gateway Stubs Section */
453
454    /* Store location counter for SPI non-retentive sections. */
455    sgstubs_pre_location = .;
456
457    /* Determine the secure gateway stubs address either by the provided linker variable or the next 1024-byte block. */
458    SGSTUBS_LOC = (DEFINED(PROJECT_SECURE) && DEFINED(FLASH_NSC_START)) ? ABSOLUTE(FLASH_NSC_START) : ALIGN(1024);
459    .gnu.sgstubs SGSTUBS_LOC : ALIGN(1024)
460    {
461        __FLASH_NSC_START = DEFINED(FLASH_NSC_START) ? ABSOLUTE(FLASH_NSC_START) : __RESERVE_NS_RAM ? ABSOLUTE(FLASH_START + FLASH_LENGTH) : ALIGN(1024);
462        _start_sg = .;
463        *(.gnu.sgstubs*)
464        . = ALIGN(32);
465        _end_sg = .;
466    } > FLASH
467
468    __tz_FLASH_N = DEFINED(FLASH_NS_START) ? ABSOLUTE(FLASH_NS_START) : __RESERVE_NS_RAM ? ABSOLUTE(FLASH_START + FLASH_LENGTH) : FLASH_LENGTH < 32768 ? FLASH_LENGTH : ALIGN(32768);
469    FLASH_NS_IMAGE_START = DEFINED(FLASH_NS_IMAGE_START) ? FLASH_NS_IMAGE_START : __tz_FLASH_N;
470
471    /* Note: There are no secure/non-secure boundaries for QSPI.  These symbols are provided for the RA configuration tool. */
472    __tz_QSPI_FLASH_S = ORIGIN(QSPI_FLASH);
473
474    /* QSPI_FLASH section to be downloaded via debugger */
475    .qspi_flash :
476    {
477        __qspi_flash_start__ = .;
478        KEEP(*(.qspi_flash*))
479        KEEP(*(.code_in_qspi*))
480        __qspi_flash_end__ = .;
481    } > QSPI_FLASH
482    __qspi_flash_code_size__ = __qspi_flash_end__ - __qspi_flash_start__;
483
484    /* QSPI_FLASH non-retentive section, creates a copy in internal flash that can be copied to QSPI */
485    __qspi_flash_code_addr__ = sgstubs_pre_location;
486    .qspi_non_retentive : AT(__qspi_flash_code_addr__)
487    {
488        __qspi_non_retentive_start__ = .;
489        KEEP(*(.qspi_non_retentive*))
490        __qspi_non_retentive_end__ = .;
491    } > QSPI_FLASH
492    __qspi_non_retentive_size__ = __qspi_non_retentive_end__ - __qspi_non_retentive_start__;
493
494    __qspi_region_max_size__ = 0x4000000;   /* Must be the same as defined in MEMORY above */
495    __qspi_region_start_address__ = __qspi_flash_start__;
496    __qspi_region_end_address__ = __qspi_flash_start__ + __qspi_region_max_size__;
497
498    /* Note: There are no secure/non-secure boundaries for QSPI.  These symbols are provided for the RA configuration tool. */
499    __tz_QSPI_FLASH_N = __qspi_non_retentive_end__;
500
501    /* Support for OctaRAM */
502    .OSPI_DEVICE_0_NO_LOAD (NOLOAD):
503    {
504        . = ALIGN(4);
505        __ospi_device_0_start__ = .;
506        *(.ospi_device_0_no_load*)
507        . = ALIGN(4);
508        __ospi_device_0_end__ = .;
509    } > OSPI_DEVICE_0_RAM
510
511    .OSPI_DEVICE_1_NO_LOAD (NOLOAD):
512    {
513        . = ALIGN(4);
514        __ospi_device_1_start__ = .;
515        *(.ospi_device_1_no_load*)
516        . = ALIGN(4);
517        __ospi_device_1_end__ = .;
518    } > OSPI_DEVICE_1_RAM
519
520    /* Note: There are no secure/non-secure boundaries for QSPI.  These symbols are provided for the RA configuration tool. */
521    __tz_OSPI_DEVICE_0_S = ORIGIN(OSPI_DEVICE_0);
522
523    /* OSPI_DEVICE_0 section to be downloaded via debugger */
524    .OSPI_DEVICE_0 :
525    {
526        __ospi_device_0_start__ = .;
527        KEEP(*(.ospi_device_0*))
528        KEEP(*(.code_in_ospi_device_0*))
529        __ospi_device_0_end__ = .;
530    } > OSPI_DEVICE_0
531    __ospi_device_0_code_size__ = __ospi_device_0_end__ - __ospi_device_0_start__;
532
533    /* OSPI_DEVICE_0 non-retentive section, creates a copy in internal flash that can be copied to OSPI */
534     __ospi_device_0_code_addr__ = sgstubs_pre_location + (SIZEOF(.qspi_non_retentive));
535    .ospi_device_0_non_retentive : AT(__ospi_device_0_code_addr__)
536    {
537        __ospi_device_0_non_retentive_start__ = .;
538        KEEP(*(.ospi_device_0_non_retentive*))
539        __ospi_device_0_non_retentive_end__ = .;
540    } > OSPI_DEVICE_0
541    __ospi_device_0_non_retentive_size__ = __ospi_device_0_non_retentive_end__ - __ospi_device_0_non_retentive_start__;
542
543    __ospi_device_0_region_max_size__ = 0x8000000;   /* Must be the same as defined in MEMORY above */
544    __ospi_device_0_region_start_address__ = __ospi_device_0_start__;
545    __ospi_device_0_region_end_address__ = __ospi_device_0_start__ + __ospi_device_0_region_max_size__;
546
547    /* Note: There are no secure/non-secure boundaries for OSPI.  These symbols are provided for the RA configuration tool. */
548    __tz_OSPI_DEVICE_0_N = __ospi_device_0_non_retentive_end__;
549
550    /* Note: There are no secure/non-secure boundaries for OSPI.  These symbols are provided for the RA configuration tool. */
551    __tz_OSPI_DEVICE_1_S = ORIGIN(OSPI_DEVICE_1);
552
553    /* OSPI_DEVICE_1 section to be downloaded via debugger */
554    .OSPI_DEVICE_1 :
555    {
556        __ospi_device_1_start__ = .;
557        KEEP(*(.ospi_device_1*))
558        KEEP(*(.code_in_ospi_device_1*))
559        __ospi_device_1_end__ = .;
560    } > OSPI_DEVICE_1
561    __ospi_device_1_code_size__ = __ospi_device_1_end__ - __ospi_device_1_start__;
562
563    /* OSPI_DEVICE_1 non-retentive section, creates a copy in internal flash that can be copied to OSPI */
564    __ospi_device_1_code_addr__ = sgstubs_pre_location + (SIZEOF(.qspi_non_retentive) + SIZEOF(.ospi_device_0_non_retentive));
565    .ospi_device_1_non_retentive : AT(__ospi_device_1_code_addr__)
566    {
567        __ospi_device_1_non_retentive_start__ = .;
568        KEEP(*(.ospi_device_1_non_retentive*))
569        __ospi_device_1_non_retentive_end__ = .;
570    } > OSPI_DEVICE_1
571    __ospi_device_1_non_retentive_size__ = __ospi_device_1_non_retentive_end__ - __ospi_device_1_non_retentive_start__;
572
573    __ospi_device_1_region_max_size__ = 0x10000000;   /* Must be the same as defined in MEMORY above */
574    __ospi_device_1_region_start_address__ = __ospi_device_1_start__;
575    __ospi_device_1_region_end_address__ = __ospi_device_1_start__ + __ospi_device_1_region_max_size__;
576
577    /* Note: There are no secure/non-secure boundaries for OSPI.  These symbols are provided for the RA configuration tool. */
578    __tz_OSPI_DEVICE_1_N = __ospi_device_1_non_retentive_end__;
579
580    .noinit (NOLOAD):
581    {
582        . = ALIGN(4);
583        __noinit_start = .;
584        KEEP(*(.noinit*))
585        . = ALIGN(8);
586        /* Place the FreeRTOS heap here so that the __HeapLimit calculation does not include the freertos heap. */
587        KEEP(*(.heap.*))
588        __noinit_end = .;
589    } > RAM
590
591    . = .;
592    __nocache_pre_location = .;
593    .nocache ALIGN(32) (NOLOAD):
594    {
595        __nocache_start = .;
596
597        KEEP(*(.nocache))
598
599        . = ALIGN(32);
600        __nocache_end = .;
601    } > RAM
602    . = (SIZEOF(.nocache) > 0) ? __nocache_end : __nocache_pre_location;
603
604    .bss :
605    {
606        . = ALIGN(4);
607        __bss_start__ = .;
608        *(.bss*)
609        *(COMMON)
610        . = ALIGN(4);
611        __bss_end__ = .;
612    } > RAM
613
614    .heap (NOLOAD):
615    {
616        . = ALIGN(8);
617        __HeapBase = .;
618        /* Place the STD heap here. */
619        KEEP(*(.heap))
620        __HeapLimit = .;
621    } > RAM
622
623    /* Stacks are stored in this section. */
624    .stack_dummy (NOLOAD):
625    {
626        . = ALIGN(8);
627        __StackLimit = .;
628        /* Main stack */
629        KEEP(*(.stack))
630        __StackTop = .;
631        /* Thread stacks */
632        KEEP(*(.stack*))
633        __StackTopAll = .;
634    } > RAM
635
636    PROVIDE(__stack = __StackTopAll);
637
638    /* This symbol represents the end of user allocated RAM. The RAM after this symbol can be used
639       at run time for things such as ThreadX memory pool allocations. */
640    __RAM_segment_used_end__ = ALIGN(__StackTopAll , 4);
641
642    /* RAM_NSC_START can be used to set a fixed address for non-secure callable RAM in secure projects.
643     * If it is not specified, the address for NSC RAM is the end of RAM aligned to a 1K boundary.
644     * In flat projects that require non-secure RAM, this variable is set to the start of non-secure RAM. */
645    __RAM_NSC_START = DEFINED(RAM_NSC_START) ? ABSOLUTE(RAM_NSC_START - RAM_NS_BUFFER_BLOCK_LENGTH) : __RESERVE_NS_RAM ? ABSOLUTE(RAM_NS_BUFFER_BLOCK_START) : ALIGN(__RAM_segment_used_end__, 1024);
646
647    /* RAM_NS_START can be used to set a fixed address for non-secure RAM in secure projects or flat projects.
648     * RAM_NS_BUFFER_BLOCK_LENGTH is used to allocate non-secure buffers in a flat project. If it is not
649     * specified, the address for NSC RAM is the end of RAM aligned to an 8K boundary.
650     * In flat projects that require non-secure RAM, this variable is set to the start of non-secure RAM. */
651    __tz_RAM_N = DEFINED(FLASH_BOOTLOADER_LENGTH) ? (RAM_START + RAM_LENGTH - RAM_APPLICATION_NS_LENGTH) : DEFINED(RAM_NS_START) ? ABSOLUTE(RAM_NS_START - RAM_NS_BUFFER_BLOCK_LENGTH) : __RESERVE_NS_RAM ? ABSOLUTE(RAM_NS_BUFFER_BLOCK_START) : ALIGN(__RAM_NSC_START, 8192);
652
653    /* Non-secure buffers must be in non-secure RAM. This is primarily used for the EDMAC in flat projects.
654     * The EDMAC is a non-secure bus master and can only access non-secure RAM. */
655    .ns_buffer (NOLOAD):
656    {
657        /* Allocate RAM on a 32-byte boundary to help with placement of Ethernet buffers. */
658        . = __RESERVE_NS_RAM ? ABSOLUTE(RAM_NS_BUFFER_START & 0xFFFFFFE0) : .;
659
660        KEEP(*(.ns_buffer*))
661    } > RAM
662
663    /* Data flash. */
664    .data_flash :
665    {
666        . = ORIGIN(DATA_FLASH);
667        __tz_DATA_FLASH_S = .;
668        __Data_Flash_Start = .;
669        KEEP(*(.data_flash*))
670        __Data_Flash_End = .;
671
672        __tz_DATA_FLASH_N = DEFINED(DATA_FLASH_NS_START) ? ABSOLUTE(DATA_FLASH_NS_START) : __RESERVE_NS_RAM ? ABSOLUTE(DATA_FLASH_START + DATA_FLASH_LENGTH) : ALIGN(1024);
673    } > DATA_FLASH
674
675    /* Note: There are no secure/non-secure boundaries for SDRAM.  These symbols are provided for the RA configuration tool. */
676    __tz_SDRAM_S = ORIGIN(SDRAM);
677
678    /* SDRAM */
679    .sdram (NOLOAD):
680    {
681        __SDRAM_Start = .;
682        KEEP(*(.sdram*))
683        KEEP(*(.frame*))
684        __SDRAM_End = .;
685    } > SDRAM
686
687    . = .;
688    __nocache_sdram_pre_location = .;
689    .nocache_sdram ALIGN(32) (NOLOAD):
690    {
691        __nocache_sdram_start = .;
692
693        KEEP(*(.nocache_sdram))
694
695        . = ALIGN(32);
696        __nocache_sdram_end = .;
697    } > SDRAM
698    . = (SIZEOF(.nocache_sdram) > 0) ? __nocache_sdram_end : __nocache_sdram_pre_location;
699
700    /* Note: There are no secure/non-secure boundaries for SDRAM.  These symbols are provided for the RA configuration tool. */
701    __tz_SDRAM_N = __SDRAM_End;
702
703    /* Note: There are no secure/non-secure boundaries for ID_CODE.  These symbols are provided for the RA configuration tool. */
704    __tz_ID_CODE_S = ORIGIN(ID_CODE);
705
706    /* Note: There are no secure/non-secure boundaries for ID_CODE.  These symbols are provided for the RA configuration tool.
707     *       Set this symbol to the same value as __tz_ID_CODE_S so the RA configuration tool does not split the ID_CODE
708     *       memory region between TrustZone projects. */
709    __tz_ID_CODE_N = __tz_ID_CODE_S;
710
711    .id_code :
712    {
713        __ID_Code_Start = .;
714        KEEP(*(.id_code*))
715        __ID_Code_End = .;
716    } > ID_CODE
717
718
719    /* Symbol required for RA Configuration tool. */
720    __tz_OPTION_SETTING_S = ORIGIN(OPTION_SETTING_OFS);
721
722    .option_setting_ofs :
723    {
724        __OPTION_SETTING_OFS_Start = .;
725        KEEP(*(.option_setting_ofs0))
726        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_OFS_Start + 0x04 : __OPTION_SETTING_OFS_Start;
727        KEEP(*(.option_setting_ofs2))
728        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_OFS_Start + 0x10 : __OPTION_SETTING_OFS_Start;
729        KEEP(*(.option_setting_dualsel))
730        __OPTION_SETTING_OFS_End = .;
731    } > OPTION_SETTING_OFS = 0xFF
732
733    .option_setting_sas :
734    {
735        __OPTION_SETTING_SAS_Start = .;
736        KEEP(*(.option_setting_sas))
737        __OPTION_SETTING_SAS_End = .;
738    } > OPTION_SETTING_SAS = 0xFF
739
740    /* Symbol required for RA Configuration tool. */
741    __tz_OPTION_SETTING_N = ABSOLUTE(OPTION_SETTING_START_NS);
742
743    .option_setting_ns :
744    {
745        __OPTION_SETTING_NS_Start = .;
746        KEEP(*(.option_setting_ofs1))
747        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x04 : __OPTION_SETTING_NS_Start;
748        KEEP(*(.option_setting_ofs3))
749        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x10 : __OPTION_SETTING_NS_Start;
750        KEEP(*(.option_setting_banksel))
751        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x40 : __OPTION_SETTING_NS_Start;
752        KEEP(*(.option_setting_bps0))
753        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x44 : __OPTION_SETTING_NS_Start;
754        KEEP(*(.option_setting_bps1))
755        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x48 : __OPTION_SETTING_NS_Start;
756        KEEP(*(.option_setting_bps2))
757        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x4C : __OPTION_SETTING_NS_Start;
758        KEEP(*(.option_setting_bps3))
759        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x60 : __OPTION_SETTING_NS_Start;
760        KEEP(*(.option_setting_pbps0))
761        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x64 : __OPTION_SETTING_NS_Start;
762        KEEP(*(.option_setting_pbps1))
763        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x68 : __OPTION_SETTING_NS_Start;
764        KEEP(*(.option_setting_pbps2))
765        . = USE_OPTION_SETTING_NS ? __OPTION_SETTING_NS_Start + 0x6C : __OPTION_SETTING_NS_Start;
766        KEEP(*(.option_setting_pbps3))
767        __OPTION_SETTING_NS_End = .;
768    } > OPTION_SETTING = 0xFF
769
770    /* Symbol required for RA Configuration tool. */
771    __tz_OPTION_SETTING_S_S = ORIGIN(OPTION_SETTING_S);
772
773    .option_setting_s :
774    {
775        __OPTION_SETTING_S_Start = .;
776        KEEP(*(.option_setting_ofs1_sec))
777        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x04 : __OPTION_SETTING_S_Start;
778        KEEP(*(.option_setting_ofs3_sec))
779        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x10 : __OPTION_SETTING_S_Start;
780        KEEP(*(.option_setting_banksel_sec))
781        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x40 : __OPTION_SETTING_S_Start;
782        KEEP(*(.option_setting_bps_sec0))
783        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x44 : __OPTION_SETTING_S_Start;
784        KEEP(*(.option_setting_bps_sec1))
785        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x48 : __OPTION_SETTING_S_Start;
786        KEEP(*(.option_setting_bps_sec2))
787        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x4C : __OPTION_SETTING_S_Start;
788        KEEP(*(.option_setting_bps_sec3))
789        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x60 : __OPTION_SETTING_S_Start;
790        KEEP(*(.option_setting_pbps_sec0))
791        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x64 : __OPTION_SETTING_S_Start;
792        KEEP(*(.option_setting_pbps_sec1))
793        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x68 : __OPTION_SETTING_S_Start;
794        KEEP(*(.option_setting_pbps_sec2))
795        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x6C : __OPTION_SETTING_S_Start;
796        KEEP(*(.option_setting_pbps_sec3))
797        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x80 : __OPTION_SETTING_S_Start;
798        KEEP(*(.option_setting_ofs1_sel))
799        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x84 : __OPTION_SETTING_S_Start;
800        KEEP(*(.option_setting_ofs3_sel))
801        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0x90 : __OPTION_SETTING_S_Start;
802        KEEP(*(.option_setting_banksel_sel))
803        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0xC0 : __OPTION_SETTING_S_Start;
804        KEEP(*(.option_setting_bps_sel0))
805        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0xC4 : __OPTION_SETTING_S_Start;
806        KEEP(*(.option_setting_bps_sel1))
807        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0xC8 : __OPTION_SETTING_S_Start;
808        KEEP(*(.option_setting_bps_sel2))
809        . = PROJECT_SECURE_OR_FLAT ? __OPTION_SETTING_S_Start + 0xCC : __OPTION_SETTING_S_Start;
810        KEEP(*(.option_setting_bps_sel3))
811        __OPTION_SETTING_S_End = .;
812    } > OPTION_SETTING_S = 0xFF
813
814    /* Symbol required for RA Configuration tool. */
815    __tz_OPTION_SETTING_S_N = __OPTION_SETTING_S_End;
816    /* Symbol required for RA Configuration tool. */
817    __tz_OPTION_SETTING_DATA_FLASH_S_S = ORIGIN(OPTION_SETTING_DATA_FLASH_S);
818
819    .option_setting_data_flash_s :
820    {
821        __OPTION_SETTING_DATA_FLASH_S_Start = .;
822        KEEP(*(.option_setting_data_flash_fsblctrl0))
823        . = USE_OPTION_SETTING_DATA_FLASH ? __OPTION_SETTING_DATA_FLASH_S_Start + 0x04 : __OPTION_SETTING_DATA_FLASH_S_Start;
824        KEEP(*(.option_setting_data_flash_fsblctrl1))
825        . = USE_OPTION_SETTING_DATA_FLASH ? __OPTION_SETTING_DATA_FLASH_S_Start + 0x08 : __OPTION_SETTING_DATA_FLASH_S_Start;
826        KEEP(*(.option_setting_data_flash_fsblctrl2))
827        . = USE_OPTION_SETTING_DATA_FLASH ? __OPTION_SETTING_DATA_FLASH_S_Start + 0x0C : __OPTION_SETTING_DATA_FLASH_S_Start;
828        KEEP(*(.option_setting_data_flash_sacc0))
829        . = USE_OPTION_SETTING_DATA_FLASH ? __OPTION_SETTING_DATA_FLASH_S_Start + 0x10 : __OPTION_SETTING_DATA_FLASH_S_Start;
830        KEEP(*(.option_setting_data_flash_sacc1))
831        . = USE_OPTION_SETTING_DATA_FLASH ? __OPTION_SETTING_DATA_FLASH_S_Start + 0x14 : __OPTION_SETTING_DATA_FLASH_S_Start;
832        KEEP(*(.option_setting_data_flash_samr))
833        . = USE_OPTION_SETTING_DATA_FLASH ? __OPTION_SETTING_DATA_FLASH_S_Start + 0x2E0 : __OPTION_SETTING_DATA_FLASH_S_Start;
834        KEEP(*(.option_setting_data_flash_hoemrtpk))
835        __OPTION_SETTING_DATA_FLASH_S_End = .;
836    } > OPTION_SETTING_DATA_FLASH_S = 0xFF
837
838    /* Symbol required for RA Configuration tool. */
839    __tz_OPTION_SETTING_DATA_FLASH_S_N = __OPTION_SETTING_DATA_FLASH_S_End;
840}