[U-Boot] [RFC] sandbox: Enable 1:1 map

Alexander Graf agraf at suse.de
Thu Jun 14 23:13:16 UTC 2018


So far we've always had a split address space situation with
"U-Boot addresses" (a number space starting from 0) and "host
virtual addresses" (128MB mapped randomly in address space).

This meant that we had to make sure all code is properly aware that
addresses and pointers are not the same thing, so they must not cast
between the two.

However, most real boards do actually have a 1:1 map. So it's
much easier to just expose the same in sandbox.

So this patch maps sandbox RAM from 0x8000000-0x10000000. This
address range fits just fine on both 32bit and 64bit systems.

---

The patch is on top of my "efi-sandbox-v3" tree. But I'm sure
it easily applies on vanilla too.

I also don't know if this really is the best path forward, but
at least it's one that gets rid of the one awkward target that
does not have a 1:1 map ;)
---
 arch/sandbox/cpu/cpu.c             | 18 ++----------------
 arch/sandbox/cpu/state.c           |  4 ++--
 arch/sandbox/cpu/u-boot.lds        |  3 +++
 arch/sandbox/include/asm/io.h      | 17 +++++------------
 common/board_f.c                   |  4 +++-
 configs/sandbox64_defconfig        |  6 +++---
 configs/sandbox_defconfig          |  6 +++---
 configs/sandbox_flattree_defconfig |  4 ++--
 configs/sandbox_noblk_defconfig    |  4 ++--
 configs/sandbox_spl_defconfig      |  4 ++--
 include/configs/sandbox.h          | 22 +++++++++++-----------
 11 files changed, 38 insertions(+), 54 deletions(-)

diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index 23d8b70648..5f5d6c9158 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -58,16 +58,6 @@ int cleanup_before_linux_select(int flags)
 	return 0;
 }
 
-void *phys_to_virt(phys_addr_t paddr)
-{
-	return (void *)(gd->arch.ram_buf + paddr);
-}
-
-phys_addr_t virt_to_phys(void *vaddr)
-{
-	return (phys_addr_t)((uint8_t *)vaddr - gd->arch.ram_buf);
-}
-
 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 {
 #if defined(CONFIG_PCI) && !defined(CONFIG_SPL_BUILD)
@@ -103,11 +93,6 @@ void sandbox_set_enable_pci_map(int enable)
 	enable_pci_map = enable;
 }
 
-phys_addr_t map_to_sysmem(const void *ptr)
-{
-	return (u8 *)ptr - gd->arch.ram_buf;
-}
-
 void flush_dcache_range(unsigned long start, unsigned long stop)
 {
 }
