Add additional sandbox features and infrastructure
Subsystems (8)
v2 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 added, 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
- 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)
Major functions which still remain without sandbox support are I2C, networking and USB.
Note:
Much of this series was sent out in November. Due to problems with the LCD side it was not ready for the last release, although about a dozen patches from the series were applied. I have rebased and tidied things up. U-Boot now starts by default without the LCD visible since for much sandbox testing we don't want the LCD. The Chrome OS EC code has been updated and tidied up and full keyboard support is now present in the LCD window.
Changes in v2:
- Add new patch to adjust #ifdef position in cros_ec
- Add new patch to sync with latest Chrome OS EC version
- Add new patches to bring in protocol v3 support
- Rebase to master
- Update series to take account of patches now merges from original series
Randall Spangler (2):
cros_ec: Clean up multiple EC protocol support
cros_ec: spi: Add support for EC protocol version 3
Simon Glass (27):
Use a const pointer for map_to_sysmem()
sandbox: Increase memory size to 32MB
sandbox: Build a device tree file for sandbox
sandbox: Use os functions to read host device tree
sandbox: dts: Add display and keyboard to sandbox
cros_ec: Add an enum for the number of flash regions
cros_ec: Add a function for reading a flash map entry
cros_ec: Add a function for decoding the Chrome OS EC flashmap
cros_ec: Support systems with no EC interrupt
cros_ec: Move #ifdef to permit flash region access
cros_ec: Sync up with latest Chrome OS EC version
cros_ec: Add base support for protocol v3
cros_ec: Correct comparison between signed and unsigned numbers
cros_ec: sandbox: Add Chrome OS EC emulation
sandbox: Plumb in Chrome OS EC emulation
cros_ec: Implement I2C pass-through
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
sound: Move Samsung-specific code into its own file
sandbox: Deal with conflicting getenv() for SDL
sandbox: Allow Ctrl-C to work in sandbox
sandbox: Add options to clean up temporary files
sandbox: Add implementation of spi_setup_slave_fdt()
sandbox: config: Enable cros_ec emulation and related items
Vadim Bendebury (2):
cros_ec: Move EC interface into common library
cros_ec: Drop old EC version support from EC driver
Makefile | 3 +- arch/sandbox/config.mk | 5 + arch/sandbox/cpu/Makefile | 3 + arch/sandbox/cpu/cpu.c | 2 +- arch/sandbox/cpu/os.c | 108 ++++- arch/sandbox/cpu/sdl.c | 341 ++++++++++++++ arch/sandbox/cpu/start.c | 60 +++ arch/sandbox/cpu/state.c | 6 +- arch/sandbox/dts/Makefile | 11 + arch/sandbox/dts/sandbox.dts | 125 ++++++ arch/sandbox/include/asm/arch-sandbox/sound.h | 14 + arch/sandbox/include/asm/sdl.h | 118 +++++ arch/sandbox/include/asm/state.h | 29 +- arch/sandbox/include/asm/u-boot-sandbox.h | 3 + board/samsung/common/board.c | 29 +- board/samsung/smdk5250/exynos5-dt.c | 1 - board/sandbox/sandbox/sandbox.c | 49 ++- common/Makefile | 1 + common/board_f.c | 48 +- common/cros_ec.c | 44 ++ common/lcd.c | 21 +- disk/part.c | 17 - doc/device-tree-bindings/video/sandbox-fb.txt | 13 + drivers/input/cros_ec_keyb.c | 34 +- drivers/misc/Makefile | 1 + drivers/misc/cros_ec.c | 611 +++++++++++++++++++++++--- drivers/misc/cros_ec_i2c.c | 64 ++- drivers/misc/cros_ec_lpc.c | 80 +--- drivers/misc/cros_ec_sandbox.c | 559 +++++++++++++++++++++++ drivers/misc/cros_ec_spi.c | 30 ++ drivers/serial/sandbox.c | 10 +- drivers/sound/Makefile | 4 +- drivers/sound/sandbox.c | 23 + drivers/sound/sound-i2s.c | 208 +++++++++ drivers/sound/sound.c | 221 +--------- drivers/spi/sandbox_spi.c | 13 + drivers/video/Makefile | 1 + drivers/video/sandbox_sdl.c | 79 ++++ include/common.h | 6 + include/configs/exynos5250-dt.h | 1 + include/configs/sandbox.h | 41 +- include/cros_ec.h | 94 +++- include/cros_ec_message.h | 2 +- include/ec_commands.h | 348 +++++++++++++-- include/fdtdec.h | 20 + include/lcd.h | 3 + include/os.h | 27 +- include/sound.h | 9 + lib/fdtdec.c | 26 ++ 49 files changed, 3032 insertions(+), 534 deletions(-) create mode 100644 arch/sandbox/cpu/sdl.c create mode 100644 arch/sandbox/dts/Makefile create mode 100644 arch/sandbox/dts/sandbox.dts create mode 100644 arch/sandbox/include/asm/arch-sandbox/sound.h create mode 100644 arch/sandbox/include/asm/sdl.h create mode 100644 common/cros_ec.c create mode 100644 doc/device-tree-bindings/video/sandbox-fb.txt create mode 100644 drivers/misc/cros_ec_sandbox.c create mode 100644 drivers/sound/sandbox.c create mode 100644 drivers/sound/sound-i2s.c create mode 100644 drivers/video/sandbox_sdl.c
Signature · 6 lines
1.9.0.279.gdc9e3eb -- 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 v2 1/31 Use a const pointer for map_to_sysmem()
This function does not actually change the pointer contents, so use const so that functions which have a const pointer do not need to cast.
---
Changes in v2: None
arch/sandbox/cpu/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/cpu/cpu.c +1 -1
@@ -58,7 +58,7 @@ 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) +phys_addr_t map_to_sysmem (const void *ptr) {return (u8 *)ptr - gd->arch.ram_buf; }
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 2/31 sandbox: Increase memory size to 32MB
In reply to Simon GlassThe current 4MB size is a little small for some tests, so increase it.
---
Changes in v2: None
include/configs/sandbox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/sandbox.h +1 -1
@@ -57,7 +57,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.9.0.279.gdc9e3eb
PATCH v2 3/31 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
---
Changes in v2: None
Makefile | 3 ++- arch/sandbox/dts/Makefile | 11 +++++++++++ arch/sandbox/dts/sandbox.dts | 30 ++++++++++++++++++++++++++++++ include/configs/sandbox.h | 1 + 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 arch/sandbox/dts/Makefile create mode 100644 arch/sandbox/dts/sandbox.dts
Makefile +2 -1
@@ -720,6 +720,7 @@ ALL-$(CONFIG_SPL) += spl/u-boot-spl.bin ALL-$(CONFIG_SPL_FRAMEWORK) += u-boot.img ALL-$(CONFIG_TPL) += tpl/u-boot-tpl.bin ALL-$(CONFIG_OF_SEPARATE) += u-boot.dtb u-boot-dtb.bin +ALL-$(CONFIG_OF_HOSTFILE) += u-boot.dtb ifneq ($(CONFIG_SPL_TARGET),) ALL-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%) endif
@@ -1371,7 +1372,7 @@ endif $(build)=$(build-dir) $(@:.ko=.o) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost -# FIXME Should go into a make.lib or something +# FIXME Should go into a make.lib or something # =========================================================================== quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
arch/sandbox/dts/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +dtb-$(CONFIG_SANDBOX) += sandbox.dtb + +targets += $(dtb-y) + +DTC_FLAGS += -R 4 -p 0x1000 + +PHONY += dtbs +dtbs: $(addprefix $(obj)/, $(dtb-y)) + @: + +clean-files := *.dtb
arch/sandbox/dts/sandbox.dts new file +30 -0
@@ -0,0 +1,30 @@ +/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.9.0.279.gdc9e3eb
PATCH v2 4/31 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.
---
Changes in v2: None
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
@@ -452,23 +452,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.9.0.279.gdc9e3eb
A message that is not in the archive (sent off-list or not yet received): 1393532785-9020-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
PATCH v2 5/31 sandbox: dts: Add display and keyboard to sandbox
Add an LCD display and keyboard to the sandbox device tree so that these features can be used.
---
Changes in v2: None
arch/sandbox/dts/sandbox.dts | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+)
arch/sandbox/dts/sandbox.dts +95 -0
@@ -27,4 +27,99 @@ sides = <6>; }; + host@0 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "sandbox,host-emulation"; + cros-ec@0 { + reg = <0>; + compatible = "google,cros-ec"; + + /* + * This describes the flash memory within the EC. Note + * that the STM32L flash erases to 0, not 0xff. + */ + #address-cells = <1>; + #size-cells = <1>; + flash@8000000 { + reg = <0x08000000 0x20000>; + erase-value = <0>; + #address-cells = <1>; + #size-cells = <1>; + + /* Information for sandbox */ + ro { + reg = <0 0xf000>; + }; + wp-ro { + reg = <0xf000 0x1000>; + }; + rw { + reg = <0x10000 0x10000>; + }; + }; + }; + }; + + 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 · 6 lines
1.9.0.279.gdc9e3eb -- 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 v2 6/31 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.
---
Changes in v2: None
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.9.0.279.gdc9e3eb
PATCH v2 7/31 cros_ec: 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.
---
Changes in v2: None
include/fdtdec.h | 18 ++++++++++++++++++ lib/fdtdec.c | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
include/fdtdec.h +18 -0
@@ -530,4 +530,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
@@ -617,3 +617,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.9.0.279.gdc9e3eb
PATCH v2 8/31 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.
---
Changes in v2: None
board/samsung/common/board.c | 29 +++--------------------- board/samsung/smdk5250/exynos5-dt.c | 1 - common/Makefile | 1 + common/cros_ec.c | 44 +++++++++++++++++++++++++++++++++++++ include/cros_ec.h | 18 +++++++++++++++ 5 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 common/cros_ec.c
board/samsung/common/board.c +3 -26
@@ -26,13 +26,6 @@DECLARE_GLOBAL_DATA_PTR ; -struct local_info { -struct cros_ec_dev *cros_ec_dev;/* Pointer to cros_ec device */ -int cros_ec_err;/* Error for cros_ec, 0 if ok */ -}; - -static struct local_info local; -#if definedCONFIG_EXYNOS_TMU /* Boot Time Thermal Analysis for SoC temperature threshold breach */ static void boot_temp_check (void )
@@ -144,22 +137,6 @@ int board_early_init_f(void) }#endif -struct cros_ec_dev *board_get_cros_ec_dev (void ) -{ -return local.cros_ec_dev; -} - -#ifdef CONFIG_CROS_EC -static int board_init_cros_ec_devices (const void *blob) -{ - local.cros_ec_err =cros_ec_init (blob, &local.cros_ec_dev); -if (local.cros_ec_err) -return -1 ;/* Will report in board_late_init() */ - -return 0 ; -} -#endif -#if defined(CONFIG_POWER )#ifdef CONFIG_POWER_MAX77686 static int pmic_reg_update (struct pmic *p,int reg,uint regval)
@@ -384,12 +361,12 @@ int board_late_init(void) {stdio_print_current_devices (); -if (local.cros_ec_err) { +if (cros_ec_get_error ()) {/* Force console on */ gd->flags &= ~GD_FLG_SILENT ;printf ("cros-ec communications failure %d\n" , - local.cros_ec_err); +cros_ec_get_error ());puts ("\nPlease reset with Power+Refresh\n\n" );panic ("Cannot init cros-ec device" );return -1 ;
@@ -401,7 +378,7 @@ int board_late_init(void)int arch_early_init_r (void ) {#ifdef CONFIG_CROS_EC -if (board_init_cros_ec_devices (gd->fdt_blob)) { +if (cros_ec_board_init ()) {printf ("%s: Failed to init EC\n" , __func__);return 0 ; }
board/samsung/smdk5250/exynos5-dt.c +0 -1
@@ -5,7 +5,6 @@*/ #include <common.h> -#include <cros_ec.h> #include <fdtdec.h> #include <asm/io.h> #include <errno.h>
common/Makefile +1 -0
@@ -229,6 +229,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.9.0.279.gdc9e3eb
PATCH v2 9/31 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 update in a system with a real EC.
---
Changes in v2: None
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.9.0.279.gdc9e3eb
PATCH v2 10/31 cros_ec: Drop old EC version support from EC driver
In reply to Simon GlassFrom: Vadim Bendebury <[email protected]>
There is no need to support old style EC moving forward. Ultimately we should get rid of the check_version() API. For now just return error in case the EC does not seem to support the new API.
---
Changes in v2: None
drivers/misc/cros_ec.c | 15 ++------- drivers/misc/cros_ec_lpc.c | 80 ++-------------------------------------------- 2 files changed, 6 insertions(+), 89 deletions(-)
drivers/misc/cros_ec.c +3 -12
@@ -132,10 +132,6 @@ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd,uint8_t *din;int len; -if (cmd_version !=0 && !dev->cmd_version_is_supported) { -debug ("%s: Command version >0 unsupported\n" , __func__); -return -1 ; - } len =send_command (dev, cmd, cmd_version, dout, dout_len, &din, din_len);
@@ -510,14 +506,9 @@ static int cros_ec_check_version(struct cros_ec_dev *dev)/* It appears to understand new version commands */ dev->cmd_version_is_supported =1 ; }else { - dev->cmd_version_is_supported =0 ; -if (ec_command_inptr (dev,EC_CMD_HELLO ,0 , &req, -sizeof (req), (uint8_t **)&resp, -sizeof (*resp)) <0 ) { -debug ("%s: Failed both old and new command style\n" , - __func__); -return -1 ; - } +printf ("%s: ERROR: old EC interface not supported\n" , + __func__); +return -1 ; }return 0 ;
drivers/misc/cros_ec_lpc.c +3 -77
98 lines not on this page · raw message
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 11/31 cros_ec: Support systems with no EC interrupt
In reply to Simon GlassSome systems do not have an EC interrupt. Rather than assuming that the interrupt is always present, and hanging forever waiting for more input, handle the missing interrupt. This works by reading key scans only until we get an identical one. This means the EC keyscan FIFO is empty.
---
Changes in v2: None
drivers/input/cros_ec_keyb.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-)
drivers/input/cros_ec_keyb.c +30 -4
@@ -8,6 +8,7 @@#include <common.h> #include <cros_ec.h> +#include <errno.h> #include <fdtdec.h> #include <input.h> #include <key_matrix.h>
@@ -39,20 +40,34 @@ static struct keyb {* @param config Keyboard config * @param keys List of keys that we have detected * @param max_count Maximum number of keys to return -* @return number of pressed keys, 0 for none +* @param samep Set to true if this scan repeats the last, else false +* @return number of pressed keys, 0 for none, -EIO on error */ static int check_for_keys (struct keyb *config, -struct key_matrix_key *keys,int max_count) +struct key_matrix_key *keys,int max_count, +bool *samep) {struct key_matrix_key *key; +static struct mbkp_keyscan last_scan; +static bool last_scan_valid;struct mbkp_keyscan scan;unsigned int row, col, bit, data;int num_keys;if (cros_ec_scan_keyboard (config->dev, &scan)) {debug ("%s: keyboard scan failed\n" , __func__); -return -1 ; +return -EIO ; } + *samep = last_scan_valid && !memcmp (&last_scan, &scan,sizeof (scan)); + +/* +* This is a bit odd. The EC has no way to tell us that it has run +* out of key scans. It just returns the same scan over and over +* again. So the only way to detect that we have run out is to detect +* that this scan is the same as the last. +*/ + last_scan_valid = true; +memcpy (&last_scan, &scan,sizeof (last_scan));for (col = num_keys = bit =0 ; col < config->matrix.num_cols; col++) {
@@ -112,6 +127,7 @@ int cros_ec_kbc_check(struct input_config *input)int keycodes[KBC_MAX_KEYS ];int num_keys, num_keycodes;int irq_pending, sent; +bool same = false;/* * Loop until the EC has no more keyscan records, or we have
@@ -125,7 +141,10 @@ int cros_ec_kbc_check(struct input_config *input) do { irq_pending = cros_ec_interrupt_pending(config.dev); if (irq_pending) { - num_keys = check_for_keys(&config, keys, KBC_MAX_KEYS); + num_keys = check_for_keys(&config, keys, KBC_MAX_KEYS, + &same); + if (num_keys < 0) + return 0; last_num_keys = num_keys; memcpy(last_keys, keys, sizeof(keys)); } else {
@@ -142,6 +161,13 @@ int cros_ec_kbc_check(struct input_config *input) num_keycodes =key_matrix_decode (&config.matrix, keys, num_keys, keycodes,KBC_MAX_KEYS ); sent =input_send_keycodes (input, keycodes, num_keycodes); + +/* +* For those ECs without an interrupt, stop scanning when we +* see that the scan is the same as last time. +*/ +if ((irq_pending <0 ) && same) +break ; }while (irq_pending && !sent);return 1 ;
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 12/31 cros_ec: Move #ifdef to permit flash region access
In reply to Simon GlassFlash region access is not tied to having commands, so adjust the #ifdef to reflect this.
---
Changes in v2:
- Add new patch to adjust #ifdef position in cros_ec
drivers/misc/cros_ec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/misc/cros_ec.c +2 -1
@@ -932,7 +932,6 @@ int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp)return 0 ; } -#ifdef CONFIG_CMD_CROS_EC int cros_ec_decode_region (int argc,char *const argv[]) {if (argc >0 ) {
@@ -999,6 +998,8 @@ int cros_ec_decode_ec_flash(const void *blob, struct fdt_cros_ec *config)return 0 ; } +#ifdef CONFIG_CMD_CROS_EC +/** * Perform a flash read or write command *
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 13/31 cros_ec: Sync up with latest Chrome OS EC version
In reply to Simon GlassThe EC messages have been expanded and some parts have been renamed.
---
Changes in v2:
- Add new patch to sync with latest Chrome OS EC version
drivers/misc/cros_ec.c | 33 ++--- include/cros_ec.h | 4 +- include/cros_ec_message.h | 2 +- include/ec_commands.h | 344 ++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 321 insertions(+), 62 deletions(-)
drivers/misc/cros_ec.c +17 -16
@@ -7,10 +7,11 @@*/ /* -* The Matrix Keyboard Protocol driver handles talking to the keyboard -* controller chip. Mostly this is for keyboard functions, but some other -* things have slipped in, so we provide generic services to talk to the -* KBC. +* This is the interface to the Chrome OS EC. It provides keyboard functions, +* power control and battery management. Quite a few other functions are +* provided to enable the EC software to be updated, talk to the EC's I2C bus +* and store a small amount of data in a memory which persists while the EC +* is not reset. */ #include <common.h>
@@ -216,7 +217,7 @@ static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,int cros_ec_scan_keyboard (struct cros_ec_dev *dev,struct mbkp_keyscan *scan) { -if (ec_command (dev,EC_CMD_CROS_EC_STATE ,0 ,NULL ,0 , scan, +if (ec_command (dev,EC_CMD_MKBP_STATE ,0 ,NULL ,0 , scan,sizeof (scan->data)) <sizeof (scan->data))return -1 ;
@@ -263,7 +264,7 @@ int cros_ec_read_version(struct cros_ec_dev *dev,int cros_ec_read_build_info (struct cros_ec_dev *dev,char **strp) {if (ec_command_inptr (dev,EC_CMD_GET_BUILD_INFO ,0 ,NULL ,0 , - (uint8_t **)strp,EC_HOST_PARAM_SIZE ) <0 ) + (uint8_t **)strp,EC_PROTO2_MAX_PARAM_SIZE ) <0 )return -1 ;return 0 ;
@@ -332,7 +333,7 @@ int cros_ec_read_hash(struct cros_ec_dev *dev,debug ("%s: No valid hash (status=%d size=%d). Compute one...\n" , __func__, hash->status, hash->size); - p.cmd =EC_VBOOT_HASH_RECALC ; + p.cmd =EC_VBOOT_HASH_START ; p.hash_type =EC_VBOOT_HASH_TYPE_SHA256 ; p.nonce_size =0 ; p.offset =EC_VBOOT_HASH_OFFSET_RW ;
@@ -414,10 +415,10 @@ int cros_ec_interrupt_pending(struct cros_ec_dev *dev)return !gpio_get_value (dev->ec_int.gpio); } -int cros_ec_info (struct cros_ec_dev *dev,struct ec_response_cros_ec_info *info) +int cros_ec_info (struct cros_ec_dev *dev,struct ec_response_mkbp_info *info) { -if (ec_command (dev,EC_CMD_CROS_EC_INFO ,0 ,NULL ,0 , info, -sizeof (*info)) <sizeof (*info)) +if (ec_command (dev,EC_CMD_MKBP_INFO ,0 ,NULL ,0 , info, +sizeof (*info)) <sizeof (*info))return -1 ;return 0 ;
@@ -590,8 +591,8 @@ static int cros_ec_flash_write_block(struct cros_ec_dev *dev, p.offset = offset; p.size = size; -assert (data && p.size <=sizeof (p.data)); -memcpy (p.data, data, p.size); +assert (data && p.size <=EC_FLASH_WRITE_VER0_SIZE ); +memcpy (&p +1 , data, p.size);return ec_command_inptr (dev,EC_CMD_FLASH_WRITE ,0 , &p,sizeof (p),NULL ,0 ) >=0 ?0 :-1 ;
@@ -602,8 +603,7 @@ static int cros_ec_flash_write_block(struct cros_ec_dev *dev,*/ static int cros_ec_flash_write_burst_size (struct cros_ec_dev *dev) { -struct ec_params_flash_write p; -return sizeof (p.data); +return EC_FLASH_WRITE_VER0_SIZE ; }/**
@@ -804,7 +804,8 @@ int cros_ec_get_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t *state) }/** -* Decode MBKP details from the device tree and allocate a suitable device. +* Decode EC interface details from the device tree and allocate a suitable +* device. * * @param blob Device tree blob * @param node Node to decode from
@@ -1086,7 +1087,7 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }printf ("%s\n" , id); }else if (0 ==strcmp ("info" , cmd)) { -struct ec_response_cros_ec_info info; +struct ec_response_mkbp_info info;if (cros_ec_info (dev, &info)) {debug ("%s: Could not read KBC info\n" , __func__);
include/cros_ec.h +2 -2
@@ -151,7 +151,7 @@ enum { };/** -* Set up the Chromium OS matrix keyboard protocol +* Initialise the Chromium OS EC driver * * @param blob Device tree blob containing setup information * @param cros_ecp Returns pointer to the cros_ec device, or NULL if none
@@ -168,7 +168,7 @@ int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp);* @param info Place to put the info structure */ int cros_ec_info (struct cros_ec_dev *dev, -struct ec_response_cros_ec_info *info); +struct ec_response_mkbp_info *info);/** * Read the host event flags
include/cros_ec_message.h +1 -1
@@ -23,7 +23,7 @@ enum {MSG_PROTO_BYTES =MSG_HEADER_BYTES +MSG_TRAILER_BYTES ,/* Max length of messages */ - MSG_BYTES = EC_HOST_PARAM_SIZE + MSG_PROTO_BYTES, + MSG_BYTES = EC_PROTO2_MAX_PARAM_SIZE + MSG_PROTO_BYTES, };#endif
include/ec_commands.h +301 -43
471 lines not on this page · raw message
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 14/31 cros_ec: Clean up multiple EC protocol support
In reply to Simon GlassFrom: Randall Spangler <[email protected]>
Version 1 protocols (without command version) were already no longer supported in cros_ec.c. This removes some dead code from the cros_ec_i2c driver.
Version 2 protcols (with command version) are now called protocol_version=2, instead of cmd_version_is_supported=1.
A subsequent change will introduce protocol version 3 for SPI.
---
Changes in v2: None
drivers/misc/cros_ec.c | 21 +++++++++------ drivers/misc/cros_ec_i2c.c | 64 ++++++++++++++++++++-------------------------- drivers/misc/cros_ec_spi.c | 6 +++++ include/cros_ec.h | 5 ++-- 4 files changed, 49 insertions(+), 47 deletions(-)
drivers/misc/cros_ec.c +13 -8
@@ -501,18 +501,23 @@ static int cros_ec_check_version(struct cros_ec_dev *dev)* * So for now, just read all the data anyway. */ - dev->cmd_version_is_supported =1 ; + +/* Try sending a version 2 packet */ + dev->protocol_version =2 ;if (ec_command_inptr (dev,EC_CMD_HELLO ,0 , &req,sizeof (req), (uint8_t **)&resp,sizeof (*resp)) >0 ) { -/* It appears to understand new version commands */ - dev->cmd_version_is_supported =1 ; - }else { -printf ("%s: ERROR: old EC interface not supported\n" , - __func__); -return -1 ; +return 0 ; } -return 0 ; +/* +* Fail if we're still here, since the EC doesn't understand any +* protcol version we speak. Version 1 interface without command +* version is no longer supported, and we don't know about any new +* protocol versions. +*/ + dev->protocol_version =0 ; +printf ("%s: ERROR: old EC interface not supported\n" , __func__); +return -1 ; }int cros_ec_test (struct cros_ec_dev *dev)
drivers/misc/cros_ec_i2c.c +28 -36
92 lines not on this page · raw message
drivers/misc/cros_ec_spi.c +6 -0
@@ -42,6 +42,12 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,int csum, len;int rv; +if (dev->protocol_version !=2 ) { +debug ("%s: Unsupported EC protcol version %d\n" , + __func__, dev->protocol_version); +return -1 ; + } +/* * Sanity-check input size to make sure it plus transaction overhead * fits in the internal device buffer.
include/cros_ec.h +2 -3
@@ -33,7 +33,7 @@ struct cros_ec_dev {unsigned int bus_num;/* Bus number (for I2C) */ unsigned int max_frequency;/* Maximum interface frequency */ struct fdt_gpio_state ec_int;/* GPIO used as EC interrupt line */ -int cmd_version_is_supported;/* Device supports command versions */ +int protocol_version;/* Protocol version to use */ int optimise_flash_write;/* Don't write erased flash blocks */ /*
@@ -260,8 +260,7 @@ int cros_ec_spi_decode_fdt(struct cros_ec_dev *dev, const void *blob);* Check whether the LPC interface supports new-style commands. * * LPC has its own way of doing this, which involves checking LPC values -* visible to the host. Do this, and update dev->cmd_version_is_supported -* accordingly. +* visible to the host. Do this, and update dev->protocol_version accordingly. * * @param dev CROS-EC device to check */
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 15/31 cros_ec: Add base support for protocol v3
In reply to Simon GlassProtocol v2 was shipped with snow, link and spring. Protocol v3 is for pit and is targetted at SPI operation.
---
Changes in v2:
- Add new patches to bring in protocol v3 support
drivers/misc/cros_ec.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-)
drivers/misc/cros_ec.c +164 -1
@@ -74,11 +74,174 @@ int cros_ec_calc_checksum(const uint8_t *data, int size)return csum &0xff ; } +/** +* Create a request packet for protocol version 3. +* +* The packet is stored in the device's internal output buffer. +* +* @param dev CROS-EC device +* @param cmd Command to send (EC_CMD_...) +* @param cmd_version Version of command to send (EC_VER_...) +* @param dout Output data (may be NULL If dout_len=0) +* @param dout_len Size of output data in bytes +* @return packet size in bytes, or <0 if error. +*/ +static int create_proto3_request (struct cros_ec_dev *dev, +int cmd,int cmd_version, +const void *dout,int dout_len) +{ +struct ec_host_request *rq = (struct ec_host_request *)dev->dout; +int out_bytes = dout_len +sizeof (*rq); + +/* Fail if output size is too big */ +if (out_bytes > (int )sizeof (dev->dout)) { +debug ("%s: Cannot send %d bytes\n" , __func__, dout_len); +return -EC_RES_REQUEST_TRUNCATED ; + } + +/* Fill in request packet */ + rq->struct_version =EC_HOST_REQUEST_VERSION ; + rq->checksum =0 ; + rq->command = cmd; + rq->command_version = cmd_version; + rq->reserved =0 ; + rq->data_len = dout_len; + +/* Copy data after header */ +memcpy (rq +1 , dout, dout_len); + +/* Write checksum field so the entire packet sums to 0 */ + rq->checksum = (uint8_t )(-cros_ec_calc_checksum (dev->dout, out_bytes)); + +cros_ec_dump_data ("out" , cmd, dev->dout, out_bytes); + +/* Return size of request packet */ +return out_bytes; +} + +/** +* Prepare the device to receive a protocol version 3 response. +* +* @param dev CROS-EC device +* @param din_len Maximum size of response in bytes +* @return maximum expected number of bytes in response, or <0 if error. +*/ +static int prepare_proto3_response_buffer (struct cros_ec_dev *dev,int din_len) +{ +int in_bytes = din_len +sizeof (struct ec_host_response ); + +/* Fail if input size is too big */ +if (in_bytes > (int )sizeof (dev->din)) { +debug ("%s: Cannot receive %d bytes\n" , __func__, din_len); +return -EC_RES_RESPONSE_TOO_BIG ; + } + +/* Return expected size of response packet */ +return in_bytes; +} + +/** +* Handle a protocol version 3 response packet. +* +* The packet must already be stored in the device's internal input buffer. +* +* @param dev CROS-EC device +* @param dinp Returns pointer to response data +* @param din_len Maximum size of response in bytes +* @return number of bytes of response data, or <0 if error +*/ +static int handle_proto3_response (struct cros_ec_dev *dev, +uint8_t **dinp,int din_len) +{ +struct ec_host_response *rs = (struct ec_host_response *)dev->din; +int in_bytes; +int csum; + +cros_ec_dump_data ("in-header" ,-1 , dev->din,sizeof (*rs)); + +/* Check input data */ +if (rs->struct_version !=EC_HOST_RESPONSE_VERSION ) { +debug ("%s: EC response version mismatch\n" , __func__); +return -EC_RES_INVALID_RESPONSE ; + } + +if (rs->reserved) { +debug ("%s: EC response reserved != 0\n" , __func__); +return -EC_RES_INVALID_RESPONSE ; + } + +if (rs->data_len > din_len) { +debug ("%s: EC returned too much data\n" , __func__); +return -EC_RES_RESPONSE_TOO_BIG ; + } + +cros_ec_dump_data ("in-data" ,-1 , dev->din +sizeof (*rs), rs->data_len); + +/* Update in_bytes to actual data size */ + in_bytes =sizeof (*rs) + rs->data_len; + +/* Verify checksum */ + csum =cros_ec_calc_checksum (dev->din, in_bytes); +if (csum) { +debug ("%s: EC response checksum invalid: 0x%02x\n" , __func__, + csum); +return -EC_RES_INVALID_CHECKSUM ; + } + +/* Return error result, if any */ +if (rs->result) +return -(int )rs->result; + +/* If we're still here, set response data pointer and return length */ + *dinp = (uint8_t *)(rs +1 ); + +return rs->data_len; +} + +static int send_command_proto3 (struct cros_ec_dev *dev, +int cmd,int cmd_version, +const void *dout,int dout_len, +uint8_t **dinp,int din_len) +{ +int out_bytes, in_bytes; +int rv; + +/* Create request packet */ + out_bytes =create_proto3_request (dev, cmd, cmd_version, + dout, dout_len); +if (out_bytes <0 ) +return out_bytes; + +/* Prepare response buffer */ + in_bytes =prepare_proto3_response_buffer (dev, din_len); +if (in_bytes <0 ) +return in_bytes; + +switch (dev->interface) { +case CROS_EC_IF_NONE : +/* TODO: support protocol 3 for LPC, I2C; for now fall through */ +default : +debug ("%s: Unsupported interface\n" , __func__); + rv =-1 ; + } +if (rv <0 ) +return rv; + +/* Process the response */ +return handle_proto3_response (dev, dinp, din_len); +} +static int send_command (struct cros_ec_dev *dev,uint8_t cmd,int cmd_version,const void *dout,int dout_len,uint8_t **dinp,int din_len) { -int ret; +int ret =-1 ; + +/* Handle protocol version 3 support */ +if (dev->protocol_version ==3 ) { +return send_command_proto3 (dev, cmd, cmd_version, + dout, dout_len, dinp, din_len); + }switch (dev->interface) {#ifdef CONFIG_CROS_EC_SPI
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 16/31 cros_ec: spi: Add support for EC protocol version 3
In reply to Simon GlassFrom: Randall Spangler <[email protected]>
Protocol version 3 will be attempted first; if the EC doesn't support it, u-boot will fall back to the old protocol version (2).
---
Changes in v2: None
drivers/misc/cros_ec.c | 12 ++++++++++++ drivers/misc/cros_ec_spi.c | 24 ++++++++++++++++++++++++ include/cros_ec.h | 13 +++++++++++++ 3 files changed, 49 insertions(+)
drivers/misc/cros_ec.c +12 -0
@@ -218,6 +218,11 @@ static int send_command_proto3(struct cros_ec_dev *dev,return in_bytes;switch (dev->interface) { +#ifdef CONFIG_CROS_EC_SPI +case CROS_EC_IF_SPI : + rv =cros_ec_spi_packet (dev, out_bytes, in_bytes); +break ; +#endif case CROS_EC_IF_NONE :/* TODO: support protocol 3 for LPC, I2C; for now fall through */ default :
@@ -665,6 +670,13 @@ static int cros_ec_check_version(struct cros_ec_dev *dev)* So for now, just read all the data anyway. */ +/* Try sending a version 3 packet */ + dev->protocol_version =3 ; +if (ec_command_inptr (dev,EC_CMD_HELLO ,0 , &req,sizeof (req), + (uint8_t **)&resp,sizeof (*resp)) >0 ) { +return 0 ; + } +/* Try sending a version 2 packet */ dev->protocol_version =2 ; if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
drivers/misc/cros_ec_spi.c +24 -0
@@ -17,6 +17,30 @@#include <cros_ec.h> #include <spi.h> +int cros_ec_spi_packet (struct cros_ec_dev *dev,int out_bytes,int in_bytes) +{ +int rv; + +/* Do the transfer */ +if (spi_claim_bus (dev->spi)) { +debug ("%s: Cannot claim SPI bus\n" , __func__); +return -1 ; + } + + rv =spi_xfer (dev->spi,max (out_bytes, in_bytes) *8 , + dev->dout, dev->din, +SPI_XFER_BEGIN |SPI_XFER_END ); + +spi_release_bus (dev->spi); + +if (rv) { +debug ("%s: Cannot complete SPI transfer\n" , __func__); +return -1 ; + } + +return in_bytes; +} +/** * Send a command to a LPC CROS_EC device and return the reply. *
include/cros_ec.h +13 -0
@@ -312,6 +312,19 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, uint8_t **dinp, int din_len);/** +* Send a packet to a CROS-EC device and return the response packet. +* +* Expects the request packet to be stored in dev->dout. Stores the response +* packet in dev->din. +* +* @param dev CROS-EC device +* @param out_bytes Size of request packet to output +* @param in_bytes Maximum size of response packet to receive +* @return number of bytes in response packet, or <0 on error +*/ +int cros_ec_spi_packet (struct cros_ec_dev *dev,int out_bytes,int in_bytes); + +/** * Dump a block of data for a command. * * @param name Name for data (e.g. 'in', 'out')
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 17/31 cros_ec: Correct comparison between signed and unsigned numbers
In reply to Simon GlassDue to signed/unsigned comparison, '< sizeof(struct)' does not do the right thing, since if ec_command() returns a -ve number we will consider this be success.
Adjust all comparisons to avoid this problem.
This error was found with sandbox, which gives a segfault in this case. On ARM we may instead silently fail.
We should also consider turning on -Wsign-compare to catch this sort of thing in future.
---
Changes in v2: None
drivers/misc/cros_ec.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
drivers/misc/cros_ec.c +18 -16
@@ -21,6 +21,7 @@#include <fdtdec.h> #include <malloc.h> #include <spi.h> +#include <asm/errno.h> #include <asm/io.h> #include <asm-generic/gpio.h>
@@ -298,7 +299,7 @@ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version, const void *dout, int dout_len, uint8_t **dinp, int din_len) { - uint8_t *din; + uint8_t *din = NULL;int len; len = send_command(dev, cmd, cmd_version, dout, dout_len,
@@ -306,7 +307,7 @@ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd,/* If the command doesn't complete, wait a while */ if (len == -EC_RES_IN_PROGRESS ) { -struct ec_response_get_comms_status *resp; +struct ec_response_get_comms_status *resp =NULL ;ulong start;/* Wait for command to complete */
@@ -334,7 +335,8 @@ static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd, NULL, 0, &din, din_len); } -debug ("%s: len=%d, dinp=%p, *dinp=%p\n" , __func__, len, dinp, *dinp); +debug ("%s: len=%d, dinp=%p, *dinp=%p\n" , __func__, len, dinp, + dinp ? *dinp :NULL );if (dinp) {/* If we have any data to return, it must be 64bit-aligned */ assert (len <=0 || !((uintptr_t )din &7 ));
@@ -386,7 +388,7 @@ static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,int cros_ec_scan_keyboard (struct cros_ec_dev *dev,struct mbkp_keyscan *scan) {if (ec_command (dev,EC_CMD_MKBP_STATE ,0 ,NULL ,0 , scan, -sizeof (scan->data)) <sizeof (scan->data)) +sizeof (scan->data)) !=sizeof (scan->data))return -1 ;return 0 ;
@@ -397,10 +399,10 @@ int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen)struct ec_response_get_version *r;if (ec_command_inptr (dev,EC_CMD_GET_VERSION ,0 ,NULL ,0 , - (uint8_t **)&r,sizeof (*r)) <sizeof (*r)) + (uint8_t **)&r,sizeof (*r)) !=sizeof (*r))return -1 ; -if (maxlen >sizeof (r->version_string_ro)) +if (maxlen > (int )sizeof (r->version_string_ro)) maxlen =sizeof (r->version_string_ro);switch (r->current_image) {
@@ -423,7 +425,7 @@ int cros_ec_read_version(struct cros_ec_dev *dev, {if (ec_command_inptr (dev,EC_CMD_GET_VERSION ,0 ,NULL ,0 , (uint8_t **)versionp,sizeof (**versionp)) - <sizeof (**versionp)) + !=sizeof (**versionp))return -1 ;return 0 ;
@@ -444,7 +446,7 @@ int cros_ec_read_current_image(struct cros_ec_dev *dev,struct ec_response_get_version *r;if (ec_command_inptr (dev,EC_CMD_GET_VERSION ,0 ,NULL ,0 , - (uint8_t **)&r,sizeof (*r)) <sizeof (*r)) + (uint8_t **)&r,sizeof (*r)) !=sizeof (*r))return -1 ; *image = r->current_image;
@@ -578,7 +580,7 @@ int cros_ec_interrupt_pending(struct cros_ec_dev *dev) {/* no interrupt support : always poll */ if (!fdt_gpio_isvalid (&dev->ec_int)) -return 1 ; +return -ENOENT ;return !gpio_get_value (dev->ec_int.gpio); }
@@ -586,7 +588,7 @@ int cros_ec_interrupt_pending(struct cros_ec_dev *dev)int cros_ec_info (struct cros_ec_dev *dev,struct ec_response_mkbp_info *info) {if (ec_command (dev,EC_CMD_MKBP_INFO ,0 ,NULL ,0 , info, -sizeof (*info)) <sizeof (*info)) +sizeof (*info)) !=sizeof (*info))return -1 ;return 0 ;
@@ -601,7 +603,7 @@ int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr)* used by ACPI/SMI. */ if (ec_command_inptr (dev,EC_CMD_HOST_EVENT_GET_B ,0 ,NULL ,0 , - (uint8_t **)&resp,sizeof (*resp)) <sizeof (*resp)) + (uint8_t **)&resp,sizeof (*resp)) < (int )sizeof (*resp))return -1 ;if (resp->mask &EC_HOST_EVENT_MASK (EC_HOST_EVENT_INVALID ))
@@ -639,7 +641,7 @@ int cros_ec_flash_protect(struct cros_ec_dev *dev,if (ec_command (dev,EC_CMD_FLASH_PROTECT ,EC_VER_FLASH_PROTECT , ¶ms,sizeof (params), - resp,sizeof (*resp)) <sizeof (*resp)) + resp,sizeof (*resp)) !=sizeof (*resp))return -1 ;return 0 ;
@@ -889,7 +891,7 @@ int cros_ec_flash_update_rw(struct cros_ec_dev *dev,if (cros_ec_flash_offset (dev,EC_FLASH_REGION_RW , &rw_offset, &rw_size))return -1 ; -if (image_size > rw_size) +if (image_size > (int )rw_size)return -1 ;/* Invalidate the existing hash, just in case the AP reboots
@@ -975,7 +977,7 @@ int cros_ec_get_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t *state)if (ec_command_inptr (dev,EC_CMD_LDO_GET ,0 , ¶ms,sizeof (params), - (uint8_t **)&resp,sizeof (*resp)) <sizeof (*resp)) + (uint8_t **)&resp,sizeof (*resp)) !=sizeof (*resp))return -1 ; *state = resp->state;
@@ -1436,10 +1438,10 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])if (!ret) {/* Print versions */ printf ("RO version: %1.*s\n" , -sizeof (p->version_string_ro), + (int )sizeof (p->version_string_ro), p->version_string_ro);printf ("RW version: %1.*s\n" , -sizeof (p->version_string_rw), + (int )sizeof (p->version_string_rw), p->version_string_rw); printf("Firmware copy: %s\n", (p->current_image <
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 18/31 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 such as keyboard handling.
---
Changes in v2: None
drivers/misc/Makefile | 1 + drivers/misc/cros_ec.c | 16 ++ drivers/misc/cros_ec_sandbox.c | 559 +++++++++++++++++++++++++++++++++++++++++ include/cros_ec.h | 21 ++ include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 6 files changed, 599 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.c +16 -0
@@ -224,6 +224,11 @@ static int send_command_proto3(struct cros_ec_dev *dev, rv =cros_ec_spi_packet (dev, out_bytes, in_bytes);break ;#endif +#ifdef CONFIG_CROS_EC_SANDBOX +case CROS_EC_IF_SANDBOX : + rv =cros_ec_sandbox_packet (dev, out_bytes, in_bytes); +break ; +#endif case CROS_EC_IF_NONE :/* TODO: support protocol 3 for LPC, I2C; for now fall through */ default :
@@ -1033,6 +1038,11 @@ static int cros_ec_decode_fdt(const void *blob, int node, dev->interface =CROS_EC_IF_LPC ;break ;#endif +#ifdef CONFIG_CROS_EC_SANDBOX +case COMPAT_SANDBOX_HOST_EMULATION : + dev->interface =CROS_EC_IF_SANDBOX ; +break ; +#endif default :debug ("%s: Unknown compat id %d\n" , __func__, compat);return -1 ;
@@ -1088,6 +1098,12 @@ int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp)return -CROS_EC_ERR_DEV_INIT ;break ;#endif +#ifdef CONFIG_CROS_EC_SANDBOX +case CROS_EC_IF_SANDBOX : +if (cros_ec_sandbox_init (dev, blob)) +return -CROS_EC_ERR_DEV_INIT ; +break ; +#endif case CROS_EC_IF_NONE :default :return 0 ;
drivers/misc/cros_ec_sandbox.c new file +559 -0
559 lines not on this page · raw message
include/cros_ec.h +21 -0
@@ -20,6 +20,7 @@ enum cros_ec_interface_t {CROS_EC_IF_SPI ,CROS_EC_IF_I2C ,CROS_EC_IF_LPC ,/* Intel Low Pin Count interface */ + CROS_EC_IF_SANDBOX, };/* Our configuration information */
@@ -237,6 +238,7 @@ struct cros_ec_dev *board_get_cros_ec_dev(void);int cros_ec_i2c_init (struct cros_ec_dev *dev,const void *blob);int cros_ec_spi_init (struct cros_ec_dev *dev,const void *blob);int cros_ec_lpc_init (struct cros_ec_dev *dev,const void *blob); +int cros_ec_sandbox_init (struct cros_ec_dev *dev,const void *blob);/** * Read information from the fdt for the i2c cros_ec interface
@@ -257,6 +259,15 @@ int cros_ec_i2c_decode_fdt(struct cros_ec_dev *dev, const void *blob);int cros_ec_spi_decode_fdt (struct cros_ec_dev *dev,const void *blob);/** +* Read information from the fdt for the sandbox cros_ec interface +* +* @param dev CROS-EC device +* @param blob Device tree blob +* @return 0 if ok, -1 if we failed to read all required information +*/ +int cros_ec_sandbox_decode_fdt (struct cros_ec_dev *dev,const void *blob); + +/** * Check whether the LPC interface supports new-style commands. * * LPC has its own way of doing this, which involves checking LPC values
@@ -323,6 +334,8 @@ int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,* @return number of bytes in response packet, or <0 on error */ int cros_ec_spi_packet (struct cros_ec_dev *dev,int out_bytes,int in_bytes); +int cros_ec_sandbox_packet (struct cros_ec_dev *dev,int out_bytes, +int in_bytes);/** * Dump a block of data for a command.
@@ -480,4 +493,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
@@ -88,6 +88,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
@@ -61,6 +61,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.9.0.279.gdc9e3eb
PATCH v2 19/31 sandbox: Plumb in Chrome OS EC emulation
In reply to Simon GlassAdd board code to set up the Chrome OS EC on startup.
---
Changes in v2: None
board/sandbox/sandbox/sandbox.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
board/sandbox/sandbox/sandbox.c +30 -1
@@ -4,7 +4,7 @@*/ #include <common.h> - +#include <cros_ec.h> #include <os.h> /*
@@ -28,3 +28,32 @@ int dram_init(void) gd->ram_size =CONFIG_SYS_SDRAM_SIZE ;return 0 ; } + +int arch_early_init_r (void ) +{ +#ifdef CONFIG_CROS_EC +if (cros_ec_board_init ()) { +printf ("%s: Failed to init EC\n" , __func__); +return 0 ; + } +#endif + +return 0 ; +} + +#ifdef CONFIG_BOARD_LATE_INIT +int board_late_init (void ) +{ +if (cros_ec_get_error ()) { +/* Force console on */ + gd->flags &= ~GD_FLG_SILENT ; + +printf ("cros-ec communications failure %d\n" , +cros_ec_get_error ()); +puts ("\nPlease reset with Power+Refresh\n\n" ); +panic ("Cannot init cros-ec device" ); +return -1 ; + } +return 0 ; +} +#endif
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 20/31 cros_ec: Implement I2C pass-through
In reply to Simon GlassThe Chrome EC has a feature where you can access its I2C buses through a pass-through arrangement. Add a command to support this, and export the function for it also.
---
Changes in v2: None
drivers/misc/cros_ec.c | 270 ++++++++++++++++++++++++++++++++++++++++++++++++- include/cros_ec.h | 14 +++ 2 files changed, 282 insertions(+), 2 deletions(-)
drivers/misc/cros_ec.c +268 -2
@@ -1197,6 +1197,87 @@ int cros_ec_decode_ec_flash(const void *blob, struct fdt_cros_ec *config)return 0 ; } +int cros_ec_i2c_xfer (struct cros_ec_dev *dev,uchar chip,uint addr, +int alen,uchar *buffer,int len,int is_read) +{ +union { +struct ec_params_i2c_passthru p; +uint8_t outbuf[EC_PROTO2_MAX_PARAM_SIZE ]; + } params; +union { +struct ec_response_i2c_passthru r; +uint8_t inbuf[EC_PROTO2_MAX_PARAM_SIZE ]; + } response; +struct ec_params_i2c_passthru *p = ¶ms.p; +struct ec_response_i2c_passthru *r = &response.r; +struct ec_params_i2c_passthru_msg *msg = p->msg; +uint8_t *pdata; +int read_len, write_len; +int size; +int rv; + + p->port =0 ; + +if (alen !=1 ) { +printf ("Unsupported address length %d\n" , alen); +return -1 ; + } +if (is_read) { + read_len = len; + write_len = alen; + p->num_msgs =2 ; + }else { + read_len =0 ; + write_len = alen + len; + p->num_msgs =1 ; + } + + size =sizeof (*p) + p->num_msgs *sizeof (*msg); +if (size + write_len >sizeof (params)) { +puts ("Params too large for buffer\n" ); +return -1 ; + } +if (sizeof (*r) + read_len >sizeof (response)) { +puts ("Read length too big for buffer\n" ); +return -1 ; + } + +/* Create a message to write the register address and optional data */ + pdata = (uint8_t *)p + size; + msg->addr_flags = chip; + msg->len = write_len; + pdata[0 ] = addr; +if (!is_read) +memcpy (pdata +1 , buffer, len); + msg++; + +if (read_len) { + msg->addr_flags = chip |EC_I2C_FLAG_READ ; + msg->len = read_len; + } + + rv =ec_command (dev,EC_CMD_I2C_PASSTHRU ,0 , p, size + write_len, + r,sizeof (*r) + read_len); +if (rv <0 ) +return rv; + +/* Parse response */ +if (r->i2c_status &EC_I2C_STATUS_ERROR ) { +printf ("Transfer failed with status=0x%x\n" , r->i2c_status); +return -1 ; + } + +if (rv <sizeof (*r) + read_len) { +puts ("Truncated read response\n" ); +return -1 ; + } + +if (read_len) +memcpy (buffer, r->data, read_len); + +return 0 ; +} +#ifdef CONFIG_CMD_CROS_EC /**
@@ -1252,6 +1333,187 @@ static int do_read_write(struct cros_ec_dev *dev, int is_write, int argc,return 0 ; } +/** +* get_alen() - Small parser helper function to get address length +* +* Returns the address length. +*/ +static uint get_alen (char *arg) +{ +int j; +int alen; + + alen =1 ; +for (j =0 ; j <8 ; j++) { +if (arg[j] =='.' ) { + alen = arg[j+1 ] -'0' ; +break ; + }else if (arg[j] =='\0' ) { +break ; + } + } +return alen; +} + +#define DISP_LINE_LEN 16 + +/* +* TODO([email protected]): This code copied almost verbatim from cmd_i2c.c +* so we can remove it later. +*/ +static int cros_ec_i2c_md (struct cros_ec_dev *dev,int flag,int argc, +char *const argv[]) +{ +u_char chip; +uint addr, alen, length =0x10 ; +int j, nbytes, linebytes; + +if (argc <2 ) +return CMD_RET_USAGE ; + +if (1 || (flag &CMD_FLAG_REPEAT ) ==0 ) { +/* +* New command specified. +*/ + +/* +* I2C chip address +*/ + chip =simple_strtoul (argv[0 ],NULL ,16 ); + +/* +* I2C data address within the chip. This can be 1 or +* 2 bytes long. Some day it might be 3 bytes long :-). +*/ + addr =simple_strtoul (argv[1 ],NULL ,16 ); + alen =get_alen (argv[1 ]); +if (alen >3 ) +return CMD_RET_USAGE ; + +/* +* If another parameter, it is the length to display. +* Length is the number of objects, not number of bytes. +*/ +if (argc >2 ) + length =simple_strtoul (argv[2 ],NULL ,16 ); + } + +/* +* Print the lines. +* +* We buffer all read data, so we can make sure data is read only +* once. +*/ + nbytes = length; +do { +unsigned char linebuf[DISP_LINE_LEN ]; +unsigned char *cp; + + linebytes = (nbytes >DISP_LINE_LEN ) ?DISP_LINE_LEN : nbytes; + +if (cros_ec_i2c_xfer (dev, chip, addr, alen, linebuf, linebytes, +1 )) +puts ("Error reading the chip.\n" ); +else { +printf ("%04x:" , addr); + cp = linebuf; +for (j =0 ; j < linebytes; j++) { +printf (" %02x" , *cp++); + addr++; + } +puts (" " ); + cp = linebuf; +for (j =0 ; j < linebytes; j++) { +if ((*cp <0x20 ) || (*cp >0x7e )) +puts ("." ); +else +printf ("%c" , *cp); + cp++; + } +putc ('\n' ); + } + nbytes -= linebytes; + }while (nbytes >0 ); + +return 0 ; +} + +static int cros_ec_i2c_mw (struct cros_ec_dev *dev,int flag,int argc, +char *const argv[]) +{ +uchar chip; +ulong addr; +uint alen; +uchar byte; +int count; + +if ((argc <3 ) || (argc >4 )) +return CMD_RET_USAGE ; + +/* +* Chip is always specified. +*/ + chip =simple_strtoul (argv[0 ],NULL ,16 ); + +/* +* Address is always specified. +*/ + addr =simple_strtoul (argv[1 ],NULL ,16 ); + alen =get_alen (argv[1 ]); +if (alen >3 ) +return CMD_RET_USAGE ; + +/* +* Value to write is always specified. +*/ + byte =simple_strtoul (argv[2 ],NULL ,16 ); + +/* +* Optional count +*/ +if (argc ==4 ) + count =simple_strtoul (argv[3 ],NULL ,16 ); +else + count =1 ; + +while (count-- >0 ) { +if (cros_ec_i2c_xfer (dev, chip, addr++, alen, &byte,1 ,0 )) +puts ("Error writing the chip.\n" ); +/* +* Wait for the write to complete. The write can take +* up to 10mSec (we allow a little more time). +*/ +/* +* No write delay with FRAM devices. +*/ +#if !defined(CONFIG_SYS_I2C_FRAM ) +udelay (11000 ); +#endif + } + +return 0 ; +} + +/* Temporary code until we have driver model and can use the i2c command */ +static int cros_ec_i2c_passthrough (struct cros_ec_dev *dev,int flag, +int argc,char *const argv[]) +{ +const char *cmd; + +if (argc <1 ) +return CMD_RET_USAGE ; + cmd = *argv++; + argc--; +if (0 ==strcmp ("md" , cmd)) +cros_ec_i2c_md (dev, flag, argc, argv); +else if (0 ==strcmp ("mw" , cmd)) +cros_ec_i2c_mw (dev, flag, argc, argv); +else +return CMD_RET_USAGE ; + +return 0 ; +} +static int do_cros_ec (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {struct cros_ec_dev *dev = last_dev;
@@ -1495,6 +1757,8 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])debug ("%s: Could not access LDO%d\n" , __func__, index);return ret; } + }else if (0 ==strcmp ("i2c" , cmd)) { + ret =cros_ec_i2c_passthrough (dev, flag, argc -2 , argv +2 ); }else {return CMD_RET_USAGE ; }
@@ -1508,7 +1772,7 @@ static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }U_BOOT_CMD ( - crosec,5 ,1 , do_cros_ec, + crosec,6 ,1 , do_cros_ec,"CROS-EC utility command" ,"init Re-init CROS-EC (done on startup automatically)\n" "crosec id Read CROS-EC ID\n"
@@ -1525,6 +1789,8 @@ U_BOOT_CMD("crosec vbnvcontext [hexstring] Read [write] VbNvContext from EC\n" "crosec ldo <idx> [<state>] Switch/Read LDO state\n" "crosec test run tests on cros_ec\n" -"crosec version Read CROS-EC version" +"crosec version Read CROS-EC version\n" +"crosec i2c md chip address[.0, .1, .2] [# of objects] - read from I2C passthru\n" +"crosec i2c mw chip address[.0, .1, .2] value [count] - write to I2C passthru (fill)" );#endif
include/cros_ec.h +14 -0
@@ -501,4 +501,18 @@ int cros_ec_decode_ec_flash(const void *blob, struct fdt_cros_ec *config);*/ void cros_ec_check_keyboard (struct cros_ec_dev *dev); +/* +* Tunnel an I2C transfer to the EC +* +* @param dev CROS-EC device +* @param chip Chip address (7-bit I2C address) +* @param addr Register address to read/write +* @param alen Length of register address in bytes +* @param buffer Buffer containing data to read/write +* @param len Length of buffer +* @param is_read 1 if this is a read, 0 if this is a write +*/ +int cros_ec_i2c_xfer (struct cros_ec_dev *dev,uchar chip,uint addr, +int alen,uchar *buffer,int len,int is_read); +#endif
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 21/31 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.
---
Changes in v2: None
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.9.0.279.gdc9e3eb
PATCH v2 22/31 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.
---
Changes in v2: None
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.9.0.279.gdc9e3eb
PATCH v2 23/31 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.
---
Changes in v2: None
arch/sandbox/config.mk | 5 + arch/sandbox/cpu/Makefile | 3 + arch/sandbox/cpu/sdl.c | 341 +++++++++++++++++++++++++++++++++++++++++ arch/sandbox/include/asm/sdl.h | 118 ++++++++++++++ 4 files changed, 467 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 +3 -0
@@ -8,6 +8,7 @@ # 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 # CFLAGS_REMOVE_os.o cannot be used to drop header include path
@@ -17,3 +18,5 @@ cmd_cc_os.o = $(CC) $(filter-out -nostdinc, \ $(obj)/os.o: $(src)/os.c FORCE $(call if_changed_dep,cc_os.o) +$(obj)/sdl.o: $(src)/sdl.c FORCE + $(call if_changed_dep,cc_os.o)
arch/sandbox/cpu/sdl.c new file +341 -0
341 lines not on this page · raw message
arch/sandbox/include/asm/sdl.h new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 24/31 sandbox: Add a simple sound driver
In reply to Simon GlassAdd a sound driver for sandbox, which uses SDL.
---
Changes in v2: None
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.9.0.279.gdc9e3eb
PATCH v2 25/31 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 --show_lcd option to enable it.
---
Changes in v2: None
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 | 18 ++++++ 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 | 79 +++++++++++++++++++++++++++ include/fdtdec.h | 1 + include/lcd.h | 3 + lib/fdtdec.c | 1 + 12 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 doc/device-tree-bindings/video/sandbox-fb.txt create mode 100644 drivers/video/sandbox_sdl.c
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_show_lcd (struct sandbox_state *state, +const char *arg) +{ + state->show_lcd = true; +return 0 ; +} +SANDBOX_CMDLINE_OPT_SHORT (show_lcd,'l' ,0 , +"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 show_lcd;/* Show 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 -0
@@ -6,6 +6,7 @@#include <common.h> #include <cros_ec.h> #include <os.h> +#include <asm/u-boot-sandbox.h> /* * Pointer to initial global data area
@@ -29,6 +30,23 @@ int dram_init(void)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 +int arch_early_init_r (void ) {#ifdef CONFIG_CROS_EC
common/lcd.c +17 -4
@@ -28,6 +28,8 @@#include <watchdog.h> #include <asm/unaligned.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 }
@@ -403,7 +416,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 */
@@ -494,8 +507,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);
@@ -886,7 +899,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
@@ -33,6 +33,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 +79 -0
79 lines not on this page · raw message
include/fdtdec.h +1 -0
@@ -89,6 +89,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
@@ -313,6 +313,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
@@ -62,6 +62,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.9.0.279.gdc9e3eb
PATCH v2 26/31 sound: Move Samsung-specific code into its own file
In reply to Simon GlassThe i2s code is in fact Samsung-specific, but there might be other implementation. Move this code into its own file. This makes it slightly more obviously how to adjust the code to support another SoC, when someone takes this task on.
Also drop non-FDT support, since it isn't used on Exynos 5.
---
Changes in v2: None
drivers/sound/Makefile | 2 +- drivers/sound/sound-i2s.c | 208 +++++++++++++++++++++++++++++++++++++ drivers/sound/sound.c | 221 +--------------------------------------- include/configs/exynos5250-dt.h | 1 + include/sound.h | 9 ++ 5 files changed, 220 insertions(+), 221 deletions(-) create mode 100644 drivers/sound/sound-i2s.c
drivers/sound/Makefile +1 -1
@@ -6,7 +6,7 @@ # obj-$(CONFIG_SOUND) += sound.o -obj-$(CONFIG_I2S) += samsung-i2s.o +obj-$(CONFIG_I2S) += sound-i2s.o obj-$(CONFIG_I2S_SAMSUNG) += samsung-i2s.o obj-$(CONFIG_SOUND_SANDBOX) += sandbox.o obj-$(CONFIG_SOUND_WM8994) += wm8994.o
drivers/sound/sound-i2s.c new file +208 -0
208 lines not on this page · raw message
drivers/sound/sound.c +1 -220
233 lines not on this page · raw message
include/configs/exynos5250-dt.h +1 -0
@@ -51,6 +51,7 @@#define CONFIG_CMD_SOUND #ifdef CONFIG_CMD_SOUND #define CONFIG_SOUND +#define CONFIG_I2S_SAMSUNG #define CONFIG_I2S #define CONFIG_SOUND_MAX98095 #define CONFIG_SOUND_WM8994
include/sound.h +9 -0
@@ -30,6 +30,15 @@ struct sound_codec_info { };/* +* Generates square wave sound data for 1 second +* +* @param data data buffer pointer +* @param size size of the buffer +* @param freq frequency of the wave +*/ +void sound_create_square_wave (unsigned short *data,int size,uint32_t freq); + +/* * Initialises audio sub system * @param blob Pointer of device tree node or NULL if none. * @return int value 0 for success, -1 for error
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 27/31 sandbox: Deal with conflicting getenv() for SDL
In reply to Simon GlassUnfortunately SDL requires getenv() to operate, since it wants to figure out the display type. U-Boot has its own getenv() and they conflict. As a work-around use #define to resolve the conflict.
A better but more complex solution might be to rename some U-Boot symbols at link time. SDL audio is not functional at present, likely due to a related issue.
Note: Vic Yank wrote a script for this, filed in crbug.com/271125.
---
Changes in v2: None
include/common.h | 5 +++++ 1 file changed, 5 insertions(+)
include/common.h +5 -0
@@ -359,6 +359,11 @@ int do_ext2load(cmd_tbl_t *, int, int, char * const []);int env_init (void );void env_relocate (void );int envmatch (uchar *,int ); + +/* Avoid unfortunate conflict with libc's getenv() */ +#ifdef CONFIG_SANDBOX +#define getenv uboot_getenv +#endif 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);
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 28/31 sandbox: Allow Ctrl-C to work in sandbox
In reply to Simon GlassIt is useful for Cltl-C to be handled by U-Boot as it is on other boards. But it is also useful to be able to terminate U-Boot with Ctrl-C.
Add an option to enable signals while in raw mode, and make this the default. Add an option to leave the terminal cooked, which is useful for redirecting output.
---
Changes in v2: None
arch/sandbox/cpu/os.c | 13 +++++++------ arch/sandbox/cpu/start.c | 28 ++++++++++++++++++++++++++++ arch/sandbox/include/asm/state.h | 24 ++++++++++++++++++++++++ drivers/serial/sandbox.c | 6 +++++- include/os.h | 6 +++++- 5 files changed, 69 insertions(+), 8 deletions(-)
arch/sandbox/cpu/os.c +7 -6
@@ -99,21 +99,22 @@ void os_exit(int exit_code)/* Restore tty state when we exit */ static struct termios orig_term; +static bool term_setup;static void os_fd_restore (void ) { -tcsetattr (0 ,TCSANOW , &orig_term); +if (term_setup) +tcsetattr (0 ,TCSANOW , &orig_term); }/* Put tty into raw mode so <tab> and <ctrl+c> work */ -void os_tty_raw (int fd) +void os_tty_raw (int fd,bool allow_sigs) { -static int setup =0 ;struct termios term; -if (setup) +if (term_setup)return ; - setup =1 ; + term_setup = true;/* If not a tty, don't complain */ if (tcgetattr (fd, &orig_term))
@@ -123,7 +124,7 @@ void os_tty_raw(int fd) term.c_iflag =IGNBRK |IGNPAR ; term.c_oflag =OPOST |ONLCR ; term.c_cflag =CS8 |CREAD |CLOCAL ; - term.c_lflag =0 ; + term.c_lflag = allow_sigs ?ISIG :0 ;if (tcsetattr (fd,TCSANOW , &term))return ;
arch/sandbox/cpu/start.c +28 -0
@@ -184,6 +184,34 @@ static int sandbox_cmdline_cb_show_lcd(struct sandbox_state *state,SANDBOX_CMDLINE_OPT_SHORT (show_lcd,'l' ,0 ,"Show the sandbox LCD display" ); +static const char *term_args[STATE_TERM_COUNT ] = { +"raw-with-sigs" , +"raw" , +"cooked" , +}; + +static int sandbox_cmdline_cb_terminal (struct sandbox_state *state, +const char *arg) +{ +int i; + +for (i =0 ; i <STATE_TERM_COUNT ; i++) { +if (!strcmp (arg, term_args[i])) { + state->term_raw = i; +return 0 ; + } + } + +printf ("Unknown terminal setting '%s' (" , arg); +for (i =0 ; i <STATE_TERM_COUNT ; i++) +printf ("%s%s" , i ?", " :"" , term_args[i]); +puts (")\n" ); + +return 1 ; +} +SANDBOX_CMDLINE_OPT_SHORT (terminal,'t' ,1 , +"Set terminal to raw/cooked mode" ); +int main (int argc,char *argv[]) {struct sandbox_state *state;
arch/sandbox/include/asm/state.h +24 -0
@@ -17,6 +17,29 @@ enum exit_type_id { STATE_EXIT_POWER_OFF, }; +/** +* Selects the behavior of the serial terminal. +* +* If Ctrl-C is processed by U-Boot, then the only way to quit sandbox is with +* the 'reset' command, or equivalent. +* +* If the terminal is cooked, then Ctrl-C will terminate U-Boot, and the +* command line will not be quite such a faithful emulation. +* +* Options are: +* +* raw-with-sigs - Raw, but allow signals (Ctrl-C will quit) +* raw - Terminal is always raw +* cooked - Terminal is always cooked +*/ +enum state_terminal_raw { +STATE_TERM_RAW_WITH_SIGS ,/* Default */ +STATE_TERM_RAW , +STATE_TERM_COOKED , + +STATE_TERM_COUNT , +}; +struct sandbox_spi_info {const char *spec;const struct sandbox_spi_emu_ops *ops;
@@ -42,6 +65,7 @@ struct sandbox_state {bool write_state;/* Write sandbox state on exit */ bool ignore_missing_state_on_read;/* No error if state missing */ bool show_lcd;/* Show LCD on start-up */ +enum state_terminal_raw term_raw;/* Terminal raw/cooked */ /* Pointer to information for each SPI bus/cs */ struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS ]
drivers/serial/sandbox.c +5 -1
@@ -15,6 +15,7 @@#include <os.h> #include <serial.h> #include <linux/compiler.h> +#include <asm/state.h> /* *
@@ -31,7 +32,10 @@ static unsigned int serial_buf_read;static int sandbox_serial_init (void ) { -os_tty_raw (0 ); +struct sandbox_state *state =state_get_current (); + +if (state->term_raw !=STATE_TERM_COOKED ) +os_tty_raw (0 , state->term_raw ==STATE_TERM_RAW_WITH_SIGS );return 0 ; }
include/os.h +5 -1
@@ -95,8 +95,12 @@ void os_exit(int exit_code) __attribute__((noreturn));/** * Put tty into raw mode to mimic serial console better +* +* @param fd File descriptor of stdin (normally 0) +* @param allow_sigs Allow Ctrl-C, Ctrl-Z to generate signals rather than +* be handled by U-Boot */ -void os_tty_raw (int fd); +void os_tty_raw (int fd,bool allow_sigs);/** * Acquires some memory from the underlying os.
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 29/31 sandbox: Add options to clean up temporary files
In reply to Simon GlassWhen jumping from one sandbox U-Boot to another in sandbox, the RAM buffer is preserved in the jump by using a temporary file. Add an option to tell the receiving U-Boot to remove this file when it is no longer needed.
Similarly the old U-Boot image is left behind in this case. We cannot delete it immediately since gdb cannot then find its debug symbols. Delete it just before exiting.
Together these changes ensure that temporary files are removed both for memory and U-Boot.
---
Changes in v2: None
arch/sandbox/cpu/os.c | 8 +++++++- arch/sandbox/cpu/start.c | 23 +++++++++++++++-------- arch/sandbox/cpu/state.c | 6 +++++- arch/sandbox/include/asm/state.h | 3 ++- include/os.h | 2 ++ 5 files changed, 31 insertions(+), 11 deletions(-)
arch/sandbox/cpu/os.c +7 -1
@@ -92,6 +92,11 @@ int os_close(int fd)return close (fd); } +int os_unlink (const char *fname) +{ +return unlink (fname); +} +void os_exit (int exit_code) {exit (exit_code);
@@ -483,7 +488,7 @@ 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 ]; +const char *extra_args[5 ];char **argv = state->argv;#ifdef DEBUG int argc, i;
@@ -508,6 +513,7 @@ int os_jump_to_image(const void *dest, int size) extra_args[1 ] = fname; extra_args[2 ] ="-m" ; extra_args[3 ] = mem_fname; + extra_args[4 ] ="--rm_memory" ; err =add_args (&argv, extra_args,sizeof (extra_args) /sizeof (extra_args[0 ]));if (err)
arch/sandbox/cpu/start.c +15 -8
@@ -110,14 +110,8 @@ 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); -*/ +/* Remember to delete this U-Boot image later */ + state->jumped_fname = arg;return 0 ; }
@@ -142,6 +136,15 @@ 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_rm_memory (struct sandbox_state *state, +const char *arg) +{ + state->ram_buf_rm = true; + +return 0 ; +} +SANDBOX_CMDLINE_OPT (rm_memory,0 ,"Remove memory file after reading" ); +static int sandbox_cmdline_cb_state (struct sandbox_state *state,const char *arg) {
@@ -229,6 +232,10 @@ int main(int argc, char *argv[])if (ret) goto err; +/* Remove old memory file if required */ +if (state->ram_buf_rm && state->ram_buf_fname) +os_unlink (state->ram_buf_fname); +/* Do pre- and post-relocation init */ board_init_f (0 );
arch/sandbox/cpu/state.c +5 -1
@@ -365,7 +365,7 @@ int state_uninit(void) state = &main_state; -if (state->write_ram_buf) { +if (state->write_ram_buf && !state->ram_buf_rm) { err =os_write_ram_buf (state->ram_buf_fname);if (err) {printf ("Failed to write RAM buffer\n" );
@@ -380,6 +380,10 @@ int state_uninit(void) } } +/* Delete this at the last moment so as not to upset gdb too much */ +if (state->jumped_fname) +os_unlink (state->jumped_fname); +if (state->state_fdt)os_free (state->state_fdt);memset (state,'\0' ,sizeof (*state));
arch/sandbox/include/asm/state.h +2 -1
@@ -54,10 +54,11 @@ struct sandbox_state {const char *parse_err;/* Error to report from parsing */ int argc;/* Program arguments */ char **argv;/* Command line arguments */ -bool jumped;/* Jumped from previous U_Boot */ +const char *jumped_fname;/* 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 */ +bool ram_buf_rm;/* Remove RAM buffer file after read */ bool write_ram_buf;/* Write RAM buffer on exit */ const char *state_fname;/* File containing sandbox state */ void *state_fdt;/* Holds saved state for sandbox */
include/os.h +2 -0
@@ -268,4 +268,6 @@ int os_read_ram_buf(const char *fname);*/ int os_jump_to_image (const void *dest,int size); +int os_unlink (const char *fname); +#endif
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 30/31 sandbox: Add implementation of spi_setup_slave_fdt()
In reply to Simon GlassThis function is needed when CONFIG_OF_SPI is defined.
---
Changes in v2: None
drivers/spi/sandbox_spi.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/spi/sandbox_spi.c +13 -0
@@ -202,3 +202,16 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,return ret; } + +/** +* Set up a new SPI slave for an fdt node +* +* @param blob Device tree blob +* @param node SPI peripheral node to use +* @return 0 if ok, -1 on error +*/ +struct spi_slave *spi_setup_slave_fdt (const void *blob,int slave_node, +int spi_node) +{ +return NULL ; +}
Signature · 1 line
1.9.0.279.gdc9e3eb
PATCH v2 31/31 sandbox: config: Enable cros_ec emulation and related items
In reply to Simon GlassEnable the Chrome OS EC emulation for sandbox along with LCD, sound expanded GPIOs and a few other options to make this work correctly.
---
Changes in v2:
- Rebase to master
- Update series to take account of patches now merges from original series
include/common.h | 1 + include/configs/sandbox.h | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-)
include/common.h +1 -0
@@ -313,6 +313,7 @@ static inline int print_cpuinfo(void) }#endif int update_flash_size (int flash_size); +int arch_early_init_r (void );/** * Show the DRAM size in a board-specific way
include/configs/sandbox.h +33 -5
@@ -49,7 +49,7 @@#define CONFIG_CMD_GPIO #define CONFIG_SANDBOX_GPIO -#define CONFIG_SANDBOX_GPIO_COUNT 20 +#define CONFIG_SANDBOX_GPIO_COUNT 128#define CONFIG_CMD_GPT #define CONFIG_PARTITION_UUIDS
@@ -72,6 +72,7 @@#define CONFIG_CMDLINE_EDITING #define CONFIG_COMMAND_HISTORY #define CONFIG_AUTO_COMPLETE +#define CONFIG_BOOTDELAY 3#define CONFIG_ENV_SIZE 8192#define CONFIG_ENV_IS_NOWHERE
@@ -82,6 +83,8 @@#define CONFIG_CMD_SF_TEST #define CONFIG_CMD_SPI #define CONFIG_SPI_FLASH +#define CONFIG_OF_SPI +#define CONFIG_OF_SPI_FLASH #define CONFIG_SPI_FLASH_SANDBOX #define CONFIG_SPI_FLASH_STMICRO #define CONFIG_SPI_FLASH_WINBOND
@@ -90,7 +93,9 @@#define CONFIG_SYS_LOAD_ADDR 0x00000000#define CONFIG_SYS_MEMTEST_START 0x00100000#define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_MEMTEST_START + 0x1000) -#define CONFIG_SYS_FDT_LOAD_ADDR 0x1000000 +#define CONFIG_SYS_FDT_LOAD_ADDR 0x100 + +#define CONFIG_PHYSMEM /* Size of our emulated memory */ #define CONFIG_SYS_SDRAM_BASE 0
@@ -118,13 +123,36 @@#define CONFIG_SHA1 #define CONFIG_SHA256 +#define CONFIG_TPM_TIS_SANDBOX +#define CONFIG_CMD_SANDBOX #define CONFIG_BOOTARGS "" -#define CONFIG_EXTRA_ENV_SETTINGS "stdin=serial\0" \ - "stdout=serial\0" \ - "stderr=serial\0" +#define CONFIG_CROS_EC +#define CONFIG_CMD_CROS_EC +#define CONFIG_CROS_EC_SANDBOX +#define CONFIG_KEYBOARD +#define CONFIG_CROS_EC_KEYB +#define CONFIG_ARCH_EARLY_INIT_R +#define CONFIG_BOARD_LATE_INIT + +#define CONFIG_SOUND +#define CONFIG_SOUND_SANDBOX +#define CONFIG_CMD_SOUND + +#define CONFIG_SANDBOX_SDL +#define CONFIG_LCD +#define CONFIG_VIDEO_SANDBOX_SDL +#define CONFIG_CMD_BMP +#define CONFIG_BOARD_EARLY_INIT_F +#define CONFIG_CONSOLE_MUX +#define CONFIG_SYS_CONSOLE_IS_IN_ENV +#define LCD_BPP LCD_COLOR16 + +#define CONFIG_EXTRA_ENV_SETTINGS "stdin=serial,cros-ec-keyb\0" \ + "stdout=serial,lcd\0" \ + "stderr=serial,lcd\0"#define CONFIG_GZIP_COMPRESSED #define CONFIG_BZIP2
Signature · 1 line
1.9.0.279.gdc9e3eb