[PATCH] malloc: Enable assertions if UNIT_TEST is enabled

2023-10-07 Thread Sean Anderson
dlmalloc has some sanity checks it performs on free() which can help detect
memory corruption. However, they are only enabled if DEBUG is defined before
including common.h. Define DEBUG earlier if UNIT_TEST is enabled so that
assertions are enabled in sandbox.

Signed-off-by: Sean Anderson 
---

 common/dlmalloc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index dcecdb8623c..500a0dbda89 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -8,14 +8,14 @@
  * as file malloc-2.6.6.c.
  */
 
+#if CONFIG_IS_ENABLED(UNIT_TEST)
+#define DEBUG
+#endif
+
 #include 
 #include 
 #include 
 
-#if CONFIG_IS_ENABLED(UNIT_TEST)
-#define DEBUG
-#endif
-
 #include 
 #include 
 #include 
-- 
2.37.1



[PATCH] net: Add option for tracing packets

2023-10-07 Thread Sean Anderson
Add an option to trace all packets send/received. This can be helpful when
debugging protocol issues, as the packets can then be imported into
wireshark [1] and analyzed further.

[1] https://www.wireshark.org/docs/wsug_html_chunked/ChIOImportSection.html

Signed-off-by: Sean Anderson 
---

 include/net.h | 4 
 net/net.c | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/include/net.h b/include/net.h
index e254df7d7f4..e63a946002d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -16,6 +16,7 @@
 #include 
 #include  /* for nton* / ntoh* stuff */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -29,6 +30,7 @@ struct udevice;
 #define DEBUG_DEV_PKT 0/* Packets or info directed to the 
device */
 #define DEBUG_NET_PKT 0/* Packets on info on the network at 
large */
 #define DEBUG_INT_STATE 0  /* Internal network state changes */
+#define DEBUG_NET_PKT_TRACE 0  /* Trace all packet data */
 
 /*
  * The number of receive packet buffers, and the required packet buffer
@@ -640,6 +642,8 @@ uchar * net_get_async_tx_pkt_buf(void);
 /* Transmit a packet */
 static inline void net_send_packet(uchar *pkt, int len)
 {
+   if (DEBUG_NET_PKT_TRACE)
+   print_hex_dump_bytes("tx: ", DUMP_PREFIX_OFFSET, pkt, len);
/* Currently no way to return errors from eth_send() */
(void) eth_send(pkt, len);
 }
diff --git a/net/net.c b/net/net.c
index 43abbac7c32..53eb9ef1324 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1201,6 +1201,9 @@ void net_process_received_packet(uchar *in_packet, int 
len)
ushort cti = 0, vlanid = VLAN_NONE, myvlanid, mynvlanid;
 
debug_cond(DEBUG_NET_PKT, "packet received\n");
+   if (DEBUG_NET_PKT_TRACE)
+   print_hex_dump_bytes("rx: ", DUMP_PREFIX_OFFSET, in_packet,
+len);
 
 #if defined(CONFIG_CMD_PCAP)
pcap_post(in_packet, len, false);
-- 
2.37.1



[PATCH] spl: mmc: Fix subsequent calls to spl_mmc_load with CONFIG_BLK

2023-10-07 Thread Sean Anderson
MMC devices do not have uclass platdata containing blk_descs, only their
child block devices do. Fortunately, we have a function just for this
purpose. This fixes subsequent calls to spl_mmc_load.

Fixes: bf28d9a6599 ("spl: mmc: Use correct MMC device when loading image")
Signed-off-by: Sean Anderson 
---

 common/spl/spl_mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index a665091b00f..2be991d5890 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -396,7 +396,7 @@ static int spl_mmc_get_mmc_devnum(struct mmc *mmc)
 #if !CONFIG_IS_ENABLED(BLK)
block_dev = &mmc->block_dev;
 #else
-   block_dev = dev_get_uclass_plat(mmc->dev);
+   block_dev = mmc_get_blk_desc(mmc);
 #endif
return block_dev->devnum;
 }
-- 
2.37.1



Re: [PATCH 3/3] mx28evk: Add USB Mass Storage support

2023-10-07 Thread Marek Vasut

On 10/7/23 23:56, Fabio Estevam wrote:

From: Fabio Estevam 

Select the USB options to allow running "ums 0 mmc 0".

Signed-off-by: Fabio Estevam 
---
  configs/mx28evk_defconfig | 14 ++
  1 file changed, 14 insertions(+)

diff --git a/configs/mx28evk_defconfig b/configs/mx28evk_defconfig
index df0cceaea719..15cc99684c05 100644
--- a/configs/mx28evk_defconfig
+++ b/configs/mx28evk_defconfig
@@ -32,6 +32,9 @@ CONFIG_CMD_DM=y
  CONFIG_CMD_GPIO=y
  CONFIG_CMD_MMC=y
  CONFIG_CMD_NAND_TRIMFFS=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_USB_SDP=y


This seems to be doing more than just enabling UMS, right ?
SDP is enabled too, but not mentioned in commit message.


+CONFIG_CMD_USB_MASS_STORAGE=y
  CONFIG_CMD_CACHE=y
  CONFIG_CMD_DATE=y
  CONFIG_CMD_EXT4=y
@@ -65,3 +68,14 @@ CONFIG_RTC_MXS=y
  CONFIG_DM_SERIAL=y
  CONFIG_SPI=y
  CONFIG_USB=y
+CONFIG_SPL_USB_HOST=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_MAX_CONTROLLER_COUNT=2
+CONFIG_USB_GADGET=y
+CONFIG_SPL_USB_GADGET=y


This SPL USB gadget is not related to UMS either .

Please fix, either document the full amount of changes, or drop 
unrelated changes.


[...]


Re: [PATCH 2/3] usb: ehci: mxs: Use regulator_set_enable_if_allowed()

2023-10-07 Thread Marek Vasut

On 10/7/23 23:56, Fabio Estevam wrote:

From: Fabio Estevam 

Since commit 4fcba5d556b4 ("regulator: implement basic reference
counter") the return value of regulator_set_enable() may be EALREADY or
EBUSY for fixed/GPIO regulators.

Swict to using the more relaxed regulator_set_enable_if_allowed() to
continue if regulator already was enabled or disabled.

This fixes the following error when running the 'ums' command:

=> ums 0 mmc 0
UMS: LUN 0, dev mmc 0, hwpart 0, sector 0x0, count 0xece000
Error enabling VBUS supply
g_dnl_register: failed!, error: -114
g_dnl_register failed

Signed-off-by: Fabio Estevam 


Reviewed-by: Marek Vasut 


Re: [PATCH 1/3] usb: ehci: mxs: Fix the USB node pointer retrieval

2023-10-07 Thread Marek Vasut

On 10/7/23 23:56, Fabio Estevam wrote:

From: Fabio Estevam 

Use dev_ofnode() to retrieve the USB node pointer from the udevice
structure.

This fixes the following build error:

drivers/usb/host/ehci-mxs.c:143:38: error: 'struct udevice' has no member named 
'node_'


How come this was never trapped by CI ?

Reviewed-by: Marek Vasut 


Re: [PATCH v2 RESEND] mmc: dw_mmc: reset controller after data error

2023-10-07 Thread Kever Yang



On 2023/6/19 18:33, Eugen Hristev wrote:

From: Ziyuan Xu 

Per dw_mmc databook, it's recommended to reset the host controller if
some data-related error occurred.
Implement a reset mechanism.

Signed-off-by: Ziyuan Xu 
Co-developed-by: Jason Zhu 
Signed-off-by: Jason Zhu 
[eugen.hris...@collabora.com: modified a bit the variables initialization]
Signed-off-by: Eugen Hristev 



Reviewed-by: Kever Yang 

Thanks,
- Kever


---
  drivers/mmc/dw_mmc.c | 20 +++-
  1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c
index 5085a3b491da..d6cad998b0cd 100644
--- a/drivers/mmc/dw_mmc.c
+++ b/drivers/mmc/dw_mmc.c
@@ -138,7 +138,7 @@ static int dwmci_data_transfer(struct dwmci_host *host, 
struct mmc_data *data)
  {
struct mmc *mmc = host->mmc;
int ret = 0;
-   u32 timeout, mask, size, i, len = 0;
+   u32 timeout, reset_timeout = 100, status, ctrl, mask, size, i, len = 0;
u32 *buf = NULL;
ulong start = get_timer(0);
u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >>
@@ -159,6 +159,24 @@ static int dwmci_data_transfer(struct dwmci_host *host, 
struct mmc_data *data)
/* Error during data transfer. */
if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) {
debug("%s: DATA ERROR!\n", __func__);
+
+   dwmci_wait_reset(host, DWMCI_RESET_ALL);
+   dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT |
+DWMCI_CMD_UPD_CLK | DWMCI_CMD_START);
+
+   do {
+   status = dwmci_readl(host, DWMCI_CMD);
+   if (!reset_timeout--)
+   break;
+   udelay(100);
+   } while (status & DWMCI_CMD_START);
+
+   if (!host->fifo_mode) {
+   ctrl = dwmci_readl(host, DWMCI_BMOD);
+   ctrl |= DWMCI_BMOD_IDMAC_RESET;
+   dwmci_writel(host, DWMCI_BMOD, ctrl);
+   }
+
ret = -EINVAL;
break;
}


Re: [PATCH v2 RESEND] mmc: dw_mmc: reset controller after data error

2023-10-07 Thread Kever Yang

Hi Tom,

    Could you have a try with rockchip vendor U-Boot, maybe still some 
other fixes are missing in mainline U-Boot mmc driver.



Thanks,

- Kever

On 2023/10/7 22:37, Tom Fitzhenry wrote:

I am able to reproduce this on RK3588 QuartzPro64.

I thought "[PATCH v2 RESEND] mmc: dw_mmc: reset controller after data
error"[0] might fix this, but after applying that, I am still able to
reproduce the issue.

0. 
https://lore.kernel.org/u-boot/20230619103347.278004-1-eugen.hris...@collabora.com/


Re: Pull request: u-boot-rockchip-20231007

2023-10-07 Thread Kever Yang

Hi Jonas,

On 2023/10/7 18:37, Jonas Karlman wrote:

Hi Kever,

Looks like the following patch is missing:

[v2,7/7] rockchip: rk3568-radxa-e25: Enable pcie3x1 node
https://patchwork.ozlabs.org/patch/1816145/


This patch set does not show in sorted order in the patchwork system.

I use the last patch(which is 6/7) to apply this series, but 
unfortunately 7/7 is missing.


How do you send this patch set? All other patch sets looks OK in system.

I can pick this patch up later when merge other patches for next PR.


Thanks,

- Kever



from merged series:
[v2,0/7] rockchip: rk3568: Fix use of PCIe bifurcation

Do you want me to send it as a new separate patch?

Regards,
Jonas

On 2023-10-07 12:26, Kever Yang wrote:

Hi Tom,

Please pull the updates for rockchip platform:
- Add Board: rk3568 Bananapi R2Pro;
- Update pcie bifurcation support;
- dwc_eth_qos controller support for rk3568 and rk3588;
- Compressed binary support for U-Boot on rockchip platform;
- dts and config updates for different board and soc;

CI:
https://source.denx.de/u-boot/custodians/u-boot-rockchip/-/pipelines/18047

Thanks,
- Kever

The following changes since commit be2abe73df58a35da9e8d5afb13fccdf1b0faa8e:

   Merge https://source.denx.de/u-boot/custodians/u-boot-riscv (2023-10-05 
13:26:44 -0400)

are available in the Git repository at:

   https://source.denx.de/u-boot/custodians/u-boot-rockchip.git 
tags/u-boot-rockchip-20231007

for you to fetch changes up to dd8d52c934e8858264f91e8e8e2d8c7d8b059dd7:

   rockchip: rk356x-u-boot: Add bootph-all to i2c0_xfer pinctrl node 
(2023-10-07 16:52:48 +0800)


FUKAUMI Naoki (5):
   configs: rockchip: rock-pi-s: use default bootdelay (2s)
   arm: dts: rockchip: sync DT for RK3588 series with Linux
   arm: dts: rockchip: rock-5b: add support for PCIe3 and NVMe
   configs: rockchip: rk3308: use CONFIG_DEFAULT_FDT_FILE
   configs: rockchip: rk3308: enable CONFIG_OF_LIBFDT_OVERLAY

Frank Wunderlich (1):
   board: rockchip: Add Bananapi R2Pro Board

Jonas Karlman (22):
   pci: pcie_dw_rockchip: Configure number of lanes and link width speed
   phy: rockchip: snps-pcie3: Refactor to use clk_bulk API
   phy: rockchip: snps-pcie3: Refactor to use a phy_init ops
   phy: rockchip: snps-pcie3: Add bifurcation support for RK3568
   phy: rockchip: snps-pcie3: Add support for RK3588
   phy: rockchip: naneng-combphy: Use signal from comb PHY on RK3588
   rockchip: rk3568-nanopi-r5: Update defconfig for NanoPi R5C and R5S
   rockchip: rk3568-nanopi-r5: Enable PCIe on NanoPi R5C and R5S
   power: regulator: Only run autoset once for each regulator
   rockchip: Port IO-domain driver for RK3568 from linux
   rockchip: board: Add minimal generic RK3566/RK3568 board
   net: dwc_eth_qos: Drop unused rx_pkt from eqos_priv
   net: dwc_eth_qos: Return error code when start fails
   net: dwc_eth_qos: Stop spam of RX packet not available message
   net: dwc_eth_qos: Add glue driver for GMAC on Rockchip RK3568
   net: dwc_eth_qos_rockchip: Add support for RK3588
   configs: rockchip: Enable ethernet driver on RK356x boards
   configs: rockchip: Enable ethernet driver on RK3588 boards
   power: pmic: rk8xx: Use sysreset implementation of the poweroff command
   rockchip: rk356x: Enable poweroff command
   power: pmic: rk8xx: Fix power-on source check in SPL
   rockchip: rk356x-u-boot: Add bootph-all to i2c0_xfer pinctrl node

Joseph Chen (1):
   regulator: rk8xx: Return correct voltage for buck converters

Manoj Sai (4):
   spl: fit: support for booting a GZIP-compressed U-boot binary
   spl: fit: support for booting a LZMA-compressed U-boot binary
   rockchip: Add support to generate GZIP compressed U-boot binary
   rockchip: Add support to generate LZMA compressed U-boot binary

Massimo Pegorer (3):
   rockchip: Kconfig: Enable external TPL binary for rk3308
   doc: rockchip: Update and improve info on rk3308, TPL and TF-A
   configs: rockchip: add DOS_PARTITION to RK3308 boards defconfig

shengfei Xu (1):
   regulator: rk8xx: Return correct voltage for switchout converters

  arch/arm/dts/Makefile  |   1 +
  arch/arm/dts/rk3568-bpi-r2-pro-u-boot.dtsi |  19 +
  arch/arm/dts/rk3568-bpi-r2-pro.dts | 852 +
  arch/arm/dts/rk3568-generic-u-boot.dtsi|  14 +
  arch/arm/dts/rk3568-generic.dts|  38 +
  arch/arm/dts/rk3568-nanopi-r5c-u-boot.dtsi |   4 +
  arch/arm/dts/rk3568-nanopi-r5c.dts |   2 +-
  arch/arm/dts/rk3568-nanopi-r5s-u-boot.dtsi |  10 +-
  arch/arm/dts/rk356x-u-boot.dtsi|   8 +
  arch/arm/dts/rk3588-edgeble-neu6a-io-u-boot.dtsi   |   1 -
  arch/arm/dts/rk3588-edgeble-neu6a.dtsi |   1 -
  arch/arm/dts/rk3588-edgeble-neu6b-io-u-boot.dtsi

Re: [PATCH v2 04/27] bootstd: Correct dependencies on CMDLINE

2023-10-07 Thread Simon Glass
Hi Tom,

On Sat, 7 Oct 2023 at 17:32, Tom Rini  wrote:
>
> On Sat, Oct 07, 2023 at 05:12:23PM -0600, Simon Glass wrote:
>
> > With recent changes in boot/Kconfig it is no-longer possible to disable
> > CMDLINE. It results in various link errors because some options which
> > require CMDLINE are enabled regardless of whether it is available.
>
> How "recent" is this problem?

Over the last few years, I think. It was definitely in better shape
3-4 years ago.

I just realised that I sent your patches as part of my series, sorry.

Regards,
Simon


Re: [PATCH v2 04/27] bootstd: Correct dependencies on CMDLINE

2023-10-07 Thread Tom Rini
On Sat, Oct 07, 2023 at 05:12:23PM -0600, Simon Glass wrote:

> With recent changes in boot/Kconfig it is no-longer possible to disable
> CMDLINE. It results in various link errors because some options which
> require CMDLINE are enabled regardless of whether it is available.

How "recent" is this problem?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 07/25] tegra: Change #ifdef for nop

2023-10-07 Thread Sean Anderson

On 10/7/23 19:10, Simon Glass wrote:

Hi Tom.

On Sun, 24 Sept 2023 at 18:43, Tom Rini  wrote:


On Sun, Sep 24, 2023 at 02:39:25PM -0600, Simon Glass wrote:


This code is normally compiled for Tegra, but sandbox can also compile
it. We should not use UNIT_TEST as a synonym for SANDBOX, since it is
possible to disable UNIT_TEST for sandbox.

Correct the condition.

Signed-off-by: Simon Glass 
---

  include/k210/pll.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/k210/pll.h b/include/k210/pll.h
index fd16a89cb203..6dd60b2eb4fc 100644
--- a/include/k210/pll.h
+++ b/include/k210/pll.h
@@ -13,7 +13,7 @@ struct k210_pll_config {
   u8 od;
  };

-#ifdef CONFIG_UNIT_TEST
+#ifdef CONFIG_SANDBOX
  TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in,
struct k210_pll_config *best);
  #ifndef nop


Tegra? Do you mean sifive?  That's where CLK_K210 stuff is... but it


Oh yes, I got confused.


also seems wrong, you can run unit test on real hardware, and this is a
test that could (should?) be run on that platform.


Only if it enables UNIT_TEST. You cannot run unit tests without that.
The current tests are designed for sandbox.


FWIW I have run this test on actual hardware. My intent here was to allow
unit tests to access functions which would otherwise be declared static.

--Sean


[PATCH v2 25/27] arm: x86: Drop discarding of command linker-lists

2023-10-07 Thread Simon Glass
Since we can now cleanly disable CMDLINE when needed, drop the rules
which discard the command code.  It will not be built in the first
place.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to drop discarding of command linker-lists

 arch/arm/cpu/u-boot.lds | 3 ---
 arch/x86/cpu/u-boot-64.lds  | 4 
 arch/x86/cpu/u-boot-spl.lds | 4 
 arch/x86/cpu/u-boot.lds | 4 
 4 files changed, 15 deletions(-)

diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds
index fc4f63d83489..7724c9332c3b 100644
--- a/arch/arm/cpu/u-boot.lds
+++ b/arch/arm/cpu/u-boot.lds
@@ -14,9 +14,6 @@ OUTPUT_ARCH(arm)
 ENTRY(_start)
 SECTIONS
 {
-#ifndef CONFIG_CMDLINE
-   /DISCARD/ : { *(__u_boot_list_2_cmd_*) }
-#endif
 #if defined(CONFIG_ARMV7_SECURE_BASE) && defined(CONFIG_ARMV7_NONSEC)
/*
 * If CONFIG_ARMV7_SECURE_BASE is true, secure code will not
diff --git a/arch/x86/cpu/u-boot-64.lds b/arch/x86/cpu/u-boot-64.lds
index d0398ff00d71..00a6d8691211 100644
--- a/arch/x86/cpu/u-boot-64.lds
+++ b/arch/x86/cpu/u-boot-64.lds
@@ -11,10 +11,6 @@ ENTRY(_start)
 
 SECTIONS
 {
-#ifndef CONFIG_CMDLINE
-   /DISCARD/ : { *(__u_boot_list_2_cmd_*) }
-#endif
-
 #ifdef CONFIG_TEXT_BASE
. = CONFIG_TEXT_BASE;   /* Location of bootcode in flash */
 #endif
diff --git a/arch/x86/cpu/u-boot-spl.lds b/arch/x86/cpu/u-boot-spl.lds
index a0a2a06a18cd..50b4b1608552 100644
--- a/arch/x86/cpu/u-boot-spl.lds
+++ b/arch/x86/cpu/u-boot-spl.lds
@@ -11,10 +11,6 @@ ENTRY(_start)
 
 SECTIONS
 {
-#ifndef CONFIG_CMDLINE
-   /DISCARD/ : { *(__u_boot_list_2_cmd_*) }
-#endif
-
. = IMAGE_TEXT_BASE;/* Location of bootcode in flash */
__text_start = .;
.text  : {
diff --git a/arch/x86/cpu/u-boot.lds b/arch/x86/cpu/u-boot.lds
index a31f4220a000..c418ff44aa08 100644
--- a/arch/x86/cpu/u-boot.lds
+++ b/arch/x86/cpu/u-boot.lds
@@ -11,10 +11,6 @@ ENTRY(_start)
 
 SECTIONS
 {
-#ifndef CONFIG_CMDLINE
-   /DISCARD/ : { *(__u_boot_list_2_cmd_*) }
-#endif
-
. = CONFIG_TEXT_BASE;   /* Location of bootcode in flash */
__text_start = .;
 
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 22/27] efi: Depend on CMDLINE for efi_loader

2023-10-07 Thread Simon Glass
This features currently requires the command line, so make this
explicit. Future work could adjust this, but it needs effort within
the booting support first, like the bootm command.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/efi_loader/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 621ed5e5b0fb..2aef9336034e 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -12,6 +12,7 @@ config EFI_LOADER
depends on !EFI_STUB || !X86 || X86_64 || EFI_STUB_32BIT
depends on BLK
depends on !EFI_APP
+   depends on CMDLINE
default y if !ARM || SYS_CPU = armv7 || SYS_CPU = armv8
select CHARSET
# We need to send DM events, dynamically, in the EFI block driver
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 24/27] sandbox: Avoid requiring cmdline

2023-10-07 Thread Simon Glass
Use 'imply' rather than 'select' for command-related options, so that
it is possible to build sandbox without CONFIG_CMDLINE enabled.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 19f2891ba1c5..789be7a9f1e8 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -134,7 +134,6 @@ config SANDBOX
select ARCH_SUPPORTS_LTO
select BOARD_LATE_INIT
select BZIP2
-   select CMD_POWEROFF
select DM
select DM_EVENT
select DM_FUZZING_ENGINE
@@ -152,10 +151,8 @@ config SANDBOX
select PCI_ENDPOINT
select SPI
select SUPPORT_OF_CONTROL
-   select SYSRESET_CMD_POWEROFF
select SYS_CACHE_SHIFT_4
select IRQ
-   select SUPPORT_EXTENSION_SCAN
select SUPPORT_ACPI
imply BITREVERSE
select BLOBLIST
@@ -167,6 +164,7 @@ config SANDBOX
imply CMD_IO
imply CMD_IOTRACE
imply CMD_LZMADEC
+   imply CMD_POWEROFF
imply CMD_SF
imply CMD_SF_TEST
imply CRC32_VERIFY
@@ -208,6 +206,8 @@ config SANDBOX
imply PHYSMEM
imply GENERATE_ACPI_TABLE
imply BINMAN
+   imply SYSRESET_CMD_POWEROFF
+   imply SUPPORT_EXTENSION_SCAN
 
 config SH
bool "SuperH architecture"
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 23/27] cmd: Make all commands depend on CMDLINE

2023-10-07 Thread Simon Glass
If this option is disabled, commands should not be available. Convert
the CMDLINE option into a menuconfig and make every command in
cmd/Kconfig depend on it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/Kconfig | 29 -
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index c952b2e286cd..0a8c3e07242a 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1,7 +1,5 @@
-menu "Command line interface"
-
-config CMDLINE
-   bool "Support U-Boot commands"
+menuconfig CMDLINE
+   bool "Command line interface"
default y
help
  Enable U-Boot's command-line functions. This provides a means
@@ -11,9 +9,10 @@ config CMDLINE
  Depending on the number of commands enabled, this can add
  substantially to the size of U-Boot.
 
+if CMDLINE
+
 config HUSH_PARSER
bool "Use hush shell"
-   depends on CMDLINE
help
  This option enables the "hush" shell (from Busybox) as command line
  interpreter, thus enabling powerful command line syntax like
@@ -25,7 +24,6 @@ config HUSH_PARSER
 
 config CMDLINE_EDITING
bool "Enable command line editing"
-   depends on CMDLINE
default y
help
  Enable editing and History functions for interactive command line
@@ -40,15 +38,13 @@ config CMDLINE_PS_SUPPORT
 
 config AUTO_COMPLETE
bool "Enable auto complete using TAB"
-   depends on CMDLINE
default y
help
  Enable auto completion of commands using TAB.
 
 config SYS_LONGHELP
bool "Enable long help messages"
-   depends on CMDLINE
-   default y if CMDLINE
+   default y
help
  Defined when you want long help messages included
  Do not set this option when short of memory.
@@ -86,8 +82,7 @@ config SYS_CBSIZE
 
 config SYS_XTRACE
bool "Command execution tracer"
-   depends on CMDLINE
-   default y if CMDLINE
+   default y
help
  This option enables the possiblity to print all commands before
  executing them and after all variables are evaluated (similar
@@ -219,7 +214,6 @@ menu "Boot commands"
 
 config CMD_BOOTD
bool "bootd"
-   depends on CMDLINE
default y
help
  Run the command stored in the environment "bootcmd", i.e.
@@ -409,7 +403,6 @@ source lib/efi_selftest/Kconfig
 
 config CMD_BOOTMENU
bool "bootmenu"
-   depends on CMDLINE
select MENU
select CHARSET
help
@@ -476,7 +469,6 @@ config CMD_GO
 
 config CMD_RUN
bool "run"
-   depends on CMDLINE
default y
help
  Run the command in the given environment variable.
@@ -567,7 +559,6 @@ menu "Environment commands"
 
 config CMD_ASKENV
bool "ask for env variable"
-   depends on CMDLINE
help
  Ask for environment variable
 
@@ -1687,7 +1678,6 @@ if NET
 
 menuconfig CMD_NET
bool "Network commands"
-   depends on CMDLINE
default y
imply NETDEVICES
 
@@ -1991,7 +1981,6 @@ config CMD_ETHSW
 
 config CMD_PXE
bool "pxe"
-   depends on CMDLINE
select PXE_UTILS
help
  Boot image via network using PXE protocol
@@ -2126,7 +2115,6 @@ config CMD_EFICONFIG
 
 config CMD_EXCEPTION
bool "exception - raise exception"
-   depends on CMDLINE
depends on ARM || RISCV || SANDBOX || X86
help
  Enable the 'exception' command which allows to raise an exception.
@@ -2227,14 +2215,12 @@ config CMD_SOUND
 
 config CMD_SYSBOOT
bool "sysboot"
-   depends on CMDLINE
select PXE_UTILS
help
  Boot image via local extlinux.conf file
 
 config CMD_QFW
bool "qfw"
-   depends on CMDLINE
select QFW
help
  This provides access to the QEMU firmware interface.  The main
@@ -2883,4 +2869,5 @@ config CMD_MESON
default y
help
  Enable useful commands for the Meson Soc family developed by Amlogic 
Inc.
-endmenu
+
+endif # CMDLINE
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 27/27] sandbox: Add a test for disabling CONFIG_CMDLINE

2023-10-07 Thread Simon Glass
Now that everything is working, add a test to make sure that this
builds correctly.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Rebase on Tom's LONGHELP series
- Correct 'of' typo

 test/py/tests/test_sandbox_opts.py | 20 
 1 file changed, 20 insertions(+)
 create mode 100644 test/py/tests/test_sandbox_opts.py

diff --git a/test/py/tests/test_sandbox_opts.py 
b/test/py/tests/test_sandbox_opts.py
new file mode 100644
index ..91790b3374b4
--- /dev/null
+++ b/test/py/tests/test_sandbox_opts.py
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2022 Google LLC
+# Written by Simon Glass 
+
+import pytest
+
+import u_boot_utils as util
+
+# This is needed for Azure, since the default '..' directory is not writeable
+TMPDIR = '/tmp/test_cmdline'
+
+@pytest.mark.slow
+@pytest.mark.boardspec('sandbox')
+def test_sandbox_cmdline(u_boot_console):
+"""Test building sandbox without CONFIG_CMDLINE"""
+cons = u_boot_console
+
+out = util.run_and_log(
+cons, ['./tools/buildman/buildman', '-m', '--board', 'sandbox',
+   '-a', '~CMDLINE', '-o', TMPDIR])
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 21/27] video: Dont require the font command

2023-10-07 Thread Simon Glass
While it is nice to have the font command, using 'select' makes it
impossible to build the console code without it. Change this to use
'imply' instead.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/video/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index ab927641bb7a..21ea5c860cca 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -180,7 +180,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
bool "Support a console that uses TrueType fonts"
-   select CMD_SELECT_FONT
+   imply CMD_SELECT_FONT
help
  TrueTrype fonts can provide outline-drawing capability rather than
  needing to provide a bitmap for each font and size that is needed.
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 26/27] mmc: env: Unify the U_BOOT_ENV_LOCATION conditions

2023-10-07 Thread Simon Glass
The declaration of U_BOOT_ENV_LOCATION() uses a different #ifdef
condition from the code it calls. Use the same condition to avoid a
build warning if CONFIG_CMD_SAVEENV is disabled.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to unify the U_BOOT_ENV_LOCATION conditions

 env/mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/env/mmc.c b/env/mmc.c
index cb14bbb58f13..da84cddd74f0 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -495,7 +495,7 @@ U_BOOT_ENV_LOCATION(mmc) = {
.location   = ENVL_MMC,
ENV_NAME("MMC")
.load   = env_mmc_load,
-#ifndef CONFIG_SPL_BUILD
+#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_SPL_BUILD)
.save   = env_save_ptr(env_mmc_save),
.erase  = ENV_ERASE_PTR(env_mmc_erase)
 #endif
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 20/27] video: Allow use without CONFIG_CMDLINE

2023-10-07 Thread Simon Glass
Provide a fallback for when CONFIG_SYS_CBSIZE is not provided, so that
the console can still be used.

Signed-off-by: Simon Glass 
---

(no changes since v1)

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

diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 0f9bb49e44f7..8186b5b49f0b 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -124,7 +124,11 @@ struct pos_info {
  * Allow one for each character on the command line plus one for each newline.
  * This is just an estimate, but it should not be exceeded.
  */
+#ifdef CONFIG_SYS_CBSIZE
 #define POS_HISTORY_SIZE   (CONFIG_SYS_CBSIZE * 11 / 10)
+#else
+#define POS_HISTORY_SIZE   (250 * 11 / 10)
+#endif
 
 /**
  * struct console_tt_metrics - Information about a font / size combination
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 15/27] console: Move SYS_PBSIZE into common/

2023-10-07 Thread Simon Glass
This relates to printing output and does not need a command line. Move
it next to the other console-related options.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/Kconfig| 5 -
 common/Kconfig | 5 +
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index f9e023730c53..96ea40109abd 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -84,11 +84,6 @@ config SYS_CBSIZE
default 256 if M68K || PPC
default 1024
 
-config SYS_PBSIZE
-   int "Buffer size for console output"
-   default 1024 if ARCH_SUNXI
-   default 1044
-
 config SYS_XTRACE
bool "Command execution tracer"
depends on CMDLINE
diff --git a/common/Kconfig b/common/Kconfig
index 5e79b5422178..16601655caf7 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -52,6 +52,11 @@ config CONSOLE_RECORD_IN_SIZE
  The buffer is allocated immediately after the malloc() region is
  ready.
 
+config SYS_PBSIZE
+   int "Buffer size for console output"
+   default 1024 if ARCH_SUNXI
+   default 1044
+
 config DISABLE_CONSOLE
bool "Add functionality to disable console completely"
help
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 08/27] sifive: Change #ifdef for nop

2023-10-07 Thread Simon Glass
This code is normally compiled for sifive, but sandbox can also compile
it. We should not use UNIT_TEST as a synonym for SANDBOX, since it is
possible to disable UNIT_TEST for sandbox.

Correct the condition.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/k210/pll.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/k210/pll.h b/include/k210/pll.h
index fd16a89cb203..6dd60b2eb4fc 100644
--- a/include/k210/pll.h
+++ b/include/k210/pll.h
@@ -13,7 +13,7 @@ struct k210_pll_config {
u8 od;
 };
 
-#ifdef CONFIG_UNIT_TEST
+#ifdef CONFIG_SANDBOX
 TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in,
 struct k210_pll_config *best);
 #ifndef nop
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 11/27] cmd: Use an #ifdef around run_commandf()

2023-10-07 Thread Simon Glass
This is not available if CMDLINE is disabled, so add an #ifdef to correct
this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/cli.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/cli.c b/common/cli.c
index 3916a7b10a7d..4d0fea4387f2 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -129,6 +129,7 @@ int run_command_list(const char *cmd, int len, int flag)
return rcode;
 }
 
+#ifdef CONFIG_CMDLINE
 int run_commandf(const char *fmt, ...)
 {
va_list args;
@@ -153,6 +154,7 @@ int run_commandf(const char *fmt, ...)
}
return run_command(console_buffer, 0);
 }
+#endif /* CMDLINE */
 
 //
 
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 10/27] cli: Always build cli_getch

2023-10-07 Thread Simon Glass
This module is used for user input with menus, not just with the command
line. Compile it always, so it is available even when CMDLINE is disabled.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/Makefile b/common/Makefile
index cdeadf72026c..b21916f15340 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -8,6 +8,7 @@ ifndef CONFIG_SPL_BUILD
 obj-y += init/
 obj-y += main.o
 obj-y += exports.o
+obj-y += cli_getch.o
 obj-$(CONFIG_HUSH_PARSER) += cli_hush.o
 obj-$(CONFIG_AUTOBOOT) += autoboot.o
 
@@ -37,7 +38,7 @@ obj-$(CONFIG_SPLASH_SOURCE) += splash_source.o
 obj-$(CONFIG_MENU) += menu.o
 obj-$(CONFIG_UPDATE_COMMON) += update.o
 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
-obj-$(CONFIG_CMDLINE) += cli_getch.o cli_readline.o cli_simple.o
+obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o
 
 endif # !CONFIG_SPL_BUILD
 
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 09/27] fastboot: Declare a dependency on CMDLINE

2023-10-07 Thread Simon Glass
When CMDLINE is not enabled, this code fails to build. Correct this by
adding a condition.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Change this to use a Kconfig dependency instead of code failing

 drivers/fastboot/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index 837c6f1180da..24b100f381fe 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -2,6 +2,7 @@ menu "Fastboot support"
 
 config FASTBOOT
bool
+   depends on CMDLINE
imply ANDROID_BOOT_IMAGE
imply CMD_FASTBOOT
help
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 19/27] log: Allow use without CONFIG_CMDLINE

2023-10-07 Thread Simon Glass
When CONFIG_SYS_CBSIZE is not used we need an alternative. For logging
it seems that CONFIG_SYS_PBSIZE is a better choice anyway, so update
this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/log.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/log.c b/common/log.c
index b2de57fcb3b8..72a4de3274c7 100644
--- a/common/log.c
+++ b/common/log.c
@@ -206,7 +206,7 @@ static bool log_passes_filters(struct log_device *ldev, 
struct log_rec *rec)
 static int log_dispatch(struct log_rec *rec, const char *fmt, va_list args)
 {
struct log_device *ldev;
-   char buf[CONFIG_SYS_CBSIZE];
+   char buf[CONFIG_SYS_PBSIZE];
 
/*
 * When a log driver writes messages (e.g. via the network stack) this
@@ -268,7 +268,7 @@ int _log(enum log_category_t cat, enum log_level_t level, 
const char *file,
/* display dropped traces with console puts and DEBUG_UART */
if (rec.level <= CONFIG_LOG_DEFAULT_LEVEL ||
rec.flags & LOGRECF_FORCE_DEBUG) {
-   char buf[CONFIG_SYS_CBSIZE];
+   char buf[CONFIG_SYS_PBSIZE];
 
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 13/27] pxe: Depend on CMDLINE

2023-10-07 Thread Simon Glass
We cannot use PXE or sysboot commands without CONFIG_CMDLINE so add the
required condition.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/Kconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index f914da6fe1ac..f9e023730c53 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1995,6 +1995,7 @@ config CMD_ETHSW
 
 config CMD_PXE
bool "pxe"
+   depends on CMDLINE
select PXE_UTILS
help
  Boot image via network using PXE protocol
@@ -2230,6 +2231,7 @@ config CMD_SOUND
 
 config CMD_SYSBOOT
bool "sysboot"
+   depends on CMDLINE
select PXE_UTILS
help
  Boot image via local extlinux.conf file
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 12/27] Move bootmenu_conv_key() into its own file

2023-10-07 Thread Simon Glass
This conversion function is used by expo which does not require CMDLINE.
The menu feature does require CMDLINE.

Move the function into a separate file so that it can be used even when
CMDLINE is not enabled.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/Makefile|  2 +-
 common/cli_getch.c |  1 +
 common/menu.c  | 40 -
 common/menu_key.c  | 49 ++
 4 files changed, 51 insertions(+), 41 deletions(-)
 create mode 100644 common/menu_key.c

diff --git a/common/Makefile b/common/Makefile
index b21916f15340..637066ae6682 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -8,7 +8,7 @@ ifndef CONFIG_SPL_BUILD
 obj-y += init/
 obj-y += main.o
 obj-y += exports.o
-obj-y += cli_getch.o
+obj-y += cli_getch.o menu_key.o
 obj-$(CONFIG_HUSH_PARSER) += cli_hush.o
 obj-$(CONFIG_AUTOBOOT) += autoboot.o
 
diff --git a/common/cli_getch.c b/common/cli_getch.c
index 61d4cb261b81..c3332dc27fae 100644
--- a/common/cli_getch.c
+++ b/common/cli_getch.c
@@ -8,6 +8,7 @@
 
 #include 
 #include 
+#include 
 
 /**
  * enum cli_esc_state_t - indicates what to do with an escape character
diff --git a/common/menu.c b/common/menu.c
index b55cf7b99967..844d0ec52af3 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -483,46 +483,6 @@ enum bootmenu_key bootmenu_autoboot_loop(struct 
bootmenu_data *menu,
return key;
 }
 
-enum bootmenu_key bootmenu_conv_key(int ichar)
-{
-   enum bootmenu_key key;
-
-   switch (ichar) {
-   case '\n':
-   /* enter key was pressed */
-   key = BKEY_SELECT;
-   break;
-   case CTL_CH('c'):
-   case '\e':
-   /* ^C was pressed */
-   key = BKEY_QUIT;
-   break;
-   case CTL_CH('p'):
-   key = BKEY_UP;
-   break;
-   case CTL_CH('n'):
-   key = BKEY_DOWN;
-   break;
-   case CTL_CH('s'):
-   key = BKEY_SAVE;
-   break;
-   case '+':
-   key = BKEY_PLUS;
-   break;
-   case '-':
-   key = BKEY_MINUS;
-   break;
-   case ' ':
-   key = BKEY_SPACE;
-   break;
-   default:
-   key = BKEY_NONE;
-   break;
-   }
-
-   return key;
-}
-
 enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
struct cli_ch_state *cch)
 {
diff --git a/common/menu_key.c b/common/menu_key.c
new file mode 100644
index ..4e9c3b426b0c
--- /dev/null
+++ b/common/menu_key.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2010-2011 Calxeda, Inc.
+ * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+
+enum bootmenu_key bootmenu_conv_key(int ichar)
+{
+   enum bootmenu_key key;
+
+   switch (ichar) {
+   case '\n':
+   /* enter key was pressed */
+   key = BKEY_SELECT;
+   break;
+   case CTL_CH('c'):
+   case '\e':
+   /* ^C was pressed */
+   key = BKEY_QUIT;
+   break;
+   case CTL_CH('p'):
+   key = BKEY_UP;
+   break;
+   case CTL_CH('n'):
+   key = BKEY_DOWN;
+   break;
+   case CTL_CH('s'):
+   key = BKEY_SAVE;
+   break;
+   case '+':
+   key = BKEY_PLUS;
+   break;
+   case '-':
+   key = BKEY_MINUS;
+   break;
+   case ' ':
+   key = BKEY_SPACE;
+   break;
+   default:
+   key = BKEY_NONE;
+   break;
+   }
+
+   return key;
+}
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 14/27] env: Split out non-command code into a new file

2023-10-07 Thread Simon Glass
It is not possible to set environment variables without having
CONFIG_CMD_NVEDIT enabled. When CONFIG_CMDLINE is disabled, we need a
way to set variables.

Split the setting code out into its own file, so that env_set() is
available even when CONFIG_CMDLINE is not. If it is never called, the
code will be dropped at link time.

Update the Makefile rule to only include the env commands when
CONFIG_CMD_NVEDIT is enabled.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/Makefile   |   2 +-
 cmd/nvedit.c   | 122 ++---
 env/Makefile   |   1 +
 env/env_set.c  | 132 +
 include/env_internal.h |  23 +++
 5 files changed, 161 insertions(+), 119 deletions(-)
 create mode 100644 env/env_set.c

diff --git a/cmd/Makefile b/cmd/Makefile
index 9bebf321c397..5be2b4bd3800 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -240,7 +240,7 @@ endif # !CONFIG_SPL_BUILD
 obj-$(CONFIG_$(SPL_)CMD_TLV_EEPROM) += tlv_eeprom.o
 
 # core command
-obj-y += nvedit.o
+obj-$(CONFIG_$(SPL_)CMDLINE) += nvedit.o
 
 obj-$(CONFIG_CMD_BCM_EXT_UTILS) += broadcom/
 
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index daf1ad37f9be..812d82b157f4 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -49,20 +49,6 @@ DECLARE_GLOBAL_DATA_PTR;
  */
 #defineMAX_ENV_SIZE(1 << 20)   /* 1 MiB */
 
-/*
- * This variable is incremented on each do_env_set(), so it can
- * be used via env_get_id() as an indication, if the environment
- * has changed or not. So it is possible to reread an environment
- * variable only if the environment was changed ... done so for
- * example in NetInitLoop()
- */
-static int env_id = 1;
-
-int env_get_id(void)
-{
-   return env_id;
-}
-
 #ifndef CONFIG_SPL_BUILD
 /*
  * Command interface: print one or all environment variables
@@ -195,108 +181,8 @@ DONE:
 
return 0;
 }
-#endif
-#endif /* CONFIG_SPL_BUILD */
-
-/*
- * Set a new environment variable,
- * or replace or delete an existing one.
- */
-static int _do_env_set(int flag, int argc, char *const argv[], int env_flag)
-{
-   int   i, len;
-   char  *name, *value, *s;
-   struct env_entry e, *ep;
-
-   debug("Initial value for argc=%d\n", argc);
-
-#if !IS_ENABLED(CONFIG_SPL_BUILD) && IS_ENABLED(CONFIG_CMD_NVEDIT_EFI)
-   if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e')
-   return do_env_set_efi(NULL, flag, --argc, ++argv);
-#endif
-
-   while (argc > 1 && **(argv + 1) == '-') {
-   char *arg = *++argv;
-
-   --argc;
-   while (*++arg) {
-   switch (*arg) {
-   case 'f':   /* force */
-   env_flag |= H_FORCE;
-   break;
-   default:
-   return CMD_RET_USAGE;
-   }
-   }
-   }
-   debug("Final value for argc=%d\n", argc);
-   name = argv[1];
-
-   if (strchr(name, '=')) {
-   printf("## Error: illegal character '='"
-  "in variable name \"%s\"\n", name);
-   return 1;
-   }
-
-   env_id++;
-
-   /* Delete only ? */
-   if (argc < 3 || argv[2] == NULL) {
-   int rc = hdelete_r(name, &env_htab, env_flag);
-
-   /* If the variable didn't exist, don't report an error */
-   return rc && rc != -ENOENT ? 1 : 0;
-   }
-
-   /*
-* Insert / replace new value
-*/
-   for (i = 2, len = 0; i < argc; ++i)
-   len += strlen(argv[i]) + 1;
-
-   value = malloc(len);
-   if (value == NULL) {
-   printf("## Can't malloc %d bytes\n", len);
-   return 1;
-   }
-   for (i = 2, s = value; i < argc; ++i) {
-   char *v = argv[i];
-
-   while ((*s++ = *v++) != '\0')
-   ;
-   *(s - 1) = ' ';
-   }
-   if (s != value)
-   *--s = '\0';
-
-   e.key   = name;
-   e.data  = value;
-   hsearch_r(e, ENV_ENTER, &ep, &env_htab, env_flag);
-   free(value);
-   if (!ep) {
-   printf("## Error inserting \"%s\" variable, errno=%d\n",
-   name, errno);
-   return 1;
-   }
-
-   return 0;
-}
-
-int env_set(const char *varname, const char *varvalue)
-{
-   const char * const argv[4] = { "setenv", varname, varvalue, NULL };
-
-   /* before import into hashtable */
-   if (!(gd->flags & GD_FLG_ENV_READY))
-   return 1;
-
-   if (varvalue == NULL || varvalue[0] == '\0')
-   return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC);
-   else
-   return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC);
-}
+#endif /* CONFIG_CMD_GREPENV */
 
-#ifndef CONFIG_SPL_BUILD
 static int do_env_set(struct cmd_tbl *cmdtp, int flag, int argc,

[PATCH v2 18/27] net: Depend on CONFIG_CMDLINE

2023-10-07 Thread Simon Glass
At present it isn't possible to use networking without the command line
enabled. Add this as a condition.

Signed-off-by: Simon Glass 
Reviewed-by: Ramon Fried 
---

(no changes since v1)

 cmd/Kconfig | 1 +
 net/Kconfig | 1 +
 2 files changed, 2 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 96ea40109abd..c952b2e286cd 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1687,6 +1687,7 @@ if NET
 
 menuconfig CMD_NET
bool "Network commands"
+   depends on CMDLINE
default y
imply NETDEVICES
 
diff --git a/net/Kconfig b/net/Kconfig
index 4215889127c9..25d494e1db46 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -4,6 +4,7 @@
 
 menuconfig NET
bool "Networking support"
+   depends on CMDLINE
default y
 
 if NET
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 06/27] cmd: Add a few more dependencies on CMDLINE

2023-10-07 Thread Simon Glass
Add this to some more commands to avoid build errors with sandbox.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/Kconfig | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6470b138d2f8..f914da6fe1ac 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -224,6 +224,7 @@ menu "Boot commands"
 
 config CMD_BOOTD
bool "bootd"
+   depends on CMDLINE
default y
help
  Run the command stored in the environment "bootcmd", i.e.
@@ -413,6 +414,7 @@ source lib/efi_selftest/Kconfig
 
 config CMD_BOOTMENU
bool "bootmenu"
+   depends on CMDLINE
select MENU
select CHARSET
help
@@ -479,6 +481,7 @@ config CMD_GO
 
 config CMD_RUN
bool "run"
+   depends on CMDLINE
default y
help
  Run the command in the given environment variable.
