[U-Boot] [PATCH v3 0/17] 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

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.
Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v3: None Changes in v2: None
Makefile | 10 ++++++++++ config.mk | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile index 3fd6d15..42f2b02 100644 --- a/Makefile +++ b/Makefile @@ -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. diff --git a/config.mk b/config.mk index 1fd109f..16a4fdb 100644 --- a/config.mk +++ b/config.mk @@ -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

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.
Signed-off-by: Simon Glass sjg@chromium.org --- 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(+)
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index b2788d5..dd8d495 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -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) { } diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index d8c0236..54051a3 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -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); diff --git a/include/common.h b/include/common.h index 0cfa6a8..76c79ae 100644 --- a/include/common.h +++ b/include/common.h @@ -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__ */

Add generic board support for sandbox.
Signed-off-by: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index 4fd0d4e..aeb9da9 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -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 diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index 54051a3..0c022f1 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -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 diff --git a/arch/sandbox/include/asm/u-boot.h b/arch/sandbox/include/asm/u-boot.h index de8120a..7b93acb 100644 --- a/arch/sandbox/include/asm/u-boot.h +++ b/arch/sandbox/include/asm/u-boot.h @@ -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
diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile index fbe579b..b1ae168 100644 --- a/arch/sandbox/lib/Makefile +++ b/arch/sandbox/lib/Makefile @@ -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) diff --git a/board/sandbox/sandbox/sandbox.c b/board/sandbox/sandbox/sandbox.c index 9883013..8bdba92 100644 --- a/board/sandbox/sandbox/sandbox.c +++ b/board/sandbox/sandbox/sandbox.c @@ -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; } diff --git a/common/board_f.c b/common/board_f.c index 00ca811..2045055 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -49,9 +49,11 @@ #include <mpc5xxx.h> #endif
+#include <os.h> #include <post.h> #include <spi.h> #include <watchdog.h> +#include <asm/errno.h> #include <asm/io.h> #ifdef CONFIG_MP #include <asm/mp.h> @@ -61,6 +63,9 @@ #include <asm/init_helpers.h> #include <asm/relocate.h> #endif +#ifdef CONFIG_SANDBOX +#include <asm/state.h> +#endif #include <linux/compiler.h>
/* @@ -155,6 +160,7 @@ static int init_baud_rate(void)
static int display_text_info(void) { +#ifndef CONFIG_SANDBOX ulong bss_start, bss_end;
#ifdef CONFIG_SYS_SYM_OFFSETS @@ -166,6 +172,7 @@ static int display_text_info(void) #endif debug("U-Boot code: %08X -> %08lX BSS: -> %08lX\n", CONFIG_SYS_TEXT_BASE, bss_start, bss_end); +#endif
#ifdef CONFIG_MODEM_SUPPORT debug("Modem Support enabled\n"); @@ -284,6 +291,8 @@ static int setup_mon_len(void) { #ifdef CONFIG_SYS_SYM_OFFSETS gd->mon_len = _bss_end_ofs; +#elif defined(CONFIG_SANDBOX) + gd->mon_len = (ulong)&_end - (ulong)_init; #else /* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */ gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE; @@ -296,6 +305,17 @@ __weak int arch_cpu_init(void) return 0; }
+#ifdef CONFIG_SANDBOX +static int setup_ram_buf(void) +{ + gd->arch.ram_buf = os_malloc(CONFIG_SYS_SDRAM_SIZE); + assert(gd->arch.ram_buf); + gd->ram_size = CONFIG_SYS_SDRAM_SIZE; + + return 0; +} +#endif + static int setup_fdt(void) { #ifdef CONFIG_OF_EMBED @@ -470,7 +490,7 @@ static int reserve_malloc(void) static int reserve_board(void) { gd->dest_addr_sp -= sizeof(bd_t); - gd->bd = (bd_t *)gd->dest_addr_sp; + gd->bd = (bd_t *)map_sysmem(gd->dest_addr_sp, sizeof(bd_t)); memset(gd->bd, '\0', sizeof(bd_t)); debug("Reserving %zu Bytes for Board Info at: %08lx\n", sizeof(bd_t), gd->dest_addr_sp); @@ -489,7 +509,7 @@ static int setup_machine(void) static int reserve_global_data(void) { gd->dest_addr_sp -= sizeof(gd_t); - gd->new_gd = (gd_t *)gd->dest_addr_sp; + gd->new_gd = (gd_t *)map_sysmem(gd->dest_addr_sp, sizeof(gd_t)); debug("Reserving %zu Bytes for Global Data at: %08lx\n", sizeof(gd_t), gd->dest_addr_sp); return 0; @@ -506,9 +526,9 @@ static int reserve_fdt(void) gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
gd->dest_addr_sp -= gd->fdt_size; - gd->new_fdt = (void *)gd->dest_addr_sp; - debug("Reserving %lu Bytes for FDT at: %p\n", - gd->fdt_size, gd->new_fdt); + gd->new_fdt = map_sysmem(gd->dest_addr_sp, gd->fdt_size); + debug("Reserving %lu Bytes for FDT at: %08lx\n", + gd->fdt_size, gd->dest_addr_sp); }
return 0; @@ -709,8 +729,9 @@ static int setup_reloc(void) memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
debug("Relocation Offset is: %08lx\n", gd->reloc_off); - debug("Relocating to %08lx, new gd at %p, sp at %08lx\n", - gd->dest_addr, gd->new_gd, gd->dest_addr_sp); + debug("Relocating to %08lx, new gd at %08lx, sp at %08lx\n", + gd->dest_addr, (ulong)map_to_sysmem(gd->new_gd), + gd->dest_addr_sp);
return 0; } @@ -736,6 +757,8 @@ static int jump_to_copy(void) * (CPU cache) */ board_init_f_r_trampoline(gd->start_addr_sp); +#elif defined(CONFIG_SANDBOX) + board_init_r(gd->new_gd, 0); #else relocate_code(gd->dest_addr_sp, gd->new_gd, gd->dest_addr); #endif @@ -758,6 +781,9 @@ static init_fnc_t init_sequence_f[] = { !defined(CONFIG_MPC86xx) && !defined(CONFIG_X86) zero_global_data, #endif +#ifdef CONFIG_SANDBOX + setup_ram_buf, +#endif setup_fdt, setup_mon_len, #if defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) @@ -816,8 +842,11 @@ static init_fnc_t init_sequence_f[] = { init_baud_rate, /* initialze baudrate settings */ serial_init, /* serial communications setup */ console_init_f, /* stage 1 init of console */ -#if defined(CONFIG_X86) && defined(CONFIG_OF_CONTROL) - prepare_fdt, /* TODO(sjg@chromium.org): remove */ +#ifdef CONFIG_SANDBOX + sandbox_early_getopt_check, +#endif +#ifdef CONFIG_OF_CONTROL + fdtdec_prepare_fdt, #endif display_options, /* say that we are here */ display_text_info, /* show debugging info if required */ @@ -1007,5 +1036,9 @@ void board_init_f_r(void) void hang(void) { puts("### ERROR ### Please RESET the board ###\n"); +#ifdef CONFIG_SANDBOX + os_exit(0); +#else for (;;); +#endif } diff --git a/common/board_r.c b/common/board_r.c index 2b17fa6..f801e41 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -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(); diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index cca1edb..4b39844 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -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[]; diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 406da43..da7cc9a 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -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,\ diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 92fbefe..60369fb 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -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;

