Re: [PATCH v2 04/16] treewide: Make arch-specific bootm code depend on BOOTM

2023-12-22 Thread Angelo Dureghello

Hi Simon,

Acked-by: Angelo Dureghello 

On 15/12/23 5:19 AM, Simon Glass wrote:

Allow these functions to be compiled in when CONFIG_BOOTM is enabled,
even if CONFIG_CMD_BOOTM is not.

Signed-off-by: Simon Glass 
---

(no changes since v1)

  arch/arc/lib/Makefile| 2 +-
  arch/arm/lib/Makefile| 2 +-
  arch/m68k/lib/Makefile   | 2 +-
  arch/microblaze/lib/Makefile | 2 +-
  arch/mips/lib/Makefile   | 2 +-
  arch/nios2/lib/Makefile  | 2 +-
  arch/powerpc/lib/Makefile| 2 +-
  arch/riscv/lib/Makefile  | 2 +-
  arch/sandbox/lib/Makefile| 2 +-
  arch/sh/lib/Makefile | 2 +-
  arch/x86/lib/Makefile| 2 +-
  arch/xtensa/lib/Makefile | 2 +-
  12 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/arc/lib/Makefile b/arch/arc/lib/Makefile
index 0eb44bcf33d0..bde1c3d8af3a 100644
--- a/arch/arc/lib/Makefile
+++ b/arch/arc/lib/Makefile
@@ -12,6 +12,6 @@ obj-y += reset.o
  obj-y += ints_low.o
  obj-y += init_helpers.o
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  
  lib-$(CONFIG_USE_PRIVATE_LIBGCC) += _millicodethunk.o libgcc2.o

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index b1bcd3746625..b20a467f684c 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -31,7 +31,7 @@ endif
  obj-$(CONFIG_CPU_V7M) += cmd_boot.o
  obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
  obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o
-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_BOOTZ) += bootm.o zimage.o
  else
  obj-$(CONFIG_$(SPL_TPL_)FRAMEWORK) += spl.o
diff --git a/arch/m68k/lib/Makefile b/arch/m68k/lib/Makefile
index 6e1fd938f526..5ccd9545cb5c 100644
--- a/arch/m68k/lib/Makefile
+++ b/arch/m68k/lib/Makefile
@@ -8,7 +8,7 @@
  lib-$(CONFIG_USE_PRIVATE_LIBGCC) += lshrdi3.o muldi3.o ashldi3.o ashrdi3.o
  
  obj-y	+= bdinfo.o

-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-y += cache.o
  obj-y += interrupts.o
  obj-y += time.o
diff --git a/arch/microblaze/lib/Makefile b/arch/microblaze/lib/Makefile
index dfd8135f4f25..2f234825f804 100644
--- a/arch/microblaze/lib/Makefile
+++ b/arch/microblaze/lib/Makefile
@@ -3,6 +3,6 @@
  # (C) Copyright 2003-2006
  # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_BDI) += bdinfo.o
  obj-y += muldi3.o
diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile
index 9ee1fcb5c702..f8e162c53b58 100644
--- a/arch/mips/lib/Makefile
+++ b/arch/mips/lib/Makefile
@@ -10,7 +10,7 @@ obj-y += reloc.o
  obj-y += stack.o
  obj-y += traps.o
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_GO) += boot.o
  obj-$(CONFIG_SPL_BUILD) += spl.o
  
diff --git a/arch/nios2/lib/Makefile b/arch/nios2/lib/Makefile

index a9f3c7100e72..68a5ca007d55 100644
--- a/arch/nios2/lib/Makefile
+++ b/arch/nios2/lib/Makefile
@@ -4,5 +4,5 @@
  # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
  
  obj-y	+= cache.o

-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-y += libgcc.o
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index bb819dcbb6cc..dcce9834927d 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -34,7 +34,7 @@ obj-y += ticks.o
  endif
  obj-y += reloc.o
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  obj-y += cache.o
  obj-y += extable.o
  obj-y += interrupts.o
diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index 9a05b662fd63..0b2c88db6bad 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -6,7 +6,7 @@
  # Copyright (C) 2017 Andes Technology Corporation
  # Rick Chen, Andes Technology Corporation 
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o
  obj-$(CONFIG_CMD_GO) += boot.o
  obj-y += cache.o
diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile
index a2bc5a7ee60f..c4924b23c832 100644
--- a/arch/sandbox/lib/Makefile
+++ b/arch/sandbox/lib/Makefile
@@ -7,5 +7,5 @@
  
  obj-y	+= fdt_fixup.o interrupts.o sections.o

  obj-$(CONFIG_PCI) += pci_io.o
-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_BOOTZ) += bootm.o
diff --git a/arch/sh/lib/Makefile b/arch/sh/lib/Makefile
index e7520a328d54..8c3c30293a3c 100644
--- a/arch/sh/lib/Makefile
+++ b/arch/sh/lib/Makefile
@@ -6,7 +6,7 @@
  extra-y   += start.o
  
  obj-y	+= board.o

-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-y += time.o
  obj-$(CONFIG_CMD_SH_ZIMAGEBOOT) += zimageboot.o
  
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile

index 8fc35e1b51ea..94aa335ede4c 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -16,7 +16,7 @@ obj-$(CONFIG_X86_32BIT_INIT) += string.o
  endif
  
  ifndef CONFIG_SPL_BUILD

-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONF

Re: [PATCH 04/14] treewide: Make arch-specific bootm code depend on BOOTM

2023-12-22 Thread Angelo Dureghello

Hi Simon,

Acked-by: Angelo Dureghello 

On 04/12/23 1:31 AM, Simon Glass wrote:

Allow these functions to be compiled in when CONFIG_BOOTM is enabled,
even if CONFIG_CMD_BOOTM is not.

Signed-off-by: Simon Glass 
---

  arch/arc/lib/Makefile| 2 +-
  arch/arm/lib/Makefile| 2 +-
  arch/m68k/lib/Makefile   | 2 +-
  arch/microblaze/lib/Makefile | 2 +-
  arch/mips/lib/Makefile   | 2 +-
  arch/nios2/lib/Makefile  | 2 +-
  arch/powerpc/lib/Makefile| 2 +-
  arch/riscv/lib/Makefile  | 2 +-
  arch/sandbox/lib/Makefile| 2 +-
  arch/sh/lib/Makefile | 2 +-
  arch/x86/lib/Makefile| 2 +-
  arch/xtensa/lib/Makefile | 2 +-
  12 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/arc/lib/Makefile b/arch/arc/lib/Makefile
index 0eb44bcf33d0..bde1c3d8af3a 100644
--- a/arch/arc/lib/Makefile
+++ b/arch/arc/lib/Makefile
@@ -12,6 +12,6 @@ obj-y += reset.o
  obj-y += ints_low.o
  obj-y += init_helpers.o
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  
  lib-$(CONFIG_USE_PRIVATE_LIBGCC) += _millicodethunk.o libgcc2.o

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index b1bcd3746625..b20a467f684c 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -31,7 +31,7 @@ endif
  obj-$(CONFIG_CPU_V7M) += cmd_boot.o
  obj-$(CONFIG_OF_LIBFDT) += bootm-fdt.o
  obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o
-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_BOOTZ) += bootm.o zimage.o
  else
  obj-$(CONFIG_$(SPL_TPL_)FRAMEWORK) += spl.o
diff --git a/arch/m68k/lib/Makefile b/arch/m68k/lib/Makefile
index 6e1fd938f526..5ccd9545cb5c 100644
--- a/arch/m68k/lib/Makefile
+++ b/arch/m68k/lib/Makefile
@@ -8,7 +8,7 @@
  lib-$(CONFIG_USE_PRIVATE_LIBGCC) += lshrdi3.o muldi3.o ashldi3.o ashrdi3.o
  
  obj-y	+= bdinfo.o

-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-y += cache.o
  obj-y += interrupts.o
  obj-y += time.o
diff --git a/arch/microblaze/lib/Makefile b/arch/microblaze/lib/Makefile
index dfd8135f4f25..2f234825f804 100644
--- a/arch/microblaze/lib/Makefile
+++ b/arch/microblaze/lib/Makefile
@@ -3,6 +3,6 @@
  # (C) Copyright 2003-2006
  # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_BDI) += bdinfo.o
  obj-y += muldi3.o
diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile
index 9ee1fcb5c702..f8e162c53b58 100644
--- a/arch/mips/lib/Makefile
+++ b/arch/mips/lib/Makefile
@@ -10,7 +10,7 @@ obj-y += reloc.o
  obj-y += stack.o
  obj-y += traps.o
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_GO) += boot.o
  obj-$(CONFIG_SPL_BUILD) += spl.o
  
diff --git a/arch/nios2/lib/Makefile b/arch/nios2/lib/Makefile

index a9f3c7100e72..68a5ca007d55 100644
--- a/arch/nios2/lib/Makefile
+++ b/arch/nios2/lib/Makefile
@@ -4,5 +4,5 @@
  # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
  
  obj-y	+= cache.o

-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-y += libgcc.o
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index bb819dcbb6cc..dcce9834927d 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -34,7 +34,7 @@ obj-y += ticks.o
  endif
  obj-y += reloc.o
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  obj-y += cache.o
  obj-y += extable.o
  obj-y += interrupts.o
diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index 9a05b662fd63..0b2c88db6bad 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -6,7 +6,7 @@
  # Copyright (C) 2017 Andes Technology Corporation
  # Rick Chen, Andes Technology Corporation 
  
-obj-$(CONFIG_CMD_BOOTM) += bootm.o

+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_BOOTI) += bootm.o image.o
  obj-$(CONFIG_CMD_GO) += boot.o
  obj-y += cache.o
diff --git a/arch/sandbox/lib/Makefile b/arch/sandbox/lib/Makefile
index a2bc5a7ee60f..c4924b23c832 100644
--- a/arch/sandbox/lib/Makefile
+++ b/arch/sandbox/lib/Makefile
@@ -7,5 +7,5 @@
  
  obj-y	+= fdt_fixup.o interrupts.o sections.o

  obj-$(CONFIG_PCI) += pci_io.o
-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-$(CONFIG_CMD_BOOTZ) += bootm.o
diff --git a/arch/sh/lib/Makefile b/arch/sh/lib/Makefile
index e7520a328d54..8c3c30293a3c 100644
--- a/arch/sh/lib/Makefile
+++ b/arch/sh/lib/Makefile
@@ -6,7 +6,7 @@
  extra-y   += start.o
  
  obj-y	+= board.o

-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  obj-y += time.o
  obj-$(CONFIG_CMD_SH_ZIMAGEBOOT) += zimageboot.o
  
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile

index 8fc35e1b51ea..94aa335ede4c 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -16,7 +16,7 @@ obj-$(CONFIG_X86_32BIT_INIT) += string.o
  endif
  
  ifndef CONFIG_SPL_BUILD

-obj-$(CONFIG_CMD_BOOTM) += bootm.o
+obj-$(CONFIG_BOOTM) += bootm.o
  

[PATCH v1] Kconfig: boot: Imply BOOTSTD_DEFAULT when BOOTSTD_FULL=y

2023-12-22 Thread Shantur Rathore
We need BOOTSTD_DEFAULT when BOOTSTD_FULL is selected.

Signed-off-by: Shantur Rathore 
---

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

diff --git a/boot/Kconfig b/boot/Kconfig
index 9f5b8a0cb2..fc96aadb27 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -426,6 +426,7 @@ config VPL_BOOTSTD
 config BOOTSTD_FULL
bool "Enhanced features for standard boot"
default y if SANDBOX
+   imply BOOTSTD_DEFAULTS
help
  This enables various useful features for standard boot, which are not
  essential for operation:
-- 
2.40.1



[PATCH] board: rockchip: Add support for FriendlyARM NanoPi R2C Plus

2023-12-22 Thread Tianling Shen
The NanoPi R2C Plus is a small variant of NanoPi R2C with a on-board
eMMC flash (8G) included.

The device tree is taken from the kernel v6.5.

Signed-off-by: Tianling Shen 
---
 arch/arm/dts/Makefile |   1 +
 .../dts/rk3328-nanopi-r2c-plus-u-boot.dtsi|   9 ++
 arch/arm/dts/rk3328-nanopi-r2c-plus.dts   |  33 +
 board/rockchip/evb_rk3328/MAINTAINERS |   6 +
 configs/nanopi-r2c-plus-rk3328_defconfig  | 114 ++
 5 files changed, 163 insertions(+)
 create mode 100644 arch/arm/dts/rk3328-nanopi-r2c-plus-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3328-nanopi-r2c-plus.dts
 create mode 100644 configs/nanopi-r2c-plus-rk3328_defconfig

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 9d28a485bec..6909f95e084 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -126,6 +126,7 @@ dtb-$(CONFIG_ROCKCHIP_RK3308) += \
 dtb-$(CONFIG_ROCKCHIP_RK3328) += \
rk3328-evb.dtb \
rk3328-nanopi-r2c.dtb \
+   rk3328-nanopi-r2c-plus.dtb \
rk3328-nanopi-r2s.dtb \
rk3328-orangepi-r1-plus.dtb \
rk3328-orangepi-r1-plus-lts.dtb \
diff --git a/arch/arm/dts/rk3328-nanopi-r2c-plus-u-boot.dtsi 
b/arch/arm/dts/rk3328-nanopi-r2c-plus-u-boot.dtsi
new file mode 100644
index 000..f8adb9e5e1f
--- /dev/null
+++ b/arch/arm/dts/rk3328-nanopi-r2c-plus-u-boot.dtsi
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "rk3328-nanopi-r2c-u-boot.dtsi"
+
+/ {
+   chosen {
+   u-boot,spl-boot-order = "same-as-spl", &sdmmc, &emmc;
+   };
+};
diff --git a/arch/arm/dts/rk3328-nanopi-r2c-plus.dts 
b/arch/arm/dts/rk3328-nanopi-r2c-plus.dts
new file mode 100644
index 000..16a1958e457
--- /dev/null
+++ b/arch/arm/dts/rk3328-nanopi-r2c-plus.dts
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+/*
+ * Copyright (c) 2021 FriendlyElec Computer Tech. Co., Ltd.
+ * (http://www.friendlyarm.com)
+ *
+ * Copyright (c) 2023 Tianling Shen 
+ */
+
+/dts-v1/;
+#include "rk3328-nanopi-r2c.dts"
+
+/ {
+   model = "FriendlyElec NanoPi R2C Plus";
+   compatible = "friendlyarm,nanopi-r2c-plus", "rockchip,rk3328";
+
+   aliases {
+   mmc1 = &emmc;
+   };
+};
+
+&emmc {
+   bus-width = <8>;
+   cap-mmc-highspeed;
+   max-frequency = <15000>;
+   mmc-ddr-1_8v;
+   mmc-hs200-1_8v;
+   non-removable;
+   pinctrl-names = "default";
+   pinctrl-0 = <&emmc_clk &emmc_cmd &emmc_bus8>;
+   vmmc-supply = <&vcc_io_33>;
+   vqmmc-supply = <&vcc18_emmc>;
+   status = "okay";
+};
diff --git a/board/rockchip/evb_rk3328/MAINTAINERS 
b/board/rockchip/evb_rk3328/MAINTAINERS
index 8a19eb373d0..5fc114a63f6 100644
--- a/board/rockchip/evb_rk3328/MAINTAINERS
+++ b/board/rockchip/evb_rk3328/MAINTAINERS
@@ -11,6 +11,12 @@ S:  Maintained
 F:  configs/nanopi-r2c-rk3328_defconfig
 F:  arch/arm/dts/rk3328-nanopi-r2c-u-boot.dtsi
 
+NANOPI-R2C-PLUS-RK3328
+M:  Tianling Shen 
+S:  Maintained
+F:  configs/nanopi-r2c-plus-rk3328_defconfig
+F:  arch/arm/dts/rk3328-nanopi-r2c-plus-u-boot.dtsi
+
 NANOPI-R2S-RK3328
 M:  David Bauer 
 S:  Maintained
diff --git a/configs/nanopi-r2c-plus-rk3328_defconfig 
b/configs/nanopi-r2c-plus-rk3328_defconfig
new file mode 100644
index 000..320ed8b434a
--- /dev/null
+++ b/configs/nanopi-r2c-plus-rk3328_defconfig
@@ -0,0 +1,114 @@
+CONFIG_ARM=y
+CONFIG_SKIP_LOWLEVEL_INIT=y
+CONFIG_COUNTER_FREQUENCY=2400
+CONFIG_ARCH_ROCKCHIP=y
+CONFIG_TEXT_BASE=0x0020
+CONFIG_SPL_GPIO=y
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
+CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x30
+CONFIG_SF_DEFAULT_SPEED=2000
+CONFIG_ENV_OFFSET=0x3F8000
+CONFIG_DEFAULT_DEVICE_TREE="rk3328-nanopi-r2c-plus"
+CONFIG_DM_RESET=y
+CONFIG_ROCKCHIP_RK3328=y
+CONFIG_TPL_ROCKCHIP_COMMON_BOARD=y
+CONFIG_TPL_LIBCOMMON_SUPPORT=y
+CONFIG_TPL_LIBGENERIC_SUPPORT=y
+CONFIG_SPL_DRIVERS_MISC=y
+CONFIG_SPL_STACK_R_ADDR=0x60
+CONFIG_SPL_STACK=0x40
+CONFIG_TPL_SYS_MALLOC_F_LEN=0x800
+CONFIG_DEBUG_UART_BASE=0xFF13
+CONFIG_DEBUG_UART_CLOCK=2400
+CONFIG_SYS_LOAD_ADDR=0x800800
+CONFIG_DEBUG_UART=y
+# CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_SPL_LOAD_FIT=y
+CONFIG_DEFAULT_FDT_FILE="rockchip/rk3328-nanopi-r2c-plus.dtb"
+# CONFIG_DISPLAY_CPUINFO is not set
+CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_MISC_INIT_R=y
+CONFIG_SPL_MAX_SIZE=0x4
+CONFIG_SPL_PAD_TO=0x7f8000
+CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
+CONFIG_SPL_BSS_START_ADDR=0x200
+CONFIG_SPL_BSS_MAX_SIZE=0x2000
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
+CONFIG_SPL_STACK_R=y
+CONFIG_SPL_I2C=y
+CONFIG_SPL_POWER=y
+CONFIG_SPL_ATF=y
+CONFIG_SPL_ATF_NO_PLATFORM_PARAM=y
+CONFIG_TPL_SYS_MALLOC_SIMPLE=y
+CONFIG_CMD_BOOTZ=y
+CONFIG_CMD_GPT=y
+CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_TIME=y
+CONFIG_SPL_OF_CONTROL

[PATCH v2 1/1] lib: smbios: remove redundant next_header()

2023-12-22 Thread Heinrich Schuchardt
next_header() and get_next_header() only differ in how the const attribute
is used. One function taking a const parameter and returning a non-const is
good enough.

Signed-off-by: Heinrich Schuchardt 
Reviewed-by: Ilias Apalodimas 
---
v2:
remove Fixes tag as the code redundancy is not an actual bug
---
 lib/smbios-parser.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c
index b578c30840..f4de350e6e 100644
--- a/lib/smbios-parser.c
+++ b/lib/smbios-parser.c
@@ -50,14 +50,7 @@ static u8 *find_next_header(u8 *pos)
return pos;
 }

