public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to have different stack/malloc area
@ 2008-05-21 16:26 Menon, Nishanth
  2008-06-03  8:08 ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Menon, Nishanth @ 2008-05-21 16:26 UTC (permalink / raw)
  To: u-boot

The default setup of ARM memory allocation is as follows:
 ----
Stack Area
 ----
Heap Area
---
_u_boot_start
Rest of U-Boot..

This is an excellent strategy to catch stack overflow and memory buffer overflow issues. However, in conditions where:
a) U-Boot is automatically loaded by h/w in the default location without a writable memory area above it, this will crash,
b) Multiple non-contiguous memory areas available in system (e.g. SRAM and SDRAM), but the area where U-Boot is loaded is restricted in size and cannot fit the required heap and stack areas.
In these cases, we need to have ability to move the Heap and stack to the area of our choice. This patch introduces CONFIG_MALLOC_START for machine configurations which require this.
This would need to be enabled only if MACH_CAN_MODIFY_MALLOC_START is defined by the machine configurations that desire it. I have clubbed both heap and stack area to still catch some of those overflow issues.

Signed-off-by: Nishanth Menon<x0nishan@ti.com>

---
 arch/arm/Kconfig         |   22 ++++++++++++++++++++++
 arch/arm/cpu/start-arm.S |    9 +++++++++
 arch/arm/lib/arm.c       |    5 +++++
 3 files changed, 36 insertions(+)

Index: u-boot-v2.git/arch/arm/lib/arm.c
===================================================================
--- u-boot-v2.git.orig/arch/arm/lib/arm.c	2008-05-20 17:19:42.000000000 -0500
+++ u-boot-v2.git/arch/arm/lib/arm.c	2008-05-20 17:26:33.000000000 -0500
@@ -6,8 +6,13 @@
 
 int arm_mem_malloc_init(void)
 {
+#ifndef CONFIG_MALLOC_START
 	mem_malloc_init((void *)(_u_boot_start - CFG_MALLOC_LEN),
 			(void *)_u_boot_start);
+#else
+	mem_malloc_init((void *)(CONFIG_MALLOC_START - CFG_MALLOC_LEN),
+			(void *)CONFIG_MALLOC_START);
+#endif
 	return 0;
 }
 
Index: u-boot-v2.git/arch/arm/Kconfig
===================================================================
--- u-boot-v2.git.orig/arch/arm/Kconfig	2008-05-20 17:19:42.000000000 -0500
+++ u-boot-v2.git/arch/arm/Kconfig	2008-05-20 17:26:33.000000000 -0500
@@ -168,6 +168,28 @@
 	  If you want to start a 2.6 kernel and use an
 	  initrd image say y here.
 
+config MACH_CAN_MODIFY_MALLOC_START
+	bool
+
+config MALLOC_START_MODIFY
+	bool "Change Malloc Address location from default"
+	default n
+	depends on MACH_CAN_MODIFY_MALLOC_START
+	help
+	  Say Y here if you meanto put malloc and stack elsewhere.
+	  The default is to put Malloc and stack just above the
+	  interrupt vectors(_start). It is usually desired to keep it here
+	  as we can catch stack overflow and corruption issues easily.
+	  USE THIS OPTION WITH CAUTION
+
+config MALLOC_START
+	hex
+	prompt "Provide Alternate Malloc Start address"
+	depends on MALLOC_START_MODIFY
+	help
+	  Provide the alternate malloc start address. Remember that the area
+	  that will be used will be (this address) to (this address - CFG_MALLOC_LEN - CONFIG_STACKSIZE)
+
 endmenu
 
 source common/Kconfig
Index: u-boot-v2.git/arch/arm/cpu/start-arm.S
===================================================================
--- u-boot-v2.git.orig/arch/arm/cpu/start-arm.S	2008-05-20 17:26:30.000000000 -0500
+++ u-boot-v2.git/arch/arm/cpu/start-arm.S	2008-05-20 17:26:33.000000000 -0500
@@ -90,11 +90,20 @@
  * FIXME
  *************************************************************************/
 
+#ifndef CONFIG_MALLOC_START
 _MALLOC_START:
 	.word _start - CFG_MALLOC_LEN
 
 _STACK_START:
 	.word _start - CFG_MALLOC_LEN - CONFIG_STACKSIZE
