[U-Boot] [PATCH] spl: add size check including devicetree

Current linker based size checks do not account for the devicetree, as this is added after linker stage.
This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK into a common function that is called for SPL, too.
For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.
This is RFC for two reasons: - scripts/Kbuild.include might not be the perfect place for this new function but was the only place I found included by both /Makefile and /scripts/Makefile.spl - CONFIG_SPL_MAX_SIZE at least for some boards defines the size of the initially available SRAM. However, this check checks the SPL binary only. Initial SRAM must hold gd, heap and stack in addition to that.
Signed-off-by: Simon Goldschmidt simon.k.r.goldschmidt@gmail.com ---
Makefile | 11 +---------- scripts/Kbuild.include | 16 ++++++++++++++++ scripts/Makefile.spl | 6 ++++++ 3 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile index 75a5c7d171..7e1241cf9f 100644 --- a/Makefile +++ b/Makefile @@ -771,16 +771,7 @@ LDPPFLAGS += \ #########################################################################
ifneq ($(CONFIG_BOARD_SIZE_LIMIT),) -BOARD_SIZE_CHECK = \ - @actual=`wc -c $@ | awk '{print $$1}'`; \ - limit=`printf "%d" $(CONFIG_BOARD_SIZE_LIMIT)`; \ - if test $$actual -gt $$limit; then \ - echo "$@ exceeds file size limit:" >&2 ; \ - echo " limit: $$limit bytes" >&2 ; \ - echo " actual: $$actual bytes" >&2 ; \ - echo " excess: $$((actual - limit)) bytes" >&2; \ - exit 1; \ - fi +BOARD_SIZE_CHECK = $(call board_size_check,$(CONFIG_BOARD_SIZE_LIMIT)) else BOARD_SIZE_CHECK = endif diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index b8969e2a75..e3e0aead3f 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -332,3 +332,19 @@ else SPL_ := SPL_TPL_ := endif + +# added for U-Boot +# board size check +# --------------------------------------------------------------------------- +# This checks binaries created in makefiles ($@) for size constraints ($(1)). +define board_size_check + @actual=`wc -c $@ | awk '{print $$1}'`; \ + limit=`printf "%d" $(1)`; \ + if test $$actual -gt $$limit; then \ + echo "$@ exceeds file size limit:" >&2 ; \ + echo " limit: $$limit bytes" >&2 ; \ + echo " actual: $$actual bytes" >&2 ; \ + echo " excess: $$((actual - limit)) bytes" >&2; \ + exit 1; \ + fi +endef diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index 9d5921606e..31339ab9e6 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -253,12 +253,18 @@ else FINAL_DTB_CONTAINER = $(obj)/$(SPL_BIN).multidtb.fit endif
+ifneq ($(CONFIG_SPL_MAX_SIZE),) +SPL_BOARD_SIZE_CHECK = $(call board_size_check,$(CONFIG_SPL_MAX_SIZE)) +else +SPL_BOARD_SIZE_CHECK = +endif
ifeq ($(CONFIG_$(SPL_TPL_)OF_CONTROL)$(CONFIG_OF_SEPARATE)$(CONFIG_$(SPL_TPL_)OF_PLATDATA),yy) $(obj)/$(SPL_BIN)-dtb.bin: $(obj)/$(SPL_BIN)-nodtb.bin \ $(if $(CONFIG_SPL_SEPARATE_BSS),,$(obj)/$(SPL_BIN)-pad.bin) \ $(FINAL_DTB_CONTAINER) FORCE $(call if_changed,cat) + $(SPL_BOARD_SIZE_CHECK)
$(obj)/$(SPL_BIN).bin: $(obj)/$(SPL_BIN)-dtb.bin FORCE $(call if_changed,copy)

