diff mbox series

[U-Boot,045/126] spl: Add a size check for TPL

Message ID 20190925145750.200592-46-sjg@chromium.org
State Superseded
Delegated to: Bin Meng
Headers show
Series x86: Add initial support for apollolake | expand

Commit Message

Simon Glass Sept. 25, 2019, 2:56 p.m. UTC
We have the ability to enforce a maximum size for SPL but not yet for TPL.
Add a new option for this.

Document the size check macro while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 Makefile           | 7 +++++++
 common/spl/Kconfig | 8 ++++++++
 2 files changed, 15 insertions(+)

Comments

Simon Goldschmidt Sept. 26, 2019, 12:22 p.m. UTC | #1
Hi Simon,

On Wed, Sep 25, 2019 at 5:36 PM Simon Glass <sjg@chromium.org> wrote:
>
> We have the ability to enforce a maximum size for SPL but not yet for TPL.
> Add a new option for this.
>
> Document the size check macro while we are here.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  Makefile           | 7 +++++++
>  common/spl/Kconfig | 8 ++++++++
>  2 files changed, 15 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index a7a48b6aef3..43961af590f 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -806,6 +806,12 @@ else
>  SPL_SIZE_CHECK =
>  endif
>
> +ifneq ($(CONFIG_TPL_SIZE_LIMIT),0)
> +TPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_TPL_SIZE_LIMIT))

Using a constant here is not what SPL does by now: some months ago, I
implemented a more sophisticated size check for SPL that also integrates
'gd', stack and heap usage into the size check. Wouldn't that be required for
TPL as well (at least on platforms where everything must fit into SRAM)?

Regards,
Simon


> +else
> +TPL_SIZE_CHECK =
> +endif
> +
>  # Statically apply RELA-style relocations (currently arm64 only)
>  # This is useful for arm64 where static relocation needs to be performed on
>  # the raw binary, but certain simulators only accept an ELF file (but don't
> @@ -1786,6 +1792,7 @@ spl/boot.bin: spl/u-boot-spl
>  tpl/u-boot-tpl.bin: tools prepare \
>                 $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb)
>         $(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
> +       $(TPL_SIZE_CHECK)
>
>  TAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
>
> diff --git a/common/spl/Kconfig b/common/spl/Kconfig
> index ef4fb19e52c..b6d7bc81802 100644
> --- a/common/spl/Kconfig
> +++ b/common/spl/Kconfig
> @@ -1183,6 +1183,14 @@ config TPL
>
>  if TPL
>
> +config TPL_SIZE_LIMIT
> +       hex "Maximum size of TPL image"
> +       depends on TPL
> +       default 0
> +       help
> +         Specifies the maximum length of the U-Boot TPL image.
> +         If this value is zero, it is ignored.
> +
>  config TPL_HANDOFF
>         bool "Pass hand-off information from TPL to SPL and U-Boot proper"
>         depends on HANDOFF && TPL_BLOBLIST
> --
> 2.23.0.444.g18eeb5a265-goog
>
Simon Glass Oct. 11, 2019, 11:47 p.m. UTC | #2
Hi Simon,

On Thu, 26 Sep 2019 at 06:23, Simon Goldschmidt
<simon.k.r.goldschmidt@gmail.com> wrote:
>
> Hi Simon,
>
> On Wed, Sep 25, 2019 at 5:36 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > We have the ability to enforce a maximum size for SPL but not yet for TPL.
> > Add a new option for this.
> >
> > Document the size check macro while we are here.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> >  Makefile           | 7 +++++++
> >  common/spl/Kconfig | 8 ++++++++
> >  2 files changed, 15 insertions(+)
> >
> > diff --git a/Makefile b/Makefile
> > index a7a48b6aef3..43961af590f 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -806,6 +806,12 @@ else
> >  SPL_SIZE_CHECK =
> >  endif
> >
> > +ifneq ($(CONFIG_TPL_SIZE_LIMIT),0)
> > +TPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_TPL_SIZE_LIMIT))
>
> Using a constant here is not what SPL does by now: some months ago, I
> implemented a more sophisticated size check for SPL that also integrates
> 'gd', stack and heap usage into the size check. Wouldn't that be required for
> TPL as well (at least on platforms where everything must fit into SRAM)?

Yes I see, but in this case we just need the image to be below a
certain size. The actual memory used is somewhere else.

Regards,
SImon
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index a7a48b6aef3..43961af590f 100644
--- a/Makefile
+++ b/Makefile
@@ -806,6 +806,12 @@  else
 SPL_SIZE_CHECK =
 endif
 
+ifneq ($(CONFIG_TPL_SIZE_LIMIT),0)
+TPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_TPL_SIZE_LIMIT))
+else
+TPL_SIZE_CHECK =
+endif
+
 # Statically apply RELA-style relocations (currently arm64 only)
 # This is useful for arm64 where static relocation needs to be performed on
 # the raw binary, but certain simulators only accept an ELF file (but don't
@@ -1786,6 +1792,7 @@  spl/boot.bin: spl/u-boot-spl
 tpl/u-boot-tpl.bin: tools prepare \
 		$(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb)
 	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
+	$(TPL_SIZE_CHECK)
 
 TAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
 
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index ef4fb19e52c..b6d7bc81802 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -1183,6 +1183,14 @@  config TPL
 
 if TPL
 
+config TPL_SIZE_LIMIT
+	hex "Maximum size of TPL image"
+	depends on TPL
+	default 0
+	help
+	  Specifies the maximum length of the U-Boot TPL image.
+	  If this value is zero, it is ignored.
+
 config TPL_HANDOFF
 	bool "Pass hand-off information from TPL to SPL and U-Boot proper"
 	depends on HANDOFF && TPL_BLOBLIST