1/******************************************************************************
2 * Copyright (C) 2022-2023, Xiaohua Semiconductor Co., Ltd. All rights reserved.
3 *
4 * This software component is licensed by XHSC under BSD 3-Clause license
5 * (the "License"); You may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at:
7 *                    opensource.org/licenses/BSD-3-Clause
8 *
9 */
10/*****************************************************************************/
11/*  File        HC32F4A0xI.ld                                                */
12/*  Abstract    Linker script for HC32F4A0 Device with                       */
13/*              2MByte FLASH, 516KByte RAM                                   */
14/*  Version     V1.0                                                         */
15/*  Date        2022-03-31                                                   */
16/*****************************************************************************/
17
18/* Custom defines, according to section 7.7 of the user manual.
19   Take OTP sector 16 for example. */
20__OTP_DATA_START = 0x03000000;
21__OTP_DATA_SIZE  = 2048;
22__OTP_LOCK_START = 0x03001840;
23__OTP_LOCK_SIZE  = 4;
24
25/* Use contiguous memory regions for simple. */
26MEMORY
27{
28    FLASH       (rx): ORIGIN = 0x00000000, LENGTH = 2M
29    OTP_DATA    (rx): ORIGIN = __OTP_DATA_START, LENGTH = __OTP_DATA_SIZE
30    OTP_LOCK    (rx): ORIGIN = __OTP_LOCK_START, LENGTH = __OTP_LOCK_SIZE
31    RAM        (rwx): ORIGIN = 0x1FFE0000, LENGTH = 512K
32    RAMB       (rwx): ORIGIN = 0x200F0000, LENGTH = 4K
33}
34
35ENTRY(Reset_Handler)
36
37SECTIONS
38{
39    .vectors :
40    {
41        . = ALIGN(4);
42        KEEP(*(.vectors))
43        . = ALIGN(4);
44    } >FLASH
45
46    .icg_sec 0x00000400 :
47    {
48        KEEP(*(.icg_sec))
49    } >FLASH
50
51    .text :
52    {
53        . = ALIGN(4);
54        _stext = .;
55        KEEP(*(.isr_vector))            /* Startup code */
56        . = ALIGN(4);
57        *(.text)                        /* remaining code */
58        *(.text.*)                      /* remaining code */
59        *(.rodata)                      /* read-only data (constants) */
60        *(.rodata*)
61        *(.glue_7)
62        *(.glue_7t)
63        *(.gnu.linkonce.t*)
64
65        /* section information for finsh shell */
66        . = ALIGN(4);
67        __fsymtab_start = .;
68        KEEP(*(FSymTab))
69        __fsymtab_end = .;
70        . = ALIGN(4);
71        __vsymtab_start = .;
72        KEEP(*(VSymTab))
73        __vsymtab_end = .;
74        . = ALIGN(4);
75
76        /* section information for initial. */
77        . = ALIGN(4);
78        __rt_init_start = .;
79        KEEP(*(SORT(.rti_fn*)))
80        __rt_init_end = .;
81        . = ALIGN(4);
82
83        . = ALIGN(4);
84        _etext = .;
85    } >FLASH
86
87    .rodata :
88    {
89        . = ALIGN(4);
90        *(.rodata)
91        *(.rodata*)
92        . = ALIGN(4);
93    } >FLASH
94
95    .ARM.extab :
96    {
97        *(.ARM.extab* .gnu.linkonce.armextab.*)
98    } >FLASH
99
100    __exidx_start = .;
101    .ARM.exidx :
102    {
103        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
104    } >FLASH
105    __exidx_end = .;
106
107    .preinit_array :
108    {
109        . = ALIGN(4);
110        /* preinit data */
111        PROVIDE_HIDDEN (__preinit_array_start = .);
112        KEEP(*(.preinit_array))
113        PROVIDE_HIDDEN (__preinit_array_end = .);
114        . = ALIGN(4);
115    } >FLASH
116
117    .init_array :
118    {
119        . = ALIGN(4);
120        /* init data */
121        PROVIDE_HIDDEN (__init_array_start = .);
122        KEEP(*(SORT(.init_array.*)))
123        KEEP(*(.init_array))
124        PROVIDE_HIDDEN (__init_array_end = .);
125        . = ALIGN(4);
126    } >FLASH
127
128    .fini_array :
129    {
130        . = ALIGN(4);
131        /* finit data */
132        PROVIDE_HIDDEN (__fini_array_start = .);
133        KEEP(*(SORT(.fini_array.*)))
134        KEEP(*(.fini_array))
135        PROVIDE_HIDDEN (__fini_array_end = .);
136        . = ALIGN(4);
137    } >FLASH
138
139    __etext = ALIGN(4);
140
141    .otp_data_sec :
142    {
143        KEEP(*(.otp_data_sec))
144    } >OTP_DATA
145
146    .otp_lock_sec :
147    {
148        KEEP(*(.otp_lock_sec))
149    } >OTP_LOCK
150
151    .data : AT (__etext)
152    {
153        . = ALIGN(4);
154        __data_start__ = .;
155        *(vtable)
156        *(.data)
157        *(.data*)
158        *(.gnu.linkonce.d*)
159        . = ALIGN(4);
160        *(.ramfunc)
161        *(.ramfunc*)
162        . = ALIGN(4);
163        __data_end__ = .;
164    } >RAM
165
166    .heap_stack (COPY) :
167    {
168        . = ALIGN(8);
169        __end__ = .;
170        PROVIDE(end = .);
171        PROVIDE(_end = .);
172        *(.heap*)
173        . = ALIGN(8);
174        __HeapLimit = .;
175
176        __StackLimit = .;
177        *(.stack*)
178        . = ALIGN(8);
179        __StackTop = .;
180    } >RAM
181
182    __etext_ramb = __etext + ALIGN (SIZEOF(.data), 4);
183    .ramb_data : AT (__etext_ramb)
184    {
185        . = ALIGN(4);
186        __data_start_ramb__ = .;
187        *(.ramb_data)
188        *(.ramb_data*)
189        . = ALIGN(4);
190        __data_end_ramb__ = .;
191    } >RAMB
192
193    __bss_start = .;
194    .bss __StackTop (NOLOAD):
195    {
196        . = ALIGN(4);
197        _sbss = .;
198        __bss_start__ = _sbss;
199        *(.bss)
200        *(.bss*)
201        *(COMMON)
202        . = ALIGN(4);
203        _ebss = .;
204        __bss_end__ = _ebss;
205        . = ALIGN(4);
206        *(.noinit*)
207        . = ALIGN(4);
208    } >RAM
209    __bss_end = .;
210
211    .ramb_bss :
212    {
213        . = ALIGN(4);
214        __bss_start_ramb__ = .;
215        *(.ramb_bss)
216        *(.ramb_bss*)
217        . = ALIGN(4);
218        __bss_end_ramb__ = .;
219    } >RAMB
220
221    /DISCARD/ :
222    {
223        libc.a (*)
224        libm.a (*)
225        libgcc.a (*)
226    }
227
228    .ARM.attributes 0 : { *(.ARM.attributes) }
229
230    PROVIDE(_stack = __StackTop);
231    PROVIDE(_Min_Heap_Size = __HeapLimit - __HeapBase);
232    PROVIDE(_Min_Stack_Size = __StackTop - __StackLimit);
233
234    __RamEnd = ORIGIN(RAM) + LENGTH(RAM);
235    ASSERT(__StackTop <= __RamEnd, "region RAM overflowed with stack")
236
237    /* Stabs debugging sections.  */
238    .stab          0 : { *(.stab) }
239    .stabstr       0 : { *(.stabstr) }
240    .stab.excl     0 : { *(.stab.excl) }
241    .stab.exclstr  0 : { *(.stab.exclstr) }
242    .stab.index    0 : { *(.stab.index) }
243    .stab.indexstr 0 : { *(.stab.indexstr) }
244    .comment       0 : { *(.comment) }
245    /* DWARF debug sections.
246     * Symbols in the DWARF debugging sections are relative to the beginning
247     * of the section so we begin them at 0.  */
248    /* DWARF 1 */
249    .debug          0 : { *(.debug) }
250    .line           0 : { *(.line) }
251    /* GNU DWARF 1 extensions */
252    .debug_srcinfo  0 : { *(.debug_srcinfo) }
253    .debug_sfnames  0 : { *(.debug_sfnames) }
254    /* DWARF 1.1 and DWARF 2 */
255    .debug_aranges  0 : { *(.debug_aranges) }
256    .debug_pubnames 0 : { *(.debug_pubnames) }
257    /* DWARF 2 */
258    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
259    .debug_abbrev   0 : { *(.debug_abbrev) }
260    .debug_line     0 : { *(.debug_line) }
261    .debug_frame    0 : { *(.debug_frame) }
262    .debug_str      0 : { *(.debug_str) }
263    .debug_loc      0 : { *(.debug_loc) }
264    .debug_macinfo  0 : { *(.debug_macinfo) }
265    /* SGI/MIPS DWARF 2 extensions */
266    .debug_weaknames 0 : { *(.debug_weaknames) }
267    .debug_funcnames 0 : { *(.debug_funcnames) }
268    .debug_typenames 0 : { *(.debug_typenames) }
269    .debug_varnames  0 : { *(.debug_varnames) }
270}
271