Skip to content

Commit 685733b

Browse files
committed
Linker: make linker scripts cleaner and more robust
1 parent 7a34afb commit 685733b

10 files changed

+89
-70
lines changed

Linker/STM32F7xx.ld

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ MEMORY
4545
/* Sections */
4646
SECTIONS
4747
{
48+
.restart_info (NOLOAD) :
49+
{
50+
. = ALIGN(4);
51+
KEEP(*(.restart_info))
52+
. = ALIGN(4);
53+
} >RAM1
54+
4855
/* The startup code into "FLASH" Rom type memory */
4956
.isr_vector :
5057
{
@@ -127,11 +134,6 @@ SECTIONS
127134
/* Used by the startup to initialize data */
128135
_sidata = LOADADDR(.data);
129136

130-
.restart_info : ALIGN(4)
131-
{
132-
KEEP(*(.restart_info))
133-
} >RAM1 AT> FLASH
134-
135137
/* Initialized data sections into "RAM" Ram type memory */
136138
.data :
137139
{

Linker/STM32F7xx_RAM.ld

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ MEMORY
4545
/* Sections */
4646
SECTIONS
4747
{
48+
.restart_info (NOLOAD) :
49+
{
50+
. = ALIGN(4);
51+
KEEP(*(.restart_info))
52+
. = ALIGN(4);
53+
} >RAM1
54+
4855
/* The startup code into "RAM" Ram type memory */
4956
.isr_vector :
5057
{
@@ -129,11 +136,6 @@ SECTIONS
129136
/* Used by the startup to initialize data */
130137
_sidata = LOADADDR(.data);
131138

132-
.restart_info : ALIGN(4)
133-
{
134-
KEEP(*(.restart_info))
135-
} >RAM1 AT> RAM2
136-
137139
/* Initialized data sections into "RAM" Ram type memory */
138140
.data :
139141
{
@@ -161,7 +163,7 @@ SECTIONS
161163
. = ALIGN(4);
162164
_ebss = .; /* define a global symbol at bss end */
163165
__bss_end__ = _ebss;
164-
} >RAM1 AT> RAM2
166+
} >RAM1
165167

166168
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
167169
._user_heap_stack :
@@ -172,7 +174,7 @@ SECTIONS
172174
. = . + _Min_Heap_Size;
173175
. = . + _Min_Stack_Size;
174176
. = ALIGN(8);
175-
} >RAM1 AT> RAM2
177+
} >RAM1
176178

177179
/* Remove information from the compiler libraries */
178180
/DISCARD/ :

Linker/STM32F7xx_RAM_SIGNATURE.ld

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ SECTIONS
5151
KEEP(*(.bl_ram_signature))
5252
} >SIGNATURE
5353

54+
.restart_info (NOLOAD) :
55+
{
56+
. = ALIGN(4);
57+
KEEP(*(.restart_info))
58+
. = ALIGN(4);
59+
} >RAM1
60+
5461
/* The startup code into "RAM" Ram type memory */
5562
.isr_vector :
5663
{
@@ -131,15 +138,10 @@ SECTIONS
131138
PROVIDE_HIDDEN (__fini_array_end = .);
132139
. = ALIGN(4);
133140
} >RAM2
134-
141+
135142
/* Used by the startup to initialize data */
136143
_sidata = LOADADDR(.data);
137144

138-
.restart_info : ALIGN(4)
139-
{
140-
KEEP(*(.restart_info))
141-
} >RAM1 AT> RAM2
142-
143145
/* Initialized data sections into "RAM" Ram type memory */
144146
.data :
145147
{
@@ -167,7 +169,7 @@ SECTIONS
167169
. = ALIGN(4);
168170
_ebss = .; /* define a global symbol at bss end */
169171
__bss_end__ = _ebss;
170-
} >RAM1 AT> RAM2
172+
} >RAM1
171173

172174
/* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
173175
._user_heap_stack :
@@ -178,7 +180,7 @@ SECTIONS
178180
. = . + _Min_Heap_Size;
179181
. = . + _Min_Stack_Size;
180182
. = ALIGN(8);
181-
} >RAM1 AT> RAM2
183+
} >RAM1
182184

183185
/* Remove information from the compiler libraries */
184186
/DISCARD/ :

Linker/STM32F7xx_SIGNATURE.ld

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ SECTIONS
5151
KEEP(*(.bl_flash_signature))
5252
} >SIGNATURE
5353

