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<[EMAIL PROTECTED]>

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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
U-Boot-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/u-boot-users

Reply via email to