diff options
author | Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> | 2019-07-16 22:30:36 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2019-08-11 16:43:41 -0400 |
commit | d8c0332031ea90555d8f974867237a38630fda0d (patch) | |
tree | c47cba330d44e734f8f8e50299585b2f35dae21f /common/init | |
parent | af325e9597dfe47943f6f3b92d0b7012317f4a53 (diff) | |
download | u-boot-d8c0332031ea90555d8f974867237a38630fda0d.tar.gz u-boot-d8c0332031ea90555d8f974867237a38630fda0d.tar.bz2 u-boot-d8c0332031ea90555d8f974867237a38630fda0d.zip |
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>
Diffstat (limited to 'common/init')
-rw-r--r-- | common/init/board_init.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/common/init/board_init.c b/common/init/board_init.c index 526fee35ff..e52106966d 100644 --- a/common/init/board_init.c +++ b/common/init/board_init.c @@ -18,6 +18,23 @@ __weak void arch_setup_gd(struct global_data *gd_ptr) } #endif /* !CONFIG_X86 && !CONFIG_ARM */ +/** + * This function is called after the position of the initial stack is + * determined in gd->start_addr_sp. Boards can override it to set up + * stack-checking markers. + */ +__weak void board_init_f_init_stack_protection(void) +{ +#if CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE) + ulong stack_bottom = gd->start_addr_sp - + CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK); + + /* substact some safety margin (0x20) since stack is in use here */ + memset((void *)stack_bottom, CONFIG_VAL(SYS_STACK_F_CHECK_BYTE), + CONFIG_VAL(SIZE_LIMIT_PROVIDE_STACK) - 0x20); +#endif +} + /* * Allocate reserved space for use as 'globals' from 'top' address and * return 'bottom' address of allocated space @@ -126,6 +143,9 @@ void board_init_f_init_reserve(ulong base) /* next alloc will be higher by one 'early malloc arena' size */ base += CONFIG_VAL(SYS_MALLOC_F_LEN); #endif + + if (CONFIG_IS_ENABLED(SYS_REPORT_STACK_F_USAGE)) + board_init_f_init_stack_protection(); } /* |