Skip to content

Commit 0f4c9f7

Browse files
earlephilhowerd-a-v
authored andcommitted
Split IRAM into 2 linker sections to move std::fcn (#5922)
* Split IRAM into 2 linker sections to move std::fcn Callbacks need to be placed in IRAM when being called from an IRQ (like the SPISlave callbacks). This can be done by hacking the std::functional header and making every single specialization of the template into an IRAM section, which would take a lot of space for no benefit in the majority of cases. The alternate is to specify the single instantiation types/operators required, but the problem is the flash segment matcher would match them before the IRAM section was begun, and rules for them would just not be applied. Get around this by splitting the IRAM section definition into .text and .text1. This is linker syntactic sugar and does not actually change the on-chip layout. But it does allow us to put the exception vectors at the required absolute addresses and add single functions to IRAM. * Add .text1 segment to space used calculation in IDE * All functional callers are now placed in IRAM * Write out the .text1 segment to the BIN The extra segment name needs to be placed into the output binary as well, or else only the init code gets stored and none of the real app is present. This leads to an infinite boot loop. This change adds in the segment to the generated image.
1 parent fa0db2e commit 0f4c9f7

File tree

3 files changed

+43
-32
lines changed

3 files changed

+43
-32
lines changed

platform.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ recipe.output.save_file={build.project_name}.{build.variant}.bin
117117

118118
## Compute size
119119
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
120-
recipe.size.regex=^(?:\.irom0\.text|\.text|\.data|\.rodata|)\s+([0-9]+).*
120+
recipe.size.regex=^(?:\.irom0\.text|\.text|\.text1|\.data|\.rodata|)\s+([0-9]+).*
121121
recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
122122
#recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
123123

tools/elf2bin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def main():
109109

110110
out = open(args.out, "wb")
111111
write_bin(out, args.eboot, ['.text'], 4096, args.flash_mode, args.flash_size, args.flash_freq, args.path)
112-
write_bin(out, args.app, ['.irom0.text', '.text', '.data', '.rodata'], 0, args.flash_mode, args.flash_size, args.flash_freq, args.path)
112+
write_bin(out, args.app, ['.irom0.text', '.text', '.text1', '.data', '.rodata'], 0, args.flash_mode, args.flash_size, args.flash_freq, args.path)
113113
out.close()
114114

115115
return 0

tools/sdk/ld/eagle.app.v6.common.ld.h

+41-30
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,44 @@ SECTIONS
9393
#include "eagle.app.v6.common.ld.vtables.h"
9494
#endif
9595

96+
/* IRAM is split into .text and .text1 to allow for moving specific */
97+
/* functions into IRAM that would be matched by the irom0.text matcher */
98+
.text : ALIGN(4)
99+
{
100+
_stext = .;
101+
_text_start = ABSOLUTE(.);
102+
*(.UserEnter.text)
103+
. = ALIGN(16);
104+
*(.DebugExceptionVector.text)
105+
. = ALIGN(16);
106+
*(.NMIExceptionVector.text)
107+
. = ALIGN(16);
108+
*(.KernelExceptionVector.text)
109+
LONG(0)
110+
LONG(0)
111+
LONG(0)
112+
LONG(0)
113+
. = ALIGN(16);
114+
*(.UserExceptionVector.text)
115+
LONG(0)
116+
LONG(0)
117+
LONG(0)
118+
LONG(0)
119+
. = ALIGN(16);
120+
*(.DoubleExceptionVector.text)
121+
LONG(0)
122+
LONG(0)
123+
LONG(0)
124+
LONG(0)
125+
. = ALIGN (16);
126+
*(.entry.text)
127+
*(.init.literal)
128+
*(.init)
129+
130+
/* all functional callers are placed in IRAM (including SPI/IRQ callbacks/etc) here */
131+
*(.text._ZNKSt8functionIF*EE*) /* std::function<any(...)>::operator()() const */
132+
} >iram1_0_seg :iram1_0_phdr
133+
96134
.irom0.text : ALIGN(4)
97135
{
98136
_irom0_text_start = ABSOLUTE(.);
@@ -163,37 +201,10 @@ SECTIONS
163201
_flash_code_end = ABSOLUTE(.);
164202
} >irom0_0_seg :irom0_0_phdr
165203

166-
.text : ALIGN(4)
204+
205+
206+
.text1 : ALIGN(4)
167207
{
168-
_stext = .;
169-
_text_start = ABSOLUTE(.);
170-
*(.UserEnter.text)
171-
. = ALIGN(16);
172-
*(.DebugExceptionVector.text)
173-
. = ALIGN(16);
174-
*(.NMIExceptionVector.text)
175-
. = ALIGN(16);
176-
*(.KernelExceptionVector.text)
177-
LONG(0)
178-
LONG(0)
179-
LONG(0)
180-
LONG(0)
181-
. = ALIGN(16);
182-
*(.UserExceptionVector.text)
183-
LONG(0)
184-
LONG(0)
185-
LONG(0)
186-
LONG(0)
187-
. = ALIGN(16);
188-
*(.DoubleExceptionVector.text)
189-
LONG(0)
190-
LONG(0)
191-
LONG(0)
192-
LONG(0)
193-
. = ALIGN (16);
194-
*(.entry.text)
195-
*(.init.literal)
196-
*(.init)
197208
*(.literal .text .iram.literal .iram.text .iram.text.* .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
198209
#ifdef VTABLES_IN_IRAM
199210
*(.rodata._ZTV*) /* C++ vtables */

0 commit comments

Comments
 (0)