Patchwork [U-Boot,v3,04/22] sandbox: Add un/map_sysmen() to deal with sandbox's ram_buf

mail settings
Submitter Simon Glass
Date Feb. 25, 2013, 3:33 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/222822/
State Accepted, archived
Delegated to: Tom Rini
Headers show


Simon Glass - Feb. 25, 2013, 3:33 a.m.
Sandbox doesn't actually provide U-Boot access to the machine's physical
memory. Instead it provides a RAM buffer of configurable size, and all
memory accesses are within that buffer. Sandbox memory starts at 0 and
is CONFIG_DRAM_SIZE bytes in size. Allowing access outside this buffer
might produce unpredictable results in the event of an error, and would
expose the host machine's memory architecture to the sandbox U-Boot.

Most U-Boot functions assume that they can just access memory at given
address. For sandbox this is not true.

Add a map_sysmem() call which converts a U-Boot address to a system
address. In most cases this is a NOP, but for sandbox it returns a
pointer to that memory inside the RAM buffer.

To get a U-Boot feature to work correctly within sandbox, you should call
map_sysmem() to get a pointer to the address, and then use that address for
any U-Boot memory accesses.

Signed-off-by: Simon Glass <>
Changes in v3: None
Changes in v2: None

 README                        |  9 +++++++++
 arch/sandbox/        |  1 +
 arch/sandbox/include/asm/io.h | 10 ++++++++++
 include/common.h              | 12 ++++++++++++
 4 files changed, 32 insertions(+)


diff --git a/README b/README
index d8cb394..affa096 100644
--- a/README
+++ b/README
@@ -3810,6 +3810,15 @@  Low Level (hardware related) configuration options:
 		that is executed before the actual U-Boot. E.g. when
 		compiling a NAND SPL.
+		Generally U-Boot (and in particular the md command) uses
+		effective address. It is therefore not necessary to regard
+		U-Boot address as virtual addresses that need to be translated
+		to physical addresses. However, sandbox requires this, since
+		it maintains its own little RAM buffer which contains all
+		addressable memory. This option causes some memory accesses
+		to be mapped through map_sysmem() / unmap_sysmem().
 		If these options are used a optimized version of memcpy/memset will
diff --git a/arch/sandbox/ b/arch/sandbox/
index 02ce4a4..4fd0d4e 100644
--- a/arch/sandbox/
+++ b/arch/sandbox/
@@ -18,4 +18,5 @@ 
 # MA 02111-1307 USA
diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index 0392d21..d8c0236 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -39,3 +39,13 @@  static inline void unmap_physmem(void *vaddr, unsigned long flags)
+/* For sandbox, we want addresses to point into our RAM buffer */
+static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
+	return map_physmem(paddr, len, MAP_WRBACK);
+static inline void unmap_sysmem(const void *vaddr)
diff --git a/include/common.h b/include/common.h
index 170f439..1d0728f 100644
--- a/include/common.h
+++ b/include/common.h
@@ -870,6 +870,18 @@  int cpu_disable(int nr);
 int cpu_release(int nr, int argc, char * const argv[]);
+/* Define a null map_sysmem() if the architecture doesn't use it */
+static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
+	return (void *)(uintptr_t)paddr;
+static inline void unmap_sysmem(const void *vaddr)
+# endif
 #endif /* __ASSEMBLY__ */
 #ifdef CONFIG_PPC