@@ -569,6 +572,7 @@ menu "Environment commands"
 
 config CMD_ASKENV
bool "ask for env variable"
+   depends on CMDLINE
help
  Ask for environment variable
 
@@ -2125,6 +2129,7 @@ config CMD_EFICONFIG
 
 config CMD_EXCEPTION
bool "exception - raise exception"
+   depends on CMDLINE
depends on ARM || RISCV || SANDBOX || X86
help
  Enable the 'exception' command which allows to raise an exception.
@@ -2231,6 +2236,7 @@ config CMD_SYSBOOT
 
 config CMD_QFW
bool "qfw"
+   depends on CMDLINE
select QFW
help
  This provides access to the QEMU firmware interface.  The main
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 05/27] autoboot: Correct dependencies on CMDLINE

2023-10-07 Thread Simon Glass
Make AUTOBOOT depend on CMDLINE since it is mostly meaningless without it.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Move AUTOBOOT_USE_MENUKEY under AUTOBOOT

 boot/Kconfig | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index f74ac7e9cc72..6461f7ebd040 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -1167,14 +1167,16 @@ menu "Autoboot options"
 
 config AUTOBOOT
bool "Autoboot"
+   depends on CMDLINE
default y
help
  This enables the autoboot.  See doc/README.autoboot for detail.
 
+if AUTOBOOT
+
 config BOOTDELAY
int "delay in seconds before automatically booting"
default 2
-   depends on AUTOBOOT
help
  Delay before automatically running bootcmd;
  set to 0 to autoboot with no delay, but you can stop it by key input.
@@ -1196,9 +1198,11 @@ config AUTOBOOT_KEYED
  U-Boot automatic booting process and bring the device
  to the U-Boot prompt for user input.
 
+if AUTOBOOT_KEYED
+
 config AUTOBOOT_FLUSH_STDIN
bool "Enable flushing stdin before starting to read the password"
-   depends on AUTOBOOT_KEYED && !SANDBOX
+   depends on !SANDBOX
help
  When this option is enabled stdin buffer will be flushed before
  starting to read the password.
@@ -1207,7 +1211,6 @@ config AUTOBOOT_FLUSH_STDIN
 
 config AUTOBOOT_PROMPT
string "Autoboot stop prompt"
-   depends on AUTOBOOT_KEYED
default "Autoboot in %d seconds\\n"
help
  This string is displayed before the boot delay selected by
@@ -1223,7 +1226,6 @@ config AUTOBOOT_PROMPT
 
 config AUTOBOOT_ENCRYPTION
bool "Enable encryption in autoboot stopping"
-   depends on AUTOBOOT_KEYED
help
  This option allows a string to be entered into U-Boot to stop the
  autoboot.
@@ -1250,7 +1252,7 @@ config AUTOBOOT_SHA256_FALLBACK
 
 config AUTOBOOT_DELAY_STR
string "Delay autobooting via specific input key / string"
-   depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
+   depends on !AUTOBOOT_ENCRYPTION
help
  This option delays the automatic boot feature by issuing
  a specific input key or string. If CONFIG_AUTOBOOT_DELAY_STR
@@ -1262,7 +1264,7 @@ config AUTOBOOT_DELAY_STR
 
 config AUTOBOOT_STOP_STR
string "Stop autobooting via specific input key / string"
-   depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
+   depends on !AUTOBOOT_ENCRYPTION
help
  This option enables stopping (aborting) of the automatic
  boot feature only by issuing a specific input key or
@@ -1274,7 +1276,7 @@ config AUTOBOOT_STOP_STR
 
 config AUTOBOOT_KEYED_CTRLC
bool "Enable Ctrl-C autoboot interruption"
-   depends on AUTOBOOT_KEYED && !AUTOBOOT_ENCRYPTION
+   depends on !AUTOBOOT_ENCRYPTION
help
  This option allows for the boot sequence to be interrupted
  by ctrl-c, in addition to the "bootdelaykey" and "bootstopkey".
@@ -1283,7 +1285,7 @@ config AUTOBOOT_KEYED_CTRLC
 
 config AUTOBOOT_NEVER_TIMEOUT
bool "Make the password entry never time-out"
-   depends on AUTOBOOT_KEYED && AUTOBOOT_ENCRYPTION && CRYPT_PW
+   depends on AUTOBOOT_ENCRYPTION && CRYPT_PW
help
  This option removes the timeout from the password entry
  when the user first presses the  key before entering
@@ -1291,7 +1293,7 @@ config AUTOBOOT_NEVER_TIMEOUT
 
 config AUTOBOOT_STOP_STR_ENABLE
bool "Enable fixed string to stop autobooting"
-   depends on AUTOBOOT_KEYED && AUTOBOOT_ENCRYPTION
+   depends on AUTOBOOT_ENCRYPTION
help
  This option enables the feature to add a fixed stop
  string that is defined at compile time.
@@ -1322,9 +1324,12 @@ config AUTOBOOT_STOP_STR_SHA256
  includes a ":", the portion prior to the ":" will be treated
  as a salt value.
 
+endif  # AUTOBOOT_KEYED
+
+if !AUTOBOOT_KEYED
+
 config AUTOBOOT_USE_MENUKEY
bool "Allow a specify key to run a menu from the environment"
-   depends on !AUTOBOOT_KEYED
help
  If a specific key is pressed to stop autoboot, then the commands in
  the environment variable 'menucmd' are executed before boot starts.
@@ -1339,6 +1344,10 @@ config AUTOBOOT_MENUKEY
  For example, 33 means "!" in ASCII, so pressing ! at boot would take
  this action.
 
+endif
+
+endif  # AUTOBOOT
+
 config AUTOBOOT_MENU_SHOW
bool "Show a menu on boot"
depends on CMD_BOOTMENU
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 02/27] cmd: Convert existing long help messages to the new macro

2023-10-07 Thread Simon Glass
From: Tom Rini 

- Generally we just drop the #ifdef CONFIG_SYS_LONGHELP and endif lines
  and use U_BOOT_LONGHELP to declare the same variable name as before
- In a few places, either rename the variable to follow convention or
  introduce the variable as it was being done inline before.

Signed-off-by: Tom Rini 
Reviewed-by: Simon Glass 
Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/mach-imx/cmd_nandbcb.c  |  6 ++
 board/freescale/common/ngpixis.c |  6 ++
 board/work-microwave/work_92105/work_92105_display.c | 12 
 board/xilinx/common/fru.c|  7 ++-
 board/xilinx/versal/cmds.c   |  7 ++-
 board/xilinx/zynq/cmds.c |  6 ++
 board/xilinx/zynqmp/cmds.c   |  6 ++
 cmd/acpi.c   |  6 ++
 cmd/aes.c|  6 ++
 cmd/armffa.c |  4 ++--
 cmd/axi.c|  4 ++--
 cmd/bloblist.c   |  6 ++
 cmd/bootcount.c  |  9 ++---
 cmd/bootdev.c|  6 ++
 cmd/bootefi.c|  6 ++
 cmd/bootflow.c   |  9 -
 cmd/booti.c  |  6 ++
 cmd/bootm.c  |  6 ++
 cmd/bootmeth.c   |  6 ++
 cmd/bootz.c  |  6 ++
 cmd/cat.c|  6 ++
 cmd/cedit.c  |  6 ++
 cmd/clk.c|  6 ++
 cmd/conitrace.c  |  4 +---
 cmd/cpu.c|  7 ++-
 cmd/cyclic.c |  4 ++--
 cmd/dm.c |  7 ++-
 cmd/efidebug.c   |  6 ++
 cmd/event.c  |  6 ++
 cmd/fdt.c|  6 ++
 cmd/font.c   |  6 ++
 cmd/help.c   |  5 -
 cmd/i2c.c|  6 ++
 cmd/kaslrseed.c  |  6 ++
 cmd/log.c|  7 ++-
 cmd/mp.c |  6 ++
 cmd/mtd.c|  6 ++
 cmd/mtdparts.c   |  6 ++
 cmd/mux.c|  4 ++--
 cmd/nand.c   |  6 ++
 cmd/nvedit.c |  6 ++
 cmd/osd.c|  4 ++--
 cmd/pcap.c   |  4 ++--
 cmd/pci.c|  6 ++
 cmd/pci_mps.c|  6 ++
 cmd/riscv/sbi.c  |  7 ++-
 cmd/rng.c|  6 ++
 cmd/sandbox/exception.c  |  5 ++---
 cmd/scp03.c  |  7 ---
 cmd/sf.c |  8 +++-
 cmd/source.c |  9 -
 cmd/ti/pd.c  | 10 +-
 cmd/vbe.c|  6 ++
 cmd/wdt.c|  4 ++--
 cmd/ximg.c   |  6 ++
 cmd/xxd.c|  6 ++
 test/cmd_ut.c|  6 ++
 test/fuzz/cmd_fuzz.c |  7 ++-
 58 files changed, 129 insertions(+), 230 deletions(-)

diff --git a/arch/arm/mach-imx/cmd_nandbcb.c b/arch/arm/mach-imx/cmd_nandbcb.c
index c54f52b343c7..70a213a49dd0 100644
--- a/arch/arm/mach-imx/cmd_nandbcb.c
+++ b/arch/arm/mach-imx/cmd_nandbcb.c
@@ -1561,8 +1561,7 @@ usage:
return CMD_RET_USAGE;
 }
 
