From 0f4c9f710318ab9199714b9adcdd9701d78d264e Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 10 Apr 2019 11:49:31 +0300 Subject: [PATCH] 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. --- platform.txt | 2 +- tools/elf2bin.py | 2 +- tools/sdk/ld/eagle.app.v6.common.ld.h | 71 ++++++++++++++++----------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/platform.txt b/platform.txt index b3c184ae6..2a62afde1 100644 --- a/platform.txt +++ b/platform.txt @@ -117,7 +117,7 @@ recipe.output.save_file={build.project_name}.{build.variant}.bin ## Compute size recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" -recipe.size.regex=^(?:\.irom0\.text|\.text|\.data|\.rodata|)\s+([0-9]+).* +recipe.size.regex=^(?:\.irom0\.text|\.text|\.text1|\.data|\.rodata|)\s+([0-9]+).* recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).* #recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).* diff --git a/tools/elf2bin.py b/tools/elf2bin.py index 0d3c8b3be..3e70caf14 100755 --- a/tools/elf2bin.py +++ b/tools/elf2bin.py @@ -109,7 +109,7 @@ def main(): out = open(args.out, "wb") write_bin(out, args.eboot, ['.text'], 4096, args.flash_mode, args.flash_size, args.flash_freq, args.path) - write_bin(out, args.app, ['.irom0.text', '.text', '.data', '.rodata'], 0, args.flash_mode, args.flash_size, args.flash_freq, args.path) + write_bin(out, args.app, ['.irom0.text', '.text', '.text1', '.data', '.rodata'], 0, args.flash_mode, args.flash_size, args.flash_freq, args.path) out.close() return 0 diff --git a/tools/sdk/ld/eagle.app.v6.common.ld.h b/tools/sdk/ld/eagle.app.v6.common.ld.h index aa4201221..1aeb257c2 100644 --- a/tools/sdk/ld/eagle.app.v6.common.ld.h +++ b/tools/sdk/ld/eagle.app.v6.common.ld.h @@ -93,6 +93,44 @@ SECTIONS #include "eagle.app.v6.common.ld.vtables.h" #endif + /* IRAM is split into .text and .text1 to allow for moving specific */ + /* functions into IRAM that would be matched by the irom0.text matcher */ + .text : ALIGN(4) + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.UserEnter.text) + . = ALIGN(16); + *(.DebugExceptionVector.text) + . = ALIGN(16); + *(.NMIExceptionVector.text) + . = ALIGN(16); + *(.KernelExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.UserExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN(16); + *(.DoubleExceptionVector.text) + LONG(0) + LONG(0) + LONG(0) + LONG(0) + . = ALIGN (16); + *(.entry.text) + *(.init.literal) + *(.init) + + /* all functional callers are placed in IRAM (including SPI/IRQ callbacks/etc) here */ + *(.text._ZNKSt8functionIF*EE*) /* std::function::operator()() const */ + } >iram1_0_seg :iram1_0_phdr + .irom0.text : ALIGN(4) { _irom0_text_start = ABSOLUTE(.); @@ -163,37 +201,10 @@ SECTIONS _flash_code_end = ABSOLUTE(.); } >irom0_0_seg :irom0_0_phdr - .text : ALIGN(4) + + + .text1 : ALIGN(4) { - _stext = .; - _text_start = ABSOLUTE(.); - *(.UserEnter.text) - . = ALIGN(16); - *(.DebugExceptionVector.text) - . = ALIGN(16); - *(.NMIExceptionVector.text) - . = ALIGN(16); - *(.KernelExceptionVector.text) - LONG(0) - LONG(0) - LONG(0) - LONG(0) - . = ALIGN(16); - *(.UserExceptionVector.text) - LONG(0) - LONG(0) - LONG(0) - LONG(0) - . = ALIGN(16); - *(.DoubleExceptionVector.text) - LONG(0) - LONG(0) - LONG(0) - LONG(0) - . = ALIGN (16); - *(.entry.text) - *(.init.literal) - *(.init) *(.literal .text .iram.literal .iram.text .iram.text.* .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) #ifdef VTABLES_IN_IRAM *(.rodata._ZTV*) /* C++ vtables */