Skip to contentSkip to conversation

Clean up up malloc pool init

PATCH New Peter Tyser 4 participants 13 messages Aug 22, 2009 – Sep 4, 2009

lore
Share & tools
lore
#0 lore raw

cover Clean up up malloc pool init

Most architectures share nearly identical malloc initialization code. This series factors out the common code into dlmalloc.c.

I tested on the XPedite5200, an mpc8548-based board. Let me know if anyone runs into any issues on other architectures.

Peter Tyser (3):
Consolidate arch-specific sbrk() implementations Standardize mem_malloc_init() implementation Consolidate arch-specific mem_malloc_init() implementations

 common/dlmalloc.c      |   33 ++++++++++++++++++++++++++++++++-
 include/malloc.h       |    8 ++++++++
 lib_arm/board.c        |   34 ++--------------------------------
 lib_avr32/board.c      |   41 ++++-------------------------------------
 lib_blackfin/board.c   |   25 +------------------------
 lib_i386/board.c       |   21 ---------------------
 lib_m68k/board.c       |   41 +++--------------------------------------
 lib_microblaze/board.c |   40 ++++++----------------------------------
 lib_mips/board.c       |   40 +++-------------------------------------
 lib_nios/board.c       |   37 ++++---------------------------------
 lib_nios2/board.c      |   37 ++++---------------------------------
 lib_ppc/board.c        |   44 ++++++--------------------------------------
 lib_sh/board.c         |   31 ++-----------------------------
 lib_sparc/board.c      |   42 +++---------------------------------------
 14 files changed, 78 insertions(+), 396 deletions(-)
#1 lore raw

PATCH 1/3 Consolidate arch-specific sbrk() implementations

---
 common/dlmalloc.c      |   18 +++++++++++++++++-
 include/malloc.h       |    6 ++++++
 lib_arm/board.c        |   20 --------------------
 lib_avr32/board.c      |   19 -------------------
 lib_blackfin/board.c   |   20 +++-----------------
 lib_i386/board.c       |   21 ---------------------
 lib_m68k/board.c       |   20 --------------------
 lib_microblaze/board.c |   19 -------------------
 lib_mips/board.c       |   19 -------------------
 lib_nios/board.c       |   20 +-------------------
 lib_nios2/board.c      |   20 +-------------------
 lib_ppc/board.c        |   19 -------------------
 lib_sh/board.c         |   18 ------------------
 lib_sparc/board.c      |   19 -------------------
 14 files changed, 28 insertions(+), 230 deletions(-)
common/dlmalloc.c +17 -1
index 4a18562..f3bced4 100644
@@ -1502,7 +1502,23 @@ void malloc_bin_reloc (void)
 		*p++ += gd->reloc_off;
 	}
 }
-
+
+ulong mem_malloc_start = 0;
+ulong mem_malloc_end = 0;
+ulong mem_malloc_brk = 0;
+
+void *sbrk(ptrdiff_t increment)
+{
+	ulong old = mem_malloc_brk;
+	ulong new = old + increment;
+
+	if ((new < mem_malloc_start) || (new > mem_malloc_end))
+		return NULL;
+
+	mem_malloc_brk = new;
+
+	return (void *)old;
+}
 
 /* field-extraction macros */
 
include/malloc.h +6 -0
index a38464e..0382169 100644
@@ -937,6 +937,12 @@ int     mALLOPt();
 struct mallinfo mALLINFo();
 #endif
 
+/*
+ * Begin and End of memory area for malloc(), and current "brk"
+ */
+extern ulong mem_malloc_start;
+extern ulong mem_malloc_end;
+extern ulong mem_malloc_brk;
 
 #ifdef __cplusplus
 };  /* end of extern "C" */
lib_arm/board.c +0 -20
index a44d308..9bd5eca 100644
@@ -86,13 +86,6 @@ extern void rtl8019_get_enetaddr (uchar * addr);
 #include <i2c.h>
 #endif
 
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
 static
 void mem_malloc_init (ulong dest_addr)
 {
@@ -104,19 +97,6 @@ void mem_malloc_init (ulong dest_addr)
 			mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk (ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-
-	return ((void *) old);
-}
-
 
 /************************************************************************
  * Coloured LED functionality
lib_avr32/board.c +0 -19
index e2b0a2e..03a520c 100644
@@ -41,13 +41,6 @@ const char version_string[] =
 
 unsigned long monitor_flash_len;
 
-/*
- * Begin and end of memory area for malloc(), and current "brk"
- */
-static unsigned long mem_malloc_start = 0;
-static unsigned long mem_malloc_end = 0;
-static unsigned long mem_malloc_brk = 0;
-
 /* Weak aliases for optional board functions */
 static int __do_nothing(void)
 {
@@ -73,18 +66,6 @@ static void mem_malloc_init(void)
 		mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk(ptrdiff_t increment)
-{
-	unsigned long old = mem_malloc_brk;
-	unsigned long new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end))
-		return NULL;
-
-	mem_malloc_brk = new;
-	return ((void *)old);
-}
-
 #ifdef CONFIG_SYS_DMA_ALLOC_LEN
 #include <asm/arch/cacheflush.h>
 #include <asm/io.h>
lib_blackfin/board.c +3 -17
index b957a9d..b293c1b 100644
@@ -44,27 +44,13 @@ static inline void serial_early_puts(const char *s)
 #endif
 }
 