54+
.restart_info (NOLOAD) :
55+
{
56+
. = ALIGN(4);
57+
KEEP(*(.restart_info))
58+
. = ALIGN(4);
59+
} >RAM1
60+
5461
/* The startup code into "FLASH" Rom type memory */
5562
.isr_vector :
5663
{
@@ -133,11 +140,6 @@ SECTIONS
133140
/* Used by the startup to initialize data */
134141
_sidata = LOADADDR(.data);
135142

136-
.restart_info : ALIGN(4)
137-
{
138-
KEEP(*(.restart_info))
139-
} >RAM1 AT> FLASH
140-
141143
/* Initialized data sections into "RAM" Ram type memory */
142144
.data :
143145
{

Linker/STM32H7xx.ld

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,19 @@ RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 128K
6666
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
6767
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
6868
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
69-
SIGNATURE (rx) : ORIGIN = 0x07FFFFC0, LENGTH = 64 /* Never written to the FLASH, it is for binary signature. */
7069
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
7170
}
7271

7372
/* Define output sections */
7473
SECTIONS
7574
{
75+
.restart_info (NOLOAD) :
76+
{
77+
. = ALIGN(4);
78+
KEEP(*(.restart_info))
79+
. = ALIGN(4);
80+
} >DTCMRAM
81+
7682
/* The startup code goes first into FLASH */
7783
.isr_vector :
7884
{
@@ -139,14 +145,9 @@ SECTIONS
139145
KEEP (*(.fini_array*))
140146
PROVIDE_HIDDEN (__fini_array_end = .);
141147
} >FLASH
142-
143-
/* used by the startup to initialize data */
144-
_sidata = LOADADDR(.data);
145148

146-
.restart_info : ALIGN(4)
147-
{
148-
KEEP(*(.restart_info))
149-
} >DTCMRAM AT> FLASH
149+
/* used by the startup to initialize data */
150+
_sidata = LOADADDR(.data);
150151

151152
/* Initialized data sections goes into RAM, load LMA copy after code */
152153
.data :
@@ -160,7 +161,6 @@ SECTIONS
160161
_edata = .; /* define a global symbol at data end */
161162
} >DTCMRAM AT> FLASH
162163

163-
164164
/* Uninitialized data section */
165165
. = ALIGN(4);
166166
.bss :

Linker/STM32H7xx_RAM.ld

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
ENTRY(Reset_Handler)
5454

5555
/* Highest address of the user mode stack */
56-
_estack = 0x20020000; /* end of RAM */
56+
_estack = ORIGIN(DTCMRAM) + LENGTH(DTCMRAM); /* end of RAM */
5757
/* Generate a link error if heap and stack don't fit into RAM */
5858
_Min_Heap_Size = 0x200; /* required amount of heap */
5959
_Min_Stack_Size = 0x400; /* required amount of stack */
@@ -62,8 +62,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
6262
MEMORY
6363
{
6464
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
65-
SIGNATURE (rx) : ORIGIN = 0x23FFFFC0, LENGTH = 64 /* Never written to the RAM, it is for binary signature. */
66-
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
65+
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 128K
6766
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
6867
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
6968
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
@@ -73,6 +72,13 @@ FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K
7372
/* Define output sections */
7473
SECTIONS
7574
{
75+
.restart_info (NOLOAD) :
76+
{
77+
. = ALIGN(4);
78+
KEEP(*(.restart_info))
79+
. = ALIGN(4);
80+
} >DTCMRAM
81+
7682
/* The startup code goes first into RAM_D1 */
7783
.isr_vector :
7884
{
@@ -139,14 +145,16 @@ SECTIONS
139145
KEEP (*(.fini_array*))
140146
PROVIDE_HIDDEN (__fini_array_end = .);
141147
} >RAM_D1
142-
143-
/* used by the startup to initialize data */
144-
_sidata = LOADADDR(.data);
145148

146-
.restart_info : ALIGN(4)
149+
.restart_info (NOLOAD) :
147150
{
151+
. = ALIGN(4);
148152
KEEP(*(.restart_info))
149-
} >DTCMRAM AT> RAM_D1
153+
. = ALIGN(4);
154+
} >DTCMRAM
155+
156+
/* used by the startup to initialize data */
157+
_sidata = LOADADDR(.data);
150158

151159
/* Initialized data sections goes into RAM, load LMA copy after code */
152160
.data :
@@ -156,11 +164,11 @@ SECTIONS
156164
*(.data) /* .data sections */
157165
*(.data*) /* .data* sections */
158166

159-
. = ALIGN(4);
167+
. = ALIGN(8);
168+
. = . + 4; /* Workaround for AXISRAM preserving data after reset*/
160169
_edata = .; /* define a global symbol at data end */
161170
} >DTCMRAM AT> RAM_D1
162171

163-
164172
/* Uninitialized data section */
165173
. = ALIGN(4);
166174
.bss :
@@ -175,7 +183,7 @@ SECTIONS
175183
. = ALIGN(4);
176184
_ebss = .; /* define a global symbol at bss end */
177185
__bss_end__ = _ebss;
178-
} >DTCMRAM AT> RAM_D1
186+
} >DTCMRAM
179187

