[RESEND PATCH v5 7/7] board: ti: j721s2: MAINTAINERS: Update the MAINTAINERS File.

2023-09-19 Thread Manorit Chawdhry
Update the MAINTAINERS file and propose a new MAINTAINER for j721s2 due
to the previous MAINTAINER not being associated with TI.

Reviewed-by: Nishanth Menon 
Signed-off-by: Manorit Chawdhry 
---
 board/ti/j721s2/MAINTAINERS | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/board/ti/j721s2/MAINTAINERS b/board/ti/j721s2/MAINTAINERS
index 323bd2353a7e..08c8d110ac0a 100644
--- a/board/ti/j721s2/MAINTAINERS
+++ b/board/ti/j721s2/MAINTAINERS
@@ -1,16 +1,23 @@
 J721S2 BOARD
-M: Aswath Govindraju 
+M: Manorit Chawdhry 
 S: Maintained
 F: board/ti/j721s2
+F: arch/arm/mach-k3/j721s2
+F: doc/board/ti/j721s2_evm.rst
 F: include/configs/j721s2_evm.h
 F: configs/j721s2_evm_r5_defconfig
 F: configs/j721s2_evm_a72_defconfig
 F: arch/arm/dts/k3-j721s2.dtsi
 F: arch/arm/dts/k3-j721s2-main.dtsi
 F: arch/arm/dts/k3-j721s2-mcu-wakeup.dtsi
+F: arch/arm/dts/k3-j721s2-thermal.dtsi
 F: arch/arm/dts/k3-j721s2-som-p0.dtsi
 F: arch/arm/dts/k3-j721s2-common-proc-board.dts
 F: arch/arm/dts/k3-j721s2-common-proc-board-u-boot.dtsi
-F: arch/arm/dts//k3-j721s2-r5-common-proc-board.dts
+F: arch/arm/dts/k3-j721s2-r5-common-proc-board.dts
 F: arch/arm/dts/k3-j721s2-ddr.dtsi
 F: arch/arm/dts/k3-j721s2-ddr-evm-lp4-4266.dtsi
+F: arch/arm/dts/k3-am68-sk-som.dtsi
+F: arch/arm/dts/k3-am68-sk-base-board.dts
+F: arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi
+F: arch/arm/dts/k3-am68-sk-r5-base-board.dts

-- 
2.41.0



[RESEND PATCH v5 6/7] docs: board: ti: Add j721s2_evm documentation

2023-09-19 Thread Manorit Chawdhry
Add the documentation for J721S2-EVM and SK-AM68

TRM for J721S2/AM68: https://www.ti.com/lit/pdf/spruj28
Product Page for J721S2: https://www.ti.com/tool/J721S2XSOMXEVM
Product Page for AM68: https://www.ti.com/tool/SK-AM68

Reviewed-by: Neha Malcom Francis 
Reviewed-by: Nishanth Menon 
Signed-off-by: Manorit Chawdhry 
---
 doc/board/ti/j721s2_evm.rst | 341 
 doc/board/ti/k3.rst |   1 +
 2 files changed, 342 insertions(+)