-static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk;
-
 static void mem_malloc_init(void)
 {
-	mem_malloc_start = (void *)CONFIG_SYS_MALLOC_BASE;
-	mem_malloc_end = (void *)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
+	mem_malloc_start = (ulong)CONFIG_SYS_MALLOC_BASE;
+	mem_malloc_end = (ulong)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
 	mem_malloc_brk = mem_malloc_start;
-	memset(mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
-}
-
-void *sbrk(ptrdiff_t increment)
-{
-	void *old = mem_malloc_brk;
-	void *new = old + increment;
-
-	if (new < mem_malloc_start || new > mem_malloc_end)
-		return NULL;
-
-	mem_malloc_brk = new;
 
-	return old;
+	memset((void*)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
 }
 
 static int display_banner(void)
lib_i386/board.c +0 -21
index 54ef6e7..0262b5e 100644
@@ -73,14 +73,6 @@ ulong i386boot_bios_size     = (ulong)&_i386boot_bios_size;     /* size of BIOS
 const char version_string[] =
 	U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")";
 
-
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
 static int mem_malloc_init(void)
 {
 	/* start malloc area right after the stack */
@@ -96,19 +88,6 @@ static int mem_malloc_init(void)
 	return 0;
 }
 
-void *sbrk (ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-
-	return ((void *) old);
-}
-
 /************************************************************************
  * Init Utilities							*
  ************************************************************************
lib_m68k/board.c +0 -20
index 483c9b6..4392bcc 100644
@@ -101,13 +101,6 @@ extern int watchdog_disable(void);
 
 ulong monitor_flash_len;
 
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static	ulong	mem_malloc_start = 0;
-static	ulong	mem_malloc_end	 = 0;
-static	ulong	mem_malloc_brk	 = 0;
-
 /************************************************************************
  * Utilities								*
  ************************************************************************
@@ -129,19 +122,6 @@ static void mem_malloc_init (void)
 		mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk (ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) ||
-	    (new > mem_malloc_end) ) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-	return ((void *)old);
-}
-
 /*
  * All attempts to come up with a "common" initialization sequence
  * that works for all boards and architectures failed: some of the
lib_microblaze/board.c +0 -19
index cfed5fe..fc25a75 100644
@@ -47,13 +47,6 @@ extern int getenv_IPaddr (char *);
 #endif
 
 /*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start;
-static ulong mem_malloc_end;
-static ulong mem_malloc_brk;
-
-/*
  * The Malloc area is immediately below the monitor copy in DRAM
  * aka CONFIG_SYS_MONITOR_BASE - Note there is no need for reloc_off
  * as our monitory code is run from SDRAM
@@ -66,18 +59,6 @@ static void mem_malloc_init (void)
 	memset ((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk (ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-	return ((void *)old);
-}
-
 /*
  * All attempts to come up with a "common" initialization sequence
  * that works for all boards and architectures failed: some of the
lib_mips/board.c +0 -19
index aa5b129..68a3697 100644
@@ -60,13 +60,6 @@ const char version_string[] =
 static char *failed = "*** failed ***\n";
 
 /*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start;
-static ulong mem_malloc_end;
-static ulong mem_malloc_brk;
-
-/*
  * mips_io_port_base is the begin of the address space to which x86 style
  * I/O ports are mapped.
  */
@@ -97,18 +90,6 @@ static void mem_malloc_init (void)
 		mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk (ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-	return ((void *) old);
-}
-
 
 static int init_func_ram (void)
 {
lib_nios/board.c +1 -19
index cd23457..30cdb47 100644
@@ -27,6 +27,7 @@
 #include <common.h>
 #include <stdio_dev.h>
 #include <watchdog.h>
+#include <malloc.h>
 #include <net.h>
 #ifdef CONFIG_STATUS_LED
 #include <status_led.h>
@@ -52,13 +53,6 @@ extern void malloc_bin_reloc (void);
 typedef int (init_fnc_t) (void);
 
 /*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static	ulong	mem_malloc_start = 0;
-static	ulong	mem_malloc_end	 = 0;
-static	ulong	mem_malloc_brk	 = 0;
-
-/*
  * The Malloc area is immediately below the monitor copy in RAM
  */
 static void mem_malloc_init (void)
@@ -71,18 +65,6 @@ static void mem_malloc_init (void)
 		mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk (ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-	return ((void *) old);
-}
-
 
 /************************************************************************
  * Initialization sequence						*
lib_nios2/board.c +1 -19
index b142c59..e5a8d54 100644
@@ -27,6 +27,7 @@
 #include <common.h>
 #include <stdio_dev.h>
 #include <watchdog.h>
+#include <malloc.h>
 #include <net.h>
 #ifdef CONFIG_STATUS_LED
 #include <status_led.h>
@@ -55,13 +56,6 @@ extern void malloc_bin_reloc (void);
 typedef int (init_fnc_t) (void);
 
 /*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static	ulong	mem_malloc_start = 0;
-static	ulong	mem_malloc_end	 = 0;
-static	ulong	mem_malloc_brk	 = 0;
-
-/*
  * The Malloc area is immediately below the monitor copy in RAM
  */
 static void mem_malloc_init (void)
@@ -74,18 +68,6 @@ static void mem_malloc_init (void)
 		mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk (ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-	return ((void *) old);
-}
-
 
 /************************************************************************
  * Initialization sequence						*
lib_ppc/board.c +0 -19
index 6dd4d56..8a8cca1 100644
@@ -136,13 +136,6 @@ ulong monitor_flash_len;
 #include <bedbug/type.h>
 #endif
 
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static	ulong	mem_malloc_start = 0;
-static	ulong	mem_malloc_end	 = 0;
-static	ulong	mem_malloc_brk	 = 0;
-
 /************************************************************************
  * Utilities								*
  ************************************************************************
@@ -164,18 +157,6 @@ static void mem_malloc_init (void)
 		mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk (ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-	return ((void *) old);
-}
-
 /*
  * All attempts to come up with a "common" initialization sequence
  * that works for all boards and architectures failed: some of the
lib_sh/board.c +0 -18
index 829455d..001e89c 100644
@@ -38,10 +38,6 @@ const char version_string[] = U_BOOT_VERSION" ("U_BOOT_DATE" - "U_BOOT_TIME")";
 
 unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
 
-static unsigned long mem_malloc_start;
-static unsigned long mem_malloc_end;
-static unsigned long mem_malloc_brk;
-
 static void mem_malloc_init(void)
 {
 
@@ -52,20 +48,6 @@ static void mem_malloc_init(void)
 		(mem_malloc_end - mem_malloc_start));
 }
 
-void *sbrk(ptrdiff_t increment)
-{
-	unsigned long old = mem_malloc_brk;
-	unsigned long new = old + increment;
-
-	if ((new < mem_malloc_start) ||
-	    (new > mem_malloc_end)) {
-		return NULL;
-	}
-
-	mem_malloc_brk = new;
-	return (void *) old;
-}
-
 static int sh_flash_init(void)
 {
 	DECLARE_GLOBAL_DATA_PTR;
lib_sparc/board.c +0 -19
index d40834b..37b7c0a 100644
@@ -74,13 +74,6 @@ static char *failed = "*** failed ***\n";
 
 ulong monitor_flash_len;
 
-/*
- * Begin and End of memory area for malloc(), and current "brk"
- */
-static ulong mem_malloc_start = 0;
-static ulong mem_malloc_end = 0;
-static ulong mem_malloc_brk = 0;
-
 /************************************************************************
  * Utilities								*
  ************************************************************************
@@ -97,18 +90,6 @@ static void mem_malloc_init(void)
 	memset((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
 }
 
-void *sbrk(ptrdiff_t increment)
-{
-	ulong old = mem_malloc_brk;
-	ulong new = old + increment;
-
-	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
-		return (NULL);
-	}
-	mem_malloc_brk = new;
-	return ((void *)old);
-}
-
 /***********************************************************************/
 
 /************************************************************************
Signature · 1 line
1.6.2.1
#2 lore raw

PATCH 1/3 Consolidate arch-specific sbrk() implementations

Dear Peter Tyser,

Quoted 17 lines · In message <[email protected]> you wrote:
---
 common/dlmalloc.c      |   18 +++++++++++++++++-
 include/malloc.h       |    6 ++++++
 lib_arm/board.c        |   20 --------------------
 lib_avr32/board.c      |   19 -------------------
 lib_blackfin/board.c   |   20 +++-----------------
 lib_i386/board.c       |   21 ---------------------
 lib_m68k/board.c       |   20 --------------------
 lib_microblaze/board.c |   19 -------------------
 lib_mips/board.c       |   19 -------------------
 lib_nios/board.c       |   20 +-------------------
 lib_nios2/board.c      |   20 +-------------------
 lib_ppc/board.c        |   19 -------------------
 lib_sh/board.c         |   18 ------------------
 lib_sparc/board.c      |   19 -------------------
 14 files changed, 28 insertions(+), 230 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Unsichtbar macht sich die Dummheit, indem sie immer  gr??ere  Ausma?e
annimmt.                             -- Bertold Brecht: Der Tui-Roman
#3 lore raw

PATCH 2/3 Standardize mem_malloc_init() implementation

In reply to Peter Tyser

This lays the groundwork to allow architectures to share a common mem_malloc_init().

Note that the x86 implementation was not modified as it did not fit the mold of all other architectures.

---
 lib_arm/board.c        |   14 +++++++-------
 lib_avr32/board.c      |   17 +++++++----------
 lib_blackfin/board.c   |   12 ++++++------
 lib_m68k/board.c       |   17 +++++++----------
 lib_microblaze/board.c |   13 +++++++------
 lib_mips/board.c       |   17 +++++++----------
 lib_nios/board.c       |   15 +++++++--------
 lib_nios2/board.c      |   13 ++++++-------
 lib_ppc/board.c        |   21 ++++++++++-----------
 lib_sh/board.c         |   14 +++++++-------
 lib_sparc/board.c      |   14 ++++++++------
 11 files changed, 79 insertions(+), 88 deletions(-)
lib_arm/board.c +7 -7
index 9bd5eca..a923ddc 100644
@@ -87,14 +87,13 @@ extern void rtl8019_get_enetaddr (uchar * addr);
 #endif
 
 static
-void mem_malloc_init (ulong dest_addr)
+void mem_malloc_init (ulong start, ulong size)
 {
-	mem_malloc_start = dest_addr;
-	mem_malloc_end = dest_addr + CONFIG_SYS_MALLOC_LEN;
-	mem_malloc_brk = mem_malloc_start;
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
 
-	memset ((void *) mem_malloc_start, 0,
-			mem_malloc_end - mem_malloc_start);
+	memset ((void *)mem_malloc_start, 0, size);
 }
 
 
@@ -304,7 +303,8 @@ void start_armboot (void)
 	}
 
 	/* armboot_start is defined in the board-specific linker script */
-	mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN);
+	mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,
+			CONFIG_SYS_MALLOC_LEN);
 
 #ifndef CONFIG_SYS_NO_FLASH
 	/* configure available FLASH banks */