180188
/* User_heap_stack section, used to check that there is enough RAM left */
181189
._user_heap_stack :
@@ -186,7 +194,7 @@ SECTIONS
186194
. = . + _Min_Heap_Size;
187195
. = . + _Min_Stack_Size;
188196
. = ALIGN(8);
189-
} >DTCMRAM AT> RAM_D1
197+
} >DTCMRAM
190198

191199

192200
/* Remove information from the standard libraries */

Linker/STM32H7xx_RAM_SIGNATURE.ld

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
ENTRY(Reset_Handler)
5454

5555
/* Highest address of the user mode stack */
56-
_estack = 0x20010000; /* end of RAM */
56+
_estack = ORIGIN(DTCMRAM) + LENGTH(DTCMRAM); /* end of RAM */
5757
/* Generate a link error if heap and stack don't fit into RAM */
5858
_Min_Heap_Size = 0x200; /* required amount of heap */
5959
_Min_Stack_Size = 0x400; /* required amount of stack */
@@ -63,7 +63,7 @@ MEMORY
6363
{
6464
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
6565
SIGNATURE (rx) : ORIGIN = 0x23FFFFC0, LENGTH = 64 /* Never written to the RAM, it is for binary signature. */
66-
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
66+
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 128K
6767
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
6868
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
6969
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
@@ -78,6 +78,13 @@ SECTIONS
7878
KEEP(*(.bl_ram_signature))
7979
} >SIGNATURE
8080

81+
.restart_info (NOLOAD) :
82+
{
83+
. = ALIGN(4);
84+
KEEP(*(.restart_info))
85+
. = ALIGN(4);
86+
} >DTCMRAM
87+
8188
/* The startup code goes first into RAM_D1 */
8289
.isr_vector :
8390
{
@@ -113,7 +120,7 @@ SECTIONS
113120
} >RAM_D1
114121

115122
.ARM.extab (READONLY) : /* The READONLY keyword is only supported in GCC11 and later, remove it if using GCC10 or earlier. */
116-
{
123+
{
117124
*(.ARM.extab* .gnu.linkonce.armextab.*)
118125
} >RAM_D1
119126

@@ -144,13 +151,8 @@ SECTIONS
144151
KEEP (*(.fini_array*))
145152
PROVIDE_HIDDEN (__fini_array_end = .);
146153
} >RAM_D1
147-
148-
.restart_info : ALIGN(4)
149-
{
150-
KEEP(*(.restart_info))
151-
} >DTCMRAM AT> RAM_D1
152154

153-
/* used by the startup to initialize data */
155+
/* used by the startup to initialize data */
154156
_sidata = LOADADDR(.data);
155157

156158
/* Initialized data sections goes into RAM, load LMA copy after code */
@@ -161,10 +163,10 @@ SECTIONS
161163
*(.data) /* .data sections */
162164
*(.data*) /* .data* sections */
163165

164-
. = ALIGN(4);
166+
. = ALIGN(8);
167+
. = . + 4; /* Workaround for AXISRAM preserving data after reset */
165168
_edata = .; /* define a global symbol at data end */
166169
} >DTCMRAM AT> RAM_D1
167-
168170

169171
/* Uninitialized data section */
170172
. = ALIGN(4);
@@ -180,7 +182,7 @@ SECTIONS
180182
. = ALIGN(4);
181183
_ebss = .; /* define a global symbol at bss end */
182184
__bss_end__ = _ebss;
183-
} >DTCMRAM AT> RAM_D1
185+
} >DTCMRAM
184186

185187
/* User_heap_stack section, used to check that there is enough RAM left */
186188
._user_heap_stack :
@@ -191,7 +193,7 @@ SECTIONS
191193
. = . + _Min_Heap_Size;
192194
. = . + _Min_Stack_Size;
193195
. = ALIGN(8);
194-
} >DTCMRAM AT> RAM_D1
196+
} >DTCMRAM
195197

196198

197199
/* Remove information from the standard libraries */

0 commit comments

Comments
 (0)