Skip to content

Commit c6245e5

Browse files
Adrian Negreanumbrossard
authored andcommitted
lpc4322 (gcc): add GNU linker script
The stack and heap have to reside in m_data. The largest symbols (.bss.TraceBuf, .bss.sector_buf, .bss.DAP_Cmd_queue) are explicitly placed in m_data_2. Signed-off-by: Adrian Negreanu <[email protected]>
1 parent ea6013d commit c6245e5

File tree

2 files changed

+235
-0
lines changed

2 files changed

+235
-0
lines changed

records/hic_hal/lpc4322.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ tool_specific:
3232
hic_hal:
3333
- source/hic_hal/nxp/lpc4322/armcc
3434
gcc_arm:
35+
linker_file:
36+
- source/hic_hal/nxp/lpc4322/gcc/lpc4322.ld
3537
sources:
3638
hic_hal:
3739
- source/hic_hal/nxp/lpc4322/gcc
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
/**
2+
* @file daplink.ld
3+
* @brief
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2016 Freescale Semiconductor, Inc.
7+
* Copyright (c) 2020-2021 NXP, All Rights Reserved
8+
* SPDX-License-Identifier: Apache-2.0
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
11+
* not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
23+
#include "daplink_addr.h"
24+
25+
/* Entry Point */
26+
ENTRY(Reset_Handler)
27+
28+
HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400;
29+
STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;
30+
31+
/* Specify the memory areas */
32+
MEMORY
33+
{
34+
m_interrupts (RX) : ORIGIN = DAPLINK_ROM_APP_START, LENGTH = 0x400
35+
m_text (RX) : ORIGIN = DAPLINK_ROM_APP_START + 0x400, LENGTH = DAPLINK_ROM_APP_SIZE - 0x400
36+
m_cfgrom (RW) : ORIGIN = DAPLINK_ROM_CONFIG_USER_START, LENGTH = DAPLINK_ROM_CONFIG_USER_SIZE
37+
m_data (RW) : ORIGIN = DAPLINK_RAM_APP_START, LENGTH = DAPLINK_RAM_APP_SIZE
38+
m_cfgram (RW) : ORIGIN = DAPLINK_RAM_SHARED_START, LENGTH = DAPLINK_RAM_SHARED_SIZE
39+
m_data_2 (RW) : ORIGIN = DAPLINK_RAM_APP2_START, LENGTH = DAPLINK_RAM_APP2_SIZE
40+
}
41+
42+
/* Define output sections */
43+
SECTIONS
44+
{
45+
/* The startup code goes first into internal flash */
46+
.interrupts :
47+
{
48+
. = ALIGN(4);
49+
KEEP(*(.isr_vector)) /* Startup code */
50+
FILL(0xffffffff)
51+
. = ALIGN(4);
52+
. += LENGTH(m_interrupts) - (. - ORIGIN(m_interrupts)); /* pad out to end of m_interrupts */
53+
} > m_interrupts
54+
55+
/* The program code and other data goes into internal flash */
56+
.text :
57+
{
58+
. = ALIGN(4);
59+
*(.text) /* .text sections (code) */
60+
*(.text*) /* .text* sections (code) */
61+
*(.rodata) /* .rodata sections (constants, strings, etc.) */
62+
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
63+
*(.glue_7) /* glue arm to thumb code */
64+
*(.glue_7t) /* glue thumb to arm code */
65+
*(.eh_frame)
66+
KEEP (*(.init))
67+
KEEP (*(.fini))
68+
. = ALIGN(4);
69+
} > m_text
70+
71+
.ARM.extab :
72+
{
73+
*(.ARM.extab* .gnu.linkonce.armextab.*)
74+
} > m_text
75+
76+
.ARM :
77+
{
78+
__exidx_start = .;
79+
*(.ARM.exidx*)
80+
__exidx_end = .;
81+
} > m_text
82+
83+
.ctors :
84+
{
85+
__CTOR_LIST__ = .;
86+
/* gcc uses crtbegin.o to find the start of
87+
the constructors, so we make sure it is
88+
first. Because this is a wildcard, it
89+
doesn't matter if the user does not
90+
actually link against crtbegin.o; the
91+
linker won't look for a file to match a
92+
wildcard. The wildcard also means that it
93+
doesn't matter which directory crtbegin.o
94+
is in. */
95+
KEEP (*crtbegin.o(.ctors))
96+
KEEP (*crtbegin?.o(.ctors))
97+
/* We don't want to include the .ctor section from
98+
from the crtend.o file until after the sorted ctors.
99+
The .ctor section from the crtend file contains the
100+
end of ctors marker and it must be last */
101+
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors))
102+
KEEP (*(SORT(.ctors.*)))
103+
KEEP (*(.ctors))
104+
__CTOR_END__ = .;
105+
} > m_text
106+
107+
.dtors :
108+
{
109+
__DTOR_LIST__ = .;
110+
KEEP (*crtbegin.o(.dtors))
111+
KEEP (*crtbegin?.o(.dtors))
112+
KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors))
113+
KEEP (*(SORT(.dtors.*)))
114+
KEEP (*(.dtors))
115+
__DTOR_END__ = .;
116+
} > m_text
117+
118+
.preinit_array :
119+
{
120+
PROVIDE_HIDDEN (__preinit_array_start = .);
121+
KEEP (*(.preinit_array*))
122+
PROVIDE_HIDDEN (__preinit_array_end = .);
123+
} > m_text
124+
125+
.init_array :
126+
{
127+
PROVIDE_HIDDEN (__init_array_start = .);
128+
KEEP (*(SORT(.init_array.*)))
129+
KEEP (*(.init_array*))
130+
PROVIDE_HIDDEN (__init_array_end = .);
131+
} > m_text
132+
133+
.fini_array :
134+
{
135+
PROVIDE_HIDDEN (__fini_array_start = .);
136+
KEEP (*(SORT(.fini_array.*)))
137+
KEEP (*(.fini_array*))
138+
PROVIDE_HIDDEN (__fini_array_end = .);
139+
} > m_text
140+
141+
__etext = .; /* define a global symbol at end of code */
142+
__DATA_ROM = .; /* Symbol is used by startup for data initialization */
143+
144+
.data : AT(__DATA_ROM)
145+
{
146+
. = ALIGN(4);
147+
__DATA_RAM = .;
148+
__data_start__ = .; /* create a global symbol at data start */
149+
*(.data) /* .data sections */
150+
*(.data*) /* .data* sections */
151+
KEEP(*(.jcr*))
152+
. = ALIGN(4);
153+
__data_end__ = .; /* define a global symbol at data end */
154+
} > m_data
155+
156+
__DATA_END = __DATA_ROM + (__data_end__ - __data_start__);
157+
158+
/* fill .text out to the end of the app */
159+
.fill __DATA_END :
160+
{
161+
FILL(0xffffffff)
162+
. = ALIGN(4);
163+
. += DAPLINK_ROM_APP_START + DAPLINK_ROM_APP_SIZE - __DATA_END - 4;
164+
/* Need some contents in this section or it won't be copied to bin or hex. The CRC will
165+
* be placed here by post_build_script.py. */
166+
LONG(0x55555555)
167+
} > m_text
168+
169+
text_end = ORIGIN(m_text) + LENGTH(m_text);
170+
ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data")
171+
172+
.cfgrom (NOLOAD) :
173+
{
174+
*(cfgrom)
175+
} > m_cfgrom
176+
177+
/* Uninitialized data section */
178+
179+
/* build .bss_2 first so we don't have to exclude any sections put in here from .bss */
180+
.bss_2 :
181+
{
182+
. = ALIGN(4);
183+
*(.bss.TraceBuf)
184+
*(.bss.sector_buf)
185+
*(.bss.DAP_Cmd_queue)
186+
. = ALIGN(4);
187+
} > m_data_2
188+
189+
.bss :
190+
{
191+
/* This is used by the startup in order to initialize the .bss section */
192+
. = ALIGN(4);
193+
__START_BSS = .;
194+
__bss_start__ = .;
195+
*(.bss)
196+
*(.bss*)
197+
*(COMMON)
198+
. = ALIGN(4);
199+
__bss_end__ = .;
200+
__END_BSS = .;
201+
} > m_data
202+
203+
.heap :
204+
{
205+
. = ALIGN(8);
206+
__end__ = .;
207+
PROVIDE(end = .);
208+
__HeapBase = .;
209+
. += HEAP_SIZE;
210+
__HeapLimit = .;
211+
__heap_limit = .; /* Add for _sbrk */
212+
} > m_data
213+
214+
.stack :
215+
{
216+
. = ALIGN(8);
217+
. += STACK_SIZE;
218+
} > m_data
219+
220+
.cfgram (NOLOAD) :
221+
{
222+
*(cfgram)
223+
} > m_cfgram
224+
225+
/* Initializes stack on the end of block */
226+
__StackTop = ORIGIN(m_data) + LENGTH(m_data);
227+
__StackLimit = __StackTop - STACK_SIZE;
228+
PROVIDE(__stack = __StackTop);
229+
230+
.ARM.attributes 0 : { *(.ARM.attributes) }
231+
232+
ASSERT(__StackLimit >= __HeapLimit, "region overflowed with stack and heap")
233+
}

0 commit comments

Comments
 (0)