@@ -187,7 +172,8 @@ void longjmp(jmp_buf jmp, int ret)
  */
 void efi_add_known_memory(void)
 {
-	u64 ram_start = (uintptr_t)map_sysmem(0, gd->ram_size);
+	u64 ram_start = (uintptr_t)map_sysmem(CONFIG_SYS_SDRAM_BASE,
+					      gd->ram_size);
 	u64 ram_size = gd->ram_size;
 	u64 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
 	u64 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT;
diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index cc50819ab9..75ad564274 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -12,6 +12,7 @@
 /* Main state record for the sandbox */
 static struct sandbox_state main_state;
 static struct sandbox_state *state;	/* Pointer to current state record */
+static __attribute__ ((section (".ram"))) u8 sandbox_ram[CONFIG_SYS_SDRAM_SIZE];
 
 static int state_ensure_space(int extra_size)
 {
@@ -366,8 +367,7 @@ int state_init(void)
 	state = &main_state;
 
 	state->ram_size = CONFIG_SYS_SDRAM_SIZE;
-	state->ram_buf = os_malloc(state->ram_size);
-	assert(state->ram_buf);
+	state->ram_buf = sandbox_ram;
 
 	state_reset_for_test(state);
 	/*
diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds
index 3a6cf55eb9..8d0dfadfe0 100644
--- a/arch/sandbox/cpu/u-boot.lds
+++ b/arch/sandbox/cpu/u-boot.lds
@@ -47,6 +47,9 @@ SECTIONS
 		*(.__efi_runtime_rel_stop)
 	}
 
+	.ram 0x8000000 : {
+		*(.ram)
+	}
 }
 
 INSERT BEFORE .data;
diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index 81b7750628..fe792200a7 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -6,12 +6,6 @@
 #ifndef __SANDBOX_ASM_IO_H
 #define __SANDBOX_ASM_IO_H
 
-void *phys_to_virt(phys_addr_t paddr);
-#define phys_to_virt phys_to_virt
-
-phys_addr_t virt_to_phys(void *vaddr);
-#define virt_to_phys virt_to_phys
-
 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags);
 #define map_physmem map_physmem
 
@@ -23,20 +17,19 @@ void unmap_physmem(const void *vaddr, unsigned long flags);
 
 #include <asm-generic/io.h>
 
-/* 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);
+	return (void *)(unsigned long)paddr;
 }
 
-/* Remove a previous mapping */
 static inline void unmap_sysmem(const void *vaddr)
 {
-	unmap_physmem(vaddr, MAP_WRBACK);
 }
 
-/* Map from a pointer to our RAM buffer */
-phys_addr_t map_to_sysmem(const void *ptr);
+static inline phys_addr_t map_to_sysmem(const void *ptr)
+{
+	return (phys_addr_t)(unsigned long)ptr;
+}
 
 /* Define nops for sandbox I/O access */
 #define readb(addr) ((void)addr, 0)
diff --git a/common/board_f.c b/common/board_f.c
index e943347ce3..b06f9d30ad 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -219,7 +219,9 @@ static int setup_mon_len(void)
 {
 #if defined(__ARM__) || defined(__MICROBLAZE__)
 	gd->mon_len = (ulong)&__bss_end - (ulong)_start;
-#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
+#elif defined(CONFIG_SANDBOX)
+	gd->mon_len = 0;
+#elif defined(CONFIG_EFI_APP)
 	gd->mon_len = (ulong)&_end - (ulong)_init;
 #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
 	gd->mon_len = CONFIG_SYS_MONITOR_LEN;
diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 20a2ab3ffb..5c47b651d4 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -1,4 +1,4 @@
-CONFIG_SYS_TEXT_BASE=0
+CONFIG_SYS_TEXT_BASE=0x8000000
 CONFIG_SYS_MALLOC_F_LEN=0x2000
 CONFIG_SANDBOX64=y
 CONFIG_DEFAULT_DEVICE_TREE="sandbox64"
@@ -11,13 +11,13 @@ CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
 CONFIG_BOOTSTAGE_STASH=y
-CONFIG_BOOTSTAGE_STASH_ADDR=0x0
+CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000
 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
 CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
 CONFIG_SILENT_CONSOLE=y
 CONFIG_PRE_CONSOLE_BUFFER=y
-CONFIG_PRE_CON_BUF_ADDR=0x100000
+CONFIG_PRE_CON_BUF_ADDR=0x8100000
 CONFIG_LOG_MAX_LEVEL=6
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_CMD_CPU=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 2fc84a16c9..84828c972c 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -1,4 +1,4 @@
-CONFIG_SYS_TEXT_BASE=0
+CONFIG_SYS_TEXT_BASE=0x8000000
 CONFIG_SYS_MALLOC_F_LEN=0x2000
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
 CONFIG_DISTRO_DEFAULTS=y
@@ -10,13 +10,13 @@ CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
 CONFIG_BOOTSTAGE_STASH=y
-CONFIG_BOOTSTAGE_STASH_ADDR=0x0
+CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000
 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
 CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
 CONFIG_SILENT_CONSOLE=y
 CONFIG_PRE_CONSOLE_BUFFER=y
-CONFIG_PRE_CON_BUF_ADDR=0x100000
+CONFIG_PRE_CON_BUF_ADDR=0x8100000
 CONFIG_LOG_MAX_LEVEL=6
 CONFIG_LOG_ERROR_RETURN=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig
index e922c4b38f..567ec15c22 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -1,4 +1,4 @@
-CONFIG_SYS_TEXT_BASE=0
+CONFIG_SYS_TEXT_BASE=0x8000000
 CONFIG_SYS_MALLOC_F_LEN=0x2000
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
 CONFIG_DISTRO_DEFAULTS=y
@@ -10,7 +10,7 @@ CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
 CONFIG_BOOTSTAGE_STASH=y
-CONFIG_BOOTSTAGE_STASH_ADDR=0x0
+CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000
 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
 CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
diff --git a/configs/sandbox_noblk_defconfig b/configs/sandbox_noblk_defconfig
index 8bdd4edcda..c46b0bc06c 100644
--- a/configs/sandbox_noblk_defconfig
+++ b/configs/sandbox_noblk_defconfig
@@ -1,4 +1,4 @@
-CONFIG_SYS_TEXT_BASE=0
+CONFIG_SYS_TEXT_BASE=0x8000000
 CONFIG_SYS_MALLOC_F_LEN=0x2000
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
 CONFIG_DISTRO_DEFAULTS=y
@@ -10,7 +10,7 @@ CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
 CONFIG_BOOTSTAGE_STASH=y
-CONFIG_BOOTSTAGE_STASH_ADDR=0x0
+CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000
 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
 # CONFIG_USE_BOOTCOMMAND is not set
 CONFIG_CONSOLE_RECORD=y
diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig
index fb6bb4baa2..4327e3f8b6 100644
--- a/configs/sandbox_spl_defconfig
+++ b/configs/sandbox_spl_defconfig
@@ -1,4 +1,4 @@
-CONFIG_SYS_TEXT_BASE=0
+CONFIG_SYS_TEXT_BASE=0x8000000
 CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_SYS_MALLOC_F_LEN=0x2000
@@ -17,7 +17,7 @@ CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
 CONFIG_BOOTSTAGE_STASH=y
-CONFIG_BOOTSTAGE_STASH_ADDR=0x0
+CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000
 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096
 CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index 1a49d1dab5..49a583fbe8 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -11,7 +11,7 @@
 #define CONFIG_TRACE_BUFFER_SIZE	(16 << 20)
 #define CONFIG_TRACE_EARLY_SIZE		(8 << 20)
 #define CONFIG_TRACE_EARLY
-#define CONFIG_TRACE_EARLY_ADDR		0x00100000
+#define CONFIG_TRACE_EARLY_ADDR		0x08100000
 
 #endif
 
@@ -30,7 +30,7 @@
 /*
  * Size of malloc() pool, before and after relocation
  */
-#define CONFIG_MALLOC_F_ADDR		0x0010000
+#define CONFIG_MALLOC_F_ADDR		0x08010000
 #define CONFIG_SYS_MALLOC_LEN		(32 << 20)	/* 32MB  */
 
 #define CONFIG_SYS_CBSIZE		1024	/* Console I/O Buffer Size */
@@ -44,15 +44,15 @@
 #define CONFIG_I2C_EDID
 
 /* Memory things - we don't really want a memory test */
-#define CONFIG_SYS_LOAD_ADDR		0x00000000
-#define CONFIG_SYS_MEMTEST_START	0x00100000
+#define CONFIG_SYS_LOAD_ADDR		0x08000000
+#define CONFIG_SYS_MEMTEST_START	0x08100000
 #define CONFIG_SYS_MEMTEST_END		(CONFIG_SYS_MEMTEST_START + 0x1000)
-#define CONFIG_SYS_FDT_LOAD_ADDR	        0x100
+#define CONFIG_SYS_FDT_LOAD_ADDR	0x08000100
 
 #define CONFIG_PHYSMEM
 
 /* Size of our emulated memory */
-#define CONFIG_SYS_SDRAM_BASE		0
+#define CONFIG_SYS_SDRAM_BASE		0x8000000
 #define CONFIG_SYS_SDRAM_SIZE		(128 << 20)
 #define CONFIG_SYS_MONITOR_BASE	0
 #define CONFIG_NR_DRAM_BANKS		1
@@ -104,11 +104,11 @@
 
 #define MEM_LAYOUT_ENV_SETTINGS \
 	"bootm_size=0x10000000\0" \
-	"kernel_addr_r=0x1000000\0" \
-	"fdt_addr_r=0xc00000\0" \
-	"ramdisk_addr_r=0x2000000\0" \
-	"scriptaddr=0x1000\0" \
-	"pxefile_addr_r=0x2000\0"
+	"kernel_addr_r=0x9000000\0" \
+	"fdt_addr_r=0x8c00000\0" \
+	"ramdisk_addr_r=0xa000000\0" \
+	"scriptaddr=0x8001000\0" \
+	"pxefile_addr_r=0x8002000\0"
 
 #define CONFIG_EXTRA_ENV_SETTINGS \
 	SANDBOX_SERIAL_SETTINGS \
-- 
2.12.3



More information about the U-Boot mailing list