spl: add size check including devicetree
PATCH 1/1 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.
---
Makefile | 11 +---------- scripts/Kbuild.include | 16 ++++++++++++++++ scripts/Makefile.spl | 6 ++++++ 3 files changed, 23 insertions(+), 10 deletions(-)
Makefile +1 -10
@@ -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
scripts/Kbuild.include +16 -0
@@ -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
scripts/Makefile.spl +6 -0
@@ -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)
Signature · 1 line
2.17.1
Quoted 17 lines · Simon Goldschmidt
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_CHECKinto a common function that is called for SPL, too.For SPL,
CONFIG_SPL_MAX_SIZEis used to check u-boot-spl-dtb.bin.This is RFC for two reasons:
-scripts/Kbuild.includemight 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_SIZEat 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.
Quoted 1 line
Signed-off-by Simon Goldschmidt <[email protected]>
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
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190322/9a66d6d0/attachment.sig>
Am 22.03.2019 um 14:03 schrieb Tom Rini:
Quoted 21 lines · Simon Goldschmidt
Quoted 18 lines
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_CHECKinto a common function that is called for SPL, too.For SPL,
CONFIG_SPL_MAX_SIZEis used to check u-boot-spl-dtb.bin.This is RFC for two reasons:
-scripts/Kbuild.includemight 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_SIZEat 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.Quoted 1 line
Signed-off-by Simon Goldschmidt <[email protected]>
Quoted 8 lines
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
Quoted 31 lines · Simon Goldschmidt
Am 22.03.2019 um 14:03 schrieb Tom Rini:
Quoted 21 lines · Simon Goldschmidt
Quoted 18 lines
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_CHECKinto a common function that is called for SPL, too.For SPL,
CONFIG_SPL_MAX_SIZEis used to check u-boot-spl-dtb.bin.This is RFC for two reasons:
-scripts/Kbuild.includemight 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_SIZEat 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.Quoted 1 line
Signed-off-by Simon Goldschmidt <[email protected]>Quoted 8 lines
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
Quoted 3 lines
Right. We could run the define through
libt/asm-offsets.c(just likeGENERATED_GBL_DATA_SIZEis created), but how would we get the result back into theMakefile?
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?
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190322/5a11542c/attachment.sig>
Tom Rini <[email protected]> schrieb am Fr., 22. März 2019, 21:50:
Quoted 34 lines · Simon Goldschmidt
Quoted 25 lines
Am 22.03.2019 um 14:03 schrieb Tom Rini:
Quoted 24 lines · Simon Goldschmidt
Quoted 18 lines
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_CHECKinto a common function that is called for SPL, too.For SPL,
CONFIG_SPL_MAX_SIZEis used to check u-boot-spl-dtb.bin.This is RFC for two reasons:
-scripts/Kbuild.includemight 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_SIZEat 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.Quoted 1 line
Signed-off-by Simon Goldschmidt <[email protected]>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
Quoted 5 lines
Quoted 5 lines
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
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Right. We could run the define through
libt/asm-offsets.c(just likeGENERATED_GBL_DATA_SIZEis created), but how would we get the result back into theMakefile?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
Quoted 1 line
Quoted 17 lines · Simon Goldschmidt
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_CHECKinto a common function that is called for SPL, too.For SPL,
CONFIG_SPL_MAX_SIZEis used to check u-boot-spl-dtb.bin.This is RFC for two reasons:
-scripts/Kbuild.includemight 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_SIZEat 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.
Quoted 1 line
Signed-off-by Simon Goldschmidt <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190322/c53596e0/attachment.sig>
Tom Rini <[email protected]> schrieb am Sa., 23. März 2019, 00:17:
Quoted 19 lines · Simon Goldschmidt
Quoted 18 lines
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_CHECKinto a common function that is called for SPL, too.For SPL,
CONFIG_SPL_MAX_SIZEis used to check u-boot-spl-dtb.bin.This is RFC for two reasons:
-scripts/Kbuild.includemight 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_SIZEat 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.
Quoted 4 lines
Quoted 1 line
Signed-off-by Simon Goldschmidt <[email protected]>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
Quoted 1 line
Quoted 21 lines · Simon Goldschmidt
Tom Rini <[email protected]> schrieb am Sa., 23. März 2019, 00:17:
Quoted 19 lines · Simon Goldschmidt
Quoted 18 lines
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_CHECKinto a common function that is called for SPL, too.For SPL,
CONFIG_SPL_MAX_SIZEis used to check u-boot-spl-dtb.bin.This is RFC for two reasons:
-scripts/Kbuild.includemight 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_SIZEat 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.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Simon Goldschmidt <[email protected]>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.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190411/073cf748/attachment.sig>