diff --git a/doc/board/ti/j721s2_evm.rst b/doc/board/ti/j721s2_evm.rst
new file mode 100644
index ..fec2acabe845
--- /dev/null
+++ b/doc/board/ti/j721s2_evm.rst
@@ -0,0 +1,341 @@
+.. SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+.. sectionauthor:: Manorit Chawdhry 
+
+J721S2 and AM68 Platforms
+=
+
+Introduction:
+-
+The J721S2 family of SoCs are part of K3 Multicore SoC architecture platform
+targeting automotive applications. They are designed as a low power, high
+performance and highly integrated device architecture, adding significant
+enhancement on processing power, graphics capability, video and imaging
+processing, virtualization and coherent memory support.
+
+The AM68 Starter Kit/Evaluation Module (EVM) is based on the J721S2 family
+of SoCs. They are designed for machine vision, traffic monitoring, retail
+automation, and factory automation.
+
+The device is partitioned into three functional domains, each containing
+specific processing cores and peripherals:
+
+1. Wake-up (WKUP) domain:
+* ARM Cortex-M4F processor, runs TI Foundational Security (TIFS)
+
+2. Microcontroller (MCU) domain:
+* Dual core ARM Cortex-R5F processor, runs device management
+  and SoC early boot
+
+3. MAIN domain:
+* Dual core 64-bit ARM Cortex-A72, runs HLOS
+
+More info can be found in TRM: https://www.ti.com/lit/pdf/spruj28
+
+Platform information:
+
+* https://www.ti.com/tool/J721S2XSOMXEVM
+* https://www.ti.com/tool/SK-AM68
+
+Boot Flow:
+--
+Below is the pictorial representation of boot flow:
+
+.. image:: img/boot_diagram_k3_current.svg
+
+- On this platform, "TI Foundational Security" (TIFS) functions as the
+  security enclave master while "Device Manager" (DM), also known as the
+  "TISCI server" in TI terminology, offers all the essential services.
+
+- As illustrated in the diagram above, R5 SPL manages power and clock
+  services independently before handing over control to "DM". The A72 or
+  the C7x (Aux core) software components request TIFS/DM to handle
+  security or device management services.
+
+Sources:
+
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_boot_sources
+:end-before: .. k3_rst_include_end_boot_sources
+
+Build procedure:
+
+0. Setup the environment variables:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_common_env_vars_desc
+:end-before: .. k3_rst_include_end_common_env_vars_desc
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_board_env_vars_desc
+:end-before: .. k3_rst_include_end_board_env_vars_desc
+
+Set the variables corresponding to this platform:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_common_env_vars_defn
+:end-before: .. k3_rst_include_end_common_env_vars_defn
+.. code-block:: bash
+
+ $ export UBOOT_CFG_CORTEXR=j721s2_evm_r5_defconfig
+ $ export UBOOT_CFG_CORTEXA=j721s2_evm_a72_defconfig
+ $ export TFA_BOARD=generic
+ $ export TFA_EXTRA_ARGS="K3_USART=0x8"
+ $ # The following is not a typo, j784s4 is the OP-TEE platform for j721s2
+ $ export OPTEE_PLATFORM=k3-j784s4
+ $ export OPTEE_EXTRA_ARGS="CFG_CONSOLE_UART=0x8"
+
+.. j721s2_evm_rst_include_start_build_steps
+
+1. Trusted Firmware-A:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_build_steps_tfa
+:end-before: .. k3_rst_include_end_build_steps_tfa
+
+
+2. OP-TEE:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_build_steps_optee
+:end-before: .. k3_rst_include_end_build_steps_optee
+
+3. U-Boot:
+
+.. _j721s2_evm_rst_u_boot_r5:
+
+* 3.1 R5:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_build_steps_spl_r5
+:end-before: .. k3_rst_include_end_build_steps_spl_r5
+
+.. _j721s2_evm_rst_u_boot_a72:
+
+* 3.2 A72:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_build_steps_uboot
+:end-before: .. k3_rst_include_end_build_steps_uboot
+.. j721s2_evm_rst_include_end_build_steps
+
+Target Images
+--
+In order to boot we need tiboot3.bin, tispl.bin and u-boot.img. Each SoC
+variant (GP, HS-FS, HS-SE) requires a different source for these files.
+
+ - GP
+
+* tiboot3-j721s2-gp-evm.bin from :ref:`step 3.1 `
+* tispl.bin_unsigned, u-boot.img_unsigned from :ref:`step 3.2 
`
+
+ - HS-FS
+
+* tiboot3-j721s2-hs-fs-evm.bin from :ref:`step 3.1 
`
+* tispl.bin, u-boot.img from :ref:`step 3.2 `
+
+ - HS-SE
+
+* tiboot3-j721s2-hs-evm.bin from :ref:`step 

[RESEND PATCH v5 5/7] k3-am68: Sync from Linux tag v6.6-rc1

2023-09-19 Thread Manorit Chawdhry
The following commit syncs the device tree from Linux tag
v6.6-rc1 to U-boot and fixes the following to be compatible with
the future syncs -

- Include k3-am68-sk-base-board.dts file

Remove the duplicated pinmuxes from r5 and -u-boot.dtsi files and
include k3-am68-sk-base-board.dts for Linux fixes to propagate
to U-boot.

- Fixing the mcu_timer0

Remove timer0 and use the mcu_timer0 defined in mcu-wakeup.dtsi

- Fixing secure proxy nodes

Linux DT now have these nodes defined so remove them and rename to
use the Linux DT ones.

- Remove cpsw node

The compatible is now fixed and the node is not required in
-u-boot specifically

- Remove aliases and chosen node

Use these from Linux and don't override when not required.

- Remove /delete-property/ from sdhci nodes

We have the necessary clock and dev data so remove these.

- Remove dummy_clocks and fs_loader0

These weren't being used anywhere so remove it.

- Remove mcu_ringacc override

All these have been put in a single commit to not break the
bisectability.

Reviewed-by: Neha Malcom Francis 
Reviewed-by: Nishanth Menon 
Signed-off-by: Manorit Chawdhry 
---
 arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi |  75 ++--
 arch/arm/dts/k3-am68-sk-base-board.dts | 524 +
 arch/arm/dts/k3-am68-sk-r5-base-board.dts  | 151 +--
 arch/arm/dts/k3-am68-sk-som.dtsi   | 112 +-
 4 files changed, 431 insertions(+), 431 deletions(-)

diff --git a/arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi 
b/arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi
index 79faa1b5737d..5dc580ee6e2f 100644
--- a/arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi
@@ -1,29 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+ * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
  */
 
 #include "k3-j721s2-binman.dtsi"
 
-/ {
-   chosen {
-   stdout-path = "serial2:115200n8";
-   tick-timer = 
-   };
-
-   aliases {
-   serial0 = _uart0;
-   serial1 = _uart0;
-   serial2 = _uart8;
-   i2c0 = _i2c0;
-   i2c1 = _i2c0;
-   i2c2 = _i2c1;
-   i2c3 = _i2c0;
-   ethernet0 = _port1;
-   mmc1 = _sdhci1;
-   };
-};
-
 _i2c0 {
bootph-pre-ram;
 };
@@ -39,14 +20,6 @@
 _mcu_wakeup {
bootph-pre-ram;
 
-   timer1: timer@4040 {
-   compatible = "ti,omap5430-timer";
-   reg = <0x0 0x4040 0x0 0x80>;
-   ti,timer-alwon;
-   clock-frequency = <25000>;
-   bootph-pre-ram;
-   };
-
chipid@4314 {
bootph-pre-ram;
};
@@ -57,12 +30,6 @@
 };
 
 _ringacc {
-   reg =   <0x0 0x2b80 0x0 0x40>,
-   <0x0 0x2b00 0x0 0x40>,
-   <0x0 0x2859 0x0 0x100>,
-   <0x0 0x2a50 0x0 0x4>,
-   <0x0 0x2844 0x0 0x4>;
-   reg-names = "rt", "fifos", "proxy_gcfg", "proxy_target", "cfg";
bootph-pre-ram;
 };
 
@@ -102,10 +69,26 @@
bootph-pre-ram;
 };
 
+_usbss0_pins_default {
+   bootph-pre-ram;
+};
+
 _pmx0 {
bootph-pre-ram;
 };
 
+_pmx1 {
+   bootph-pre-ram;
+};
+
+_pmx2 {
+   bootph-pre-ram;
+};
+
+_pmx3 {
+   bootph-pre-ram;
+};
+
 _pds {
bootph-pre-ram;
 };
@@ -130,23 +113,23 @@
bootph-pre-ram;
 };
 
-_cpsw {
-   reg = <0x0 0x4600 0x0 0x20>,
- <0x0 0x40f00200 0x0 0x8>;
-   reg-names = "cpsw_nuss", "mac_efuse";
-   /delete-property/ ranges;
+_sdhci1 {
+   bootph-pre-ram;
+};
 
-   cpsw-phy-sel@40f04040 {
-   compatible = "ti,am654-cpsw-phy-sel";
-   reg= <0x0 0x40f04040 0x0 0x4>;
-   reg-names = "gmii-sel";
-   };
+ {
+   status = "disabled";
 };
 
-_sdhci0 {
+ {
status = "disabled";
 };
 
-_sdhci1 {
+ {
+   bootph-pre-ram;
+};
+
+ {
+   dr_mode = "peripheral";
bootph-pre-ram;
 };
diff --git a/arch/arm/dts/k3-am68-sk-base-board.dts 
b/arch/arm/dts/k3-am68-sk-base-board.dts
index 8fc03324ab8a..5df5946687b3 100644
--- a/arch/arm/dts/k3-am68-sk-base-board.dts
+++ b/arch/arm/dts/k3-am68-sk-base-board.dts
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+ * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
  *
- * Base Board: **Yet to Add**
+ * Base Board: https://www.ti.com/lit/zip/SPRR463
  */
 
 /dts-v1/;
@@ -12,21 +12,28 @@
 #include 
 #include 
 
+#include "k3-serdes.h"
+
 / {
compatible = "ti,am68-sk", "ti,j721s2";
model = "Texas Instruments AM68 SK";
 
chosen {
stdout-path = "serial2:115200n8";
-   bootargs = 

[RESEND PATCH v5 4/7] k3-j721s2: Sync from Linux tag v6.6-rc1

2023-09-19 Thread Manorit Chawdhry
The following commit syncs the device tree from Linux tag
v6.6-rc1 to U-boot and fixes the following to be compatible with
the future syncs -

- Include k3-j721s2-common-proc-board.dts file

Remove the duplicated pinmuxes from r5 and -u-boot.dtsi files and
include k3-j721s2-common-proc-board.dts for Linux fixes to propagate
to U-boot.

- Fixing the mcu_timer0

Remove timer0 and use the mcu_timer0 defined in mcu-wakeup.dtsi

- Fixing secure proxy nodes

Linux DT now have these nodes defined so remove them and rename to
use the Linux DT ones.

- Remove cpsw node

The compatible is now fixed and the node is not required in
-u-boot specifically

- Remove aliases and chosen node

Use these from Linux and don't override when not required.

- Remove /delete-property/ from sdhci nodes

We have the necessary clock and dev data so remove these.

- Remove dummy_clocks and fs_loader0

These weren't being used anywhere so remove it.

- Remove mcu_ringacc override

All these have been put in a single commit to not break the
bisectability.

Reviewed-by: Neha Malcom Francis 
Reviewed-by: Nishanth Menon 
Signed-off-by: Manorit Chawdhry 
---
 .../dts/k3-j721s2-common-proc-board-u-boot.dtsi|  66 +-
 arch/arm/dts/k3-j721s2-common-proc-board.dts   | 376 ++
 arch/arm/dts/k3-j721s2-main.dtsi   | 777 -
 arch/arm/dts/k3-j721s2-mcu-wakeup.dtsi | 374 +-
 arch/arm/dts/k3-j721s2-r5-common-proc-board.dts| 158 +
 arch/arm/dts/k3-j721s2-som-p0.dtsi | 172 ++---
 arch/arm/dts/k3-j721s2-thermal.dtsi| 101 +++
 arch/arm/dts/k3-j721s2.dtsi|  12 +-
 arch/arm/dts/k3-serdes.h   | 204 ++
 9 files changed, 1794 insertions(+), 446 deletions(-)

diff --git a/arch/arm/dts/k3-j721s2-common-proc-board-u-boot.dtsi 
b/arch/arm/dts/k3-j721s2-common-proc-board-u-boot.dtsi
index f940ffee8787..a49561bc364b 100644
--- a/arch/arm/dts/k3-j721s2-common-proc-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-j721s2-common-proc-board-u-boot.dtsi
@@ -1,28 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/
+ * Copyright (C) 2021-2023 Texas Instruments Incorporated - https://www.ti.com/
  */
 
 #include "k3-j721s2-binman.dtsi"
 
-/ {
-   chosen {
-   stdout-path = "serial2:115200n8";
-   tick-timer = 
-   };
-
-   aliases {
-   serial0 = _uart0;
-   serial1 = _uart0;
-   serial2 = _uart8;
-   i2c0 = _i2c0;
-   i2c1 = _i2c0;
-   i2c2 = _i2c1;
-   i2c3 = _i2c0;
-   ethernet0 = _port1;
-   };
-};
-
 _i2c0 {
bootph-pre-ram;
 };
@@ -38,14 +20,6 @@
 _mcu_wakeup {
bootph-pre-ram;
 
-   timer1: timer@4040 {
-   compatible = "ti,omap5430-timer";
-   reg = <0x0 0x4040 0x0 0x80>;
-   ti,timer-alwon;
-   clock-frequency = <25000>;
-   bootph-pre-ram;
-   };
-
chipid@4314 {
bootph-pre-ram;
};
@@ -56,12 +30,6 @@
 };
 
 _ringacc {
-   reg =   <0x0 0x2b80 0x0 0x40>,
-   <0x0 0x2b00 0x0 0x40>,
-   <0x0 0x2859 0x0 0x100>,
-   <0x0 0x2a50 0x0 0x4>,
-   <0x0 0x2844 0x0 0x4>;
-   reg-names = "rt", "fifos", "proxy_gcfg", "proxy_target", "cfg";
bootph-pre-ram;
 };
 
@@ -101,6 +69,10 @@
bootph-pre-ram;
 };
 
+_usbss0_pins_default {
+   bootph-pre-ram;
+};
+
 _pmx0 {
bootph-pre-ram;
 };
@@ -129,23 +101,27 @@
bootph-pre-ram;
 };
 
-_cpsw {
-   reg = <0x0 0x4600 0x0 0x20>,
- <0x0 0x40f00200 0x0 0x8>;
-   reg-names = "cpsw_nuss", "mac_efuse";
-   /delete-property/ ranges;
+_sdhci0 {
+   bootph-pre-ram;
+};
 
-   cpsw-phy-sel@40f04040 {
-   compatible = "ti,am654-cpsw-phy-sel";
-   reg= <0x0 0x40f04040 0x0 0x4>;
-   reg-names = "gmii-sel";
-   };
+_sdhci1 {
+   bootph-pre-ram;
 };
 
-_sdhci0 {
+ {
+   status = "disabled";
+};
+
+ {
+   status = "disabled";
+};
+
+ {
bootph-pre-ram;
 };
 
-_sdhci1 {
+ {
+   dr_mode = "peripheral";
bootph-pre-ram;
 };
diff --git a/arch/arm/dts/k3-j721s2-common-proc-board.dts 
b/arch/arm/dts/k3-j721s2-common-proc-board.dts
index 3bba6473a3b6..c6b85bbf9a17 100644
--- a/arch/arm/dts/k3-j721s2-common-proc-board.dts
+++ b/arch/arm/dts/k3-j721s2-common-proc-board.dts
@@ -2,13 +2,17 @@
 /*
  * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/
  *
- * Link to Common Processor Board: https://www.ti.com/lit/zip/sprr439
+ * Common Processor Board: https://www.ti.com/tool/J721EXCPXEVM
  */
 
 /dts-v1/;
 
 #include "k3-j721s2-som-p0.dtsi"
 #include 
+#include 
+#include 
+
+#include 

[RESEND PATCH v5 3/7] arm: mach-k3: j721s2: Add mcu_timer0 id to the dev list

2023-09-19 Thread Manorit Chawdhry
mcu_timer0 is used by u-boot as the tick-timer. Add it to the soc
devices lsit so it an be enabled via the k3 power controller.

Reviewed-by: Neha Malcom Francis 
Reviewed-by: Nishanth Menon 
Signed-off-by: Manorit Chawdhry 
---
 arch/arm/mach-k3/j721s2/dev-data.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-k3/j721s2/dev-data.c 
b/arch/arm/mach-k3/j721s2/dev-data.c
index 8c999a3c5a8b..df70c5e5d7c0 100644
--- a/arch/arm/mach-k3/j721s2/dev-data.c
+++ b/arch/arm/mach-k3/j721s2/dev-data.c
@@ -47,6 +47,7 @@ static struct ti_lpsc soc_lpsc_list[] = {
 };
 
 static struct ti_dev soc_dev_list[] = {
+   PSC_DEV(35, _lpsc_list[0]),
PSC_DEV(108, _lpsc_list[0]),
PSC_DEV(109, _lpsc_list[0]),
PSC_DEV(110, _lpsc_list[0]),

-- 
2.41.0



[RESEND PATCH v5 2/7] Revert "arm: dts: k3-j7*: ddr: Update to 0.10 version of DDR config tool"

2023-09-19 Thread Manorit Chawdhry
The update causes instability in am68-sk boards so revert the patch in
the meantime till fix is available.

This reverts commit f1edf4bb6aa19732574ac23ca90cb9a0ba395ec1.

Signed-off-by: Manorit Chawdhry 
---
 arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi  |  98 +++---
 arch/arm/dts/k3-j721s2-ddr-evm-lp4-4266.dtsi | 464 +--
 2 files changed, 281 insertions(+), 281 deletions(-)

diff --git a/arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi 
b/arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi
index a0285ce0520e..5a6f9b11b8e3 100644
--- a/arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi
+++ b/arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi
@@ -1,9 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
- * This file was generated by the Jacinto7_DDRSS_RegConfigTool, Revision: 
0.10.0
- * This file was generated on 04/12/2023
- */
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ * This file was generated by the Jacinto7_DDRSS_RegConfigTool, Revision: 0.9.1
+ * This file was generated on 07/17/2022
+*/
 
 #define DDRSS_PLL_FHS_CNT 10
 #define DDRSS_PLL_FREQUENCY_0 2750
@@ -54,11 +54,11 @@
 #define DDRSS_CTL_41_DATA 0x1B60008B
 #define DDRSS_CTL_42_DATA 0x2000422B
 #define DDRSS_CTL_43_DATA 0x000A0A09
-#define DDRSS_CTL_44_DATA 0x040003C5
+#define DDRSS_CTL_44_DATA 0x0400078A
 #define DDRSS_CTL_45_DATA 0x1E161104
-#define DDRSS_CTL_46_DATA 0x1000922C
+#define DDRSS_CTL_46_DATA 0x10012458
 #define DDRSS_CTL_47_DATA 0x1E161110
-#define DDRSS_CTL_48_DATA 0x1000922C
+#define DDRSS_CTL_48_DATA 0x10012458
 #define DDRSS_CTL_49_DATA 0x02030410
 #define DDRSS_CTL_50_DATA 0x2C040500
 #define DDRSS_CTL_51_DATA 0x082D2C2D
@@ -71,11 +71,11 @@
 #define DDRSS_CTL_58_DATA 0x00010100
 #define DDRSS_CTL_59_DATA 0x0301
 #define DDRSS_CTL_60_DATA 0x1008
-#define DDRSS_CTL_61_DATA 0x0063
+#define DDRSS_CTL_61_DATA 0x00CE
 #define DDRSS_CTL_62_DATA 0x0256
-#define DDRSS_CTL_63_DATA 0x1035
+#define DDRSS_CTL_63_DATA 0x2073
 #define DDRSS_CTL_64_DATA 0x0256
-#define DDRSS_CTL_65_DATA 0x1035
+#define DDRSS_CTL_65_DATA 0x2073
 #define DDRSS_CTL_66_DATA 0x0005
 #define DDRSS_CTL_67_DATA 0x0004
 #define DDRSS_CTL_68_DATA 0x00950012
@@ -112,27 +112,27 @@
 #define DDRSS_CTL_99_DATA 0x
 #define DDRSS_CTL_100_DATA 0x00040005
 #define DDRSS_CTL_101_DATA 0x
-#define DDRSS_CTL_102_DATA 0x18C0
-#define DDRSS_CTL_103_DATA 0x18C0
-#define DDRSS_CTL_104_DATA 0x18C0
-#define DDRSS_CTL_105_DATA 0x18C0
-#define DDRSS_CTL_106_DATA 0x18C0
+#define DDRSS_CTL_102_DATA 0x3380
+#define DDRSS_CTL_103_DATA 0x3380
+#define DDRSS_CTL_104_DATA 0x3380
+#define DDRSS_CTL_105_DATA 0x3380
+#define DDRSS_CTL_106_DATA 0x3380
 #define DDRSS_CTL_107_DATA 0x
-#define DDRSS_CTL_108_DATA 0x02B5
-#define DDRSS_CTL_109_DATA 0x00040D40
-#define DDRSS_CTL_110_DATA 0x00040D40
-#define DDRSS_CTL_111_DATA 0x00040D40
-#define DDRSS_CTL_112_DATA 0x00040D40
-#define DDRSS_CTL_113_DATA 0x00040D40
+#define DDRSS_CTL_108_DATA 0x05A2
+#define DDRSS_CTL_109_DATA 0x00081CC0
+#define DDRSS_CTL_110_DATA 0x00081CC0
+#define DDRSS_CTL_111_DATA 0x00081CC0
+#define DDRSS_CTL_112_DATA 0x00081CC0
+#define DDRSS_CTL_113_DATA 0x00081CC0
 #define DDRSS_CTL_114_DATA 0x
-#define DDRSS_CTL_115_DATA 0x7173
-#define DDRSS_CTL_116_DATA 0x00040D40
-#define DDRSS_CTL_117_DATA 0x00040D40
-#define DDRSS_CTL_118_DATA 0x00040D40
-#define DDRSS_CTL_119_DATA 0x00040D40
-#define DDRSS_CTL_120_DATA 0x00040D40
+#define DDRSS_CTL_115_DATA 0xE325
+#define DDRSS_CTL_116_DATA 0x00081CC0
+#define DDRSS_CTL_117_DATA 0x00081CC0
+#define DDRSS_CTL_118_DATA 0x00081CC0
+#define DDRSS_CTL_119_DATA 0x00081CC0
+#define DDRSS_CTL_120_DATA 0x00081CC0
 #define DDRSS_CTL_121_DATA 0x
-#define DDRSS_CTL_122_DATA 0x7173
+#define DDRSS_CTL_122_DATA 0xE325
 #define DDRSS_CTL_123_DATA 0x
 #define DDRSS_CTL_124_DATA 0x
 #define DDRSS_CTL_125_DATA 0x
@@ -399,29 +399,29 @@
 #define DDRSS_CTL_386_DATA 0x
 #define DDRSS_CTL_387_DATA 0x3A3A1B00
 #define DDRSS_CTL_388_DATA 0x000A
-#define DDRSS_CTL_389_DATA 0x00C6
+#define DDRSS_CTL_389_DATA 0x019C
 #define DDRSS_CTL_390_DATA 0x0200
 #define DDRSS_CTL_391_DATA 0x0200
 #define DDRSS_CTL_392_DATA 0x0200
 #define DDRSS_CTL_393_DATA 0x0200
-#define DDRSS_CTL_394_DATA 0x0252
-#define DDRSS_CTL_395_DATA 0x07BC
+#define DDRSS_CTL_394_DATA 0x04D4
+#define DDRSS_CTL_395_DATA 0x1018
 #define DDRSS_CTL_396_DATA 0x0204
-#define DDRSS_CTL_397_DATA 0x206A
+#define DDRSS_CTL_397_DATA 0x40E6
 #define DDRSS_CTL_398_DATA 0x0200
 #define DDRSS_CTL_399_DATA 0x0200
 #define DDRSS_CTL_400_DATA 0x0200
 #define DDRSS_CTL_401_DATA 0x0200
-#define DDRSS_CTL_402_DATA 0x613E
-#define DDRSS_CTL_403_DATA 0x00014424
+#define DDRSS_CTL_402_DATA 0xC2B2
+#define 

[RESEND PATCH v5 1/7] configs: j721s2_evm_r5_defconfig: Increase malloc pool size in DRAM

2023-09-19 Thread Manorit Chawdhry
From: Udit Kumar 

The malloc capacity in DRAM at R5 SPL is set to 1MB which isn't
sufficient to load the new tispl.bin to
enable loading of tispl.bin the size is increased by 256KB to 1.25MB.

Cc: Nikhil M Jain 
Signed-off-by: Udit Kumar 
Reviewed-by: Nishanth Menon 
Signed-off-by: Manorit Chawdhry 
---
 configs/j721s2_evm_r5_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/j721s2_evm_r5_defconfig b/configs/j721s2_evm_r5_defconfig
index 1e66ac23d05b..e2b83b337809 100644
--- a/configs/j721s2_evm_r5_defconfig
+++ b/configs/j721s2_evm_r5_defconfig
@@ -42,6 +42,7 @@ CONFIG_SPL_SYS_REPORT_STACK_F_USAGE=y
 CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_STACK_R=y
+CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x14
 CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SYS_SPL_MALLOC=y
 CONFIG_HAS_CUSTOM_SPL_MALLOC_START=y

-- 
2.41.0



[RESEND PATCH v5 0/7] J721S2 DTS Sync from v6.6-rc1 to u-boot

2023-09-19 Thread Manorit Chawdhry
The sync tries to ensure that U-boot remains functional with the updated
Linux DTS and all the fixes from Linux move to U-boot during the sync.

The series tries to sync from Linux v6.6-rc1 along with addition of
the documentation for J721S2 that had been previously missing.

DMA fixes [0] are currently being upstreamed to Linux.

Test Logs are included in [1]

[0]: https://lore.kernel.org/all/20230810174356.3322583-1-vigne...@ti.com/
[1]: https://gist.github.com/manorit2001/dbad09fd00e8b7c3872e85874c8e648c

Signed-off-by: Manorit Chawdhry 
---
Changes in v5:
- Fix the link ( Apurva )
- Sync with v6.6-rc1
- Remove mcu_ringacc override from -u-boot.dtsi
- Added a patch revert that bring some instability in SK-AM68
- Update the commit messages to that of 6.6-rc1
- Link to v4: 
https://lore.kernel.org/r/20230816-b4-upstream-j721s2-r5-pinmux-v4-0-dc114bece...@ti.com

---
Manorit Chawdhry (6):
  Revert "arm: dts: k3-j7*: ddr: Update to 0.10 version of DDR config tool"
  arm: mach-k3: j721s2: Add mcu_timer0 id to the dev list
  k3-j721s2: Sync from Linux tag v6.6-rc1
  k3-am68: Sync from Linux tag v6.6-rc1
  docs: board: ti: Add j721s2_evm documentation
  board: ti: j721s2: MAINTAINERS: Update the MAINTAINERS File.

Udit Kumar (1):
  configs: j721s2_evm_r5_defconfig: Increase malloc pool size in DRAM

 arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi |  75 +-
 arch/arm/dts/k3-am68-sk-base-board.dts | 524 +-
 arch/arm/dts/k3-am68-sk-r5-base-board.dts  | 151 +---
 arch/arm/dts/k3-am68-sk-som.dtsi   | 112 +--
 arch/arm/dts/k3-j721e-ddr-evm-lp4-4266.dtsi|  98 +--
 .../dts/k3-j721s2-common-proc-board-u-boot.dtsi|  66 +-
 arch/arm/dts/k3-j721s2-common-proc-board.dts   | 376 ++
 arch/arm/dts/k3-j721s2-ddr-evm-lp4-4266.dtsi   | 464 ++--
 arch/arm/dts/k3-j721s2-main.dtsi   | 777 -
 arch/arm/dts/k3-j721s2-mcu-wakeup.dtsi | 374 +-
 arch/arm/dts/k3-j721s2-r5-common-proc-board.dts| 158 +
 arch/arm/dts/k3-j721s2-som-p0.dtsi | 172 ++---
 arch/arm/dts/k3-j721s2-thermal.dtsi| 101 +++
 arch/arm/dts/k3-j721s2.dtsi|  12 +-
 arch/arm/dts/k3-serdes.h   | 204 ++
 arch/arm/mach-k3/j721s2/dev-data.c |   1 +
 board/ti/j721s2/MAINTAINERS|  11 +-
 configs/j721s2_evm_r5_defconfig|   1 +
 doc/board/ti/j721s2_evm.rst| 341 +
 doc/board/ti/k3.rst|   1 +
 20 files changed, 2859 insertions(+), 1160 deletions(-)
---
base-commit: 2fe4b54556ea6271237b35de68dc458bfceab94c
change-id: 20230816-b4-upstream-j721s2-r5-pinmux-25c4cd61b258

Best regards,
-- 
Manorit Chawdhry 



Re: [PATCH] J721S2 DTS Sync from v6.6-rc1 to u-boot

2023-09-19 Thread Manorit Chawdhry
Hi Konstantin,

On 17:26-20230919, Konstantin Ryabitsev wrote:
> September 19, 2023 at 7:20 AM, "Manorit Chawdhry"  wrote:
> > Am not sure either.. I had been using b4 for all the patches and I still
> > see that my next revision queued by b4 also has the same problem. Not
> > exactly sure what went wrong with b4 but would be careful next time.
> > Thanks for pointing it out.
> 
> I'm curious how this happened as well.
> Can you please send me the output of:
> 
> b4 prep --version
> b4 prep --show-info (while in the branch that caused this problem)
> 

I believe it had been my mistake, there is a bug in b4 that I had been
trying to fix locally but forgot to cover all the cases for that. I
believe that caused it to break. The bug is basically that when you
apply patch prefix, the prefix actually wasn't behaving like a prefix [0].

I have re-spinned my local fix but if possible, please let me know if
there are any mistakes that you see in the current patch as well [1]. If
possible, I would like to upstream the fix as well as am not sure where
I can reach out to for this. Thanks for reaching out.

[0]: https://github.com/mricon/b4/issues/3
[1]: 
https://github.com/manorit2001/b4/commit/463b32ab67696daec743ba7d85e8dc4da4edb2f1

Regards,
Manorit

> -K


[PATCH v6 1/2] configs: Add support in Kconfig and convert for armada boards

2023-09-19 Thread Venkatesh Yadav Abbarapu
From: Algapally Santosh Sagar 

The DEFAULT_ENV_IS_RW is moved to the Kconfig for easier configuration.
Hence, the CONFIG_DEFAULT_ENV_IS_RW config is added to the defconfig files
to allow enabling them for armada boards.

Signed-off-by: Algapally Santosh Sagar 
Signed-off-by: Venkatesh Yadav Abbarapu 
---
 configs/eDPU_defconfig  | 1 +
 configs/mvebu_db-88f3720_defconfig  | 1 +
 configs/mvebu_espressobin-88f3720_defconfig | 1 +
 configs/uDPU_defconfig  | 1 +
 drivers/serial/Kconfig  | 6 ++
 include/configs/mvebu_armada-37xx.h | 1 -
 include/env_default.h   | 2 +-
 include/env_internal.h  | 2 +-
 8 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/configs/eDPU_defconfig b/configs/eDPU_defconfig
index 77ea2b2eec..61fb9bd2a5 100644
--- a/configs/eDPU_defconfig
+++ b/configs/eDPU_defconfig
@@ -21,6 +21,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_USE_PREBOOT=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_SYS_MAXARGS=32
diff --git a/configs/mvebu_db-88f3720_defconfig 
b/configs/mvebu_db-88f3720_defconfig
index 829567014f..e6fb80167a 100644
--- a/configs/mvebu_db-88f3720_defconfig
+++ b/configs/mvebu_db-88f3720_defconfig
@@ -22,6 +22,7 @@ CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_SYS_MAXARGS=32
diff --git a/configs/mvebu_espressobin-88f3720_defconfig 
b/configs/mvebu_espressobin-88f3720_defconfig
index fc394a7e9d..64ee99d64b 100644
--- a/configs/mvebu_espressobin-88f3720_defconfig
+++ b/configs/mvebu_espressobin-88f3720_defconfig
@@ -24,6 +24,7 @@ CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_BOARD_LATE_INIT=y
diff --git a/configs/uDPU_defconfig b/configs/uDPU_defconfig
index fa1989518b..4d3d53ac7e 100644
--- a/configs/uDPU_defconfig
+++ b/configs/uDPU_defconfig
@@ -21,6 +21,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_USE_PREBOOT=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_DEFAULT_ENV_IS_RW=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_SYS_MAXARGS=32
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 8c54bc9c47..4d27034c3f 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -24,6 +24,12 @@ config BAUDRATE
  in the SPL stage (most drivers) or for choosing a default baudrate
  in the absence of an environment setting (serial_mxc.c).
 
+config DEFAULT_ENV_IS_RW
+   bool "Make default environment as writable"
+   help
+ Select this to enable to make default environment writable. This
+ allows modifying the default environment.
+
 config REQUIRE_SERIAL_CONSOLE
bool "Require a serial port for console"
# Running without a serial console is not supported by the
diff --git a/include/configs/mvebu_armada-37xx.h 
b/include/configs/mvebu_armada-37xx.h
index 76e148f55e..18b55be0d8 100644
--- a/include/configs/mvebu_armada-37xx.h
+++ b/include/configs/mvebu_armada-37xx.h
@@ -30,7 +30,6 @@
 /*
  * Environment
  */
-#define DEFAULT_ENV_IS_RW  /* required for configuring default 
fdtfile= */
 
 #ifdef CONFIG_MMC
 #define BOOT_TARGET_DEVICES_MMC(func, i) func(MMC, mmc, i)
diff --git a/include/env_default.h b/include/env_default.h
index b16c22d5a2..227cad7c34 100644
--- a/include/env_default.h
+++ b/include/env_default.h
@@ -21,7 +21,7 @@ env_t embedded_environment __UBOOT_ENV_SECTION__(environment) 
= {
{
 #elif defined(DEFAULT_ENV_INSTANCE_STATIC)
 static char default_environment[] = {
-#elif defined(DEFAULT_ENV_IS_RW)
+#elif defined(CONFIG_DEFAULT_ENV_IS_RW)
 char default_environment[] = {
 #else
 const char default_environment[] = {
diff --git a/include/env_internal.h b/include/env_internal.h
index 6a69494646..fcb464263f 100644
--- a/include/env_internal.h
+++ b/include/env_internal.h
@@ -89,7 +89,7 @@ typedef struct environment_s {
 extern env_t embedded_environment;
 #endif /* ENV_IS_EMBEDDED */
 
-#ifdef DEFAULT_ENV_IS_RW
+#ifdef CONFIG_DEFAULT_ENV_IS_RW
 extern char default_environment[];
 #else
 extern const char default_environment[];
-- 
2.17.1



[PATCH v6 2/2] serial: zynqmp: Fetch baudrate from dtb and update

2023-09-19 Thread Venkatesh Yadav Abbarapu
From: Algapally Santosh Sagar 

The baudrate configured in .config is taken by default by serial. If
change of baudrate is required then the .config needs to changed and
u-boot recompilation is required or the u-boot environment needs to be
updated.

To avoid this, support is added to fetch the baudrate directly from the
device tree file and update.
The serial, prints the log with the configured baudrate in the dtb.
The commit c4df0f6f315c ("arm: mvebu: Espressobin: Set default value for
$fdtfile env variable") is taken as reference for changing the default
environment variable.

The default environment stores the default baudrate value, When default
baudrate and dtb baudrate are not same glitches are seen on the serial.
So, the environment also needs to be updated with the dtb baudrate to
avoid the glitches on the serial.

Signed-off-by: Algapally Santosh Sagar 
Signed-off-by: Venkatesh Yadav Abbarapu 
---
 doc/README.serial_dt_baud  | 41 
 drivers/core/ofnode.c  | 18 ++
 drivers/serial/Kconfig |  9 +++
 drivers/serial/serial-uclass.c | 43 ++
 include/dm/ofnode.h| 14 +--
 include/env_default.h  |  6 -
 include/serial.h   | 15 
 7 files changed, 143 insertions(+), 3 deletions(-)
 create mode 100644 doc/README.serial_dt_baud

diff --git a/doc/README.serial_dt_baud b/doc/README.serial_dt_baud
new file mode 100644
index 00..f8768d0e1b
--- /dev/null
+++ b/doc/README.serial_dt_baud
@@ -0,0 +1,41 @@
+Fetch serial baudrate from DT
+-
+
+To support fetching of baudrate from DT, the following is done:-
+
+The baudrate configured in Kconfig symbol CONFIG_BAUDRATE is taken by default 
by serial.
+If change of baudrate is required then the Kconfig symbol CONFIG_BAUDRATE 
needs to
+changed and U-Boot recompilation is required or the U-Boot environment needs 
to be updated.
+
+To avoid this, add support to fetch the baudrate directly from the device tree 
file and
+update the environment.
+
+The default environment stores the default baudrate value. When default 
baudrate and dtb
+baudrate are not same glitches are seen on the serial.
+So, the environment also needs to be updated with the dtb baudrate to avoid 
the glitches on
+the serial which is enabled by OF_SERIAL_BAUD.
+
+The Kconfig SPL_ENV_SUPPORT needs to be enabled to allow patching in SPL.
+
+The Kconfig DEFAULT_ENV_IS_RW which is enabled by OF_SERIAL_BAUD with making 
the environment
+writable.
+
+The ofnode_read_baud() function parses and fetches the baudrate value from the 
DT. This value
+is validated and updated to baudrate during serial init. Padding is added at 
the end of the
+default environment and the dt baudrate is updated with the latest value.
+
+Example:-
+
+The serial port options are of the form "pnf", where "" is the baud 
rate, "p" is parity ("n", "o", or "e"),
+"n" is number of bits, and "f" is flow control ("r" for RTS or omit it). 
Default is "115200n8".
+
+chosen {
+   bootargs = "earlycon console=ttyPS0,115200 clk_ignore_unused 
root=/dev/ram0 rw init_fatal_sh=1";
+   stdout-path = "serial0:115200n8";
+   };
+
+From the chosen node, stdout-path property is obtained as string.
+
+   stdout-path = "serial0:115200n8";
+
+The string is parsed to get the baudrate 115200. This string is converted to 
integer and updated to the environment.
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 8df16e56af..42f51ca93c 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -895,6 +895,24 @@ ofnode ofnode_get_chosen_node(const char *name)
return ofnode_path(prop);
 }
 
+int ofnode_read_baud(void)
+{
+   const char *str, *p;
+   u32 baud;
+
+   str = ofnode_read_chosen_string("stdout-path");
+   if (!str)
+   return -EINVAL;
+
+   /* Parse string serial0:115200n8 */
+   p = strchr(str, ':');
+   if (!p)
+   return -EINVAL;
+
+   baud = dectoul(p + 1, NULL);
+   return baud;
+}
+
 const void *ofnode_read_aliases_prop(const char *propname, int *sizep)
 {
ofnode node;
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 4d27034c3f..7fdf600dc5 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -24,6 +24,15 @@ config BAUDRATE
  in the SPL stage (most drivers) or for choosing a default baudrate
  in the absence of an environment setting (serial_mxc.c).
 
+config OF_SERIAL_BAUD
+   bool "Fetch serial baudrate from device tree"
+   depends on DM_SERIAL && SPL_ENV_SUPPORT
+   select DEFAULT_ENV_IS_RW
+   help
+ Select this to enable fetching and setting of the baudrate
+ configured in the DT. Replace the default baudrate with the DT
+ baudrate and also set it to the environment.
+
 config DEFAULT_ENV_IS_RW
bool "Make default environment as 

[PATCH v6 0/2] Add support to fetch baudrate from dtb

2023-09-19 Thread Venkatesh Yadav Abbarapu
In this patch series
- Add support in Kconfig and convert for armada boards
- Fetch baudrate from the dtb and update

Changes in v6:
- Changed Kconfig OF_SERIAL_DT_BAUD to OF_SERIAL_BAUD.
- Added IS_ENABLED() in place of #ifdef CONFIG_OF_SERIAL_AUD

Changes in v5:
- Adding DEFAULT_ENV_IS_RW Kconfig in missing files
- Updating DEFAULT_ENV_IS_RW to CONFIG_DEFAULT_ENV_IS_RW

Changes in v4:
- Moved SERIAL_DT_BAUD to another patch
- Added doc file for fetching serial baudrate from DT.
- Changed Kconfig SERIAL_DT_BAUD to OF_SERIAL_DT_BAUD
- Added function docs wherever required.
- Moved changes from fdtdec api to ofnode
- Changed serial_get_valid_baudrate to check_valid_baudrate
- Added function fetch_baud_from_dtb to fetch baud from DT
- Used dectoul() for parsing baudrate

Changes in v3:
- Add SERIAL_DT_BAUD to Kconfig
- Moved DEFAULT_ENV_IS_RW to Kconfig also updated armada files
- Moved filler changes from zynqmp.h to generic file env_default.h
- Removed ENV_RW_FILLER and added padding in the generic file env_default.h.
- Print baudrate parameter properly when SERIAL_DT is enabled.

Changes in v2:
- Changed to #ifdef from #if CONFIG_IS_ENABLED to enable patching in spl.
- Added SPL_ENV_SUPPORT dependency in SERIAL_DT_BAUD to allow SPL compilation.
- Moved DEFAULT_ENV_IS_RW to Kconfig also updated armada files
- Moved ENV_RW_FILLER to generic file env_default.h.
- Increased the ENV_RW_FILLER padding to support 800 baud.

Algapally Santosh Sagar (2):
  configs: Add support in Kconfig and convert for armada boards
  serial: zynqmp: Fetch baudrate from dtb and update

 configs/eDPU_defconfig  |  1 +
 configs/mvebu_db-88f3720_defconfig  |  1 +
 configs/mvebu_espressobin-88f3720_defconfig |  1 +
 configs/uDPU_defconfig  |  1 +
 doc/README.serial_dt_baud   | 41 
 drivers/core/ofnode.c   | 18 +
 drivers/serial/Kconfig  | 15 +++
 drivers/serial/serial-uclass.c  | 43 +
 include/configs/mvebu_armada-37xx.h |  1 -
 include/dm/ofnode.h | 14 ++-
 include/env_default.h   |  8 +++-
 include/env_internal.h  |  2 +-
 include/serial.h| 15 +++
 13 files changed, 155 insertions(+), 6 deletions(-)
 create mode 100644 doc/README.serial_dt_baud

-- 
2.17.1



[PATCH] pinctrl: Increase size of pinmux status buffer

2023-09-19 Thread Venkatesh Yadav Abbarapu
For Xilinx ZynqMP SOC new parameter was added and now it can
set 7 parameters for its pins. Pinmux status command will
print the status of these parameters for each pin. But
current print buffer length is only 80 characters long, increase it
to 90 to print all the parameters without truncation.

Signed-off-by: Venkatesh Yadav Abbarapu 
---
 include/dm/pinctrl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h
index e3e50afeaf..70d8cc5eca 100644
--- a/include/dm/pinctrl.h
+++ b/include/dm/pinctrl.h
@@ -7,7 +7,7 @@
 #define __PINCTRL_H
 
 #define PINNAME_SIZE   10
-#define PINMUX_SIZE80
+#define PINMUX_SIZE90
 
 /**
  * struct pinconf_param - pin config parameters
-- 
2.17.1



[PATCH v2] cmd: sf: Fix the flash_is_unlocked api size parameter

2023-09-19 Thread Venkatesh Yadav Abbarapu
When flash erase is called with size parameter, code is checking
if sectors are locked or not. But for checking, the whole device
length minus offset is used instead of actual size which should
be erased. That's why when only some sectors are locked it is
not possible to erase unlocked sectors.

The length is calculated as "length = max_chipsize - offset",
flash_is_unlocked() api is getting updated with length which is
incorrect. Fix this flash_is_unlocked() api by passing the size
parameter.

ZynqMP> sf erase 0 10
len=0x800 which is flash size
size=0x10

We need to update the size in the flash_is_unlocked() api and not
the length.

Signed-off-by: Venkatesh Yadav Abbarapu 
---
Changes in v2:
- Updated the commit description.
---
 cmd/sf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/sf.c b/cmd/sf.c
index 55bef2f769..977ffcb63c 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -366,7 +366,7 @@ static int do_spi_flash_erase(int argc, char *const argv[])
}
 
if (flash->flash_is_unlocked &&
-   !flash->flash_is_unlocked(flash, offset, len)) {
+   !flash->flash_is_unlocked(flash, offset, size)) {
printf("ERROR: flash area is locked\n");
return CMD_RET_FAILURE;
}
-- 
2.17.1



[PATCH v5 19/20] x86: doc: Split out manual booting into its own file

2023-09-19 Thread Simon Glass
Move this out of the main file since for simple users it is easier to
rely on standard boot.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Add new patch

 doc/arch/x86/index.rst   |   1 +
 doc/arch/x86/manual_boot.rst | 276 +++
 doc/arch/x86/x86.rst | 272 +-
 3 files changed, 280 insertions(+), 269 deletions(-)
 create mode 100644 doc/arch/x86/manual_boot.rst

diff --git a/doc/arch/x86/index.rst b/doc/arch/x86/index.rst
index 3dc19d603d4c..69db0a5d6489 100644
--- a/doc/arch/x86/index.rst
+++ b/doc/arch/x86/index.rst
@@ -9,3 +9,4 @@ x86
:maxdepth: 2
 
x86
+   manual_boot
diff --git a/doc/arch/x86/manual_boot.rst b/doc/arch/x86/manual_boot.rst
new file mode 100644
index ..ec069f2c3972
--- /dev/null
+++ b/doc/arch/x86/manual_boot.rst
@@ -0,0 +1,276 @@
+Booting Ubuntu Manually
+---
+
+This shows a manual approach to booting Ubuntu without standard boot or the EFI
+interface.
+
+As an example of how to set up your boot flow with U-Boot, here are
+instructions for starting Ubuntu from U-Boot. These instructions have been
+tested on Minnowboard MAX with a SATA drive but are equally applicable on
+other platforms and other media. There are really only four steps and it's a
+very simple script, but a more detailed explanation is provided here for
+completeness.
+
+Note: It is possible to set up U-Boot to boot automatically using syslinux.
+It could also use the grub.cfg file (/efi/ubuntu/grub.cfg) to obtain the
+GUID. If you figure these out, please post patches to this README.
+
+Firstly, you will need Ubuntu installed on an available disk. It should be
+possible to make U-Boot start a USB start-up disk but for now let's assume
+that you used another boot loader to install Ubuntu.
+
+Use the U-Boot command line to find the UUID of the partition you want to
+boot. For example our disk is SCSI device 0::
+
+   => part list scsi 0
+
+   Partition Map for SCSI device 0  --   Partition Type: EFI
+
+  Part Start LBA   End LBA Name
+Attributes
+Type GUID
+Partition GUID
+  10x0800  0x001007ff  ""
+attrs: 0x
+type:  c12a7328-f81f-11d2-ba4b-00a0c93ec93b
+guid:  9d02e8e4-4d59-408f-a9b0-fd497bc9291c
+  20x00100800  0x037d8fff  ""
+attrs: 0x
+type:  0fc63daf-8483-4772-8e79-3d69d8477de4
+guid:  965c59ee-1822-4326-90d2-b02446050059
+  30x037d9000  0x03ba27ff  ""
+attrs: 0x
+type:  0657fd6d-a4ab-43c4-84e5-0933c84b4f4f
+guid:  2c4282bd-1e82-4bcf-a5ff-51dedbf39f17
+  =>
+
+This shows that your SCSI disk has three partitions. The really long hex
+strings are called Globally Unique Identifiers (GUIDs). You can look up the
+'type' ones `here`_. On this disk the first partition is for EFI and is in
+VFAT format (DOS/Windows)::
+
+   => fatls scsi 0:1
+   efi/
+
+   0 file(s), 1 dir(s)
+
+
+Partition 2 is 'Linux filesystem data' so that will be our root disk. It is
+in ext2 format::
+
+   => ext2ls scsi 0:2
+  4096 .
+  4096 ..
+ 16384 lost+found
+  4096 boot
+ 12288 etc
+  4096 media
+  4096 bin
+  4096 dev
+  4096 home
+  4096 lib
+  4096 lib64
+  4096 mnt
+  4096 opt
+  4096 proc
+  4096 root
+  4096 run
+ 12288 sbin
+  4096 srv
+  4096 sys
+  4096 tmp
+  4096 usr
+  4096 var
+33 initrd.img
+30 vmlinuz
+  4096 cdrom
+33 initrd.img.old
+   =>
+
+and if you look in the /boot directory you will see the kernel::
+
+   => ext2ls scsi 0:2 /boot
+  4096 .
+  4096 ..
+  4096 efi
+  4096 grub
+3381262 System.map-3.13.0-32-generic
+1162712 abi-3.13.0-32-generic
+ 165611 config-3.13.0-32-generic
+ 176500 memtest86+.bin
+ 178176 memtest86+.elf
+ 178680 memtest86+_multiboot.bin
+5798112 vmlinuz-3.13.0-32-generic
+ 165762 config-3.13.0-58-generic
+1165129 abi-3.13.0-58-generic
+5823136 vmlinuz-3.13.0-58-generic
+   19215259 initrd.img-3.13.0-58-generic
+3391763 System.map-3.13.0-58-generic
+5825048 vmlinuz-3.13.0-58-generic.efi.signed
+   28304443 initrd.img-3.13.0-32-generic
+   =>
+
+The 'vmlinuz' files contain a packaged Linux kernel. The format is a kind of
+self-extracting compressed file mixed with some 'setup' configuration data.
+Despite its size (uncompressed it is >10MB) this only includes a basic set of
+device drivers, enough to boot on most hardware types.
+
+The 'initrd' files contain a RAM disk. This is something that can 

[PATCH v5 20/20] x86: doc: coreboot: Mention 64-bit Linux distros

2023-09-19 Thread Simon Glass
Add a little more detail as to why coreboot64 is preferred for booting
Linux distros.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Add new patch

 doc/board/coreboot/coreboot.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/board/coreboot/coreboot.rst b/doc/board/coreboot/coreboot.rst
index 3ef563b71dc9..10ef78bb5ada 100644
--- a/doc/board/coreboot/coreboot.rst
+++ b/doc/board/coreboot/coreboot.rst
@@ -82,6 +82,8 @@ build in `$CBDIR`::
   -device ahci,id=ahci \
   -device ide-hd,drive=disk,bus=ahci.0 \
 
+This allows booting and installing various distros, many of which are
+64-bit-only, so cannot work with the 32-bit 'coreboot' build.
 
 CBFS access
 ---
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 18/20] x86: doc: Update summaries and add links

2023-09-19 Thread Simon Glass
Refresh the summary information so it is more up-to-date. Add links to
the coreboot and slimbootloader docs.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Add new patch

 doc/arch/x86/x86.rst | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/doc/arch/x86/x86.rst b/doc/arch/x86/x86.rst
index ef6970b88a59..e75b5a73ffc0 100644
--- a/doc/arch/x86/x86.rst
+++ b/doc/arch/x86/x86.rst
@@ -11,9 +11,9 @@ including supported boards, build instructions, todo list, 
etc.
 Status
 --
 U-Boot supports running as a `coreboot`_ payload on x86. So far only Link
-(Chromebook Pixel) and `QEMU`_ x86 targets have been tested, but it should
-work with minimal adjustments on other x86 boards since coreboot deals with
-most of the low-level details.
+(Chromebook Pixel), Brya (Alder Lake Chromebook) and `QEMU`_ x86 targets have
+been tested, but it should work with minimal adjustments on other x86 boards
+since coreboot deals with most of the low-level details.
 
 U-Boot is a main bootloader on Intel Edison board.
 
@@ -31,12 +31,14 @@ are supported:
- Link (Chromebook Pixel)
- Minnowboard MAX
- Samus (Chromebook Pixel 2015)
+   - Coral (Apollo Lake Chromebooks circa 2017)
- QEMU x86 (32-bit & 64-bit)
 
 As for loading an OS, U-Boot supports directly booting a 32-bit or 64-bit
 Linux kernel as part of a FIT image. It also supports a compressed zImage.
 U-Boot supports loading an x86 VxWorks kernel. Please check README.vxworks
-for more details.
+for more details. Finally, U-Boot can boot Linux distributions with a UEFI
+interface.
 
 Build Instructions for U-Boot as BIOS replacement (bare mode)
 -
@@ -700,9 +702,10 @@ for details of EFI support in U-Boot.
 
 Chain-loading
 -
-U-Boot can be chain-loaded from another bootloader, such as coreboot or
-Slim Bootloader. Typically this is done by building for targets 'coreboot' or
-'slimbootloader'.
+U-Boot can be chain-loaded from another bootloader, such as
+:doc:`../../board/coreboot/index` coreboot or
+:doc:`../../board/intel/slimbootloader`. Typically this is done by building for
+targets 'coreboot' or 'slimbootloader'.
 
 For example, at present we have a 'coreboot' target but this runs very
 different code from the bare-metal targets, such as coral. There is very little
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 17/20] x86: doc: Move into its own directory

2023-09-19 Thread Simon Glass
There is enough material that it makes sense to split this up into
several files. Create an x86/ directory for this purpose.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Add new patch

 doc/arch/index.rst |  2 +-
 doc/arch/x86/index.rst | 11 +++
 doc/arch/{ => x86}/x86.rst |  6 +++---
 3 files changed, 15 insertions(+), 4 deletions(-)
 create mode 100644 doc/arch/x86/index.rst
 rename doc/arch/{ => x86}/x86.rst (99%)

diff --git a/doc/arch/index.rst b/doc/arch/index.rst
index 2f916f4026c5..60c93b3b6640 100644
--- a/doc/arch/index.rst
+++ b/doc/arch/index.rst
@@ -15,5 +15,5 @@ Architecture-specific doc
riscv
sandbox/index
sh
-   x86
+   x86/index
xtensa
diff --git a/doc/arch/x86/index.rst b/doc/arch/x86/index.rst
new file mode 100644
index ..3dc19d603d4c
--- /dev/null
+++ b/doc/arch/x86/index.rst
@@ -0,0 +1,11 @@
+.. SPDX-License-Identifier: GPL-2.0+ */
+.. Copyright 2023 Google LLC
+.. sectionauthor:: Simon Glass 
+
+x86
+===
+
+.. toctree::
+   :maxdepth: 2
+
+   x86
diff --git a/doc/arch/x86.rst b/doc/arch/x86/x86.rst
similarity index 99%
rename from doc/arch/x86.rst
rename to doc/arch/x86/x86.rst
index 725a1ae58639..ef6970b88a59 100644
--- a/doc/arch/x86.rst
+++ b/doc/arch/x86/x86.rst
@@ -695,8 +695,8 @@ to load a 'u-boot-payload.efi', see below test logs on QEMU.
   No controllers found
   Hit any key to stop autoboot:  0
 
-See :doc:`../develop/uefi/u-boot_on_efi` and :doc:`../develop/uefi/uefi` for
-details of EFI support in U-Boot.
+See :doc:`../../develop/uefi/u-boot_on_efi` and :doc:`../../develop/uefi/uefi`
+for details of EFI support in U-Boot.
 
 Chain-loading
 -
@@ -732,7 +732,7 @@ SMBIOS tables
 To generate SMBIOS tables in U-Boot, for use by the OS, enable the
 CONFIG_GENERATE_SMBIOS_TABLE option. The easiest way to provide the values to
 use is via the device tree. For details see
-:download:`smbios.txt <../device-tree-bindings/sysinfo/smbios.txt>`.
+:download:`smbios.txt <../../device-tree-bindings/sysinfo/smbios.txt>`.
 
 TODO List
 -
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 16/20] x86: coreboot: Record the position of the SMBIOS tables

2023-09-19 Thread Simon Glass
Make a note of where coreboot installed the SMBIOS tables so that we can
pass this on to EFI.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Add new patch

 arch/x86/lib/coreboot/cb_sysinfo.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/lib/coreboot/cb_sysinfo.c 
b/arch/x86/lib/coreboot/cb_sysinfo.c
index dfbc80c430e1..f7fd9ea5bcbb 100644
--- a/arch/x86/lib/coreboot/cb_sysinfo.c
+++ b/arch/x86/lib/coreboot/cb_sysinfo.c
@@ -471,6 +471,7 @@ int get_coreboot_info(struct sysinfo_t *info)
return -ENOENT;
gd->arch.coreboot_table = addr;
gd_set_acpi_start(map_to_sysmem(info->rsdp));
+   gd_set_smbios_start(info->smbios_start);
gd->flags |= GD_FLG_SKIP_LL_INIT;
 
return 0;
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 15/20] efi: Use the installed SMBIOS tables

2023-09-19 Thread Simon Glass
U-Boot should set up the SMBIOS tables during startup, as it does on x86.
Ensure that it does this correctly on non-x86 machines too, by creating
an event spy for last-stage init.

Tidy up the installation-condition code while we are here.

Signed-off-by: Simon Glass 
---

(no changes since v4)

Changes in v4:
- Rewrite this to use events instead

Changes in v3:
- Use log_debug() to show the message
- Squash in the next patch

Changes in v2:
- Add new patch

 lib/Kconfig  |  1 +
 lib/efi_loader/Makefile  |  2 +-
 lib/efi_loader/efi_setup.c   | 10 ++---
 lib/efi_loader/efi_smbios.c  | 72 
 test/py/tests/test_event_dump.py |  1 +
 5 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/lib/Kconfig b/lib/Kconfig
index 6b5389f3a87d..79cf9ef0fa31 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -1049,6 +1049,7 @@ config SMBIOS
bool "SMBIOS support"
depends on X86 || EFI_LOADER
default y
+   select LAST_STAGE_INIT
help
  Indicates that this platform can support System Management BIOS
  (SMBIOS) tables. These provide various pieces of information about
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 0eb748ff1a59..8d31fc61c601 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -79,7 +79,7 @@ obj-$(CONFIG_VIDEO) += efi_gop.o
 obj-$(CONFIG_BLK) += efi_disk.o
 obj-$(CONFIG_NETDEVICES) += efi_net.o
 obj-$(CONFIG_ACPI) += efi_acpi.o
-obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
+obj-$(CONFIG_SMBIOS) += efi_smbios.o
 obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
 obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o
 obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_riscv.o
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index ad719afd6328..e6de685e8795 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -326,11 +326,11 @@ efi_status_t efi_init_obj_list(void)
if (ret != EFI_SUCCESS)
goto out;
}
-#ifdef CONFIG_GENERATE_SMBIOS_TABLE
-   ret = efi_smbios_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-#endif
+   if (IS_ENABLED(CONFIG_SMBIOS)) {
+   ret = efi_smbios_register();
+   if (ret != EFI_SUCCESS)
+   goto out;
+   }
ret = efi_watchdog_register();
if (ret != EFI_SUCCESS)
goto out;
diff --git a/lib/efi_loader/efi_smbios.c b/lib/efi_loader/efi_smbios.c
index 306c0bc54f90..48446f654d9b 100644
--- a/lib/efi_loader/efi_smbios.c
+++ b/lib/efi_loader/efi_smbios.c
@@ -10,8 +10,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
+
+enum {
+   TABLE_SIZE  = SZ_4K,
+};
 
 /*
  * Install the SMBIOS table as a configuration table.
@@ -20,36 +26,50 @@
  */
 efi_status_t efi_smbios_register(void)
 {
-   /* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
-   u64 dmi_addr = U32_MAX;
+   ulong addr;
efi_status_t ret;
-   void *dmi;
 
-   /* Reserve 4kiB page for SMBIOS */
-   ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
-EFI_RUNTIME_SERVICES_DATA, 1, _addr);
+   addr = gd->arch.smbios_start;
+   if (!addr) {
+   log_err("No SMBIOS tables to install\n");
+   return EFI_NOT_FOUND;
+   }
+
+   /* Mark space used for tables */
+   ret = efi_add_memory_map(addr, TABLE_SIZE, EFI_RUNTIME_SERVICES_DATA);
+   if (ret)
+   return ret;
+
+   log_debug("EFI using SMBIOS tables at %lx\n", addr);
+
+   /* Install SMBIOS information as configuration table */
+   return efi_install_configuration_table(_guid,
+  map_sysmem(addr, 0));
+}
+
+static int install_smbios_table(void)
+{
+   ulong addr;
+   void *buf;
 
-   if (ret != EFI_SUCCESS) {
-   /* Could not find space in lowmem, use highmem instead */
-   ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
-EFI_RUNTIME_SERVICES_DATA, 1,
-_addr);
+   if (!IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE) || IS_ENABLED(CONFIG_X86))
+   return 0;
 
-   if (ret != EFI_SUCCESS)
-   return ret;
+   /* Align the table to a 4KB boundary to keep EFI happy */
+   buf = memalign(SZ_4K, TABLE_SIZE);
+   if (!buf)
+   return log_msg_ret("mem", -ENOMEM);
+
+   addr = map_to_sysmem(buf);
+   if (!write_smbios_table(addr)) {
+   log_err("Failed to write SMBIOS table\n");
+   return log_msg_ret("smbios", -EINVAL);
}
 
-   /*
-* Generate SMBIOS tables - we know that efi_allocate_pages() returns
-* a 4k-aligned address, so it is safe to assume that
-* write_smbios_table() will write the 

[PATCH v5 14/20] Record the position of the SMBIOS tables

2023-09-19 Thread Simon Glass
Remember where these end up so that we can pass this information on to
the EFI layer.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v4)

Changes in v4:
- Fix arm and riscv

Changes in v2:
- Add new patch

 arch/arm/include/asm/global_data.h | 3 +++
 arch/riscv/include/asm/global_data.h   | 3 +++
 arch/sandbox/include/asm/global_data.h | 1 +
 arch/x86/include/asm/global_data.h | 1 +
 arch/x86/lib/tables.c  | 3 +++
 include/asm-generic/global_data.h  | 8 
 6 files changed, 19 insertions(+)

diff --git a/arch/arm/include/asm/global_data.h 
b/arch/arm/include/asm/global_data.h
index 2a222c53882a..b385bae02669 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -102,6 +102,9 @@ struct arch_global_data {
 #ifdef CONFIG_ARCH_IMX8ULP
bool m33_handshake_done;
 #endif
+#ifdef CONFIG_SMBIOS
+   ulong smbios_start; /* Start address of SMBIOS table */
+#endif
 };
 
 #include 
diff --git a/arch/riscv/include/asm/global_data.h 
b/arch/riscv/include/asm/global_data.h
index 9d97517e124c..937fa4d15446 100644
--- a/arch/riscv/include/asm/global_data.h
+++ b/arch/riscv/include/asm/global_data.h
@@ -32,6 +32,9 @@ struct arch_global_data {
ulong available_harts;
 #endif
 #endif
+#ifdef CONFIG_SMBIOS
+   ulong smbios_start; /* Start address of SMBIOS table */
+#endif
 };
 
 #include 
diff --git a/arch/sandbox/include/asm/global_data.h 
b/arch/sandbox/include/asm/global_data.h
index f0ab3ba5c146..c6977735029d 100644
--- a/arch/sandbox/include/asm/global_data.h
+++ b/arch/sandbox/include/asm/global_data.h
@@ -17,6 +17,7 @@ struct arch_global_data {
ulong table_end;/* End address of x86 tables */
ulong table_start_high; /* Start address of high x86 tables */
ulong table_end_high;   /* End address of high x86 tables */
+   ulong smbios_start; /* Start address of SMBIOS table */
 };
 
 #include 
diff --git a/arch/x86/include/asm/global_data.h 
b/arch/x86/include/asm/global_data.h
index ea58259ad774..6f4a7130f1da 100644
--- a/arch/x86/include/asm/global_data.h
+++ b/arch/x86/include/asm/global_data.h
@@ -127,6 +127,7 @@ struct arch_global_data {
ulong table_end;/* End address of x86 tables */
ulong table_start_high; /* Start address of high x86 tables */
ulong table_end_high;   /* End address of high x86 tables */
+   ulong smbios_start; /* Start address of SMBIOS table */
 };
 
 #endif
diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c
index 67bc0a72aebc..5b5070f7ca57 100644
--- a/arch/x86/lib/tables.c
+++ b/arch/x86/lib/tables.c
@@ -97,6 +97,9 @@ int write_tables(void)
int size = table->size ? : CONFIG_ROM_TABLE_SIZE;
u32 rom_table_end;
 
+   if (!strcmp("smbios", table->name))
+   gd->arch.smbios_start = rom_addr;
+
if (IS_ENABLED(CONFIG_BLOBLIST_TABLES) && table->tag) {
if (!gd->arch.table_end)
gd->arch.table_end = rom_addr;
diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index 8fc205ded1a3..3421daea3632 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -552,6 +552,14 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
 #define gd_set_acpi_start(addr)
 #endif
 
+#ifdef CONFIG_SMBIOS
+#define gd_smbios_start()  gd->smbios_start
+#define gd_set_smbios_start(addr)  gd->arch.smbios_start = addr
+#else
+#define gd_smbios_start()  0UL
+#define gd_set_smbios_start(addr)
+#endif
+
 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
 #define gd_multi_dtb_fit() gd->multi_dtb_fit
 #define gd_set_multi_dtb_fit(_dtb) gd->multi_dtb_fit = _dtb
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 13/20] bootstd: Keep track of use of usb stop

2023-09-19 Thread Simon Glass
When 'usb stop' is run, doing 'bootflow scan' does not run the USB hunter
again so does not see any devices. Fix this by telling bootstd about the
state of USB.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/bootdev-uclass.c | 27 +++
 drivers/usb/host/usb-uclass.c |  8 
 include/bootdev.h |  9 +
 3 files changed, 44 insertions(+)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 69506e3865fc..974ddee5d2fa 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -830,6 +830,33 @@ int bootdev_hunt(const char *spec, bool show)
return result;
 }
 
+int bootdev_unhunt(enum uclass_id id)
+{
+   struct bootdev_hunter *start;
+   int n_ent, i;
+
+   start = ll_entry_start(struct bootdev_hunter, bootdev_hunter);
+   n_ent = ll_entry_count(struct bootdev_hunter, bootdev_hunter);
+   for (i = 0; i < n_ent; i++) {
+   struct bootdev_hunter *info = start + i;
+
+   if (info->uclass == id) {
+   struct bootstd_priv *std;
+   int ret;
+
+   ret = bootstd_get_priv();
+   if (ret)
+   return log_msg_ret("std", ret);
+   if (!(std->hunters_used & BIT(i)))
+   return -EALREADY;
+   std->hunters_used &= ~BIT(i);
+   return 0;
+   }
+   }
+
+   return -ENOENT;
+}
+
 int bootdev_hunt_prio(enum bootdev_prio_t prio, bool show)
 {
struct bootdev_hunter *start;
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
index e5fe949f254c..27e172a4fe5b 100644
--- a/drivers/usb/host/usb-uclass.c
+++ b/drivers/usb/host/usb-uclass.c
@@ -9,6 +9,7 @@
 #define LOG_CATEGORY UCLASS_USB
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -208,6 +209,13 @@ int usb_stop(void)
 #ifdef CONFIG_USB_STORAGE
usb_stor_reset();
 #endif
+   if (IS_ENABLED(CONFIG_BOOTSTD)) {
+   int ret;
+
+   ret = bootdev_unhunt(UCLASS_USB);
+   if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && ret && ret != -EALREADY)
+   printf("failed to unhunt USB (err=%dE)\n", ret);
+   }
uc_priv->companion_device_count = 0;
usb_started = 0;
 
diff --git a/include/bootdev.h b/include/bootdev.h
index 848233187f87..b079a91b5b7f 100644
--- a/include/bootdev.h
+++ b/include/bootdev.h
@@ -320,6 +320,15 @@ int bootdev_hunt(const char *spec, bool show);
  */
 int bootdev_hunt_prio(enum bootdev_prio_t prio, bool show);
 
+/**
+ * bootdev_unhunt() - Mark a device as needing to be hunted again
+ *
+ * @id: uclass ID to update
+ * Return: 0 if done, -EALREADY if already in this state, -ENOENT if no hunter
+ * found for that uclass
+ */
+int bootdev_unhunt(enum uclass_id id);
+
 /**
  * bootdev_hunt_and_find_by_label() - Hunt for bootdevs by label
  *
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 12/20] x86: smbios: Add a Kconfig indicating SMBIOS-table presence

2023-09-19 Thread Simon Glass
When booted from coreboot, U-Boot does not build the SMBIOS tables, but
it should still pass them on to the OS. Add a new option which indicates
whether SMBIOS tables are present, however they were built.

Flip the ordering so that the dependency is listed first, which is less
confusing.

Adjust GENERATE_SMBIOS_TABLE to depend on this new symbol.

Signed-off-by: Simon Glass 
Reviewed-by: Heinrich Schuchardt 
Reviewed-by: Bin Meng 
---

(no changes since v3)

Changes in v3:
- Allow SMBIOS if EFI_LOADER is enabled
- Reword the help

Changes in v2:
- Add new patch

 lib/Kconfig | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/Kconfig b/lib/Kconfig
index 7edaeebfdaf5..6b5389f3a87d 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -975,8 +975,8 @@ config BLOBLIST_TABLES
 
 config GENERATE_SMBIOS_TABLE
bool "Generate an SMBIOS (System Management BIOS) table"
+   depends on SMBIOS
default y
-   depends on X86 || EFI_LOADER
help
  The System Management BIOS (SMBIOS) specification addresses how
  motherboard and system vendors present management information about
@@ -1045,6 +1045,19 @@ config SPL_OID_REGISTRY
  unambiguous persistent name 
(https://en.wikipedia.org/wiki/Object_identifier).
  Enable fast lookup object identifier registry in the SPL.
 
+config SMBIOS
+   bool "SMBIOS support"
+   depends on X86 || EFI_LOADER
+   default y
+   help
+ Indicates that this platform can support System Management BIOS
+ (SMBIOS) tables. These provide various pieces of information about
+ the board, such as the manufacturer and the model name.
+
+ See GENERATE_SMBIOS_TABLE which controls whether U-Boot actually
+ creates these tables, rather than them coming from a previous firmware
+ stage.
+
 config SMBIOS_PARSER
bool "SMBIOS parser"
help
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 11/20] efi: x86: Correct the condition for installing ACPI tables

2023-09-19 Thread Simon Glass
It is not always the case that U-Boot builds the ACPI tables itself. For
example, when booting from coreboot, the ACPI tables are built by
coreboot.

Correct the Makefile condition so that U-Boot can pass on tables built
by a previous firmware stage.

Tidy up the installation-condition code while we are here.

Signed-off-by: Simon Glass 
Reviewed-by: Ilias Apalodimas 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Add new patch

 lib/efi_loader/Makefile|  2 +-
 lib/efi_loader/efi_setup.c | 10 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 1a8c8d7cab5c..0eb748ff1a59 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -78,7 +78,7 @@ obj-$(CONFIG_EFI_ESRT) += efi_esrt.o
 obj-$(CONFIG_VIDEO) += efi_gop.o
 obj-$(CONFIG_BLK) += efi_disk.o
 obj-$(CONFIG_NETDEVICES) += efi_net.o
-obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o
+obj-$(CONFIG_ACPI) += efi_acpi.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
 obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
 obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 58d4e1340233..ad719afd6328 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -321,11 +321,11 @@ efi_status_t efi_init_obj_list(void)
if (ret != EFI_SUCCESS)
goto out;
 #endif
-#ifdef CONFIG_GENERATE_ACPI_TABLE
-   ret = efi_acpi_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-#endif
+   if (IS_ENABLED(CONFIG_ACPI)) {
+   ret = efi_acpi_register();
+   if (ret != EFI_SUCCESS)
+   goto out;
+   }
 #ifdef CONFIG_GENERATE_SMBIOS_TABLE
ret = efi_smbios_register();
if (ret != EFI_SUCCESS)
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 10/20] x86: coreboot: Enable VIDEO_COPY

2023-09-19 Thread Simon Glass
At least on modern machines the write-back mechanism for the frame buffer
is quite slow when scrolling, since it must read the entire frame buffer
and write it back.

Enable the VIDEO_COPY feature to resolve this problem.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 arch/x86/dts/coreboot.dts|  1 +
 configs/coreboot64_defconfig |  1 +
 configs/coreboot_defconfig   |  1 +
 drivers/video/coreboot.c | 12 
 4 files changed, 15 insertions(+)

diff --git a/arch/x86/dts/coreboot.dts b/arch/x86/dts/coreboot.dts
index f9ff5346a79b..0eb31cae42c1 100644
--- a/arch/x86/dts/coreboot.dts
+++ b/arch/x86/dts/coreboot.dts
@@ -42,6 +42,7 @@
};
 
coreboot-fb {
+   bootph-some-ram;
compatible = "coreboot-fb";
};
 };
diff --git a/configs/coreboot64_defconfig b/configs/coreboot64_defconfig
index dc3548aa736c..555d281ef3cf 100644
--- a/configs/coreboot64_defconfig
+++ b/configs/coreboot64_defconfig
@@ -59,6 +59,7 @@ CONFIG_NVME_PCI=y
 CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
+CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_SPL_ACPI=y
 CONFIG_CMD_DHRYSTONE=y
diff --git a/configs/coreboot_defconfig b/configs/coreboot_defconfig
index 630eb9aa384c..edc38f1f5923 100644
--- a/configs/coreboot_defconfig
+++ b/configs/coreboot_defconfig
@@ -53,6 +53,7 @@ CONFIG_NVME_PCI=y
 CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
+CONFIG_VIDEO_COPY=y
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
diff --git a/drivers/video/coreboot.c b/drivers/video/coreboot.c
index c586475e41ed..5b718ae3e5a5 100644
--- a/drivers/video/coreboot.c
+++ b/drivers/video/coreboot.c
@@ -73,6 +73,17 @@ err:
return ret;
 }
 
+static int coreboot_video_bind(struct udevice *dev)
+{
+   struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
+
+   /* Set the maximum supported resolution */
+   uc_plat->size = 4096 * 2160 * 4;
+   log_debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
+
+   return 0;
+}
+
 static const struct udevice_id coreboot_video_ids[] = {
{ .compatible = "coreboot-fb" },
{ }
@@ -82,5 +93,6 @@ U_BOOT_DRIVER(coreboot_video) = {
.name   = "coreboot_video",
.id = UCLASS_VIDEO,
.of_match = coreboot_video_ids,
+   .bind   = coreboot_video_bind,
.probe  = coreboot_video_probe,
 };
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 09/20] x86: coreboot: Align options between coreboot and coreboot64

2023-09-19 Thread Simon Glass
These two builds are similar but have some different options for not good
reason. Line them up to be as similar as possible.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Update the malloc size too

 configs/coreboot64_defconfig | 7 +++
 configs/coreboot_defconfig   | 9 -
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/configs/coreboot64_defconfig b/configs/coreboot64_defconfig
index c04056339462..dc3548aa736c 100644
--- a/configs/coreboot64_defconfig
+++ b/configs/coreboot64_defconfig
@@ -1,5 +1,6 @@
 CONFIG_X86=y
 CONFIG_TEXT_BASE=0x112
+CONFIG_SYS_MALLOC_LEN=0x200
 CONFIG_NR_DRAM_BANKS=8
 CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="coreboot"
@@ -18,6 +19,9 @@ CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
+CONFIG_LOG=y
+CONFIG_LOGF_LINE=y
+CONFIG_LOGF_FUNC=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_NO_BSS_LIMIT=y
 CONFIG_SYS_PBSIZE=532
@@ -50,10 +54,13 @@ CONFIG_SYS_ATA_ALT_OFFSET=0
 CONFIG_ATAPI=y
 CONFIG_LBA48=y
 CONFIG_SYS_64BIT_LBA=y
+CONFIG_NVME_PCI=y
 # CONFIG_PCI_PNP is not set
 CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
 CONFIG_SPL_ACPI=y
+CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
+CONFIG_SMBIOS_PARSER=y
diff --git a/configs/coreboot_defconfig b/configs/coreboot_defconfig
index e7e45c2b0a9b..630eb9aa384c 100644
--- a/configs/coreboot_defconfig
+++ b/configs/coreboot_defconfig
@@ -24,23 +24,14 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_PCI_INIT_R=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_MMC=y
-CONFIG_CMD_PART=y
 CONFIG_CMD_SATA=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
-CONFIG_CMD_DHCP=y
 CONFIG_BOOTP_BOOTFILESIZE=y
-CONFIG_CMD_PING=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_SOUND=y
-CONFIG_CMD_EXT2=y
-CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
-CONFIG_CMD_FAT=y
-CONFIG_CMD_FS_GENERIC=y
 CONFIG_MAC_PARTITION=y
-CONFIG_ISO_PARTITION=y
-CONFIG_EFI_PARTITION=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_USE_BOOTFILE=y
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 08/20] x86: coreboot: Drop USB init on startup

2023-09-19 Thread Simon Glass
This is very annoying as it is quite slow on many machines. Also, U-Boot
has an existing 'preboot' mechanism to enable this feature if desired.

Drop this code so that it is possible to choose whether to init USB or
not.

Use the existing USE_PREBOOT mechanism instead.

Signed-off-by: Simon Glass 
---

Changes in v5:
- Make use of the uSE_PREBOOT mechanism

 arch/x86/cpu/coreboot/Kconfig| 1 +
 arch/x86/cpu/coreboot/coreboot.c | 4 
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/x86/cpu/coreboot/Kconfig b/arch/x86/cpu/coreboot/Kconfig
index b97c27790419..178f8ad18162 100644
--- a/arch/x86/cpu/coreboot/Kconfig
+++ b/arch/x86/cpu/coreboot/Kconfig
@@ -25,6 +25,7 @@ config SYS_COREBOOT
imply FS_CBFS
imply CBMEM_CONSOLE
imply X86_TSC_READ_BASE
+   imply USE_PREBOOT
select BINMAN if X86_64
 
 endif
diff --git a/arch/x86/cpu/coreboot/coreboot.c b/arch/x86/cpu/coreboot/coreboot.c
index da43d66e95d7..82fe4c71cd27 100644
--- a/arch/x86/cpu/coreboot/coreboot.c
+++ b/arch/x86/cpu/coreboot/coreboot.c
@@ -86,10 +86,6 @@ static int last_stage_init(void)
if (IS_ENABLED(CONFIG_SPL_BUILD))
return 0;
 
-   /* start usb so that usb keyboard can be used as input device */
-   if (IS_ENABLED(CONFIG_USB_KEYBOARD))
-   usb_init();
-
board_final_init();
 
return 0;
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 07/20] x86: coreboot: Enable CONFIG_SYS_NS16550_MEM32

2023-09-19 Thread Simon Glass
The debug UART on modern machines uses a 32-bit wide transfer. Without
this, setting debug output causes a hang or no output. It is not obvious
(when enabling CONFIG_DEBUG_UART) that this is needed.

Enable 32-bit access to avoid this trap.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/coreboot64_defconfig | 1 +
 configs/coreboot_defconfig   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/configs/coreboot64_defconfig b/configs/coreboot64_defconfig
index e8165961c199..c04056339462 100644
--- a/configs/coreboot64_defconfig
+++ b/configs/coreboot64_defconfig
@@ -51,6 +51,7 @@ CONFIG_ATAPI=y
 CONFIG_LBA48=y
 CONFIG_SYS_64BIT_LBA=y
 # CONFIG_PCI_PNP is not set
+CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
diff --git a/configs/coreboot_defconfig b/configs/coreboot_defconfig
index 311ca6672cbd..e7e45c2b0a9b 100644
--- a/configs/coreboot_defconfig
+++ b/configs/coreboot_defconfig
@@ -59,6 +59,7 @@ CONFIG_LBA48=y
 CONFIG_SYS_64BIT_LBA=y
 CONFIG_NVME_PCI=y
 # CONFIG_PCI_PNP is not set
+CONFIG_SYS_NS16550_MEM32=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 06/20] x86: coreboot: Look for DBG2 UART in SPL too

2023-09-19 Thread Simon Glass
If coreboot does not set up sysinfo for the UART, SPL currently hangs.
Use the DBG2 technique there as well. This allows coreboot64 to boot from
coreboot even if the console info is missing from sysinfo

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v5:
- Correct 'teechnique' typo in commit message

 configs/coreboot64_defconfig | 1 +
 drivers/serial/Kconfig   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/configs/coreboot64_defconfig b/configs/coreboot64_defconfig
index 5623197f6be2..e8165961c199 100644
--- a/configs/coreboot64_defconfig
+++ b/configs/coreboot64_defconfig
@@ -54,4 +54,5 @@ CONFIG_SYS_64BIT_LBA=y
 CONFIG_SOUND=y
 CONFIG_SOUND_I8254=y
 CONFIG_CONSOLE_SCROLL_LINES=5
+CONFIG_SPL_ACPI=y
 # CONFIG_GZIP is not set
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 7ca42df6a7e2..27b4b9d96507 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -672,7 +672,7 @@ config COREBOOT_SERIAL
 config COREBOOT_SERIAL_FROM_DBG2
bool "Obtain UART from ACPI tables"
depends on COREBOOT_SERIAL
-   default y if !SPL
+   default y
help
  Select this to try to find a DBG2 record in the ACPI tables, in the
  event that coreboot does not provide information about the UART in the
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 05/20] x86: Allow APCI in SPL

2023-09-19 Thread Simon Glass
This is needed so we can find the DBG2 table provided by coreboot. Add a
Kconfig so it can be enabled.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 lib/Kconfig | 8 
 1 file changed, 8 insertions(+)

diff --git a/lib/Kconfig b/lib/Kconfig
index eb2b10161824..7edaeebfdaf5 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -289,6 +289,14 @@ config ACPI
  not necessarily include generation of tables
  (see GENERATE_ACPI_TABLE), but allows for tables to be located.
 
+config SPL_ACPI
+   bool "Enable support for ACPI libraries in SPL"
+   depends on SPL && SUPPORT_ACPI
+   help
+ Provides library functions for dealing with ACPI tables in SPL. This
+ does not necessarily include generation of tables
+ (see GENERATE_ACPI_TABLE), but allows for tables to be located.
+
 config GENERATE_ACPI_TABLE
bool "Generate an ACPI (Advanced Configuration and Power Interface) 
table"
depends on ACPI
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 04/20] x86: Set the CPU vendor in SPL

2023-09-19 Thread Simon Glass
We don't read this information in 64-bit mode, since we don't have the
macros for doing it. Set it to Intel by default. This allows the TSC timer
to work correctly.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 arch/x86/cpu/x86_64/cpu.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c
index d1c3873dd6a7..2647bff891f8 100644
--- a/arch/x86/cpu/x86_64/cpu.c
+++ b/arch/x86/cpu/x86_64/cpu.c
@@ -8,8 +8,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int cpu_has_64bit(void)
 {
return true;
@@ -38,6 +41,10 @@ int x86_mp_init(void)
 
 int x86_cpu_reinit_f(void)
 {
+   /* set the vendor to Intel so that native_calibrate_tsc() works */
+   gd->arch.x86_vendor = X86_VENDOR_INTEL;
+   gd->arch.has_mtrr = true;
+
return 0;
 }
 
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 03/20] x86: coreboot: Rearrange arch_cpu_init()

2023-09-19 Thread Simon Glass
Init errors in SPL are currently ignored by this function.

Change the code to init the CPU, reporting an error if something is wrong.
After that, look for the coreboot table.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v5:
- Drop unwanted space

 arch/x86/cpu/coreboot/coreboot.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/cpu/coreboot/coreboot.c b/arch/x86/cpu/coreboot/coreboot.c
index 835b2c777462..da43d66e95d7 100644
--- a/arch/x86/cpu/coreboot/coreboot.c
+++ b/arch/x86/cpu/coreboot/coreboot.c
@@ -21,7 +21,14 @@
 
 int arch_cpu_init(void)
 {
-   int ret = get_coreboot_info(_sysinfo);
+   int ret;
+
+   ret = IS_ENABLED(CONFIG_X86_RUN_64BIT) ? x86_cpu_reinit_f() :
+   x86_cpu_init_f();
+   if (ret)
+   return ret;
+
+   ret = get_coreboot_info(_sysinfo);
if (ret != 0) {
printf("Failed to parse coreboot tables.\n");
return ret;
@@ -29,8 +36,7 @@ int arch_cpu_init(void)
 
timestamp_init();
 
-   return IS_ENABLED(CONFIG_X86_RUN_64BIT) ? x86_cpu_reinit_f() :
-x86_cpu_init_f();
+   return 0;
 }
 
 int checkcpu(void)
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 02/20] x86: coreboot: Enable standard boot

2023-09-19 Thread Simon Glass
Enable bootstd options and provide instructions on how to boot a linux
distro using coreboot.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v5:
- Use 'lzma' instead of 'LZMA'

 configs/coreboot64_defconfig| 14 ++
 configs/coreboot_defconfig  |  1 +
 doc/board/coreboot/coreboot.rst | 16 ++--
 3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/configs/coreboot64_defconfig b/configs/coreboot64_defconfig
index a456547a25d4..5623197f6be2 100644
--- a/configs/coreboot64_defconfig
+++ b/configs/coreboot64_defconfig
@@ -10,39 +10,29 @@ CONFIG_VENDOR_COREBOOT=y
 CONFIG_TARGET_COREBOOT=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
+CONFIG_BOOTSTD_FULL=y
+CONFIG_BOOTSTD_DEFAULTS=y
 CONFIG_SYS_MONITOR_BASE=0x0112
 CONFIG_SHOW_BOOT_PROGRESS=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="root=/dev/sdb3 init=/sbin/init rootwait ro"
-CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="ext2load scsi 0:3 0100 /boot/vmlinuz; zboot 0100"
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_NO_BSS_LIMIT=y
-CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PBSIZE=532
 CONFIG_CMD_IDE=y
 CONFIG_CMD_MMC=y
-CONFIG_CMD_PART=y
 CONFIG_CMD_SATA=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
-CONFIG_CMD_DHCP=y
 CONFIG_BOOTP_BOOTFILESIZE=y
-CONFIG_CMD_PING=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_SOUND=y
-CONFIG_CMD_EXT2=y
-CONFIG_CMD_EXT4=y
 CONFIG_CMD_EXT4_WRITE=y
-CONFIG_CMD_FAT=y
-CONFIG_CMD_FS_GENERIC=y
 CONFIG_MAC_PARTITION=y
 # CONFIG_SPL_MAC_PARTITION is not set
 # CONFIG_SPL_DOS_PARTITION is not set
-CONFIG_ISO_PARTITION=y
-CONFIG_EFI_PARTITION=y
 # CONFIG_SPL_EFI_PARTITION is not set
 CONFIG_ENV_OVERWRITE=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
diff --git a/configs/coreboot_defconfig b/configs/coreboot_defconfig
index aedad4c93c30..311ca6672cbd 100644
--- a/configs/coreboot_defconfig
+++ b/configs/coreboot_defconfig
@@ -10,6 +10,7 @@ CONFIG_TARGET_COREBOOT=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_BOOTSTD_FULL=y
+CONFIG_BOOTSTD_DEFAULTS=y
 CONFIG_SYS_MONITOR_BASE=0x0111
 CONFIG_SHOW_BOOT_PROGRESS=y
 CONFIG_USE_BOOTARGS=y
diff --git a/doc/board/coreboot/coreboot.rst b/doc/board/coreboot/coreboot.rst
index be5b0de5495e..3ef563b71dc9 100644
--- a/doc/board/coreboot/coreboot.rst
+++ b/doc/board/coreboot/coreboot.rst
@@ -67,9 +67,21 @@ To use 4GB of memory, typically necessary for booting Linux 
distros, add
 In addition to the 32-bit 'coreboot' build there is a 'coreboot64' build. This
 produces an image which can be booted from coreboot (32-bit). Internally it
 works by using a 32-bit SPL binary to switch to 64-bit for running U-Boot. It
-can be useful for running UEFI applications, for example.
+can be useful for running UEFI applications, for example with the coreboot
+build in `$CBDIR`::
+
+   DISK=ubuntu-23.04-desktop-amd64.iso
+   CBDIR=~/coreboot/build
+
+   cp $CBDIR/coreboot.rom.in coreboot.rom
+   cbfstool coreboot.rom add-flat-binary -f u-boot-x86-with-spl.bin \
+  -n fallback/payload -c lzma -l 0x111 -e 0x111
+
+   qemu-system-x86_64 -m 2G -smp 4 -bios coreboot.rom \
+  -drive id=disk,file=$DISK,if=none \
+  -device ahci,id=ahci \
+  -device ide-hd,drive=disk,bus=ahci.0 \
 
-This has only been lightly tested.
 
 CBFS access
 ---
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 01/20] x86: coreboot: Add IDE and SATA

2023-09-19 Thread Simon Glass
Add these options to permit access to more disk types.

Add some documentation as well.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 configs/coreboot64_defconfig|  1 +
 configs/coreboot_defconfig  |  9 +
 doc/board/coreboot/coreboot.rst | 20 
 3 files changed, 30 insertions(+)

diff --git a/configs/coreboot64_defconfig b/configs/coreboot64_defconfig
index 2793e2c0b9d1..a456547a25d4 100644
--- a/configs/coreboot64_defconfig
+++ b/configs/coreboot64_defconfig
@@ -25,6 +25,7 @@ CONFIG_SYS_PBSIZE=532
 CONFIG_CMD_IDE=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PART=y
+CONFIG_CMD_SATA=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_DHCP=y
diff --git a/configs/coreboot_defconfig b/configs/coreboot_defconfig
index f196ed776d0b..aedad4c93c30 100644
--- a/configs/coreboot_defconfig
+++ b/configs/coreboot_defconfig
@@ -21,8 +21,10 @@ CONFIG_LOGF_LINE=y
 CONFIG_LOGF_FUNC=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_PCI_INIT_R=y
+CONFIG_CMD_IDE=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PART=y
+CONFIG_CMD_SATA=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_DHCP=y
@@ -47,6 +49,13 @@ CONFIG_USE_ROOTPATH=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 # CONFIG_ACPIGEN is not set
+CONFIG_SYS_IDE_MAXDEVICE=4
+CONFIG_SYS_ATA_DATA_OFFSET=0
+CONFIG_SYS_ATA_REG_OFFSET=0
+CONFIG_SYS_ATA_ALT_OFFSET=0
+CONFIG_ATAPI=y
+CONFIG_LBA48=y
+CONFIG_SYS_64BIT_LBA=y
 CONFIG_NVME_PCI=y
 # CONFIG_PCI_PNP is not set
 CONFIG_SOUND=y
diff --git a/doc/board/coreboot/coreboot.rst b/doc/board/coreboot/coreboot.rst
index d660a223d9c8..be5b0de5495e 100644
--- a/doc/board/coreboot/coreboot.rst
+++ b/doc/board/coreboot/coreboot.rst
@@ -41,6 +41,26 @@ At present it seems that for Minnowboard Max, coreboot does 
not pass through
 the video information correctly (it always says the resolution is 0x0). This
 works correctly for link though.
 
+You can run via QEMU using::
+
+  qemu-system-x86_64 -bios build/coreboot.rom -serial mon:stdio
+
+The `-serial mon:stdio` part shows both output in the display and on the
+console. It is optional. You can add `nographic` as well to *only* get console
+output.
+
+To run with a SATA drive called `$DISK`::
+
+  qemu-system-x86_64 -bios build/coreboot.rom -serial mon:stdio \
+   -drive id=disk,file=$DISK,if=none \
+   -device ahci,id=ahci \
+   -device ide-hd,drive=disk,bus=ahci.0
+
+Then you can scan it with `scsi scan` and access it normally.
+
+To use 4GB of memory, typically necessary for booting Linux distros, add
+`-m 4GB`.
+
 64-bit U-Boot
 -
 
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH v5 00/20] x86: efi: Fixes and improvements for coreboot

2023-09-19 Thread Simon Glass
This little series fixes various bugs and annoyances in coreboot and
coreboot64.

With this both coreboot and coreboot64 start up and work reasonably well
on Brya (x86 Chromebook) and U-Boot can boot common Linux distros.

- Make coreboot64 debug UART start reliably
- Avoid the long USB-init delay on startup
- Correct the timer speed on coreboo64
- Fix a bootstd cros bug (will likely be squashed into another patch)
- Fix the terribly slow console scrolling

With v2 I have also brought in some lost x86 patches so they are all in
one series.

Changes in v5:
- Use 'lzma' instead of 'LZMA'
- Drop unwanted space
- Correct 'teechnique' typo in commit message
- Make use of the uSE_PREBOOT mechanism

Changes in v4:
- Fix arm and riscv
- Rewrite this to use events instead

Changes in v3:
- Allow SMBIOS if EFI_LOADER is enabled
- Reword the help
- Use log_debug() to show the message
- Squash in the next patch

Changes in v2:
- Update the malloc size too
- Add new patch
- Add new patch
- Add new patch
- Add new patch
- Add new patch
- Add new patch
- Add new patch
- Add new patch
- Add new patch

Simon Glass (20):
  x86: coreboot: Add IDE and SATA
  x86: coreboot: Enable standard boot
  x86: coreboot: Rearrange arch_cpu_init()
  x86: Set the CPU vendor in SPL
  x86: Allow APCI in SPL
  x86: coreboot: Look for DBG2 UART in SPL too
  x86: coreboot: Enable CONFIG_SYS_NS16550_MEM32
  x86: coreboot: Drop USB init on startup
  x86: coreboot: Align options between coreboot and coreboot64
  x86: coreboot: Enable VIDEO_COPY
  efi: x86: Correct the condition for installing ACPI tables
  x86: smbios: Add a Kconfig indicating SMBIOS-table presence
  bootstd: Keep track of use of usb stop
  Record the position of the SMBIOS tables
  efi: Use the installed SMBIOS tables
  x86: coreboot: Record the position of the SMBIOS tables
  x86: doc: Move into its own directory
  x86: doc: Update summaries and add links
  x86: doc: Split out manual booting into its own file
  x86: doc: coreboot: Mention 64-bit Linux distros

 arch/arm/include/asm/global_data.h |   3 +
 arch/riscv/include/asm/global_data.h   |   3 +
 arch/sandbox/include/asm/global_data.h |   1 +
 arch/x86/cpu/coreboot/Kconfig  |   1 +
 arch/x86/cpu/coreboot/coreboot.c   |  16 +-
 arch/x86/cpu/x86_64/cpu.c  |   7 +
 arch/x86/dts/coreboot.dts  |   1 +
 arch/x86/include/asm/global_data.h |   1 +
 arch/x86/lib/coreboot/cb_sysinfo.c |   1 +
 arch/x86/lib/tables.c  |   3 +
 boot/bootdev-uclass.c  |  27 +++
 configs/coreboot64_defconfig   |  25 ++-
 configs/coreboot_defconfig |  21 +-
 doc/arch/index.rst |   2 +-
 doc/arch/x86/index.rst |  12 +
 doc/arch/x86/manual_boot.rst   | 276 +++
 doc/arch/{ => x86}/x86.rst | 295 ++---
 doc/board/coreboot/coreboot.rst|  38 +++-
 drivers/serial/Kconfig |   2 +-
 drivers/usb/host/usb-uclass.c  |   8 +
 drivers/video/coreboot.c   |  12 +
 include/asm-generic/global_data.h  |   8 +
 include/bootdev.h  |   9 +
 lib/Kconfig|  24 +-
 lib/efi_loader/Makefile|   4 +-
 lib/efi_loader/efi_setup.c |  20 +-
 lib/efi_loader/efi_smbios.c|  72 +++---
 test/py/tests/test_event_dump.py   |   1 +
 28 files changed, 543 insertions(+), 350 deletions(-)
 create mode 100644 doc/arch/x86/index.rst
 create mode 100644 doc/arch/x86/manual_boot.rst
 rename doc/arch/{ => x86}/x86.rst (64%)

-- 
2.42.0.459.ge4e396fd5e-goog



Re: [PATCH v4 2/2] x86: Update cbmem driver

2023-09-19 Thread Simon Glass
Hi Bin,

On Tue, 19 Sept 2023 at 02:47, Bin Meng  wrote:
>
> Hi Simon,
>
> On Mon, Sep 11, 2023 at 3:13 AM Simon Glass  wrote:
> >
> > This driver is not actually built since a Kconfig was never created for
> > it.
> >
> > Add a Kconfig (which is already implied by COREBOOT) and update the
> > implementation to avoid using unnecessary memory. Drop the #ifdef at the
> > top since we can rely on Kconfig to get that right.
> >
> > To enable it (in addition to serial and video), use:
> >
> >setenv stdout serial,vidconsole,cbmem
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v4:
> > - Add some comments to help understand the overflow mechanism
> >
> > Changes in v2:
> > - Update to support the new overflow mechanism
> >
> >  drivers/misc/Kconfig |  8 +++
> >  drivers/misc/cbmem_console.c | 43 ++--
> >  2 files changed, 34 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > index a6e3f62ecb09..c930e4a361bf 100644
> > --- a/drivers/misc/Kconfig
> > +++ b/drivers/misc/Kconfig
> > @@ -122,6 +122,14 @@ config VEXPRESS_CONFIG
> >   configuration bus on the Arm Versatile Express boards via
> >   a sysreg driver.
> >
> > +config CBMEM_CONSOLE
> > +   bool "Write console output to coreboot cbmem"
> > +   depends on X86
> > +   help
> > + Enables console output to the cbmem console, which is a memory
> > + region set up by coreboot to hold a record of all console output.
> > + Enable this only if booting from coreboot.
> > +
> >  config CMD_CROS_EC
> > bool "Enable crosec command"
> > depends on CROS_EC
> > diff --git a/drivers/misc/cbmem_console.c b/drivers/misc/cbmem_console.c
> > index 8bbe33d414da..3cbe9fb1a46a 100644
> > --- a/drivers/misc/cbmem_console.c
> > +++ b/drivers/misc/cbmem_console.c
> > @@ -5,27 +5,37 @@
> >
> >  #include 
> >  #include 
> > -#ifndef CONFIG_SYS_COREBOOT
> > -#error This driver requires coreboot
> > -#endif
> > -
> >  #include 
> >
> > -struct cbmem_console {
> > -   u32 buffer_size;
> > -   u32 buffer_cursor;
> > -   u8  buffer_body[0];
> > -}  __attribute__ ((__packed__));
> > -
> > -static struct cbmem_console *cbmem_console_p;
> > -
> >  void cbmemc_putc(struct stdio_dev *dev, char data)
> >  {
> > -   int cursor;
> > +   const struct sysinfo_t *sysinfo = cb_get_sysinfo();
> > +   struct cbmem_console *cons;
> > +   uint pos, flags;
> > +
> > +   if (!sysinfo)
> > +   return;
> > +   cons = sysinfo->cbmem_cons;
> > +   if (!cons)
> > +   return;
> > +
> > +   pos = cons->cursor & CBMC_CURSOR_MASK;
> > +
> > +   /* preserve the overflow flag if present */
> > +   flags = cons->cursor & ~CBMC_CURSOR_MASK;
> > +
> > +   cons->body[pos++] = data;
> > +
> > +   /*
> > +* Deal with overflow - the flag may be cleared by another program 
> > which
> > +* reads the buffer out, e.g. Linux
> > +*/
>
> U-Boot is not memory resident, so this does not sound like a correct
> overflow mechanism to me.

I am not sure what you mean. This logic is used in coreboot and some
payloads, so I want to do the same in U-Boot. It basically let's
U-Boot handle an overflow properly by setting the overflow flag. A
later program (e.g. Linux) can then tell that that an overflow
occurred.


>
> > +   if (pos >= cons->size) {
> > +   pos = 0;
> > +   flags |= CBMC_OVERFLOW;
> > +   }
> >
> > -   cursor = cbmem_console_p->buffer_cursor++;
> > -   if (cursor < cbmem_console_p->buffer_size)
> > -   cbmem_console_p->buffer_body[cursor] = data;
> > +   cons->cursor = flags | pos;
> >  }
> >
> >  void cbmemc_puts(struct stdio_dev *dev, const char *str)
> > @@ -40,7 +50,6 @@ int cbmemc_init(void)
> >  {
> > int rc;
> > struct stdio_dev cons_dev;
> > -   cbmem_console_p = lib_sysinfo.cbmem_cons;
> >
> > memset(_dev, 0, sizeof(cons_dev));
> >
>

Regards,
Simon


Re: [PATCH v4 07/20] x86: coreboot: Enable CONFIG_SYS_NS16550_MEM32

2023-09-19 Thread Simon Glass
Hi Bin,

On Tue, 19 Sept 2023 at 01:19, Bin Meng  wrote:
>
> Hi Simon,
>
> On Thu, Aug 24, 2023 at 5:11 AM Simon Glass  wrote:
> >
> > The debug UART on modern machines uses a 32-bit wide transfer. Without
> > this, setting debug output causes a hang or no output. It is not obvious
> > (when enabling CONFIG_DEBUG_UART) that this is needed.
> >
> > Enable 32-bit access to avoid this trap.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > (no changes since v1)
> >
> >  configs/coreboot64_defconfig | 1 +
> >  configs/coreboot_defconfig   | 1 +
> >  2 files changed, 2 insertions(+)
> >
>
> Can we use CONFIG_NS16550_DYNAMIC?

We do actually use this for coreboot.

>
> Hardcode CONFIG_SYS_NS16550_MEM32 in the defconfig just works for one
> configuration like yours, but it fails on some other configurations,
> e.g.: IO port based ns16550.

This is for the debug UART which does not support CONFIG_NS16550_DYNAMIC

Regards,
Simon


Re: [PATCH v4 08/20] x86: coreboot: Drop USB init on startup

2023-09-19 Thread Simon Glass
Hi Bin,

On Tue, 19 Sept 2023 at 01:19, Bin Meng  wrote:
>
> Hi Simon,
>
> On Thu, Aug 24, 2023 at 5:11 AM Simon Glass  wrote:
> >
> > This is very annoying as it is quite slow on many machines. Also, U-Boot
> > has an existing 'preboot' mechanism to enable this feature if desired.
> >
> > Drop this code so that it is possible to choose whether to init USB or
> > not.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > (no changes since v1)
> >
> >  arch/x86/cpu/coreboot/coreboot.c | 4 
> >  1 file changed, 4 deletions(-)
> >
> > diff --git a/arch/x86/cpu/coreboot/coreboot.c 
> > b/arch/x86/cpu/coreboot/coreboot.c
> > index c2ceaa9a56c..567f1ab116c 100644
> > --- a/arch/x86/cpu/coreboot/coreboot.c
> > +++ b/arch/x86/cpu/coreboot/coreboot.c
> > @@ -86,10 +86,6 @@ static int last_stage_init(void)
> > if (IS_ENABLED(CONFIG_SPL_BUILD))
> > return 0;
> >
> > -   /* start usb so that usb keyboard can be used as input device */
> > -   if (IS_ENABLED(CONFIG_USB_KEYBOARD))
> > -   usb_init();
>
> Dropping this causes USB keyboards to fail to be usable as the U-Boot
> input device.

OK I will enable the normal USE_PREBOOT mechanism in v5


>
> > -
> > board_final_init();
> >
> > return 0;
> > --
Regards,
Simon


Re: [PATCH v4 16/20] x86: coreboot: Record the position of the SMBIOS tables

2023-09-19 Thread Simon Glass
Hi Bin,

On Tue, 19 Sept 2023 at 01:20, Bin Meng  wrote:
>
> On Thu, Aug 24, 2023 at 5:11 AM Simon Glass  wrote:
> >
> > Make a note of where coreboot installed the SMBIOS tables so that we can
> > pass this on to EFI.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > (no changes since v2)
> >
> > Changes in v2:
> > - Add new patch
> >
> >  arch/x86/lib/coreboot/cb_sysinfo.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/x86/lib/coreboot/cb_sysinfo.c 
> > b/arch/x86/lib/coreboot/cb_sysinfo.c
> > index dfbc80c430e..f7fd9ea5bcb 100644
> > --- a/arch/x86/lib/coreboot/cb_sysinfo.c
> > +++ b/arch/x86/lib/coreboot/cb_sysinfo.c
> > @@ -471,6 +471,7 @@ int get_coreboot_info(struct sysinfo_t *info)
> > return -ENOENT;
> > gd->arch.coreboot_table = addr;
> > gd_set_acpi_start(map_to_sysmem(info->rsdp));
> > +   gd_set_smbios_start(info->smbios_start);
>
> use map_to_sysmem() too?

Actually that field is a u64, so already an address.


>
> > gd->flags |= GD_FLG_SKIP_LL_INIT;
> >
> > return 0;
> > --
>
> Reviewed-by: Bin Meng 
Regards,
Simon


Re: [PATCH 1/1] binman: doc: Remove incomplete sentence

2023-09-19 Thread Simon Glass
Hi Heinrich,


On Tue, 19 Sept 2023 at 04:02, Heinrich Schuchardt
 wrote:
>
> This is the difference between version 1 and 2 of Massimo's patch:
>
> binman: doc: fix reference tag placement for Logging section
> v2: 
> https://lore.kernel.org/u-boot/20230913161633.999542-1-massimo.pegorer+...@gmail.com/
> v1: 
> https://lore.kernel.org/u-boot/20230909135235.21242-1-massimo.pegorer+...@gmail.com/
>
> Fixes: 0f40e23fd22 ("binman: add documentation for binman sign option")
> Signed-off-by: Massimo Pegorer 
> Signed-off-by: Heinrich Schuchardt 
> ---
>  tools/binman/binman.rst | 2 --
>  1 file changed, 2 deletions(-)

Reviewed-by: Simon Glass 

I don't mind which patch is applied.


>
> diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
> index 8945b19446..020988d955 100644
> --- a/tools/binman/binman.rst
> +++ b/tools/binman/binman.rst
> @@ -1480,8 +1480,6 @@ as set in stone, so Binman will ensure it doesn't 
> change. Without this feature,
>  repacking an entry might cause it to disobey the original constraints 
> provided
>  when it was created.
>
> - Repacking an image involves
> -
>
>  Signing FIT container with private key in an image
>  --
> --
> 2.40.1
>


[PATCH 2/2] dm: core: Adjust dump-sorting to get stats only when needed

2023-09-19 Thread Simon Glass
If we are not sorting the tree we don't need to get the stats. Adjust the
code to avoid the wasted time.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/core/dump.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index 3e77832a3a00..bf95c0f52379 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -91,14 +91,14 @@ void dm_dump_tree(bool sort)
 
root = dm_root();
if (root) {
-   int dev_count, uclasses;
struct udevice **devs = NULL;
 
-   dm_get_stats(_count, );
-
printf(" Class Index  Probed  Driver
Name\n");

printf("---\n");
if (sort) {
+   int dev_count, uclasses;
+
+   dm_get_stats(_count, );
devs = calloc(dev_count, sizeof(struct udevice *));
if (!devs) {
printf("(out of memory)\n");
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 1/2] dm: core: Correct references to DM_SPL

2023-09-19 Thread Simon Glass
This does not existing anymore. Update the two in-tree uses of it to the
correct Kconfig option, which is SPL_DM

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to correct references to DM_SPL

 drivers/block/Kconfig | 2 +-
 drivers/core/Kconfig  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 1abea3f10db4..ef41aba03555 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -13,7 +13,7 @@ config BLK
 
 config SPL_LEGACY_BLOCK
bool # "Enable Legacy Block Device"
-   depends on SPL && !DM_SPL
+   depends on SPL && !SPL_DM
default y if SPL_MMC || SPL_USB_STORAGE || SCSI || NVME || IDE
default y if SPL_AHCI_PCI
help
diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig
index f0d848f45d8e..6c287c68a1c2 100644
--- a/drivers/core/Kconfig
+++ b/drivers/core/Kconfig
@@ -88,7 +88,7 @@ config DM_STATS
 
 config SPL_DM_STATS
bool "Collect and show driver model stats in SPL"
-   depends on DM_SPL
+   depends on SPL_DM
help
  Enable this to collect and display memory statistics about driver
  model. This can help to figure out where all the memory is going and
-- 
2.42.0.459.ge4e396fd5e-goog



Re: [PATCH] mx8m: csf.sh: pad csf blob for u-boot.itb to CSF_SIZE minus IVT header

2023-09-19 Thread Marek Vasut

On 9/19/23 21:15, Rasmus Villemoes wrote:

On 19/09/2023 20.27, Marek Vasut wrote:

On 9/19/23 12:00, Rasmus Villemoes wrote:

When built with CONFIG_IMX_HAB, the full FIT image, including stuff
tacked on beyond the end of the fdt structure, is expected to be (fdt
size rounded up to 0x1000 boundary)+CONFIG_CSF_SIZE.

Now, when the FIT image is loaded from a storage device, it doesn't
really matter that the flash.bin that gets written to target isn't
quite that big - we will just load some garbage bytes that are never
read or used for anything. But when flash.bin is uploaded via uuu,
it's important that we actually serve at least as many bytes as the
target expects, or we will hang in rom_api_download_image().

Extend the logic in the csf.sh script so that the csf blob is padded
to CONFIG_CSF_SIZE minus the size of the IVT header.


On which SoC do you trigger this stuff ?


imx8mp


(or rather, which bootrom version, v1 or v2? they each use SDP or SDPS
respectively)


Absolutely no idea. I just do "uuu flash.bin", which seems to DTRT
automatically, I've never figured out the esoteric uuu language, and
I've never found any actual documentation for it.


So yeah, MX8MP is SDPS (streaming).


It also doesn't work without
https://lore.kernel.org/u-boot/20230919134932.134678-1-rasmus.villem...@prevas.dk/
due to the spl_load_simple_fit() abuse.


+
+# When loading flash.bin via USB, we must ensure that the file being
+# served is as large as the target expects (see
+# board_spl_fit_size_align()), otherwise the target will hang in
+# rom_api_download_image() waiting for the remaining bytes.
+CSF_SIZE=$(sed -n "/CONFIG_CSF_SIZE=/ s@.*=@@p" .config)
+truncate -s $((CSF_SIZE - 0x20)) csf_fit.bin


Can you use dd(1) instead ? I think dd(1) is more portable than
truncate(1) , at least I cannot find truncate(1) in opengroup specs.


Certainly.


Please do v2 with dd and then we should be all fine, thanks.


Re: [PATCH v5 00/21] Kconfig: Tidy up some options

2023-09-19 Thread Tom Rini
On Thu, 14 Sep 2023 10:55:38 -0600, Simon Glass wrote:

> The view from 'make menuconfig' is confusing in places. This series aims
> to improve the top-level menu and also the boot menu.
> 
> It also groups FDT-fixup options tegether, at least the ones I could fine.
> 
> Finally this series marks the distro scripts as deprecated, so people have
> a pointer to standard boot.
> 
> [...]

Applied to u-boot/next, thanks!

-- 
Tom



Re: [PATCH] J721S2 DTS Sync from v6.6-rc1 to u-boot

2023-09-19 Thread Konstantin Ryabitsev
September 19, 2023 at 7:20 AM, "Manorit Chawdhry"  wrote:
> Am not sure either.. I had been using b4 for all the patches and I still
> see that my next revision queued by b4 also has the same problem. Not
> exactly sure what went wrong with b4 but would be careful next time.
> Thanks for pointing it out.

I'm curious how this happened as well.
Can you please send me the output of:

b4 prep --version
b4 prep --show-info (while in the branch that caused this problem)

-K


Re: [RFC PATCH 0/5] Allow for removal of DT nodes and properties

2023-09-19 Thread Tom Rini
On Tue, Sep 19, 2023 at 02:25:49PM -0600, Simon Glass wrote:
> Hi Rob,
> 
> On Mon, 18 Sept 2023 at 11:00, Rob Herring  wrote:
> >
> > On Thu, Sep 14, 2023 at 5:42 PM Simon Glass  wrote:
> > >
> > > Hi Rob,
> > >
> > > On Wed, 13 Sept 2023 at 16:39, Rob Herring  wrote:
> > > >
> > > > On Fri, Sep 8, 2023 at 1:06 PM Mark Kettenis  
> > > > wrote:
> > > > >
> > > > > > From: Jassi Brar 
> > > > > > Date: Fri, 8 Sep 2023 09:37:12 -0500
> > > > > >
> > > > > > Hi Simon,
> > > > > >
> > > > > > On Thu, Sep 7, 2023 at 3:08 PM Simon Glass  
> > > > > > wrote:
> > > > > > > On Wed, 6 Sept 2023 at 23:20, Ilias Apalodimas
> > > > > > > >
> > > > > > > > > > I beg to differ. Devicetree is more than just hardware and 
> > > > > > > > > > always has
> > > > > > > > > > been. See, for example the /chosen and /options nodes.
> > > > > > > > >
> > > > > > > > > There are exceptions...
> > > > > > > > >
> > > > > > > >
> > > > > > > > We've been this over and over again and frankly it gets a bit 
> > > > > > > > annoying.
> > > > > > > > It's called *DEVICE* tree for a reason.  As Rob pointed out 
> > > > > > > > there are
> > > > > > > > exceptions, but those made a lot of sense.  Having arbitrary 
> > > > > > > > internal ABI
> > > > > > > > stuff of various projects in the schema just defeats the 
> > > > > > > > definition of a
> > > > > > > > spec.
> > > > > > >
> > > > > > > Our efforts should not just be about internal ABI, but working to
> > > > > > > provide a consistent configuration system for all firmware 
> > > > > > > elements.
> > > > > > >
> > > > > > Sure, programmatically we can pass any data/info via DT, however it 
> > > > > > is
> > > > > > only meant to map hardware features onto data structures.
> > > > > >
> > > > > > devicetree.org  landing page
> > > > > > "The devicetree is a data structure for describing hardware."
> > > > > >
> > > > > > devicetree-specification-v0.3.pdf  Chapter-2 Line-1
> > > > > >"DTSpec specifies a construct called a devicetree to describe
> > > > > > system hardware."
> > > > >
> > > > > But it doesn't say that it describes *only* hardware.  And it does
> > > > > describe more than just hardware.  There is /chosen to specify
> > > > > firmware configuration and there are several examples of device tree
> > > > > bindings that describe non-discoverable firmware interfaces in the
> > > > > Linux tree.  And it has been that way since the days of IEEE 1275.
> > > > > There are also bindings describing things like the firmware partition
> > > > > layout.
> > > >
> > > > Yes. The exact title for 1275[1] is: IEEE Standard for Boot
> > > > (Initialization Configuration)
> > > > Firmware: Core Requirements and Practices
> > > >
> > > > I see "configuration" in there. However, in the OF case, it's
> > > > generally how firmware configured the hardware and what it discovered.
> > > > That's a little different than telling the OS how to configure the
> > > > hardware which is what we do with FDT.
> > >
> > > For the /options node it says "The properties of this node are the
> > > system’s configuration variables."
> > >
> > > Then there is section 7.4.4 which has a large list of options which
> > > don't seem to be so narrowly defined.
> > >
> > > In any case, this is not quite the point, which IMO is that we need DT
> > > to support firmware use cases, whether or not a 29-year-old spec
> > > thought of it or not. In fact it is amazing to me how forward-looking
> > > Open Firmware was.
> > >
> > > > Then there's stuff that's how
> > > > to configure Linux which we try to reject.
> > >
> > > Fair enough: Linux has user-space for that.
> >
> > Yep, the question I usually ask is who needs to configure something
> > and what determines the config. Changing things with sysfs is much
> > easier than changing the DT provided by firmware.
> >
> > > >
> > > > Once we get into configuration of the OS/client (including u-boot),
> > > > making that an ABI is a lot harder and if we use DT for that, I don't
> > > > think it should be an ABI.
> > > >
> > > > > > If we want to digress from the spec, we need the majority of
> > > > > > developers to switch sides :)  which is unlikely to happen and 
> > > > > > rightly
> > > > > > so, imho.
> > > > >
> > > > > It isn't even clear what the spec is.  There is the document you
> > > > > reference above, there are the yaml files at
> > > > > https://github.com/devicetree-org/dt-schema and then there are
> > > > > additional yaml files in the Linux tree.  As far as I know it isn't
> > > > > written down anywhere that those are the only places where device tree
> > > > > bindings can live.
> > > >
> > > > There's not any restriction.
> > > >
> > > > My intention with dtschema schemas is to only have "spec level"
> > > > schemas. (Stuff we'd add to DTSpec (but don't because no one wants to
> > > > write specs).) Hardware specific stuff lives somewhere else. That
> > > > happens to be the Linux tree because that is where all the h/w support
> > > > is 

[PATCH] bootstd: use ARCH_DMA_MINALIGN in memalign() when allocating memory

2023-09-19 Thread Tony Dinh
Use ARCH_DMA_MINALIGN in memalign() when allocating memory to read the script 
from the media.

Ref: 
https://lore.kernel.org/u-boot/cajalify05f3cr4x4g2mvkppxnbefzrhq+5cngyn8ejpg8en...@mail.gmail.com/T/#m26daadc2463fe653b814a94e6309e5e6bb6be1d1

Note: this patch depends on the previous patch
https://patchwork.ozlabs.org/project/uboot/patch/20230917230649.30357-1-mibo...@gmail.com/

Signed-off-by: Tony Dinh 
---

 boot/bootmeth_script.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/boot/bootmeth_script.c b/boot/bootmeth_script.c
index 96e0ec5efa..de2e510da1 100644
--- a/boot/bootmeth_script.c
+++ b/boot/bootmeth_script.c
@@ -99,7 +99,7 @@ static int script_read_bootflow_file(struct udevice *bootstd,
if (!bflow->subdir)
return log_msg_ret("prefix", -ENOMEM);
 
-   ret = bootmeth_alloc_file(bflow, 0x1, 1);
+   ret = bootmeth_alloc_file(bflow, 0x1, ARCH_DMA_MINALIGN);
if (ret)
return log_msg_ret("read", ret);
 
-- 
2.39.2



Re: [PATCH 1/2] spl: make SYS_SPL_MALLOC depend on !(SPL_STACK_R && SPL_SYS_MALLOC_SIMPLE)

2023-09-19 Thread Tom Rini
On Fri, Sep 15, 2023 at 07:50:49PM +0200, Rasmus Villemoes wrote:

> Currently, one can have both SYS_SPL_MALLOC=y and
> SPL_SYS_MALLOC_SIMPLE=y.
> 
> However, while the former does make board_init_r() in spl.c call
> mem_malloc_init(), that has no effect at all, because that just
> updates a few bookkeeping variables, but as the linker map shows, the
> latter setting has (as expected) caused most of dlmalloc.o to be
> garbage-collected. That is, those bookkeeping variables are not used
> for anything.
> 
> IOWs, with SYS_SPL_MALLOC=y and SPL_SYS_MALLOC_SIMPLE=y, the value of
> CONFIG_SYS_SPL_MALLOC_SIZE is irrelevant, and one still only has the
> small, SRAM-backed, malloc arena available.
> 
> Now I want to change that so that the mem_malloc_init() instead
> updates the gd->malloc* variables to point at the SDRAM area.
> 
> However, there's a small complication, namely when SPL_STACK_R=y is
> also in the mix. In that case, the "simple" malloc arena is indeed
> updated to point at the SDRAM area carved out of the new stack (see
> spl_relocate_stack_gd()). So that case works in the sense that one
> does get a "large" "simple" malloc arena (of size
> SPL_STACK_R_MALLOC_SIMPLE_LEN) - but CONFIG_SYS_SPL_MALLOC_SIZE is
> still irrelevant. Once I change the mem_malloc_init() logic, this
> would then break, because the gd->malloc* variables would be updated
> again. Also, it doesn't really make sense to allow the .config to
> essentially specify two different SDRAM-backed malloc arenas.
> 
> So since CONFIG_SYS_SPL_MALLOC and its dependent options are no-ops
> currently when SPL_STACK_R && SPL_SYS_MALLOC_SIMPLE, simply forbid
> that combination.
> 
> Simple grepping suggests that these boards/configs are affected, in
> that they become a tiny bit smaller, and the defconfig will need
> refreshing:
> 
>   am62ax_evm_r5_defconfig
>   am62x_evm_r5_defconfig
>   am64x_evm_a53_defconfig
>   am64x_evm_r5_defconfig
>   am65x_evm_a53_defconfig
>   am65x_hs_evm_a53_defconfig
>   iot2050_defconfig
>   j7200_evm_a72_defconfig
>   j721e_evm_a72_defconfig
>   j721s2_evm_a72_defconfig
>   j721s2_evm_r5_defconfig
>   verdin-am62_r5_defconfig

I've boot tested this on j721e and am65x evms, so it's likely true that
all of these platforms are fine.

-- 
Tom


signature.asc
Description: PGP signature


Re: [RFC PATCH 0/5] Allow for removal of DT nodes and properties

2023-09-19 Thread Simon Glass
Hi Rob,

On Mon, 18 Sept 2023 at 11:00, Rob Herring  wrote:
>
> On Thu, Sep 14, 2023 at 5:42 PM Simon Glass  wrote:
> >
> > Hi Rob,
> >
> > On Wed, 13 Sept 2023 at 16:39, Rob Herring  wrote:
> > >
> > > On Fri, Sep 8, 2023 at 1:06 PM Mark Kettenis  
> > > wrote:
> > > >
> > > > > From: Jassi Brar 
> > > > > Date: Fri, 8 Sep 2023 09:37:12 -0500
> > > > >
> > > > > Hi Simon,
> > > > >
> > > > > On Thu, Sep 7, 2023 at 3:08 PM Simon Glass  wrote:
> > > > > > On Wed, 6 Sept 2023 at 23:20, Ilias Apalodimas
> > > > > > >
> > > > > > > > > I beg to differ. Devicetree is more than just hardware and 
> > > > > > > > > always has
> > > > > > > > > been. See, for example the /chosen and /options nodes.
> > > > > > > >
> > > > > > > > There are exceptions...
> > > > > > > >
> > > > > > >
> > > > > > > We've been this over and over again and frankly it gets a bit 
> > > > > > > annoying.
> > > > > > > It's called *DEVICE* tree for a reason.  As Rob pointed out there 
> > > > > > > are
> > > > > > > exceptions, but those made a lot of sense.  Having arbitrary 
> > > > > > > internal ABI
> > > > > > > stuff of various projects in the schema just defeats the 
> > > > > > > definition of a
> > > > > > > spec.
> > > > > >
> > > > > > Our efforts should not just be about internal ABI, but working to
> > > > > > provide a consistent configuration system for all firmware elements.
> > > > > >
> > > > > Sure, programmatically we can pass any data/info via DT, however it is
> > > > > only meant to map hardware features onto data structures.
> > > > >
> > > > > devicetree.org  landing page
> > > > > "The devicetree is a data structure for describing hardware."
> > > > >
> > > > > devicetree-specification-v0.3.pdf  Chapter-2 Line-1
> > > > >"DTSpec specifies a construct called a devicetree to describe
> > > > > system hardware."
> > > >
> > > > But it doesn't say that it describes *only* hardware.  And it does
> > > > describe more than just hardware.  There is /chosen to specify
> > > > firmware configuration and there are several examples of device tree
> > > > bindings that describe non-discoverable firmware interfaces in the
> > > > Linux tree.  And it has been that way since the days of IEEE 1275.
> > > > There are also bindings describing things like the firmware partition
> > > > layout.
> > >
> > > Yes. The exact title for 1275[1] is: IEEE Standard for Boot
> > > (Initialization Configuration)
> > > Firmware: Core Requirements and Practices
> > >
> > > I see "configuration" in there. However, in the OF case, it's
> > > generally how firmware configured the hardware and what it discovered.
> > > That's a little different than telling the OS how to configure the
> > > hardware which is what we do with FDT.
> >
> > For the /options node it says "The properties of this node are the
> > system’s configuration variables."
> >
> > Then there is section 7.4.4 which has a large list of options which
> > don't seem to be so narrowly defined.
> >
> > In any case, this is not quite the point, which IMO is that we need DT
> > to support firmware use cases, whether or not a 29-year-old spec
> > thought of it or not. In fact it is amazing to me how forward-looking
> > Open Firmware was.
> >
> > > Then there's stuff that's how
> > > to configure Linux which we try to reject.
> >
> > Fair enough: Linux has user-space for that.
>
> Yep, the question I usually ask is who needs to configure something
> and what determines the config. Changing things with sysfs is much
> easier than changing the DT provided by firmware.
>
> > >
> > > Once we get into configuration of the OS/client (including u-boot),
> > > making that an ABI is a lot harder and if we use DT for that, I don't
> > > think it should be an ABI.
> > >
> > > > > If we want to digress from the spec, we need the majority of
> > > > > developers to switch sides :)  which is unlikely to happen and rightly
> > > > > so, imho.
> > > >
> > > > It isn't even clear what the spec is.  There is the document you
> > > > reference above, there are the yaml files at
> > > > https://github.com/devicetree-org/dt-schema and then there are
> > > > additional yaml files in the Linux tree.  As far as I know it isn't
> > > > written down anywhere that those are the only places where device tree
> > > > bindings can live.
> > >
> > > There's not any restriction.
> > >
> > > My intention with dtschema schemas is to only have "spec level"
> > > schemas. (Stuff we'd add to DTSpec (but don't because no one wants to
> > > write specs).) Hardware specific stuff lives somewhere else. That
> > > happens to be the Linux tree because that is where all the h/w support
> > > is (nothing else is close (by far)). Last I checked, we've got ~3700
> > > schemas and ~1500 unconverted bindings.
> >
> > That scope is quite a bit narrower than I understood it to be. It
> > seems to leave a significant gap between the Linux repo and yours.
> >
> > >
> > > > Anyway, let's face it, there is some consensus among 

Re: [PATCH v1 1/2] TO BE FOLDED: x86: tangier: Add FADT to the chain

2023-09-19 Thread Simon Glass
Hi Bin,

On Tue, 19 Sept 2023 at 01:56, Bin Meng  wrote:
>
> On Tue, Sep 19, 2023 at 3:28 PM Bin Meng  wrote:
> >
> > Hi Andy,
> >
> > On Fri, Aug 25, 2023 at 9:52 PM Andy Shevchenko
> >  wrote:
> > >
> > > The Simon's patch missed the FADT to be added to the chain, hence all
> > > the issues on Intel Tangier.
> > >
> > > Signed-off-by: Andy Shevchenko 
> > > ---
> > >  arch/x86/cpu/tangier/acpi.c | 2 ++
> > >  1 file changed, 2 insertions(+)
> > >
> > > diff --git a/arch/x86/cpu/tangier/acpi.c b/arch/x86/cpu/tangier/acpi.c
> > > index 01b30553818c..ffaa56ab6f87 100644
> > > --- a/arch/x86/cpu/tangier/acpi.c
> > > +++ b/arch/x86/cpu/tangier/acpi.c
> > > @@ -52,6 +52,8 @@ static int tangier_write_fadt(struct acpi_ctx *ctx,
> > >
> > > header->checksum = table_compute_checksum(fadt, header->length);
> > >
> > > +   acpi_add_table(ctx, fadt);
> > > +
> > > acpi_inc(ctx, sizeof(struct acpi_fadt));
> > >
> > > return 0;
> > > --
> >
> > Which commit should we squash this patch in?
> >
>
> Ah, I see this patch is already included in Simon's patch:
> https://patchwork.ozlabs.org/project/uboot/patch/20230901112707.v3.1.I61008e563b1209243a9a7f2b66073b4737ff82d1@changeid/
>
> I am going to apply Simon's patch unless you guys say I am looking at
> the wrong patch :)

Yes, that's it.

Regards,
Simon


Re: [PATCH v2] clk: ti: Notify AVS driver upon setting clock rate

2023-09-19 Thread Nishanth Menon
On 22:58-20230919, Kumar, Udit wrote:
> Hi Nishanth,
> 
> On 9/19/2023 9:07 PM, Nishanth Menon wrote:
> > On 19:34-20230919, Udit Kumar wrote:
> > > AVS is enabled at R5 SPL stage, on few platforms like J721E
> > > and J7200 clk-k3 is used instead if clk-sci driver.
> > > 
> > > Add support in clk-k3 driver as well to notify AVS driver
> > > upon setting clock rate so that voltage is changed accordingly.
> > > 
> > > Cc: Keerthy 
> > > Signed-off-by: Udit Kumar 
> > > ---
> > > Change log:
> > > Changes in v2:
> > > - Kept clk-sci.c as is because this is used by
> > > AM64 and AM65 platforms
> > > - v1 link
> > > https://lore.kernel.org/all/20230919060649.2518147-1-u-kum...@ti.com/
> > > 
> > >   drivers/clk/ti/clk-k3.c | 5 +
> > >   1 file changed, 5 insertions(+)
> > > 
> > > diff --git a/drivers/clk/ti/clk-k3.c b/drivers/clk/ti/clk-k3.c
> > > index ba925fa3c4..8016c3784a 100644
> > > --- a/drivers/clk/ti/clk-k3.c
> > > +++ b/drivers/clk/ti/clk-k3.c
> > > @@ -11,6 +11,7 @@
> > >   #include 
> > >   #include 
> > >   #include 
> > > +#include 
> > >   #include "k3-clk.h"
> > >   #define PLL_MIN_FREQ8
> > > @@ -339,6 +340,10 @@ static ulong ti_clk_set_rate(struct clk *clk, ulong 
> > > rate)
> > >   }
> > >   }
> > > + if (IS_ENABLED(CONFIG_K3_AVS0))
> > > + k3_avs_notify_freq(data->map[clk->id].dev_id,
> > > +data->map[clk->id].clk_id, rate);
> > > +
> > Don't you want to do this prior to actual clock change?
> 
> Not really, As i see new freq to be less than current one.
> 
> > F1, V1 -> F2, V2
> > 
> > Seq 1:
> > F1, V1
> > F2, V1
> > F2, V2
> > 
> > Seq 2:
> > F1, V1
> > F1, V2
> > F2, V2
> > 
> > If V2 < V1 (implying F2 < F1), then Seq 1 is valid. But if V2 > V1 (F2 >
> > F1) Seq 2 is valid.
> > 
> > We seem to ignore this constraint. Can you explain this in the commit
> > message?
> 
> Sure, will do , Below is reasoning, Please see if make sense
> 
> On J7 devices,  In default device tree, A72 freq is set to 2Ghz, few SOCs
> can operate at lower freq.
> 
> So while setting OPP freq (which is less than default one), First freq needs
> to set
> 
> before changing voltage.
> 
> 
> On other hand, I am thinking to fix properly for both cases, irrespective of
> seq 1 is
> 
> valid for current use case.

Thanks.

> > 
> > clk-sci.c seems to use Seq 2, vs this patch seems to take Seq 1.
> 
> I think, something to be fixed for clk-sci.c as well.
> As I see three freq point
> https://elixir.bootlin.com/u-boot/latest/source/drivers/misc/k3_avs.c#L339
> 
> So we can choose either way new-freq > current-freq or new-freq <
> current-freq,
> 
> Based upon new-freq , voltage to be set before/after clock change.

We should handle both cases, ideally.

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH] mx8m: csf.sh: pad csf blob for u-boot.itb to CSF_SIZE minus IVT header

2023-09-19 Thread Rasmus Villemoes
On 19/09/2023 20.27, Marek Vasut wrote:
> On 9/19/23 12:00, Rasmus Villemoes wrote:
>> When built with CONFIG_IMX_HAB, the full FIT image, including stuff
>> tacked on beyond the end of the fdt structure, is expected to be (fdt
>> size rounded up to 0x1000 boundary)+CONFIG_CSF_SIZE.
>>
>> Now, when the FIT image is loaded from a storage device, it doesn't
>> really matter that the flash.bin that gets written to target isn't
>> quite that big - we will just load some garbage bytes that are never
>> read or used for anything. But when flash.bin is uploaded via uuu,
>> it's important that we actually serve at least as many bytes as the
>> target expects, or we will hang in rom_api_download_image().
>>
>> Extend the logic in the csf.sh script so that the csf blob is padded
>> to CONFIG_CSF_SIZE minus the size of the IVT header.
> 
> On which SoC do you trigger this stuff ?

imx8mp

> (or rather, which bootrom version, v1 or v2? they each use SDP or SDPS
> respectively)

Absolutely no idea. I just do "uuu flash.bin", which seems to DTRT
automatically, I've never figured out the esoteric uuu language, and
I've never found any actual documentation for it.

It also doesn't work without
https://lore.kernel.org/u-boot/20230919134932.134678-1-rasmus.villem...@prevas.dk/
due to the spl_load_simple_fit() abuse.

>> +
>> +# When loading flash.bin via USB, we must ensure that the file being
>> +# served is as large as the target expects (see
>> +# board_spl_fit_size_align()), otherwise the target will hang in
>> +# rom_api_download_image() waiting for the remaining bytes.
>> +CSF_SIZE=$(sed -n "/CONFIG_CSF_SIZE=/ s@.*=@@p" .config)
>> +truncate -s $((CSF_SIZE - 0x20)) csf_fit.bin
> 
> Can you use dd(1) instead ? I think dd(1) is more portable than
> truncate(1) , at least I cannot find truncate(1) in opengroup specs.

Certainly.

Rasmus



Re: [PATCH] mx8m: csf.sh: pad csf blob for u-boot.itb to CSF_SIZE minus IVT header

2023-09-19 Thread Marek Vasut

On 9/19/23 12:00, Rasmus Villemoes wrote:

When built with CONFIG_IMX_HAB, the full FIT image, including stuff
tacked on beyond the end of the fdt structure, is expected to be (fdt
size rounded up to 0x1000 boundary)+CONFIG_CSF_SIZE.

Now, when the FIT image is loaded from a storage device, it doesn't
really matter that the flash.bin that gets written to target isn't
quite that big - we will just load some garbage bytes that are never
read or used for anything. But when flash.bin is uploaded via uuu,
it's important that we actually serve at least as many bytes as the
target expects, or we will hang in rom_api_download_image().

Extend the logic in the csf.sh script so that the csf blob is padded
to CONFIG_CSF_SIZE minus the size of the IVT header.


On which SoC do you trigger this stuff ?
(or rather, which bootrom version, v1 or v2? they each use SDP or SDPS 
respectively)



Signed-off-by: Rasmus Villemoes 
---
  doc/imx/habv4/csf_examples/mx8m/csf.sh | 8 
  1 file changed, 8 insertions(+)

diff --git a/doc/imx/habv4/csf_examples/mx8m/csf.sh 
b/doc/imx/habv4/csf_examples/mx8m/csf.sh
index 65c143073c..80edc94aeb 100644
--- a/doc/imx/habv4/csf_examples/mx8m/csf.sh
+++ b/doc/imx/habv4/csf_examples/mx8m/csf.sh
@@ -75,5 +75,13 @@ dd if=ivt.bin of=flash.bin bs=1 seek=${ivt_block_offset} 
conv=notrunc
  
  # Generate CSF blob

  cst -i csf_fit.tmp -o csf_fit.bin
+
+# When loading flash.bin via USB, we must ensure that the file being
+# served is as large as the target expects (see
+# board_spl_fit_size_align()), otherwise the target will hang in
+# rom_api_download_image() waiting for the remaining bytes.
+CSF_SIZE=$(sed -n "/CONFIG_CSF_SIZE=/ s@.*=@@p" .config)
+truncate -s $((CSF_SIZE - 0x20)) csf_fit.bin


Can you use dd(1) instead ? I think dd(1) is more portable than 
truncate(1) , at least I cannot find truncate(1) in opengroup specs.


Re: [PATCH] imx8mp: binman: rename spl and u-boot nodes

2023-09-19 Thread Marek Vasut

On 9/19/23 11:28, Rasmus Villemoes wrote:

The hab signing script doc/imx/habv4/csf_examples/mx8m/csf.sh does

   fdtget -t x u-boot.dtb /binman/imx-boot/uboot offset

to figure out the offset of u-boot.itb inside flash.bin. That works
fine for imx8mm, imx8mn, imx8mq, but fails for imx8mp because in that
case 'uboot' is merely a label and not actually the node name.

Homogenize these cases and make imx8mp the same as the other imx8m*
variants. The binman type is explicitly given and no longer derived
from the node name, and the csf.sh script will work for all four SOCs.

Signed-off-by: Rasmus Villemoes 
---
  arch/arm/dts/imx8mp-u-boot.dtsi | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm/dts/imx8mp-u-boot.dtsi b/arch/arm/dts/imx8mp-u-boot.dtsi
index 200938a980..355af16cf3 100644
--- a/arch/arm/dts/imx8mp-u-boot.dtsi
+++ b/arch/arm/dts/imx8mp-u-boot.dtsi
@@ -171,14 +171,16 @@
filename = "flash.bin";
pad-byte = <0x00>;
  
-		spl: blob-ext@1 {

+   spl {
filename = "spl.bin";
offset = <0x0>;
+   type = "blob-ext";
};
  
-		uboot: blob-ext@2 {

+   binman_uboot: uboot {
filename = "u-boot.itb";
offset = <0x58000>;
+   type = "blob-ext";
};
};
  };


Reviewed-by: Marek Vasut 


[PATCH 36/36] expo: Update documentation to include textline

2023-09-19 Thread Simon Glass
Update the expo documentation to include mention of this new object
type.

Signed-off-by: Simon Glass 
---

 doc/develop/cedit.rst |  3 ++-
 doc/develop/expo.rst  | 48 ++-
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/doc/develop/cedit.rst b/doc/develop/cedit.rst
index 63dff9d3f14..82305b921f0 100644
--- a/doc/develop/cedit.rst
+++ b/doc/develop/cedit.rst
@@ -162,7 +162,8 @@ Cedit provides several options for persistent settings:
 - Writing an FDT file to a filesystem
 - Writing to U-Boot's environment variables, which are then typically stored in
   a persistent manner
-- Writing to CMOS RAM registers (common on x86 machines)
+- Writing to CMOS RAM registers (common on x86 machines). Note that textline
+  objects do not appear in CMOS RAM registers
 
 For now, reading and writing settings is not automatic. See the
 :doc:`../usage/cmd/cedit` for how to do this on the command line or in a
diff --git a/doc/develop/expo.rst b/doc/develop/expo.rst
index f13761995d3..c87b6ec8128 100644
--- a/doc/develop/expo.rst
+++ b/doc/develop/expo.rst
@@ -63,9 +63,12 @@ select the item), label and description. All three are shown 
in a single line
 within the menu. Items can also have a preview image, which is shown when the
 item is highlighted.
 
-All components have a name. This is purely for debugging, so it is easy to see
-what object is referred to. Of course the ID numbers can help as well, but they
-are less easy to distinguish.
+A `textline object` contains a label and an editable string.
+
+All components have a name. This is mostly for debugging, so it is easy to see
+what object is referred to, although the name is also used for saving values.
+Of course the ID numbers can help as well, but they are less easy to
+distinguish.
 
 While the expo implementation provides support for handling keypresses and
 rendering on the display or serial port, it does not actually deal with reading
@@ -136,7 +139,9 @@ this is to use `cli_ch_process()`, since it handles 
conversion of escape
 sequences into keys. However, expo has some special menu-key codes for
 navigating the interface. These are defined in `enum bootmenu_key` and include
 `BKEY_UP` for moving up and `BKEY_SELECT` for selecting an item. You can use
-`bootmenu_conv_key()` to convert an ASCII key into one of these.
+`bootmenu_conv_key()` to convert an ASCII key into one of these, but if it
+returns a value >= `BKEY_FIRST_EXTRA` then you should pass the unmodified ASCII
+key to the expo, since it may be used by textline objects.
 
 Once a keypress is decoded, call `expo_send_key()` to send it to the expo. This
 may cause an update to the expo state and may produce an action.
@@ -312,6 +317,9 @@ type
 "menu"
 Menu containing items which can be selected by the user
 
+"textline"
+A line of text which can be edited
+
 id
 type: u32, required
 
@@ -362,6 +370,26 @@ desc-label / desc-label-id
 Specifies the description for each item in the menu. These are currently
 only intended for use in simple mode.
 
+Textline nodes have the following additional properties:
+
+label / label-id
+type: string / u32, required
+
+Specifies the label of the textline. This is shown to the left of the area
+for this textline.
+
+edit-id
+type: u32, required
+
+Specifies the ID of the of the editable text object. This can be used to
+obtain the text from the textline
+
+max-chars:
+type: u32, required
+
+Specifies the maximum number of characters permitted to be in the textline.
+The user will be prevented from adding more.
+
 
 Expo layout
 ~~~
@@ -401,6 +429,9 @@ strings are provided inline in the nodes where they are 
used.
 ID_AC_ON,
 ID_AC_MEMORY,
 
+ID_MACHINE_NAME,
+ID_MACHINE_NAME_EDIT,
+
 ID_DYNAMIC_START,
 */
 
@@ -447,6 +478,13 @@ strings are provided inline in the nodes where they are 
used.
 
 item-id = ;
 };
+
+machine-name {
+id = ;
+type = "textline";
+max-chars = <20>;
+title = "Machine name";
+edit-id = ;
 };
 };
 
@@ -474,7 +512,7 @@ Some ideas for future work:
 - Image formats other than BMP
 - Use of ANSI sequences to control a serial terminal
 - Colour selection
-- Support for more widgets, e.g. text, numeric, radio/option
+- Support for more widgets, e.g. numeric, radio/option
 - Mouse support
 - Integrate Nuklear, NxWidgets or some other library for a richer UI
 - Optimise rendering by only updating the display with changes since last 
render
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 35/36] expo: Update tests to include textline

2023-09-19 Thread Simon Glass
Provide test coverage for the new expo object type, including building
and reading/writing settings.

Signed-off-by: Simon Glass 
---

 arch/sandbox/dts/cedit.dtsi |  8 
 include/test/cedit-test.h   |  5 -
 test/boot/cedit.c   | 30 +++---
 test/boot/expo.c|  2 +-
 test/boot/files/expo_ids.h  |  3 +++
 test/boot/files/expo_layout.dts |  8 
 6 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/arch/sandbox/dts/cedit.dtsi b/arch/sandbox/dts/cedit.dtsi
index a9eb4c2d594..9bd84e62936 100644
--- a/arch/sandbox/dts/cedit.dtsi
+++ b/arch/sandbox/dts/cedit.dtsi
@@ -51,6 +51,14 @@
 
item-id = ;
};
+
+   machine-name {
+   id = ;
+   type = "textline";
+   max-chars = <20>;
+   title = "Machine name";
+   edit-id = ;
+   };
};
};
 
diff --git a/include/test/cedit-test.h b/include/test/cedit-test.h
index 349df75b16d..475ecc9c2dc 100644
--- a/include/test/cedit-test.h
+++ b/include/test/cedit-test.h
@@ -24,6 +24,9 @@
 #define ID_AC_ON   11
 #define ID_AC_MEMORY   12
 
-#define ID_DYNAMIC_START   13
+#define ID_MACHINE_NAME13
+#define ID_MACHINE_NAME_EDIT   14
+
+#define ID_DYNAMIC_START   15
 
 #endif
diff --git a/test/boot/cedit.c b/test/boot/cedit.c
index ab2b8a1f9ff..aa417190486 100644
--- a/test/boot/cedit.c
+++ b/test/boot/cedit.c
@@ -58,6 +58,7 @@ BOOTSTD_TEST(cedit_base, 0);
 /* Check the cedit write_fdt and read_fdt commands */
 static int cedit_fdt(struct unit_test_state *uts)
 {
+   struct scene_obj_textline *tline;
struct video_priv *vid_priv;
extern struct expo *cur_exp;
struct scene_obj_menu *menu;
@@ -66,6 +67,7 @@ static int cedit_fdt(struct unit_test_state *uts)
struct scene *scn;
oftree tree;
ofnode node;
+   char *str;
void *fdt;
int i;
 
@@ -79,6 +81,12 @@ static int cedit_fdt(struct unit_test_state *uts)
ut_assertnonnull(menu);
menu->cur_item_id = ID_CPU_SPEED_2;
 
+   /* get a textline to fiddle with too */
+   tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE);
+   ut_assertnonnull(tline);
+   str = abuf_data(>buf);
+   strcpy(str, "my-machine");
+
ut_assertok(run_command("cedit write_fdt hostfs - settings.dtb", 0));
ut_assertok(run_commandf("load hostfs - %lx settings.dtb", addr));
ut_assert_nextlinen("1024 bytes read");
@@ -86,26 +94,29 @@ static int cedit_fdt(struct unit_test_state *uts)
fdt = map_sysmem(addr, 1024);
tree = oftree_from_fdt(fdt);
node = ofnode_find_subnode(oftree_root(tree), CEDIT_NODE_NAME);
+   ut_assert(ofnode_valid(node));
 
ut_asserteq(ID_CPU_SPEED_2,
ofnode_read_u32_default(node, "cpu-speed", 0));
ut_asserteq_str("2.5 GHz", ofnode_read_string(node, "cpu-speed-str"));
-   ut_assert(ofnode_valid(node));
+   ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name"));
 
-   /* There should only be 4 properties */
+   /* There should only be 5 properties */
for (i = 0, ofnode_first_property(node, ); ofprop_valid();
 i++, ofnode_next_property())
;
-   ut_asserteq(4, i);
+   ut_asserteq(5, i);
 
ut_assert_console_end();
 
/* reset the expo */
menu->cur_item_id = ID_CPU_SPEED_1;
+   *str = '\0';
 
/* load in the settings and make sure they update */
ut_assertok(run_command("cedit read_fdt hostfs - settings.dtb", 0));
ut_asserteq(ID_CPU_SPEED_2, menu->cur_item_id);
+   ut_asserteq_str("my-machine", ofnode_read_string(node, "machine-name"));
 
ut_assertnonnull(menu);
ut_assert_console_end();
@@ -117,10 +128,12 @@ BOOTSTD_TEST(cedit_fdt, 0);
 /* Check the cedit write_env and read_env commands */
 static int cedit_env(struct unit_test_state *uts)
 {
+   struct scene_obj_textline *tline;
struct video_priv *vid_priv;
extern struct expo *cur_exp;
struct scene_obj_menu *menu;
struct scene *scn;
+   char *str;
 
console_record_reset_enable();
ut_assertok(run_command("cedit load hostfs - cedit.dtb", 0));
@@ -132,25 +145,36 @@ static int cedit_env(struct unit_test_state *uts)
ut_assertnonnull(menu);
menu->cur_item_id = ID_CPU_SPEED_2;
 
+   /* get a textline to fiddle with too */
+   tline = scene_obj_find(scn, ID_MACHINE_NAME, SCENEOBJT_TEXTLINE);
+   ut_assertnonnull(tline);
+   str = abuf_data(>buf);
+   strcpy(str, "my-machine");
+
ut_assertok(run_command("cedit write_env -v", 0));
ut_assert_nextlinen("c.cpu-speed=7");

[PATCH 34/36] expo: Support building an expo with a textline

2023-09-19 Thread Simon Glass
Add textline to the list of objects which tthe expo builder can build.
This allows them to be provided in the description.

Signed-off-by: Simon Glass 
---

 boot/expo_build.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/boot/expo_build.c b/boot/expo_build.c
index 48ed31d5b32..95dd7463c84 100644
--- a/boot/expo_build.c
+++ b/boot/expo_build.c
@@ -287,6 +287,49 @@ static int menu_build(struct build_info *info, ofnode 
node, struct scene *scn,
return 0;
 }
 
+static int textline_build(struct build_info *info, ofnode node,
+ struct scene *scn, uint id, struct scene_obj **objp)
+{
+   struct scene_obj_textline *ted;
+   uint ted_id, edit_id;
+   const char *name;
+   u32 max_chars;
+   int ret;
+
+   name = ofnode_get_name(node);
+
+   info->err_prop = "max-chars";
+   ret = ofnode_read_u32(node, "max-chars", _chars);
+   if (ret)
+   return log_msg_ret("max", -ENOENT);
+
+   ret = scene_textline(scn, name, id, max_chars, );
+   if (ret < 0)
+   return log_msg_ret("ted", ret);
+   ted_id = ret;
+
+   /* Set the title */
+   ret = add_txt_str(info, node, scn, "title", 0);
+   if (ret < 0)
+   return log_msg_ret("tit", ret);
+   ted->label_id = ret;
+
+   /* Setup the editor */
+   info->err_prop = "edit-id";
+   ret = ofnode_read_u32(node, "edit-id", );
+   if (ret)
+   return log_msg_ret("id", -ENOENT);
+   edit_id = ret;
+
+   ret = scene_txt_str(scn, "edit", edit_id, 0, abuf_data(>buf),
+   NULL);
+   if (ret < 0)
+   return log_msg_ret("add", ret);
+   ted->edit_id = ret;
+
+   return 0;
+}
+
 /**
  * obj_build() - Build an expo object and add it to a scene
  *
@@ -316,6 +359,8 @@ static int obj_build(struct build_info *info, ofnode node, 
struct scene *scn)
 
if (!strcmp("menu", type))
ret = menu_build(info, node, scn, id, );
+   else if (!strcmp("textline", type))
+   ret = textline_build(info, node, scn, id, );
else
ret = -EOPNOTSUPP;
if (ret)
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 33/36] expo: Plumb in textline to cedit

2023-09-19 Thread Simon Glass
Support textlines in the configuration editor.

Signed-off-by: Simon Glass 
---

 boot/cedit.c | 58 +++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/boot/cedit.c b/boot/cedit.c
index 407793aaddd..f2387170127 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -81,6 +81,12 @@ int cedit_arange(struct expo *exp, struct video_priv *vpriv, 
uint scene_id)
scene_menu_arrange(scn, (struct scene_obj_menu *)obj);
y += 50;
break;
+   case SCENEOBJT_TEXTLINE:
+   scene_obj_set_pos(scn, obj->id, 50, y);
+   scene_textline_arrange(scn,
+   (struct scene_obj_textline *)obj);
+   y += 50;
+   break;
}
}
 
@@ -295,6 +301,7 @@ static int h_write_settings(struct scene_obj *obj, void 
*vpriv)
 {
struct cedit_iter_priv *priv = vpriv;
struct abuf *buf = priv->buf;
+   int ret;
 
switch (obj->type) {
case SCENEOBJT_NONE:
@@ -305,7 +312,7 @@ static int h_write_settings(struct scene_obj *obj, void 
*vpriv)
const struct scene_obj_menu *menu;
const char *str;
char name[80];
-   int ret, i;
+   int i;
 
/* write the ID of the current item */
menu = (struct scene_obj_menu *)obj;
@@ -335,6 +342,15 @@ static int h_write_settings(struct scene_obj *obj, void 
*vpriv)
 
break;
}
+   case SCENEOBJT_TEXTLINE: {
+   const struct scene_obj_textline *tline;
+
+   tline = (struct scene_obj_textline *)obj;
+   ret = write_dt_string(buf, obj->name, abuf_data(>buf));
+   if (ret)
+   return log_msg_ret("wr2", ret);
+   break;
+   }
}
 
return 0;
@@ -405,6 +421,19 @@ static int h_read_settings(struct scene_obj *obj, void 
*vpriv)
 
break;
}
+   case SCENEOBJT_TEXTLINE: {
+   const struct scene_obj_textline *tline;
+   const char *val;
+   int len;
+
+   tline = (struct scene_obj_textline *)obj;
+
+   val = ofnode_read_prop(node, obj->name, );
+   if (len >= tline->max_chars)
+   return log_msg_ret("str", -ENOSPC);
+   strcpy(abuf_data(>buf), val);
+   break;
+   }
}
 
return 0;
@@ -472,6 +501,20 @@ static int h_write_settings_env(struct scene_obj *obj, 
void *vpriv)
if (ret)
return log_msg_ret("st2", ret);
break;
+   case SCENEOBJT_TEXTLINE: {
+   const struct scene_obj_textline *tline;
+
+   tline = (struct scene_obj_textline *)obj;
+   str = abuf_data(>buf);
+   ret = env_set(var, str);
+   if (ret)
+   return log_msg_ret("set", ret);
+
+   if (priv->verbose)
+   printf("%s=%s\n", var, str);
+
+   break;
+   }
}
 
return 0;
@@ -521,6 +564,19 @@ static int h_read_settings_env(struct scene_obj *obj, void 
*vpriv)
 */
menu->cur_item_id = val;
break;
+   case SCENEOBJT_TEXTLINE: {
+   const struct scene_obj_textline *tline;
+   const char *value;
+
+   tline = (struct scene_obj_textline *)obj;
+   value = env_get(var);
+   if (strlen(value) >= tline->max_chars)
+   return log_msg_ret("str", -ENOSPC);
+   if (priv->verbose)
+   printf("%s=%s\n", var, value);
+   strcpy(abuf_data(>buf), value);
+   break;
+   }
}
 
return 0;
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 32/36] expo: Support handling any key in cedit

2023-09-19 Thread Simon Glass
At present cedit only supports menu keys. For textline objects we need
to insert normal ASCII characters.

We also need to handle backspace, which is ASCII 9.

In fact, expo does not make use of all the menu keys, so partition
them accordingly and update the logic to support normal ASCII
characters, too.

Signed-off-by: Simon Glass 
---

 boot/cedit.c   | 2 +-
 include/menu.h | 7 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/boot/cedit.c b/boot/cedit.c
index bb194af77bd..407793aaddd 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -176,7 +176,7 @@ int cedit_run(struct expo *exp)
key = 0;
if (ichar) {
key = bootmenu_conv_key(ichar);
-   if (key == BKEY_NONE)
+   if (key == BKEY_NONE || key >= BKEY_FIRST_EXTRA)
key = ichar;
}
if (!key)
diff --git a/include/menu.h b/include/menu.h
index 64ce89b7d26..6571c39b143 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -50,12 +50,17 @@ enum bootmenu_key {
BKEY_DOWN,
BKEY_SELECT,
BKEY_QUIT,
+   BKEY_SAVE,
+
+   /* 'extra' keys, which are used by menus but not cedit */
BKEY_PLUS,
BKEY_MINUS,
BKEY_SPACE,
-   BKEY_SAVE,
 
BKEY_COUNT,
+
+   /* Keys from here on are not used by cedit */
+   BKEY_FIRST_EXTRA = BKEY_PLUS,
 };
 
 /**
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 31/36] video: Mark truetype_measure() static

2023-09-19 Thread Simon Glass
This function is not used outside this file, so mark it static.

Signed-off-by: Simon Glass 
---

 drivers/video/console_truetype.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 242b8b71342..14fb81e9563 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -718,8 +718,8 @@ static int truetype_select_font(struct udevice *dev, const 
char *name,
return 0;
 }
 
-int truetype_measure(struct udevice *dev, const char *name, uint size,
-const char *text, struct vidconsole_bbox *bbox)
+static int truetype_measure(struct udevice *dev, const char *name, uint size,
+   const char *text, struct vidconsole_bbox *bbox)
 {
struct console_tt_metrics *met;
stbtt_fontinfo *font;
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 30/36] expo: Plumb in textlines to a scene

2023-09-19 Thread Simon Glass
Provide an implementation for textlines in the scene code, so that they
are displayed correctly. Provide a way to have a border around the
textline, with the internal part being the same colour as the
background. This looks more natural.

Signed-off-by: Simon Glass 
---

 boot/scene.c  | 56 +++--
 boot/scene_internal.h | 58 +++
 2 files changed, 112 insertions(+), 2 deletions(-)

diff --git a/boot/scene.c b/boot/scene.c
index 6c7c926f7c9..d4dfb49ada1 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -280,6 +280,7 @@ int scene_obj_get_hw(struct scene *scn, uint id, int 
*widthp)
switch (obj->type) {
case SCENEOBJT_NONE:
case SCENEOBJT_MENU:
+   case SCENEOBJT_TEXTLINE:
break;
case SCENEOBJT_IMAGE: {
struct scene_obj_img *img = (struct scene_obj_img *)obj;
@@ -328,8 +329,10 @@ int scene_obj_get_hw(struct scene *scn, uint id, int 
*widthp)
  * scene_render_background() - Render the background for an object
  *
  * @obj: Object to render
+ * @box_only: true to show a box around the object, but keep the normal
+ * background colour inside
  */
-static void scene_render_background(struct scene_obj *obj)
+static void scene_render_background(struct scene_obj *obj, bool box_only)
 {
struct expo *exp = obj->scene->expo;
const struct expo_theme *theme = >theme;
@@ -360,6 +363,11 @@ static void scene_render_background(struct scene_obj *obj)
label_bbox.x1 + inset, label_bbox.y1 + inset,
vid_priv->colour_fg);
vidconsole_pop_colour(cons, );
+   if (box_only) {
+   video_fill_part(dev, label_bbox.x0, label_bbox.y0,
+   label_bbox.x1, label_bbox.y1,
+   vid_priv->colour_bg);
+   }
 }
 
 /**
@@ -445,7 +453,7 @@ static int scene_obj_render(struct scene_obj *obj, bool 
text_mode)
return -ENOTSUPP;
 
/* draw a background behind the menu items */
-   scene_render_background(obj);
+   scene_render_background(obj, false);
}
/*
 * With a vidconsole, the text and item pointer are rendered as
@@ -461,6 +469,10 @@ static int scene_obj_render(struct scene_obj *obj, bool 
text_mode)
 
break;
}
+   case SCENEOBJT_TEXTLINE:
+   if (obj->flags & SCENEOF_OPEN)
+   scene_render_background(obj, true);
+   break;
}
 
return 0;
@@ -486,6 +498,15 @@ int scene_arrange(struct scene *scn)
return log_msg_ret("arr", ret);
break;
}
+   case SCENEOBJT_TEXTLINE: {
+   struct scene_obj_textline *tline;
+
+   tline = (struct scene_obj_textline *)obj,
+   ret = scene_textline_arrange(scn, tline);
+   if (ret)
+   return log_msg_ret("arr", ret);
+   break;
+   }
}
}
 
@@ -517,6 +538,10 @@ int scene_render_deps(struct scene *scn, uint id)
scene_menu_render_deps(scn,
   (struct scene_obj_menu *)obj);
break;
+   case SCENEOBJT_TEXTLINE:
+   scene_textline_render_deps(scn,
+   (struct scene_obj_textline *)obj);
+   break;
}
}
 
@@ -637,6 +662,15 @@ int scene_send_key(struct scene *scn, int key, struct 
expo_action *event)
return log_msg_ret("key", ret);
break;
}
+   case SCENEOBJT_TEXTLINE: {
+   struct scene_obj_textline *tline;
+
+   tline = (struct scene_obj_textline *)obj,
+   ret = scene_textline_send_key(scn, tline, key, event);
+   if (ret)
+   return log_msg_ret("key", ret);
+   break;
+   }
}
return 0;
}
@@ -670,6 +704,13 @@ int scene_obj_calc_bbox(struct scene_obj *obj, struct 
vidconsole_bbox *bbox,
scene_menu_calc_bbox(menu, bbox, label_bbox);
break;
}
+   case SCENEOBJT_TEXTLINE: {
+   struct scene_obj_textline *tline;
+
+   tline = (struct scene_obj_textline *)obj;
+   scene_textline_calc_bbox(tline, bbox, label_bbox);
+   break;
+   }
}
 
return 0;
@@ -708,6 +749,16 @@ int scene_calc_dims(struct scene *scn, bool do_menus)
}
break;
}
+   

[PATCH 29/36] expo: Support opening a textline

2023-09-19 Thread Simon Glass
This object needs special handling when it is opened, to set up the CLI
and the vidconsole context. Add special support for this.

Signed-off-by: Simon Glass 
---

 boot/scene.c  | 32 
 boot/scene_internal.h | 22 ++
 boot/scene_textline.c |  5 -
 3 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/boot/scene.c b/boot/scene.c
index 0b44a13748a..6c7c926f7c9 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -759,10 +759,42 @@ void scene_highlight_first(struct scene *scn)
}
 }
 
+static int scene_obj_open(struct scene *scn, struct scene_obj *obj)
+{
+   int ret;
+
+   switch (obj->type) {
+   case SCENEOBJT_NONE:
+   case SCENEOBJT_IMAGE:
+   case SCENEOBJT_MENU:
+   case SCENEOBJT_TEXT:
+   break;
+   case SCENEOBJT_TEXTLINE:
+   ret = scene_textline_open(scn,
+ (struct scene_obj_textline *)obj);
+   if (ret)
+   return log_msg_ret("op", ret);
+   break;
+   }
+
+   return 0;
+}
+
 int scene_set_open(struct scene *scn, uint id, bool open)
 {
+   struct scene_obj *obj;
int ret;
 
+   obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
+   if (!obj)
+   return log_msg_ret("find", -ENOENT);
+
+   if (open) {
+   ret = scene_obj_open(scn, obj);
+   if (ret)
+   return log_msg_ret("op", ret);
+   }
+
ret = scene_obj_flag_clrset(scn, id, SCENEOF_OPEN,
open ? SCENEOF_OPEN : 0);
if (ret)
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index 1c2bfeadcd3..7a84977646a 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -278,4 +278,26 @@ void scene_menu_calc_bbox(struct scene_obj_menu *menu,
 int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox,
struct vidconsole_bbox *label_bbox);
 
+/**
+ * scene_textline_open() - Open a textline object
+ *
+ * Set up the text editor ready for use
+ *
+ * @scn: Scene containing the textline
+ * @tline: textline object
+ * Return: 0 if OK, -ve on error
+ */
+int scene_textline_open(struct scene *scn, struct scene_obj_textline *tline);
+
+/**
+ * scene_textline_close() - Close a textline object
+ *
+ * Close out the text editor after use
+ *
+ * @scn: Scene containing the textline
+ * @tline: textline object
+ * Return: 0 if OK, -ve on error
+ */
+int scene_textline_close(struct scene *scn, struct scene_obj_textline *tline);
+
 #endif /* __SCENE_INTERNAL_H */
diff --git a/boot/scene_textline.c b/boot/scene_textline.c
index 2caa81ee158..6ea072a1c26 100644
--- a/boot/scene_textline.c
+++ b/boot/scene_textline.c
@@ -227,8 +227,3 @@ int scene_textline_open(struct scene *scn, struct 
scene_obj_textline *tline)
 
return 0;
 }
-
-int scene_textline_close(struct scene *scn, struct scene_obj_textline *tline)
-{
-   return 0;
-}
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 28/36] expo: Add basic support for textline objects

2023-09-19 Thread Simon Glass
A textline is a line of text which can be edited by the user. It has a
maximum length (in chracters) but otherwise there are no restrictions.

Signed-off-by: Simon Glass 
---

 boot/Makefile |   3 +-
 boot/scene_textline.c | 234 ++
 include/expo.h|  36 +++
 3 files changed, 272 insertions(+), 1 deletion(-)
 create mode 100644 boot/scene_textline.c

diff --git a/boot/Makefile b/boot/Makefile
index 10f01572237..e5bd6bb6fa3 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -52,7 +52,8 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o
 endif
 
-obj-$(CONFIG_$(SPL_TPL_)EXPO) += expo.o scene.o scene_menu.o expo_build.o
+obj-$(CONFIG_$(SPL_TPL_)EXPO) += expo.o scene.o expo_build.o
+obj-$(CONFIG_$(SPL_TPL_)EXPO) += scene_menu.o scene_textline.o
 
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_REQUEST) += vbe_request.o
diff --git a/boot/scene_textline.c b/boot/scene_textline.c
new file mode 100644
index 000..2caa81ee158
--- /dev/null
+++ b/boot/scene_textline.c
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Implementation of a menu in a scene
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass 
+ */
+
+#define LOG_CATEGORY   LOGC_EXPO
+
+#include 
+#include 
+#include 
+#include 
+#include "scene_internal.h"
+
+int scene_textline(struct scene *scn, const char *name, uint id, uint 
max_chars,
+  struct scene_obj_textline **tlinep)
+{
+   struct scene_obj_textline *tline;
+   char *buf;
+   int ret;
+
+   if (max_chars >= EXPO_MAX_CHARS)
+   return log_msg_ret("chr", -E2BIG);
+
+   ret = scene_obj_add(scn, name, id, SCENEOBJT_TEXTLINE,
+   sizeof(struct scene_obj_textline),
+   (struct scene_obj **));
+   if (ret < 0)
+   return log_msg_ret("obj", -ENOMEM);
+   abuf_init(>buf);
+   if (!abuf_realloc(>buf, max_chars + 1))
+   return log_msg_ret("buf", -ENOMEM);
+   buf = abuf_data(>buf);
+   *buf = '\0';
+   tline->pos = max_chars;
+   tline->max_chars = max_chars;
+
+   if (tlinep)
+   *tlinep = tline;
+
+   return tline->obj.id;
+}
+
+void scene_textline_calc_bbox(struct scene_obj_textline *tline,
+ struct vidconsole_bbox *bbox,
+ struct vidconsole_bbox *edit_bbox)
+{
+   const struct expo_theme *theme = >obj.scene->expo->theme;
+
+   bbox->valid = false;
+   scene_bbox_union(tline->obj.scene, tline->label_id, 0, bbox);
+   scene_bbox_union(tline->obj.scene, tline->edit_id, 0, bbox);
+
+   edit_bbox->valid = false;
+   scene_bbox_union(tline->obj.scene, tline->edit_id, theme->menu_inset,
+edit_bbox);
+}
+
+int scene_textline_calc_dims(struct scene_obj_textline *tline)
+{
+   struct scene *scn = tline->obj.scene;
+   struct vidconsole_bbox bbox;
+   struct scene_obj_txt *txt;
+   int ret;
+
+   txt = scene_obj_find(scn, tline->edit_id, SCENEOBJT_NONE);
+   if (!txt)
+   return log_msg_ret("dim", -ENOENT);
+
+   ret = vidconsole_nominal(scn->expo->cons, txt->font_name,
+txt->font_size, tline->max_chars, );
+   if (ret)
+   return log_msg_ret("nom", ret);
+
+   if (bbox.valid) {
+   tline->obj.dim.w = bbox.x1 - bbox.x0;
+   tline->obj.dim.h = bbox.y1 - bbox.y0;
+
+   scene_obj_set_size(scn, tline->edit_id, tline->obj.dim.w,
+  tline->obj.dim.h);
+   }
+
+   return 0;
+}
+
+int scene_textline_arrange(struct scene *scn, struct scene_obj_textline *tline)
+{
+   const bool open = tline->obj.flags & SCENEOF_OPEN;
+   bool point;
+   int x, y;
+   int ret;
+
+   x = tline->obj.dim.x;
+   y = tline->obj.dim.y;
+   if (tline->label_id) {
+   ret = scene_obj_set_pos(scn, tline->label_id, tline->obj.dim.x,
+   y);
+   if (ret < 0)
+   return log_msg_ret("tit", ret);
+
+   ret = scene_obj_set_pos(scn, tline->edit_id,
+   tline->obj.dim.x + 200, y);
+   if (ret < 0)
+   return log_msg_ret("tit", ret);
+
+   ret = scene_obj_get_hw(scn, tline->label_id, NULL);
+   if (ret < 0)
+   return log_msg_ret("hei", ret);
+
+   y += ret * 2;
+   }
+
+   point = scn->highlight_id == tline->obj.id;
+   point &= !open;
+   scene_obj_flag_clrset(scn, tline->edit_id, SCENEOF_POINT,
+ point ? SCENEOF_POINT : 0);
+
+   return 0;
+}
+
+int scene_textline_send_key(struct scene *scn, struct scene_obj_textline 
*tline,
+   int key, struct expo_action *event)
+{

[PATCH 27/36] expo: Add some scene fields needed for text entry

2023-09-19 Thread Simon Glass
Add the CLI state, a buffer to hold the old value of the text being
edited and a place to save vidconsole entry context. These will be use
by the textline object.

Set an upper limit on the maximum number of characters in a textline
object supported by expo, at least for now.

Signed-off-by: Simon Glass 
---

 boot/scene.c   | 10 ++
 include/expo.h | 14 ++
 2 files changed, 24 insertions(+)

diff --git a/boot/scene.c b/boot/scene.c
index 314dd7c6e84..0b44a13748a 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -32,6 +32,14 @@ int scene_new(struct expo *exp, const char *name, uint id, 
struct scene **scnp)
return log_msg_ret("name", -ENOMEM);
}
 
+   abuf_init(>buf);
+   if (!abuf_realloc(>buf, EXPO_MAX_CHARS + 1)) {
+   free(scn->name);
+   free(scn);
+   return log_msg_ret("buf", -ENOMEM);
+   }
+   abuf_init(>entry_save);
+
INIT_LIST_HEAD(>obj_head);
scn->id = resolve_id(exp, id);
scn->expo = exp;
@@ -57,6 +65,8 @@ void scene_destroy(struct scene *scn)
list_for_each_entry_safe(obj, next, >obj_head, sibling)
scene_obj_destroy(obj);
 
+   abuf_uninit(>entry_save);
+   abuf_uninit(>buf);
free(scn->name);
free(scn);
 }
diff --git a/include/expo.h b/include/expo.h
index b192d55665a..c470f5be34d 100644
--- a/include/expo.h
+++ b/include/expo.h
@@ -7,11 +7,14 @@
 #ifndef __EXPO_H
 #define __EXPO_H
 
+#include 
 #include 
 #include 
 
 struct udevice;
 
+#include 
+
 /**
  * enum expoact_type - types of actions reported by the expo
  *
@@ -121,6 +124,9 @@ struct expo_string {
  * @id: ID number of the scene
  * @title_id: String ID of title of the scene (allocated)
  * @highlight_id: ID of highlighted object, if any
+ * @cls: cread state to use for input
+ * @buf: Buffer for input
+ * @entry_save: Buffer to hold vidconsole text-entry information
  * @sibling: Node to link this scene to its siblings
  * @obj_head: List of objects in the scene
  */
@@ -130,6 +136,9 @@ struct scene {
uint id;
uint title_id;
uint highlight_id;
+   struct cli_line_state cls;
+   struct abuf buf;
+   struct abuf entry_save;
struct list_head sibling;
struct list_head obj_head;
 };
@@ -180,6 +189,11 @@ enum scene_obj_flags_t {
SCENEOF_OPEN= 1 << 2,
 };
 
+enum {
+   /* Maximum number of characters allowed in an line editor */
+   EXPO_MAX_CHARS  = 250,
+};
+
 /**
  * struct scene_obj - information about an object in a scene
  *
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 26/36] expo: Allow rendering the background of any object

2023-09-19 Thread Simon Glass
So far only menus have a background. When other object types are
rendered, they may have a background too. Make this code more generic
so it will be usable by new object types.

Signed-off-by: Simon Glass 
---

 boot/scene.c  | 40 +++-
 boot/scene_internal.h |  7 ---
 boot/scene_menu.c | 29 -
 3 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/boot/scene.c b/boot/scene.c
index e98676b9387..314dd7c6e84 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -314,6 +314,44 @@ int scene_obj_get_hw(struct scene *scn, uint id, int 
*widthp)
return 0;
 }
 
+/**
+ * scene_render_background() - Render the background for an object
+ *
+ * @obj: Object to render
+ */
+static void scene_render_background(struct scene_obj *obj)
+{
+   struct expo *exp = obj->scene->expo;
+   const struct expo_theme *theme = >theme;
+   struct vidconsole_bbox bbox, label_bbox;
+   struct udevice *dev = exp->display;
+   struct video_priv *vid_priv;
+   struct udevice *cons = exp->cons;
+   struct vidconsole_colour old;
+   enum colour_idx fore, back;
+   uint inset = theme->menu_inset;
+
+   /* draw a background for the object */
+   if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) {
+   fore = VID_BLACK;
+   back = VID_WHITE;
+   } else {
+   fore = VID_LIGHT_GRAY;
+   back = VID_BLACK;
+   }
+
+   /* see if this object wants to render a background */
+   if (scene_obj_calc_bbox(obj, , _bbox))
+   return;
+
+   vidconsole_push_colour(cons, fore, back, );
+   vid_priv = dev_get_uclass_priv(dev);
+   video_fill_part(dev, label_bbox.x0 - inset, label_bbox.y0 - inset,
+   label_bbox.x1 + inset, label_bbox.y1 + inset,
+   vid_priv->colour_fg);
+   vidconsole_pop_colour(cons, );
+}
+
 /**
  * scene_obj_render() - Render an object
  *
@@ -397,7 +435,7 @@ static int scene_obj_render(struct scene_obj *obj, bool 
text_mode)
return -ENOTSUPP;
 
/* draw a background behind the menu items */
-   scene_menu_render(menu);
+   scene_render_background(obj);
}
/*
 * With a vidconsole, the text and item pointer are rendered as
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index 326508874e6..1c2bfeadcd3 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -165,13 +165,6 @@ int scene_render(struct scene *scn);
  */
 int scene_send_key(struct scene *scn, int key, struct expo_action *event);
 
-/**
- * scene_menu_render() - Render the background behind a menu
- *
- * @menu: Menu to render
- */
-void scene_menu_render(struct scene_obj_menu *menu);
-
 /**
  * scene_render_deps() - Render an object and its dependencies
  *
diff --git a/boot/scene_menu.c b/boot/scene_menu.c
index 95c283af4b0..63994165efb 100644
--- a/boot/scene_menu.c
+++ b/boot/scene_menu.c
@@ -516,35 +516,6 @@ int scene_menu_display(struct scene_obj_menu *menu)
return -ENOTSUPP;
 }
 
-void scene_menu_render(struct scene_obj_menu *menu)
-{
-   struct expo *exp = menu->obj.scene->expo;
-   const struct expo_theme *theme = >theme;
-   struct vidconsole_bbox bbox, label_bbox;
-   struct udevice *dev = exp->display;
-   struct video_priv *vid_priv;
-   struct udevice *cons = exp->cons;
-   struct vidconsole_colour old;
-   enum colour_idx fore, back;
-
-   if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) {
-   fore = VID_BLACK;
-   back = VID_WHITE;
-   } else {
-   fore = VID_LIGHT_GRAY;
-   back = VID_BLACK;
-   }
-
-   scene_menu_calc_bbox(menu, , _bbox);
-   vidconsole_push_colour(cons, fore, back, );
-   vid_priv = dev_get_uclass_priv(dev);
-   video_fill_part(dev, label_bbox.x0 - theme->menu_inset,
-   label_bbox.y0 - theme->menu_inset,
-   label_bbox.x1, label_bbox.y1 + theme->menu_inset,
-   vid_priv->colour_fg);
-   vidconsole_pop_colour(cons, );
-}
-
 int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu)
 {
struct scene_menitem *item;
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 25/36] expo: Make calculation of an object bounding box generic

2023-09-19 Thread Simon Glass
We want to support this for any object, not just menus. Move the code
around to allow this.

Signed-off-by: Simon Glass 
---

 boot/scene.c  | 45 +++
 boot/scene_internal.h | 39 +
 boot/scene_menu.c | 39 +++--
 3 files changed, 87 insertions(+), 36 deletions(-)

diff --git a/boot/scene.c b/boot/scene.c
index 4d7cabd75f4..e98676b9387 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -608,6 +608,25 @@ int scene_send_key(struct scene *scn, int key, struct 
expo_action *event)
return 0;
 }
 
+int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox,
+   struct vidconsole_bbox *label_bbox)
+{
+   switch (obj->type) {
+   case SCENEOBJT_NONE:
+   case SCENEOBJT_IMAGE:
+   case SCENEOBJT_TEXT:
+   return -ENOSYS;
+   case SCENEOBJT_MENU: {
+   struct scene_obj_menu *menu = (struct scene_obj_menu *)obj;
+
+   scene_menu_calc_bbox(menu, bbox, label_bbox);
+   break;
+   }
+   }
+
+   return 0;
+}
+
 int scene_calc_dims(struct scene *scn, bool do_menus)
 {
struct scene_obj *obj;
@@ -719,3 +738,29 @@ int scene_iter_objs(struct scene *scn, 
expo_scene_obj_iterator iter,
 
return 0;
 }
+
+int scene_bbox_union(struct scene *scn, uint id, int inset,
+struct vidconsole_bbox *bbox)
+{
+   struct scene_obj *obj;
+
+   if (!id)
+   return 0;
+   obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
+   if (!obj)
+   return log_msg_ret("obj", -ENOENT);
+   if (bbox->valid) {
+   bbox->x0 = min(bbox->x0, obj->dim.x - inset);
+   bbox->y0 = min(bbox->y0, obj->dim.y);
+   bbox->x1 = max(bbox->x1, obj->dim.x + obj->dim.w + inset);
+   bbox->y1 = max(bbox->y1, obj->dim.y + obj->dim.h);
+   } else {
+   bbox->x0 = obj->dim.x - inset;
+   bbox->y0 = obj->dim.y;
+   bbox->x1 = obj->dim.x + obj->dim.w + inset;
+   bbox->y1 = obj->dim.y + obj->dim.h;
+   bbox->valid = true;
+   }
+
+   return 0;
+}
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index 42efcee092f..326508874e6 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -9,6 +9,8 @@
 #ifndef __SCENE_INTERNAL_H
 #define __SCENE_INTERNAL_H
 
+struct vidconsole_bbox;
+
 typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv);
 
 /**
@@ -246,4 +248,41 @@ struct scene_menitem *scene_menuitem_find(const struct 
scene_obj_menu *menu,
 struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu 
*menu,
  uint seq);
 
+/**
+ * scene_bbox_union() - update bouding box with the demensions of an object
+ *
+ * Updates @bbox so that it encompasses the bounding box of object @id
+ *
+ * @snd: Scene containing object
+ * @id: Object id
+ * @inset: Amount of inset to use for width
+ * @bbox: Bounding box to update
+ * Return: 0 if OK, -ve on error
+ */
+int scene_bbox_union(struct scene *scn, uint id, int inset,
+struct vidconsole_bbox *bbox);
+
+/**
+ * scene_menu_calc_bbox() - Calculate bounding boxes for the menu
+ *
+ * @menu: Menu to process
+ * @bbox: Returns bounding box of menu including prompts
+ * @label_bbox: Returns bounding box of labels
+ * Return: 0 if OK, -ve on error
+ */
+void scene_menu_calc_bbox(struct scene_obj_menu *menu,
+ struct vidconsole_bbox *bbox,
+ struct vidconsole_bbox *label_bbox);
+
+/**
+ * scene_obj_calc_bbox() - Calculate bounding boxes for an object
+ *
+ * @obj: Object to process
+ * @bbox: Returns bounding box of object including prompts
+ * @label_bbox: Returns bounding box of labels (active area)
+ * Return: 0 if OK, -ve on error
+ */
+int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox,
+   struct vidconsole_bbox *label_bbox);
+
 #endif /* __SCENE_INTERNAL_H */
diff --git a/boot/scene_menu.c b/boot/scene_menu.c
index e0dcd0a4e04..95c283af4b0 100644
--- a/boot/scene_menu.c
+++ b/boot/scene_menu.c
@@ -114,42 +114,9 @@ static void menu_point_to_item(struct scene_obj_menu 
*menu, uint item_id)
update_pointers(menu, item_id, true);
 }
 
-static int scene_bbox_union(struct scene *scn, uint id, int inset,
-   struct vidconsole_bbox *bbox)
-{
-   struct scene_obj *obj;
-
-   if (!id)
-   return 0;
-   obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
-   if (!obj)
-   return log_msg_ret("obj", -ENOENT);
-   if (bbox->valid) {
-   bbox->x0 = min(bbox->x0, obj->dim.x - inset);
-   bbox->y0 = min(bbox->y0, obj->dim.y);
-   bbox->x1 = max(bbox->x1, obj->dim.x + obj->dim.w + inset);
-   bbox->y1 = 

[PATCH 24/36] expo: Add a function to write a property to a devicetree

2023-09-19 Thread Simon Glass
When the devicetree is too small for the property being written, we need
to expand the devicetree and retry the write.

Put this logic into a function so it can be reused.

Signed-off-by: Simon Glass 
---

 boot/cedit.c | 38 ++
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/boot/cedit.c b/boot/cedit.c
index b7329c3245e..bb194af77bd 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -269,6 +269,28 @@ static int get_cur_menuitem_text(const struct 
scene_obj_menu *menu,
return 0;
 }
 
+static int write_dt_string(struct abuf *buf, const char *name, const char *str)
+{
+   int ret, i;
+
+   /* write the text of the current item */
+   ret = -EAGAIN;
+   for (i = 0; ret && i < 2; i++) {
+   ret = fdt_property_string(abuf_data(buf), name, str);
+   if (!i) {
+   ret = check_space(ret, buf);
+   if (ret)
+   return log_msg_ret("rs2", -ENOMEM);
+   }
+   }
+
+   /* this should not happen */
+   if (ret)
+   return log_msg_ret("str", -EFAULT);
+
+   return 0;
+}
+
 static int h_write_settings(struct scene_obj *obj, void *vpriv)
 {
struct cedit_iter_priv *priv = vpriv;
@@ -285,6 +307,7 @@ static int h_write_settings(struct scene_obj *obj, void 
*vpriv)
char name[80];
int ret, i;
 
+   /* write the ID of the current item */
menu = (struct scene_obj_menu *)obj;
ret = -EAGAIN;
for (i = 0; ret && i < 2; i++) {
@@ -304,20 +327,11 @@ static int h_write_settings(struct scene_obj *obj, void 
*vpriv)
if (ret)
return log_msg_ret("mis", ret);
 
+   /* write the text of the current item */
snprintf(name, sizeof(name), "%s-str", obj->name);
-   ret = -EAGAIN;
-   for (i = 0; ret && i < 2; i++) {
-   ret = fdt_property_string(abuf_data(buf), name, str);
-   if (!i) {
-   ret = check_space(ret, buf);
-   if (ret)
-   return log_msg_ret("rs2", -ENOMEM);
-   }
-   }
-
-   /* this should not happen */
+   ret = write_dt_string(buf, name, str);
if (ret)
-   return log_msg_ret("wr2", -EFAULT);
+   return log_msg_ret("wr2", ret);
 
break;
}
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 23/36] expo: Allow highlighting other scene-object types

2023-09-19 Thread Simon Glass
So far only menus can be highlighted. With the coming addition of
text lines we need to be able to highlight other objects. Add a function
to determine whether an object can be highlighted.

Signed-off-by: Simon Glass 
---

 boot/scene.c   | 11 ---
 include/expo.h |  8 
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/boot/scene.c b/boot/scene.c
index 8e5d3aa7dc0..4d7cabd75f4 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -516,7 +516,7 @@ static void send_key_obj(struct scene *scn, struct 
scene_obj *obj, int key,
   sibling)) {
obj = list_entry(obj->sibling.prev,
 struct scene_obj, sibling);
-   if (obj->type == SCENEOBJT_MENU) {
+   if (scene_obj_can_highlight(obj)) {
event->type = EXPOACT_POINT_OBJ;
event->select.id = obj->id;
log_debug("up to obj %d\n", event->select.id);
@@ -528,7 +528,7 @@ static void send_key_obj(struct scene *scn, struct 
scene_obj *obj, int key,
while (!list_is_last(>sibling, >obj_head)) {
obj = list_entry(obj->sibling.next, struct scene_obj,
 sibling);
-   if (obj->type == SCENEOBJT_MENU) {
+   if (scene_obj_can_highlight(obj)) {
event->type = EXPOACT_POINT_OBJ;
event->select.id = obj->id;
log_debug("down to obj %d\n", event->select.id);
@@ -537,7 +537,7 @@ static void send_key_obj(struct scene *scn, struct 
scene_obj *obj, int key,
}
break;
case BKEY_SELECT:
-   if (obj->type == SCENEOBJT_MENU) {
+   if (scene_obj_can_highlight(obj)) {
event->type = EXPOACT_OPEN;
event->select.id = obj->id;
log_debug("open obj %d\n", event->select.id);
@@ -685,12 +685,9 @@ void scene_highlight_first(struct scene *scn)
struct scene_obj *obj;
 
list_for_each_entry(obj, >obj_head, sibling) {
-   switch (obj->type) {
-   case SCENEOBJT_MENU:
+   if (scene_obj_can_highlight(obj)) {
scene_set_highlight_id(scn, obj->id);
return;
-   default:
-   break;
}
}
 }
diff --git a/include/expo.h b/include/expo.h
index 297d892de8e..b192d55665a 100644
--- a/include/expo.h
+++ b/include/expo.h
@@ -146,6 +146,8 @@ enum scene_obj_t {
SCENEOBJT_NONE  = 0,
SCENEOBJT_IMAGE,
SCENEOBJT_TEXT,
+
+   /* types from here on can be highlighted */
SCENEOBJT_MENU,
 };
 
@@ -203,6 +205,12 @@ struct scene_obj {
struct list_head sibling;
 };
 
+/* object can be highlighted when moving around expo */
+static inline bool scene_obj_can_highlight(const struct scene_obj *obj)
+{
+   return obj->type >= SCENEOBJT_MENU;
+}
+
 /**
  * struct scene_obj_img - information about an image object in a scene
  *
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 22/36] expo: Correct the logic for duplicate-ID detection

2023-09-19 Thread Simon Glass
Update scene_txt_str() to account for the possibility that the passed-in
str_id may be 0

Signed-off-by: Simon Glass 
---

 boot/scene.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/boot/scene.c b/boot/scene.c
index 9c4466c1a47..8e5d3aa7dc0 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -176,8 +176,9 @@ int scene_txt_str(struct scene *scn, const char *name, uint 
id, uint str_id,
ret = expo_str(scn->expo, name, str_id, str);
if (ret < 0)
return log_msg_ret("str", ret);
-   else if (ret != str_id)
+   if (str_id && ret != str_id)
return log_msg_ret("id", -EEXIST);
+   str_id = ret;
 
ret = scene_obj_add(scn, name, id, SCENEOBJT_TEXT,
sizeof(struct scene_obj_txt),
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 21/36] expo: Correct some swallowed errors in scene

2023-09-19 Thread Simon Glass
Return the reported error, rather than assuming it is -ENOMEM

Signed-off-by: Simon Glass 
---

 boot/scene.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/boot/scene.c b/boot/scene.c
index 08ed85e9188..9c4466c1a47 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -137,7 +137,7 @@ int scene_img(struct scene *scn, const char *name, uint id, 
char *data,
sizeof(struct scene_obj_img),
(struct scene_obj **));
if (ret < 0)
-   return log_msg_ret("obj", -ENOMEM);
+   return log_msg_ret("obj", ret);
 
img->data = data;
 
@@ -157,7 +157,7 @@ int scene_txt(struct scene *scn, const char *name, uint id, 
uint str_id,
sizeof(struct scene_obj_txt),
(struct scene_obj **));
if (ret < 0)
-   return log_msg_ret("obj", -ENOMEM);
+   return log_msg_ret("obj", ret);
 
txt->str_id = str_id;
 
@@ -183,7 +183,7 @@ int scene_txt_str(struct scene *scn, const char *name, uint 
id, uint str_id,
sizeof(struct scene_obj_txt),
(struct scene_obj **));
if (ret < 0)
-   return log_msg_ret("obj", -ENOMEM);
+   return log_msg_ret("obj", ret);
 
txt->str_id = str_id;
 
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 20/36] expo: Use switch statements more for object types

2023-09-19 Thread Simon Glass
In a lot of cases menus are the only objects which are have their own
behaviour in the cedit, e.g. to move between menus. With expo expanding
to support text, this is no-longer true.

Use a switch() statement so that we can simply insert a new 'case' for
the new object types.

Signed-off-by: Simon Glass 
---

 boot/cedit.c | 88 +++-
 boot/scene.c | 38 ++-
 2 files changed, 83 insertions(+), 43 deletions(-)

diff --git a/boot/cedit.c b/boot/cedit.c
index 1324a861998..b7329c3245e 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -71,10 +71,16 @@ int cedit_arange(struct expo *exp, struct video_priv 
*vpriv, uint scene_id)
 
y = 100;
list_for_each_entry(obj, >obj_head, sibling) {
-   if (obj->type == SCENEOBJT_MENU) {
+   switch (obj->type) {
+   case SCENEOBJT_NONE:
+   case SCENEOBJT_IMAGE:
+   case SCENEOBJT_TEXT:
+   break;
+   case SCENEOBJT_MENU:
scene_obj_set_pos(scn, obj->id, 50, y);
scene_menu_arrange(scn, (struct scene_obj_menu *)obj);
y += 50;
+   break;
}
}
 
@@ -422,31 +428,37 @@ static int h_write_settings_env(struct scene_obj *obj, 
void *vpriv)
const char *str;
int val, ret;
 
-   if (obj->type != SCENEOBJT_MENU)
-   return 0;
-
-   menu = (struct scene_obj_menu *)obj;
-   val = menu->cur_item_id;
snprintf(var, sizeof(var), "c.%s", obj->name);
 
-   if (priv->verbose)
-   printf("%s=%d\n", var, val);
+   switch (obj->type) {
+   case SCENEOBJT_NONE:
+   case SCENEOBJT_IMAGE:
+   case SCENEOBJT_TEXT:
+   break;
+   case SCENEOBJT_MENU:
+   menu = (struct scene_obj_menu *)obj;
+   val = menu->cur_item_id;
 
-   ret = env_set_ulong(var, val);
-   if (ret)
-   return log_msg_ret("set", ret);
+   if (priv->verbose)
+   printf("%s=%d\n", var, val);
 
-   ret = get_cur_menuitem_text(menu, );
-   if (ret)
-   return log_msg_ret("mis", ret);
+   ret = env_set_ulong(var, val);
+   if (ret)
+   return log_msg_ret("set", ret);
 
-   snprintf(name, sizeof(name), "c.%s-str", obj->name);
-   if (priv->verbose)
-   printf("%s=%s\n", name, str);
+   ret = get_cur_menuitem_text(menu, );
+   if (ret)
+   return log_msg_ret("mis", ret);
 
-   ret = env_set(name, str);
-   if (ret)
-   return log_msg_ret("st2", ret);
+   snprintf(name, sizeof(name), "c.%s-str", obj->name);
+   if (priv->verbose)
+   printf("%s=%s\n", name, str);
+
+   ret = env_set(name, str);
+   if (ret)
+   return log_msg_ret("st2", ret);
+   break;
+   }
 
return 0;
 }
@@ -474,24 +486,28 @@ static int h_read_settings_env(struct scene_obj *obj, 
void *vpriv)
char var[60];
int val;
 
-   if (obj->type != SCENEOBJT_MENU)
-   return 0;
-
-   menu = (struct scene_obj_menu *)obj;
-   val = menu->cur_item_id;
snprintf(var, sizeof(var), "c.%s", obj->name);
 
-   val = env_get_ulong(var, 10, 0);
-   if (priv->verbose)
-   printf("%s=%d\n", var, val);
-   if (!val)
-   return log_msg_ret("get", -ENOENT);
-
-   /*
-* note that no validation is done here, to make sure the ID is valid
-* and actually points to a menu item
-*/
-   menu->cur_item_id = val;
+   switch (obj->type) {
+   case SCENEOBJT_NONE:
+   case SCENEOBJT_IMAGE:
+   case SCENEOBJT_TEXT:
+   break;
+   case SCENEOBJT_MENU:
+   menu = (struct scene_obj_menu *)obj;
+   val = env_get_ulong(var, 10, 0);
+   if (priv->verbose)
+   printf("%s=%d\n", var, val);
+   if (!val)
+   return log_msg_ret("get", -ENOENT);
+
+   /*
+* note that no validation is done here, to make sure the ID is
+* valid * and actually points to a menu item
+*/
+   menu->cur_item_id = val;
+   break;
+   }
 
return 0;
 }
diff --git a/boot/scene.c b/boot/scene.c
index 6c52948eb69..08ed85e9188 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -423,13 +423,20 @@ int scene_arrange(struct scene *scn)
int ret;
 
list_for_each_entry(obj, >obj_head, sibling) {
-   if (obj->type == SCENEOBJT_MENU) {
+   switch (obj->type) {
+   case SCENEOBJT_NONE:
+   case SCENEOBJT_IMAGE:
+   case SCENEOBJT_TEXT:
+   

[PATCH 19/36] expo: Fix up comments for get_cur_menuitem_text() et al

2023-09-19 Thread Simon Glass
This internal function could use a comment. Add one.

Also tidy up a few other comments.

Signed-off-by: Simon Glass 

fixup: comments
---

 boot/cedit.c  | 10 ++
 boot/scene_internal.h |  2 +-
 include/expo.h|  2 +-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/boot/cedit.c b/boot/cedit.c
index 73645f70b6c..1324a861998 100644
--- a/boot/cedit.c
+++ b/boot/cedit.c
@@ -229,6 +229,16 @@ static int check_space(int ret, struct abuf *buf)
return 0;
 }
 
+/**
+ * get_cur_menuitem_text() - Get the text of the currently selected item
+ *
+ * Looks up the object for the current item, finds text object for it and looks
+ * up the string for that text
+ *
+ * @menu: Menu to look at
+ * @strp: Returns a pointer to the next
+ * Return: 0 if OK, -ENOENT if something was not found
+ */
 static int get_cur_menuitem_text(const struct scene_obj_menu *menu,
 const char **strp)
 {
diff --git a/boot/scene_internal.h b/boot/scene_internal.h
index 695a907dc6a..42efcee092f 100644
--- a/boot/scene_internal.h
+++ b/boot/scene_internal.h
@@ -185,7 +185,7 @@ int scene_render_deps(struct scene *scn, uint id);
  * Renders the menu and all of its attached objects
  *
  * @scn: Scene to render
- * @menu: Menu render
+ * @menu: Menu to render
  * Returns: 0 if OK, -ve on error
  */
 int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu);
diff --git a/include/expo.h b/include/expo.h
index a2b3a71c159..297d892de8e 100644
--- a/include/expo.h
+++ b/include/expo.h
@@ -505,7 +505,7 @@ int scene_txt(struct scene *scn, const char *name, uint id, 
uint str_id,
  struct scene_obj_txt **txtp);
 
 /**
- * scene_txt_str() - add a new string to expr and text object to a scene
+ * scene_txt_str() - add a new string to expo and text object to a scene
  *
  * @scn: Scene to update
  * @name: Name to use (this is allocated by this call)
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 18/36] expo: Add better error reporting

2023-09-19 Thread Simon Glass
When building an expo fails, show some information about which node
caused the problem. Use -ENOENT consistently when the ID is missing.
This makes it easier for the user to debug things.

Signed-off-by: Simon Glass 
---

 boot/expo_build.c | 58 +--
 1 file changed, 46 insertions(+), 12 deletions(-)

diff --git a/boot/expo_build.c b/boot/expo_build.c
index bb33cc2a33f..48ed31d5b32 100644
--- a/boot/expo_build.c
+++ b/boot/expo_build.c
@@ -23,10 +23,14 @@
  * if there is nothing for this ID. Since ID 0 is never used, the first
  * element of this array is always NULL
  * @str_count: Number of entries in @str_for_id
+ * @err_node: Node being processed (for error reporting)
+ * @err_prop: Property being processed (for error reporting)
  */
 struct build_info {
const char **str_for_id;
int str_count;
+   ofnode err_node;
+   const char *err_prop;
 };
 
 /**
@@ -46,6 +50,7 @@ int add_txt_str(struct build_info *info, ofnode node, struct 
scene *scn,
uint str_id;
int ret;
 
+   info->err_prop = find_name;
text = ofnode_read_string(node, find_name);
if (!text) {
char name[40];
@@ -54,7 +59,7 @@ int add_txt_str(struct build_info *info, ofnode node, struct 
scene *scn,
snprintf(name, sizeof(name), "%s-id", find_name);
ret = ofnode_read_u32(node, name, );
if (ret)
-   return log_msg_ret("id", -EINVAL);
+   return log_msg_ret("id", -ENOENT);
 
if (id >= info->str_count)
return log_msg_ret("id", -E2BIG);
@@ -164,9 +169,10 @@ static int read_strings(struct build_info *info, ofnode 
root)
int ret;
u32 id;
 
+   info->err_node = node;
ret = ofnode_read_u32(node, "id", );
if (ret)
-   return log_msg_ret("id", -EINVAL);
+   return log_msg_ret("id", -ENOENT);
val = ofnode_read_string(node, "value");
if (!val)
return log_msg_ret("val", -EINVAL);
@@ -241,6 +247,8 @@ static int menu_build(struct build_info *info, ofnode node, 
struct scene *scn,
return log_msg_ret("tit", ret);
title_id = ret;
ret = scene_menu_set_title(scn, menu_id, title_id);
+   if (ret)
+   return log_msg_ret("set", ret);
 
item_ids = ofnode_read_prop(node, "item-id", );
if (!item_ids)
@@ -300,7 +308,7 @@ static int obj_build(struct build_info *info, ofnode node, 
struct scene *scn)
log_debug("- object %s\n", ofnode_get_name(node));
ret = ofnode_read_u32(node, "id", );
if (ret)
-   return log_msg_ret("id", -EINVAL);
+   return log_msg_ret("id", -ENOENT);
 
type = ofnode_read_string(node, "type");
if (!type)
@@ -308,8 +316,8 @@ static int obj_build(struct build_info *info, ofnode node, 
struct scene *scn)
 
if (!strcmp("menu", type))
ret = menu_build(info, node, scn, id, );
-else
-   ret = -EINVAL;
+   else
+   ret = -EOPNOTSUPP;
if (ret)
return log_msg_ret("bld", ret);
 
@@ -341,11 +349,12 @@ static int scene_build(struct build_info *info, ofnode 
scn_node,
ofnode node;
int ret;
 
+   info->err_node = scn_node;
name = ofnode_get_name(scn_node);
log_debug("Building scene %s\n", name);
ret = ofnode_read_u32(scn_node, "id", );
if (ret)
-   return log_msg_ret("id", -EINVAL);
+   return log_msg_ret("id", -ENOENT);
 
ret = scene_new(exp, name, id, );
if (ret < 0)
@@ -362,6 +371,7 @@ static int scene_build(struct build_info *info, ofnode 
scn_node,
return log_msg_ret("pr", ret);
 
ofnode_for_each_subnode(node, scn_node) {
+   info->err_node = node;
ret = obj_build(info, node, scn);
if (ret < 0)
return log_msg_ret("mit", ret);
@@ -370,20 +380,20 @@ static int scene_build(struct build_info *info, ofnode 
scn_node,
return 0;
 }
 
-int expo_build(ofnode root, struct expo **expp)
+int build_it(struct build_info *info, ofnode root, struct expo **expp)
 {
-   struct build_info info;
+   ;
ofnode scenes, node;
struct expo *exp;
u32 dyn_start;
int ret;
 
-   memset(, '\0', sizeof(info));
-   ret = read_strings(, root);
+   ret = read_strings(info, root);
if (ret)
return log_msg_ret("str", ret);
if (_DEBUG)
-   list_strings();
+   list_strings(info);
+   info->err_node = root;
 
ret = expo_new("name", NULL, );
if (ret)
@@ -397,7 +407,7 @@ int expo_build(ofnode root, struct expo **expp)
return log_msg_ret("sno", 

[PATCH 17/36] video: Support showing a cursor

2023-09-19 Thread Simon Glass
Add rudimentary support for displaying a cursor on a vidconsole. This
helps the user to see where text is being entered.

The implementation so far is very simple: the cursor is just a vertical
bar of fixed width and cannot be erased. To erase the cursor, the text
must be redrawn over it.

This is good enough for expo but will need enhancement to be useful for
the command-line console. For example, it could save and restore the
area behind the cursor.

For now, enable this only for expo, to reduce code size.

Signed-off-by: Simon Glass 
---

 drivers/video/console_core.c|  31 +
 drivers/video/console_normal.c  |  29 
 drivers/video/console_truetype.c| 103 
 drivers/video/vidconsole-uclass.c   |  15 
 drivers/video/vidconsole_internal.h |  24 +++
 include/video_console.h |  35 ++
 6 files changed, 237 insertions(+)

diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index b5d0e3dceca..d17764d0b08 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -176,6 +176,37 @@ int fill_char_horizontally(uchar *pfont, void **line, 
struct video_priv *vid_pri
return ret;
 }
 
+int draw_cursor_vertically(void **line, struct video_priv *vid_priv,
+  uint height, bool direction)
+{
+   int step, line_step, pbytes, ret;
+   uint value;
+   void *dst;
+
+   ret = check_bpix_support(vid_priv->bpix);
+   if (ret)
+   return ret;
+
+   pbytes = VNBYTES(vid_priv->bpix);
+   if (direction) {
+   step = -pbytes;
+   line_step = -vid_priv->line_length;
+   } else {
+   step = pbytes;
+   line_step = vid_priv->line_length;
+   }
+
+   value = vid_priv->colour_fg;
+
+   for (int row = 0; row < height; row++) {
+   dst = *line;
+   for (int col = 0; col < VIDCONSOLE_CURSOR_WIDTH; col++)
+   fill_pixel_and_goto_next(, value, pbytes, step);
+   *line += line_step;
+   }
+   return ret;
+}
+
 int console_probe(struct udevice *dev)
 {
return console_set_font(dev, fonts);
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 413c7abee9e..a0231293f31 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -97,6 +97,34 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, 
uint y, char ch)
return VID_TO_POS(fontdata->width);
 }
 
+static int console_set_cursor_visible(struct udevice *dev, bool visible,
+ uint x, uint y, uint index)
+{
+   struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+   struct udevice *vid = dev->parent;
+   struct video_priv *vid_priv = dev_get_uclass_priv(vid);
+   struct console_simple_priv *priv = dev_get_priv(dev);
+   struct video_fontdata *fontdata = priv->fontdata;
+   int pbytes = VNBYTES(vid_priv->bpix);
+   void *start, *line;
+
+   /* for now, this is not used outside expo */
+   if (!IS_ENABLED(CONFIG_EXPO))
+   return -ENOSYS;
+
+   x += index * fontdata->width;
+   start = vid_priv->fb + y * vid_priv->line_length + x * pbytes;
+
+   /* place the cursor 1 pixel before the start of the next char */
+   x -= 1;
+
+   line = start;
+   draw_cursor_vertically(, vid_priv, vc_priv->y_charsize,
+  NORMAL_DIRECTION);
+
+   return 0;
+}
+
 struct vidconsole_ops console_ops = {
.putc_xy= console_putc_xy,
.move_rows  = console_move_rows,
@@ -104,6 +132,7 @@ struct vidconsole_ops console_ops = {
.get_font_size  = console_simple_get_font_size,
.get_font   = console_simple_get_font,
.select_font= console_simple_select_font,
+   .set_cursor_visible = console_set_cursor_visible,
 };
 
 U_BOOT_DRIVER(vidconsole_normal) = {
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 1ce01a96bb6..242b8b71342 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -831,6 +831,108 @@ static int truetype_entry_restore(struct udevice *dev, 
struct abuf *buf)
return 0;
 }
 
+static int truetype_set_cursor_visible(struct udevice *dev, bool visible,
+  uint x, uint y, uint index)
+{
+   struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+   struct udevice *vid = dev->parent;
+   struct video_priv *vid_priv = dev_get_uclass_priv(vid);
+   struct console_tt_priv *priv = dev_get_priv(dev);
+   struct console_tt_metrics *met = priv->cur_met;
+   uint row, width, height, xoff;
+   void *start, *line;
+   uint out, val;
+   int ret;
+
+   if (!visible)
+   return 0;
+
+   /*
+* figure out where to place the cursor. This driver ignores the

[PATCH 16/36] video: Export vidconsole_entry_start()

2023-09-19 Thread Simon Glass
At present this is called only when a newline is detected, since this
indicates the start of a line of text being entered.

Export this function so it can be used by expo, which may start a new
text line itself, without first writing out a newline.

Signed-off-by: Simon Glass 
---

 drivers/video/vidconsole-uclass.c | 2 +-
 include/video_console.h   | 9 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/video/vidconsole-uclass.c 
b/drivers/video/vidconsole-uclass.c
index 07427ba346b..2f3f685a55c 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -48,7 +48,7 @@ int vidconsole_set_row(struct udevice *dev, uint row, int clr)
return ops->set_row(dev, row, clr);
 }
 
-static int vidconsole_entry_start(struct udevice *dev)
+int vidconsole_entry_start(struct udevice *dev)
 {
struct vidconsole_ops *ops = vidconsole_get_ops(dev);
 
diff --git a/include/video_console.h b/include/video_console.h
index 28d65451889..87f9a588575 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -399,6 +399,15 @@ int vidconsole_move_rows(struct udevice *dev, uint rowdst, 
uint rowsrc,
  */
 int vidconsole_set_row(struct udevice *dev, uint row, int clr);
 
+/**
+ * vidconsole_entry_start() - Set the start position of a vidconsole line
+ *
+ * Marks the current cursor position as the start of a line
+ *
+ * @dev:   Device to adjust
+ */
+int vidconsole_entry_start(struct udevice *dev);
+
 /**
  * vidconsole_put_char() - Output a character to the current console position
  *
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 15/36] video: Allow saving and restoring text-entry state

2023-09-19 Thread Simon Glass
Text entry operates within a context which includes quite a bit of
information. For example, with Truetype fonts, each character in the
text string has a position stored, so that it is possible to
backspace to that character. This information is built up as strings
are drawn on the display.

For the command line, there is just a single context. It is created
when command-line entry starts and it is destroyed (or at least not
needed anymore) when the user presses  to enter the command.

By contrast, expo needs to be able to switch in and out of a text-entry
context, since it is also displaying other objects in the scene.

Add a way to save and restore the entry context for a vidconsole. This
is only needed for the truetype vidconsole, so add a method for that,
storing the information in an abuf struct.

Signed-off-by: Simon Glass 
---

 drivers/video/console_truetype.c  | 53 +++
 drivers/video/vidconsole-uclass.c | 32 +++
 include/video_console.h   | 49 
 3 files changed, 134 insertions(+)

diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 8ed79c37676..1ce01a96bb6 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -175,6 +176,17 @@ struct console_tt_priv {
int pos_ptr;
 };
 
+/**
+ * struct console_tt_store - Format used for save/restore of entry information
+ *
+ * @priv: Private data
+ * @cur: Current cursor position
+ */
+struct console_tt_store {
+   struct console_tt_priv priv;
+   struct pos_info cur;
+};
+
 static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
 {
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
@@ -780,6 +792,45 @@ static int truetype_nominal(struct udevice *dev, const 
char *name, uint size,
return 0;
 }
 
+static int truetype_entry_save(struct udevice *dev, struct abuf *buf)
+{
+   struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+   struct console_tt_priv *priv = dev_get_priv(dev);
+   struct console_tt_store store;
+   const uint size = sizeof(store);
+
+   /*
+* store the whole priv structure as it is simpler that picking out
+* what we need
+*/
+   if (!abuf_realloc(buf, size))
+   return log_msg_ret("sav", -ENOMEM);
+
+   store.priv = *priv;
+   store.cur.xpos_frac = vc_priv->xcur_frac;
+   store.cur.ypos  = vc_priv->ycur;
+   memcpy(abuf_data(buf), , size);
+
+   return 0;
+}
+
+static int truetype_entry_restore(struct udevice *dev, struct abuf *buf)
+{
+   struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+   struct console_tt_priv *priv = dev_get_priv(dev);
+   struct console_tt_store store;
+
+   memcpy(, abuf_data(buf), sizeof(store));
+
+   vc_priv->xcur_frac = store.cur.xpos_frac;
+   vc_priv->ycur = store.cur.ypos;
+   priv->pos_ptr = store.priv.pos_ptr;
+   memcpy(priv->pos, store.priv.pos,
+  store.priv.pos_ptr * sizeof(struct pos_info));
+
+   return 0;
+}
+
 const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep)
 {
struct console_tt_priv *priv = dev_get_priv(dev);
@@ -833,6 +884,8 @@ struct vidconsole_ops console_truetype_ops = {
.select_font= truetype_select_font,
.measure= truetype_measure,
.nominal= truetype_nominal,
+   .entry_save = truetype_entry_save,
+   .entry_restore  = truetype_entry_restore,
 };
 
 U_BOOT_DRIVER(vidconsole_truetype) = {
diff --git a/drivers/video/vidconsole-uclass.c 
b/drivers/video/vidconsole-uclass.c
index 23b1b81731b..07427ba346b 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -10,6 +10,7 @@
 #define LOG_CATEGORY UCLASS_VIDEO_CONSOLE
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -640,6 +641,37 @@ int vidconsole_nominal(struct udevice *dev, const char 
*name, uint size,
return 0;
 }
 
+int vidconsole_entry_save(struct udevice *dev, struct abuf *buf)
+{
+   struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+   int ret;
+
+   if (ops->measure) {
+   ret = ops->entry_save(dev, buf);
+   if (ret != -ENOSYS)
+   return ret;
+   }
+
+   /* no data so make sure the buffer is empty */
+   abuf_realloc(buf, 0);
+
+   return 0;
+}
+
+int vidconsole_entry_restore(struct udevice *dev, struct abuf *buf)
+{
+   struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+   int ret;
+
+   if (ops->measure) {
+   ret = ops->entry_restore(dev, buf);
+   if (ret != -ENOSYS)
+   return ret;
+   }
+
+   return 0;
+}
+
 void vidconsole_push_colour(struct udevice *dev, enum colour_idx fg,
enum colour_idx 

[PATCH 14/36] video: Allow obtaining the nominal size of a string size

2023-09-19 Thread Simon Glass
At present there is a method for measuring text, but if the actual text
string is not known, it cannot be used.

For text editor we want to set the size of the entry box to cover the
expected text size. Add the concept of a 'norminal' size with a method
to calculate that for the vidconsole.

If the method is not implemented, fall back to using the font size,
which is sufficient for fixed-width fonts.

Signed-off-by: Simon Glass 
---

 drivers/video/console_truetype.c  | 31 +++
 drivers/video/vidconsole-uclass.c | 22 ++
 include/video_console.h   | 30 ++
 3 files changed, 83 insertions(+)

diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 0f9bb49e44f..8ed79c37676 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -750,6 +750,36 @@ int truetype_measure(struct udevice *dev, const char 
*name, uint size,
return 0;
 }
 
+static int truetype_nominal(struct udevice *dev, const char *name, uint size,
+   uint num_chars, struct vidconsole_bbox *bbox)
+{
+   struct console_tt_metrics *met;
+   stbtt_fontinfo *font;
+   int lsb, advance;
+   int width;
+   int ret;
+
+   ret = get_metrics(dev, name, size, );
+   if (ret)
+   return log_msg_ret("sel", ret);
+
+   font = >font;
+   width = 0;
+
+   /* First get some basic metrics about this character */
+   stbtt_GetCodepointHMetrics(font, 'W', , );
+
+   width = advance;
+
+   bbox->valid = true;
+   bbox->x0 = 0;
+   bbox->y0 = 0;
+   bbox->x1 = tt_ceil((double)width * num_chars * met->scale);
+   bbox->y1 = met->font_size;
+
+   return 0;
+}
+
 const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep)
 {
struct console_tt_priv *priv = dev_get_priv(dev);
@@ -802,6 +832,7 @@ struct vidconsole_ops console_truetype_ops = {
.get_font_size  = console_truetype_get_font_size,
.select_font= truetype_select_font,
.measure= truetype_measure,
+   .nominal= truetype_nominal,
 };
 
 U_BOOT_DRIVER(vidconsole_truetype) = {
diff --git a/drivers/video/vidconsole-uclass.c 
b/drivers/video/vidconsole-uclass.c
index b5b3b662590..23b1b81731b 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -618,6 +618,28 @@ int vidconsole_measure(struct udevice *dev, const char 
*name, uint size,
return 0;
 }
 
+int vidconsole_nominal(struct udevice *dev, const char *name, uint size,
+  uint num_chars, struct vidconsole_bbox *bbox)
+{
+   struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+   struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+   int ret;
+
+   if (ops->measure) {
+   ret = ops->nominal(dev, name, size, num_chars, bbox);
+   if (ret != -ENOSYS)
+   return ret;
+   }
+
+   bbox->valid = true;
+   bbox->x0 = 0;
+   bbox->y0 = 0;
+   bbox->x1 = priv->x_charsize * num_chars;
+   bbox->y1 = priv->y_charsize;
+
+   return 0;
+}
+
 void vidconsole_push_colour(struct udevice *dev, enum colour_idx fg,
enum colour_idx bg, struct vidconsole_colour *old)
 {
diff --git a/include/video_console.h b/include/video_console.h
index 2694e44f6ec..5234c85efd6 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -224,6 +224,21 @@ struct vidconsole_ops {
 */
int (*measure)(struct udevice *dev, const char *name, uint size,
   const char *text, struct vidconsole_bbox *bbox);
+
+   /**
+* nominal() - Measure the expected width of a line of text
+*
+* Uses an average font width and nominal height
+*
+* @dev: Console device to use
+* @name: Font name, NULL for default
+* @size: Font size, ignored if @name is NULL
+* @num_chars: Number of characters to use
+* @bbox: Returns nounding box of @num_chars characters
+* Returns: 0 if OK, -ve on error
+*/
+   int (*nominal)(struct udevice *dev, const char *name, uint size,
+  uint num_chars, struct vidconsole_bbox *bbox);
 };
 
 /* Get a pointer to the driver operations for a video console device */
@@ -263,6 +278,21 @@ int vidconsole_select_font(struct udevice *dev, const char 
*name, uint size);
 int vidconsole_measure(struct udevice *dev, const char *name, uint size,
   const char *text, struct vidconsole_bbox *bbox);
 
+/**
+ * vidconsole_nominal() - Measure the expected width of a line of text
+ *
+ * Uses an average font width and nominal height
+ *
+ * @dev: Console device to use
+ * @name: Font name, NULL for default
+ * @size: Font size, ignored if @name is NULL
+ * @num_chars: Number of characters to use
+ * @bbox: Returns nounding box of 

[PATCH 13/36] cli: Add a function to set up a new cread

2023-09-19 Thread Simon Glass
Create a init function so that it is easy to use command-line reading.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 24 +++-
 include/cli.h | 17 -
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index 23913a857a9..06b8d465044 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -424,28 +424,34 @@ int cread_line_process_ch(struct cli_line_state *cls, 
char ichar)
return -EAGAIN;
 }
 
+void cli_cread_init(struct cli_line_state *cls, char *buf, uint buf_size)
+{
+   int init_len = strlen(buf);
+
+   memset(cls, '\0', sizeof(struct cli_line_state));
+   cls->insert = true;
+   cls->buf = buf;
+   cls->len = buf_size;
+
+   if (init_len)
+   cread_add_str(buf, init_len, 0, >num, >eol_num, buf,
+ buf_size);
+}
+
 static int cread_line(const char *const prompt, char *buf, unsigned int *len,
  int timeout)
 {
struct cli_ch_state s_cch, *cch = _cch;
struct cli_line_state s_cls, *cls = _cls;
char ichar;
-   int init_len = strlen(buf);
int first = 1;
 
cli_ch_init(cch);
-   memset(cls, '\0', sizeof(struct cli_line_state));
-   cls->insert = true;
-   cls->len = *len;
+   cli_cread_init(cls, buf, *len);
cls->prompt = prompt;
-   cls->buf = buf;
cls->history = true;
cls->cmd_complete = true;
 
-   if (init_len)
-   cread_add_str(buf, init_len, 1, >num, >eol_num, buf,
- *len);
-
while (1) {
int ret;
 
diff --git a/include/cli.h b/include/cli.h
index ad3cb4499fe..e183d561369 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -32,7 +32,8 @@ struct cli_ch_state {
  * @eol_num: Number of characters in the buffer
  * @insert: true if in 'insert' mode
  * @history: true if history should be accessible
- * @cmd_complete: true if tab completion should be enabled
+ * @cmd_complete: true if tab completion should be enabled (requires @prompt to
+ * be set)
  * @buf: Buffer containing line
  * @prompt: Prompt for the line
  */
@@ -262,6 +263,20 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar);
  */
 int cread_line_process_ch(struct cli_line_state *cls, char ichar);
 
+/**
+ * cli_cread_init() - Set up a new cread struct
+ *
+ * Sets up a new cread state, with history and cmd_complete set to false
+ *
+ * After calling this, you can use cread_line_process_ch() to process 
characters
+ * received from the user.
+ *
+ * @cls: CLI line state
+ * @buf: Text buffer containing the initial text
+ * @buf_size: Buffer size, including nul terminator
+ */
+void cli_cread_init(struct cli_line_state *cls, char *buf, uint buf_size);
+
 /** cread_print_hist_list() - Print the command-line history list */
 void cread_print_hist_list(void);
 
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 12/36] cli: Allow command completion to be disabled

2023-09-19 Thread Simon Glass
When inputting text outside the command line we don't want to use tab
for command completion. Add an option to control this.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 3 ++-
 include/cli.h | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index fa8f525d3a4..23913a857a9 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -389,7 +389,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char 
ichar)
}
break;
case '\t':
-   if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
+   if (IS_ENABLED(CONFIG_AUTO_COMPLETE) && cls->cmd_complete) {
int num2, col;
 
/* do not autocomplete when in the middle */
@@ -440,6 +440,7 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
cls->prompt = prompt;
cls->buf = buf;
cls->history = true;
+   cls->cmd_complete = true;
 
if (init_len)
cread_add_str(buf, init_len, 1, >num, >eol_num, buf,
diff --git a/include/cli.h b/include/cli.h
index 252bdb70ab0..ad3cb4499fe 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -32,6 +32,7 @@ struct cli_ch_state {
  * @eol_num: Number of characters in the buffer
  * @insert: true if in 'insert' mode
  * @history: true if history should be accessible
+ * @cmd_complete: true if tab completion should be enabled
  * @buf: Buffer containing line
  * @prompt: Prompt for the line
  */
@@ -41,6 +42,7 @@ struct cli_line_state {
uint len;
bool insert;
bool history;
+   bool cmd_complete;
char *buf;
const char *prompt;
 };
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 11/36] cli: Allow history to be disabled

2023-09-19 Thread Simon Glass
When inputting text outside the command line we don't want history to be
accessible. Add an option to control this.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 42 ++
 include/cli.h |  2 ++
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index fdb84d9204f..fa8f525d3a4 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -361,32 +361,33 @@ int cread_line_process_ch(struct cli_line_state *cls, 
char ichar)
break;
case CTL_CH('p'):
case CTL_CH('n'):
-   {
-   char *hline;
+   if (cls->history) {
+   char *hline;
 
-   if (ichar == CTL_CH('p'))
-   hline = hist_prev();
-   else
-   hline = hist_next();
+   if (ichar == CTL_CH('p'))
+   hline = hist_prev();
+   else
+   hline = hist_next();
 
-   if (!hline) {
-   getcmd_cbeep();
-   break;
-   }
+   if (!hline) {
+   getcmd_cbeep();
+   break;
+   }
 
-   /* nuke the current line */
-   /* first, go home */
-   BEGINNING_OF_LINE();
+   /* nuke the current line */
+   /* first, go home */
+   BEGINNING_OF_LINE();
 
-   /* erase to end of line */
-   ERASE_TO_EOL();
+   /* erase to end of line */
+   ERASE_TO_EOL();
 
-   /* copy new line into place and display */
-   strcpy(buf, hline);
-   cls->eol_num = strlen(buf);
-   REFRESH_TO_EOL();
+   /* copy new line into place and display */
+   strcpy(buf, hline);
+   cls->eol_num = strlen(buf);
+   REFRESH_TO_EOL();
+   break;
+   }
break;
-   }
case '\t':
if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
int num2, col;
@@ -438,6 +439,7 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
cls->len = *len;
cls->prompt = prompt;
cls->buf = buf;
+   cls->history = true;
 
if (init_len)
cread_add_str(buf, init_len, 1, >num, >eol_num, buf,
diff --git a/include/cli.h b/include/cli.h
index bbc53276435..252bdb70ab0 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -31,6 +31,7 @@ struct cli_ch_state {
  * @num: Current cursor position, where 0 is the start
  * @eol_num: Number of characters in the buffer
  * @insert: true if in 'insert' mode
+ * @history: true if history should be accessible
  * @buf: Buffer containing line
  * @prompt: Prompt for the line
  */
@@ -39,6 +40,7 @@ struct cli_line_state {
uint eol_num;
uint len;
bool insert;
+   bool history;
char *buf;
const char *prompt;
 };
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 10/36] cli: Terminate the string in cread_line_process_ch()

2023-09-19 Thread Simon Glass
Rather than relying on the caller, terminate the string inside this
function. Do this each time we return, whether input is finished or
not. It is not needed when the input is aborted, since the string will
be discarded in that case.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index 62d419bb36a..fdb84d9204f 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -263,6 +263,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char 
ichar)
 
if (ichar == '\n') {
putc('\n');
+   buf[cls->eol_num] = '\0';   /* terminate the string */
return 0;
}
 
@@ -413,6 +414,12 @@ int cread_line_process_ch(struct cli_line_state *cls, char 
ichar)
break;
}
 
+   /*
+* keep the string terminated...if we added a char at the end then we
+* want a \0 after it
+*/
+   buf[cls->eol_num] = '\0';
+
return -EAGAIN;
 }
 
@@ -467,7 +474,6 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
break;
}
*len = cls->eol_num;
-   buf[cls->eol_num] = '\0';   /* lose the newline */
 
if (buf[0] && buf[0] != CREAD_HIST_CHAR)
cread_add_to_hist(buf);
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 09/36] cli: Create a function to process characters

2023-09-19 Thread Simon Glass
Move most of the inner loop from cread_line() into a new function. This
will allow using it from other code.

This involves adding a few more members to the state struct.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 108 --
 include/cli.h |  15 ++
 2 files changed, 78 insertions(+), 45 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index f5d1cb03433..62d419bb36a 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -253,52 +253,17 @@ static void cread_add_str(char *str, int strsize, int 
insert,
}
 }
 
-static int cread_line(const char *const prompt, char *buf, unsigned int *len,
-   int timeout)
+int cread_line_process_ch(struct cli_line_state *cls, char ichar)
 {
-   struct cli_ch_state s_cch, *cch = _cch;
-   struct cli_line_state s_cls, *cls = _cls;
-   char ichar;
-   int init_len = strlen(buf);
-   int first = 1;
-
-   cli_ch_init(cch);
-   memset(cls, '\0', sizeof(struct cli_line_state));
-   cls->insert = true;
-
-   if (init_len)
-   cread_add_str(buf, init_len, 1, >num, >eol_num, buf,
- *len);
-
-   while (1) {
-   /* Check for saved characters */
-   ichar = cli_ch_process(cch, 0);
-
-   if (!ichar) {
-   if (bootretry_tstc_timeout())
-   return -2;  /* timed out */
-   if (first && timeout) {
-   u64 etime = endtick(timeout);
-
-   while (!tstc()) {   /* while no incoming 
data */
-   if (get_ticks() >= etime)
-   return -2;  /* timed out */
-   schedule();
-   }
-   first = 0;
-   }
-
-   ichar = getcmd_getch();
-   ichar = cli_ch_process(cch, ichar);
-   }
+   char *buf = cls->buf;
 
/* ichar=0x0 when error occurs in U-Boot getc */
if (!ichar)
-   continue;
+   return -EAGAIN;
 
if (ichar == '\n') {
putc('\n');
-   break;
+   return 0;
}
 
switch (ichar) {
@@ -307,7 +272,7 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
break;
case CTL_CH('c'):   /* ^C - break */
*buf = '\0';/* discard input */
-   return -1;
+   return -EINTR;
case CTL_CH('f'):
if (cls->num < cls->eol_num) {
getcmd_putch(buf[cls->num]);
@@ -405,7 +370,7 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
 
if (!hline) {
getcmd_cbeep();
-   continue;
+   break;
}
 
/* nuke the current line */
@@ -419,7 +384,7 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
strcpy(buf, hline);
cls->eol_num = strlen(buf);
REFRESH_TO_EOL();
-   continue;
+   break;
}
case '\t':
if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
@@ -432,9 +397,9 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
}
 
buf[cls->num] = '\0';
-   col = strlen(prompt) + cls->eol_num;
+   col = strlen(cls->prompt) + cls->eol_num;
num2 = cls->num;
-   if (cmd_auto_complete(prompt, buf, , )) {
+   if (cmd_auto_complete(cls->prompt, buf, , )) {
col = num2 - cls->num;
cls->num += col;
cls->eol_num += col;
@@ -444,9 +409,62 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
fallthrough;
default:
cread_add_char(ichar, cls->insert, >num, >eol_num,
-  buf, *len);
+  buf, cls->len);
break;
}
+
+   return -EAGAIN;
+}
+
+static int cread_line(const char *const prompt, char *buf, unsigned int *len,
+ int timeout)
+{
+   struct cli_ch_state s_cch, *cch = _cch;
+   struct cli_line_state s_cls, *cls = _cls;
+   char ichar;
+   int init_len = strlen(buf);
+   int first = 1;
+
+   cli_ch_init(cch);
+   memset(cls, '\0', sizeof(struct cli_line_state));
+   cls->insert = true;
+   cls->len = *len;
+   cls->prompt = prompt;
+   cls->buf = buf;
+
+   if (init_len)
+ 

[PATCH 08/36] cli: Unindent some code in cread_line()

2023-09-19 Thread Simon Glass
Reduce the indentation level of this code so it is easier to review the
next patch, which moves it into a function.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 279 +-
 1 file changed, 139 insertions(+), 140 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index 03624ca18af..f5d1cb03433 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -292,162 +292,161 @@ static int cread_line(const char *const prompt, char 
*buf, unsigned int *len,
ichar = cli_ch_process(cch, ichar);
}
 
-   /* ichar=0x0 when error occurs in U-Boot getc */
-   if (!ichar)
-   continue;
-
-   if (ichar == '\n') {
-   putc('\n');
-   break;
-   }
+   /* ichar=0x0 when error occurs in U-Boot getc */
+   if (!ichar)
+   continue;
 
-   switch (ichar) {
-   case CTL_CH('a'):
-   BEGINNING_OF_LINE();
-   break;
-   case CTL_CH('c'):   /* ^C - break */
-   *buf = '\0';/* discard input */
-   return -1;
-   case CTL_CH('f'):
-   if (cls->num < cls->eol_num) {
-   getcmd_putch(buf[cls->num]);
-   cls->num++;
-   }
-   break;
-   case CTL_CH('b'):
-   if (cls->num) {
-   getcmd_putch(CTL_BACKSPACE);
-   cls->num--;
-   }
-   break;
-   case CTL_CH('d'):
-   if (cls->num < cls->eol_num) {
-   uint wlen;
+   if (ichar == '\n') {
+   putc('\n');
+   break;
+   }
 
-   wlen = cls->eol_num - cls->num - 1;
-   if (wlen) {
-   memmove([cls->num],
-   [cls->num + 1], wlen);
-   putnstr(buf + cls->num, wlen);
-   }
+   switch (ichar) {
+   case CTL_CH('a'):
+   BEGINNING_OF_LINE();
+   break;
+   case CTL_CH('c'):   /* ^C - break */
+   *buf = '\0';/* discard input */
+   return -1;
+   case CTL_CH('f'):
+   if (cls->num < cls->eol_num) {
+   getcmd_putch(buf[cls->num]);
+   cls->num++;
+   }
+   break;
+   case CTL_CH('b'):
+   if (cls->num) {
+   getcmd_putch(CTL_BACKSPACE);
+   cls->num--;
+   }
+   break;
+   case CTL_CH('d'):
+   if (cls->num < cls->eol_num) {
+   uint wlen;
 
-   getcmd_putch(' ');
-   do {
-   getcmd_putch(CTL_BACKSPACE);
-   } while (wlen--);
-   cls->eol_num--;
-   }
-   break;
-   case CTL_CH('k'):
-   ERASE_TO_EOL();
-   break;
-   case CTL_CH('e'):
-   REFRESH_TO_EOL();
-   break;
-   case CTL_CH('o'):
-   cls->insert = !cls->insert;
-   break;
-   case CTL_CH('w'):
-   if (cls->num) {
-   uint base, wlen;
-
-   for (base = cls->num - 1;
-base >= 0 && buf[base] == ' ';)
-   base--;
-   for (; base > 0 && buf[base - 1] != ' ';)
-   base--;
-
-   /* now delete chars from base to cls->num */
-   wlen = cls->num - base;
-   cls->eol_num -= wlen;
-   memmove([base], [cls->num],
-   cls->eol_num - base + 1);
-   cls->num = base;
-   getcmd_putchars(wlen, CTL_BACKSPACE);
-   puts(buf + base);
-   getcmd_putchars(wlen, ' ');
-   getcmd_putchars(wlen + cls->eol_num - cls->num,
-   CTL_BACKSPACE);
-   }
-   break;
-   case CTL_CH('x'):
-   case CTL_CH('u'):
-   BEGINNING_OF_LINE();
-   

[PATCH 07/36] cli: Convert cread_line() to use a struct for the main vars

2023-09-19 Thread Simon Glass
We want to reuse the editing code elsewhere. As a first step, move the
common variables into a struct. This will allow us to eventually put the
contents of the inner loop in a function, so it can be called from
elsewhere.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 116 ++
 include/cli.h |  14 +
 2 files changed, 75 insertions(+), 55 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index f863404110c..03624ca18af 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -188,27 +188,27 @@ void cread_print_hist_list(void)
 }
 
 #define BEGINNING_OF_LINE() {  \
-   while (num) {   \
+   while (cls->num) {  \
getcmd_putch(CTL_BACKSPACE);\
-   num--;  \
+   cls->num--; \
}   \
 }
 
 #define ERASE_TO_EOL() {   \
-   if (num < eol_num) {\
-   printf("%*s", (int)(eol_num - num), ""); \
+   if (cls->num < cls->eol_num) {  \
+   printf("%*s", (int)(cls->eol_num - cls->num), ""); \
do {\
getcmd_putch(CTL_BACKSPACE);\
-   } while (--eol_num > num);  \
+   } while (--cls->eol_num > cls->num);\
}   \
 }
 
-#define REFRESH_TO_EOL() { \
-   if (num < eol_num) {\
-   wlen = eol_num - num;   \
-   putnstr(buf + num, wlen);   \
-   num = eol_num;  \
-   }   \
+#define REFRESH_TO_EOL() { \
+   if (cls->num < cls->eol_num) {  \
+   uint wlen = cls->eol_num - cls->num;\
+   putnstr(buf + cls->num, wlen);  \
+   cls->num = cls->eol_num;\
+   }   \
 }
 
 static void cread_add_char(char ichar, int insert, uint *num,
@@ -257,18 +257,18 @@ static int cread_line(const char *const prompt, char 
*buf, unsigned int *len,
int timeout)
 {
struct cli_ch_state s_cch, *cch = _cch;
-   uint num = 0;
-   uint eol_num = 0;
-   uint wlen;
+   struct cli_line_state s_cls, *cls = _cls;
char ichar;
-   int insert = 1;
int init_len = strlen(buf);
int first = 1;
 
cli_ch_init(cch);
+   memset(cls, '\0', sizeof(struct cli_line_state));
+   cls->insert = true;
 
if (init_len)
-   cread_add_str(buf, init_len, 1, , _num, buf, *len);
+   cread_add_str(buf, init_len, 1, >num, >eol_num, buf,
+ *len);
 
while (1) {
/* Check for saved characters */
@@ -309,30 +309,33 @@ static int cread_line(const char *const prompt, char 
*buf, unsigned int *len,
*buf = '\0';/* discard input */
return -1;
case CTL_CH('f'):
-   if (num < eol_num) {
-   getcmd_putch(buf[num]);
-   num++;
+   if (cls->num < cls->eol_num) {
+   getcmd_putch(buf[cls->num]);
+   cls->num++;
}
break;
case CTL_CH('b'):
-   if (num) {
+   if (cls->num) {
getcmd_putch(CTL_BACKSPACE);
-   num--;
+   cls->num--;
}
break;
case CTL_CH('d'):
-   if (num < eol_num) {
-   wlen = eol_num - num - 1;
+   if (cls->num < cls->eol_num) {
+   uint wlen;
+
+   wlen = cls->eol_num - cls->num - 1;
if (wlen) {
-   memmove([num], [num+1], wlen);
-   putnstr(buf + num, wlen);
+   memmove([cls->num],
+   [cls->num + 1], wlen);
+   putnstr(buf + cls->num, wlen);
}
 
getcmd_putch(' ');
do {
getcmd_putch(CTL_BACKSPACE);
} while (wlen--);
-   eol_num--;
+   cls->eol_num--;
   

[PATCH 06/36] cli: Use unsigned int instead of unsigned long

2023-09-19 Thread Simon Glass
The index values are not very large so it makes no sense to use a long
integer. Change these to uint instead.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index 687e239bfa7..f863404110c 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -171,7 +171,7 @@ static char *hist_next(void)
 void cread_print_hist_list(void)
 {
int i;
-   unsigned long n;
+   uint n;
 
n = hist_num - hist_max;
 
@@ -211,10 +211,10 @@ void cread_print_hist_list(void)
}   \
 }
 
-static void cread_add_char(char ichar, int insert, unsigned long *num,
-  unsigned long *eol_num, char *buf, unsigned long len)
+static void cread_add_char(char ichar, int insert, uint *num,
+  uint *eol_num, char *buf, uint len)
 {
-   unsigned long wlen;
+   uint wlen;
 
/* room ??? */
if (insert || *num == *eol_num) {
@@ -245,8 +245,7 @@ static void cread_add_char(char ichar, int insert, unsigned 
long *num,
 }
 
 static void cread_add_str(char *str, int strsize, int insert,
- unsigned long *num, unsigned long *eol_num,
- char *buf, unsigned long len)
+ uint *num, uint *eol_num, char *buf, uint len)
 {
while (strsize--) {
cread_add_char(*str, insert, num, eol_num, buf, len);
@@ -258,9 +257,9 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
int timeout)
 {
struct cli_ch_state s_cch, *cch = _cch;
-   unsigned long num = 0;
-   unsigned long eol_num = 0;
-   unsigned long wlen;
+   uint num = 0;
+   uint eol_num = 0;
+   uint wlen;
char ichar;
int insert = 1;
int init_len = strlen(buf);
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 05/36] cli: Implement delete-word in cread_line()

2023-09-19 Thread Simon Glass
The Ctrl-W option is implemented in the cread_line_simple() but not in
the full version. This seems odd, so add an implementation.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index 458e927e492..687e239bfa7 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -89,6 +89,14 @@ static char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save 
room for NULL */
 
 #define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
 
+static void getcmd_putchars(int count, int ch)
+{
+   int i;
+
+   for (i = 0; i < count; i++)
+   getcmd_putch(ch);
+}
+
 static void hist_init(void)
 {
int i;
@@ -337,6 +345,29 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
case CTL_CH('o'):
insert = !insert;
break;
+   case CTL_CH('w'):
+   if (num) {
+   uint base;
+
+   for (base = num - 1;
+base >= 0 && buf[base] == ' ';)
+   base--;
+   for (; base > 0 && buf[base - 1] != ' ';)
+   base--;
+
+   /* now delete chars from base to num */
+   wlen = num - base;
+   eol_num -= wlen;
+   memmove([base], [num],
+   eol_num - base + 1);
+   num = base;
+   getcmd_putchars(wlen, CTL_BACKSPACE);
+   puts(buf + base);
+   getcmd_putchars(wlen, ' ');
+   getcmd_putchars(wlen + eol_num - num,
+   CTL_BACKSPACE);
+   }
+   break;
case CTL_CH('x'):
case CTL_CH('u'):
BEGINNING_OF_LINE();
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 04/36] cli: Drop #ifdefs for CONFIG_AUTO_COMPLETE in cli_readline

2023-09-19 Thread Simon Glass
Use a static inline and adjust the logic to avoid the need for #ifdefs in
cli_readline_into_buffer()

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 85 +--
 include/command.h |  6 +++
 2 files changed, 48 insertions(+), 43 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index 61f9ba99068..458e927e492 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -386,27 +386,27 @@ static int cread_line(const char *const prompt, char 
*buf, unsigned int *len,
REFRESH_TO_EOL();
continue;
}
-#ifdef CONFIG_AUTO_COMPLETE
-   case '\t': {
-   int num2, col;
+   case '\t':
+   if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
+   int num2, col;
+
+   /* do not autocomplete when in the middle */
+   if (num < eol_num) {
+   getcmd_cbeep();
+   break;
+   }
 
-   /* do not autocomplete when in the middle */
-   if (num < eol_num) {
-   getcmd_cbeep();
+   buf[num] = '\0';
+   col = strlen(prompt) + eol_num;
+   num2 = num;
+   if (cmd_auto_complete(prompt, buf, , 
)) {
+   col = num2 - num;
+   num += col;
+   eol_num += col;
+   }
break;
}
-
-   buf[num] = '\0';
-   col = strlen(prompt) + eol_num;
-   num2 = num;
-   if (cmd_auto_complete(prompt, buf, , )) {
-   col = num2 - num;
-   num += col;
-   eol_num += col;
-   }
-   break;
-   }
-#endif
+   fallthrough;
default:
cread_add_char(ichar, insert, , _num, buf,
   *len);
@@ -519,14 +519,15 @@ static int cread_line_simple(const char *const prompt, 
char *p)
continue;
 
default:
-   /*
-* Must be a normal character then
-*/
-   if (n < CONFIG_SYS_CBSIZE-2) {
-   if (c == '\t') {/* expand TABs */
-#ifdef CONFIG_AUTO_COMPLETE
+   /* Must be a normal character then */
+   if (n >= CONFIG_SYS_CBSIZE - 2) { /* Buffer full */
+   putc('\a');
+   break;
+   }
+   if (c == '\t') {/* expand TABs */
+   if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
/*
-* if auto completion triggered just
+* if auto-completion triggered just
 * continue
 */
*p = '\0';
@@ -536,26 +537,24 @@ static int cread_line_simple(const char *const prompt, 
char *p)
p = p_buf + n;  /* reset */
continue;
}
-#endif
-   puts(tab_seq + (col & 07));
-   col += 8 - (col & 07);
-   } else {
-   char __maybe_unused buf[2];
-
-   /*
-* Echo input using puts() to force an
-* LCD flush if we are using an LCD
-*/
-   ++col;
-   buf[0] = c;
-   buf[1] = '\0';
-   puts(buf);
}
-   *p++ = c;
-   ++n;
-   } else {/* Buffer full */
-   putc('\a');
+   puts(tab_seq + (col & 07));
+   col += 8 - (col & 07);
+   } else {
+   char __maybe_unused buf[2];
+
+   /*
+   

[PATCH 03/36] cli: Drop some #ifdefs in cli_readline

2023-09-19 Thread Simon Glass
Add a few static inlines to avoid the need for #ifdefs in
cli_readline_into_buffer()

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index f3ba76a62ec..61f9ba99068 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -423,6 +423,18 @@ static int cread_line(const char *const prompt, char *buf, 
unsigned int *len,
return 0;
 }
 
+#else /* !CONFIG_CMDLINE_EDITING */
+
+static inline void hist_init(void)
+{
+}
+
+static int cread_line(const char *const prompt, char *buf, unsigned int *len,
+ int timeout)
+{
+   return 0;
+}
+
 #endif /* CONFIG_CMDLINE_EDITING */
 
 //
@@ -552,8 +564,7 @@ int cli_readline_into_buffer(const char *const prompt, char 
*buffer,
 int timeout)
 {
char *p = buffer;
-#ifdef CONFIG_CMDLINE_EDITING
-   unsigned int len = CONFIG_SYS_CBSIZE;
+   uint len = CONFIG_SYS_CBSIZE;
int rc;
static int initted;
 
@@ -563,7 +574,7 @@ int cli_readline_into_buffer(const char *const prompt, char 
*buffer,
 * Revert to non-history version if still
 * running from flash.
 */
-   if (gd->flags & GD_FLG_RELOC) {
+   if (IS_ENABLED(CONFIG_CMDLINE_EDITING) && (gd->flags & GD_FLG_RELOC)) {
if (!initted) {
hist_init();
initted = 1;
@@ -576,9 +587,6 @@ int cli_readline_into_buffer(const char *const prompt, char 
*buffer,
return rc < 0 ? rc : len;
 
} else {
-#endif /* CONFIG_CMDLINE_EDITING */
return cread_line_simple(prompt, p);
-#ifdef CONFIG_CMDLINE_EDITING
}
-#endif
 }
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 02/36] cli: Add a command to show cmdline history

2023-09-19 Thread Simon Glass
There is a function for this but it is never used. Showing the history is
a useful feature, so add a new 'history' command.

Signed-off-by: Simon Glass 
---

 cmd/Kconfig   |  7 
 cmd/Makefile  |  1 +
 cmd/history.c | 23 +
 common/cli_readline.c |  4 +--
 doc/usage/cmd/history.rst | 68 +++
 doc/usage/index.rst   |  1 +
 include/cli.h |  3 ++
 test/cmd/Makefile |  1 +
 test/cmd/history.c| 49 
 9 files changed, 154 insertions(+), 3 deletions(-)
 create mode 100644 cmd/history.c
 create mode 100644 doc/usage/cmd/history.rst
 create mode 100644 test/cmd/history.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 3f14923b5ef..0f35f7f6ec6 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -176,6 +176,13 @@ config CMD_FWU_METADATA
help
  Command to read the metadata and dump it's contents
 
+config CMD_HISTORY
+   bool "history"
+   depends on CMDLINE_EDITING
+   help
+ Show the command-line history, i.e. a list of commands that are in
+ the history buffer.
+
 config CMD_LICENSE
bool "license"
select BUILD_BIN2C
diff --git a/cmd/Makefile b/cmd/Makefile
index 9bebf321c39..971f78a7fbd 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -91,6 +91,7 @@ obj-$(CONFIG_CMD_FUSE) += fuse.o
 obj-$(CONFIG_CMD_FWU_METADATA) += fwu_mdata.o
 obj-$(CONFIG_CMD_GETTIME) += gettime.o
 obj-$(CONFIG_CMD_GPIO) += gpio.o
+obj-$(CONFIG_CMD_HISTORY) += history.o
 obj-$(CONFIG_CMD_HVC) += smccc.o
 obj-$(CONFIG_CMD_I2C) += i2c.o
 obj-$(CONFIG_CMD_IOTRACE) += iotrace.o
diff --git a/cmd/history.c b/cmd/history.c
new file mode 100644
index 000..b6bf4670b1c
--- /dev/null
+++ b/cmd/history.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass 
+ */
+
+#include 
+#include 
+#include 
+
+static int do_history(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   cread_print_hist_list();
+
+   return 0;
+}
+
+U_BOOT_CMD(
+   history,CONFIG_SYS_MAXARGS, 1,  do_history,
+   "print command history",
+   ""
+);
diff --git a/common/cli_readline.c b/common/cli_readline.c
index 9a7c268719d..f3ba76a62ec 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -160,8 +160,7 @@ static char *hist_next(void)
return ret;
 }
 
-#ifndef CONFIG_CMDLINE_EDITING
-static void cread_print_hist_list(void)
+void cread_print_hist_list(void)
 {
int i;
unsigned long n;
@@ -179,7 +178,6 @@ static void cread_print_hist_list(void)
i++;
}
 }
-#endif /* CONFIG_CMDLINE_EDITING */
 
 #define BEGINNING_OF_LINE() {  \
while (num) {   \
diff --git a/doc/usage/cmd/history.rst b/doc/usage/cmd/history.rst
new file mode 100644
index 000..7d5a87babb2
--- /dev/null
+++ b/doc/usage/cmd/history.rst
@@ -0,0 +1,68 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+history command
+===
+
+Synopis
+---
+
+::
+
+history
+
+Description
+---
+
+The *history* command shows a list of previously entered commands on the
+command line. When U-Boot starts, this it is initially empty. Each new command
+entered is added to the list.
+
+Normally these commands can be accessed by pressing the `up arrow` and
+`down arrow` keys, which cycle through the list. The `history` command provides
+a simple way to view the list.
+
+Example
+---
+
+This example shows entering three commands, then `history`. Note that `history`
+itself is added to the list.
+
+::
+
+=> bootflow scan -l
+Scanning for bootflows in all bootdevs
+Seq  Method   State   UclassPart  Name  
Filename
+---  ---  --        

+Scanning global bootmeth 'firmware0':
+Hunting with: simple_bus
+Found 2 extension board(s).
+Scanning bootdev 'mmc2.bootdev':
+Scanning bootdev 'mmc1.bootdev':
+  0  extlinux ready   mmc  1  mmc1.bootdev.part_1   
/extlinux/extlinux.conf
+No more bootdevs
+---  ---  --        

+(1 bootflow, 1 valid)
+=> bootflow select 0
+=> bootflow info
+Name:  mmc1.bootdev.part_1
+Device:mmc1.bootdev
+Block dev: mmc1.blk
+Method:extlinux
+State: ready
+Partition: 1
+Subdir:(none)
+Filename:  /extlinux/extlinux.conf
+Buffer:aebdea0
+Size:  253 (595 bytes)
+OS:Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
+Cmdline:   (none)
+Logo:  (none)
+FDT:   
+Error: 0
+=> history
+bootflow scan -l
+bootflow select 0
+bootflow info
+history
+=>
+
diff --git a/doc/usage/index.rst b/doc/usage/index.rst

[PATCH 01/36] cli: Move simple readline into a function

2023-09-19 Thread Simon Glass
Move this code into its own function since it is a separate
implementation from the full version.

Signed-off-by: Simon Glass 
---

 common/cli_readline.c | 79 +--
 1 file changed, 46 insertions(+), 33 deletions(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index e83743e90c9..9a7c268719d 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -440,41 +440,22 @@ int cli_readline(const char *const prompt)
return cli_readline_into_buffer(prompt, console_buffer, 0);
 }
 
-
-int cli_readline_into_buffer(const char *const prompt, char *buffer,
-int timeout)
+/**
+ * cread_line_simple() - Simple (small) command-line reader
+ *
+ * This supports only basic editing, with no cursor movement
+ *
+ * @prompt: Prompt to display
+ * @p: Text buffer to edit
+ * Return: length of text buffer, or -1 if input was cannncelled (Ctrl-C)
+ */
+static int cread_line_simple(const char *const prompt, char *p)
 {
-   char *p = buffer;
-#ifdef CONFIG_CMDLINE_EDITING
-   unsigned int len = CONFIG_SYS_CBSIZE;
-   int rc;
-   static int initted;
-
-   /*
-* History uses a global array which is not
-* writable until after relocation to RAM.
-* Revert to non-history version if still
-* running from flash.
-*/
-   if (gd->flags & GD_FLG_RELOC) {
-   if (!initted) {
-   hist_init();
-   initted = 1;
-   }
-
-   if (prompt)
-   puts(prompt);
-
-   rc = cread_line(prompt, p, , timeout);
-   return rc < 0 ? rc : len;
-
-   } else {
-#endif /* CONFIG_CMDLINE_EDITING */
char *p_buf = p;
-   int n = 0;  /* buffer index */
-   int plen = 0;   /* prompt length*/
-   int col;/* output column cnt*/
-   charc;
+   int n = 0;  /* buffer index */
+   int plen = 0;   /* prompt length */
+   int col;/* output column cnt */
+   char c;
 
/* print prompt */
if (prompt) {
@@ -567,6 +548,38 @@ int cli_readline_into_buffer(const char *const prompt, 
char *buffer,
}
}
}
+}
+
+int cli_readline_into_buffer(const char *const prompt, char *buffer,
+int timeout)
+{
+   char *p = buffer;
+#ifdef CONFIG_CMDLINE_EDITING
+   unsigned int len = CONFIG_SYS_CBSIZE;
+   int rc;
+   static int initted;
+
+   /*
+* History uses a global array which is not
+* writable until after relocation to RAM.
+* Revert to non-history version if still
+* running from flash.
+*/
+   if (gd->flags & GD_FLG_RELOC) {
+   if (!initted) {
+   hist_init();
+   initted = 1;
+   }
+
+   if (prompt)
+   puts(prompt);
+
+   rc = cread_line(prompt, p, , timeout);
+   return rc < 0 ? rc : len;
+
+   } else {
+#endif /* CONFIG_CMDLINE_EDITING */
+   return cread_line_simple(prompt, p);
 #ifdef CONFIG_CMDLINE_EDITING
}
 #endif
-- 
2.42.0.459.ge4e396fd5e-goog



[PATCH 00/36] expo: Support editing lines of text

2023-09-19 Thread Simon Glass
So far expo only supports menus. These are quite flexible for various
kinds of settings, but cannot deal with free-form input, such as a
serial number or a machine name.

This series adds support for a textline object, which is a single line
of text. It has a maximum length and its value is stored within the expo
structure.

U-Boot already has a command-line editor which provides most of the
features needed by expo. But the code runs in its own loop and only
returns when the line is finished. This is not suitable for expo, which
must handle a keypress at a time, returning to its caller after each
one.

In order to use the CLI code, some significant refactoring is included
here. This mostly involves moving the internal loop of the CLI to a
separate function and recording its state in a struct, just as was done
for single keypresses some time back. A minor addition is support for
Ctrl-W to delete a word, since strangely this is currently only present
in the simple version.

The video-console system provides most of the features needed by
testline, but a few things are missing. This series provides:

- primitive cursor support so the user can see where he is typing
- saving and restoring of the text-entry context, so that expo can allow
  the user to continue where he left off, including deleting previously
  entered characters correctly (for Truetype)
- obtaining the nominal width of a string of n characters, so that a
  suitable width can be chosen for the textline object

Note that no support is provided for clearing the cursor. This was
addressed in a previous series[1] which could perhaps be rebased. For
this implementation, the cursor is therefore not enabled for the normal
command line, only for expo.

Reading and writing textline objects is supported for FDT and
environment, but not for CMOS RAM, since it would likely use too much
RAM to store a string.

In terms of code size, the overall size increase is 180 bytes for
Thumb02 boards, 160 of whcih is the addition of Ctrl-W to delete a word.

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=280178=*


Simon Glass (36):
  cli: Move simple readline into a function
  cli: Add a command to show cmdline history
  cli: Drop some #ifdefs in cli_readline
  cli: Drop #ifdefs for CONFIG_AUTO_COMPLETE in cli_readline
  cli: Implement delete-word in cread_line()
  cli: Use unsigned int instead of unsigned long
  cli: Convert cread_line() to use a struct for the main vars
  cli: Unindent some code in cread_line()
  cli: Create a function to process characters
  cli: Terminate the string in cread_line_process_ch()
  cli: Allow history to be disabled
  cli: Allow command completion to be disabled
  cli: Add a function to set up a new cread
  video: Allow obtaining the nominal size of a string size
  video: Allow saving and restoring text-entry state
  video: Export vidconsole_entry_start()
  video: Support showing a cursor
  expo: Add better error reporting
  expo: Fix up comments for get_cur_menuitem_text() et al
  expo: Use switch statements more for object types
  expo: Correct some swallowed errors in scene
  expo: Correct the logic for duplicate-ID detection
  expo: Allow highlighting other scene-object types
  expo: Add a function to write a property to a devicetree
  expo: Make calculation of an object bounding box generic
  expo: Allow rendering the background of any object
  expo: Add some scene fields needed for text entry
  expo: Add basic support for textline objects
  expo: Support opening a textline
  expo: Plumb in textlines to a scene
  video: Mark truetype_measure() static
  expo: Support handling any key in cedit
  expo: Plumb in textline to cedit
  expo: Support building an expo with a textline
  expo: Update tests to include textline
  expo: Update documentation to include textline

 arch/sandbox/dts/cedit.dtsi |   8 +
 boot/Makefile   |   3 +-
 boot/cedit.c| 196 ---
 boot/expo_build.c   | 103 +-
 boot/scene.c| 237 +++--
 boot/scene_internal.h   | 128 ++-
 boot/scene_menu.c   |  68 +---
 boot/scene_textline.c   | 229 +
 cmd/Kconfig |   7 +
 cmd/Makefile|   1 +
 cmd/history.c   |  23 ++
 common/cli_readline.c   | 498 
 doc/develop/cedit.rst   |   3 +-
 doc/develop/expo.rst|  48 ++-
 doc/usage/cmd/history.rst   |  68 
 doc/usage/index.rst |   1 +
 drivers/video/console_core.c|  31 ++
 drivers/video/console_normal.c  |  29 ++
 drivers/video/console_truetype.c| 191 ++-
 drivers/video/vidconsole-uclass.c   |  71 +++-
 drivers/video/vidconsole_internal.h |  24 ++
 include/cli.h   |  51 +++
 include/command.h   |   6 +
 include/expo.h  |  

Re: [PATCH v3 16/16] doc: board: ti: k3: Add J784S4 EVM and AM69 SK documentation

2023-09-19 Thread Apurva Nandan



On 09/09/23 17:08, Roger Quadros wrote:


On 08/09/2023 14:05, Apurva Nandan wrote:

TI K3 J784S4 and AM69 SK are new additions to the K3 SoC family.

J784S4 is a SoC variant, AM69-SK is a board using AM69 SoC variant.
How can a board be part of SoC family?


Okay will fix that statement.


Looking at the TRM [1] there seem to be 6 different SoC variants
i.e. J784S4, TDA4AP, TDA4VP, TDA4AH, TDA4VH, AM69

I suppose all of them will use the same base SoC device tree and platform code?

Now about the boards. So far there seem to be 2 boards J784S4-EVM and AM69-SK.

Why are you combining information for both in one location in this patch?
I would suggest to have separate location for AM69-SK.

Both boards are supported by same source and one build. So being
identical in boot flow etc, I think we can keeping documentation for both
boards under one file, the only difference being in boot mode pins and
debugger setup.

[1] - https://www.ti.com/document-viewer/lit/html/spruj52


Add documentation about the J784S4 EVM and AM69 SK.

Signed-off-by: Dasnavis Sabiya 
Signed-off-by: Apurva Nandan 
---
  board/ti/j784s4/MAINTAINERS |   1 +
  doc/board/ti/j784s4_evm.rst | 339 
  doc/board/ti/k3.rst |   1 +
  3 files changed, 341 insertions(+)
  create mode 100644 doc/board/ti/j784s4_evm.rst

diff --git a/board/ti/j784s4/MAINTAINERS b/board/ti/j784s4/MAINTAINERS
index 7d3549dd31..be2f9a04b7 100644
--- a/board/ti/j784s4/MAINTAINERS
+++ b/board/ti/j784s4/MAINTAINERS
@@ -18,3 +18,4 @@ F:arch/arm/dts/k3-j784s4-ddr-evm-lp4-4266.dtsi
  F:arch/arm/dts/k3-am69-sk.dts
  F:arch/arm/dts/k3-am69-sk-u-boot.dtsi
  F:arch/arm/dts/k3-am69-r5-sk.dts
+F: doc/board/ti/j784s4_evm.rst
diff --git a/doc/board/ti/j784s4_evm.rst b/doc/board/ti/j784s4_evm.rst
new file mode 100644
index 00..1e2b7f3820
--- /dev/null
+++ b/doc/board/ti/j784s4_evm.rst
@@ -0,0 +1,339 @@
+.. SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+.. sectionauthor:: Apurva Nandan 
+
+J784S4 and AM69 Platforms
+=
+
+Introduction:
+-
+The J784S4 SoC belongs to the K3 Multicore SoC architecture
+platform, providing advanced system integration in automotive,
+ADAS and industrial applications requiring AI at the network edge.
+This SoC extends the K3 Jacinto 7 family of SoCs with focus on
+raising performance and integration while providing interfaces,
+memory architecture and compute performance for multi-sensor, high
+concurrency applications.
+
+The device is partitioned into three functional domains, each containing
+specific processing cores and peripherals:
+
+1. Wake-up (WKUP) domain:
+* ARM Cortex-M4F processor, runs TI Foundational Security (TIFS)
+
+2. Microcontroller (MCU) domain:
+* Dual core ARM Cortex-R5F processor, runs device management
+  and SoC early boot
+
+3. MAIN domain:
+* Dual core 64-bit ARM Cortex-A72, runs HLOS
+
+More info can be found in TRM: http://www.ti.com/lit/zip/spruj52
+
+Platform information:
+
+* https://www.ti.com/tool/J784S4XEVM
+* https://www.ti.com/tool/SK-AM69
+
+Boot Flow:
+--
+Below is the pictorial representation of boot flow:
+
+.. image:: img/boot_diagram_k3_current.svg
+
+- On this platform, "TI Foundational Security (TIFS)" functions as the
+  security enclave master. While "Device Manager (DM)", also known as the
+  "TISCI server" in TI terminology, offers all the essential services.
+
+- As illustrated in the diagram above, R5 SPL manages power and clock
+  services independently before handing over control to DM. The A72 or
+  the C7x (Aux core) software components request TIFS/DM to handle
+  security or device management services.
+
+Sources:
+
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_boot_sources
+:end-before: .. k3_rst_include_end_boot_sources
+
+Build procedure:
+
+0. Setup the environment variables:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_common_env_vars_desc
+:end-before: .. k3_rst_include_end_common_env_vars_desc
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_board_env_vars_desc
+:end-before: .. k3_rst_include_end_board_env_vars_desc
+
+Set the variables corresponding to this platform:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_common_env_vars_defn
+:end-before: .. k3_rst_include_end_common_env_vars_defn
+.. code-block:: bash
+
+ $ export UBOOT_CFG_CORTEXR=j784s4_evm_r5_defconfig
+ $ export UBOOT_CFG_CORTEXA=j784s4_evm_a72_defconfig
+ $ export TFA_BOARD=generic
+ $ export TFA_EXTRA_ARGS="K3_USART=0x8"
+ $ export OPTEE_PLATFORM=k3-j784s4
+ $ export OPTEE_EXTRA_ARGS="CFG_CONSOLE_UART=0x8"
+
+.. j784s4_evm_rst_include_start_build_steps
+
+1. Trusted Firmware-A:
+
+.. include::  k3.rst
+:start-after: .. k3_rst_include_start_build_steps_tfa
+:end-before: .. k3_rst_include_end_build_steps_tfa
+
+
+2. OP-TEE:
+
+.. include::  k3.rst
+:start-after: 

Re: [PATCH v3 08/16] board: ti: j784s4: Add board support for J784S4 EVM

2023-09-19 Thread Apurva Nandan



On 09/09/23 16:59, Roger Quadros wrote:


On 08/09/2023 14:05, Apurva Nandan wrote:

Add board files for J784S4 EVM.

Signed-off-by: Hari Nagalla 
[ add env and board specific yaml files for binman ]
Signed-off-by: Neha Malcom Francis 
[ cleaned up the env files ]
Signed-off-by: Manorit Chawdhry 
Signed-off-by: Apurva Nandan 
---
  arch/arm/mach-k3/Kconfig |1 +
  board/ti/j784s4/Kconfig  |   63 +
  board/ti/j784s4/MAINTAINERS  |   20 +
  board/ti/j784s4/Makefile |8 +
  board/ti/j784s4/board-cfg.yaml   |   36 +
  board/ti/j784s4/evm.c|   87 +
  board/ti/j784s4/j784s4.env   |   35 +
  board/ti/j784s4/pm-cfg.yaml  |   12 +
  board/ti/j784s4/rm-cfg.yaml  | 3057 ++
  board/ti/j784s4/sec-cfg.yaml |  379 
  board/ti/j784s4/tifs-rm-cfg.yaml | 2655 ++
  include/configs/j784s4_evm.h |   20 +
  12 files changed, 6373 insertions(+)
  create mode 100644 board/ti/j784s4/Kconfig
  create mode 100644 board/ti/j784s4/MAINTAINERS
  create mode 100644 board/ti/j784s4/Makefile
  create mode 100644 board/ti/j784s4/board-cfg.yaml
  create mode 100644 board/ti/j784s4/evm.c
  create mode 100644 board/ti/j784s4/j784s4.env
  create mode 100644 board/ti/j784s4/pm-cfg.yaml
  create mode 100644 board/ti/j784s4/rm-cfg.yaml
  create mode 100644 board/ti/j784s4/sec-cfg.yaml
  create mode 100644 board/ti/j784s4/tifs-rm-cfg.yaml
  create mode 100644 include/configs/j784s4_evm.h

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 0af2ec6ddb..ba3dd393e3 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -197,4 +197,5 @@ source "board/ti/j721e/Kconfig"
  source "board/siemens/iot2050/Kconfig"
  source "board/ti/j721s2/Kconfig"
  source "board/toradex/verdin-am62/Kconfig"
+source "board/ti/j784s4/Kconfig"
  endif
diff --git a/board/ti/j784s4/Kconfig b/board/ti/j784s4/Kconfig
new file mode 100644
index 00..7eeb21f451
--- /dev/null
+++ b/board/ti/j784s4/Kconfig
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+#  Hari Nagalla 
+
+choice
+   prompt "K3 J784S4 board"
+   optional
+
+config TARGET_J784S4_A72_EVM
+   bool "TI K3 based J784S4 EVM running on A72"
+   select ARM64
+   select SOC_K3_J784S4
+   select BOARD_LATE_INIT
+   select SYS_DISABLE_DCACHE_OPS
+   select BINMAN
+
+config TARGET_J784S4_R5_EVM
+   bool "TI K3 based J784S4 EVM running on R5"
+   select CPU_V7R
+   select SYS_THUMB_BUILD
+   select SOC_K3_J784S4
+   select K3_LOAD_SYSFW
+   select RAM
+   select SPL_RAM
+   select K3_DDRSS
+   select BINMAN
+   imply SYS_K3_SPL_ATF
+
+endchoice
+
+if TARGET_J784S4_A72_EVM
+
+config SYS_BOARD
+   default "j784s4"
+
+config SYS_VENDOR
+   default "ti"
+
+config SYS_CONFIG_NAME
+   default "j784s4_evm"
+
+source "board/ti/common/Kconfig"
+
+endif
+
+if TARGET_J784S4_R5_EVM
+
+config SYS_BOARD
+   default "j784s4"
+
+config SYS_VENDOR
+   default "ti"
+
+config SYS_CONFIG_NAME
+   default "j784s4_evm"
+
+config SPL_LDSCRIPT
+   default "arch/arm/mach-omap2/u-boot-spl.lds"
+
+source "board/ti/common/Kconfig"
+
+endif
diff --git a/board/ti/j784s4/MAINTAINERS b/board/ti/j784s4/MAINTAINERS
new file mode 100644
index 00..7d3549dd31
--- /dev/null
+++ b/board/ti/j784s4/MAINTAINERS
@@ -0,0 +1,20 @@
+J784S4 BOARD
+M: Hari Nagalla 
+S: Maintained
+F: board/ti/j784s4
+F: arch/arm/mach-k3/j784s4
+F: include/configs/j784s4_evm.h
+F: configs/j784s4_evm_r5_defconfig
+F: configs/j784s4_evm_a72_defconfig
+F: arch/arm/dts/k3-j784s4.dtsi
+F: arch/arm/dts/k3-j784s4-main.dtsi
+F: arch/arm/dts/k3-j784s4-mcu-wakeup.dtsi
+F: arch/arm/dts/k3-j784s4-thermal.dtsi
+F: arch/arm/dts/k3-j784s4-evm.dts
+F: arch/arm/dts/k3-j784s4-evm-u-boot.dtsi
+F: arch/arm/dts/k3-j784s4-r5-evm.dts
+F: arch/arm/dts/k3-j784s4-ddr.dtsi
+F: arch/arm/dts/k3-j784s4-ddr-evm-lp4-4266.dtsi
+F: arch/arm/dts/k3-am69-sk.dts
+F: arch/arm/dts/k3-am69-sk-u-boot.dtsi
+F: arch/arm/dts/k3-am69-r5-sk.dts

These 3 files are not part of J724S4 EVM.

Okay, will fix. Thanks!

--
Thanks and regards,
Apurva Nandan,
Texas Instruments India.



Re: [PATCH v3 08/16] board: ti: j784s4: Add board support for J784S4 EVM

2023-09-19 Thread Apurva Nandan

Hi,

On 09/09/23 16:32, Roger Quadros wrote:


On 08/09/2023 14:05, Apurva Nandan wrote:

Add board files for J784S4 EVM.

Signed-off-by: Hari Nagalla 
[ add env and board specific yaml files for binman ]
Signed-off-by: Neha Malcom Francis 
[ cleaned up the env files ]
Signed-off-by: Manorit Chawdhry 
Signed-off-by: Apurva Nandan 
---
  arch/arm/mach-k3/Kconfig |1 +
  board/ti/j784s4/Kconfig  |   63 +
  board/ti/j784s4/MAINTAINERS  |   20 +
  board/ti/j784s4/Makefile |8 +
  board/ti/j784s4/board-cfg.yaml   |   36 +
  board/ti/j784s4/evm.c|   87 +
  board/ti/j784s4/j784s4.env   |   35 +
  board/ti/j784s4/pm-cfg.yaml  |   12 +
  board/ti/j784s4/rm-cfg.yaml  | 3057 ++
  board/ti/j784s4/sec-cfg.yaml |  379 
  board/ti/j784s4/tifs-rm-cfg.yaml | 2655 ++
  include/configs/j784s4_evm.h |   20 +
  12 files changed, 6373 insertions(+)
  create mode 100644 board/ti/j784s4/Kconfig
  create mode 100644 board/ti/j784s4/MAINTAINERS
  create mode 100644 board/ti/j784s4/Makefile
  create mode 100644 board/ti/j784s4/board-cfg.yaml
  create mode 100644 board/ti/j784s4/evm.c
  create mode 100644 board/ti/j784s4/j784s4.env
  create mode 100644 board/ti/j784s4/pm-cfg.yaml
  create mode 100644 board/ti/j784s4/rm-cfg.yaml
  create mode 100644 board/ti/j784s4/sec-cfg.yaml
  create mode 100644 board/ti/j784s4/tifs-rm-cfg.yaml
  create mode 100644 include/configs/j784s4_evm.h

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 0af2ec6ddb..ba3dd393e3 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -197,4 +197,5 @@ source "board/ti/j721e/Kconfig"
  source "board/siemens/iot2050/Kconfig"
  source "board/ti/j721s2/Kconfig"
  source "board/toradex/verdin-am62/Kconfig"
+source "board/ti/j784s4/Kconfig"
  endif
diff --git a/board/ti/j784s4/Kconfig b/board/ti/j784s4/Kconfig
new file mode 100644
index 00..7eeb21f451
--- /dev/null
+++ b/board/ti/j784s4/Kconfig
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+#  Hari Nagalla 
+
+choice
+   prompt "K3 J784S4 board"
+   optional
+
+config TARGET_J784S4_A72_EVM
+   bool "TI K3 based J784S4 EVM running on A72"
+   select ARM64
+   select SOC_K3_J784S4
+   select BOARD_LATE_INIT
+   select SYS_DISABLE_DCACHE_OPS
+   select BINMAN
+
+config TARGET_J784S4_R5_EVM
+   bool "TI K3 based J784S4 EVM running on R5"
+   select CPU_V7R
+   select SYS_THUMB_BUILD
+   select SOC_K3_J784S4
+   select K3_LOAD_SYSFW
+   select RAM
+   select SPL_RAM
+   select K3_DDRSS
+   select BINMAN
+   imply SYS_K3_SPL_ATF
+
+endchoice
+
+if TARGET_J784S4_A72_EVM
+
+config SYS_BOARD
+   default "j784s4"
+
+config SYS_VENDOR
+   default "ti"
+
+config SYS_CONFIG_NAME
+   default "j784s4_evm"
+
+source "board/ti/common/Kconfig"
+
+endif
+
+if TARGET_J784S4_R5_EVM
+
+config SYS_BOARD
+   default "j784s4"
+
+config SYS_VENDOR
+   default "ti"
+
+config SYS_CONFIG_NAME
+   default "j784s4_evm"
+
+config SPL_LDSCRIPT
+   default "arch/arm/mach-omap2/u-boot-spl.lds"
+
+source "board/ti/common/Kconfig"
+
+endif
diff --git a/board/ti/j784s4/MAINTAINERS b/board/ti/j784s4/MAINTAINERS
new file mode 100644
index 00..7d3549dd31
--- /dev/null
+++ b/board/ti/j784s4/MAINTAINERS
@@ -0,0 +1,20 @@
+J784S4 BOARD
+M: Hari Nagalla 
+S: Maintained
+F: board/ti/j784s4
+F: arch/arm/mach-k3/j784s4
+F: include/configs/j784s4_evm.h
+F: configs/j784s4_evm_r5_defconfig
+F: configs/j784s4_evm_a72_defconfig
+F: arch/arm/dts/k3-j784s4.dtsi
+F: arch/arm/dts/k3-j784s4-main.dtsi
+F: arch/arm/dts/k3-j784s4-mcu-wakeup.dtsi
+F: arch/arm/dts/k3-j784s4-thermal.dtsi
+F: arch/arm/dts/k3-j784s4-evm.dts
+F: arch/arm/dts/k3-j784s4-evm-u-boot.dtsi
+F: arch/arm/dts/k3-j784s4-r5-evm.dts
+F: arch/arm/dts/k3-j784s4-ddr.dtsi
+F: arch/arm/dts/k3-j784s4-ddr-evm-lp4-4266.dtsi
+F: arch/arm/dts/k3-am69-sk.dts
+F: arch/arm/dts/k3-am69-sk-u-boot.dtsi
+F: arch/arm/dts/k3-am69-r5-sk.dts
diff --git a/board/ti/j784s4/Makefile b/board/ti/j784s4/Makefile
new file mode 100644
index 00..fc98b24a2d
--- /dev/null
+++ b/board/ti/j784s4/Makefile
@@ -0,0 +1,8 @@
+#
+# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
+#  Hari Nagalla 
+#
+# SPDX-License-Identifier: GPL-2.0+

SPDX tag must be the first line?

Okay, will fix, thanks!



+#
+
+obj-y  += evm.o
diff --git a/board/ti/j784s4/board-cfg.yaml b/board/ti/j784s4/board-cfg.yaml
new file mode 100644
index 00..ea9a8b4a26
--- /dev/null
+++ b/board/ti/j784s4/board-cfg.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Board configuration for J784S4
+#
+




--
Thanks 

Re: [PATCH v3 07/16] remoteproc: k3-dsp: Extend support for C71x DSPs on J784S4 SoCs

2023-09-19 Thread Apurva Nandan



On 09/09/23 16:28, Roger Quadros wrote:


On 08/09/2023 14:05, Apurva Nandan wrote:

From: Hari Nagalla 

The K3 J784S4 SoCs have four C71x DSP subsystems in MAIN voltage domain

missing period.

SoCs have/SoC has


The C71x DSPs are 64 bit machine with fixed and floating point DSP> operations. 
The C71x DSP subsystem is a slighly updated version of the

slighly/slightly


C71x DSP subsystem on J721e. And, same ip data can be used for J7200,

J721e/J721E
ip/IP


J721S2 and J784S4.

Extend support to the C71x DSPs for J784S4 with J721S2 compatible
string.



Signed-off-by: Hari Nagalla 
Signed-off-by: Apurva Nandan 
---
  drivers/remoteproc/ti_k3_dsp_rproc.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/ti_k3_dsp_rproc.c 
b/drivers/remoteproc/ti_k3_dsp_rproc.c
index 1a2e9dd1f5..d856e31db8 100644
--- a/drivers/remoteproc/ti_k3_dsp_rproc.c
+++ b/drivers/remoteproc/ti_k3_dsp_rproc.c
@@ -327,7 +327,8 @@ static int k3_dsp_of_get_memories(struct udevice *dev)
  
  	for (i = 0; i < dsp->num_mems; i++) {

/* C71 cores only have a L1P Cache, there are no L1P SRAMs */
-   if (device_is_compatible(dev, "ti,j721e-c71-dsp") &&
+   if (((device_is_compatible(dev, "ti,j721e-c71-dsp")) ||
+(device_is_compatible(dev, "ti,j721s2-c71-dsp"))) &&
!strcmp(mem_names[i], "l1pram")) {
dsp->mem[i].bus_addr = FDT_ADDR_T_NONE;
dsp->mem[i].dev_addr = FDT_ADDR_T_NONE;
@@ -446,6 +447,7 @@ static const struct k3_dsp_boot_data c71_data = {
  static const struct udevice_id k3_dsp_ids[] = {
{ .compatible = "ti,j721e-c66-dsp", .data = (ulong)_data, },
{ .compatible = "ti,j721e-c71-dsp", .data = (ulong)_data, },
+   { .compatible = "ti,j721s2-c71-dsp", .data = (ulong)_data, },
{}
  };
  

Okay, will fix all, thanks!

--
Thanks and regards,
Apurva Nandan,
Texas Instruments India.



Re: [PATCH v3 06/16] remoteproc: k3-r5: Extend support for R5F clusters on J784S4 SoCs

2023-09-19 Thread Apurva Nandan

Hi,

On 09/09/23 16:26, Roger Quadros wrote:


On 08/09/2023 14:05, Apurva Nandan wrote:

From: Hari Nagalla 

The K3 J784S4 SoCs have four dual-core R5F subsystems, one in MCU
voltage domain and the other three in MAIN voltage domain. These R5F
clusters are similar to the R5F clusters in J7200 and J721S2 SoCs.

Extend support to the R5F clusters for J784S4 with J721S2 compatible
string.

Signed-off-by: Hari Nagalla 
Signed-off-by: Apurva Nandan 
---
  drivers/remoteproc/ti_k3_r5f_rproc.c | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/ti_k3_r5f_rproc.c 
b/drivers/remoteproc/ti_k3_r5f_rproc.c
index 6f3e12d915..631e548dcc 100644
--- a/drivers/remoteproc/ti_k3_r5f_rproc.c
+++ b/drivers/remoteproc/ti_k3_r5f_rproc.c
@@ -855,7 +855,7 @@ static const struct k3_r5f_ip_data k3_data = {
.tcm_ecc_autoinit = false,
  };
  
-static const struct k3_r5f_ip_data j7200_data = {

+static const struct k3_r5f_ip_data j7200_j721s2_data = {

No need to rename this.

Okay



.tcm_is_double = true,
.tcm_ecc_autoinit = true,
  };
@@ -863,7 +863,8 @@ static const struct k3_r5f_ip_data j7200_data = {
  static const struct udevice_id k3_r5f_rproc_ids[] = {
{ .compatible = "ti,am654-r5f", .data = (ulong)_data, },
{ .compatible = "ti,j721e-r5f", .data = (ulong)_data, },
-   { .compatible = "ti,j7200-r5f", .data = (ulong)_data, },
+   { .compatible = "ti,j7200-r5f", .data = (ulong)_j721s2_data, },
+   { .compatible = "ti,j721s2-r5f", .data = (ulong)_j721s2_data, },

Where is DT binding documentation for this?

Don't you need compatible for ti,j728s4-r5f?

We don't actually need a new compatible for j784s4 r5f, as
it is the same IP as on j721s2 and j7200. It uses same ip data
in the driver as well.



{}
  };
  
@@ -901,6 +902,7 @@ static const struct udevice_id k3_r5fss_ids[] = {

{ .compatible = "ti,am654-r5fss"},
{ .compatible = "ti,j721e-r5fss"},
{ .compatible = "ti,j7200-r5fss"},
+   { .compatible = "ti,j721s2-r5fss"},
{}
  };
  


--
Thanks and regards,
Apurva Nandan,
Texas Instruments India.



Re: [PATCH v3 02/16] arm: mach-k3: Add basic support for J784S4 SoC definition

2023-09-19 Thread Apurva Nandan

Hi,

On 09/09/23 16:18, Roger Quadros wrote:

Hi,

On 08/09/2023 14:05, Apurva Nandan wrote:

Add j784s4 initialization files for initial SPL boot.

Please be consistent in naming. J784S4 ?


Signed-off-by: Hari Nagalla 
[ add firewall configurations and change the R5 MCU scratchpad ]
Signed-off-by: Manorit Chawdhry 
Signed-off-by: Dasnavis Sabiya 
Signed-off-by: Apurva Nandan 
---
  arch/arm/mach-k3/Kconfig  |  16 +-
  arch/arm/mach-k3/Makefile |   3 +
  arch/arm/mach-k3/arm64-mmu.c  |  52 +++
  arch/arm/mach-k3/include/mach/hardware.h  |   4 +
  .../mach-k3/include/mach/j784s4_hardware.h|  60 
  arch/arm/mach-k3/include/mach/j784s4_spl.h|  46 +++
  arch/arm/mach-k3/include/mach/spl.h   |   6 +-
  arch/arm/mach-k3/j784s4_fdt.c |  15 +
  arch/arm/mach-k3/j784s4_init.c| 332 ++
  9 files changed, 526 insertions(+), 8 deletions(-)
  create mode 100644 arch/arm/mach-k3/include/mach/j784s4_hardware.h
  create mode 100644 arch/arm/mach-k3/include/mach/j784s4_spl.h
  create mode 100644 arch/arm/mach-k3/j784s4_fdt.c
  create mode 100644 arch/arm/mach-k3/j784s4_init.c

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 9168bf842d..0af2ec6ddb 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -22,6 +22,9 @@ config SOC_K3_AM625
  config SOC_K3_AM62A7
bool "TI's K3 based AM62A7 SoC Family Support"
  
+config SOC_K3_J784S4

+   bool "TI's K3 based J784S4 SoC Family Support"
+
  endchoice
  
  config SYS_SOC

@@ -30,7 +33,7 @@ config SYS_SOC
  config SYS_K3_NON_SECURE_MSRAM_SIZE
hex
default 0x8 if SOC_K3_AM654
-   default 0x10 if SOC_K3_J721E || SOC_K3_J721S2
+   default 0x10 if SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_J784S4
default 0x1c if SOC_K3_AM642
default 0x3c000 if SOC_K3_AM625 || SOC_K3_AM62A7
help
@@ -42,7 +45,7 @@ config SYS_K3_NON_SECURE_MSRAM_SIZE
  config SYS_K3_MAX_DOWNLODABLE_IMAGE_SIZE
hex
default 0x58000 if SOC_K3_AM654
-   default 0xc if SOC_K3_J721E || SOC_K3_J721S2
+   default 0xc if SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_J784S4
default 0x18 if SOC_K3_AM642
default 0x38000 if SOC_K3_AM625 || SOC_K3_AM62A7
help
@@ -52,15 +55,14 @@ config SYS_K3_MAX_DOWNLODABLE_IMAGE_SIZE
  config SYS_K3_MCU_SCRATCHPAD_BASE
hex
default 0x4028 if SOC_K3_AM654
-   default 0x41cff9fc if SOC_K3_J721S2
-   default 0x41cff9fc if SOC_K3_J721E
+   default 0x41cff9fc if SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_J784S4
help
  Describes the base address of MCU Scratchpad RAM.
  
  config SYS_K3_MCU_SCRATCHPAD_SIZE

hex
default 0x200 if SOC_K3_AM654
-   default 0x200 if SOC_K3_J721E || SOC_K3_J721S2
+   default 0x200 if SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_J784S4
help
  Describes the size of MCU Scratchpad RAM.
  
@@ -68,7 +70,7 @@ config SYS_K3_BOOT_PARAM_TABLE_INDEX

hex
default 0x41c7fbfc if SOC_K3_AM654
default 0x41cffbfc if SOC_K3_J721E
-   default 0x41cfdbfc if SOC_K3_J721S2
+   default 0x41cfdbfc if SOC_K3_J721S2 || SOC_K3_J784S4

Pleas move this to one line along with SOC_K3_J721E


default 0x701bebfc if SOC_K3_AM642
default 0x43c3f290 if SOC_K3_AM625
default 0x43c3f290 if SOC_K3_AM62A7 && CPU_V7R
@@ -172,7 +174,7 @@ config K3_ATF_LOAD_ADDR
  
  config K3_DM_FW

bool "Separate DM firmware image"
-   depends on SPL && CPU_V7R && (SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_AM625 || 
SOC_K3_AM62A7) && !CLK_TI_SCI && !TI_SCI_POWER_DOMAIN
+   depends on SPL && CPU_V7R && (SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_AM625 || 
SOC_K3_AM62A7 || SOC_K3_J784S4) && !CLK_TI_SCI && !TI_SCI_POWER_DOMAIN
default y
help
  Enabling this will indicate that the system has separate DM
diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
index fd77b8bbba..6fe36c265c 100644
--- a/arch/arm/mach-k3/Makefile
+++ b/arch/arm/mach-k3/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_SOC_K3_J721E) += j721e/ j7200/
  obj-$(CONFIG_SOC_K3_J721S2) += j721s2/
  obj-$(CONFIG_SOC_K3_AM625) += am62x/
  obj-$(CONFIG_SOC_K3_AM62A7) += am62ax/
+obj-$(CONFIG_SOC_K3_J784S4) += j784s4/
  obj-$(CONFIG_ARM64) += arm64-mmu.o
  obj-$(CONFIG_CPU_V7R) += r5_mpu.o lowlevel_init.o
  obj-$(CONFIG_ARM64) += cache.o
@@ -16,6 +17,7 @@ obj-$(CONFIG_SOC_K3_AM654) += am654_fdt.o
  obj-$(CONFIG_SOC_K3_J721E) += j721e_fdt.o
  obj-$(CONFIG_SOC_K3_J721S2) += j721s2_fdt.o
  obj-$(CONFIG_SOC_K3_AM625) += am625_fdt.o
+obj-$(CONFIG_SOC_K3_J784S4) += j784s4_fdt.o
  endif
  ifeq ($(CONFIG_SPL_BUILD),y)
  obj-$(CONFIG_SOC_K3_AM654) += am654_init.o
@@ -24,6 +26,7 @@ obj-$(CONFIG_SOC_K3_J721S2) += j721s2_init.o
  obj-$(CONFIG_SOC_K3_AM642) += am642_init.o
  obj-$(CONFIG_SOC_K3_AM625) += am625_init.o
  

Re: [PATCH v3 01/16] arm: dts: Introduce j784s4 dts from linux kernel

2023-09-19 Thread Apurva Nandan

Hi,

On 09/09/23 16:20, Roger Quadros wrote:


On 08/09/2023 14:05, Apurva Nandan wrote:

Introduce the basic j784s4 SoC dts from the next-20230905 tag of the
linux kernel.

Signed-off-by: Hari Nagalla 
Signed-off-by: Apurva Nandan 
---
  arch/arm/dts/k3-j784s4-evm.dts |  864 +
  arch/arm/dts/k3-j784s4-main.dtsi   | 1571 
  arch/arm/dts/k3-j784s4-mcu-wakeup.dtsi |  703 +++
  arch/arm/dts/k3-j784s4-thermal.dtsi|  101 ++
  arch/arm/dts/k3-j784s4.dtsi|  294 +
  5 files changed, 3533 insertions(+)
  create mode 100644 arch/arm/dts/k3-j784s4-evm.dts
  create mode 100644 arch/arm/dts/k3-j784s4-main.dtsi
  create mode 100644 arch/arm/dts/k3-j784s4-mcu-wakeup.dtsi
  create mode 100644 arch/arm/dts/k3-j784s4-thermal.dtsi
  create mode 100644 arch/arm/dts/k3-j784s4.dtsi

Shouldn't this patch come last in the series?
What about DT-binding documentation for J784S4 SoC and its modules?

These dts files are directly imported/copied from Linux dts source,
so the binding are already taken care of in Linux.

As it is a direct import from linux, and u-boot dts depend on these,
I had put them in start. But if you want, I can put them just after
patch #8

--
Thanks and regards,
Apurva Nandan,
Texas Instruments India.



Re: [PATCH v2] clk: ti: Notify AVS driver upon setting clock rate

2023-09-19 Thread Kumar, Udit

Hi Nishanth,

On 9/19/2023 9:07 PM, Nishanth Menon wrote:

On 19:34-20230919, Udit Kumar wrote:

AVS is enabled at R5 SPL stage, on few platforms like J721E
and J7200 clk-k3 is used instead if clk-sci driver.

Add support in clk-k3 driver as well to notify AVS driver
upon setting clock rate so that voltage is changed accordingly.

Cc: Keerthy 
Signed-off-by: Udit Kumar 
---
Change log:
Changes in v2:
- Kept clk-sci.c as is because this is used by
AM64 and AM65 platforms
- v1 link
https://lore.kernel.org/all/20230919060649.2518147-1-u-kum...@ti.com/

  drivers/clk/ti/clk-k3.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/drivers/clk/ti/clk-k3.c b/drivers/clk/ti/clk-k3.c
index ba925fa3c4..8016c3784a 100644
--- a/drivers/clk/ti/clk-k3.c
+++ b/drivers/clk/ti/clk-k3.c
@@ -11,6 +11,7 @@
  #include 
  #include 
  #include 
+#include 
  #include "k3-clk.h"
  
  #define PLL_MIN_FREQ	8

@@ -339,6 +340,10 @@ static ulong ti_clk_set_rate(struct clk *clk, ulong rate)
}
}
  
+	if (IS_ENABLED(CONFIG_K3_AVS0))

+   k3_avs_notify_freq(data->map[clk->id].dev_id,
+  data->map[clk->id].clk_id, rate);
+

Don't you want to do this prior to actual clock change?


Not really, As i see new freq to be less than current one.


F1, V1 -> F2, V2

Seq 1:
F1, V1
F2, V1
F2, V2

Seq 2:
F1, V1
F1, V2
F2, V2

If V2 < V1 (implying F2 < F1), then Seq 1 is valid. But if V2 > V1 (F2 >
F1) Seq 2 is valid.

We seem to ignore this constraint. Can you explain this in the commit
message?


Sure, will do , Below is reasoning, Please see if make sense

On J7 devices,  In default device tree, A72 freq is set to 2Ghz, few 
SOCs can operate at lower freq.


So while setting OPP freq (which is less than default one), First freq 
needs to set


before changing voltage.


On other hand, I am thinking to fix properly for both cases, 
irrespective of seq 1 is


valid for current use case.




clk-sci.c seems to use Seq 2, vs this patch seems to take Seq 1.


I think, something to be fixed for clk-sci.c as well.
As I see three freq point 
https://elixir.bootlin.com/u-boot/latest/source/drivers/misc/k3_avs.c#L339


So we can choose either way new-freq > current-freq or new-freq < 
current-freq,


Based upon new-freq , voltage to be set before/after clock change.





return new_rate;
  }
  
--

2.34.1



[PATCH] arm64: versal: Add SelectMAP boot mode identification

2023-09-19 Thread Polak, Leszek
Add missing SelectMAP bootmode for proper identification during boot.

The SelectMAP configuration interface provides an 8-bit, 16-bit or
32-bit bidirectional data bus interface to the Versal FPGA
configuration logic that can be used for both configuration and
readback.

A connected microcontoller to the SelectMAP interface can load boot
image with bitstream, TF-A (ARM Trusted Firmware) and U-Boot.

This commit adds the missing identification of the SelectMAP mode.

Signed-off-by: Leszek Polak 
Cc: Michal Simek 
Cc: Stefan Roese 
---
 arch/arm/mach-versal-net/include/mach/hardware.h | 1 +
 arch/arm/mach-versal/include/mach/hardware.h | 1 +
 board/xilinx/versal-net/board.c  | 4 
 board/xilinx/versal/board.c  | 5 +
 4 files changed, 11 insertions(+)

diff --git a/arch/arm/mach-versal-net/include/mach/hardware.h 
b/arch/arm/mach-versal-net/include/mach/hardware.h
index 9bddb8b00723..767cdd368682 100644
--- a/arch/arm/mach-versal-net/include/mach/hardware.h
+++ b/arch/arm/mach-versal-net/include/mach/hardware.h
@@ -66,6 +66,7 @@ struct crp_regs {
 #define EMMC_MODE  0x0006
 #define USB_MODE   0x0007
 #define OSPI_MODE  0x0008
+#define SELECTMAP_MODE 0x000A
 #define SD1_LSHFT_MODE 0x000E /* SD1 Level shifter */
 #define JTAG_MODE  0x
 #define BOOT_MODE_USE_ALT  0x100
diff --git a/arch/arm/mach-versal/include/mach/hardware.h 
b/arch/arm/mach-versal/include/mach/hardware.h
index 000af974e867..9d1c2f0dcfc1 100644
--- a/arch/arm/mach-versal/include/mach/hardware.h
+++ b/arch/arm/mach-versal/include/mach/hardware.h
@@ -82,6 +82,7 @@ struct crp_regs {
 #define EMMC_MODE  0x0006
 #define USB_MODE   0x0007
 #define OSPI_MODE  0x0008
+#define SELECTMAP_MODE 0x000A
 #define SD1_LSHFT_MODE 0x000E /* SD1 Level shifter */
 #define JTAG_MODE  0x
 #define BOOT_MODE_USE_ALT  0x100
diff --git a/board/xilinx/versal-net/board.c b/board/xilinx/versal-net/board.c
index f0d2224b332e..992e0df73b30 100644
--- a/board/xilinx/versal-net/board.c
+++ b/board/xilinx/versal-net/board.c
@@ -287,6 +287,10 @@ int board_late_init(void)
mode = "mmc";
bootseq = dev_seq(dev);
break;
+   case SELECTMAP_MODE:
+   puts("SELECTMAP_MODE\n");
+   mode = "selectmap";
+   break;
default:
mode = "";
printf("Invalid Boot Mode:0x%x\n", bootmode);
diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
index 60bf37d3c90f..b619dbc73c80 100644
--- a/board/xilinx/versal/board.c
+++ b/board/xilinx/versal/board.c
@@ -213,6 +213,10 @@ int board_late_init(void)
mode = "mmc";
bootseq = dev_seq(dev);
break;
+   case SELECTMAP_MODE:
+   puts("SELECTMAP_MODE\n");
+   mode = "selectmap";
+   break;
default:
mode = "";
printf("Invalid Boot Mode:0x%x\n", bootmode);
@@ -298,6 +302,7 @@ enum env_location env_get_location(enum env_operation op, 
int prio)
return ENVL_SPI_FLASH;
return ENVL_NOWHERE;
case JTAG_MODE:
+   case SELECTMAP_MODE:
default:
return ENVL_NOWHERE;
}
--
2.42.0


  1   2   >