spl: implement stack usage check
This implements a stack usage check in SPL.
Many boards start up SPL to run code + data from one common, rather small
SRAM. To implement a sophisticated SPL binary size limit on such boards,
the stack size (as well as malloc size and global data size) must be
subtracted from this SRAM size.
However, to do that properly, the stack size first needs to be known.
This patch adds a new Kconfig option:
- SPL_SYS_REPORT_STACK_F_USAGE: memset(0xaa) the whole area of the stack
very early and check stack usage based on this constant later before the
stack is switched to DRAM
Initializing the stack and checking it is implemented in weak functions,
in case a board does not use the stack as saved in gd->start_addr_sp.
Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 54154b9..6304916 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -62,6 +62,25 @@
of SRAM available for SPL when the stack required before reolcation
uses this SRAM, too.
+config SPL_SYS_STACK_F_CHECK_BYTE
+ hex
+ default 0xaa
+ help
+ Constant used to check the stack
+
+config SPL_SYS_REPORT_STACK_F_USAGE
+ depends on SPL_SIZE_LIMIT_PROVIDE_STACK != 0
+ bool "Check and report stack usage in SPL before relocation"
+ help
+ If this option is enabled, the initial SPL stack is filled with 0xaa
+ very early, up to the size configured with
+ SPL_SIZE_LIMIT_PROVIDE_STACK.
+ Later when SPL is done using this initial stack and switches to a
+ stack in DRAM, the actually used size of this initial stack is
+ reported by examining the memory and searching for the lowest
+ occurrence of non 0xaa bytes.
+ This default implementation works for stacks growing down only.
+
menu "PowerPC SPL Boot options"
depends on PPC && (SUPPORT_SPL && !SPL_FRAMEWORK)