sandbox: Add un/map_sysmen() to deal with sandbox's ram_buf
authorSimon Glass <sjg@chromium.org>
Sun, 24 Feb 2013 17:33:14 +0000 (17:33 +0000)
committerChanho Park <chanho61.park@samsung.com>
Fri, 24 Jul 2015 07:29:47 +0000 (16:29 +0900)
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 <sjg@chromium.org>
README
arch/sandbox/config.mk
arch/sandbox/include/asm/io.h
include/common.h

diff --git a/README b/README
index 1adac287f18fc2789da61e7e0ca6ca174c210785..cb08485292c4e07135e42cd894c3ecfedee888bc 100644 (file)
--- a/README
+++ b/README
@@ -3529,6 +3529,15 @@ Low Level (hardware related) configuration options:
                that is executed before the actual U-Boot. E.g. when
                compiling a NAND SPL.
 
+- CONFIG_ARCH_MAP_SYSMEM
+               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().
+
 - CONFIG_USE_ARCH_MEMCPY
   CONFIG_USE_ARCH_MEMSET
                If these options are used a optimized version of memcpy/memset will
index 02ce4a44109b3d712f9b4ad4c29206ef662696d1..4fd0d4e58f9bbf1f2d88fc8178e9f74ec23d738a 100644 (file)
@@ -18,4 +18,5 @@
 # MA 02111-1307 USA
 
 PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ -U_FORTIFY_SOURCE
+PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM
 PLATFORM_LIBS += -lrt
index 0392d218ec2cd156a6a6b8418460e1f7b2876f19..d8c02364d9e811186eb0550fd39a0e3eb2e376c9 100644 (file)
@@ -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)
+{
+}
index 42d9efa3179c4ad4573740c9d3a861b4f88bb7ec..fc62d66b53e1ff01f17efd05ba483b5665309f77 100644 (file)
@@ -846,6 +846,18 @@ int cpu_disable(int nr);
 int cpu_release(int nr, int argc, char * const argv[]);
 #endif
 
+/* Define a null map_sysmem() if the architecture doesn't use it */
+# ifndef CONFIG_ARCH_MAP_SYSMEM
+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