On Sat, Apr 20, 2013 at 11:42:38AM -0700, Simon Glass wrote:
Add generic board support for sandbox.
[snip]
diff --git a/arch/sandbox/include/asm/u-boot.h b/arch/sandbox/include/asm/u-boot.h index de8120a..7b93acb 100644 --- a/arch/sandbox/include/asm/u-boot.h +++ b/arch/sandbox/include/asm/u-boot.h @@ -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]
diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile index fbe579b..b1ae168 100644 --- a/arch/sandbox/lib/Makefile +++ b/arch/sandbox/lib/Makefile @@ -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.

On Mon, Apr 22, 2013 at 10:03:10AM -0400, Tom Rini wrote:
On Sat, Apr 20, 2013 at 11:42:38AM -0700, Simon Glass wrote:
Add generic board support for sandbox.
[snip]
diff --git a/arch/sandbox/include/asm/u-boot.h b/arch/sandbox/include/asm/u-boot.h index de8120a..7b93acb 100644 --- a/arch/sandbox/include/asm/u-boot.h +++ b/arch/sandbox/include/asm/u-boot.h @@ -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]
diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile index fbe579b..b1ae168 100644 --- a/arch/sandbox/lib/Makefile +++ b/arch/sandbox/lib/Makefile @@ -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.
In short, squash 3/4/5 into one patch.