lib_avr32/board.c +7 -10
index 03a520c..ca1bd6f 100644
@@ -50,20 +50,16 @@ int board_postclk_init(void) __attribute__((weak, alias("__do_nothing")));
 int board_early_init_r(void) __attribute__((weak, alias("__do_nothing")));
 
 /* The malloc area is right below the monitor image in RAM */
-static void mem_malloc_init(void)
+static void mem_malloc_init(ulong start, ulong size)
 {
-	unsigned long monitor_addr;
-
-	monitor_addr = CONFIG_SYS_MONITOR_BASE + gd->reloc_off;
-	mem_malloc_end = monitor_addr;
-	mem_malloc_start = mem_malloc_end - CONFIG_SYS_MALLOC_LEN;
-	mem_malloc_brk = mem_malloc_start;
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
 
 	printf("malloc: Using memory from 0x%08lx to 0x%08lx\n",
 	       mem_malloc_start, mem_malloc_end);
 
-	memset ((void *)mem_malloc_start, 0,
-		mem_malloc_end - mem_malloc_start);
+	memset((void *)mem_malloc_start, 0, size);
 }
 
 #ifdef CONFIG_SYS_DMA_ALLOC_LEN
@@ -312,7 +308,8 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
 #endif
 
 	timer_init();
-	mem_malloc_init();
+	mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
+			CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN);
 	malloc_bin_reloc();
 	dma_alloc_init();
 
lib_blackfin/board.c +6 -6
index b293c1b..80f70ca 100644
@@ -44,13 +44,13 @@ static inline void serial_early_puts(const char *s)
 #endif
 }
 
-static void mem_malloc_init(void)
+static void mem_malloc_init(ulong start, ulong size)
 {
-	mem_malloc_start = (ulong)CONFIG_SYS_MALLOC_BASE;
-	mem_malloc_end = (ulong)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
-	mem_malloc_brk = mem_malloc_start;
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
 
-	memset((void*)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
+	memset((void*)mem_malloc_start, 0, size);
 }
 
 static int display_banner(void)
@@ -311,7 +311,7 @@ void board_init_r(gd_t * id, ulong dest_addr)
 #endif
 
 	/* initialize malloc() area */
-	mem_malloc_init();
+	mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
 	malloc_bin_reloc();
 
 #if	!defined(CONFIG_SYS_NO_FLASH)
lib_m68k/board.c +7 -10
index 4392bcc..cbc6b50 100644
@@ -109,17 +109,13 @@ ulong monitor_flash_len;
 /*
  * The Malloc area is immediately below the monitor copy in DRAM
  */
-static void mem_malloc_init (void)
+static void mem_malloc_init(ulong start, ulong size)
 {
-	ulong dest_addr = CONFIG_SYS_MONITOR_BASE + gd->reloc_off;
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
 
-	mem_malloc_end = dest_addr;
-	mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
-	mem_malloc_brk = mem_malloc_start;
-
-	memset ((void *) mem_malloc_start,
-		0,
-		mem_malloc_end - mem_malloc_start);
+	memset ((void *)mem_malloc_start, 0, size);
 }
 
 /*
@@ -499,7 +495,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	trap_init (CONFIG_SYS_SDRAM_BASE);
 
 	/* initialize malloc() area */
-	mem_malloc_init ();
+	mem_malloc_init (CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
+			TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
 	malloc_bin_reloc ();
 
 #if !defined(CONFIG_SYS_NO_FLASH)
lib_microblaze/board.c +7 -6
index fc25a75..a5d924a 100644
@@ -51,12 +51,13 @@ extern int getenv_IPaddr (char *);
  * aka CONFIG_SYS_MONITOR_BASE - Note there is no need for reloc_off
  * as our monitory code is run from SDRAM
  */
-static void mem_malloc_init (void)
+static void mem_malloc_init(ulong start, ulong size)
 {
-	mem_malloc_end = (CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN);
-	mem_malloc_start = CONFIG_SYS_MALLOC_BASE;
-	mem_malloc_brk = mem_malloc_start;
-	memset ((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
+
+	memset ((void *)mem_malloc_start, 0, size);
 }
 
 /*
@@ -104,7 +105,7 @@ void board_init (void)
 	gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
 
 	/* Initialise malloc() area */
-	mem_malloc_init ();
+	mem_malloc_init (CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
 
 	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
 		WATCHDOG_RESET ();
lib_mips/board.c +7 -10
index 68a3697..b233a6c 100644
@@ -77,17 +77,13 @@ int board_early_init_f(void) __attribute__((weak, alias("__board_early_init_f"))
 /*
  * The Malloc area is immediately below the monitor copy in DRAM
  */
-static void mem_malloc_init (void)
+static void mem_malloc_init(ulong start, ulong size)
 {
-	ulong dest_addr = CONFIG_SYS_MONITOR_BASE + gd->reloc_off;
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
 
-	mem_malloc_end = dest_addr;
-	mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
-	mem_malloc_brk = mem_malloc_start;
-
-	memset ((void *) mem_malloc_start,
-		0,
-		mem_malloc_end - mem_malloc_start);
+	memset ((void *)mem_malloc_start, 0, size);
 }
 
 
@@ -352,7 +348,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	bd = gd->bd;
 
 	/* initialize malloc() area */
-	mem_malloc_init();
+	mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
+			TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
 	malloc_bin_reloc();
 
 #ifndef CONFIG_SYS_NO_FLASH
lib_nios/board.c +7 -8
index 30cdb47..745e0a4 100644
@@ -55,14 +55,13 @@ typedef int (init_fnc_t) (void);
 /*
  * The Malloc area is immediately below the monitor copy in RAM
  */
-static void mem_malloc_init (void)
+static void mem_malloc_init(ulong start, ulong size)
 {
-	mem_malloc_start = CONFIG_SYS_MALLOC_BASE;
-	mem_malloc_end = mem_malloc_start + CONFIG_SYS_MALLOC_LEN;
-	mem_malloc_brk = mem_malloc_start;
-	memset ((void *) mem_malloc_start,
-		0,
-		mem_malloc_end - mem_malloc_start);
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
+
+	memset ((void *)mem_malloc_start, 0, size);
 }
 
 
@@ -125,7 +124,7 @@ void board_init (void)
 	}
 
 	WATCHDOG_RESET ();
-	mem_malloc_init();
+	mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
 	malloc_bin_reloc();
 
 	WATCHDOG_RESET ();
lib_nios2/board.c +6 -7
index e5a8d54..2c470dd 100644
@@ -60,12 +60,11 @@ typedef int (init_fnc_t) (void);
  */
 static void mem_malloc_init (void)
 {
-	mem_malloc_start = CONFIG_SYS_MALLOC_BASE;
-	mem_malloc_end = mem_malloc_start + CONFIG_SYS_MALLOC_LEN;
-	mem_malloc_brk = mem_malloc_start;
-	memset ((void *) mem_malloc_start,
-		0,
-		mem_malloc_end - mem_malloc_start);
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start
+
+	memset((void *)mem_malloc_start, 0, size);
 }
 
 
@@ -131,7 +130,7 @@ void board_init (void)
 	}
 
 	WATCHDOG_RESET ();
-	mem_malloc_init();
+	mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
 	malloc_bin_reloc();
 
 	WATCHDOG_RESET ();
lib_ppc/board.c +10 -11
index 8a8cca1..a49b896 100644
@@ -144,17 +144,13 @@ ulong monitor_flash_len;
 /*
  * The Malloc area is immediately below the monitor copy in DRAM
  */
-static void mem_malloc_init (void)
+static void mem_malloc_init(ulong start, ulong size)
 {
-#if !defined(CONFIG_RELOC_FIXUP_WORKS)
-	mem_malloc_end = CONFIG_SYS_MONITOR_BASE + gd->reloc_off;
-#endif
-	mem_malloc_start = mem_malloc_end - TOTAL_MALLOC_LEN;
-	mem_malloc_brk = mem_malloc_start;
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
 
-	memset ((void *) mem_malloc_start,
-		0,
-		mem_malloc_end - mem_malloc_start);
+	memset ((void *)mem_malloc_start, 0, size);
 }
 
 /*
@@ -647,6 +643,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #ifndef CONFIG_ENV_IS_NOWHERE
 	extern char * env_name_spec;
 #endif
+	ulong malloc_start;
 
 #ifndef CONFIG_SYS_NO_FLASH
 	ulong flash_size;
@@ -659,9 +656,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
 #if defined(CONFIG_RELOC_FIXUP_WORKS)
 	gd->reloc_off = 0;
-	mem_malloc_end = dest_addr;
+	malloc_start = dest_addr - TOTAL_MALLOC_LEN;
 #else
 	gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
+	malloc_start = CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
+			TOTAL_MALLOC_LEN;
 #endif
 
 #ifdef CONFIG_SERIAL_MULTI
@@ -757,7 +756,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	asm ("sync ; isync");
 
 	/* initialize malloc() area */
-	mem_malloc_init ();
+	mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
 	malloc_bin_reloc ();
 
 #if !defined(CONFIG_SYS_NO_FLASH)
lib_sh/board.c +7 -7
index 001e89c..2691316 100644
@@ -38,14 +38,13 @@ const char version_string[] = U_BOOT_VERSION" ("U_BOOT_DATE" - "U_BOOT_TIME")";
 
 unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
 
-static void mem_malloc_init(void)
+static void mem_malloc_init(ulong start, ulong size)
 {
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
 
-	mem_malloc_start = (TEXT_BASE - CONFIG_SYS_GBL_DATA_SIZE - CONFIG_SYS_MALLOC_LEN);
-	mem_malloc_end = (mem_malloc_start + CONFIG_SYS_MALLOC_LEN - 16);
-	mem_malloc_brk = mem_malloc_start;
-	memset((void *) mem_malloc_start, 0,
-		(mem_malloc_end - mem_malloc_start));
+	memset((void *)mem_malloc_start, 0, size);
 }
 
 static int sh_flash_init(void)
@@ -96,7 +95,8 @@ static int sh_pci_init(void)
 
 static int sh_mem_env_init(void)
 {
-	mem_malloc_init();
+	mem_malloc_init(TEXT_BASE - CONFIG_SYS_GBL_DATA_SIZE -
+			CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
 	malloc_bin_reloc();
 	env_relocate();
 	jumptable_init();
lib_sparc/board.c +8 -6
index 37b7c0a..e69431f 100644
@@ -82,12 +82,13 @@ ulong monitor_flash_len;
 /*
  * The Malloc area is immediately below the monitor copy in RAM
  */
-static void mem_malloc_init(void)
+static void mem_malloc_init(ulong start, ulong size)
 {
-	mem_malloc_start = CONFIG_SYS_MALLOC_BASE;
-	mem_malloc_end = CONFIG_SYS_MALLOC_END;
-	mem_malloc_brk = mem_malloc_start;
-	memset((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start
+
+	memset((void *)mem_malloc_start, 0, size);
 }
 
 /***********************************************************************/
@@ -313,7 +314,8 @@ void board_init_f(ulong bootflag)
 	interrupt_init();
 
 	/* initialize malloc() area */
-	mem_malloc_init();
+	mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
+			CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
 	malloc_bin_reloc();
 
 #if !defined(CONFIG_SYS_NO_FLASH)
Signature · 1 line
1.6.2.1
#4 lore raw

PATCH 2/3 Standardize mem_malloc_init() implementation

Dear Peter Tyser,

Quoted 7 lines · In message <[email protected]> you wrote:

This lays the groundwork to allow architectures to share a common mem_malloc_init().

Note that the x86 implementation was not modified as it did not fit the mold of all other architectures.

Quoted 13 lines
---
 lib_arm/board.c        |   14 +++++++-------
 lib_avr32/board.c      |   17 +++++++----------
 lib_blackfin/board.c   |   12 ++++++------
 lib_m68k/board.c       |   17 +++++++----------
 lib_microblaze/board.c |   13 +++++++------
 lib_mips/board.c       |   17 +++++++----------
 lib_nios/board.c       |   15 +++++++--------
 lib_nios2/board.c      |   13 ++++++-------
 lib_ppc/board.c        |   21 ++++++++++-----------
 lib_sh/board.c         |   14 +++++++-------
 lib_sparc/board.c      |   14 ++++++++------
 11 files changed, 79 insertions(+), 88 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If I ever needed a brain transplant, I'd choose a teenager's  because
I'd want a brain that had never been used.
#5 lore raw

PATCH 3/3 Consolidate arch-specific mem_malloc_init() implementations

In reply to Peter Tyser
---
 common/dlmalloc.c      |   15 +++++++++++++++
 include/malloc.h       |    2 ++
 lib_arm/board.c        |   10 ----------
 lib_avr32/board.c      |   15 ++-------------
 lib_blackfin/board.c   |    9 ---------
 lib_m68k/board.c       |   14 +-------------
 lib_microblaze/board.c |   20 +++++---------------
 lib_mips/board.c       |   14 +-------------
 lib_nios/board.c       |   14 ++------------
 lib_nios2/board.c      |   14 ++------------
 lib_ppc/board.c        |   14 +-------------
 lib_sh/board.c         |    9 ---------
 lib_sparc/board.c      |   21 +--------------------
 13 files changed, 32 insertions(+), 139 deletions(-)
common/dlmalloc.c +15 -0
index f3bced4..241db8c 100644
@@ -1520,6 +1520,21 @@ void *sbrk(ptrdiff_t increment)
 	return (void *)old;
 }
 
+#ifndef CONFIG_X86
+/*
+ * x86 boards use a slightly different init sequence thus they implement
+ * their own version of mem_malloc_init()
+ */
+void mem_malloc_init(ulong start, ulong size)
+{
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
+
+	memset((void *)mem_malloc_start, 0, size);
+}
+#endif
+
 /* field-extraction macros */
 
 #define first(b) ((b)->fd)
include/malloc.h +2 -0
index 0382169..3e145ad 100644
@@ -944,6 +944,8 @@ extern ulong mem_malloc_start;
 extern ulong mem_malloc_end;
 extern ulong mem_malloc_brk;
 
+void mem_malloc_init(ulong start, ulong size);
+
 #ifdef __cplusplus
 };  /* end of extern "C" */
 #endif
lib_arm/board.c +0 -10
index a923ddc..d38db7a 100644
@@ -86,16 +86,6 @@ extern void rtl8019_get_enetaddr (uchar * addr);
 #include <i2c.h>
 #endif
 
-static
-void mem_malloc_init (ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	memset ((void *)mem_malloc_start, 0, size);
-}
-
 
 /************************************************************************
  * Coloured LED functionality
lib_avr32/board.c +2 -13
index ca1bd6f..29999d8 100644
@@ -49,19 +49,6 @@ static int __do_nothing(void)
 int board_postclk_init(void) __attribute__((weak, alias("__do_nothing")));
 int board_early_init_r(void) __attribute__((weak, alias("__do_nothing")));
 
-/* The malloc area is right below the monitor image in RAM */
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	printf("malloc: Using memory from 0x%08lx to 0x%08lx\n",
-	       mem_malloc_start, mem_malloc_end);
-
-	memset((void *)mem_malloc_start, 0, size);
-}
-
 #ifdef CONFIG_SYS_DMA_ALLOC_LEN
 #include <asm/arch/cacheflush.h>
 #include <asm/io.h>
@@ -308,6 +295,8 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
 #endif
 
 	timer_init();
+
+	/* The malloc area is right below the monitor image in RAM */
 	mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
 			CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN);
 	malloc_bin_reloc();
lib_blackfin/board.c +0 -9
index 80f70ca..0ab10ed 100644
@@ -44,15 +44,6 @@ static inline void serial_early_puts(const char *s)
 #endif
 }
 
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	memset((void*)mem_malloc_start, 0, size);
-}
-
 static int display_banner(void)
 {
 	printf("\n\n%s\n\n", version_string);
lib_m68k/board.c +1 -13
index cbc6b50..3d88530 100644
@@ -107,18 +107,6 @@ ulong monitor_flash_len;
  */
 
 /*
- * The Malloc area is immediately below the monitor copy in DRAM
- */
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	memset ((void *)mem_malloc_start, 0, size);
-}
-
-/*
  * All attempts to come up with a "common" initialization sequence
  * that works for all boards and architectures failed: some of the
  * requirements are just _too_ different. To get rid of the resulting
@@ -494,7 +482,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	 */
 	trap_init (CONFIG_SYS_SDRAM_BASE);
 
-	/* initialize malloc() area */
+	/* The Malloc area is immediately below the monitor copy in DRAM */
 	mem_malloc_init (CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
 			TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
 	malloc_bin_reloc ();
lib_microblaze/board.c +5 -15
index a5d924a..200ea5d 100644
@@ -47,20 +47,6 @@ extern int getenv_IPaddr (char *);
 #endif
 
 /*
- * The Malloc area is immediately below the monitor copy in DRAM
- * aka CONFIG_SYS_MONITOR_BASE - Note there is no need for reloc_off
- * as our monitory code is run from SDRAM
- */
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	memset ((void *)mem_malloc_start, 0, size);
-}
-
-/*
  * All attempts to come up with a "common" initialization sequence
  * that works for all boards and architectures failed: some of the
  * requirements are just _too_ different. To get rid of the resulting
@@ -104,7 +90,11 @@ void board_init (void)
 	bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
 	gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
 
-	/* Initialise malloc() area */
+	/*
+	 * The Malloc area is immediately below the monitor copy in DRAM
+	 * aka CONFIG_SYS_MONITOR_BASE - Note there is no need for reloc_off
+	 * as our monitory code is run from SDRAM
+	 */
 	mem_malloc_init (CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
 
 	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
lib_mips/board.c +1 -13
index b233a6c..f62a46a 100644
@@ -74,18 +74,6 @@ int __board_early_init_f(void)
 }
 int board_early_init_f(void) __attribute__((weak, alias("__board_early_init_f")));
 
-/*
- * The Malloc area is immediately below the monitor copy in DRAM
- */
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	memset ((void *)mem_malloc_start, 0, size);
-}
-
 
 static int init_func_ram (void)
 {
@@ -347,7 +335,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
 	bd = gd->bd;
 
-	/* initialize malloc() area */
+	/* The Malloc area is immediately below the monitor copy in DRAM */
 	mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
 			TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
 	malloc_bin_reloc();
lib_nios/board.c +2 -12
index 745e0a4..72713a8 100644
@@ -52,18 +52,6 @@ DECLARE_GLOBAL_DATA_PTR;
 extern void malloc_bin_reloc (void);
 typedef int (init_fnc_t) (void);
 
-/*
- * The Malloc area is immediately below the monitor copy in RAM
- */
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	memset ((void *)mem_malloc_start, 0, size);
-}
-
 
 /************************************************************************
  * Initialization sequence						*
@@ -124,6 +112,8 @@ void board_init (void)
 	}
 
 	WATCHDOG_RESET ();
+
+	/* The Malloc area is immediately below the monitor copy in RAM */
 	mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
 	malloc_bin_reloc();
 
lib_nios2/board.c +2 -12
index 2c470dd..c6b36f4 100644
@@ -55,18 +55,6 @@ DECLARE_GLOBAL_DATA_PTR;
 extern void malloc_bin_reloc (void);
 typedef int (init_fnc_t) (void);
 
-/*
- * The Malloc area is immediately below the monitor copy in RAM
- */
-static void mem_malloc_init (void)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start
-
-	memset((void *)mem_malloc_start, 0, size);
-}
-
 
 /************************************************************************
  * Initialization sequence						*
@@ -130,6 +118,8 @@ void board_init (void)
 	}
 
 	WATCHDOG_RESET ();
+
+	/* The Malloc area is immediately below the monitor copy in RAM */
 	mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
 	malloc_bin_reloc();
 
