Add additional sandbox features and infrastructure
Subsystems (8)
cover Add additional sandbox features and infrastructure
At present sandbox only supports a basic set of features. To help address this, a recent series added SPI and SPI flash support; this series expands the coverage further.
Firstly SDL is used to provide LCD and audio support. Sandbox gains its own LCD driver which can display images, host a command line, etc. The audio support is basic and needs additional work, but it is a starting point. SDL also provides a keyboard emulation (using the Chrome OS EC code as a base).
Secondly a TPM emulation is added. This does not include all features (the implementation is quite simplistic) but it is enough to do basic secure boot operations.
Finally, various pieces of useful infrastructure are adding, including:
- loading and saving of the emulated SDRAM to permit test runs to carry over state
- loading and saving of general sandbox state (for example a driver can save its stage and reload it on the next run)
- support for using bootm to load a kernel
- providing a device tree for use by sandbox
- block device emulation using host files
- a means to jump to another U-Boot while preserving state (useful for test environments which want to run a series of tests with script-selectable state)
- allowing the console to be active on start-up so that errors are not silent supressed
The block device emulation provides access to filesystems from sandbox which should make it possible to write comprehensive filesystem tests.
Major functions which still remain without sandbox support are I2C, networking and USB.
Che-Liang Chiou (1):
sandbox: tpm: Fix nvwrite command
Henrik Nordström (1):
sandbox: block driver using host file/device as backing store
Simon Glass (29):
Add crc8 routine
sandbox: Use system headers first for sandbox's os.c
sandbox: Use uint64_t instead of u64 for time
sandbox: Increase memory size to 32MB
sandbox: spi: Adjust 'sf test' to work on sandbox
sandbox: Build a device tree file for sandbox
sandbox: config: Don't use 64-bit physical memory
sandbox: Correct data sizes and printf() strings in fdtdec.c
sandbox: Use os functions to read host device tree
sandbox: Improve/augment memory allocation functions
sandbox: Correct help message <arg> garbling
sandbox: Allow return from board_init_f()
sandbox: Implement the bootm command for sandbox
sandbox: Allow the console to work earlier
sandbox: Add -i option to enter interactive mode
sandbox: Allow reading/writing of RAM buffer
sandbox: Add facility to save/restore sandbox state
sandbox: tpm: Add TPM emulation
sandbox: dts: Add display and keyboard to sandbox
sandbox: Add a prototype for cleanup_before_linux()
cros_ec: Add an enum for the number of flash regions
fdt: Add a function for reading a flash map entry
cros_ec: Add a function for decoding the Chrome OS EC flashmap
cros_ec: sandbox: Add Chrome OS EC emulation
sandbox: Add os_jump_to_image() to run another executable
sandbox: Add -j option to indicate a jump from a previous U-Boot
sandbox: Add SDL library for LCD, keyboard, audio
sandbox: Add a simple sound driver
sandbox: Add LCD driver
Vadim Bendebury (1):
cros_ec: Move EC interface into common library
Makefile | 1 + arch/sandbox/config.mk | 7 + arch/sandbox/cpu/Makefile | 12 +- arch/sandbox/cpu/cpu.c | 21 +- arch/sandbox/cpu/os.c | 187 ++++++++- arch/sandbox/cpu/sdl.c | 334 +++++++++++++++ arch/sandbox/cpu/start.c | 121 +++++- arch/sandbox/cpu/state.c | 353 ++++++++++++++++ arch/sandbox/include/asm/arch-sandbox/sound.h | 14 + arch/sandbox/include/asm/global_data.h | 2 +- arch/sandbox/include/asm/sdl.h | 20 + arch/sandbox/include/asm/state.h | 132 +++++- arch/sandbox/include/asm/types.h | 4 +- arch/sandbox/include/asm/u-boot-sandbox.h | 5 + board/samsung/smdk5250/exynos5-dt.c | 5 - board/sandbox/dts/sandbox.dts | 91 +++++ board/sandbox/sandbox/sandbox.c | 19 +- common/Makefile | 1 + common/board_f.c | 63 ++- common/cmd_sandbox.c | 64 +++ common/cmd_sf.c | 14 +- common/console.c | 16 +- common/cros_ec.c | 44 ++ common/lcd.c | 21 +- config.mk | 9 +- disk/part.c | 23 +- doc/device-tree-bindings/video/sandbox-fb.txt | 13 + drivers/block/Makefile | 1 + drivers/block/sandbox.c | 124 ++++++ drivers/misc/Makefile | 1 + drivers/misc/cros_ec.c | 50 +++ drivers/misc/cros_ec_sandbox.c | 558 ++++++++++++++++++++++++++ drivers/serial/sandbox.c | 4 + drivers/sound/Makefile | 2 + drivers/sound/sandbox.c | 23 ++ drivers/tpm/Makefile | 1 + drivers/tpm/tpm_tis_sandbox.c | 260 ++++++++++++ drivers/video/Makefile | 1 + drivers/video/sandbox_sdl.c | 70 ++++ include/config_fallbacks.h | 3 +- include/configs/sandbox.h | 9 +- include/cros_ec.h | 45 +++ include/ec_commands.h | 4 +- include/fdtdec.h | 20 + include/lcd.h | 3 + include/linux/crc8.h | 23 ++ include/os.h | 88 +++- include/part.h | 5 + include/sandboxblockdev.h | 18 + lib/Makefile | 1 + lib/crc8.c | 25 ++ lib/fdtdec.c | 34 +- 52 files changed, 2866 insertions(+), 103 deletions(-) create mode 100644 arch/sandbox/cpu/sdl.c create mode 100644 arch/sandbox/include/asm/arch-sandbox/sound.h create mode 100644 arch/sandbox/include/asm/sdl.h create mode 100644 board/sandbox/dts/sandbox.dts create mode 100644 common/cros_ec.c create mode 100644 doc/device-tree-bindings/video/sandbox-fb.txt create mode 100644 drivers/block/sandbox.c create mode 100644 drivers/misc/cros_ec_sandbox.c create mode 100644 drivers/sound/sandbox.c create mode 100644 drivers/tpm/tpm_tis_sandbox.c create mode 100644 drivers/video/sandbox_sdl.c create mode 100644 include/linux/crc8.h create mode 100644 include/sandboxblockdev.h create mode 100644 lib/crc8.c
Signature · 6 lines
1.8.4.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/32 Add crc8 routine
Add an implementation of the CRC8 algorithm. This is required by the TPM emulation, but is probably useful to U-Boot in general.
--- include/linux/crc8.h | 23 +++++++++++++++++++++++ lib/Makefile | 1 + lib/crc8.c | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 include/linux/crc8.h create mode 100644 lib/crc8.c
include/linux/crc8.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + + +#ifndef __linux_crc8_h +#define __linux_crc8_h + +/** +* crc8() - Calculate and return CRC-8 of the data +* +* This uses an x^8 + x^2 + x + 1 polynomial. A table-based algorithm would +* be faster, but for only a few bytes it isn't worth the code size +* +* @vptr: Buffer to checksum +* @len: Length of buffer in bytes +* @return CRC8 checksum +*/ +unsigned int crc8 (const unsigned char *vptr,int len); + +#endif
lib/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_BZIP2) += bzlib_randtable.o obj-$(CONFIG_BZIP2) += bzlib_huffman.o obj-$(CONFIG_USB_TTY) += circbuf.o obj-y += crc7.o +obj-y += crc8.o obj-y += crc16.o obj-$(CONFIG_OF_CONTROL) += fdtdec.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
lib/crc8.c new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include "linux/crc8.h" + +unsigned int crc8 (const unsigned char *vptr,int len) +{ +const unsigned char *data = vptr; +unsigned int crc =0 ; +int i, j; + +for (j = len; j; j--, data++) { + crc ^= (*data <<8 ); +for (i =8 ; i; i--) { +if (crc &0x8000 ) + crc ^= (0x1070 <<3 ); + crc <<=1 ; + } + } + +return (crc >>8 ) &0xff ; +}
Signature · 1 line
1.8.4.1
PATCH 2/32 sandbox: Use system headers first for sandbox's os.c
In reply to Simon GlassThis file must be compiled with system headers, even if U-Boot has headers of the same name. The existing solution for this is good enough for libfdt, but fails when we have headers like stdint.h in U-Boot.
Use -idirafter instead of -I, and remove the -nostdinc and other things that we don't want for this file. The best way to do this is to keep a copy of the original flags, rather than trying to filter them later.
--- arch/sandbox/cpu/Makefile | 6 ++++-- config.mk | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-)
arch/sandbox/cpu/Makefile +4 -2
@@ -10,5 +10,7 @@ obj-y := cpu.o os.o start.o state.o # os.c is build in the system environment, so needs standard includes -$(obj)os.o: ALL_CFLAGS := $(filter-out -nostdinc,$(ALL_CFLAGS)) -$(obj).depend.os: CPPFLAGS := $(filter-out -nostdinc,$(CPPFLAGS)) +$(obj)os.o: ALL_CFLAGS := $(BASE_CPPFLAGS) \ + $(patsubst %, -idirafter %, $(BASE_INCLUDE_DIRS)) +$(obj).depend.os: CPPFLAGS := $(BASE_CPPFLAGS) \ + $(patsubst %, -idirafter %, $(BASE_INCLUDE_DIRS))
config.mk +7 -2
@@ -256,11 +256,16 @@ Please undefined CONFIG_SYS_GENERIC_BOARD in your board config file) endif endif +# Sandbox needs the base flags and includes, so keep them around +BASE_CPPFLAGS := $(CPPFLAGS) + ifneq ($(OBJTREE),$(SRCTREE)) -CPPFLAGS += -I$(OBJTREE)/include +BASE_INCLUDE_DIRS := $(OBJTREE)/include endif -CPPFLAGS += -I$(TOPDIR)/include -I$(SRCTREE)/arch/$(ARCH)/include +BASE_INCLUDE_DIRS += $(TOPDIR)/include $(SRCTREE)/arch/$(ARCH)/include + +CPPFLAGS += $(patsubst %, -I%, $(BASE_INCLUDE_DIRS)) CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \ -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
Signature · 1 line
1.8.4.1
PATCH 3/32 sandbox: Use uint64_t instead of u64 for time
In reply to Simon GlassThe uint64_t type is defined in linux/types.h, so is safer than u64, which is not actually a Linux type.
--- arch/sandbox/cpu/os.c | 3 ++- include/os.h | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
arch/sandbox/cpu/os.c +2 -1
@@ -8,6 +8,7 @@#include <fcntl.h> #include <getopt.h> #include <stdio.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #include <termios.h>
@@ -136,7 +137,7 @@ void os_usleep(unsigned long usec)usleep (usec); } -u64 __attribute__((no_instrument_function))os_get_nsec (void ) +uint64_t __attribute__((no_instrument_function))os_get_nsec (void ) {#if defined(CLOCK_MONOTONIC ) && defined(_POSIX_MONOTONIC_CLOCK)struct timespec tp;
include/os.h +3 -1
@@ -11,6 +11,8 @@#ifndef __OS_H__#define __OS_H__ +#include <linux/types.h> +struct sandbox_state ;/**
@@ -116,7 +118,7 @@ void os_usleep(unsigned long usec);* * \return A monotonic increasing time scaled in nano seconds */ -u64 os_get_nsec (void ); +uint64_t os_get_nsec (void );/** * Parse arguments and update sandbox state.
Signature · 1 line
1.8.4.1
PATCH 4/32 sandbox: Increase memory size to 32MB
In reply to Simon GlassThe current 4MB size is a little small for some tests, so increase it.
--- include/configs/sandbox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/sandbox.h +1 -1
@@ -53,7 +53,7 @@/* * Size of malloc() pool, although we don't actually use this yet. */ -#define CONFIG_SYS_MALLOC_LEN (4 << 20)/* 4MB */ +#define CONFIG_SYS_MALLOC_LEN (32 << 20)/* 32MB */ #define CONFIG_SYS_HUSH_PARSER #define CONFIG_SYS_LONGHELP /* #undef to save memory */
Signature · 1 line
1.8.4.1
PATCH 5/32 sandbox: spi: Adjust 'sf test' to work on sandbox
In reply to Simon GlassAdd map_sysmem() calls so that this test works correctly on sandbox.
--- common/cmd_sf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
common/cmd_sf.c +9 -5
@@ -358,7 +358,8 @@ static void show_time(struct test_info *test, int stage)int bps;/* Bits per second */ speed = (long long )test->bytes *1000 ; -do_div (speed, test->time_ms[stage] *1024 ); +if (test->time_ms[stage]) +do_div (speed, test->time_ms[stage] *1024 ); bps = speed *8 ; printf("%d %s: %d ticks, %d KiB/s %d.%03d Mbps\n", stage,
@@ -446,11 +447,13 @@ static int do_spi_flash_test(int argc, char * const argv[]) {unsigned long offset;unsigned long len; -uint8_t *buf = (uint8_t *)CONFIG_SYS_TEXT_BASE ; +uint8_t *buf, *from;char *endp;uint8_t *vbuf;int ret; +if (argc <3 ) +return -1 ; offset =simple_strtoul (argv[1 ], &endp,16 );if (*argv[1 ] ==0 || *endp !=0 )return -1 ;
@@ -460,17 +463,18 @@ static int do_spi_flash_test(int argc, char * const argv[]) vbuf =malloc (len);if (!vbuf) { -printf ("Cannot allocate memory\n" ); +printf ("Cannot allocate memory (%lu bytes)\n" , len);return 1 ; } buf =malloc (len);if (!buf) {free (vbuf); -printf ("Cannot allocate memory\n" ); +printf ("Cannot allocate memory (%lu bytes)\n" , len);return 1 ; } -memcpy (buf, (char *)CONFIG_SYS_TEXT_BASE , len); + from =map_sysmem (CONFIG_SYS_TEXT_BASE ,0 ); +memcpy (buf, from, len); ret =spi_flash_test (flash, buf, len, offset, vbuf);free (vbuf);free (buf);
Signature · 1 line
1.8.4.1
PATCH 5/32 sandbox: spi: Adjust 'sf test' to work on sandbox
Quoted 61 lines · Simon Glass
Add
map_sysmem()calls so that this test works correctly on sandbox.Signed-off-by Simon Glass <[email protected]>Signed-off-by Simon Glass <[email protected]>Reviewed-by Hung-ying Tyan <[email protected]>--- common/cmd_sf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)common/cmd_sf.c +9
-6@@ -358,7 +358,8 @@ static void show_time(struct test_info *test, int stage)int bps;/* Bits per second */ speed = (long long )test->bytes *1000 ; -do_div (speed, test->time_ms[stage] *1024 ); +if (test->time_ms[stage]) +do_div (speed, test->time_ms[stage] *1024 ); bps = speed *8 ; printf("%d %s: %d ticks, %d KiB/s %d.%03d Mbps\n", stage,@@ -446,11 +447,13 @@ static int do_spi_flash_test(int argc, char * const argv[]) {unsigned long offset;unsigned long len; -uint8_t *buf = (uint8_t *)CONFIG_SYS_TEXT_BASE ; +uint8_t *buf, *from;char *endp;uint8_t *vbuf;int ret; +if (argc <3 ) +return -1 ; offset =simple_strtoul (argv[1 ], &endp,16 );if (*argv[1 ] ==0 || *endp !=0 )return -1 ;@@ -460,17 +463,18 @@ static int do_spi_flash_test(int argc, char * const argv[]) vbuf =malloc (len);if (!vbuf) { -printf ("Cannot allocate memory\n" ); +printf ("Cannot allocate memory (%lu bytes)\n" , len);return 1 ; } buf =malloc (len);if (!buf) {free (vbuf); -printf ("Cannot allocate memory\n" ); +printf ("Cannot allocate memory (%lu bytes)\n" , len);return 1 ; } -memcpy (buf, (char *)CONFIG_SYS_TEXT_BASE , len); + from =map_sysmem (CONFIG_SYS_TEXT_BASE ,0 ); +memcpy (buf, from, len); ret =spi_flash_test (flash, buf, len, offset, vbuf);free (vbuf);free (buf); --
Quoted 2 lines
1.8.4.1
Applied to u-boot-spi/master
Signature · 2 lines
Thanks, Jagan.
PATCH 6/32 sandbox: Build a device tree file for sandbox
In reply to Simon GlassAdd support for building a device tree for sandbox's CONFIG_OF_HOSTFILE option to make it easier to use device tree with sandbox.
This adjusts the Makefile to build a u-boot.dtb file which can be passed to sandbox U-Boot with:
./u-boot -d u-boot.dtb
--- Makefile | 1 + arch/sandbox/config.mk | 2 ++ board/sandbox/dts/sandbox.dts | 29 +++++++++++++++++++++++++++++ include/configs/sandbox.h | 1 + 4 files changed, 33 insertions(+) create mode 100644 board/sandbox/dts/sandbox.dts
Makefile +1 -0
@@ -365,6 +365,7 @@ ALL-$(CONFIG_SPL) += $(obj)spl/u-boot-spl.bin ALL-$(CONFIG_SPL_FRAMEWORK) += $(obj)u-boot.img ALL-$(CONFIG_TPL) += $(obj)tpl/u-boot-tpl.bin ALL-$(CONFIG_OF_SEPARATE) += $(obj)u-boot.dtb $(obj)u-boot-dtb.bin +ALL-$(CONFIG_OF_HOSTFILE) += $(obj)u-boot.dtb ifneq ($(CONFIG_SPL_TARGET),) ALL-$(CONFIG_SPL) += $(obj)$(subst ",,$(CONFIG_SPL_TARGET)) endif
arch/sandbox/config.mk +2 -0
@@ -7,3 +7,5 @@ PLATFORM_LIBS += -lrt # Support generic board on sandbox __HAVE_ARCH_GENERIC_BOARD := y + +CONFIG_ARCH_DEVICE_TREE := sandbox
board/sandbox/dts/sandbox.dts new file +29 -0
@@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + model = "Sandbox test environment"; + + memory { + reg = <0 0x08000000>; + }; + + triangle { + compatible = "demo-shape"; + colour = "cyan"; + sides = <3>; + character = <83>; + }; + square { + compatible = "demo-shape"; + colour = "blue"; + sides = <4>; + }; + hexagon { + compatible = "demo-simple"; + colour = "white"; + sides = <6>; + }; +};
include/configs/sandbox.h +1 -0
@@ -32,6 +32,7 @@#define CONFIG_FIT_SIGNATURE #define CONFIG_RSA #define CONFIG_CMD_FDT +#define CONFIG_DEFAULT_DEVICE_TREE sandbox#define CONFIG_FS_FAT #define CONFIG_FS_EXT4
Signature · 1 line
1.8.4.1
PATCH 7/32 sandbox: config: Don't use 64-bit physical memory
In reply to Simon GlassSandbox uses an emulated memory map which is quite small. We don't need the CONFIG_PHYS_64BIT option since we can address memory with a 32-bit offset into our ram_buf.
Adjust the phys_addr_t and phys_size_t types accordingly.
--- arch/sandbox/include/asm/types.h | 4 ++-- include/configs/sandbox.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-)
arch/sandbox/include/asm/types.h +2 -2
@@ -48,8 +48,8 @@ typedef unsigned long long u64;#define BITS_PER_LONG CONFIG_SANDBOX_BITS_PER_LONGtypedef unsigned long dma_addr_t ; -typedef unsigned long phys_addr_t ; -typedef unsigned long phys_size_t ; +typedef u32 phys_addr_t ; +typedef u32 phys_size_t ;#endif /* __KERNEL__ */
include/configs/sandbox.h +0 -1
@@ -86,7 +86,6 @@#define CONFIG_SYS_LOAD_ADDR 0x00000000#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 */
Signature · 1 line
1.8.4.1
PATCH 8/32 sandbox: Correct data sizes and printf() strings in fdtdec.c
In reply to Simon GlassThere are a few wwrnings in this file when building for sandbox. Addresses coming from the device tree need to be treated as ulong as elsewhere in U-Boot and we must use map_sysmem() to convert to a pointer when needed.
--- lib/fdtdec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/fdtdec.c +4 -4
@@ -86,10 +86,10 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, size = (fdt_size_t *)((char *)cell +sizeof (fdt_addr_t)); *sizep =fdt_size_to_cpu (*size); -debug ("addr=%p, size=%p\n" , (void *)addr, - (void *)*sizep); +debug ("addr=%08lx, size=%08x\n" , + (ulong )addr, *sizep); }else { -debug ("%p\n" , (void *)addr); +debug ("%08lx\n" , (ulong )addr); }return addr; }
@@ -611,7 +611,7 @@ int fdtdec_decode_region(const void *blob, int node,if (!cell || (len !=sizeof (fdt_addr_t) *2 ))return -1 ; - *ptrp = (void *)fdt_addr_to_cpu (*cell); + *ptrp =map_sysmem (fdt_addr_to_cpu (*cell), *size); *size =fdt_size_to_cpu (cell[1 ]);debug ("%s: size=%zx\n" , __func__, *size);return 0 ;
Signature · 1 line
1.8.4.1
PATCH 9/32 sandbox: Use os functions to read host device tree
In reply to Simon GlassAt present we use U-Boot's filesystem layer to read the sandbox device tree, but this is problematic since it relies on a temporary feauture added there. Since we plan to implement proper block layer support for sandbox, change this code to use the os layer functions instead. Also use the new fdt_create_empty_tree() instead of our own code.
--- common/board_f.c | 48 +++++++++++++++++++++--------------------------- disk/part.c | 17 ----------------- 2 files changed, 21 insertions(+), 44 deletions(-)
common/board_f.c +21 -27
@@ -297,45 +297,39 @@ __weak int arch_cpu_init(void)#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 (); +const char *fname = state->fdt_fname;void *blob; -int size; +ssize_t size;int err; +int fd; blob =map_sysmem (CONFIG_SYS_FDT_LOAD_ADDR ,0 );if (!state->fdt_fname) { - err =make_empty_fdt (blob); + err =fdt_create_empty_tree (blob,256 );if (!err) goto done; -return err; +printf ("Unable to create empty FDT: %s\n" ,fdt_strerror (err)); +return -EINVAL ; + } + + size =os_get_filesize (fname); +if (size <0 ) { +printf ("Failed to file FDT file '%s'\n" , fname); +return -ENOENT ; + } + fd =os_open (fname,OS_O_RDONLY ); +if (fd <0 ) { +printf ("Failed to open FDT file '%s'\n" , fname); +return -EACCES ; } - 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 ) +if (os_read (fd, blob, size) != size) { +os_close (fd);return -EIO ; + } +os_close (fd); done: gd->fdt_blob = blob;
disk/part.c +0 -17
@@ -446,23 +446,6 @@ int get_device_and_partition(const char *ifname, const char *dev_part_str,int part;disk_partition_t tmpinfo; -/* -* For now, we have a special case for sandbox, since there is no -* real block device support. -*/ -if (0 ==strcmp (ifname,"host" )) { - *dev_desc =NULL ; - info->start = info->size = info->blksz =0 ; - info->bootable =0 ; -strcpy ((char *)info->type,BOOT_PART_TYPE ); -strcpy ((char *)info->name,"Sandbox host" ); -#ifdef CONFIG_PARTITION_UUIDS - info->uuid[0 ] =0 ; -#endif - -return 0 ; - } -/* If no dev_part_str, use bootdevice environment variable */ if (!dev_part_str || !strlen (dev_part_str) || !strcmp (dev_part_str,"-" ))
Signature · 1 line
1.8.4.1
PATCH 10/32 sandbox: block driver using host file/device as backing store
In reply to Simon GlassFrom: Henrik Nordstr?m <[email protected]>
Provide a way to use any host file or device as a block device in U-Boot. This can be used to provide filesystem access within U-Boot to an ext2 image file on the host, for example.
The support is plumbed into the filesystem and partition interfaces.
We don't want to print a message in the driver every time we find a missing device. Pass the information back to the caller where a message can be printed if desired.
- Removed change to part.c get_device_and_partition()
--- common/cmd_sandbox.c | 64 +++++++++++++++++++++++ disk/part.c | 6 +++ drivers/block/Makefile | 1 + drivers/block/sandbox.c | 124 +++++++++++++++++++++++++++++++++++++++++++++ include/config_fallbacks.h | 3 +- include/configs/sandbox.h | 3 ++ include/part.h | 5 ++ include/sandboxblockdev.h | 18 +++++++ 8 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 drivers/block/sandbox.c create mode 100644 include/sandboxblockdev.h
common/cmd_sandbox.c +64 -0
@@ -6,6 +6,9 @@#include <common.h> #include <fs.h> +#include <part.h> +#include <sandboxblockdev.h> +#include <asm/errno.h> static int do_sandbox_load (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[])
@@ -25,10 +28,69 @@ static int do_sandbox_save(cmd_tbl_t *cmdtp, int flag, int argc,return do_save (cmdtp, flag, argc, argv,FS_TYPE_SANDBOX ); } +static int do_sandbox_bind (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +if (argc <2 || argc >3 ) +return CMD_RET_USAGE ; +char *ep; +char *dev_str = argv[1 ]; +char *file = argc >=3 ? argv[2 ] :NULL ; +int dev =simple_strtoul (dev_str, &ep,16 ); +if (*ep) { +printf ("** Bad device specification %s **\n" , dev_str); +return CMD_RET_USAGE ; + } +return host_dev_bind (dev, file); +} + +static int do_sandbox_info (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +if (argc <1 || argc >2 ) +return CMD_RET_USAGE ; +int min_dev =0 ; +int max_dev =CONFIG_HOST_MAX_DEVICES -1 ; +if (argc >=2 ) { +char *ep; +char *dev_str = argv[1 ]; +int dev =simple_strtoul (dev_str, &ep,16 ); +if (*ep) { +printf ("** Bad device specification %s **\n" , dev_str); +return CMD_RET_USAGE ; + } + min_dev = dev; + max_dev = dev; + } +int dev; +printf ("%3s %12s %s\n" ,"dev" ,"blocks" ,"path" ); +for (dev = min_dev; dev <= max_dev; dev++) { +block_dev_desc_t *blk_dev; +int ret; + +printf ("%3d " , dev); + ret =host_get_dev_err (dev, &blk_dev); +if (ret) { +if (ret == -ENOENT ) +puts ("Not bound to a backing file\n" ); +else if (ret == -ENODEV ) +puts ("Invalid host device number\n" ); + +continue ; + } +struct host_block_dev *host_dev = blk_dev->priv; +printf ("%12lu %s\n" , (unsigned long )blk_dev->lba, + host_dev->filename); + } +return 0 ; +} +static cmd_tbl_t cmd_sandbox_sub[] = {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,"" ,"" ), +U_BOOT_CMD_MKENT (bind,3 ,0 , do_sandbox_bind,"" ,"" ), +U_BOOT_CMD_MKENT (info,3 ,0 , do_sandbox_info,"" ,"" ), }; static int do_sandbox(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -57,4 +119,6 @@ U_BOOT_CMD("sb ls host <filename> - list files on host\n" "sb save host <dev> <filename> <addr> <bytes> [<offset>] - " "save a file to host\n" +"sb bind <dev> [<filename>] - bind \"host\" device to file\n" +"sb info [<dev>] - show device binding & info" );
disk/part.c +6 -0
@@ -43,6 +43,9 @@ static const struct block_drvr block_drvr[] = { #if defined(CONFIG_SYSTEMACE) { .name = "ace", .get_dev = systemace_get_dev, }, #endif +#if defined(CONFIG_SANDBOX) + { .name = "host", .get_dev = host_get_dev, }, +#endif { }, };
@@ -286,6 +289,9 @@ static void print_part_header (const char *type, block_dev_desc_t * dev_desc)case IF_TYPE_MMC :puts ("MMC" );break ; +case IF_TYPE_HOST : +puts ("HOST" ); +break ;default :puts ("UNKNOWN" );break ;
drivers/block/Makefile +1 -0
@@ -18,5 +18,6 @@ obj-$(CONFIG_SATA_DWC) += sata_dwc.o obj-$(CONFIG_SATA_SIL3114) += sata_sil3114.o obj-$(CONFIG_SATA_SIL) += sata_sil.o obj-$(CONFIG_IDE_SIL680) += sil680.o +obj-$(CONFIG_SANDBOX) += sandbox.o obj-$(CONFIG_SCSI_SYM53C8XX) += sym53c8xx.o obj-$(CONFIG_SYSTEMACE) += systemace.o
drivers/block/sandbox.c new file +124 -0
124 lines not on this page · raw message
include/config_fallbacks.h +2 -1
@@ -50,7 +50,8 @@defined (CONFIG_CMD_PART ) || \defined (CONFIG_CMD_GPT ) || \defined (CONFIG_MMC ) || \ - defined(CONFIG_SYSTEMACE) +defined (CONFIG_SYSTEMACE ) || \ + defined(CONFIG_SANDBOX)#define HAVE_BLOCK_DEVICE #endif
include/configs/sandbox.h +3 -0
@@ -40,6 +40,9 @@#define CONFIG_CMD_FAT #define CONFIG_CMD_EXT4 #define CONFIG_CMD_EXT4_WRITE +#define CONFIG_CMD_PART +#define CONFIG_DOS_PARTITION +#define CONFIG_HOST_MAX_DEVICES 4#define CONFIG_SYS_VSNPRINTF
include/part.h +5 -0
@@ -58,6 +58,8 @@ typedef struct block_dev_desc {#define IF_TYPE_MMC 6#define IF_TYPE_SD 7#define IF_TYPE_SATA 8 +#define IF_TYPE_HOST 9 +#define IF_TYPE_MAX 10/* Max number of IF_TYPE_* supported */ /* Part types */ #define PART_TYPE_UNKNOWN 0x00
@@ -102,6 +104,8 @@ block_dev_desc_t* usb_stor_get_dev(int dev);block_dev_desc_t *mmc_get_dev (int dev);block_dev_desc_t *systemace_get_dev (int dev);block_dev_desc_t *mg_disk_get_dev (int dev); +block_dev_desc_t *host_get_dev (int dev); +int host_get_dev_err (int dev,block_dev_desc_t **blk_devp);/* disk/part.c */ int get_partition_info (block_dev_desc_t * dev_desc,int part,disk_partition_t *info);
@@ -123,6 +127,7 @@ static inline block_dev_desc_t* usb_stor_get_dev(int dev) { return NULL; }static inline block_dev_desc_t *mmc_get_dev (int dev) {return NULL ; }static inline block_dev_desc_t *systemace_get_dev (int dev) {return NULL ; }static inline block_dev_desc_t *mg_disk_get_dev (int dev) {return NULL ; } +static inline block_dev_desc_t *host_get_dev (int dev) {return NULL ; }static inline int get_partition_info (block_dev_desc_t * dev_desc,int part,disk_partition_t *info) {return -1 ; }
include/sandboxblockdev.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright (c) 2013, Henrik Nordstrom <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __SANDBOX_BLOCK_DEV__ +#define __SANDBOX_BLOCK_DEV__ + +struct host_block_dev { +block_dev_desc_t blk_dev; +char *filename; +int fd; +}; + +int host_dev_bind (int dev,char *filename); + +#endif
Signature · 1 line
1.8.4.1
PATCH 11/32 sandbox: Improve/augment memory allocation functions
In reply to Simon GlassImplement realloc() and free() for sandbox, by adding a header to each block which contains the block size.
--- arch/sandbox/cpu/os.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- include/os.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-)
arch/sandbox/cpu/os.c +43 -2
@@ -27,6 +27,10 @@/* Operating System Interface */ +struct os_mem_hdr { +size_t length;/* number of bytes in the block */ +}; +ssize_t os_read (int fd,void *buf,size_t count) {return read (fd, buf, count);
@@ -128,8 +132,45 @@ void os_tty_raw(int fd)void *os_malloc (size_t length) { -return mmap (NULL , length,PROT_READ |PROT_WRITE , -MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 ); +struct os_mem_hdr *hdr; + + hdr =mmap (NULL , length +sizeof (*hdr),PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 ); +if (hdr ==MAP_FAILED ) +return NULL ; + hdr->length = length; + +return hdr +1 ; +} + +void *os_free (void *ptr) +{ +struct os_mem_hdr *hdr = ptr; + + hdr--; +if (ptr) +munmap (hdr, hdr->length +sizeof (*hdr)); +} + +void *os_realloc (void *ptr,size_t length) +{ +struct os_mem_hdr *hdr = ptr; +void *buf =NULL ; + + hdr--; +if (length !=0 ) { + buf =os_malloc (length); +if (!buf) +return buf; +if (ptr) { +if (length > hdr->length) + length = hdr->length; +memcpy (buf, ptr, length); + } + } +os_free (ptr); + +return buf; }void os_usleep (unsigned long usec)
include/os.h +29 -0
@@ -107,6 +107,35 @@ void os_tty_raw(int fd);void *os_malloc (size_t length);/** +* Free memory previous allocated with os_malloc()/os_realloc() +* +* This returns the memory to the OS. +* +* \param ptr Pointer to memory block to free +*/ +void *os_free (void *ptr); + +/** +* Reallocate previously-allocated memory to increase/decrease space +* +* This works in a similar way to the C library realloc() function. If +* length is 0, then ptr is freed. Otherwise the space used by ptr is +* expanded or reduced depending on whether length is larger or smaller +* than before. +* +* If ptr is NULL, then this is similar to calling os_malloc(). +* +* This function may need to move the memory block to make room for any +* extra space, in which case the new pointer is returned. +* +* \param ptr Pointer to memory block to reallocate +* \param length New length for memory block +* \return pointer to new memory block, or NULL on failure or if length +* is 0. +*/ +void *os_realloc (void *ptr,size_t length); + +/** * Access to the usleep function of the os * * \param usec Time to sleep in micro seconds
Signature · 1 line
1.8.4.1
PATCH 12/32 sandbox: Correct help message <arg> garbling
In reply to Simon GlassThe <arg> is displayed for options with no argument, and omitted for those with an argument. Swap this around.
--- arch/sandbox/cpu/start.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/sandbox/cpu/start.c +2 -2
@@ -50,9 +50,9 @@ int sandbox_early_getopt_check(void)/* then the long flag */ if (opt->has_arg) -printf ("--%-*s" , max_noarg_len, opt->flag); -else printf ("--%-*s <arg> " , max_arg_len, opt->flag); +else +printf ("--%-*s" , max_noarg_len, opt->flag);/* finally the help text */ printf (" %s\n" , opt->help);
Signature · 1 line
1.8.4.1
PATCH 13/32 sandbox: Allow return from board_init_f()
In reply to Simon GlassThe execution flow becomes easier if we can return from board_init_f() as ARM does. We can control things from start.c instead of having to call back into that file from other places.
--- arch/sandbox/cpu/start.c | 11 ++++++----- common/board_f.c | 8 +++----- 2 files changed, 9 insertions(+), 10 deletions(-)
arch/sandbox/cpu/start.c +6 -5
@@ -10,6 +10,8 @@#include <os.h> +DECLARE_GLOBAL_DATA_PTR ; +int sandbox_early_getopt_check (void ) {struct sandbox_state *state =state_get_current ();
@@ -109,12 +111,11 @@ int main(int argc, char *argv[])if (os_parse_args (state, argc, argv))return 1 ; -/* -* Do pre- and post-relocation init, then start up U-Boot. This will -* never return. -*/ +/* Do pre- and post-relocation init */ board_init_f (0 ); -/* NOTREACHED - board_init_f() does not return */ +board_init_r (gd->new_gd,0 ); + +/* NOTREACHED - board_init_r() does not return */ return 0 ; }
common/board_f.c +3 -5
@@ -766,7 +766,7 @@ static int setup_reloc(void) }/* ARM calls relocate_code from its crt0.S */ -#if !defined(CONFIG_ARM ) +#if !defined(CONFIG_ARM ) && !defined(CONFIG_SANDBOX )static int jump_to_copy (void ) {
@@ -786,8 +786,6 @@ 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->start_addr_sp, gd->new_gd, gd->relocaddr);#endif
@@ -989,7 +987,7 @@ static init_fnc_t init_sequence_f[] = { INIT_FUNC_WATCHDOG_RESET reloc_fdt, setup_reloc, -#ifndef CONFIG_ARM +#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) jump_to_copy, #endif NULL,
@@ -1008,7 +1006,7 @@ void board_init_f(ulong boot_flags)if (initcall_run_list (init_sequence_f))hang (); -#ifndef CONFIG_ARM +#if !defined(CONFIG_ARM ) && !defined(CONFIG_SANDBOX )/* NOTREACHED - jump_to_copy() does not return */ hang ();#endif
Signature · 1 line
1.8.4.1
PATCH 14/32 sandbox: Implement the bootm command for sandbox
In reply to Simon GlassWhen sandbox does a 'bootm' to run a kernel we cannot actually execute it. So just exit sandbox, which is essentially what U-Boot does on other archs. Also, allow sandbox to use bootm on any kernel, so that it can be used to test booting of kernels from any architecture.
--- arch/sandbox/cpu/cpu.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
arch/sandbox/cpu/cpu.c +15 -2
@@ -8,10 +8,16 @@DECLARE_GLOBAL_DATA_PTR ; -int do_reset (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +void reset_cpu (ulong ignored) {/* This is considered normal termination for now */ os_exit (0 ); +} + +int do_reset (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +reset_cpu (0 ); +return 0 ; }
@@ -28,7 +34,14 @@ unsigned long __attribute__((no_instrument_function)) timer_get_us(void)int do_bootm_linux (int flag,int argc,char *argv[],bootm_headers_t *images) { -return -1 ; +if (flag & (BOOTM_STATE_OS_GO |BOOTM_STATE_OS_FAKE_GO )) { +bootstage_mark (BOOTSTAGE_ID_RUN_OS ); +printf ("## Transferring control to Linux (at address %08lx)...\n" , + images->ep); +reset_cpu (0 ); + } + +return 0 ; }int cleanup_before_linux (void )
Signature · 1 line
1.8.4.1
PATCH 15/32 sandbox: Allow the console to work earlier
In reply to Simon GlassWith sandbox, errors and problems may be reported before console_init_f() is executed. For example, an argument may not parse correctly or U-Boot may panic(). At present this output is swallowed so there is no indication what is going wrong.
Adjust the console to deal with a very early sandbox setup, by detecting that there is no global_data yet, and calling os functions in that case.
--- arch/sandbox/cpu/os.c | 11 +++++++++++ common/console.c | 16 +++++++++++++++- include/os.h | 20 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-)
arch/sandbox/cpu/os.c +11 -0
@@ -388,3 +388,14 @@ ssize_t os_get_filesize(const char *fname)return ret;return buf.st_size; } + +void os_putc (int ch) +{ +putchar (ch); +} + +void os_puts (const char *str) +{ +while (*str) +os_putc (*str++); +}
common/console.c +15 -1
@@ -8,6 +8,7 @@#include <common.h> #include <stdarg.h> #include <malloc.h> +#include <os.h> #include <serial.h> #include <stdio_dev.h> #include <exports.h>
@@ -415,6 +416,12 @@ static inline void print_pre_console_buffer(void) {}void putc (const char c) { +#ifdef CONFIG_SANDBOX +if (!gd) { +os_putc (c); +return ; + } +#endif #ifdef CONFIG_SILENT_CONSOLE if (gd->flags &GD_FLG_SILENT )return ;
@@ -439,6 +446,13 @@ void putc(const char c)void puts (const char *s) { +#ifdef CONFIG_SANDBOX +if (!gd) { +os_puts (s); +return ; + } +#endif +#ifdef CONFIG_SILENT_CONSOLE if (gd->flags &GD_FLG_SILENT )return ;
@@ -467,7 +481,7 @@ int printf(const char *fmt, ...)uint i;char printbuffer[CONFIG_SYS_PBSIZE ]; -#ifndef CONFIG_PRE_CONSOLE_BUFFER +#if !defined(CONFIG_SANDBOX ) && !defined(CONFIG_PRE_CONSOLE_BUFFER )if (!gd->have_console)return 0 ;#endif
include/os.h +20 -0
@@ -209,4 +209,24 @@ const char *os_dirent_get_typename(enum os_dirent_t type);*/ ssize_t os_get_filesize (const char *fname); +/** +* Write a character to the controlling OS terminal +* +* This bypasses the U-Boot console support and writes directly to the OS +* stdout file descriptor. +* +* @param ch Character to write +*/ +void os_putc (int ch); + +/** +* Write a string to the controlling OS terminal +* +* This bypasses the U-Boot console support and writes directly to the OS +* stdout file descriptor. +* +* @param str String to write (note that \n is not appended) +*/ +void os_puts (const char *str); +#endif
Signature · 1 line
1.8.4.1
PATCH 16/32 sandbox: Add -i option to enter interactive mode
In reply to Simon GlassNormally when U-Boot starts with a command (-c option) it quits when the command completes. Normally this is what is requires, since the test is likely complete.
Provide an option to jump into the console instead, so that debugging or other tasks may be performed before quitting.
--- arch/sandbox/cpu/start.c | 12 +++++++++++- arch/sandbox/include/asm/state.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-)
arch/sandbox/cpu/start.c +11 -1
@@ -77,7 +77,8 @@ int sandbox_main_loop_init(void)/* Execute command if required */ if (state->cmd) {run_command_list (state->cmd,-1 ,0 ); -os_exit (state->exit_type); +if (!state->interactive) +os_exit (state->exit_type); }return 0 ;
@@ -98,6 +99,15 @@ static int sandbox_cmdline_cb_fdt(struct sandbox_state *state, const char *arg) }SANDBOX_CMDLINE_OPT_SHORT (fdt,'d' ,1 ,"Specify U-Boot's control FDT" ); +static int sandbox_cmdline_cb_interactive (struct sandbox_state *state, +const char *arg) +{ + state->interactive = true; +return 0 ; +} + +SANDBOX_CMDLINE_OPT_SHORT (interactive,'i' ,0 ,"Enter interactive mode" ); +int main (int argc,char *argv[]) {struct sandbox_state *state;
arch/sandbox/include/asm/state.h +2 -0
@@ -7,6 +7,7 @@#define __SANDBOX_STATE_H#include <config.h> +#include <stdbool.h> /* How we exited U-Boot */ enum exit_type_id {
@@ -23,6 +24,7 @@ struct sandbox_spi_info {/* The complete state of the test system */ struct sandbox_state {const char *cmd;/* Command to execute */ +bool interactive;/* Enable cmdline after 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 */
Signature · 1 line
1.8.4.1
PATCH 17/32 sandbox: Allow reading/writing of RAM buffer
In reply to Simon GlassIt is useful to be able to save and restore the RAM contents of sandbox U-Boot either for setting up tests, for later analysys, or for chaining together multiple tests which need to keep the same memory contents.
Add a function to provide a memory file for U-Boot. This is read on start-up and written when shutting down. If the file does not exist on start-up, it will be created when shutting down.
--- arch/sandbox/cpu/cpu.c | 4 ++++ arch/sandbox/cpu/os.c | 39 ++++++++++++++++++++++++++++++++++ arch/sandbox/cpu/start.c | 22 +++++++++++++++++-- arch/sandbox/cpu/state.c | 22 +++++++++++++++++++ arch/sandbox/include/asm/global_data.h | 2 +- arch/sandbox/include/asm/state.h | 12 +++++++++++ common/board_f.c | 7 +++--- include/os.h | 16 ++++++++++++++ 8 files changed, 118 insertions(+), 6 deletions(-)
arch/sandbox/cpu/cpu.c +4 -0
@@ -5,11 +5,15 @@#include <common.h> #include <os.h> +#include <asm/state.h> DECLARE_GLOBAL_DATA_PTR ;void reset_cpu (ulong ignored) { +if (state_uninit ()) +os_exit (2 ); +/* This is considered normal termination for now */ os_exit (0 ); }
arch/sandbox/cpu/os.c +39 -0
@@ -399,3 +399,42 @@ void os_puts(const char *str)while (*str)os_putc (*str++); } + +int os_write_ram_buf (const char *fname) +{ +struct sandbox_state *state =state_get_current (); +int fd, ret; + + fd =open (fname,O_CREAT |O_WRONLY ,0777 ); +if (fd <0 ) +return -ENOENT ; + ret =write (fd, state->ram_buf, state->ram_size); +close (fd); +if (ret != state->ram_size) +return -EIO ; + +return 0 ; +} + +int os_read_ram_buf (const char *fname) +{ +struct sandbox_state *state =state_get_current (); +int fd, ret; +int size; + + size =os_get_filesize (fname); +if (size <0 ) +return -ENOENT ; +if (size != state->ram_size) +return -ENOSPC ; + fd =open (fname,O_RDONLY ); +if (fd <0 ) +return -ENOENT ; + + ret =read (fd, state->ram_buf, state->ram_size); +close (fd); +if (ret != state->ram_size) +return -EIO ; + +return 0 ; +}
arch/sandbox/cpu/start.c +20 -2
@@ -4,12 +4,11 @@*/ #include <common.h> +#include <os.h> #include <asm/getopt.h> #include <asm/sections.h> #include <asm/state.h> -#include <os.h> -DECLARE_GLOBAL_DATA_PTR ;int sandbox_early_getopt_check (void )
@@ -108,6 +107,25 @@ static int sandbox_cmdline_cb_interactive(struct sandbox_state *state,SANDBOX_CMDLINE_OPT_SHORT (interactive,'i' ,0 ,"Enter interactive mode" ); +static int sandbox_cmdline_cb_memory (struct sandbox_state *state, +const char *arg) +{ +int err; + +/* For now assume we always want to write it */ + state->write_ram_buf = true; + state->ram_buf_fname = arg; + +if (os_read_ram_buf (arg)) { +printf ("Failed to read RAM buffer\n" ); +return err; + } + +return 0 ; +} +SANDBOX_CMDLINE_OPT_SHORT (memory,'m' ,1 , +"Read/write ram_buf memory contents from file" ); +int main (int argc,char *argv[]) {struct sandbox_state *state;
arch/sandbox/cpu/state.c +22 -0
@@ -4,6 +4,7 @@*/ #include <common.h> +#include <os.h> #include <asm/state.h> /* Main state record for the sandbox */
@@ -25,6 +26,10 @@ int state_init(void) { state = &main_state; + state->ram_size =CONFIG_SYS_SDRAM_SIZE ; + state->ram_buf =os_malloc (state->ram_size); +assert (state->ram_buf); +/* * Example of how to use GPIOs: *
@@ -33,3 +38,20 @@ int state_init(void)*/ return 0 ; } + +int state_uninit (void ) +{ +int err; + + state = &main_state; + +if (state->write_ram_buf) { + err =os_write_ram_buf (state->ram_buf_fname); +if (err) { +printf ("Failed to write RAM buffer\n" ); +return err; + } + } + +return 0 ; +}
arch/sandbox/include/asm/global_data.h +1 -1
@@ -12,7 +12,7 @@/* Architecture-specific global data */ struct arch_global_data { -u8 *ram_buf;/* emulated RAM buffer */ +uint8_t *ram_buf;/* emulated RAM buffer */ };#include <asm-generic/global_data.h>
arch/sandbox/include/asm/state.h +12 -0
@@ -30,6 +30,10 @@ struct sandbox_state {const char *parse_err;/* Error to report from parsing */ int argc;/* Program arguments */ char **argv; +uint8_t *ram_buf;/* Emulated RAM buffer */ +unsigned int ram_size;/* Size of RAM buffer */ +const char *ram_buf_fname;/* Filename to use for RAM buffer */ +bool write_ram_buf;/* Write RAM buffer on exit */ /* Pointer to information for each SPI bus/cs */ struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS ]
@@ -55,4 +59,12 @@ struct sandbox_state *state_get_current(void);*/ int state_init (void ); +/** +* Uninitialize the test system state, writing out state if configured to +* do so. +* +* @return 0 if OK, -ve on error +*/ +int state_uninit (void ); +#endif
common/board_f.c +4 -3
@@ -341,9 +341,10 @@ done:#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 ; +struct sandbox_state *state =state_get_current (); + + gd->arch.ram_buf = state->ram_buf; + gd->ram_size = state->ram_size;return 0 ; }
include/os.h +16 -0
@@ -229,4 +229,20 @@ void os_putc(int ch);*/ void os_puts (const char *str); +/** +* Write the sandbox RAM buffer to a existing file +* +* @param fname Filename to write memory to (simple binary format) +* @return 0 if OK, -ve on error +*/ +int os_write_ram_buf (const char *fname); + +/** +* Read the sandbox RAM buffer from an existing file +* +* @param fname Filename containing memory (simple binary format) +* @return 0 if OK, -ve on error +*/ +int os_read_ram_buf (const char *fname); +#endif
Signature · 1 line
1.8.4.1
PATCH 18/32 sandbox: Add facility to save/restore sandbox state
In reply to Simon GlassIt is often useful to be able to save out the state from a sandbox test run, for analysis or to restore it later to continue a test. Add generic infrastructure for doing this using a device tree binary file. This is a flexible tagged file format which is already supported by U-Boot, and it supports hierarchy if needed.
--- arch/sandbox/cpu/start.c | 49 +++++- arch/sandbox/cpu/state.c | 331 +++++++++++++++++++++++++++++++++++++++ arch/sandbox/include/asm/state.h | 114 ++++++++++++++ 3 files changed, 490 insertions(+), 4 deletions(-)
arch/sandbox/cpu/start.c +45 -4
@@ -126,19 +126,56 @@ static int sandbox_cmdline_cb_memory(struct sandbox_state *state,SANDBOX_CMDLINE_OPT_SHORT (memory,'m' ,1 ,"Read/write ram_buf memory contents from file" ); +static int sandbox_cmdline_cb_state (struct sandbox_state *state, +const char *arg) +{ + state->state_fname = arg; +return 0 ; +} +SANDBOX_CMDLINE_OPT_SHORT (state,'s' ,1 ,"Specify the sandbox state FDT" ); + +static int sandbox_cmdline_cb_read (struct sandbox_state *state, +const char *arg) +{ + state->read_state = true; +return 0 ; +} +SANDBOX_CMDLINE_OPT_SHORT (read,'r' ,0 ,"Read the state FDT on startup" ); + +static int sandbox_cmdline_cb_write (struct sandbox_state *state, +const char *arg) +{ + state->write_state = true; +return 0 ; +} +SANDBOX_CMDLINE_OPT_SHORT (write,'w' ,0 ,"Write state FDT on exit" ); + +static int sandbox_cmdline_cb_ignore_missing (struct sandbox_state *state, +const char *arg) +{ + state->ignore_missing_state_on_read = true; +return 0 ; +} +SANDBOX_CMDLINE_OPT_SHORT (ignore_missing,'n' ,0 , +"Ignore missing state on read" ); +int main (int argc,char *argv[]) {struct sandbox_state *state; -int err; +int ret; - err =state_init (); -if (err) -return err; + ret =state_init (); +if (ret) + goto err; state =state_get_current ();if (os_parse_args (state, argc, argv))return 1 ; + ret =sandbox_read_state (state, state->state_fname); +if (ret) + goto err; +/* Do pre- and post-relocation init */ board_init_f (0 );
@@ -146,4 +183,8 @@ int main(int argc, char *argv[])/* NOTREACHED - board_init_r() does not return */ return 0 ; + +err: +printf ("Error %d\n" , ret); +return 1 ; }
arch/sandbox/cpu/state.c +331 -0
348 lines not on this page · raw message
arch/sandbox/include/asm/state.h +114 -0
138 lines not on this page · raw message
Signature · 1 line
1.8.4.1
PATCH 19/32 sandbox: tpm: Add TPM emulation
In reply to Simon GlassAdd a simple TPM emulator for sandbox. It only supports a small subset of TPM operations. However, these are enough to perform common tasks.
Note this is an initial commit to get this working, but it could use cleaning up (for example constants instead of open-coded values).
--- drivers/tpm/Makefile | 1 + drivers/tpm/tpm_tis_sandbox.c | 262 ++++++++++++++++++++++++++++++++++++++++++ include/configs/sandbox.h | 2 + 3 files changed, 265 insertions(+) create mode 100644 drivers/tpm/tpm_tis_sandbox.c
drivers/tpm/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o obj-$(CONFIG_TPM_TIS_I2C) += tpm.o obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o +obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
drivers/tpm/tpm_tis_sandbox.c new file +262 -0
262 lines not on this page · raw message
include/configs/sandbox.h +2 -0
@@ -130,4 +130,6 @@#define CONFIG_LZO #define CONFIG_LZMA +#define CONFIG_TPM_TIS_SANDBOX +#endif
Signature · 1 line
1.8.4.1
PATCH 20/32 sandbox: dts: Add display and keyboard to sandbox
In reply to Simon GlassAdd an LCD display and keyboard to the sandbox device tree so that these features can be used.
--- board/sandbox/dts/sandbox.dts | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
board/sandbox/dts/sandbox.dts +62 -0
@@ -26,4 +26,66 @@ colour = "white"; sides = <6>; }; + + lcd { + compatible = "sandbox,lcd-sdl"; + xres = <800>; + yres = <600>; + }; + + cros-ec-keyb { + compatible = "google,cros-ec-keyb"; + google,key-rows = <8>; + google,key-columns = <13>; + google,repeat-delay-ms = <240>; + google,repeat-rate-ms = <30>; + google,ghost-filter; + /* + * Keymap entries take the form of 0xRRCCKKKK where + * RR=Row CC=Column KKKK=Key Code + * The values below are for a US keyboard layout and + * are taken from the Linux driver. Note that the + * 102ND key is not used for US keyboards. + */ + linux,keymap = < + /* CAPSLCK F1 B F10 */ + 0x0001003a 0x0002003b 0x00030030 0x00040044 + /* N = R_ALT ESC */ + 0x00060031 0x0008000d 0x000a0064 0x01010001 + /* F4 G F7 H */ + 0x0102003e 0x01030022 0x01040041 0x01060023 + /* ' F9 BKSPACE L_CTRL */ + 0x01080028 0x01090043 0x010b000e 0x0200001d + /* TAB F3 T F6 */ + 0x0201000f 0x0202003d 0x02030014 0x02040040 + /* ] Y 102ND [ */ + 0x0205001b 0x02060015 0x02070056 0x0208001a + /* F8 GRAVE F2 5 */ + 0x02090042 0x03010029 0x0302003c 0x03030006 + /* F5 6 - \ */ + 0x0304003f 0x03060007 0x0308000c 0x030b002b + /* R_CTRL A D F */ + 0x04000061 0x0401001e 0x04020020 0x04030021 + /* S K J ; */ + 0x0404001f 0x04050025 0x04060024 0x04080027 + /* L ENTER Z C */ + 0x04090026 0x040b001c 0x0501002c 0x0502002e + /* V X , M */ + 0x0503002f 0x0504002d 0x05050033 0x05060032 + /* L_SHIFT / . SPACE */ + 0x0507002a 0x05080035 0x05090034 0x050B0039 + /* 1 3 4 2 */ + 0x06010002 0x06020004 0x06030005 0x06040003 + /* 8 7 0 9 */ + 0x06050009 0x06060008 0x0608000b 0x0609000a + /* L_ALT DOWN RIGHT Q */ + 0x060a0038 0x060b006c 0x060c006a 0x07010010 + /* E R W I */ + 0x07020012 0x07030013 0x07040011 0x07050017 + /* U R_SHIFT P O */ + 0x07060016 0x07070036 0x07080019 0x07090018 + /* UP LEFT */ + 0x070b0067 0x070c0069>; + }; + };
Signature · 1 line
1.8.4.1
PATCH 21/32 sandbox: Add a prototype for cleanup_before_linux()
In reply to Simon GlassThis function is defined but has no prototype declaration. Add it.
--- arch/sandbox/include/asm/u-boot-sandbox.h | 2 ++ 1 file changed, 2 insertions(+)
arch/sandbox/include/asm/u-boot-sandbox.h +2 -0
@@ -23,4 +23,6 @@ int dram_init(void);int sandbox_early_getopt_check (void );int sandbox_main_loop_init (void ); +int cleanup_before_linux (void ); +#endif /* _U_BOOT_SANDBOX_H_ */
Signature · 1 line
1.8.4.1
PATCH 22/32 sandbox: tpm: Fix nvwrite command
In reply to Simon GlassFrom: Che-Liang Chiou <[email protected]>
The original codes misused recvbuf in source buffer instead of sendbuf, and read from incorrect offset 14 instead of 22.
--- drivers/tpm/tpm_tis_sandbox.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/tpm/tpm_tis_sandbox.c +1 -3
@@ -190,9 +190,7 @@ int tis_sendrecv(const u8 *sendbuf, size_t send_size,if (seq <0 )return -1 ;printf ("tpm: nvwrite index=%#02x, len=%#02x\n" , index, length); -memcpy (&tpm->nvdata[seq], - recvbuf +TPM_RESPONSE_HEADER_LENGTH +sizeof (uint32_t ), - length); +memcpy (&tpm->nvdata[seq], sendbuf +22 , length); *recv_len =12 ;memset (recvbuf,'\0' , *recv_len);break ;
Signature · 1 line
1.8.4.1
PATCH 23/32 cros_ec: Add an enum for the number of flash regions
In reply to Simon GlassAdd an enum for the number of flash regions so we can keep track of all the possible regions.
--- include/ec_commands.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/ec_commands.h +3 -1
@@ -536,7 +536,7 @@ struct ec_response_flash_protect {enum ec_flash_region {/* Region which holds read-only EC image */ -EC_FLASH_REGION_RO , +EC_FLASH_REGION_RO =0 ,/* Region which holds rewritable EC image */ EC_FLASH_REGION_RW ,/*
@@ -544,6 +544,8 @@ enum ec_flash_region {* EC_FLASH_REGION_RO) */ EC_FLASH_REGION_WP_RO , +/* Number of regions */ + EC_FLASH_REGION_COUNT, }; struct ec_params_flash_region_info {
Signature · 1 line
1.8.4.1
PATCH 24/32 fdt: Add a function for reading a flash map entry
In reply to Simon GlassA flash map describes the layout of flash memory in terms of offsets and sizes for each region. Add a function to read a flash map entry from the device tree.
(Unfortunately I had to change this commit to also touch cros/ but it is a very small change and can be removed for upstreaming.)
--- include/fdtdec.h | 18 ++++++++++++++++++ lib/fdtdec.c | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
include/fdtdec.h +18 -0
@@ -529,4 +529,22 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node,*/ int fdtdec_decode_region (const void *blob,int node,const char *prop_name,void **ptrp,size_t *size); + +/* A flash map entry, containing an offset and length */ +struct fmap_entry { +uint32_t offset; +uint32_t length; +}; + +/** +* Read a flash entry from the fdt +* +* @param blob FDT blob +* @param node Offset of node to read +* @param name Name of node being read +* @param entry Place to put offset and size of this node +* @return 0 if ok, -ve on error +*/ +int fdtdec_read_fmap_entry (const void *blob,int node,const char *name, +struct fmap_entry *entry);#endif
lib/fdtdec.c +24 -0
@@ -616,3 +616,27 @@ int fdtdec_decode_region(const void *blob, int node,debug ("%s: size=%zx\n" , __func__, *size);return 0 ; } + +/** +* Read a flash entry from the fdt +* +* @param blob FDT blob +* @param node Offset of node to read +* @param name Name of node being read +* @param entry Place to put offset and size of this node +* @return 0 if ok, -ve on error +*/ +int fdtdec_read_fmap_entry (const void *blob,int node,const char *name, +struct fmap_entry *entry) +{ +u32 reg[2 ]; + +if (fdtdec_get_int_array (blob, node,"reg" , reg,2 )) { +debug ("Node '%s' has bad/missing 'reg' property\n" , name); +return -FDT_ERR_NOTFOUND ; + } + entry->offset = reg[0 ]; + entry->length = reg[1 ]; + +return 0 ; +}
Signature · 1 line
1.8.4.1
PATCH 25/32 cros_ec: Move EC interface into common library
In reply to Simon GlassFrom: Vadim Bendebury <[email protected]>
Add a common library for obtaining access to the Chrome OS EC. This is used by boards which need to talk to the EC.
--- board/samsung/smdk5250/exynos5-dt.c | 5 ----- common/Makefile | 1 + common/cros_ec.c | 44 +++++++++++++++++++++++++++++++++++++ include/cros_ec.h | 18 +++++++++++++++ 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 common/cros_ec.c
board/samsung/smdk5250/exynos5-dt.c +0 -5
@@ -73,11 +73,6 @@ static void board_enable_audio_codec(void) }#endif -struct cros_ec_dev *board_get_cros_ec_dev (void ) -{ -return local.cros_ec_dev; -} -static int board_init_cros_ec_devices (const void *blob) { local.cros_ec_err =cros_ec_init (blob, &local.cros_ec_dev);
common/Makefile +1 -0
@@ -222,6 +222,7 @@ obj-$(SPD) += ddr_spd.o obj-$(CONFIG_HWCONFIG) += hwconfig.o obj-$(CONFIG_BOUNCE_BUFFER) += bouncebuf.o obj-y += console.o +obj-$(CONFIG_CROS_EC) += cros_ec.o obj-y += dlmalloc.o obj-y += image.o obj-$(CONFIG_OF_LIBFDT) += image-fdt.o
common/cros_ec.c new file +44 -0
44 lines not on this page · raw message
include/cros_ec.h +18 -0
@@ -431,4 +431,22 @@ int cros_ec_set_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t state);* @return 0 if ok, -1 on error */ int cros_ec_get_ldo (struct cros_ec_dev *dev,uint8_t index,uint8_t *state); + +/** +* Initialize the Chrome OS EC at board initialization time. +* +* @return 0 if ok, -ve on error +*/ +int cros_ec_board_init (void ); + +/** +* Get access to the error reported when cros_ec_board_init() was called +* +* This permits delayed reporting of the EC error if it failed during +* early init. +* +* @return error (0 if there was no error, -ve if there was an error) +*/ +int cros_ec_get_error (void ); +#endif
Signature · 1 line
1.8.4.1
PATCH 26/32 cros_ec: Add a function for decoding the Chrome OS EC flashmap
In reply to Simon GlassIn order to talk to the EC properly we need to be able to understand the layout of its internal flash memory. This permits emulation of the EC for sandbox, and also software system with a real EC.
--- drivers/misc/cros_ec.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/cros_ec.h | 19 +++++++++++++++++++ 2 files changed, 69 insertions(+)
drivers/misc/cros_ec.c +50 -0
@@ -958,6 +958,56 @@ int cros_ec_decode_region(int argc, char * const argv[])return -1 ; } +int cros_ec_decode_ec_flash (const void *blob,struct fdt_cros_ec *config) +{ +int flash_node, node; + + node =fdtdec_next_compatible (blob,0 ,COMPAT_GOOGLE_CROS_EC ); +if (node <0 ) { +debug ("Failed to find chrome-ec node'\n" ); +return -1 ; + } + + flash_node =fdt_subnode_offset (blob, node,"flash" ); +if (flash_node <0 ) { +debug ("Failed to find flash node\n" ); +return -1 ; + } + +if (fdtdec_read_fmap_entry (blob, flash_node,"flash" , + &config->flash)) { +debug ("Failed to decode flash node in chrome-ec'\n" ); +return -1 ; + } + + config->flash_erase_value =fdtdec_get_int (blob, flash_node, +"erase-value" ,-1 ); +for (node =fdt_first_subnode (blob, flash_node); node >=0 ; + node =fdt_next_subnode (blob, node)) { +const char *name =fdt_get_name (blob, node,NULL ); +enum ec_flash_region region; + +if (0 ==strcmp (name,"ro" )) { + region =EC_FLASH_REGION_RO ; + }else if (0 ==strcmp (name,"rw" )) { + region =EC_FLASH_REGION_RW ; + }else if (0 ==strcmp (name,"wp-ro" )) { + region =EC_FLASH_REGION_WP_RO ; + }else { +debug ("Unknown EC flash region name '%s'\n" , name); +return -1 ; + } + +if (fdtdec_read_fmap_entry (blob, node,"reg" , + &config->region[region])) { +debug ("Failed to decode flash region in chrome-ec'\n" ); +return -1 ; + } + } + +return 0 ; +} +/** * Perform a flash read or write command *
include/cros_ec.h +19 -0
@@ -63,6 +63,17 @@ struct mbkp_keyscan {uint8_t data[CROS_EC_KEYSCAN_COLS ]; }; +/* Holds information about the Chrome EC */ +struct fdt_cros_ec { +struct fmap_entry flash;/* Address and size of EC flash */ +/* +* Byte value of erased flash, or -1 if not known. It is normally +* 0xff but some flash devices use 0 (e.g. STM32Lxxx) +*/ +int flash_erase_value; +struct fmap_entry region[EC_FLASH_REGION_COUNT ]; +}; +/** * Read the ID of the CROS-EC device *
@@ -449,4 +460,12 @@ int cros_ec_board_init(void);*/ int cros_ec_get_error (void ); +/** +* Returns information from the FDT about the Chrome EC flash +* +* @param blob FDT blob to use +* @param config Structure to use to return information +*/ +int cros_ec_decode_ec_flash (const void *blob,struct fdt_cros_ec *config); +#endif
Signature · 1 line
1.8.4.1
PATCH 27/32 cros_ec: sandbox: Add Chrome OS EC emulation
In reply to Simon GlassAdd a simple emulation of the Chrome OS EC for sandbox, so that it can perform various EC tasks required by verified boot.
--- drivers/misc/Makefile | 1 + drivers/misc/cros_ec_sandbox.c | 558 +++++++++++++++++++++++++++++++++++++++++ include/cros_ec.h | 8 + include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 5 files changed, 569 insertions(+) create mode 100644 drivers/misc/cros_ec_sandbox.c
drivers/misc/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o obj-$(CONFIG_CROS_EC) += cros_ec.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpc.o obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o +obj-$(CONFIG_CROS_EC_SANDBOX) += cros_ec_sandbox.o obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o obj-$(CONFIG_FSL_IIM) += fsl_iim.o obj-$(CONFIG_GPIO_LED) += gpio_led.o
drivers/misc/cros_ec_sandbox.c new file +558 -0
558 lines not on this page · raw message
include/cros_ec.h +8 -0
@@ -468,4 +468,12 @@ int cros_ec_get_error(void);*/ int cros_ec_decode_ec_flash (const void *blob,struct fdt_cros_ec *config); +/** +* Check the current keyboard state, in case recovery mode is requested. +* This function is for sandbox only. +* +* @param ec CROS-EC device +*/ +void cros_ec_check_keyboard (struct cros_ec_dev *dev); +#endif
include/fdtdec.h +1 -0
@@ -87,6 +87,7 @@ enum fdt_compat_id {COMPAT_INFINEON_SLB9635_TPM ,/* Infineon SLB9635 TPM */ COMPAT_INFINEON_SLB9645_TPM ,/* Infineon SLB9645 TPM */ COMPAT_SAMSUNG_EXYNOS5_I2C ,/* Exynos5 High Speed I2C Controller */ +COMPAT_SANDBOX_HOST_EMULATION ,/* Sandbox emulation of a function */ COMPAT_COUNT, };
lib/fdtdec.c +1 -0
@@ -60,6 +60,7 @@ static const char * const compat_names[COMPAT_COUNT] = {COMPAT (INFINEON_SLB9635_TPM ,"infineon,slb9635-tpm" ),COMPAT (INFINEON_SLB9645_TPM ,"infineon,slb9645-tpm" ),COMPAT (SAMSUNG_EXYNOS5_I2C ,"samsung,exynos5-hsi2c" ), + COMPAT(SANDBOX_HOST_EMULATION, "sandbox,host-emulation"), };const char *fdtdec_get_compatible (enum fdt_compat_id id)
Signature · 1 line
1.8.4.1
PATCH 28/32 sandbox: Add os_jump_to_image() to run another executable
In reply to Simon GlassFor some tests it is useful to be able to run U-Boot again but pass on the same memory contents. Add a function to achieve this.
--- arch/sandbox/cpu/os.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/os.h | 19 +++++++++++ 2 files changed, 108 insertions(+)
arch/sandbox/cpu/os.c +89 -0
@@ -438,3 +438,92 @@ int os_read_ram_buf(const char *fname)return 0 ; } + +static int make_exec (char *fname,const void *data,int size) +{ +int fd; + +strcpy (fname,"/tmp/u-boot.jump.XXXXXX" ); + fd =mkstemp (fname); +if (fd <0 ) +return -ENOENT ; +if (write (fd, data, size) <0 ) +return -EIO ; +close (fd); +if (chmod (fname,0777 )) +return -ENOEXEC ; + +return 0 ; +} + +static int add_args (char ***argvp,const char *add_args[],int count) +{ +char **argv; +int argc; + +for (argv = *argvp, argc =0 ; (*argvp)[argc]; argc++) + ; + + argv =malloc ((argc + count +1 ) *sizeof (char *)); +if (!argv) { +printf ("Out of memory for %d argv\n" , count); +return -ENOMEM ; + } +memcpy (argv, *argvp, argc *sizeof (char *)); +memcpy (argv + argc, add_args, count *sizeof (char *)); + argv[argc + count] =NULL ; + + *argvp = argv; +return 0 ; +} + +int os_jump_to_image (const void *dest,int size) +{ +struct sandbox_state *state =state_get_current (); +char fname[30 ], mem_fname[30 ]; +int fd, err; +const char *extra_args[4 ]; +char **argv = state->argv; +#ifdef DEBUG +int argc, i; +#endif + + err =make_exec (fname, dest, size); +if (err) +return err; + +strcpy (mem_fname,"/tmp/u-boot.mem.XXXXXX" ); + fd =mkstemp (mem_fname); +if (fd <0 ) +return -ENOENT ; +close (fd); + err =os_write_ram_buf (mem_fname); +if (err) +return err; + +os_fd_restore (); + + extra_args[0 ] ="-j" ; + extra_args[1 ] = fname; + extra_args[2 ] ="-m" ; + extra_args[3 ] = mem_fname; + err =add_args (&argv, extra_args, +sizeof (extra_args) /sizeof (extra_args[0 ])); +if (err) +return err; + +#ifdef DEBUG +for (i =0 ; argv[i]; i++) +printf ("%d %s\n" , i, argv[i]); +#endif + +if (state_uninit ()) +os_exit (2 ); + + err =execv (fname, argv); +free (argv); +if (err) +return err; + +return unlink (fname); +}
include/os.h +19 -0
@@ -245,4 +245,23 @@ int os_write_ram_buf(const char *fname);*/ int os_read_ram_buf (const char *fname); +/** +* Jump to a new executable image +* +* This uses exec() to run a new executable image, after putting it in a +* temporary file. The same arguments and environment are passed to this +* new image, with the addition of: +* +* -j <filename> Specifies the filename the image was written to. The +* calling image may want to delete this at some point. +* -m <filename> Specifies the file containing the sandbox memory +* (ram_buf) from this image, so that the new image can +* have access to this. It also means that the original +* memory filename passed to U-Boot will be left intact. +* +* @param dest Buffer containing executable image +* @param size Size of buffer +*/ +int os_jump_to_image (const void *dest,int size); +#endif
Signature · 1 line
1.8.4.1
PATCH 29/32 sandbox: Add -j option to indicate a jump from a previous U-Boot
In reply to Simon GlassIn order to support the 'go' command we allow the jumping U-Boot to pass its filename to the new U-Boot image. This can then be used to delete that image if required.
--- arch/sandbox/cpu/start.c | 16 ++++++++++++++++ arch/sandbox/include/asm/state.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-)
arch/sandbox/cpu/start.c +16 -0
@@ -107,6 +107,22 @@ static int sandbox_cmdline_cb_interactive(struct sandbox_state *state,SANDBOX_CMDLINE_OPT_SHORT (interactive,'i' ,0 ,"Enter interactive mode" ); +static int sandbox_cmdline_cb_jump (struct sandbox_state *state, +const char *arg) +{ + state->jumped =1 ; + +/* +* TODO(sjg at chromium.org): Note this causes problems for gdb which +* wants to read debug data from the image. +* +* os_unlink(arg); +*/ + +return 0 ; +} +SANDBOX_CMDLINE_OPT_SHORT (jump,'j' ,1 ,"Jumped from previous U-Boot" ); +static int sandbox_cmdline_cb_memory (struct sandbox_state *state,const char *arg) {
arch/sandbox/include/asm/state.h +2 -1
@@ -30,7 +30,8 @@ struct sandbox_state {enum exit_type_id exit_type;/* How we exited U-Boot */ const char *parse_err;/* Error to report from parsing */ int argc;/* Program arguments */ -char **argv; +char **argv;/* Command line arguments */ +bool jumped;/* Jumped from previous U_Boot */ uint8_t *ram_buf;/* Emulated RAM buffer */ unsigned int ram_size;/* Size of RAM buffer */ const char *ram_buf_fname;/* Filename to use for RAM buffer */
Signature · 1 line
1.8.4.1
PATCH 30/32 sandbox: Add SDL library for LCD, keyboard, audio
In reply to Simon GlassSDL (Simple DirectMedia Layer - see www.libsdl.org) is a library which provides simple graphics and sound features. It works under X11 and also with a simple frame buffer interface. It is ideally suited to sandbox U-Boot since it fits nicely with the low-level feature set required by U-Boot. For example, U-Boot has its own font drawing routines, its own keyboard processing and just needs raw sound output.
We can use SDL to provide emulation of these basic functions for sandbox. This significantly expands the testing that is possible with sandbox.
Add a basic SDL library which we will use in future commits.
--- arch/sandbox/config.mk | 5 + arch/sandbox/cpu/Makefile | 6 + arch/sandbox/cpu/sdl.c | 332 +++++++++++++++++++++++++++++++++++++++++ arch/sandbox/include/asm/sdl.h | 20 +++ 4 files changed, 363 insertions(+) create mode 100644 arch/sandbox/cpu/sdl.c create mode 100644 arch/sandbox/include/asm/sdl.h
arch/sandbox/config.mk +5 -0
@@ -5,6 +5,11 @@ PLATFORM_CPPFLAGS += -DCONFIG_SANDBOX -D__SANDBOX__ -U_FORTIFY_SOURCE PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM -DCONFIG_SYS_GENERIC_BOARD PLATFORM_LIBS += -lrt +ifdef CONFIG_SANDBOX_SDL +PLATFORM_LIBS += $(shell sdl-config --libs) +PLATFORM_CPPFLAGS += $(shell sdl-config --cflags) +endif + # Support generic board on sandbox __HAVE_ARCH_GENERIC_BOARD := y
arch/sandbox/cpu/Makefile +6 -0
@@ -8,9 +8,15 @@ # obj-y := cpu.o os.o start.o state.o +obj-$(CONFIG_SANDBOX_SDL) += sdl.o # os.c is build in the system environment, so needs standard includes $(obj)os.o: ALL_CFLAGS := $(BASE_CPPFLAGS) \ $(patsubst %, -idirafter %, $(BASE_INCLUDE_DIRS)) $(obj).depend.os: CPPFLAGS := $(BASE_CPPFLAGS) \ $(patsubst %, -idirafter %, $(BASE_INCLUDE_DIRS)) + +$(obj)sdl.o: ALL_CFLAGS := $(BASE_CPPFLAGS) \ + $(patsubst %, -idirafter %, $(BASE_INCLUDE_DIRS)) +$(obj).depend.sdl: CPPFLAGS := $(BASE_CPPFLAGS) \ + $(patsubst %, -idirafter %, $(BASE_INCLUDE_DIRS))
arch/sandbox/cpu/sdl.c new file +332 -0
332 lines not on this page · raw message
arch/sandbox/include/asm/sdl.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __SANDBOX_SDL_H +#define __SANDBOX_SDL_H + +int sandbox_sdl_init_display (int width,int height,int log2_bpp); +int sandbox_sdl_sync (void *lcd_base); + +int sandbox_sdl_scan_keys (int key[],int max_keys); +int sandbox_sdl_key_pressed (int keycode); + +int sandbox_sdl_sound_start (uint frequency); +int sandbox_sdl_sound_stop (void ); +int sandbox_sdl_sound_init (void ); + +#endif
Signature · 1 line
1.8.4.1
PATCH 31/32 sandbox: Add a simple sound driver
In reply to Simon GlassAdd a sound driver for sandbox, which uses SDL.
--- arch/sandbox/include/asm/arch-sandbox/sound.h | 14 ++++++++++++++ drivers/sound/Makefile | 2 ++ drivers/sound/sandbox.c | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 arch/sandbox/include/asm/arch-sandbox/sound.h create mode 100644 drivers/sound/sandbox.c
arch/sandbox/include/asm/arch-sandbox/sound.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __SANDBOX_SOUND_H +#define __SANDBOX_SOUND_H + +int sound_play (unsigned int msec,unsigned int frequency); + +int sound_init (const void *blob); + +#endif
drivers/sound/Makefile +2 -0
@@ -7,5 +7,7 @@ obj-$(CONFIG_SOUND) += sound.o obj-$(CONFIG_I2S) += samsung-i2s.o +obj-$(CONFIG_I2S_SAMSUNG) += samsung-i2s.o +obj-$(CONFIG_SOUND_SANDBOX) += sandbox.o obj-$(CONFIG_SOUND_WM8994) += wm8994.o obj-$(CONFIG_SOUND_MAX98095) += max98095.o
drivers/sound/sandbox.c new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <asm/arch/sound.h> +#include <asm/sdl.h> + +int sound_play (uint32_t msec,uint32_t frequency) +{ +sandbox_sdl_sound_start (frequency); +mdelay (msec); +sandbox_sdl_sound_stop (); + +return 0 ; +} + +int sound_init (const void *blob) +{ +return sandbox_sdl_sound_init (); +}
Signature · 1 line
1.8.4.1
PATCH 32/32 sandbox: Add LCD driver
In reply to Simon GlassAdd a simple LCD driver which uses SDL to display the image. We update the image regularly, while still providing for reasonable performance.
Adjust the common lcd code to support sandbox.
For command-line runs we do not want the LCD to be displayed, so add a --hide_lcd option to disable it.
--- arch/sandbox/cpu/sdl.c | 4 +- arch/sandbox/cpu/start.c | 9 ++++ arch/sandbox/include/asm/state.h | 1 + arch/sandbox/include/asm/u-boot-sandbox.h | 3 ++ board/sandbox/sandbox/sandbox.c | 19 +++++++- common/lcd.c | 21 ++++++-- doc/device-tree-bindings/video/sandbox-fb.txt | 13 +++++ drivers/serial/sandbox.c | 4 ++ drivers/video/Makefile | 1 + drivers/video/sandbox_sdl.c | 70 +++++++++++++++++++++++++++ include/fdtdec.h | 1 + include/lcd.h | 3 ++ lib/fdtdec.c | 1 + 13 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 doc/device-tree-bindings/video/sandbox-fb.txt create mode 100644 drivers/video/sandbox_sdl.c
arch/sandbox/cpu/sdl.c +3 -1
@@ -55,7 +55,9 @@ static int sandbox_sdl_ensure_init(void)int sandbox_sdl_init_display (int width,int height,int log2_bpp) { -if (!width) +struct sandbox_state *state =state_get_current (); + +if (!width || state->hide_lcd)return 0 ;if (sandbox_sdl_ensure_init ())return -1 ;
arch/sandbox/cpu/start.c +9 -0
@@ -175,6 +175,15 @@ static int sandbox_cmdline_cb_ignore_missing(struct sandbox_state *state,SANDBOX_CMDLINE_OPT_SHORT (ignore_missing,'n' ,0 ,"Ignore missing state on read" ); +static int sandbox_cmdline_cb_hide_lcd (struct sandbox_state *state, +const char *arg) +{ + state->hide_lcd = true; +return 0 ; +} +SANDBOX_CMDLINE_OPT_SHORT (hide_lcd,'l' ,0 , +"Don't show the sandbox LCD display" ); +int main (int argc,char *argv[]) {struct sandbox_state *state;
arch/sandbox/include/asm/state.h +1 -0
@@ -41,6 +41,7 @@ struct sandbox_state {bool read_state;/* Read sandbox state on startup */ bool write_state;/* Write sandbox state on exit */ bool ignore_missing_state_on_read;/* No error if state missing */ +bool hide_lcd;/* Hide LCD on start-up */ /* Pointer to information for each SPI bus/cs */ struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS ]
arch/sandbox/include/asm/u-boot-sandbox.h +3 -0
@@ -25,4 +25,7 @@ int sandbox_main_loop_init(void);int cleanup_before_linux (void ); +/* drivers/video/sandbox_sdl.c */ +int sandbox_lcd_sdl_early_init (void ); +#endif /* _U_BOOT_SANDBOX_H_ */
board/sandbox/sandbox/sandbox.c +18 -1
@@ -4,8 +4,8 @@*/ #include <common.h> -#include <os.h> +#include <asm/u-boot-sandbox.h> /* * Pointer to initial global data area
@@ -33,3 +33,20 @@ int dram_init(void) gd->ram_size =CONFIG_SYS_SDRAM_SIZE ;return 0 ; } + +#ifdef CONFIG_BOARD_EARLY_INIT_F +int board_early_init_f (void ) +{ +#ifdef CONFIG_VIDEO_SANDBOX_SDL +int ret; + + ret =sandbox_lcd_sdl_early_init (); +if (ret) { +puts ("Could not init sandbox LCD emulation\n" ); +return ret; + } +#endif + +return 0 ; +} +#endif
common/lcd.c +17 -4
@@ -28,6 +28,8 @@#include <watchdog.h> #include <splash.h> +#include <asm/io.h> +#include <asm/unaligned.h> #if defined(CONFIG_CPU_PXA25X ) || defined(CONFIG_CPU_PXA27X ) || \ defined(CONFIG_CPU_MONAHANS )
@@ -63,6 +65,10 @@# endif #endif +#ifdef CONFIG_SANDBOX +#include <asm/sdl.h> +#endif +#ifndef CONFIG_LCD_ALIGNMENT #define CONFIG_LCD_ALIGNMENT PAGE_SIZE#endif
@@ -144,6 +150,13 @@ void lcd_sync(void)if (lcd_flush_dcache)flush_dcache_range ((u32 )lcd_base, (u32)(lcd_base +lcd_get_size (&line_length))); +#elif defined(CONFIG_SANDBOX ) && defined(CONFIG_VIDEO_SANDBOX_SDL ) +static ulong last_sync; + +if (get_timer (last_sync) >10 ) { +sandbox_sdl_sync (lcd_base); + last_sync =get_timer (0 ); + }#endif }
@@ -398,7 +411,7 @@ int drv_lcd_init(void)struct stdio_dev lcddev;int rc; - lcd_base = (void *) gd->fb_base; + lcd_base =map_sysmem (gd->fb_base,0 );lcd_init (lcd_base);/* LCD initialization */
@@ -489,8 +502,8 @@ static int lcd_init(void *lcdbase)* by setting up gd->fb_base. Check for this condition and fixup * 'lcd_base' address. */ -if ((unsigned long )lcdbase != gd->fb_base) - lcd_base = (void *)gd->fb_base; +if (map_to_sysmem (lcdbase) != gd->fb_base) + lcd_base =map_sysmem (gd->fb_base,0 );debug ("[LCD] Using LCD frambuffer at %p\n" , lcd_base);
@@ -882,7 +895,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)ushort *cmap_base =NULL ;ushort i, j;uchar *fb; -bmp_image_t *bmp=(bmp_image_t *)bmp_image; +bmp_image_t *bmp = (bmp_image_t *)map_sysmem (bmp_image,0 );uchar *bmap;ushort padded_width;unsigned long width, height, byte_width;
doc/device-tree-bindings/video/sandbox-fb.txt new file +13 -0
@@ -0,0 +1,13 @@ +Sandbox LCD +=========== + +This uses the displaymode.txt binding except that only xres and yres are +required properties. + +Example: + + lcd { + compatible = "sandbox,lcd-sdl"; + xres = <800>; + yres = <600>; + };
drivers/serial/sandbox.c +4 -0
@@ -11,6 +11,7 @@*/ #include <common.h> +#include <lcd.h> #include <os.h> #include <serial.h> #include <linux/compiler.h>
@@ -60,6 +61,9 @@ static int sandbox_serial_tstc(void)ssize_t count;os_usleep (100 ); +#ifdef CONFIG_LCD +lcd_sync (); +#endif if (next_index == serial_buf_read)return 1 ;/* buffer full */
drivers/video/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_VIDEO_MX3) += mx3fb.o videomodes.o obj-$(CONFIG_VIDEO_IPUV3) += mxc_ipuv3_fb.o ipu_common.o ipu_disp.o obj-$(CONFIG_VIDEO_MXS) += mxsfb.o videomodes.o obj-$(CONFIG_VIDEO_OMAP3) += omap3_dss.o +obj-$(CONFIG_VIDEO_SANDBOX_SDL) += sandbox_sdl.o obj-$(CONFIG_VIDEO_SED13806) += sed13806.o obj-$(CONFIG_VIDEO_SM501) += sm501.o obj-$(CONFIG_VIDEO_SMI_LYNXEM) += smiLynxEM.o videomodes.o
drivers/video/sandbox_sdl.c new file +70 -0
70 lines not on this page · raw message
include/fdtdec.h +1 -0
@@ -88,6 +88,7 @@ enum fdt_compat_id {COMPAT_INFINEON_SLB9645_TPM ,/* Infineon SLB9645 TPM */ COMPAT_SAMSUNG_EXYNOS5_I2C ,/* Exynos5 High Speed I2C Controller */ COMPAT_SANDBOX_HOST_EMULATION ,/* Sandbox emulation of a function */ +COMPAT_SANDBOX_LCD_SDL ,/* Sandbox LCD emulation with SDL */ COMPAT_COUNT, };
include/lcd.h +3 -0
@@ -311,6 +311,9 @@ int lcd_get_size(int *line_length);int lcd_dt_simplefb_add_node (void *blob);int lcd_dt_simplefb_enable_existing_node (void *blob); +/* Update the LCD / flush the cache */ +void lcd_sync (void ); +/************************************************************************/ /* ** BITMAP DISPLAY SUPPORT */ /************************************************************************/
lib/fdtdec.c +1 -0
@@ -61,6 +61,7 @@ static const char * const compat_names[COMPAT_COUNT] = {COMPAT (INFINEON_SLB9645_TPM ,"infineon,slb9645-tpm" ),COMPAT (SAMSUNG_EXYNOS5_I2C ,"samsung,exynos5-hsi2c" ),COMPAT (SANDBOX_HOST_EMULATION ,"sandbox,host-emulation" ), + COMPAT(SANDBOX_LCD_SDL, "sandbox,lcd-sdl"), };const char *fdtdec_get_compatible (enum fdt_compat_id id)
Signature · 1 line
1.8.4.1
PATCH 32/32 sandbox: Add LCD driver
Hello Simon.
Quoted 10 lines
Add a simple LCD driver which uses SDL to display the image. We update the image regularly, while still providing for reasonable performance.
Adjust the common lcd code to support sandbox.
For command-line runs we do not want the LCD to be displayed, so add a --hide_lcd option to disable it.
Signed-off-by Simon Glass <[email protected]>Signed-off-by Simon Glass <[email protected]>
Please be careful to not double Signed-off-by.
I think you used patman to post this series.
This is a problem of patman.
Patman always adds Signed-off-by
even when it had been already added to log by hand.
Best Regards
Masahiro Yamada
PATCH 32/32 sandbox: Add LCD driver
Hi Masahiro,
Quoted 15 lines · Masahiro Yamada
Hello Simon.
Quoted 10 lines
Add a simple LCD driver which uses SDL to display the image. We update the image regularly, while still providing for reasonable performance.
Adjust the common lcd code to support sandbox.
For command-line runs we do not want the LCD to be displayed, so add a --hide_lcd option to disable it.
Signed-off-by Simon Glass <[email protected]>Signed-off-by Simon Glass <[email protected]>
Quoted 7 lines
Please be careful to not double Signed-off-by.
I think you used patman to post this series.
This is a problem of patman.Patman always adds Signed-off-by
even when it had been already added to log by hand.
Yes. Commit c737914 went part of the way to this, but it needs an adjustment. I think I will remove duplicate sign-offs by default.
Regards,
Simon