On Fri, Mar 01, 2019 at 10:34:17PM +0100, Simon Goldschmidt wrote:
Current linker based size checks do not account for the devicetree, as this is added after linker stage.
This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK into a common function that is called for SPL, too.
For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.
This is RFC for two reasons:
- scripts/Kbuild.include might not be the perfect place for this new function but was the only place I found included by both /Makefile and /scripts/Makefile.spl
- CONFIG_SPL_MAX_SIZE at least for some boards defines the size of the initially available SRAM. However, this check checks the SPL binary only. Initial SRAM must hold gd, heap and stack in addition to that.
Signed-off-by: Simon Goldschmidt simon.k.r.goldschmidt@gmail.com
So, a problem is that we need to get at values after they've been pre-processed: /bin/sh: 1: printf: (SRAM_SCRATCH_SPACE_ADDR - CONFIG_SPL_TEXT_BASE): expected numeric value spl/u-boot-spl-dtb.bin exceeds file size limit: limit: 0 bytes actual: 124970 bytes excess: 124970 bytes ../scripts/Makefile.spl:266: recipe for target 'spl/u-boot-spl-dtb.bin' failed

Am 22.03.2019 um 14:03 schrieb Tom Rini:
On Fri, Mar 01, 2019 at 10:34:17PM +0100, Simon Goldschmidt wrote:
Current linker based size checks do not account for the devicetree, as this is added after linker stage.
This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK into a common function that is called for SPL, too.
For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.
This is RFC for two reasons:
- scripts/Kbuild.include might not be the perfect place for this new function but was the only place I found included by both /Makefile and /scripts/Makefile.spl
- CONFIG_SPL_MAX_SIZE at least for some boards defines the size of the initially available SRAM. However, this check checks the SPL binary only. Initial SRAM must hold gd, heap and stack in addition to that.
Signed-off-by: Simon Goldschmidt simon.k.r.goldschmidt@gmail.com
So, a problem is that we need to get at values after they've been pre-processed: /bin/sh: 1: printf: (SRAM_SCRATCH_SPACE_ADDR - CONFIG_SPL_TEXT_BASE): expected numeric value spl/u-boot-spl-dtb.bin exceeds file size limit: limit: 0 bytes actual: 124970 bytes excess: 124970 bytes ../scripts/Makefile.spl:266: recipe for target 'spl/u-boot-spl-dtb.bin' failed
Right. We could run the define through libt/asm-offsets.c (just like GENERATED_GBL_DATA_SIZE is created), but how would we get the result back into the Makefile?
Regards, Simon

On Fri, Mar 22, 2019 at 09:47:06PM +0100, Simon Goldschmidt wrote:
Am 22.03.2019 um 14:03 schrieb Tom Rini:
On Fri, Mar 01, 2019 at 10:34:17PM +0100, Simon Goldschmidt wrote:
Current linker based size checks do not account for the devicetree, as this is added after linker stage.
This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK into a common function that is called for SPL, too.
For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.
This is RFC for two reasons:
- scripts/Kbuild.include might not be the perfect place for this new function but was the only place I found included by both /Makefile and /scripts/Makefile.spl
- CONFIG_SPL_MAX_SIZE at least for some boards defines the size of the initially available SRAM. However, this check checks the SPL binary only. Initial SRAM must hold gd, heap and stack in addition to that.
Signed-off-by: Simon Goldschmidt simon.k.r.goldschmidt@gmail.com
So, a problem is that we need to get at values after they've been pre-processed: /bin/sh: 1: printf: (SRAM_SCRATCH_SPACE_ADDR - CONFIG_SPL_TEXT_BASE): expected numeric value spl/u-boot-spl-dtb.bin exceeds file size limit: limit: 0 bytes actual: 124970 bytes excess: 124970 bytes ../scripts/Makefile.spl:266: recipe for target 'spl/u-boot-spl-dtb.bin' failed
Right. We could run the define through libt/asm-offsets.c (just like GENERATED_GBL_DATA_SIZE is created), but how would we get the result back into the Makefile?
I'm honestly not sure. I can only think of what I first want to call hacks such as having a C program do the check instead. But maybe that's not such a hack afterall?