Hi Tom,
On Mon, Apr 22, 2013 at 7:11 AM, Tom Rini trini@ti.com wrote:
On Mon, Apr 22, 2013 at 10:03:10AM -0400, Tom Rini wrote:
On Sat, Apr 20, 2013 at 11:42:38AM -0700, Simon Glass wrote:
Add generic board support for sandbox.
[snip]
diff --git a/arch/sandbox/include/asm/u-boot.h b/arch/sandbox/include/asm/u-boot.h index de8120a..7b93acb 100644 --- a/arch/sandbox/include/asm/u-boot.h +++ b/arch/sandbox/include/asm/u-boot.h @@ -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]
diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile index fbe579b..b1ae168 100644 --- a/arch/sandbox/lib/Makefile +++ b/arch/sandbox/lib/Makefile @@ -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.
In short, squash 3/4/5 into one patch.
OK I have done this and resent this one combined patch as v4.
Regards, Simon

Select CONFIG_SYS_GENERIC_BOARD for sandbox now that this is supported.
Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v3: None Changes in v2: None
arch/sandbox/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index aeb9da9..988b52c 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -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

We can use generic board for sandbox, so the old board init code can now be removed.
Signed-off-by: Simon Glass sjg@chromium.org --- 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
diff --git a/arch/sandbox/include/asm/u-boot.h b/arch/sandbox/include/asm/u-boot.h index 7b93acb..5bea1f2 100644 --- a/arch/sandbox/include/asm/u-boot.h +++ b/arch/sandbox/include/asm/u-boot.h @@ -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 diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile index b1ae168..3aad574 100644 --- a/arch/sandbox/lib/Makefile +++ b/arch/sandbox/lib/Makefile @@ -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) diff --git a/arch/sandbox/lib/board.c b/arch/sandbox/lib/board.c deleted file mode 100644 index 3752fab..0000000 --- a/arch/sandbox/lib/board.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 2011 The Chromium OS Authors. - * - * (C) Copyright 2002-2006 - * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * (C) Copyright 2002 - * Sysgo Real-Time Solutions, GmbH <www.elinos.com> - * Marius Groeger mgroeger@sysgo.de - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -/* - * This file was taken from ARM and changed to remove things we don't - * need. This is most of it, so have tried to avoid being over-zealous! - * For example, we want to have an emulation of the 'DRAM' used by - * U-Boot. - * - * has been talk upstream of unifying the architectures w.r.t board.c, - * so the less change here the better. - */ - -#include <common.h> -#include <command.h> -#include <malloc.h> -#include <stdio_dev.h> -#include <timestamp.h> -#include <version.h> -#include <serial.h> - -#include <os.h> - -DECLARE_GLOBAL_DATA_PTR; - -static gd_t gd_mem; - -/************************************************************************ - * Init Utilities * - ************************************************************************ - * Some of this code should be moved into the core functions, - * or dropped completely, - * but let's get it working (again) first... - */ - -static int display_banner(void) -{ - display_options(); - - return 0; -} - -/** - * Configure and report on the DRAM configuration, which in our case is - * fairly simple. - */ -static int display_dram_config(void) -{ - ulong size = 0; - int i; - - debug("RAM Configuration:\n"); - - for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { -#ifdef DEBUG - printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start); - print_size(gd->bd->bi_dram[i].size, "\n"); -#endif - size += gd->bd->bi_dram[i].size; - } - puts("DRAM: "); - print_size(size, "\n"); - return 0; -} - -/* - * Breathe some life into the board... - * - * Initialize a serial port as console, and carry out some hardware - * tests. - * - * The first part of initialization is running from Flash memory; - * its main purpose is to initialize the RAM so that we - * can relocate the monitor code to RAM. - */ - -/* - * All attempts to come up with a "common" initialization sequence - * that works for all boards and architectures failed: some of the - * requirements are just _too_ different. To get rid of the resulting - * mess of board dependent #ifdef'ed code we now make the whole - * initialization sequence configurable to the user. - * - * The requirements for any new initalization function is simple: it - * receives a pointer to the "global data" structure as it's only - * argument, and returns an integer return code, where 0 means - * "continue" and != 0 means "fatal error, hang the system". - */ -typedef int (init_fnc_t) (void); - -void __dram_init_banksize(void) -{ - gd->bd->bi_dram[0].start = 0; - gd->bd->bi_dram[0].size = gd->ram_size; -} - -void dram_init_banksize(void) - __attribute__((weak, alias("__dram_init_banksize"))); - -init_fnc_t *init_sequence[] = { -#if defined(CONFIG_ARCH_CPU_INIT) - arch_cpu_init, /* basic arch cpu dependent setup */ -#endif -#if defined(CONFIG_BOARD_EARLY_INIT_F) - board_early_init_f, -#endif - timer_init, /* initialize timer */ - env_init, /* initialize environment */ - serial_init, /* serial communications setup */ - console_init_f, /* stage 1 init of console */ - sandbox_early_getopt_check, /* process command line flags (err/help) */ - display_banner, /* say that we are here */ -#if defined(CONFIG_DISPLAY_CPUINFO) - print_cpuinfo, /* display cpu info (and speed) */ -#endif -#if defined(CONFIG_DISPLAY_BOARDINFO) - checkboard, /* display board info */ -#endif - dram_init, /* configure available RAM banks */ - NULL, -}; - -void board_init_f(ulong bootflag) -{ - init_fnc_t **init_fnc_ptr; - uchar *mem; - unsigned long addr_sp, addr, size; - - gd = &gd_mem; - assert(gd); - - memset((void *)gd, 0, sizeof(gd_t)); - -#if defined(CONFIG_OF_EMBED) - /* Get a pointer to the FDT */ - gd->fdt_blob = _binary_dt_dtb_start; -#elif defined(CONFIG_OF_SEPARATE) - /* FDT is at end of image */ - gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE); -#endif - - for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { - if ((*init_fnc_ptr)() != 0) - hang(); - } - - size = CONFIG_SYS_SDRAM_SIZE; - mem = os_malloc(CONFIG_SYS_SDRAM_SIZE); - - assert(mem); - gd->arch.ram_buf = mem; - addr = (ulong)(mem + size); - - /* - * reserve memory for malloc() arena - */ - addr_sp = addr - TOTAL_MALLOC_LEN; - debug("Reserving %dk for malloc() at: %08lx\n", - TOTAL_MALLOC_LEN >> 10, addr_sp); - /* - * (permanently) allocate a Board Info struct - * and a permanent copy of the "global" data - */ - addr_sp -= sizeof(bd_t); - gd->bd = (bd_t *) addr_sp; - debug("Reserving %zu Bytes for Board Info at: %08lx\n", - sizeof(bd_t), addr_sp); - - /* Ram ist board specific, so move it to board code ... */ - dram_init_banksize(); - display_dram_config(); /* and display it */ - - /* We don't relocate, so just run the post-relocation code */ - board_init_r(NULL, 0); - - /* NOTREACHED - no way out of command loop except booting */ -} - -/************************************************************************ - * - * This is the next part if the initialization sequence: we are now - * running from RAM and have a "normal" C environment, i. e. global - * data can be written, BSS has been cleared, the stack size in not - * that critical any more, etc. - * - ************************************************************************ - */ - -void board_init_r(gd_t *id, ulong dest_addr) -{ - - if (id) - gd = id; - - gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ - - serial_initialize(); - -#ifdef CONFIG_POST - post_output_backlog(); -#endif - - /* The Malloc area is at the top of simulated DRAM */ - mem_malloc_init((ulong)gd->arch.ram_buf + gd->ram_size - - TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN); - - /* initialize environment */ - env_relocate(); - - stdio_init(); /* get the devices list going. */ - - jumptable_init(); - - console_init_r(); /* fully init console as a device */ - -#if defined(CONFIG_DISPLAY_BOARDINFO_LATE) - checkboard(); -#endif - -#if defined(CONFIG_ARCH_MISC_INIT) - /* miscellaneous arch dependent initialisations */ - arch_misc_init(); -#endif -#if defined(CONFIG_MISC_INIT_R) - /* miscellaneous platform dependent initialisations */ - misc_init_r(); -#endif - - /* set up exceptions */ - interrupt_init(); - /* enable exceptions */ - enable_interrupts(); - -#ifdef CONFIG_BOARD_LATE_INIT - board_late_init(); -#endif - -#ifdef CONFIG_POST - post_run(NULL, POST_RAM | post_bootmode_get(0)); -#endif - - sandbox_main_loop_init(); - - /* - * For now, run the main loop. Later we might let this be done - * in the main program. - */ - while (1) - main_loop(); - - /* NOTREACHED - no way out of command loop except booting */ -} - -void hang(void) -{ - puts("### ERROR ### Please RESET the board ###\n"); - for (;;) - ; -}

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.
Signed-off-by: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 5287fd5..2fcec8b 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -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; diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index 2b62b46..9552708 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -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 */ diff --git a/common/board_f.c b/common/board_f.c index 2045055..3a6638f 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -31,6 +31,7 @@ #include <version.h> #include <environment.h> #include <fdtdec.h> +#include <fs.h> #if defined(CONFIG_CMD_IDE) #include <ide.h> #endif @@ -305,6 +306,55 @@ __weak int arch_cpu_init(void) return 0; }
+#ifdef CONFIG_OF_HOSTFILE + +#define CHECK(x) err = (x); if (err) goto failed; + +/* Create an empty device tree blob */ +static int make_empty_fdt(void *fdt) +{ + int err; + + CHECK(fdt_create(fdt, 256)); + CHECK(fdt_finish_reservemap(fdt)); + CHECK(fdt_begin_node(fdt, "")); + CHECK(fdt_end_node(fdt)); + CHECK(fdt_finish(fdt)); + + return 0; +failed: + printf("Unable to create empty FDT: %s\n", fdt_strerror(err)); + return -EACCES; +} + +static int read_fdt_from_file(void) +{ + struct sandbox_state *state = state_get_current(); + void *blob; + int size; + int err; + + blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0); + if (!state->fdt_fname) { + err = make_empty_fdt(blob); + if (!err) + goto done; + return err; + } + err = fs_set_blk_dev("host", NULL, FS_TYPE_SANDBOX); + if (err) + return err; + size = fs_read(state->fdt_fname, CONFIG_SYS_FDT_LOAD_ADDR, 0, 0); + if (size < 0) + return -EIO; + +done: + gd->fdt_blob = blob; + + return 0; +} +#endif + #ifdef CONFIG_SANDBOX static int setup_ram_buf(void) { @@ -328,6 +378,11 @@ static int setup_fdt(void) # else gd->fdt_blob = (ulong *)&_end; # endif +#elif defined(CONFIG_OF_HOSTFILE) + if (read_fdt_from_file()) { + puts("Failed to read control FDT\n"); + return -1; + } #endif /* Allow the early environment to override the fdt address */ gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16, diff --git a/doc/README.fdt-control b/doc/README.fdt-control index 8352835..5963f78 100644 --- a/doc/README.fdt-control +++ b/doc/README.fdt-control @@ -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 diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index da7cc9a..8efaded 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -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

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().
Signed-off-by: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index ac77a08..07072f3 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -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;

