9
0
Fork 0

ARM: Automatically determine malloc size

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2013-01-26 01:09:37 +01:00
parent b7bcba8b65
commit 65f7a718e6
3 changed files with 28 additions and 15 deletions

View File

@ -35,6 +35,7 @@ static noinline __noreturn void __start(uint32_t membase, uint32_t memsize,
uint32_t boarddata)
{
unsigned long endmem = membase + memsize;
unsigned long malloc_start, malloc_end;
setup_c();
@ -50,6 +51,33 @@ static noinline __noreturn void __start(uint32_t membase, uint32_t memsize,
mmu_early_enable(membase, memsize, endmem);
}
if ((unsigned long)_text > membase + memsize ||
(unsigned long)_text < membase)
/*
* barebox is either outside SDRAM or in another
* memory bank, so we can use the whole bank for
* malloc.
*/
malloc_end = endmem;
else
malloc_end = (unsigned long)_text;
/*
* Maximum malloc space is the Kconfig value if given
* or 64MB.
*/
if (MALLOC_SIZE > 0) {
malloc_start = malloc_end - MALLOC_SIZE;
if (malloc_start < membase)
malloc_start = membase;
} else {
malloc_start = malloc_end - (malloc_end - membase) / 2;
if (malloc_end - malloc_start > SZ_64M)
malloc_start = malloc_end - SZ_64M;
}
mem_malloc_init((void *)malloc_start, (void *)malloc_end - 1);
start_barebox();
}

View File

@ -4,7 +4,6 @@ obj-$(CONFIG_CMD_BOOTZ) += bootz.o
obj-$(CONFIG_CMD_BOOTU) += bootu.o
obj-y += div0.o
obj-y += findbit.o
obj-y += arm.o
obj-y += io.o
obj-y += io-readsb.o
obj-y += io-readsw-armv4.o

View File

@ -1,14 +0,0 @@
#include <common.h>
#include <init.h>
#include <memory.h>
#include <asm/barebox-arm.h>
#include <asm-generic/memory_layout.h>
static int arm_mem_malloc_init(void)
{
mem_malloc_init((void *)MALLOC_BASE,
(void *)(MALLOC_BASE + MALLOC_SIZE - 1));
return 0;
}
core_initcall(arm_mem_malloc_init);