summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c90a4dd)
raw | patch | inline | side by side (parent: c90a4dd)
author | Matthias Weisser <weisserm@arcor.de> | |
Sat, 5 Nov 2011 10:40:34 +0000 (11:40 +0100) | ||
committer | Mike Frysinger <vapier@gentoo.org> | |
Sat, 10 Dec 2011 22:54:04 +0000 (17:54 -0500) |
Using mmap to allocate memory from the OS for RAM simulation we can use
u-boot own malloc implementation.
Tested-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
u-boot own malloc implementation.
Tested-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
arch/sandbox/cpu/os.c | patch | blob | history | |
arch/sandbox/lib/board.c | patch | blob | history | |
common/Makefile | patch | blob | history | |
include/os.h | patch | blob | history |
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index f80faac1f5ff5d911e9b76f92a803b542aeb04cf..b7c3bf5f80adbb68c63651653328d8edb0786c98 100644 (file)
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/mman.h>
#include <os.h>
atexit(os_fd_restore);
}
+
+void *os_malloc(size_t length)
+{
+ return mmap(NULL, length, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+}
index ae5a5176056cc7322d051edc94c117b03e05a02c..b7997e9a73ee63cc92d825fe0c200a4d3bf47fcf 100644 (file)
--- a/arch/sandbox/lib/board.c
+++ b/arch/sandbox/lib/board.c
#include <version.h>
#include <serial.h>
+#include <os.h>
+
DECLARE_GLOBAL_DATA_PTR;
+static gd_t gd_mem;
+
/************************************************************************
* Init Utilities *
************************************************************************
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));
}
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);
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 1be7236035c49eb30eab81549913c1436dbdc8e0..2d9ae8c5c92319f666edd859b28903b179e54eec 100644 (file)
--- a/common/Makefile
+++ b/common/Makefile
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 d5df22f77c83c35b8197ec223049afb526f50568..fd4120c359346769a109fc0a9395b745a660cf1d 100644 (file)
--- a/include/os.h
+++ b/include/os.h
* 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);