On 04/20/2013 02:42 PM, Simon Glass wrote:
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().
Signed-off-by: Simon Glass sjg@chromium.org
Acked-by: Gerald Van Baren vanbaren@cideas.com
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(-)

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.
Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v3: None Changes in v2: None
common/cmd_nvedit.c | 15 +++++++++++++++ include/common.h | 13 +++++++++++++ 2 files changed, 28 insertions(+)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 68b0f4f..d893aa1 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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[]) { diff --git a/include/common.h b/include/common.h index 76c79ae..28aa4b9 100644 --- a/include/common.h +++ b/include/common.h @@ -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)

There is an existing fdt command to deal with the working FDT. Enhance this to support the control FDT also (CONFIG_OF_CONTROL).
Signed-off-by: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 07072f3..e582961 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -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

On 04/20/2013 02:42 PM, Simon Glass wrote:
There is an existing fdt command to deal with the working FDT. Enhance this to support the control FDT also (CONFIG_OF_CONTROL).
Signed-off-by: Simon Glass sjg@chromium.org
Acked-by: Gerald Van Baren vanbaren@cideas.com
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(-)

By using map_sysmem() we can get the fdt command to work correctly with sandbox.
Signed-off-by: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index e582961..edefd77 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -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;

On 04/20/2013 02:42 PM, Simon Glass wrote:
By using map_sysmem() we can get the fdt command to work correctly with sandbox.
Signed-off-by: Simon Glass sjg@chromium.org
Acked-by: Gerald Van Baren vanbaren@cideas.com
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(-)