+#else
+_MALLOC_START:
+	.word CONFIG_MALLOC_START - CFG_MALLOC_LEN
+
+_STACK_START:
+	.word CONFIG_MALLOC_START - CFG_MALLOC_LEN - CONFIG_STACKSIZE
+#endif
+
 
 /*
  * These are defined in the board-specific linker script.

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

* [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to have different stack/malloc area
  2008-05-21 16:26 [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to have different stack/malloc area Menon, Nishanth
@ 2008-06-03  8:08 ` Sascha Hauer
  2008-06-03 15:04   ` [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to havedifferent " Menon, Nishanth
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2008-06-03  8:08 UTC (permalink / raw)
  To: u-boot

On Wed, May 21, 2008 at 11:26:25AM -0500, Menon, Nishanth wrote:
> The default setup of ARM memory allocation is as follows:
>  ----
> Stack Area
>  ----
> Heap Area
> ---
> _u_boot_start
> Rest of U-Boot..
> 
> This is an excellent strategy to catch stack overflow and memory buffer overflow issues. However, in conditions where:
> a) U-Boot is automatically loaded by h/w in the default location without a writable memory area above it, this will crash,
> b) Multiple non-contiguous memory areas available in system (e.g. SRAM and SDRAM), but the area where U-Boot is loaded is restricted in size and cannot fit the required heap and stack areas.
> In these cases, we need to have ability to move the Heap and stack to the area of our choice. This patch introduces CONFIG_MALLOC_START for machine configurations which require this.
> This would need to be enabled only if MACH_CAN_MODIFY_MALLOC_START is defined by the machine configurations that desire it. I have clubbed both heap and stack area to still catch some of those overflow issues.

This patch rises an issue we currently have in U-Boot-v2: We have as
many stack/memory strategies as we have architectures :(

Instead of modifying this for one architecture I would prefer something
like this (currently no implementation, only kconfig).
Would this solve your issues?

regards,
 Sascha

diff --git a/common/Kconfig b/common/Kconfig
index 79a3684..d764482 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -19,13 +19,66 @@ menu "General Settings              "
 config BOARDINFO
 	string
 
+menu "memory layout                 "
+
 config TEXT_BASE
+	depends on HAVE_CONFIGURABLE_TEXT_BASE
 	prompt "TEXT_BASE"
 	hex
 	default ARCH_TEXT_BASE
 	help
 	  The Address U-Boot gets linked at.
 
+choice
+	prompt "select stack base policy"
+	depends on HAVE_CONFIGURABLE_STACK
+	default STACK_BASE_FIXED
+
+config STACK_BASE_DEFAULT
+	bool "place stack before malloc space"
+
+config STACK_BASE_FIXED
+	bool "manually assign a stack base"
+
+endchoice
+
+config STACK_BASE
+	depends on STACK_BASE_FIXED
+	hex
+	prompt "STACK_BASE"
+
+config STACK_SIZE
+	hex
+	depends on HAVE_CONFIGURABLE_STACK
+	default 0x8000
+	prompt "Stack size"
+
+choice
+	prompt "select stack base policy"
+	depends on HAVE_CONFIGURABLE_MALLOC
+
+config MALLOC_BASE_DEFAULT
+	bool
+	prompt "place stack before U-Boot"
+
+config MALLOC_BASE_FIXED
+	bool
+	prompt "manually assign a malloc base"
+
+endchoice
+
+config MALLOC_BASE
+	depends on MALLOC_BASE_FIXED
+	hex
+	prompt "MALLOC_BASE"
+
+config MALLOC_SIZE
+	hex
+	depends on HAVE_CONFIGURABLE_MALLOC
+	default 0x400000
+	prompt "malloc area size"
+endmenu
+
 config BROKEN
 	bool
 	prompt "Prompt for broken or incomplete code"


-- 
Pengutronix e.K. - Linux Solutions for Science and Industry
-----------------------------------------------------------
Kontakt-Informationen finden Sie im Header dieser Mail oder
auf der Webseite -> http://www.pengutronix.de/impressum/ <-

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

* [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to havedifferent stack/malloc area
  2008-06-03  8:08 ` Sascha Hauer
@ 2008-06-03 15:04   ` Menon, Nishanth
  2008-06-03 15:24     ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Menon, Nishanth @ 2008-06-03 15:04 UTC (permalink / raw)
  To: u-boot

Sascha,

> -----Original Message-----
> From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
> Sent: Tuesday, June 03, 2008 3:08 AM
> To: Menon, Nishanth
> Cc: u-boot-users at lists.sourceforge.net; Laurent Desnogues; dirk.behme at googlemail.com;
> philip.balister at gmail.com; Gopinath, Thara; Kamat, Nishant; Syed Mohammed, Khasim
> Subject: Re: [Patch 05/17] U-Boot-V2:ARM: Introduce capability to havedifferent stack/malloc area
> 
> This patch rises an issue we currently have in U-Boot-v2: We have as
> many stack/memory strategies as we have architectures :(
> 
> Instead of modifying this for one architecture I would prefer something
> like this (currently no implementation, only kconfig).
> Would this solve your issues?
Yes, :). Couple of minor comments though..

> diff --git a/common/Kconfig b/common/Kconfig
> index 79a3684..d764482 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -19,13 +19,66 @@ menu "General Settings              "
>  config BOARDINFO
>  	string
> 
> +menu "memory layout                 "
Curious: Why have the extra space? I see this in other places too.. it kind of messes up the defconfig with trailing spaces :(.

> +choice
> +	prompt "select stack base policy"
s/stack/heap?
> +	depends on HAVE_CONFIGURABLE_MALLOC
> +
> +config MALLOC_BASE_DEFAULT
> +	bool
> +	prompt "place stack before U-Boot"
s/stack/heap?
> +
> +config MALLOC_BASE_FIXED
> +	bool
> +	prompt "manually assign a malloc base"
> +
> +endchoice
> +
> +endmenu
> +
Ack to the changes. This should be good for me.

Regards,
Nishanth Menon

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

* [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to havedifferent stack/malloc area
  2008-06-03 15:04   ` [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to havedifferent " Menon, Nishanth
@ 2008-06-03 15:24     ` Sascha Hauer
  2008-06-04  5:04       ` [U-Boot-Users] [Patch 05/17 Try 2] U-Boot-V2:ARM: Introduce capability tohavedifferent " Menon, Nishanth
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2008-06-03 15:24 UTC (permalink / raw)
  To: u-boot

On Tue, Jun 03, 2008 at 10:04:29AM -0500, Menon, Nishanth wrote:
> Sascha,
> 
> > -----Original Message-----
> > From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
> > Sent: Tuesday, June 03, 2008 3:08 AM
> > To: Menon, Nishanth
> > Cc: u-boot-users at lists.sourceforge.net; Laurent Desnogues; dirk.behme at googlemail.com;
> > philip.balister at gmail.com; Gopinath, Thara; Kamat, Nishant; Syed Mohammed, Khasim
> > Subject: Re: [Patch 05/17] U-Boot-V2:ARM: Introduce capability to havedifferent stack/malloc area
> > 
> > This patch rises an issue we currently have in U-Boot-v2: We have as
> > many stack/memory strategies as we have architectures :(
> > 
> > Instead of modifying this for one architecture I would prefer something
> > like this (currently no implementation, only kconfig).
> > Would this solve your issues?
> Yes, :). Couple of minor comments though..
> 
> > diff --git a/common/Kconfig b/common/Kconfig
> > index 79a3684..d764482 100644
> > --- a/common/Kconfig
> > +++ b/common/Kconfig
> > @@ -19,13 +19,66 @@ menu "General Settings              "
> >  config BOARDINFO
> >  	string
> > 
> > +menu "memory layout                 "
> Curious: Why have the extra space? I see this in other places too.. it kind of messes up the defconfig with trailing spaces :(.

It's just to align the menu arrows nicely under each other in make
menuconfig.

> 
> > +choice
> > +	prompt "select stack base policy"
> s/stack/heap?
> > +	depends on HAVE_CONFIGURABLE_MALLOC
> > +
> > +config MALLOC_BASE_DEFAULT
> > +	bool
> > +	prompt "place stack before U-Boot"
> s/stack/heap?

No, this is the processor stack...
> > +
> > +config MALLOC_BASE_FIXED
> > +	bool
> > +	prompt "manually assign a malloc base"
> > +

...while this is the malloc heap.

> > +endchoice
> > +
> > +endmenu
> > +
> Ack to the changes. This should be good for me.
> 
> Regards,
> Nishanth Menon
> 

-- 
Pengutronix e.K. - Linux Solutions for Science and Industry
-----------------------------------------------------------
Kontakt-Informationen finden Sie im Header dieser Mail oder
auf der Webseite -> http://www.pengutronix.de/impressum/ <-

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

* [U-Boot-Users] [Patch 05/17 Try 2] U-Boot-V2:ARM: Introduce capability tohavedifferent stack/malloc area
  2008-06-03 15:24     ` Sascha Hauer
@ 2008-06-04  5:04       ` Menon, Nishanth
  2008-06-04  9:57         ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Menon, Nishanth @ 2008-06-04  5:04 UTC (permalink / raw)
  To: u-boot

Sascha,
> -----Original Message-----
> From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
> Sent: Tuesday, June 03, 2008 10:24 AM
> To: Menon, Nishanth
> Cc: u-boot-users at lists.sourceforge.net; Laurent Desnogues; dirk.behme at googlemail.com;
> philip.balister at gmail.com; Gopinath, Thara; Kamat, Nishant; Syed Mohammed, Khasim
> Subject: Re: [Patch 05/17] U-Boot-V2:ARM: Introduce capability tohavedifferent stack/malloc area
>
> > Instead of modifying this for one architecture I would prefer something
> > like this (currently no implementation, only kconfig).
> > Would this solve your issues?

Modification only done for ARM.

Signed-off-by: Nishanth Menon<x0nishan@ti.com>

---
 arch/arm/cpu/start-arm.S |   27 +++++++++++++++++++-
 arch/arm/lib/arm.c       |   16 ++++++++++--
 common/Kconfig           |   61 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 4 deletions(-)

Index: u-boot.v2/arch/arm/lib/arm.c
===================================================================
--- u-boot.v2.orig/arch/arm/lib/arm.c   2008-06-03 20:56:27.000000000 -0500
+++ u-boot.v2/arch/arm/lib/arm.c        2008-06-03 20:56:46.000000000 -0500
@@ -4,10 +4,22 @@
 #include <asm/u-boot-arm.h>
 #include <reloc.h>

+#ifdef CONFIG_MALLOC_BASE
+#define ARM_MALLOC_START CONFIG_MALLOC_BASE
+#else
+#define ARM_MALLOC_START _u_boot_start
+#endif
+
+#ifdef CONFIG_MALLOC_SIZE
+#define ARM_MALLOC_SIZE CONFIG_MALLOC_SIZE
+#else
+#define ARM_MALLOC_SIZE CFG_MALLOC_LEN
+#endif
+
 int arm_mem_malloc_init(void)
 {
-       mem_malloc_init((void *)(_u_boot_start - CFG_MALLOC_LEN),
-                       (void *)_u_boot_start);
+       mem_malloc_init((void *)(ARM_MALLOC_START - ARM_MALLOC_SIZE),
+                       (void *)ARM_MALLOC_START);
        return 0;
 }

Index: u-boot.v2/arch/arm/cpu/start-arm.S
===================================================================
--- u-boot.v2.orig/arch/arm/cpu/start-arm.S     2008-06-03 20:56:40.000000000 -0500
+++ u-boot.v2/arch/arm/cpu/start-arm.S  2008-06-03 21:08:04.000000000 -0500
@@ -90,11 +90,34 @@
  * FIXME
  *************************************************************************/

