From patchwork Tue Nov 1 14:07:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Weisser X-Patchwork-Id: 123074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 34302B6F86 for ; Wed, 2 Nov 2011 01:07:51 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D304E28EAB; Tue, 1 Nov 2011 15:07:49 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5ecpzkOBE0of; Tue, 1 Nov 2011 15:07:49 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2527028EB2; Tue, 1 Nov 2011 15:07:48 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2BE9728EB2 for ; Tue, 1 Nov 2011 15:07:44 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wJ7FNCL4w3k3 for ; Tue, 1 Nov 2011 15:07:42 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-in-14.arcor-online.net (mail-in-14.arcor-online.net [151.189.21.54]) by theia.denx.de (Postfix) with ESMTPS id 5DF4A28EAB for ; Tue, 1 Nov 2011 15:07:40 +0100 (CET) Received: from mail-in-16-z2.arcor-online.net (mail-in-16-z2.arcor-online.net [151.189.8.33]) by mx.arcor.de (Postfix) with ESMTP id 66D659C041; Tue, 1 Nov 2011 15:07:40 +0100 (CET) Received: from mail-in-12.arcor-online.net (mail-in-12.arcor-online.net [151.189.21.52]) by mail-in-16-z2.arcor-online.net (Postfix) with ESMTP id 58A103FE10D; Tue, 1 Nov 2011 15:07:40 +0100 (CET) Received: from mat-frame.fritz.box (HSI-KBW-078-042-175-106.hsi3.kabel-badenwuerttemberg.de [78.42.175.106]) (Authenticated sender: weisserm@arcor.de) by mail-in-12.arcor-online.net (Postfix) with ESMTPA id 2BA1826393; Tue, 1 Nov 2011 15:07:40 +0100 (CET) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-12.arcor-online.net 2BA1826393 From: Matthias Weisser To: u-boot@lists.denx.de Date: Tue, 1 Nov 2011 15:07:31 +0100 Message-Id: <1320156451-8961-1-git-send-email-weisserm@arcor.de> X-Mailer: git-send-email 1.7.4.1 Subject: [U-Boot] [PATCH] sandbox: Add improved RAM simulation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Using mmap we can simulate RAM at a specific address. This also eliminated the use of system malloc function. Signed-off-by: Matthias Weisser --- arch/sandbox/cpu/os.c | 9 +++++++++ arch/sandbox/lib/board.c | 19 +++++++++++-------- include/configs/sandbox.h | 1 + include/os.h | 13 +++++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 6c175d4..cd2fb05 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -53,3 +54,11 @@ void os_exit(int exit_code) { exit(exit_code); } + +void *os_mmap(void *addr, size_t length, int prot, int flags, int fd, + off_t offset) +{ + return mmap((void *)addr, 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 ae5a517..0912a8b 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 * ************************************************************************ @@ -112,7 +116,7 @@ typedef int (init_fnc_t) (void); void __dram_init_banksize(void) { - gd->bd->bi_dram[0].start = 0; + gd->bd->bi_dram[0].start = (ulong) gd->ram_buf; gd->bd->bi_dram[0].size = gd->ram_size; } @@ -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_mmap((void *)CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_SDRAM_SIZE, + 0, 0, -1, 0); 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(gd->ram_buf + gd->ram_size - TOTAL_MALLOC_LEN, + TOTAL_MALLOC_LEN); /* initialize environment */ env_relocate(); diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 0230256..ce4675d 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -60,6 +60,7 @@ #define CONFIG_PHYS_64BIT /* Size of our emulated memory */ +#define CONFIG_SYS_SDRAM_BASE 0x20000000 #define CONFIG_SYS_SDRAM_SIZE (128 << 20) #define CONFIG_BAUDRATE 115200 diff --git a/include/os.h b/include/os.h index 3ea6d2d..ed4cd4f 100644 --- a/include/os.h +++ b/include/os.h @@ -71,3 +71,16 @@ int os_close(int fd); * @param exit_code exit code for U-Boot */ void os_exit(int exit_code); + +/** + * Access to the OS mmap() system call. Currently all + * + * \param addr Prefered address of the mapping + * \param length Length in bytes + * \param prot Ignored. Always PROT_READ | PROT_WRITE + * \param flags Ignored. Always MAP_PRIVATE | MAP_ANONYMOUS + * \param fd Ignored. Always -1 + * \param offset Ignored. Always 0 + */ +void *os_mmap(void *addr, size_t length, int prot, int flags, int fd, + off_t offset);