Skip to contentSkip to conversation

sandbox: Generic board support and other improvements

PATCH Superseded Simon Glass 3 participants 30 messages Apr 20, 2013 – May 6, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover sandbox: Generic board support and other improvements

This series adds generic board support to sandbox and switches to use this always.

With sandbox it was noticed that turning CONFIG_SYS_GENERIC_BOARD off can cause a build failure if a previous autoconf.mk exists which indicates that generic board is not supported, so a patch is provided to fix this.

It is useful to convert a pointer into an 'address' in the sandbox RAM buffer - the opposite of map_sysmem(). This is added in this series and used in several places.

With sandbox it is easier to read a file from the host than to use the CONFIG_OF_SEPARATE option, since this option requires knowledge of the executable image structure which is not really appropriate on the host system. A new CONFIG_OF_HOSTFILE provides this.

A few related FDT changes are included in this series also.

The -c option is enhanced to support passing entire scripts to sandbox. This is useful when writing non-trivial test code.

Most of these patches were previously submitted as part of the verified boot effort. This series collects the independent sandbox-related patches together to make it easier to review. THe whole series is marked as version 3 for this reason.

Changes in v3:
- Rebase on master, to take account of generic board
- Add CONFIG_OF_HOSTFILE support to generic board instead of sandbox
- Remove #ifdefs which are not needed now that we have generic global_data

Changes in v2:
- Use gd->arch.ram_buf instead of gd->ram_buf (now that generic board is in)
- Fix typo "os defined" -> "is defined"
- Use gd->arch.ram_buf instead of gd->ram_buf (now that generic board is in)
- Fix checkpatch warnings about split strings
- fdt_valid() sets the FDT pointer to NULL on error, to simplify callers
- Allow the control FDT to be set even if there is currently no control FDT
- Correct bug in setting control FDT
- Fix checkpatch checks about parenthesis alignment
- Rebase to use updated fdt_valid() function
- Fix checkpatch checks about parenthesis alignment
- Revert the whole change including the set_working_fdt_addr() part
- Move sandbox's command list patch from a later series

Simon Glass (17):
Trigger generic board error only when building
sandbox: Provide a way to map from host RAM to U-Boot RAM
sandbox: Add support for generic board
sandbox: Use generic board init
sandbox: Remove old board init code
sandbox: Add CONFIG_OF_HOSTFILE to read FDT from host file
fdt: Add a parameter to fdt_valid()
Add getenv_hex() to return an environment variable as hex
fdt: Allow fdt command to check and update control FDT
sandbox: fdt: Support fdt command for sandbox
fdt: Skip checking FDT if the pointer is NULL Revert "fdt- Tell the FDT library where the device tree is"
sandbox: Allow -c argument to provide a command list
sandbox: Support 'source' command
fs: Add support for saving data to filesystems
sandbox: fs: Add support for saving files to host filesystem
sandbox: config: Enable CONFIG_FIT and CONFIG_CMD_FIT

 Makefile                          |  10 ++
 arch/sandbox/config.mk            |   5 +-
 arch/sandbox/cpu/cpu.c            |   5 +
 arch/sandbox/cpu/start.c          |   9 +-
 arch/sandbox/include/asm/io.h     |   8 ++
 arch/sandbox/include/asm/state.h  |   1 +
 arch/sandbox/include/asm/u-boot.h |  22 +--
 arch/sandbox/lib/Makefile         |   1 -
 arch/sandbox/lib/board.c          | 285 --------------------------------------
 board/sandbox/sandbox/sandbox.c   |   2 +-
 common/board_f.c                  | 106 ++++++++++++--
 common/board_r.c                  |   8 +-
 common/cmd_fdt.c                  |  87 ++++++++----
 common/cmd_nvedit.c               |  15 ++
 common/cmd_sandbox.c              |  18 ++-
 common/cmd_source.c               |  11 +-
 common/main.c                     |   8 --
 config.mk                         |   4 +-
 doc/README.fdt-control            |   6 +-
 fs/fs.c                           |  75 ++++++++++
 fs/sandbox/sandboxfs.c            |  33 +++++
 include/asm-generic/sections.h    |   2 +-
 include/common.h                  |  18 +++
 include/configs/sandbox.h         |  11 +-
 include/fs.h                      |   2 +
 include/sandboxfs.h               |   1 +
 lib/fdtdec.c                      |   5 +-
 27 files changed, 383 insertions(+), 375 deletions(-)
 delete mode 100644 arch/sandbox/lib/board.c
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH v3 1/17 Trigger generic board error only when building

At present the generic board error can occur when configuring U-Boot, or during distclean, but this is incorrect. The existing autoconf.mk may come from an earlier U-Boot configuration which is about to be overwritten.

Make the error conditional so that it will only be triggered when we are actually building U-Boot.

This avoids a problem where the system is being reconfigured to remove CONFIG_SYS_GENERIC_BOARD on an architecture that does not support it. Currently this will print an error and require the manual removal of include/autoconf.mk.

---
Changes in v3: None
Changes in v2: None

 Makefile  | 10 ++++++++++
 config.mk |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)
Makefile +10 -0
index 3fd6d15..42f2b02 100644
@@ -183,6 +183,16 @@ endif
 # load other configuration
 include $(TOPDIR)/config.mk
 
+# Targets which don't build the source code
+NON_BUILD_TARGETS = backup clean clobber distclean mkproper tidy unconfig
+
+# Only do the generic board check when actually building, not configuring
+ifeq ($(filter $(NON_BUILD_TARGETS),$(MAKECMDGOALS)),)
+ifeq ($(findstring _config,$(MAKECMDGOALS)),)
+$(CHECK_GENERIC_BOARD)
+endif
+endif
+
 # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
 # that (or fail if absent).  Otherwise, search for a linker script in a
 # standard location.
config.mk +2 -2
index 1fd109f..16a4fdb 100644
@@ -229,8 +229,8 @@ endif
 # Does this architecture support generic board init?
 ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
 ifneq ($(CONFIG_SYS_GENERIC_BOARD),)
-$(error Your architecture does not support generic board. Please undefined \
-CONFIG_SYS_GENERIC_BOARD in your board config file)
+CHECK_GENERIC_BOARD = $(error Your architecture does not support generic board. \
+Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file)
 endif
 endif
 
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH v3 2/17 sandbox: Provide a way to map from host RAM to U-Boot RAM

In reply to Simon Glass

In many cases, pointers to memory are passed around, and these pointers refer to U-Boot memory, not host memory. This in itself is not a problem.

However, in a few places, we cast that pointer back to a ulong (being a U-Boot memory address). It is possible to convert many of these cases to avoid this. However there are data structures (e.g. struct bootm_headers) which use pointers. We could with a lot of effort adjust the structs and all code that uses them to use ulong instead of pointers.

This seems like an unacceptable cost, since our objective with sandbox is to minimise the impact on U-Boot code while maximising the features available to sandbox.

Therefore, create a map_to_sysmem() function which converts from a pointer to a U-Boot address. This can be used sparingly when needed.

---
Changes in v3:
- Rebase on master, to take account of generic board

Changes in v2:
- Use gd->arch.ram_buf instead of gd->ram_buf (now that generic board is in)

 arch/sandbox/cpu/cpu.c        | 5 +++++
 arch/sandbox/include/asm/io.h | 3 +++
 include/common.h              | 5 +++++
 3 files changed, 13 insertions(+)
arch/sandbox/cpu/cpu.c +5 -0
index b2788d5..dd8d495 100644
@@ -57,6 +57,11 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
 	return (void *)(gd->arch.ram_buf + paddr);
 }
 
+phys_addr_t map_to_sysmem(void *ptr)
+{
+	return (u8 *)ptr - gd->arch.ram_buf;
+}
+
 void flush_dcache_range(unsigned long start, unsigned long stop)
 {
 }
arch/sandbox/include/asm/io.h +3 -0
index d8c0236..54051a3 100644
@@ -49,3 +49,6 @@ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
 static inline void unmap_sysmem(const void *vaddr)
 {
 }