-#ifdef CONFIG_SYS_LONGHELP
-static char nandbcb_help_text[] =
+U_BOOT_LONGHELP(nandbcb,
"init addr off|partition len - update 'len' bytes starting at\n"
"   'off|part' to memory address 'addr', skipping  bad blocks\n"
"nandbcb bcbonly off|partition fw1-off fw1-size [fw2-off fw2-size]\n"
@@ -1572,8 +1571,7 @@ static char nandbcb_help_text[] =
"   FIY, BCB isn't erased automatically, so mtd erase should\n

[PATCH v2 16/27] bootm: Allow building when cleanup functions are missing

2023-10-07 Thread Simon Glass
There are two cleanup functions needed during boot which depend on
CMD_BOOTM: bootm_disable_interrupts() and board_quiesce_devices()

Provide static inline versions of these for when commands are not
enabled.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/lib/bootm.c |  2 ++
 boot/bootm.c | 10 --
 include/bootm.h  | 15 +--
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index c56285738a26..db8df57cb56e 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -42,9 +42,11 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static struct tag *params;
 
+#ifdef CONFIG_CMD_BOOTM
 __weak void board_quiesce_devices(void)
 {
 }
+#endif
 
 /**
  * announce_and_cleanup() - Print message and prepare for kernel boot
diff --git a/boot/bootm.c b/boot/bootm.c
index 8f96a80d4259..7deae058552a 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -47,9 +47,11 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, 
int flag, int argc,
   char *const argv[], struct bootm_headers 
*images,
   ulong *os_data, ulong *os_len);
 
+#ifdef CONFIG_CMD_BOOTM
 __weak void board_quiesce_devices(void)
 {
 }
+#endif
 
 #ifdef CONFIG_LMB
 static void boot_start_lmb(struct bootm_headers *images)
@@ -470,12 +472,7 @@ static int bootm_load_os(struct bootm_headers *images, int 
boot_progress)
return 0;
 }
 
-/**
- * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot
- *
- * Return: interrupt flag (0 if interrupts were disabled, non-zero if they were
- * enabled)
- */
+#ifdef CONFIG_CMD_BOOTM
 ulong bootm_disable_interrupts(void)
 {
ulong iflag;
@@ -505,6 +502,7 @@ ulong bootm_disable_interrupts(void)
 #endif
return iflag;
 }
+#endif
 
 #define CONSOLE_ARG"console="
 #define NULL_CONSOLE   (CONSOLE_ARG "ttynull")
diff --git a/include/bootm.h b/include/bootm.h
index c3c7336207b1..17c740449efd 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -50,8 +50,6 @@ int bootm_host_load_images(const void *fit, int cfg_noffset);
 int boot_selected_os(int argc, char *const argv[], int state,
 struct bootm_headers *images, boot_os_fn *boot_fn);
 
-ulong bootm_disable_interrupts(void);
-
 /* This is a special function used by booti/bootz */
 int bootm_find_images(int flag, int argc, char *const argv[], ulong start,
  ulong size);
@@ -62,6 +60,15 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int 
argc,
 
 void arch_preboot_os(void);
 
+#ifdef CONFIG_CMD_BOOTM
+/**
+ * bootm_disable_interrupts() - Disable interrupts, stop Ethernet and USB
+ *
+ * Return: interrupt flag (0 if interrupts were disabled, non-zero if they were
+ * enabled)
+ */
+ulong bootm_disable_interrupts(void);
+
 /*
  * boards should define this to disable devices when EFI exits from boot
  * services.
@@ -69,6 +76,10 @@ void arch_preboot_os(void);
  * TODO(s...@chromium.org>): Update this to use driver model's device_remove().
  */
 void board_quiesce_devices(void);
+#else
+static inline ulong bootm_disable_interrupts(void) { return 0; }
+static inline void board_quiesce_devices(void) {}
+#endif
 
 /**
  * switch_to_non_secure_mode() - switch to non-secure mode
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 07/27] test: Make UNIT_TEST depend on CMDLINE

2023-10-07 Thread Simon Glass
Many tests make some use of the command line, so require it for all test
code.

This could be teased apart, perhaps with a test flag indicating that ut
uses the command line. Leave that for later.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 test/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/test/Kconfig b/test/Kconfig
index 830245b6f9a9..2b4036704f91 100644
--- a/test/Kconfig
+++ b/test/Kconfig
@@ -2,6 +2,7 @@ menu "Testing"
 
 config UNIT_TEST
bool "Unit tests"
+   depends on CMDLINE
help
  Select this to compile in unit tests for various parts of
  U-Boot. Test suites will be subcommands of the "ut" command.
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 04/27] bootstd: Correct dependencies on CMDLINE

2023-10-07 Thread Simon Glass
With recent changes in boot/Kconfig it is no-longer possible to disable
CMDLINE. It results in various link errors because some options which
require CMDLINE are enabled regardless of whether it is available.

Add the necessary conditions to fix this.

Note that it would be better to have all commands depend on CMDLINE,
but that is extremely difficult at present, since some functions use
CMD_xxx to enable feature xxx. For example networking and environment
have a number of problems to tease apart.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Kconfig   | 19 ---
 lib/efi_loader/Kconfig |  1 +
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index a01e6cb8aafe..f74ac7e9cc72 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -342,6 +342,7 @@ endif # FIT
 
 config PXE_UTILS
bool
+   depends on CMDLINE
select MENU
help
  Utilities for parsing PXE file formats.
@@ -357,7 +358,7 @@ config BOOT_DEFAULTS
select CMD_PART if PARTITIONS
select CMD_DHCP if CMD_NET
select CMD_PING if CMD_NET
-   select CMD_PXE if CMD_NET
+   select CMD_PXE if CMDLINE && CMD_NET
select SUPPORT_RAW_INITRD
select ENV_VARS_UBOOT_CONFIG
select CMD_BOOTI if ARM64
@@ -461,6 +462,7 @@ config BOOTMETH_GLOBAL
 
 config BOOTMETH_CROS
bool "Bootdev support for Chromium OS"
+   depends on CMDLINE
depends on X86 || ARM || SANDBOX
default y if !ARM
select EFI_PARTITION
@@ -475,6 +477,7 @@ config BOOTMETH_CROS
 
 config BOOTMETH_EXTLINUX
bool "Bootdev support for extlinux boot"
+   depends on CMDLINE
select PXE_UTILS
default y
help
@@ -490,7 +493,7 @@ config BOOTMETH_EXTLINUX
 
 config BOOTMETH_EXTLINUX_PXE
bool "Bootdev support for extlinux boot over network"
-   depends on CMD_PXE && CMD_NET && DM_ETH
+   depends on CMDLINE && CMD_PXE && CMD_NET && DM_ETH
default y
help
  Enables support for extlinux boot using bootdevs. This makes the
@@ -504,7 +507,7 @@ config BOOTMETH_EXTLINUX_PXE
 
 config BOOTMETH_EFILOADER
bool "Bootdev support for EFI boot"
-   depends on EFI_LOADER
+   depends on EFI_LOADER && CMDLINE
default y
help
  Enables support for EFI boot using bootdevs. This makes the
@@ -536,10 +539,10 @@ config BOOTMETH_VBE
 
 config BOOTMETH_DISTRO
bool  # Options needed to boot any distro
-   select BOOTMETH_SCRIPT  # E.g. Armbian uses scripts
-   select BOOTMETH_EXTLINUX  # E.g. Debian uses these
-   select BOOTMETH_EXTLINUX_PXE if CMD_PXE && CMD_NET && DM_ETH
-   select BOOTMETH_EFILOADER if EFI_LOADER # E.g. Ubuntu uses this
+   select BOOTMETH_SCRIPT if CMDLINE # E.g. Armbian uses scripts
+   select BOOTMETH_EXTLINUX if CMDLINE # E.g. Debian uses these
+   select BOOTMETH_EXTLINUX_PXE if CMDLINE && CMD_PXE && CMD_NET && DM_ETH
+   select BOOTMETH_EFILOADER if CMDLINE && EFI_LOADER # E.g. Ubuntu uses 
this
 
 config SPL_BOOTMETH_VBE
bool "Bootdev support for Verified Boot for Embedded (SPL)"
@@ -663,6 +666,7 @@ config BOOTMETH_SANDBOX
 
 config BOOTMETH_SCRIPT
bool "Bootdev support for U-Boot scripts"
+   depends on CMDLINE
default y if BOOTSTD_FULL
select HUSH_PARSER
help
@@ -777,6 +781,7 @@ endmenu # Boot images
 
 config DISTRO_DEFAULTS
bool "(deprecated) Script-based booting of Linux distributions"
+   depends on CMDLINE
select BOOT_DEFAULTS
select AUTO_COMPLETE
select CMDLINE_EDITING
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index d20aaab6dba4..621ed5e5b0fb 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -34,6 +34,7 @@ if EFI_LOADER
 
 config CMD_BOOTEFI_BOOTMGR
bool "UEFI Boot Manager"
+   depends on CMDLINE
default y
select BOOTMETH_GLOBAL if BOOTSTD
help
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 01/27] command.h: Add a U_BOOT_LONGHELP macro

2023-10-07 Thread Simon Glass
From: Tom Rini 

In order to be able to discard unused long help texts without further
linker lists, add a macro for defining the long help messages which uses
__maybe_unused.  This allows us to discard them as unreferenced as part
of the link.

Signed-off-by: Tom Rini 
Reviewed-by: Simon Glass 
Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/command.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/command.h b/include/command.h
index 34ea989b39b4..a836ea795ab6 100644
--- a/include/command.h
+++ b/include/command.h
@@ -322,6 +322,9 @@ int cmd_source_script(ulong addr, const char *fit_uname, 
const char *confname);
 # define _CMD_HELP(x)
 #endif
 
+#define U_BOOT_LONGHELP(_cmdname, text)
\
+   static __maybe_unused const char _cmdname##_help_text[] = text;
+
 #define U_BOOT_SUBCMDS_DO_CMD(_cmdname)
\
static int do_##_cmdname(struct cmd_tbl *cmdtp, int flag,   \
 int argc, char *const argv[],  \
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 03/27] buildman: Use oldconfig when adjusting the config

2023-10-07 Thread Simon Glass
We cannot be sure that the new config is consistent, particularly when
changing a major item like CONFIG_CMDLINE. Use 'make oldconfig' to
check that and avoid any such problems.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/buildman/builder.py   | 2 +-
 tools/buildman/builderthread.py | 6 ++
 tools/buildman/func_test.py | 4 +++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 5305477c5be6..782e59dd5cca 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -476,7 +476,7 @@ class Builder:
 Args:
 commit: Commit object that is being built
 brd: Board object that is being built
-stage: Stage that we are at (mrproper, config, build)
+stage: Stage that we are at (mrproper, config, oldconfig, build)
 cwd: Directory where make should be run
 args: Arguments to pass to make
 kwargs: Arguments to pass to command.run_pipe()
diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py
index 6a61f64da1d4..a8599c0bb2a8 100644
--- a/tools/buildman/builderthread.py
+++ b/tools/buildman/builderthread.py
@@ -426,6 +426,12 @@ class BuilderThread(threading.Thread):
 
 # Now do the build, if everything looks OK
 if result.return_code == 0:
+if adjust_cfg:
+oldc_args = list(args) + ['oldconfig']
+oldc_result = self.make(commit, brd, 'oldconfig', cwd,
+*oldc_args, env=env)
+if oldc_result.return_code:
+return oldc_result
 result = self._build(commit, brd, cwd, args, env, cmd_list,
  config_only)
 if adjust_cfg:
diff --git a/tools/buildman/func_test.py b/tools/buildman/func_test.py
index 55dd494fe8ee..6b88ed815d65 100644
--- a/tools/buildman/func_test.py
+++ b/tools/buildman/func_test.py
@@ -439,6 +439,8 @@ class TestFunctional(unittest.TestCase):
 tools.write_file(fname, b'CONFIG_SOMETHING=1')
 return command.CommandResult(return_code=0,
 combined='Test configuration complete')
+elif stage == 'oldconfig':
+return command.CommandResult(return_code=0)
 elif stage == 'build':
 stderr = ''
 fname = os.path.join(cwd or '', out_dir, 'u-boot')
@@ -461,7 +463,7 @@ Some images are invalid'''
 return command.CommandResult(return_code=0)
 
 # Not handled, so abort
-print('make', stage)
+print('_HandleMake failure: make', stage)
 sys.exit(1)
 
 # Example function to print output lines
-- 
2.42.0.609.gbb76f46606-goog



[PATCH v2 17/27] fdt: Move working_fdt into fdt_support

2023-10-07 Thread Simon Glass
This can be accessed even when commands are not enabled. Move it into
the fdt_support.c file, which is where most of the FDT helpers are.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/fdt_support.c | 5 +
 cmd/fdt.c  | 5 -
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/boot/fdt_support.c b/boot/fdt_support.c
index 5e49078f8c35..6ae7b8e20f65 100644
--- a/boot/fdt_support.c
+++ b/boot/fdt_support.c
@@ -23,6 +23,11 @@
 #include 
 #include 
 
+/*
+ * The working_fdt points to our working flattened device tree.
+ */
+struct fdt_header *working_fdt;
+
 /**
  * fdt_getprop_u32_default_node - Return a node's property or a default
  *
diff --git a/cmd/fdt.c b/cmd/fdt.c
index 331564c13be9..86e847a41826 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -31,11 +31,6 @@ static int fdt_parse_prop(char *const*newval, int count, 
char *data, int *len);
 static int fdt_print(const char *pathp, char *prop, int depth);
 static int is_printable_string(const void *data, int len);
 
-/*
- * The working_fdt points to our working flattened device tree.
- */
-struct fdt_header *working_fdt;
-
 static void set_working_fdt_addr_quiet(ulong addr)
 {
void *buf;
-- 
2.42.0.609.gbb76f46606-goog



Re: [PATCH 08/25] fastboot: Avoid depending on CMDLINE

2023-10-07 Thread Simon Glass
Hi Tom,

On Sun, 24 Sept 2023 at 16:59, Tom Rini  wrote:
>
> On Sun, Sep 24, 2023 at 02:39:26PM -0600, Simon Glass wrote:
>
> > When CMDLINE is not enabled, this code fails to build. Correct this by
> > adding conditions.
> >
> > Note that this should not happen in normal use, since the use of
> > 'select CMDLINE' will cause a visible warning. But it is needed for the
> > sandbox build to pass without CMDLINE.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  drivers/fastboot/fb_command.c |  3 ++-
> >  drivers/fastboot/fb_common.c  | 15 +--
> >  2 files changed, 15 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c
> > index 71cfaec6e9dc..4e52e6f0f8bf 100644
> > --- a/drivers/fastboot/fb_command.c
> > +++ b/drivers/fastboot/fb_command.c
> > @@ -346,7 +346,8 @@ static char g_a_cmd_buff[64];
> >
> >  void fastboot_acmd_complete(void)
> >  {
> > - run_command(g_a_cmd_buff, 0);
> > + if (IS_ENABLED(CONFIG_CMDLINE))
> > + run_command(g_a_cmd_buff, 0);
> >  }
> >
> >  /**
> > diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> > index 4e9d9b719c6f..35b7aafe5af3 100644
> > --- a/drivers/fastboot/fb_common.c
> > +++ b/drivers/fastboot/fb_common.c
> > @@ -132,6 +132,13 @@ void fastboot_boot(void)
> >  {
> >   char *s;
> >
> > + /*
> > +  * Avoid a build error; this will always have generated a Kconfig
> > +  * warning about CMDLINE not being enabled
> > +  */
> > + if (!IS_ENABLED(CONFIG_CMDLINE))
> > + return;
> > +
> >   s = env_get("fastboot_bootcmd");
> >   if (s) {
> >   run_command(s, CMD_FLAG_ENV);
> > @@ -170,8 +177,12 @@ void fastboot_handle_boot(int command, bool success)
> >
> >   switch (command) {
> >   case FASTBOOT_COMMAND_BOOT:
> > - fastboot_boot();
> > - net_set_state(NETLOOP_SUCCESS);
> > + if (IS_ENABLED(CONFIG_CMDLINE)) {
> > + fastboot_boot();
> > + net_set_state(NETLOOP_SUCCESS);
> > + } else {
> > + net_set_state(NETLOOP_FAIL);
> > + }
> >   break;
> >
> >   case FASTBOOT_COMMAND_CONTINUE:
>
> All of this just means it now fails to work, yes?

It actually fails to build, since there is a Kconfig conflict, as
mentioned in the commit message. The use of 'select FASTBOOT' when
CMDLINE is not enabled produces an error.

I will see if I can do this another way.

Regards,
Simon


[PATCH v2 00/27] Tidy up use of CONFIG_CMDLINE

2023-10-07 Thread Simon Glass
It should be possible to disable CONFIG_CMDLINE and have all commands
and related functionality dropped from U-Boot. This is useful when
trying to reduce the size of U-Boot.

Recent changes have stopped this from working.

This series repairs the feature for sandbox and adds a test to stop it
breaking again.

Note that quite a lot of functionality is lost if CONFIG_CMDLINE is
disabled, e.g. networking and most booting options. Further work is
needed to make the option more generally useful.

Changes in v2:
- Move AUTOBOOT_USE_MENUKEY under AUTOBOOT
- Change this to use a Kconfig dependency instead of code failing
- Add new patch to drop discarding of command linker-lists
- Add new patch to unify the U_BOOT_ENV_LOCATION conditions
- Rebase on Tom's LONGHELP series
- Correct 'of' typo

Simon Glass (25):
  buildman: Use oldconfig when adjusting the config
  bootstd: Correct dependencies on CMDLINE
  autoboot: Correct dependencies on CMDLINE
  cmd: Add a few more dependencies on CMDLINE
  test: Make UNIT_TEST depend on CMDLINE
  sifive: Change #ifdef for nop
  fastboot: Declare a dependency on CMDLINE
  cli: Always build cli_getch
  cmd: Use an #ifdef around run_commandf()
  Move bootmenu_conv_key() into its own file
  pxe: Depend on CMDLINE
  env: Split out non-command code into a new file
  console: Move SYS_PBSIZE into common/
  bootm: Allow building when cleanup functions are missing
  fdt: Move working_fdt into fdt_support
  net: Depend on CONFIG_CMDLINE
  log: Allow use without CONFIG_CMDLINE
  video: Allow use without CONFIG_CMDLINE
  video: Dont require the font command
  efi: Depend on CMDLINE for efi_loader
  cmd: Make all commands depend on CMDLINE
  sandbox: Avoid requiring cmdline
  arm: x86: Drop discarding of command linker-lists
  mmc: env: Unify the U_BOOT_ENV_LOCATION conditions
  sandbox: Add a test for disabling CONFIG_CMDLINE

Tom Rini (2):
  command.h: Add a U_BOOT_LONGHELP macro
  cmd: Convert existing long help messages to the new macro

 arch/Kconfig  |   6 +-
 arch/arm/cpu/u-boot.lds   |   3 -
 arch/arm/lib/bootm.c  |   2 +
 arch/arm/mach-imx/cmd_nandbcb.c   |   6 +-
 arch/x86/cpu/u-boot-64.lds|   4 -
 arch/x86/cpu/u-boot-spl.lds   |   4 -
 arch/x86/cpu/u-boot.lds   |   4 -
 board/freescale/common/ngpixis.c  |   6 +-
 .../work_92105/work_92105_display.c   |  12 +-
 board/xilinx/common/fru.c |   7 +-
 board/xilinx/versal/cmds.c|   7 +-
 board/xilinx/zynq/cmds.c  |   6 +-
 board/xilinx/zynqmp/cmds.c|   6 +-
 boot/Kconfig  |  48 ---
 boot/bootm.c  |  10 +-
 boot/fdt_support.c|   5 +
 cmd/Kconfig   |  25 ++--
 cmd/Makefile  |   2 +-
 cmd/acpi.c|   6 +-
 cmd/aes.c |   6 +-
 cmd/armffa.c  |   4 +-
 cmd/axi.c |   4 +-
 cmd/bloblist.c|   6 +-
 cmd/bootcount.c   |   9 +-
 cmd/bootdev.c |   6 +-
 cmd/bootefi.c |   6 +-
 cmd/bootflow.c|   9 +-
 cmd/booti.c   |   6 +-
 cmd/bootm.c   |   6 +-
 cmd/bootmeth.c|   6 +-
 cmd/bootz.c   |   6 +-
 cmd/cat.c |   6 +-
 cmd/cedit.c   |   6 +-
 cmd/clk.c |   6 +-
 cmd/conitrace.c   |   4 +-
 cmd/cpu.c |   7 +-
 cmd/cyclic.c  |   4 +-
 cmd/dm.c  |   7 +-
 cmd/efidebug.c|   6 +-
 cmd/event.c   |   6 +-
 cmd/fdt.c |  11 +-
 cmd/font.c|   6 +-
 cmd/help.c|   5 +-
 cmd/i2c.c |   6 +-
 cmd/kaslrseed.c   |   6 +-
 cmd/log.c |   7 +-
 cmd/mp.c  |   6 +-
 cmd/mtd.c |   6 +-
 cmd/mtdparts.c|   6 +-
 cmd/mux.c |   4 +-
 cmd/nand.c|   6 +-
 cmd/nvedit.c  | 128 +
 cmd/osd.c |   4 +-
 cmd/pcap.c

Re: [PATCH 3/5] binman: capsule: Use dumped capsule header contents for verification

2023-10-07 Thread Simon Glass
Hi Sughosh,

On Wed, 4 Oct 2023 at 05:27, Sughosh Ganu  wrote:
>
> The various fields of a generated capsule are currently verified
> through hard-coded offsets. Use the dump-capsule feature for dumping
> the capsule header contents and use those for capsule verification.
>
> Signed-off-by: Sughosh Ganu 
> ---
>  tools/binman/ftest.py | 95 ---
>  1 file changed, 54 insertions(+), 41 deletions(-)

This looks good apart from a few nits below. However, the tests fail for me.

>
> diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
> index 8e419645a6..2b8871ab7e 100644
> --- a/tools/binman/ftest.py
> +++ b/tools/binman/ftest.py
> @@ -121,9 +121,11 @@ COMP_BINTOOLS = ['bzip2', 'gzip', 'lz4', 'lzma_alone', 
> 'lzop', 'xz', 'zstd']
>  TEE_ADDR = 0x5678
>
>  # Firmware Management Protocol(FMP) GUID
> -FW_MGMT_GUID = 'edd5cb6d2de8444cbda17194199ad92a'
> +FW_MGMT_GUID = '6DCBD5ED-E82D-4C44-BDA1-7194199AD92A'
>  # Image GUID specified in the DTS
> -CAPSULE_IMAGE_GUID = '52cfd7092007104791d108469b7fe9c8'
> +CAPSULE_IMAGE_GUID = '09D7CF52-0720-4710-91D1-08469B7FE9C8'
> +# Windows cert GUID
> +WIN_CERT_TYPE_EFI_GUID = '4AAFD29D-68DF-49EE-8AA9-347D375665A7'

Please use lower-case hex

>
>  class TestFunctional(unittest.TestCase):
>  """Functional tests for binman
> @@ -7223,52 +7225,63 @@ fdt fdtmapExtract the 
> devicetree blob from the fdtmap
>  self.assertRegex(err,
>   "Image 'image'.*missing bintools.*: bootgen")
>
> +def _GetCapsuleHeaders(self, data):

This should have a function comment so it is clear what it is doing, returning.

> +capsule_file = os.path.join(self._indir, 'test.capsule')
> +tools.write_file(capsule_file, data)
> +
> +out = tools.run('mkeficapsule', '--dump-capsule', capsule_file)
> +lines = out.splitlines()
> +
> +re_line = re.compile(r'^([^:\-\t]*)(?:\t*\s*:\s*(.*))?$')
> +vals = collections.defaultdict(list)
> +for line in lines:
> +mat = re_line.match(line)
> +if mat:
> +vals[mat.group(1)] = mat.group(2)
> +
> +return vals
> +
[..]

Regards,
Simon


Re: [PATCH RESEND 5/7] spl: riscv: add os type for next booting stage

2023-10-07 Thread Simon Glass
Hi Randolph,

On Fri, 6 Oct 2023 at 05:27, Randolph  wrote:
>
> If SPL_LOAD_FIT_OPENSBI_OS_BOOT is enabled, the function
> spl_invoke_opensbi should change the target OS type to IH_OS_LINUX.
> OpenSBI will load the Linux image as the next boot stage.
> The os_takes_devicetree function returns a value of true or false
> depending on whether or not SPL_LOAD_FIT_OPENSBI_OS_BOOT is enabled.
>
> Signed-off-by: Randolph 
> ---
>  common/spl/spl_fit.c | 4 
>  common/spl/spl_opensbi.c | 7 ++-
>  2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
> index 730639f756..750562721a 100644
> --- a/common/spl/spl_fit.c
> +++ b/common/spl/spl_fit.c
> @@ -351,7 +351,11 @@ static bool os_takes_devicetree(uint8_t os)
> case IH_OS_U_BOOT:
> return true;
> case IH_OS_LINUX:
> +#ifdef CONFIG_RISCV

Can you not set CONFIG_SPL_OS_BOOT in this case, and avoid this extra
condition? We really don't want arch-specific code in a generic file.

> +   return IS_ENABLED(CONFIG_SPL_LOAD_FIT_OPENSBI_OS_BOOT);
> +#else
> return IS_ENABLED(CONFIG_SPL_OS_BOOT);
> +#endif
> default:
> return false;
> }
> diff --git a/common/spl/spl_opensbi.c b/common/spl/spl_opensbi.c
> index a0c5f35dab..708869ad48 100644
> --- a/common/spl/spl_opensbi.c
> +++ b/common/spl/spl_opensbi.c
> @@ -58,9 +58,14 @@ void __noreturn spl_invoke_opensbi(struct spl_image_info 
> *spl_image)
>
> /*
>  * Find next os image in /fit-images
> -* The next os image default is u-boot proper
> +* The next os image default is u-boot proper, once enable
> +* OpenSBI OS boot mode, the OS image should be linux.
>  */
> +#if CONFIG_IS_ENABLED(LOAD_FIT_OPENSBI_OS_BOOT)
> +   os_type = IH_OS_LINUX;
> +#else
> os_type = IH_OS_U_BOOT;
> +#endif

Please use if().

> ret = spl_opensbi_find_os_node(spl_image->fdt_addr, &os_node, 
> os_type);
> if (ret) {
> pr_err("Can't find %s node for opensbi, %d\n",
> --
> 2.34.1
>

Regards,
Simon


Re: [PATCH v2 8/9] test: bdinfo: Test bdinfo -m

2023-10-07 Thread Simon Glass
On Sat, 7 Oct 2023 at 15:41, Marek Vasut
 wrote:
>
> The bdinfo -m should print only the board memory layout.
> Test the expected output.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Bin Meng 
> Cc: Mario Six 
> Cc: Nikhil M Jain 
> Cc: Simon Glass 
> ---
> V2: Rename bdinfo_test_mem() to bdinfo_check_mem()
> ---
>  test/cmd/bdinfo.c | 26 +++---
>  1 file changed, 23 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH] cmd: mbr: Allow 4 MBR partitions without need for extended

2023-10-07 Thread Simon Glass
Hi Alexander,

On Fri, 6 Oct 2023 at 21:58, Alexander Gendin  wrote:
>
> Current code allows up to 3 MBR partitions without extended one.
> If more than 3 partitions are required, then extended partition(s)
> must be used.
> This commit allows up to 4 primary MBR partitions without the
> need for extended partition.
>
> Add mbr test unit. In order to use the test, mmc1.img file of size
> 12 MiB or greater is required in the same directory as u-boot.
> Running mbr test is only supported in sandbox mode.
>
> Signed-off-by: Alex Gendin 
> ---
>  disk/part_dos.c   |   2 +-
>  include/test/suites.h |   1 +
>  test/cmd/Makefile |   1 +
>  test/cmd/mbr.c| 440 ++
>  test/cmd_ut.c |   4 +
>  5 files changed, 447 insertions(+), 1 deletion(-)
>  create mode 100644 test/cmd/mbr.c

This looks OK apart from one thing...also I have a few suggestions /
questions below.

>
> diff --git a/disk/part_dos.c b/disk/part_dos.c
> index 3337438437..567ead7511 100644
> --- a/disk/part_dos.c
> +++ b/disk/part_dos.c
> @@ -466,7 +466,7 @@ int layout_mbr_partitions(struct disk_partition *p, int 
> count,
> ext = &p[i];
> }
>
> -   if (count < 4)
> +   if (count <= 4)
> return 0;
>
> if (!ext) {
> diff --git a/include/test/suites.h b/include/test/suites.h
> index 1c7dc65966..51acbe47b2 100644
> --- a/include/test/suites.h
> +++ b/include/test/suites.h
> @@ -45,6 +45,7 @@ int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, 
> char *const argv[]);
>  int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
>  int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> argv[]);
>  int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const 
> argv[]);
> +int do_ut_mbr(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
>  int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
>  int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> argv[]);
>  int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc,
> diff --git a/test/cmd/Makefile b/test/cmd/Makefile
> index 6e3d7e919e..2f251e07b4 100644
> --- a/test/cmd/Makefile
> +++ b/test/cmd/Makefile
> @@ -23,6 +23,7 @@ obj-$(CONFIG_CMD_PINMUX) += pinmux.o
>  obj-$(CONFIG_CMD_PWM) += pwm.o
>  obj-$(CONFIG_CMD_SEAMA) += seama.o
>  ifdef CONFIG_SANDBOX
> +obj-$(CONFIG_CMD_MBR) += mbr.o
>  obj-$(CONFIG_CMD_READ) += rw.o
>  obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
>  obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
> diff --git a/test/cmd/mbr.c b/test/cmd/mbr.c
> new file mode 100644
> index 00..bedcef0638
> --- /dev/null
> +++ b/test/cmd/mbr.c
> @@ -0,0 +1,440 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Tests for mbr command
> + *
> + * Copyright 2023 Matrox Video
> + * Written by Alex Gendin 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +/*
> + * Test requirements:
> + * mmc1.img - File size needs to be at least 12 MiB
> + *
> + * Command to create mmc1.img:
> + * $ dd if=/dev/zero of=mmc1.img bs=12M count=1
> + *
> + * Place mmc1.img into the same directory as sandboxed u-boot
> + *
> + * To run this test manually:
> + * $ ./u-boot -Tc 'ut mbr'

These requirements need to be dealt with by a test script. You can set
up this device in test_ut_dm_init_bootstd(). You may need to create a
new mmc as the others are in use.

> + */
> +
> +static char * mbr_parts_header = "setenv mbr_parts '";
> +static char * mbr_parts_p1 = 
> "uuid_disk=0x12345678;name=p1,start=8M,bootable,size=1M,id=0x0e";
> +static char * mbr_parts_p2 = ";name=p2,size=1M,id=0x0e";
> +static char * mbr_parts_p3 = ";name=p3,size=1M,id=0x0e";
> +static char * mbr_parts_p4 = ";name=p4,size=1M,id=0x0e";
> +static char * mbr_parts_p5 = 
> ";name=[ext],size=2M,id=0x05;name=p5,size=1M,id=0x0e";
> +static char * mbr_parts_tail = "'";
> +
> +/*
> + * One MBR partition
> +01b0  00 00 00 00 00 00 00 00  78 56 34 12 00 00 80 05  
> |xV4.|
> +01c0  05 01 0e 25 24 01 00 40  00 00 00 08 00 00 00 00  
> |...%$..@|
> +01d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  
> ||
> +01e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  
> ||
> +01f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  
> |..U.|
> +*/
> +static unsigned mbr_cmp_start = 0x1B8;
> +static unsigned mbr_cmp_size = 0x48;
> +static unsigned char mbr_parts_ref_p1[] = {
> +0x78, 0x56, 0x34, 0x12, 
> 0x00, 0x00, 0x80, 0x05,
> +0x05, 0x01, 0x0e, 0x25, 0x24, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x08, 
> 0x00, 0x00, 0x00, 0x00,
> +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
> 0x00, 0x00, 0x00, 0x00,
> +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
> 0x00, 0x00, 0x00, 0x

Re: [PATCH v3 1/2] binman: openssl: x509: ti_secure_rom: Add support for bootcore_opts

2023-10-07 Thread Simon Glass
Hi Neha,

On Fri, 6 Oct 2023 at 04:07, Neha Malcom Francis  wrote:
>
> According to the TRMs of K3 platform of devices, the ROM boot image
> format specifies a "Core Options Field" that provides the capability to
> set the boot core in lockstep when set to 0 or to split mode when set
> to 2. Add support for providing the same from the binman DTS. Also
> modify existing test case for ensuring future coverage.
>
> Signed-off-by: Neha Malcom Francis 
> ---
> Link to J721E TRM: https://www.ti.com/lit/zip/spruil1
> Section 4.5.4.1 Boot Info
>
> Changes in v3:
> - updated function comments
> - removed inconsistency in setting bootcore_opts to 32
>
> Changes in v2:
> - included TRM link in commit message
>
>  tools/binman/btool/openssl.py   |  6 --
>  tools/binman/entries.rst|  1 +
>  tools/binman/etype/ti_secure_rom.py | 11 +--
>  tools/binman/etype/x509_cert.py |  3 ++-
>  tools/binman/test/297_ti_secure_rom.dts |  1 +
>  5 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/tools/binman/btool/openssl.py b/tools/binman/btool/openssl.py
> index aad3b61ae2..86cc56fbd7 100644
> --- a/tools/binman/btool/openssl.py
> +++ b/tools/binman/btool/openssl.py
> @@ -155,6 +155,7 @@ authInPlace = INTEGER:2
>  C, ST, L, O, OU, CN and emailAddress
>  cert_type (int): Certification type
>  bootcore (int): Booting core
> +bootcore_opts(int): Booting core option (split/lockstep mode)

Please indicate what possible values are allowed

>  load_addr (int): Load address of image
>  sha (int): Hash function
>
> @@ -225,7 +226,7 @@ emailAddress   = 
> {req_dist_name_dict['emailAddress']}
>imagesize_sbl, hashval_sbl, load_addr_sysfw, 
> imagesize_sysfw,
>hashval_sysfw, load_addr_sysfw_data, imagesize_sysfw_data,
>hashval_sysfw_data, sysfw_inner_cert_ext_boot_block,
> -  dm_data_ext_boot_block):
> +  dm_data_ext_boot_block, bootcore_opts):
>  """Create a certificate
>
>  Args:
> @@ -241,6 +242,7 @@ emailAddress   = 
> {req_dist_name_dict['emailAddress']}
>  bootcore (int): Booting core
>  load_addr (int): Load address of image
>  sha (int): Hash function
> +bootcore_opts (int): Boot core option (split/lockstep mode)
>
>  Returns:
>  str: Tool output
> @@ -285,7 +287,7 @@ sysfw_data=SEQUENCE:sysfw_data
>  [sbl]
>  compType = INTEGER:1
>  bootCore = INTEGER:16
> -compOpts = INTEGER:0
> +compOpts = INTEGER:{bootcore_opts}
>  destAddr = FORMAT:HEX,OCT:{load_addr:08x}
>  compSize = INTEGER:{imagesize_sbl}
>  shaType  = OID:{sha_type}
> diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
> index 801bd94674..b401f9426a 100644
> --- a/tools/binman/entries.rst
> +++ b/tools/binman/entries.rst
> @@ -1900,6 +1900,7 @@ Properties / Entry arguments:
>  - core: core on which bootloader runs, valid cores are 'secure' and 
> 'public'
>  - content: phandle of SPL in case of legacy bootflow or phandles of 
> component binaries
>in case of combined bootflow
> +- core-opts (optional): split-mode (0) or lockstep mode (1) set to 0 by 
> default

Here it is 1 but below it says 2

>
>  The following properties are only for generating a combined bootflow binary:
>  - sysfw-inner-cert: boolean if binary contains sysfw inner certificate
> diff --git a/tools/binman/etype/ti_secure_rom.py 
> b/tools/binman/etype/ti_secure_rom.py
> index 9a7ac9e9e0..17c50cefa1 100644
> --- a/tools/binman/etype/ti_secure_rom.py
> +++ b/tools/binman/etype/ti_secure_rom.py
> @@ -32,6 +32,7 @@ class Entry_ti_secure_rom(Entry_x509_cert):
>  - core: core on which bootloader runs, valid cores are 'secure' and 
> 'public'
>  - content: phandle of SPL in case of legacy bootflow or phandles of 
> component binaries
>in case of combined bootflow
> +- core-opts (optional): split-mode (0) or lockstep mode (1) set to 0 
> by default
>
>  The following properties are only for generating a combined bootflow 
> binary:
>  - sysfw-inner-cert: boolean if binary contains sysfw inner 
> certificate
> @@ -69,6 +70,7 @@ class Entry_ti_secure_rom(Entry_x509_cert):
>  self.sw_rev = fdt_util.GetInt(self._node, 'sw-rev', 1)
>  self.sha = fdt_util.GetInt(self._node, 'sha', 512)
>  self.core = fdt_util.GetString(self._node, 'core', 'secure')
> +self.bootcore_opts = fdt_util.GetInt(self._node, 'core-opts')
>  self.key_fname = self.GetEntryArgsOrProps([
>  EntryArg('keyfile', str)], required=True)[0]
>  if self.combined:
> @@ -97,17 +99,19 @@ class Entry_ti_secure_rom(Entry_x509_cert):
>  bytes content of the entry, which is the certificate binary for 
> the
>  provided data
>  """
> +i

Re: [PATCH RESEND 2/7] riscv: dts: add binman_linux.dtsi for opensbi os boot mode

2023-10-07 Thread Simon Glass
Hi Randoph,

On Fri, 6 Oct 2023 at 05:26, Randolph  wrote:
>
> The binman_linux.dtsi is a fork of binman.dtsi, just change the first
> section image from the "u-boot" to "linux". Note that the filename
> is also changed. In binman.dtsi, the filename of u-boot section filename
> is called "u-boot-nodtb.bin". In binman_linux.dtsi, the filename should
> be called "Image", which is located in linux/arch/riscv/boot.
>
> Signed-off-by: Randolph 
> ---
>  arch/riscv/dts/binman_linux.dtsi | 79 
>  1 file changed, 79 insertions(+)
>  create mode 100644 arch/riscv/dts/binman_linux.dtsi
>
> diff --git a/arch/riscv/dts/binman_linux.dtsi 
> b/arch/riscv/dts/binman_linux.dtsi
> new file mode 100644
> index 00..334d64bc40
> --- /dev/null
> +++ b/arch/riscv/dts/binman_linux.dtsi
> @@ -0,0 +1,79 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2021, Bin Meng 
> + */
> +
> +#include 
> +
> +/ {
> +   binman: binman {
> +   multiple-images;
> +   };
> +};
> +
> +&binman {
> +   itb {
> +   filename = "linux.itb";
> +
> +   fit {
> +   description = "Configuration to load OpenSBI before 
> Linux";
> +   #address-cells = <1>;
> +   fit,fdt-list = "of-list";
> +
> +   images {
> +   linux {
> +   description = "Linux";
> +   type = "standalone";
> +   os = "Linux";
> +   arch = "riscv";
> +   compression = "none";
> +   load = ;
> +
> +   linux_blob: blob-ext {
> +   filename = "Image";
> +   };
> +   };
> +
> +   opensbi {
> +   description = "OpenSBI fw_dynamic 
> Firmware";
> +   type = "firmware";
> +   os = "opensbi";
> +   arch = "riscv";
> +   compression = "none";
> +   load = ;
> +   entry = 
> ;
> +
> +   opensbi_blob: opensbi {
> +   filename = "fw_dynamic.bin";
> +   missing-msg = "opensbi";
> +   };
> +   };
> +
> +#ifndef CONFIG_OF_BOARD
> +   @fdt-SEQ {
> +   description = "NAME";
> +   type = "flat_dt";
> +   compression = "none";
> +   };
> +#endif
> +   };
> +
> +   configurations {
> +   default = "conf-1";
> +
> +#ifndef CONFIG_OF_BOARD
> +   @conf-SEQ {
> +#else
> +   conf-1 {
> +#endif
> +   description = "NAME";
> +   firmware = "opensbi";
> +   loadables = "linux";
> +#ifndef CONFIG_OF_BOARD
> +   fdt = "fdt-SEQ";
> +#endif
> +   };
> +   };
> +   };
> +   };
> +};
> --
> 2.34.1
>

Could you instead put an #ifdef to include the right file (or nodes)
in a single file?

i.e. always include binman.dtsi but have it do different things in either case?

Regards,
Simon


Re: [PATCH v3 1/6] binman: ti-secure: Add support for firewalling entities

2023-10-07 Thread Simon Glass
Hi Manorit,

On Wed, 4 Oct 2023 at 06:32, Manorit Chawdhry  wrote:
>
> We can now firewall entities while loading them through our secure
> entity TIFS, the required information should be present in the
> certificate that is being parsed by TIFS.
>
> The following commit adds the support to enable the certificates to be
> generated if the firewall configurations are present in the binman dtsi
> nodes.
>
> Signed-off-by: Manorit Chawdhry 
> ---
>  tools/binman/btool/openssl.py   | 16 +++-
>  tools/binman/etype/ti_secure.py | 85 
> +
>  tools/binman/etype/x509_cert.py |  3 +-
>  3 files changed, 101 insertions(+), 3 deletions(-)
>
> diff --git a/tools/binman/btool/openssl.py b/tools/binman/btool/openssl.py
> index aad3b61ae27c..dff439df211f 100644
> --- a/tools/binman/btool/openssl.py
> +++ b/tools/binman/btool/openssl.py
> @@ -82,7 +82,7 @@ imageSize  = INTEGER:{len(indata)}
>  return self.run_cmd(*args)
>
>  def x509_cert_sysfw(self, cert_fname, input_fname, key_fname, sw_rev,
> -  config_fname, req_dist_name_dict):
> +  config_fname, req_dist_name_dict, firewall_cert_data):
>  """Create a certificate to be booted by system firmware
>
>  Args:
> @@ -94,6 +94,13 @@ imageSize  = INTEGER:{len(indata)}
>  req_dist_name_dict (dict): Dictionary containing key-value pairs 
> of
>  req_distinguished_name section extensions, must contain 
> extensions for
>  C, ST, L, O, OU, CN and emailAddress
> +firewall_cert_data (dict):
> +  - auth_in_place (int): The Priv ID for copying as the
> +specific host in firewall protected region
> +  - num_firewalls (int): The number of firewalls in the
> +extended certificate
> +  - certificate (str): Extended firewall certificate with
> +the information for the firewall configurations.
>
>  Returns:
>  str: Tool output
> @@ -121,6 +128,7 @@ basicConstraints   = CA:true
>  1.3.6.1.4.1.294.1.3= ASN1:SEQUENCE:swrv
>  1.3.6.1.4.1.294.1.34   = ASN1:SEQUENCE:sysfw_image_integrity
>  1.3.6.1.4.1.294.1.35   = ASN1:SEQUENCE:sysfw_image_load
> +1.3.6.1.4.1.294.1.37   = ASN1:SEQUENCE:firewall
>
>  [ swrv ]
>  swrv = INTEGER:{sw_rev}
> @@ -132,7 +140,11 @@ imageSize  = INTEGER:{len(indata)}
>
>  [ sysfw_image_load ]
>  destAddr = FORMAT:HEX,OCT:
> -authInPlace = INTEGER:2
> +authInPlace = INTEGER:{hex(firewall_cert_data['auth_in_place'])}
> +
> +[ firewall ]
> +numFirewallRegions = INTEGER:{firewall_cert_data['num_firewalls']}
> +{firewall_cert_data['certificate']}

Do we want the text above if there is no firewall info?

>  ''', file=outf)
>  args = ['req', '-new', '-x509', '-key', key_fname, '-nodes',
>  '-outform', 'DER', '-out', cert_fname, '-config', 
> config_fname,
> diff --git a/tools/binman/etype/ti_secure.py b/tools/binman/etype/ti_secure.py
> index d939dce57139..a7409023fa55 100644
> --- a/tools/binman/etype/ti_secure.py
> +++ b/tools/binman/etype/ti_secure.py
> @@ -7,9 +7,35 @@
>
>  from binman.entry import EntryArg
>  from binman.etype.x509_cert import Entry_x509_cert
> +from dataclasses import dataclass
>
>  from dtoc import fdt_util
>
> +@dataclass
> +class Firewall():
> +id: int
> +region: int
> +control : int
> +permissions: list[hex]
> +start_address: str
> +end_address: str
> +
> +def get_certificate(self) -> str:
> +unique_identifier = f"{self.id}{self.region}"
> +cert = f"""
> +firewallID{unique_identifier} = INTEGER:{self.id}
> +region{unique_identifier} = INTEGER:{self.region}
> +control{unique_identifier} = INTEGER:{hex(self.control)}
> +nPermissionRegs{unique_identifier} = INTEGER:{len(self.permissions)}
> +"""
> +for index, permission in enumerate(self.permissions):
> +cert += f"""permissions{unique_identifier}{index} = 
> INTEGER:{hex(permission)}
> +"""
> +cert += f"""startAddress{unique_identifier} = 
> FORMAT:HEX,OCT:{self.start_address:02x}
> +endAddress{unique_identifier} = FORMAT:HEX,OCT:{self.end_address:02x}
> +"""
> +return cert
> +
>  class Entry_ti_secure(Entry_x509_cert):
>  """Entry containing a TI x509 certificate binary
>
> @@ -17,6 +43,11 @@ class Entry_ti_secure(Entry_x509_cert):
>  - content: List of phandles to entries to sign
>  - keyfile: Filename of file containing key to sign binary with
>  - sha: Hash function to be used for signing
> +- auth_in_place: This is an integer field that contains two pieces
> +  of information
> +Lower Byte - Remains 0x02 as per our use case
> +( 0x02: Move the authenticated binary back to the header )
> +Upper Byte - The Host ID of the core owning the firewall
>
>  Output files:
>  - input. - input file passed to openssl

Re: [PATCH 4/5] btool: mkeficapsule: Add support for EFI empty capsule generation

2023-10-07 Thread Simon Glass
Hi Sugosh,

On Wed, 4 Oct 2023 at 05:27, Sughosh Ganu  wrote:
>
> Add a method to the mkeficapsule bintool to generate empty
> capsules. These are capsules needed for the FWU A/B update feature.
>
> Signed-off-by: Sughosh Ganu 
> ---
>  tools/binman/btool/mkeficapsule.py | 29 +
>  1 file changed, 29 insertions(+)
>
> diff --git a/tools/binman/btool/mkeficapsule.py 
> b/tools/binman/btool/mkeficapsule.py
> index 61179747ff..89c0adfc9f 100644
> --- a/tools/binman/btool/mkeficapsule.py
> +++ b/tools/binman/btool/mkeficapsule.py
> @@ -80,6 +80,35 @@ class Bintoolmkeficapsule(bintool.Bintool):
>
>  return self.run_cmd(*args)
>
> +def generate_empty_capsule(self, accept, revert, image_guid,

Instead of two separate bools, how about an 'operation' param, a
string which is either accept or revert? Or perhaps just have 'accept'
 and pass True or False?

> +   output_fname):
> +"""Generate empty capsules for FWU A/B updates
> +
> +Args:
> +accept (int): Generate an accept capsule
> +revert (int): Generate a revert capsule
> +image_guid (str): GUID used for identifying the image
> +output_fname (str): Path to the output capsule file
> +
> +Returns:
> +str: Tool output
> +"""
> +if accept:
> +args = [
> +f'--guid={image_guid}',
> +'--fw-accept'
> +]
> +elif revert:
> +args = [
> +'--fw-revert'
> +]

That can be on none line

> +
> +args += [
> +output_fname
> +]

Same here

> +
> +return self.run_cmd(*args)
> +
>  def fetch(self, method):
>  """Fetch handler for mkeficapsule
>
> --
> 2.34.1
>

Regards,
Simon


Re: [PATCH] test: Fix SPL tests not being run

2023-10-07 Thread Simon Glass
On Thu, 5 Oct 2023 at 16:24, Sean Anderson  wrote:
>
> On 10/2/23 14:56, Simon Glass wrote:
> > Hi Sean,
> >
> > On Mon, 2 Oct 2023 at 08:38, Sean Anderson  wrote:
> >>
> >> On 10/1/23 15:36, Simon Glass wrote:
> >> > Hi Sean,
> >> >
> >> > On Fri, 29 Sept 2023 at 10:12, Sean Anderson  
> >> > wrote:
> >> >>
> >> >> On 9/29/23 12:06, Sean Anderson wrote:
> >> >> > SPL doesn't have OF_LIVE enabled, so we can only run tests with a flat
> >> >> > tree. Don't skip them even if they don't use the devicetree.
> >> >> >
> >> >> > Fixes: 6ec5178c0ef ("test: Skip flat-tree tests if devicetree is not 
> >> >> > used")
> >> >> > Signed-off-by: Sean Anderson 
> >> >> > ---
> >> >> >
> >> >> >  test/test-main.c | 3 ++-
> >> >> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >> >> >
> >> >> > diff --git a/test/test-main.c b/test/test-main.c
> >> >> > index 778bf0a18a0..edb20bc4b9c 100644
> >> >> > --- a/test/test-main.c
> >> >> > +++ b/test/test-main.c
> >> >> > @@ -476,7 +476,8 @@ static int ut_run_test_live_flat(struct 
> >> >> > unit_test_state *uts,
> >> >> >*   (for sandbox we handle this by copying the tree, but not 
> >> >> > for other
> >> >> >*boards)
> >> >> >*/
> >> >> > - if ((test->flags & UT_TESTF_SCAN_FDT) &&
> >> >> > + if ((!CONFIG_IS_ENABLED(OF_LIVE) ||
> >> >> > +  (test->flags & UT_TESTF_SCAN_FDT)) &&
> >> >> >   !(test->flags & UT_TESTF_LIVE_TREE) &&
> >> >> >   (CONFIG_IS_ENABLED(OFNODE_MULTI_TREE) ||
> >> >> >!(test->flags & UT_TESTF_OTHER_FDT)) &&
> >> >>
> >> >> Upon further review, do we even need 6ec5178c0ef in the first place?
> >> >> ut_test_run_on_flattree looks like it's trying to do the same thing.
> >> >
> >> > Well one problem is that many tests are not run at all unless OF_LIVE
> >> > is enabled. The code as is is assuming that OF_LIVE is active.
> >> >
> >> > On boards where OF_LIVE is not active, many tests won't run at all
> >> > unless they are marked with UT_TESTF_SCAN_FDT.
> >> >
> >> > So I think that UT_TESTF_SCAN_FDT line needs to be removed.
> >>
> >> OK, so to clarify, since 6ec5178c0ef added that UT_TESTF_SCAN_FDT, you 
> >> would like to
> >> revert that commit?
> >
> > Yes, I think that will work...but just check that tests without the
> > UT_TESTF_SCAN_FDT flag don't then run twice with sandbox. There was
> > perhaps something else wrong at the time.
>
> Actually, upon further review, I think that the above patch is correct. A 
> revert would
> cause tests with UT_TESTF_DM but without UT_TESTF_SCAN_FDT to run twice.
>

Thanks

Reviewed-by: Simon Glass 


Re: [PATCH RESEND 4/7] riscv: dts: introduce SPL_LOAD_FIT_OPENSBI_OS_BOOT symbol

2023-10-07 Thread Simon Glass
Hi Randolph,

On Fri, 6 Oct 2023 at 05:27, Randolph  wrote:
>
> Introduce common Kconfig symbol for riscv architecture.
> This symbol SPL_LOAD_FIT_OPENSBI_OS_BOOT is like falcon mode on ARM,
> the Falcon boot is a shortcut boot method for SD/eMMC targets. It
> skips the loading the RAM version U-Boot. Instead, it will loads
> the FIT image and boots directly to Linux.
>
> When SPL_OPENSBI_OS_BOOT is enabled, linux.itb is created after
> compilation instead of the default u-boot.itb. It initialises memory
> with the U-Boot SPL at the first stage, just as a normal boot process
> does at the beginning. Instead of jumping to the U-Boot proper from
> OpenSBI before booting the Linux kernel, the RISC-V falcon mode
> process jumps directly to the Linux kernel to gain shorter booting time.
>
> When SPL_OPENSBI_OS_BOOT is enabled, it will change the default FIT
> configure file "binman.dtsi" to "binman_linux.dtsi"
> Default is not enabled.
>
> Signed-off-by: Randolph 
> ---
>  arch/riscv/Kconfig | 9 +
>  1 file changed, 9 insertions(+)
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index ec1cfcaaa7..4f104789a7 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -422,8 +422,17 @@ config TPL_USE_ARCH_MEMSET
>
>  endmenu
>
> +config SPL_LOAD_FIT_OPENSBI_OS_BOOT
> +   bool "Enable SPL (OpenSBI OS boot mode) applying linux from FIT"
> +   depends on SPL_LOAD_FIT
> +   help
> + Use fw_dynamic from the FIT image, and u-boot SPL will invoke it 
> directly.
> + This is a shortcut boot flow, from u-boot SPL -> OpenSBI -> u-boot 
> proper
> + -> linux to u-boot SPL -> OpenSBI -> linux.

This bit seems OK

> +
>  config SPL_LOAD_FIT_CONFIG
> string "Default FIT configuration for SPL"
> +   default "binman_linux.dtsi" if SPL_LOAD_FIT_OPENSBI_OS_BOOT

But I'm hoping you can drop this and put the logic in binman.dtsi

> default "binman.dtsi"
> depends on SPL_LOAD_FIT
> help
> --
> 2.34.1
>

Regards,
Simon


Re: [PATCH RESEND 3/7] spl: riscv: opensbi: change the default os_type as varible

2023-10-07 Thread Simon Glass
On Fri, 6 Oct 2023 at 05:26, Randolph  wrote:
>
> In order to introduce the Opensbi OS boot mode, the next stage boot
> image of OpenSBI should be configurable.
>
> Signed-off-by: Randolph 
> ---
>  common/spl/spl_opensbi.c | 26 --
>  1 file changed, 16 insertions(+), 10 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH RESEND 1/7] riscv: dts: Introduce SPL_LOAD_FIT_CONFIG symbol

2023-10-07 Thread Simon Glass
Hi Randoph,

On Fri, 6 Oct 2023 at 05:26, Randolph  wrote:
>
> Introduce common Kconfig symbol for riscv architecture
> This symbol SPL_LOAD_FIT_CONFIG for binman itb layout selection
> Default is using binman.dtsi
>
> Signed-off-by: Randolph 
> ---
>  arch/riscv/Kconfig   | 7 +++
>  arch/riscv/dts/ae350-u-boot.dtsi | 1 +
>  arch/riscv/dts/ae350_32.dts  | 1 -
>  arch/riscv/dts/ae350_64.dts  | 1 -
>  4 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index aff1f33665..ec1cfcaaa7 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -422,4 +422,11 @@ config TPL_USE_ARCH_MEMSET
>
>  endmenu
>
> +config SPL_LOAD_FIT_CONFIG
> +   string "Default FIT configuration for SPL"
> +   default "binman.dtsi"
> +   depends on SPL_LOAD_FIT
> +   help
> + Specify corresponding FIT configuration for SPL modes.
> +
>  endmenu
> diff --git a/arch/riscv/dts/ae350-u-boot.dtsi 
> b/arch/riscv/dts/ae350-u-boot.dtsi
> index aef9159b7a..ff5725501f 100644
> --- a/arch/riscv/dts/ae350-u-boot.dtsi
> +++ b/arch/riscv/dts/ae350-u-boot.dtsi
> @@ -1,4 +1,5 @@
>  // SPDX-License-Identifier: (GPL-2.0 OR MIT)
> +#include CONFIG_SPL_LOAD_FIT_CONFIG

That doesn't seem great to me. I will check the next patch.

>  / {
> cpus {
> diff --git a/arch/riscv/dts/ae350_32.dts b/arch/riscv/dts/ae350_32.dts
> index 61af6d5465..2caabad888 100644
> --- a/arch/riscv/dts/ae350_32.dts
> +++ b/arch/riscv/dts/ae350_32.dts
> @@ -2,7 +2,6 @@
>
>  /dts-v1/;
>
> -#include "binman.dtsi"
>  #include "ae350-u-boot.dtsi"
>
>  / {
> diff --git a/arch/riscv/dts/ae350_64.dts b/arch/riscv/dts/ae350_64.dts
> index 8c7db29b4f..9d5f6c743c 100644
> --- a/arch/riscv/dts/ae350_64.dts
> +++ b/arch/riscv/dts/ae350_64.dts
> @@ -2,7 +2,6 @@
>
>  /dts-v1/;
>
> -#include "binman.dtsi"
>  #include "ae350-u-boot.dtsi"
>
>  / {
> --
> 2.34.1
>

Regards,
Simon


Re: [PATCH 1/5] tools: mkeficapsule: Add support to print capsule headers

2023-10-07 Thread Simon Glass
On Wed, 4 Oct 2023 at 05:27, Sughosh Ganu  wrote:
>
> Add support to dump the contents of capsule headers. This is useful as
> a debug feature for checking the contents of the capsule headers, and
> can also be used in capsule verification.
>
> Signed-off-by: Sughosh Ganu 
> ---
>  tools/eficapsule.h   |   2 +
>  tools/mkeficapsule.c | 229 ++-
>  2 files changed, 230 insertions(+), 1 deletion(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH 07/25] tegra: Change #ifdef for nop

2023-10-07 Thread Simon Glass
Hi Tom.

On Sun, 24 Sept 2023 at 18:43, Tom Rini  wrote:
>
> On Sun, Sep 24, 2023 at 02:39:25PM -0600, Simon Glass wrote:
>
> > This code is normally compiled for Tegra, but sandbox can also compile
> > it. We should not use UNIT_TEST as a synonym for SANDBOX, since it is
> > possible to disable UNIT_TEST for sandbox.
> >
> > Correct the condition.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  include/k210/pll.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/k210/pll.h b/include/k210/pll.h
> > index fd16a89cb203..6dd60b2eb4fc 100644
> > --- a/include/k210/pll.h
> > +++ b/include/k210/pll.h
> > @@ -13,7 +13,7 @@ struct k210_pll_config {
> >   u8 od;
> >  };
> >
> > -#ifdef CONFIG_UNIT_TEST
> > +#ifdef CONFIG_SANDBOX
> >  TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in,
> >struct k210_pll_config *best);
> >  #ifndef nop
>
> Tegra? Do you mean sifive?  That's where CLK_K210 stuff is... but it

Oh yes, I got confused.

> also seems wrong, you can run unit test on real hardware, and this is a
> test that could (should?) be run on that platform.

Only if it enables UNIT_TEST. You cannot run unit tests without that.
The current tests are designed for sandbox.

>
> --
> Tom

Regards,
Simon


Re: [PATCH 5/5] binman: capsule: Add support for generating EFI empty capsules

2023-10-07 Thread Simon Glass
Hi Sugosh,

On Wed, 4 Oct 2023 at 05:27, Sughosh Ganu  wrote:
>
> Add support in binman for generating EFI empty capsules. These
> capsules are used in the FWU A/B update feature. Also add test cases
> in binman for the corresponding code coverage.
>
> Signed-off-by: Sughosh Ganu 
> ---
>  tools/binman/etype/efi_empty_capsule.py   | 91 +++
>  tools/binman/ftest.py | 52 +++
>  tools/binman/test/319_capsule_accept.dts  | 16 
>  tools/binman/test/320_capsule_revert.dts  | 14 +++
>  .../test/321_capsule_accept_missing_guid.dts  | 14 +++
>  .../binman/test/322_capsule_accept_revert.dts | 17 
>  6 files changed, 204 insertions(+)
>  create mode 100644 tools/binman/etype/efi_empty_capsule.py
>  create mode 100644 tools/binman/test/319_capsule_accept.dts
>  create mode 100644 tools/binman/test/320_capsule_revert.dts
>  create mode 100644 tools/binman/test/321_capsule_accept_missing_guid.dts
>  create mode 100644 tools/binman/test/322_capsule_accept_revert.dts
>
> diff --git a/tools/binman/etype/efi_empty_capsule.py 
> b/tools/binman/etype/efi_empty_capsule.py
> new file mode 100644
> index 00..d2c781627b
> --- /dev/null
> +++ b/tools/binman/etype/efi_empty_capsule.py
> @@ -0,0 +1,91 @@
> +# SPDX-License-Identifier: GPL-2.0+
> +# Copyright (c) 2023 Linaro Limited
> +#
> +# Entry-type module for producing an empty  EFI capsule
> +#
> +
> +import os
> +
> +from binman.entry import Entry
> +from binman.etype.section import Entry_section
> +from dtoc import fdt_util
> +from u_boot_pylib import tools
> +
> +class Entry_efi_empty_capsule(Entry_section):

Do you think this could subclass Entry_efi_capsule? They seem to do
similar things. You could call generate_capsule() or
generate_empty_capsule(). depending on whether any data is present
(and perhaps require an operation if no data).

I'm not sure about this, just an idea.

> +"""Generate EFI empty capsules
> +
> +The parameters needed for generation of the empty capsules can
> +be provided as properties in the entry.
> +
> +Properties / Entry arguments:
> +- image-guid: Image GUID which will be used for identifying the
> +  updatable image on the board. Mandatory for accept capsule.
> +- accept-capsule - Boolean property to generate an accept capsule.
> +  image-type-id
> +- revert-capsule - Boolean property to generate a revert capsule
> +
> +For more details on the description of the capsule format, and the 
> capsule
> +update functionality, refer Section 8.5 and Chapter 23 in the `UEFI
> +specification`_. For more information on the empty capsule, refer the
> +sections 2.3.2 and 2.3.3 in the `Dependable Boot specification`_.
> +
> +A typical accept empty capsule entry node would then look something like 
> this
> +
> +empty-capsule {
> +type = "efi-empty-capsule";
> +/* Image GUID for testing capsule update */
> +image-type-id = SANDBOX_UBOOT_IMAGE_GUID;
> +accept-capsule;
> +};
> +
> +A typical revert empty capsule entry node would then look something like 
> this
> +
> +empty-capsule {
> +type = "efi-empty-capsule";
> +revert-capsule;
> +};
> +
> +The empty capsules do not have any input payload image.
> +
> +.. _`UEFI specification`: 
> https://uefi.org/sites/default/files/resources/UEFI_Spec_2_10_Aug29.pdf
> +.. _`Dependable Boot specification`: 
> https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf
> +"""
> +def __init__(self, section, etype, node):
> +super().__init__(section, etype, node)
> +self.accept = 0
> +self.revert = 0
> +
> +def ReadNode(self):
> +super().ReadNode()
> +
> +self.image_guid = fdt_util.GetString(self._node, 'image-guid')
> +self.accept = fdt_util.GetBool(self._node, 'accept-capsule')
> +self.revert = fdt_util.GetBool(self._node, 'revert-capsule')

Perhaps it should be

operation = "accept" / "revert" ?

Using two conflicting bools is not great.

> +
> +if self.accept and not self.image_guid:
> +self.Raise('Image GUID needed for generating accept capsule')
> +
> +if self.accept and self.revert:
> +self.Raise('Need to enable either Accept or Revert capsule')
> +
> +def BuildSectionData(self, required):
> +def get_binman_test_guid(type_str):
> +TYPE_TO_GUID = {
> +'binman-test' : '09d7cf52-0720-4710-91d1-08469b7fe9c8'

Can you put this in a shared file somewhere, used by this and the
efi_capsule.py module?

> +}
> +return TYPE_TO_GUID[type_str]
> +
> +uniq = self.GetUniqueName()
> +outfile = self._filename if self._filename else 'capsule.%s' % uniq
> +capsule_fname = tools.get_output_filename(outfile)
> +guid = self.image_guid
> +if self.image_guid

Re: [RESEND PATCH] bootstd: sata: bootdev scanning for ahci sata with no drive attached

2023-10-07 Thread Simon Glass
On Fri, 6 Oct 2023 at 21:34, Tony Dinh  wrote:
>
> It's normal to have no SATA drive attached to the controller, so return a
> successful status when there is no block device found after probing.
>
> Note: this patch depends on the previous patch
> https://patchwork.ozlabs.org/project/uboot/patch/20230917230649.30357-1-mibo...@gmail.com/
>
> Resend the right patch.
>
> Signed-off-by: Tony Dinh 
> ---
>
>  drivers/ata/sata.c | 6 ++
>  1 file changed, 6 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH 2/5] doc: capsule: Add documentation for the capsule dump feature

2023-10-07 Thread Simon Glass
On Wed, 4 Oct 2023 at 05:27, Sughosh Ganu  wrote:
>
> Add documentation to explain the printing of the capsule headers
> through the mkeficapsule tool.
>
> Signed-off-by: Sughosh Ganu 
> ---
>  doc/develop/uefi/uefi.rst | 17 +
>  1 file changed, 17 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH] cli: Consume invalid escape sequences early

2023-10-07 Thread Simon Glass
Hi Yurii,

On Fri, 6 Oct 2023 at 15:32, Yurii Monakov  wrote:
>
> This commit fixes some issues with extra 'Esc' keys entered by user:
>
> 1. Sequence  right after autoboot stop gives:
> =>
> nknown command 'ry 'help'
> =>
> 2. Sequence  gives:
> => ri
> Unknown command 'ri' - try 'help'
> =>
> 3. Extra 'Esc' key presses break backspace functionality.
>
> Signed-off-by: Yurii Monakov 
> ---
>  common/cli_getch.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/common/cli_getch.c b/common/cli_getch.c
> index 61d4cb261b..0ee7908777 100644
> --- a/common/cli_getch.c
> +++ b/common/cli_getch.c
> @@ -46,6 +46,8 @@ static int cli_ch_esc(struct cli_ch_state *cch, int ichar,
> case 1:
> if (ichar == '[' || ichar == 'O')
> act = ESC_SAVE;
> +   else
> +   act = ESC_CONVERTED;
> break;
> case 2:
> switch (ichar) {
> --
> 2.34.1
>

This is a bit unfortunate. Basically the problem (as I understand it)
is that characters are built up for processing so the expected ichar
== 0 is never passed in.

I think the fix is reasonable. Does it work as well if use:

   else if (ichar == '\e')
   act = ESC_CONVERTED;

?

Also please can you add a test case o test/common/cread.c

https://u-boot.readthedocs.io/en/latest/develop/tests_sandbox.html

Regards,
Simon


[PATCH] arm: mvebu: Enable bootstd for Thecus N2350 board

2023-10-07 Thread Tony Dinh
Enable bootstd for Thecus N2350 board, and remove distroboot.

Signed-off-by: Tony Dinh 
---

 configs/n2350_defconfig |  3 ++-
 include/configs/n2350.h | 12 +---
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/configs/n2350_defconfig b/configs/n2350_defconfig
index 109f0e10e9..07135742d3 100644
--- a/configs/n2350_defconfig
+++ b/configs/n2350_defconfig
@@ -29,7 +29,8 @@ CONFIG_ENV_ADDR=0x10
 CONFIG_PCI=y
 CONFIG_DEBUG_UART=y
 CONFIG_AHCI=y
-CONFIG_DISTRO_DEFAULTS=y
+CONFIG_BOOTSTD_FULL=y
+CONFIG_BOOTSTD_DEFAULTS=y
 CONFIG_BOOTDELAY=10
 CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
diff --git a/include/configs/n2350.h b/include/configs/n2350.h
index 92b2270236..d8a9814d3e 100644
--- a/include/configs/n2350.h
+++ b/include/configs/n2350.h
@@ -20,15 +20,8 @@
  */
 #include "mv-common.h"
 
-/* Include the common distro boot environment */
 #ifndef CONFIG_SPL_BUILD
 
-#define BOOT_TARGET_DEVICES(func) \
-   func(SCSI, scsi, 0) \
-   func(USB, usb, 0) \
-   func(PXE, pxe, na) \
-   func(DHCP, dhcp, na)
-
 #define KERNEL_ADDR_R  __stringify(0x100)
 #define FDT_ADDR_R __stringify(0x200)
 #define RAMDISK_ADDR_R __stringify(0x220)
@@ -42,14 +35,11 @@
"scriptaddr=" SCRIPT_ADDR_R "\0" \
"pxefile_addr_r=" PXEFILE_ADDR_R "\0"
 
-#include 
-
 #define CFG_EXTRA_ENV_SETTINGS \
RELOCATION_LIMITS_ENV_SETTINGS \
LOAD_ADDRESS_ENV_SETTINGS \
"fdtfile=" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
-   "console=ttyS0,115200\0" \
-   BOOTENV
+   "console=ttyS0,115200\0"
 
 #endif /* CONFIG_SPL_BUILD */
 
-- 
2.39.2



[PATCH 2/3] usb: ehci: mxs: Use regulator_set_enable_if_allowed()

2023-10-07 Thread Fabio Estevam
From: Fabio Estevam 

Since commit 4fcba5d556b4 ("regulator: implement basic reference
counter") the return value of regulator_set_enable() may be EALREADY or
EBUSY for fixed/GPIO regulators.

Swict to using the more relaxed regulator_set_enable_if_allowed() to
continue if regulator already was enabled or disabled.

This fixes the following error when running the 'ums' command:

=> ums 0 mmc 0
UMS: LUN 0, dev mmc 0, hwpart 0, sector 0x0, count 0xece000
Error enabling VBUS supply
g_dnl_register: failed!, error: -114
g_dnl_register failed

Signed-off-by: Fabio Estevam 
---
 drivers/usb/host/ehci-mxs.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/ehci-mxs.c b/drivers/usb/host/ehci-mxs.c
index 092c79fd4bc5..ddf7cc2d00a7 100644
--- a/drivers/usb/host/ehci-mxs.c
+++ b/drivers/usb/host/ehci-mxs.c
@@ -236,9 +236,9 @@ static int ehci_usb_probe(struct udevice *dev)
debug("%s: No vbus supply\n", dev->name);
 
if (!ret && priv->vbus_supply) {
-   ret = regulator_set_enable(priv->vbus_supply,
-  (type == USB_INIT_DEVICE) ?
-  false : true);
+   ret = regulator_set_enable_if_allowed(priv->vbus_supply,
+ (type == USB_INIT_DEVICE) 
?
+ false : true);
if (ret) {
puts("Error enabling VBUS supply\n");
return ret;
@@ -265,7 +265,7 @@ static int ehci_usb_remove(struct udevice *dev)
 
 #if CONFIG_IS_ENABLED(DM_REGULATOR)
if (priv->vbus_supply) {
-   ret = regulator_set_enable(priv->vbus_supply, false);
+   ret = regulator_set_enable_if_allowed(priv->vbus_supply, false);
if (ret) {
puts("Error disabling VBUS supply\n");
return ret;
-- 
2.34.1



[PATCH 3/3] mx28evk: Add USB Mass Storage support

2023-10-07 Thread Fabio Estevam
From: Fabio Estevam 

Select the USB options to allow running "ums 0 mmc 0".

Signed-off-by: Fabio Estevam 
---
 configs/mx28evk_defconfig | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/configs/mx28evk_defconfig b/configs/mx28evk_defconfig
index df0cceaea719..15cc99684c05 100644
--- a/configs/mx28evk_defconfig
+++ b/configs/mx28evk_defconfig
@@ -32,6 +32,9 @@ CONFIG_CMD_DM=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_NAND_TRIMFFS=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_USB_SDP=y
+CONFIG_CMD_USB_MASS_STORAGE=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_DATE=y
 CONFIG_CMD_EXT4=y
@@ -65,3 +68,14 @@ CONFIG_RTC_MXS=y
 CONFIG_DM_SERIAL=y
 CONFIG_SPI=y
 CONFIG_USB=y
+CONFIG_SPL_USB_HOST=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_MAX_CONTROLLER_COUNT=2
+CONFIG_USB_GADGET=y
+CONFIG_SPL_USB_GADGET=y
+CONFIG_USB_GADGET_MANUFACTURER="FSL"
+CONFIG_USB_GADGET_VENDOR_NUM=0x0525
+CONFIG_USB_GADGET_PRODUCT_NUM=0xa4a5
+CONFIG_CI_UDC=y
+CONFIG_USB_GADGET_DOWNLOAD=y
+CONFIG_SPL_USB_SDP_SUPPORT=y
-- 
2.34.1



[PATCH 1/3] usb: ehci: mxs: Fix the USB node pointer retrieval

2023-10-07 Thread Fabio Estevam
From: Fabio Estevam 

Use dev_ofnode() to retrieve the USB node pointer from the udevice
structure.

This fixes the following build error:

drivers/usb/host/ehci-mxs.c:143:38: error: 'struct udevice' has no member named 
'node_'

Signed-off-by: Fabio Estevam 
---
 drivers/usb/host/ehci-mxs.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ehci-mxs.c b/drivers/usb/host/ehci-mxs.c
index 147b2fa145d6..092c79fd4bc5 100644
--- a/drivers/usb/host/ehci-mxs.c
+++ b/drivers/usb/host/ehci-mxs.c
@@ -136,11 +136,12 @@ static int ehci_usb_ofdata_to_platdata(struct udevice 
*dev)
struct usb_plat *plat = dev_get_plat(dev);
struct ehci_mxs_port *port = &priv->port;
u32 phandle, phy_reg, clk_reg, clk_id;
+   ofnode np = dev_ofnode(dev);
ofnode phy_node, clk_node;
const char *mode;
int ret;
 
-   mode = ofnode_read_string(dev->node_, "dr_mode");
+   mode = ofnode_read_string(np, "dr_mode");
if (mode) {
if (strcmp(mode, "peripheral") == 0)
plat->init_type = USB_INIT_DEVICE;
@@ -151,12 +152,12 @@ static int ehci_usb_ofdata_to_platdata(struct udevice 
*dev)
}
 
/* Read base address of the USB IP block */
-   ret = ofnode_read_u32(dev->node_, "reg", &port->usb_regs);
+   ret = ofnode_read_u32(np, "reg", &port->usb_regs);
if (ret)
return ret;
 
/* Read base address of the USB PHY IP block */
-   ret = ofnode_read_u32(dev->node_, "fsl,usbphy", &phandle);
+   ret = ofnode_read_u32(np, "fsl,usbphy", &phandle);
if (ret)
return ret;
 
-- 
2.34.1



[PATCH v2 8/9] test: bdinfo: Test bdinfo -m

2023-10-07 Thread Marek Vasut
The bdinfo -m should print only the board memory layout.
Test the expected output.

Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Rename bdinfo_test_mem() to bdinfo_check_mem()
---
 test/cmd/bdinfo.c | 26 +++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index 2f34d877e5c..c9be182e370 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -130,13 +130,11 @@ static int lmb_test_dump_all(struct unit_test_state *uts, 
struct lmb *lmb)
return 0;
 }
 
-static int bdinfo_test_all(struct unit_test_state *uts)
+static int bdinfo_check_mem(struct unit_test_state *uts)
 {
struct bd_info *bd = gd->bd;
int i;
 
-   ut_assertok(test_num_l(uts, "boot_params", 0));
-
for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
if (bd->bi_dram[i].size) {
ut_assertok(test_num_l(uts, "DRAM bank", i));
@@ -147,6 +145,15 @@ static int bdinfo_test_all(struct unit_test_state *uts)
}
}
 
+   return 0;
+}
+
+static int bdinfo_test_all(struct unit_test_state *uts)
+{
+   ut_assertok(test_num_l(uts, "boot_params", 0));
+
+   ut_assertok(bdinfo_check_mem(uts));
+
/* CONFIG_SYS_HAS_SRAM testing not supported */
ut_assertok(test_num_l(uts, "flashstart", 0));
ut_assertok(test_num_l(uts, "flashsize", 0));
@@ -243,6 +250,19 @@ static int bdinfo_test_help(struct unit_test_state *uts)
 
 BDINFO_TEST(bdinfo_test_help, UT_TESTF_CONSOLE_REC);
 
+static int bdinfo_test_memory(struct unit_test_state *uts)
+{
+   /* Test BDINFO memory layout only print */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("bdinfo -m"));
+   ut_assertok(bdinfo_check_mem(uts));
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+BDINFO_TEST(bdinfo_test_memory, UT_TESTF_CONSOLE_REC);
+
 int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test);
-- 
2.40.1



[PATCH v2 6/9] test: bdinfo: Test both bdinfo and bdinfo -a

2023-10-07 Thread Marek Vasut
Factor out the core of test for all bdinfo output into bdinfo_test_all()
and then reuse it to verify that both 'bdinfo' and 'bdinfo -a' print all
the bdinfo output.

Reviewed-by: Simon Glass 
Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Add RB from Simon
---
 test/cmd/bdinfo.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index b2896e8eb41..509a8b5c586 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -130,15 +130,11 @@ static int lmb_test_dump_all(struct unit_test_state *uts, 
struct lmb *lmb)
return 0;
 }
 
-static int bdinfo_test_full(struct unit_test_state *uts)
+static int bdinfo_test_all(struct unit_test_state *uts)
 {
struct bd_info *bd = gd->bd;
int i;
 
-   /* Test moving the working BDINFO to a new location */
-   ut_assertok(console_record_reset_enable());
-   ut_assertok(run_commandf("bdinfo"));
-
ut_assertok(test_num_l(uts, "boot_params", 0));
 
for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
@@ -212,6 +208,17 @@ static int bdinfo_test_full(struct unit_test_state *uts)
ut_assertok(test_num_l(uts, "malloc base", gd_malloc_start()));
}
 
+   return 0;
+}
+
+static int bdinfo_test_full(struct unit_test_state *uts)
+{
+   /* Test BDINFO full print */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("bdinfo"));
+   ut_assertok(bdinfo_test_all(uts));
+   ut_assertok(run_commandf("bdinfo -a"));
+   ut_assertok(bdinfo_test_all(uts));
ut_assertok(ut_check_console_end(uts));
 
return 0;
-- 
2.40.1



[PATCH v2 5/9] test: bdinfo: Rename bdinfo_test_move() to bdinfo_test_full()

2023-10-07 Thread Marek Vasut
Rename bdinfo_test_move() to bdinfo_test_full(). The former is a
remnant of deriving this test from another test. No functional
change.

Reviewed-by: Simon Glass 
Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Add RB from Simon
---
 test/cmd/bdinfo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index 8c09281cac0..b2896e8eb41 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -130,7 +130,7 @@ static int lmb_test_dump_all(struct unit_test_state *uts, 
struct lmb *lmb)
return 0;
 }
 
-static int bdinfo_test_move(struct unit_test_state *uts)
+static int bdinfo_test_full(struct unit_test_state *uts)
 {
struct bd_info *bd = gd->bd;
int i;
@@ -217,7 +217,7 @@ static int bdinfo_test_move(struct unit_test_state *uts)
return 0;
 }
 
-BDINFO_TEST(bdinfo_test_move, UT_TESTF_CONSOLE_REC);
+BDINFO_TEST(bdinfo_test_full, UT_TESTF_CONSOLE_REC);
 
 int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
-- 
2.40.1



[PATCH v2 9/9] test: bdinfo: Test bdinfo -e

2023-10-07 Thread Marek Vasut
The bdinfo -e should print only the board ethernet settings.
Test the expected output.

Reviewed-by: Simon Glass 
Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Add RB from Simon
---
 test/cmd/bdinfo.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index c9be182e370..9744bd16df9 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -263,6 +263,20 @@ static int bdinfo_test_memory(struct unit_test_state *uts)
 
 BDINFO_TEST(bdinfo_test_memory, UT_TESTF_CONSOLE_REC);
 
+static int bdinfo_test_eth(struct unit_test_state *uts)
+{
+   /* Test BDINFO ethernet settings only print */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("bdinfo -e"));
+   if (IS_ENABLED(CONFIG_CMD_NET))
+   ut_assertok(test_eth(uts));
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+BDINFO_TEST(bdinfo_test_eth, UT_TESTF_CONSOLE_REC);
+
 int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test);
-- 
2.40.1



[PATCH v2 7/9] test: bdinfo: Test bdinfo -h

2023-10-07 Thread Marek Vasut
The bdinfo -h should print error message that -h is an unknown
parameter and then command help text. Test the expected output.

Reviewed-by: Simon Glass 
Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Add RB from Simon
---
 test/cmd/bdinfo.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/test/cmd/bdinfo.c b/test/cmd/bdinfo.c
index 509a8b5c586..2f34d877e5c 100644
--- a/test/cmd/bdinfo.c
+++ b/test/cmd/bdinfo.c
@@ -226,6 +226,23 @@ static int bdinfo_test_full(struct unit_test_state *uts)
 
 BDINFO_TEST(bdinfo_test_full, UT_TESTF_CONSOLE_REC);
 
+static int bdinfo_test_help(struct unit_test_state *uts)
+{
+   /* Test BDINFO unknown option help text print */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("bdinfo -h"));
+   ut_assert_nextlinen("bdinfo: invalid option -- h");
+   ut_assert_nextlinen("bdinfo - print Board Info structure");
+   ut_assert_nextline_empty();
+   ut_assert_nextlinen("Usage:");
+   ut_assert_nextlinen("bdinfo");
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+BDINFO_TEST(bdinfo_test_help, UT_TESTF_CONSOLE_REC);
+
 int do_ut_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(bdinfo_test);
-- 
2.40.1



[PATCH v2 3/9] cmd: bdinfo: Implement support for printing ethernet settings via bdinfo -e

2023-10-07 Thread Marek Vasut
Add support for printing ethernet settings only via 'bdinfo -e' .

Reviewed-by: Simon Glass 
Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Add RB from Simon
---
 cmd/bdinfo.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index c720ee6f9b6..79106caeec2 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -193,10 +193,15 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
return bdinfo_print_all(bd);
 
getopt_init_state(&gs);
-   while ((opt = getopt(&gs, argc, argv, "am")) > 0) {
+   while ((opt = getopt(&gs, argc, argv, "aem")) > 0) {
switch (opt) {
case 'a':
return bdinfo_print_all(bd);
+   case 'e':
+   if (!IS_ENABLED(CONFIG_CMD_NET))
+   return CMD_RET_USAGE;
+   print_eth();
+   return CMD_RET_SUCCESS;
case 'm':
print_bi_dram(bd);
return CMD_RET_SUCCESS;
-- 
2.40.1



[PATCH v2 4/9] configs: sandbox: Enable GETOPT for sandbox and sandbox64 target

2023-10-07 Thread Marek Vasut
Enable GETOPT so that 'bdinfo' command with getopt() support can be
tested in CI.

Reviewed-by: Simon Glass 
Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Add RB from Simon
---
 configs/sandbox64_defconfig | 1 +
 configs/sandbox_defconfig   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 1a033b22018..e937ac66964 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -262,6 +262,7 @@ CONFIG_CMD_DHRYSTONE=y
 CONFIG_TPM=y
 CONFIG_LZ4=y
 CONFIG_ERRNO_STR=y
+CONFIG_GETOPT=y
 CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y
 CONFIG_EFI_CAPSULE_ON_DISK=y
 CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 01830c7bd25..019e41580c1 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -338,6 +338,7 @@ CONFIG_ECDSA_VERIFY=y
 CONFIG_TPM=y
 CONFIG_SHA384=y
 CONFIG_ERRNO_STR=y
+CONFIG_GETOPT=y
 CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y
 CONFIG_EFI_CAPSULE_ON_DISK=y
 CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
-- 
2.40.1



[PATCH v2 2/9] cmd: bdinfo: Implement support for printing memory layout via bdinfo -m

2023-10-07 Thread Marek Vasut
Add support for printing memory layout only via 'bdinfo -m' .

Reviewed-by: Simon Glass 
Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Add RB from Simon
---
 cmd/bdinfo.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index 2c0d5e9c01b..c720ee6f9b6 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -193,10 +193,13 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
return bdinfo_print_all(bd);
 
getopt_init_state(&gs);
-   while ((opt = getopt(&gs, argc, argv, "a")) > 0) {
+   while ((opt = getopt(&gs, argc, argv, "am")) > 0) {
switch (opt) {
case 'a':
return bdinfo_print_all(bd);
+   case 'm':
+   print_bi_dram(bd);
+   return CMD_RET_SUCCESS;
default:
return CMD_RET_USAGE;
}
-- 
2.40.1



[PATCH v2 1/9] cmd: bdinfo: Optionally use getopt and implement bdinfo -a

2023-10-07 Thread Marek Vasut
Add optional support for getopt() and in case this is enabled via
GETOPT configuration option, implement support for 'bdinfo -a'.
The 'bdinfo -a' behaves exactly like bdinfo and prints 'all' the
bdinfo information. This is implemented in preparation for other
more fine-grained options.

Reviewed-by: Simon Glass 
Signed-off-by: Marek Vasut 
---
Cc: Bin Meng 
Cc: Mario Six 
Cc: Nikhil M Jain 
Cc: Simon Glass 
---
V2: Add RB from Simon
---
 cmd/bdinfo.c | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index 1fe13ca13a0..2c0d5e9c01b 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -133,10 +134,8 @@ static void print_serial(struct udevice *dev)
bdinfo_print_num_l(" clock", info.clock);
 }
 
-int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+static int bdinfo_print_all(struct bd_info *bd)
 {
-   struct bd_info *bd = gd->bd;
-
 #ifdef DEBUG
bdinfo_print_num_l("bd address", (ulong)bd);
 #endif
@@ -184,8 +183,30 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[])
return 0;
 }
 
+int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+   struct bd_info *bd = gd->bd;
+   struct getopt_state gs;
+   int opt;
+
+   if (!CONFIG_IS_ENABLED(GETOPT) || argc == 1)
+   return bdinfo_print_all(bd);
+
+   getopt_init_state(&gs);
+   while ((opt = getopt(&gs, argc, argv, "a")) > 0) {
+   switch (opt) {
+   case 'a':
+   return bdinfo_print_all(bd);
+   default:
+   return CMD_RET_USAGE;
+   }
+   }
+
+   return CMD_RET_USAGE;
+}
+
 U_BOOT_CMD(
-   bdinfo, 1,  1,  do_bdinfo,
+   bdinfo, 2,  1,  do_bdinfo,
"print Board Info structure",
""
 );
-- 
2.40.1



[PATCH] arm: mvebu: Enable bootstd for Synology DS116 board

2023-10-07 Thread Tony Dinh
Enable bootstd for Synology DS116 board, and remove distroboot.

Signed-off-by: Tony Dinh 
---

 configs/ds116_defconfig |  3 ++-
 include/configs/ds116.h | 12 +---
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/configs/ds116_defconfig b/configs/ds116_defconfig
index 0cd546c223..2437be73cd 100644
--- a/configs/ds116_defconfig
+++ b/configs/ds116_defconfig
@@ -28,7 +28,8 @@ CONFIG_SYS_LOAD_ADDR=0x80
 CONFIG_PCI=y
 CONFIG_DEBUG_UART=y
 CONFIG_AHCI=y
-CONFIG_DISTRO_DEFAULTS=y
+CONFIG_BOOTSTD_FULL=y
+CONFIG_BOOTSTD_DEFAULTS=y
 CONFIG_BOOTDELAY=10
 CONFIG_USE_PREBOOT=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
diff --git a/include/configs/ds116.h b/include/configs/ds116.h
index 031f4f6afc..0883ec4d53 100644
--- a/include/configs/ds116.h
+++ b/include/configs/ds116.h
@@ -20,15 +20,8 @@
  */
 #include "mv-common.h"
 
-/* Include the common distro boot environment */
 #ifndef CONFIG_SPL_BUILD
 
-#define BOOT_TARGET_DEVICES(func) \
-   func(USB, usb, 0) \
-   func(SCSI, scsi, 0) \
-   func(PXE, pxe, na) \
-   func(DHCP, dhcp, na)
-
 #define KERNEL_ADDR_R  __stringify(0x100)
 #define FDT_ADDR_R __stringify(0x200)
 #define RAMDISK_ADDR_R __stringify(0x220)
@@ -42,14 +35,11 @@
"scriptaddr=" SCRIPT_ADDR_R "\0" \
"pxefile_addr_r=" PXEFILE_ADDR_R "\0"
 
-#include 
-
 #define CFG_EXTRA_ENV_SETTINGS \
RELOCATION_LIMITS_ENV_SETTINGS \
LOAD_ADDRESS_ENV_SETTINGS \
"fdtfile=" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
-   "console=ttyS0,115200\0" \
-   BOOTENV
+   "console=ttyS0,115200\0"
 
 #endif /* CONFIG_SPL_BUILD */
 
-- 
2.39.2



Re: [PATCH 10/16] serial: sh: Add RZ/G2L SCIF support

2023-10-07 Thread Marek Vasut

On 10/5/23 14:08, Paul Barker wrote:

On 04/10/2023 20:41, Marek Vasut wrote:

On 10/4/23 18:38, Paul Barker wrote:

On Wed, Oct 04, 2023 at 05:17:55PM +0200, Marek Vasut wrote:

On 10/4/23 15:43, Paul Barker wrote:

On Wed, Oct 04, 2023 at 02:26:49PM +0200, Marek Vasut wrote:

On 10/4/23 10:48, Paul Barker wrote:

On 03/10/2023 14:23, Marek Vasut wrote:

On 9/20/23 14:42, Paul Barker wrote:

Extend the existing driver to support the SCIF serial ports on the
Renesas RZ/G2L (R9A07G044) SoC. This also requires us to ensure that the
relevant reset signal is de-asserted before we try to talk to the SCIF
module.

Signed-off-by: Paul Barker 
Reviewed-by: Biju Das 
Reviewed-by: Lad Prabhakar 
---
  arch/arm/mach-rmobile/Kconfig |  1 +
  drivers/serial/serial_sh.c| 32 ++--
  drivers/serial/serial_sh.h| 19 ++-
  3 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-rmobile/Kconfig b/arch/arm/mach-rmobile/Kconfig
index 973e84fcf7ba..0ab22356aee5 100644
--- a/arch/arm/mach-rmobile/Kconfig
+++ b/arch/arm/mach-rmobile/Kconfig
@@ -77,6 +77,7 @@ config RZG2L
imply RENESAS_SDHI
imply CLK_RZG2L
imply PINCTRL_RZG2L
+   imply SCIF_CONSOLE
help
  Enable support for the Renesas RZ/G2L family of SoCs, including the
  the RZ/G2L itself (based on the R9A07G044 SoC).
diff --git a/drivers/serial/serial_sh.c b/drivers/serial/serial_sh.c
index 5e543dbf3d58..a2e9a57137a6 100644
--- a/drivers/serial/serial_sh.c
+++ b/drivers/serial/serial_sh.c
@@ -17,6 +17,8 @@
  #include 
  #include 
  #include 
+#include 
+#include 
  #include "serial_sh.h"
  DECLARE_GLOBAL_DATA_PTR;
@@ -79,8 +81,16 @@ sh_serial_setbrg_generic(struct uart_port *port, int clk, 
int baudrate)
  static void handle_error(struct uart_port *port)
  {
-   sci_in(port, SCxSR);
-   sci_out(port, SCxSR, SCxSR_ERROR_CLEAR(port));
+   /* The RZ/G2L datasheet says that error conditions are cleared by
+* resetting the error bits in the FSR register to zero.


Can you be more specific here ?

It doesn't seem Linux sh-sci.c driver does anything special for G2L, so
is this special case really needed ?


On page 1268 of the datasheet (R01UH0914EJ0130 Rev.1.30):

"DR is cleared to 0 when DR = 1 is read and then 0 is written to the DR
flag."

On page 1270:

"[Clearing condition]
● When 0 is written to ER after it has been read as 1"

So zeros must be written to clear these errors, not ones.

We have an open task to investigate the issue in the Linux driver and
fix it.


Is the G2L UART broken in Linux ?


Likely yes, but we need to reproduce the issue.


Does it misbehave in U-Boot ?


Yes, before I changed this, if a framing error occurred it could never
be cleared and the serial port stopped sending/receiving data.

The framing error was triggered by accident by unnecessarily re-doing
pinmuxing for the serial port after TrustedFirmware had already set it
up correctly. Since SCIF0 is wired to an FTDI USB/serial adaptor chip on
the SMARC carrier board, it seems very difficult to trigger a framing
error in any other way, the FTDI chip is too well behaved.


Is it possible to trigger this on RZ/G2 with SCIF on those platforms
as well ?


It's not been seen or reported to my knowledge, but it's on our list to
look into further.


Can you give it a quick try ? I'd really like to avoid G2L specific
behavior here if it can be avoided.

Is there a testcase ?



The case we're interested in here is the Receive Error (ER) & Break
Detect (BRK) conditions. I've done some further datasheet digging...

RZ/G2L datasheet says these are cleared by writing zero to the
appropriate bits of the FSR register.

RZ/G2{H,M,N,E} datasheet says the same (pages 50-18 & 50-19 of
R01UH0808EJ0111 Rev.1.11).

The R-Car Gen3 Hardware Manual says the same (pages 55-18 & 55-19 of
R19UH0105EJ0230 Rev.2.30).

For R-Car S4, there is an Excel spreadsheet attached to page 105-5 of
the datasheet (R19UH0161EJ0100 Rev.1.00) which again says the same.

For R-Car V4H, the relevant info is on pages 105-16 & 105-18 of the
datasheet (R19UH0172EJ0081 Rev.0.81) and says the same.

On the RZ/G2L I was able to reproduce a break condition by changing
pinmux settings after the SCIF interface has been configured. You could
try this out on an R-Car system, but I don't think it's guaranteed to
cause a break condition, it may depend on how the port input is
implemented in those SoCs. From my reading, the only guaranteed way to
cause a break condition is to hold the Rx signal low, and you might need
to solder on some extra wires on to a board to be able to do that.


Can't you simply send a BREAK from terminal program ?
In minicom, I think that's meta-F B .


We should still fix the error handling here, even if the boards we have
don't easily cause Receive Errors or Break conditions, other folks may
have their own boards based on these SoCs.

If you're h

Re: [PATCH v5 5/6] sysinfo: rcar3: Use int instead of char for revision

2023-10-07 Thread Marek Vasut

On 10/2/23 17:20, Detlev Casanova wrote:

To be used with the sysinfo command, revision values must be considered
as integers, not chars as some boards will implement BOARD_REVISION_*
and might use numbers greater than 9.

Signed-off-by: Detlev Casanova 
---
  drivers/sysinfo/rcar3.c | 73 ++---
  1 file changed, 39 insertions(+), 34 deletions(-)

diff --git a/drivers/sysinfo/rcar3.c b/drivers/sysinfo/rcar3.c
index 7b127986da7..633e80bc19b 100644
--- a/drivers/sysinfo/rcar3.c
+++ b/drivers/sysinfo/rcar3.c
@@ -68,8 +68,9 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
bool salvator_xs = false;
bool ebisu_4d = false;
bool condor_i = false;
-   char rev_major = '?';
-   char rev_minor = '?';
+   char rev[4] = "?.?";
+   u8 rev_major = 0;
+   u8 rev_minor = 0;
  
  	switch (board_id) {

case BOARD_SALVATOR_XS:
@@ -77,81 +78,85 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv 
*priv)
fallthrough;
case BOARD_SALVATOR_X:
if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
-   rev_major = '1';
-   rev_minor = '0' + (board_rev & BIT(0));
+   rev_major = 1;
+   rev_minor = board_rev & BIT(0);
+   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
}
snprintf(priv->boardmodel, sizeof(priv->boardmodel),
-"Renesas Salvator-X%s board rev %c.%c",
-salvator_xs ? "S" : "", rev_major, rev_minor);
+"Renesas Salvator-X%s board rev %s",
+salvator_xs ? "S" : "", rev);
+
return;


Extra newline got added just before the return here. If you want to do 
V6 with that fixed, that would be nice. In either case:


Reviewed-by: Marek Vasut 

Thanks !


Re: [PATCH v5 6/6] sysinfo: rcar3: Implement BOARD_ID and BOARD_REV_*

2023-10-07 Thread Marek Vasut

On 10/2/23 17:20, Detlev Casanova wrote:

Expose that information to the sysinfo command to let scripts make
decisions based on the board id and revision.

Signed-off-by: Detlev Casanova 
---
  drivers/sysinfo/rcar3.c | 89 +
  1 file changed, 63 insertions(+), 26 deletions(-)

diff --git a/drivers/sysinfo/rcar3.c b/drivers/sysinfo/rcar3.c
index 633e80bc19b..a554323506a 100644
--- a/drivers/sysinfo/rcar3.c
+++ b/drivers/sysinfo/rcar3.c
@@ -32,6 +32,10 @@
   */
  struct sysinfo_rcar_priv {
charboardmodel[64];
+   u8  id;
+   u8  rev_major;
+   u8  rev_minor;
+   boolhas_rev;
u8  val;
  };
  
@@ -56,9 +60,33 @@ static int sysinfo_rcar_get_str(struct udevice *dev, int id, size_t size, char *

};
  }
  
+static int sysinfo_rcar_get_int(struct udevice *dev, int id, int *val)

+{
+   struct sysinfo_rcar_priv *priv = dev_get_priv(dev);
+
+   switch (id) {
+   case SYSINFO_ID_BOARD_ID:
+   *val = priv->id;
+   return 0;
+   case SYSINFO_ID_BOARD_REV_MAJOR:
+   if (!priv->has_rev)
+   return -EINVAL;
+   *val = priv->rev_major;
+   return 0;
+   case SYSINFO_ID_BOARD_REV_MINOR:
+   if (!priv->has_rev)
+   return -EINVAL;
+   *val = priv->rev_minor;
+   return 0;
+   default:
+   return -EINVAL;
+   };
+}
+
  static const struct sysinfo_ops sysinfo_rcar_ops = {
.detect = sysinfo_rcar_detect,
.get_str = sysinfo_rcar_get_str,
+   .get_int = sysinfo_rcar_get_int,
  };
  
  static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)

@@ -69,8 +97,9 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
bool ebisu_4d = false;
bool condor_i = false;
char rev[4] = "?.?";
-   u8 rev_major = 0;
-   u8 rev_minor = 0;
+
+   priv->id = board_id;
+   priv->has_rev = false;


Would it make more sense to assign

priv->rev_major = 1;
priv->rev_minor = 0;

And get rid of priv->has_rev entirely ?

Basically say that the default case is rev. 1.0 board.

[...]


[PATCH] board: rockchip: add FriendlyElec NanoPC-T6 rk3588 board

2023-10-07 Thread John Clark
NanoPC-T6 is a Rockchip RK3588 based SBC by FriendlyElec.

There are four variants depending on the DRAM size: 4G/32GB eMMC, 8G/64GB eMMC,
16G/16MB SPI NOR, and 16G/256GB eMMC/16MB SPI NOR

Specifications:
CPU: Rockchip RK3588, 4x Cortex-A76 (up to 2.4GHz) + 4x Cortex-A55 (up to 
1.8GHz)
GPU: Mali-G610 MP4
VPU: 8K@60fps H.265 and VP9 decoder, 8K@30fps H.264 decoder,
 4K@60fps AV1 decoder, 8K@30fps H.264 and H.265 encoder
NPU: 6TOPs, supports INT4/INT8/INT16/FP16
RAM: 64-bit 4GB/8GB/16GB LPDDR4X at 2133MHz
eMMC: 0GB/32GB/64GB/256GB HS400
MicroSD Slot: MicroSD SDR104
PCIe 3.0: M.2 M-Key x1, PCIe 3.0 x4 for NVMe SSDs up to 2,500 MB/s
Ethernet: PCIe 2.5G 2x Ethernet (RTL8125BG)
PCIe 2.1: M.2 E-Key x1, PCIe 2.1 x1 and USB2.0 Host, supports M.2 WiFi and 
Bluetooth
4G Module: MiniPCIe x1, MicroSIM Card Slot x1
Audio Out: 3.5mm jack for stereo headphone output
Audio In: 2.0mm PH-2A connector for analog microphone input
Video Input: standard HDMI input port, up to 4Kp60
2x 4-lane MIPI-CSI, compatible with MIPI V1.2
Video Output: 2x standard HDMI output ports compatible with HDMI2.1, 
HDMI2.0, and HDMI1.4
2x 4-lane MIPI-DSI, compatible with MIPI DPHY 2.0 or CPHY 1.1
USB-A: USB 3.0, Type A
USB-C: Full function USB Type‑C port, supports DP display up to 4Kp60, USB 
3.0
40-pin 2.54mm header connector: up to 2x SPIs, 6x UARTs, 1x I2Cs, 8x PWMs, 
2x I2Ss, 28x GPIOs
Debug UART: 3 Pin 2.54mm header, 3V level, 150bps
Onboard IR receiver: 38KHz carrier frequency
RTC Battery: 2 Pin 1.27/1.25mm RTC battery input connector for low power 
RTC IC HYM8563TS
5V Fan connector
Working Temperature: 0C to 70C
Power: 5.5*2.1mm DC Jack, 12VDC input
Dimensions: 110x80x1.6mm (without case) / 86x114.5x30mm (with case)

Kernel commits:
893c17716d0c ("arm64: dts: rockchip: Add NanoPC T6")
a721e28dfad2 ("arm64: dts: rockchip: Add NanoPC T6 PCIe Ethernet support")
ac76b786cc37 ("arm64: dts: rockchip: Add NanoPC T6 PCIe e-key support")

Signed-off-by: John Clark 
---

 arch/arm/dts/Makefile |   1 +
 arch/arm/dts/rk3588-nanopc-t6-u-boot.dtsi |  36 +
 arch/arm/dts/rk3588-nanopc-t6.dts | 916 ++
 arch/arm/mach-rockchip/rk3588/rk3588.c|   1 +
 configs/nanopc-t6-rk3588_defconfig| 113 +++
 5 files changed, 1067 insertions(+)
 create mode 100644 arch/arm/dts/rk3588-nanopc-t6-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3588-nanopc-t6.dts
 create mode 100644 configs/nanopc-t6-rk3588_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index bde2176ec7..6a4335cf9c 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -189,6 +189,7 @@ dtb-$(CONFIG_ROCKCHIP_RK3588) += \
rk3588-edgeble-neu6a-io.dtb \
rk3588-edgeble-neu6b-io.dtb \
rk3588-evb1-v10.dtb \
+   rk3588-nanopc-t6.dtb \
rk3588s-rock-5a.dtb \
rk3588-rock-5b.dtb
 
diff --git a/arch/arm/dts/rk3588-nanopc-t6-u-boot.dtsi 
b/arch/arm/dts/rk3588-nanopc-t6-u-boot.dtsi
new file mode 100644
index 00..87831c9d43
--- /dev/null
+++ b/arch/arm/dts/rk3588-nanopc-t6-u-boot.dtsi
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2023 John Clark 
+ *
+ */
+
+#include "rk3588-u-boot.dtsi"
+
+/ {
+   chosen {
+   u-boot,spl-boot-order = "same-as-spl", &sdmmc, &sdhci;
+   };
+};
+
+&fspim1_pins {
+   bootph-all;
+};
+
+&sfc {
+   bootph-pre-ram;
+   u-boot,spl-sfc-no-dma;
+   pinctrl-names = "default";
+   pinctrl-0 = <&fspim1_pins>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   status = "okay";
+
+   flash@0 {
+   bootph-pre-ram;
+   compatible = "jedec,spi-nor";
+   reg = <0>;
+   spi-max-frequency = <2400>;
+   spi-rx-bus-width = <4>;
+   spi-tx-bus-width = <1>;
+   };
+};
diff --git a/arch/arm/dts/rk3588-nanopc-t6.dts 
b/arch/arm/dts/rk3588-nanopc-t6.dts
new file mode 100644
index 00..965bf5263d
--- /dev/null
+++ b/arch/arm/dts/rk3588-nanopc-t6.dts
@@ -0,0 +1,916 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
+ * Copyright (c) 2023 Thomas McKahan
+ *
+ */
+
+/dts-v1/;
+
+#include 
+#include 
+#include 
+#include "rk3588.dtsi"
+
+/ {
+   model = "FriendlyElec NanoPC-T6";
+   compatible = "friendlyarm,nanopc-t6", "rockchip,rk3588";
+
+   aliases {
+   mmc0 = &sdhci;
+   mmc1 = &sdmmc;
+   serial2 = &uart2;
+   };
+
+   chosen {
+   stdout-path = "serial2:150n8";
+   };
+
+   sound {
+   compatible = "simple-audio-card";
+   pinctrl-names = "default";
+   pinctrl-0 = <&hp_det>;
+
+   simple-audio-card,name = "realtek,rt5616-codec";
+   simple-audio-card,format = "i2s";
+

Re: [PATCH] doc: Migrate Renesas board docs to rst

2023-10-07 Thread Marek Vasut

On 10/5/23 19:07, Paul Barker wrote:

[...]


+   * - R-Car Gen3
+ - Salvator-X


Salvator-X(S)


+ - R8A77950 (H3)


These ones are actually not 77950, but 77951 , all of them.


+ - arm64
+ - ``rcar3_salvator-x_defconfig``
+
+   * -
+ - ULCB
+ - R8A77950 (H3)


DTTO


+ - arm64
+ - ``rcar3_ulcb_defconfig``
+
+   * -
+ - Salvator-X
+ - R8A77960 (M3-W)
+ - arm64
+ - ``rcar3_salvator-x_defconfig``
+
+   * -
+ - ULCB
+ - R8A77960 (M3-W)
+ - arm64
+ - ``rcar3_ulcb_defconfig``
+
+   * -
+ - Salvator-X
+ - R8A77965 (M3-N)
+ - arm64
+ - ``rcar3_salvator-x_defconfig``
+
+   * -
+ - ULCB
+ - R8A77965 (M3-N)
+ - arm64
+ - ``rcar3_ulcb_defconfig``
+
+   * -
+ - Eagle
+ - R8A77970 (V3M)
+ - arm64
+ - ``r8a77970_eagle_defconfig``
+
+   * -
+ - V3MSK
+ - R8A77970 (V3M)
+ - arm64
+ - ``r8a77970_v3msk_defconfig``
+
+   * -
+ - Condor
+ - R8A77980 (V3H)
+ - arm64
+ - ``r8a77980_condor_defconfig``
+
+   * -
+ - V3MSK


V3HSK


+ - R8A77980 (V3H)
+ - arm64
+ - ``r8a77980_v3hsk_defconfig``
+
+   * -
+ - Ebisu
+ - R8A77990 (E3)
+ - arm64
+ - ``r8a77990_ebisu_defconfig``
+
+   * -
+ - Draak
+ - R8A77995 (D3)
+ - arm64
+ - ``r8a77995_draak_defconfig``
+
+   * - R-Car Gen4
+ - Falcon
+ - R8A779A0 (V3U)
+ - arm64
+ - ``r8a779a0_falcon_defconfig``
+
+   * -
+ - Spider
+ - R8A779F0 (S4)
+ - arm64
+ - ``r8a779f0_spider_defconfig``
+
+   * -
+ - Whitehawk


White Hawk


+ - R8A779G0 (V4H)
+ - arm64
+ - ``r8a779g0_whitehawk_defconfig``


[...]

Looks good otherwise, thanks !


Re: [PATCH 16/16] board: rzg2l: Add RZ/G2L SMARC EVK board

2023-10-07 Thread Marek Vasut

On 10/6/23 14:51, Biju Das wrote:

Hi Paul,


Subject: Re: [PATCH 16/16] board: rzg2l: Add RZ/G2L SMARC EVK board

On 03/10/2023 14:36, Marek Vasut wrote:

On 9/20/23 14:42, Paul Barker wrote:

The Renesas RZ/G2L SMARC Evaluation Board Kit consists of the RZ/G2L
System-on-Module (SOM) based on the R9A07G044L2 SoC, and a common
SMARC carrier board.

The ARM TrustedFirmware code for the Renesas RZ/G2L SoC family passes
a devicetree blob to the bootloader as an argument in the same was
previous R-Car gen3/gen4 SoCs. This blob contains a compatible string
which can be used to identify the particular SoC we are running on
and this is used to select the appropriate device tree to load.

The configuration renesas_rzg2l_smarc_defconfig is added to support
building for this target. In the future this defconfig will be
extended to support other SoCs and evaluation boards from the RZ/G2L

family.


Signed-off-by: Paul Barker 
Reviewed-by: Biju Das 
Reviewed-by: Lad Prabhakar 
---
   arch/arm/mach-rmobile/Kconfig.rzg2l   | 14 +
   board/renesas/rzg2l/Kconfig   | 18 +++
   board/renesas/rzg2l/MAINTAINERS   |  6 +++
   board/renesas/rzg2l/Makefile  |  4 ++
   board/renesas/rzg2l/rzg2l.c   | 76 +++
   configs/renesas_rzg2l_smarc_defconfig | 52 ++
   include/configs/rzg2l-smarc.h | 14 +
   7 files changed, 184 insertions(+)
   create mode 100644 board/renesas/rzg2l/Kconfig
   create mode 100644 board/renesas/rzg2l/MAINTAINERS
   create mode 100644 board/renesas/rzg2l/Makefile
   create mode 100644 board/renesas/rzg2l/rzg2l.c
   create mode 100644 configs/renesas_rzg2l_smarc_defconfig
   create mode 100644 include/configs/rzg2l-smarc.h

diff --git a/arch/arm/mach-rmobile/Kconfig.rzg2l
b/arch/arm/mach-rmobile/Kconfig.rzg2l
index 7d268e8c366a..1fe49e323300 100644
--- a/arch/arm/mach-rmobile/Kconfig.rzg2l
+++ b/arch/arm/mach-rmobile/Kconfig.rzg2l
@@ -9,6 +9,20 @@ config R9A07G044L
help
  Enable support for the R9A07G044L SoC used in the RZ/G2L.

+choice
+   prompt "Renesas RZ/G2L Family Board selection"
+   default TARGET_RZG2L_SMARC_EVK
+
+config TARGET_RZG2L_SMARC_EVK
+   bool "Renesas RZ/G2L SMARC EVK"
+   imply R9A07G044L
+   help
+ Enable support for the RZ/G2L SMARC evaluation board.
+
+source "board/renesas/rzg2l/Kconfig"
+
+endchoice
+
   config MULTI_DTB_FIT_UNCOMPRESS_SZ
default 0x8 if TARGET_RZG2L_SMARC_EVK

diff --git a/board/renesas/rzg2l/Kconfig
b/board/renesas/rzg2l/Kconfig new file mode 100644 index
..1335fc7ae806
--- /dev/null
+++ b/board/renesas/rzg2l/Kconfig
@@ -0,0 +1,18 @@
+# Copyright (C) 2023 Renesas Electronics Corporation #
+SPDX-License-Identifier: GPL-2.0+
+
+if TARGET_RZG2L_SMARC_EVK
+
+config SYS_SOC
+   default "rmobile"
+
+config SYS_BOARD
+   default "rzg2l"
+
+config SYS_VENDOR
+   default "renesas"
+
+config SYS_CONFIG_NAME
+   default "rzg2l-smarc"
+
+endif
diff --git a/board/renesas/rzg2l/MAINTAINERS
b/board/renesas/rzg2l/MAINTAINERS new file mode 100644 index
..0a51391c1fc9
--- /dev/null
+++ b/board/renesas/rzg2l/MAINTAINERS
@@ -0,0 +1,6 @@
+RENESAS RZG2L BOARD FAMILY
+M: Paul Barker 
+S: Supported
+F: arch/arm/dts/rz-smarc-common.dtsi


I suspect there should be more files here, right ?
You likely want to be CCed on things like rzg2l clock, scif, and so on.


+N: rzg2l
+N: r9a07g044
diff --git a/board/renesas/rzg2l/Makefile
b/board/renesas/rzg2l/Makefile new file mode 100644 index
..466935fc8158
--- /dev/null
+++ b/board/renesas/rzg2l/Makefile
@@ -0,0 +1,4 @@
+# Copyright (C) 2023 Renesas Electronics Corporation #
+SPDX-License-Identifier: GPL-2.0+
+
+obj-y  := rzg2l.o



diff --git a/board/renesas/rzg2l/rzg2l.c
b/board/renesas/rzg2l/rzg2l.c new file mode 100644 index
..2b1bb3546c26
--- /dev/null
+++ b/board/renesas/rzg2l/rzg2l.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * RZ/G2L board support.
+ * Copyright (C) 2023 Renesas Electronics Corporation  */
+
+#include 
+#include 
+#include 
+
+#if IS_ENABLED(CONFIG_MULTI_DTB_FIT)
+/* If the firmware passed a device tree, use it for board
+identification. */ extern u64 rcar_atf_boot_args[];
+
+static bool is_rzg2l_board(const char *board_name) {
+   void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
+
+   return fdt_node_check_compatible(atf_fdt_blob, 0, board_name) == 0;
+}
+
+int board_fit_config_name_match(const char *name) {
+   void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
+
+   if (fdt_magic(atf_fdt_blob) != FDT_MAGIC)
+   return -1;
+
+   if (is_rzg2l_board("renesas,r9a07g044l2"))
+   return strcmp(name, "r9a07g044l2-smarc");
+
+   return -1;
+}
+#endif
+
+static void apply_atf_overlay(void *fdt_blob) {
+   void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
+
+   if (fdt_magic(atf_fdt_blob) == FDT_MAGIC)
+   fdt_

Re: [PATCH 16/16] board: rzg2l: Add RZ/G2L SMARC EVK board

2023-10-07 Thread Marek Vasut

On 10/5/23 22:50, Paul Barker wrote:

On 03/10/2023 14:36, Marek Vasut wrote:

On 9/20/23 14:42, Paul Barker wrote:

The Renesas RZ/G2L SMARC Evaluation Board Kit consists of the RZ/G2L
System-on-Module (SOM) based on the R9A07G044L2 SoC, and a common SMARC
carrier board.

The ARM TrustedFirmware code for the Renesas RZ/G2L SoC family passes a
devicetree blob to the bootloader as an argument in the same was
previous R-Car gen3/gen4 SoCs. This blob contains a compatible string
which can be used to identify the particular SoC we are running on and
this is used to select the appropriate device tree to load.

The configuration renesas_rzg2l_smarc_defconfig is added to support
building for this target. In the future this defconfig will be extended
to support other SoCs and evaluation boards from the RZ/G2L family.

Signed-off-by: Paul Barker 
Reviewed-by: Biju Das 
Reviewed-by: Lad Prabhakar 
---
   arch/arm/mach-rmobile/Kconfig.rzg2l   | 14 +
   board/renesas/rzg2l/Kconfig   | 18 +++
   board/renesas/rzg2l/MAINTAINERS   |  6 +++
   board/renesas/rzg2l/Makefile  |  4 ++
   board/renesas/rzg2l/rzg2l.c   | 76 +++
   configs/renesas_rzg2l_smarc_defconfig | 52 ++
   include/configs/rzg2l-smarc.h | 14 +
   7 files changed, 184 insertions(+)
   create mode 100644 board/renesas/rzg2l/Kconfig
   create mode 100644 board/renesas/rzg2l/MAINTAINERS
   create mode 100644 board/renesas/rzg2l/Makefile
   create mode 100644 board/renesas/rzg2l/rzg2l.c
   create mode 100644 configs/renesas_rzg2l_smarc_defconfig
   create mode 100644 include/configs/rzg2l-smarc.h

diff --git a/arch/arm/mach-rmobile/Kconfig.rzg2l 
b/arch/arm/mach-rmobile/Kconfig.rzg2l
index 7d268e8c366a..1fe49e323300 100644
--- a/arch/arm/mach-rmobile/Kconfig.rzg2l
+++ b/arch/arm/mach-rmobile/Kconfig.rzg2l
@@ -9,6 +9,20 @@ config R9A07G044L
help
  Enable support for the R9A07G044L SoC used in the RZ/G2L.
   
+choice

+   prompt "Renesas RZ/G2L Family Board selection"
+   default TARGET_RZG2L_SMARC_EVK
+
+config TARGET_RZG2L_SMARC_EVK
+   bool "Renesas RZ/G2L SMARC EVK"
+   imply R9A07G044L
+   help
+ Enable support for the RZ/G2L SMARC evaluation board.
+
+source "board/renesas/rzg2l/Kconfig"
+
+endchoice
+
   config MULTI_DTB_FIT_UNCOMPRESS_SZ
default 0x8 if TARGET_RZG2L_SMARC_EVK
   
diff --git a/board/renesas/rzg2l/Kconfig b/board/renesas/rzg2l/Kconfig

new file mode 100644
index ..1335fc7ae806
--- /dev/null
+++ b/board/renesas/rzg2l/Kconfig
@@ -0,0 +1,18 @@
+# Copyright (C) 2023 Renesas Electronics Corporation
+# SPDX-License-Identifier: GPL-2.0+
+
+if TARGET_RZG2L_SMARC_EVK
+
+config SYS_SOC
+   default "rmobile"
+
+config SYS_BOARD
+   default "rzg2l"
+
+config SYS_VENDOR
+   default "renesas"
+
+config SYS_CONFIG_NAME
+   default "rzg2l-smarc"
+
+endif
diff --git a/board/renesas/rzg2l/MAINTAINERS b/board/renesas/rzg2l/MAINTAINERS
new file mode 100644
index ..0a51391c1fc9
--- /dev/null
+++ b/board/renesas/rzg2l/MAINTAINERS
@@ -0,0 +1,6 @@
+RENESAS RZG2L BOARD FAMILY
+M: Paul Barker 
+S: Supported
+F: arch/arm/dts/rz-smarc-common.dtsi


I suspect there should be more files here, right ?
You likely want to be CCed on things like rzg2l clock, scif, and so on.


+N: rzg2l
+N: r9a07g044
diff --git a/board/renesas/rzg2l/Makefile b/board/renesas/rzg2l/Makefile
new file mode 100644
index ..466935fc8158
--- /dev/null
+++ b/board/renesas/rzg2l/Makefile
@@ -0,0 +1,4 @@
+# Copyright (C) 2023 Renesas Electronics Corporation
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-y  := rzg2l.o



diff --git a/board/renesas/rzg2l/rzg2l.c b/board/renesas/rzg2l/rzg2l.c
new file mode 100644
index ..2b1bb3546c26
--- /dev/null
+++ b/board/renesas/rzg2l/rzg2l.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * RZ/G2L board support.
+ * Copyright (C) 2023 Renesas Electronics Corporation
+ */
+
+#include 
+#include 
+#include 
+
+#if IS_ENABLED(CONFIG_MULTI_DTB_FIT)
+/* If the firmware passed a device tree, use it for board identification. */
+extern u64 rcar_atf_boot_args[];
+
+static bool is_rzg2l_board(const char *board_name)
+{
+   void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
+
+   return fdt_node_check_compatible(atf_fdt_blob, 0, board_name) == 0;
+}
+
+int board_fit_config_name_match(const char *name)
+{
+   void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
+
+   if (fdt_magic(atf_fdt_blob) != FDT_MAGIC)
+   return -1;
+
+   if (is_rzg2l_board("renesas,r9a07g044l2"))
+   return strcmp(name, "r9a07g044l2-smarc");
+
+   return -1;
+}
+#endif
+
+static void apply_atf_overlay(void *fdt_blob)
+{
+   void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
+
+   if (fdt_magic(atf_fdt_blob) == FDT_MAGIC)
+   fdt_overlay_apply_node(fdt_blob, 0, atf_fdt_blob, 0);
+}
+
+int fdtdec

Re: [PATCH RESEND v2 2/2] usb: udc: Try to clarify an error message

2023-10-07 Thread Marek Vasut

On 10/5/23 17:51, Miquel Raynal wrote:

Hi Marek,

ma...@denx.de wrote on Thu, 5 Oct 2023 15:04:25 +0200:


On 10/2/23 15:46, Miquel Raynal wrote:

At some point when trying to use USB gadgets, two situations may arise
and lead to a failure. Either the UDC (USB Device Controller) is not
available at all (not described or not probed) or the UDC is already in
use. For instance, as the USB Ethernet gadget remains bound to the UDC,
the use of any other USB gadget (fastboot, dfu, etc) *after* will always
fail with the "couldn't find an available UDC" error.

Let's give a more helpful message by making a difference between the two
cases. Let's also hint people who would get this error and grep it into
the sources a better explanation of what's wrong with their workflow.

Signed-off-by: Miquel Raynal 
---
While doing this I really wanted to add "much more" error comments but I
faced another reality: often the messages are there but use
pr_err/log_err which is actually silenced by default with LOGLEVEL=3, so
I consider this unnecessary, as decreasing the loglevel will make these
messages appear. I would have expected errors to be displayed, but I
understand it makes the binaries even bigger.

Resend: no change.

Changes in v2:
* s/UDC/UDCs/. I kept the sentence as it was as the suggested form did
not sound well at all when there is only one UDC.
---
   drivers/usb/gadget/udc/udc-core.c | 13 -
   1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 7f73926cb3e..8405b03462e 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -323,6 +323,7 @@ err1:
   int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
   {
struct usb_udc  *udc = NULL;
+   unsigned intudc_count = 0;
int ret;
   > if (!driver || !driver->bind || !driver->setup)
@@ -330,12 +331,22 @@ int usb_gadget_probe_driver(struct usb_gadget_driver 
*driver)
   > mutex_lock(&udc_lock);
list_for_each_entry(udc, &udc_list, list) {
+   udc_count++;
+
/* For now we take the first one */
if (!udc->driver)
goto found;
}
   > -   printf("couldn't find an available UDC\n");
+   if (!udc_count)
+   printf("No UDC available in the system\n");
+   else
+   /* When this happens, users should 'unbind  '
+* using the output of 'dm tree' and looking at the line right
+* after the USB peripheral/device controller.
+*/
+   printf("All UDCs in use (%d available), use the unbind 
command\n",
+  udc_count);


Users should really use 'bind' command in the first place, to avoid this 
guesswork to which UDC (on systems with multiple UDCs) a gadget gets bound to, 
and instead bind the gadget to specific UDC they want to bind it to. This code 
should then be removed entirely.


There are two cases when this can happen:
* a single UDC (common) but a function already bound, there is no
   guessing here
* two (or more) UDC and there is some guessing

Before your cleanup, drivers would get automatically unbound from the
UDC to let the one being needed to bind.


How did that ever work ?


This is no longer the case,
so there is a change in the CLI and I want to help people facing
this new problem with a slightly more comprehensive message because
people don't fully understand what USB is all about. We cannot
ask all U-Boot USB users to be U-Boot experts and USB experts. This
is just a little help.


In that case, you have to handle the details like CMD_BIND may not be 
enabled, and CMD_DM may not be enabled. But then, maybe what we want to 
do is fix the automatic switching of gadgets to make it work again ?



In an ideal world, we will have the possibility to create
composite gadgets and all this can go away once it is well
integrated, I guess?


I believe you would still have to do a disconnect/connect cycle even 
with a composite driver, you cannot just add functions to existing 
composite at runtime.


Re: [PATCH RESEND v2 1/2] cmd: bind: Try to improve the (un)bind help

2023-10-07 Thread Marek Vasut

On 10/5/23 17:54, Miquel Raynal wrote:

Hi Marek,

ma...@denx.de wrote on Thu, 5 Oct 2023 15:01:51 +0200:


On 10/2/23 15:46, Miquel Raynal wrote:

While it may sound totally obvious for the regular U-Boot developer to
get the parameters of the bind/unbind commands from the output of 'dm
tree', it did not felt straightforward to me until I was explicitly
told to look there. And even when I knew the command, I did not make a
direct link between the arguments of this command and the columns
returned by 'dm tree'.

Several of us lost a lot of time because of that, I would like to kindly
help other users by slightly improving this textual line. Unfortunately,
because of how this string is used (like within the 'help' command) I
cannot detail much more, but at least the pointer is there.

Signed-off-by: Miquel Raynal 
---
Resend: no change.

Changes in v2:
* Moved the details in the long text section as suggested by Heinrich.
* Rephrased the help text as well, not fully following Heinrich
suggestion, but taking inspiration from it.
---
   cmd/bind.c | 4 
   1 file changed, 4 insertions(+)

diff --git a/cmd/bind.c b/cmd/bind.c
index 4d1b7885e60..be0d4d2a711 100644
--- a/cmd/bind.c
+++ b/cmd/bind.c
@@ -246,6 +246,8 @@ U_BOOT_CMD(
"Bind a device to a driver",
" \n"
"bind   \n"
+   "Use 'dm tree' to list all devices registered in the driver model,\n"
+   "their path, class, index and current driver.\n"
   );
   >   U_BOOT_CMD(
@@ -254,4 +256,6 @@ U_BOOT_CMD(
"\n"
"unbind  \n"
"unbind   \n"
+   "Use 'dm tree' to list all devices registered in the driver model,\n"
+   "their path, class, index and current driver.\n"


'dm tree' depends on CMD_DM , you might need some if (IS_ENABLED()) here.


Well, no, and that's my point actually. People need to know that this
command exist and should be used for this purpose. If you only tell
them "use 'dm tree'" conditionally, you loose part of the audience:
people not aware of this command or its usefulness.


If you tell them 'Use "dm tree"' and it prints "no command found" , then 
it's a bug.


You likely want to add 'imply CMD_DM' into CMD_BIND Kconfig to make sure 
CMD_DM is available by default, but also that users can turn it off if 
they really want to.


Re: [PATCH v2 01/17] dm: usb: udc: Factor out plain udevice handler functions

2023-10-07 Thread Marek Vasut

On 10/2/23 15:42, Miquel Raynal wrote:

Hi Marek,

ma...@denx.de wrote on Sat, 30 Sep 2023 23:11:17 +0200:


On 9/27/23 15:59, Miquel Raynal wrote:

Hi Marek,


Hi,


miquel.ray...@bootlin.com wrote on Fri, 22 Sep 2023 12:00:12 +0200:
   

Hi Marek,

I'm answering here as there is no cover letter. Just to let you know
I'm still concerned by the series and want to test it but did not had
the time to do so recently. Hopefully next week.


The series looks good to me and works as well on a Beagle Bone Black
with no visible functional changes regarding the use of the UDC. The
whole series is:

Tested-by: Miquel Raynal 

By the way, following your initial series there have been three
followup patches trying to improve a little bit the doc, one got merged
and two others were delegated to you:
https://patchwork.ozlabs.org/project/uboot/list/?series=367635

They are almost 2 months old now, would you mind acking or merging
them so both your initial USB gadget rework and the additional
(related) doc can be in the same release please?


Can you resend those and CC this mail address ?


Of course!


That said, 1/2 should be in some sort of README instead, and the 'dm tree' 
command depends on CMD_DM=y .


Well, the README is more something which targets the developer IMO,
whereas here I want to target the users. Many people only see U-Boot
through Yocto now (that's a different topic) and the purpose of this
additional text is to help them in finding their way into U-Boot device
model *alone*. It's really short, but I bet it can really help, given
how I felt when I actually understood why you advised to type a couple
of semi-random bind/unbind commands which eventually worked. Anybody not
involved in any DM conversion is likely just not aware of all of that.
Having people finding their own way through the DM means less
complaints/needs for help on the mailing list.


Thinking about it back and forth, I think you've got a point, yes.


The usb_gadget_probe_driver() is code synchronized from kernel, you likely want 
to add any such clarification to usb_gadget_register_driver() .


Actually the kernel functions do have some kind of alternate error
message as well now :-) Clearly different given that this code has been
adapted to U-Boot's DM, but the idea is close. However
usb_gadget_register_driver() is kind of blind regarding the number of
UDCs in the system and if they are already bound or not, so I don't
really see the point in moving the error message there along with all
the logic duplication involved.


That said, the usb_gadget_register_driver() should be reworked into
some new functions, which takes UDC controller *udevice pointer to
avoid this binding heuristics.


Yes, I don't know many boards with two UDCs but it's a clear limitation.


i.MX8M Plus is one such example, Quad I think is another, and pretty 
much anything with more than one DWC3 controller is. The CI HDRC is also 
often present in OTG capable configuration, so a lot of i.MXes are multi 
UDC systems.


Re: [PATCH v3 02/27] moveconfig: Avoid deprecation warning for setDaemon

2023-10-07 Thread Simon Glass
Use the recommended new way of setting a thread to be a daemon.

This avoids a warning:

   DeprecationWarning: setDaemon() is deprecated, set the daemon attribute
  instead

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 03/27] moveconfig: Correct ordering of asteval import

2023-10-07 Thread Simon Glass
This should be after the standard imports. Move it to avoid a lot of
pylint warnings.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 04/27] moveconfig: Drop unused cleanup options

2023-10-07 Thread Simon Glass
Cleaning up the README and config.h files are not needed now, since we
don't have any CONFIG options to convert. Drop this code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 254 +---
 1 file changed, 2 insertions(+), 252 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 07/27] moveconfig: Drop suspicious boards

2023-10-07 Thread Simon Glass
This code isn't needed anymore. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 25 -
 1 file changed, 25 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 08/27] moveconfig: Correct some regular-expression strings

2023-10-07 Thread Simon Glass
Use the 'r' prefix for these strings to avoid pylint warnings.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 05/27] moveconfig: Drop CONFIG-moving code

2023-10-07 Thread Simon Glass
As a step towards cleaning out old code, drop most of the code that moves
CONFIG options to Kconfig. This includes parse_one_config().

Drop the ACTION_... values as well, since they are no-longer used.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 163 ++--
 1 file changed, 19 insertions(+), 144 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 09/27] moveconfig: Correct parameter-type warnings

2023-10-07 Thread Simon Glass
Fix pylint warnings related to parameter types.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 43 ++-
 1 file changed, 22 insertions(+), 21 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 06/27] moveconfig: Drop check_defconfig() and update_dotconfig()

2023-10-07 Thread Simon Glass
These functions are not needed anymore. Drop them.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 62 ++---
 1 file changed, 2 insertions(+), 60 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 11/27] moveconfig: Correct unused variables

2023-10-07 Thread Simon Glass
Fix pylint warnings about unused variables.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 10/27] moveconfig: Use f strings where possible

2023-10-07 Thread Simon Glass
Avoid pylint warnings by using 'f' strings where possible.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 56 ++---
 1 file changed, 28 insertions(+), 28 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 12/27] moveconfig: Correct non-snake variables names

2023-10-07 Thread Simon Glass
Correct some variable names that do not conform to snake case, with the
three-character minimum.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 70 ++---
 1 file changed, 35 insertions(+), 35 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 13/27] moveconfig: Correct use of members not declared in __init__()

2023-10-07 Thread Simon Glass
Fix these pylint warnings.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 4 
 1 file changed, 4 insertions(+)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 15/27] moveconfig: Use an encoding with open()

2023-10-07 Thread Simon Glass
Fix pylint warnings about needing an explicit character encoding.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 20/27] moveconfig: Use u_boot_pylib for terminal colour

2023-10-07 Thread Simon Glass
Use the existing terminal code to handle ANSI colours. Enable colour by
default if the output is going to a terminal.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 92 +++--
 1 file changed, 38 insertions(+), 54 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 14/27] moveconfig: Correct list-comprehension warnings

2023-10-07 Thread Simon Glass
Correct some pylint warnings about needing to use list comprehension.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 18/27] moveconfig: Reduce the amount of output

2023-10-07 Thread Simon Glass
Output a single line in the case where the defconfig only has one line
of output. Show the name without the _defconfig suffix, since that is the
same for all boards.

Use a list for the log so it is easier to process at the end.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/moveconfig.py | 29 +
 1 file changed, 17 insertions(+), 12 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


Re: [PATCH v3 17/27] moveconfig: Only show output when there is a reason

2023-10-07 Thread Simon Glass
There is no point in listing a board if everything went well. It makes it
harder to see the failures, particularly on a fast machine.

Suppress output unless something actually happened.

Drop the 'Syncing by savedefconfig' since this is selected by the -s and
is the same for all boards in this mode.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Fix 'Supress' typo

 tools/moveconfig.py | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

Applied to u-boot-dm, thanks!
Applied to u-boot-dm, thanks!


  1   2   >