Patchwork [U-Boot,V2,2/5] ARM: enhance u-boot.lds to detect over-sized SPL

login
register
mail settings
Submitter Stephen Warren
Date Oct. 18, 2012, 11:25 p.m.
Message ID <1350602759-22605-2-git-send-email-swarren@wwwdotorg.org>
Download mbox | patch
Permalink /patch/192477/
State Superseded
Delegated to: Albert ARIBAUD
Headers show

Comments

Stephen Warren - Oct. 18, 2012, 11:25 p.m.
From: Stephen Warren <swarren@nvidia.com>

Add an ASSERT() to u-boot.lds to detect an SPL that doesn't fit within
SPL_TEXT_BASE..SPL_MAX_SIZE.

Different .lds files implement this check in two possible ways:
1) An ASSERT() like this
2) Defining a MEMORY region of size SPL_MAX_SIZE, and re-directing all
   linker output into that region. Since u-boot.lds is used for both
   SPL and main U-Boot, this would entail only sometimes defining a
   MEMORY region, and only sometimes performing that redirection, and
   hence option (1) was deemed much simpler, and hence implemented.

Note that this causes build failures at least for NVIDIA Tegra Seaboard
and Ventana. However, these are legitimate; the SPL doesn't fit within
the required space, and this does cause runtime issues.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
v2: New patch; replaced checks in Makefile.
---
 arch/arm/cpu/u-boot.lds |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Simon Glass - Oct. 19, 2012, 7:52 p.m.
On Thu, Oct 18, 2012 at 4:25 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Add an ASSERT() to u-boot.lds to detect an SPL that doesn't fit within
> SPL_TEXT_BASE..SPL_MAX_SIZE.
>
> Different .lds files implement this check in two possible ways:
> 1) An ASSERT() like this
> 2) Defining a MEMORY region of size SPL_MAX_SIZE, and re-directing all
>    linker output into that region. Since u-boot.lds is used for both
>    SPL and main U-Boot, this would entail only sometimes defining a
>    MEMORY region, and only sometimes performing that redirection, and
>    hence option (1) was deemed much simpler, and hence implemented.
>
> Note that this causes build failures at least for NVIDIA Tegra Seaboard
> and Ventana. However, these are legitimate; the SPL doesn't fit within
> the required space, and this does cause runtime issues.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>

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

Nice!

> ---
> v2: New patch; replaced checks in Makefile.
> ---
>  arch/arm/cpu/u-boot.lds |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
> index 9153c3d..ec2a273 100644
> --- a/arch/arm/cpu/u-boot.lds
> +++ b/arch/arm/cpu/u-boot.lds
> @@ -92,3 +92,7 @@ SECTIONS
>         /DISCARD/ : { *(.interp*) }
>         /DISCARD/ : { *(.gnu*) }
>  }
> +
> +#if defined(CONFIG_SPL_TEXT_BASE) && defined(CONFIG_SPL_MAX_SIZE)
> +ASSERT(__bss_end__ < (CONFIG_SPL_TEXT_BASE + CONFIG_SPL_MAX_SIZE), "SPL image too big");
> +#endif
> --
> 1.7.0.4
>
Allen Martin - Oct. 20, 2012, 5:49 a.m.
On Thu, Oct 18, 2012 at 04:25:56PM -0700, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
> 
> Add an ASSERT() to u-boot.lds to detect an SPL that doesn't fit within
> SPL_TEXT_BASE..SPL_MAX_SIZE.
> 
> Different .lds files implement this check in two possible ways:
> 1) An ASSERT() like this
> 2) Defining a MEMORY region of size SPL_MAX_SIZE, and re-directing all
>    linker output into that region. Since u-boot.lds is used for both
>    SPL and main U-Boot, this would entail only sometimes defining a
>    MEMORY region, and only sometimes performing that redirection, and
>    hence option (1) was deemed much simpler, and hence implemented.
> 
> Note that this causes build failures at least for NVIDIA Tegra Seaboard
> and Ventana. However, these are legitimate; the SPL doesn't fit within
> the required space, and this does cause runtime issues.
> 

Acked-by: Allen Martin <amartin@nvidia.com>

> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
> v2: New patch; replaced checks in Makefile.
> ---
>  arch/arm/cpu/u-boot.lds |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
> index 9153c3d..ec2a273 100644
> --- a/arch/arm/cpu/u-boot.lds
> +++ b/arch/arm/cpu/u-boot.lds
> @@ -92,3 +92,7 @@ SECTIONS
>  	/DISCARD/ : { *(.interp*) }
>  	/DISCARD/ : { *(.gnu*) }
>  }
> +
> +#if defined(CONFIG_SPL_TEXT_BASE) && defined(CONFIG_SPL_MAX_SIZE)
> +ASSERT(__bss_end__ < (CONFIG_SPL_TEXT_BASE + CONFIG_SPL_MAX_SIZE), "SPL image too big");
> +#endif
> -- 
> 1.7.0.4
>

Patch

diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index 9153c3d..ec2a273 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -92,3 +92,7 @@  SECTIONS
 	/DISCARD/ : { *(.interp*) }
 	/DISCARD/ : { *(.gnu*) }
 }
+
+#if defined(CONFIG_SPL_TEXT_BASE) && defined(CONFIG_SPL_MAX_SIZE)
+ASSERT(__bss_end__ < (CONFIG_SPL_TEXT_BASE + CONFIG_SPL_MAX_SIZE), "SPL image too big");
+#endif