+#ifdef CONFIG_MALLOC_BASE
+#define ARM_MALLOC_START CONFIG_MALLOC_BASE
+#else
+#define ARM_MALLOC_START _start
+#endif
+
+#ifdef CONFIG_MALLOC_SIZE
+#define ARM_MALLOC_SIZE CONFIG_MALLOC_SIZE
+#else
+#define ARM_MALLOC_SIZE CFG_MALLOC_LEN
+#endif
 _MALLOC_START:
-       .word _start - CFG_MALLOC_LEN
+       .word ARM_MALLOC_START - ARM_MALLOC_SIZE

+#ifdef CONFIG_STACK_BASE
+#define ARM_STACK_START CONFIG_STACK_BASE
+#else
+#define ARM_STACK_START (ARM_MALLOC_START - ARM_MALLOC_SIZE)
+#endif
+
+#ifdef CONFIG_STACK_SIZE
+#define ARM_STACK_SIZE CONFIG_STACK_SIZE
+#else
+#define ARM_STACK_SIZE CFG_STACK_LEN
+#endif
 _STACK_START:
-       .word _start - CFG_MALLOC_LEN - CONFIG_STACKSIZE
+       .word ARM_STACK_START - CONFIG_STACKSIZE
+

 /*
  * These are defined in the board-specific linker script.
Index: u-boot.v2/common/Kconfig
===================================================================
--- u-boot.v2.orig/common/Kconfig       2008-06-03 20:56:40.000000000 -0500
+++ u-boot.v2/common/Kconfig    2008-06-03 21:08:37.000000000 -0500
@@ -19,13 +19,74 @@
 config BOARDINFO
        string

+menu "memory layout                 "
+
+config HAVE_CONFIGURABLE_TEXT_BASE
+       bool
+
 config TEXT_BASE
+       depends on HAVE_CONFIGURABLE_TEXT_BASE
        prompt "TEXT_BASE"
        hex
        default ARCH_TEXT_BASE
        help
          The Address U-Boot gets linked at.

+config HAVE_CONFIGURABLE_STACK
+       bool
+choice
+       prompt "select stack base policy"
+       depends on HAVE_CONFIGURABLE_STACK
+       default STACK_BASE_FIXED
+
+config STACK_BASE_DEFAULT
+       bool "place stack before malloc space"
+
+config STACK_BASE_FIXED
+       bool "manually assign a stack base"
+
+endchoice
+
+config STACK_BASE
+       depends on STACK_BASE_FIXED
+       hex
+       prompt "STACK_BASE"
+
+config STACK_SIZE
+       hex
+       depends on HAVE_CONFIGURABLE_STACK
+       default 0x8000
+       prompt "Stack size"
+
+config HAVE_CONFIGURABLE_MALLOC
+       bool
+
+choice
+       prompt "select malloc base policy"
+       depends on HAVE_CONFIGURABLE_MALLOC
+
+config MALLOC_BASE_DEFAULT
+       bool
+       prompt "place malloc before U-Boot"
+
+config MALLOC_BASE_FIXED
+       bool
+       prompt "manually assign a malloc base"
+
+endchoice
+
+config MALLOC_BASE
+       depends on MALLOC_BASE_FIXED
+       hex
+       prompt "MALLOC_BASE"
+
+config MALLOC_SIZE
+       hex
+       depends on HAVE_CONFIGURABLE_MALLOC
+       default 0x400000
+       prompt "malloc area size"
+endmenu
+
 config BROKEN
        bool
        prompt "Prompt for broken or incomplete code"

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

* [U-Boot-Users] [Patch 05/17 Try 2] U-Boot-V2:ARM: Introduce capability tohavedifferent stack/malloc area
  2008-06-04  5:04       ` [U-Boot-Users] [Patch 05/17 Try 2] U-Boot-V2:ARM: Introduce capability tohavedifferent " Menon, Nishanth
@ 2008-06-04  9:57         ` Sascha Hauer
  0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2008-06-04  9:57 UTC (permalink / raw)
  To: u-boot

On Wed, Jun 04, 2008 at 12:04:51AM -0500, Menon, Nishanth wrote:
> Sascha,
> > -----Original Message-----
> > From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
> > Sent: Tuesday, June 03, 2008 10:24 AM
> > To: Menon, Nishanth
> > Cc: u-boot-users at lists.sourceforge.net; Laurent Desnogues; dirk.behme at googlemail.com;
> > philip.balister at gmail.com; Gopinath, Thara; Kamat, Nishant; Syed Mohammed, Khasim
> > Subject: Re: [Patch 05/17] U-Boot-V2:ARM: Introduce capability tohavedifferent stack/malloc area
> >
> > > Instead of modifying this for one architecture I would prefer something
> > > like this (currently no implementation, only kconfig).
> > > Would this solve your issues?
> 
> Modification only done for ARM.
> 

I checked in a similar version of the patch, should work for you.

Sascha

-- 
Pengutronix e.K. - Linux Solutions for Science and Industry
-----------------------------------------------------------
Kontakt-Informationen finden Sie im Header dieser Mail oder
auf der Webseite -> http://www.pengutronix.de/impressum/ <-

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

end of thread, other threads:[~2008-06-04  9:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-21 16:26 [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to have different stack/malloc area Menon, Nishanth
2008-06-03  8:08 ` Sascha Hauer
2008-06-03 15:04   ` [U-Boot-Users] [Patch 05/17] U-Boot-V2:ARM: Introduce capability to havedifferent " Menon, Nishanth
2008-06-03 15:24     ` Sascha Hauer
2008-06-04  5:04       ` [U-Boot-Users] [Patch 05/17 Try 2] U-Boot-V2:ARM: Introduce capability tohavedifferent " Menon, Nishanth
2008-06-04  9:57         ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox