Standardize mem_malloc_init() implementation

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.

Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
This commit is contained in:
Peter Tyser 2009-08-21 23:05:20 -05:00 committed by Wolfgang Denk
parent 5e93bd1c9a
commit a483a167bc
11 changed files with 79 additions and 88 deletions

View File

@ -83,14 +83,13 @@ extern void rtl8019_get_enetaddr (uchar * addr);
#endif #endif
static static
void mem_malloc_init (ulong dest_addr) void mem_malloc_init (ulong start, ulong size)
{ {
mem_malloc_start = dest_addr; mem_malloc_start = start;
mem_malloc_end = dest_addr + CONFIG_SYS_MALLOC_LEN; mem_malloc_end = start + size;
mem_malloc_brk = mem_malloc_start; mem_malloc_brk = start;
memset ((void *) mem_malloc_start, 0, memset ((void *)mem_malloc_start, 0, size);
mem_malloc_end - mem_malloc_start);
} }
@ -300,7 +299,8 @@ void start_armboot (void)
} }
/* armboot_start is defined in the board-specific linker script */ /* 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 #ifndef CONFIG_SYS_NO_FLASH
/* configure available FLASH banks */ /* configure available FLASH banks */

View File

@ -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"))); int board_early_init_r(void) __attribute__((weak, alias("__do_nothing")));
/* The malloc area is right below the monitor image in RAM */ /* 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; mem_malloc_start = start;
mem_malloc_end = start + size;
monitor_addr = CONFIG_SYS_MONITOR_BASE + gd->reloc_off; mem_malloc_brk = start;
mem_malloc_end = monitor_addr;
mem_malloc_start = mem_malloc_end - CONFIG_SYS_MALLOC_LEN;
mem_malloc_brk = mem_malloc_start;
printf("malloc: Using memory from 0x%08lx to 0x%08lx\n", printf("malloc: Using memory from 0x%08lx to 0x%08lx\n",
mem_malloc_start, mem_malloc_end); mem_malloc_start, mem_malloc_end);
memset ((void *)mem_malloc_start, 0, memset((void *)mem_malloc_start, 0, size);
mem_malloc_end - mem_malloc_start);
} }
#ifdef CONFIG_SYS_DMA_ALLOC_LEN #ifdef CONFIG_SYS_DMA_ALLOC_LEN
@ -312,7 +308,8 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)
#endif #endif
timer_init(); 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(); malloc_bin_reloc();
dma_alloc_init(); dma_alloc_init();

View File

@ -44,13 +44,13 @@ static inline void serial_early_puts(const char *s)
#endif #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_start = start;
mem_malloc_end = (ulong)(CONFIG_SYS_MALLOC_BASE + CONFIG_SYS_MALLOC_LEN); mem_malloc_end = start + size;
mem_malloc_brk = mem_malloc_start; 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) static int display_banner(void)
@ -311,7 +311,7 @@ void board_init_r(gd_t * id, ulong dest_addr)
#endif #endif
/* initialize malloc() area */ /* initialize malloc() area */
mem_malloc_init(); mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
malloc_bin_reloc(); malloc_bin_reloc();
#if !defined(CONFIG_SYS_NO_FLASH) #if !defined(CONFIG_SYS_NO_FLASH)

View File

@ -109,17 +109,13 @@ ulong monitor_flash_len;
/* /*
* The Malloc area is immediately below the monitor copy in DRAM * 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; memset ((void *)mem_malloc_start, 0, size);
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);
} }
/* /*
@ -499,7 +495,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
trap_init (CONFIG_SYS_SDRAM_BASE); trap_init (CONFIG_SYS_SDRAM_BASE);
/* initialize malloc() area */ /* 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 (); malloc_bin_reloc ();
#if !defined(CONFIG_SYS_NO_FLASH) #if !defined(CONFIG_SYS_NO_FLASH)

View File

@ -51,12 +51,13 @@ extern int getenv_IPaddr (char *);
* aka CONFIG_SYS_MONITOR_BASE - Note there is no need for reloc_off * aka CONFIG_SYS_MONITOR_BASE - Note there is no need for reloc_off
* as our monitory code is run from SDRAM * 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 = start;
mem_malloc_start = CONFIG_SYS_MALLOC_BASE; mem_malloc_end = start + size;
mem_malloc_brk = mem_malloc_start; mem_malloc_brk = start;
memset ((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_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 */ gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
/* Initialise malloc() area */ /* 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) { for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
WATCHDOG_RESET (); WATCHDOG_RESET ();

View File

@ -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 * 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; memset ((void *)mem_malloc_start, 0, size);
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);
} }
@ -352,7 +348,8 @@ void board_init_r (gd_t *id, ulong dest_addr)
bd = gd->bd; bd = gd->bd;
/* initialize malloc() area */ /* 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(); malloc_bin_reloc();
#ifndef CONFIG_SYS_NO_FLASH #ifndef CONFIG_SYS_NO_FLASH

View File

@ -55,14 +55,13 @@ typedef int (init_fnc_t) (void);
/* /*
* The Malloc area is immediately below the monitor copy in RAM * 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_start = start;
mem_malloc_end = mem_malloc_start + CONFIG_SYS_MALLOC_LEN; mem_malloc_end = start + size;
mem_malloc_brk = mem_malloc_start; mem_malloc_brk = start;
memset ((void *) mem_malloc_start,
0, memset ((void *)mem_malloc_start, 0, size);
mem_malloc_end - mem_malloc_start);
} }
@ -125,7 +124,7 @@ void board_init (void)
} }
WATCHDOG_RESET (); WATCHDOG_RESET ();
mem_malloc_init(); mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
malloc_bin_reloc(); malloc_bin_reloc();
WATCHDOG_RESET (); WATCHDOG_RESET ();

View File

@ -60,12 +60,11 @@ typedef int (init_fnc_t) (void);
*/ */
static void mem_malloc_init (void) static void mem_malloc_init (void)
{ {
mem_malloc_start = CONFIG_SYS_MALLOC_BASE; mem_malloc_start = start;
mem_malloc_end = mem_malloc_start + CONFIG_SYS_MALLOC_LEN; mem_malloc_end = start + size;
mem_malloc_brk = mem_malloc_start; mem_malloc_brk = start
memset ((void *) mem_malloc_start,
0, memset((void *)mem_malloc_start, 0, size);
mem_malloc_end - mem_malloc_start);
} }
@ -131,7 +130,7 @@ void board_init (void)
} }
WATCHDOG_RESET (); WATCHDOG_RESET ();
mem_malloc_init(); mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
malloc_bin_reloc(); malloc_bin_reloc();
WATCHDOG_RESET (); WATCHDOG_RESET ();

View File

@ -144,17 +144,13 @@ ulong monitor_flash_len;
/* /*
* The Malloc area is immediately below the monitor copy in DRAM * 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_start = start;
mem_malloc_end = CONFIG_SYS_MONITOR_BASE + gd->reloc_off; mem_malloc_end = start + size;
#endif mem_malloc_brk = start;
mem_malloc_start = mem_malloc_end - TOTAL_MALLOC_LEN;
mem_malloc_brk = mem_malloc_start;
memset ((void *) mem_malloc_start, memset ((void *)mem_malloc_start, 0, size);
0,
mem_malloc_end - mem_malloc_start);
} }
/* /*
@ -650,6 +646,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
#ifndef CONFIG_ENV_IS_NOWHERE #ifndef CONFIG_ENV_IS_NOWHERE
extern char * env_name_spec; extern char * env_name_spec;
#endif #endif
ulong malloc_start;
#ifndef CONFIG_SYS_NO_FLASH #ifndef CONFIG_SYS_NO_FLASH
ulong flash_size; ulong flash_size;
@ -662,9 +659,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
#if defined(CONFIG_RELOC_FIXUP_WORKS) #if defined(CONFIG_RELOC_FIXUP_WORKS)
gd->reloc_off = 0; gd->reloc_off = 0;
mem_malloc_end = dest_addr; malloc_start = dest_addr - TOTAL_MALLOC_LEN;
#else #else
gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE; gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
malloc_start = CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
TOTAL_MALLOC_LEN;
#endif #endif
#ifdef CONFIG_SERIAL_MULTI #ifdef CONFIG_SERIAL_MULTI
@ -760,7 +759,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
asm ("sync ; isync"); asm ("sync ; isync");
/* initialize malloc() area */ /* initialize malloc() area */
mem_malloc_init (); mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
malloc_bin_reloc (); malloc_bin_reloc ();
#if !defined(CONFIG_SYS_NO_FLASH) #if !defined(CONFIG_SYS_NO_FLASH)

View File

@ -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; 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); memset((void *)mem_malloc_start, 0, size);
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));
} }
static int sh_flash_init(void) static int sh_flash_init(void)
@ -96,7 +95,8 @@ static int sh_pci_init(void)
static int sh_mem_env_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(); malloc_bin_reloc();
env_relocate(); env_relocate();
jumptable_init(); jumptable_init();

View File

@ -82,12 +82,13 @@ ulong monitor_flash_len;
/* /*
* The Malloc area is immediately below the monitor copy in RAM * 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_start = start;
mem_malloc_end = CONFIG_SYS_MALLOC_END; mem_malloc_end = start + size;
mem_malloc_brk = mem_malloc_start; mem_malloc_brk = start
memset((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
memset((void *)mem_malloc_start, 0, size);
} }
/***********************************************************************/ /***********************************************************************/
@ -313,7 +314,8 @@ void board_init_f(ulong bootflag)
interrupt_init(); interrupt_init();
/* initialize malloc() area */ /* initialize malloc() area */
mem_malloc_init(); mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
malloc_bin_reloc(); malloc_bin_reloc();
#if !defined(CONFIG_SYS_NO_FLASH) #if !defined(CONFIG_SYS_NO_FLASH)