Tom Rini trini@konsulko.com schrieb am Fr., 22. März 2019, 21:50:
On Fri, Mar 22, 2019 at 09:47:06PM +0100, Simon Goldschmidt wrote:
Am 22.03.2019 um 14:03 schrieb Tom Rini:
On Fri, Mar 01, 2019 at 10:34:17PM +0100, Simon Goldschmidt wrote:
Current linker based size checks do not account for the devicetree, as this is added after linker stage.
This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK into a common function that is called for SPL, too.
For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.
This is RFC for two reasons:
- scripts/Kbuild.include might not be the perfect place for this new function but was the only place I found included by both /Makefile and /scripts/Makefile.spl
- CONFIG_SPL_MAX_SIZE at least for some boards defines the size of the initially available SRAM. However, this check checks the SPL binary only. Initial SRAM must hold gd, heap and stack in addition to that.
Signed-off-by: Simon Goldschmidt simon.k.r.goldschmidt@gmail.com
So, a problem is that we need to get at values after they've been pre-processed: /bin/sh: 1: printf: (SRAM_SCRATCH_SPACE_ADDR - CONFIG_SPL_TEXT_BASE):
expected numeric value
spl/u-boot-spl-dtb.bin exceeds file size limit: limit: 0 bytes actual: 124970 bytes excess: 124970 bytes ../scripts/Makefile.spl:266: recipe for target 'spl/u-boot-spl-dtb.bin'
failed
Right. We could run the define through libt/asm-offsets.c (just like GENERATED_GBL_DATA_SIZE is created), but how would we get the result back into the Makefile?
I'm honestly not sure. I can only think of what I first want to call hacks such as having a C program do the check instead. But maybe that's not such a hack afterall?
Right. Given the problems we're having with a pure Makefile based approach, a C program doing this might indeed be a less fragile solution.
Regards, Simon

On Fri, Mar 01, 2019 at 10:34:17PM +0100, Simon Goldschmidt wrote:
Current linker based size checks do not account for the devicetree, as this is added after linker stage.
This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK into a common function that is called for SPL, too.
For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.
This is RFC for two reasons:
- scripts/Kbuild.include might not be the perfect place for this new function but was the only place I found included by both /Makefile and /scripts/Makefile.spl
- CONFIG_SPL_MAX_SIZE at least for some boards defines the size of the initially available SRAM. However, this check checks the SPL binary only. Initial SRAM must hold gd, heap and stack in addition to that.
Signed-off-by: Simon Goldschmidt simon.k.r.goldschmidt@gmail.com
Applied to u-boot/master, thanks!

Tom Rini trini@konsulko.com schrieb am Sa., 23. März 2019, 00:17:
On Fri, Mar 01, 2019 at 10:34:17PM +0100, Simon Goldschmidt wrote:
Current linker based size checks do not account for the devicetree, as this is added after linker stage.
This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK into a common function that is called for SPL, too.
For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.
This is RFC for two reasons:
- scripts/Kbuild.include might not be the perfect place for this new function but was the only place I found included by both /Makefile and /scripts/Makefile.spl
- CONFIG_SPL_MAX_SIZE at least for some boards defines the size of the initially available SRAM. However, this check checks the SPL binary only. Initial SRAM must hold gd, heap and stack in addition to that.
Signed-off-by: Simon Goldschmidt simon.k.r.goldschmidt@gmail.com
Applied to u-boot/master, thanks!
Are you sure about that? I don't see it on github, and this was an RFC which probably needs a bit of cleanup...
Regards, Simon

On Wed, Mar 27, 2019 at 03:47:21PM +0100, Simon Goldschmidt wrote:
Tom Rini trini@konsulko.com schrieb am Sa., 23. März 2019, 00:17:
On Fri, Mar 01, 2019 at 10:34:17PM +0100, Simon Goldschmidt wrote:
Current linker based size checks do not account for the devicetree, as this is added after linker stage.
This patch moves the logic behind U-Boot proper BOARD_SIZE_CHECK into a common function that is called for SPL, too.
For SPL, CONFIG_SPL_MAX_SIZE is used to check u-boot-spl-dtb.bin.
This is RFC for two reasons:
- scripts/Kbuild.include might not be the perfect place for this new function but was the only place I found included by both /Makefile and /scripts/Makefile.spl
- CONFIG_SPL_MAX_SIZE at least for some boards defines the size of the initially available SRAM. However, this check checks the SPL binary only. Initial SRAM must hold gd, heap and stack in addition to that.
Signed-off-by: Simon Goldschmidt simon.k.r.goldschmidt@gmail.com
Applied to u-boot/master, thanks!
Are you sure about that? I don't see it on github, and this was an RFC which probably needs a bit of cleanup...
... oops, this was in my to-send queue by accident still when I sent it.
participants (2)
-
Simon Goldschmidt
-
Tom Rini