-static struct smbios_header *get_next_header(struct smbios_header *curr)
-{
-   u8 *pos = ((u8 *)curr) + curr->length;
-
-   return (struct smbios_header *)find_next_header(pos);
-}
-
-static const struct smbios_header *next_header(const struct smbios_header 
*curr)
+static struct smbios_header *get_next_header(const struct smbios_header *curr)
 {
u8 *pos = ((u8 *)curr) + curr->length;

@@ -73,7 +66,7 @@ const struct smbios_header *smbios_header(const struct 
smbios_entry *entry, int
if (header->type == type)
return header;

-   header = next_header(header);
+   header = get_next_header(header);
}

return NULL;
--
2.43.0



[PATCH v2 2/2] smbios: copy QEMU tables

2023-12-22 Thread Heinrich Schuchardt
From: Heinrich Schuchardt 

QEMU provides SMBIOS tables with detailed information. We should not try to
replicate them in U-Boot.

If we want to inform about U-Boot, we can add a Firmware Inventory
Information (type 45) table in future.

Signed-off-by: Heinrich Schuchardt 
---
v2:
fix parsing of SMBIOS anchor
enable copying on x86 and 32bit ARM/RISC-V
---
 arch/x86/lib/tables.c   |   2 +-
 drivers/misc/Kconfig|   7 ++
 drivers/misc/Makefile   |   1 +
 drivers/misc/qfw_smbios.c   | 197 
 lib/efi_loader/efi_smbios.c |   4 +-
 5 files changed, 209 insertions(+), 2 deletions(-)
 create mode 100644 drivers/misc/qfw_smbios.c

diff --git a/arch/x86/lib/tables.c b/arch/x86/lib/tables.c
index 5b5070f7ca..914d9de0cb 100644
--- a/arch/x86/lib/tables.c
+++ b/arch/x86/lib/tables.c
@@ -61,7 +61,7 @@ static struct table_info table_list[] = {
 #ifdef CONFIG_GENERATE_ACPI_TABLE
{ "acpi", write_acpi_tables, BLOBLISTT_ACPI_TABLES, 0x1, 0x1000},
 #endif
-#ifdef CONFIG_GENERATE_SMBIOS_TABLE
+#if defined(CONFIG_GENERATE_SMBIOS_TABLE) && !defined(CONFIG_QFW_SMBIOS)
{ "smbios", write_smbios_table, BLOBLISTT_SMBIOS_TABLES, 0x1000, 0x100},
 #endif
 };
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index e8e4400516..d2536c54e0 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -561,6 +561,13 @@ config QFW_MMIO
  Hidden option to enable MMIO QEMU fw_cfg interface. This will be
  selected by the appropriate QEMU board.

+config QFW_SMBIOS
+   bool
+   default y
+   depends on QFW && SMBIOS && !SANDBOX
+   help
+ Hidden option to read SMBIOS tables from QEMU.
+
 config I2C_EEPROM
bool "Enable driver for generic I2C-attached EEPROMs"
depends on MISC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index cda701d38e..64bea92f51 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -66,6 +66,7 @@ obj-y += qfw.o
 obj-$(CONFIG_QFW_ACPI) += qfw_acpi.o
 obj-$(CONFIG_QFW_PIO) += qfw_pio.o
 obj-$(CONFIG_QFW_MMIO) += qfw_mmio.o
+obj-$(CONFIG_QFW_SMBIOS) += qfw_smbios.o
 obj-$(CONFIG_SANDBOX) += qfw_sandbox.o
 endif
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
diff --git a/drivers/misc/qfw_smbios.c b/drivers/misc/qfw_smbios.c
new file mode 100644
index 00..9019345783
--- /dev/null
+++ b/drivers/misc/qfw_smbios.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * (C) Copyright 2023 Heinrich Schuchardt 
+ */
+
+#define LOG_CATEGORY UCLASS_QFW
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/**
+ * qfw_load_smbios_table() - load a QEMU firmware file
+ *
+ * @dev:   QEMU firmware device
+ * @size:  parameter to return the size of the loaded table
+ * @name:  name of the table to load
+ * Return: address of the loaded table, NULL on error
+ */
+static void *qfw_load_smbios_table(struct udevice *dev, uint32_t *size,
+  char *name)
+{
+   struct fw_file *file;
+   struct bios_linker_entry *table;
+
+   file = qfw_find_file(dev, name);
+   if (!file) {
+   log_debug("Can't find %s\n", name);
+   return NULL;
+   }
+
+   *size = be32_to_cpu(file->cfg.size);
+
+   table = malloc(*size);
+   if (!table) {
+   log_err("Out of memory\n");
+   return NULL;
+   }
+
+   qfw_read_entry(dev, be16_to_cpu(file->cfg.select), *size, table);
+
+   return table;
+}
+
+/**
+ * qfw_parse_smbios_anchor() - parse QEMU's SMBIOS anchor
+ *
+ * @dev:   QEMU firmware device
+ * @entry: SMBIOS 3 structure to be filled from QEMU's anchor
+ * Return: 0 for success, -ve on error
+ */
+static int qfw_parse_smbios_anchor(struct udevice *dev,
+  struct smbios3_entry *entry)
+{
+   void *table;
+   uint32_t size;
+   struct smbios_entry *entry2;
+   struct smbios3_entry *entry3;
+   const char smbios_sig[] = "_SM_";
+   const char smbios3_sig[] = "_SM3_";
+   int ret = 0;
+
+   table = qfw_load_smbios_table(dev, &size, "etc/smbios/smbios-anchor");
+   if (!table)
+   return -ENOMEM;
+   if (!memcmp(table, smbios3_sig, sizeof(smbios3_sig) - 1)) {
+   entry3 = table;
+   if (entry3->length != sizeof(struct smbios3_entry)) {
+   ret = -ENOENT;
+   goto out;
+   }
+   memcpy(entry, entry3, sizeof(struct smbios3_entry));
+   } else if (!memcmp(table, smbios_sig, sizeof(smbios_sig) - 1)) {
+   entry2 = table;
+   if (entry2->length != sizeof(struct smbios_entry)) {
+   ret = -ENOENT;
+   goto out;
+   }
+   memset(entry, 0, sizeof(struct smbios3_entry));
+   me

[PATCH v2 1/2] smbios: SMBIOS 3.0 (64-bit) Entry Point structure

2023-12-22 Thread Heinrich Schuchardt
From: Heinrich Schuchardt 

Add definition of the SMBIOS 3.0 (64-bit) Entry Point structure.

Signed-off-by: Heinrich Schuchardt 
---
v2:
no change
---
 include/smbios.h | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/include/smbios.h b/include/smbios.h
index c9df2706f5..e601283d29 100644
--- a/include/smbios.h
+++ b/include/smbios.h
@@ -54,6 +54,32 @@ struct __packed smbios_entry {
u8 bcd_rev;
 };

+/**
+ * struct smbios3_entry - SMBIOS 3.0 (64-bit) Entry Point structure
+ */
+struct __packed smbios3_entry {
+   /** @anchor: anchor string */
+   u8 anchor[5];
+   /** @checksum: checksum of the entry point structure */
+   u8 checksum;
+   /** @length: length of the entry point structure */
+   u8 length;
+   /** @major_ver: major version of the SMBIOS specification */
+   u8 major_ver;
+   /** @minor_ver: minor version of the SMBIOS specification */
+   u8 minor_ver;
+   /** @docrev: revision of the SMBIOS specification */
+   u8 doc_rev;
+   /** @entry_point_rev: revision of the entry point structure */
+   u8 entry_point_rev;
+   /** @reserved: reserved */
+   u8 reserved;
+   /** maximum size of SMBIOS table */
+   u32 max_struct_size;
+   /** @struct_table_address: 64-bit physical starting address */
+   u64 struct_table_address;
+};
+
 /* BIOS characteristics */
 #define BIOS_CHARACTERISTICS_PCI_SUPPORTED (1 << 7)
 #define BIOS_CHARACTERISTICS_UPGRADEABLE   (1 << 11)
--
2.43.0



[PATCH v2 0/2] smbios: copy QEMU tables

2023-12-22 Thread Heinrich Schuchardt
QEMU provides SMBIOS tables with detailed information. We should not try to
replicate them in U-Boot.

With this series we add code to copy the QEMU generated SMBIOS tables to
RAM. efi_smbios_register() later installs the SMBIOS table as EFI
configuration table for the OS to pick it up.

If we want to inform about U-Boot, we can add a Firmware Inventory
Information (type 45) table in future.

With 32bit ARM I did not see a correct SMBIOS table being transferred. We
need to check if our code in qfw_read_entry() is 32bit compliant.

For providing SMBIOS support in QEMU for RISC-V I have sent a patch
upstream:

[PATCH 1/1] target/riscv: SMBIOS support for RISC-V virt machine
https://lore.kernel.org/qemu-riscv/9183a3fb-b9f7-470c-b9a6-8d8cc6dce...@canonical.com/T/#t

Currently we have a predefined constant TABLE_SIZE = SZ_4K in
lib/efi_loader/efi_smbios.c. We should strive to refactor the code in
future to provide the length of the SMBIOS tables in global data. But
that is beyond the scope of this series.

Further we should find a matainer for drivers/misc/qfw*. It would be
plausible to add it to 'ACPI' maintenance.

A test via a new SMBIOS command is supplied in

[PATCH 0/5] cmd: provide command to display SMBIOS information
https://lore.kernel.org/u-boot/20231223004429.247301-1-xypron.g...@gmx.de/T/#t

v2:
fix parsing of SMBIOS anchor
enable copying on x86 and 32bit ARM/RISC-V

Heinrich Schuchardt (2):
  smbios: SMBIOS 3.0 (64-bit) Entry Point structure
  smbios: copy QEMU tables

 arch/x86/lib/tables.c   |   2 +-
 drivers/misc/Kconfig|   7 ++
 drivers/misc/Makefile   |   1 +
 drivers/misc/qfw_smbios.c   | 197 
 include/smbios.h|  26 +
 lib/efi_loader/efi_smbios.c |   4 +-
 6 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 drivers/misc/qfw_smbios.c

--
2.43.0



[PATCH 5/5] test: unit test for smbios command

2023-12-22 Thread Heinrich Schuchardt
Provide a unit test for the smbios command.

Provide different test functions for QEMU, sandbox, and other systems.

Signed-off-by: Heinrich Schuchardt 
---
 test/py/tests/test_smbios.py | 47 
 1 file changed, 47 insertions(+)
 create mode 100644 test/py/tests/test_smbios.py

diff --git a/test/py/tests/test_smbios.py b/test/py/tests/test_smbios.py
new file mode 100644
index 00..86d8d07539
--- /dev/null
+++ b/test/py/tests/test_smbios.py
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+"""Test smbios command"""
+
+import pytest
+
+@pytest.mark.buildconfigspec('cmd_smbios')
+@pytest.mark.notbuildconfigspec('qfw_smbios')
+@pytest.mark.notbuildconfigspec('sandbox')
+def test_cmd_smbios(u_boot_console):
+"""Run the smbios command"""
+output = u_boot_console.run_command('smbios')
+assert 'DMI type 0,' in output
+assert 'String 1: U-Boot' in output
+assert 'DMI type 1,' in output
+assert 'DMI type 2,' in output
+assert 'DMI type 3,' in output
+assert 'DMI type 4,' in output
+assert 'DMI type 127,' in output
+
+@pytest.mark.buildconfigspec('cmd_smbios')
+@pytest.mark.buildconfigspec('qfw_smbios')
+@pytest.mark.notbuildconfigspec('sandbox')
+# TODO:
+# QEMU v8.2.0 lacks SMBIOS support for RISC-V
+# Once support is available in our Docker image we can remove the constraint.
+@pytest.mark.notbuildconfigspec('riscv')
+def test_cmd_smbios_qemu(u_boot_console):
+"""Run the smbios command on QEMU"""
+output = u_boot_console.run_command('smbios')
+assert 'DMI type 1,' in output
+assert 'Manufacturer: QEMU' in output
+assert 'DMI type 127,' in output
+
+@pytest.mark.buildconfigspec('cmd_smbios')
+@pytest.mark.buildconfigspec('sandbox')
+def test_cmd_smbios_sandbox(u_boot_console):
+"""Run the smbios command on the sandbox"""
+output = u_boot_console.run_command('smbios')
+assert 'DMI type 0,' in output
+assert 'String 1: U-Boot' in output
+assert 'DMI type 1,' in output
+assert 'Manufacturer: sandbox' in output
+assert 'DMI type 2,' in output
+assert 'DMI type 3,' in output
+assert 'DMI type 4,' in output
+assert 'DMI type 127,' in output
--
2.43.0



[PATCH 3/5] cmd: provide command to display SMBIOS information

2023-12-22 Thread Heinrich Schuchardt
U-Boot can either generated an SMBIOS table or copy it from a prior boot
stage, e.g. QEMU.

Provide a command to display the SMBIOS information.

Currently only type 1 and 2 are translated to human readable text.
Other types may be added later. Currently only a hexdump and the list of
strings is provided for these.

Signed-off-by: Heinrich Schuchardt 
---
 cmd/Kconfig  |   7 ++
 cmd/Makefile |   1 +
 cmd/smbios.c | 191 +++
 3 files changed, 199 insertions(+)
 create mode 100644 cmd/smbios.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 5a7678f0ac..580aeec8ee 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -206,6 +206,13 @@ config CMD_SBI
help
  Display information about the SBI implementation.

+config CMD_SMBIOS
+   bool "smbios"
+   depends on SMBIOS
+   default y
+   help
+ Display the SMBIOS information.
+
 endmenu

 menu "Boot commands"
diff --git a/cmd/Makefile b/cmd/Makefile
index 5ed0e4011d..8a5dfd8ca9 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -168,6 +168,7 @@ obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
 obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o
 obj-$(CONFIG_CMD_SPI) += spi.o
 obj-$(CONFIG_CMD_STRINGS) += strings.o
+obj-$(CONFIG_CMD_SMBIOS) += smbios.o
 obj-$(CONFIG_CMD_SMC) += smccc.o
 obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o
 obj-$(CONFIG_CMD_STACKPROTECTOR_TEST) += stackprot_test.o
diff --git a/cmd/smbios.c b/cmd/smbios.c
new file mode 100644
index 00..63f908e92c
--- /dev/null
+++ b/cmd/smbios.c
@@ -0,0 +1,191 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * The 'smbios' command displays information from the SMBIOS table.
+ *
+ * Copyright (c) 2023, Heinrich Schuchardt 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/**
+ * smbios_get_string() - get SMBIOS string from table
+ *
+ * @table: SMBIOS table
+ * @index: index of the string
+ * Return: address of string, may point to empty string
+ */
+static const char *smbios_get_string(void *table, int index)
+{
+   const char *str = (char *)table +
+ ((struct smbios_header *)table)->length;
+
+   if (!*str)
+   ++str;
+   for (--index; *str && index; --index)
+   str += strlen(str) + 1;
+
+   return str;
+}
+
+static struct smbios_header *next_table(struct smbios_header *table)
+{
+   const char *str;
+
+   if (table->type == SMBIOS_END_OF_TABLE)
+   return NULL;
+
+   str = smbios_get_string(table, 0);
+   return (struct smbios_header *)(++str);
+}
+
+static void smbios_print_generic(struct smbios_header *table)
+{
+   char *str = (char *)table + table->length;
+
+   if (CONFIG_IS_ENABLED(HEXDUMP)) {
+   printf("Header and Data:\n");
+   print_hex_dump("\t", DUMP_PREFIX_OFFSET, 16, 1,
+  table, table->length, false);
+   }
+   if (*str) {
+   printf("Strings:\n");
+   for (int index = 1; *str; ++index) {
+   printf("\tString %u: %s\n", index, str);
+   str += strlen(str) + 1;
+   }
+   }
+}
+
+void smbios_print_str(const char *label, void *table, u8 index)
+{
+   printf("\t%s: %s\n", label, smbios_get_string(table, index));
+}
+
+static void smbios_print_type1(struct smbios_type1 *table)
+{
+   printf("System Information\n");
+   smbios_print_str("Manufacturer", table, table->manufacturer);
+   smbios_print_str("Product Name", table, table->product_name);
+   smbios_print_str("Version", table, table->version);
+   smbios_print_str("Serial Number", table, table->serial_number);
+   if (table->length >= 0x19) {
+   printf("\tUUID %pUl\n", table->uuid);
+   smbios_print_str("Wake Up Type", table, table->serial_number);
+   }
+   if (table->length >= 0x1b) {
+   smbios_print_str("Serial Number", table, table->serial_number);
+   smbios_print_str("SKU Number", table, table->sku_number);
+   }
+}
+
+static void smbios_print_type2(struct smbios_type2 *table)
+{
+   u16 *handle;
+
+   printf("Base Board Information\n");
+   smbios_print_str("Manufacturer", table, table->manufacturer);
+   smbios_print_str("Product Name", table, table->product_name);
+   smbios_print_str("Version", table, table->version);
+   smbios_print_str("Serial Number", table, table->serial_number);
+   smbios_print_str("Asset Tag", table, table->asset_tag_number);
+   printf("\tFeature Flags: 0x%2x\n", table->feature_flags);
+   smbios_print_str("Chassis Location", table, table->chassis_location);
+   printf("\tChassis Handle: 0x%2x\n", table->chassis_handle);
+   smbios_print_str("Board Type", table, table->board_type);
+   printf("\tContained Object Handles: ");
+   handle = (void *)table->eos;
+   for (int i = 0; i < table->number_cont

[PATCH 4/5] doc: man-page for smbios command

2023-12-22 Thread Heinrich Schuchardt
Provide a man-page for the smbios command.

Signed-off-by: Heinrich Schuchardt 
---
 doc/usage/cmd/smbios.rst | 93 
 doc/usage/index.rst  |  1 +
 2 files changed, 94 insertions(+)
 create mode 100644 doc/usage/cmd/smbios.rst

diff --git a/doc/usage/cmd/smbios.rst b/doc/usage/cmd/smbios.rst
new file mode 100644
index 00..1ffd706d7d
--- /dev/null
+++ b/doc/usage/cmd/smbios.rst
@@ -0,0 +1,93 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later:
+
+smbios command
+==
+
+Synopsis
+
+
+::
+
+smbios
+
+Description
+---
+
+The smbios command displays information from the SMBIOS tables.
+
+Examples
+
+
+The example below shows an example output of the smbios command.
+
+::
+
+=> smbios
+SMBIOS 2.8.0 present.
+8 structures occupying 81 bytes
+Table at 0x6d35018
+
+Handle 0x0100, DMI type 1, 27 bytes at 0x6d35018
+System Information
+Manufacturer: QEMU
+Product Name: Standard PC (i440FX + PIIX, 1996)
+Version: pc-i440fx-2.5
+Serial Number:
+UUID ----
+Wake Up Type:
+Serial Number:
+SKU Number:
+
+Handle 0x0300, DMI type 3, 22 bytes at 0x6d35069
+Header and Data:
+: 03 16 00 03 01 01 02 00 00 03 03 03 02 00 00 00
+0010: 00 00 00 00 00 00
+Strings:
+String 1: QEMU
+String 2: pc-i440fx-2.5
+
+Handle 0x0400, DMI type 4, 42 bytes at 0x6d35093
+Header and Data:
+: 04 2a 00 04 01 03 01 02 63 06 00 00 fd ab 81 07
+0010: 03 00 00 00 d0 07 d0 07 41 01 ff ff ff ff ff ff
+0020: 00 00 00 01 01 01 02 00 01 00
+Strings:
+String 1: CPU 0
+String 2: QEMU
+String 3: pc-i440fx-2.5
+
+Handle 0x1000, DMI type 16, 23 bytes at 0x6d350d7
+Header and Data:
+: 10 17 00 10 01 03 06 00 00 02 00 fe ff 01 00 00
+0010: 00 00 00 00 00 00 00
+
+Handle 0x1100, DMI type 17, 40 bytes at 0x6d350f0
+Header and Data:
+: 11 28 00 11 00 10 fe ff ff ff ff ff 80 00 09 00
+0010: 01 00 07 02 00 00 00 02 00 00 00 00 00 00 00 00
+0020: 00 00 00 00 00 00 00 00
+Strings:
+String 1: DIMM 0
+String 2: QEMU
+
+Handle 0x1300, DMI type 19, 31 bytes at 0x6d35125
+Header and Data:
+: 13 1f 00 13 00 00 00 00 ff ff 01 00 00 10 01 00
+0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+Handle 0x2000, DMI type 32, 11 bytes at 0x6d35146
+Header and Data:
+: 20 0b 00 20 00 00 00 00 00 00 00
+
+Handle 0x7f00, DMI type 127, 4 bytes at 0x6d35153
+End Of Table
+
+Configuration
+-
+
+The command is only available if CONFIG_CMD_SMBIOS=y.
+
+Return value
+
+
+The return value $? is 0 (true) on success, 1 (false) otherwise.
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 1a626c03c2..eb2b2311f8 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -102,6 +102,7 @@ Shell commands
cmd/size
cmd/sleep
cmd/sm
+   cmd/smbios
cmd/sound
cmd/source
cmd/temperature
--
2.43.0



[PATCH 2/5] smbios: type2: contained object handles

2023-12-22 Thread Heinrich Schuchardt
The type 2 structure must include information about the contained objects.
It is fine to set the number of contained object handles to 0.

Add the missing field.

Fixes: 721e992a8af5 ("x86: Add SMBIOS table support")
Signed-off-by: Heinrich Schuchardt 
---
 include/smbios.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/smbios.h b/include/smbios.h
index e601283d29..88c19ae062 100644
--- a/include/smbios.h
+++ b/include/smbios.h
@@ -139,6 +139,7 @@ struct __packed smbios_type2 {
u8 chassis_location;
u16 chassis_handle;
u8 board_type;
+   u8 number_contained_objects;
char eos[SMBIOS_STRUCT_EOS_BYTES];
 };

--
2.43.0



[PATCH 1/5] smbios: correct definition of gd_smbios_start() macro

2023-12-22 Thread Heinrich Schuchardt
gd_smbios_start() currently points to a non-existent field.
It should return the field written by gd_set_smbios_start().

Fixes: 50834884a815 ("Record the position of the SMBIOS tables")
Signed-off-by: Heinrich Schuchardt 
---
 include/asm-generic/global_data.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index e8c6412e3f..c1f7818817 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -553,7 +553,7 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
 #endif

 #ifdef CONFIG_SMBIOS
-#define gd_smbios_start()  gd->smbios_start
+#define gd_smbios_start()  gd->arch.smbios_start
 #define gd_set_smbios_start(addr)  gd->arch.smbios_start = addr
 #else
 #define gd_smbios_start()  0UL
--
2.43.0



[PATCH 0/5] cmd: provide command to display SMBIOS information

2023-12-22 Thread Heinrich Schuchardt
U-Boot may supply an SMBIOS table or they may be copied from QEMU.

Provide a command to display the SMBIOS information.

Currently only type 1 and 2 are translated to human readable text.
Other types may be added later. Currently only a hexdump and the list of
strings is provided for these.

The following prerequisites had to be fixed:

* The definition of SMBIOS type 2 lacked a field.

Heinrich Schuchardt (5):
  smbios: correct definition of gd_smbios_start() macro
  smbios: type2: contained object handles
  cmd: provide command to display SMBIOS information
  doc: man-page for smbios command
  test: unit test for smbios command

 cmd/Kconfig   |   7 ++
 cmd/Makefile  |   1 +
 cmd/smbios.c  | 191 ++
 doc/usage/cmd/smbios.rst  |  93 +++
 doc/usage/index.rst   |   1 +
 include/asm-generic/global_data.h |   2 +-
 include/smbios.h  |   1 +
 test/py/tests/test_smbios.py  |  47 
 8 files changed, 342 insertions(+), 1 deletion(-)
 create mode 100644 cmd/smbios.c
 create mode 100644 doc/usage/cmd/smbios.rst
 create mode 100644 test/py/tests/test_smbios.py

--
2.43.0



Re: [PATCH v3] arch: arm: Kconfig: Enable BOOTSTD_FULL for Rockchip SoCs

2023-12-22 Thread Shantur Rathore
Hi,

On Fri, Dec 22, 2023 at 12:09 PM Shantur Rathore  wrote:
>
> On Fri, Dec 22, 2023 at 12:07 PM Tom Rini  wrote:
> >
> > On Fri, Dec 22, 2023 at 12:05:39PM +, Shantur Rathore wrote:
> > > Hi all,
> > >
> > > On Mon, Dec 11, 2023 at 6:27 PM Tom Rini  wrote:
> > > >
> > > > On Mon, Dec 11, 2023 at 11:22:45AM -0700, Simon Glass wrote:
> > > > > Hi Tom,
> > > > [snip]
> > > > > > I think in hind-sight too much stuff is omitted without 
> > > > > > BOOTSTD_FULL.
> > > > > > The option itself then enables other stuff too by default, but some
> > > > > > parts of the bootflow command itself should be visible even without 
> > > > > > FULL
> > > > > > to make things easier on the user.
> > > > >
> > > > > At the time the goal was to avoid growth compared to the distro
> > > > > scripts. We could perhaps add some more things in with BOOTSTD_FULL
> > > > > but still have it as an option?
> > > >
> > > > Right. But now that we've tried this, some of the feedback has been that
> > > > it's just too minimal right now. Like looking at the help message for
> > > > bootflow, list and info should probably always be available. And maybe
> > > > the flags for "scan" should be re-thought? Too late to change things now
> > > > but "bootflow scan -b" should maybe how it's always been for "scan and
> > > > boot".
> > >
> > > What would be the preferred approach for this patch?
> > > Is it to update the default capabilities of bootflow or we can have this 
> > > patch?
> >
> > Well, I don't see a problem with just adding this to the platforms which
> > enable BOOTSTD_FULL until we can rework what's included/excluded by that
> > flag, and there's an issue filed for it now.
> >
> > --
> > Tom
>
> Great,  can we have this merged in please then [0]
>
> [0] - 
> https://patchwork.ozlabs.org/project/uboot/patch/20231119172310.1307942-...@shantur.com/
>

I tried this patch over the next branch and it failed to build.

Sent v4 here :
https://patchwork.ozlabs.org/project/uboot/patch/2023134358.563121-...@shantur.com/

Regards,
Shantur


[PATCH v4] arch: arm: Kconfig: Enable BOOTSTD_FULL for Rockchip SoCs

2023-12-22 Thread Shantur Rathore
Rockchip SoCs can support wide range of bootflows.
Without full bootflow commands, it can be difficult to
figure out issues if any, hence enable by default.

Reviewed-by: Simon Glass 

Signed-off-by: Shantur Rathore 
---

Changes in v4:
- Replace BOOTSTD_DEFAULT with BOOTSTD_FULL as previous version
didn't work on next

 arch/arm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d812685c98..a0265b36ad 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1985,7 +1985,7 @@ config ARCH_ROCKCHIP
imply ADC
imply CMD_DM
imply DEBUG_UART_BOARD_INIT
-   imply BOOTSTD_DEFAULTS
+   imply BOOTSTD_FULL
imply FAT_WRITE
imply SARADC_ROCKCHIP
imply SPL_SYSRESET
-- 
2.40.1



[PATCH v3 9/9] qemu-arm: get FDT from bloblist

2023-12-22 Thread Raymond Mao
Get devicetree from a bloblist if it exists.
If not, fallback to get FDT from the specified memory address.

Signed-off-by: Raymond Mao 
---
Changes in v2
- Refactor of board_fdt_blob_setup().

 board/emulation/qemu-arm/qemu-arm.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index e225011bf0..d326668caf 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -149,9 +149,17 @@ int dram_init_banksize(void)
 
 void *board_fdt_blob_setup(int *err)
 {
+   void *fdt = NULL;
*err = 0;
-   /* QEMU loads a generated DTB for us at the start of RAM. */
-   return (void *)CFG_SYS_SDRAM_BASE;
+
+   /* Check if a DTB exists in bloblist */
+   if (IS_ENABLED(CONFIG_BLOBLIST) && !bloblist_maybe_init())
+   fdt = bloblist_find(BLOBLISTT_CONTROL_FDT, 0);
+   if (!fdt)
+   /* QEMU loads a generated DTB for us at the start of RAM. */
+   return (void *)CFG_SYS_SDRAM_BASE;
+
+   return fdt;
 }
 
 int board_bloblist_from_boot_arg(unsigned long addr, unsigned long size)
-- 
2.25.1



[PATCH v3 8/9] fdt: update the document and Kconfig description

2023-12-22 Thread Raymond Mao
Update the document and Kconfig to describe the behavior of board
specific custom functions when CONFIG_OF_BOARD is defined.

Signed-off-by: Raymond Mao 
---
 doc/develop/devicetree/control.rst | 6 +++---
 dts/Kconfig| 7 +--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/doc/develop/devicetree/control.rst 
b/doc/develop/devicetree/control.rst
index cbb65c9b17..e061f4e812 100644
--- a/doc/develop/devicetree/control.rst
+++ b/doc/develop/devicetree/control.rst
@@ -104,9 +104,9 @@ in u-boot.bin so you can still just flash u-boot.bin onto 
your board. If you are
 using CONFIG_SPL_FRAMEWORK, then u-boot.img will be built to include the device
 tree binary.
 
-If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
-devicetree at runtime, for example if an earlier bootloader stage creates
-it and passes it to U-Boot.
+If CONFIG_OF_BOARD is defined, board-specific routines will provide the
+bloblist and devicetree at runtime, for example if an earlier bootloader stage
+creates it and passes it to U-Boot.
 
 If CONFIG_SANDBOX is defined, then it will be read from a file on
 startup. Use the -d flag to U-Boot to specify the file to read, -D for the
diff --git a/dts/Kconfig b/dts/Kconfig
index 00c0aeff89..12d61dc748 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -110,8 +110,11 @@ config OF_BOARD
default y if SANDBOX || OF_HAS_PRIOR_STAGE
help
  If this option is enabled, the device tree is provided at runtime by
- a custom function called board_fdt_blob_setup(). The board must
- implement this function if it wishes to provide special behaviour.
+ a custom function called board_fdt_blob_setup().
+ If this option is enabled, bloblist is provided at runtime by a
+ custom function called board_bloblist_from_boot_arg().
+ The board must implement these functions if it wishes to provide
+ special behaviour.
 
  With this option, the device tree build by U-Boot may be overridden or
  ignored. See OF_HAS_PRIOR_STAGE.
-- 
2.25.1



[PATCH v3 7/9] bloblist: Load the bloblist from the previous loader

2023-12-22 Thread Raymond Mao
During bloblist initialization, when CONFIG_OF_BOARD is defined,
invoke the platform custom function to load the bloblist via boot
arguments from the previous loader.
If the bloblist exists, copy it into the fixed bloblist memory region.

Signed-off-by: Raymond Mao 
---
 common/bloblist.c  | 47 --
 include/bloblist.h | 16 
 2 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/common/bloblist.c b/common/bloblist.c
index 5ad1db137a..e66afcde64 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -492,31 +492,38 @@ int bloblist_init(void)
bool fixed = IS_ENABLED(CONFIG_BLOBLIST_FIXED);
int ret = -ENOENT;
ulong addr, size;
-   bool expected;
-
-   /**
-* We don't expect to find an existing bloblist in the first phase of
-* U-Boot that runs. Also we have no way to receive the address of an
-* allocated bloblist from a previous stage, so it must be at a fixed
+   /*
+* If U-Boot is not in the first phase, an existing bloblist must be
+* at a fixed address.
+*/
+   bool from_addr = fixed && !u_boot_first_phase();
+   /*
+* If U-Boot is in the first phase that a board specific routine should
+* install the bloblist passed from previous loader to this fixed
 * address.
 */
-   expected = fixed && !u_boot_first_phase();
+   bool from_board = fixed && IS_ENABLED(CONFIG_OF_BOARD) &&
+ u_boot_first_phase();
+
if (spl_prev_phase() == PHASE_TPL && !IS_ENABLED(CONFIG_TPL_BLOBLIST))
-   expected = false;
+   from_addr = false;
if (fixed)
addr = IF_ENABLED_INT(CONFIG_BLOBLIST_FIXED,
  CONFIG_BLOBLIST_ADDR);
size = CONFIG_BLOBLIST_SIZE;
-   if (expected) {
+
+   if (from_board)
+   ret = board_bloblist_from_boot_arg(addr, size);
+   else if (from_addr)
ret = bloblist_check(addr, size);
-   if (ret) {
-   log_warning("Expected bloblist at %lx not found 
(err=%d)\n",
-   addr, ret);
-   } else {
-   /* Get the real size, if it is not what we expected */
-   size = gd->bloblist->total_size;
-   }
-   }
+
+   if (ret)
+   log_warning("Bloblist at %lx not found (err=%d)\n",
+   addr, ret);
+   else
+   /* Get the real size */
+   size = gd->bloblist->total_size;
+
if (ret) {
if (CONFIG_IS_ENABLED(BLOBLIST_ALLOC)) {
void *ptr = memalign(BLOBLIST_ALIGN, size);
@@ -525,7 +532,8 @@ int bloblist_init(void)
return log_msg_ret("alloc", -ENOMEM);
addr = map_to_sysmem(ptr);
} else if (!fixed) {
-   return log_msg_ret("!fixed", ret);
+   return log_msg_ret("BLOBLIST_FIXED is not enabled",
+  ret);
}
log_debug("Creating new bloblist size %lx at %lx\n", size,
  addr);
@@ -538,6 +546,9 @@ int bloblist_init(void)
return log_msg_ret("ini", ret);
gd->flags |= GD_FLG_BLOBLIST_READY;
 
+   bloblist_show_stats();
+   bloblist_show_list();
+
return 0;
 }
 
diff --git a/include/bloblist.h b/include/bloblist.h
index c1dab11f78..2f4246576e 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -445,6 +445,22 @@ int bloblist_reloc(void *to, uint to_size);
  */
 int bloblist_init(void);
 
+#if (IS_ENABLED(CONFIG_ARCH_QEMU) && IS_ENABLED(CONFIG_ARM))
+/* Board custom function for qemu-arm */
+int board_bloblist_from_boot_arg(unsigned long addr, unsigned long size);
+#else
+/*
+ * A board need to implement this custom function if it needs to retrieve
+ * bloblist from a previous loader
+ */
+static inline
+int board_bloblist_from_boot_arg(unsigned long __always_unused addr,
+unsigned long __always_unused size)
+{
+   return -1;
+}
+#endif
+
 #if CONFIG_IS_ENABLED(BLOBLIST)
 /**
  * bloblist_maybe_init() - Init the bloblist system if not already done
-- 
2.25.1



[PATCH v3 6/9] qemu-arm: Get bloblist from boot arguments

2023-12-22 Thread Raymond Mao
Add platform custom function to get bloblist from boot arguments.
Check whether boot arguments aligns with the register conventions
defined in FW Handoff spec v0.9.
Add bloblist related options into qemu default config.

Signed-off-by: Raymond Mao 
---
Changes in v2
- Remove low level code for copying boot arguments.
- Refactor board_fdt_blob_setup() and remove direct access of gd->bloblist.
Changes in v3
- Optimize board_bloblist_from_boot_arg().

 board/emulation/qemu-arm/qemu-arm.c | 30 +
 configs/qemu_arm64_defconfig|  3 +++
 2 files changed, 33 insertions(+)

diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index 942f1fff57..e225011bf0 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -102,6 +103,15 @@ static struct mm_region qemu_arm64_mem_map[] = {
 struct mm_region *mem_map = qemu_arm64_mem_map;
 #endif
 
+/*
+ * Boot parameters saved from start.S
+ * saved_args[0]: FDT base address
+ * saved_args[1]: Bloblist signature
+ * saved_args[2]: must be 0
+ * saved_args[3]: Bloblist base address
+ */
+extern unsigned long saved_args[];
+
 int board_init(void)
 {
return 0;
@@ -144,6 +154,26 @@ void *board_fdt_blob_setup(int *err)
return (void *)CFG_SYS_SDRAM_BASE;
 }
 
+int board_bloblist_from_boot_arg(unsigned long addr, unsigned long size)
+{
+   int ret = -ENOENT;
+
+   if (!IS_ENABLED(CONFIG_OF_BOARD) || !IS_ENABLED(CONFIG_BLOBLIST))
+   return -ENOENT;
+
+   ret = bloblist_check(saved_args[3], size);
+   if (ret)
+   return ret;
+
+   /* Check the register conventions */
+   ret = bloblist_check_reg_conv(saved_args[0], saved_args[2]);
+   if (!ret)
+   /* Relocate the bloblist to the fixed address */
+   ret = bloblist_reloc((void *)addr, CONFIG_BLOBLIST_SIZE);
+
+   return ret;
+}
+
 void enable_caches(void)
 {
 icache_enable();
diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig
index c010c25a92..418f48001c 100644
--- a/configs/qemu_arm64_defconfig
+++ b/configs/qemu_arm64_defconfig
@@ -69,3 +69,6 @@ CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_PCI=y
 CONFIG_SEMIHOSTING=y
 CONFIG_TPM=y
+CONFIG_BLOBLIST=y
+CONFIG_BLOBLIST_ADDR=0x40004000
+CONFIG_BLOBLIST_SIZE=0x4000
-- 
2.25.1



[PATCH v3 5/9] arm: armv8: save boot arguments

2023-12-22 Thread Raymond Mao
Save boot arguments x[0-3] into an array for handover of bloblist from
previous boot stage.

Signed-off-by: Raymond Mao 
---
Changes in v2
- New patch file created for v2.

 arch/arm/cpu/armv8/start.S | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
index 6cc1d26e5e..8e704f590e 100644
--- a/arch/arm/cpu/armv8/start.S
+++ b/arch/arm/cpu/armv8/start.S
@@ -370,5 +370,19 @@ ENTRY(c_runtime_cpu_setup)
 ENDPROC(c_runtime_cpu_setup)
 
 WEAK(save_boot_params)
+#if (IS_ENABLED(CONFIG_OF_BOARD) && IS_ENABLED(CONFIG_BLOBLIST))
+   adr x9, saved_args
+   stp x0, x1, [x9]
+   /* Increment the address by 16 bytes for the next pair of values */
+   stp x2, x3, [x9, #16]
+#endif
b   save_boot_params_ret/* back to my caller */
 ENDPROC(save_boot_params)
+
+.section .data
+.global saved_args
+saved_args:
+   .rept 4
+   .xword 0
+   .endr
+END(saved_args)
-- 
2.25.1



[PATCH v3 4/9] arm: armv7: save boot arguments

2023-12-22 Thread Raymond Mao
Save boot arguments r[0-3] into an array for handover of bloblist from
previous boot stage.

Signed-off-by: Raymond Mao 
---
Changes in v2
- New patch file created for v2.
Changes in v3
- Swap value of r0 with r2.

 arch/arm/cpu/armv7/start.S | 13 +
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S
index 69e281b086..2ca63ca32c 100644
--- a/arch/arm/cpu/armv7/start.S
+++ b/arch/arm/cpu/armv7/start.S
@@ -152,9 +152,22 @@ ENDPROC(c_runtime_cpu_setup)
  *
  */
 WEAK(save_boot_params)
+#if (IS_ENABLED(CONFIG_OF_BOARD) && IS_ENABLED(CONFIG_BLOBLIST))
+   ldr r12, =saved_args
+   /* Intentionally swapping r0 with r2 */
+   stm r12, {r2, r1, r0, r3}
+#endif
b   save_boot_params_ret@ back to my caller
 ENDPROC(save_boot_params)
 
+.section .data
+.global saved_args
+saved_args:
+   .rept 4
+   .word 0
+   .endr
+END(saved_args)
+
 #ifdef CONFIG_ARMV7_LPAE
 WEAK(switch_to_hypervisor)
b   switch_to_hypervisor_ret
-- 
2.25.1



[PATCH v3 3/9] bloblist: refactor of bloblist_reloc()

2023-12-22 Thread Raymond Mao
The current bloblist pointer and size can be retrieved from global
data, so we don't need to pass them from the function arguments.
This change also help to remove all external access of gd->bloblist
outside of bloblist module.

Signed-off-by: Raymond Mao 
---
Changes in v2
- New patch file created for v2.
Changes in v3
- Check the space size before copying the bloblist.
- Add return code of bloblist_reloc().

 common/bloblist.c  | 10 --
 common/board_f.c   |  8 ++--
 include/bloblist.h |  8 
 test/bloblist.c|  6 ++
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/common/bloblist.c b/common/bloblist.c
index db3fbb20cf..5ad1db137a 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -472,13 +472,19 @@ void bloblist_show_list(void)
}
 }
 
-void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
+int bloblist_reloc(void *to, uint to_size)
 {
struct bloblist_hdr *hdr;
 
-   memcpy(to, from, from_size);
+   if (to_size < gd->bloblist->total_size)
+   return -ENOSPC;
+
+   memcpy(to, gd->bloblist, gd->bloblist->total_size);
hdr = to;
hdr->total_size = to_size;
+   gd->bloblist = to;
+
+   return 0;
 }
 
 int bloblist_init(void)
diff --git a/common/board_f.c b/common/board_f.c
index d4d7d01f8f..00b0430889 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -676,13 +676,9 @@ static int reloc_bloblist(void)
return 0;
}
if (gd->new_bloblist) {
-   int size = CONFIG_BLOBLIST_SIZE;
-
debug("Copying bloblist from %p to %p, size %x\n",
- gd->bloblist, gd->new_bloblist, size);
-   bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC,
-  gd->bloblist, size);
-   gd->bloblist = gd->new_bloblist;
+ gd->bloblist, gd->new_bloblist, gd->bloblist->total_size);
+   bloblist_reloc(gd->new_bloblist, CONFIG_BLOBLIST_SIZE_RELOC);
}
 #endif
 
diff --git a/include/bloblist.h b/include/bloblist.h
index bd32e38a06..c1dab11f78 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -418,11 +418,11 @@ const char *bloblist_tag_name(enum bloblist_tag_t tag);
  * bloblist_reloc() - Relocate the bloblist and optionally resize it
  *
  * @to: Pointer to new bloblist location (must not overlap old location)
- * @to_size: New size for bloblist (must be larger than from_size)
- * @from: Pointer to bloblist to relocate
- * @from_size: Size of bloblist to relocate
+ * @to_size: New size for bloblist
+ * Return: 0 if OK, -ENOSPC if the new size is small than the bloblist total
+ *size.
  */
-void bloblist_reloc(void *to, uint to_size, void *from, uint from_size);
+int bloblist_reloc(void *to, uint to_size);
 
 /**
  * bloblist_init() - Init the bloblist system with a single bloblist
diff --git a/test/bloblist.c b/test/bloblist.c
index 7dab9addf8..1c60bbac36 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -376,13 +376,12 @@ static int bloblist_test_reloc(struct unit_test_state 
*uts)
 {
const uint large_size = TEST_BLOBLIST_SIZE;
const uint small_size = 0x20;
-   void *old_ptr, *new_ptr;
+   void *new_ptr;
void *blob1, *blob2;
ulong new_addr;
ulong new_size;
 
ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0, 0));
-   old_ptr = map_sysmem(TEST_ADDR, TEST_BLOBLIST_SIZE);
 
/* Add one blob and then one that won't fit */
blob1 = bloblist_add(TEST_TAG, small_size, 0);
@@ -394,8 +393,7 @@ static int bloblist_test_reloc(struct unit_test_state *uts)
new_addr = TEST_ADDR + TEST_BLOBLIST_SIZE;
new_size = TEST_BLOBLIST_SIZE + 0x100;
new_ptr = map_sysmem(new_addr, TEST_BLOBLIST_SIZE);
-   bloblist_reloc(new_ptr, new_size, old_ptr, TEST_BLOBLIST_SIZE);
-   gd->bloblist = new_ptr;
+   ut_assertok(bloblist_reloc(new_ptr, new_size));
 
/* Check the old blob is there and that we can now add the bigger one */
ut_assertnonnull(bloblist_find(TEST_TAG, small_size));
-- 
2.25.1



[PATCH v3 2/9] bloblist: check bloblist with specified buffer size

2023-12-22 Thread Raymond Mao
Instead of expecting the bloblist total size to be the same as the
pre-allocated buffer size, practically we are more interested in
whether the pre-allocated buffer size is bigger than the bloblist
total size.

Signed-off-by: Raymond Mao 
Reviewed-by: Ilias Apalodimas 
---
Changes in v2
- New patch file created for v2.

 common/bloblist.c | 2 +-
 test/bloblist.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/bloblist.c b/common/bloblist.c
index ba17dd851a..db3fbb20cf 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -384,7 +384,7 @@ int bloblist_check(ulong addr, uint size)
return log_msg_ret("Bad magic", -ENOENT);
if (hdr->version != BLOBLIST_VERSION)
return log_msg_ret("Bad version", -EPROTONOSUPPORT);
-   if (!hdr->total_size || (size && hdr->total_size != size))
+   if (!hdr->total_size || (size && hdr->total_size > size))
return log_msg_ret("Bad total size", -EFBIG);
if (hdr->used_size > hdr->total_size)
return log_msg_ret("Bad used size", -ENOENT);
diff --git a/test/bloblist.c b/test/bloblist.c
index 17d9dd03d0..7dab9addf8 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -207,7 +207,7 @@ static int bloblist_test_checksum(struct unit_test_state 
*uts)
hdr->flags++;
 
hdr->total_size--;
-   ut_asserteq(-EFBIG, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
+   ut_asserteq(-EIO, bloblist_check(TEST_ADDR, TEST_BLOBLIST_SIZE));
hdr->total_size++;
 
hdr->spare++;
-- 
2.25.1



[PATCH v3 1/9] bloblist: add API to check the register conventions

2023-12-22 Thread Raymond Mao
Add bloblist_check_reg_conv() to check whether the bloblist is compliant
to the register conventions defined in Firmware Handoff specification.
This API can be used for all Arm platforms.

Signed-off-by: Raymond Mao 
---
Changes in v2
- Refactor of bloblist_check_reg_conv().
Changes in v3
- bloblist_check_reg_conv() returns -ENOENT if OF_BOARD is disabled.

 common/bloblist.c  | 13 +
 include/bloblist.h | 12 
 2 files changed, 25 insertions(+)

diff --git a/common/bloblist.c b/common/bloblist.c
index 625e480f6b..ba17dd851a 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -542,3 +542,16 @@ int bloblist_maybe_init(void)
 
return 0;
 }
+
+int bloblist_check_reg_conv(ulong rfdt, ulong rzero)
+{
+   if (!IS_ENABLED(CONFIG_OF_BOARD))
+   return -ENOENT;
+
+   if (rzero || rfdt != (ulong)bloblist_find(BLOBLISTT_CONTROL_FDT, 0)) {
+   gd->bloblist = NULL;  /* Reset the gd bloblist pointer */
+   return -EIO;
+   }
+
+   return 0;
+}
diff --git a/include/bloblist.h b/include/bloblist.h
index 84fc943819..bd32e38a06 100644
--- a/include/bloblist.h
+++ b/include/bloblist.h
@@ -461,4 +461,16 @@ static inline int bloblist_maybe_init(void)
 }
 #endif /* BLOBLIST */
 
+/**
+ * bloblist_check_reg_conv() - Check whether the bloblist is compliant to
+ *the register conventions according to the
+ *Firmware Handoff spec.
+ *
+ * @rfdt:  Register that holds the FDT base address.
+ * @rzero: Register that must be zero.
+ * Return: 0 if OK, -EIO if the bloblist is not compliant to the register
+ *conventions, -ENOENT if OF_BOARD is disabled.
+ */
+int bloblist_check_reg_conv(ulong rfdt, ulong rzero);
+
 #endif /* __BLOBLIST_H */
-- 
2.25.1



[PATCH v3 0/9] Handoff bloblist from previous boot stage

2023-12-22 Thread Raymond Mao
This patch set depends on another series:
"[PATCH v3 00/14] Support Firmware Handoff spec via bloblist".

This patch set implements Qemu-Arm platform custom functions to retrieve
the bloblist (aka. Transfer List) from previous loader via boot arguments
when CONFIG_OF_BOARD option is enabled and all boot arguments are compliant
to the register conventions defined in the Firmware Handoff spec v0.9.

Qemu-Arm platform custom function will load the FDT from the bloblist if it
exists.
Otherwise it fallbacks to get the FDT from the specified memory address.

If a platform vendor wish to have different behaviors for loading bloblist
or FDT from the previous boot stage, it is required to implement the custom
functions board_bloblist_from_boot_arg() and board_fdt_blob_setup().

Raymond Mao (9):
  bloblist: add API to check the register conventions
  bloblist: check bloblist with specified buffer size
  bloblist: refactor of bloblist_reloc()
  arm: armv7: save boot arguments
  arm: armv8: save boot arguments
  qemu-arm: Get bloblist from boot arguments
  bloblist: Load the bloblist from the previous loader
  fdt: update the document and Kconfig description
  qemu-arm: get FDT from bloblist

 arch/arm/cpu/armv7/start.S  | 13 ++
 arch/arm/cpu/armv8/start.S  | 14 ++
 board/emulation/qemu-arm/qemu-arm.c | 42 -
 common/bloblist.c   | 72 -
 common/board_f.c|  8 +---
 configs/qemu_arm64_defconfig|  3 ++
 doc/develop/devicetree/control.rst  |  6 +--
 dts/Kconfig |  7 ++-
 include/bloblist.h  | 36 +--
 test/bloblist.c |  8 ++--
 10 files changed, 166 insertions(+), 43 deletions(-)

-- 
2.25.1



Re: [PATCH v13 15/24] cli: add modern hush as parser for run_command*()

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 10:10:42PM +0100, Francis Laniel wrote:
> Hi!
> 
> 
> Le vendredi 22 décembre 2023, 22:02:35 CET Francis Laniel a écrit :
> > Enables using, in code, modern hush as parser for run_command function
> > family. It also enables the command run to be used by CLI user of modern
> > hush.
> > 
> > Reviewed-by: Simon Glass 
> > Signed-off-by: Francis Laniel 
[snip]
> > diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
> > index a9b555c779..104f49deef 100644
> > --- a/test/boot/bootflow.c
> > +++ b/test/boot/bootflow.c
> > @@ -710,7 +710,21 @@ static int bootflow_scan_menu_boot(struct
> > unit_test_state *uts) ut_assert_skip_to_line("(2 bootflows, 2 valid)");
> > 
> > ut_assert_nextline("Selected: Armbian");
> > -   ut_assert_skip_to_line("Boot failed (err=-14)");
> > +
> > +   if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
> > +   /*
> > +* With old hush, despite booti failing to boot, i.e. returning
> > +* CMD_RET_FAILURE, run_command() returns 0 which leads 
> bootflow_boot(),
> > as + * we are using bootmeth_script here, to return -EFAULT.
> > +*/
> > +   ut_assert_skip_to_line("Boot failed (err=-14)");
> > +   } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
> > +   /*
> > +* While with modern one, run_command() propagates 
> CMD_RET_FAILURE
> > returned +   * by booti, so we get 1 here.
> > +*/
> > +   ut_assert_skip_to_line("Boot failed (err=1)");
> > +   }
> 
> I would like to give a bit of context here.
> With the following patch:
> diff --git a/test/py/tests/test_ut.py b/test/py/tests/test_ut.py
> index c169c835e3..cc5adda0a3 100644
> --- a/test/py/tests/test_ut.py
> +++ b/test/py/tests/test_ut.py
> @@ -173,7 +173,7 @@ else
> fi
>  fi
>  booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
> -
> +echo $?
>  # Recompile with:
>  # mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
>  ''' % (mmc_dev)
> We can easily see that booti is failing while running the test:
> $ ./test/py/test.py -o log_cli=true -s --build -v -k 
> 'test_ut[ut_bootstd_bootflow_scan_menu_boot'
> ...
> Aborting!
> Failed to load '/boot/dtb/rockchip/overlay/-fixup.scr'
> 1
> 
> The problem with old hush, is that the 1 returned here, which corresponds to 
> CMD_RET_FAILURE, is not propagated as the return value of run_command().
> So, this lead the -EFAULT branch here to be taken:
> int bootflow_boot(struct bootflow *bflow)
> {
>   /* ... */
> 
>   ret = bootmeth_boot(bflow->method, bflow);
>   if (ret)
>   return log_msg_ret("boot", ret);
> 
>   /*
>* internal error, should not get here since we should have booted
>* something or returned an error
>*/
> 
>   return log_msg_ret("end", -EFAULT);
> }
> 
> With modern hush, CMD_RET_FAILURE is propagated as the return value of 
> run_command().
> As a consequence, we return with log_mst_ret("boot", 1), which leaded to this 
> test to fail.
> The above modification consists in adapting the expected output to the 
> current 
> shell flavor.
> I think this is the good thing to do, as I find modern hush behavior better 
> than the old one, i.e. it propagates CMD_RET_FAILURE as return of 
> run_command().

Oh very nice, thanks for digging in to this and explaining!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v13 15/24] cli: add modern hush as parser for run_command*()

2023-12-22 Thread Francis Laniel
Hi!


Le vendredi 22 décembre 2023, 22:02:35 CET Francis Laniel a écrit :
> Enables using, in code, modern hush as parser for run_command function
> family. It also enables the command run to be used by CLI user of modern
> hush.
> 
> Reviewed-by: Simon Glass 
> Signed-off-by: Francis Laniel 
> ---
>  common/cli.c   | 67 --
>  common/cli_hush_upstream.c |  2 +-
>  test/boot/bootflow.c   | 16 -
>  3 files changed, 66 insertions(+), 19 deletions(-)
> 
> diff --git a/common/cli.c b/common/cli.c
> index b3eb512b62..a34938294e 100644
> --- a/common/cli.c
> +++ b/common/cli.c
> @@ -25,6 +25,14 @@
>  #include 
> 
>  #ifdef CONFIG_CMDLINE
> +
> +static inline bool use_hush_old(void)
> +{
> + return IS_ENABLED(CONFIG_HUSH_SELECTABLE) ?
> + gd->flags & GD_FLG_HUSH_OLD_PARSER :
> + IS_ENABLED(CONFIG_HUSH_OLD_PARSER);
> +}
> +
>  /*
>   * Run a command using the selected parser.
>   *
> @@ -43,15 +51,30 @@ int run_command(const char *cmd, int flag)
>   return 1;
> 
>   return 0;
> -#elif CONFIG_IS_ENABLED(HUSH_OLD_PARSER)
> - int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP;
> -
> - if (flag & CMD_FLAG_ENV)
> - hush_flags |= FLAG_CONT_ON_NEWLINE;
> - return parse_string_outer(cmd, hush_flags);
> -#else /* HUSH_MODERN_PARSER */
> - /* Not yet implemented. */
> - return 1;
> +#else
> + if (use_hush_old()) {
> + int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP;
> +
> + if (flag & CMD_FLAG_ENV)
> + hush_flags |= FLAG_CONT_ON_NEWLINE;
> + return parse_string_outer(cmd, hush_flags);
> + }
> + /*
> +  * Possible values for flags are the following:
> +  * FLAG_EXIT_FROM_LOOP: This flags ensures we exit from loop in
> +  * parse_and_run_stream() after first iteration while normal
> +  * behavior, * i.e. when called from cli_loop(), is to loop
> +  * infinitely.
> +  * FLAG_PARSE_SEMICOLON: modern Hush parses ';' and does not stop
> +  * first time it sees one. So, I think we do not need this flag.
> +  * FLAG_REPARSING: For the moment, I do not understand the goal
> +  * of this flag.
> +  * FLAG_CONT_ON_NEWLINE: This flag seems to be used to continue
> +  * parsing even when reading '\n' when coming from
> +  * run_command(). In this case, modern Hush reads until it finds
> +  * '\0'. So, I think we do not need this flag.
> +  */
> + return parse_string_outer_modern(cmd, FLAG_EXIT_FROM_LOOP);
>  #endif
>  }
> 
> @@ -67,12 +90,23 @@ int run_command_repeatable(const char *cmd, int flag)
>  #ifndef CONFIG_HUSH_PARSER
>   return cli_simple_run_command(cmd, flag);
>  #else
> + int ret;
> +
> + if (use_hush_old()) {
> + ret = parse_string_outer(cmd,
> +  FLAG_PARSE_SEMICOLON
> +  | FLAG_EXIT_FROM_LOOP);
> + } else {
> + ret = parse_string_outer_modern(cmd,
> +   FLAG_PARSE_SEMICOLON
> +   | FLAG_EXIT_FROM_LOOP);
> + }
> +
>   /*
>* parse_string_outer() returns 1 for failure, so clean up
>* its result.
>*/
> - if (parse_string_outer(cmd,
> -FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP))
> + if (ret)
>   return -1;
> 
>   return 0;
> @@ -111,12 +145,11 @@ int run_command_list(const char *cmd, int len, int
> flag) buff[len] = '\0';
>   }
>  #ifdef CONFIG_HUSH_PARSER
> -#if CONFIG_IS_ENABLED(HUSH_OLD_PARSER)
> - rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON);
> -#else /* HUSH_MODERN_PARSER */
> - /* Not yet implemented. */
> - rcode = 1;
> -#endif
> + if (use_hush_old()) {
> + rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON);
> + } else {
> + rcode = parse_string_outer_modern(buff, FLAG_PARSE_SEMICOLON);
> + }
>  #else
>   /*
>* This function will overwrite any \n it sees with a \0, which
> diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
> index 7f6b058e6c..11870c51e8 100644
> --- a/common/cli_hush_upstream.c
> +++ b/common/cli_hush_upstream.c
> @@ -8022,7 +8022,7 @@ static int parse_and_run_string(const char *s)
>  }
> 
>  #ifdef __U_BOOT__
> -int parse_string_outer(const char *cmd, int flags)
> +int parse_string_outer_modern(const char *cmd, int flags)
>  {
>   int ret;
>   int old_flags;
> diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
> index a9b555c779..104f49deef 100644
> --- a/test/boot/bootflow.c
> +++ b/test/boot/bootflow.c
> @@ -710,7 +710,21 @@ static int bootflow_scan_menu_boot(struct
> unit_test_state *uts) ut_assert_skip_to_line("(2 bootflows, 2 valid)");
> 
>   ut_assert_nextline("Selected: Armbian");
> - ut_assert_skip_to_line("Boot failed (err=-14)");
> +
> +

[PATCH v13 24/24] configs: Use old hush for several boards

2023-12-22 Thread Francis Laniel
The keymile board family is not compatible with modern hush parser.
Indeed, This boards used set_local_var() to store some variables as local shell.
They then used get_local_var() to retrieve the variables values.
Sadly, this two functions do not exist with CONFIG_HUSH_MODERN_PARSER.
A patch was proposed to use environment variables rather than local variables
but it does not tackle the problem, so complementary work is needed to make
this boards use CONFIG_HUSH_MODERN_PARSER.

Also, with CONFIG_HUSH_MODERN_PARSER, kirkwoord sheevaplug and phytec bk4r1 hit
their board limits, so better to stick with old hush.

Cc: Holger Brunck 
Link: https://marc.info/?l=u-boot&m=165541917618725&w=2
Signed-off-by: Francis Laniel 
---
 configs/kmcent2_defconfig  | 1 +
 configs/kmcoge5ne_defconfig| 1 +
 configs/kmeter1_defconfig  | 1 +
 configs/kmopti2_defconfig  | 1 +
 configs/kmsupx5_defconfig  | 1 +
 configs/kmtepr2_defconfig  | 1 +
 configs/pg_wcom_expu1_defconfig| 1 +
 configs/pg_wcom_expu1_update_defconfig | 1 +
 configs/pg_wcom_seli8_defconfig| 1 +
 configs/pg_wcom_seli8_update_defconfig | 1 +
 configs/socfpga_secu1_defconfig| 1 +
 configs/tuge1_defconfig| 1 +
 configs/tuxx1_defconfig| 1 +
 13 files changed, 13 insertions(+)

diff --git a/configs/kmcent2_defconfig b/configs/kmcent2_defconfig
index 2cf9565fc9..ac272b3840 100644
--- a/configs/kmcent2_defconfig
+++ b/configs/kmcent2_defconfig
@@ -111,3 +111,4 @@ CONFIG_BCH=y
 CONFIG_PANIC_HANG=y
 CONFIG_LZO=y
 CONFIG_POST=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/kmcoge5ne_defconfig b/configs/kmcoge5ne_defconfig
index 257ceeca90..ace5080690 100644
--- a/configs/kmcoge5ne_defconfig
+++ b/configs/kmcoge5ne_defconfig
@@ -202,3 +202,4 @@ CONFIG_QE=y
 CONFIG_SYS_NS16550=y
 CONFIG_BCH=y
 CONFIG_POST=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/kmeter1_defconfig b/configs/kmeter1_defconfig
index 46e0370e35..56b83c085d 100644
--- a/configs/kmeter1_defconfig
+++ b/configs/kmeter1_defconfig
@@ -173,3 +173,4 @@ CONFIG_DM_ETH_PHY=y
 CONFIG_QE_UEC=y
 CONFIG_QE=y
 CONFIG_SYS_NS16550=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/kmopti2_defconfig b/configs/kmopti2_defconfig
index c6c021adde..08c7602f5d 100644
--- a/configs/kmopti2_defconfig
+++ b/configs/kmopti2_defconfig
@@ -183,3 +183,4 @@ CONFIG_QE_UEC=y
 # CONFIG_PINCTRL_FULL is not set
 CONFIG_QE=y
 CONFIG_SYS_NS16550=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/kmsupx5_defconfig b/configs/kmsupx5_defconfig
index 25642e7018..72db26f320 100644
--- a/configs/kmsupx5_defconfig
+++ b/configs/kmsupx5_defconfig
@@ -166,3 +166,4 @@ CONFIG_QE_UEC=y
 # CONFIG_PINCTRL_FULL is not set
 CONFIG_QE=y
 CONFIG_SYS_NS16550=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/kmtepr2_defconfig b/configs/kmtepr2_defconfig
index ea37a29060..ed908d3c77 100644
--- a/configs/kmtepr2_defconfig
+++ b/configs/kmtepr2_defconfig
@@ -182,3 +182,4 @@ CONFIG_QE_UEC=y
 # CONFIG_PINCTRL_FULL is not set
 CONFIG_QE=y
 CONFIG_SYS_NS16550=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/pg_wcom_expu1_defconfig b/configs/pg_wcom_expu1_defconfig
index 455b439151..0337447f79 100644
--- a/configs/pg_wcom_expu1_defconfig
+++ b/configs/pg_wcom_expu1_defconfig
@@ -105,3 +105,4 @@ CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_LZO=y
 CONFIG_POST=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/pg_wcom_expu1_update_defconfig 
b/configs/pg_wcom_expu1_update_defconfig
index 269116cd0d..e5daa306ab 100644
--- a/configs/pg_wcom_expu1_update_defconfig
+++ b/configs/pg_wcom_expu1_update_defconfig
@@ -103,3 +103,4 @@ CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_LZO=y
 CONFIG_POST=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/pg_wcom_seli8_defconfig b/configs/pg_wcom_seli8_defconfig
index 678bc10070..e86a17abdf 100644
--- a/configs/pg_wcom_seli8_defconfig
+++ b/configs/pg_wcom_seli8_defconfig
@@ -105,3 +105,4 @@ CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_LZO=y
 CONFIG_POST=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/pg_wcom_seli8_update_defconfig 
b/configs/pg_wcom_seli8_update_defconfig
index 7c7b001903..886334a043 100644
--- a/configs/pg_wcom_seli8_update_defconfig
+++ b/configs/pg_wcom_seli8_update_defconfig
@@ -103,3 +103,4 @@ CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
 CONFIG_LZO=y
 CONFIG_POST=y
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/socfpga_secu1_defconfig b/configs/socfpga_secu1_defconfig
index 6a4106a559..0f8a65c42f 100644
--- a/configs/socfpga_secu1_defconfig
+++ b/configs/socfpga_secu1_defconfig
@@ -113,3 +113,4 @@ CONFIG_DESIGNWARE_WATCHDOG=y
 CONFIG_WDT=y
 CONFIG_SYS_TIMER_COUNTS_DOWN=y
 # CONFIG_GZIP is not set
+CONFIG_HUSH_OLD_PARSER=y
diff --git a/configs/tuge1_defconfig b/configs/tuge1_defconfig
index 9ff5d1599f..5c4d33235e 100644
--- a/configs/tuge1_defconfig
+++ b/configs/tuge1_defconfig
@@ -166,3 +166,4 @@ CONFIG_QE_UEC=y
 # CONFIG_PINCTRL_FULL is not set
 CONFIG_QE=y
 CONFIG_SYS_NS16550=y
+CONFIG_H

[PATCH v13 23/24] cmd: Set modern hush as default shell

2023-12-22 Thread Francis Laniel
Signed-off-by: Francis Laniel 
---
 cmd/Kconfig | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index e25578cde3..26ad03 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -27,21 +27,17 @@ depends on HUSH_PARSER
 
 config HUSH_OLD_PARSER
bool "Use hush old parser"
-   default y
help
  This option enables the old flavor of hush based on hush Busybox from
  2005.
 
- It is actually the default U-Boot shell when decided to use hush as 
shell.
-
 config HUSH_MODERN_PARSER
bool "Use hush modern parser"
+   default y
help
  This option enables the new flavor of hush based on hush upstream
  Busybox.
 
- This parser is experimental and not well tested.
-
 config HUSH_SELECTABLE
bool
default y if HUSH_OLD_PARSER && HUSH_MODERN_PARSER
-- 
2.34.1



[PATCH v13 22/24] cli: modern_hush: Add upstream commits up to 2nd October 2023.

2023-12-22 Thread Francis Laniel
This commit adds the following hush busybox upstream commits:
791b222dd55d ("sleep: fix "sleep -- ARGS"")
5353df91cba7 ("Update applet size estimates")
e41e481fd571 ("hush: fix a compile failure")
07a95cfcabb0 ("ash: disable check for "good" function name, bash does not check 
this")
e5692e2342c6 ("hush: quote values in "readonly" output")
96769486e20f ("shell: move varcmp() to shell_common.h and use it in hush")
bab8828b0dad ("hush: fix expansion of space in "a=${a:+$a }c" construct")
b5be8da350b5 ("hush: make "false" built-in")
6824298ab4d3 ("hush: fix ELIF cmd1;cmd2 THEN ... not executing cmd2, closes 
15571")
3a7f00eadcf4 ("hush: add comment about abort on syntax error %{^}")
acae889dd972 ("ash,hush: tab completion of functions and aliases")
90b607d79a13 ("hush: quote variable values printed by "set" (match ash 
behavior)")
6748e6494c22 ("hush (NOMMU): fix LINENO in execed children")
fd5fb2d2b596 ("hush: speed up "big heredoc" code")
1409432d072e ("hush: add TODO comment")
93ae7464e6e4 ("hush: restore SIGHUP handling, this time explain why we do what 
we do")
1fdb33bd07e5 ("hush: restore tty pgrp on SIGHUP")
6101b6d3eaa0 ("hush: remove special handling of SIGHUP")
93e0898c663a ("shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line 
input, closes 15256")
969e00816835 ("hush: code shrink")
27be0e8cfeb6 ("shell: fix compile failures in some configs")
7d1c7d833785 ("ash,hush: use HOME for tab completion and prompts")
21afddefd258 ("hush: fix "error: invalid preprocessing directive ##"")
e53c7dbafc78 ("hush: fix set -n to act immediately, not just after run_list()")
574b9c446da1 ("hush: fix var_LINENO3.tests failure")
49bcf9f40cff ("hush: speed up ${x//\*/|} too")
53b2fdcdba4c ("*: add NOINLINEs where code noticeably shrinks")
7c3e96d4b3d4 ("shell: use more compact SHELL_ASH / HUSH config defines. no code 
changes")
62f1eed1e191 ("hush: in a comment, document what -i might be doing")
aaf3d5ba74c5 ("shell: tweak --help")
db5546ca1018 ("libbb: code shrink: introduce and use [_]exit_SUCCESS()")
931c55f9e2b4 ("libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> 
SETUP_ENV_CHDIR")
12566e7f9b5e ("ash,hush: fix handling of SIGINT while waiting for interactive 
input")
987be932ed3c ("*: slap on a few ALIGN_PTR where appropriate")

Signed-off-by: Francis Laniel 
---
 common/cli_hush_modern.c   |  20 +-
 common/cli_hush_upstream.c | 407 ++---
 2 files changed, 304 insertions(+), 123 deletions(-)

diff --git a/common/cli_hush_modern.c b/common/cli_hush_modern.c
index fb578c3853..9a1bc977d5 100644
--- a/common/cli_hush_modern.c
+++ b/common/cli_hush_modern.c
@@ -26,7 +26,7 @@
 /*
  * BusyBox Version: UPDATE THIS WHEN PULLING NEW UPSTREAM REVISION!
  */
-#define BB_VER "1.34.0.git37460f5daff9"
+#define BB_VER "1.35.0.git7d1c7d833785"
 
 /*
  * Define hush features by the names used upstream.
@@ -236,6 +236,24 @@ static size_t list_size(char **list)
return size;
 }
 
+static int varcmp(const char *p, const char *q)
+{
+   int c, d;
+
+   while ((c = *p) == (d = *q)) {
+   if (c == '\0' || c == '=')
+   goto out;
+   p++;
+   q++;
+   }
+   if (c == '=')
+   c = '\0';
+   if (d == '=')
+   d = '\0';
+out:
+   return c - d;
+}
+
 struct in_str;
 static int u_boot_cli_readline(struct in_str *i);
 
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 748edc9d2f..ca40bbb2cd 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -91,7 +91,7 @@
  * in word = GLOB, quoting should be significant on char-by-char basis: a*cd"*"
  */
 //config:config HUSH
-//config:  bool "hush (68 kb)"
+//config:  bool "hush (70 kb)"
 //config:  default y
 //config:  select SHELL_HUSH
 //config:  help
@@ -339,7 +339,7 @@
  * therefore we don't show them either.
  */
 //usage:#define hush_trivial_usage
-//usage:   "[-enxl] [-c 'SCRIPT' [ARG0 ARGS] | FILE [ARGS] | -s [ARGS]]"
+//usage:   "[-enxl] [-c 'SCRIPT' [ARG0 ARGS] | FILE ARGS | -s ARGS]"
 //usage:#define hush_full_usage "\n\n"
 //usage:   "Unix shell interpreter"
 
@@ -374,7 +374,7 @@
 # define F_DUPFD_CLOEXEC F_DUPFD
 #endif
 
-#if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS && !(ENABLE_ASH || ENABLE_SH_IS_ASH || 
ENABLE_BASH_IS_ASH)
+#if ENABLE_FEATURE_SH_EMBEDDED_SCRIPTS && !ENABLE_SHELL_ASH
 # include "embedded_scripts.h"
 #else
 # define NUM_SCRIPTS 0
@@ -573,7 +573,7 @@ enum {
 #define NULL_O_STRING { NULL }
 
 #ifndef debug_printf_parse
-static const char *const assignment_flag[] = {
+static const char *const assignment_flag[] ALIGN_PTR = {
"MAYBE_ASSIGNMENT",
"DEFINITELY_ASSIGNMENT",
"NOT_ASSIGNMENT",
@@ -957,6 +957,7 @@ struct globals {
 #if ENABLE_HUSH_INTERACTIVE
smallint promptmode; /* 0: PS1, 1: PS2 */
 #endif
+   /* set by signal handler if SIGINT is received _and_ its trap is not 
set */
smal

[PATCH v13 21/24] test: hush: Fix loop tests for modern hush

2023-12-22 Thread Francis Laniel
Modifies return code got from while loop as modern hush always returns 0 from
while loop.

Reviewed-by: Simon Glass 
Signed-off-by: Francis Laniel 
---
 test/hush/loop.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/test/hush/loop.c b/test/hush/loop.c
index ca777e38fe..80a9071a80 100644
--- a/test/hush/loop.c
+++ b/test/hush/loop.c
@@ -9,6 +9,9 @@
 #include 
 #include 
 #include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
 
 static int hush_test_for(struct unit_test_state *uts)
 {
@@ -21,7 +24,12 @@ static int hush_test_for(struct unit_test_state *uts)
ut_assert_nextline("quux");
ut_assert_console_end();
 
-   puts("Beware: this test set local variable loop_i and it cannot be 
unset!");
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /* Reset local variable. */
+   ut_assertok(run_command("loop_i=", 0));
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   puts("Beware: this test set local variable loop_i and it cannot 
be unset!");
+   }
 
return 0;
 }
@@ -31,12 +39,30 @@ static int hush_test_while(struct unit_test_state *uts)
 {
console_record_reset_enable();
 
-   /* Exit status is that of test, so 1 since test is false to quit the 
loop. */
-   ut_asserteq(1, run_command("while test -z \"$loop_foo\"; do echo bar; 
loop_foo=quux; done", 0));
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /*
+* Hush 2021 always returns 0 from while loop...
+* You can see code snippet near this line to have a better
+* understanding:
+* debug_printf_exec(": while expr is false: breaking 
(exitcode:EXIT_SUCCESS)\n");
+*/
+   ut_assertok(run_command("while test -z \"$loop_foo\"; do echo 
bar; loop_foo=quux; done", 0));
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   /*
+* Exit status is that of test, so 1 since test is false to quit
+* the loop.
+*/
+   ut_asserteq(1, run_command("while test -z \"$loop_foo\"; do 
echo bar; loop_foo=quux; done", 0));
+   }
ut_assert_nextline("bar");
ut_assert_console_end();
 
-   puts("Beware: this test set local variable loop_foo and it cannot be 
unset!");
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /* Reset local variable. */
+   ut_assertok(run_command("loop_foo=", 0));
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   puts("Beware: this test set local variable loop_foo and it 
cannot be unset!");
+   }
 
return 0;
 }
-- 
2.34.1



[PATCH v13 20/24] cli: hush_modern: Enable loops

2023-12-22 Thread Francis Laniel
Enables the use of for, while and until loops for command line as
well as with run_command().

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 common/cli_hush_modern.c   |  1 +
 common/cli_hush_upstream.c | 15 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/common/cli_hush_modern.c b/common/cli_hush_modern.c
index 6360747f21..fb578c3853 100644
--- a/common/cli_hush_modern.c
+++ b/common/cli_hush_modern.c
@@ -34,6 +34,7 @@
 #define ENABLE_HUSH_INTERACTIVE1
 #define ENABLE_FEATURE_EDITING 1
 #define ENABLE_HUSH_IF 1
+#define ENABLE_HUSH_LOOPS  1
 /* No MMU in U-Boot */
 #define BB_MMU 0
 #define USE_FOR_NOMMU(...) __VA_ARGS__
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 06af538a48..748edc9d2f 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -10348,7 +10348,7 @@ static int run_list(struct pipe *pi)
 #ifndef __U_BOOT__
for (; pi; pi = IF_HUSH_LOOPS(rword == RES_DONE ? loop_top : ) 
pi->next) {
 #else /* __U_BOOT__ */
-   for (; pi; pi = pi->next) {
+   for (; pi; pi = rword == RES_DONE ? loop_top : pi->next) {
 #endif /* __U_BOOT__ */
int r;
int sv_errexit_depth;
@@ -10450,7 +10450,20 @@ static int run_list(struct pipe *pi)
}
/* Insert next value from for_lcur */
/* note: *for_lcur already has quotes removed, $var 
expanded, etc */
+#ifndef __U_BOOT__
set_local_var(xasprintf("%s=%s", pi->cmds[0].argv[0], 
*for_lcur++), /*flag:*/ 0);
+#else /* __U_BOOT__ */
+   /* We cannot use xasprintf, so we emulate it. */
+   char *full_var;
+   char *var = pi->cmds[0].argv[0];
+   char *val = *for_lcur++;
+
+   /* + 1 to take into account =. */
+   full_var = xmalloc(strlen(var) + strlen(val) + 1);
+   sprintf(full_var, "%s=%s", var, val);
+
+   set_local_var_modern(full_var, /*flag:*/ 0);
+#endif /* __U_BOOT__ */
continue;
}
if (rword == RES_IN) {
-- 
2.34.1



[PATCH v13 19/24] cli: hush_modern: Enable if keyword

2023-12-22 Thread Francis Laniel
Adds support for "if then else" construct both for command line interface and
through run_command().

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 common/cli_hush_modern.c   | 11 +++
 common/cli_hush_upstream.c | 12 
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/common/cli_hush_modern.c b/common/cli_hush_modern.c
index 15bb1f0d92..6360747f21 100644
--- a/common/cli_hush_modern.c
+++ b/common/cli_hush_modern.c
@@ -33,6 +33,7 @@
  */
 #define ENABLE_HUSH_INTERACTIVE1
 #define ENABLE_FEATURE_EDITING 1
+#define ENABLE_HUSH_IF 1
 /* No MMU in U-Boot */
 #define BB_MMU 0
 #define USE_FOR_NOMMU(...) __VA_ARGS__
@@ -124,6 +125,11 @@ static void bb_error_msg(const char *s, ...)
va_end(p);
 }
 
+static void bb_simple_error_msg(const char *s)
+{
+   bb_error_msg("%s", s);
+}
+
 static void *xmalloc(size_t size)
 {
void *p = NULL;
@@ -147,6 +153,11 @@ static void *xrealloc(void *ptr, size_t size)
return p;
 }
 
+static void *xmemdup(const void *s, int n)
+{
+   return memcpy(xmalloc(n), s, n);
+}
+
 #define xstrdupstrdup
 #define xstrndup   strndup
 
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index a56ea6c5c8..06af538a48 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -1487,7 +1487,6 @@ static void msg_and_die_if_script(unsigned lineno, const 
char *fmt, ...)
die_if_script();
 }
 
-#ifndef __U_BOOT__
 static void syntax_error(unsigned lineno UNUSED_PARAM, const char *msg)
 {
if (msg)
@@ -1496,7 +1495,6 @@ static void syntax_error(unsigned lineno UNUSED_PARAM, 
const char *msg)
bb_simple_error_msg("syntax error");
die_if_script();
 }
-#endif /* !__U_BOOT__ */
 
 static void syntax_error_at(unsigned lineno UNUSED_PARAM, const char *msg)
 {
@@ -3961,7 +3959,6 @@ static void debug_print_tree(struct pipe *pi, int lvl)
[PIPE_OR ] = "OR" ,
[PIPE_BG ] = "BG" ,
};
-#ifndef __U_BOOT__
static const char *RES[] = {
[RES_NONE ] = "NONE" ,
 # if ENABLE_HUSH_IF
@@ -3991,7 +3988,6 @@ static void debug_print_tree(struct pipe *pi, int lvl)
[RES_ ] = "" ,
[RES_SNTX ] = "SNTX" ,
};
-#endif /* !__U_BOOT__ */
static const char *const CMDTYPE[] = {
"{}",
"()",
@@ -4009,10 +4005,8 @@ static void debug_print_tree(struct pipe *pi, int lvl)
lvl*2, "",
pin,
pi->num_cmds,
-#ifdef __U_BOOT__
(IF_HAS_KEYWORDS(pi->pi_inverted ? "! " :) ""),
RES[pi->res_word],
-#endif /* !__U_BOOT__ */
pi->followup, PIPE[pi->followup]
);
prn = 0;
@@ -9832,6 +9826,7 @@ static NOINLINE int run_pipe(struct pipe *pi)
rcode = 1; /* exitcode if redir failed */
 #ifndef __U_BOOT__
if (setup_redirects(command, &squirrel) == 0) {
+#endif /* !__U_BOOT__ */
debug_printf_exec(": run_list\n");
 //FIXME: we need to pass squirrel down into run_list()
 //for SH_STANDALONE case, or else this construct:
@@ -9840,10 +9835,11 @@ static NOINLINE int run_pipe(struct pipe *pi)
 //and in SH_STANDALONE mode, "find" is not execed,
 //therefore CLOEXEC on saved fd does not help.
rcode = run_list(command->group) & 0xff;
+#ifndef __U_BOOT__
}
restore_redirects(squirrel);
-   IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;)
 #endif /* !__U_BOOT__ */
+   IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;)
debug_leave();
debug_printf_exec("run_pipe: return %d\n", rcode);
return rcode;
@@ -10362,12 +10358,12 @@ static int run_list(struct pipe *pi)
break;
if (G_flag_return_in_progress == 1)
break;
+#endif /* !__U_BOOT__ */
 
IF_HAS_KEYWORDS(rword = pi->res_word;)
debug_printf_exec(": rword=%d cond_code=%d last_rword=%d\n",
rword, cond_code, last_rword);
 
-#endif /* !__U_BOOT__ */
sv_errexit_depth = G.errexit_depth;
if (
 #if ENABLE_HUSH_IF
-- 
2.34.1



[PATCH v13 18/24] cli: hush_modern: Enable using < and > as string compare operators

2023-12-22 Thread Francis Laniel
In Busybox hush, '<' and '>' are used as redirection operators.
For example, cat foo > bar will write content of file foo inside file bar.
In U-Boot, we do not have file system, so we can hardly redirect command output
inside a file.

But, in actual U-Boot hush, these operators ('<' and '>') are used as string
compare operators.
For example, test aaa < bbb returns 0 as aaa is before bbb in the dictionary.
Busybox hush also permits this, but operators need to be escaped ('\<' and
'\>').
Indeed, if escaping is needed it permits the developer to think about its code,
as in a lot of case, we want to compare integers (using '-lt' or '-gt') rather
than strings.

As testing in U-Boot is handled by the test command, we will stick with the
original behaviour and not adapt to Busybox one.

Nonetheless, if one day we decide to implement test with '[[ ]]', we will then
stick to upstream Busybox behavior.

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 common/cli_hush_upstream.c | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 11870c51e8..a56ea6c5c8 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -6159,7 +6159,28 @@ static struct pipe *parse_stream(char **pstring,
if (parse_redirect(&ctx, redir_fd, redir_style, input))
goto parse_error_exitcode1;
continue; /* get next char */
-#endif /* !__U_BOOT__ */
+#else /* __U_BOOT__ */
+   /*
+* In U-Boot, '<' and '>' can be used in test command 
to test if
+* a string is, alphabetically, before or after another.
+* In 2021 Busybox hush, we will keep the same behavior 
and so not treat
+* them as redirection operator.
+*
+* Indeed, in U-Boot, tests are handled by the test 
command and not by the
+* shell code.
+* So, better to give this character as input to test 
command.
+*
+* NOTE In my opinion, when you use '<' or '>' I am 
almost sure
+* you wanted to use "-gt" or "-lt" in place, so 
thinking to
+* escape these will make you should check your code 
(sh syntax
+* at this level is, for me, error prone).
+*/
+   case '>':
+   fallthrough;
+   case '<':
+   o_addQchr(&ctx.word, ch);
+   continue;
+#endif /* __U_BOOT__ */
case '#':
if (ctx.word.length == 0 && !ctx.word.has_quoted_part) {
/* skip "#comment" */
-- 
2.34.1



[PATCH v13 17/24] test: hush: Fix variable expansion tests for modern hush

2023-12-22 Thread Francis Laniel
Modifies the expected result for modern hush.
Indeed, there were bugs in actual U-Boot hush which were fixed in upstream
Busybox.
As modern hush is based on upstream Busybox, these bugs no longer exist.

Reviewed-by: Simon Glass 
Signed-off-by: Francis Laniel 
---
 test/hush/dollar.c | 79 --
 1 file changed, 69 insertions(+), 10 deletions(-)

diff --git a/test/hush/dollar.c b/test/hush/dollar.c
index defb2c3fd0..7ab7ea7084 100644
--- a/test/hush/dollar.c
+++ b/test/hush/dollar.c
@@ -9,6 +9,9 @@
 #include 
 #include 
 #include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
 
 static int hush_test_simple_dollar(struct unit_test_state *uts)
 {
@@ -51,13 +54,29 @@ static int hush_test_simple_dollar(struct unit_test_state 
*uts)
ut_asserteq(1, run_command("dollar_foo='bar quux", 0));
/* Next line contains error message */
ut_assert_skipline();
-   ut_assert_console_end();
+
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /*
+* For some strange reasons, the console is not empty after
+* running above command.
+* So, we reset it to not have side effects for other tests.
+*/
+   console_record_reset_enable();
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   ut_assert_console_end();
+   }
 
ut_asserteq(1, run_command("dollar_foo=bar quux\"", 0));
/* Two next lines contain error message */
ut_assert_skipline();
ut_assert_skipline();
-   ut_assert_console_end();
+
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /* See above comments. */
+   console_record_reset_enable();
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   ut_assert_console_end();
+   }
 
ut_assertok(run_command("dollar_foo='bar \"quux'", 0));
 
@@ -71,17 +90,35 @@ static int hush_test_simple_dollar(struct unit_test_state 
*uts)
 */
console_record_reset_enable();
 
-   ut_asserteq(1, run_command("dollar_foo=\"bar 'quux\"", 0));
-   /* Next line contains error message */
-   ut_assert_skipline();
-   ut_assert_console_end();
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /*
+* Old parser returns an error because it waits for closing
+* '\'', but this behavior is wrong as the '\'' is surrounded by
+* '"', so no need to wait for a closing one.
+*/
+   ut_assertok(run_command("dollar_foo=\"bar 'quux\"", 0));
+
+   ut_assertok(run_command("echo $dollar_foo", 0));
+   ut_assert_nextline("bar 'quux");
+   ut_assert_console_end();
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   ut_asserteq(1, run_command("dollar_foo=\"bar 'quux\"", 0));
+   /* Next line contains error message */
+   ut_assert_skipline();
+   ut_assert_console_end();
+   }
 
ut_assertok(run_command("dollar_foo='bar quux'", 0));
ut_assertok(run_command("echo $dollar_foo", 0));
ut_assert_nextline("bar quux");
ut_assert_console_end();
 
-   puts("Beware: this test set local variable dollar_foo and it cannot be 
unset!");
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /* Reset local variable. */
+   ut_assertok(run_command("dollar_foo=", 0));
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   puts("Beware: this test set local variable dollar_foo and it 
cannot be unset!");
+   }
 
return 0;
 }
@@ -109,7 +146,12 @@ static int hush_test_env_dollar(struct unit_test_state 
*uts)
/* Clean up setting the variable */
env_set("env_foo", NULL);
 
-   puts("Beware: this test set local variable env_foo and it cannot be 
unset!");
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /* Reset local variable. */
+   ut_assertok(run_command("env_foo=", 0));
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   puts("Beware: this test set local variable env_foo and it 
cannot be unset!");
+   }
 
return 0;
 }
@@ -144,7 +186,18 @@ static int hush_test_command_dollar(struct unit_test_state 
*uts)
ut_assertok(run_command("dollar_bar='echo bar\\n'", 0));
 
ut_assertok(run_command("$dollar_bar", 0));
-   ut_assert_nextline("barn");
+
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /*
+* This difference seems to come from a bug solved in Busybox
+* hush.
+* Behavior of hush 2021 is coherent with bash and other shells.
+*/
+   ut_assert_nextline("bar\\n");
+   } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   ut_assert_nextline("barn");
+   }
+
ut_assert_console_end();
 
ut_

[PATCH v13 16/24] test: hush: Fix instructions list tests for modern hush

2023-12-22 Thread Francis Laniel
Modifies the expected result for modern hush.
Indeed, there were bugs in actual U-Boot hush which were fixed in upstream
Busybox.
As modern hush is based on upstream Busybox, these bugs no longer exist.

Reviewed-by: Simon Glass 
Signed-off-by: Francis Laniel 
---
 test/hush/list.c | 69 +---
 1 file changed, 65 insertions(+), 4 deletions(-)

diff --git a/test/hush/list.c b/test/hush/list.c
index 052cf2783c..73ae36e88f 100644
--- a/test/hush/list.c
+++ b/test/hush/list.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static int hush_test_semicolon(struct unit_test_state *uts)
 {
@@ -46,12 +47,43 @@ static int hush_test_or(struct unit_test_state *uts)
 }
 HUSH_TEST(hush_test_or, 0);
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static int hush_test_and_or(struct unit_test_state *uts)
 {
/* A && B || C truth table. */
ut_asserteq(1, run_command("false && false || false", 0));
-   ut_asserteq(1, run_command("false && false || true", 0));
-   ut_asserteq(1, run_command("false && true || true", 0));
+
+   if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   ut_asserteq(1, run_command("false && false || true", 0));
+   } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /*
+* This difference seems to come from a bug solved in Busybox
+* hush.
+*
+* Indeed, the following expression can be seen like this:
+* (false && false) || true
+* So, (false && false) returns 1, the second false is not
+* executed, and true is executed because of ||.
+*/
+   ut_assertok(run_command("false && false || true", 0));
+   }
+
+   if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   ut_asserteq(1, run_command("false && true || true", 0));
+   } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /*
+* This difference seems to come from a bug solved in Busybox
+* hush.
+*
+* Indeed, the following expression can be seen like this:
+* (false && true) || true
+* So, (false && true) returns 1, the true is not executed, and
+* true is executed because of ||.
+*/
+   ut_assertok(run_command("false && true || true", 0));
+   }
+
ut_asserteq(1, run_command("false && true || false", 0));
ut_assertok(run_command("true && true || false", 0));
ut_asserteq(1, run_command("true && false || false", 0));
@@ -69,8 +101,37 @@ static int hush_test_or_and(struct unit_test_state *uts)
ut_asserteq(1, run_command("false || false && true", 0));
ut_assertok(run_command("false || true && true", 0));
ut_asserteq(1, run_command("false || true && false", 0));
-   ut_assertok(run_command("true || true && false", 0));
-   ut_assertok(run_command("true || false && false", 0));
+
+   if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   ut_assertok(run_command("true || true && false", 0));
+   } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /*
+* This difference seems to come from a bug solved in Busybox
+* hush.
+*
+* Indeed, the following expression can be seen like this:
+* (true || true) && false
+* So, (true || true) returns 0, the second true is not
+* executed, and then false is executed because of &&.
+*/
+   ut_asserteq(1, run_command("true || true && false", 0));
+   }
+
+   if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   ut_assertok(run_command("true || false && false", 0));
+   } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) {
+   /*
+* This difference seems to come from a bug solved in Busybox
+* hush.
+*
+* Indeed, the following expression can be seen like this:
+* (true || false) && false
+* So, (true || false) returns 0, the false is not executed, and
+* then false is executed because of &&.
+*/
+   ut_asserteq(1, run_command("true || false && false", 0));
+   }
+
ut_assertok(run_command("true || false && true", 0));
ut_assertok(run_command("true || true && true", 0));
 
-- 
2.34.1



[PATCH v13 15/24] cli: add modern hush as parser for run_command*()

2023-12-22 Thread Francis Laniel
Enables using, in code, modern hush as parser for run_command function family.
It also enables the command run to be used by CLI user of modern hush.

Reviewed-by: Simon Glass 
Signed-off-by: Francis Laniel 
---
 common/cli.c   | 67 --
 common/cli_hush_upstream.c |  2 +-
 test/boot/bootflow.c   | 16 -
 3 files changed, 66 insertions(+), 19 deletions(-)

diff --git a/common/cli.c b/common/cli.c
index b3eb512b62..a34938294e 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -25,6 +25,14 @@
 #include 
 
 #ifdef CONFIG_CMDLINE
+
+static inline bool use_hush_old(void)
+{
+   return IS_ENABLED(CONFIG_HUSH_SELECTABLE) ?
+   gd->flags & GD_FLG_HUSH_OLD_PARSER :
+   IS_ENABLED(CONFIG_HUSH_OLD_PARSER);
+}
+
 /*
  * Run a command using the selected parser.
  *
@@ -43,15 +51,30 @@ int run_command(const char *cmd, int flag)
return 1;
 
return 0;
-#elif CONFIG_IS_ENABLED(HUSH_OLD_PARSER)
-   int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP;
-
-   if (flag & CMD_FLAG_ENV)
-   hush_flags |= FLAG_CONT_ON_NEWLINE;
-   return parse_string_outer(cmd, hush_flags);
-#else /* HUSH_MODERN_PARSER */
-   /* Not yet implemented. */
-   return 1;
+#else
+   if (use_hush_old()) {
+   int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP;
+
+   if (flag & CMD_FLAG_ENV)
+   hush_flags |= FLAG_CONT_ON_NEWLINE;
+   return parse_string_outer(cmd, hush_flags);
+   }
+   /*
+* Possible values for flags are the following:
+* FLAG_EXIT_FROM_LOOP: This flags ensures we exit from loop in
+* parse_and_run_stream() after first iteration while normal
+* behavior, * i.e. when called from cli_loop(), is to loop
+* infinitely.
+* FLAG_PARSE_SEMICOLON: modern Hush parses ';' and does not stop
+* first time it sees one. So, I think we do not need this flag.
+* FLAG_REPARSING: For the moment, I do not understand the goal
+* of this flag.
+* FLAG_CONT_ON_NEWLINE: This flag seems to be used to continue
+* parsing even when reading '\n' when coming from
+* run_command(). In this case, modern Hush reads until it finds
+* '\0'. So, I think we do not need this flag.
+*/
+   return parse_string_outer_modern(cmd, FLAG_EXIT_FROM_LOOP);
 #endif
 }
 
@@ -67,12 +90,23 @@ int run_command_repeatable(const char *cmd, int flag)
 #ifndef CONFIG_HUSH_PARSER
return cli_simple_run_command(cmd, flag);
 #else
+   int ret;
+
+   if (use_hush_old()) {
+   ret = parse_string_outer(cmd,
+FLAG_PARSE_SEMICOLON
+| FLAG_EXIT_FROM_LOOP);
+   } else {
+   ret = parse_string_outer_modern(cmd,
+ FLAG_PARSE_SEMICOLON
+ | FLAG_EXIT_FROM_LOOP);
+   }
+
/*
 * parse_string_outer() returns 1 for failure, so clean up
 * its result.
 */
-   if (parse_string_outer(cmd,
-  FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP))
+   if (ret)
return -1;
 
return 0;
@@ -111,12 +145,11 @@ int run_command_list(const char *cmd, int len, int flag)
buff[len] = '\0';
}
 #ifdef CONFIG_HUSH_PARSER
-#if CONFIG_IS_ENABLED(HUSH_OLD_PARSER)
-   rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON);
-#else /* HUSH_MODERN_PARSER */
-   /* Not yet implemented. */
-   rcode = 1;
-#endif
+   if (use_hush_old()) {
+   rcode = parse_string_outer(buff, FLAG_PARSE_SEMICOLON);
+   } else {
+   rcode = parse_string_outer_modern(buff, FLAG_PARSE_SEMICOLON);
+   }
 #else
/*
 * This function will overwrite any \n it sees with a \0, which
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 7f6b058e6c..11870c51e8 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -8022,7 +8022,7 @@ static int parse_and_run_string(const char *s)
 }
 
 #ifdef __U_BOOT__
-int parse_string_outer(const char *cmd, int flags)
+int parse_string_outer_modern(const char *cmd, int flags)
 {
int ret;
int old_flags;
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index a9b555c779..104f49deef 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -710,7 +710,21 @@ static int bootflow_scan_menu_boot(struct unit_test_state 
*uts)
ut_assert_skip_to_line("(2 bootflows, 2 valid)");
 
ut_assert_nextline("Selected: Armbian");
-   ut_assert_skip_to_line("Boot failed (err=-14)");
+
+   if (gd->flags & GD_FLG_HUSH_OLD_PARSER) {
+   /*
+* With old hush, despite booti failing to boot, i.e. returning
+* CMD_RET_FAILURE, run_c

[PATCH v13 13/24] cli: hush_modern: Enable variables expansion for modern hush

2023-12-22 Thread Francis Laniel
Enables variables expansion for modern hush, both for local and environment
variables.
So the following commands:
foo=bar
echo $foo
setenv bar foo
echo $bar
leads to "bar" and "foo" being printed on console output.

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 common/cli_hush_modern.c   | 17 +++
 common/cli_hush_upstream.c | 91 +++---
 2 files changed, 103 insertions(+), 5 deletions(-)

diff --git a/common/cli_hush_modern.c b/common/cli_hush_modern.c
index 626fed089b..15bb1f0d92 100644
--- a/common/cli_hush_modern.c
+++ b/common/cli_hush_modern.c
@@ -207,6 +207,23 @@ static const char* endofname(const char *name)
return name;
 }
 
+/**
+ * list_size() - returns the number of elements in char ** before NULL.
+ *
+ * Argument must contain NULL to signalize its end.
+ *
+ * @list The list to count the number of element.
+ * @return The number of element in list.
+ */
+static size_t list_size(char **list)
+{
+   size_t size;
+
+   for (size = 0; list[size] != NULL; size++);
+
+   return size;
+}
+
 struct in_str;
 static int u_boot_cli_readline(struct in_str *i);
 
diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 4b6ab20f3b..ff4a57c6e3 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -3485,7 +3485,6 @@ static int o_get_last_ptr(o_string *o, int n)
return ((int)(uintptr_t)list[n-1]) + string_start;
 }
 
-#ifndef __U_BOOT__
 /*
  * Globbing routines.
  *
@@ -3740,8 +3739,10 @@ static int glob_needed(const char *s)
  */
 static int perform_glob(o_string *o, int n)
 {
+#ifndef __U_BOOT__
glob_t globdata;
int gr;
+#endif /* __U_BOOT__ */
char *pattern;
 
debug_printf_glob("start perform_glob: n:%d o->data:%p\n", n, o->data);
@@ -3750,13 +3751,16 @@ static int perform_glob(o_string *o, int n)
pattern = o->data + o_get_last_ptr(o, n);
debug_printf_glob("glob pattern '%s'\n", pattern);
if (!glob_needed(pattern)) {
+#ifndef __U_BOOT__
  literal:
+#endif /* __U_BOOT__ */
/* unbackslash last string in o in place, fix length */
o->length = unbackslash(pattern) - o->data;
debug_printf_glob("glob pattern '%s' is literal\n", pattern);
return o_save_ptr_helper(o, n);
}
 
+#ifndef __U_BOOT__
memset(&globdata, 0, sizeof(globdata));
/* Can't use GLOB_NOCHECK: it does not unescape the string.
 * If we glob "*.\*" and don't find anything, we need
@@ -3792,16 +3796,22 @@ static int perform_glob(o_string *o, int n)
if (DEBUG_GLOB)
debug_print_list("perform_glob returning", o, n);
return n;
+#else /* __U_BOOT__ */
+   /*
+* NOTE We only use perform glob to call unbackslash to remove backslash
+* from string once expanded.
+* So, it seems OK to return this if no previous return was done.
+*/
+   return o_save_ptr_helper(o, n);
+#endif /* __U_BOOT__ */
 }
 
-#endif /* !__U_BOOT__ */
 #endif /* !HUSH_BRACE_EXPANSION */
 
 /* If o->o_expflags & EXP_FLAG_GLOB, glob the string so far remembered.
  * Otherwise, just finish current list[] and start new */
 static int o_save_ptr(o_string *o, int n)
 {
-#ifndef __U_BOOT__
if (o->o_expflags & EXP_FLAG_GLOB) {
/* If o->has_empty_slot, list[n] was already globbed
 * (if it was requested back then when it was filled)
@@ -3809,7 +3819,6 @@ static int o_save_ptr(o_string *o, int n)
if (!o->has_empty_slot)
return perform_glob(o, n); /* o_save_ptr_helper is 
inside */
}
-#endif /* !__U_BOOT__ */
return o_save_ptr_helper(o, n);
 }
 
@@ -5455,7 +5464,20 @@ static int parse_dollar(o_string *as_string,
nommu_addchr(as_string, ch);
if (ch == '}')
break;
+#ifndef __U_BOOT__
if (!isalnum(ch) && ch != '_') {
+#else /* __U_BOOT__ */
+   /*
+* In several places in U-Boot, we use variable like
+* foo# (e.g. serial#), particularly in env.
+* So, we need to authorize # to appear inside
+* variable name and then expand this variable.
+* NOTE Having # in variable name is not permitted in
+* upstream hush but expansion will be done (even though
+* the result will be empty).
+*/
+   if (!isalnum(ch) && ch != '_' && ch != '#') {
+#endif /* __U_BOOT__ */
unsigned end_ch;
 #ifndef __U_BOOT__
unsigned char last_ch;
@@ -7030,7 +7052,20 @@ static NOINLINE int expand_one_var(o_string *output, int 
n,
}
 #endif /* !__U_BOOT__ */
default:
+#ifndef __U_BOOT__

[PATCH v13 14/24] cli: hush_modern: Add functions to be called from run_command()

2023-12-22 Thread Francis Laniel
run_command() is called internally by the command run and it can also be called
directly from U-Boot code, e.g. to do unit tests.
This commit adds this path to go to modern hush.

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 common/cli_hush_upstream.c | 66 --
 1 file changed, 63 insertions(+), 3 deletions(-)

diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index ff4a57c6e3..7f6b058e6c 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -1011,6 +1011,7 @@ struct globals {
 #ifdef __U_BOOT__
int flag_repeat;
int do_repeat;
+   int run_command_flags;
 #endif /* __U_BOOT__ */
char *ifs_whitespace; /* = G.ifs or malloced */
 #ifndef __U_BOOT__
@@ -3004,7 +3005,24 @@ static int i_getch(struct in_str *i)
if (i->p && *i->p != '\0') {
ch = (unsigned char)*i->p++;
goto out;
+#ifndef __U_BOOT__
}
+#else /* __U_BOOT__ */
+   /*
+* There are two ways for command to be called:
+* 1. The first one is when they are typed by the user.
+* 2. The second one is through run_command() (NOTE command run
+* internally calls run_command()).
+*
+* In the second case, we do not get input from the user, so once we
+* get a '\0', it means we need to stop.
+* NOTE G.run_command_flags is only set on run_command call stack, so
+* we use this to know if we come from user input or run_command().
+*/
+   } else if (i->p && *i->p == '\0' && G.run_command_flags){
+   return EOF;
+   }
+#endif /* __U_BOOT__ */
 #endif
 #ifndef __U_BOOT__
/* peek_buf[] is an int array, not char. Can contain EOF. */
@@ -3163,7 +3181,6 @@ static void setup_file_in_str(struct in_str *i)
 #endif /* !__U_BOOT__ */
 }
 
-#ifndef __U_BOOT__
 static void setup_string_in_str(struct in_str *i, const char *s)
 {
memset(i, 0, sizeof(*i));
@@ -3171,7 +3188,6 @@ static void setup_string_in_str(struct in_str *i, const 
char *s)
i->p = s;
 }
 
-#endif /* !__U_BOOT__ */
 
 /*
  * o_string support
@@ -7910,7 +7926,11 @@ static int run_and_free_list(struct pipe *pi);
  * NUL: parse all, execute, return
  * ';': parse till ';' or newline, execute, repeat till EOF
  */
+#ifndef __U_BOOT__
 static void parse_and_run_stream(struct in_str *inp, int end_trigger)
+#else /* __U_BOOT__ */
+static int parse_and_run_stream(struct in_str *inp, int end_trigger)
+#endif /* __U_BOOT__ */
 {
/* Why we need empty flag?
 * An obscure corner case "false; ``; echo $?":
@@ -7919,7 +7939,11 @@ static void parse_and_run_stream(struct in_str *inp, int 
end_trigger)
 * this breaks "false; echo `echo $?`" case.
 */
bool empty = 1;
+#ifndef __U_BOOT__
while (1) {
+#else /* __U_BOOT__ */
+   do {
+#endif /* __U_BOOT__ */
struct pipe *pipe_list;
 
 #if ENABLE_HUSH_INTERACTIVE
@@ -7966,21 +7990,57 @@ static void parse_and_run_stream(struct in_str *inp, 
int end_trigger)
empty = 0;
if (G_flag_return_in_progress == 1)
break;
+#ifndef __U_BOOT__
}
+#else /* __U_BOOT__ */
+   /*
+* This do/while is needed by run_command to avoid looping on a command
+* with syntax error.
+*/
+   } while (!(G.run_command_flags & FLAG_EXIT_FROM_LOOP));
+
+   return G.last_exitcode;
+#endif /* __U_BOOT__ */
 }
 
 #ifndef __U_BOOT__
 static void parse_and_run_string(const char *s)
+#else /* __U_BOOT__ */
+static int parse_and_run_string(const char *s)
+#endif /* __U_BOOT__ */
 {
struct in_str input;
//IF_HUSH_LINENO_VAR(unsigned sv = G.parse_lineno;)
 
setup_string_in_str(&input, s);
+#ifndef __U_BOOT__
parse_and_run_stream(&input, '\0');
+#else /* __U_BOOT__ */
+   return parse_and_run_stream(&input, '\0');
+#endif /* __U_BOOT__ */
//IF_HUSH_LINENO_VAR(G.parse_lineno = sv;)
 }
-#endif /* !__U_BOOT__ */
 
+#ifdef __U_BOOT__
+int parse_string_outer(const char *cmd, int flags)
+{
+   int ret;
+   int old_flags;
+
+   /*
+* Keep old values of run_command to be able to restore them once
+* command was executed.
+*/
+   old_flags = G.run_command_flags;
+   G.run_command_flags = flags;
+
+   ret = parse_and_run_string(cmd);
+
+   G.run_command_flags = old_flags;
+
+   return ret;
+}
+#endif /* __U_BOOT__ */
 #ifndef __U_BOOT__
 static void parse_and_run_file(HFILE *fp)
 #else /* __U_BOOT__ */
-- 
2.34.1



[PATCH v13 12/24] cli: Enables using modern hush parser as command line parser

2023-12-22 Thread Francis Laniel
If one defines HUSH_MODERN_PARSER, it is then possible to use modern parser 
with:
=> cli get
old
=> cli set modern
=> cli get
modern

Reviewed-by: Simon Glass 
Signed-off-by: Francis Laniel 
---
 cmd/Kconfig   | 12 
 cmd/Makefile  |  2 +-
 cmd/cli.c | 28 ++---
 common/Makefile   |  1 +
 common/cli.c  | 38 +++
 common/cli_hush_modern.c  |  3 ++
 common/cli_hush_upstream.c| 46 +---
 doc/usage/cmd/cli.rst | 19 ++--
 include/asm-generic/global_data.h |  4 +++
 include/cli_hush.h| 51 +--
 10 files changed, 184 insertions(+), 20 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 15715ac6ad..e25578cde3 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -33,6 +33,18 @@ config HUSH_OLD_PARSER
  2005.
 
  It is actually the default U-Boot shell when decided to use hush as 
shell.
+
+config HUSH_MODERN_PARSER
+   bool "Use hush modern parser"
+   help
+ This option enables the new flavor of hush based on hush upstream
+ Busybox.
+
+ This parser is experimental and not well tested.
+
+config HUSH_SELECTABLE
+   bool
+   default y if HUSH_OLD_PARSER && HUSH_MODERN_PARSER
 endmenu
 
 config CMDLINE_EDITING
diff --git a/cmd/Makefile b/cmd/Makefile
index 477b86cf23..e2a2b16ab2 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -229,7 +229,7 @@ obj-$(CONFIG_CMD_AVB) += avb.o
 # Foundries.IO SCP03
 obj-$(CONFIG_CMD_SCP03) += scp03.o
 
-obj-$(CONFIG_HUSH_PARSER) += cli.o
+obj-$(CONFIG_HUSH_SELECTABLE) += cli.o
 
 obj-$(CONFIG_ARM) += arm/
 obj-$(CONFIG_RISCV) += riscv/
diff --git a/cmd/cli.c b/cmd/cli.c
index 86c6471aa4..b93cc952ed 100644
--- a/cmd/cli.c
+++ b/cmd/cli.c
@@ -12,6 +12,8 @@ static const char *gd_flags_to_parser_name(void)
 {
if (gd->flags & GD_FLG_HUSH_OLD_PARSER)
return "old";
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER)
+   return "modern";
return NULL;
 }
 
@@ -34,18 +36,31 @@ static int parser_string_to_gd_flags(const char *parser)
 {
if (!strcmp(parser, "old"))
return GD_FLG_HUSH_OLD_PARSER;
+   if (!strcmp(parser, "modern"))
+   return GD_FLG_HUSH_MODERN_PARSER;
+   return -1;
+}
+
+static int gd_flags_to_parser_config(int flag)
+{
+   if (gd->flags & GD_FLG_HUSH_OLD_PARSER)
+   return CONFIG_VAL(HUSH_OLD_PARSER);
+   if (gd->flags & GD_FLG_HUSH_MODERN_PARSER)
+   return CONFIG_VAL(HUSH_MODERN_PARSER);
return -1;
 }
 
 static void reset_parser_gd_flags(void)
 {
gd->flags &= ~GD_FLG_HUSH_OLD_PARSER;
+   gd->flags &= ~GD_FLG_HUSH_MODERN_PARSER;
 }
 
 static int do_cli_set(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[])
 {
char *parser_name;
+   int parser_config;
int parser_flag;
 
if (argc < 2)
@@ -59,9 +74,14 @@ static int do_cli_set(struct cmd_tbl *cmdtp, int flag, int 
argc,
return CMD_RET_USAGE;
}
 
-   if (parser_flag == GD_FLG_HUSH_OLD_PARSER &&
-   !CONFIG_IS_ENABLED(HUSH_OLD_PARSER)) {
-   printf("Want to set current parser to old, but its code was not 
compiled!\n");
+   parser_config = gd_flags_to_parser_config(parser_flag);
+   switch (parser_config) {
+   case -1:
+   printf("Bad value for parser flags: %d\n", parser_flag);
+   return CMD_RET_FAILURE;
+   case 0:
+   printf("Want to set current parser to %s, but its code was not 
compiled!\n",
+   parser_name);
return CMD_RET_FAILURE;
}
 
@@ -102,7 +122,7 @@ static int do_cli(struct cmd_tbl *cmdtp, int flag, int argc,
 #if CONFIG_IS_ENABLED(SYS_LONGHELP)
 static char cli_help_text[] =
"get - print current cli\n"
-   "set - set the current cli, possible value is: old"
+   "set - set the current cli, possible value are: old, modern"
;
 #endif
 
diff --git a/common/Makefile b/common/Makefile
index 3bb33b4e36..f010c2a1b9 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -10,6 +10,7 @@ obj-y += main.o
 obj-y += exports.o
 obj-y += cli_getch.o cli_simple.o cli_readline.o
 obj-$(CONFIG_HUSH_OLD_PARSER) += cli_hush.o
+obj-$(CONFIG_HUSH_MODERN_PARSER) += cli_hush_modern.o
 obj-$(CONFIG_AUTOBOOT) += autoboot.o
 obj-y += version.o
 
diff --git a/common/cli.c b/common/cli.c
index d419671e8c..b3eb512b62 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -43,12 +43,15 @@ int run_command(const char *cmd, int flag)
return 1;
 
return 0;
-#else
+#elif CONFIG_IS_ENABLED(HUSH_OLD_PARSER)
int hush_flags = FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP;
 
if (flag & CMD_FLAG_ENV)
hush_flags |= FLAG_CONT_ON_NEWLINE;
return parse_string

[PATCH v13 11/24] cmd: Add new cli command

2023-12-22 Thread Francis Laniel
This command can be used to print the current parser with 'cli get'.
It can also be used to set the current parser with 'cli set'.
For the moment, only one value is valid for set: old.

Signed-off-by: Francis Laniel 
---
 cmd/Makefile  |   2 +
 cmd/cli.c | 114 ++
 common/cli.c  |   3 +-
 doc/usage/cmd/cli.rst |  59 ++
 doc/usage/index.rst   |   1 +
 5 files changed, 178 insertions(+), 1 deletion(-)
 create mode 100644 cmd/cli.c
 create mode 100644 doc/usage/cmd/cli.rst

diff --git a/cmd/Makefile b/cmd/Makefile
index 5ed0e4011d..477b86cf23 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -229,6 +229,8 @@ obj-$(CONFIG_CMD_AVB) += avb.o
 # Foundries.IO SCP03
 obj-$(CONFIG_CMD_SCP03) += scp03.o
 
+obj-$(CONFIG_HUSH_PARSER) += cli.o
+
 obj-$(CONFIG_ARM) += arm/
 obj-$(CONFIG_RISCV) += riscv/
 obj-$(CONFIG_SANDBOX) += sandbox/
diff --git a/cmd/cli.c b/cmd/cli.c
new file mode 100644
index 00..86c6471aa4
--- /dev/null
+++ b/cmd/cli.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static const char *gd_flags_to_parser_name(void)
+{
+   if (gd->flags & GD_FLG_HUSH_OLD_PARSER)
+   return "old";
+   return NULL;
+}
+
+static int do_cli_get(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   const char *current = gd_flags_to_parser_name();
+
+   if (!current) {
+   printf("current cli value is not valid, this should not 
happen!\n");
+   return CMD_RET_FAILURE;
+   }
+
+   printf("%s\n", current);
+
+   return CMD_RET_SUCCESS;
+}
+
+static int parser_string_to_gd_flags(const char *parser)
+{
+   if (!strcmp(parser, "old"))
+   return GD_FLG_HUSH_OLD_PARSER;
+   return -1;
+}
+
+static void reset_parser_gd_flags(void)
+{
+   gd->flags &= ~GD_FLG_HUSH_OLD_PARSER;
+}
+
+static int do_cli_set(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   char *parser_name;
+   int parser_flag;
+
+   if (argc < 2)
+   return CMD_RET_USAGE;
+
+   parser_name = argv[1];
+
+   parser_flag = parser_string_to_gd_flags(parser_name);
+   if (parser_flag == -1) {
+   printf("Bad value for parser name: %s\n", parser_name);
+   return CMD_RET_USAGE;
+   }
+
+   if (parser_flag == GD_FLG_HUSH_OLD_PARSER &&
+   !CONFIG_IS_ENABLED(HUSH_OLD_PARSER)) {
+   printf("Want to set current parser to old, but its code was not 
compiled!\n");
+   return CMD_RET_FAILURE;
+   }
+
+   reset_parser_gd_flags();
+   gd->flags |= parser_flag;
+
+   cli_init();
+   cli_loop();
+
+   /* cli_loop() should never return. */
+   return CMD_RET_FAILURE;
+}
+
+static struct cmd_tbl parser_sub[] = {
+   U_BOOT_CMD_MKENT(get, 1, 1, do_cli_get, "", ""),
+   U_BOOT_CMD_MKENT(set, 2, 1, do_cli_set, "", ""),
+};
+
+static int do_cli(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   struct cmd_tbl *cp;
+
+   if (argc < 2)
+   return CMD_RET_USAGE;
+
+   /* drop initial "parser" arg */
+   argc--;
+   argv++;
+
+   cp = find_cmd_tbl(argv[0], parser_sub, ARRAY_SIZE(parser_sub));
+   if (cp)
+   return cp->cmd(cmdtp, flag, argc, argv);
+
+   return CMD_RET_USAGE;
+}
+
+#if CONFIG_IS_ENABLED(SYS_LONGHELP)
+static char cli_help_text[] =
+   "get - print current cli\n"
+   "set - set the current cli, possible value is: old"
+   ;
+#endif
+
+U_BOOT_CMD(cli, 3, 1, do_cli,
+  "cli",
+#if CONFIG_IS_ENABLED(SYS_LONGHELP)
+  cli_help_text
+#endif
+);
diff --git a/common/cli.c b/common/cli.c
index e5fe1060d0..d419671e8c 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -268,7 +268,8 @@ void cli_loop(void)
 void cli_init(void)
 {
 #ifdef CONFIG_HUSH_PARSER
-   if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER))
+   if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER)
+   && CONFIG_IS_ENABLED(HUSH_OLD_PARSER))
gd->flags |= GD_FLG_HUSH_OLD_PARSER;
u_boot_hush_start();
 #endif
diff --git a/doc/usage/cmd/cli.rst b/doc/usage/cmd/cli.rst
new file mode 100644
index 00..89ece3203d
--- /dev/null
+++ b/doc/usage/cmd/cli.rst
@@ -0,0 +1,59 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+cli command
+===
+
+Synopis
+---
+
+::
+
+cli get
+cli set cli_flavor
+
+Description
+---
+
+The cli command permits getting and changing the current parser at runtime.
+
+cli get
+~~~
+
+It shows the current value of the parser used by the CLI.
+
+cli set
+~~~
+
+It permits setting the value of the parser used by the CLI.
+
+Possible values are old and 2021.
+Note that, to use a specific parser its code should have been compiled, that
+is to say y

[PATCH v13 10/24] global_data.h: add GD_FLG_HUSH_OLD_PARSER flag

2023-12-22 Thread Francis Laniel
This flag is used to indicate we are using the hush parser.

Reviewed-by: Simon Glass 
Signed-off-by: Francis Laniel 
---
 common/cli.c  | 2 ++
 include/asm-generic/global_data.h | 4 
 2 files changed, 6 insertions(+)

diff --git a/common/cli.c b/common/cli.c
index 3916a7b10a..e5fe1060d0 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -268,6 +268,8 @@ void cli_loop(void)
 void cli_init(void)
 {
 #ifdef CONFIG_HUSH_PARSER
+   if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER))
+   gd->flags |= GD_FLG_HUSH_OLD_PARSER;
u_boot_hush_start();
 #endif
 
diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index e8c6412e3f..0a9b6bd92a 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -697,6 +697,10 @@ enum gd_flags {
 * @GD_FLG_BLOBLIST_READY: bloblist is ready for use
 */
GD_FLG_BLOBLIST_READY = 0x80,
+   /**
+* @GD_FLG_HUSH_OLD_PARSER: Use hush old parser.
+*/
+   GD_FLG_HUSH_OLD_PARSER = 0x100,
 };
 
 #endif /* __ASSEMBLY__ */
-- 
2.34.1



[PATCH v13 08/24] cli: Port upstream Busybox hush to U-Boot

2023-12-22 Thread Francis Laniel
Adds new file cli_hush_upstream.c, it is a copy of Busybox hush file as it was 
of
time to commit 37460f5da.
This commit modifies Busybox hush to not compile some part specific to Busybox
and adds some code needed by U-Boot.
The modifications consists mainly on adding code #if(n)def guards.

For the moment, this refurbished flavor of hush only permits running command
without any keywords (i.e., if and for are not recognized) or variable expansion
(i.e., echo $foo prints foo and not value stored in variable foo).

A new file was also added to define some functions specific to U-Boot.

Signed-off-by: Francis Laniel 
Signed-off-by: Harald Seiler 
---
 common/cli_hush_modern.c   | 274 
 common/cli_hush_upstream.c | 502 -
 2 files changed, 774 insertions(+), 2 deletions(-)
 create mode 100644 common/cli_hush_modern.c

diff --git a/common/cli_hush_modern.c b/common/cli_hush_modern.c
new file mode 100644
index 00..34278fdca2
--- /dev/null
+++ b/common/cli_hush_modern.c
@@ -0,0 +1,274 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * This file defines the compilation unit for the new hush shell version.  The
+ * actual implementation from upstream BusyBox can be found in
+ * `cli_hush_upstream.c` which is included at the end of this file.
+ *
+ * This "wrapper" technique is used to keep the changes to the upstream version
+ * as minmal as possible.  Instead, all defines and redefines necessary are 
done
+ * here, outside the upstream sources.  This will hopefully make upgrades to
+ * newer revisions much easier.
+ *
+ * Copyright (c) 2021, Harald Seiler, DENX Software Engineering, h...@denx.de
+ */
+
+#include  /* readline */
+#include 
+#include  /* malloc, free, realloc*/
+#include /* isalpha, isdigit */
+#include 
+#include 
+#include 
+#include 
+#include /* find_cmd */
+#include 
+
+/*
+ * BusyBox Version: UPDATE THIS WHEN PULLING NEW UPSTREAM REVISION!
+ */
+#define BB_VER "1.34.0.git37460f5daff9"
+
+/*
+ * Define hush features by the names used upstream.
+ */
+#define ENABLE_HUSH_INTERACTIVE1
+#define ENABLE_FEATURE_EDITING 1
+/* No MMU in U-Boot */
+#define BB_MMU 0
+#define USE_FOR_NOMMU(...) __VA_ARGS__
+#define USE_FOR_MMU(...)
+
+/*
+ * Size-saving "small" ints (arch-dependent)
+ */
+#if CONFIG_IS_ENABLED(X86) || CONFIG_IS_ENABLED(X86_64) || 
CONFIG_IS_ENABLED(MIPS)
+/* add other arches which benefit from this... */
+typedef signed char smallint;
+typedef unsigned char smalluint;
+#else
+/* for arches where byte accesses generate larger code: */
+typedef int smallint;
+typedef unsigned smalluint;
+#endif
+
+/*
+ * Alignment defines used by BusyBox.
+ */
+#define ALIGN1 __attribute__((aligned(1)))
+#define ALIGN2 __attribute__((aligned(2)))
+#define ALIGN4 __attribute__((aligned(4)))
+#define ALIGN8 __attribute__((aligned(8)))
+#define ALIGN_PTR  __attribute__((aligned(sizeof(void*
+
+/*
+ * Miscellaneous compiler/platform defines.
+ */
+#define FAST_FUNC /* not used in U-Boot */
+#define UNUSED_PARAM   __always_unused
+#define ALWAYS_INLINE  __always_inline
+#define NOINLINE   noinline
+
+/*
+ * Defines to provide equivalents to what libc/BusyBox defines.
+ */
+#define EOF(-1)
+#define EXIT_SUCCESS   0
+#define EXIT_FAILURE   1
+
+/*
+ * Stubs to provide libc/BusyBox functions based on U-Boot equivalents where it
+ * makes sense.
+ */
+#define utoa   simple_itoa
+
+static void __noreturn xfunc_die(void)
+{
+   panic("HUSH died!");
+}
+
+#define bb_error_msg_and_die(format, ...) do { \
+panic("HUSH: " format, __VA_ARGS__); \
+} while (0);
+
+#define bb_simple_error_msg_and_die(msg) do { \
+panic_str("HUSH: " msg); \
+} while (0);
+
+/* fdprintf() is used for debug output. */
+static int __maybe_unused fdprintf(int fd, const char *format, ...)
+{
+   va_list args;
+   uint i;
+
+   assert(fd == 2);
+
+   va_start(args, format);
+   i = vprintf(format, args);
+   va_end(args);
+
+   return i;
+}
+
+static void bb_verror_msg(const char *s, va_list p, const char* strerr)
+{
+   /* TODO: what to do with strerr arg? */
+   vprintf(s, p);
+}
+
+static void bb_error_msg(const char *s, ...)
+{
+   va_list p;
+
+   va_start(p, s);
+   bb_verror_msg(s, p, NULL);
+   va_end(p);
+}
+
+static void *xmalloc(size_t size)
+{
+   void *p = NULL;
+   if (!(p = malloc(size)))
+   panic("out of memory");
+   return p;
+}
+
+static void *xzalloc(size_t size)
+{
+   void *p = xmalloc(size);
+   memset(p, 0, size);
+   return p;
+}
+
+static void *xrealloc(void *ptr, size_t size)
+{
+   void *p = NULL;
+   if (!(p = realloc(ptr, size)))
+   panic("out of memory");
+   return p;
+}
+
+#define xstrdupstrdup
+#

[PATCH v13 09/24] cli: Add menu for hush parser

2023-12-22 Thread Francis Laniel
For the moment, the menu contains only entry: HUSH_OLD_PARSER which is the
default.
The goal is to prepare the field to add a new hush parser which guarantees
actual behavior is still correct.

Reviewed-by: Simon Glass 
Signed-off-by: Francis Laniel 
---
 cmd/Kconfig | 13 +
 common/Makefile |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 5a7678f0ac..15715ac6ad 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -22,6 +22,19 @@ config HUSH_PARSER
  If disabled, you get the old, much simpler behaviour with a somewhat
  smaller memory footprint.
 
+menu "Hush flavor to use"
+depends on HUSH_PARSER
+
+config HUSH_OLD_PARSER
+   bool "Use hush old parser"
+   default y
+   help
+ This option enables the old flavor of hush based on hush Busybox from
+ 2005.
+
+ It is actually the default U-Boot shell when decided to use hush as 
shell.
+endmenu
+
 config CMDLINE_EDITING
bool "Enable command line editing"
default y
diff --git a/common/Makefile b/common/Makefile
index 1495436d5d..3bb33b4e36 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -9,7 +9,7 @@ obj-y += init/
 obj-y += main.o
 obj-y += exports.o
 obj-y += cli_getch.o cli_simple.o cli_readline.o
-obj-$(CONFIG_HUSH_PARSER) += cli_hush.o
+obj-$(CONFIG_HUSH_OLD_PARSER) += cli_hush.o
 obj-$(CONFIG_AUTOBOOT) += autoboot.o
 obj-y += version.o
 
-- 
2.34.1



[PATCH v13 06/24] test: hush: Test hush loops

2023-12-22 Thread Francis Laniel
The added tests verifies correct behavior of for, while and until loops.

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 test/hush/Makefile |  1 +
 test/hush/loop.c   | 65 ++
 2 files changed, 66 insertions(+)
 create mode 100644 test/hush/loop.c

diff --git a/test/hush/Makefile b/test/hush/Makefile
index ff4fe7700b..a2d98815e5 100644
--- a/test/hush/Makefile
+++ b/test/hush/Makefile
@@ -7,3 +7,4 @@ obj-y += cmd_ut_hush.o
 obj-y += if.o
 obj-y += dollar.o
 obj-y += list.o
+obj-y += loop.o
diff --git a/test/hush/loop.c b/test/hush/loop.c
new file mode 100644
index 00..ca777e38fe
--- /dev/null
+++ b/test/hush/loop.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) Copyright 2021
+ * Francis Laniel, Amarula Solutions, francis.lan...@amarulasolutions.com
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int hush_test_for(struct unit_test_state *uts)
+{
+   console_record_reset_enable();
+
+   ut_assertok(run_command("for loop_i in foo bar quux quux; do echo 
$loop_i; done", 0));
+   ut_assert_nextline("foo");
+   ut_assert_nextline("bar");
+   ut_assert_nextline("quux");
+   ut_assert_nextline("quux");
+   ut_assert_console_end();
+
+   puts("Beware: this test set local variable loop_i and it cannot be 
unset!");
+
+   return 0;
+}
+HUSH_TEST(hush_test_for, 0);
+
+static int hush_test_while(struct unit_test_state *uts)
+{
+   console_record_reset_enable();
+
+   /* Exit status is that of test, so 1 since test is false to quit the 
loop. */
+   ut_asserteq(1, run_command("while test -z \"$loop_foo\"; do echo bar; 
loop_foo=quux; done", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   puts("Beware: this test set local variable loop_foo and it cannot be 
unset!");
+
+   return 0;
+}
+HUSH_TEST(hush_test_while, 0);
+
+static int hush_test_until(struct unit_test_state *uts)
+{
+   console_record_reset_enable();
+   env_set("loop_bar", "bar");
+
+   /*
+* WARNING We have to use environment variable because it is not 
possible
+* resetting local variable.
+*/
+   ut_assertok(run_command("until test -z \"$loop_bar\"; do echo quux; 
setenv loop_bar; done", 0));
+   ut_assert_nextline("quux");
+   ut_assert_console_end();
+
+   /*
+* Loop normally resets foo environment variable, but we reset it here 
in
+* case the test failed.
+*/
+   env_set("loop_bar", NULL);
+   return 0;
+}
+HUSH_TEST(hush_test_until, 0);
-- 
2.34.1



[PATCH v13 05/24] test: hush: Test hush commands list

2023-12-22 Thread Francis Laniel
Verifies behavior of commands separated by ';', '&&' and '||'.

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 test/hush/Makefile |  1 +
 test/hush/list.c   | 79 ++
 2 files changed, 80 insertions(+)
 create mode 100644 test/hush/list.c

diff --git a/test/hush/Makefile b/test/hush/Makefile
index feb4f71956..ff4fe7700b 100644
--- a/test/hush/Makefile
+++ b/test/hush/Makefile
@@ -6,3 +6,4 @@
 obj-y += cmd_ut_hush.o
 obj-y += if.o
 obj-y += dollar.o
+obj-y += list.o
diff --git a/test/hush/list.c b/test/hush/list.c
new file mode 100644
index 00..052cf2783c
--- /dev/null
+++ b/test/hush/list.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) Copyright 2021
+ * Francis Laniel, Amarula Solutions, francis.lan...@amarulasolutions.com
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int hush_test_semicolon(struct unit_test_state *uts)
+{
+   /* A; B = B truth table. */
+   ut_asserteq(1, run_command("false; false", 0));
+   ut_assertok(run_command("false; true", 0));
+   ut_assertok(run_command("true; true", 0));
+   ut_asserteq(1, run_command("true; false", 0));
+
+   return 0;
+}
+HUSH_TEST(hush_test_semicolon, 0);
+
+static int hush_test_and(struct unit_test_state *uts)
+{
+   /* A && B truth table. */
+   ut_asserteq(1, run_command("false && false", 0));
+   ut_asserteq(1, run_command("false && true", 0));
+   ut_assertok(run_command("true && true", 0));
+   ut_asserteq(1, run_command("true && false", 0));
+
+   return 0;
+}
+HUSH_TEST(hush_test_and, 0);
+
+static int hush_test_or(struct unit_test_state *uts)
+{
+   /* A || B truth table. */
+   ut_asserteq(1, run_command("false || false", 0));
+   ut_assertok(run_command("false || true", 0));
+   ut_assertok(run_command("true || true", 0));
+   ut_assertok(run_command("true || false", 0));
+
+   return 0;
+}
+HUSH_TEST(hush_test_or, 0);
+
+static int hush_test_and_or(struct unit_test_state *uts)
+{
+   /* A && B || C truth table. */
+   ut_asserteq(1, run_command("false && false || false", 0));
+   ut_asserteq(1, run_command("false && false || true", 0));
+   ut_asserteq(1, run_command("false && true || true", 0));
+   ut_asserteq(1, run_command("false && true || false", 0));
+   ut_assertok(run_command("true && true || false", 0));
+   ut_asserteq(1, run_command("true && false || false", 0));
+   ut_assertok(run_command("true && false || true", 0));
+   ut_assertok(run_command("true && true || true", 0));
+
+   return 0;
+}
+HUSH_TEST(hush_test_and_or, 0);
+
+static int hush_test_or_and(struct unit_test_state *uts)
+{
+   /* A || B && C truth table. */
+   ut_asserteq(1, run_command("false || false && false", 0));
+   ut_asserteq(1, run_command("false || false && true", 0));
+   ut_assertok(run_command("false || true && true", 0));
+   ut_asserteq(1, run_command("false || true && false", 0));
+   ut_assertok(run_command("true || true && false", 0));
+   ut_assertok(run_command("true || false && false", 0));
+   ut_assertok(run_command("true || false && true", 0));
+   ut_assertok(run_command("true || true && true", 0));
+
+   return 0;
+}
+HUSH_TEST(hush_test_or_and, 0);
-- 
2.34.1



[PATCH v13 04/24] test: hush: Test hush variable expansion

2023-12-22 Thread Francis Laniel
Verifies shell variables are replaced by their values.

Reviewed-by: Simon Glass 
Signed-off-by: Francis Laniel 
---
 test/hush/Makefile   |   1 +
 test/hush/dollar.c   | 167 +++
 test/py/tests/test_ut.py |   8 +-
 3 files changed, 175 insertions(+), 1 deletion(-)
 create mode 100644 test/hush/dollar.c

diff --git a/test/hush/Makefile b/test/hush/Makefile
index a3c9ae5106..feb4f71956 100644
--- a/test/hush/Makefile
+++ b/test/hush/Makefile
@@ -5,3 +5,4 @@
 
 obj-y += cmd_ut_hush.o
 obj-y += if.o
+obj-y += dollar.o
diff --git a/test/hush/dollar.c b/test/hush/dollar.c
new file mode 100644
index 00..defb2c3fd0
--- /dev/null
+++ b/test/hush/dollar.c
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) Copyright 2021
+ * Francis Laniel, Amarula Solutions, francis.lan...@amarulasolutions.com
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int hush_test_simple_dollar(struct unit_test_state *uts)
+{
+   console_record_reset_enable();
+   ut_assertok(run_command("echo $dollar_foo", 0));
+   ut_assert_nextline_empty();
+   ut_assert_console_end();
+
+   ut_assertok(run_command("echo ${dollar_foo}", 0));
+   ut_assert_nextline_empty();
+   ut_assert_console_end();
+
+   ut_assertok(run_command("dollar_foo=bar", 0));
+
+   ut_assertok(run_command("echo $dollar_foo", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   ut_assertok(run_command("echo ${dollar_foo}", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   ut_assertok(run_command("dollar_foo=\\$bar", 0));
+
+   ut_assertok(run_command("echo $dollar_foo", 0));
+   ut_assert_nextline("$bar");
+   ut_assert_console_end();
+
+   ut_assertok(run_command("dollar_foo='$bar'", 0));
+
+   ut_assertok(run_command("echo $dollar_foo", 0));
+   ut_assert_nextline("$bar");
+   ut_assert_console_end();
+
+   ut_asserteq(1, run_command("dollar_foo=bar quux", 0));
+   /* Next line contains error message */
+   ut_assert_skipline();
+   ut_assert_console_end();
+
+   ut_asserteq(1, run_command("dollar_foo='bar quux", 0));
+   /* Next line contains error message */
+   ut_assert_skipline();
+   ut_assert_console_end();
+
+   ut_asserteq(1, run_command("dollar_foo=bar quux\"", 0));
+   /* Two next lines contain error message */
+   ut_assert_skipline();
+   ut_assert_skipline();
+   ut_assert_console_end();
+
+   ut_assertok(run_command("dollar_foo='bar \"quux'", 0));
+
+   ut_assertok(run_command("echo $dollar_foo", 0));
+   /*
+* This one is buggy.
+* ut_assert_nextline("bar \"quux");
+* ut_assert_console_end();
+*
+* So, let's reset output:
+*/
+   console_record_reset_enable();
+
+   ut_asserteq(1, run_command("dollar_foo=\"bar 'quux\"", 0));
+   /* Next line contains error message */
+   ut_assert_skipline();
+   ut_assert_console_end();
+
+   ut_assertok(run_command("dollar_foo='bar quux'", 0));
+   ut_assertok(run_command("echo $dollar_foo", 0));
+   ut_assert_nextline("bar quux");
+   ut_assert_console_end();
+
+   puts("Beware: this test set local variable dollar_foo and it cannot be 
unset!");
+
+   return 0;
+}
+HUSH_TEST(hush_test_simple_dollar, 0);
+
+static int hush_test_env_dollar(struct unit_test_state *uts)
+{
+   env_set("env_foo", "bar");
+   console_record_reset_enable();
+
+   ut_assertok(run_command("echo $env_foo", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   ut_assertok(run_command("echo ${env_foo}", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   /* Environment variables have priority over local variable */
+   ut_assertok(run_command("env_foo=quux", 0));
+   ut_assertok(run_command("echo ${env_foo}", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   /* Clean up setting the variable */
+   env_set("env_foo", NULL);
+
+   puts("Beware: this test set local variable env_foo and it cannot be 
unset!");
+
+   return 0;
+}
+HUSH_TEST(hush_test_env_dollar, 0);
+
+static int hush_test_command_dollar(struct unit_test_state *uts)
+{
+   console_record_reset_enable();
+
+   ut_assertok(run_command("dollar_bar=\"echo bar\"", 0));
+
+   ut_assertok(run_command("$dollar_bar", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   ut_assertok(run_command("${dollar_bar}", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   ut_assertok(run_command("dollar_bar=\"echo\nbar\"", 0));
+
+   ut_assertok(run_command("$dollar_bar", 0));
+   ut_assert_nextline("bar");
+   ut_assert_console_end();
+
+   ut_assertok(run_command("dollar_bar='echo bar\n'", 0));
+
+   ut_assertok(run_command("$dol

[PATCH v13 03/24] test/py: hush_if_test: Remove the test file

2023-12-22 Thread Francis Laniel
5804ebfeb1ce ("test: hush: Test hush if/else") translated this test to a C test,
so this python file is no more needed.

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 test/py/tests/test_hush_if_test.py | 197 -
 1 file changed, 197 deletions(-)
 delete mode 100644 test/py/tests/test_hush_if_test.py

diff --git a/test/py/tests/test_hush_if_test.py 
b/test/py/tests/test_hush_if_test.py
deleted file mode 100644
index 3b4b6fcaf4..00
--- a/test/py/tests/test_hush_if_test.py
+++ /dev/null
@@ -1,197 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
-
-# Test operation of the "if" shell command.
-
-import os
-import os.path
-import pytest
-
-# TODO: These tests should be converted to a C test.
-# For more information please take a look at the thread
-# https://lists.denx.de/pipermail/u-boot/2019-October/388732.html
-
-pytestmark = pytest.mark.buildconfigspec('hush_parser')
-
-# The list of "if test" conditions to test.
-subtests = (
-# Base if functionality.
-
-('true', True),
-('false', False),
-
-# Basic operators.
-
-('test aaa = aaa', True),
-('test aaa = bbb', False),
-
-('test aaa != bbb', True),
-('test aaa != aaa', False),
-
-('test aaa < bbb', True),
-('test bbb < aaa', False),
-
-('test bbb > aaa', True),
-('test aaa > bbb', False),
-
-('test 123 -eq 123', True),
-('test 123 -eq 456', False),
-
-('test 123 -ne 456', True),
-('test 123 -ne 123', False),
-
-('test 123 -lt 456', True),
-('test 123 -lt 123', False),
-('test 456 -lt 123', False),
-
-('test 123 -le 456', True),
-('test 123 -le 123', True),
-('test 456 -le 123', False),
-
-('test 456 -gt 123', True),
-('test 123 -gt 123', False),
-('test 123 -gt 456', False),
-
-('test 456 -ge 123', True),
-('test 123 -ge 123', True),
-('test 123 -ge 456', False),
-
-# Octal tests
-
-('test 010 -eq 010', True),
-('test 010 -eq 011', False),
-
-('test 010 -ne 011', True),
-('test 010 -ne 010', False),
-
-# Hexadecimal tests
-
-('test 0x200 -gt 0x201', False),
-('test 0x200 -gt 0x200', False),
-('test 0x200 -gt 0x1ff', True),
-
-# Mixed tests
-
-('test 010 -eq 10', False),
-('test 010 -ne 10', True),
-('test 0xa -eq 10', True),
-('test 0xa -eq 012', True),
-
-('test 200 -gt 0x1ff', False),
-('test 0x200 -gt 1ff', True),
-('test 0x200 -lt 1ff', False),
-('test 0x200 -eq 200', False),
-('test 0x200 -ne 200', True),
-
-('test -z ""', True),
-('test -z "aaa"', False),
-
-('test -n "aaa"', True),
-('test -n ""', False),
-
-# Inversion of simple tests.
-
-('test ! aaa = aaa', False),
-('test ! aaa = bbb', True),
-('test ! ! aaa = aaa', True),
-('test ! ! aaa = bbb', False),
-
-# Binary operators.
-
-('test aaa != aaa -o bbb != bbb', False),
-('test aaa != aaa -o bbb = bbb', True),
-('test aaa = aaa -o bbb != bbb', True),
-('test aaa = aaa -o bbb = bbb', True),
-
-('test aaa != aaa -a bbb != bbb', False),
-('test aaa != aaa -a bbb = bbb', False),
-('test aaa = aaa -a bbb != bbb', False),
-('test aaa = aaa -a bbb = bbb', True),
-
-# Inversion within binary operators.
-
-('test ! aaa != aaa -o ! bbb != bbb', True),
-('test ! aaa != aaa -o ! bbb = bbb', True),
-('test ! aaa = aaa -o ! bbb != bbb', True),
-('test ! aaa = aaa -o ! bbb = bbb', False),
-
-('test ! ! aaa != aaa -o ! ! bbb != bbb', False),
-('test ! ! aaa != aaa -o ! ! bbb = bbb', True),
-('test ! ! aaa = aaa -o ! ! bbb != bbb', True),
-('test ! ! aaa = aaa -o ! ! bbb = bbb', True),
-)
-
-def exec_hush_if(u_boot_console, expr, result):
-"""Execute a shell "if" command, and validate its result."""
-
-config = u_boot_console.config.buildconfig
-maxargs = int(config.get('config_sys_maxargs', '0'))
-args = len(expr.split(' ')) - 1
-if args > maxargs:
-u_boot_console.log.warning('CONFIG_SYS_MAXARGS too low; need ' +
-str(args))
-pytest.skip()
-
-cmd = 'if ' + expr + '; then echo true; else echo false; fi'
-response = u_boot_console.run_command(cmd)
-assert response.strip() == str(result).lower()
-
-@pytest.mark.buildconfigspec('cmd_echo')
-@pytest.mark.parametrize('expr,result', subtests)
-def test_hush_if_test(u_boot_console, expr, result):
-"""Test a single "if test" condition."""
-
-exec_hush_if(u_boot_console, expr, result)
-
-def test_hush_z(u_boot_console):
-"""Test the -z operator"""
-u_boot_console.run_command('setenv ut_var_nonexistent')
-u_boot_console.run_command('setenv ut_var_exists 1')
-exec_hush_if(u_boot_console, 'test -z "$ut_var_nonexistent"', True)
-exec_hush_if(u_boot_console, 'test -z "$ut_var_exists"', False)
-u_boot_console.run_command('se

[PATCH v13 02/24] test: hush: Test hush if/else

2023-12-22 Thread Francis Laniel
As asked in commit 9c6bf1715f6a ("test/py: hush_if_test: Add tests to cover
octal/hex values"), this commit translates test_hush_if_test.py to a C test.

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 test/hush/Makefile |   1 +
 test/hush/if.c | 316 +
 2 files changed, 317 insertions(+)
 create mode 100644 test/hush/if.c

diff --git a/test/hush/Makefile b/test/hush/Makefile
index dfa2a92615..a3c9ae5106 100644
--- a/test/hush/Makefile
+++ b/test/hush/Makefile
@@ -4,3 +4,4 @@
 # Francis Laniel, Amarula Solutions, francis.lan...@amarulasolutions.com
 
 obj-y += cmd_ut_hush.o
+obj-y += if.o
diff --git a/test/hush/if.c b/test/hush/if.c
new file mode 100644
index 00..b7200e32ec
--- /dev/null
+++ b/test/hush/if.c
@@ -0,0 +1,316 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) Copyright 2021
+ * Francis Laniel, Amarula Solutions, francis.lan...@amarulasolutions.com
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * All tests will execute the following:
+ * if condition_to_test; then
+ *   true
+ * else
+ *   false
+ * fi
+ * If condition is true, command returns 1, 0 otherwise.
+ */
+const char *if_format = "if %s; then true; else false; fi";
+
+static int hush_test_if_base(struct unit_test_state *uts)
+{
+   char if_formatted[128];
+
+   sprintf(if_formatted, if_format, "true");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "false");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   return 0;
+}
+HUSH_TEST(hush_test_if_base, 0);
+
+static int hush_test_if_basic_operators(struct unit_test_state *uts)
+{
+   char if_formatted[128];
+
+   sprintf(if_formatted, if_format, "test aaa = aaa");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test aaa = bbb");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test aaa != bbb");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test aaa != aaa");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test aaa < bbb");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test bbb < aaa");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test bbb > aaa");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test aaa > bbb");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -eq 123");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -eq 456");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -ne 456");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -ne 123");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -lt 456");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -lt 123");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 456 -lt 123");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -le 456");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -le 123");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 456 -le 123");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 456 -gt 123");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -gt 123");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -gt 456");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 456 -ge 123");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -ge 123");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 123 -ge 456");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   return 0;
+}
+HUSH_TEST(hush_test_if_basic_operators, 0);
+
+static int hush_test_if_octal(struct unit_test_state *uts)
+{
+   char if_formatted[128];
+
+   sprintf(if_formatted, if_format, "test 010 -eq 010");
+   ut_assertok(run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 010 -eq 011");
+   ut_asserteq(1, run_command(if_formatted, 0));
+
+   sprintf(if_formatted, if_format, "test 010 -ne 011");
+   ut_assertok(run_command(if_fo

[PATCH v13 01/24] test: Add framework to test hush behavior

2023-12-22 Thread Francis Laniel
Introduce a new subcommand to ut: ut hush.
For the moment, this command does nothing, future commits will add tests which
will be run on command call.

Note that CONFIG_HUSH_PARSER must be defined to compile this new subcommand.

Signed-off-by: Francis Laniel 
Reviewed-by: Simon Glass 
---
 include/test/hush.h | 15 +++
 include/test/suites.h   |  1 +
 test/Makefile   |  3 +++
 test/cmd_ut.c   |  6 ++
 test/hush/Makefile  |  6 ++
 test/hush/cmd_ut_hush.c | 20 
 6 files changed, 51 insertions(+)
 create mode 100644 include/test/hush.h
 create mode 100644 test/hush/Makefile
 create mode 100644 test/hush/cmd_ut_hush.c

diff --git a/include/test/hush.h b/include/test/hush.h
new file mode 100644
index 00..cca66544a0
--- /dev/null
+++ b/include/test/hush.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * (C) Copyright 2021
+ * Francis Laniel, Amarula Solutions, francis.lan...@amarulasolutions.com
+ */
+
+#ifndef __TEST_HUSH_H__
+#define __TEST_HUSH_H__
+
+#include 
+
+/* Declare a new environment test */
+#define HUSH_TEST(_name, _flags)   UNIT_TEST(_name, _flags, hush_test)
+
+#endif /* __TEST_HUSH_H__ */
diff --git a/include/test/suites.h b/include/test/suites.h
index 49224d8ea2..365d5f20df 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -43,6 +43,7 @@ int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[]);
 int do_ut_exit(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+int do_ut_hush(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[]);
diff --git a/test/Makefile b/test/Makefile
index 6b8a1506f5..9aeef02f9e 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -17,6 +17,9 @@ obj-$(CONFIG_FUZZ) += fuzz/
 ifndef CONFIG_SANDBOX_VPL
 obj-$(CONFIG_UNIT_TEST) += lib/
 endif
+ifneq ($(CONFIG_HUSH_PARSER),)
+obj-$(CONFIG_$(SPL_)CMDLINE) += hush/
+endif
 obj-$(CONFIG_$(SPL_)CMDLINE) += print_ut.o
 obj-$(CONFIG_$(SPL_)CMDLINE) += str_ut.o
 obj-$(CONFIG_UT_TIME) += time_ut.o
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 1b934b2329..0677ce0cd1 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -121,6 +121,9 @@ static struct cmd_tbl cmd_ut_sub[] = {
 #ifdef CONFIG_CMD_ADDRMAP
U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
 #endif
+#if CONFIG_IS_ENABLED(HUSH_PARSER)
+   U_BOOT_CMD_MKENT(hush, CONFIG_SYS_MAXARGS, 1, do_ut_hush, "", ""),
+#endif
 #ifdef CONFIG_CMD_LOADM
U_BOOT_CMD_MKENT(loadm, CONFIG_SYS_MAXARGS, 1, do_ut_loadm, "", ""),
 #endif
@@ -216,6 +219,9 @@ U_BOOT_LONGHELP(ut,
 #ifdef CONFIG_CONSOLE_TRUETYPE
"\nfont - font command"
 #endif
+#if CONFIG_IS_ENABLED(HUSH_PARSER)
+   "\nhush - Test hush behavior"
+#endif
 #ifdef CONFIG_CMD_LOADM
"\nloadm - loadm command parameters and loading memory blob"
 #endif
diff --git a/test/hush/Makefile b/test/hush/Makefile
new file mode 100644
index 00..dfa2a92615
--- /dev/null
+++ b/test/hush/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2021
+# Francis Laniel, Amarula Solutions, francis.lan...@amarulasolutions.com
+
+obj-y += cmd_ut_hush.o
diff --git a/test/hush/cmd_ut_hush.c b/test/hush/cmd_ut_hush.c
new file mode 100644
index 00..48a1adbf28
--- /dev/null
+++ b/test/hush/cmd_ut_hush.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) Copyright 2021
+ * Francis Laniel, Amarula Solutions, francis.lan...@amarulasolutions.com
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int do_ut_hush(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+   struct unit_test *tests = UNIT_TEST_SUITE_START(hush_test);
+   const int n_ents = UNIT_TEST_SUITE_COUNT(hush_test);
+
+   return cmd_ut_category("hush", "hush_test_",
+  tests, n_ents, argc, argv);
+}
-- 
2.34.1



[PATCH v13 00/24] Modernize U-Boot shell

2023-12-22 Thread Francis Laniel
Hi!


During 2021 summer, Sean Anderson wrote a contribution to add a new shell, based
on LIL, to U-Boot [1, 2].
While one of the goals of this contribution was to address the fact actual
U-Boot shell, which is based on Busybox hush, is old there was a discussion
about adding a new shell versus updating the actual one [3, 4].

So, in this series, with Harald Seiler, we updated the actual U-Boot shell to
reflect what is currently in Busybox source code.
Basically, this contribution is about taking a snapshot of Busybox shell/hush.c
file (as it exists in commit 37460f5da) and adapt it to suit U-Boot needs.

This contribution was written to be as backward-compatible as possible to avoid
breaking the existing.
So, the modern hush flavor offers the same as the actual, that is to say:
1. Variable expansion.
2. Instruction lists (;, && and ||).
3. If, then and else.
4. Loops (for, while and until).
No new features offered by Busybox hush were implemented (e.g. functions).

It is possible to change the parser at runtime using the "cli" command:
=> cli print
old
=> cli set modern
=> cli print
modern
=> cli set old
The default parser is the old one.
Note that to use both parser, you would need to set both
CONFIG_HUSH_MODERN_PARSER and CONFIG_HUSH_OLD_PARSER.

In terms of testing, new unit tests were added to ut to ensure the new behavior
is the same as the old one and it does not add regression.
Nonetheless, if old behavior was buggy and fixed upstream, the fix is then added
to U-Boot [5].
In sandbox, all of these tests pass smoothly:
=> printenv board
board=sandbox
=> ut hush
Running 20 hush tests
...
Failures: 0
=> cli set modern
=> ut hush
Running 20 hush tests
...
Failures: 0

Thanks to the effort of Harald Seiler, I was successful booting a board:
=> printenv fdtfile
fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb
=> cli get
old
=> boot
...
root@lepotato:~#
root@lepotato:~# reboot
...
=> cli set modern
=> cli get
modern
=> printenv fdtfile
fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb
=> boot
...
root@lepotato:~#

This contribution indeed adds a lot of code and there were concern about its
size [6, 7].
With regard to the amount of code added, the cli_hush_upstream.c is 13030 lines
long but it seems a smaller subset is really used:
gcc -D__U_BOOT__ -E common/cli_hush_upstream.c | wc -l
2870
Despite this, it is better to still have the whole upstream code for the sake of
easing maintenance.
With regard to memory size, I conducted some experiments for version 8 of this
series and for a subset of arm64 boards and found the worst case to be 4K [8].
Tom Rini conducted more research on this and also found the increase to be
acceptable [9].

If you want to review it - your review will really be appreciated - here are
some information regarding the commits:
* commits marked as "test:" deal with unit tests.
* commit "cli: Add Busybox upstream hush.c file." copies Busybox shell/hush.c
into U-Boot tree, this explain why this commit contains around 12000 additions.
* commit "cli: Port Busybox 2021 hush to U-Boot." modifies previously added file
to permit us to use this as new shell.
The really good idea of #include'ing Busybox code into a wrapper file to define
some particular functions while minimizing modifications to upstream code comes
from Harald Seiler.
* commit "cmd: Add new parser command" adds a new command which permits
selecting parser at runtime.
I am not really satisfied with the fact it calls cli_init() and cli_loop() each
time the parser is set, so your reviews would be welcomed.
* Other commits focus on enabling features we need (e.g. if).

Changes since:
 v2:
  * Added a small fix to compile sandbox with NO_SDL=1.
  * Added a command to change parser at runtime.
  * Added 2021 parser function to all run_command*().
 v3:
  * Various bug fixes pointed by the CI.
  * Added upstream busybox hush commits until 6th February 2022.
 v4:
  * Various cleaning.
  * Modified python test to accept failure output when the test are designed to
  fail.
  * Bumped upstream busybox hush commits until 24h March 2022.
 v5:
  * Bumped upstream busybox hush commits until 30th January 2023.
  * Fix how hush interprets '<' and '>', indeed we needed to escape them but I
  removed this behavior as tests are handled by test command and not hush
  itself. This permitted to have the ut fdt to pass.
  * Fix a problem with how exit was handled. This was reported by the ut exit
  test.
 v6:
  * There was no v6 and I got mixed up with version.
 v7:
  * Bumped upstream busybox hush commits until 9th May 2023.
  * Renamed parser command to change parser at runtime to cli and added
  documentation.
  * Added better separation of patches.
  * Removed code about __gnu_thumb1_case_si as it was merged in another series.
  * Various cleaning.
 v8:
  * Bumped upstream busybox hush commits until 25th May 2023.
 v9:
  * Bumped upstream busybox hush commits until 2nd October 2023.
 v10:
  * Fixed a build error in commit adding cli command.
  * Add

RE: [PATCH v7 2/2] schemas: Add some common reserved-memory usages

2023-12-22 Thread Chiu, Chasel

Please see my reply below inline.

Thanks,
Chasel


> -Original Message-
> From: Ard Biesheuvel 
> Sent: Friday, December 22, 2023 4:48 AM
> To: Chiu, Chasel 
> Cc: Simon Glass ; devicet...@vger.kernel.org; Mark Rutland
> ; Rob Herring ; Tan, Lean Sheng
> ; lkml ; Dhaval
> Sharma ; Brune, Maximilian
> ; Yunhui Cui ;
> Dong, Guo ; Tom Rini ; ron minnich
> ; Guo, Gua ; linux-
> a...@vger.kernel.org; U-Boot Mailing List 
> Subject: Re: [PATCH v7 2/2] schemas: Add some common reserved-memory
> usages
> 
> On Thu, 21 Dec 2023 at 17:50, Chiu, Chasel  wrote:
> >
> >
> > Hi Ard,
> >
> > Please see my reply below inline and let me know your thoughts.
> >
> > Thanks,
> > Chasel
> >
> >
> > > -Original Message-
> > > From: Ard Biesheuvel 
> > > Sent: Thursday, December 21, 2023 6:31 AM
> > > To: Chiu, Chasel 
> > > Cc: Simon Glass ; devicet...@vger.kernel.org; Mark
> > > Rutland ; Rob Herring ; Tan,
> > > Lean Sheng ; lkml
> > > ; Dhaval Sharma ;
> > > Brune, Maximilian ; Yunhui Cui
> > > ; Dong, Guo ; Tom Rini
> > > ; ron minnich ; Guo, Gua
> > > ; linux- a...@vger.kernel.org; U-Boot Mailing
> > > List 
> > > Subject: Re: [PATCH v7 2/2] schemas: Add some common reserved-memory
> > > usages
> > >
> > > On Tue, 28 Nov 2023 at 21:31, Chiu, Chasel  wrote:
> > > >
> > > >
> > > >
> > > >
> > > > > -Original Message-
> > > > > From: Ard Biesheuvel 
> > > > > Sent: Tuesday, November 28, 2023 10:08 AM
> > > > > To: Chiu, Chasel 
> > > > > Cc: Simon Glass ; devicet...@vger.kernel.org;
> > > > > Mark Rutland ; Rob Herring
> > > > > ; Tan, Lean Sheng ;
> > > > > lkml ; Dhaval Sharma
> > > > > ; Brune, Maximilian
> > > > > ; Yunhui Cui
> > > > > ; Dong, Guo ; Tom
> > > > > Rini ; ron minnich ;
> > > > > Guo, Gua ; linux- a...@vger.kernel.org;
> > > > > U-Boot Mailing List 
> > > > > Subject: Re: [PATCH v7 2/2] schemas: Add some common
> > > > > reserved-memory usages
> > > > >
> > > > > You are referring to a 2000 line patch so it is not 100% clear where 
> > > > > to look
> tbh.
> > > > >
> > > > >
> > > > > On Tue, 21 Nov 2023 at 19:37, Chiu, Chasel 
> wrote:
> > > > > >
> > > > > >
> > > > > > In PR, UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c,
> > > > > > line
> > > > > > 268 is for
> > > > > related example code.
> > > > > >
> > > > >
> > > > > That refers to a 'memory-allocation' node, right? How does that
> > > > > relate to the 'reserved-memory' node?
> > > > >
> > > > > And crucially, how does this clarify in which way "runtime-code"
> > > > > and
> > > > > "runtime- data" reservations are being used?
> > > > >
> > > > > Since the very beginning of this discussion, I have been asking
> > > > > repeatedly for examples that describe the wider context in which
> > > > > these
> > > reservations are used.
> > > > > The "runtime" into runtime-code and runtime-data means that
> > > > > these regions have a special significance to the operating
> > > > > system, not just to the next bootloader stage. So I want to
> > > > > understand exactly why it is necessary to describe these regions
> > > > > in a way where the operating system might be expected to
> > > > > interpret this information and act
> > > upon it.
> > > > >
> > > >
> > > >
> > > > I think runtime code and data today are mainly for supporting UEFI
> > > > runtime
> > > services - some BIOS functions for OS to utilize, OS may follow
> > > below ACPI spec to treat them as reserved range:
> > > > https://uefi.org/specs/ACPI/6.5/15_System_Address_Map_Interfaces.h
> > > > tml# uefi-memory-types-and-mapping-to-acpi-address-range-types
> > > >
> > > > Like I mentioned earlier, that PR is still in early phase and has
> > > > not reflected all
> > > the required changes yet, but the idea is to build
> > > gEfiMemoryTypeInformationGuid HOB from FDT reserved-memory nodes.
> > > > UEFI generic Payload has DxeMain integrated, however Memory Types
> > > > are
> > > platform-specific, for example, some platforms may need bigger
> > > runtime memory for their implementation, that's why we want such FDT
> > > reserved-memory node to tell DxeMain.
> > > >
> > >
> > > > The Payload flow will be like this:
> > > >   Payload creates built-in default MemoryTypes table ->
> > > > FDT reserved-memory node to override if required (this also
> > > > ensures the
> > > same memory map cross boots so ACPI S4 works) ->
> > > >   Build gEfiMemoryTypeInformationGuid HOB by "platfom specific"
> > > MemoryTypes Table ->
> > > > DxeMain/GCD to consume this MemoryTypes table and setup
> > > > memory
> > > service ->
> > > >   Install memory types table to UEFI system table.Configuration 
> > > > table...
> > > >
> > > > Note: if Payload built-in default MemoryTypes table works fine for
> > > > the platform, then FDT reserved-memory node does not need to
> > > > provide such
> > > 'usage' compatible strings. (optional) This FDT node could allow
> > > flexibility/compatibility without rebuilding Payload binary.
> > > >
> > > > Not sure if I answ

[PATCH 1/1] smbios: type2: contained object handles

2023-12-22 Thread Heinrich Schuchardt
The type 2 structure must include information about the contained objects.
It is fine to set the number of contained object handles to 0.

Add the missing field.

Fixes: 721e992a8af5 ("x86: Add SMBIOS table support")
Signed-off-by: Heinrich Schuchardt 
---
 include/smbios.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/smbios.h b/include/smbios.h
index e601283d29..88c19ae062 100644
--- a/include/smbios.h
+++ b/include/smbios.h
@@ -139,6 +139,7 @@ struct __packed smbios_type2 {
u8 chassis_location;
u16 chassis_handle;
u8 board_type;
+   u8 number_contained_objects;
char eos[SMBIOS_STRUCT_EOS_BYTES];
 };

--
2.43.0



Re: [PATCH 1/1] lib: smbios: remove redundant next_header()

2023-12-22 Thread Ilias Apalodimas
Hi Heinrich,

On Fri, 22 Dec 2023 at 19:54, Heinrich Schuchardt  wrote:
>
> next_header() and get_next_header() only differ in how the const attribute
> is used. One function taking a const parameter and returning a non-const is
> good enough.
>
> Fixes: 3d49ee8510d3 ("efi_loader: add SMBIOS table measurement")\

This doesn't fix a bug. It correctly cleans up code, so I think the
Fixes tag must be omitted.

> Signed-off-by: Heinrich Schuchardt 
> ---
>  lib/smbios-parser.c | 11 ++-
>  1 file changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c
> index b578c30840..f4de350e6e 100644
> --- a/lib/smbios-parser.c
> +++ b/lib/smbios-parser.c
> @@ -50,14 +50,7 @@ static u8 *find_next_header(u8 *pos)
> return pos;
>  }
>
> -static struct smbios_header *get_next_header(struct smbios_header *curr)
> -{
> -   u8 *pos = ((u8 *)curr) + curr->length;
> -
> -   return (struct smbios_header *)find_next_header(pos);
> -}
> -
> -static const struct smbios_header *next_header(const struct smbios_header 
> *curr)
> +static struct smbios_header *get_next_header(const struct smbios_header 
> *curr)
>  {
> u8 *pos = ((u8 *)curr) + curr->length;
>
> @@ -73,7 +66,7 @@ const struct smbios_header *smbios_header(const struct 
> smbios_entry *entry, int
> if (header->type == type)
> return header;
>
> -   header = next_header(header);
> +   header = get_next_header(header);
> }
>
> return NULL;
> --
> 2.43.0
>

Other than that
Reviewed-by: Ilias Apalodimas 


[PATCH 1/1] lib: smbios: verify_checksum() is duplicate

2023-12-22 Thread Heinrich Schuchardt
The function verify_checksum() duplicates what table_compute_checksum()
does. Replace it.

Fixes: 415eab0655a8 ("smbios: add parsing API")
Signed-off-by: Heinrich Schuchardt 
---
 lib/smbios-parser.c | 18 ++
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c
index f4de350e6e..a29a06398d 100644
--- a/lib/smbios-parser.c
+++ b/lib/smbios-parser.c
@@ -5,23 +5,9 @@

 #define LOG_CATEGORY   LOGC_BOOT

+#include 
 #include 

-static inline int verify_checksum(const struct smbios_entry *e)
-{
-   /*
-* Checksums for SMBIOS tables are calculated to have a value, so that
-* the sum over all bytes yields zero (using unsigned 8 bit arithmetic).
-*/
-   u8 *byte = (u8 *)e;
-   u8 sum = 0;
-
-   for (int i = 0; i < e->length; i++)
-   sum += byte[i];
-
-   return sum;
-}
-
 const struct smbios_entry *smbios_entry(u64 address, u32 size)
 {
const struct smbios_entry *entry = (struct smbios_entry 
*)(uintptr_t)address;
@@ -32,7 +18,7 @@ const struct smbios_entry *smbios_entry(u64 address, u32 size)
if (memcmp(entry->anchor, "_SM_", 4))
return NULL;

-   if (verify_checksum(entry))
+   if (table_compute_checksum(entry, entry->length))
return NULL;

return entry;
--
2.43.0



[PATCH 1/1] lib: smbios: remove redundant next_header()

2023-12-22 Thread Heinrich Schuchardt
next_header() and get_next_header() only differ in how the const attribute
is used. One function taking a const parameter and returning a non-const is
good enough.

Fixes: 3d49ee8510d3 ("efi_loader: add SMBIOS table measurement")
Signed-off-by: Heinrich Schuchardt 
---
 lib/smbios-parser.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c
index b578c30840..f4de350e6e 100644
--- a/lib/smbios-parser.c
+++ b/lib/smbios-parser.c
@@ -50,14 +50,7 @@ static u8 *find_next_header(u8 *pos)
return pos;
 }

-static struct smbios_header *get_next_header(struct smbios_header *curr)
-{
-   u8 *pos = ((u8 *)curr) + curr->length;
-
-   return (struct smbios_header *)find_next_header(pos);
-}
-
-static const struct smbios_header *next_header(const struct smbios_header 
*curr)
+static struct smbios_header *get_next_header(const struct smbios_header *curr)
 {
u8 *pos = ((u8 *)curr) + curr->length;

@@ -73,7 +66,7 @@ const struct smbios_header *smbios_header(const struct 
smbios_entry *entry, int
if (header->type == type)
return header;

-   header = next_header(header);
+   header = get_next_header(header);
}

return NULL;
--
2.43.0



Re: [PATCH 00/13] Complete decoupling of zboot logic from commands

2023-12-22 Thread Tom Rini
On Sun, Dec 03, 2023 at 05:29:25PM -0700, Simon Glass wrote:

> This series refactors the zboot code to allow it to be used with
> CONFIG_COMMAND disabled.
> 
> A new zboot_run() function is used to boot a zimage.
> 
> This is cmde (part e of CMDLINE refactoring)
> It depends on dm/cmdd-working
> which depends on dm/bootstda-working
> which depends on dm/cmdc-working

Just FYI, at this point all of the required series are now in -next so
this could come in via the x86 tree now.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 0/7] Add SE HMBSC board support

2023-12-22 Thread Caleb Connolly
[snip]

 Sumit, could you rebase this series on my generic board support? [1] in
 it's current form this series conflicts, and includes some of the major
 anti-patterns I'm trying to move away from in mach-snapdragon.
>>>
>>> Although, I haven't gone through your series but I was expecting those
>>> conflicts. Let's work together to make this series compatible on top
>>> of yours.
>>>

 You should not have to introduce a new CONFIG_TARGET_XYZ variable, and
 from what I can tell you shouldn't even need to add the board/schneider
 directory at all, you can just set the following in your defconfig:

 CONFIG_SYS_BOARD="dragonboard410c"
>>>
>>> This is simply a misnomer, its HMIBSC board. I suppose we should
>>> rather separate the SoC specific bits into mach-snapdragon and let
>>> different boards use them.
>>
>> Is there any reason why you can't just use the existing db410c board
>> code as-is? I don't see why you want to duplicate it.
> 
> I don't want to duplicate it but rather we should make the common
> parts as part of arch/arm/mach-snapdragon/ and let derivative boards
> use them. The HMIBSC board is an industrial board which doesn't need
> any generic distro boot but rather FIT booting with OTA updates via
> RAUC [1] along with U-boot environment protection. Doesn't that make
> it different from db410c?

Right, your series does this board specific configuration in the board
header file (include/configs/hmibsc.h) and in the defconfig.

The actual board code in board/schneider/hmibsc/hmibsc.c is directly
copied from board/qualcomm/dragonboard410c/dragonboard410c.c with just
the copyright changed, the serial number code removed, and a style fix
to a comment. Ignoring for a moment the copyright issue which would
definitely need to be fixed, what I'm suggesting that you do is just use
the board code from db410c.

The way I have designed the generic board support is so that two similar
boards can share the same board code but with different config headers,
from what I can tell this would work just fine for you.

--- board/qualcomm/dragonboard410c/dragonboard410c.c
+++ board/schneider/hmibsc/hmibsc.c
@@ -2,5 +2,5 @@
 /*
- * Board init file for Dragonboard 410C
+ * Board init file for SE HMIBSC
  *
- * (C) Copyright 2015 Mateusz Kulikowski 
+ * (C) Copyright 2023 Sumit Garg 
  */
@@ -8,3 +8,2 @@
 #include 
-#include 
 #include 
@@ -137,7 +136,2 @@
 {
-   char serial[16];
-
-   memset(serial, 0, 16);
-   snprintf(serial, 13, "%x", msm_board_serial());
-   env_set("serial#", serial);
return 0;
@@ -145,3 +139,4 @@

-/* Fixup of DTB for Linux Kernel
+/*
+ * Fixup of DTB for Linux Kernel
  * 1. Fixup installed DRAM.
@@ -165,3 +160,2 @@

-
if (!eth_env_get_enetaddr("btaddr", mac)) {
@@ -169,5 +163,6 @@

-/* The BD address is same as WLAN MAC address but with
- * least significant bit flipped.
- */
+   /*
+* The BD address is same as WLAN MAC address but with
+* least significant bit flipped.
+*/
mac[0] ^= 0x01;

> 
> [1] https://rauc.io/
> 
>>
>> The only reason the db410c and db820c have their board code is because
>> they're old platforms and already supported. For adding new support
>> there needs to be some very strong justification to have board-specific
>> C code.
>>
>> I think it would be nice to make the db410c code go away, or be toggled
>> at runtime, probably most of it will just work and not break any other
>> boards anyway. The db820c code is just part of what should be in the
>> pinctrl driver...
>>
>> Let's move away from this old model and towards having more generic
>> U-Boot images. This will snowball towards making future bringup even easier.
> 
> As I have mentioned in the other thread, we should give alternatives
> to the board code as well. How would you handle the following?
> 
> - Fastboot mode entry on a button press.

This can be nicely handled through CONFIG_AUTOBOOT. I currently use
AUTOBOOT_STOP_STR but that's quite limited (only works for the power
button with "\r"). Probably the right solution here is to use
CONFIG_AUTOBOOT_USE_MENUKEY and introduce support for
CONFIG_AUTOBOOT_MENUBUTTON to allow specifying a named button instead of
an ASCII code. One would then configure "menucmd" in the U-Boot
environment to launch fastboot.

This lets us drop all the weird non-standard keycode handling in board
code and just configure it in the defconfig instead. I plan to implement
this eventually but would for sure appreciate it if someone beat me to it.
> - Configure MAC address for network support.

I believe you mentioned elsewhere some board with the MAC address on an
i2c EEPROM? The NVMEM framework solves exactly this issue, and U-Boot
already supports it, just add support to your ethernet driver to
retrieve its MAC address via NVMEM.
> - Setup board serial number.

Same as above, the quick and dirty way to go would be to have
mach-snapdragon check fo

Re: [PATCH v2 3/9] bloblist: refactor of bloblist_reloc()

2023-12-22 Thread Raymond Mao
Hi Ilias,

On Fri, 22 Dec 2023 at 10:46, Ilias Apalodimas 
wrote:

> Hi Raymond,
>
> On Fri, 22 Dec 2023 at 17:30, Raymond Mao  wrote:
> >
> > Hi Ilias,
> >
> > On Fri, 22 Dec 2023 at 06:12, Ilias Apalodimas <
> ilias.apalodi...@linaro.org> wrote:
> >>
> >> Hi Raymond,
> >>
> >> On Thu, 21 Dec 2023 at 02:41, Raymond Mao 
> wrote:
> >> >
> >> > The current bloblist pointer and size can be retrieved from global
> >> > data, so we don't need to pass them from the function arguments.
> >> > This change also help to remove all external access of gd->bloblist
> >> > outside of bloblist module.
> >> >
> >> > Signed-off-by: Raymond Mao 
> >> > ---
> >>
> >> [...]
> >>
> >> > }
> >> >  }
> >> >
> >> > -void bloblist_reloc(void *to, uint to_size, void *from, uint
> from_size)
> >> > +void bloblist_reloc(void *to, uint to_size)
> >> >  {
> >> > struct bloblist_hdr *hdr;
> >> >
> >> > -   memcpy(to, from, from_size);
> >> > +   memcpy(to, gd->bloblist, gd->bloblist->total_size);
> >> > hdr = to;
> >> > -   hdr->total_size = to_size;
> >> > +   if (to_size < gd->bloblist->total_size)
> >>
> >> What's the size of *to? Is it equal to to_size?
> >> Because if to_size can be smaller that gd->bloblist->total_size the
> >> memcpy above is wrong
> >
> > to_size should be 0 (use the total_size) or a value larger than
> total_size.
> > I think I should keep the below line from the function header.
>
> The point here is, are we certain that the *to is big enough? Or we'll
> end up overflowing ?
>
Yes, this needs to be checked before copying.

Thanks and regards,
Raymond


Re: [PATCH v2 12/32] board: dragonboard410c: upstream DT compat

2023-12-22 Thread Caleb Connolly
Hi Sumit,

[...]
>> -   if (init == USB_INIT_HOST) {
>> -   /* Start USB Hub */
>> -   dm_gpio_set_dir_flags(&hub_reset,
>> - GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
>> -   mdelay(100);
>> -   /* Switch usb to host connectors */
>> -   dm_gpio_set_dir_flags(&usb_sel,
>> - GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
>> -   mdelay(100);
>> -   } else { /* Device */
>> -   /* Disable hub */
>> -   dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
>> -   /* Switch back to device connector */
>> -   dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
>> +   /* Select "default" or "device" pinctrl */
>> +   switch (init) {
>> +   case USB_INIT_HOST:
>> +   pinctrl_select_state(usb, "default");
>> +   break;
>> +   case USB_INIT_DEVICE:
>> +   pinctrl_select_state(usb, "device");
>> +   break;
>> +   default:
>> +   debug("Unknown usb_init_type %d\n", init);
>> +   break;
> 
> Can this pinctrl configuration move to the corresponding USB driver instead?

Possibly, this is definitely something where DT is currently lacking,
similar discussions in Linux resulted in the USB onboard_hub driver, it
would be nice to add support for that U-Boot at some point.

I don't think putting the pinctrl code directly into the USB driver is
the right way to go, as it definitely wouldn't be accepted in upstream
DT bindings.
> 
> -Sumit
> 
-- 
// Caleb (they/them)


Re: [PATCH v2 0/8] An effort to bring DT bindings compliance within U-Boot

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 04:55:54PM +0100, Krzysztof Kozlowski wrote:
> On 22/12/2023 16:46, Tom Rini wrote:
> > On Fri, Dec 22, 2023 at 04:38:01PM +0100, Krzysztof Kozlowski wrote:
> >> On 22/12/2023 14:43, Sumit Garg wrote:
> >>> On Fri, 22 Dec 2023 at 13:48, Krzysztof Kozlowski
> >>>  wrote:
> 
>  On 22/12/2023 07:12, Sumit Garg wrote:
> > Changes in v2:
> > --
> > - Patch #1: excluded gitab CI config check and added commit description.
> > - Patch #3: s/UBOOT_DTSI_LOC/u_boot_dtsi_loc/
> > - Patch #4: s/DEVICE_TREE_LOC/dt_dir/ and s/U-boot/U-Boot/
> > - Patch #5: s/U-boot/U-Boot/
> > - Patch #6 and #7: Picked up review tags
> >
> > Prerequisite
> > 
> >
> > This patch series requires devicetree-rebasing git repo to be added as a
> > subtree to the main U-Boot repo via:
> >
> > $ git subtree add --prefix devicetree-rebasing \
> >   
> > git://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git
> >  \
> >   v6.6-dts --squash
> >
> > Background
> > --
> >
> > This effort started while I was reviewing patch series corresponding to
> > Qcom platforms [1] which was about to import modified devicetree source
> > files from Linux kernel. I suppose keeping devicetree files sync with
> > Linux kernel without any DT bindings schema validation has been a pain
> > for U-Boot SoC/platform maintainers. There has been past discussions
> > about a single DT repo but that hasn't come up and Linux kernel remained
> > the place where DT source files as well as bindings are placed and
> > maintained.
> 
>  Thanks for doing this.
> 
>  I really suggest to store information that kernel DTS is directly
>  re-used, thus DTS backward and forward compatibility matters, also in
>  Linux kernel sources. The point is that sub-arch maintainers should be
>  aware of it. I don't think that as DT maintainers we can efficiently
>  keep an eye on it. Maybe create a subsystem profile and include it to
>  maintainer entries of such affected platforms?
> 
> >>>
> >>> From U-Boot point of view, currently we have the config option:
> >>> "CONFIG_OF_UPSTREAM=y" per platform which means directly re-use of
> >>> kernel DTS. So U-Boot sub-arch maintainers should be aware of
> >>> platforms which get converted to re-use kernel DTS.
> >>
> >> I was speaking about kernel.
> >>
> >>>
> >>> I suppose we have to relay information to kernel sub-arch maintainers
> >>> who aren't the same as maintaining U-Boot counterparts. How about
> >>> adding U-Boot ML to CC for whichever DT change gets submitted in the
> >>
> >> And every other project? Just setup lei filters.
> >>
> >>> kernel? Otherwise adding U-Boot sub-arch maintainers as reviewers for
> >>> corresponding kernel DT changes works too if that's acceptable.
> >>
> >> You just entirely ignored my proposal without addressing it... ok let it
> >> be. No, CC-ing U-boot maintainers changes nothing because as I said, I
> >> want kernel maintainers and contributors to be aware.
> > 
> > Maybe an underlying question is, what kernel maintainers aren't aware,
> > but should have been already? Then we can figure out how to address
> 
> None of them is aware.
> 
> > that. For example, with your Samsung hat on you weren't aware that
> > exynos 4/5/7 DTS files are cared about by U-Boot, but are now aware.
> 
> Hm, I am still not aware of this. I mean, you wrote it above, but it is
> the first time I see using directly usptream DTS for U-Boot on Samsung
> platforms.
> 
> Did anyone test it actually? I certainly did not. I think this patchset
> did not remove U-Boot-tree Samsung DTS, did it?

With this literal patchset, only the amlogic platforms Sumit is changing
have been tested, yes. In general, the U-Boot guideline has been "resync
your DTS files from the kernel as often as possible" as well as "start
with DTS files from the kernel, not hand-crafted". And some SoCs/vendors
have been better about following these rules than others. There's a good
number of commits under arch/arm/dts/ today syncing up with various
states of v6.6. Which I guess emphasises my question, what kernel
maintainers weren't aware that U-Boot has been consuming their DTS files
as-is (as much as possible) for a number of years now?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 0/8] An effort to bring DT bindings compliance within U-Boot

2023-12-22 Thread Krzysztof Kozlowski
On 22/12/2023 16:46, Tom Rini wrote:
> On Fri, Dec 22, 2023 at 04:38:01PM +0100, Krzysztof Kozlowski wrote:
>> On 22/12/2023 14:43, Sumit Garg wrote:
>>> On Fri, 22 Dec 2023 at 13:48, Krzysztof Kozlowski
>>>  wrote:

 On 22/12/2023 07:12, Sumit Garg wrote:
> Changes in v2:
> --
> - Patch #1: excluded gitab CI config check and added commit description.
> - Patch #3: s/UBOOT_DTSI_LOC/u_boot_dtsi_loc/
> - Patch #4: s/DEVICE_TREE_LOC/dt_dir/ and s/U-boot/U-Boot/
> - Patch #5: s/U-boot/U-Boot/
> - Patch #6 and #7: Picked up review tags
>
> Prerequisite
> 
>
> This patch series requires devicetree-rebasing git repo to be added as a
> subtree to the main U-Boot repo via:
>
> $ git subtree add --prefix devicetree-rebasing \
>   
> git://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git
>  \
>   v6.6-dts --squash
>
> Background
> --
>
> This effort started while I was reviewing patch series corresponding to
> Qcom platforms [1] which was about to import modified devicetree source
> files from Linux kernel. I suppose keeping devicetree files sync with
> Linux kernel without any DT bindings schema validation has been a pain
> for U-Boot SoC/platform maintainers. There has been past discussions
> about a single DT repo but that hasn't come up and Linux kernel remained
> the place where DT source files as well as bindings are placed and
> maintained.

 Thanks for doing this.

 I really suggest to store information that kernel DTS is directly
 re-used, thus DTS backward and forward compatibility matters, also in
 Linux kernel sources. The point is that sub-arch maintainers should be
 aware of it. I don't think that as DT maintainers we can efficiently
 keep an eye on it. Maybe create a subsystem profile and include it to
 maintainer entries of such affected platforms?

>>>
>>> From U-Boot point of view, currently we have the config option:
>>> "CONFIG_OF_UPSTREAM=y" per platform which means directly re-use of
>>> kernel DTS. So U-Boot sub-arch maintainers should be aware of
>>> platforms which get converted to re-use kernel DTS.
>>
>> I was speaking about kernel.
>>
>>>
>>> I suppose we have to relay information to kernel sub-arch maintainers
>>> who aren't the same as maintaining U-Boot counterparts. How about
>>> adding U-Boot ML to CC for whichever DT change gets submitted in the
>>
>> And every other project? Just setup lei filters.
>>
>>> kernel? Otherwise adding U-Boot sub-arch maintainers as reviewers for
>>> corresponding kernel DT changes works too if that's acceptable.
>>
>> You just entirely ignored my proposal without addressing it... ok let it
>> be. No, CC-ing U-boot maintainers changes nothing because as I said, I
>> want kernel maintainers and contributors to be aware.
> 
> Maybe an underlying question is, what kernel maintainers aren't aware,
> but should have been already? Then we can figure out how to address

None of them is aware.

> that. For example, with your Samsung hat on you weren't aware that
> exynos 4/5/7 DTS files are cared about by U-Boot, but are now aware.

Hm, I am still not aware of this. I mean, you wrote it above, but it is
the first time I see using directly usptream DTS for U-Boot on Samsung
platforms.

Did anyone test it actually? I certainly did not. I think this patchset
did not remove U-Boot-tree Samsung DTS, did it?

Best regards,
Krzysztof



Re: [PATCH v2 0/8] An effort to bring DT bindings compliance within U-Boot

2023-12-22 Thread Krzysztof Kozlowski
On 22/12/2023 16:45, Conor Dooley wrote:
>>>
>>> I suppose we have to relay information to kernel sub-arch maintainers
>>> who aren't the same as maintaining U-Boot counterparts. How about
>>> adding U-Boot ML to CC for whichever DT change gets submitted in the
>>
>> And every other project? Just setup lei filters.
>>
>>> kernel? Otherwise adding U-Boot sub-arch maintainers as reviewers for
>>> corresponding kernel DT changes works too if that's acceptable.
>>
>> You just entirely ignored my proposal without addressing it... ok let it
>> be. No, CC-ing U-boot maintainers changes nothing because as I said, I
>> want kernel maintainers and contributors to be aware.
> 
> I don't think that adding U-Boot platform maintainers as reviewers for
> the platforms in the kernel is a terrible idea. Certainly kernel
> platform maintainers for which U-Boot platform maintainers are added to
> the MAINTAINERS entry will be aware. That said, something like your

The point is it does not solve my concern here. I did not express
problem that U-Boot maintainers are not aware. They can easily be aware
by setting simple lei filters.

The problem I want to solve is the kernel maintainers to be aware.

Best regards,
Krzysztof



Re: [PATCH 1/1] bootmeth: pass size to efi_binary_run()

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 05:46:11PM +0200, Ilias Apalodimas wrote:
> On Fri, 22 Dec 2023 at 17:43, Peter Robinson  wrote:
> >
> > On Fri, Dec 22, 2023 at 3:37 PM Tom Rini  wrote:
> > >
> > > On Fri, 22 Dec 2023 16:01:56 +0100, Heinrich Schuchardt wrote:
> > >
> > > > If we call efi_binary_run() with size parameter set to zero, we get an 
> > > > error
> > > >
> > > >  Not a PE-COFF file
> > > >
> > > > Fill the missing value.
> > > >
> > > >
> > > > [...]
> > >
> > > Applied to u-boot/next, thanks!
> >
> > Is this a fix that should land for 2024.01?
> 
> I was about to ask the same. I think it should go into -master as well

This specifically fixes the merge of -rc5 in to -next however.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/1] bootmeth: pass size to efi_binary_run()

2023-12-22 Thread Ilias Apalodimas
On Fri, 22 Dec 2023 at 17:43, Peter Robinson  wrote:
>
> On Fri, Dec 22, 2023 at 3:37 PM Tom Rini  wrote:
> >
> > On Fri, 22 Dec 2023 16:01:56 +0100, Heinrich Schuchardt wrote:
> >
> > > If we call efi_binary_run() with size parameter set to zero, we get an 
> > > error
> > >
> > >  Not a PE-COFF file
> > >
> > > Fill the missing value.
> > >
> > >
> > > [...]
> >
> > Applied to u-boot/next, thanks!
>
> Is this a fix that should land for 2024.01?

I was about to ask the same. I think it should go into -master as well

Thanks
/Ilias


Re: [PATCH v2 0/8] An effort to bring DT bindings compliance within U-Boot

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 04:38:01PM +0100, Krzysztof Kozlowski wrote:
> On 22/12/2023 14:43, Sumit Garg wrote:
> > On Fri, 22 Dec 2023 at 13:48, Krzysztof Kozlowski
> >  wrote:
> >>
> >> On 22/12/2023 07:12, Sumit Garg wrote:
> >>> Changes in v2:
> >>> --
> >>> - Patch #1: excluded gitab CI config check and added commit description.
> >>> - Patch #3: s/UBOOT_DTSI_LOC/u_boot_dtsi_loc/
> >>> - Patch #4: s/DEVICE_TREE_LOC/dt_dir/ and s/U-boot/U-Boot/
> >>> - Patch #5: s/U-boot/U-Boot/
> >>> - Patch #6 and #7: Picked up review tags
> >>>
> >>> Prerequisite
> >>> 
> >>>
> >>> This patch series requires devicetree-rebasing git repo to be added as a
> >>> subtree to the main U-Boot repo via:
> >>>
> >>> $ git subtree add --prefix devicetree-rebasing \
> >>>   
> >>> git://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git
> >>>  \
> >>>   v6.6-dts --squash
> >>>
> >>> Background
> >>> --
> >>>
> >>> This effort started while I was reviewing patch series corresponding to
> >>> Qcom platforms [1] which was about to import modified devicetree source
> >>> files from Linux kernel. I suppose keeping devicetree files sync with
> >>> Linux kernel without any DT bindings schema validation has been a pain
> >>> for U-Boot SoC/platform maintainers. There has been past discussions
> >>> about a single DT repo but that hasn't come up and Linux kernel remained
> >>> the place where DT source files as well as bindings are placed and
> >>> maintained.
> >>
> >> Thanks for doing this.
> >>
> >> I really suggest to store information that kernel DTS is directly
> >> re-used, thus DTS backward and forward compatibility matters, also in
> >> Linux kernel sources. The point is that sub-arch maintainers should be
> >> aware of it. I don't think that as DT maintainers we can efficiently
> >> keep an eye on it. Maybe create a subsystem profile and include it to
> >> maintainer entries of such affected platforms?
> >>
> > 
> > From U-Boot point of view, currently we have the config option:
> > "CONFIG_OF_UPSTREAM=y" per platform which means directly re-use of
> > kernel DTS. So U-Boot sub-arch maintainers should be aware of
> > platforms which get converted to re-use kernel DTS.
> 
> I was speaking about kernel.
> 
> > 
> > I suppose we have to relay information to kernel sub-arch maintainers
> > who aren't the same as maintaining U-Boot counterparts. How about
> > adding U-Boot ML to CC for whichever DT change gets submitted in the
> 
> And every other project? Just setup lei filters.
> 
> > kernel? Otherwise adding U-Boot sub-arch maintainers as reviewers for
> > corresponding kernel DT changes works too if that's acceptable.
> 
> You just entirely ignored my proposal without addressing it... ok let it
> be. No, CC-ing U-boot maintainers changes nothing because as I said, I
> want kernel maintainers and contributors to be aware.

Maybe an underlying question is, what kernel maintainers aren't aware,
but should have been already? Then we can figure out how to address
that. For example, with your Samsung hat on you weren't aware that
exynos 4/5/7 DTS files are cared about by U-Boot, but are now aware.
Samsung platforms are only recently becoming more active in U-Boot as
well, so that's all understandable. On the other hand TI folks know, and
I expect the K3 families to switch over to this series ASAP, and STM32
and all of the AMD/Xilinx stuff too.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 3/9] bloblist: refactor of bloblist_reloc()

2023-12-22 Thread Ilias Apalodimas
Hi Raymond,

On Fri, 22 Dec 2023 at 17:30, Raymond Mao  wrote:
>
> Hi Ilias,
>
> On Fri, 22 Dec 2023 at 06:12, Ilias Apalodimas  
> wrote:
>>
>> Hi Raymond,
>>
>> On Thu, 21 Dec 2023 at 02:41, Raymond Mao  wrote:
>> >
>> > The current bloblist pointer and size can be retrieved from global
>> > data, so we don't need to pass them from the function arguments.
>> > This change also help to remove all external access of gd->bloblist
>> > outside of bloblist module.
>> >
>> > Signed-off-by: Raymond Mao 
>> > ---
>>
>> [...]
>>
>> > }
>> >  }
>> >
>> > -void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
>> > +void bloblist_reloc(void *to, uint to_size)
>> >  {
>> > struct bloblist_hdr *hdr;
>> >
>> > -   memcpy(to, from, from_size);
>> > +   memcpy(to, gd->bloblist, gd->bloblist->total_size);
>> > hdr = to;
>> > -   hdr->total_size = to_size;
>> > +   if (to_size < gd->bloblist->total_size)
>>
>> What's the size of *to? Is it equal to to_size?
>> Because if to_size can be smaller that gd->bloblist->total_size the
>> memcpy above is wrong
>
> to_size should be 0 (use the total_size) or a value larger than total_size.
> I think I should keep the below line from the function header.

The point here is, are we certain that the *to is big enough? Or we'll
end up overflowing ?

Thanks
/Ilias
> >> - * @to_size: New size for bloblist (must be larger than from_size)
> I will refactor this part.
>
>>
>> > +   hdr->total_size = gd->bloblist->total_size;
>> > +   else
>> > +   hdr->total_size = to_size;
>> > +   gd->bloblist = to;
>> >  }
>> >
>> >  int bloblist_init(void)
>> > diff --git a/common/board_f.c b/common/board_f.c
>> > index d4d7d01f8f..00b0430889 100644
>> > --- a/common/board_f.c
>>
>> [...]
>>
>> /Ilias


Re: [PATCH v2 0/8] An effort to bring DT bindings compliance within U-Boot

2023-12-22 Thread Conor Dooley
On Fri, Dec 22, 2023 at 04:38:01PM +0100, Krzysztof Kozlowski wrote:
> On 22/12/2023 14:43, Sumit Garg wrote:
> > On Fri, 22 Dec 2023 at 13:48, Krzysztof Kozlowski
> >  wrote:
> >>
> >> On 22/12/2023 07:12, Sumit Garg wrote:
> >>> Changes in v2:
> >>> --
> >>> - Patch #1: excluded gitab CI config check and added commit description.
> >>> - Patch #3: s/UBOOT_DTSI_LOC/u_boot_dtsi_loc/
> >>> - Patch #4: s/DEVICE_TREE_LOC/dt_dir/ and s/U-boot/U-Boot/
> >>> - Patch #5: s/U-boot/U-Boot/
> >>> - Patch #6 and #7: Picked up review tags
> >>>
> >>> Prerequisite
> >>> 
> >>>
> >>> This patch series requires devicetree-rebasing git repo to be added as a
> >>> subtree to the main U-Boot repo via:
> >>>
> >>> $ git subtree add --prefix devicetree-rebasing \
> >>>   
> >>> git://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git
> >>>  \
> >>>   v6.6-dts --squash
> >>>
> >>> Background
> >>> --
> >>>
> >>> This effort started while I was reviewing patch series corresponding to
> >>> Qcom platforms [1] which was about to import modified devicetree source
> >>> files from Linux kernel. I suppose keeping devicetree files sync with
> >>> Linux kernel without any DT bindings schema validation has been a pain
> >>> for U-Boot SoC/platform maintainers. There has been past discussions
> >>> about a single DT repo but that hasn't come up and Linux kernel remained
> >>> the place where DT source files as well as bindings are placed and
> >>> maintained.
> >>
> >> Thanks for doing this.
> >>
> >> I really suggest to store information that kernel DTS is directly
> >> re-used, thus DTS backward and forward compatibility matters, also in
> >> Linux kernel sources. The point is that sub-arch maintainers should be
> >> aware of it. I don't think that as DT maintainers we can efficiently
> >> keep an eye on it. Maybe create a subsystem profile and include it to
> >> maintainer entries of such affected platforms?
> >>
> > 
> > From U-Boot point of view, currently we have the config option:
> > "CONFIG_OF_UPSTREAM=y" per platform which means directly re-use of
> > kernel DTS. So U-Boot sub-arch maintainers should be aware of
> > platforms which get converted to re-use kernel DTS.
> 
> I was speaking about kernel.
> 
> > 
> > I suppose we have to relay information to kernel sub-arch maintainers
> > who aren't the same as maintaining U-Boot counterparts. How about
> > adding U-Boot ML to CC for whichever DT change gets submitted in the
> 
> And every other project? Just setup lei filters.
> 
> > kernel? Otherwise adding U-Boot sub-arch maintainers as reviewers for
> > corresponding kernel DT changes works too if that's acceptable.
> 
> You just entirely ignored my proposal without addressing it... ok let it
> be. No, CC-ing U-boot maintainers changes nothing because as I said, I
> want kernel maintainers and contributors to be aware.

I don't think that adding U-Boot platform maintainers as reviewers for
the platforms in the kernel is a terrible idea. Certainly kernel
platform maintainers for which U-Boot platform maintainers are added to
the MAINTAINERS entry will be aware. That said, something like your
"strict dts compliance" maintainer profile entry [1] would be helpful I think
to denote which platforms' dts are being shared in this manner

1:
ARM/SAMSUNG S3C, S5P AND EXYNOS ARM ARCHITECTURES
M:  Krzysztof Kozlowski 
R:  Alim Akhtar 
L:  linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
L:  linux-samsung-...@vger.kernel.org
S:  Maintained
P:  Documentation/process/maintainer-soc-clean-dts.rst
Q:  https://patchwork.kernel.org/project/linux-samsung-soc/list/


signature.asc
Description: PGP signature


[PATCH 1/1] MAINTAINERS: fix folders within glob pattern

2023-12-22 Thread Anthony Loiseau
From: Anthony Loiseau 

A "F: foo*" entry does not match any foo*/ folder nor its subtree,
another "F: foo*/" entry is needed for that.

Add missing foo*/ entries where an existing folder was ignored,
so this folder and its subtree is properly covered.

Arm tegra, Arm TI and Environment sections are affected.

Cc: Tom Rini 
Cc: Thierry Reding 
Cc: Svyatoslav Ryhel 
Cc: Tom Rini 
Cc: Joe Hershberger 
Signed-off-by: Anthony Loiseau 
---
 MAINTAINERS | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 969514468c..8c57d142d7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -675,6 +675,7 @@ F:  arch/arm/dts/tegra*
 F: arch/arm/include/asm/arch-tegra*/
 F: arch/arm/mach-tegra/
 F: drivers/*/tegra*
+F: drivers/*/tegra*/
 
 ARM TI
 M: Tom Rini 
@@ -690,6 +691,7 @@ F:  arch/arm/include/asm/arch-omap*/
 F: arch/arm/include/asm/ti-common/
 F: board/ti/
 F: drivers/dma/ti*
+F: drivers/dma/ti*/
 F: drivers/firmware/ti_sci.*
 F: drivers/gpio/omap_gpio.c
 F: drivers/memory/ti-aemif.c
@@ -701,6 +703,7 @@ F:  drivers/phy/omap-usb2-phy.c
 F: drivers/phy/phy-ti-am654.c
 F: drivers/phy/ti-pipe3-phy.c
 F: drivers/ram/k3*
+F: drivers/ram/k3*/
 F: drivers/remoteproc/ipu_rproc.c
 F: drivers/remoteproc/k3_system_controller.c
 F: drivers/remoteproc/pruc_rpoc.c
@@ -1029,8 +1032,10 @@ ENVIRONMENT
 M: Joe Hershberger 
 S: Maintained
 F: env/
+F: include/env/
 F: include/env*
 F: test/env/
+F: tools/env/
 F: tools/env*
 F: tools/mkenvimage.c
 
-- 
2.11.0



[PATCH 0/1] MAINTAINERS: fix folders within glob pattern

2023-12-22 Thread Anthony Loiseau
From: Anthony Loiseau 

This patch fixes few folders I think mishandled within MAINTAINERS file.

For example, files within drivers/clk/tegra/ were not affilated to ARM TEGRA
because rule "F: drivers/*/tegra*" does not match them. See MAINTAINERS file
embedded documentation on top.

The same for tools/env/* files which where not affiliated to Environment
section despite the "F: tools/env*" rule.

It worth be noted that despite I successfully tested this update for
Arm Tegra and Environment sections, Arm TI related updates does nothing.
My feeling is that those updates are good and wanted but another issue remains.
It looks like all sections maintained by Tom Rini are entirely ignored, I don't
know why and did not dig into it deeply.

Example of test:
./scripts/get_maintainer.pl -f drivers/clk/tegra/Makefile
now lists Arm Tegra maintainers were it did not.

Cc: Tom Rini 
Cc: Thierry Reding 
Cc: Svyatoslav Ryhel 
Cc: Tom Rini 
Cc: Joe Hershberger 
Signed-off-by: Anthony Loiseau 

Anthony Loiseau (1):
  MAINTAINERS: fix folders within glob pattern

 MAINTAINERS | 5 +
 1 file changed, 5 insertions(+)

-- 
2.11.0



Re: [PATCH 1/1] bootmeth: pass size to efi_binary_run()

2023-12-22 Thread Peter Robinson
On Fri, Dec 22, 2023 at 3:37 PM Tom Rini  wrote:
>
> On Fri, 22 Dec 2023 16:01:56 +0100, Heinrich Schuchardt wrote:
>
> > If we call efi_binary_run() with size parameter set to zero, we get an error
> >
> >  Not a PE-COFF file
> >
> > Fill the missing value.
> >
> >
> > [...]
>
> Applied to u-boot/next, thanks!

Is this a fix that should land for 2024.01?


Re: [PATCH v2 0/8] An effort to bring DT bindings compliance within U-Boot

2023-12-22 Thread Krzysztof Kozlowski
On 22/12/2023 14:43, Sumit Garg wrote:
> On Fri, 22 Dec 2023 at 13:48, Krzysztof Kozlowski
>  wrote:
>>
>> On 22/12/2023 07:12, Sumit Garg wrote:
>>> Changes in v2:
>>> --
>>> - Patch #1: excluded gitab CI config check and added commit description.
>>> - Patch #3: s/UBOOT_DTSI_LOC/u_boot_dtsi_loc/
>>> - Patch #4: s/DEVICE_TREE_LOC/dt_dir/ and s/U-boot/U-Boot/
>>> - Patch #5: s/U-boot/U-Boot/
>>> - Patch #6 and #7: Picked up review tags
>>>
>>> Prerequisite
>>> 
>>>
>>> This patch series requires devicetree-rebasing git repo to be added as a
>>> subtree to the main U-Boot repo via:
>>>
>>> $ git subtree add --prefix devicetree-rebasing \
>>>   
>>> git://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git
>>>  \
>>>   v6.6-dts --squash
>>>
>>> Background
>>> --
>>>
>>> This effort started while I was reviewing patch series corresponding to
>>> Qcom platforms [1] which was about to import modified devicetree source
>>> files from Linux kernel. I suppose keeping devicetree files sync with
>>> Linux kernel without any DT bindings schema validation has been a pain
>>> for U-Boot SoC/platform maintainers. There has been past discussions
>>> about a single DT repo but that hasn't come up and Linux kernel remained
>>> the place where DT source files as well as bindings are placed and
>>> maintained.
>>
>> Thanks for doing this.
>>
>> I really suggest to store information that kernel DTS is directly
>> re-used, thus DTS backward and forward compatibility matters, also in
>> Linux kernel sources. The point is that sub-arch maintainers should be
>> aware of it. I don't think that as DT maintainers we can efficiently
>> keep an eye on it. Maybe create a subsystem profile and include it to
>> maintainer entries of such affected platforms?
>>
> 
> From U-Boot point of view, currently we have the config option:
> "CONFIG_OF_UPSTREAM=y" per platform which means directly re-use of
> kernel DTS. So U-Boot sub-arch maintainers should be aware of
> platforms which get converted to re-use kernel DTS.

I was speaking about kernel.

> 
> I suppose we have to relay information to kernel sub-arch maintainers
> who aren't the same as maintaining U-Boot counterparts. How about
> adding U-Boot ML to CC for whichever DT change gets submitted in the

And every other project? Just setup lei filters.

> kernel? Otherwise adding U-Boot sub-arch maintainers as reviewers for
> corresponding kernel DT changes works too if that's acceptable.

You just entirely ignored my proposal without addressing it... ok let it
be. No, CC-ing U-boot maintainers changes nothing because as I said, I
want kernel maintainers and contributors to be aware.

Best regards,
Krzysztof



Re: [PATCH 1/1] bootmeth: pass size to efi_binary_run()

2023-12-22 Thread Tom Rini
On Fri, 22 Dec 2023 16:01:56 +0100, Heinrich Schuchardt wrote:

> If we call efi_binary_run() with size parameter set to zero, we get an error
> 
>  Not a PE-COFF file
> 
> Fill the missing value.
> 
> 
> [...]

Applied to u-boot/next, thanks!

-- 
Tom




Re: [PATCH v2 6/9] qemu-arm: Get bloblist from boot arguments

2023-12-22 Thread Raymond Mao
On Fri, 22 Dec 2023 at 06:19, Ilias Apalodimas 
wrote:

> >  #endif
> >
> > +/* Boot parameters saved from start.S */
> > +extern unsigned long saved_args[];
> > +
> >  int board_init(void)
> >  {
> > return 0;
> > @@ -144,6 +148,35 @@ void *board_fdt_blob_setup(int *err)
> > return (void *)CFG_SYS_SDRAM_BASE;
> >  }
> >
> > +int board_bloblist_from_boot_arg(unsigned long addr, unsigned long size)
> > +{
> > +   int ret = -ENOENT;
> > +   unsigned long reg_fdt;
> > +   unsigned long reg_zero;
> > +
> > +   if (!IS_ENABLED(CONFIG_OF_BOARD) || !IS_ENABLED(CONFIG_BLOBLIST))
> > +   return -ENOENT;
> > +
> > +   ret = bloblist_check(saved_args[3], size);
> > +   if (ret)
> > +   return ret;
> > +
> > +   if (IS_ENABLED(CONFIG_ARM64)) {
> > +   reg_fdt = saved_args[0];
> > +   reg_zero = saved_args[2];
> > +   } else {
> > +   reg_fdt = saved_args[2];
> > +   reg_zero = saved_args[0];
>
> I think it's better if we fix up the order in the low-level asm code.
> Store the variables in the 'correct' order there and get rid of this
> if
>
Yes I agree. I can swap the order for aarch32.

Thanks and regards,
Raymond


Re: [PATCH v2 3/9] bloblist: refactor of bloblist_reloc()

2023-12-22 Thread Raymond Mao
Hi Ilias,

On Fri, 22 Dec 2023 at 06:12, Ilias Apalodimas 
wrote:

> Hi Raymond,
>
> On Thu, 21 Dec 2023 at 02:41, Raymond Mao  wrote:
> >
> > The current bloblist pointer and size can be retrieved from global
> > data, so we don't need to pass them from the function arguments.
> > This change also help to remove all external access of gd->bloblist
> > outside of bloblist module.
> >
> > Signed-off-by: Raymond Mao 
> > ---
>
> [...]
>
> > }
> >  }
> >
> > -void bloblist_reloc(void *to, uint to_size, void *from, uint from_size)
> > +void bloblist_reloc(void *to, uint to_size)
> >  {
> > struct bloblist_hdr *hdr;
> >
> > -   memcpy(to, from, from_size);
> > +   memcpy(to, gd->bloblist, gd->bloblist->total_size);
> > hdr = to;
> > -   hdr->total_size = to_size;
> > +   if (to_size < gd->bloblist->total_size)
>
> What's the size of *to? Is it equal to to_size?
> Because if to_size can be smaller that gd->bloblist->total_size the
> memcpy above is wrong
>
to_size should be 0 (use the total_size) or a value larger than total_size.
I think I should keep the below line from the function header.
>> - * @to_size: New size for bloblist (must be larger than from_size)
I will refactor this part.


> > +   hdr->total_size = gd->bloblist->total_size;
> > +   else
> > +   hdr->total_size = to_size;
> > +   gd->bloblist = to;
> >  }
> >
> >  int bloblist_init(void)
> > diff --git a/common/board_f.c b/common/board_f.c
> > index d4d7d01f8f..00b0430889 100644
> > --- a/common/board_f.c
>
> [...]
>
> /Ilias
>


Re: [PATCH v2 1/9] bloblist: add API to check the register conventions

2023-12-22 Thread Raymond Mao
On Fri, 22 Dec 2023 at 05:55, Ilias Apalodimas 
wrote:

> ...
> The function looks correct, but the name is a bit off. There are no
> registers conventions check AFAICT. We are just comparing 2 addresses.
> Am I missing anything?
>
The function name is from the spec. Below is the section describes the
expectation of arg[0-3]:
https://github.com/FirmwareHandoff/firmware_handoff/blob/main/source/register_conventions.rst

Thanks and regards,
Raymond


Re: [PATCH 1/1] bootmeth: pass size to efi_binary_run()

2023-12-22 Thread Ilias Apalodimas
On Fri, 22 Dec 2023 at 17:02, Heinrich Schuchardt  wrote:
>
> If we call efi_binary_run() with size parameter set to zero, we get an error
>
>  Not a PE-COFF file
>
> Fill the missing value.
>
> Fixes: 1373ffde52e1 ("Merge tag 'v2024.01-rc5' into next")
> Fixes: 7017fc54a5bc ("bootmeth: use efi_loader interfaces instead of bootefi 
> command")
> Signed-off-by: Heinrich Schuchardt 
> ---
>  boot/bootmeth_efi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
> index 00060f7d25..c4eb331d69 100644
> --- a/boot/bootmeth_efi.c
> +++ b/boot/bootmeth_efi.c
> @@ -454,12 +454,12 @@ static int distro_efi_boot(struct udevice *dev, struct 
> bootflow *bflow)
>
> if (bflow->flags & BOOTFLOWF_USE_BUILTIN_FDT) {
> log_debug("Booting with built-in fdt\n");
> -   if (efi_binary_run(map_sysmem(kernel, 0), 0,
> +   if (efi_binary_run(map_sysmem(kernel, 0), bflow->size,
>EFI_FDT_USE_INTERNAL))
> return log_msg_ret("run", -EINVAL);
> } else {
> log_debug("Booting with external fdt\n");
> -   if (efi_binary_run(map_sysmem(kernel, 0), 0,
> +   if (efi_binary_run(map_sysmem(kernel, 0), bflow->size,
>map_sysmem(fdt, 0)))
> return log_msg_ret("run", -EINVAL);
> }
> --
> 2.43.0
>
Reviewed-by: Ilias Apalodimas 


[PATCH 1/1] bootmeth: pass size to efi_binary_run()

2023-12-22 Thread Heinrich Schuchardt
If we call efi_binary_run() with size parameter set to zero, we get an error

 Not a PE-COFF file

Fill the missing value.

Fixes: 1373ffde52e1 ("Merge tag 'v2024.01-rc5' into next")
Fixes: 7017fc54a5bc ("bootmeth: use efi_loader interfaces instead of bootefi 
command")
Signed-off-by: Heinrich Schuchardt 
---
 boot/bootmeth_efi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
index 00060f7d25..c4eb331d69 100644
--- a/boot/bootmeth_efi.c
+++ b/boot/bootmeth_efi.c
@@ -454,12 +454,12 @@ static int distro_efi_boot(struct udevice *dev, struct 
bootflow *bflow)

if (bflow->flags & BOOTFLOWF_USE_BUILTIN_FDT) {
log_debug("Booting with built-in fdt\n");
-   if (efi_binary_run(map_sysmem(kernel, 0), 0,
+   if (efi_binary_run(map_sysmem(kernel, 0), bflow->size,
   EFI_FDT_USE_INTERNAL))
return log_msg_ret("run", -EINVAL);
} else {
log_debug("Booting with external fdt\n");
-   if (efi_binary_run(map_sysmem(kernel, 0), 0,
+   if (efi_binary_run(map_sysmem(kernel, 0), bflow->size,
   map_sysmem(fdt, 0)))
return log_msg_ret("run", -EINVAL);
}
--
2.43.0



[PATCH v4] dts: rockpro64: Disable usb regulators-always-on

2023-12-22 Thread Shantur Rathore
USB port regulators should be controlled by PHYs
so we remove always-on property and let phy manage the
regulator.

phy-supply isn't configured for TypeC port in upstream and
now that we are removing always-on, we need to add the
phy-supply until its fixed upstream.

Signed-off-by: Shantur Rathore 

---

Changes in v4:
- otg port must be configured with phy-supply instead of host port node

Changes in v3:
- Split up patches as seperate series

Changes in v2:
- As requested, added fix for regulator-always-on in RockPro64

 arch/arm/dts/rk3399-rockpro64-u-boot.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/dts/rk3399-rockpro64-u-boot.dtsi 
b/arch/arm/dts/rk3399-rockpro64-u-boot.dtsi
index 732727d9b0..0ac9fa9a03 100644
--- a/arch/arm/dts/rk3399-rockpro64-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-rockpro64-u-boot.dtsi
@@ -22,6 +22,18 @@
};
 };
 
+&u2phy0_otg {
+   phy-supply = <&vcc5v0_typec>;
+};
+
+&vcc5v0_host {
+   /delete-property/ regulator-always-on;
+};
+
+&vcc5v0_typec {
+   /delete-property/ regulator-always-on;
+};
+
 &vdd_center {
regulator-min-microvolt = <95>;
regulator-max-microvolt = <95>;
-- 
2.40.1



Re: [PATCH v2 5/8] doc: devicetree: Updates for devicetree-rebasing subtree

2023-12-22 Thread Sumit Garg
On Fri, 22 Dec 2023 at 19:26, Tom Rini  wrote:
>
> On Fri, Dec 22, 2023 at 07:18:05PM +0530, Sumit Garg wrote:
> > On Fri, 22 Dec 2023 at 18:05, Tom Rini  wrote:
> > >
> > > On Fri, Dec 22, 2023 at 11:42:05AM +0530, Sumit Garg wrote:
> > >
> > > > Encourage SoC/board maintainers to migrate to using devicetree-rebasing
> > > > subtree and maintain a regular sync with Linux kernel devicetree files
> > > > and bindings.
> > > >
> > > > Along with that add documentation regarding how to run DT bindings
> > > > schema checks.
> > > >
> > > > Signed-off-by: Sumit Garg 
> > > > ---
> > > >  doc/develop/devicetree/control.rst | 108 +++--
> > > >  1 file changed, 86 insertions(+), 22 deletions(-)
> > > [snip]
> > > > @@ -81,18 +94,21 @@ Failing that, you could write one from scratch 
> > > > yourself!
> > > >  Configuration
> > > >  -
> > > >
> > > > -Use::
> > > > +Traditionally, U-Boot placed copies of devicetree source files from 
> > > > Linux
> > > > +kernel into `arch//dts/.dts` which can be selected via::
> > > >
> > > > -   #define CONFIG_DEFAULT_DEVICE_TREE""
> > > > +#define CONFIG_DEFAULT_DEVICE_TREE   ""
> > >
> > > Oh, oof. This never got updated for Kconfig rather than config.h. Can
> > > you please include re-wording this to be setting  when prompted
> > > for DEFAULT_DEVICE_TREE by Kconfig? And the rest of the text you're
> > > updating as well to match, thanks.
> > >
> >
> > Sure but how about changing it to say via board defconfig as
> > CONFIG_DEFAULT_DEVICE_TREE="", since AFAIK most people use
> > defconfig to configure U-Boot.
>
> Well, do kernel docs tell people to modify defconfigs, or to use the
> config menu/etc?
>

Okay I see your point, I will use wording to select
DEFAULT_DEVICE_TREE by Kconfig instead.

-Sumit

> --
> Tom


Re: [PATCH v2 7/8] dts: meson-gxbb: Switch to using upstream DT

2023-12-22 Thread Sumit Garg
On Fri, 22 Dec 2023 at 19:24, Tom Rini  wrote:
>
> On Fri, Dec 22, 2023 at 06:50:32PM +0530, Sumit Garg wrote:
> > On Fri, 22 Dec 2023 at 18:01, Tom Rini  wrote:
> > >
> > > On Fri, Dec 22, 2023 at 11:42:07AM +0530, Sumit Garg wrote:
> > >
> > > > Although there were still some variations in board DTS files based on
> > > > meson-gxbb SoC but I think those were minor differences from upstream
> > > > and shouldn't impact boot on these devices.
> > > >
> > > > So switch to upstream DT via mirroring amlogic/ directory from
> > > > devicetree-rebasing/src/arm64/amlogic/ directory. And thereby directly
> > > > building DTB from there including *-u-boot.dtsi files from
> > > > arch/$(ARCH)/dts/ directory.
> > > >
> > > > Reviewed-by: Neil Armstrong 
> > > > Signed-off-by: Sumit Garg 
> > > > ---
> > > >  configs/nanopi-k2_defconfig   | 3 ++-
> > > >  configs/odroid-c2_defconfig   | 3 ++-
> > > >  configs/p200_defconfig| 3 ++-
> > > >  configs/p201_defconfig| 3 ++-
> > > >  configs/videostrong-kii-pro_defconfig | 3 ++-
> > > >  configs/wetek-hub_defconfig   | 3 ++-
> > > >  configs/wetek-play2_defconfig | 3 ++-
> > > >  dts/arch/arm64/Makefile   | 9 +
> > > >  dts/arch/arm64/amlogic| 1 +
> > > >  9 files changed, 24 insertions(+), 7 deletions(-)
> > > >  create mode 12 dts/arch/arm64/amlogic
> > >
> > > Do we need all of the Makefile portions of this? One of the things that
> > > works today is that trees listed in ONFIG_DEFAULT_DEVICE_TREE (and a few
> > > other variables) will be automatically built. We might just need the new
> > > Makefiles to just have:
> > > include $(srctree)/scripts/Makefile.dts
> > > and then the trees a given config will need will be built.
> >
> > That sounds fine for Amlogic SoC and many others too with
> > CONFIG_DEFAULT_DEVICE_TREE="" CONFIG_OF_LIST="" options available.
> > However, if in future we have truely generalized U-Boot (like efforts
> > for Qcom platform) then CONFIG_OF_LIST="" may become an overloaded
> > choice.
>
> I don't object to listing them when needed, I'm just not totally sure on
> how the use case really works out. But we can cross that when we get
> there, too.

Agree and I have similar concerns about it.

-Sumit

>
> --
> Tom


Re: [PATCH v2 5/8] doc: devicetree: Updates for devicetree-rebasing subtree

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 07:18:05PM +0530, Sumit Garg wrote:
> On Fri, 22 Dec 2023 at 18:05, Tom Rini  wrote:
> >
> > On Fri, Dec 22, 2023 at 11:42:05AM +0530, Sumit Garg wrote:
> >
> > > Encourage SoC/board maintainers to migrate to using devicetree-rebasing
> > > subtree and maintain a regular sync with Linux kernel devicetree files
> > > and bindings.
> > >
> > > Along with that add documentation regarding how to run DT bindings
> > > schema checks.
> > >
> > > Signed-off-by: Sumit Garg 
> > > ---
> > >  doc/develop/devicetree/control.rst | 108 +++--
> > >  1 file changed, 86 insertions(+), 22 deletions(-)
> > [snip]
> > > @@ -81,18 +94,21 @@ Failing that, you could write one from scratch 
> > > yourself!
> > >  Configuration
> > >  -
> > >
> > > -Use::
> > > +Traditionally, U-Boot placed copies of devicetree source files from Linux
> > > +kernel into `arch//dts/.dts` which can be selected via::
> > >
> > > -   #define CONFIG_DEFAULT_DEVICE_TREE""
> > > +#define CONFIG_DEFAULT_DEVICE_TREE   ""
> >
> > Oh, oof. This never got updated for Kconfig rather than config.h. Can
> > you please include re-wording this to be setting  when prompted
> > for DEFAULT_DEVICE_TREE by Kconfig? And the rest of the text you're
> > updating as well to match, thanks.
> >
> 
> Sure but how about changing it to say via board defconfig as
> CONFIG_DEFAULT_DEVICE_TREE="", since AFAIK most people use
> defconfig to configure U-Boot.

Well, do kernel docs tell people to modify defconfigs, or to use the
config menu/etc?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 7/8] dts: meson-gxbb: Switch to using upstream DT

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 06:50:32PM +0530, Sumit Garg wrote:
> On Fri, 22 Dec 2023 at 18:01, Tom Rini  wrote:
> >
> > On Fri, Dec 22, 2023 at 11:42:07AM +0530, Sumit Garg wrote:
> >
> > > Although there were still some variations in board DTS files based on
> > > meson-gxbb SoC but I think those were minor differences from upstream
> > > and shouldn't impact boot on these devices.
> > >
> > > So switch to upstream DT via mirroring amlogic/ directory from
> > > devicetree-rebasing/src/arm64/amlogic/ directory. And thereby directly
> > > building DTB from there including *-u-boot.dtsi files from
> > > arch/$(ARCH)/dts/ directory.
> > >
> > > Reviewed-by: Neil Armstrong 
> > > Signed-off-by: Sumit Garg 
> > > ---
> > >  configs/nanopi-k2_defconfig   | 3 ++-
> > >  configs/odroid-c2_defconfig   | 3 ++-
> > >  configs/p200_defconfig| 3 ++-
> > >  configs/p201_defconfig| 3 ++-
> > >  configs/videostrong-kii-pro_defconfig | 3 ++-
> > >  configs/wetek-hub_defconfig   | 3 ++-
> > >  configs/wetek-play2_defconfig | 3 ++-
> > >  dts/arch/arm64/Makefile   | 9 +
> > >  dts/arch/arm64/amlogic| 1 +
> > >  9 files changed, 24 insertions(+), 7 deletions(-)
> > >  create mode 12 dts/arch/arm64/amlogic
> >
> > Do we need all of the Makefile portions of this? One of the things that
> > works today is that trees listed in ONFIG_DEFAULT_DEVICE_TREE (and a few
> > other variables) will be automatically built. We might just need the new
> > Makefiles to just have:
> > include $(srctree)/scripts/Makefile.dts
> > and then the trees a given config will need will be built.
> 
> That sounds fine for Amlogic SoC and many others too with
> CONFIG_DEFAULT_DEVICE_TREE="" CONFIG_OF_LIST="" options available.
> However, if in future we have truely generalized U-Boot (like efforts
> for Qcom platform) then CONFIG_OF_LIST="" may become an overloaded
> choice.

I don't object to listing them when needed, I'm just not totally sure on
how the use case really works out. But we can cross that when we get
there, too.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 5/8] doc: devicetree: Updates for devicetree-rebasing subtree

2023-12-22 Thread Sumit Garg
On Fri, 22 Dec 2023 at 18:05, Tom Rini  wrote:
>
> On Fri, Dec 22, 2023 at 11:42:05AM +0530, Sumit Garg wrote:
>
> > Encourage SoC/board maintainers to migrate to using devicetree-rebasing
> > subtree and maintain a regular sync with Linux kernel devicetree files
> > and bindings.
> >
> > Along with that add documentation regarding how to run DT bindings
> > schema checks.
> >
> > Signed-off-by: Sumit Garg 
> > ---
> >  doc/develop/devicetree/control.rst | 108 +++--
> >  1 file changed, 86 insertions(+), 22 deletions(-)
> [snip]
> > @@ -81,18 +94,21 @@ Failing that, you could write one from scratch yourself!
> >  Configuration
> >  -
> >
> > -Use::
> > +Traditionally, U-Boot placed copies of devicetree source files from Linux
> > +kernel into `arch//dts/.dts` which can be selected via::
> >
> > -   #define CONFIG_DEFAULT_DEVICE_TREE""
> > +#define CONFIG_DEFAULT_DEVICE_TREE   ""
>
> Oh, oof. This never got updated for Kconfig rather than config.h. Can
> you please include re-wording this to be setting  when prompted
> for DEFAULT_DEVICE_TREE by Kconfig? And the rest of the text you're
> updating as well to match, thanks.
>

Sure but how about changing it to say via board defconfig as
CONFIG_DEFAULT_DEVICE_TREE="", since AFAIK most people use
defconfig to configure U-Boot.

-Sumit

> --
> Tom


Re: [PATCH v2 0/8] An effort to bring DT bindings compliance within U-Boot

2023-12-22 Thread Sumit Garg
On Fri, 22 Dec 2023 at 13:48, Krzysztof Kozlowski
 wrote:
>
> On 22/12/2023 07:12, Sumit Garg wrote:
> > Changes in v2:
> > --
> > - Patch #1: excluded gitab CI config check and added commit description.
> > - Patch #3: s/UBOOT_DTSI_LOC/u_boot_dtsi_loc/
> > - Patch #4: s/DEVICE_TREE_LOC/dt_dir/ and s/U-boot/U-Boot/
> > - Patch #5: s/U-boot/U-Boot/
> > - Patch #6 and #7: Picked up review tags
> >
> > Prerequisite
> > 
> >
> > This patch series requires devicetree-rebasing git repo to be added as a
> > subtree to the main U-Boot repo via:
> >
> > $ git subtree add --prefix devicetree-rebasing \
> >   
> > git://git.kernel.org/pub/scm/linux/kernel/git/devicetree/devicetree-rebasing.git
> >  \
> >   v6.6-dts --squash
> >
> > Background
> > --
> >
> > This effort started while I was reviewing patch series corresponding to
> > Qcom platforms [1] which was about to import modified devicetree source
> > files from Linux kernel. I suppose keeping devicetree files sync with
> > Linux kernel without any DT bindings schema validation has been a pain
> > for U-Boot SoC/platform maintainers. There has been past discussions
> > about a single DT repo but that hasn't come up and Linux kernel remained
> > the place where DT source files as well as bindings are placed and
> > maintained.
>
> Thanks for doing this.
>
> I really suggest to store information that kernel DTS is directly
> re-used, thus DTS backward and forward compatibility matters, also in
> Linux kernel sources. The point is that sub-arch maintainers should be
> aware of it. I don't think that as DT maintainers we can efficiently
> keep an eye on it. Maybe create a subsystem profile and include it to
> maintainer entries of such affected platforms?
>

>From U-Boot point of view, currently we have the config option:
"CONFIG_OF_UPSTREAM=y" per platform which means directly re-use of
kernel DTS. So U-Boot sub-arch maintainers should be aware of
platforms which get converted to re-use kernel DTS.

I suppose we have to relay information to kernel sub-arch maintainers
who aren't the same as maintaining U-Boot counterparts. How about
adding U-Boot ML to CC for whichever DT change gets submitted in the
kernel? Otherwise adding U-Boot sub-arch maintainers as reviewers for
corresponding kernel DT changes works too if that's acceptable.

-Sumit

> Best regards,
> Krzysztof
>
> Best regards,
> Krzysztof
>


Re: [PATCH v2 7/8] dts: meson-gxbb: Switch to using upstream DT

2023-12-22 Thread Sumit Garg
On Fri, 22 Dec 2023 at 18:01, Tom Rini  wrote:
>
> On Fri, Dec 22, 2023 at 11:42:07AM +0530, Sumit Garg wrote:
>
> > Although there were still some variations in board DTS files based on
> > meson-gxbb SoC but I think those were minor differences from upstream
> > and shouldn't impact boot on these devices.
> >
> > So switch to upstream DT via mirroring amlogic/ directory from
> > devicetree-rebasing/src/arm64/amlogic/ directory. And thereby directly
> > building DTB from there including *-u-boot.dtsi files from
> > arch/$(ARCH)/dts/ directory.
> >
> > Reviewed-by: Neil Armstrong 
> > Signed-off-by: Sumit Garg 
> > ---
> >  configs/nanopi-k2_defconfig   | 3 ++-
> >  configs/odroid-c2_defconfig   | 3 ++-
> >  configs/p200_defconfig| 3 ++-
> >  configs/p201_defconfig| 3 ++-
> >  configs/videostrong-kii-pro_defconfig | 3 ++-
> >  configs/wetek-hub_defconfig   | 3 ++-
> >  configs/wetek-play2_defconfig | 3 ++-
> >  dts/arch/arm64/Makefile   | 9 +
> >  dts/arch/arm64/amlogic| 1 +
> >  9 files changed, 24 insertions(+), 7 deletions(-)
> >  create mode 12 dts/arch/arm64/amlogic
>
> Do we need all of the Makefile portions of this? One of the things that
> works today is that trees listed in ONFIG_DEFAULT_DEVICE_TREE (and a few
> other variables) will be automatically built. We might just need the new
> Makefiles to just have:
> include $(srctree)/scripts/Makefile.dts
> and then the trees a given config will need will be built.

That sounds fine for Amlogic SoC and many others too with
CONFIG_DEFAULT_DEVICE_TREE="" CONFIG_OF_LIST="" options available.
However, if in future we have truely generalized U-Boot (like efforts
for Qcom platform) then CONFIG_OF_LIST="" may become an overloaded
choice.

For now, let me drop the Makefile portions.

-Sumit

>
> --
> Tom


Re: [PATCH v7 2/2] schemas: Add some common reserved-memory usages

2023-12-22 Thread Ard Biesheuvel
On Thu, 21 Dec 2023 at 17:50, Chiu, Chasel  wrote:
>
>
> Hi Ard,
>
> Please see my reply below inline and let me know your thoughts.
>
> Thanks,
> Chasel
>
>
> > -Original Message-
> > From: Ard Biesheuvel 
> > Sent: Thursday, December 21, 2023 6:31 AM
> > To: Chiu, Chasel 
> > Cc: Simon Glass ; devicet...@vger.kernel.org; Mark 
> > Rutland
> > ; Rob Herring ; Tan, Lean Sheng
> > ; lkml ; Dhaval
> > Sharma ; Brune, Maximilian
> > ; Yunhui Cui ;
> > Dong, Guo ; Tom Rini ; ron minnich
> > ; Guo, Gua ; linux-
> > a...@vger.kernel.org; U-Boot Mailing List 
> > Subject: Re: [PATCH v7 2/2] schemas: Add some common reserved-memory
> > usages
> >
> > On Tue, 28 Nov 2023 at 21:31, Chiu, Chasel  wrote:
> > >
> > >
> > >
> > >
> > > > -Original Message-
> > > > From: Ard Biesheuvel 
> > > > Sent: Tuesday, November 28, 2023 10:08 AM
> > > > To: Chiu, Chasel 
> > > > Cc: Simon Glass ; devicet...@vger.kernel.org; Mark
> > > > Rutland ; Rob Herring ; Tan,
> > > > Lean Sheng ; lkml
> > > > ; Dhaval Sharma ;
> > > > Brune, Maximilian ; Yunhui Cui
> > > > ; Dong, Guo ; Tom Rini
> > > > ; ron minnich ; Guo, Gua
> > > > ; linux- a...@vger.kernel.org; U-Boot Mailing
> > > > List 
> > > > Subject: Re: [PATCH v7 2/2] schemas: Add some common reserved-memory
> > > > usages
> > > >
> > > > You are referring to a 2000 line patch so it is not 100% clear where to 
> > > > look tbh.
> > > >
> > > >
> > > > On Tue, 21 Nov 2023 at 19:37, Chiu, Chasel  
> > > > wrote:
> > > > >
> > > > >
> > > > > In PR, UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c, line
> > > > > 268 is for
> > > > related example code.
> > > > >
> > > >
> > > > That refers to a 'memory-allocation' node, right? How does that
> > > > relate to the 'reserved-memory' node?
> > > >
> > > > And crucially, how does this clarify in which way "runtime-code" and
> > > > "runtime- data" reservations are being used?
> > > >
> > > > Since the very beginning of this discussion, I have been asking
> > > > repeatedly for examples that describe the wider context in which these
> > reservations are used.
> > > > The "runtime" into runtime-code and runtime-data means that these
> > > > regions have a special significance to the operating system, not
> > > > just to the next bootloader stage. So I want to understand exactly
> > > > why it is necessary to describe these regions in a way where the
> > > > operating system might be expected to interpret this information and act
> > upon it.
> > > >
> > >
> > >
> > > I think runtime code and data today are mainly for supporting UEFI runtime
> > services - some BIOS functions for OS to utilize, OS may follow below ACPI 
> > spec to
> > treat them as reserved range:
> > > https://uefi.org/specs/ACPI/6.5/15_System_Address_Map_Interfaces.html#
> > > uefi-memory-types-and-mapping-to-acpi-address-range-types
> > >
> > > Like I mentioned earlier, that PR is still in early phase and has not 
> > > reflected all
> > the required changes yet, but the idea is to build
> > gEfiMemoryTypeInformationGuid HOB from FDT reserved-memory nodes.
> > > UEFI generic Payload has DxeMain integrated, however Memory Types are
> > platform-specific, for example, some platforms may need bigger runtime 
> > memory
> > for their implementation, that's why we want such FDT reserved-memory node 
> > to
> > tell DxeMain.
> > >
> >
> > > The Payload flow will be like this:
> > >   Payload creates built-in default MemoryTypes table ->
> > > FDT reserved-memory node to override if required (this also ensures 
> > > the
> > same memory map cross boots so ACPI S4 works) ->
> > >   Build gEfiMemoryTypeInformationGuid HOB by "platfom specific"
> > MemoryTypes Table ->
> > > DxeMain/GCD to consume this MemoryTypes table and setup memory
> > service ->
> > >   Install memory types table to UEFI system table.Configuration 
> > > table...
> > >
> > > Note: if Payload built-in default MemoryTypes table works fine for the
> > > platform, then FDT reserved-memory node does not need to provide such
> > 'usage' compatible strings. (optional) This FDT node could allow
> > flexibility/compatibility without rebuilding Payload binary.
> > >
> > > Not sure if I answered all your questions, please highlight which area 
> > > you need
> > more information.
> > >
> >
> > The gEfiMemoryTypeInformationGuid HOB typically carries platform defaults, 
> > and
> > the actual memory type information is kept in a non-volatile EFI variable, 
> > which
> > gets updated when the memory usage changes. Is this different for
> > UefiPayloadPkg?
> >
> > (For those among the cc'ees less versed in EFI/EDK2: when you get the 
> > 'config
> > changed -rebooting' message from the boot firmware, it typically means that 
> > this
> > memory type table has changed, and a reboot is necessary.)
> >
> > So the platform init needs to read this variable, or get the information in 
> > a
> > different way. I assume it is the payload, not the platform init that 
> > updates the
> > v

Re: [PATCH v3 0/7] rpi5: initial support

2023-12-22 Thread Marc Zyngier

On 2023-12-22 12:33, Ivan T. Ivanov wrote:

On 12-22 12:19, Marc Zyngier wrote:


Hi Ivan,

On 2023-12-18 21:03, Ivan T. Ivanov wrote:
> Hi,
>
> These patches are adding basic support for RPi5.
> They are based on v2 series from Dmitry Malkin[1].
>
> With them I am able to _start_ current openSUSE
> Tumbleweed without modification. They are still
> a lot of things to be added to the upstream Linux
> before it runs flawlessly on this device, but at
> least in U-Booot SD controller used for uSD card
> and Frameboffer and HDMI0 devices are working fine
> now. It seems that PCIe controller is working fine
> too, but I have not tested it too much.
>
> Serial console and reset are also functional.
>
> Hopefully this will help others add missing pieces
> more easily.

So I've given this a go, and the basics (serial) worked
out of the box (thanks for that!) after performing the
memory-map change you described in your reply to patch 1.

However, I don't get anything on the PCIe front:

U-Boot> pci enum
PCIe BRCM: link down
PCIe BRCM: link down

despite having an nvme device connected and enabled
(the RPi kernel finds it).

I'm guessing I must be missing something. How did you
test PCIe?



No, you are not missing anything. I have not tested it
for real. That is why I said "it seems". Sorry.

Yesterday I started looking more closely at what's missing
and unfortunately a lot more changes are needed.


Ah, fair enough. I was slightly surprised that it appeared
to be working out of the box, which would have been a first
on the ARM side...

Happy to test whatever patches you come up with!

Thanks,

M.
--
Jazz is not dead. It just smells funny...


Re: [RFC PATCH 00/16] Introduce ICSSG Ethernet driver

2023-12-22 Thread Roger Quadros


On 22/12/2023 12:26, MD Danish Anwar wrote:
> Hi Roger,
> 
> On 20/12/23 3:29 pm, Roger Quadros wrote:
>> Hi,
>>
>> On 19/12/2023 12:11, MD Danish Anwar wrote:
>>> Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used in TI
>>> AM654 SR2.0.
>>>
>>> The ICSSG PRU Sub-system runs on EMAC firmware. This series Introduces
>>> support for ICSSG driver in uboot. This series also adds the driver's
>>> dependencies.
>>>
>>> The ICSSG2 node is added in device tree overlay so that it remains in
>>> sync with linux kernel.
>>>
>>> The series introduces device tree and config changes and AM65x
>>> to enable ICSSG driver. The series also enables SPL_LOAD_FIT_APPLY_OVERLAY
>>> for AM65x in order to load overlay over spl.
>>>
>>> This series has been tested on AM65x SR2.0, and the ICSSG interface is
>>> able to ping / dhcp and boot kernel using tftp in uboot.
>>>
>>> To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to PRU RPROC
>>> cores and RPROC cores need to be booted with the firmware. This step is
>>> done inside driver in kernel as kernel supports APIs like
>>> rproc_set_firmware() and rproc_fw_boot(). But as u-boot doesn't have these
>>> APIs, the same needs to be done via u-boot cmds.
>>>
>>> To make sure icssg-eth works we need to do below steps.
>>>
>>> 1. Initialize rproc cores i.e. rproc_init()
>>> 2. Load $firmware_file from partition '1:2' (root) on device (mmc in this
>>>example)
>>> 3. Load the firmware file to rproc cores passing. i.e. rproc_load()
>>>taking rproc_id, loadaddr and file size as arguments.
>>> 4. Start rproc cores. i.e. rproc_start() taking rproc_id as arguments
>>>
>>> The above steps are done by running the below commands at u-boot prompt.
>>>
>>> => setenv start_icssg2 'rproc start 14; rproc start 15; rproc start 16; 
>>> rproc start 17; rproc start 18; rproc start 19'
>>> => setenv stop_icssg2 'rproc stop 14; rproc stop 15; rproc stop 16; rproc 
>>> stop 17; rproc stop 18; rproc stop 19'
>>> => setenv firmware_dir '/lib/firmware/ti-pruss'
>>> => setenv get_firmware_mmc 'load mmc ${bootpart} ${loadaddr} 
>>> ${firmware_dir}/${firmware_file}'
>>>
>>> => setenv init_icssg2 'setenv ethact icssg2-eth; setenv autoload no; rproc 
>>> init; setenv loadaddr 0x8000; \
>>> setenv firmware_file am65x-sr2-pru0-prueth-fw.elf; run 
>>> get_firmware_mmc;  rproc load 14 0x8000 ${filesize}; \
>>> setenv loadaddr 0x8900; setenv firmware_file 
>>> am65x-sr2-rtu0-prueth-fw.elf; run get_firmware_mmc; rproc load 15 
>>> 0x8900 ${filesize}; \
>>> setenv loadaddr 0x9000; setenv firmware_file 
>>> am65x-sr2-txpru0-prueth-fw.elf; run get_firmware_mmc; rproc load 16 
>>> 0x9000 ${filesize}; \
>>> setenv loadaddr 0x8000; setenv firmware_file 
>>> am65x-sr2-pru1-prueth-fw.elf; run get_firmware_mmc; rproc load 17 
>>> 0x8000 ${filesize}; \
>>> setenv loadaddr 0x8900; setenv firmware_file 
>>> am65x-sr2-rtu1-prueth-fw.elf; run get_firmware_mmc; rproc load 18 
>>> 0x8900 ${filesize}; \
>>> setenv loadaddr 0x9000; setenv firmware_file 
>>> am65x-sr2-txpru1-prueth-fw.elf; run get_firmware_mmc; rproc load 19 
>>> 0x9000 ${filesize}; \
>>> run start_icssg2;'
>>
>> A whole bunch of commands are required to get ethernet functional.
>> This is not at all user friendly and will be a maintenance nightmare.
>> What worries me is tracking the 6 different rproc cores and the 6 different 
>> firmware files to start 1 ethernet device.
>> This will get even more interesting when we have to deal with different 
>> ICSSG instances on different boards.
>>
>> What is preventing the driver from starting the rproc cores it needs so user 
>> doesn't need to care about it?
>> All the necessary information is in the Device tree. At least this is how it 
>> is done on Linux.
>>
> 
> I tried removing the need for these commands and implementing them
> inside the driver only. I am able to load the firmware from driver using
> the fs_loader API request_firmware_into_buf(). It requires changes to
> dt. A DT node called fs-loader needs to be added also CONFIG_FS_LOADER
> needs to enabled. In the DT node we need to specify the storage media
> that we are using i.e. mmc, ospi, usb. It's upto user to modify the
> storage media, the driver will take the media from DT and try to laod
> firmware from their.
> 
> For loading firmwares to rproc cores, rproc_load() API is needed. Now
> this API takes rproc_id, loadaddr and firmware_size as arguments.
> loadaddr is fixed for all three pru cores. firmware_size is obtained
> from request_firmware_into_buf() but I couldn't find a way to get the
> rproc_id. For now based on the ICSSG instance and slice number I am
> figuring out the rproc_id and passing it to rproc_load() and
> rproc_start() APIs. Please let me know if you have any other / better
> way of finding rproc_id.
> 
> Below is the entire diff to remove these commands and move their
> functionality to driver. Please have a look and let me know

Re: [PATCH v2 5/8] doc: devicetree: Updates for devicetree-rebasing subtree

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 11:42:05AM +0530, Sumit Garg wrote:

> Encourage SoC/board maintainers to migrate to using devicetree-rebasing
> subtree and maintain a regular sync with Linux kernel devicetree files
> and bindings.
> 
> Along with that add documentation regarding how to run DT bindings
> schema checks.
> 
> Signed-off-by: Sumit Garg 
> ---
>  doc/develop/devicetree/control.rst | 108 +++--
>  1 file changed, 86 insertions(+), 22 deletions(-)
[snip]
> @@ -81,18 +94,21 @@ Failing that, you could write one from scratch yourself!
>  Configuration
>  -
>  
> -Use::
> +Traditionally, U-Boot placed copies of devicetree source files from Linux
> +kernel into `arch//dts/.dts` which can be selected via::
>  
> -   #define CONFIG_DEFAULT_DEVICE_TREE""
> +#define CONFIG_DEFAULT_DEVICE_TREE   ""

Oh, oof. This never got updated for Kconfig rather than config.h. Can
you please include re-wording this to be setting  when prompted
for DEFAULT_DEVICE_TREE by Kconfig? And the rest of the text you're
updating as well to match, thanks.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 0/7] rpi5: initial support

2023-12-22 Thread Ivan T. Ivanov
On 12-22 12:19, Marc Zyngier wrote:
> 
> Hi Ivan,
> 
> On 2023-12-18 21:03, Ivan T. Ivanov wrote:
> > Hi,
> > 
> > These patches are adding basic support for RPi5.
> > They are based on v2 series from Dmitry Malkin[1].
> > 
> > With them I am able to _start_ current openSUSE
> > Tumbleweed without modification. They are still
> > a lot of things to be added to the upstream Linux
> > before it runs flawlessly on this device, but at
> > least in U-Booot SD controller used for uSD card
> > and Frameboffer and HDMI0 devices are working fine
> > now. It seems that PCIe controller is working fine
> > too, but I have not tested it too much.
> > 
> > Serial console and reset are also functional.
> > 
> > Hopefully this will help others add missing pieces
> > more easily.
> 
> So I've given this a go, and the basics (serial) worked
> out of the box (thanks for that!) after performing the
> memory-map change you described in your reply to patch 1.
> 
> However, I don't get anything on the PCIe front:
> 
> U-Boot> pci enum
> PCIe BRCM: link down
> PCIe BRCM: link down
> 
> despite having an nvme device connected and enabled
> (the RPi kernel finds it).
> 
> I'm guessing I must be missing something. How did you
> test PCIe?
> 

No, you are not missing anything. I have not tested it
for real. That is why I said "it seems". Sorry.

Yesterday I started looking more closely at what's missing
and unfortunately a lot more changes are needed.

Regards,
Ivan



Re: [PATCH v2 3/8] scripts/Makefile.lib: Statically define *-u-boot.dtsi files location

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 11:42:03AM +0530, Sumit Garg wrote:

> Allow u-boot to build DTB from a different directory tree such that
> *-u-boot.dtsi files can be included from a common location. Currently
> that location is arch/$(ARCH)/dts/, so statically define that common
> location.
> 
> This is needed for platform owners to start building DTB files from
> devicetree-rebasing directory but still being able to include
> *-u-boot.dtsi files.
> 
> Signed-off-by: Sumit Garg 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 1/8] CI: Exclude devicetree-rebasing subtree for CONFIG checks

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 11:42:01AM +0530, Sumit Garg wrote:

> Since devicetree-rebasing is an external repo with its own coding style,
> exclude it from Azure and gitlab CI CONFIG checks.
> 
> Signed-off-by: Sumit Garg 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 7/8] dts: meson-gxbb: Switch to using upstream DT

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 11:42:07AM +0530, Sumit Garg wrote:

> Although there were still some variations in board DTS files based on
> meson-gxbb SoC but I think those were minor differences from upstream
> and shouldn't impact boot on these devices.
> 
> So switch to upstream DT via mirroring amlogic/ directory from
> devicetree-rebasing/src/arm64/amlogic/ directory. And thereby directly
> building DTB from there including *-u-boot.dtsi files from
> arch/$(ARCH)/dts/ directory.
> 
> Reviewed-by: Neil Armstrong 
> Signed-off-by: Sumit Garg 
> ---
>  configs/nanopi-k2_defconfig   | 3 ++-
>  configs/odroid-c2_defconfig   | 3 ++-
>  configs/p200_defconfig| 3 ++-
>  configs/p201_defconfig| 3 ++-
>  configs/videostrong-kii-pro_defconfig | 3 ++-
>  configs/wetek-hub_defconfig   | 3 ++-
>  configs/wetek-play2_defconfig | 3 ++-
>  dts/arch/arm64/Makefile   | 9 +
>  dts/arch/arm64/amlogic| 1 +
>  9 files changed, 24 insertions(+), 7 deletions(-)
>  create mode 12 dts/arch/arm64/amlogic

Do we need all of the Makefile portions of this? One of the things that
works today is that trees listed in ONFIG_DEFAULT_DEVICE_TREE (and a few
other variables) will be automatically built. We might just need the new
Makefiles to just have:
include $(srctree)/scripts/Makefile.dts
and then the trees a given config will need will be built.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 0/7] rpi5: initial support

2023-12-22 Thread Marc Zyngier

Hi Ivan,

On 2023-12-18 21:03, Ivan T. Ivanov wrote:

Hi,

These patches are adding basic support for RPi5.
They are based on v2 series from Dmitry Malkin[1].

With them I am able to _start_ current openSUSE
Tumbleweed without modification. They are still
a lot of things to be added to the upstream Linux
before it runs flawlessly on this device, but at
least in U-Booot SD controller used for uSD card
and Frameboffer and HDMI0 devices are working fine
now. It seems that PCIe controller is working fine
too, but I have not tested it too much.

Serial console and reset are also functional.

Hopefully this will help others add missing pieces
more easily.


So I've given this a go, and the basics (serial) worked
out of the box (thanks for that!) after performing the
memory-map change you described in your reply to patch 1.

However, I don't get anything on the PCIe front:

U-Boot> pci enum
PCIe BRCM: link down
PCIe BRCM: link down

despite having an nvme device connected and enabled
(the RPi kernel finds it).

I'm guessing I must be missing something. How did you
test PCIe?

Thanks,

M.
--
Jazz is not dead. It just smells funny...


Re: [PATCH v3] arch: arm: Kconfig: Enable BOOTSTD_FULL for Rockchip SoCs

2023-12-22 Thread Shantur Rathore
On Fri, Dec 22, 2023 at 12:07 PM Tom Rini  wrote:
>
> On Fri, Dec 22, 2023 at 12:05:39PM +, Shantur Rathore wrote:
> > Hi all,
> >
> > On Mon, Dec 11, 2023 at 6:27 PM Tom Rini  wrote:
> > >
> > > On Mon, Dec 11, 2023 at 11:22:45AM -0700, Simon Glass wrote:
> > > > Hi Tom,
> > > [snip]
> > > > > I think in hind-sight too much stuff is omitted without BOOTSTD_FULL.
> > > > > The option itself then enables other stuff too by default, but some
> > > > > parts of the bootflow command itself should be visible even without 
> > > > > FULL
> > > > > to make things easier on the user.
> > > >
> > > > At the time the goal was to avoid growth compared to the distro
> > > > scripts. We could perhaps add some more things in with BOOTSTD_FULL
> > > > but still have it as an option?
> > >
> > > Right. But now that we've tried this, some of the feedback has been that
> > > it's just too minimal right now. Like looking at the help message for
> > > bootflow, list and info should probably always be available. And maybe
> > > the flags for "scan" should be re-thought? Too late to change things now
> > > but "bootflow scan -b" should maybe how it's always been for "scan and
> > > boot".
> >
> > What would be the preferred approach for this patch?
> > Is it to update the default capabilities of bootflow or we can have this 
> > patch?
>
> Well, I don't see a problem with just adding this to the platforms which
> enable BOOTSTD_FULL until we can rework what's included/excluded by that
> flag, and there's an issue filed for it now.
>
> --
> Tom

Great,  can we have this merged in please then [0]

[0] - 
https://patchwork.ozlabs.org/project/uboot/patch/20231119172310.1307942-...@shantur.com/

Regards,
Shantur


Re: [PATCH v3] arch: arm: Kconfig: Enable BOOTSTD_FULL for Rockchip SoCs

2023-12-22 Thread Tom Rini
On Fri, Dec 22, 2023 at 12:05:39PM +, Shantur Rathore wrote:
> Hi all,
> 
> On Mon, Dec 11, 2023 at 6:27 PM Tom Rini  wrote:
> >
> > On Mon, Dec 11, 2023 at 11:22:45AM -0700, Simon Glass wrote:
> > > Hi Tom,
> > [snip]
> > > > I think in hind-sight too much stuff is omitted without BOOTSTD_FULL.
> > > > The option itself then enables other stuff too by default, but some
> > > > parts of the bootflow command itself should be visible even without FULL
> > > > to make things easier on the user.
> > >
> > > At the time the goal was to avoid growth compared to the distro
> > > scripts. We could perhaps add some more things in with BOOTSTD_FULL
> > > but still have it as an option?
> >
> > Right. But now that we've tried this, some of the feedback has been that
> > it's just too minimal right now. Like looking at the help message for
> > bootflow, list and info should probably always be available. And maybe
> > the flags for "scan" should be re-thought? Too late to change things now
> > but "bootflow scan -b" should maybe how it's always been for "scan and
> > boot".
> 
> What would be the preferred approach for this patch?
> Is it to update the default capabilities of bootflow or we can have this 
> patch?

Well, I don't see a problem with just adding this to the platforms which
enable BOOTSTD_FULL until we can rework what's included/excluded by that
flag, and there's an issue filed for it now.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3] arch: arm: Kconfig: Enable BOOTSTD_FULL for Rockchip SoCs

2023-12-22 Thread Shantur Rathore
Hi all,

On Mon, Dec 11, 2023 at 6:27 PM Tom Rini  wrote:
>
> On Mon, Dec 11, 2023 at 11:22:45AM -0700, Simon Glass wrote:
> > Hi Tom,
> [snip]
> > > I think in hind-sight too much stuff is omitted without BOOTSTD_FULL.
> > > The option itself then enables other stuff too by default, but some
> > > parts of the bootflow command itself should be visible even without FULL
> > > to make things easier on the user.
> >
> > At the time the goal was to avoid growth compared to the distro
> > scripts. We could perhaps add some more things in with BOOTSTD_FULL
> > but still have it as an option?
>
> Right. But now that we've tried this, some of the feedback has been that
> it's just too minimal right now. Like looking at the help message for
> bootflow, list and info should probably always be available. And maybe
> the flags for "scan" should be re-thought? Too late to change things now
> but "bootflow scan -b" should maybe how it's always been for "scan and
> boot".

What would be the preferred approach for this patch?
Is it to update the default capabilities of bootflow or we can have this patch?

Thanks
Shantur

>
> --
> Tom


Re: Proposal: U-Boot memory management

2023-12-22 Thread Ilias Apalodimas
Hi Simon

I'll respond to the rest more thoroughly but I since I caught this early,

[...]

>
> 5. Avoid calling efi_allocate_pages() and efi_allocate_pool() outside
> boot-time services. This solves the problem 6. If memory is needed by
> an app, allocate it with malloc() and see 3. There are only two
> efi_allocate_pages() (smbios and efi_runtime). There are more calls of
> efi_allocate_pool(), but most of these seem easy to fix up. For
> example, efi_init_event_log() allocates a buffer, but this can be
> allocated in normal malloc() space or in a bloblist.

The TCG event log is only valid in the EFI world and is described by
the EFI spec extensions [0]. I prefer it to remain as is

>
> 6. Don't worry too much about whether EFI will be used for booting.
> The cost is likely not that great: use bootstage to measure it as is
> done for driver model. Try to minmise the cost of its tables,
> particularly for execution time, but otherwise just rely on the
> ability to disable EFI_LOADER.
>
> –
>
> Regards,
> Simon

[0] 
https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
Thanks
/Ilias


  1   2   >