sandbox: Various bug fixes
Subsystems (5)
cover sandbox: Various bug fixes
This series collects together a lot of fixes for sandbox (mostly) that were discovered in the last release. Most of them are minor.
Simon Glass (17):
spl: misc: Allow misc drivers in SPL and TPL
Add an empty stdint.h file
sandbox: Sync up sandbox64.dts with main DT
sandbox: Create a common sandbox DT
sandbox: Add an alias for SPI
sandbox: Exit when SYSRESET_POWER_OFF is requested
sandbox: Quit when hang() is called
sandbox: spl: Lower priority of standard loader
sandbox: Add a comment to board_init_f()
sandbox: Allo sdl-config to be overridden
sandbox: Add a memory {} node
sandbox: Correct spi flash operation
sandbox: Add documentation on how to run valgrind
x86: Add a forward struct declaration in coreboot_tables.h
bootstage: Add support for TPL record count
blk: Allow control of the block cache in TPL
spi: Avoid using malloc() in a critical function
arch/sandbox/config.mk | 5 +- arch/sandbox/cpu/spl.c | 3 +- arch/sandbox/cpu/state.c | 1 + arch/sandbox/dts/sandbox.dts | 336 +----------------------- arch/sandbox/dts/sandbox.dtsi | 346 +++++++++++++++++++++++++ arch/sandbox/dts/sandbox64.dts | 275 +------------------- arch/x86/include/asm/coreboot_tables.h | 2 + board/sandbox/README.sandbox | 21 ++ common/Kconfig | 7 + drivers/block/Kconfig | 7 + drivers/misc/Kconfig | 72 +++++ drivers/misc/Makefile | 8 +- drivers/spi/Kconfig | 2 +- drivers/spi/spi-mem.c | 15 +- drivers/sysreset/sysreset_sandbox.c | 1 + include/configs/sandbox.h | 4 + include/stdint.h | 7 + lib/hang.c | 3 + 18 files changed, 508 insertions(+), 607 deletions(-) create mode 100644 arch/sandbox/dts/sandbox.dtsi create mode 100644 include/stdint.h
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 1/17 spl: misc: Allow misc drivers in SPL and TPL
In some cases it is necessary to read the keyboard in early phases of U-Boot. The cros_ec keyboard is kept in the misc directory. Update the config to allow this.
---
drivers/misc/Kconfig | 72 +++++++++++++++++++++++++++++++++++++++++++ drivers/misc/Makefile | 8 +++-- 2 files changed, 77 insertions(+), 3 deletions(-)
drivers/misc/Kconfig +72 -0
@@ -13,6 +13,24 @@ config MISC set of generic read, write and ioctl methods may be used to access the device. +config SPL_MISC + bool "Enable Driver Model for Misc drivers in SPL" + depends on SPL_DM + help + Enable driver model for miscellaneous devices. This class is + used only for those do not fit other more general classes. A + set of generic read, write and ioctl methods may be used to + access the device. + +config TPL_MISC + bool "Enable Driver Model for Misc drivers in TPL" + depends on TPL_DM + help + Enable driver model for miscellaneous devices. This class is + used only for those do not fit other more general classes. A + set of generic read, write and ioctl methods may be used to + access the device. + config ALTERA_SYSID bool "Altera Sysid support" depends on MISC
@@ -68,6 +86,24 @@ config CROS_EC control access to the battery and main PMIC depending on the device. You can use the 'crosec' command to access it. +config SPL_CROS_EC + bool "Enable Chrome OS EC in SPL" + help + Enable access to the Chrome OS EC in SPL. This is a separate + microcontroller typically available on a SPI bus on Chromebooks. It + provides access to the keyboard, some internal storage and may + control access to the battery and main PMIC depending on the + device. You can use the 'crosec' command to access it. + +config TPL_CROS_EC + bool "Enable Chrome OS EC in TPL" + help + Enable access to the Chrome OS EC in TPL. This is a separate + microcontroller typically available on a SPI bus on Chromebooks. It + provides access to the keyboard, some internal storage and may + control access to the battery and main PMIC depending on the + device. You can use the 'crosec' command to access it. + config CROS_EC_I2C bool "Enable Chrome OS EC I2C driver" depends on CROS_EC
@@ -86,6 +122,24 @@ config CROS_EC_LPC through a legacy port interface, so on x86 machines the main function of the EC is power and thermal management. +config SPL_CROS_EC_LPC + bool "Enable Chrome OS EC LPC driver in SPL" + depends on CROS_EC + help + Enable I2C access to the Chrome OS EC. This is used on x86 + Chromebooks such as link and falco. The keyboard is provided + through a legacy port interface, so on x86 machines the main + function of the EC is power and thermal management. + +config TPL_CROS_EC_LPC + bool "Enable Chrome OS EC LPC driver in TPL" + depends on CROS_EC + help + Enable I2C access to the Chrome OS EC. This is used on x86 + Chromebooks such as link and falco. The keyboard is provided + through a legacy port interface, so on x86 machines the main + function of the EC is power and thermal management. + config CROS_EC_SANDBOX bool "Enable Chrome OS EC sandbox driver" depends on CROS_EC && SANDBOX
@@ -95,6 +149,24 @@ config CROS_EC_SANDBOX EC flash read/write/erase support and a few other things. It is enough to perform a Chrome OS verified boot on sandbox. +config SPL_CROS_EC_SANDBOX + bool "Enable Chrome OS EC sandbox driver in SPL" + depends on SPL_CROS_EC && SANDBOX + help + Enable a sandbox emulation of the Chrome OS EC in SPL. This supports + keyboard (use the -l flag to enable the LCD), verified boot context, + EC flash read/write/erase support and a few other things. It is + enough to perform a Chrome OS verified boot on sandbox. + +config TPL_CROS_EC_SANDBOX + bool "Enable Chrome OS EC sandbox driver in TPL" + depends on TPL_CROS_EC && SANDBOX + help + Enable a sandbox emulation of the Chrome OS EC in TPL. This supports + keyboard (use the -l flag to enable the LCD), verified boot context, + EC flash read/write/erase support and a few other things. It is + enough to perform a Chrome OS verified boot on sandbox. + config CROS_EC_SPI bool "Enable Chrome OS EC SPI driver" depends on CROS_EC
drivers/misc/Makefile +5 -3
@@ -4,11 +4,13 @@ # Wolfgang Denk, DENX Software Engineering, wd at denx.de. obj-$(CONFIG_MISC) += misc-uclass.o + +obj-$(CONFIG_$(SPL_TPL_)CROS_EC) += cros_ec.o +obj-$(CONFIG_$(SPL_TPL_)CROS_EC_SANDBOX) += cros_ec_sandbox.o +obj-$(CONFIG_$(SPL_TPL_)CROS_EC_LPC) += cros_ec_lpc.o + ifndef CONFIG_SPL_BUILD -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 endif
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 2/17 Add an empty stdint.h file
In reply to Simon GlassSome libraries build by U-Boot may include stdint.h. This is not used by U-Boot itself and causes conflicts with the types defined in linux/types.h. To work around this, add an empty file with this name so that it will be used in preference to the compiler version.
---
include/stdint.h | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 include/stdint.h
include/stdint.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Dummy file to allow libraries linked with U-Boot to include stdint.h without +* getting the system version. +* +* U-Boot uses linux types (linux/types.h) so does not make use of stdint.h +*/
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 2/17 Add an empty stdint.h file
Quoted 6 lines · Simon Glass
Some libraries build by U-Boot may include
stdint.h. This is not used by U-Boot itself and causes conflicts with the types defined inlinux/types.h. To work around this, add an empty file with this name so that it will be used in preference to the compiler version.
Quoted 6 lines
Signed-off-by Simon Glass <[email protected]>---
include/stdint.h | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 include/stdint.h
Applied to u-boot-dm.
PATCH 3/17 sandbox: Sync up sandbox64.dts with main DT
In reply to Simon GlassVarious nodes have been added and adjusted with sandbox. Move these changes over to sandbox64.dts to keep these in sync.
---
arch/sandbox/dts/sandbox64.dts | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
arch/sandbox/dts/sandbox64.dts +67 -0
@@ -11,14 +11,21 @@ i2c0 = &i2c_0; pci0 = &pci; rtc0 = &rtc_0; + axi0 = &axi; }; chosen { stdout-path = "/serial"; }; + audio: audio-codec { + compatible = "sandbox,audio-codec"; + #sound-dai-cells = <1>; + }; + cros_ec: cros-ec { reg = <0 0 0 0>; + u-boot,dm-pre-reloc; compatible = "google,cros-ec-sandbox"; /*
@@ -26,6 +33,7 @@ * that the STM32L flash erases to 0, not 0xff. */ flash { + u-boot,dm-pre-reloc; image-pos = <0x08000000>; size = <0x20000>; erase-value = <0>;
@@ -58,6 +66,7 @@ }; gpio_a: gpios at 0 { + u-boot,dm-pre-reloc; gpio-controller; compatible = "sandbox,gpio"; #gpio-cells = <1>;
@@ -66,6 +75,7 @@ }; gpio_b: gpios at 1 { + u-boot,dm-pre-reloc; gpio-controller; compatible = "sandbox,gpio"; #gpio-cells = <2>;
@@ -120,6 +130,11 @@ }; }; + i2s: i2s { + compatible = "sandbox,i2s"; + #sound-dai-cells = <1>; + }; + lcd { u-boot,dm-pre-reloc; compatible = "sandbox,lcd-sdl";
@@ -159,6 +174,7 @@ pinctrl { compatible = "sandbox,pinctrl"; + status = "okay"; pinctrl_i2c0: i2c0 { groups = "i2c";
@@ -170,19 +186,38 @@ groups = "serial_a"; function = "serial"; }; + + pinctrl_onewire0: onewire0 { + groups = "w1"; + function = "w1"; + bias-pull-up; + }; }; reset at 1 { compatible = "sandbox,reset"; }; + sound { + compatible = "sandbox,sound"; + cpu { + sound-dai = <&i2s 0>; + }; + + codec { + sound-dai = <&audio 0>; + }; + }; + spi at 0 { + u-boot,dm-pre-reloc; #address-cells = <1>; #size-cells = <0>; reg = <0 0 0 0>; compatible = "sandbox,spi"; cs-gpios = <0>, <&gpio_a 0>; firmware_storage_spi: flash at 0 { + u-boot,dm-pre-reloc; reg = <0>; compatible = "spansion,m25p16", "sandbox,spi-flash"; spi-max-frequency = <40000000>;
@@ -238,6 +273,7 @@ }; tpm { + u-boot,dm-pre-reloc; compatible = "google,sandbox-tpm"; };
@@ -255,6 +291,7 @@ /* Needs to be available prior to relocation */ uart0: serial { + u-boot,dm-spl; compatible = "sandbox,serial"; sandbox,text-colour = "cyan"; pinctrl-names = "default";
@@ -319,6 +356,29 @@ }; }; + axi: axi at 0 { + compatible = "sandbox,axi"; + #address-cells = <0x1>; + #size-cells = <0x1>; + store at 0 { + compatible = "sandbox,sandbox_store"; + reg = <0x0 0x400>; + }; + }; + + onewire0: onewire { + compatible = "w1-gpio"; + gpios = <&gpio_a 8>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_onewire0>; + status = "okay"; + + sandbox_eeprom0: sandbox_eeprom at 0 { + compatible = "sandbox,w1-eeprom"; + status = "okay"; + }; + }; + sandbox_tee { compatible = "sandbox,tee"; };
@@ -326,3 +386,10 @@ #include "cros-ec-keyboard.dtsi" #include "sandbox_pmic.dtsi" + +&cros_ec { + u-boot,dm-pre-reloc; + keyboard-controller { + u-boot,dm-pre-reloc; + }; +};
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 4/17 sandbox: Create a common sandbox DT
In reply to Simon GlassAt present sandbox and sandbox64 have duplicated nodes. This is hard to maintain since changes in one need to be manually added to the other.
Create a common file to solve this problem.
---
arch/sandbox/dts/sandbox.dts | 333 +------------------------------ arch/sandbox/dts/sandbox.dtsi | 346 +++++++++++++++++++++++++++++++++ arch/sandbox/dts/sandbox64.dts | 333 +------------------------------ 3 files changed, 348 insertions(+), 664 deletions(-) create mode 100644 arch/sandbox/dts/sandbox.dtsi
arch/sandbox/dts/sandbox.dts +1 -332
@@ -1,7 +1,5 @@ /dts-v1/; -#define USB_CLASS_HUB 9 - / { #address-cells = <1>; #size-cells = <1>;
@@ -14,44 +12,10 @@ axi0 = &axi; }; - chosen { - stdout-path = "/serial"; - }; - - audio: audio-codec { - compatible = "sandbox,audio-codec"; - #sound-dai-cells = <1>; - }; - cros_ec: cros-ec { reg = <0 0>; u-boot,dm-pre-reloc; compatible = "google,cros-ec-sandbox"; - - /* - * This describes the flash memory within the EC. Note - * that the STM32L flash erases to 0, not 0xff. - */ - flash { - u-boot,dm-pre-reloc; - image-pos = <0x08000000>; - size = <0x20000>; - erase-value = <0>; - - /* Information for sandbox */ - ro { - image-pos = <0>; - size = <0xf000>; - }; - wp-ro { - image-pos = <0xf000>; - size = <0x1000>; - }; - rw { - image-pos = <0x10000>; - size = <0x10000>; - }; - }; }; ethrawbus {
@@ -65,30 +29,6 @@ fake-host-hwaddr = [00 00 66 44 22 00]; }; - gpio_a: gpios at 0 { - u-boot,dm-pre-reloc; - gpio-controller; - compatible = "sandbox,gpio"; - #gpio-cells = <1>; - gpio-bank-name = "a"; - sandbox,gpio-count = <20>; - }; - - gpio_b: gpios at 1 { - u-boot,dm-pre-reloc; - gpio-controller; - compatible = "sandbox,gpio"; - #gpio-cells = <2>; - gpio-bank-name = "b"; - sandbox,gpio-count = <10>; - }; - - hexagon { - compatible = "demo-simple"; - colour = "white"; - sides = <6>; - }; - i2c_0: i2c at 0 { #address-cells = <1>; #size-cells = <0>;
@@ -97,63 +37,6 @@ clock-frequency = <400000>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_i2c0>; - eeprom at 2c { - reg = <0x2c>; - compatible = "i2c-eeprom"; - sandbox,emul = <&emul_eeprom>; - }; - - rtc_0: rtc at 43 { - reg = <0x43>; - compatible = "sandbox-rtc"; - sandbox,emul = <&emul0>; - }; - sandbox_pmic: sandbox_pmic { - reg = <0x40>; - }; - - mc34708: pmic at 41 { - reg = <0x41>; - }; - - i2c_emul: emul { - reg = <0xff>; - compatible = "sandbox,i2c-emul-parent"; - emul_eeprom: emul-eeprom { - compatible = "sandbox,i2c-eeprom"; - sandbox,filename = "i2c.bin"; - sandbox,size = <256>; - }; - emul0: emul0 { - compatible = "sandbox,i2c-rtc"; - }; - }; - }; - - i2s: i2s { - compatible = "sandbox,i2s"; - #sound-dai-cells = <1>; - }; - - lcd { - u-boot,dm-pre-reloc; - compatible = "sandbox,lcd-sdl"; - xres = <1366>; - yres = <768>; - }; - - leds { - compatible = "gpio-leds"; - - iracibble { - gpios = <&gpio_a 1 0>; - label = "sandbox:red"; - }; - - martinet { - gpios = <&gpio_a 2 0>; - label = "sandbox:green"; - }; }; pci: pci-controller {
@@ -163,50 +46,6 @@ #size-cells = <2>; ranges = <0x02000000 0 0x10000000 0x10000000 0 0x2000 0x01000000 0 0x20000000 0x20000000 0 0x2000>; - pci at 1f,0 { - compatible = "pci-generic"; - reg = <0xf800 0 0 0 0>; - emul at 1f,0 { - compatible = "sandbox,swap-case"; - }; - }; - }; - - pinctrl { - compatible = "sandbox,pinctrl"; - status = "okay"; - - pinctrl_i2c0: i2c0 { - groups = "i2c"; - function = "i2c"; - bias-pull-up; - }; - - pinctrl_serial0: uart0 { - groups = "serial_a"; - function = "serial"; - }; - - pinctrl_onewire0: onewire0 { - groups = "w1"; - function = "w1"; - bias-pull-up; - }; - }; - - reset at 1 { - compatible = "sandbox,reset"; - }; - - sound { - compatible = "sandbox,sound"; - cpu { - sound-dai = <&i2s 0>; - }; - - codec { - sound-dai = <&audio 0>; - }; }; spi at 0 {
@@ -216,180 +55,10 @@ reg = <0 0>; compatible = "sandbox,spi"; cs-gpios = <0>, <&gpio_a 0>; - firmware_storage_spi: flash at 0 { - u-boot,dm-pre-reloc; - reg = <0>; - compatible = "spansion,m25p16", "sandbox,spi-flash"; - spi-max-frequency = <40000000>; - sandbox,filename = "spi.bin"; - }; }; - spl-test { - u-boot,dm-pre-reloc; - compatible = "sandbox,spl-test"; - boolval; - intval = <1>; - intarray = <2 3 4>; - byteval = [05]; - bytearray = [06]; - longbytearray = [09 0a 0b 0c 0d 0e 0f 10 11]; - stringval = "message"; - stringarray = "multi-word", "message"; - }; - - spl-test2 { - u-boot,dm-pre-reloc; - compatible = "sandbox,spl-test"; - intval = <3>; - intarray = <5>; - byteval = [08]; - bytearray = [01 23 34]; - longbytearray = [09 0a 0b 0c]; - stringval = "message2"; - stringarray = "another", "multi-word", "message"; - }; - - spl-test3 { - u-boot,dm-pre-reloc; - compatible = "sandbox,spl-test"; - stringarray = "one"; - }; - - spl-test4 { - u-boot,dm-pre-reloc; - compatible = "sandbox,spl-test.2"; - }; - - square { - compatible = "demo-shape"; - colour = "blue"; - sides = <4>; - }; - - timer { - compatible = "sandbox,timer"; - clock-frequency = <1000000>; - }; - - tpm { - u-boot,dm-pre-reloc; - compatible = "google,sandbox-tpm"; - }; - - tpm2 { - compatible = "sandbox,tpm2"; - }; - - triangle { - compatible = "demo-shape"; - colour = "cyan"; - sides = <3>; - character = <83>; - light-gpios = <&gpio_a 2>, <&gpio_b 6 0>; - }; - - /* Needs to be available prior to relocation */ - uart0: serial { - u-boot,dm-spl; - compatible = "sandbox,serial"; - sandbox,text-colour = "cyan"; - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_serial0>; - }; - - usb at 0 { - compatible = "sandbox,usb"; - status = "disabled"; - hub { - compatible = "sandbox,usb-hub"; - #address-cells = <1>; - #size-cells = <0>; - flash-stick { - reg = <0>; - compatible = "sandbox,usb-flash"; - }; - }; - }; - - usb at 1 { - compatible = "sandbox,usb"; - hub { - compatible = "usb-hub"; - usb,device-class = <USB_CLASS_HUB>; - hub-emul { - compatible = "sandbox,usb-hub"; - #address-cells = <1>; - #size-cells = <0>; - flash-stick { - reg = <0>; - compatible = "sandbox,usb-flash"; - sandbox,filepath = "flash.bin"; - }; - }; - }; - }; - - usb at 2 { - compatible = "sandbox,usb"; - status = "disabled"; - }; - - spmi: spmi at 0 { - compatible = "sandbox,spmi"; - #address-cells = <0x1>; - #size-cells = <0x1>; - pm8916 at 0 { - compatible = "qcom,spmi-pmic"; - reg = <0x0 0x1>; - #address-cells = <0x1>; - #size-cells = <0x1>; - - spmi_gpios: gpios at c000 { - compatible = "qcom,pm8916-gpio"; - reg = <0xc000 0x400>; - gpio-controller; - gpio-count = <4>; - #gpio-cells = <2>; - gpio-bank-name="spmi"; - }; - }; - }; - - axi: axi at 0 { - compatible = "sandbox,axi"; - #address-cells = <0x1>; - #size-cells = <0x1>; - store at 0 { - compatible = "sandbox,sandbox_store"; - reg = <0x0 0x400>; - }; - }; - - onewire0: onewire { - compatible = "w1-gpio"; - gpios = <&gpio_a 8>; - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_onewire0>; - status = "okay"; - - sandbox_eeprom0: sandbox_eeprom at 0 { - compatible = "sandbox,w1-eeprom"; - status = "okay"; - }; - }; - - sandbox_tee { - compatible = "sandbox,tee"; - }; }; +#include "sandbox.dtsi" #include "cros-ec-keyboard.dtsi" #include "sandbox_pmic.dtsi" - -&cros_ec { - u-boot,dm-pre-reloc; - keyboard-controller { - u-boot,dm-pre-reloc; - }; -};
arch/sandbox/dts/sandbox.dtsi new file +346 -0
346 lines not on this page · raw message
arch/sandbox/dts/sandbox64.dts +1 -332
375 lines not on this page · raw message
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 5/17 sandbox: Add an alias for SPI
In reply to Simon GlassAt present 'sf probe' does not work since it cannot find SPI bus 0. Add an alias to correct this, now that we no-longer have the --spi_sf option.
---
arch/sandbox/dts/sandbox.dts | 3 ++- arch/sandbox/dts/sandbox64.dts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/sandbox/dts/sandbox.dts +2 -1
@@ -10,6 +10,7 @@ pci0 = &pci; rtc0 = &rtc_0; axi0 = &axi; + spi0 = &spi; }; cros_ec: cros-ec {
@@ -48,7 +49,7 @@ 0x01000000 0 0x20000000 0x20000000 0 0x2000>; }; - spi at 0 { + spi: spi at 0 { u-boot,dm-pre-reloc; #address-cells = <1>; #size-cells = <0>;
arch/sandbox/dts/sandbox64.dts +2 -1
@@ -10,6 +10,7 @@ pci0 = &pci; rtc0 = &rtc_0; axi0 = &axi; + spi0 = &spi; }; cros_ec: cros-ec {
@@ -48,7 +49,7 @@ 0x01000000 0 0x20000000 0 0x20000000 0 0x2000>; }; - spi at 0 { + spi: spi at 0 { u-boot,dm-pre-reloc; #address-cells = <1>; #size-cells = <0>;
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 6/17 sandbox: Exit when SYSRESET_POWER_OFF is requested
In reply to Simon GlassAt present this returns but it seems better to just exit sandbox immediately.
reset
---
arch/sandbox/cpu/state.c | 1 + drivers/sysreset/sysreset_sandbox.c | 1 + 2 files changed, 2 insertions(+)
arch/sandbox/cpu/state.c +1 -0
@@ -356,6 +356,7 @@ void state_reset_for_test(struct sandbox_state *state)/* No reset yet, so mark it as such. Always allow power reset */ state->last_sysreset =SYSRESET_COUNT ; state->sysreset_allowed[SYSRESET_POWER ] = true; + state->sysreset_allowed[SYSRESET_POWER_OFF ] = true;memset (&state->wdt,'\0' ,sizeof (state->wdt));memset (state->spi,'\0' ,sizeof (state->spi));
drivers/sysreset/sysreset_sandbox.c +1 -0
@@ -66,6 +66,7 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)case SYSRESET_POWER_OFF :if (!state->sysreset_allowed[type])return -EACCES ; +sandbox_exit ();default :return -ENOSYS ; }
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 7/17 sandbox: Quit when hang() is called
In reply to Simon GlassIt doesn't make a lot of sense to hang on sandbox when hang() is called, since the only way out is Ctrl-C. In fact, Ctrl-C does not work if the terminal is in raw mode, which it will be if the command-line has not been reached yet. In that case, Ctrl-Z / kill -9 must be used, which is not very friendly.
Avoid all of this by quiting when hang() is called.
---
lib/hang.c | 3 +++ 1 file changed, 3 insertions(+)
lib/hang.c +3 -0
@@ -9,6 +9,7 @@#include <common.h> #include <bootstage.h> +#include <os.h> /** * hang - stop processing by staying in an endless loop
@@ -26,6 +27,8 @@ void hang(void)puts ("### ERROR ### Please RESET the board ###\n" );#endif bootstage_error (BOOTSTAGE_ID_NEED_RESET ); +if (IS_ENABLED (CONFIG_SANDBOX )) +os_exit (1 );for (;;) ; }
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 8/17 sandbox: spl: Lower priority of standard loader
In reply to Simon GlassWe normally want to load U-Boot from SPL, but if a board wants to do something else, it is currently not possible since the standard loader has the top priority. Lower it to allow other SPL_LOAD_IMAGE_METHOD() declarations to override it.
---
arch/sandbox/cpu/spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/cpu/spl.c +1 -1
@@ -44,7 +44,7 @@ static int spl_board_load_image(struct spl_image_info *spl_image,return 0 ; } -SPL_LOAD_IMAGE_METHOD ("sandbox" ,0 ,BOOT_DEVICE_BOARD , spl_board_load_image); +SPL_LOAD_IMAGE_METHOD ("sandbox" ,9 ,BOOT_DEVICE_BOARD , spl_board_load_image);void spl_board_init (void ) {
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 9/17 sandbox: Add a comment to board_init_f()
In reply to Simon GlassThis function is used for both SPL and TPL. Add a comment to that effect.
---
arch/sandbox/cpu/spl.c | 1 + 1 file changed, 1 insertion(+)
arch/sandbox/cpu/spl.c +1 -0
@@ -12,6 +12,7 @@DECLARE_GLOBAL_DATA_PTR ; +/* SPL / TPL init function */ void board_init_f (ulong flag) {struct sandbox_state *state =state_get_current ();
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 10/17 sandbox: Allo sdl-config to be overridden
In reply to Simon GlassWhen cross-compiling, sometimes sdl-config must come from a different path from the default. Add a way to override it, by adding SDL_CONFIG to the environment before building U-Boot.
---
arch/sandbox/config.mk | 5 +++-- board/sandbox/README.sandbox | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-)
arch/sandbox/config.mk +3 -2
@@ -5,14 +5,15 @@ PLATFORM_CPPFLAGS += -D__SANDBOX__ -U_FORTIFY_SOURCE PLATFORM_CPPFLAGS += -DCONFIG_ARCH_MAP_SYSMEM PLATFORM_CPPFLAGS += -fPIC PLATFORM_LIBS += -lrt +SDL_CONFIG ?= sdl-config # Define this to avoid linking with SDL, which requires SDL libraries # This can solve 'sdl-config: Command not found' errors ifneq ($(NO_SDL),) PLATFORM_CPPFLAGS += -DSANDBOX_NO_SDL else -PLATFORM_LIBS += $(shell sdl-config --libs) -PLATFORM_CPPFLAGS += $(shell sdl-config --cflags) +PLATFORM_LIBS += $(shell $(SDL_CONFIG) --libs) +PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags) endif cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
board/sandbox/README.sandbox +7 -0
@@ -435,6 +435,13 @@ board_init_f() and board_init_r(). This approach can be used on normal boards as well as sandbox. +SDL_CONFIG +---------- + +If sdl-config is on a different path from the default, set the SDL_CONFIG +environment variable to the correct pathname before building U-Boot. + + Testing -------
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 11/17 sandbox: Add a memory {} node
In reply to Simon GlassAdd a memory node which indicates the size of sandbox memory.
---
arch/sandbox/dts/sandbox.dts | 6 ++++++ arch/sandbox/dts/sandbox64.dts | 6 ++++++ include/configs/sandbox.h | 4 ++++ 3 files changed, 16 insertions(+)
arch/sandbox/dts/sandbox.dts +6 -0
@@ -1,5 +1,7 @@ /dts-v1/; +#include <config.h> + / { #address-cells = <1>; #size-cells = <1>;
@@ -13,6 +15,10 @@ spi0 = &spi; }; + memory { + reg = <0 CONFIG_SYS_SDRAM_SIZE>; + }; + cros_ec: cros-ec { reg = <0 0>; u-boot,dm-pre-reloc;
arch/sandbox/dts/sandbox64.dts +6 -0
@@ -1,5 +1,7 @@ /dts-v1/; +#include <config.h> + / { #address-cells = <2>; #size-cells = <2>;
@@ -13,6 +15,10 @@ spi0 = &spi; }; + memory { + reg = /bits/ 64 <0 CONFIG_SYS_SDRAM_SIZE>; + }; + cros_ec: cros-ec { reg = <0 0 0 0>; u-boot,dm-pre-reloc;
include/configs/sandbox.h +4 -0
@@ -63,7 +63,11 @@ func(HOST, host, 1) \ func(HOST, host, 0) +#ifdef __ASSEMBLY__ +#define BOOTENV +#else #include <config_distro_bootcmd.h> +#endif #define CONFIG_KEEP_SERVERADDR #define CONFIG_UDP_CHECKSUM
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 12/17 sandbox: Correct spi flash operation
In reply to Simon GlassSince the SPI nor conversion, 'sf probe' does not work on sandbox. Fix this by using the expected compatible string in the flash node.
---
arch/sandbox/dts/sandbox.dtsi | 2 +- drivers/spi/Kconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/sandbox/dts/sandbox.dtsi +1 -1
@@ -150,7 +150,7 @@ firmware_storage_spi: flash at 0 { u-boot,dm-pre-reloc; reg = <0>; - compatible = "spansion,m25p16", "sandbox,spi-flash"; + compatible = "spansion,m25p16", "jedec,spi-nor"; spi-max-frequency = <40000000>; sandbox,filename = "spi.bin"; };
drivers/spi/Kconfig +1 -1
@@ -207,7 +207,7 @@ config SANDBOX_SPI cs-gpios = <0>, <&gpio_a 0>; flash at 0 { reg = <0>; - compatible = "spansion,m25p16", "sandbox,spi-flash"; + compatible = "spansion,m25p16", "jedec,spi-nor"; spi-max-frequency = <40000000>; sandbox,filename = "spi.bin"; };
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 13/17 sandbox: Add documentation on how to run valgrind
In reply to Simon GlassU-Boot sandbox can run with valgrind to check memory allocations. Add documentation on how to do this.
---
board/sandbox/README.sandbox | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
board/sandbox/README.sandbox +14 -0
@@ -442,6 +442,20 @@ If sdl-config is on a different path from the default, set the SDL_CONFIG environment variable to the correct pathname before building U-Boot. +Using valgrind / memcheck +------------------------- + +It is possible to run U-Boot under valgrind to check memory allocations: + + valgrind u-boot + +If you are running sandbox SPL or TPL, then valgrind will not by default +notice when U-Boot jumps from TPL to SPL, or from SPL to U-Boot proper. To +fix this, use: + + valgrind --trace-children=yes u-boot + + Testing -------
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 14/17 x86: Add a forward struct declaration in coreboot_tables.h
In reply to Simon GlassThis struct is not defined in this header file. Add a forward declaration so that it can be included in any context.
---
arch/x86/include/asm/coreboot_tables.h | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/include/asm/coreboot_tables.h +2 -0
@@ -8,6 +8,8 @@ #ifndef _COREBOOT_TABLES_H #define _COREBOOT_TABLES_H +struct memory_area; + struct cbuint64 { u32 lo; u32 hi;
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 14/17 x86: Add a forward struct declaration in coreboot_tables.h
Quoted 10 lines · Simon Glass
This struct is not defined in this header file. Add a forward declaration so that it can be included in any context.
Signed-off-by Simon Glass <[email protected]>---
arch/x86/include/asm/coreboot_tables.h | 2 ++ 1 file changed, 2 insertions(+)
PATCH 15/17 bootstage: Add support for TPL record count
In reply to Simon GlassIf bootstage is enabled in TPL it lacks a record count and so does not build. Fix this by adding a new Kconfig option.
---
common/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+)
common/Kconfig +7 -0
@@ -69,6 +69,13 @@ config SPL_BOOTSTAGE_RECORD_COUNT This is the size of the bootstage record list and is the maximum number of bootstage records that can be recorded. +config TPL_BOOTSTAGE_RECORD_COUNT + int "Number of boot stage records to store for TPL" + default 5 + help + This is the size of the bootstage record list and is the maximum + number of bootstage records that can be recorded. + config BOOTSTAGE_FDT bool "Store boot timing information in the OS device tree" depends on BOOTSTAGE
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 16/17 blk: Allow control of the block cache in TPL
In reply to Simon GlassGenerally block devices are not enabled in TPL, but in case they are, add a Kconfig option for the block cache. This allows the setting (default off) to be found with CONFIG_IS_ENABLED().
---
drivers/block/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/block/Kconfig +7 -0
@@ -56,6 +56,13 @@ config SPL_BLOCK_CACHE help This option enables the disk-block cache in SPL +config TPL_BLOCK_CACHE + bool "Use block device cache in TPL" + depends on TPL_BLK + default n + help + This option enables the disk-block cache in TPL + config IDE bool "Support IDE controllers" select HAVE_BLOCK_DEVICE
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 17/17 spi: Avoid using malloc() in a critical function
In reply to Simon GlassIn general we should avoid calling malloc() and free() repeatedly in U-Boot lest we turn it into tianocore. In SPL this can make SPI flash unusable since free() is often a nop and allocation space is limited.
In any case, these seems no need for malloc() since the number of bytes is very small, perhaps less than 8.
memory controllers)
---
drivers/spi/spi-mem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/spi/spi-mem.c +11 -4
@@ -201,7 +201,6 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)unsigned int pos =0 ;const u8 *tx_buf =NULL ;u8 *rx_buf =NULL ; -u8 *op_buf;int op_len;u32 flag;int ret;
@@ -338,7 +337,17 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) } op_len =sizeof (op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes; - op_buf =calloc (1 , op_len); + +/* +* Avoid using malloc() here so that we can use this code in SPL where +* simple malloc may be used. That implementation does not allow free() +* so repeated calls to this code can exhaust the space. +* +* The value of op_len is small, since it does not include the actual +* data being sent, only the op-code and address. In fact, it should be +* possible to just use a small fixed value here instead of op_len. +*/ +u8 op_buf[op_len]; op_buf[pos++] = op->cmd.opcode;
@@ -382,8 +391,6 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)debug ("%02x " , tx_buf ? tx_buf[i] : rx_buf[i]);debug ("[ret %d]\n" , ret); -free (op_buf); -if (ret <0 )return ret;#endif /* __UBOOT__ */
Signature · 1 line
2.21.0.1020.gf2820cf01a-goog
PATCH 17/17 spi: Avoid using malloc() in a critical function
Hi,
Quoted 35 lines · Simon Glass
In general we should avoid calling
malloc()andfree()repeatedly in U-Boot lest we turn it into tianocore. In SPL this can make SPI flash unusable sincefree()is often a nop and allocation space is limited.In any case, these seems no need for
malloc()since the number of bytes is very small, perhaps less than 8.Signed-off-by Simon Glass <[email protected]>Fixes d13f5b254a (spi: Extend the core to ease integration of SPImemory controllers)
---
drivers/spi/spi-mem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)drivers/spi/spi-mem.c +1
-2@@ -201,7 +201,6 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)unsigned int pos =0 ;const u8 *tx_buf =NULL ;u8 *rx_buf =NULL ; -u8 *op_buf;int op_len;u32 flag;int ret;@@ -338,7 +337,17 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) } op_len =sizeof (op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes; - op_buf =calloc (1 , op_len); +
drivers/spi/spi-mem.c int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) · line 350
Quoted 10 lines
drivers/spi/spi-mem.c +10
-0+/* +* Avoid using malloc() here so that we can use this code in SPL where +* simple malloc may be used. That implementation does not allow free() +* so repeated calls to this code can exhaust the space. +* +* The value of op_len is small, since it does not include the actual +* data being sent, only the op-code and address. In fact, it should be +* possible to just use a small fixed value here instead of op_len. +*/ +u8 op_buf[op_len];
I'd say just make this a fixed buffer instead of a VLA - less code space bloat and potential stack problems in case of nonsensical inputs.
As for the size, 8 bytes would be fine and actually leave some margin:
the most i would expect for op_len is 1 + 4 + 1 = 6 bytes (the lowest would be 1+3+0 and the usual 1+3+1).
Signature · 1 line
Urja Rannikko
PATCH 17/17 spi: Avoid using malloc() in a critical function
Hi Urja,
Quoted 54 lines · Urja Rannikko
Hi,
Quoted 35 lines · Simon Glass
In general we should avoid calling
malloc()andfree()repeatedly in U-Boot lest we turn it into tianocore. In SPL this can make SPI flash unusable sincefree()is often a nop and allocation space is limited.In any case, these seems no need for
malloc()since the number of bytes is very small, perhaps less than 8.Signed-off-by Simon Glass <[email protected]>Fixes d13f5b254a (spi: Extend the core to ease integration of SPImemory controllers)
---
drivers/spi/spi-mem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)drivers/spi/spi-mem.c +1
-2@@ -201,7 +201,6 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)unsigned int pos =0 ;const u8 *tx_buf =NULL ;u8 *rx_buf =NULL ; -u8 *op_buf;int op_len;u32 flag;int ret;@@ -338,7 +337,17 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) } op_len =sizeof (op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes; - op_buf =calloc (1 , op_len); +drivers/spi/spi-mem.c int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) · line 350
Quoted 10 lines
drivers/spi/spi-mem.c +10
-0+/* +* Avoid using malloc() here so that we can use this code in SPL where +* simple malloc may be used. That implementation does not allow free() +* so repeated calls to this code can exhaust the space. +* +* The value of op_len is small, since it does not include the actual +* data being sent, only the op-code and address. In fact, it should be +* possible to just use a small fixed value here instead of op_len. +*/ +u8 op_buf[op_len];I'd say just make this a fixed buffer instead of a VLA - less code space bloat and potential stack problems in case of nonsensical inputs.
Quoted 3 lines
As for the size, 8 bytes would be fine and actually leave some margin:
the most i would expect forop_lenis 1 + 4 + 1 = 6 bytes (the lowest would be 1+3+0 and the usual 1+3+1).
Is it possible to add a build-time assert for this somewhere?
Is VLA very large array? How large is very large?
I think the stack is much better place than a fixed buffer for something only 8 bytes in size.
Regards,
Simon
PATCH 17/17 spi: Avoid using malloc() in a critical function
Hi Simon,
Quoted 2 lines · Simon Glass
Hi Urja,
<snip>
Quoted 1 line
Is it possible to add a build-time assert for this somewhere?
I'm not sure, you'd need to check every user of these operations - i was going to suggest just bailing out with an error code or a runtime assert, and going through the users of the SPI_MEM_OP macros to make sure there's no surprises.
Quoted 2 lines
Is VLA very large array? How large is very large?
VLA as in variable length array, the C feature you're using above. For a reference of sorts, more on VLAs and the kernel, which got rid of them in 4.20: https://lwn.net/Articles/749064/
Quoted 2 lines
I think the stack is much better place than a fixed buffer for something only 8 bytes in size.
Yes.
Signature · 1 line
Urja Rannikko
PATCH 17/17 spi: Avoid using malloc() in a critical function
Hi Urja,
Quoted 5 lines · Urja Rannikko
Hi Simon,
Quoted 1 line · Simon Glass
Quoted 7 lines
Quoted 1 line
Hi Urja,
<snip>
Quoted 1 line
Is it possible to add a build-time assert for this somewhere?
I'm not sure, you'd need to check every user of these operations - i was going to suggest just bailing out with an error code or a runtime assert, and going through the users of the
SPI_MEM_OPmacros to make sure there's no surprises.
I think bailing out with -ENOSPC would be fine.
Quoted 5 lines
Quoted 2 lines
Is VLA very large array? How large is very large?
VLA as in variable length array, the C feature you're using above. For a reference of sorts, more on VLAs and the kernel, which got rid of them in 4.20: https://lwn.net/Articles/749064/
OK I see. My only concern with variable-length arrays is when the length is unbounded. If we had a run-time check beforehand (size < 100 for example), then I suppose it would be OK. It seems like in this case we don't need one though.
Quoted 4 lines
Quoted 3 lines
I think the stack is much better place than a fixed buffer for something only 8 bytes in size.
Yes.
Regards,
Simon
cover sandbox: Various bug fixes
In reply to Simon GlassHi,
Quoted 46 lines · Simon Glass
This series collects together a lot of fixes for sandbox (mostly) that were discovered in the last release. Most of them are minor.
Simon Glass (17):
spl: misc: Allow misc drivers in SPL and TPL
Add an emptystdint.hfile
sandbox: Sync upsandbox64.dtswith main DT
sandbox: Create a common sandbox DT
sandbox: Add an alias for SPI
sandbox: Exit whenSYSRESET_POWER_OFFis requested
sandbox: Quit whenhang()is called
sandbox: spl: Lower priority of standard loader
sandbox: Add a comment toboard_init_f()
sandbox: Allo sdl-config to be overridden
sandbox: Add a memory {} node
sandbox: Correct spi flash operation
sandbox: Add documentation on how to run valgrind
x86: Add a forward struct declaration incoreboot_tables.h
bootstage: Add support for TPL record count
blk: Allow control of the block cache in TPL
spi: Avoid usingmalloc()in a critical functionarch/sandbox/config.mk | 5 +- arch/sandbox/cpu/spl.c | 3 +- arch/sandbox/cpu/state.c | 1 + arch/sandbox/dts/sandbox.dts | 336 +----------------------- arch/sandbox/dts/sandbox.dtsi | 346 +++++++++++++++++++++++++ arch/sandbox/dts/sandbox64.dts | 275 +------------------- arch/x86/include/asm/coreboot_tables.h | 2 + board/sandbox/README.sandbox | 21 ++ common/Kconfig | 7 + drivers/block/Kconfig | 7 + drivers/misc/Kconfig | 72 +++++ drivers/misc/Makefile | 8 +- drivers/spi/Kconfig | 2 +- drivers/spi/spi-mem.c | 15 +- drivers/sysreset/sysreset_sandbox.c | 1 + include/configs/sandbox.h | 4 + include/stdint.h | 7 + lib/hang.c | 3 + 18 files changed, 508 insertions(+), 607 deletions(-) create mode 100644 arch/sandbox/dts/sandbox.dtsi create mode 100644 include/stdint.h
Quoted 3 lines
--
2.21.0.1020.gf2820cf01a-goog
Series applied to u-boot-dm/next.