Skip to contentSkip to conversation

sandbox: Various bug fixes

PATCH New Simon Glass 3 participants 25 messages May 18, 2019 – Jun 28, 2019

Subsystems (5)
x86 Block layer Library code SPI +1 more subsystems
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 0e645f58be0..cb8b5c04dbc 100644
@@ -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
index 6bdf5054f47..509c588582d 100644
@@ -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
#2 lore raw

PATCH 2/17 Add an empty stdint.h file

In reply to 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 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
new file mode 100644
index 00000000000..2e126d14bd9
@@ -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
#3 lore raw

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 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.

Quoted 6 lines

---

 include/stdint.h | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 include/stdint.h

Applied to u-boot-dm.

#4 lore raw

PATCH 3/17 sandbox: Sync up sandbox64.dts with main DT

In reply to Simon Glass

Various 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
index a3c95f2cdb2..e5b44264261 100644
@@ -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
#5 lore raw

PATCH 4/17 sandbox: Create a common sandbox DT

In reply to Simon Glass

At 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
index a41b5f052d7..c0bdba94a73 100644
@@ -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
#6 lore raw

PATCH 5/17 sandbox: Add an alias for SPI

In reply to Simon Glass

At 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
index c0bdba94a73..9a949791a0e 100644
@@ -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
index a263f78c957..da2b4423fdc 100644
@@ -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
#7 lore raw

PATCH 6/17 sandbox: Exit when SYSRESET_POWER_OFF is requested

In reply to Simon Glass

At 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
index d3b9c059859..2333240fda8 100644
@@ -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
index 38e2a7e241d..7dfd89460f0 100644
@@ -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
#8 lore raw

PATCH 7/17 sandbox: Quit when hang() is called

In reply to Simon Glass

It 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
index c5a78694be6..4d026a3e64c 100644
@@ -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
#9 lore raw

PATCH 8/17 sandbox: spl: Lower priority of standard loader

In reply to Simon Glass

We 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
index 2ca4cd6e35e..106a78ac1c1 100644
@@ -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
#10 lore raw

PATCH 9/17 sandbox: Add a comment to board_init_f()

In reply to Simon Glass

This 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
index 106a78ac1c1..4f415c71d63 100644
@@ -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
#11 lore raw

PATCH 10/17 sandbox: Allo sdl-config to be overridden

In reply to Simon Glass

When 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
index 31a12db103d..05fbbd7bcc7 100644
@@ -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
index 48c1e2b9e7b..5e8fa58ba29 100644
@@ -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
#12 lore raw

PATCH 11/17 sandbox: Add a memory {} node

In reply to Simon Glass

Add 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
index 9a949791a0e..16a33db87d3 100644
@@ -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
index da2b4423fdc..37a5539ff47 100644
@@ -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
index bf03baefe83..47983ced2e6 100644
@@ -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
#13 lore raw

PATCH 12/17 sandbox: Correct spi flash operation

In reply to Simon Glass

Since the SPI nor conversion, 'sf probe' does not work on sandbox. Fix this by using the expected compatible string in the flash node.

Fixes cd35365762 (mtd: sf_probe: remove spi-flash compatible)

---

 arch/sandbox/dts/sandbox.dtsi | 2 +-
 drivers/spi/Kconfig           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/sandbox/dts/sandbox.dtsi +1 -1
index ebc4ece8248..2fb365d86e8 100644
@@ -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
index c3a829deaec..237f4e6539e 100644
@@ -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
#14 lore raw

PATCH 13/17 sandbox: Add documentation on how to run valgrind

In reply to Simon Glass

U-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
index 5e8fa58ba29..c10dd444df0 100644
@@ -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
#15 lore raw

PATCH 14/17 x86: Add a forward struct declaration in coreboot_tables.h

In reply to Simon Glass

This 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
index c42175b94da..2c54e24e02f 100644
@@ -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
#16 lore raw

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.

---

 arch/x86/include/asm/coreboot_tables.h | 2 ++
 1 file changed, 2 insertions(+)
#17 lore raw

PATCH 15/17 bootstage: Add support for TPL record count

In reply to Simon Glass

If 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
index 1a1951f874e..cd0934fff9a 100644
@@ -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
#18 lore raw

PATCH 16/17 blk: Allow control of the block cache in TPL

In reply to Simon Glass

Generally 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
index 33f4aa24185..1e6dad86927 100644
@@ -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
#19 lore raw

PATCH 17/17 spi: Avoid using malloc() in a critical function

In reply to Simon Glass

In 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.

Fixes d13f5b254a (spi: Extend the core to ease integration of SPI

memory controllers)

---

 drivers/spi/spi-mem.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/spi/spi-mem.c +11 -4
index b86eee75bcb..7aabebeff5f 100644
@@ -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
#20 lore raw

PATCH 17/17 spi: Avoid using malloc() in a critical function

Hi,

Quoted 35 lines · Simon Glass

In 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.

Fixes d13f5b254a (spi: Extend the core to ease integration of SPI

memory controllers)

---

 drivers/spi/spi-mem.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/spi/spi-mem.c +1 -2
index b86eee75bcb..7aabebeff5f 100644
@@ -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
#21 lore raw

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() 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.

Fixes d13f5b254a (spi: Extend the core to ease integration of SPI

memory controllers)

---

 drivers/spi/spi-mem.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/spi/spi-mem.c +1 -2
index b86eee75bcb..7aabebeff5f 100644
@@ -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 for op_len is 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

#22 lore raw

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
#23 lore raw

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_OP macros 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

#24 lore raw

cover sandbox: Various bug fixes

In reply to Simon Glass

Hi,

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 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
Quoted 3 lines

--
2.21.0.1020.gf2820cf01a-goog

Series applied to u-boot-dm/next.