* [U-Boot] [PATCH 01/17] spl: misc: Allow misc drivers in SPL and TPL
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 02/17] Add an empty stdint.h file Simon Glass
` (16 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
drivers/misc/Kconfig | 72 +++++++++++++++++++++++++++++++++++++++++++
drivers/misc/Makefile | 8 +++--
2 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 0e645f58be0..cb8b5c04dbc 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -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
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 6bdf5054f47..509c588582d 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -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
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 02/17] Add an empty stdint.h file
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 01/17] spl: misc: Allow misc drivers in SPL and TPL Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-22 13:21 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 03/17] sandbox: Sync up sandbox64.dts with main DT Simon Glass
` (15 subsequent siblings)
17 siblings, 1 reply; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
include/stdint.h | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 include/stdint.h
diff --git a/include/stdint.h b/include/stdint.h
new file mode 100644
index 00000000000..2e126d14bd9
--- /dev/null
+++ b/include/stdint.h
@@ -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
+ */
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 02/17] Add an empty stdint.h file
2019-05-18 17:59 ` [U-Boot] [PATCH 02/17] Add an empty stdint.h file Simon Glass
@ 2019-05-22 13:21 ` Simon Glass
0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-22 13:21 UTC (permalink / raw)
To: u-boot
On Sat, 18 May 2019 at 12:00, Simon Glass <sjg@chromium.org> wrote:
>
> 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.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> include/stdint.h | 7 +++++++
> 1 file changed, 7 insertions(+)
> create mode 100644 include/stdint.h
Applied to u-boot-dm.
^ permalink raw reply [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 03/17] sandbox: Sync up sandbox64.dts with main DT
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 01/17] spl: misc: Allow misc drivers in SPL and TPL Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 02/17] Add an empty stdint.h file Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 04/17] sandbox: Create a common sandbox DT Simon Glass
` (14 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
Various nodes have been added and adjusted with sandbox. Move these
changes over to sandbox64.dts to keep these in sync.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/sandbox/dts/sandbox64.dts | 67 ++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts
index a3c95f2cdb2..e5b44264261 100644
--- a/arch/sandbox/dts/sandbox64.dts
+++ b/arch/sandbox/dts/sandbox64.dts
@@ -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;
+ };
+};
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 04/17] sandbox: Create a common sandbox DT
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (2 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 03/17] sandbox: Sync up sandbox64.dts with main DT Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 05/17] sandbox: Add an alias for SPI Simon Glass
` (13 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
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
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index a41b5f052d7..c0bdba94a73 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -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;
- };
-};
diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
new file mode 100644
index 00000000000..ebc4ece8248
--- /dev/null
+++ b/arch/sandbox/dts/sandbox.dtsi
@@ -0,0 +1,346 @@
+/*
+ * This is the common sandbox device-tree nodes. This is shared between sandbox
+ * and sandbox64 builds.
+ */
+
+#define USB_CLASS_HUB 9
+
+/ {
+ chosen {
+ stdout-path = "/serial";
+ };
+
+ audio: audio-codec {
+ compatible = "sandbox,audio-codec";
+ #sound-dai-cells = <1>;
+ };
+
+ 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 {
+ 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-controller {
+ 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 {
+ 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";
+ };
+};
+
+&cros_ec {
+ /*
+ * This describes the flash memory within the EC. Note
+ * that the STM32L flash erases to 0, not 0xff.
+ */
+ flash {
+ 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>;
+ };
+ };
+
+ keyboard-controller {
+ u-boot,dm-pre-reloc;
+ };
+};
diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts
index e5b44264261..a263f78c957 100644
--- a/arch/sandbox/dts/sandbox64.dts
+++ b/arch/sandbox/dts/sandbox64.dts
@@ -1,7 +1,5 @@
/dts-v1/;
-#define USB_CLASS_HUB 9
-
/ {
#address-cells = <2>;
#size-cells = <2>;
@@ -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 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 0 0x10000000 0 0x2000
0x01000000 0 0x20000000 0 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 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;
- };
-};
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 05/17] sandbox: Add an alias for SPI
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (3 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 04/17] sandbox: Create a common sandbox DT Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 06/17] sandbox: Exit when SYSRESET_POWER_OFF is requested Simon Glass
` (12 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/sandbox/dts/sandbox.dts | 3 ++-
arch/sandbox/dts/sandbox64.dts | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index c0bdba94a73..9a949791a0e 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -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>;
diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts
index a263f78c957..da2b4423fdc 100644
--- a/arch/sandbox/dts/sandbox64.dts
+++ b/arch/sandbox/dts/sandbox64.dts
@@ -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>;
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 06/17] sandbox: Exit when SYSRESET_POWER_OFF is requested
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (4 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 05/17] sandbox: Add an alias for SPI Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 07/17] sandbox: Quit when hang() is called Simon Glass
` (11 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
At present this returns but it seems better to just exit sandbox
immediately.
Signed-off-by: Simon Glass <sjg@chromium.org>
reset
---
arch/sandbox/cpu/state.c | 1 +
drivers/sysreset/sysreset_sandbox.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index d3b9c059859..2333240fda8 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -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));
diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c
index 38e2a7e241d..7dfd89460f0 100644
--- a/drivers/sysreset/sysreset_sandbox.c
+++ b/drivers/sysreset/sysreset_sandbox.c
@@ -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;
}
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 07/17] sandbox: Quit when hang() is called
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (5 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 06/17] sandbox: Exit when SYSRESET_POWER_OFF is requested Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 08/17] sandbox: spl: Lower priority of standard loader Simon Glass
` (10 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
lib/hang.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/hang.c b/lib/hang.c
index c5a78694be6..4d026a3e64c 100644
--- a/lib/hang.c
+++ b/lib/hang.c
@@ -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 (;;)
;
}
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 08/17] sandbox: spl: Lower priority of standard loader
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (6 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 07/17] sandbox: Quit when hang() is called Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 09/17] sandbox: Add a comment to board_init_f() Simon Glass
` (9 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/sandbox/cpu/spl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 2ca4cd6e35e..106a78ac1c1 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -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)
{
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 09/17] sandbox: Add a comment to board_init_f()
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (7 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 08/17] sandbox: spl: Lower priority of standard loader Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 10/17] sandbox: Allo sdl-config to be overridden Simon Glass
` (8 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
This function is used for both SPL and TPL. Add a comment to that effect.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/sandbox/cpu/spl.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 106a78ac1c1..4f415c71d63 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -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();
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 10/17] sandbox: Allo sdl-config to be overridden
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (8 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 09/17] sandbox: Add a comment to board_init_f() Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 11/17] sandbox: Add a memory {} node Simon Glass
` (7 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/sandbox/config.mk | 5 +++--
board/sandbox/README.sandbox | 7 +++++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 31a12db103d..05fbbd7bcc7 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -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) \
diff --git a/board/sandbox/README.sandbox b/board/sandbox/README.sandbox
index 48c1e2b9e7b..5e8fa58ba29 100644
--- a/board/sandbox/README.sandbox
+++ b/board/sandbox/README.sandbox
@@ -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
-------
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 11/17] sandbox: Add a memory {} node
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (9 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 10/17] sandbox: Allo sdl-config to be overridden Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 12/17] sandbox: Correct spi flash operation Simon Glass
` (6 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
Add a memory node which indicates the size of sandbox memory.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/sandbox/dts/sandbox.dts | 6 ++++++
arch/sandbox/dts/sandbox64.dts | 6 ++++++
include/configs/sandbox.h | 4 ++++
3 files changed, 16 insertions(+)
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 9a949791a0e..16a33db87d3 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -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;
diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts
index da2b4423fdc..37a5539ff47 100644
--- a/arch/sandbox/dts/sandbox64.dts
+++ b/arch/sandbox/dts/sandbox64.dts
@@ -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;
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index bf03baefe83..47983ced2e6 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -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
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 12/17] sandbox: Correct spi flash operation
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (10 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 11/17] sandbox: Add a memory {} node Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 13/17] sandbox: Add documentation on how to run valgrind Simon Glass
` (5 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
Since the SPI nor conversion, 'sf probe' does not work on sandbox. Fix
this by using the expected compatible string in the flash node.
Signed-off-by: Simon Glass <sjg@chromium.org>
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(-)
diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
index ebc4ece8248..2fb365d86e8 100644
--- a/arch/sandbox/dts/sandbox.dtsi
+++ b/arch/sandbox/dts/sandbox.dtsi
@@ -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";
};
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index c3a829deaec..237f4e6539e 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -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";
};
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 13/17] sandbox: Add documentation on how to run valgrind
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (11 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 12/17] sandbox: Correct spi flash operation Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 14/17] x86: Add a forward struct declaration in coreboot_tables.h Simon Glass
` (4 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
U-Boot sandbox can run with valgrind to check memory allocations. Add
documentation on how to do this.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
board/sandbox/README.sandbox | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/board/sandbox/README.sandbox b/board/sandbox/README.sandbox
index 5e8fa58ba29..c10dd444df0 100644
--- a/board/sandbox/README.sandbox
+++ b/board/sandbox/README.sandbox
@@ -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
-------
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 14/17] x86: Add a forward struct declaration in coreboot_tables.h
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (12 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 13/17] sandbox: Add documentation on how to run valgrind Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-19 7:39 ` Bin Meng
2019-05-18 17:59 ` [U-Boot] [PATCH 15/17] bootstage: Add support for TPL record count Simon Glass
` (3 subsequent siblings)
17 siblings, 1 reply; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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 <sjg@chromium.org>
---
arch/x86/include/asm/coreboot_tables.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/include/asm/coreboot_tables.h b/arch/x86/include/asm/coreboot_tables.h
index c42175b94da..2c54e24e02f 100644
--- a/arch/x86/include/asm/coreboot_tables.h
+++ b/arch/x86/include/asm/coreboot_tables.h
@@ -8,6 +8,8 @@
#ifndef _COREBOOT_TABLES_H
#define _COREBOOT_TABLES_H
+struct memory_area;
+
struct cbuint64 {
u32 lo;
u32 hi;
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 15/17] bootstage: Add support for TPL record count
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (13 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 14/17] x86: Add a forward struct declaration in coreboot_tables.h Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 16/17] blk: Allow control of the block cache in TPL Simon Glass
` (2 subsequent siblings)
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
If bootstage is enabled in TPL it lacks a record count and so does not
build. Fix this by adding a new Kconfig option.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
common/Kconfig | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig
index 1a1951f874e..cd0934fff9a 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -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
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 16/17] blk: Allow control of the block cache in TPL
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (14 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 15/17] bootstage: Add support for TPL record count Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-18 17:59 ` [U-Boot] [PATCH 17/17] spi: Avoid using malloc() in a critical function Simon Glass
2019-06-28 13:54 ` [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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().
Signed-off-by: Simon Glass <sjg@chromium.org>
---
drivers/block/Kconfig | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 33f4aa24185..1e6dad86927 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -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
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 17/17] spi: Avoid using malloc() in a critical function
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (15 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 16/17] blk: Allow control of the block cache in TPL Simon Glass
@ 2019-05-18 17:59 ` Simon Glass
2019-05-19 17:04 ` Urja Rannikko
2019-06-28 13:54 ` [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
17 siblings, 1 reply; 25+ messages in thread
From: Simon Glass @ 2019-05-18 17:59 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Simon Glass <sjg@chromium.org>
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(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index b86eee75bcb..7aabebeff5f 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -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__ */
--
2.21.0.1020.gf2820cf01a-goog
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 17/17] spi: Avoid using malloc() in a critical function
2019-05-18 17:59 ` [U-Boot] [PATCH 17/17] spi: Avoid using malloc() in a critical function Simon Glass
@ 2019-05-19 17:04 ` Urja Rannikko
2019-05-20 16:09 ` Simon Glass
0 siblings, 1 reply; 25+ messages in thread
From: Urja Rannikko @ 2019-05-19 17:04 UTC (permalink / raw)
To: u-boot
Hi,
On Sat, May 18, 2019 at 6:05 PM Simon Glass <sjg@chromium.org> wrote:
>
> 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.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> 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(-)
>
> diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> index b86eee75bcb..7aabebeff5f 100644
> --- a/drivers/spi/spi-mem.c
> +++ b/drivers/spi/spi-mem.c
> @@ -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];
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).
--
Urja Rannikko
^ permalink raw reply [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 17/17] spi: Avoid using malloc() in a critical function
2019-05-19 17:04 ` Urja Rannikko
@ 2019-05-20 16:09 ` Simon Glass
2019-05-20 16:35 ` Urja Rannikko
0 siblings, 1 reply; 25+ messages in thread
From: Simon Glass @ 2019-05-20 16:09 UTC (permalink / raw)
To: u-boot
Hi Urja,
On Sun, 19 May 2019 at 11:04, Urja Rannikko <urjaman@gmail.com> wrote:
>
> Hi,
>
> On Sat, May 18, 2019 at 6:05 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > 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.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > 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(-)
> >
> > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
> > index b86eee75bcb..7aabebeff5f 100644
> > --- a/drivers/spi/spi-mem.c
> > +++ b/drivers/spi/spi-mem.c
> > @@ -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];
>
> 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).
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
^ permalink raw reply [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 17/17] spi: Avoid using malloc() in a critical function
2019-05-20 16:09 ` Simon Glass
@ 2019-05-20 16:35 ` Urja Rannikko
2019-05-20 20:51 ` Simon Glass
0 siblings, 1 reply; 25+ messages in thread
From: Urja Rannikko @ 2019-05-20 16:35 UTC (permalink / raw)
To: u-boot
Hi Simon,
On Mon, May 20, 2019 at 7:09 PM Simon Glass <sjg@chromium.org> wrote:
>
> Hi Urja,
<snip>
> 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.
>
> 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/
> I think the stack is much better place than a fixed buffer for
> something only 8 bytes in size.
Yes.
--
Urja Rannikko
^ permalink raw reply [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 17/17] spi: Avoid using malloc() in a critical function
2019-05-20 16:35 ` Urja Rannikko
@ 2019-05-20 20:51 ` Simon Glass
0 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-05-20 20:51 UTC (permalink / raw)
To: u-boot
Hi Urja,
On Mon, 20 May 2019 at 10:36, Urja Rannikko <urjaman@gmail.com> wrote:
>
> Hi Simon,
>
> On Mon, May 20, 2019 at 7:09 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Urja,
> <snip>
> > 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.
> >
> > 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.
>
> > I think the stack is much better place than a fixed buffer for
> > something only 8 bytes in size.
> Yes.
Regards,
Simon
^ permalink raw reply [flat|nested] 25+ messages in thread
* [U-Boot] [PATCH 00/17] sandbox: Various bug fixes
2019-05-18 17:59 [U-Boot] [PATCH 00/17] sandbox: Various bug fixes Simon Glass
` (16 preceding siblings ...)
2019-05-18 17:59 ` [U-Boot] [PATCH 17/17] spi: Avoid using malloc() in a critical function Simon Glass
@ 2019-06-28 13:54 ` Simon Glass
17 siblings, 0 replies; 25+ messages in thread
From: Simon Glass @ 2019-06-28 13:54 UTC (permalink / raw)
To: u-boot
Hi,
On Sat, 18 May 2019 at 11:59, Simon Glass <sjg@chromium.org> wrote:
>
> 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
>
> --
> 2.21.0.1020.gf2820cf01a-goog
>
Series applied to u-boot-dm/next.
^ permalink raw reply [flat|nested] 25+ messages in thread