[U-Boot] [PATCH] spl: implement stack usage check

Simon Goldschmidt simon.k.r.goldschmidt at gmail.com
Wed Jul 17 18:18:23 UTC 2019


Am 17.07.2019 um 20:07 schrieb Tom Rini:
> On Tue, Jul 16, 2019 at 10:30:36PM +0200, Simon Goldschmidt wrote:
> 
>> 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 at gmail.com>
> 
> Very nice!  I wish I had thought of something like that years ago when
> Wolfgang asked and I came up with the -fstack-usage stuff we have today.

Well, I think theoretically, a compile-time approach is better than what 
I did. However, that -fstack-usage thing did not work out for me (I'd 
have to look into that again), so I implemented this runtime check.

On the positive side, pre-relocation stack usage doesn't change too 
much, so the old rule of thumb of checking it once and the taking 
roughly the double as config option should be good ;-)

Regards,
Simon



More information about the U-Boot mailing list