From: Matthias Weisser Date: Sat, 5 Nov 2011 10:40:34 +0000 (+0100) Subject: sandbox: Add improved RAM simulation X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=21899b10850b8ba155b16038fac5dd8d98214842;p=u-boot.git sandbox: Add improved RAM simulation Using mmap to allocate memory from the OS for RAM simulation we can use u-boot own malloc implementation. Tested-by: Simon Glass Signed-off-by: Matthias Weisser Signed-off-by: Mike Frysinger --- diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index f80faac1f5..b7c3bf5f80 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -87,3 +88,9 @@ void os_tty_raw(int fd) atexit(os_fd_restore); } + +void *os_malloc(size_t length) +{ + return mmap(NULL, length, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +} diff --git a/arch/sandbox/lib/board.c b/arch/sandbox/lib/board.c index ae5a517605..b7997e9a73 100644 --- a/arch/sandbox/lib/board.c +++ b/arch/sandbox/lib/board.c @@ -45,8 +45,12 @@ #include #include +#include + DECLARE_GLOBAL_DATA_PTR; +static gd_t gd_mem; + /************************************************************************ * Init Utilities * ************************************************************************ @@ -147,7 +151,7 @@ void board_init_f(ulong bootflag) uchar *mem; unsigned long addr_sp, addr, size; - gd = malloc(sizeof(gd_t)); + gd = &gd_mem; assert(gd); memset((void *)gd, 0, sizeof(gd_t)); @@ -158,7 +162,8 @@ void board_init_f(ulong bootflag) } size = CONFIG_SYS_SDRAM_SIZE; - mem = malloc(size); + mem = os_malloc(CONFIG_SYS_SDRAM_SIZE); + assert(mem); gd->ram_buf = mem; addr = (ulong)(mem + size); @@ -214,11 +219,9 @@ void board_init_r(gd_t *id, ulong dest_addr) post_output_backlog(); #endif -#if 0 /* Sandbox uses system malloc for now */ - /* The Malloc area is immediately below the monitor copy in DRAM */ - malloc_start = dest_addr - TOTAL_MALLOC_LEN; - mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN); -#endif + /* The Malloc area is at the top of simulated DRAM */ + mem_malloc_init((ulong)gd->ram_buf + gd->ram_size - TOTAL_MALLOC_LEN, + TOTAL_MALLOC_LEN); /* initialize environment */ env_relocate(); diff --git a/common/Makefile b/common/Makefile index 1be7236035..2d9ae8c5c9 100644 --- a/common/Makefile +++ b/common/Makefile @@ -29,9 +29,6 @@ LIB = $(obj)libcommon.o ifndef CONFIG_SPL_BUILD COBJS-y += main.o COBJS-y += command.o -ifndef CONFIG_SANDBOX -COBJS-y += dlmalloc.o -endif COBJS-y += exports.o COBJS-$(CONFIG_SYS_HUSH_PARSER) += hush.o COBJS-y += image.o diff --git a/include/os.h b/include/os.h index d5df22f77c..fd4120c359 100644 --- a/include/os.h +++ b/include/os.h @@ -76,3 +76,11 @@ void os_exit(int exit_code); * Put tty into raw mode to mimic serial console better */ void os_tty_raw(int fd); + +/** + * Acquires some memory from the underlying os. + * + * \param length Number of bytes to be allocated + * \return Pointer to length bytes or NULL on error + */ +void *os_malloc(size_t length);