lib_ppc/board.c +1 -13
index a49b896..5c099aa 100644
@@ -142,18 +142,6 @@ ulong monitor_flash_len;
  */
 
 /*
- * The Malloc area is immediately below the monitor copy in DRAM
- */
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	memset ((void *)mem_malloc_start, 0, size);
-}
-
-/*
  * All attempts to come up with a "common" initialization sequence
  * that works for all boards and architectures failed: some of the
  * requirements are just _too_ different. To get rid of the resulting
@@ -654,6 +642,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
 	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
 
+	/* The Malloc area is immediately below the monitor copy in DRAM */
 #if defined(CONFIG_RELOC_FIXUP_WORKS)
 	gd->reloc_off = 0;
 	malloc_start = dest_addr - TOTAL_MALLOC_LEN;
@@ -755,7 +744,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 
 	asm ("sync ; isync");
 
-	/* initialize malloc() area */
 	mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
 	malloc_bin_reloc ();
 
lib_sh/board.c +0 -9
index 2691316..5d61f0d 100644
@@ -38,15 +38,6 @@ const char version_string[] = U_BOOT_VERSION" ("U_BOOT_DATE" - "U_BOOT_TIME")";
 
 unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
 
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start;
-
-	memset((void *)mem_malloc_start, 0, size);
-}
-
 static int sh_flash_init(void)
 {
 	DECLARE_GLOBAL_DATA_PTR;
lib_sparc/board.c +1 -20
index e69431f..6aadb56 100644
@@ -75,25 +75,6 @@ static char *failed = "*** failed ***\n";
 ulong monitor_flash_len;
 
 /************************************************************************
- * Utilities								*
- ************************************************************************
- */
-
-/*
- * The Malloc area is immediately below the monitor copy in RAM
- */
-static void mem_malloc_init(ulong start, ulong size)
-{
-	mem_malloc_start = start;
-	mem_malloc_end = start + size;
-	mem_malloc_brk = start
-
-	memset((void *)mem_malloc_start, 0, size);
-}
-
-/***********************************************************************/
-
-/************************************************************************
  * Init Utilities							*
  ************************************************************************
  * Some of this code should be moved into the core functions,
@@ -313,7 +294,7 @@ void board_init_f(ulong bootflag)
 	 */
 	interrupt_init();
 
-	/* initialize malloc() area */
+	/* The Malloc area is immediately below the monitor copy in RAM */
 	mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
 			CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
 	malloc_bin_reloc();
Signature · 1 line
1.6.2.1
#6 lore raw

PATCH 3/3 Consolidate arch-specific mem_malloc_init() implementations

Quoted 22 lines · Peter Tyser
---
 common/dlmalloc.c      |   15 +++++++++++++++
 include/malloc.h       |    2 ++
 lib_arm/board.c        |   10 ----------
 lib_avr32/board.c      |   15 ++-------------
 lib_blackfin/board.c   |    9 ---------
 lib_m68k/board.c       |   14 +-------------
 lib_microblaze/board.c |   20 +++++---------------
 lib_mips/board.c       |   14 +-------------
 lib_nios/board.c       |   14 ++------------
 lib_nios2/board.c      |   14 ++------------
 lib_ppc/board.c        |   14 +-------------
 lib_sh/board.c         |    9 ---------
 lib_sparc/board.c      |   21 +--------------------
 13 files changed, 32 insertions(+), 139 deletions(-)
common/dlmalloc.c +0 -0
index f3bced4..241db8c 100644

common/dlmalloc.c void *sbrk(ptrdiff_t increment) · line 1523

Quoted 4 lines
common/dlmalloc.c +1 -0
@@ -1520,6 +1520,21 @@ void *sbrk(ptrdiff_t increment)
 	return (void *)old;
 }
 
