1/*
2 * Copyright (c) 2023 HPMicro
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6ENTRY(_start)
7
8STACK_SIZE = _stack_size;
9HEAP_SIZE = _heap_size;
10UF2_BOOTLOADER_RESERVED_LENGTH = DEFINED(_uf2_bl_length) ? _uf2_bl_length : 0x20000;
11
12MEMORY
13{
14    XPI0 (rx) : ORIGIN = 0x80000000 + UF2_BOOTLOADER_RESERVED_LENGTH, LENGTH = _flash_size - UF2_BOOTLOADER_RESERVED_LENGTH
15    ILM (wx) : ORIGIN = 0x00000000, LENGTH = 128K
16    DLM (w) : ORIGIN = 0x00080000, LENGTH = 128K
17    AHB_SRAM (w) : ORIGIN = 0xF0400000, LENGTH = 32k
18}
19
20SECTIONS
21{
22    .start : {
23        KEEP(*(.uf2_signature))
24        KEEP(*(.start))
25    } > XPI0
26
27    __vector_load_addr__ = ADDR(.start) + SIZEOF(.start);
28    .vectors ORIGIN(ILM) : AT(__vector_load_addr__) {
29        . = ALIGN(8);
30        __vector_ram_start__ = .;
31        KEEP(*(.vector_table))
32        KEEP(*(.isr_vector))
33        KEEP(*(.vector_s_table))
34        KEEP(*(.isr_s_vector))
35        . = ALIGN(8);
36        __vector_ram_end__ = .;
37    } > ILM
38
39    .text (__vector_load_addr__ + SIZEOF(.vectors)): {
40        . = ALIGN(8);
41        *(.text)
42        *(.text*)
43        *(.rodata)
44        *(.rodata*)
45        *(.srodata)
46        *(.srodata*)
47
48        *(.hash)
49        *(.dyn*)
50        *(.gnu*)
51        *(.pl*)
52
53        KEEP (*(.init))
54        KEEP (*(.fini))
55
56        /* section information for usbh class */
57        . = ALIGN(8);
58        __usbh_class_info_start__ = .;
59        KEEP(*(.usbh_class_info))
60        __usbh_class_info_end__ = .;
61
62        /* RT-Thread related sections - Start */
63        /* section information for finsh shell */
64        . = ALIGN(4);
65        __fsymtab_start = .;
66        KEEP(*(FSymTab))
67        __fsymtab_end = .;
68        . = ALIGN(4);
69        __vsymtab_start = .;
70        KEEP(*(VSymTab))
71        __vsymtab_end = .;
72        . = ALIGN(4);
73
74        . = ALIGN(4);
75        __rt_init_start = .;
76        KEEP(*(SORT(.rti_fn*)))
77        __rt_init_end = .;
78        . = ALIGN(4);
79
80        /* section information for modules */
81        . = ALIGN(4);
82        __rtmsymtab_start = .;
83        KEEP(*(RTMSymTab))
84        __rtmsymtab_end = .;
85
86        /* RT-Thread related sections - end */
87        . = ALIGN(8);
88    } > XPI0
89
90    .eh_frame :
91    {
92        __eh_frame_start = .;
93        KEEP(*(.eh_frame))
94        __eh_frame_end = .;
95    }  > XPI0
96
97    .eh_frame_hdr :
98    {
99        KEEP(*(.eh_frame_hdr))
100    }  > XPI0
101    __eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0;
102    __eh_frame_hdr_end = SIZEOF(.eh_frame_hdr) > 0 ? . : 0;
103
104    .rel : {
105        KEEP(*(.rel*))
106    } > XPI0
107
108    PROVIDE (__etext = .);
109    PROVIDE (_etext = .);
110    PROVIDE (etext = .);
111
112    __data_load_addr__ = etext;
113    .data : AT(__data_load_addr__) {
114        . = ALIGN(8);
115        __data_start__ = .;
116        __global_pointer$ = . + 0x800;
117        *(.data)
118        *(.data*)
119        *(.sdata)
120        *(.sdata*)
121
122        KEEP(*(.jcr))
123        KEEP(*(.dynamic))
124        KEEP(*(.got*))
125        KEEP(*(.got))
126        KEEP(*(.gcc_except_table))
127        KEEP(*(.gcc_except_table.*))
128
129        . = ALIGN(8);
130        PROVIDE(__preinit_array_start = .);
131        KEEP(*(.preinit_array))
132        PROVIDE(__preinit_array_end = .);
133
134        . = ALIGN(8);
135        PROVIDE(__init_array_start = .);
136        KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)))
137        KEEP(*(.init_array))
138        PROVIDE(__init_array_end = .);
139
140        . = ALIGN(8);
141        PROVIDE(__finit_array_start = .);
142        KEEP(*(SORT_BY_INIT_PRIORITY(.finit_array.*)))
143        KEEP(*(.finit_array))
144        PROVIDE(__finit_array_end = .);
145
146        . = ALIGN(8);
147        KEEP(*crtbegin*.o(.ctors))
148        KEEP(*(EXCLUDE_FILE (*crtend*.o) .ctors))
149        KEEP(*(SORT(.ctors.*)))
150        KEEP(*(.ctors))
151
152        . = ALIGN(8);
153        KEEP(*crtbegin*.o(.dtors))
154        KEEP(*(EXCLUDE_FILE (*crtend*.o) .dtors))
155        KEEP(*(SORT(.dtors.*)))
156        KEEP(*(.dtors))
157        . = ALIGN(8);
158        __data_end__ = .;
159        PROVIDE (__edata = .);
160        PROVIDE (_edata = .);
161        PROVIDE (edata = .);
162    } > DLM
163
164    __fast_load_addr__ = etext + SIZEOF(.data);
165    .fast : AT(__fast_load_addr__) {
166        . = ALIGN(8);
167        PROVIDE(__ramfunc_start__ = .);
168        *(.fast)
169        *(.fast.*)
170        . = ALIGN(8);
171        PROVIDE(__ramfunc_end__ = .);
172    } > ILM
173
174    .bss (NOLOAD) : {
175        . = ALIGN(8);
176        __bss_start__ = .;
177        *(.bss)
178        *(.bss*)
179        *(.sbss*)
180        *(.scommon)
181        *(.scommon*)
182        *(.dynsbss*)
183        *(COMMON)
184        . = ALIGN(8);
185        _end = .;
186        __bss_end__ = .;
187    } > DLM
188
189    __tdata_load_addr__ = etext + SIZEOF(.data) + SIZEOF(.fast);
190    .tdata : AT(__tdata_load_addr__) {
191        . = ALIGN(8);
192        PROVIDE(__tdata_start__ = .);
193        *(.tdata)
194        *(.tdata.*)
195        *(.gnu.linkonce.td.*)
196        . = ALIGN(8);
197        PROVIDE(__tdata_end__ = .);
198    } > DLM
199
200    .tbss (NOLOAD) : {
201        . = ALIGN(8);
202        PROVIDE(__tbss_start__ = .);
203        __thread_pointer$ = .;
204        *(.tbss)
205        *(.tbss.*)
206        *(.gnu.linkonce.tb.*)
207        *(.tcommon)
208        . = ALIGN(8);
209        PROVIDE(__tbss_end__ = .);
210    } > DLM
211
212    .framebuffer (NOLOAD) : {
213        . = ALIGN(8);
214        KEEP(*(.framebuffer))
215        . = ALIGN(8);
216    } > DLM
217
218    __noncacheable_init_load_addr__ = etext + SIZEOF(.data) + SIZEOF(.fast) + SIZEOF(.tdata);
219    .noncacheable.init : AT(__noncacheable_init_load_addr__) {
220        . = ALIGN(8);
221        __noncacheable_init_start__ = .;
222        KEEP(*(.noncacheable.init))
223        __noncacheable_init_end__ = .;
224        . = ALIGN(8);
225    } > DLM
226
227    .noncacheable.bss (NOLOAD) : {
228        . = ALIGN(8);
229        KEEP(*(.noncacheable))
230        __noncacheable_bss_start__ = .;
231        KEEP(*(.noncacheable.bss))
232        __noncacheable_bss_end__ = .;
233        . = ALIGN(8);
234    } > DLM
235
236    __fast_ram_init_load_addr__ = etext + SIZEOF(.data) + SIZEOF(.fast) + SIZEOF(.tdata) + SIZEOF(.noncacheable.init);
237    .fast_ram.init : AT(__fast_ram_init_load_addr__) {
238        . = ALIGN(8);
239        __fast_ram_init_start__ = .;
240        KEEP(*(.fast_ram.init))
241        __fast_ram_init_end__ = .;
242        . = ALIGN(8);
243    } > DLM
244
245    .ahb_sram (NOLOAD) : {
246        KEEP(*(.ahb_sram))
247    } > AHB_SRAM
248
249    .fast_ram.bss (NOLOAD) : {
250        . = ALIGN(8);
251        KEEP(*(.fast_ram))
252        __fast_ram_bss_start__ = .;
253        KEEP(*(.fast_ram.bss))
254        __fast_ram_bss_end__ = .;
255        . = ALIGN(8);
256    } > DLM
257
258    .heap (NOLOAD) : {
259        . = ALIGN(8);
260        __heap_start__ = .;
261        . += HEAP_SIZE;
262        __heap_end__ = .;
263    } > DLM
264
265    .stack (NOLOAD) : {
266        . = ALIGN(16);
267        __stack_base__ = .;
268        . += STACK_SIZE;
269        . = ALIGN(16);
270        PROVIDE (_stack = .);
271        PROVIDE (_stack_safe = .);
272    } > DLM
273
274    __fw_size__ = SIZEOF(.start) + SIZEOF(.vectors) + SIZEOF(.rel) + SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.fast) + SIZEOF(.tdata) + SIZEOF(.noncacheable.init) + SIZEOF(.fast_ram.init);
275    __last_addr__ = __fast_ram_init_load_addr__ + SIZEOF(.fast_ram.init);
276    ASSERT(((__fw_size__ <= LENGTH(XPI0)) && (__last_addr__ <= (ORIGIN(XPI0) + LENGTH(XPI0)))), "******  FAILED! XPI0 has not enough space!  ******")
277}
278