All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] spl: add size check including devicetree
@ 2019-03-01 21:34 Simon Goldschmidt
  2019-03-22 13:03 ` [U-Boot] " Tom Rini
  2019-03-22 23:17 ` Tom Rini
  0 siblings, 2 replies; 8+ messages in thread
From: Simon Goldschmidt @ 2019-03-01 21:34 UTC (permalink / raw)
  To: u-boot

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)
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] spl: add size check including devicetree
  2019-03-01 21:34 [U-Boot] [PATCH] spl: add size check including devicetree Simon Goldschmidt
@ 2019-03-22 13:03 ` Tom Rini
  2019-03-22 20:47   ` Simon Goldschmidt
  2019-03-22 23:17 ` Tom Rini
  1 sibling, 1 reply; 8+ messages in thread
From: Tom Rini @ 2019-03-22 13:03 UTC (permalink / raw)
  To: u-boot

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

-- 
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>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] spl: add size check including devicetree
  2019-03-22 13:03 ` [U-Boot] " Tom Rini
@ 2019-03-22 20:47   ` Simon Goldschmidt
  2019-03-22 20:50     ` Tom Rini
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Goldschmidt @ 2019-03-22 20:47 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] spl: add size check including devicetree
  2019-03-22 20:47   ` Simon Goldschmidt
@ 2019-03-22 20:50     ` Tom Rini
  2019-03-22 21:05       ` Simon Goldschmidt
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Rini @ 2019-03-22 20:50 UTC (permalink / raw)
  To: u-boot

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
-------------- 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>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] spl: add size check including devicetree
  2019-03-22 20:50     ` Tom Rini
@ 2019-03-22 21:05       ` Simon Goldschmidt
  0 siblings, 0 replies; 8+ messages in thread
From: Simon Goldschmidt @ 2019-03-22 21:05 UTC (permalink / raw)
  To: u-boot

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

>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] spl: add size check including devicetree
  2019-03-01 21:34 [U-Boot] [PATCH] spl: add size check including devicetree Simon Goldschmidt
  2019-03-22 13:03 ` [U-Boot] " Tom Rini
@ 2019-03-22 23:17 ` Tom Rini
  2019-03-27 14:47   ` Simon Goldschmidt
  1 sibling, 1 reply; 8+ messages in thread
From: Tom Rini @ 2019-03-22 23:17 UTC (permalink / raw)
  To: u-boot

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
-------------- 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>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] spl: add size check including devicetree
  2019-03-22 23:17 ` Tom Rini
@ 2019-03-27 14:47   ` Simon Goldschmidt
  2019-04-11 16:53     ` Tom Rini
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Goldschmidt @ 2019-03-27 14:47 UTC (permalink / raw)
  To: u-boot

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

>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] spl: add size check including devicetree
  2019-03-27 14:47   ` Simon Goldschmidt
@ 2019-04-11 16:53     ` Tom Rini
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Rini @ 2019-04-11 16:53 UTC (permalink / raw)
  To: u-boot

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.

-- 
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>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-04-11 16:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01 21:34 [U-Boot] [PATCH] spl: add size check including devicetree Simon Goldschmidt
2019-03-22 13:03 ` [U-Boot] " Tom Rini
2019-03-22 20:47   ` Simon Goldschmidt
2019-03-22 20:50     ` Tom Rini
2019-03-22 21:05       ` Simon Goldschmidt
2019-03-22 23:17 ` Tom Rini
2019-03-27 14:47   ` Simon Goldschmidt
2019-04-11 16:53     ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.