1/******************************************************************************
2 * Copyright (C) 2022-2025, 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        HC32F334xA.ld                                                */
12/*  Abstract    Linker script for HC32F334 Device with                       */
13/*              128KByte FLASH, 68KByte RAM                                  */
14/*  Version     V1.0                                                         */
15/*  Date        2024-01-15                                                   */
16/*****************************************************************************/
17/* OTP section(not flash multiplexed region) implementation.
18   You need to pay attention to the size of the specified OTP block.
19   Take two OTP blocks for example. */
20__OTP_DATA_BASE = 0x03000C00;
21__OTP_LOCK_BASE = 0x03000A80;
22/* OTP block 1 */
23__OTP_DATA_B1_START  = 0x03000C00;
24__OTP_LOCK_B1_START  = 0x03000AC0;
25__OTP_DATA_B1_OFFSET = __OTP_DATA_B1_START - __OTP_DATA_BASE;
26__OTP_LOCK_B1_OFFSET = __OTP_LOCK_B1_START - __OTP_LOCK_BASE;
27/* OTP block 2 */
28__OTP_DATA_B2_START  = 0x03000C40;
29__OTP_LOCK_B2_START  = 0x03000AC4;
30__OTP_DATA_B2_OFFSET = __OTP_DATA_B2_START - __OTP_DATA_BASE;
31__OTP_LOCK_B2_OFFSET = __OTP_LOCK_B2_START - __OTP_LOCK_BASE;
32
33/* Use contiguous memory regions for simple. */
34MEMORY
35{
36    FLASH       (rx): ORIGIN = 0x00000000, LENGTH = 128K
37    OTP_DATA    (rx): ORIGIN = 0x03000C00, LENGTH = 1K
38    OTP_LOCK    (rx): ORIGIN = 0x03000A80, LENGTH = 68
39    RAM        (rwx): ORIGIN = 0x1FFFC000, LENGTH = 32K
40    RAMB       (rwx): ORIGIN = 0x200F0000, LENGTH = 4K
41}
42
43ENTRY(Reset_Handler)
44
45SECTIONS
46{
47    .vectors :
48    {
49        . = ALIGN(4);
50        KEEP(*(.vectors))
51        . = ALIGN(4);
52    } >FLASH
53
54    .icg_sec 0x00000400 :
55    {
56        KEEP(*(.icg_sec))
57    } >FLASH
58
59    .text :
60    {
61        . = ALIGN(4);
62        _stext = .;
63        KEEP(*(.isr_vector))            /* Startup code */
64        . = ALIGN(4);
65        *(.text)                        /* remaining code */
66        *(.text.*)                      /* remaining code */
67        *(.rodata)                      /* read-only data (constants) */
68        *(.rodata*)
69        *(.glue_7)
70        *(.glue_7t)
71        *(.gnu.linkonce.t*)
72
73        /* section information for finsh shell */
74        . = ALIGN(4);
75        __fsymtab_start = .;
76        KEEP(*(FSymTab))
77        __fsymtab_end = .;
78        . = ALIGN(4);
79        __vsymtab_start = .;
80        KEEP(*(VSymTab))
81        __vsymtab_end = .;
82        . = ALIGN(4);
83
84        /* section information for initial. */
85        . = ALIGN(4);
86        __rt_init_start = .;
87        KEEP(*(SORT(.rti_fn*)))
88        __rt_init_end = .;
89        . = ALIGN(4);
90
91        . = ALIGN(4);
92        _etext = .;
93    } >FLASH
94
95    .rodata :
96    {
97        . = ALIGN(4);
98        *(.rodata)
99        *(.rodata*)
100        . = ALIGN(4);
101    } >FLASH
102
103    .ARM.extab :
104    {
105        *(.ARM.extab* .gnu.linkonce.armextab.*)
106    } >FLASH
107
108    __exidx_start = .;
109    .ARM.exidx :
110    {
111        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
112    } >FLASH
113    __exidx_end = .;
114
115    .preinit_array :
116    {
117        . = ALIGN(4);
118        /* preinit data */
119        PROVIDE_HIDDEN (__preinit_array_start = .);
120        KEEP(*(.preinit_array))
121        PROVIDE_HIDDEN (__preinit_array_end = .);
122        . = ALIGN(4);
123    } >FLASH
124
125    .init_array :
126    {
127        . = ALIGN(4);
128        /* init data */
129        PROVIDE_HIDDEN (__init_array_start = .);
130        KEEP(*(SORT(.init_array.*)))
131        KEEP(*(.init_array))
132        PROVIDE_HIDDEN (__init_array_end = .);
133        . = ALIGN(4);
134    } >FLASH
135
136    .fini_array :
137    {
138        . = ALIGN(4);
139        /* finit data */
140        PROVIDE_HIDDEN (__fini_array_start = .);
141        KEEP(*(SORT(.fini_array.*)))
142        KEEP(*(.fini_array))
143        PROVIDE_HIDDEN (__fini_array_end = .);
144        . = ALIGN(4);
145    } >FLASH
146
147    __etext = ALIGN(4);
148
149    .otp_data :
150    {
151        . = ALIGN(4);
152        . = ORIGIN(OTP_DATA) + __OTP_DATA_B1_OFFSET;
153        KEEP(*(.otp_b1_data*))
154        . = ORIGIN(OTP_DATA) + __OTP_DATA_B2_OFFSET;
155        KEEP(*(.otp_b2_data*))
156        . = ALIGN(4);
157    } >OTP_DATA
158
159    .otp_lock :
160    {
161        . = ALIGN(4);
162        . = ORIGIN(OTP_LOCK) + __OTP_LOCK_B1_OFFSET;
163        KEEP(*(.otp_b1_lock*))
164        . = ORIGIN(OTP_LOCK) + __OTP_LOCK_B2_OFFSET;
165        KEEP(*(.otp_b2_lock*))
166        . = ALIGN(4);
167    } >OTP_LOCK
168
169    .data : AT (__etext)
170    {
171        . = ALIGN(4);
172        __data_start__ = .;
173        *(vtable)
174        *(.data)
175        *(.data*)
176        *(.gnu.linkonce.d*)
177        . = ALIGN(4);
178        *(.ramfunc)
179        *(.ramfunc*)
180        . = ALIGN(4);
181        __data_end__ = .;
182    } >RAM
183
184    .heap_stack (COPY) :
185    {
186        . = ALIGN(8);
187        __end__ = .;
188        PROVIDE(end = .);
189        PROVIDE(_end = .);
190        *(.heap*)
191        . = ALIGN(8);
192        __HeapLimit = .;
193
194        __StackLimit = .;
195        *(.stack*)
196        . = ALIGN(8);
197        __StackTop = .;
198    } >RAM
199
200    __etext_ramb = __etext + ALIGN (SIZEOF(.data), 4);
201    .ramb_data : AT (__etext_ramb)
202    {
203        . = ALIGN(4);
204        __data_start_ramb__ = .;
205        *(.ramb_data)
206        *(.ramb_data*)
207        . = ALIGN(4);
208        __data_end_ramb__ = .;
209    } >RAMB
210
211    __bss_start = .;
212    .bss __StackTop (NOLOAD):
213    {
214        . = ALIGN(4);
215        _sbss = .;
216        __bss_start__ = _sbss;
217        *(.bss)
218        *(.bss*)
219        *(COMMON)
220        . = ALIGN(4);
221        _ebss = .;
222        __bss_end__ = _ebss;
223        . = ALIGN(4);
224        *(.noinit*)
225        . = ALIGN(4);
226    } >RAM
227    __bss_end = .;
228
229    .ramb_bss :
230    {
231        . = ALIGN(4);
232        __bss_start_ramb__ = .;
233        *(.ramb_bss)
234        *(.ramb_bss*)
235        . = ALIGN(4);
236        __bss_end_ramb__ = .;
237    } >RAMB
238
239    /DISCARD/ :
240    {
241        libc.a (*)
242        libm.a (*)
243        libgcc.a (*)
244    }
245
246    .ARM.attributes 0 : { *(.ARM.attributes) }
247
248    PROVIDE(_stack = __StackTop);
249    PROVIDE(_Min_Heap_Size = __HeapLimit - __HeapBase);
250    PROVIDE(_Min_Stack_Size = __StackTop - __StackLimit);
251
252    __RamEnd = ORIGIN(RAM) + LENGTH(RAM);
253    ASSERT(__StackTop <= __RamEnd, "region RAM overflowed with stack")
254
255    /* Stabs debugging sections.  */
256    .stab          0 : { *(.stab) }
257    .stabstr       0 : { *(.stabstr) }
258    .stab.excl     0 : { *(.stab.excl) }
259    .stab.exclstr  0 : { *(.stab.exclstr) }
260    .stab.index    0 : { *(.stab.index) }
261    .stab.indexstr 0 : { *(.stab.indexstr) }
262    .comment       0 : { *(.comment) }
263    /* DWARF debug sections.
264     * Symbols in the DWARF debugging sections are relative to the beginning
265     * of the section so we begin them at 0.  */
266    /* DWARF 1 */
267    .debug          0 : { *(.debug) }
268    .line           0 : { *(.line) }
269    /* GNU DWARF 1 extensions */
270    .debug_srcinfo  0 : { *(.debug_srcinfo) }
271    .debug_sfnames  0 : { *(.debug_sfnames) }
272    /* DWARF 1.1 and DWARF 2 */
273    .debug_aranges  0 : { *(.debug_aranges) }
274    .debug_pubnames 0 : { *(.debug_pubnames) }
275    /* DWARF 2 */
276    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
277    .debug_abbrev   0 : { *(.debug_abbrev) }
278    .debug_line     0 : { *(.debug_line) }
279    .debug_frame    0 : { *(.debug_frame) }
280    .debug_str      0 : { *(.debug_str) }
281    .debug_loc      0 : { *(.debug_loc) }
282    .debug_macinfo  0 : { *(.debug_macinfo) }
283    /* SGI/MIPS DWARF 2 extensions */
284    .debug_weaknames 0 : { *(.debug_weaknames) }
285    .debug_funcnames 0 : { *(.debug_funcnames) }
286    .debug_typenames 0 : { *(.debug_typenames) }
287    .debug_varnames  0 : { *(.debug_varnames) }
288}
289