+#ifndef CONFIG_X86

could we have a generic name (not arch)
CONFIG_GENERIC_MALLOC_INIT

and then define it in the configs/arch.h

Quoted 22 lines
common/dlmalloc.c +14 -0
+/*
+ * x86 boards use a slightly different init sequence thus they implement
+ * their own version of mem_malloc_init()
+ */
+void mem_malloc_init(ulong start, ulong size)
+{
+	mem_malloc_start = start;
+	mem_malloc_end = start + size;
+	mem_malloc_brk = start;
+
+	memset((void *)mem_malloc_start, 0, size);
+}
+#endif
+
 /* field-extraction macros */
 
 #define first(b) ((b)->fd)
include/malloc.h +0 -0
index 0382169..3e145ad 100644

include/malloc.h extern ulong mem_malloc_start; · line 946

Quoted 3 lines
include/malloc.h +0 -0
@@ -944,6 +944,8 @@ extern ulong mem_malloc_start;
 extern ulong mem_malloc_end;
 extern ulong mem_malloc_brk;
 

Best Regards,
J.

#7 lore raw

PATCH 3/3 Consolidate arch-specific mem_malloc_init() implementations

Dear Jean-Christophe PLAGNIOL-VILLARD,

Quoted 24 lines · In message <[email protected]> you wrote:
Quoted 24 lines
 common/dlmalloc.c      |   15 +++++++++++++++
 include/malloc.h       |    2 ++
 lib_arm/board.c        |   10 ----------
 lib_avr32/board.c      |   15 ++-------------
 lib_blackfin/board.c   |    9 ---------
 lib_m68k/board.c       |   14 +-------------
 lib_microblaze/board.c |   20 +++++---------------
 lib_mips/board.c       |   14 +-------------
 lib_nios/board.c       |   14 ++------------
 lib_nios2/board.c      |   14 ++------------
 lib_ppc/board.c        |   14 +-------------
 lib_sh/board.c         |    9 ---------
 lib_sparc/board.c      |   21 +--------------------
 13 files changed, 32 insertions(+), 139 deletions(-)
