summaryrefslogtreecommitdiff
path: root/bsp/gd32/arm/gd32e230-lckfb/board/linker_scripts/link.ld
blob: d0e152f404761007120dde9daceefe66798ef1d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * linker script for GD32E230x with GNU ld
 * Adapted from GD32E50x version.
 * Corrected by Gemini to fix oversized .bin file and subsequent linker errors.
 */

MEMORY
{
    /* 
     * IMPORTANT: Please check your specific chip's datasheet for correct memory sizes.
     * The following values are for a GD32E230 with 64KB Flash and 8KB SRAM.
     */
    CODE (rx) : ORIGIN = 0x08000000, LENGTH = 64k /* MODIFIED: 64KB flash */
    DATA (rw) : ORIGIN = 0x20000000, LENGTH = 8k  /* MODIFIED: 8KB sram */
}

/* Program Entry, set to mark it as "used" and avoid gc */
ENTRY(Reset_Handler)

/* 
 * Define the size of the stack used by the system. 
 * This is for the main stack pointer (MSP), used before RT-Thread scheduler starts and in interrupts.
 * Increased to 1KB for safety.
 */
_system_stack_size = 0x400; /* MODIFIED: 1024 bytes */

SECTIONS
{
    .text :
    {
        . = ALIGN(4);
        _stext = .;
        KEEP(*(.isr_vector))            /* Startup code */
        . = ALIGN(4);
        *(.text)                        /* remaining code */
        *(.text.*)                      /* remaining code */
        *(.rodata)                      /* read-only data (constants) */
        *(.rodata*)
        *(.glue_7)
        *(.glue_7t)
        *(.gnu.linkonce.t*)

        /* section information for finsh shell */
        . = ALIGN(4);
        __fsymtab_start = .;
        KEEP(*(FSymTab))
        __fsymtab_end = .;
        . = ALIGN(4);
        __vsymtab_start = .;
        KEEP(*(VSymTab))
        __vsymtab_end = .;
        . = ALIGN(4);

        /* section information for initial. */
        . = ALIGN(4);
        __rt_init_start = .;
        KEEP(*(SORT(.rti_fn*)))
        __rt_init_end = .;
        . = ALIGN(4);

        . = ALIGN(4);
        _etext = .;
    } > CODE

    /* 
     * The .ARM.exidx section is needed for exception handling and stack unwinding.
     * It should be placed in a loadable region like CODE.
     */
    .ARM.exidx :
    {
        __exidx_start = .;
        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
        __exidx_end = .;
    } > CODE
    
    /*
     * Define the load address for the .data section.
     * It should immediately follow the .ARM.exidx section in Flash.
     */
    _sidata = __exidx_end;

    /* .data section which is used for initialized data */
    .data : AT (_sidata)
    {
        . = ALIGN(4);
        _sdata = . ;
        *(.data)
        *(.data.*)
        *(.gnu.linkonce.d*)
        . = ALIGN(4);
        _edata = . ;
    } > DATA

    /* Main stack, located at the top of the RAM region */
    .stack (NOLOAD):
    {
        . = ALIGN(8);
        _sstack = .;
        . = . + _system_stack_size;
        . = ALIGN(8);
        _estack = .;
    } > DATA

    /* .bss section which is used for uninitialized data */
    .bss :
    {
        . = ALIGN(4);
        _sbss = .;
        *(.bss)
        *(.bss.*)
        *(COMMON)
        . = ALIGN(4);
        _ebss = . ;
    } > DATA

    /* Define __bss_end for C code to find the heap start. */
    __bss_end = _ebss;

    _end = .;
    
    /******************************************************************************
     * Corrected section to discard unwanted information from the final binary. *
     ******************************************************************************/
    /DISCARD/ :
    {
        libc.a ( * )
        libm.a ( * )
        libgcc.a ( * )

        /* Discard all debugging and comment sections using the correct wildcard syntax */
        *(.comment)
        *(.note.gnu.build-id)
        *(.ARM.attributes)
    }
}