diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-01-26 01:09:37 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-02-04 15:52:41 +0100 |
commit | 65f7a718e6bb943e66d4b6ccab49c3356a3ea2d0 (patch) | |
tree | 131c707ed4ef6f283882b12a4c5e1133d31265f7 /arch/arm/cpu | |
parent | b7bcba8b65e36eb2f3a29a2f540e1ac30fbeff3d (diff) | |
download | barebox-65f7a718e6bb943e66d4b6ccab49c3356a3ea2d0.tar.gz barebox-65f7a718e6bb943e66d4b6ccab49c3356a3ea2d0.tar.xz |
ARM: Automatically determine malloc size
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/cpu')
-rw-r--r-- | arch/arm/cpu/start.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c index d90b244a8a..cd34d9c66d 100644 --- a/arch/arm/cpu/start.c +++ b/arch/arm/cpu/start.c @@ -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(); } |