common/dlmalloc.c +0 -0
index f3bced4..241db8c 100644
@@ -1520,6 +1520,21 @@ void *sbrk(ptrdiff_t increment)
 	return (void *)old;
 }
 
Quoted 3 lines

common/dlmalloc.c void *sbrk(ptrdiff_t increment) · line 1523

Quoted 1 line
common/dlmalloc.c +1 -0
+#ifndef CONFIG_X86

could we have a generic name (not arch)
CONFIG_GENERIC_MALLOC_INIT

That would mean you have to touch N board configurations. To me it sounds as if this was not per-board choice, but an architecture- specific decision. And a CONFIG_* name seems wrong (it should be CONFIG_SYS_* at least).

Quoted 1 line

and then define it in the configs/arch.h

What is configs/arch.h? There is no such file, and the name does not make sense to me.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Star Trek Lives!
#8 lore raw

PATCH 3/3 Consolidate arch-specific mem_malloc_init() implementations

Quoted 27 lines · Wolfgang Denk

Dear Jean-Christophe PLAGNIOL-VILLARD,

Quoted 24 lines · In message <[email protected]> you wrote:
Quoted 24 lines
 common/dlmalloc.c      |   15 +++++++++++++++
 include/malloc.h       |    2 ++
 lib_arm/board.c        |   10 ----------
 lib_avr32/board.c      |   15 ++-------------
 lib_blackfin/board.c   |    9 ---------
 lib_m68k/board.c       |   14 +-------------
 lib_microblaze/board.c |   20 +++++---------------
 lib_mips/board.c       |   14 +-------------
 lib_nios/board.c       |   14 ++------------
 lib_nios2/board.c      |   14 ++------------
 lib_ppc/board.c        |   14 +-------------
 lib_sh/board.c         |    9 ---------
 lib_sparc/board.c      |   21 +--------------------
 13 files changed, 32 insertions(+), 139 deletions(-)
