Skip to content

Commit e71b18d

Browse files
committed
Split RAM2 linker sections and add overflow checks
Refactors the linker script to place `.sram2`, `.dmx`, `.network`, `.pixel`, and `.http` into separate `NOLOAD` sections in RAM2, each with explicit alignment and start/end symbols. It also switches to `KEEP()` patterns for section retention and adds targeted `ASSERT` guards to fail the link if RAM2 or individual RAM2-backed regions overflow.
1 parent a2ce534 commit e71b18d

1 file changed

Lines changed: 51 additions & 17 deletions

File tree

firmware-template-gd32/gd32f207rg_flash.ld

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,63 @@ SECTIONS
115115
. = ALIGN(4);
116116
} >RAM1
117117

118-
.sram2 :
118+
.sram2 (NOLOAD) :
119119
{
120-
. = ALIGN(4);
121-
*(.sram2)
122-
*(.sram2*)
123-
. = ALIGN(4);
120+
. = ALIGN(4);
121+
_ssram2 = .;
122+
KEEP(*(.sram2))
123+
KEEP(*(.sram2.*))
124+
. = ALIGN(4);
125+
_esram2 = .;
126+
} > RAM2
127+
128+
.dmx (NOLOAD) :
129+
{
130+
. = ALIGN(4);
124131
_sdmx = .;
125-
*(.dmx)
126-
. = ALIGN(4);
132+
KEEP(*(.dmx))
133+
KEEP(*(.dmx.*))
134+
. = ALIGN(4);
127135
_edmx = .;
128-
. = ALIGN(4);
129-
_spixel = .;
130-
*(.pixel)
131-
. = ALIGN(4);
132-
_epixel = .;
133-
. = ALIGN(4);
136+
} > RAM2
137+
138+
.network (NOLOAD) :
139+
{
140+
. = ALIGN(4);
134141
_snetwork = .;
135-
*(.network*)
142+
KEEP(*(.network))
143+
KEEP(*(.network.*))
136144
. = ALIGN(4);
137145
_enetwork = .;
138-
. = ALIGN(4);
139-
*(.http*)
140-
} >RAM2
146+
} > RAM2
147+
148+
.pixel (NOLOAD) :
149+
{
150+
. = ALIGN(4);
151+
_spixel = .;
152+
KEEP(*(.pixel))
153+
KEEP(*(.pixel.*))
154+
. = ALIGN(4);
155+
_epixel = .;
156+
} > RAM2
157+
158+
.http (NOLOAD) :
159+
{
160+
. = ALIGN(4);
161+
_shttp = .;
162+
KEEP(*(.http))
163+
KEEP(*(.http.*))
164+
KEEP(*(.httpd))
165+
KEEP(*(.httpd.*))
166+
. = ALIGN(4);
167+
_ehttp = .;
168+
} > RAM2
169+
170+
ASSERT(. <= ORIGIN(RAM2) + LENGTH(RAM2), "RAM2 overflow")
171+
ASSERT(_edmx <= ORIGIN(RAM2) + LENGTH(RAM2), "DMX section exceeds RAM2")
172+
ASSERT(_enetwork <= ORIGIN(RAM2) + LENGTH(RAM2), "Network section exceeds RAM2")
173+
ASSERT(_epixel <= ORIGIN(RAM2) + LENGTH(RAM2), "Pixel section exceeds RAM2")
174+
ASSERT(_ehttp <= ORIGIN(RAM2) + LENGTH(RAM2), "HTTP section exceeds RAM2")
141175

142176
/DISCARD/ :
143177
{

0 commit comments

Comments
 (0)