+
+/* Map from a pointer to our RAM buffer */
+phys_addr_t map_to_sysmem(void *ptr);
include/common.h +5 -0
index 0cfa6a8..76c79ae 100644
@@ -897,6 +897,11 @@ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
 static inline void unmap_sysmem(const void *vaddr)
 {
 }
+
+static inline phys_addr_t map_to_sysmem(void *ptr)
+{
+	return (phys_addr_t)(uintptr_t)ptr;
+}
 # endif
 
 #endif /* __ASSEMBLY__ */
Signature · 1 line
1.8.2.1
#3 lore raw

PATCH v3 3/17 sandbox: Add support for generic board

In reply to Simon Glass

Add generic board support for sandbox.

---
Changes in v3: None
Changes in v2: None

 arch/sandbox/config.mk            |  3 +++
 arch/sandbox/include/asm/io.h     |  5 ++++
 arch/sandbox/include/asm/u-boot.h |  7 ++++++
 arch/sandbox/lib/Makefile         |  2 ++
 board/sandbox/sandbox/sandbox.c   |  2 +-
 common/board_f.c                  | 51 ++++++++++++++++++++++++++++++++-------
 common/board_r.c                  |  8 ++++--
 include/asm-generic/sections.h    |  2 +-
 include/configs/sandbox.h         |  7 +++---
 lib/fdtdec.c                      |  2 +-
 10 files changed, 72 insertions(+), 17 deletions(-)
arch/sandbox/config.mk +3 -0
index 4fd0d4e..aeb9da9 100644
@@ -20,3 +20,6 @@
 PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ -U_FORTIFY_SOURCE
 PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM
 PLATFORM_LIBS += -lrt
+
+# Support generic board on sandbox
+__HAVE_ARCH_GENERIC_BOARD := y
arch/sandbox/include/asm/io.h +5 -0
index 54051a3..0c022f1 100644
@@ -20,6 +20,9 @@
  * MA 02111-1307 USA
  */
 
+#ifndef __SANDBOX_ASM_IO_H
+#define __SANDBOX_ASM_IO_H
+
 /*
  * Given a physical address and a length, return a virtual address
  * that can be used to access the memory range with the caching
@@ -52,3 +55,5 @@ static inline void unmap_sysmem(const void *vaddr)
 
 /* Map from a pointer to our RAM buffer */
 phys_addr_t map_to_sysmem(void *ptr);
+
+#endif
arch/sandbox/include/asm/u-boot.h +7 -0
index de8120a..7b93acb 100644
@@ -36,6 +36,11 @@
 #ifndef _U_BOOT_H_
 #define _U_BOOT_H_	1
 
+#ifdef CONFIG_SYS_GENERIC_BOARD
+/* Use the generic board which requires a unified bd_info */
+#include <asm-generic/u-boot.h>
+#else
+
 typedef struct bd_info {
 	unsigned long	bi_memstart;	/* start of DRAM memory */
 	phys_size_t	bi_memsize;	/* size	 of DRAM memory in bytes */
@@ -57,6 +62,8 @@ typedef struct bd_info {
 	} bi_dram[CONFIG_NR_DRAM_BANKS];
 } bd_t;
 
+#endif /* !CONFIG_SYS_GENERIC_BOARD */
+
 /* For image.h:image_check_target_arch() */
 #define IH_ARCH_DEFAULT IH_ARCH_SANDBOX
 
arch/sandbox/lib/Makefile +2 -0
index fbe579b..b1ae168 100644
@@ -27,7 +27,9 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(ARCH).o
 
+ifndef CONFIG_SYS_GENERIC_BOARD
 COBJS-y	+= board.o
+endif
 COBJS-y	+= interrupts.o
 
 SRCS	:= $(COBJS-y:.o=.c)
board/sandbox/sandbox/sandbox.c +1 -1
index 9883013..8bdba92 100644
@@ -56,6 +56,6 @@ int timer_init(void)
 
 int dram_init(void)
 {
-	gd->ram_size = CONFIG_DRAM_SIZE;
+	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
 	return 0;
 }
common/board_f.c +42 -9

137 lines not on this page · raw message

common/board_r.c +6 -2
index 2b17fa6..f801e41 100644
@@ -136,7 +136,7 @@ static int initr_reloc_global_data(void)
 {
 #ifdef CONFIG_SYS_SYM_OFFSETS
 	monitor_flash_len = _end_ofs;
-#else
+#elif !defined(CONFIG_SANDBOX)
 	monitor_flash_len = (ulong)&__init_end - gd->dest_addr;
 #endif
 #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx)
@@ -264,7 +264,8 @@ static int initr_malloc(void)
 
 	/* The malloc area is immediately below the monitor copy in DRAM */
 	malloc_start = gd->dest_addr - TOTAL_MALLOC_LEN;
-	mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
+	mem_malloc_init((ulong)map_sysmem(malloc_start, TOTAL_MALLOC_LEN),
+			TOTAL_MALLOC_LEN);
 	return 0;
 }
 
@@ -691,6 +692,9 @@ static int initr_modem(void)
 
 static int run_main_loop(void)
 {
+#ifdef CONFIG_SANDBOX
+	sandbox_main_loop_init();
+#endif
 	/* main_loop() can return to retry autoboot, if so just run it again */
 	for (;;)
 		main_loop();
include/asm-generic/sections.h +1 -1
index cca1edb..4b39844 100644
@@ -29,7 +29,7 @@ extern char _data[], _sdata[], _edata[];
 extern char __bss_start[], __bss_stop[];
 extern char __init_begin[], __init_end[];
 extern char _sinittext[], _einittext[];
-extern char _end[];
+extern char _end[], _init[];
 extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];
 extern char __kprobes_text_start[], __kprobes_text_end[];
 extern char __entry_text_start[], __entry_text_end[];
include/configs/sandbox.h +4 -3
index 406da43..da7cc9a 100644
@@ -22,9 +22,6 @@
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-#define CONFIG_NR_DRAM_BANKS	1
-#define CONFIG_DRAM_SIZE	(128 << 20)
-
 /* Number of bits in a C 'long' on this architecture */
 #define CONFIG_SANDBOX_BITS_PER_LONG	64
 
@@ -76,7 +73,11 @@
 #define CONFIG_PHYS_64BIT
 
 /* Size of our emulated memory */
+#define CONFIG_SYS_SDRAM_BASE		0
 #define CONFIG_SYS_SDRAM_SIZE		(128 << 20)
+#define CONFIG_SYS_TEXT_BASE		0
+#define CONFIG_SYS_MONITOR_BASE	0
+#define CONFIG_NR_DRAM_BANKS		1
 
 #define CONFIG_BAUDRATE			115200
 #define CONFIG_SYS_BAUDRATE_TABLE	{4800, 9600, 19200, 38400, 57600,\
lib/fdtdec.c +1 -1
index 92fbefe..60369fb 100644
@@ -357,7 +357,7 @@ int fdtdec_prepare_fdt(void)
 	if (((uintptr_t)gd->fdt_blob & 3) || fdt_check_header(gd->fdt_blob)) {
 		printf("No valid FDT found - please append one to U-Boot "
 			"binary, use u-boot-dtb.bin or define "
-			"CONFIG_OF_EMBED\n");
+			"CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n");
 		return -1;
 	}
 	return 0;
Signature · 1 line
1.8.2.1
#4 lore raw

PATCH v3 3/17 sandbox: Add support for generic board

Quoted 1 line · Simon Glass

Add generic board support for sandbox.

[snip]

arch/sandbox/include/asm/u-boot.h line 42

Quoted 12 lines
arch/sandbox/include/asm/u-boot.h +4 -0
index de8120a..7b93acb 100644
@@ -36,6 +36,11 @@
 #ifndef _U_BOOT_H_
 #define _U_BOOT_H_	1
 
+#ifdef CONFIG_SYS_GENERIC_BOARD
+/* Use the generic board which requires a unified bd_info */
+#include <asm-generic/u-boot.h>
+#else

You're converting the whole arch here, so just drop the non-CONFIG_SYS_GENERIC_BOARD code?