If we have no FDT, don't attempt to read from it. This allows sandbox to run without an FDT if required.
Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v3: None Changes in v2: - Fix checkpatch checks about parenthesis alignment
lib/fdtdec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 60369fb..ac1fe0b 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -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");

On 04/20/2013 02:42 PM, Simon Glass wrote:
If we have no FDT, don't attempt to read from it. This allows sandbox to run without an FDT if required.
Signed-off-by: Simon Glass sjg@chromium.org
Acked-by: Gerald Van Baren vanbaren@cideas.com
Changes in v3: None Changes in v2:
Fix checkpatch checks about parenthesis alignment
lib/fdtdec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)

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.
Signed-off-by: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/common/main.c b/common/main.c index a15f020..953ef29 100644 --- a/common/main.c +++ b/common/main.c @@ -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++;

On 04/20/2013 02:42 PM, Simon Glass wrote:
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.
Signed-off-by: Simon Glass sjg@chromium.org
Acked-by: Gerald Van Baren vanbaren@cideas.com
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(-)

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.
Signed-off-by: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 2fcec8b..ae6e16c 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -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); }

Enhance the source command to work with sandbox, by using map_sysmem() to convert a ulong address into a pointer.
Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v3: None Changes in v2: None
common/cmd_source.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/common/cmd_source.c b/common/cmd_source.c index 02a862c..f0d7f52 100644 --- a/common/cmd_source.c +++ b/common/cmd_source.c @@ -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;

