diff mbox series

[U-Boot] spl: add overall SPL size check

Message ID 20190422194806.9227-1-simon.k.r.goldschmidt@gmail.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series [U-Boot] spl: add overall SPL size check | expand

Commit Message

Simon Goldschmidt April 22, 2019, 7:48 p.m. UTC
This adds a size check for SPL that can dynamically check generated
SPL binaries (including devicetree) for a size limit that ensures
this image plus global data, heap and stack fit in initial SRAM.

Since some of these sizes are not available to make, a new host tool
'spl_size_limit' is added that dumps the resulting maximum size for
an SPL binary to stdout. This tool is used in toplevel Makefile to
implement the size check on SPL binaries.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
---

 Kconfig            |  8 --------
 Makefile           |  2 +-
 common/spl/Kconfig | 36 ++++++++++++++++++++++++++++++++++++
 tools/Makefile     |  2 ++
 4 files changed, 39 insertions(+), 9 deletions(-)

Comments

Tom Rini April 22, 2019, 8:19 p.m. UTC | #1
On Mon, Apr 22, 2019 at 09:48:06PM +0200, Simon Goldschmidt wrote:

> This adds a size check for SPL that can dynamically check generated
> SPL binaries (including devicetree) for a size limit that ensures
> this image plus global data, heap and stack fit in initial SRAM.
> 
> Since some of these sizes are not available to make, a new host tool
> 'spl_size_limit' is added that dumps the resulting maximum size for
> an SPL binary to stdout. This tool is used in toplevel Makefile to
> implement the size check on SPL binaries.
> 
> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

OK, this relies on very small parts of:
https://patchwork.ozlabs.org/patch/1074741/ from Heinrich and I think
it's appropriate to grab his S-o-B line and squash those parts in.
Please speak up if either of you object.

> ---
> 
>  Kconfig            |  8 --------
>  Makefile           |  2 +-
>  common/spl/Kconfig | 36 ++++++++++++++++++++++++++++++++++++
>  tools/Makefile     |  2 ++
>  4 files changed, 39 insertions(+), 9 deletions(-)

The new tool code is missing :)
Simon Goldschmidt April 22, 2019, 8:29 p.m. UTC | #2
On 22.04.19 22:19, Tom Rini wrote:
> On Mon, Apr 22, 2019 at 09:48:06PM +0200, Simon Goldschmidt wrote:
> 
>> This adds a size check for SPL that can dynamically check generated
>> SPL binaries (including devicetree) for a size limit that ensures
>> this image plus global data, heap and stack fit in initial SRAM.
>>
>> Since some of these sizes are not available to make, a new host tool
>> 'spl_size_limit' is added that dumps the resulting maximum size for
>> an SPL binary to stdout. This tool is used in toplevel Makefile to
>> implement the size check on SPL binaries.
>>
>> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
> 
> OK, this relies on very small parts of:
> https://patchwork.ozlabs.org/patch/1074741/ from Heinrich and I think
> it's appropriate to grab his S-o-B line and squash those parts in.
> Please speak up if either of you object.

I'm ok with that.
> 
>> ---
>>
>>   Kconfig            |  8 --------
>>   Makefile           |  2 +-
>>   common/spl/Kconfig | 36 ++++++++++++++++++++++++++++++++++++
>>   tools/Makefile     |  2 ++
>>   4 files changed, 39 insertions(+), 9 deletions(-)
> 
> The new tool code is missing :)

d'oh! I've just sent v2 with the tool included.

Regards,
Simon
diff mbox series

Patch

diff --git a/Kconfig b/Kconfig
index ca31bcebde..7a5491bd67 100644
--- a/Kconfig
+++ b/Kconfig
@@ -172,14 +172,6 @@  config TPL_SYS_MALLOC_F_LEN
 	  particular needs this to operate, so that it can allocate the
 	  initial serial device and any others that are needed.
 
-config SPL_SIZE_LIMIT
-	int "Maximum size of SPL image"
-	depends on SPL
-	default 0
-	help
-	  Specifies the maximum length of the U-Boot SPL image.
-	  If this value is zero, it is ignored.
-
 menuconfig EXPERT
 	bool "Configure standard U-Boot features (expert users)"
 	default y
diff --git a/Makefile b/Makefile
index ac375f396c..df674b0e96 100644
--- a/Makefile
+++ b/Makefile
@@ -797,7 +797,7 @@  BOARD_SIZE_CHECK =
 endif
 
 ifneq ($(CONFIG_SPL_SIZE_LIMIT),0)
-SPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_SPL_SIZE_LIMIT))
+SPL_SIZE_CHECK = @$(call size_check,$@,$$(tools/spl_size_limit))
 else
 SPL_SIZE_CHECK =
 endif
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 206c24076d..24ddab3a48 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -25,6 +25,42 @@  config SPL_FRAMEWORK
 	  supports MMC, NAND and YMODEM and other methods loading of U-Boot
 	  and the Linux Kernel.  If unsure, say Y.
 
+config SPL_SIZE_LIMIT
+	hex "Maximum size of SPL image"
+	depends on SPL
+	default 0
+	help
+	  Specifies the maximum length of the U-Boot SPL image.
+	  If this value is zero, it is ignored.
+
+config SPL_SIZE_LIMIT_SUBTRACT_GD
+	bool "SPL image size check: provide space for global data"
+	depends on SPL_SIZE_LIMIT > 0
+	help
+	  If enabled, aligned size of global data is reserved in
+	  SPL_SIZE_LIMIT check to ensure such an image does not overflow SRAM
+	  if SPL_SIZE_LIMIT describes the size of SRAM available for SPL when
+	  pre-reloc global data is put into this SRAM, too.
+
+config SPL_SIZE_LIMIT_SUBTRACT_MALLOC
+	bool "SPL image size check: provide space for malloc() pool before relocation"
+	depends on SPL_SIZE_LIMIT > 0
+	help
+	  If enabled, SPL_SYS_MALLOC_F_LEN is reserved in SPL_SIZE_LIMIT check
+	  to ensure such an image does not overflow SRAM if SPL_SIZE_LIMIT
+	  describes the size of SRAM available for SPL when pre-reloc malloc
+	  pool is put into this SRAM, too.
+
+config SPL_SIZE_LIMIT_PROVIDE_STACK
+	hex "SPL image size check: provide stack space before relocation"
+	depends on SPL_SIZE_LIMIT > 0
+	default 0
+	help
+	  If set, this size is reserved in SPL_SIZE_LIMIT check to ensure such
+	  an image does not overflow SRAM if SPL_SIZE_LIMIT describes the size
+	  of SRAM available for SPL when the stack required before reolcation
+	  uses this SRAM, too.
+
 config HANDOFF
 	bool "Pass hand-off information from SPL to U-Boot proper"
 	depends on BLOBLIST
diff --git a/tools/Makefile b/tools/Makefile
index d377d85f74..d3b950553f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -199,6 +199,8 @@  hostprogs-$(CONFIG_RISCV) += prelink-riscv
 hostprogs-y += fdtgrep
 fdtgrep-objs += $(LIBFDT_OBJS) fdtgrep.o
 
+hostprogs-y += spl_size_limit
+
 hostprogs-$(CONFIG_MIPS) += mips-relocs
 
 # We build some files with extra pedantic flags to try to minimize things