[snip]

arch/sandbox/lib/Makefile include $(TOPDIR)/config.mk · line 32

Quoted 11 lines
arch/sandbox/lib/Makefile +2 -0
index fbe579b..b1ae168 100644
@@ -27,7 +27,9 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(ARCH).o
 
+ifndef CONFIG_SYS_GENERIC_BOARD
 COBJS-y	+= board.o
+endif

Then board.c goes away too.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130422/4f014cac/attachment.pgp>
#5 lore raw

PATCH v3 3/17 sandbox: Add support for generic board

Quoted 27 lines · Tom Rini
Quoted 1 line · Simon Glass

Add generic board support for sandbox.

[snip]

arch/sandbox/include/asm/u-boot.h line 42

Quoted 12 lines
arch/sandbox/include/asm/u-boot.h +4 -0
index de8120a..7b93acb 100644
@@ -36,6 +36,11 @@
 #ifndef _U_BOOT_H_
 #define _U_BOOT_H_	1
 
+#ifdef CONFIG_SYS_GENERIC_BOARD
+/* Use the generic board which requires a unified bd_info */
+#include <asm-generic/u-boot.h>
+#else

You're converting the whole arch here, so just drop the non-CONFIG_SYS_GENERIC_BOARD code?

[snip]

Quoted 6 lines
arch/sandbox/lib/Makefile +0 -0
index fbe579b..b1ae168 100644
@@ -27,7 +27,9 @@ include $(TOPDIR)/config.mk
 
Quoted 7 lines

arch/sandbox/lib/Makefile include $(TOPDIR)/config.mk · line 32

Quoted 5 lines
arch/sandbox/lib/Makefile +2 -0
 LIB	= $(obj)lib$(ARCH).o
 
+ifndef CONFIG_SYS_GENERIC_BOARD
 COBJS-y	+= board.o
+endif

Then board.c goes away too.

In short, squash 3/4/5 into one patch.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130422/207e3580/attachment.pgp>
#6 lore raw

PATCH v3 3/17 sandbox: Add support for generic board

Hi Tom,

Quoted 30 lines · Tom Rini
Quoted 29 lines · Tom Rini
Quoted 1 line · Simon Glass

Add generic board support for sandbox.

[snip]

arch/sandbox/include/asm/u-boot.h line 42

Quoted 12 lines
arch/sandbox/include/asm/u-boot.h +4 -0
index de8120a..7b93acb 100644
@@ -36,6 +36,11 @@
 #ifndef _U_BOOT_H_
 #define _U_BOOT_H_ 1
 
+#ifdef CONFIG_SYS_GENERIC_BOARD
+/* Use the generic board which requires a unified bd_info */
+#include <asm-generic/u-boot.h>
+#else

You're converting the whole arch here, so just drop the non-CONFIG_SYS_GENERIC_BOARD code?

[snip]

Quoted 8 lines
arch/sandbox/lib/Makefile +0 -0
index fbe579b..b1ae168 100644
@@ -27,7 +27,9 @@ include $(TOPDIR)/config.mk
 
 LIB        = $(obj)lib$(ARCH).o
 
Quoted 7 lines
Quoted 5 lines

arch/sandbox/lib/Makefile include $(TOPDIR)/config.mk · line 32

Quoted 3 lines
arch/sandbox/lib/Makefile +2 -0
+ifndef CONFIG_SYS_GENERIC_BOARD
 COBJS-y    += board.o
+endif

Then board.c goes away too.

In short, squash 3/4/5 into one patch.

OK I have done this and resent this one combined patch as v4.

Regards,
Simon

#7 lore raw

PATCH v3 4/17 sandbox: Use generic board init

In reply to Simon Glass

Select CONFIG_SYS_GENERIC_BOARD for sandbox now that this is supported.

---
Changes in v3: None
Changes in v2: None

 arch/sandbox/config.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/config.mk +1 -1
index aeb9da9..988b52c 100644
@@ -18,7 +18,7 @@
 # MA 02111-1307 USA
 
 PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ -U_FORTIFY_SOURCE
-PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM
+PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM -DCONFIG_SYS_GENERIC_BOARD
 PLATFORM_LIBS += -lrt
 
 # Support generic board on sandbox
Signature · 1 line
1.8.2.1
#8 lore raw

PATCH v3 5/17 sandbox: Remove old board init code

In reply to Simon Glass

We can use generic board for sandbox, so the old board init code can now be removed.

---
Changes in v3: None
Changes in v2: None

 arch/sandbox/include/asm/u-boot.h |  25 ----
 arch/sandbox/lib/Makefile         |   3 -
 arch/sandbox/lib/board.c          | 285 --------------------------------------
 3 files changed, 313 deletions(-)
 delete mode 100644 arch/sandbox/lib/board.c
arch/sandbox/include/asm/u-boot.h +0 -25
index 7b93acb..5bea1f2 100644
@@ -36,33 +36,8 @@
 #ifndef _U_BOOT_H_
 #define _U_BOOT_H_	1
 
-#ifdef CONFIG_SYS_GENERIC_BOARD
 /* Use the generic board which requires a unified bd_info */
 #include <asm-generic/u-boot.h>
-#else
-
-typedef struct bd_info {
-	unsigned long	bi_memstart;	/* start of DRAM memory */
-	phys_size_t	bi_memsize;	/* size	 of DRAM memory in bytes */
-	unsigned long	bi_flashstart;	/* start of FLASH memory */
-	unsigned long	bi_flashsize;	/* size	 of FLASH memory */
-	unsigned long	bi_flashoffset; /* reserved area for startup monitor */
-	unsigned long	bi_sramstart;	/* start of SRAM memory */
-	unsigned long	bi_sramsize;	/* size	 of SRAM memory */
-	unsigned long	bi_bootflags;	/* boot / reboot flag (for LynxOS) */
-	unsigned short	bi_ethspeed;	/* Ethernet speed in Mbps */
-	unsigned long	bi_intfreq;	/* Internal Freq, in MHz */
-	unsigned long	bi_busfreq;	/* Bus Freq, in MHz */
-	unsigned int	bi_baudrate;	/* Console Baudrate */
-	unsigned long   bi_boot_params;	/* where this board expects params */
-	struct				/* RAM configuration */
-	{
-		ulong start;
-		ulong size;
-	} bi_dram[CONFIG_NR_DRAM_BANKS];
-} bd_t;
-
-#endif /* !CONFIG_SYS_GENERIC_BOARD */
 
 /* For image.h:image_check_target_arch() */
 #define IH_ARCH_DEFAULT IH_ARCH_SANDBOX
arch/sandbox/lib/Makefile +0 -3
index b1ae168..3aad574 100644
@@ -27,9 +27,6 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(ARCH).o
 
-ifndef CONFIG_SYS_GENERIC_BOARD
-COBJS-y	+= board.o
-endif
 COBJS-y	+= interrupts.o
 
 SRCS	:= $(COBJS-y:.o=.c)
arch/sandbox/lib/board.c deleted +0 -285

285 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#9 lore raw

PATCH v3 6/17 sandbox: Add CONFIG_OF_HOSTFILE to read FDT from host file

In reply to Simon Glass

With sandbox it is tricky to add an FDT to the image at build time (or later) since we build an ELF file, not a plain binary, and the address space of the whole U-Boot is not accessible in the emulated memory map of sandbox.

Sandbox can read files directly from the host, though, so add an option to read an FDT from a host file on start-up.

---
Changes in v3:
- Add CONFIG_OF_HOSTFILE support to generic board instead of sandbox

Changes in v2:
- Fix typo "os defined" -> "is defined"
- Use gd->arch.ram_buf instead of gd->ram_buf (now that generic board is in)
- Fix checkpatch warnings about split strings

 arch/sandbox/cpu/start.c         |  7 +++++
 arch/sandbox/include/asm/state.h |  1 +
 common/board_f.c                 | 55 ++++++++++++++++++++++++++++++++++++++++
 doc/README.fdt-control           |  6 ++++-
 include/configs/sandbox.h        |  2 ++
 5 files changed, 70 insertions(+), 1 deletion(-)