Add a new method for saving that filesystems can implement. This mirrors the existing load method.
Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v3: None Changes in v2: None
fs/fs.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/fs.h | 2 ++ 2 files changed, 76 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c index 6f5063c..eee7e23 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -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; +} diff --git a/include/fs.h b/include/fs.h index b6d69e5..c837bae 100644 --- a/include/fs.h +++ b/include/fs.h @@ -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 */

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.
Signed-off-by: Simon Glass sjg@chromium.org --- 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(-)
diff --git a/common/cmd_sandbox.c b/common/cmd_sandbox.c index 206a486..a28a844 100644 --- a/common/cmd_sandbox.c +++ b/common/cmd_sandbox.c @@ -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" ); diff --git a/fs/fs.c b/fs/fs.c index eee7e23..99e516a 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -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 { diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c index 02d26ff..89769e8 100644 --- a/fs/sandbox/sandboxfs.c +++ b/fs/sandbox/sandboxfs.c @@ -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; +} diff --git a/include/sandboxfs.h b/include/sandboxfs.h index f5213ac..8ea8cb7 100644 --- a/include/sandboxfs.h +++ b/include/sandboxfs.h @@ -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

Enable these options to use FITs on sandbox.
Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v3: None Changes in v2: None
include/configs/sandbox.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 8efaded..788207d 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -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

On Sat, Apr 20, 2013 at 11:42:35AM -0700, Simon Glass wrote:
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.
For the series, Reviewed-by: Tom Rini trini@ti.com
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.

Hi Tom,
On Mon, Apr 22, 2013 at 8:18 AM, Tom Rini trini@ti.com wrote:
On Sat, Apr 20, 2013 at 11:42:35AM -0700, Simon Glass wrote:
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.
For the series, Reviewed-by: Tom Rini trini@ti.com
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.
-- Tom
Regards, Simon

Hi Tom,
On Mon, Apr 22, 2013 at 9:08 AM, Simon Glass sjg@chromium.org wrote:
Hi Tom,
On Mon, Apr 22, 2013 at 8:18 AM, Tom Rini trini@ti.com wrote:
On Sat, Apr 20, 2013 at 11:42:35AM -0700, Simon Glass wrote:
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.
For the series, Reviewed-by: Tom Rini trini@ti.com
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.
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

On Fri, Apr 26, 2013 at 06:10:15AM -0700, Simon Glass wrote:
Hi Tom,
On Mon, Apr 22, 2013 at 9:08 AM, Simon Glass sjg@chromium.org wrote:
Hi Tom,
On Mon, Apr 22, 2013 at 8:18 AM, Tom Rini trini@ti.com wrote:
On Sat, Apr 20, 2013 at 11:42:35AM -0700, Simon Glass wrote:
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.
For the series, Reviewed-by: Tom Rini trini@ti.com
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.
I have put this series in patchwork as:
This has now been applied to u-boot/master, thanks!
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.
participants (3)
-
Jerry Van Baren
-
Simon Glass
-
Tom Rini