common/dlmalloc.c +0 -0
index f3bced4..241db8c 100644
@@ -1520,6 +1520,21 @@ void *sbrk(ptrdiff_t increment)
 	return (void *)old;
 }
 
Quoted 8 lines
Quoted 3 lines

common/dlmalloc.c void *sbrk(ptrdiff_t increment) · line 1523

Quoted 1 line
common/dlmalloc.c +1 -0
+#ifndef CONFIG_X86

could we have a generic name (not arch)
CONFIG_GENERIC_MALLOC_INIT

That would mean you have to touch N board configurations. To me it sounds as if this was not per-board choice, but an architecture- specific decision. And a CONFIG_* name seems wrong (it should be CONFIG_SYS_* at least).

no the arch config file

Quoted 5 lines
Quoted 2 lines

and then define it in the configs/arch.h

What is configs/arch.h? There is no such file, and the name does not make sense to me.

as introduce by Kumar

#include <asm/config.h>

Best Regards,
J.

#9 lore raw

PATCH 3/3 Consolidate arch-specific mem_malloc_init() implementations

Dear Jean-Christophe PLAGNIOL-VILLARD,

Quoted 6 lines · In message <[email protected]> you wrote:
Quoted 5 lines

That would mean you have to touch N board configurations. To me it sounds as if this was not per-board choice, but an architecture- specific decision. And a CONFIG_* name seems wrong (it should be CONFIG_SYS_* at least).

no the arch config file

Yiour terminology is confusing. I guess what you write is not what you mean. The closes thing to "arch config file" would be cpu/*/config.mk; but I don;t think you mean that?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

and then define it in the configs/arch.h

What is configs/arch.h? There is no such file, and the name does not make sense to me.

as introduce by Kumar

#include <asm/config.h>

Ah. well, configs/arch.h != asm/config.h !!

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It would be illogical to assume that all conditions remain stable
	-- Spock, "The Enterprise" Incident", stardate 5027.3
#10 lore raw

PATCH 3/3 Consolidate arch-specific mem_malloc_init() implementations

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 26 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 25 lines · Peter Tyser
---
 common/dlmalloc.c      |   15 +++++++++++++++
 include/malloc.h       |    2 ++
 lib_arm/board.c        |   10 ----------
 lib_avr32/board.c      |   15 ++-------------
 lib_blackfin/board.c   |    9 ---------
 lib_m68k/board.c       |   14 +-------------
 lib_microblaze/board.c |   20 +++++---------------
 lib_mips/board.c       |   14 +-------------
 lib_nios/board.c       |   14 ++------------
 lib_nios2/board.c      |   14 ++------------
 lib_ppc/board.c        |   14 +-------------
 lib_sh/board.c         |    9 ---------
 lib_sparc/board.c      |   21 +--------------------
 13 files changed, 32 insertions(+), 139 deletions(-)
common/dlmalloc.c +0 -0
index f3bced4..241db8c 100644
@@ -1520,6 +1520,21 @@ void *sbrk(ptrdiff_t increment)
 	return (void *)old;
 }
 
Quoted 5 lines

common/dlmalloc.c void *sbrk(ptrdiff_t increment) · line 1523

Quoted 1 line
common/dlmalloc.c +1 -0
+#ifndef CONFIG_X86

could we have a generic name (not arch)
CONFIG_GENERIC_MALLOC_INIT

and then define it in the configs/arch.h

I thought the cleanest fix would be to update the x86 call to mem_malloc_init() to match all the other architectures', but didn't want to delve into the x86 arch init code.

I think adding a new CONFIG_* option to handle 1 non-conforming architecture is dirtier than syncing up the x86 init code in any case.

Best,
Peter

#11 lore raw

PATCH 3/3 Consolidate arch-specific mem_malloc_init() implementations

Quoted 4 lines · Peter Tyser
Quoted 3 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 2 lines · Peter Tyser

---

[snip]

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

+#ifndef CONFIG_X86

could we have a generic name (not arch)
CONFIG_GENERIC_MALLOC_INIT

Quoted 9 lines
Quoted 1 line

and then define it in the configs/arch.h

I thought the cleanest fix would be to update the x86 call to mem_malloc_init() to match all the other architectures', but didn't want to delve into the x86 arch init code.

I think adding a new CONFIG_* option to handle 1 non-conforming architecture is dirtier than syncing up the x86 init code in any case.

I am currently undertaking a fairly significant tidy up of some x86 loose ends. One that I noticed (and have not touched just yet) is how the x86 allocates the malloc pool. After these (Peter's) patches get applied, I will revisit the x86 malloc and bring it into line with the other arches

Regards,

G

Quoted 7 lines

Best,
Peter
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#12 lore raw

PATCH 3/3 Consolidate arch-specific mem_malloc_init() implementations

In reply to Peter Tyser

Dear Peter Tyser,

Quoted 16 lines · In message <[email protected]> you wrote:
---
 common/dlmalloc.c      |   15 +++++++++++++++
 include/malloc.h       |    2 ++
 lib_arm/board.c        |   10 ----------
 lib_avr32/board.c      |   15 ++-------------
 lib_blackfin/board.c   |    9 ---------
 lib_m68k/board.c       |   14 +-------------
 lib_microblaze/board.c |   20 +++++---------------
 lib_mips/board.c       |   14 +-------------
 lib_nios/board.c       |   14 ++------------
 lib_nios2/board.c      |   14 ++------------
 lib_ppc/board.c        |   14 +-------------
 lib_sh/board.c         |    9 ---------
 lib_sparc/board.c      |   21 +--------------------
 13 files changed, 32 insertions(+), 139 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 9 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Q:  How do you tell if you're making  love  to  a  nurse,  a  school-
    teacher, or an airline stewardess?
A:  A nurse says: "This won't hurt  a  bit."  A  schoolteacher  says:
    "We're  going to have to do this over and over again until we get
    it right." An airline stewardess says: "Just hold this over  your
    mouth and nose, and breath normally."