arch/sandbox/cpu/start.c +7 -0
index 5287fd5..2fcec8b 100644
@@ -104,6 +104,13 @@ static int sb_cmdline_cb_command(struct sandbox_state *state, const char *arg)
 }
 SB_CMDLINE_OPT_SHORT(command, 'c', 1, "Execute U-Boot command");
 
+static int sb_cmdline_cb_fdt(struct sandbox_state *state, const char *arg)
+{
+	state->fdt_fname = arg;
+	return 0;
+}
+SB_CMDLINE_OPT_SHORT(fdt, 'd', 1, "Specify U-Boot's control FDT");
+
 int main(int argc, char *argv[])
 {
 	struct sandbox_state *state;
arch/sandbox/include/asm/state.h +1 -0
index 2b62b46..9552708 100644
@@ -34,6 +34,7 @@ enum exit_type_id {
 /* The complete state of the test system */
 struct sandbox_state {
 	const char *cmd;		/* Command to execute */
+	const char *fdt_fname;		/* Filename of FDT binary */
 	enum exit_type_id exit_type;	/* How we exited U-Boot */
 	const char *parse_err;		/* Error to report from parsing */
 	int argc;			/* Program arguments */
common/board_f.c +55 -0

73 lines not on this page · raw message

doc/README.fdt-control +5 -1
index 8352835..5963f78 100644
@@ -142,7 +142,11 @@ join the two:
 
 and then flash image.bin onto your board.
 
-You cannot use both of these options at the same time.
+If CONFIG_OF_HOSTFILE is defined, then it will be read from a file on
+startup. This is only useful for sandbox. Use the -d flag to U-Boot to
+specify the file to read.
+
+You cannot use more than one of these options at the same time.
 
 If you wish to put the fdt at a different address in memory, you can
 define the "fdtcontroladdr" environment variable. This is the hex
include/configs/sandbox.h +2 -0
index da7cc9a..8efaded 100644
@@ -26,6 +26,7 @@
 #define CONFIG_SANDBOX_BITS_PER_LONG	64
 
 #define CONFIG_OF_CONTROL
+#define CONFIG_OF_HOSTFILE
 #define CONFIG_OF_LIBFDT
 #define CONFIG_LMB
 
@@ -71,6 +72,7 @@
 #define CONFIG_SYS_MEMTEST_START	0x00100000
 #define CONFIG_SYS_MEMTEST_END		(CONFIG_SYS_MEMTEST_START + 0x1000)
 #define CONFIG_PHYS_64BIT
+#define CONFIG_SYS_FDT_LOAD_ADDR	0x1000000
 
 /* Size of our emulated memory */
 #define CONFIG_SYS_SDRAM_BASE		0
Signature · 1 line
1.8.2.1
#10 lore raw

PATCH v3 7/17 fdt: Add a parameter to fdt_valid()

In reply to Simon Glass

At present this only checks working_fdt, but we want to check other FDTs also. So add the FDT to check as a parameter to fdt_valid().

---
Changes in v3: None
Changes in v2:
- fdt_valid() sets the FDT pointer to NULL on error, to simplify callers
- Allow the control FDT to be set even if there is currently no control FDT

 common/cmd_fdt.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)
common/cmd_fdt.c +20 -18
index ac77a08..07072f3 100644
@@ -43,7 +43,7 @@
  */
 DECLARE_GLOBAL_DATA_PTR;
 
-static int fdt_valid(void);
+static int fdt_valid(struct fdt_header **blobp);
 static int fdt_parse_prop(char *const*newval, int count, char *data, int *len);
 static int fdt_print(const char *pathp, char *prop, int depth);
 static int is_printable_string(const void *data, int len);
@@ -104,9 +104,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		 * Set the address [and length] of the fdt.
 		 */
 		if (argc == 2) {
-			if (!fdt_valid()) {
+			if (!fdt_valid(&working_fdt))
 				return 1;
-			}
 			printf("The address of the fdt is %p\n", working_fdt);
 			return 0;
 		}
@@ -114,9 +113,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		addr = simple_strtoul(argv[2], NULL, 16);
 		set_working_fdt_addr((void *)addr);
 
-		if (!fdt_valid()) {
+		if (!fdt_valid(&working_fdt))
 			return 1;
-		}
 
 		if (argc >= 4) {
 			int  len;
@@ -167,9 +165,8 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		 * Set the address and length of the fdt.
 		 */
 		working_fdt = (struct fdt_header *)simple_strtoul(argv[2], NULL, 16);
-		if (!fdt_valid()) {
+		if (!fdt_valid(&working_fdt))
 			return 1;
-		}
 
 		newaddr = (struct fdt_header *)simple_strtoul(argv[3],NULL,16);
 
@@ -592,16 +589,23 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 /****************************************************************************/
 
-static int fdt_valid(void)
+/**
+ * fdt_valid() - Check if an FDT is valid. If not, change it to NULL
+ *
+ * @blobp: Pointer to FDT pointer
+ * @return 1 if OK, 0 if bad (in which case *blobp is set to NULL)
+ */
+static int fdt_valid(struct fdt_header **blobp)
 {
-	int  err;
+	const void *blob = *blobp;
+	int err;
 
-	if (working_fdt == NULL) {
+	if (blob == NULL) {
 		printf ("The address of the fdt is invalid (NULL).\n");
 		return 0;
 	}
 
-	err = fdt_check_header(working_fdt);
+	err = fdt_check_header(blob);
 	if (err == 0)
 		return 1;	/* valid */
 
@@ -611,23 +615,21 @@ static int fdt_valid(void)
 		 * Be more informative on bad version.
 		 */
 		if (err == -FDT_ERR_BADVERSION) {
-			if (fdt_version(working_fdt) <
+			if (fdt_version(blob) <
 			    FDT_FIRST_SUPPORTED_VERSION) {
 				printf (" - too old, fdt %d < %d",
-					fdt_version(working_fdt),
+					fdt_version(blob),
 					FDT_FIRST_SUPPORTED_VERSION);
-				working_fdt = NULL;
 			}
-			if (fdt_last_comp_version(working_fdt) >
+			if (fdt_last_comp_version(blob) >
 			    FDT_LAST_SUPPORTED_VERSION) {
 				printf (" - too new, fdt %d > %d",
-					fdt_version(working_fdt),
+					fdt_version(blob),
 					FDT_LAST_SUPPORTED_VERSION);
-				working_fdt = NULL;
 			}
-			return 0;
 		}
 		printf("\n");
+		*blobp = NULL;
 		return 0;
 	}
 	return 1;
Signature · 1 line
1.8.2.1
#11 lore raw

PATCH v3 7/17 fdt: Add a parameter to fdt_valid()

Quoted 4 lines · Simon Glass

At present this only checks working_fdt, but we want to check other FDTs also. So add the FDT to check as a parameter to fdt_valid().

Quoted 8 lines

---
Changes in v3: None
Changes in v2:
- fdt_valid() sets the FDT pointer to NULL on error, to simplify callers
- Allow the control FDT to be set even if there is currently no control FDT

  common/cmd_fdt.c | 38 ++++++++++++++++++++------------------
  1 file changed, 20 insertions(+), 18 deletions(-)
#12 lore raw

PATCH v3 8/17 Add getenv_hex() to return an environment variable as hex

In reply to Simon Glass

This conversion is required in a number of places in U-Boot. Add a standard function to provide this feature, so we avoid all the different variations in the way it is coded.

---
Changes in v3: None
Changes in v2: None

 common/cmd_nvedit.c | 15 +++++++++++++++
 include/common.h    | 13 +++++++++++++
 2 files changed, 28 insertions(+)
common/cmd_nvedit.c +15 -0
index 68b0f4f..d893aa1 100644
@@ -315,6 +315,21 @@ int setenv_hex(const char *varname, ulong value)
 	return setenv(varname, str);
 }
 
+ulong getenv_hex(const char *varname, ulong default_val)
+{
+	const char *s;
+	ulong value;
+	char *endp;
+
+	s = getenv(varname);
+	if (s)
+		value = simple_strtoul(s, &endp, 16);
+	if (!s || endp == s)
+		return default_val;
+
+	return value;
+}
+
 #ifndef CONFIG_SPL_BUILD
 static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
include/common.h +13 -0
index 76c79ae..28aa4b9 100644
@@ -352,6 +352,19 @@ int	envmatch     (uchar *, int);
 char	*getenv	     (const char *);
 int	getenv_f     (const char *name, char *buf, unsigned len);
 ulong getenv_ulong(const char *name, int base, ulong default_val);
+
+/**
+ * getenv_hex() - Return an environment variable as a hex value
+ *
+ * Decode an environment as a hex number (it may or may not have a 0x
+ * prefix). If the environment variable cannot be found, or does not start
+ * with hex digits, the default value is returned.
+ *
+ * @varname:		Variable to decode
+ * @default_val:	Value to return on error
+ */
+ulong getenv_hex(const char *varname, ulong default_val);
+
 /*
  * Read an environment variable as a boolean
  * Return -1 if variable does not exist (default to true)
Signature · 1 line
1.8.2.1
#13 lore raw

PATCH v3 9/17 fdt: Allow fdt command to check and update control FDT

In reply to Simon Glass

There is an existing fdt command to deal with the working FDT. Enhance this to support the control FDT also (CONFIG_OF_CONTROL).

---
Changes in v3:
- Remove #ifdefs which are not needed now that we have generic global_data

Changes in v2:
- Correct bug in setting control FDT
- Fix checkpatch checks about parenthesis alignment

 common/cmd_fdt.c | 47 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 13 deletions(-)
common/cmd_fdt.c +34 -13
index 07072f3..e582961 100644
@@ -100,38 +100,59 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	 */
 	if (argv[1][0] == 'a') {
 		unsigned long addr;
+		int control = 0;
+		struct fdt_header *blob;
 		/*
 		 * Set the address [and length] of the fdt.
 		 */
-		if (argc == 2) {
-			if (!fdt_valid(&working_fdt))
+		argc -= 2;
+		argv += 2;
+/* Temporary #ifdef - some archs don't have fdt_blob yet */
+#ifdef CONFIG_OF_CONTROL
+		if (argc && !strcmp(*argv, "-c")) {
+			control = 1;
+			argc--;
+			argv++;
+		}
+#endif
+		if (argc == 0) {
+			if (control)
+				blob = (struct fdt_header *)gd->fdt_blob;
+			else
+				blob = working_fdt;
+			if (!blob || !fdt_valid(&blob))
 				return 1;
-			printf("The address of the fdt is %p\n", working_fdt);
+			printf("The address of the fdt is %#08lx\n",
+			       control ? (ulong)blob :
+					getenv_hex("fdtaddr", 0));
 			return 0;
 		}
 
-		addr = simple_strtoul(argv[2], NULL, 16);
-		set_working_fdt_addr((void *)addr);
-
-		if (!fdt_valid(&working_fdt))
+		addr = simple_strtoul(argv[0], NULL, 16);
+		blob = (struct fdt_header *)addr;
+		if (!fdt_valid(&blob))
 			return 1;
+		if (control)
+			gd->fdt_blob = blob;
+		else
+			set_working_fdt_addr((void *)addr);
 
-		if (argc >= 4) {
+		if (argc >= 2) {
 			int  len;
 			int  err;
 			/*
 			 * Optional new length
 			 */
-			len = simple_strtoul(argv[3], NULL, 16);
-			if (len < fdt_totalsize(working_fdt)) {
+			len = simple_strtoul(argv[1], NULL, 16);
+			if (len < fdt_totalsize(blob)) {
 				printf ("New length %d < existing length %d, "
 					"ignoring.\n",
-					len, fdt_totalsize(working_fdt));
+					len, fdt_totalsize(blob));
 			} else {
 				/*
 				 * Open in place with a new length.
 				 */
-				err = fdt_open_into(working_fdt, working_fdt, len);
+				err = fdt_open_into(blob, blob, len);
 				if (err != 0) {
 					printf ("libfdt fdt_open_into(): %s\n",
 						fdt_strerror(err));
@@ -960,7 +981,7 @@ static int fdt_print(const char *pathp, char *prop, int depth)
 /********************************************************************/
 #ifdef CONFIG_SYS_LONGHELP
 static char fdt_help_text[] =
-	"addr   <addr> [<length>]        - Set the fdt location to <addr>\n"
+	"addr [-c]  <addr> [<length>]   - Set the [control] fdt location to <addr>\n"
 #ifdef CONFIG_OF_BOARD_SETUP
 	"fdt boardsetup                      - Do board-specific set up\n"
 #endif
Signature · 1 line
1.8.2.1
#14 lore raw

PATCH v3 9/17 fdt: Allow fdt command to check and update control FDT

Quoted 4 lines · Simon Glass

There is an existing fdt command to deal with the working FDT. Enhance this to support the control FDT also (CONFIG_OF_CONTROL).

Quoted 10 lines

---
Changes in v3:
- Remove #ifdefs which are not needed now that we have generic global_data

Changes in v2:
- Correct bug in setting control FDT
- Fix checkpatch checks about parenthesis alignment

  common/cmd_fdt.c | 47 ++++++++++++++++++++++++++++++++++-------------
  1 file changed, 34 insertions(+), 13 deletions(-)
#15 lore raw

PATCH v3 10/17 sandbox: fdt: Support fdt command for sandbox

In reply to Simon Glass

By using map_sysmem() we can get the fdt command to work correctly with sandbox.

---
Changes in v3: None
Changes in v2:
- Rebase to use updated fdt_valid() function

 common/cmd_fdt.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
common/cmd_fdt.c +7 -3
index e582961..edefd77 100644
@@ -31,6 +31,7 @@
 #include <asm/global_data.h>
 #include <libfdt.h>
 #include <fdt_support.h>
+#include <asm/io.h>
 
 #define MAX_LEVEL	32		/* how deeply nested we will go */
 #define SCRATCHPAD	1024		/* bytes of scratchpad memory */
@@ -55,7 +56,10 @@ struct fdt_header *working_fdt;
 
 void set_working_fdt_addr(void *addr)
 {
-	working_fdt = addr;
+	void *buf;
+
+	buf = map_sysmem((ulong)addr, 0);
+	working_fdt = buf;
 	setenv_addr("fdtaddr", addr);
 }
 
@@ -129,13 +133,13 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		}
 
 		addr = simple_strtoul(argv[0], NULL, 16);
-		blob = (struct fdt_header *)addr;
+		blob = map_sysmem(addr, 0);
 		if (!fdt_valid(&blob))
 			return 1;
 		if (control)
 			gd->fdt_blob = blob;
 		else
-			set_working_fdt_addr((void *)addr);
+			set_working_fdt_addr(blob);
 
 		if (argc >= 2) {
 			int  len;
Signature · 1 line
1.8.2.1
#16 lore raw

PATCH v3 10/17 sandbox: fdt: Support fdt command for sandbox

Quoted 4 lines · Simon Glass

By using map_sysmem() we can get the fdt command to work correctly with sandbox.

Quoted 7 lines

---
Changes in v3: None
Changes in v2:
- Rebase to use updated fdt_valid() function

  common/cmd_fdt.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
#17 lore raw

PATCH v3 11/17 fdt: Skip checking FDT if the pointer is NULL

In reply to Simon Glass

If we have no FDT, don't attempt to read from it. This allows sandbox to run without an FDT if required.

---
Changes in v3: None
Changes in v2:
- Fix checkpatch checks about parenthesis alignment

 lib/fdtdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/fdtdec.c +2 -1
index 60369fb..ac1fe0b 100644
@@ -354,7 +354,8 @@ int fdtdec_check_fdt(void)
  */
 int fdtdec_prepare_fdt(void)
 {
-	if (((uintptr_t)gd->fdt_blob & 3) || fdt_check_header(gd->fdt_blob)) {
+	if (!gd->fdt_blob || ((uintptr_t)gd->fdt_blob & 3) ||
+	    fdt_check_header(gd->fdt_blob)) {
 		printf("No valid FDT found - please append one to U-Boot "
 			"binary, use u-boot-dtb.bin or define "
 			"CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n");
Signature · 1 line
1.8.2.1
#18 lore raw

PATCH v3 11/17 fdt: Skip checking FDT if the pointer is NULL

Quoted 4 lines · Simon Glass

If we have no FDT, don't attempt to read from it. This allows sandbox to run without an FDT if required.

Quoted 7 lines

---
Changes in v3: None
Changes in v2:
- Fix checkpatch checks about parenthesis alignment

  lib/fdtdec.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
#19 lore raw

PATCH v3 12/17 Revert "fdt- Tell the FDT library where the device tree is"

In reply to Simon Glass

This reverts commit 3b73459ea3421e9f8c6c8c62e1d3fe458ca5bc56.

In practice it doesn't seem like a good idea to make the the working FDT point to the control FDT. Now that we can access the control FDT using the 'fdt' command, there is no need for this feature. Remove it.

---
Changes in v3: None
Changes in v2:
- Revert the whole change including the set_working_fdt_addr() part

 common/main.c | 8 --------
 1 file changed, 8 deletions(-)
common/main.c +0 -8
index a15f020..953ef29 100644
@@ -45,10 +45,6 @@
 #include <fdtdec.h>
 #endif
 
-#ifdef CONFIG_OF_LIBFDT
-#include <fdt_support.h>
-#endif /* CONFIG_OF_LIBFDT */
-
 #include <post.h>
 #include <linux/ctype.h>
 #include <menu.h>
@@ -376,10 +372,6 @@ void main_loop (void)
 
 	bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
 
-#if defined CONFIG_OF_CONTROL
-       set_working_fdt_addr((void *)gd->fdt_blob);
-#endif /* CONFIG_OF_CONTROL */
-
 #ifdef CONFIG_BOOTCOUNT_LIMIT
 	bootcount = bootcount_load();
 	bootcount++;
Signature · 1 line
1.8.2.1
#20 lore raw

PATCH v3 12/17 Revert "fdt- Tell the FDT library where the device tree is"

Quoted 7 lines · Simon Glass

This reverts commit 3b73459ea3421e9f8c6c8c62e1d3fe458ca5bc56.

In practice it doesn't seem like a good idea to make the the working FDT point to the control FDT. Now that we can access the control FDT using the 'fdt' command, there is no need for this feature. Remove it.

Quoted 7 lines

---
Changes in v3: None
Changes in v2:
- Revert the whole change including the set_working_fdt_addr() part

  common/main.c | 8 --------
  1 file changed, 8 deletions(-)
#21 lore raw

PATCH v3 13/17 sandbox: Allow -c argument to provide a command list

In reply to Simon Glass

This allows passing of entire scripts to sandbox with the -c argument, which is useful for testing. Commands can be delimited with a newline or semicolon.

---
Changes in v3: None
Changes in v2:
- Move sandbox's command list patch from a later series

 arch/sandbox/cpu/start.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/cpu/start.c +1 -1
index 2fcec8b..ae6e16c 100644
@@ -90,7 +90,7 @@ int sandbox_main_loop_init(void)
 
 	/* Execute command if required */
 	if (state->cmd) {
-		run_command(state->cmd, 0);
+		run_command_list(state->cmd, -1, 0);
 		os_exit(state->exit_type);
 	}
 
Signature · 1 line
1.8.2.1
#22 lore raw

PATCH v3 14/17 sandbox: Support 'source' command

In reply to Simon Glass

Enhance the source command to work with sandbox, by using map_sysmem() to convert a ulong address into a pointer.

---
Changes in v3: None
Changes in v2: None

 common/cmd_source.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
common/cmd_source.c +7 -4
index 02a862c..f0d7f52 100644
@@ -36,6 +36,7 @@
 #include <image.h>
 #include <malloc.h>
 #include <asm/byteorder.h>
+#include <asm/io.h>
 #if defined(CONFIG_8xx)
 #include <mpc8xx.h>
 #endif
@@ -44,9 +45,10 @@ int
 source (ulong addr, const char *fit_uname)
 {
 	ulong		len;
-	image_header_t	*hdr;
+	const image_header_t *hdr;
 	ulong		*data;
 	int		verify;
+	void *buf;
 #if defined(CONFIG_FIT)
 	const void*	fit_hdr;
 	int		noffset;
@@ -56,9 +58,10 @@ source (ulong addr, const char *fit_uname)
 
 	verify = getenv_yesno ("verify");
 
-	switch (genimg_get_format ((void *)addr)) {
+	buf = map_sysmem(addr, 0);
+	switch (genimg_get_format(buf)) {
 	case IMAGE_FORMAT_LEGACY:
-		hdr = (image_header_t *)addr;
+		hdr = buf;
 
 		if (!image_check_magic (hdr)) {
 			puts ("Bad magic number\n");
@@ -104,7 +107,7 @@ source (ulong addr, const char *fit_uname)
 			return 1;
 		}
 
-		fit_hdr = (const void *)addr;
+		fit_hdr = buf;
 		if (!fit_check_format (fit_hdr)) {
 			puts ("Bad FIT image format\n");
 			return 1;
Signature · 1 line
1.8.2.1
#23 lore raw

PATCH v3 15/17 fs: Add support for saving data to filesystems

In reply to Simon Glass

Add a new method for saving that filesystems can implement. This mirrors the existing load method.

---
Changes in v3: None
Changes in v2: None

 fs/fs.c      | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/fs.h |  2 ++
 2 files changed, 76 insertions(+)
fs/fs.c +74 -0
index 6f5063c..eee7e23 100644
@@ -47,6 +47,12 @@ static inline int fs_read_unsupported(const char *filename, void *buf,
 	return -1;
 }
 
+static inline int fs_write_unsupported(const char *filename, void *buf,
+				      int offset, int len)
+{
+	return -1;
+}
+
 static inline void fs_close_unsupported(void)
 {
 }
@@ -57,6 +63,7 @@ struct fstype_info {
 		     disk_partition_t *fs_partition);
 	int (*ls)(const char *dirname);
 	int (*read)(const char *filename, void *buf, int offset, int len);
+	int (*write)(const char *filename, void *buf, int offset, int len);
 	void (*close)(void);
 };
 
@@ -94,6 +101,7 @@ static struct fstype_info fstypes[] = {
 		.close = fs_close_unsupported,
 		.ls = fs_ls_unsupported,
 		.read = fs_read_unsupported,
+		.write = fs_write_unsupported,
 	},
 };
 
@@ -125,6 +133,7 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
 			info->close += gd->reloc_off;
 			info->ls += gd->reloc_off;
 			info->read += gd->reloc_off;
+			info->write += gd->reloc_off;
 		}
 		relocated = 1;
 	}
@@ -196,6 +205,30 @@ int fs_read(const char *filename, ulong addr, int offset, int len)
 	return ret;
 }
 
+int fs_write(const char *filename, ulong addr, int offset, int len)
+{
+	struct fstype_info *info = fs_get_info(fs_type);
+	void *buf;
+	int ret;
+
+	/*
+	 * We don't actually know how many bytes are being read, since len==0
+	 * means read the whole file.
+	 */
+	buf = map_sysmem(addr, len);
+	ret = info->write(filename, buf, offset, len);
+	unmap_sysmem(buf);
+
+	/* If we requested a specific number of bytes, check we got it */
+	if (ret >= 0 && len && ret != len) {
+		printf("** Unable to write file %s **\n", filename);
+		ret = -1;
+	}
+	fs_close();
+
+	return ret;
+}
+
 int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		int fstype, int cmdline_base)
 {
@@ -277,3 +310,44 @@ int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 
 	return 0;
 }
+
+int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
+		int fstype, int cmdline_base)
+{
+	unsigned long addr;
+	const char *filename;
+	unsigned long bytes;
+	unsigned long pos;
+	int len;
+	unsigned long time;
+
+	if (argc < 6 || argc > 7)
+		return CMD_RET_USAGE;
+
+	if (fs_set_blk_dev(argv[1], argv[2], fstype))
+		return 1;
+
+	filename = argv[3];
+	addr = simple_strtoul(argv[4], NULL, cmdline_base);
+	bytes = simple_strtoul(argv[5], NULL, cmdline_base);
+	if (argc >= 7)
+		pos = simple_strtoul(argv[6], NULL, cmdline_base);
+	else
+		pos = 0;
+
+	time = get_timer(0);
+	len = fs_write(filename, addr, pos, bytes);
+	time = get_timer(time);
+	if (len <= 0)
+		return 1;
+
+	printf("%d bytes written in %lu ms", len, time);
+	if (time > 0) {
+		puts(" (");
+		print_size(len / time * 1000, "/s");
+		puts(")");
+	}
+	puts("\n");
+
+	return 0;
+}
include/fs.h +2 -0
index b6d69e5..c837bae 100644
@@ -62,5 +62,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		int fstype, int cmdline_base);
 int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 		int fstype);
+int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
+		int fstype, int cmdline_base);
 
 #endif /* _FS_H */
Signature · 1 line
1.8.2.1
#24 lore raw

PATCH v3 16/17 sandbox: fs: Add support for saving files to host filesystem

In reply to Simon Glass

This allows write of files from the host filesystem in sandbox. There is currently no concept of overwriting the file and removing its existing contents - all writing is done on top of what is there. This means that writing 10 bytes to the start of a 1KB file will only update those 10 bytes, not truncate the file to 10 byte slong.

If the file does not exist it is created.

---
Changes in v3: None
Changes in v2: None

 common/cmd_sandbox.c   | 18 ++++++++++++++----
 fs/fs.c                |  1 +
 fs/sandbox/sandboxfs.c | 33 +++++++++++++++++++++++++++++++++
 include/sandboxfs.h    |  1 +
 4 files changed, 49 insertions(+), 4 deletions(-)
common/cmd_sandbox.c +14 -4
index 206a486..a28a844 100644
@@ -32,9 +32,16 @@ static int do_sandbox_ls(cmd_tbl_t *cmdtp, int flag, int argc,
 	return do_ls(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX);
 }
 
+static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc,
+			   char * const argv[])
+{
+	return do_save(cmdtp, flag, argc, argv, FS_TYPE_SANDBOX, 16);
+}
+
 static cmd_tbl_t cmd_sandbox_sub[] = {
-	U_BOOT_CMD_MKENT(load, 3, 0, do_sandbox_load, "", ""),
+	U_BOOT_CMD_MKENT(load, 7, 0, do_sandbox_load, "", ""),
 	U_BOOT_CMD_MKENT(ls, 3, 0, do_sandbox_ls, "", ""),
+	U_BOOT_CMD_MKENT(save, 6, 0, do_sandbox_save, "", ""),
 };
 
 static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -56,8 +63,11 @@ static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
 }
 
 U_BOOT_CMD(
-	sb,	6,	1,	do_sandbox,
+	sb,	8,	1,	do_sandbox,
 	"Miscellaneous sandbox commands",
-	"load host <addr> <filename> [<bytes> <offset>]  - load a file from host\n"
-	"sb ls host <filename>      - save a file to host"
+	"load host <dev> <addr> <filename> [<bytes> <offset>]  - "
+		"load a file from host\n"
+	"sb ls host <filename>                      - list files on host\n"
+	"sb save host <dev> <filename> <addr> <bytes> [<offset>] - "
+		"save a file to host\n"
 );
fs/fs.c +1 -0
index eee7e23..99e516a 100644
@@ -93,6 +93,7 @@ static struct fstype_info fstypes[] = {
 		.close = sandbox_fs_close,
 		.ls = sandbox_fs_ls,
 		.read = fs_read_sandbox,
+		.write = fs_write_sandbox,
 	},
 #endif
 	{
fs/sandbox/sandboxfs.c +33 -0
index 02d26ff..89769e8 100644
@@ -48,6 +48,26 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos,
 	return size;
 }
 
+long sandbox_fs_write_at(const char *filename, unsigned long pos,
+			 void *buffer, unsigned long towrite)
+{
+	ssize_t size;
+	int fd, ret;
+
+	fd = os_open(filename, OS_O_RDWR | OS_O_CREAT);
+	if (fd < 0)
+		return fd;
+	ret = os_lseek(fd, pos, OS_SEEK_SET);
+	if (ret == -1) {
+		os_close(fd);
+		return ret;
+	}
+	size = os_write(fd, buffer, towrite);
+	os_close(fd);
+
+	return size;
+}
+
 int sandbox_fs_ls(const char *dirname)
 {
 	struct os_dirent_node *head, *node;
@@ -81,3 +101,16 @@ int fs_read_sandbox(const char *filename, void *buf, int offset, int len)
 
 	return len_read;
 }
+
+int fs_write_sandbox(const char *filename, void *buf, int offset, int len)
+{
+	int len_written;
+
+	len_written = sandbox_fs_write_at(filename, offset, buf, len);
+	if (len_written == -1) {
+		printf("** Unable to write file %s **\n", filename);
+		return -1;
+	}
+
+	return len_written;
+}
include/sandboxfs.h +1 -0
index f5213ac..8ea8cb7 100644
@@ -26,5 +26,6 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos,
 void sandbox_fs_close(void);
 int sandbox_fs_ls(const char *dirname);
 int fs_read_sandbox(const char *filename, void *buf, int offset, int len);
+int fs_write_sandbox(const char *filename, void *buf, int offset, int len);
 
 #endif
Signature · 1 line
1.8.2.1
#25 lore raw

PATCH v3 17/17 sandbox: config: Enable CONFIG_FIT and CONFIG_CMD_FIT

In reply to Simon Glass

Enable these options to use FITs on sandbox.

---
Changes in v3: None
Changes in v2: None

 include/configs/sandbox.h | 2 ++
 1 file changed, 2 insertions(+)
include/configs/sandbox.h +2 -0
index 8efaded..788207d 100644
@@ -29,6 +29,8 @@
 #define CONFIG_OF_HOSTFILE
 #define CONFIG_OF_LIBFDT
 #define CONFIG_LMB
+#define CONFIG_FIT
+#define CONFIG_CMD_FDT
 
 #define CONFIG_FS_FAT
 #define CONFIG_FS_EXT4
Signature · 1 line
1.8.2.1
#26 lore raw

v3 cover sandbox: Generic board support and other improvements

In reply to Simon Glass
Quoted 18 lines · Simon Glass

This series adds generic board support to sandbox and switches to use this always.

With sandbox it was noticed that turning CONFIG_SYS_GENERIC_BOARD off can cause a build failure if a previous autoconf.mk exists which indicates that generic board is not supported, so a patch is provided to fix this.

It is useful to convert a pointer into an 'address' in the sandbox RAM buffer - the opposite of map_sysmem(). This is added in this series and used in several places.

With sandbox it is easier to read a file from the host than to use the CONFIG_OF_SEPARATE option, since this option requires knowledge of the executable image structure which is not really appropriate on the host system. A new CONFIG_OF_HOSTFILE provides this.

A few related FDT changes are included in this series also.

Quoted 7 lines

The -c option is enhanced to support passing entire scripts to sandbox. This is useful when writing non-trivial test code.

Most of these patches were previously submitted as part of the verified boot effort. This series collects the independent sandbox-related patches together to make it easier to review. THe whole series is marked as version 3 for this reason.

For the series,

And I'd say 3/4/5 should be squashed into one patch, but it's your arch so I'l defer if you think it adds bisect value or similar to do it in that manner.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130422/1cf33901/attachment.pgp>
#27 lore raw

v3 cover sandbox: Generic board support and other improvements

Hi Tom,

Quoted 28 lines · Tom Rini
Quoted 18 lines · Simon Glass

This series adds generic board support to sandbox and switches to use this always.

With sandbox it was noticed that turning CONFIG_SYS_GENERIC_BOARD off can cause a build failure if a previous autoconf.mk exists which indicates that generic board is not supported, so a patch is provided to fix this.

It is useful to convert a pointer into an 'address' in the sandbox RAM buffer - the opposite of map_sysmem(). This is added in this series and used in several places.

With sandbox it is easier to read a file from the host than to use the CONFIG_OF_SEPARATE option, since this option requires knowledge of the executable image structure which is not really appropriate on the host system. A new CONFIG_OF_HOSTFILE provides this.

A few related FDT changes are included in this series also.

Quoted 7 lines

The -c option is enhanced to support passing entire scripts to sandbox. This is useful when writing non-trivial test code.

Most of these patches were previously submitted as part of the verified boot effort. This series collects the independent sandbox-related patches together to make it easier to review. THe whole series is marked as version 3 for this reason.

Quoted 6 lines

For the series,

And I'd say 3/4/5 should be squashed into one patch, but it's your arch so I'l defer if you think it adds bisect value or similar to do it in that manner.

I did that so that it could be kind-of an example of how this can be done for an arch, given that I am not planning to convert the rest. By removing the dead code in a separate step it seemed a bit clearer to me.

But it's fine either way - I will squash it and resend.

Quoted 3 lines

--
Tom

Regards,
Simon

#28 lore raw

v3 cover sandbox: Generic board support and other improvements

Hi Tom,

Quoted 38 lines · Simon Glass

Hi Tom,

Quoted 28 lines · Tom Rini
Quoted 18 lines · Simon Glass

This series adds generic board support to sandbox and switches to use this always.

With sandbox it was noticed that turning CONFIG_SYS_GENERIC_BOARD off can cause a build failure if a previous autoconf.mk exists which indicates that generic board is not supported, so a patch is provided to fix this.

It is useful to convert a pointer into an 'address' in the sandbox RAM buffer - the opposite of map_sysmem(). This is added in this series and used in several places.

With sandbox it is easier to read a file from the host than to use the CONFIG_OF_SEPARATE option, since this option requires knowledge of the executable image structure which is not really appropriate on the host system. A new CONFIG_OF_HOSTFILE provides this.

A few related FDT changes are included in this series also.

Quoted 7 lines

The -c option is enhanced to support passing entire scripts to sandbox. This is useful when writing non-trivial test code.

Most of these patches were previously submitted as part of the verified boot effort. This series collects the independent sandbox-related patches together to make it easier to review. THe whole series is marked as version 3 for this reason.

Quoted 6 lines

For the series,

And I'd say 3/4/5 should be squashed into one patch, but it's your arch so I'l defer if you think it adds bisect value or similar to do it in that manner.

Quoted 6 lines

I did that so that it could be kind-of an example of how this can be done for an arch, given that I am not planning to convert the rest. By removing the dead code in a separate step it seemed a bit clearer to me.

But it's fine either way - I will squash it and resend.

I have put this series in patchwork as:

http://patchwork.ozlabs.org/bundle/sjg/sandbox/

and below is a pull request if you want to take that instead.

I did not go through and add your Reviewed-by to each patch. Am I supposed to do that?

The following changes since commit d10f68ae47b67acab8b110b5c605dde4197a1820:

Prepare v2013.04 (2013-04-19 10:25:43 -0400)

are available in the git repository at:

git://git.denx.de/u-boot-x86.git sandbox

for you to fetch changes up to 3a95570c609a35f60d4c798948f83f8427544ff2:

sandbox: config: Enable CONFIG_FIT and CONFIG_CMD_FIT (2013-04-26
06:00:06 -0700)

----------------------------------------------------------------
Simon Glass (15):
Trigger generic board error only when building
sandbox: Provide a way to map from host RAM to U-Boot RAM
sandbox: Switch over to generic board
sandbox: Add CONFIG_OF_HOSTFILE to read FDT from host file
fdt: Add a parameter to fdt_valid()
Add getenv_hex() to return an environment variable as hex
fdt: Allow fdt command to check and update control FDT
sandbox: fdt: Support fdt command for sandbox
fdt: Skip checking FDT if the pointer is NULL Revert "fdt- Tell the FDT library where the device tree is"
sandbox: Allow -c argument to provide a command list
sandbox: Support 'source' command
fs: Add support for saving data to filesystems
sandbox: fs: Add support for saving files to host filesystem
sandbox: config: Enable CONFIG_FIT and CONFIG_CMD_FIT

 Makefile                          |  10 ++
 arch/sandbox/config.mk            |   5 +-
 arch/sandbox/cpu/cpu.c            |   5 +
 arch/sandbox/cpu/start.c          |   9 +-
 arch/sandbox/include/asm/io.h     |   8 ++
 arch/sandbox/include/asm/state.h  |   1 +
 arch/sandbox/include/asm/u-boot.h |  22 +--
 arch/sandbox/lib/Makefile         |   1 -
 arch/sandbox/lib/board.c          | 285 --------------------------------------
 board/sandbox/sandbox/sandbox.c   |   2 +-
 common/board_f.c                  | 106 ++++++++++++--
 common/board_r.c                  |   8 +-
 common/cmd_fdt.c                  |  87 ++++++++----
 common/cmd_nvedit.c               |  15 ++
 common/cmd_sandbox.c              |  18 ++-
 common/cmd_source.c               |  11 +-
 common/main.c                     |   8 --
 config.mk                         |   4 +-
 doc/README.fdt-control            |   6 +-
 fs/fs.c                           |  75 ++++++++++
 fs/sandbox/sandboxfs.c            |  33 +++++
 include/asm-generic/sections.h    |   2 +-
 include/common.h                  |  18 +++
 include/configs/sandbox.h         |  11 +-
 include/fs.h                      |   2 +
 include/sandboxfs.h               |   1 +
 lib/fdtdec.c                      |   5 +-
 27 files changed, 383 insertions(+), 375 deletions(-)
 delete mode 100644 arch/sandbox/lib/board.c

Regards,
Simon

#29 lore raw

v3 cover sandbox: Generic board support and other improvements

Quoted 46 lines · Simon Glass

Hi Tom,

Quoted 43 lines · Simon Glass

Hi Tom,

Quoted 28 lines · Tom Rini
Quoted 18 lines · Simon Glass

This series adds generic board support to sandbox and switches to use this always.

With sandbox it was noticed that turning CONFIG_SYS_GENERIC_BOARD off can cause a build failure if a previous autoconf.mk exists which indicates that generic board is not supported, so a patch is provided to fix this.

It is useful to convert a pointer into an 'address' in the sandbox RAM buffer - the opposite of map_sysmem(). This is added in this series and used in several places.

With sandbox it is easier to read a file from the host than to use the CONFIG_OF_SEPARATE option, since this option requires knowledge of the executable image structure which is not really appropriate on the host system. A new CONFIG_OF_HOSTFILE provides this.

A few related FDT changes are included in this series also.

Quoted 7 lines

The -c option is enhanced to support passing entire scripts to sandbox. This is useful when writing non-trivial test code.

Most of these patches were previously submitted as part of the verified boot effort. This series collects the independent sandbox-related patches together to make it easier to review. THe whole series is marked as version 3 for this reason.

Quoted 6 lines

For the series,

And I'd say 3/4/5 should be squashed into one patch, but it's your arch so I'l defer if you think it adds bisect value or similar to do it in that manner.

I did that so that it could be kind-of an example of how this can be done for an arch, given that I am not planning to convert the rest. By removing the dead code in a separate step it seemed a bit clearer to me.

Quoted 6 lines
Quoted 1 line

But it's fine either way - I will squash it and resend.

I have put this series in patchwork as:

http://patchwork.ozlabs.org/bundle/sjg/sandbox/

This has now been applied to u-boot/master, thanks!

Quoted 4 lines

and below is a pull request if you want to take that instead.

I did not go through and add your Reviewed-by to each patch. Am I supposed to do that?

No, that pain is supposed to help spur us into improving patchwork or the new tool we talked about back at LSM.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130501/992de569/attachment.pgp>