Re: [PATCH 1/1] The riscv spec has breaking change from 2.2 to 20191213. ...

2022-09-02 Thread Heinrich Schuchardt

On 8/30/22 01:51, Pan Li wrote:
> The riscv spec has breaking change from 2.2 to 20191213.
> Both ZICSR and ZIFENCEI are separated extension since 20191213.
> Gcc bump up the riscv spec to 20191213 since 12.x.
> So add below 4 build option for compatibility::

Hello Pan,

thank you for addressing this problem.

Nits:
You ultra long subject should have been in the commit message.

Alexandre has suggested in his patch
[PATCH] riscv: Fix build against binutils 2.38
https://lore.kernel.org/u-boot/20220128134713.2322800-1-alexandre.gh...@canonical.com/

to determine the ISA settings for building at runtime.

For a user it is preferable to use ready-made defconfigs with having to 
adjust each build manually. This is why I think we should follow 
Alexandre's approach.


On 8/30/22 01:51, Pan Li wrote:

CONFIG_RISCV_ISA_F for single float point, default no.
CONFIG_RISCV_ISA_D for double float point, default no.
CONFIG_RISCV_ISA_ZICSR for control and status register, default no.
CONFIG_RISCV_ISA_ZIFENCEI for instruction-fetch fence, default no.



I think defaults should reflect the newest and not the eldest build 
chains. This will provide better long term stability.


Best regards

Heinrich



Example when build with gcc 12.x as below.

 make qemu-riscv64_defconfig && make \
 CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv \
 CONFIG_RISCV_ISA_F=y \
 CONFIG_RISCV_ISA_D=y \
 CONFIG_RISCV_ISA_ZICSR=y \
 CONFIG_RISCV_ISA_ZIFENCEI=y

Signed-off-by: Pan Li 
---

  arch/riscv/Kconfig  | 28 
  arch/riscv/Makefile | 20 ++--
  2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 78e964db12..d54ee3aaf3 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -144,6 +144,34 @@ config SPL_RISCV_SMODE
  
  endchoice
  
+config RISCV_ISA_F

+   bool "Single precision instructions"
+   help
+ Adds "F" to the ISA subsets that the toolchain is allowed to emit
+ when building U-Boot, which results in single precision floating point
+ instructions in the U-Boot binary.
+
+config RISCV_ISA_D
+   bool "Double precision instructions"
+   help
+ Adds "D" to the ISA subsets that the toolchain is allowed to emit
+ when building U-Boot, which results in double precision floating point
+ instructions in the U-Boot binary.
+
+config RISCV_ISA_ZICSR
+   bool "Control and status register instructions"
+   help
+ Adds "ZICSR" to the ISA subsets that the toolchain is allowed to emit
+ when building U-Boot, which results in control and status Register
+ instructions in the U-Boot binary, since gcc 12.x and riscv spec 
20191213.
+
+config RISCV_ISA_ZIFENCEI
+   bool "Instruction-fetch fence instructions"
+   help
+ Adds "ZIFENCEI" to the ISA subsets that the toolchain is allowed to 
emit
+ when building U-Boot, which results in instruction-fetch fence 
instructions
+ in the U-Boot binary, since gcc 12.x and riscv spec 20191213.
+
  config RISCV_ISA_C
bool "Emit compressed instructions"
default y
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 0b80eb8d86..d333af92d1 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -14,9 +14,25 @@ endif
  ifeq ($(CONFIG_RISCV_ISA_A),y)
ARCH_A = a
  endif
+ifeq ($(CONFIG_RISCV_ISA_F),y)
+   ARCH_F = f
+ifneq ($(CONFIG_RISCV_ISA_D),y)
+   ABI_FP_SUFFIX = $(ARCH_F)
+endif
+endif
+ifeq ($(CONFIG_RISCV_ISA_D),y)
+   ARCH_D = d
+   ABI_FP_SUFFIX = $(ARCH_D)
+endif
  ifeq ($(CONFIG_RISCV_ISA_C),y)
ARCH_C = c
  endif
+ifeq ($(CONFIG_RISCV_ISA_ZICSR),y)
+   ARCH_ZICSR = _zicsr
+endif
+ifeq ($(CONFIG_RISCV_ISA_ZIFENCEI),y)
+   ARCH_ZIFENCEI = _zifencei
+endif
  ifeq ($(CONFIG_CMODEL_MEDLOW),y)
CMODEL = medlow
  endif
@@ -24,8 +40,8 @@ ifeq ($(CONFIG_CMODEL_MEDANY),y)
CMODEL = medany
  endif
  
-ARCH_FLAGS = -march=$(ARCH_BASE)$(ARCH_A)$(ARCH_C) -mabi=$(ABI) \

--mcmodel=$(CMODEL)
+ARCH_FLAGS = 
-march=$(ARCH_BASE)$(ARCH_A)$(ARCH_F)$(ARCH_D)$(ARCH_C)$(ARCH_ZICSR)$(ARCH_ZIFENCEI)
 \
+   -mabi=$(ABI)$(ABI_FP_SUFFIX) -mcmodel=$(CMODEL)
  
  PLATFORM_CPPFLAGS	+= $(ARCH_FLAGS)

  CFLAGS_EFI+= $(ARCH_FLAGS)


Re: [PATCH v7 0/8] migrate u-boot-rockchip.bin to binman and generate an image for SPI

2022-09-02 Thread Kever Yang

Hi Quentin,

I got below error for SoCs other than rk3399, eg. rk3308, rk3568, rk3328 
and etc.


+binman: Device tree 'u-boot.dtb' does not have a 'binman' node
+make[1]: *** [Makefile:1113: all] Error 1
+make: *** [Makefile:177: sub-make] Error 2

Thanks,

- Kever

On 2022/9/2 21:10, Quentin Schulz wrote:

From: Quentin Schulz 

This migrates the generation of u-boot-rockchip.bin from Makefile to binman
completely.

This also adds support for generating the same kind of image than
u-boot-rockchip.bin but for SPI flashes (specifically, a different image
type generated by mkimage is necessary, in addition to a different
offset in the storage medium).

This has been tested on Puma RK3399 with patch series from 
https://lore.kernel.org/u-boot/20220722160655.3904213-1-foss+ub...@0leil.net/#b 
(plus 
https://lore.kernel.org/u-boot/20220722113505.3875669-4-foss+ub...@0leil.net/).

Cheers,
Quentin

v7:
  - added missing rockchip-u-boot.dtsi for binman images to fix builds,
All Rockchip boards build tested with:
  #!/bin/sh
  
  for conf in $(ag -Rl ARCH_ROCKCHIP configs); do

git clean -ffdx > /dev/null
cp ../bl31.elf .
echo -n $conf=
make $(basename "$conf") > /dev/null
if grep -q -E "^CONFIG_ARM64=y" .config; then
CROSS_COMPILE="aarch64-linux-gnu-"
else
CROSS_COMPILE="arm-linux-gnu-"
fi
make CROSS_COMPILE="ccache $CROSS_COMPILE" -j$(nproc) > /dev/null 2>&1
echo $?
  done

v6:
  - rebased on u-boot-dm/master,
  - added test for mkimage multiple data files with one data file having
  no content,
  - added SPDX license for unit tests,
  - re-ordered tests and renamed test files accordingly,
  - added Rb,

v5:
  - rebased on latest master,
  - added binman test for mkimage multiple data files,
  - fixed mkimage data files to pass full paths to input files to
  mkimage,

v4:
  - added binman test for mkimage filename,
  - fixed >80 chars line in patch 2/8 binman: allow user-defined filenames for
  mkimage entry,
  - fixed wrong location for endif in patch 6/8 simplify binman image
  dependencies addition to INPUTS,


v3:
  - removed
  https://lore.kernel.org/u-boot/20220722113505.3875669-4-foss+ub...@0leil.net/,
  it'll be added later on in a separate patch series,
  - added "binman: allow user-defined filenames for mkimage entry,"
  - kept idbloader.img binary creation even with binman as requested by
  community,
  - generate idbloader-spi.img binary with binman,
  - added "rockchip: remove binman temporary files when cleaning"

v2:
  - removed patch 4/8 rockchip: pad u-boot-rockchip.bin correctly because
  it would break partitions table,
  - rebased on top of master, changes to patch 3/7 rockchip: remove
  unneeded CONFIG_SPL_PAD_TO compared to the RFC 3/8 rockchip: remove
  unneeded CONFIG_SPL_PAD_TO,

Quentin Schulz (8):
   binman: add support for skipping file concatenation for mkimage
   binman: allow user-defined filenames for mkimage entry
   rockchip: remove binman temporary files when cleaning
   rockchip: generate idbloader.img content for u-boot-rockchip.bin with
 binman for ARM
   rockchip: generate u-boot-rockchip.bin with binman for ARM64 boards
   rockchip: simplify binman image dependencies addition to INPUTS
   rockchip: allow to build SPI images even without HAS_ROM option
   rockchip: add u-boot-rockchip-spi.bin image for booting from SPI-NOR
 flash

  Makefile  | 41 +++
  arch/arm/Kconfig  |  2 +-
  arch/arm/dts/px30-u-boot.dtsi |  2 +
  arch/arm/dts/rk3288-u-boot.dtsi   |  2 +-
  arch/arm/dts/rk3308-u-boot.dtsi   |  2 +
  arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi|  2 +
  arch/arm/dts/rk3328-u-boot.dtsi   |  2 +
  arch/arm/dts/rk3368-u-boot.dtsi   |  1 +
  arch/arm/dts/rk3399-u-boot.dtsi   |  2 +-
  arch/arm/dts/rk3568-u-boot.dtsi   |  2 +
  arch/arm/dts/rockchip-u-boot.dtsi | 46 +++-
  arch/arm/mach-rockchip/Kconfig|  6 +--
  tools/binman/entries.rst  | 22 
  tools/binman/etype/mkimage.py | 52 ---
  tools/binman/ftest.py | 30 +++
  tools/binman/test/252_mkimage_mult_data.dts   | 21 
  .../test/253_mkimage_mult_no_content.dts  | 22 
  tools/binman/test/254_mkimage_filename.dts| 18 +++
  18 files changed, 226 insertions(+), 49 deletions(-)
  create mode 100644 tools/binman/test/252_mkimage_mult_data.dts
  create mode 100644 tools/binman/test/253_mkimage_mult_no_content.dts
  create mode 100644 tools/binman/test/254_mkimage_filename.dts



Re: [PATCH 1/5] dm: rtc: Make use of ut_assertnonnull()

2022-09-02 Thread Tom Rini
On Mon, Aug 01, 2022 at 07:58:44AM -0600, Simon Glass wrote:

> Use this (newish) macro since it is designed for the purpose of making
> sure things are non-NULL.
> 
> Signed-off-by: Simon Glass 

For the series, applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] arm: ARMv4 assembly compatibility

2022-09-02 Thread Tom Rini
On Sun, Aug 21, 2022 at 04:34:20PM +0300, Sergei Antonov wrote:

> There is currently a problem that U-Boot can not work on ARMv4
> because assembly imlementations of memcpy() and some other functions
> use "bx lr" instruction that is not available on ARMv4 ("mov pc, lr"
> should be used instead).
> 
> A working preprocessor-based solution to this problem is found in
> arch/arm/lib/relocate.S. Move it to the "ret" macro in
> arch/arm/include/asm/assembler.h and change all "bx lr" code
> to "ret lr" in functions that may run on ARMv4. Linux source code
> deals with this problem in the same manner.
> 
> v1 -> v2:
> Comment update. Pointed out by Andre Przywara.
> 
> Signed-off-by: Sergei Antonov 
> CC: Samuel Holland 
> CC: Ye Li 
> CC: Simon Glass 
> CC: Andre Przywara 
> CC: Marek Vasut 
> CC: Sean Anderson 
> CC: Tom Rini 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v4 1/3] cmd: bcb: introduce optional interface parameter to bcb

2022-09-02 Thread Tom Rini
On Mon, Aug 01, 2022 at 11:07:15AM +0300, Andrii Chepurnyi wrote:

> From: Andrii Chepurnyi 
> 
> From: Andrii Chepurnyi 
> 
> Originally, bcb implementation relay on mmc block devices.
> The interface parameter will give the ability to use bcb with
> various block devices by choosing the exact interface type.
> By default (if no interface parameter is provided) mmc interface
> will be used.
> 
> Reviewed-by: Igor Opaniuk 
> Signed-off-by: Andrii Chepurnyi 

The tests now fail:
https://source.denx.de/u-boot/u-boot/-/jobs/490627

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v4] cmd: Add pause command

2022-09-02 Thread Tom Rini
On Thu, Aug 18, 2022 at 03:44:04PM -0400, Samuel Dionne-Riel wrote:

> This command is being introduced with the goal of allowing user-friendly
> "generic use case" U-Boot builds to pause until user input under some
> situations.
> 
> The main use case would be when a boot failure happens, to pause until
> the user has had time to acknowledge the current state.
> 
> Tested using:
> 
> make && ./u-boot -v -T -c 'ut lib lib_test_hush_pause'
> 
> Signed-off-by: Samuel Dionne-Riel 
> Cc: Simon Glass 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] distro_bootcmd: Introduce support for extension command

2022-09-02 Thread Tom Rini
On Tue, Aug 09, 2022 at 06:54:07PM +0300, Matwey V. Kornilov wrote:

> Try to load required DTB overlays if the board supports extensions and
> CONFIG_CMD_EXTENSION is enabled.
> 
> Signed-off-by: Matwey V. Kornilov 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 2/2] ci: Add a test for a non-LTO build

2022-09-02 Thread Tom Rini
On Wed, Aug 03, 2022 at 12:13:09PM -0600, Simon Glass wrote:

> Check that sandbox builds and runs tests OK with LTO disabled.
> 
> Signed-off-by: Simon Glass 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 1/2] Makefile: Allow LTO to be disabled for a build

2022-09-02 Thread Tom Rini
On Wed, Aug 03, 2022 at 12:13:08PM -0600, Simon Glass wrote:

> LTO (Link-Time Optimisation) is an very useful feature which can
> significantly reduce the size of U-Boot binaries. So far it has been
> made available for selected ARM boards and sandbox.
> 
> However, incremental builds are much slower when LTO is used. For example,
> an incremental build of sandbox takes 2.1 seconds on my machine, but 6.7
> seconds with LTO enabled.
> 
> Add a NO_LTO parameter to the build, similar to NO_SDL, so it can be
> disabled during development if needed, for faster builds.
> 
> Add some documentation about LTO while we are here.
> 
> Signed-off-by: Simon Glass 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 4/4] test: cmd: add test for temperature command

2022-09-02 Thread Tom Rini
On Fri, Aug 12, 2022 at 08:15:50PM +0200, Robert Marko wrote:

> Add simple test for the temperature command.
> 
> Signed-off-by: Robert Marko 
> Reviewed-by: Simon Glass 
> ---
>  test/cmd/Makefile  |  1 +
>  test/cmd/temperature.c | 39 +++
>  2 files changed, 40 insertions(+)
>  create mode 100644 test/cmd/temperature.c

This causes failures such as:
https://source.denx.de/u-boot/u-boot/-/jobs/490586
 Captured stdout setup -
/u-boot
Creating new bloblist size 400 at c000
Error binding driver 'thermal-sandbox': -96
Some drivers failed to bind
initcall sequence 560e11b023a0 failed at call 0005a8ef (err=-96)
### ERROR ### Please RESET the board ###

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5] cmd: cat: add new command

2022-09-02 Thread Tom Rini
On Sun, Aug 21, 2022 at 02:54:13PM +, Roger Knecht wrote:

> Add cat command to print file content to standard out
> 
> Reviewed-by: Simon Glass 
> Signed-off-by: Roger Knecht 

Two problems:
https://source.denx.de/u-boot/u-boot/-/jobs/490480
https://source.denx.de/u-boot/u-boot/-/jobs/490473

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 0/8] Enable CONFIG_TIMER for all Kirkwood / MVEBU boards

2022-09-02 Thread Tony Dinh
Hi Stefan,

On Thu, Sep 1, 2022 at 11:25 PM Stefan Roese  wrote:
>
> This patchset enhaces the recently added Orion Timer driver to support
> all other Kirkwood & 32bit MVEBU Armada platforms. Additionally, this
> timer support is then enabled per default for those platforms, so that
> the board config files don't need to be changed. Also necessary is
> some dts hacking, so that the timer DT node is available in early
> U-Boot stages.
>
> I've successfully tested this patchset on an Armada XP board. Additional
> test on other boards and platforms are very welcome and necessary.

I've also discovered that the timer command (CONFIG_CMD_TIMER) was
broken at some time in the past. It does not keep time correctly
(lagging realtime badly), with or without this patch set . I think we
would want to investigate that issue later.

The sleep command works perfectly. Therefore,

Tested-by: Tony Dinh 

Thanks,
Tony

> Thanks,
> Stefan
>
> Stefan Roese (8):
>   timer: orion-timer: Use timer_conv_64() to fix timer wrap around
>   timer: orion-timer: Add support for other Armada SoC's
>   timer: orion-timer: Add timer_get_boot_us() for BOOTSTAGE support
>   arm: mvebu: Use CONFIG_TIMER on all MVEBU & KIRKWOOD platforms
>   arm: mvebu: dts: Makefile: Compile Armada 375 dtb in a separate step
>   arm: mvebu: dts: armada-375.dtsi: Add timer0 & timer1
>   arm: mvebu: dts: mvebu-u-boot.dtsi: Add "u-boot,dm-pre-reloc" to timer
> DT node
>   kirkwood: lsxl: Sync defconfigs
>
>  arch/arm/Kconfig  |  4 ++
>  arch/arm/dts/Makefile |  6 ++-
>  arch/arm/dts/armada-375.dtsi  |  4 +-
>  arch/arm/dts/mvebu-u-boot.dtsi| 11 +
>  arch/arm/mach-mvebu/include/mach/config.h |  5 ---
>  configs/lschlv2_defconfig |  3 --
>  configs/lsxhl_defconfig   |  3 --
>  drivers/timer/Kconfig |  5 ++-
>  drivers/timer/orion-timer.c   | 53 +--
>  9 files changed, 75 insertions(+), 19 deletions(-)
>
> --
> 2.37.3
>


Re: [PATCH v2] net: enetc: Fix use after free issue in fsl_enetc.c

2022-09-02 Thread Ramon Fried
On Fri, Sep 2, 2022 at 9:35 AM Siarhei Yasinski
 wrote:
>
> If ethernet connected to SFP, like this:
>
> &enetc_port0 {
> phy-connection-type = "sgmii";
> sfp = <&sfp0>;
> managed = "in-band-status";
> status = "okay";
> };
>
> Then enetc_config_phy returns -ENODEV and memory containing mdio interface is 
> freeing.
What do you mean freeing, can you describe the flow ?


Re: [PATCH v2] binman: bintool: remove btool_ prefix from btool names

2022-09-02 Thread Simon Glass
Hi Quentin,

On Thu, 1 Sept 2022 at 08:44, Quentin Schulz  wrote:
>
> From: Quentin Schulz 
>
> The binary is looked on the system by the suffix of the packer class.
> This means binman was looking for btool_gzip on the system and not gzip.
>
> Since a btool can have its btool_ prefix missing but its module and
> binary presence on the system appropriately found, there's no need to
> actually keep this prefix after listing all possible btools, so let's
> remove it.
>
> This fixes gzip btool by letting Bintool.find_bintool_class handle the
> missing prefix and still return the correct class which is then init
> with gzip name instead of btool_gzip.
>
> Fixes: 0f369d79925a ("binman: Add gzip bintool")
> Cc: Quentin Schulz 
> Signed-off-by: Quentin Schulz 
> ---
>  tools/binman/bintool.py | 2 ++
>  1 file changed, 2 insertions(+)

Do we still need this patch? Please see u-boot-dm/testing

Regards,
Simon


Re: [PATCH 1/1] sandbox: unblock signal before calling execv()

2022-09-02 Thread Simon Glass
On Thu, 1 Sept 2022 at 18:32, Heinrich Schuchardt
 wrote:
>
> The following faulty behavior was observed. The sandbox configured with
> CONFIG_SANDBOX_CRASH_RESET=y was invoked with
>
> ./u-boot -T -S
>
> After executing `exception undefined' the sandbox reboots.
> When executing `exception undefined' the sandbox exits with SIGSEGV.
>
> The expected behavior is that the sandbox should reboot again.
>
> If we are relaunching the sandbox in a signal handler, we have to unblock
> the respective signal before calling execv(). See signal(7) man-page.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  arch/sandbox/cpu/os.c | 16 
>  1 file changed, 16 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH v7 5/8] rockchip: generate u-boot-rockchip.bin with binman for ARM64 boards

2022-09-02 Thread Simon Glass
On Fri, 2 Sept 2022 at 07:11, Quentin Schulz  wrote:
>
> From: Quentin Schulz 
>
> This allows to build u-boot-rockchip.bin binary with binman for Rockchip
> ARM64 boards instead of the legacy Makefile way.
>
> Cc: Quentin Schulz 
> Signed-off-by: Quentin Schulz 
> ---
>
> v7:
>  - Removed reviewed-by,
>  - added missing includes for rockchip-u-boot.dtsi so that binman node
>  is always present for 64b Rockchip platforms,
>
> v6:
>  - added Rb,
>
> v4:
>  - added Reviewed-by,
>
>  Makefile   | 26 +-
>  arch/arm/Kconfig   |  2 +-
>  arch/arm/dts/px30-u-boot.dtsi  |  2 ++
>  arch/arm/dts/rk3308-u-boot.dtsi|  2 ++
>  arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi |  2 ++
>  arch/arm/dts/rk3328-u-boot.dtsi|  2 ++
>  arch/arm/dts/rk3368-u-boot.dtsi|  1 +
>  arch/arm/dts/rk3568-u-boot.dtsi|  2 ++
>  arch/arm/dts/rockchip-u-boot.dtsi  |  5 +
>  9 files changed, 18 insertions(+), 26 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 1/1] efi_selftest: on sandbox use host specific assembly

2022-09-02 Thread Simon Glass
Hi Heinrich,

On Thu, 1 Sept 2022 at 19:01, Heinrich Schuchardt
 wrote:
>
> The selftest checking the handling of exceptions in UEFI binaries is using
> assembly to provide an undefined instruction. On the sandbox the correct
> form of the instruction depends on the host architecture.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  lib/efi_selftest/efi_selftest_miniapp_exception.c | 9 -
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/lib/efi_selftest/efi_selftest_miniapp_exception.c 
> b/lib/efi_selftest/efi_selftest_miniapp_exception.c
> index 79f9a67859..a9ad381001 100644
> --- a/lib/efi_selftest/efi_selftest_miniapp_exception.c
> +++ b/lib/efi_selftest/efi_selftest_miniapp_exception.c
> @@ -9,6 +9,7 @@
>
>  #include 
>  #include 
> +#include 
>
>  /*
>   * Entry point of the EFI application.
> @@ -33,10 +34,16 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
> asm volatile (".word 0xe7f7defb\n");
>  #elif defined(CONFIG_RISCV)
> asm volatile (".word 0x\n");
> +#elif defined(CONFIG_X86)
> +   asm volatile (".word 0x\n");

What actually are these instructions? Shouldn't we define them
somewhere, or at least add a comment for each?

>  #elif defined(CONFIG_SANDBOX)
> +#if (HOST_ARCH == HOST_ARCH_ARM || HOST_ARCH == HOST_ARCH_AARCH64)
> +   asm volatile (".word 0xe7f7defb\n");
> +#elif (HOST_ARCH == HOST_ARCH_RISCV32 || HOST_ARCH == HOST_ARCH_RISCV64)
> asm volatile (".word 0x\n");
> -#elif defined(CONFIG_X86)
> +#elif (HOST_ARCH == HOST_ARCH_X86 || HOST_ARCH == HOST_ARCH_X86_64)
> asm volatile (".word 0x\n");
> +#endif
>  #endif
> con_out->output_string(con_out, u"Exception not triggered.\n");
> return EFI_ABORTED;
> --
> 2.37.2
>

Regards,
Simon


Re: [PATCH 1/1] efi_loader: compliance Simple Text Input Ex Protocol

2022-09-02 Thread Simon Glass
Hi Heinrich,

On Thu, 1 Sept 2022 at 18:36, Heinrich Schuchardt
 wrote:
>
>
>
> On 9/2/22 01:52, Simon Glass wrote:
> > On Thu, 1 Sept 2022 at 16:07, Heinrich Schuchardt
> >  wrote:
> >>
> >> We cannot expect the buffers passed to the input protocols to be zero
> >> filled. If only modifier keys are pressed, we have to return EFI_NOT_READY
> >> but we still have to fill the key structure.
> >>
> >> Signed-off-by: Heinrich Schuchardt 
> >> ---
> >>   lib/efi_loader/efi_console.c | 1 +
> >>   1 file changed, 1 insertion(+)
> >
> > Reviewed-by: Simon Glass 
> >
> >> diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
> >> index 3164fd484e..1fcaabe1c4 100644
> >> --- a/lib/efi_loader/efi_console.c
> >> +++ b/lib/efi_loader/efi_console.c
> >> @@ -987,6 +987,7 @@ static efi_status_t EFIAPI efi_cin_read_key_stroke_ex(
> >>  efi_cin_check();
> >>
> >>  if (!key_available) {
> >> +   memset(key_data, 0, sizeof(struct efi_key_data));
> >
> > '\0'
>
> memset() wants int here not char.
> (Yes, the compiler would add the missing conversion for '\0'.)

Sure, but it is actually a char, right? It is not good practice to
have function arguments be non-natural types due to the masking the
compiler must then do (increases code size and lower performance). So
that is why memset() uses a natural type.

Regards,
Simon


Re: [PATCH] fdt_support: add optional board_rng_seed() hook

2022-09-02 Thread Simon Glass
Hi Rasmus,

On Fri, 2 Sept 2022 at 01:00, Rasmus Villemoes
 wrote:
>
> On 02/09/2022 01.52, Simon Glass wrote:
> > Hi Rasmus,
> >
> > On Sat, 27 Aug 2022 at 19:52, Simon Glass  wrote:
> >>
> >> Hi Rasmus,
> >>
> >> On Wed, 24 Aug 2022 at 19:25, Simon Glass  wrote:
>
> >> I'm looking at adding full support to ofnode for reading/writing any
> >> tree, not just the control FDT. I should have a series out before the
> >> end of next week.
> >
> > Well, I sent it and I think you saw it.
>
> Yeah, I saw it, but unfortunately I don't have time to give it a
> thorough review. But please do keep me cc'ed in case you send a new
> revision.
>
> > What shall we do with this patch? Apply it?
>
> Well, that's probably not for me to decide (I guess Tom is), but I'd
> still like it applied. It's simple, and works now, and it can always be
> removed again if there's a demonstrated viable alternative.

OK I'll apply it for this release and we'll see how much progress is
made with ofnode in the next one.

Are you OK with reworking it to use events when possible?

Regards,
Simon


Re: [PATCH v1 1/6] watchdog: Integrate watchdog triggering into the cyclic framework

2022-09-02 Thread Simon Glass
Hi Stefan,

On Fri, 2 Sept 2022 at 06:11, Stefan Roese  wrote:
>
> This patch integrates the watchdog triggering into the recently added
> cyclic infrastructure. Each watchdog device that shall be triggered
> registers it's own cyclic function. This way, multiple watchdog devices
> are still supported, each via a cyclic function with separate trigger
> intervals.
>
> Signed-off-by: Stefan Roese 
> ---
> v1:
> - Reword WDT logging at startup as suggested by Rasmus
> - Fail upon !priv->cyclic initr_watchdog()
> - Remove some superflous checks in wdt_cyclic()
>
>  drivers/watchdog/Kconfig  |  2 +
>  drivers/watchdog/wdt-uclass.c | 73 ---
>  2 files changed, 43 insertions(+), 32 deletions(-)

Reviewed-by: Simon Glass 

As a future enhancement, I think the cyclic handlers should return an
error code, which is retained somewhere, so it is possible to check
(perhaps on cmdline) whether there has been an error since the last
check.

Regards,
Simon


Re: [PATCH 4/4] arm: dts: chameleonv3: Add 270-2 variant

2022-09-02 Thread Simon Glass
Hi Paweł,

On Fri, 2 Sept 2022 at 07:16, Paweł Anikiel  wrote:
>
> On Tue, Aug 30, 2022 at 5:57 PM Simon Glass  wrote:
> >
> > Hi Paweł,
> >
> > On Tue, 30 Aug 2022 at 05:51, Paweł Anikiel  wrote:
> > >
> > > On Tue, Aug 30, 2022 at 5:13 AM Alexandru M Stan  
> > > wrote:
> > > >
> > > > Hey Simon,
> > > >
> > > > On Mon, Aug 29, 2022 at 7:29 PM Simon Glass  wrote:
> > > > >
> > > > > Hi Paweł,
> > > > >
> > > > > On Mon, 29 Aug 2022 at 02:23, Paweł Anikiel  wrote:
> > > > > >
> > > > > > On Sat, Aug 27, 2022 at 2:22 AM Simon Glass  
> > > > > > wrote:
> > > > > > >
> > > > > > > Hi Paweł,
> > > > > > >
> > > > > > > On Fri, 26 Aug 2022 at 01:54, Paweł Anikiel  
> > > > > > > wrote:
> > > > > > > >
> > > > > > > > Add devicetree for chameleonv3 with the 270-2I2-D11E variant of 
> > > > > > > > the
> > > > > > > > Mercury+ AA1 module
> > > > > > > >
> > > > > > > > Signed-off-by: Paweł Anikiel 
> > > > > > > > ---
> > > > > > > >  arch/arm/dts/Makefile|  1 +
> > > > > > > >  .../socfpga_arria10_chameleonv3_270_2-u-boot.dtsi| 12 
> > > > > > > > 
> > > > > > > >  arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts   |  5 +
> > > > > > > >  3 files changed, 18 insertions(+)
> > > > > > > >  create mode 100644 
> > > > > > > > arch/arm/dts/socfpga_arria10_chameleonv3_270_2-u-boot.dtsi
> > > > > > > >  create mode 100644 
> > > > > > > > arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts
> > > > > > > >
> > > > >
> > > > >
> > > > > > > > diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> > > > > > > > index 7330121dba..36d5d65595 100644
> > > > > > > > --- a/arch/arm/dts/Makefile
> > > > > > > > +++ b/arch/arm/dts/Makefile
> > > > > > > > @@ -425,6 +425,7 @@ dtb-$(CONFIG_ARCH_SOCFPGA) +=   
> > > > > > > > \
> > > > > > > > socfpga_agilex_socdk.dtb\
> > > > > > > > socfpga_arria5_secu1.dtb\
> > > > > > > > socfpga_arria5_socdk.dtb\
> > > > > > > > +   socfpga_arria10_chameleonv3_270_2.dtb   \
> > > > > > > > socfpga_arria10_chameleonv3_270_3.dtb   \
> > > > > > > > socfpga_arria10_chameleonv3_480_2.dtb   \
> > > > > > > > socfpga_arria10_socdk_sdmmc.dtb \
> > > > > > > > diff --git 
> > > > > > > > a/arch/arm/dts/socfpga_arria10_chameleonv3_270_2-u-boot.dtsi 
> > > > > > > > b/arch/arm/dts/socfpga_arria10_chameleonv3_270_2-u-boot.dtsi
> > > > > > > > new file mode 100644
> > > > > > > > index 00..05b4485cf3
> > > > > > > > --- /dev/null
> > > > > > > > +++ b/arch/arm/dts/socfpga_arria10_chameleonv3_270_2-u-boot.dtsi
> > > > > > > > @@ -0,0 +1,12 @@
> > > > > > > > +// SPDX-License-Identifier: GPL-2.0
> > > > > > > > +/*
> > > > > > > > + * Copyright 2022 Google LLC
> > > > > > > > + */
> > > > > > > > +#include "socfpga_arria10_chameleonv3_480_2_handoff.h"
> > > > > > > > +#include "socfpga_arria10-handoff.dtsi"
> > > > > > > > +#include "socfpga_arria10_handoff_u-boot.dtsi"
> > > > > > > > +#include "socfpga_arria10_mercury_aa1-u-boot.dtsi"
> > > > > > > > +
> > > > > > > > +&fpga_mgr {
> > > > > > > > +   altr,bitstream = "fpga-270-2.itb";
> > > > > > > > +};
> > > > > > > > diff --git a/arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts 
> > > > > > > > b/arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts
> > > > > > > > new file mode 100644
> > > > > > > > index 00..5f40af6eb9
> > > > > > > > --- /dev/null
> > > > > > > > +++ b/arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts
> > > > > > > > @@ -0,0 +1,5 @@
> > > > > > > > +// SPDX-License-Identifier: GPL-2.0
> > > > > > > > +/*
> > > > > > > > + * Copyright 2022 Google LLC
> > > > > > > > + */
> > > > > > > > +#include "socfpga_arria10_chameleonv3.dts"
> > > > > > >
> > > > > > > Can you create a common .dtsi file instead? We should not be 
> > > > > > > including
> > > > > > > a .dts file into another file.
> > > > > > >
> > > > > > Do you mean renaming chameleonv3.dts to .dtsi? In Linux it's a .dts,
> > > > > > because nothing includes it (no handoff headers are needed). Is it
> > > > > > fine to have the names differ across U-Boot and Linux?
> > > > >
> > > > > Ideally not, but we should not include a .dts file in another one and
> > > > > it is probably more important to follow that rule. But why is Linux
> > > > > not getting this variant?
> > > > >
> > > > > Regards,
> > > > > Simon
> > > >
> > > > Linux (at least for the near future) does not care about which variant
> > > > it is. The big differences between 270, 480, -2, -3 are mostly about
> > > > the number of FPGA logic gates and speed grades. Such things affect
> > > > the FPGA bitstream greatly, and might even affect clock presets that
> > > > u-boot cares about, but by the time linux loads it doesn't matter
> > > > anymore.
> > >
> > > Perhaps a more detailed explanation:
> > >
> > > The Main and Peripheral PLLs (as well

Re: [PATCH 1/1] efi_loader: printing UEFI revision in helloworld.efi

2022-09-02 Thread Simon Glass
Hi Heinrich,

On Thu, 1 Sept 2022 at 19:09, Heinrich Schuchardt
 wrote:
>
>
>
> On 9/2/22 01:52, Simon Glass wrote:
> > Hi Heinrich,
> >
> >
> > On Thu, 1 Sept 2022 at 14:44, Heinrich Schuchardt
> >  wrote:
> >>
> >> We need to support multiple digits in the parts of the UEFI verision
> >> number. E.g.
> >>
> >>  EFI_SPECIFICATION_VERSION = (123 << 16) | 456
> >>
> >> must be printed as
> >>
> >>  123.45.6
> >>
> >> Signed-off-by: Heinrich Schuchardt 
> >> ---
> >>   lib/efi_loader/helloworld.c | 66 ++---
> >>   1 file changed, 54 insertions(+), 12 deletions(-)
> >
> > Gosh, I'm not sure what to make of this! Could uint2dec() use strtoul()?
>
> This is standalone code. We cannot call any library functions here and
> we convert unsigned to wide string and not string to unsigned.

Oh well

Reviewed-by: Simon Glass 


Re: [PATCH] gpio: renesas: Simplify .request/.rfree callbacks

2022-09-02 Thread Pali Rohár
On Wednesday 03 August 2022 08:48:39 Stefan Roese wrote:
> On 02.08.22 12:06, Pali Rohár wrote:
> > Remove identify wrapper functions.
> > 
> > Signed-off-by: Pali Rohár 
> 
> Reviewed-by: Stefan Roese 

Any more comments? Or could it be merged?

> Thanks,
> Stefan
> 
> > ---
> >   drivers/gpio/gpio-rcar.c | 15 ++-
> >   1 file changed, 2 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
> > index 138801850d3e..ba00bb459679 100644
> > --- a/drivers/gpio/gpio-rcar.c
> > +++ b/drivers/gpio/gpio-rcar.c
> > @@ -130,20 +130,9 @@ static int rcar_gpio_get_function(struct udevice *dev, 
> > unsigned offset)
> > return GPIOF_INPUT;
> >   }
> > -static int rcar_gpio_request(struct udevice *dev, unsigned offset,
> > -const char *label)
> > -{
> > -   return pinctrl_gpio_request(dev, offset, label);
> > -}
> > -
> > -static int rcar_gpio_free(struct udevice *dev, unsigned offset)
> > -{
> > -   return pinctrl_gpio_free(dev, offset);
> > -}
> > -
> >   static const struct dm_gpio_ops rcar_gpio_ops = {
> > -   .request= rcar_gpio_request,
> > -   .rfree  = rcar_gpio_free,
> > +   .request= pinctrl_gpio_request,
> > +   .rfree  = pinctrl_gpio_free,
> > .direction_input= rcar_gpio_direction_input,
> > .direction_output   = rcar_gpio_direction_output,
> > .get_value  = rcar_gpio_get_value,
> 
> Viele Grüße,
> Stefan Roese
> 
> -- 
> DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH v2] tee: optee: rework TA bus scanning code

2022-09-02 Thread Ilias Apalodimas
Thanks Jens

On Wed, 31 Aug 2022 at 08:59, Jens Wiklander  wrote:
>
> On Mon, Aug 29, 2022 at 8:34 AM Ilias Apalodimas
>  wrote:
> >
> > Late versions of OP-TEE support a pseudo bus.  TAs that behave as
> > hardware blocks (e.g TPM, RNG etc) present themselves on a bus which we can
> > scan.  Unfortunately U-Boot doesn't support that yet. It's worth noting
> > that we already have a workaround for RNG.  The details are in
> > commit 70812bb83da6 ("tee: optee: bind rng optee driver")
> >
> > So let's add a list of devices based on U-Boot Kconfig options that we will
> > scan until we properly implement the tee-bus functionality.
> >
> > While at it change the behaviour of the tee core itself wrt to device
> > binding.  If some device binding fails, print a warning instead of
> > disabling OP-TEE.
> >
> > Signed-off-by: Ilias Apalodimas 
> > ---
>
> Reviewed-by: Jens Wiklander 

There's a typo in that patch. For the tpm to work the string needs to
be ftpm_tee instead of ftpm-tee.  I'll send a v3, shall I keep your
RB?

Cheers
/Ilias
>
> Cheers,
> Jens
>
> > Changes since v1:
> > - remove a macro and use ARRAY_SIZE directly
> > - print a warning instead of disabling op-tee if a driver binding fails
> >
> >  drivers/tee/optee/core.c | 23 +++
> >  1 file changed, 19 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> > index a89d62aaf0b3..3cc92f09d299 100644
> > --- a/drivers/tee/optee/core.c
> > +++ b/drivers/tee/optee/core.c
> > @@ -31,6 +31,18 @@ struct optee_pdata {
> > optee_invoke_fn *invoke_fn;
> >  };
> >
> > +static const struct {
> > +   const char *drv_name;
> > +   const char *dev_name;
> > +} optee_bus_probe[] = {
> > +#ifdef CONFIG_RNG_OPTEE
> > +   { "optee-rng", "optee-rng" },
> > +#endif
> > +#ifdef CONFIG_TPM2_FTPM_TEE
> > +   { "ftpm-tee", "ftpm-tee" },
> > +#endif
> > +};
> > +
> >  struct rpc_param {
> > u32 a0;
> > u32 a1;
> > @@ -643,7 +655,7 @@ static int optee_probe(struct udevice *dev)
> > struct optee_pdata *pdata = dev_get_plat(dev);
> > u32 sec_caps;
> > struct udevice *child;
> > -   int ret;
> > +   int ret, i;
> >
> > if (!is_optee_api(pdata->invoke_fn)) {
> > dev_err(dev, "OP-TEE api uid mismatch\n");
> > @@ -672,10 +684,13 @@ static int optee_probe(struct udevice *dev)
> >  * in U-Boot, the discovery of TA on the TEE bus is not supported:
> >  * only bind the drivers associated to the supported OP-TEE TA
> >  */
> > -   if (IS_ENABLED(CONFIG_RNG_OPTEE)) {
> > -   ret = device_bind_driver(dev, "optee-rng", "optee-rng", 
> > &child);
> > +
> > +   for (i = 0; i < ARRAY_SIZE(optee_bus_probe); i++) {
> > +   ret = device_bind_driver(dev, optee_bus_probe[i].drv_name,
> > +optee_bus_probe[i].dev_name, 
> > &child);
> > if (ret)
> > -   return ret;
> > +   dev_warn(dev, "Failed to bind device %s\n",
> > +optee_bus_probe[i].dev_name);
> > }
> >
> > return 0;
> > --
> > 2.34.1
> >


[PATCH] doc: socfpga_arria10_qspi_socdk: Document for running SPL/U-Boot on the kit

2022-09-02 Thread sieu . mun . tang
From: Tien Fong Chee 

This document would describe the steps for building SPL and U-Boot, and
showing the proposed layout for the QSPI flash.

Signed-off-by: Tien Fong Chee 
Signed-off-by: Sieu Mun Tang 
---
 doc/README.socfpga_arria10_qspi_socdk | 56 +++
 1 file changed, 56 insertions(+)
 create mode 100644 doc/README.socfpga_arria10_qspi_socdk

diff --git a/doc/README.socfpga_arria10_qspi_socdk 
b/doc/README.socfpga_arria10_qspi_socdk
new file mode 100644
index 00..57ebef2510
--- /dev/null
+++ b/doc/README.socfpga_arria10_qspi_socdk
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0
+ /*
+ * Copyright (C) 2019 Intel Corporation 
+ *
+ */
+
+
+SOCFPGA Documentation for U-Boot and SPL
+
+This README is about U-Boot and SPL support for Arria 10 QSPI SoCDK.
+
+a. Steps for building SPL and U-Boot:
+-
+1. cd to U-Boot source directory.
+2. Build both SPL and U-Boot, runs "export CROSS_COMPILE=arm-altera-eabi-;
+make mrproper; make socfpga_arria10_qspi_defconfig; make -8"
+3.Runs "mkpimage -hv 1 -o spl/spl_w_dtb-mkpimage.bin
+ spl/u-boot-spl-dtb.bin spl/u-boot-spl-dtb.bin spl/u-boot-spl-dtb.bin
+ spl/u-boot-spl-dtb.bin"
+
+b. Steps for building default FIT image for FPGA bitstreams:
+
+1. Copy both ghrd_10as066n2.periph.rbf and ghrd_10as066n2.core.rbf to U-Boot
+source root directory.
+2. Runs "tools /mkimage -E -f
+ board/altera/arria10-socdk/fit_spl_fpga.its fit_spl_fpga.itb"
+
+c. Steps for buiding default FIT image for U-Boot:
+--
+1. Ensure a. Steps for building SPL and U-Boot are done.
+2. Runs "tools/mkimage -E -f board/altera/arria10-socdk/fit_uboot.its
+ fit_spl_uboot.itb"
+
+d. Steps for buiding default FIT image for Linux and DTB:
+-
+1. Copy uImage & socfpga_arria10_socdk_qspi.dtb to U-Boot source root 
directory.
+2. Runs "tools/mkimage -f
+ board/altera/arria10-socdk/fit_kernel.its kernel.itb"
+
+After going through all steps described above, those images/binaries can be
+written into QSPI flash as shown in below proposed layout. Ensure no 
overlapping
+for each image.
+
+Addr 0 --
+   | spl_w_dtb-mkpimage.bin | 1MB
+   --
+   | fit_spl_uboot.itb  | 1MB
+   --
+   |env(64K) & env_redundant(64k)   | 1MB
+   --
+   |  fit_spl_fpga.itb  | depend on bitstreams size
+Addr 0x120 --
+   |  kernel.itb| depend on kernel.itb size
+Addr 0x272  --
+   |console-image-minimal-arria10.jffs2 | -(RFS)
+   --
-- 
2.25.1



Re: [PATCH 3/5] net: tftp: add IPv6 support for tftpboot

2022-09-02 Thread Vyacheslav Mitrofanov V
On Fri, 2022-09-02 at 17:48 +0300, Ramon Fried wrote:
> «Внимание! Данное письмо от внешнего адресата!»
> 
> On Mon, Aug 22, 2022 at 9:36 AM Vyacheslav Mitrofanov V
>  wrote:
> > On Fri, 2022-08-19 at 21:01 +0300, Ramon Fried wrote:
> > > On Fri, Aug 19, 2022 at 2:30 PM Vyacheslav Mitrofanov V
> > >  wrote:
> > > > On Fri, 2022-08-19 at 14:00 +0300, Ramon Fried wrote:
> > > > > On Fri, Aug 19, 2022 at 11:10 AM Viacheslav Mitrofanov
> > > > >  wrote:
> > > > > > The command tftpboot uses IPv4 by default, to use IPv6
> > > > > > instead
> > > > > > add
> > > > > > -ipv6
> > > > > > as the last argument. All other tftpboot features and
> > > > > > parameters
> > > > > > are left
> > > > > > the same.
> > > > > > 
> > > > > In my opinion, we should be able to detect if a user has
> > > > > provided
> > > > > or
> > > > > set an IPv6 server IP address and only use IPv6 then.
> > > > I tried to save tftboot semantics. I mean if we set -ipv6
> > > > option
> > > > the
> > > > command will check server address in args if it is empty check
> > > > environmental variable and if it is not set then terminate it.
> > > > It
> > > > works
> > > > the same way as it works now. If I didn't get you, please,
> > > > clarify
> > > > it a
> > > > little bit more.
> > > > Thanks!
> > > What I meant is that if you can distinguish IPv6 address from
> > > just
> > > parsing the address itself.
> > > Perhaps the -ipv6 is redundant.
> > It is not a problem to add a parser, I'll do that.
> > I thought that suffix can be useful if we use short command
> > notation as
> > an example just 'tftpboot'. In that case it uses IPv4 but if add
> > suffix
> > it will use IPv6. Or I can remove suffix at all and use an
> > environment
> > variable for example 'use_ip6' to determine protocol.
> > What do you think?!
> > Thanks!
> I think we can stay with the ipv6. I looked at some Linux command
> line
> utilities and they also require a parameter for Ipv6.
> Reviewed-by: Ramon Fried 

Hello Ramon!

I have already add the possibility to check if there is an IPv6
address. If so -ipv6 suffix is not obligatory. All this changes are
made in a new patchset that I sent 3 days ago. Simon Glass has already
reviewed some. 

Thanks!


Re: [PATCH] net: enetc: Fix use after free issue in fsl_enetc.c

2022-09-02 Thread Ramon Fried
On Wed, Aug 31, 2022 at 4:49 PM Simon Glass  wrote:
>
> On Wed, 31 Aug 2022 at 05:20, Siarhei Yasinski
>  wrote:
> >
> > If ethernet connected to SFP, like this:
> >
> > &enetc_port0 {
> > phy-connection-type = "sgmii";
> > sfp = <&sfp0>;
> > managed = "in-band-status";
> > status = "okay";
> > };
> >
> > Then enetc_config_phy returns -ENODEV and the memory containing the mdio 
> > interface is freed.
> > It's better to unregister and free mdio resources.
> >
> > Signed-off-by: Siarhei Yasinski 
>
> Reviewed-by: Simon Glass 
>
> but note we normally use the var name 'ret' with driver model.
>
>
> >
> > diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c
> > index cd4c2c29a6..835e5bd8bd 100644
> > --- a/drivers/net/fsl_enetc.c
> > +++ b/drivers/net/fsl_enetc.c
> > @@ -22,6 +22,8 @@
> >
> >  #define ENETC_DRIVER_NAME  "enetc_eth"
> >
> > +static int enetc_remove(struct udevice *dev);
> > +
> >  /*
> >   * sets the MAC address in IERB registers, this setting is persistent and
> >   * carried over to Linux.
> > @@ -319,6 +321,7 @@ static int enetc_config_phy(struct udevice *dev)
> >  static int enetc_probe(struct udevice *dev)
> >  {
> > struct enetc_priv *priv = dev_get_priv(dev);
> > +   int res;
> >
> > if (ofnode_valid(dev_ofnode(dev)) && 
> > !ofnode_is_available(dev_ofnode(dev))) {
> > enetc_dbg(dev, "interface disabled\n");
> > @@ -350,7 +353,10 @@ static int enetc_probe(struct udevice *dev)
> >
> > enetc_start_pcs(dev);
> >
> > -   return enetc_config_phy(dev);
> > +   res = enetc_config_phy(dev);
> > +   if(res)
> > +   enetc_remove(dev);
> > +   return res;
> >  }
> >
> >  /*
Reviewed-by: Ramon Fried 


Re: [PATCH 3/5] net: tftp: add IPv6 support for tftpboot

2022-09-02 Thread Ramon Fried
On Mon, Aug 22, 2022 at 9:36 AM Vyacheslav Mitrofanov V
 wrote:
>
> On Fri, 2022-08-19 at 21:01 +0300, Ramon Fried wrote:
> >
> > On Fri, Aug 19, 2022 at 2:30 PM Vyacheslav Mitrofanov V
> >  wrote:
> > > On Fri, 2022-08-19 at 14:00 +0300, Ramon Fried wrote:
> > > > On Fri, Aug 19, 2022 at 11:10 AM Viacheslav Mitrofanov
> > > >  wrote:
> > > > > The command tftpboot uses IPv4 by default, to use IPv6 instead
> > > > > add
> > > > > -ipv6
> > > > > as the last argument. All other tftpboot features and
> > > > > parameters
> > > > > are left
> > > > > the same.
> > > > >
> > > > In my opinion, we should be able to detect if a user has provided
> > > > or
> > > > set an IPv6 server IP address and only use IPv6 then.
> > > I tried to save tftboot semantics. I mean if we set -ipv6 option
> > > the
> > > command will check server address in args if it is empty check
> > > environmental variable and if it is not set then terminate it. It
> > > works
> > > the same way as it works now. If I didn't get you, please, clarify
> > > it a
> > > little bit more.
> > > Thanks!
> > What I meant is that if you can distinguish IPv6 address from just
> > parsing the address itself.
> > Perhaps the -ipv6 is redundant.
> It is not a problem to add a parser, I'll do that.
> I thought that suffix can be useful if we use short command notation as
> an example just 'tftpboot'. In that case it uses IPv4 but if add suffix
> it will use IPv6. Or I can remove suffix at all and use an environment
> variable for example 'use_ip6' to determine protocol.
> What do you think?!
> Thanks!
I think we can stay with the ipv6. I looked at some Linux command line
utilities and they also require a parameter for Ipv6.
Reviewed-by: Ramon Fried 


[PATCH v15 10/10] test: unit test for eficonfig

2022-09-02 Thread Masahisa Kojima
Provide a unit test for the eficonfig command.

Signed-off-by: Masahisa Kojima 
Acked-by: Ilias Apalodimas 
---
No update since v15

Changes in v14:
- update to support media device enumeration in eficonfig startup
- move no block device test to the last test case

Changes in v12:
- update menu handling

Changes in v11:
- fix expected result when no BootOrder is defined

Newly added in v10

 configs/sandbox_defconfig |   1 +
 test/py/tests/test_eficonfig/conftest.py  |  40 ++
 .../py/tests/test_eficonfig/test_eficonfig.py | 350 ++
 3 files changed, 391 insertions(+)
 create mode 100644 test/py/tests/test_eficonfig/conftest.py
 create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index eba7bcbb48..48c60c606d 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -93,6 +93,7 @@ CONFIG_CMD_LINK_LOCAL=y
 CONFIG_CMD_ETHSW=y
 CONFIG_CMD_BMP=y
 CONFIG_CMD_BOOTCOUNT=y
+CONFIG_CMD_EFICONFIG=y
 CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_RTC=y
 CONFIG_CMD_TIME=y
diff --git a/test/py/tests/test_eficonfig/conftest.py 
b/test/py/tests/test_eficonfig/conftest.py
new file mode 100644
index 00..f289df0362
--- /dev/null
+++ b/test/py/tests/test_eficonfig/conftest.py
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier:  GPL-2.0+
+
+"""Fixture for UEFI eficonfig test
+"""
+
+import os
+import shutil
+from subprocess import check_call
+import pytest
+
+@pytest.fixture(scope='session')
+def efi_eficonfig_data(u_boot_config):
+"""Set up a file system to be used in UEFI "eficonfig" command
+   tests
+
+Args:
+u_boot_config -- U-boot configuration.
+
+Return:
+A path to disk image to be used for testing
+"""
+mnt_point = u_boot_config.persistent_data_dir + '/test_efi_eficonfig'
+image_path = u_boot_config.persistent_data_dir + '/efi_eficonfig.img'
+
+shutil.rmtree(mnt_point, ignore_errors=True)
+os.mkdir(mnt_point, mode = 0o755)
+
+with open(mnt_point + '/initrd-1.img', 'w', encoding = 'ascii') as file:
+file.write("initrd 1")
+
+with open(mnt_point + '/initrd-2.img', 'w', encoding = 'ascii') as file:
+file.write("initrd 2")
+
+shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/initrddump.efi',
+mnt_point + '/initrddump.efi')
+
+check_call(f'virt-make-fs --partition=gpt --size=+1M --type=vfat 
{mnt_point} {image_path}',
+   shell=True)
+
+return image_path
diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py 
b/test/py/tests/test_eficonfig/test_eficonfig.py
new file mode 100644
index 00..1c501deb1f
--- /dev/null
+++ b/test/py/tests/test_eficonfig/test_eficonfig.py
@@ -0,0 +1,350 @@
+# SPDX-License-Identifier:  GPL-2.0+
+""" Unit test for UEFI menu-driven configuration
+"""
+
+import pytest
+import time
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_eficonfig')
+@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
+def test_efi_eficonfig(u_boot_console, efi_eficonfig_data):
+
+def send_user_input_and_wait(user_str, expect_str):
+time.sleep(0.1) # TODO: does not work correctly without sleep
+u_boot_console.run_command(cmd=user_str, wait_for_prompt=False,
+   wait_for_echo=True, send_nl=False)
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+if expect_str is not None:
+for i in expect_str:
+u_boot_console.p.expect([i])
+
+def press_up_down_enter_and_wait(up_count, down_count, enter, expect_str):
+# press UP key
+for i in range(up_count):
+u_boot_console.run_command(cmd='\x1b\x5b\x41', 
wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# press DOWN key
+for i in range(down_count):
+u_boot_console.run_command(cmd='\x1b\x5b\x42', 
wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# press ENTER if requested
+if enter:
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False,
+   wait_for_echo=False, send_nl=False)
+# wait expected output
+if expect_str is not None:
+for i in expect_str:
+u_boot_console.p.expect([i])
+
+def press_escape_key(wait_prompt):
+u_boot_console.run_command(cmd='\x1b', wait_for_prompt=wait_prompt, 
wait_for_echo=False, send_nl=False)
+
+def press_enter_key(wait_prompt):
+u_boot_console.run_command(cmd='\x0d', wait_for_prompt=wait_prompt,
+   wait_for_echo=False, send_nl=False)
+
+def check_current_is_maintenance_menu():
+for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot 
Option',
+

[PATCH v15 09/10] doc:eficonfig: add documentation for eficonfig command

2022-09-02 Thread Masahisa Kojima
Add documentation for eficonfig command.

Signed-off-by: Masahisa Kojima 
Reviewed-by: Ilias Apalodimas 
---
No update since v15

Changes in v14:
- fix typos

Changes in v13:
- describe how to auto boot according to the UEFI Boot option

Changes in v12:
- CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE condition is added
  to show newly added boot option

No update since v10

Changes in v10:
- describe how to boot system after editting by eficonfig

Changes in v8:
- command name is changed from "efimenu" to "eficonfig"

Newly created in v7

 doc/usage/cmd/eficonfig.rst | 71 +
 doc/usage/index.rst |  1 +
 2 files changed, 72 insertions(+)
 create mode 100644 doc/usage/cmd/eficonfig.rst

diff --git a/doc/usage/cmd/eficonfig.rst b/doc/usage/cmd/eficonfig.rst
new file mode 100644
index 00..340ebc80db
--- /dev/null
+++ b/doc/usage/cmd/eficonfig.rst
@@ -0,0 +1,71 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. (C) Copyright 2022, Masahisa Kojima 
+
+eficonfig command
+=
+
+Synopsis
+
+::
+
+eficonfig
+
+Description
+---
+
+The "eficonfig" command uses U-Boot menu interface and provides
+a menu-driven UEFI variable maintenance feature.
+The "eficonfig" has the following menu entries.
+
+Add Boot Option
+Add new UEFI Boot Option.
+User can edit description, file path, and optional_data.
+
+Edit Boot Option
+Edit the existing UEFI Boot Option
+User can edit description, file path, and optional_data.
+
+Change Boot Order
+Change the order of UEFI BootOrder variable.
+
+Delete Boot Option
+Delete the UEFI Boot Option
+
+Configuration
+-
+
+The "eficonfig" command is enabled by::
+
+CONFIG_CMD_EFICONFIG=y
+
+If CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled, user can not enter
+U-Boot console. In this case, bootmenu can be used to invoke "eficonfig"::
+
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="setenv bootmenu_0 UEFI Maintenance Menu=eficonfig"
+
+How to boot the system with newly added UEFI Boot Option
+
+
+"eficonfig" command is responsible for configuring the UEFI variables,
+not directly handle the system boot.
+The new Boot Option added by "eficonfig" is appended at the last entry
+of UEFI BootOrder variable, user may want to change the boot order
+through "Change Boot Order".
+If the bootmenu is enabled, CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled,
+and "eficonfig" is configured as preboot command, the newly added Boot Options
+are enumerated in the bootmenu when user exits from the eficonfig menu.
+User may select the entry in the bootmenu to boot the system, or follow
+the U-Boot configuration the system already has.
+
+Auto boot with the UEFI Boot Option
+'''
+
+To do auto boot according to the UEFI BootOrder variable,
+add "bootefi bootmgr" entry as a default or first bootmenu entry::
+
+CONFIG_PREBOOT="setenv bootmenu_0 UEFI Boot Manager=bootefi bootmgr; 
setenv bootmenu_1 UEFI Maintenance Menu=eficonfig"
+
+See also
+
+* :doc:`bootmenu` provides a simple mechanism for creating menus 
with different boot items
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 28f9683a3e..09f2928970 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -35,6 +35,7 @@ Shell commands
cmd/conitrace
cmd/dm
cmd/echo
+   cmd/eficonfig
cmd/env
cmd/event
cmd/exception
-- 
2.17.1



[PATCH v15 08/10] doc:bootmenu: add description for UEFI boot support

2022-09-02 Thread Masahisa Kojima
The bootmenu enumerates the UEFI boot options
for boot device selection.
This commit adds the description how the UEFI boot work
in bootmenu. This commit also adds "Synopsis", "Description"
and "Configuration" sections to follow the U-Boot command
documentation format.

Signed-off-by: Masahisa Kojima 
Reviewed-by: Ilias Apalodimas 
---
No update since v10

Changes in v10:
- fix typos

Changes in v7:
- update the description what bootmenu do for uefi-related boot menu
- add default behavior when user exits from bootmenu

Changes in v6:
- remove distro boot related contents because the distro boot
support in bootmenu is dropped
- update uefi entry example
- add [delay] argument of bootmenu command
- add description to enable uefi boot entry

Changes in v5:
- follow the cmd documentation format same as other command, add "Synopsis",
  "Description" add "Configuration" sections

Newly created in v4

 doc/usage/cmd/bootmenu.rst | 74 ++
 1 file changed, 74 insertions(+)

diff --git a/doc/usage/cmd/bootmenu.rst b/doc/usage/cmd/bootmenu.rst
index 9430f8c9aa..cb3c8d2f93 100644
--- a/doc/usage/cmd/bootmenu.rst
+++ b/doc/usage/cmd/bootmenu.rst
@@ -4,6 +4,15 @@
 bootmenu command
 
 
+Synopsis
+
+::
+
+bootmenu [delay]
+
+Description
+---
+
 The "bootmenu" command uses U-Boot menu interfaces and provides
 a simple mechanism for creating menus with different boot items.
 The cursor keys "Up" and "Down" are used for navigation through
@@ -79,6 +88,55 @@ The above example will be rendered as below::
 The selected menu entry will be highlighted - it will have inverted
 background and text colors.
 
+UEFI boot variable enumeration
+''
+If enabled, the bootmenu command will automatically generate and add
+UEFI-related boot menu entries for the following items.
+
+ * possible bootable media with default file names
+ * user-defined UEFI boot options
+
+The bootmenu automatically enumerates the possible bootable
+media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.
+This auto generated entry is named as " :" format.
+(e.g. "usb 0:1")
+
+The bootmenu displays the UEFI-related menu entries in order of "BootOrder".
+When the user selects the UEFI boot menu entry, the bootmenu sets
+the selected boot variable index to "BootNext" without non-volatile attribute,
+then call the uefi boot manager with the command "bootefi bootmgr".
+
+Example bootmenu is as below::
+
+*** U-Boot Boot Menu ***
+
+   mmc 0:1
+   mmc 0:2
+   debian
+   nvme 0:1
+   ubuntu
+   nvme 0:2
+   usb 0:2
+   U-Boot console
+
+Default behavior when user exits from the bootmenu
+~~
+User can exit from bootmenu by selecting the last entry
+"U-Boot console"/"Quit" or ESC/CTRL+C key.
+
+When the CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is disabled,
+user exits from the bootmenu and returns to the U-Boot console.
+
+When the CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE is enabled, user can not
+enter the U-Boot console. When the user exits from the bootmenu,
+the bootmenu invokes the following default behavior.
+
+ * if CONFIG_CMD_BOOTEFI_BOOTMGR is enabled, execute "bootefi bootmgr" command
+ * "bootefi bootmgr" fails or is not enabled, then execute "run bootcmd" 
command.
+
+Configuration
+-
+
 The "bootmenu" command is enabled by::
 
 CONFIG_CMD_BOOTMENU=y
@@ -88,3 +146,19 @@ To run the bootmenu at startup add these additional 
settings::
 CONFIG_AUTOBOOT_KEYED=y
 CONFIG_BOOTDELAY=30
 CONFIG_AUTOBOOT_MENU_SHOW=y
+
+UEFI boot variable enumeration is enabled by::
+
+CONFIG_CMD_BOOTEFI_BOOTMGR=y
+
+To improve the product security, entering U-Boot console from bootmenu
+can be disabled by::
+
+CONFIG_BOOTMENU_DISABLE_UBOOT_CONSOLE=y
+
+To scan the discoverable devices connected to the buses such as
+USB and PCIe prior to bootmenu showing up, CONFIG_PREBOOT can be
+used to run the command before showing the bootmenu, i.e.::
+
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="pci enum; usb start; scsi scan; nvme scan; virtio scan"
-- 
2.17.1



[PATCH v15 07/10] eficonfig: add "Change Boot Order" menu entry

2022-09-02 Thread Masahisa Kojima
This commit adds the menu entry to update UEFI BootOrder variable.
User moves the entry with UP/DOWN key, changes the order
with PLUS/MINUS key, press SPACE to activate or deactivate
the entry, then finalizes the order by ENTER key.
If the entry is activated, the boot index is added into the
BootOrder variable in the order of the list.

The U-Boot menu framework is well designed for static menu,
this commit implements the own menu display and key handling
for dynamically change the order of menu entry.

Signed-off-by: Masahisa Kojima 
---
No update since v15

Changes in v14:
- remove scan of media device, it is moved into eficonfig startup
- add comment in default case for key handling
- add missing break in eficonfig_choice_entry

Changes in v12:
- enumerate removable media device

Changes in v11:
- remove BootOrder variable dependency
- use ANSI_CURSOR_POSITION and ANSI_CLEAR_LINE instead of printf("\n")
  since current eficonfig implementation does not handle console size correctly.
  printf("\n") at the outside of console size breaks the console output.
- add KEY_SPACE to toggle the boot option active status

No update since v9

Changes in v9:
- add function comment

Changes in v8:
- add "Save" and "Quit" entries

Changes in v7:
- use UP/DOWN and PLUS/MINUS key to change to order

no update in v6:

 cmd/eficonfig.c | 348 +++-
 1 file changed, 347 insertions(+), 1 deletion(-)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index dda45a8364..2e1f2bfd8b 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -91,6 +91,23 @@ struct eficonfig_boot_selection_data {
int *selected;
 };
 
+/**
+ * struct eficonfig_boot_order - structure to be used to update BootOrder 
variable
+ *
+ * @num:   index in the menu entry
+ * @description:   pointer to the description string
+ * @boot_index:boot option index
+ * @active:flag to include the boot option into BootOrder variable
+ * @list:  list structure
+ */
+struct eficonfig_boot_order {
+   u32 num;
+   u16 *description;
+   u32 boot_index;
+   bool active;
+   struct list_head list;
+};
+
 /**
  * eficonfig_print_msg() - print message
  *
@@ -1748,6 +1765,335 @@ out:
return ret;
 }
 
+/**
+ * eficonfig_display_change_boot_order() - display the BootOrder list
+ *
+ * @efi_menu:  pointer to the efimenu structure
+ * Return: status code
+ */
+static void eficonfig_display_change_boot_order(struct efimenu *efi_menu)
+{
+   bool reverse;
+   struct list_head *pos, *n;
+   struct eficonfig_boot_order *entry;
+
+   printf(ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION
+  "\n  ** Change Boot Order **\n"
+  ANSI_CURSOR_POSITION
+  "  Press UP/DOWN to move, +/- to change order"
+  ANSI_CURSOR_POSITION
+  "  Press SPACE to activate or deactivate the entry"
+  ANSI_CURSOR_POSITION
+  "  Select [Save] to complete, ESC/CTRL+C to quit"
+  ANSI_CURSOR_POSITION ANSI_CLEAR_LINE,
+  1, 1, efi_menu->count + 5, 1, efi_menu->count + 6, 1,
+  efi_menu->count + 7, 1,  efi_menu->count + 8, 1);
+
+   /* draw boot option list */
+   list_for_each_safe(pos, n, &efi_menu->list) {
+   entry = list_entry(pos, struct eficonfig_boot_order, list);
+   reverse = (entry->num == efi_menu->active);
+
+   printf(ANSI_CURSOR_POSITION, entry->num + 4, 7);
+
+   if (reverse)
+   puts(ANSI_COLOR_REVERSE);
+
+   if (entry->num < efi_menu->count - 2) {
+   if (entry->active)
+   printf("[*]  ");
+   else
+   printf("[ ]  ");
+   }
+
+   printf("%ls", entry->description);
+
+   if (reverse)
+   puts(ANSI_COLOR_RESET);
+   }
+}
+
+/**
+ * eficonfig_choice_change_boot_order() - handle the BootOrder update
+ *
+ * @efi_menu:  pointer to the efimenu structure
+ * Return: status code
+ */
+static efi_status_t eficonfig_choice_change_boot_order(struct efimenu 
*efi_menu)
+{
+   int esc = 0;
+   struct list_head *pos, *n;
+   struct eficonfig_boot_order *tmp;
+   enum bootmenu_key key = KEY_NONE;
+   struct eficonfig_boot_order *entry;
+
+   while (1) {
+   bootmenu_loop(NULL, &key, &esc);
+
+   switch (key) {
+   case KEY_PLUS:
+   if (efi_menu->active > 0) {
+   list_for_each_safe(pos, n, &efi_menu->list) {
+   entry = list_entry(pos, struct 
eficonfig_boot_order, list);
+   if (entry->num == efi_menu->active)
+   break;
+   }
+   tmp =

[PATCH v15 06/10] eficonfig: scan media device in eficonfig startup

2022-09-02 Thread Masahisa Kojima
In eficonfig startup, scan media devices and update
the UEFI boot option.

Signed-off-by: Masahisa Kojima 
---
No update since v14

Newly created in v14

 cmd/eficonfig.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 21d9bd3e23..dda45a8364 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -2089,6 +2089,10 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int flag, 
int argc, char *const a
if (ret != EFI_SUCCESS)
return CMD_RET_FAILURE;
 
+   ret = eficonfig_generate_media_device_boot_option();
+   if (ret != EFI_SUCCESS && ret != EFI_NOT_FOUND)
+   return ret;
+
while (1) {
efi_menu = eficonfig_create_fixed_menu(maintenance_menu_items,
   
ARRAY_SIZE(maintenance_menu_items));
-- 
2.17.1



[PATCH v15 05/10] bootmenu: add removable media entries

2022-09-02 Thread Masahisa Kojima
UEFI specification requires booting from removal media using
a architecture-specific default image name such as BOOTAA64.EFI.
This commit adds the removable media entries into bootmenu,
so that user can select the removable media and boot with
default image.

The bootmenu automatically enumerates the possible bootable
media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
add it as new UEFI boot option(BOOT) and update BootOrder
variable. This automatically generated UEFI boot option
has the dedicated guid in the optional_data to distinguish it from
the UEFI boot option user adds manually. This optional_data is
removed when the efi bootmgr loads the selected UEFI boot option.

This commit also provides the BOOT variable maintenance feature.
Depending on the system hardware setup, some devices
may not exist at a later system boot, so bootmenu checks the
available device in each bootmenu invocation and automatically
removes the BOOT variable corrensponding to the non-existent
media device.

Signed-off-by: Masahisa Kojima 
---
No update since v14

Changes in v14:
- remove invalid free() call

Changes in v13:
- remove BootOrder variable dependency

Changes in v12:
- move generate_media_device_boot_option into cmd/eficonfig.c and expose it
- remove unnecessary include file

Changes in v11:
- update delete_boot_option() parameter

Changes in v10:
- add function comment
- devname dynamic allocation removes, allocate in stack
- delete BOOT when updating BootOrder fails

Changes in v9:
- update efi_disk_get_device_name() parameter to pass efi_handle_t
- add function comment

Changes in v8:
- function and structure prefix is changed to "eficonfig"

Changes in v7:
- rename prepare_media_device_entry() to generate_media_device_boot_option()

Changes in v6:
- optional_data size is changed to 16bytes
- check the load option size before comparison
- remove guid included in optional_data of auto generated
  entry when loading

Changes in v5:
- Return EFI_SUCCESS if there is no BootOrder defined
- correctly handle the case if no removable device found
- use guid to identify the automatically generated entry by bootmenu

 cmd/bootmenu.c   |  22 +++-
 cmd/eficonfig.c  | 208 +++
 include/efi_config.h |   1 +
 include/efi_loader.h |  16 +++
 lib/efi_loader/efi_bootmgr.c |   4 +
 5 files changed, 245 insertions(+), 6 deletions(-)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 704d36debe..3340be1632 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -220,7 +220,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data 
*menu,
return 1;
 }
 
-#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR))
+#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) && 
(CONFIG_IS_ENABLED(CMD_EFICONFIG))
 /**
  * prepare_uefi_bootorder_entry() - generate the uefi bootmenu entries
  *
@@ -340,11 +340,21 @@ static struct bootmenu_data *bootmenu_create(int delay)
if (ret < 0)
goto cleanup;
 
-#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR))
+#if (CONFIG_IS_ENABLED(CMD_BOOTEFI_BOOTMGR)) && 
(CONFIG_IS_ENABLED(CMD_EFICONFIG))
if (i < MAX_COUNT - 1) {
-   ret = prepare_uefi_bootorder_entry(menu, &iter, &i);
-   if (ret < 0 && ret != -ENOENT)
-   goto cleanup;
+   efi_status_t efi_ret;
+
+   /*
+* UEFI specification requires booting from removal media using
+* a architecture-specific default image name such as 
BOOTAA64.EFI.
+*/
+   efi_ret = eficonfig_generate_media_device_boot_option();
+   if (efi_ret != EFI_SUCCESS && efi_ret != EFI_NOT_FOUND)
+   goto cleanup;
+
+   ret = prepare_uefi_bootorder_entry(menu, &iter, &i);
+   if (ret < 0 && ret != -ENOENT)
+   goto cleanup;
}
 #endif
 
diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index c9713acdda..21d9bd3e23 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1818,6 +1818,214 @@ static efi_status_t 
eficonfig_process_delete_boot_option(void *data)
return ret;
 }
 
+/**
+ * eficonfig_enumerate_boot_option() - enumerate the possible bootable media
+ *
+ * @opt:   pointer to the media boot option structure
+ * @volume_handles:pointer to the efi handles
+ * @count: number of efi handle
+ * Return: status code
+ */
+efi_status_t eficonfig_enumerate_boot_option(struct 
eficonfig_media_boot_option *opt,
+efi_handle_t *volume_handles, 
efi_status_t count)
+{
+   u32 i;
+   struct efi_handler *handler;
+   efi_status_t ret = EFI_SUCCESS;
+
+   for (i = 0; i < count; i++) {
+   u16 *p;
+   u16 dev_name[BOOTMENU_DEVICE_NAME_MAX];

[PATCH v15 04/10] eficonfig: add "Delete Boot Option" menu entry

2022-09-02 Thread Masahisa Kojima
This commit adds the menu entry to delete the UEFI boot option.
User moves the entry with UP/DOWN key, changes, then presses
ENTER key to delete the selected boot option.

Signed-off-by: Masahisa Kojima 
---
No update since v11

Changes in v11:
- update function interface to show boot selection menu
- support to delete the load option is not included in BootOrder

No update since v9

Changes in v9:
- add function comment

Changes in v8:
- function and structure prefix is changed to "eficonfig"

Changes in v7:
- to stay the boot order list after user delete the entry

no update in v6:

changes in v5:

 cmd/eficonfig.c | 71 +
 1 file changed, 71 insertions(+)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index bba83579a3..c9713acdda 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -1748,6 +1748,76 @@ out:
return ret;
 }
 
+/**
+ * delete_boot_option() - delete selected boot option
+ *
+ * @boot_index:boot option index to delete
+ * Return: status code
+ */
+static efi_status_t delete_boot_option(u16 boot_index)
+{
+   u16 *bootorder;
+   u16 varname[9];
+   efi_status_t ret;
+   unsigned int index;
+   efi_uintn_t num, size;
+
+   efi_create_indexed_name(varname, sizeof(varname),
+   "Boot", boot_index);
+   ret = efi_set_variable_int(varname, &efi_global_variable_guid,
+  0, 0, NULL, false);
+   if (ret != EFI_SUCCESS) {
+   log_err("delete boot option(%ls) failed\n", varname);
+   return ret;
+   }
+
+   /* update BootOrder if necessary */
+   bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size);
+   if (!bootorder)
+   return EFI_SUCCESS;
+
+   num = size / sizeof(u16);
+   if (!search_bootorder(bootorder, num, boot_index, &index))
+   return EFI_SUCCESS;
+
+   memmove(&bootorder[index], &bootorder[index + 1],
+   (num - index - 1) * sizeof(u16));
+   size -= sizeof(u16);
+   ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid,
+  EFI_VARIABLE_NON_VOLATILE |
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS,
+  size, bootorder, false);
+
+   return ret;
+}
+
+/**
+ * eficonfig_process_delete_boot_option() - handler to delete boot option
+ *
+ * @data:  pointer to the data for each entry
+ * Return: status code
+ */
+static efi_status_t eficonfig_process_delete_boot_option(void *data)
+{
+   efi_status_t ret;
+   unsigned int selected;
+
+   while (1) {
+   ret = eficonfig_show_boot_selection(&selected);
+   if (ret == EFI_SUCCESS)
+   ret = delete_boot_option(selected);
+
+   if (ret != EFI_SUCCESS)
+   break;
+   }
+
+   /* to stay the parent menu */
+   ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret;
+
+   return ret;
+}
+
 /**
  * eficonfig_init() - do required initialization for eficonfig command
  *
@@ -1778,6 +1848,7 @@ static efi_status_t eficonfig_init(void)
 static const struct eficonfig_item maintenance_menu_items[] = {
{"Add Boot Option", eficonfig_process_add_boot_option},
{"Edit Boot Option", eficonfig_process_edit_boot_option},
+   {"Delete Boot Option", eficonfig_process_delete_boot_option},
{"Quit", eficonfig_process_quit},
 };
 
-- 
2.17.1



[PATCH v15 03/10] menu: add KEY_PLUS, KEY_MINUS and KEY_SPACE handling

2022-09-02 Thread Masahisa Kojima
This is preparation to support menu-driven UEFI BootOrder
variable updated by KEY_PLUS, KEY_MINUS and KEY_SPACE.

Signed-off-by: Masahisa Kojima 
Reviewed-by: Heinrich Schuchardt 
Reviewed-by: Ilias Apalodimas 
---
No update since v11

Changes in v11:
- add SPACE key handling

Newly created in v7

 common/menu.c  | 9 +
 include/menu.h | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/common/menu.c b/common/menu.c
index 3e876b55b3..0d19601cf5 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -548,4 +548,13 @@ void bootmenu_loop(struct bootmenu_data *menu,
/* ^C was pressed */
if (c == 0x3)
*key = KEY_QUIT;
+
+   if (c == '+')
+   *key = KEY_PLUS;
+
+   if (c == '-')
+   *key = KEY_MINUS;
+
+   if (c == ' ')
+   *key = KEY_SPACE;
 }
diff --git a/include/menu.h b/include/menu.h
index e74616cae8..702aacb170 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -48,6 +48,9 @@ enum bootmenu_key {
KEY_DOWN,
KEY_SELECT,
KEY_QUIT,
+   KEY_PLUS,
+   KEY_MINUS,
+   KEY_SPACE,
 };
 
 void bootmenu_autoboot_loop(struct bootmenu_data *menu,
-- 
2.17.1



[PATCH v15 01/10] eficonfig: menu-driven addition of UEFI boot option

2022-09-02 Thread Masahisa Kojima
This commit add the "eficonfig" command.
The "eficonfig" command implements the menu-driven UEFI boot option
maintenance feature. This commit implements the addition of
new boot option. User can select the block device volume having
efi_simple_file_system_protocol and select the file corresponding
to the Boot variable. User can also enter the description and
optional_data of the BOOT variable in utf8.

This commit adds "include/efi_config.h", it contains the common
definition to be used from other menus such as UEFI Secure Boot
key management.

Signed-off-by: Masahisa Kojima 
---
Changes in v15:
- moves the free(entry->data) outside the eficonfig_destroy() function and
  entry->data is freed explicitly only when needed
- expose eficonfig_destroy() for succeeding secure boot key management patch

Changes in v14:
- fix the missing initialization
- add comment for key handling

No change in v13:

Changes in v12:
- add select/clear menu before displaying volume selectio
- move function declaration from efi_loader.h to efi_config.h
- remove unused declaration
- support the boot option does not have file path
- correctly handle if optional_data is empty

Changes in v11:
- refactor menu entry construction, directly use eficonfig_entry structure
- remove reading directory info to calculate the number of entry
- fix invalid efi_free_pool() in ill_file_info()
- use ANSI_CURSOR_POSITION and ANSI_CLEAR_LINE instead of printf("\n")
  since current eficonfig implementation does not handle console size correctly.
  printf("\n") at the outside of console size breaks the console output.

Changes in v10:
- add initrd file selection
- do refactoring
- eficonfig_process_common() use list structure
- remove u'/' before copying file_path into current_path
- fix typos
- check snprintf error

Changes in v9:
- move "efi_guid_bootmenu_auto_generated definition" into efi_bootmgr.c
  to address build error when CMD_EFICONFIG is disabled
- fix typos and comment
- remove file system information from error message
- remove unreachable code in eficonfig_choice_entry()
- single printf() call as much as possible
- call only getchar() in  eficonfig_print_msg()
- filter out '.' entry from file selection
- update the efi_disk_get_device_name() implementation
- add function comment

Changes in v8:
- command name is change from "efimenu" to "eficonfig"
- function and struct prefixes is changed to "eficonfig"
- fix menu header string

Changes in v7:
- add "efimenu" command and uefi variable maintenance code
  moved into cmd/efimenu.c
- create include/efimenu.h to define the common definition for
  the other menu such as UEFI Secure Boot key management
- update boot option edit UI, user can select description, file,
  and optional_data to edit in the same menu like following.

  ** Edit Boot Option **

 Description: debian
 File: virtio 0:1/EFI\debian\grubaa64.efi
 Optional Data: test
 Save
 Quit

- remove exit parameter from efimenu_process_common()
- menu title type is changed from u16 to char
- efimenu_process_common() add menu title string
- reduce printf/puts function call for displaying the menu
- efi_console_get_u16_string() accept 0 length to allow
  optional_data is empty
- efi_console_get_u16_string() the "size" parameter name is changes to "count"
- efimenu is now designed to maintain the UEFI variables, remove autoboot 
related code
- remove one empty line before "Quit" entry
- efimenu_init() processes only the first time

Changes in v6:
- fix typos
- modify volume name to match U-Boot syntax
- compile in CONFIG_EFI_LOADER=n and CONFIG_CMD_BOOTEFI_BOOTMGR=n
- simplify u16_strncmp() usage
- support "a\b.efi" file path, use link list to handle filepath
- modify length check condition
- UEFI related menu items only appears with CONFIG_AUTOBOOT_MENU_SHOW=y

Changes in v5:
- remove forward declarations
- add const qualifier for menu items
- fix the possible unaligned access for directory info access
- split into three commit 1)add boot option 2) delete boot option 3)change boot 
order
  This commit is 1)add boot option.
- fix file name buffer allocation size, it should be EFI_BOOTMENU_FILE_PATH_MAX 
* sizeof(u16)
- fix wrong size checking for file selection

Chanes in v4:
- UEFI boot option maintenance menu is integrated into bootmenu
- display the simplified volume name(e.g. usb0:1, nvme1:2) for the
  volume selection
- instead of extending lib/efi_loader/efi_bootmgr.c, newly create
  lib/efi_loader/efi_bootmenu_maintenance.c and implement boot
  variable maintenance into it.

Changes in RFC v3:
 not included in v3 series

Changes in RFC v2:
- enable utf8 user input for boot option name
- create lib/efi_loader/efi_console.c::efi_console_get_u16_string() for
  utf8 user input handling
- use u16_strlcat instead of u16_strcat
- remove the EFI_CALLs, and newly create or expose the following
  xxx_int() functions.
efi_locate_handle_buffer_int(), efi_open_volume_int(),
efi_file_open_int(), efi_file_close_int(

[PATCH v15 02/10] eficonfig: add "Edit Boot Option" menu entry

2022-09-02 Thread Masahisa Kojima
This commit adds the menu entry to edit the existing
BOOT variable contents.
User selects the item from the boot option list, then
user can edit the description, file path and optional_data.

Note that automatically generated boot option entry by bootmenu
to support the removable media device is filtered out and user
can not edit the automatically generated entry.

Signed-off-by: Masahisa Kojima 
---
Changes in v15:
- move free entry->data outside the eficonfig_destroy()

Changes in v11:
- remove BootOrder variable dependency
- change the list load option order
   1) in the order of BootOrder
   2) remaing load option that is not included in the BootOrder
- add check for the number of menu entry exceeds max
- truncate the long load option label when user edits
- add EFICONFIG_VOLUME_PATH_MAX to display text converted volume
  device path in case the volume does not exist

Changes in v10:
- update eficonfig_edit_boot_option() argument

Changes in v9:
- add function comment

Changes in v8:
- fix menu header string
- fix function and structure prefix to "eficonfig"

Newly created in v7

 cmd/eficonfig.c  | 281 +--
 include/efi_config.h |   1 +
 2 files changed, 274 insertions(+), 8 deletions(-)

diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
index 30ce55d055..bba83579a3 100644
--- a/cmd/eficonfig.c
+++ b/cmd/eficonfig.c
@@ -80,6 +80,17 @@ struct eficonfig_file_entry_data {
u16 *file_name;
 };
 
+/**
+ * struct eficonfig_boot_selection_data - structure to be used to select the 
boot option entry
+ *
+ * @boot_index:index of the boot option
+ * @selected:  pointer to store the selected index in the BootOrder 
variable
+ */
+struct eficonfig_boot_selection_data {
+   u16 boot_index;
+   int *selected;
+};
+
 /**
  * eficonfig_print_msg() - print message
  *
@@ -1169,34 +1180,58 @@ static efi_status_t prepare_file_selection_entry(struct 
efimenu *efi_menu, char
 {
u32 len;
efi_status_t ret;
-   u16 *file_name, *p;
+   u16 *file_name = NULL, *p;
efi_handle_t handle;
-   char devname[BOOTMENU_DEVICE_NAME_MAX] = {0};
+   char *devname;
+
+   devname = calloc(1, EFICONFIG_VOLUME_PATH_MAX + 1);
+   if (!devname)
+   return EFI_OUT_OF_RESOURCES;
 
/* get the device name only when the user already selected the file 
path */
handle = efi_dp_find_obj(file_info->dp_volume, NULL, NULL);
if (handle) {
-   ret = efi_disk_get_device_name(handle, devname, 
BOOTMENU_DEVICE_NAME_MAX);
+   ret = efi_disk_get_device_name(handle, devname, 
EFICONFIG_VOLUME_PATH_MAX);
if (ret != EFI_SUCCESS)
-   return ret;
+   goto out;
+   }
+
+   /*
+* If the preconfigured volume does not exist in the system, display 
the text
+* converted volume device path instead of U-Boot friendly name(e.g. 
"usb 0:1").
+*/
+   if (!handle && file_info->dp_volume) {
+   u16 *dp_str;
+   char *q = devname;
+
+   dp_str = efi_dp_str(file_info->dp_volume);
+   if (dp_str)
+   utf16_utf8_strncpy(&q, dp_str, 
EFICONFIG_VOLUME_PATH_MAX);
+
+   efi_free_pool(dp_str);
}
 
/* append u'/' to devname, it is just for display purpose. */
if (file_info->current_path[0] != u'\0' && file_info->current_path[0] 
!= u'/')
-   strlcat(devname, "/", BOOTMENU_DEVICE_NAME_MAX);
+   strlcat(devname, "/", EFICONFIG_VOLUME_PATH_MAX + 1);
 
len = strlen(devname);
len += utf16_utf8_strlen(file_info->current_path) + 1;
file_name = calloc(1, len * sizeof(u16));
-   if (!file_name)
-   return ret;
+   if (!file_name) {
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
 
p = file_name;
utf8_utf16_strcpy(&p, devname);
u16_strlcat(file_name, file_info->current_path, len);
ret = create_boot_option_entry(efi_menu, title, file_name,
   eficonfig_select_file_handler, 
file_info);
+out:
+   free(devname);
free(file_name);
+
return ret;
 }
 
@@ -1363,10 +1398,14 @@ static efi_status_t eficonfig_edit_boot_option(u16 
*varname, struct eficonfig_bo
if (ret != EFI_SUCCESS)
goto out;
 
-   if (!lo.label || (lo.label && u16_strlen(lo.label) >= 
EFICONFIG_DESCRIPTION_MAX)) {
+   if (!lo.label) {
ret = EFI_INVALID_PARAMETER;
goto out;
}
+   /* truncate the long label string */
+   if (u16_strlen(lo.label) >= EFICONFIG_DESCRIPTION_MAX)
+   lo.label[EFICONFIG_DESCRIPTION_MAX - 1] = u'\0';
+
u16_strcpy(bo->description, lo.label);
 
/* EFI image file p

[PATCH v15 00/10] enable menu-driven UEFI variable maintenance

2022-09-02 Thread Masahisa Kojima
This series adds the menu-driven UEFI boot variable maintenance
through the "eficonfig" new command.
This series also adds the removable media support in bootmenu.

Source code can be cloned with:
$ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git -b 
kojima/eficonfig_upstream_v15

[Major Changes]
- rebased to v2022.10-rc3
- there is detailed changelog in each commit

Masahisa Kojima (10):
  eficonfig: menu-driven addition of UEFI boot option
  eficonfig: add "Edit Boot Option" menu entry
  menu: add KEY_PLUS, KEY_MINUS and KEY_SPACE handling
  eficonfig: add "Delete Boot Option" menu entry
  bootmenu: add removable media entries
  eficonfig: scan media device in eficonfig startup
  eficonfig: add "Change Boot Order" menu entry
  doc:bootmenu: add description for UEFI boot support
  doc:eficonfig: add documentation for eficonfig command
  test: unit test for eficonfig

 cmd/Kconfig   |7 +
 cmd/Makefile  |1 +
 cmd/bootmenu.c|   22 +-
 cmd/eficonfig.c   | 2462 +
 common/menu.c |9 +
 configs/sandbox_defconfig |1 +
 doc/usage/cmd/bootmenu.rst|   74 +
 doc/usage/cmd/eficonfig.rst   |   71 +
 doc/usage/index.rst   |1 +
 include/efi_config.h  |   98 +
 include/efi_loader.h  |   53 +
 include/menu.h|3 +
 lib/efi_loader/efi_bootmgr.c  |7 +
 lib/efi_loader/efi_boottime.c |   52 +-
 lib/efi_loader/efi_console.c  |   70 +
 lib/efi_loader/efi_disk.c |   50 +
 lib/efi_loader/efi_file.c |   75 +-
 test/py/tests/test_eficonfig/conftest.py  |   40 +
 .../py/tests/test_eficonfig/test_eficonfig.py |  350 +++
 19 files changed, 3393 insertions(+), 53 deletions(-)
 create mode 100644 cmd/eficonfig.c
 create mode 100644 doc/usage/cmd/eficonfig.rst
 create mode 100644 include/efi_config.h
 create mode 100644 test/py/tests/test_eficonfig/conftest.py
 create mode 100644 test/py/tests/test_eficonfig/test_eficonfig.py

-- 
2.17.1



Re: [PATCH 4/4] arm: dts: chameleonv3: Add 270-2 variant

2022-09-02 Thread Paweł Anikiel
On Tue, Aug 30, 2022 at 5:57 PM Simon Glass  wrote:
>
> Hi Paweł,
>
> On Tue, 30 Aug 2022 at 05:51, Paweł Anikiel  wrote:
> >
> > On Tue, Aug 30, 2022 at 5:13 AM Alexandru M Stan  
> > wrote:
> > >
> > > Hey Simon,
> > >
> > > On Mon, Aug 29, 2022 at 7:29 PM Simon Glass  wrote:
> > > >
> > > > Hi Paweł,
> > > >
> > > > On Mon, 29 Aug 2022 at 02:23, Paweł Anikiel  wrote:
> > > > >
> > > > > On Sat, Aug 27, 2022 at 2:22 AM Simon Glass  wrote:
> > > > > >
> > > > > > Hi Paweł,
> > > > > >
> > > > > > On Fri, 26 Aug 2022 at 01:54, Paweł Anikiel  
> > > > > > wrote:
> > > > > > >
> > > > > > > Add devicetree for chameleonv3 with the 270-2I2-D11E variant of 
> > > > > > > the
> > > > > > > Mercury+ AA1 module
> > > > > > >
> > > > > > > Signed-off-by: Paweł Anikiel 
> > > > > > > ---
> > > > > > >  arch/arm/dts/Makefile|  1 +
> > > > > > >  .../socfpga_arria10_chameleonv3_270_2-u-boot.dtsi| 12 
> > > > > > > 
> > > > > > >  arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts   |  5 +
> > > > > > >  3 files changed, 18 insertions(+)
> > > > > > >  create mode 100644 
> > > > > > > arch/arm/dts/socfpga_arria10_chameleonv3_270_2-u-boot.dtsi
> > > > > > >  create mode 100644 
> > > > > > > arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts
> > > > > > >
> > > >
> > > >
> > > > > > > diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> > > > > > > index 7330121dba..36d5d65595 100644
> > > > > > > --- a/arch/arm/dts/Makefile
> > > > > > > +++ b/arch/arm/dts/Makefile
> > > > > > > @@ -425,6 +425,7 @@ dtb-$(CONFIG_ARCH_SOCFPGA) += 
> > > > > > >   \
> > > > > > > socfpga_agilex_socdk.dtb\
> > > > > > > socfpga_arria5_secu1.dtb\
> > > > > > > socfpga_arria5_socdk.dtb\
> > > > > > > +   socfpga_arria10_chameleonv3_270_2.dtb   \
> > > > > > > socfpga_arria10_chameleonv3_270_3.dtb   \
> > > > > > > socfpga_arria10_chameleonv3_480_2.dtb   \
> > > > > > > socfpga_arria10_socdk_sdmmc.dtb \
> > > > > > > diff --git 
> > > > > > > a/arch/arm/dts/socfpga_arria10_chameleonv3_270_2-u-boot.dtsi 
> > > > > > > b/arch/arm/dts/socfpga_arria10_chameleonv3_270_2-u-boot.dtsi
> > > > > > > new file mode 100644
> > > > > > > index 00..05b4485cf3
> > > > > > > --- /dev/null
> > > > > > > +++ b/arch/arm/dts/socfpga_arria10_chameleonv3_270_2-u-boot.dtsi
> > > > > > > @@ -0,0 +1,12 @@
> > > > > > > +// SPDX-License-Identifier: GPL-2.0
> > > > > > > +/*
> > > > > > > + * Copyright 2022 Google LLC
> > > > > > > + */
> > > > > > > +#include "socfpga_arria10_chameleonv3_480_2_handoff.h"
> > > > > > > +#include "socfpga_arria10-handoff.dtsi"
> > > > > > > +#include "socfpga_arria10_handoff_u-boot.dtsi"
> > > > > > > +#include "socfpga_arria10_mercury_aa1-u-boot.dtsi"
> > > > > > > +
> > > > > > > +&fpga_mgr {
> > > > > > > +   altr,bitstream = "fpga-270-2.itb";
> > > > > > > +};
> > > > > > > diff --git a/arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts 
> > > > > > > b/arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts
> > > > > > > new file mode 100644
> > > > > > > index 00..5f40af6eb9
> > > > > > > --- /dev/null
> > > > > > > +++ b/arch/arm/dts/socfpga_arria10_chameleonv3_270_2.dts
> > > > > > > @@ -0,0 +1,5 @@
> > > > > > > +// SPDX-License-Identifier: GPL-2.0
> > > > > > > +/*
> > > > > > > + * Copyright 2022 Google LLC
> > > > > > > + */
> > > > > > > +#include "socfpga_arria10_chameleonv3.dts"
> > > > > >
> > > > > > Can you create a common .dtsi file instead? We should not be 
> > > > > > including
> > > > > > a .dts file into another file.
> > > > > >
> > > > > Do you mean renaming chameleonv3.dts to .dtsi? In Linux it's a .dts,
> > > > > because nothing includes it (no handoff headers are needed). Is it
> > > > > fine to have the names differ across U-Boot and Linux?
> > > >
> > > > Ideally not, but we should not include a .dts file in another one and
> > > > it is probably more important to follow that rule. But why is Linux
> > > > not getting this variant?
> > > >
> > > > Regards,
> > > > Simon
> > >
> > > Linux (at least for the near future) does not care about which variant
> > > it is. The big differences between 270, 480, -2, -3 are mostly about
> > > the number of FPGA logic gates and speed grades. Such things affect
> > > the FPGA bitstream greatly, and might even affect clock presets that
> > > u-boot cares about, but by the time linux loads it doesn't matter
> > > anymore.
> >
> > Perhaps a more detailed explanation:
> >
> > The Main and Peripheral PLLs (as well as some other clocks) are
> > configured by U-Boot. On the other hand, Linux expects them to be
> > configured when it boots, and does not touch them.
> >
> > The clock configuration depends mainly on the speed grade of the Arria
> > 10 SoC (marked by us as -2 and -3), but also on the fpga hardware
> >

[PATCH v7 8/8] rockchip: add u-boot-rockchip-spi.bin image for booting from SPI-NOR flash

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

This new image is similar to u-boot-rockchip.bin except that it's
destined to be flashed on SPI-NOR flashes.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
Reviewed-by: Kever Yang 
Reviewed-by: Simon Glass 
---

v6:
 - added Rb,

v3:
 - added filename property so that idblaoder-spi.img binary is generated
 by binman, as per community request,
 - added new temporary files to the list of files to clean up on `make
 clean`,

 Makefile  |  3 ++-
 arch/arm/dts/rockchip-u-boot.dtsi | 30 ++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 736c4ad182..e70e92c947 100644
--- a/Makefile
+++ b/Makefile
@@ -2197,7 +2197,8 @@ CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h 
\
   idbloader.img flash.bin flash.log defconfig keep-syms-lto.c \
   mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
   itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
-  mkimage.rom.mkimage rom.map simple-bin.map
+  mkimage.rom.mkimage rom.map simple-bin.map simple-bin-spi.map \
+  idbloader-spi.img
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl \
diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
b/arch/arm/dts/rockchip-u-boot.dtsi
index f90a8bf085..584f21eb5b 100644
--- a/arch/arm/dts/rockchip-u-boot.dtsi
+++ b/arch/arm/dts/rockchip-u-boot.dtsi
@@ -39,5 +39,35 @@
offset = ;
};
};
+
+#ifdef CONFIG_ROCKCHIP_SPI_IMAGE
+   simple-bin-spi {
+   filename = "u-boot-rockchip-spi.bin";
+   pad-byte = <0xff>;
+
+   mkimage {
+   filename = "idbloader-spi.img";
+   args = "-n", CONFIG_SYS_SOC, "-T", "rkspi";
+#ifdef CONFIG_TPL
+   multiple-data-files;
+
+   u-boot-tpl {
+   };
+#endif
+   u-boot-spl {
+   };
+   };
+
+#ifdef CONFIG_ARM64
+   blob {
+   filename = "u-boot.itb";
+#else
+   u-boot-img {
+#endif
+   /* Sync with u-boot,spl-payload-offset if present */
+   offset = ;
+   };
+   };
+#endif
 };
 #endif
-- 
2.37.2



[PATCH v7 7/8] rockchip: allow to build SPI images even without HAS_ROM option

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

This prepares for the creation of a u-boot-rockchip-spi.bin image
similar to u-boot-rockchip.bin to the exception it's destined for
SPI-NOR flashes instead of MMC storage medium.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
Reviewed-by: Simon Glass 
Reviewed-by: Kever Yang 
---

v6:
 - added Rb,

 arch/arm/dts/rk3288-u-boot.dtsi | 2 +-
 arch/arm/dts/rk3399-u-boot.dtsi | 2 +-
 arch/arm/mach-rockchip/Kconfig  | 6 ++
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/arm/dts/rk3288-u-boot.dtsi b/arch/arm/dts/rk3288-u-boot.dtsi
index 9eb696b141..e411445ed6 100644
--- a/arch/arm/dts/rk3288-u-boot.dtsi
+++ b/arch/arm/dts/rk3288-u-boot.dtsi
@@ -56,7 +56,7 @@
};
 };
 
-#ifdef CONFIG_ROCKCHIP_SPI_IMAGE
+#if defined(CONFIG_ROCKCHIP_SPI_IMAGE) && defined(CONFIG_HAS_ROM)
 &binman {
rom {
filename = "u-boot.rom";
diff --git a/arch/arm/dts/rk3399-u-boot.dtsi b/arch/arm/dts/rk3399-u-boot.dtsi
index 716b9a433a..3c1a15fe51 100644
--- a/arch/arm/dts/rk3399-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-u-boot.dtsi
@@ -60,7 +60,7 @@
 
 };
 
-#ifdef CONFIG_ROCKCHIP_SPI_IMAGE
+#if defined(CONFIG_ROCKCHIP_SPI_IMAGE) && defined(CONFIG_HAS_ROM)
 &binman {
rom {
filename = "u-boot.rom";
diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index c561a77e6a..b46cea2f91 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -425,12 +425,10 @@ config SPL_MMC
 
 config ROCKCHIP_SPI_IMAGE
bool "Build a SPI image for rockchip"
-   depends on HAS_ROM
help
  Some Rockchip SoCs support booting from SPI flash. Enable this
- option to produce a 4MB SPI-flash image (called u-boot.rom)
- containing U-Boot. The image is built by binman. U-Boot sits near
- the start of the image.
+ option to produce a SPI-flash image containing U-Boot. The image
+ is built by binman. U-Boot sits near the start of the image.
 
 config LNX_KRNL_IMG_TEXT_OFFSET_BASE
default SYS_TEXT_BASE
-- 
2.37.2



[PATCH v7 6/8] rockchip: simplify binman image dependencies addition to INPUTS

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

By factoring SPL check in the first condition, this makes the checks a
bit less convoluted and more readable.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
Reviewed-by: Kever Yang 
Reviewed-by: Simon Glass 
---

v6:
 - added Rb,

v4:
 - fixed wrong place for endif for ARM32 boards,

 Makefile | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 1dee09eb36..736c4ad182 100644
--- a/Makefile
+++ b/Makefile
@@ -1001,19 +1001,14 @@ ifeq ($(CONFIG_MPC85xx)$(CONFIG_OF_SEPARATE),yy)
 INPUTS-y += u-boot-with-dtb.bin
 endif
 
-ifeq ($(CONFIG_ARCH_ROCKCHIP),y)
-# On ARM64 this target is produced by binman so we don't need this dep
+ifeq ($(CONFIG_ARCH_ROCKCHIP)$(CONFIG_SPL),yy)
+# Binman image dependencies
 ifeq ($(CONFIG_ARM64),y)
-ifeq ($(CONFIG_SPL),y)
 INPUTS-y += u-boot.itb
-endif
 else
-ifeq ($(CONFIG_SPL),y)
-# Generate these inputs for binman which will create the output files
 INPUTS-y += u-boot.img
 endif
 endif
-endif
 
 INPUTS-$(CONFIG_X86) += u-boot-x86-start16.bin u-boot-x86-reset16.bin \
$(if $(CONFIG_SPL_X86_16BIT_INIT),spl/u-boot-spl.bin) \
-- 
2.37.2



[PATCH v7 5/8] rockchip: generate u-boot-rockchip.bin with binman for ARM64 boards

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

This allows to build u-boot-rockchip.bin binary with binman for Rockchip
ARM64 boards instead of the legacy Makefile way.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---

v7:
 - Removed reviewed-by,
 - added missing includes for rockchip-u-boot.dtsi so that binman node
 is always present for 64b Rockchip platforms,

v6:
 - added Rb,

v4:
 - added Reviewed-by,

 Makefile   | 26 +-
 arch/arm/Kconfig   |  2 +-
 arch/arm/dts/px30-u-boot.dtsi  |  2 ++
 arch/arm/dts/rk3308-u-boot.dtsi|  2 ++
 arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi |  2 ++
 arch/arm/dts/rk3328-u-boot.dtsi|  2 ++
 arch/arm/dts/rk3368-u-boot.dtsi|  1 +
 arch/arm/dts/rk3568-u-boot.dtsi|  2 ++
 arch/arm/dts/rockchip-u-boot.dtsi  |  5 +
 9 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/Makefile b/Makefile
index dbe1aa254a..1dee09eb36 100644
--- a/Makefile
+++ b/Makefile
@@ -1005,8 +1005,7 @@ ifeq ($(CONFIG_ARCH_ROCKCHIP),y)
 # On ARM64 this target is produced by binman so we don't need this dep
 ifeq ($(CONFIG_ARM64),y)
 ifeq ($(CONFIG_SPL),y)
-# TODO: Get binman to generate this too
-INPUTS-y += u-boot-rockchip.bin
+INPUTS-y += u-boot.itb
 endif
 else
 ifeq ($(CONFIG_SPL),y)
@@ -1498,29 +1497,6 @@ OBJCOPYFLAGS_u-boot-with-spl.bin = -I binary -O binary \
 u-boot-with-spl.bin: $(SPL_IMAGE) $(SPL_PAYLOAD) FORCE
$(call if_changed,pad_cat)
 
-ifeq ($(CONFIG_ARCH_ROCKCHIP),y)
-
-# TPL + SPL
-ifeq ($(CONFIG_SPL)$(CONFIG_TPL),yy)
-MKIMAGEFLAGS_u-boot-tpl-rockchip.bin = -n $(CONFIG_SYS_SOC) -T rksd
-tpl/u-boot-tpl-rockchip.bin: tpl/u-boot-tpl.bin FORCE
-   $(call if_changed,mkimage)
-idbloader.img: tpl/u-boot-tpl-rockchip.bin spl/u-boot-spl.bin FORCE
-   $(call if_changed,cat)
-else
-MKIMAGEFLAGS_idbloader.img = -n $(CONFIG_SYS_SOC) -T rksd
-idbloader.img: spl/u-boot-spl.bin FORCE
-   $(call if_changed,mkimage)
-endif
-
-ifeq ($(CONFIG_ARM64),y)
-OBJCOPYFLAGS_u-boot-rockchip.bin = -I binary -O binary \
-   --pad-to=$(CONFIG_SPL_PAD_TO) --gap-fill=0xff
-u-boot-rockchip.bin: idbloader.img u-boot.itb FORCE
-   $(call if_changed,pad_cat)
-endif # CONFIG_ARM64
-
-endif # CONFIG_ARCH_ROCKCHIP
 
 ifeq ($(CONFIG_ARCH_LPC32XX)$(CONFIG_SPL),yy)
 MKIMAGEFLAGS_lpc32xx-spl.img = -T lpc32xximage -a $(CONFIG_SPL_TEXT_BASE)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0b72e4f650..82cd456f51 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1974,7 +1974,7 @@ config ARCH_STM32MP
 config ARCH_ROCKCHIP
bool "Support Rockchip SoCs"
select BLK
-   select BINMAN if SPL_OPTEE || (SPL && !ARM64)
+   select BINMAN if SPL_OPTEE || SPL
select DM
select DM_GPIO
select DM_I2C
diff --git a/arch/arm/dts/px30-u-boot.dtsi b/arch/arm/dts/px30-u-boot.dtsi
index f102b2aef4..462eaf68f8 100644
--- a/arch/arm/dts/px30-u-boot.dtsi
+++ b/arch/arm/dts/px30-u-boot.dtsi
@@ -3,6 +3,8 @@
  * (C) Copyright 2019 Rockchip Electronics Co., Ltd
  */
 
+#include "rockchip-u-boot.dtsi"
+
 / {
aliases {
mmc0 = &emmc;
diff --git a/arch/arm/dts/rk3308-u-boot.dtsi b/arch/arm/dts/rk3308-u-boot.dtsi
index 4bfad31fba..ab5bfc2ce9 100644
--- a/arch/arm/dts/rk3308-u-boot.dtsi
+++ b/arch/arm/dts/rk3308-u-boot.dtsi
@@ -3,6 +3,8 @@
  *(C) Copyright 2019 Rockchip Electronics Co., Ltd
  */
 
+#include "rockchip-u-boot.dtsi"
+
 / {
aliases {
mmc0 = &emmc;
diff --git a/arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi 
b/arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi
index 95f2652494..16c33735eb 100644
--- a/arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi
+++ b/arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi
@@ -3,6 +3,8 @@
  * Copyright (c) 2020 Theobroma Systems Design und Consulting GmbH
  */
 
+#include "rockchip-u-boot.dtsi"
+
 / {
chosen {
u-boot,spl-boot-order = &sdmmc;
diff --git a/arch/arm/dts/rk3328-u-boot.dtsi b/arch/arm/dts/rk3328-u-boot.dtsi
index 1633558264..d4a7540a92 100644
--- a/arch/arm/dts/rk3328-u-boot.dtsi
+++ b/arch/arm/dts/rk3328-u-boot.dtsi
@@ -3,6 +3,8 @@
  * (C) Copyright 2019 Rockchip Electronics Co., Ltd
  */
 
+#include "rockchip-u-boot.dtsi"
+
 / {
aliases {
mmc0 = &emmc;
diff --git a/arch/arm/dts/rk3368-u-boot.dtsi b/arch/arm/dts/rk3368-u-boot.dtsi
index 2767c2678d..811d59ac34 100644
--- a/arch/arm/dts/rk3368-u-boot.dtsi
+++ b/arch/arm/dts/rk3368-u-boot.dtsi
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include "rockchip-u-boot.dtsi"
 
 / {
dmc: dmc@ff61 {
diff --git a/arch/arm/dts/rk3568-u-boot.dtsi b/arch/arm/dts/rk3568-u-boot.dtsi
index 5a80dda275..fa9b6ae23b 100644
--- a/arch/arm/dts/rk3568-u-boot.dtsi
+++ b/arch/arm/dts/rk3568-u-boot.dtsi
@@ -3,6 +3,8 @@
  * (C) Copyright 2021 Rockchip Electronics Co., Ltd
  */
 
+#include "rockchip-u-boot.dtsi"
+
 / {
aliases {
mmc0 = &sdhci;
diff --git a/arch/arm/dts/rockc

[PATCH v7 4/8] rockchip: generate idbloader.img content for u-boot-rockchip.bin with binman for ARM

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

idbloader.img content - currently created by way of Makefile - can be
created by binman directly.

So let's do that for Rockchip ARM platforms.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
Reviewed-by: Simon Glass 
Reviewed-by: Kever Yang 
---

v6:
 - added Rb,

v4:
 - added Reviewed-by,

v3:
 - moved spl back into mkimage section,
 - added filename property so that the idbloader.img binary is still
 generated,

 Makefile  |  2 +-
 arch/arm/dts/rockchip-u-boot.dtsi | 11 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 5750a9e4b8..dbe1aa254a 100644
--- a/Makefile
+++ b/Makefile
@@ -1011,7 +1011,7 @@ endif
 else
 ifeq ($(CONFIG_SPL),y)
 # Generate these inputs for binman which will create the output files
-INPUTS-y += idbloader.img u-boot.img
+INPUTS-y += u-boot.img
 endif
 endif
 endif
diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
b/arch/arm/dts/rockchip-u-boot.dtsi
index eae3ee715d..ad72ca9700 100644
--- a/arch/arm/dts/rockchip-u-boot.dtsi
+++ b/arch/arm/dts/rockchip-u-boot.dtsi
@@ -17,8 +17,17 @@
filename = "u-boot-rockchip.bin";
pad-byte = <0xff>;
 
-   blob {
+   mkimage {
filename = "idbloader.img";
+   args = "-n", CONFIG_SYS_SOC, "-T", "rksd";
+#ifdef CONFIG_TPL
+   multiple-data-files;
+
+   u-boot-tpl {
+   };
+#endif
+   u-boot-spl {
+   };
};
 
u-boot-img {
-- 
2.37.2



[PATCH v7 3/8] rockchip: remove binman temporary files when cleaning

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

Binman mkimage entry generates temporary files so let's remove them
when calling `make clean`.

Fixes: 9b312e26fc77 ("rockchip: Enable building a SPI ROM image on jerry")
Cc: Quentin Schulz 
Reported-by: Johan Jonker 
Signed-off-by: Quentin Schulz 
Reviewed-by: Simon Glass 
Reviewed-by: Kever Yang 
---

v6:
 - added Rb,

added in v3

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

diff --git a/Makefile b/Makefile
index 541e942ed5..5750a9e4b8 100644
--- a/Makefile
+++ b/Makefile
@@ -2225,7 +2225,8 @@ CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h 
\
   lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* \
   idbloader.img flash.bin flash.log defconfig keep-syms-lto.c \
   mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
-  itb.fit.fit itb.fit.itb itb.map spl.map
+  itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
+  mkimage.rom.mkimage rom.map simple-bin.map
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl \
-- 
2.37.2



[PATCH v7 2/8] binman: allow user-defined filenames for mkimage entry

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

mkimage entry currently creates a file whose name is derived from the
section name containing said entry.

Let's allow the user to define a filename for the mkimage-generated
binary by using the 'filename' DT property.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
Reviewed-by: Simon Glass 
---

v6:
 - put test at the end of the file,
 - renumbered test file,
 - added SPDX license to test file,
 - added Rb,

v5:
 - updated unit test filename,
 - removed _testing section in unit test,
 - removed -n arg in unit test,
 - removed size property in binman node,

v4:
 - added binman test,
 - fixed >80 chars-long line,

 tools/binman/etype/mkimage.py  | 11 ---
 tools/binman/ftest.py  |  7 +++
 tools/binman/test/254_mkimage_filename.dts | 18 ++
 3 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 tools/binman/test/254_mkimage_filename.dts

diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py
index 5f4bc6fa3c..c2288c48ee 100644
--- a/tools/binman/etype/mkimage.py
+++ b/tools/binman/etype/mkimage.py
@@ -21,11 +21,13 @@ class Entry_mkimage(Entry):
 - multiple-data-files: boolean to tell binman to pass all files as
   datafiles to mkimage instead of creating a temporary file the result
   of datafiles concatenation
+- filename: filename of output binary generated by mkimage
 
 The data passed to mkimage via the -d flag is collected from subnodes of 
the
 mkimage node, e.g.::
 
 mkimage {
+filename = "imximage.bin";
 args = "-n test -T imximage";
 
 u-boot-spl {
@@ -38,8 +40,9 @@ class Entry_mkimage(Entry):
 mkimage -d  -n test -T imximage 
 
 The output from mkimage then becomes part of the image produced by
-binman. If you need to put multiple things in the data file, you can use
-a section, or just multiple subnodes like this::
+binman but also is written into `imximage.bin` file. If you need to put
+multiple things in the data file, you can use a section, or just multiple
+subnodes like this::
 
 mkimage {
 args = "-n test -T imximage";
@@ -121,6 +124,7 @@ class Entry_mkimage(Entry):
 self._multiple_data_files = fdt_util.GetBool(self._node, 
'multiple-data-files')
 self._mkimage_entries = OrderedDict()
 self._imagename = None
+self._filename = fdt_util.GetString(self._node, 'filename')
 self.align_default = None
 
 def ReadNode(self):
@@ -164,7 +168,8 @@ class Entry_mkimage(Entry):
 [self._imagename], 'mkimage-n', 1024)
 if image_data is None:
 return False
-output_fname = tools.get_output_filename('mkimage-out.%s' % uniq)
+outfile = self._filename if self._filename else 'mkimage-out.%s' % uniq
+output_fname = tools.get_output_filename(outfile)
 
 args = ['-d', input_fname]
 if self._data_to_imagename:
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index e0850b760b..3ced14b7e9 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -5921,6 +5921,13 @@ fdt fdtmapExtract the devicetree 
blob from the fdtmap
 self.assertIn('Could not complete processing of contents',
   str(exc.exception))
 
+def testMkimageFilename(self):
+"""Test using mkimage to build a binary with a filename"""
+retcode = self._DoTestFile('254_mkimage_filename.dts')
+self.assertEqual(0, retcode)
+fname = tools.get_output_filename('mkimage-test.bin')
+self.assertTrue(os.path.exists(fname))
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/tools/binman/test/254_mkimage_filename.dts 
b/tools/binman/test/254_mkimage_filename.dts
new file mode 100644
index 00..4483790ae8
--- /dev/null
+++ b/tools/binman/test/254_mkimage_filename.dts
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   binman {
+   mkimage {
+   filename = "mkimage-test.bin";
+   args = "-T script";
+
+   u-boot-spl {
+   };
+   };
+   };
+};
-- 
2.37.2



[PATCH v7 1/8] binman: add support for skipping file concatenation for mkimage

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

Some image types handled by mkimage require the datafiles to be passed
independently (-d data1:data2) for specific handling of each. A
concatenation of datafiles prior to passing them to mkimage wouldn't
work.

That is the case for rkspi for example which requires page alignment
and only writing 2KB every 4KB.

This adds the ability to tell binman to pass the datafiles without
prior concatenation to mkimage, by adding the multiple-data-files
boolean property to the mkimage node.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
Reviewed-by: Simon Glass 
---

v6:
 - added Rb,
 - put tests at the end of the file,
 - added test for multiple data files passed to mkimage with one data
 file having no content (thanks Simon for the suggestion),
 - added SPDX license to test files,
 - renumbered test files,

v5:
 - changed to use full path from input dir with tools.get_input_filename
 to make it possible to run the unit tests,
 - added unit test,

 tools/binman/entries.rst  | 22 ++
 tools/binman/etype/mkimage.py | 41 +--
 tools/binman/ftest.py | 23 +++
 tools/binman/test/252_mkimage_mult_data.dts   | 21 ++
 .../test/253_mkimage_mult_no_content.dts  | 22 ++
 5 files changed, 125 insertions(+), 4 deletions(-)
 create mode 100644 tools/binman/test/252_mkimage_mult_data.dts
 create mode 100644 tools/binman/test/253_mkimage_mult_no_content.dts

diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index b3613d7cbd..18bd328c5c 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -1175,6 +1175,9 @@ Properties / Entry arguments:
 - args: Arguments to pass
 - data-to-imagename: Indicates that the -d data should be passed in as
   the image name also (-n)
+- multiple-data-files: boolean to tell binman to pass all files as
+  datafiles to mkimage instead of creating a temporary file the result
+  of datafiles concatenation
 
 The data passed to mkimage via the -d flag is collected from subnodes of the
 mkimage node, e.g.::
@@ -1205,6 +1208,25 @@ a section, or just multiple subnodes like this::
 };
 };
 
+To pass all datafiles untouched to mkimage::
+
+mkimage {
+args = "-n rk3399 -T rkspi";
+multiple-data-files;
+
+u-boot-tpl {
+};
+
+u-boot-spl {
+};
+};
+
+This calls mkimage to create a Rockchip RK3399-specific first stage
+bootloader, made of TPL+SPL. Since this first stage bootloader requires to
+align the TPL and SPL but also some weird hacks that is handled by mkimage
+directly, binman is told to not perform the concatenation of datafiles prior
+to passing the data to mkimage.
+
 To use CONFIG options in the arguments, use a string list instead, as in
 this example which also produces four arguments::
 
diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py
index ddbd9cec65..5f4bc6fa3c 100644
--- a/tools/binman/etype/mkimage.py
+++ b/tools/binman/etype/mkimage.py
@@ -18,6 +18,9 @@ class Entry_mkimage(Entry):
 - args: Arguments to pass
 - data-to-imagename: Indicates that the -d data should be passed in as
   the image name also (-n)
+- multiple-data-files: boolean to tell binman to pass all files as
+  datafiles to mkimage instead of creating a temporary file the result
+  of datafiles concatenation
 
 The data passed to mkimage via the -d flag is collected from subnodes of 
the
 mkimage node, e.g.::
@@ -51,6 +54,25 @@ class Entry_mkimage(Entry):
 Note that binman places the contents (here SPL and TPL) into a single file
 and passes that to mkimage using the -d option.
 
+   To pass all datafiles untouched to mkimage::
+
+   mkimage {
+   args = "-n rk3399 -T rkspi";
+   multiple-data-files;
+
+   u-boot-tpl {
+   };
+
+   u-boot-spl {
+   };
+   };
+
+   This calls mkimage to create a Rockchip RK3399-specific first stage
+   bootloader, made of TPL+SPL. Since this first stage bootloader requires 
to
+   align the TPL and SPL but also some weird hacks that is handled by 
mkimage
+   directly, binman is told to not perform the concatenation of datafiles 
prior
+   to passing the data to mkimage.
+
 To use CONFIG options in the arguments, use a string list instead, as in
 this example which also produces four arguments::
 
@@ -96,6 +118,7 @@ class Entry_mkimage(Entry):
 """
 def __init__(self, section, etype, node):
 super().__init__(section, etype, node)
+self._multiple_data_files = fdt_util.GetBool(self._node, 
'multiple-data-files')
 self._mkimage_entries = OrderedDict()
 self._imagename = None
 self.align_default = None
@@ -122,10 +145,20 @@ class Entry_mkimage

[PATCH v7 0/8] migrate u-boot-rockchip.bin to binman and generate an image for SPI

2022-09-02 Thread Quentin Schulz
From: Quentin Schulz 

This migrates the generation of u-boot-rockchip.bin from Makefile to binman
completely.

This also adds support for generating the same kind of image than
u-boot-rockchip.bin but for SPI flashes (specifically, a different image
type generated by mkimage is necessary, in addition to a different
offset in the storage medium).

This has been tested on Puma RK3399 with patch series from 
https://lore.kernel.org/u-boot/20220722160655.3904213-1-foss+ub...@0leil.net/#b 
(plus 
https://lore.kernel.org/u-boot/20220722113505.3875669-4-foss+ub...@0leil.net/).

Cheers,
Quentin

v7:
 - added missing rockchip-u-boot.dtsi for binman images to fix builds,
All Rockchip boards build tested with:
 #!/bin/sh
 
 for conf in $(ag -Rl ARCH_ROCKCHIP configs); do
git clean -ffdx > /dev/null
cp ../bl31.elf .
echo -n $conf=
make $(basename "$conf") > /dev/null
if grep -q -E "^CONFIG_ARM64=y" .config; then
CROSS_COMPILE="aarch64-linux-gnu-"
else
CROSS_COMPILE="arm-linux-gnu-"
fi
make CROSS_COMPILE="ccache $CROSS_COMPILE" -j$(nproc) > /dev/null 2>&1
echo $?
 done

v6:
 - rebased on u-boot-dm/master,
 - added test for mkimage multiple data files with one data file having
 no content,
 - added SPDX license for unit tests,
 - re-ordered tests and renamed test files accordingly,
 - added Rb,

v5:
 - rebased on latest master,
 - added binman test for mkimage multiple data files,
 - fixed mkimage data files to pass full paths to input files to
 mkimage,

v4:
 - added binman test for mkimage filename,
 - fixed >80 chars line in patch 2/8 binman: allow user-defined filenames for
 mkimage entry,
 - fixed wrong location for endif in patch 6/8 simplify binman image
 dependencies addition to INPUTS,


v3:
 - removed
 https://lore.kernel.org/u-boot/20220722113505.3875669-4-foss+ub...@0leil.net/,
 it'll be added later on in a separate patch series,
 - added "binman: allow user-defined filenames for mkimage entry,"
 - kept idbloader.img binary creation even with binman as requested by
 community,
 - generate idbloader-spi.img binary with binman,
 - added "rockchip: remove binman temporary files when cleaning"

v2:
 - removed patch 4/8 rockchip: pad u-boot-rockchip.bin correctly because
 it would break partitions table,
 - rebased on top of master, changes to patch 3/7 rockchip: remove
 unneeded CONFIG_SPL_PAD_TO compared to the RFC 3/8 rockchip: remove
 unneeded CONFIG_SPL_PAD_TO,

Quentin Schulz (8):
  binman: add support for skipping file concatenation for mkimage
  binman: allow user-defined filenames for mkimage entry
  rockchip: remove binman temporary files when cleaning
  rockchip: generate idbloader.img content for u-boot-rockchip.bin with
binman for ARM
  rockchip: generate u-boot-rockchip.bin with binman for ARM64 boards
  rockchip: simplify binman image dependencies addition to INPUTS
  rockchip: allow to build SPI images even without HAS_ROM option
  rockchip: add u-boot-rockchip-spi.bin image for booting from SPI-NOR
flash

 Makefile  | 41 +++
 arch/arm/Kconfig  |  2 +-
 arch/arm/dts/px30-u-boot.dtsi |  2 +
 arch/arm/dts/rk3288-u-boot.dtsi   |  2 +-
 arch/arm/dts/rk3308-u-boot.dtsi   |  2 +
 arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi|  2 +
 arch/arm/dts/rk3328-u-boot.dtsi   |  2 +
 arch/arm/dts/rk3368-u-boot.dtsi   |  1 +
 arch/arm/dts/rk3399-u-boot.dtsi   |  2 +-
 arch/arm/dts/rk3568-u-boot.dtsi   |  2 +
 arch/arm/dts/rockchip-u-boot.dtsi | 46 +++-
 arch/arm/mach-rockchip/Kconfig|  6 +--
 tools/binman/entries.rst  | 22 
 tools/binman/etype/mkimage.py | 52 ---
 tools/binman/ftest.py | 30 +++
 tools/binman/test/252_mkimage_mult_data.dts   | 21 
 .../test/253_mkimage_mult_no_content.dts  | 22 
 tools/binman/test/254_mkimage_filename.dts| 18 +++
 18 files changed, 226 insertions(+), 49 deletions(-)
 create mode 100644 tools/binman/test/252_mkimage_mult_data.dts
 create mode 100644 tools/binman/test/253_mkimage_mult_no_content.dts
 create mode 100644 tools/binman/test/254_mkimage_filename.dts

-- 
2.37.2



Re: [PATCH v6 3/3] ARM: imx6: dh-imx6: Enable d-cache early in SPL

2022-09-02 Thread Tom Rini
On Wed, Aug 17, 2022 at 03:07:14PM +0200, Philip Oberfichtner wrote:

> From: Marek Vasut 
> 
> Enable d-cache early in SPL right after DRAM is started up.
> This reduces U-Boot proper load time by 650ms when loaded
> from SPI NOR.
> 
> Signed-off-by: Marek Vasut 
> Signed-off-by: Philip Oberfichtner 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v6 2/3] ARM: cache: Allow SPL to build cache-pl310.c

2022-09-02 Thread Tom Rini
On Wed, Aug 17, 2022 at 03:07:13PM +0200, Philip Oberfichtner wrote:

> Introduce the new Kconfig symbol CONFIG_SPL_SYS_L2_PL310 to allow the
> SPL to build cache-pl310.c.
> 
> Before this commit, the SPL could enable the PL310 L2 cache [1], but the
> cache maintenance functions from cache-pl310.c were only useable for
> non-SPL builds.
> 
> After enabling the cache one must be able to flush it, too. Thus this
> commit allows cache-pl310.c to be included in the SPL build.
> 
> [1] See for example arch/arm/mach-imx/cache.c: v7_outer_cache_enable()
> 
> Signed-off-by: Philip Oberfichtner 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v6 1/3] Convert CONFIG_SYS_L2_PL310 to Kconfig

2022-09-02 Thread Tom Rini
On Wed, Aug 17, 2022 at 03:07:12PM +0200, Philip Oberfichtner wrote:

> This converts CONFIG_SYS_L2_PL310 to Kconfig.
> 
> For omap2 and mvebu the 'select SYS_L2_PL310' locations were
> determined using ./tools/moveconfig -i CONFIG_SYS_L2_PL310.
> 
> For mx6 I manually chose ARCH_MX6 as 'select' location. The
> correctness has been verified using
> 
>   $ ./tools/moveconfig.py -f ARCH_MX6 ~SYS_L2_PL310 ~SYS_L2CACHE_OFF
>   0 matches
> 
> That means whenever an ARCH_MX6 board had SYS_L2_PL310 disabled, this
> was correctly reflected in SYS_L2CACHE_OFF. Thus it's safe to insert
> the 'select' statement under ARCH_MX6.
> 
> Signed-off-by: Philip Oberfichtner 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] Remove CONFIG_SYS_I2C_EEPROM_PAGE_WRITE_BITS et al

2022-09-02 Thread Tom Rini
On Wed, Aug 10, 2022 at 10:29:28AM -0400, Tom Rini wrote:

> This removes the following symbols:
>CONFIG_SYS_I2C_EEPROM_PAGE_WRITE_BITS
>CONFIG_SYS_I2C_EEPROM_PAGE_WRITE_DELAY_MS
>CONFIG_SYS_I2C_LDI_ADDR
>CONFIG_SYS_I2C_DVI_ADDR
>CONFIG_SYS_I2C_DVI_BUS_NUM
> 
> They are unused by any code in tree at this time.
> 
> Signed-off-by: Tom Rini 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] Convert CONFIG_SYS_I2C_EEPROM_CCID et al to Kconfig

2022-09-02 Thread Tom Rini
On Wed, Aug 10, 2022 at 10:29:27AM -0400, Tom Rini wrote:

> This converts the following to Kconfig:
>CONFIG_SYS_I2C_EEPROM_CCID
>CONFIG_SYS_I2C_EEPROM_NXID
>CONFIG_SYS_EEPROM_BUS_NUM
> 
> Signed-off-by: Tom Rini 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v1 3/6] cyclic: Use schedule() instead of WATCHDOG_RESET()

2022-09-02 Thread Stefan Roese
Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v1:
- Add Simon's SoB tag

 arch/arm/mach-at91/phy.c  |  2 +-
 arch/arm/mach-imx/i2c-mxv7.c  |  2 +-
 arch/arm/mach-socfpga/spl_a10.c   |  8 ++---
 .../cmd_stm32prog/stm32prog_serial.c  |  6 ++--
 arch/m68k/lib/time.c  |  2 +-
 arch/powerpc/cpu/mpc8xx/cpu_init.c|  2 +-
 arch/powerpc/lib/bootm.c  |  6 ++--
 arch/powerpc/lib/cache.c  |  2 +-
 arch/powerpc/lib/interrupts.c |  2 +-
 board/astro/mcf5373l/fpga.c   |  4 +--
 board/dhelectronics/dh_stm32mp1/board.c   |  2 +-
 board/liebherr/display5/spl.c |  2 +-
 board/nokia/rx51/rx51.c   |  2 +-
 board/st/stm32mp1/stm32mp1.c  |  2 +-
 boot/bootretry.c  |  2 +-
 boot/image-board.c|  2 +-
 cmd/fastboot.c|  2 +-
 cmd/mem.c | 16 -
 cmd/usb_mass_storage.c|  2 +-
 cmd/ximg.c|  2 +-
 common/board_f.c  |  4 +--
 common/board_r.c  |  2 +-
 common/cli_readline.c |  4 +--
 common/console.c  |  2 +-
 common/dfu.c  |  2 +-
 common/lcd.c  | 10 +++---
 common/menu.c |  6 ++--
 common/usb_kbd.c  |  2 +-
 common/xyzModem.c |  2 +-
 drivers/block/ide.c   |  8 ++---
 drivers/crypto/aspeed/aspeed_hace.c   |  2 +-
 drivers/crypto/hash/hash_sw.c |  2 +-
 drivers/ddr/altera/sdram_arria10.c|  4 +--
 drivers/ddr/altera/sdram_n5x.c|  4 +--
 drivers/ddr/altera/sdram_soc64.c  |  2 +-
 drivers/fpga/intel_sdm_mb.c   |  8 ++---
 drivers/fpga/socfpga_arria10.c|  8 ++---
 drivers/i2c/mxc_i2c.c |  4 +--
 drivers/mmc/octeontx_hsmmc.c  | 12 +++
 drivers/mmc/sh_mmcif.c|  6 ++--
 drivers/mmc/stm32_sdmmc2.c|  2 +-
 drivers/mtd/cfi_flash.c   |  4 +--
 drivers/mtd/nand/core.c   |  2 +-
 drivers/mtd/nand/raw/atmel_nand.c |  6 ++--
 drivers/mtd/nand/raw/nand_base.c  | 10 +++---
 drivers/mtd/nand/raw/nand_util.c  |  6 ++--
 drivers/mtd/nand/spi/core.c   |  4 +--
 drivers/mtd/onenand/onenand_base.c|  4 +--
 drivers/mtd/spi/spi-nor-core.c|  4 +--
 drivers/net/octeontx2/nix.c   |  2 +-
 drivers/net/octeontx2/nix_af.c| 32 -
 drivers/ram/stm32mp1/stm32mp1_tests.c |  2 +-
 drivers/serial/atmel_usart.c  |  2 +-
 drivers/serial/ns16550.c  |  6 ++--
 drivers/serial/serial-uclass.c|  2 +-
 drivers/serial/serial_bcm283x_mu.c|  2 +-
 drivers/serial/serial_lpuart.c|  8 ++---
 drivers/serial/serial_mpc8xx.c|  4 +--
 drivers/serial/serial_mt7620.c|  2 +-
 drivers/serial/serial_mtk.c   |  4 +--
 drivers/serial/serial_mxc.c   |  6 ++--
 drivers/serial/serial_octeon_bootcmd.c|  2 +-
 drivers/serial/serial_octeon_pcie_console.c   |  4 +--
 drivers/serial/serial_pl01x.c |  8 ++---
 drivers/serial/serial_sifive.c|  2 +-
 drivers/serial/serial_zynq.c  |  2 +-
 drivers/spi/mtk_snfi_spi.c|  2 +-
 drivers/spi/octeon_spi.c  |  2 +-
 drivers/spi/stm32_qspi.c  |  2 +-
 drivers/timer/mpc83xx_timer.c |  4 +--
 drivers/usb/eth/lan7x.h   |  4 +--
 drivers/usb/gadget/f_acm.c|  4 +--
 drivers/usb/gadget/f_sdp.c|  4 +--
 drivers/usb/host/ehci-hcd.c   |  2 +-
 drivers/usb/musb-new/musb_uboot.c |  2 +-
 drivers/video/video_bmp.c |  4 +--
 env/common.c  |  2 +-
 fs/cramfs/uncompress.c|  3 +-
 fs/jffs2/jffs2_1pass.c|  2 +-
 include/linux/compat.h|  2 +-
 include/wait_bit.h|  2 +-
 include/watchdog.h|  8 -
 lib/bzip2/bzlib.c |  2 +-
 lib/bzip2/bzlib_decompress.c  |  8 ++---
 lib/crc32.c   |  2 +-

[PATCH v1 6/6] watchdog: Further cleanup

2022-09-02 Thread Stefan Roese
Remove some now unused macros and #ifdef's.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v1:
- Add Simon's SoB tag

 include/watchdog.h | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/include/watchdog.h b/include/watchdog.h
index 91506d3327a8..ac5f11e376fa 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -10,7 +10,6 @@
 #ifndef _WATCHDOG_H_
 #define _WATCHDOG_H_
 
-#if !defined(__ASSEMBLY__)
 #include 
 
 /*
@@ -20,7 +19,6 @@
  * and the legacy arch//board.c code.
  */
 int init_func_watchdog_reset(void);
-#endif
 
 #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
 #define INIT_FUNC_WATCHDOG_INITinit_func_watchdog_init,
@@ -38,11 +36,11 @@ int init_func_watchdog_reset(void);
  * Prototypes from $(CPU)/cpu.c.
  */
 
-#if (defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)) && 
!defined(__ASSEMBLY__)
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
void hw_watchdog_init(void);
 #endif
 
-#if defined(CONFIG_MPC85xx) && !defined(__ASSEMBLY__)
+#if defined(CONFIG_MPC85xx)
void init_85xx_watchdog(void);
 #endif
 #endif /* _WATCHDOG_H_ */
-- 
2.37.3



[PATCH v1 4/6] watchdog: Get rid of ASSEMBLY hacks

2022-09-02 Thread Stefan Roese
Only one occurance of WATCHDOG_RESET is left in one assembler file.
This patch changes this occurance to a direct call to watchdog_reset
and then removes all the ASSEMBLY ifdef'ery in watchdog.h, as it's not
needed any more to clean this mess a bit up.

Signed-off-by: Stefan Roese 
---
v1:
- No change

 arch/powerpc/lib/ticks.S |  5 ++--
 include/watchdog.h   | 50 +---
 2 files changed, 19 insertions(+), 36 deletions(-)

diff --git a/arch/powerpc/lib/ticks.S b/arch/powerpc/lib/ticks.S
index c487f938fa8d..8647d77cc9ad 100644
--- a/arch/powerpc/lib/ticks.S
+++ b/arch/powerpc/lib/ticks.S
@@ -9,7 +9,6 @@
 #include 
 #include 
 #include 
-#include 
 
 /*
  * unsigned long long get_ticks(void);
@@ -42,7 +41,9 @@ wait_ticks:
addcr14, r4, r14/* Compute end time lower */
addze   r15, r3 /* and end time upper */
 
-   WATCHDOG_RESET  /* Trigger watchdog, if needed */
+#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
+   bl  schedule/* Trigger watchdog, if needed */
+#endif
 1: bl  get_ticks   /* Get current time */
subfc   r4, r4, r14 /* Subtract current time from end time */
subfe.  r3, r3, r15
diff --git a/include/watchdog.h b/include/watchdog.h
index 7a09346a0959..1365b154a295 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -38,54 +38,36 @@ int init_func_watchdog_reset(void);
  * Hardware watchdog
  */
 #ifdef CONFIG_HW_WATCHDOG
-   #if defined(__ASSEMBLY__)
-   #define WATCHDOG_RESET bl hw_watchdog_reset
-   #else
-   extern void hw_watchdog_reset(void);
+   extern void hw_watchdog_reset(void);
 
-   #define WATCHDOG_RESET hw_watchdog_reset
-   #endif /* __ASSEMBLY__ */
+   #define WATCHDOG_RESET hw_watchdog_reset
 #else
/*
 * Maybe a software watchdog?
 */
#if defined(CONFIG_WATCHDOG)
-   #if defined(__ASSEMBLY__)
-   /* Don't require the watchdog to be enabled in SPL */
-   #if defined(CONFIG_SPL_BUILD) &&\
-   !defined(CONFIG_SPL_WATCHDOG)
-   #define WATCHDOG_RESET /*XXX 
DO_NOT_DEL_THIS_COMMENT*/
-   #else
-   #define WATCHDOG_RESET bl watchdog_reset
-   #endif
+   /* Don't require the watchdog to be enabled in SPL */
+   #if defined(CONFIG_SPL_BUILD) &&\
+   !defined(CONFIG_SPL_WATCHDOG)
+   #define WATCHDOG_RESET() { \
+   cyclic_run(); \
+   }
#else
-   /* Don't require the watchdog to be enabled in SPL */
-   #if defined(CONFIG_SPL_BUILD) &&\
-   !defined(CONFIG_SPL_WATCHDOG)
-   #define WATCHDOG_RESET() { \
-   cyclic_run(); \
-   }
-   #else
-   extern void watchdog_reset(void);
+   extern void watchdog_reset(void);
 
-   #define WATCHDOG_RESET() { \
-   watchdog_reset(); \
-   cyclic_run(); \
-   }
-   #endif
+   #define WATCHDOG_RESET() { \
+   watchdog_reset(); \
+   cyclic_run(); \
+   }
#endif
#else
/*
 * No hardware or software watchdog.
 */
-   #if defined(__ASSEMBLY__)
-   #define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/
-   #else
-   #define WATCHDOG_RESET() { \
-   cyclic_run(); \
+   #define WATCHDOG_RESET() { \
+   cyclic_run(); \
}
-   #endif /* __ASSEMBLY__ */
-   #endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */
+   #endif /* CONFIG_WATCHDOG */
 #endif /* CONFIG_HW_WATCHDOG */
 
 /*
-- 
2.37.3



[PATCH v1 5/6] watchdog: Remove WATCHDOG_RESET macro

2022-09-02 Thread Stefan Roese
Now that we've globally replaced all WATCHDOG_RESET occurances, let's
remove the ugly macro itself in the header.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v1:
- Add Simon's SoB tag

 include/watchdog.h | 36 
 1 file changed, 36 deletions(-)

diff --git a/include/watchdog.h b/include/watchdog.h
index 1365b154a295..91506d3327a8 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -34,42 +34,6 @@ int init_func_watchdog_reset(void);
 #  error "Configuration error: CONFIG_HW_WATCHDOG and CONFIG_WATCHDOG can't be 
used together."
 #endif
 
-/*
- * Hardware watchdog
- */
-#ifdef CONFIG_HW_WATCHDOG
-   extern void hw_watchdog_reset(void);
-
-   #define WATCHDOG_RESET hw_watchdog_reset
-#else
-   /*
-* Maybe a software watchdog?
-*/
-   #if defined(CONFIG_WATCHDOG)
-   /* Don't require the watchdog to be enabled in SPL */
-   #if defined(CONFIG_SPL_BUILD) &&\
-   !defined(CONFIG_SPL_WATCHDOG)
-   #define WATCHDOG_RESET() { \
-   cyclic_run(); \
-   }
-   #else
-   extern void watchdog_reset(void);
-
-   #define WATCHDOG_RESET() { \
-   watchdog_reset(); \
-   cyclic_run(); \
-   }
-   #endif
-   #else
-   /*
-* No hardware or software watchdog.
-*/
-   #define WATCHDOG_RESET() { \
-   cyclic_run(); \
-   }
-   #endif /* CONFIG_WATCHDOG */
-#endif /* CONFIG_HW_WATCHDOG */
-
 /*
  * Prototypes from $(CPU)/cpu.c.
  */
-- 
2.37.3



[PATCH v1 2/6] cyclic: Introduce schedule() function

2022-09-02 Thread Stefan Roese
This patch introduces a schedule() function, which shall be used instead
of the old WATCHDOG_RESET. Follow-up patches will make sure, that this
new function is used.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v1:
- Add Simon's SoB tag
- Add more comments in the header to fully document the prototypes

 common/cyclic.c  | 11 +++
 include/cyclic.h | 12 
 2 files changed, 23 insertions(+)

diff --git a/common/cyclic.c b/common/cyclic.c
index f0bfd18c9242..0b07ede8d35e 100644
--- a/common/cyclic.c
+++ b/common/cyclic.c
@@ -18,6 +18,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+void hw_watchdog_reset(void);
+
 struct list_head *cyclic_get_list()
 {
return &gd->cyclic->cyclic_list;
@@ -96,6 +98,15 @@ void cyclic_run(void)
gd->cyclic->cyclic_running = false;
 }
 
+void schedule(void)
+{
+   /* The HW watchdog is not integrated into the cyclic IF (yet) */
+   if (IS_ENABLED(CONFIG_HW_WATCHDOG))
+   hw_watchdog_reset();
+
+   cyclic_run();
+}
+
 int cyclic_uninit(void)
 {
struct cyclic_info *cyclic, *tmp;
diff --git a/include/cyclic.h b/include/cyclic.h
index 23902234cc87..760163643345 100644
--- a/include/cyclic.h
+++ b/include/cyclic.h
@@ -106,6 +106,14 @@ struct list_head *cyclic_get_list(void);
  * needs to be executed, then call into these registered functions.
  */
 void cyclic_run(void);
+
+/**
+ * schedule() - Schedule all potentially waiting tasks
+ *
+ * Basically a wrapper for cyclic_run(), pontentially enhanced by some
+ * other parts, that need to get handled periodically.
+ */
+void schedule(void);
 #else
 static inline struct cyclic_info *cyclic_register(cyclic_func_t func,
  uint64_t delay_us,
@@ -124,6 +132,10 @@ static inline void cyclic_run(void)
 {
 }
 
+static inline void schedule(void)
+{
+}
+
 static inline int cyclic_init(void)
 {
return 0;
-- 
2.37.3



[PATCH v1 0/6] Migrate watchdog reset to cyclic infrastructure

2022-09-02 Thread Stefan Roese
This patchset migrates the watchdog triggering (WATCHDOG_RESET calls)
to the newly introduced cyclic execution framework. For this, the
watchdog driver now registers a cyclic execution function for each
WDT device that needs to get serviced. Additionally the cyclic IF is
a bit extended to also support the CONFIG_HW_WATCHDOG users. It might
make sense to deprecate this HW_WATCHDOG usage at some point.

Please note that this migration work is based on the cyclic execution
infrastructure, which I posted in the last few weeks. So these cyclic
patches need to be applied for this migration to work.

Some further cleanup and improvements are possible after this patch.
E.g. Heinrich mentioned that the WATCHDOG_RESET call locations need to
get improved / changed in some places.

I've pushed a working branch here for anyone who wants to do some
testing with this patchset:

https://source.denx.de/u-boot/custodians/u-boot-watchdog/-/commits/cyclic-v5-watchdog-migration-to-cyclic-v1-2022-09-02

Here the log from octeon_ebb7304 compiled on this branch:

U-Boot 2022.10-rc3-00063-g1050cb3e6d8e (Aug 29 2022 - 07:57:07 +0200)

SoC:   Octeon CN73xx (16 cores)
Model: cavium,ebb7304
DRAM:  256 MiB (16 GiB total)
Core:  31 devices, 24 uclasses, devicetree: separate
WDT:   Started interrupt-controller@10100 with servicing all 1000ms 
(60s timeout)
Flash: 8 MiB
MMC:   octeontx-mmc0: 0, octeontx-mmc1: 1
Loading Environment from Flash... OK
QLM 0: PCIe gen3 root complex, x4 lanes
QLM 2: SGMII
QLM 3: XLAUI
QLM 5: SGMII
Net:   eth0: ethernet-mac-nexus@11800e000
=> cyclic list
function: interrupt-controller@10100, cpu-time: 4 us, frequency: 1.11 
times/s
=> wdt list
interrupt-controller@10100 (wdt_octeontx)

Any comments and suggestions are welcome.

Thanks,
Stefan

Stefan Roese (6):
  watchdog: Integrate watchdog triggering into the cyclic framework
  cyclic: Introduce schedule() function
  cyclic: Use schedule() instead of WATCHDOG_RESET()
  watchdog: Get rid of ASSEMBLY hacks
  watchdog: Remove WATCHDOG_RESET macro
  watchdog: Further cleanup

 arch/arm/mach-at91/phy.c  |  2 +-
 arch/arm/mach-imx/i2c-mxv7.c  |  2 +-
 arch/arm/mach-socfpga/spl_a10.c   |  8 +-
 .../cmd_stm32prog/stm32prog_serial.c  |  6 +-
 arch/m68k/lib/time.c  |  2 +-
 arch/powerpc/cpu/mpc8xx/cpu_init.c|  2 +-
 arch/powerpc/lib/bootm.c  |  6 +-
 arch/powerpc/lib/cache.c  |  2 +-
 arch/powerpc/lib/interrupts.c |  2 +-
 arch/powerpc/lib/ticks.S  |  5 +-
 board/astro/mcf5373l/fpga.c   |  4 +-
 board/dhelectronics/dh_stm32mp1/board.c   |  2 +-
 board/liebherr/display5/spl.c |  2 +-
 board/nokia/rx51/rx51.c   |  2 +-
 board/st/stm32mp1/stm32mp1.c  |  2 +-
 boot/bootretry.c  |  2 +-
 boot/image-board.c|  2 +-
 cmd/fastboot.c|  2 +-
 cmd/mem.c | 16 ++--
 cmd/usb_mass_storage.c|  2 +-
 cmd/ximg.c|  2 +-
 common/board_f.c  |  4 +-
 common/board_r.c  |  2 +-
 common/cli_readline.c |  4 +-
 common/console.c  |  2 +-
 common/cyclic.c   | 11 +++
 common/dfu.c  |  2 +-
 common/lcd.c  | 10 +--
 common/menu.c |  6 +-
 common/usb_kbd.c  |  2 +-
 common/xyzModem.c |  2 +-
 drivers/block/ide.c   |  8 +-
 drivers/crypto/aspeed/aspeed_hace.c   |  2 +-
 drivers/crypto/hash/hash_sw.c |  2 +-
 drivers/ddr/altera/sdram_arria10.c|  4 +-
 drivers/ddr/altera/sdram_n5x.c|  4 +-
 drivers/ddr/altera/sdram_soc64.c  |  2 +-
 drivers/fpga/intel_sdm_mb.c   |  8 +-
 drivers/fpga/socfpga_arria10.c|  8 +-
 drivers/i2c/mxc_i2c.c |  4 +-
 drivers/mmc/octeontx_hsmmc.c  | 12 +--
 drivers/mmc/sh_mmcif.c|  6 +-
 drivers/mmc/stm32_sdmmc2.c|  2 +-
 drivers/mtd/cfi_flash.c   |  4 +-
 drivers/mtd/nand/core.c   |  2 +-
 drivers/mtd/nand/raw/atmel_nand.c |  6 +-
 drivers/mtd/nand/raw/nand_base.c  | 10 +--
 drivers/mtd/nand/raw/nand_util.c  |  6 +-
 drivers/mtd/nand/spi/core.c   |  4 +-
 drivers/mtd/onenand/onenand_base.c|  4 +-
 drivers/mtd/spi/spi-nor-core.c|  4 +-
 drivers/net/octeontx2/nix.c   |  2 +-
 drivers/net/octeontx2/nix_af.c| 32

[PATCH v1 1/6] watchdog: Integrate watchdog triggering into the cyclic framework

2022-09-02 Thread Stefan Roese
This patch integrates the watchdog triggering into the recently added
cyclic infrastructure. Each watchdog device that shall be triggered
registers it's own cyclic function. This way, multiple watchdog devices
are still supported, each via a cyclic function with separate trigger
intervals.

Signed-off-by: Stefan Roese 
---
v1:
- Reword WDT logging at startup as suggested by Rasmus
- Fail upon !priv->cyclic initr_watchdog()
- Remove some superflous checks in wdt_cyclic()

 drivers/watchdog/Kconfig  |  2 +
 drivers/watchdog/wdt-uclass.c | 73 ---
 2 files changed, 43 insertions(+), 32 deletions(-)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 50e6a1efba51..e55deaf906b5 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -3,6 +3,7 @@ menu "Watchdog Timer Support"
 config WATCHDOG
bool "Enable U-Boot watchdog reset"
depends on !HW_WATCHDOG
+   select CYCLIC
help
  This option enables U-Boot watchdog support where U-Boot is using
  watchdog_reset function to service watchdog device in U-Boot. Enable
@@ -74,6 +75,7 @@ config WDT
bool "Enable driver model for watchdog timer drivers"
depends on DM
imply WATCHDOG
+   select CYCLIC
help
  Enable driver model for watchdog timer. At the moment the API
  is very simple and only supports four operations:
diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c
index dbf556467d3c..3f342cd99fdd 100644
--- a/drivers/watchdog/wdt-uclass.c
+++ b/drivers/watchdog/wdt-uclass.c
@@ -6,6 +6,7 @@
 #define LOG_CATEGORY UCLASS_WDT
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -38,8 +39,25 @@ struct wdt_priv {
bool running;
/* No autostart */
bool noautostart;
+
+   struct cyclic_info *cyclic;
 };
 
+static void wdt_cyclic(void *ctx)
+{
+   struct udevice *dev = ctx;
+   struct wdt_priv *priv;
+
+   if (!device_active(dev))
+   return;
+
+   priv = dev_get_uclass_priv(dev);
+   if (!priv->running)
+   return;
+
+   wdt_reset(dev);
+}
+
 static void init_watchdog_dev(struct udevice *dev)
 {
struct wdt_priv *priv;
@@ -64,9 +82,6 @@ static void init_watchdog_dev(struct udevice *dev)
printf("WDT:   Failed to start %s\n", dev->name);
return;
}
-
-   printf("WDT:   Started %s with%s servicing (%ds timeout)\n", dev->name,
-  IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out", priv->timeout);
 }
 
 int initr_watchdog(void)
@@ -105,8 +120,29 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong 
flags)
ret = ops->start(dev, timeout_ms, flags);
if (ret == 0) {
struct wdt_priv *priv = dev_get_uclass_priv(dev);
+   char str[16];
 
priv->running = true;
+
+   memset(str, 0, 16);
+   if (IS_ENABLED(CONFIG_WATCHDOG)) {
+   /* Register the watchdog driver as a cyclic function */
+   priv->cyclic = cyclic_register(wdt_cyclic,
+  priv->reset_period * 
1000,
+  dev->name, dev);
+   if (!priv->cyclic) {
+   printf("cyclic_register for %s failed\n",
+  dev->name);
+   return -ENODEV;
+   } else {
+   snprintf(str, 16, "every %ldms",
+priv->reset_period);
+   }
+   }
+
+   printf("WDT:   Started %s with%s servicing %s (%ds timeout)\n",
+  dev->name, IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out",
+  str, priv->timeout);
}
 
return ret;
@@ -194,37 +230,10 @@ int wdt_expire_now(struct udevice *dev, ulong flags)
  */
 void watchdog_reset(void)
 {
-   struct wdt_priv *priv;
-   struct udevice *dev;
-   struct uclass *uc;
-   ulong now;
-
-   /* Exit if GD is not ready or watchdog is not initialized yet */
-   if (!gd || !(gd->flags & GD_FLG_WDT_READY))
-   return;
-
-   if (uclass_get(UCLASS_WDT, &uc))
-   return;
-
/*
-* All devices bound to the wdt uclass should have been probed
-* in initr_watchdog(). But just in case something went wrong,
-* check device_active() before accessing the uclass private
-* data.
+* Empty function for now. The actual WDT handling is now done in
+* the cyclic function instead.
 */
-   uclass_foreach_dev(dev, uc) {
-   if (!device_active(dev))
-   continue;
-   priv = dev_get_uclass_priv(dev);
-   if (!priv->running)
-   continue;
- 

[PATCH v6 8/8] cyclic: Add a simple test

2022-09-02 Thread Stefan Roese
Add a test for cyclic function registration and activation.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v6:
- No change

v5:
- Set 'cyclic_active' to false before registering the test
- Use WATCHDOG_RESET() instead of mdelay()
- Use COMMON_TEST()
- Added Simon's RB tag

v4:
- New patch

 test/common/Makefile |  1 +
 test/common/cyclic.c | 35 +++
 test/test-main.c |  3 +++
 3 files changed, 39 insertions(+)
 create mode 100644 test/common/cyclic.c

diff --git a/test/common/Makefile b/test/common/Makefile
index 9087788ba6a8..cc918f64e544 100644
--- a/test/common/Makefile
+++ b/test/common/Makefile
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0+
 obj-y += cmd_ut_common.o
 obj-$(CONFIG_AUTOBOOT) += test_autoboot.o
+obj-$(CONFIG_CYCLIC) += cyclic.o
 obj-$(CONFIG_EVENT) += event.o
diff --git a/test/common/cyclic.c b/test/common/cyclic.c
new file mode 100644
index ..a5c4e78989b9
--- /dev/null
+++ b/test/common/cyclic.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 Stefan Roese 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Test that cyclic function is called */
+static bool cyclic_active = false;
+
+static void cyclic_test(void *ctx)
+{
+   cyclic_active = true;
+}
+
+static int dm_test_cyclic_running(struct unit_test_state *uts)
+{
+   cyclic_active = false;
+   ut_assertnonnull(cyclic_register(cyclic_test, 10 * 1000, "cyclic_demo",
+NULL));
+
+   /* Execute all registered cyclic functions */
+   WATCHDOG_RESET();
+   ut_asserteq(true, cyclic_active);
+
+   return 0;
+}
+COMMON_TEST(dm_test_cyclic_running, 0);
diff --git a/test/test-main.c b/test/test-main.c
index 31837e57a8fb..8a609a8a2fce 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -220,6 +221,7 @@ static int dm_test_restore(struct device_node *of_root)
 static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
 {
ut_assertok(event_init());
+   ut_assertok(cyclic_init());
 
if (test->flags & UT_TESTF_DM)
ut_assertok(dm_test_pre_run(uts));
@@ -265,6 +267,7 @@ static int test_post_run(struct unit_test_state *uts, 
struct unit_test *test)
ut_unsilence_console(uts);
if (test->flags & UT_TESTF_DM)
ut_assertok(dm_test_post_run(uts));
+   ut_assertok(cyclic_uninit());
ut_assertok(event_uninit());
 
return 0;
-- 
2.37.3



[PATCH v6 7/8] cyclic: Add documentation

2022-09-02 Thread Stefan Roese
Add documentation for the cyclic function infrastructure, including the
cyclic command.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v6:
- No change

v5:
- No change

v4:
- Minor spelling fix
- Added Simon's RB tag

v3:
- New patch

 doc/develop/cyclic.rst   | 50 
 doc/develop/index.rst|  1 +
 doc/usage/cmd/cyclic.rst | 45 
 doc/usage/index.rst  |  1 +
 4 files changed, 97 insertions(+)
 create mode 100644 doc/develop/cyclic.rst
 create mode 100644 doc/usage/cmd/cyclic.rst

diff --git a/doc/develop/cyclic.rst b/doc/develop/cyclic.rst
new file mode 100644
index ..43bedacb9f88
--- /dev/null
+++ b/doc/develop/cyclic.rst
@@ -0,0 +1,50 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Cyclic functions
+
+
+The cyclic function execution infrastruture provides a way to periodically
+execute code, e.g. every 100ms. Examples for such functions might be LED
+blinking etc. The functions that are hooked into this cyclic list should
+be small timewise as otherwise the execution of the other code that relies
+on a high frequent polling (e.g. UART rx char ready check) might be
+delayed too much. To detect cyclic functions with a too long execution
+time, the Kconfig option `CONFIG_CYCLIC_MAX_CPU_TIME_US` is introduced,
+which configures the max allowed time for such a cyclic function. If it's
+execution time exceeds this time, this cyclic function will get removed
+from the cyclic list.
+
+Registering a cyclic function
+-
+
+To register a cyclic function, use something like this::
+
+static void cyclic_demo(void *ctx)
+{
+/* Just a small dummy delay here */
+udelay(10);
+}
+
+int board_init(void)
+{
+struct cyclic_info *cyclic;
+
+/* Register demo cyclic function */
+cyclic = cyclic_register(cyclic_demo, 10 * 1000, "cyclic_demo", NULL);
+if (!cyclic)
+printf("Registering of cyclic_demo failed\n");
+
+return 0;
+}
+
+This will register the function `cyclic_demo()` to be periodically
+executed all 10ms.
+
+How is this cyclic functionality integrated /  executed?
+
+
+The cyclic infrastructure integrates the main function responsible for
+calling all registered cyclic functions cyclic_run() into the common
+WATCHDOG_RESET macro. This guarantees that cyclic_run() is executed
+very often, which is necessary for the cyclic functions to get scheduled
+and executed at their configured periods.
diff --git a/doc/develop/index.rst b/doc/develop/index.rst
index f7ee09db2467..ce6b38e57629 100644
--- a/doc/develop/index.rst
+++ b/doc/develop/index.rst
@@ -27,6 +27,7 @@ Implementation
ci_testing
commands
config_binding
+   cyclic
devicetree/index
distro
driver-model/index
diff --git a/doc/usage/cmd/cyclic.rst b/doc/usage/cmd/cyclic.rst
new file mode 100644
index ..3085cc7204c0
--- /dev/null
+++ b/doc/usage/cmd/cyclic.rst
@@ -0,0 +1,45 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+cyclic command
+==
+
+Synopsis
+
+
+::
+
+cyclic list
+
+Description
+---
+
+The cyclic list command provides a list of the currently registered
+cyclic functions.
+
+This shows the following information:
+
+Function
+Function name
+
+cpu-time
+Total time spent in this cyclic function.
+
+Frequency
+Frequency of execution of this function, e.g. 100 times/s for a
+pediod of 10ms.
+
+
+See :doc:`../../develop/cyclic` for more information on cyclic functions.
+
+Example
+---
+
+::
+
+=> cyclic list
+function: cyclic_demo, cpu-time: 52906 us, frequency: 99.20 times/s
+
+Configuration
+-
+
+The cyclic command is only available if CONFIG_CMD_CYCLIC=y.
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 28f9683a3e6f..1a0665ec1b78 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -33,6 +33,7 @@ Shell commands
cmd/bootz
cmd/cbsysinfo
cmd/conitrace
+   cmd/cyclic
cmd/dm
cmd/echo
cmd/env
-- 
2.37.3



[PATCH v6 2/8] cyclic: Add basic support for cyclic function execution infrastruture

2022-09-02 Thread Stefan Roese
Add the basic infrastructure to periodically execute code, e.g. all
100ms. Examples for such functions might be LED blinking etc. The
functions that are hooked into this cyclic list should be small timewise
as otherwise the execution of the other code that relies on a high
frequent polling (e.g. UART rx char ready check) might be delayed too
much. This patch also adds the Kconfig option
CONFIG_CYCLIC_MAX_CPU_TIME_US, which configures the max allowed time
for such a cyclic function. If it's execution time exceeds this time,
this cyclic function will get removed from the cyclic list.

How is this cyclic functionality executed?
The following patch integrates the main function responsible for
calling all registered cyclic functions cyclic_run() into the
common WATCHDOG_RESET macro. This guarantees that cyclic_run() is
executed very often, which is necessary for the cyclic functions to
get scheduled and executed at their configured periods.

This cyclic infrastructure will be used by a board specific function on
the NIC23 MIPS Octeon board, which needs to check periodically, if a
PCIe FLR has occurred.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v6:
- Move static and global variables into struct in GD
- Add cyclic_get_list() to retieve pointer to the cyclic list
- Add move documentation for structs and function prototypes

v5:
- No change

v4:
- Rename cyclic_struct to cyclic_info and document it
- Set 'cyclic_ready' to false in cyclic_uninit()
- Added Simon's RB tag

v3:
- No change

v2:
- Also add cyclic_register() and cyclic_unregister() as empty functions
  when CONFIG_CYCLIC is not defined
- Misc minor changes

 MAINTAINERS   |   6 ++
 common/Kconfig|  20 +
 common/Makefile   |   1 +
 common/cyclic.c   | 123 ++
 include/asm-generic/global_data.h |   7 ++
 include/cyclic.h  | 138 ++
 6 files changed, 295 insertions(+)
 create mode 100644 common/cyclic.c
 create mode 100644 include/cyclic.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 36a2b69fcb97..7255b8286ae2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -788,6 +788,12 @@ T: git 
https://source.denx.de/u-boot/custodians/u-boot-coldfire.git
 F: arch/m68k/
 F: doc/arch/m68k.rst
 
+CYCLIC
+M: Stefan Roese 
+S: Maintained
+F: common/cyclic.c
+F: include/cyclic.h
+
 DFU
 M: Lukasz Majewski 
 S: Maintained
diff --git a/common/Kconfig b/common/Kconfig
index e7914ca750a3..a6a94ab8dfbf 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -545,6 +545,26 @@ config DISPLAY_BOARDINFO_LATE
 
 menu "Start-up hooks"
 
+config CYCLIC
+   bool "General-purpose cyclic execution mechanism"
+   help
+ This enables a general-purpose cyclic execution infrastructure,
+ to allow "small" (run-time wise) functions to be executed at
+ a specified frequency. Things like LED blinking or watchdog
+ triggering are examples for such tasks.
+
+if CYCLIC
+
+config CYCLIC_MAX_CPU_TIME_US
+   int "Sets the max allowed time for a cyclic function in us"
+   default 1000
+   help
+ The max allowed time for a cyclic function in us. If a functions
+ takes longer than this duration this function will get unregistered
+ automatically.
+
+endif # CYCLIC
+
 config EVENT
bool "General-purpose event-handling mechanism"
default y if SANDBOX
diff --git a/common/Makefile b/common/Makefile
index 2ed8672c3ac1..1d56c9f2895a 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -84,6 +84,7 @@ obj-y += malloc_simple.o
 endif
 endif
 
+obj-$(CONFIG_CYCLIC) += cyclic.o
 obj-$(CONFIG_$(SPL_TPL_)EVENT) += event.o
 
 obj-$(CONFIG_$(SPL_TPL_)HASH) += hash.o
diff --git a/common/cyclic.c b/common/cyclic.c
new file mode 100644
index ..f0bfd18c9242
--- /dev/null
+++ b/common/cyclic.c
@@ -0,0 +1,123 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * A general-purpose cyclic execution infrastructure, to allow "small"
+ * (run-time wise) functions to be executed at a specified frequency.
+ * Things like LED blinking or watchdog triggering are examples for such
+ * tasks.
+ *
+ * Copyright (C) 2022 Stefan Roese 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct list_head *cyclic_get_list(void)
+{
+   return &gd->cyclic->cyclic_list;
+}
+
+struct cyclic_info *cyclic_register(cyclic_func_t func, uint64_t delay_us,
+   const char *name, void *ctx)
+{
+   struct cyclic_info *cyclic;
+
+   if (!gd->cyclic->cyclic_ready) {
+   pr_debug("Cyclic IF not ready yet\n");
+   return NULL;
+   }
+
+   cyclic = calloc(1, sizeof(struct cyclic_info));
+   if (!cyclic) {
+   pr_debug("Memory allocation error\n");
+   return NULL;
+   }
+
+   /* Store values in struct */
+  

[PATCH v6 5/8] cyclic: Add 'cyclic list' and 'cyclic demo' commands

2022-09-02 Thread Stefan Roese
This patch adds the cyclic command, which currently only supports the
'list' subcommand, to list all currently registered cyclic functions.
Here an example:

=> cyclic list
function: cyclic_demo, cpu-time: 7010 us, frequency: 99.80 times/s
function: cyclic_demo2, cpu-time: 1 us, frequency: 1.13 times/s

As you can see, the cpu-time is accounted, so that cyclic functions
that take too long might be discovered. Additionally the frequency is
logged.

The 'cyclic demo' commands registers the cyclic_demo() function to
be executed all 'cycletime_ms' milliseconds. The only thing this
function does is delaying by 'delay_us' microseconds.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v6:
- Use cyclic_get_list()
- Use div64 macros for division and remainder

v5:
- Add 'cyclic demo' command

v4:
- Add 'default y' in Kconfig and extend help text
- Minor spelling fix
- Added Simon's RB tag

v3:
- No change

v2:
- Add depends on CYCLIC in Kconfig

 MAINTAINERS  |  1 +
 cmd/Kconfig  | 16 ++
 cmd/Makefile |  1 +
 cmd/cyclic.c | 84 
 4 files changed, 102 insertions(+)
 create mode 100644 cmd/cyclic.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 7255b8286ae2..87eef2f1b259 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -791,6 +791,7 @@ F:  doc/arch/m68k.rst
 CYCLIC
 M: Stefan Roese 
 S: Maintained
+F: cmd/cyclic.c
 F: common/cyclic.c
 F: include/cyclic.h
 
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 8ea064b8d2fb..0649ffcbdf8e 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2505,6 +2505,22 @@ config CMD_CBSYSINFO
  memory by coreboot before jumping to U-Boot. It can be useful for
  debugging the beaaviour of coreboot or U-Boot.
 
+config CMD_CYCLIC
+   bool "cyclic - Show information about cyclic functions"
+   depends on CYCLIC
+   default y
+   help
+ This enables the 'cyclic' command which provides information about
+ cyclic execution functions. This infrastructure allows registering
+ functions to be executed cyclically, e.g. every 100ms. These commands
+ are supported:
+
+   cyclic list - list cyclic functions
+   cyclic cyclic demo   - register cyclic
+   demo function
+
+ See doc/develop/cyclic.rst for more details.
+
 config CMD_DIAG
bool "diag - Board diagnostics"
help
diff --git a/cmd/Makefile b/cmd/Makefile
index 6e87522b62e8..a0abfc623a2b 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_CMD_DIAG) += diag.o
 endif
 obj-$(CONFIG_CMD_ADTIMG) += adtimg.o
 obj-$(CONFIG_CMD_ABOOTIMG) += abootimg.o
+obj-$(CONFIG_CMD_CYCLIC) += cyclic.o
 obj-$(CONFIG_CMD_EVENT) += event.o
 obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
 obj-$(CONFIG_CMD_ECHO) += echo.o
diff --git a/cmd/cyclic.c b/cmd/cyclic.c
new file mode 100644
index ..c1bc556aade9
--- /dev/null
+++ b/cmd/cyclic.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * A general-purpose cyclic execution infrastructure, to allow "small"
+ * (run-time wise) functions to be executed at a specified frequency.
+ * Things like LED blinking or watchdog triggering are examples for such
+ * tasks.
+ *
+ * Copyright (C) 2022 Stefan Roese 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct cyclic_demo_info {
+   uint delay_us;
+};
+
+static void cyclic_demo(void *ctx)
+{
+   struct cyclic_demo_info *info = ctx;
+
+   /* Just a small dummy delay here */
+   udelay(info->delay_us);
+}
+
+static int do_cyclic_demo(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   struct cyclic_demo_info *info;
+   struct cyclic_info *cyclic;
+   uint time_ms;
+
+   if (argc < 3)
+   return CMD_RET_USAGE;
+
+   info = malloc(sizeof(struct cyclic_demo_info));
+   if (!info) {
+   printf("out of memory\n");
+return CMD_RET_FAILURE;
+   }
+
+   time_ms = simple_strtoul(argv[1], NULL, 0);
+   info->delay_us = simple_strtoul(argv[2], NULL, 0);
+
+   /* Register demo cyclic function */
+   cyclic = cyclic_register(cyclic_demo, time_ms * 1000, "cyclic_demo",
+info);
+   if (!cyclic)
+   printf("Registering of cyclic_demo failed\n");
+
+   printf("Registered function \"%s\" to be executed all %dms\n",
+  "cyclic_demo", time_ms);
+
+   return 0;
+}
+
+static int do_cyclic_list(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   struct cyclic_info *cyclic, *tmp;
+   u64 cnt, freq;
+
+   list_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) {
+   cnt = cyclic->run_cnt * 100ULL * 100ULL;
+   freq = lldiv(cnt, timer_get_us() - cyclic->start_time_us);
+   printf("function: %s, cpu-time: %lld us, frequency: %lld.%02d 

[PATCH v6 3/8] cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET

2022-09-02 Thread Stefan Roese
This patch integrates the main function responsible for calling all
registered cyclic functions cyclic_run() into the common WATCHDOG_RESET
macro. This guarantees that cyclic_run() is executed very often, which
is necessary for the cyclic functions to get scheduled and executed at
their configured periods.

If CONFIG_WATCHDOG is not enabled, only cyclic_run() without calling
watchdog_reset(). This guarantees that the cyclic functionality does not
rely on CONFIG_WATCHDOG being enabled.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v6:
- No change

v5:
- No change

v4:
- Added Simon's RB tag

v3:
- No change

v2:
- No change

 fs/cramfs/uncompress.c |  2 +-
 include/watchdog.h | 23 ---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/fs/cramfs/uncompress.c b/fs/cramfs/uncompress.c
index f431cc46c1f7..38e10e2e4422 100644
--- a/fs/cramfs/uncompress.c
+++ b/fs/cramfs/uncompress.c
@@ -62,7 +62,7 @@ int cramfs_uncompress_init (void)
stream.avail_in = 0;
 
 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-   stream.outcb = (cb_func) WATCHDOG_RESET;
+   stream.outcb = (cb_func)watchdog_reset_func;
 #else
stream.outcb = Z_NULL;
 #endif /* CONFIG_HW_WATCHDOG */
diff --git a/include/watchdog.h b/include/watchdog.h
index 813cc8f2a5d3..0a9777edcbad 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -11,6 +11,8 @@
 #define _WATCHDOG_H_
 
 #if !defined(__ASSEMBLY__)
+#include 
+
 /*
  * Reset the watchdog timer, always returns 0
  *
@@ -60,11 +62,16 @@ int init_func_watchdog_reset(void);
/* Don't require the watchdog to be enabled in SPL */
#if defined(CONFIG_SPL_BUILD) &&\
!defined(CONFIG_SPL_WATCHDOG)
-   #define WATCHDOG_RESET() {}
+   #define WATCHDOG_RESET() { \
+   cyclic_run(); \
+   }
#else
extern void watchdog_reset(void);
 
-   #define WATCHDOG_RESET watchdog_reset
+   #define WATCHDOG_RESET() { \
+   watchdog_reset(); \
+   cyclic_run(); \
+   }
#endif
#endif
#else
@@ -74,11 +81,21 @@ int init_func_watchdog_reset(void);
#if defined(__ASSEMBLY__)
#define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/
#else
-   #define WATCHDOG_RESET() {}
+   #define WATCHDOG_RESET() { \
+   cyclic_run(); \
+   }
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */
 #endif /* CONFIG_HW_WATCHDOG */
 
+#if !defined(__ASSEMBLY__)
+/* Currently only needed for fs/cramfs/uncompress.c */
+static inline void watchdog_reset_func(void)
+{
+   WATCHDOG_RESET();
+}
+#endif
+
 /*
  * Prototypes from $(CPU)/cpu.c.
  */
-- 
2.37.3



[PATCH v6 4/8] cyclic: Integrate cyclic functionality at bootup in board_r/f

2022-09-02 Thread Stefan Roese
This patch adds a call to cyclic_init() to board_f/r.c, enabling the
common cyclic infrastructure. After this it's possible to add cyclic
functions via cyclic_register().

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v6:
- Move cyclic_init() in board_r.c after initr_malloc, as we now
  need malloc to work

v5:
- No change

v4:
- Added Simon's RB tag

v3:
- No change

v2:
- No change

 common/board_f.c | 2 ++
 common/board_r.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/common/board_f.c b/common/board_f.c
index 18e2246733b0..deb46be18227 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -828,6 +829,7 @@ static const init_fnc_t init_sequence_f[] = {
initf_malloc,
log_init,
initf_bootstage,/* uses its own timer, so does not need DM */
+   cyclic_init,
event_init,
 #ifdef CONFIG_BLOBLIST
bloblist_init,
diff --git a/common/board_r.c b/common/board_r.c
index 56eb60fa2753..062bc3e688c6 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #ifdef CONFIG_MTD_NOR_FLASH
@@ -611,6 +612,7 @@ static init_fnc_t init_sequence_r[] = {
 #endif
initr_barrier,
initr_malloc,
+   cyclic_init,
log_init,
initr_bootstage,/* Needs malloc() but has its own timer */
 #if defined(CONFIG_CONSOLE_RECORD)
-- 
2.37.3



[PATCH v6 6/8] mips: octeon_nic23: Add PCIe FLR fixup via cyclic infrastructure

2022-09-02 Thread Stefan Roese
From: Aaron Williams 

This patch adds a fixup function related to a PCIe FLR (Function Level
Reset) problem on the NIC23 PCIe board. This function is imported from
the Marvell Octeon 2013 U-Boot version as a (nearly) verbatim copy. It
uses the newly introduced cyclic infrastructure, so that this function
gets called every 100us, which is needed to detect this FLR issue.

Signed-off-by: Aaron Williams 
Signed-off-by: Stefan Roese 
---
v6:
- No change

v5:
- No change

v4:
- Rename cyclic_struct to cyclic_info

v3:
- No change

v2:
- No change

 board/Marvell/octeon_nic23/board.c | 197 +
 configs/octeon_nic23_defconfig |   3 +
 2 files changed, 200 insertions(+)

diff --git a/board/Marvell/octeon_nic23/board.c 
b/board/Marvell/octeon_nic23/board.c
index 3e2c5397..08b1aa4b6efe 100644
--- a/board/Marvell/octeon_nic23/board.c
+++ b/board/Marvell/octeon_nic23/board.c
@@ -3,8 +3,10 @@
  * Copyright (C) 2021-2022 Stefan Roese 
  */
 
+#include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -15,11 +17,90 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "board_ddr.h"
 
+/**
+ * cvmx_spem#_cfg_rd
+ *
+ * This register allows read access to the configuration in the PCIe core.
+ *
+ */
+union cvmx_spemx_cfg_rd {
+   u64 u64;
+   struct cvmx_spemx_cfg_rd_s {
+   u64 data : 32;
+   u64 addr : 32;
+   } s;
+   struct cvmx_spemx_cfg_rd_scn73xx;
+};
+
+/**
+ * cvmx_spem#_cfg_wr
+ *
+ * This register allows write access to the configuration in the PCIe core.
+ *
+ */
+union cvmx_spemx_cfg_wr {
+   u64 u64;
+   struct cvmx_spemx_cfg_wr_s {
+   u64 data : 32;
+   u64 addr : 32;
+   } s;
+   struct cvmx_spemx_cfg_wr_scn73xx;
+};
+
+/**
+ * cvmx_spem#_flr_pf_stopreq
+ *
+ * PF function level reset stop outbound requests register.
+ * Hardware automatically sets the STOPREQ bit for the PF when it enters a
+ * function level reset (FLR).  Software is responsible for clearing the 
STOPREQ
+ * bit but must not do so prior to hardware taking down the FLR, which could be
+ * as long as 100ms.  It may be appropriate for software to wait longer before 
clearing
+ * STOPREQ, software may need to drain deep DPI queues for example.
+ * Whenever SPEM receives a PF or child VF request mastered by CN over S2M 
(i.e. P or NP),
+ * when STOPREQ is set for the function, SPEM will discard the outgoing request
+ * before sending it to the PCIe core.  If a NP, SPEM will schedule an 
immediate
+ * SWI_RSP_ERROR completion for the request - no timeout is required.
+ * In both cases, SPEM()_DBG_PF()_INFO[P()_BMD_E] will be set and a error
+ * interrupt is generated.
+ *
+ * STOPREQ mimics the behavior of PCIEEP()_CFG001[ME] for outbound requests 
that will
+ * master the PCIe bus (P and NP).
+ *
+ * STOPREQ will have no effect on completions returned by CN over the S2M,
+ * nor on M2S traffic.
+ *
+ * When a PF()_STOPREQ is set, none of the associated
+ * PEM()_FLR_PF()_VF_STOPREQ[VF_STOPREQ] will be set.
+ *
+ * STOPREQ is reset when the MAC is reset, and is not reset after a chip soft 
reset.
+ */
+union cvmx_spemx_flr_pf_stopreq {
+   u64 u64;
+   struct cvmx_spemx_flr_pf_stopreq_s {
+   u64 reserved_3_63: 61;
+   u64 pf2_stopreq  : 1;
+   u64 pf1_stopreq  : 1;
+   u64 pf0_stopreq  : 1;
+   } s;
+   struct cvmx_spemx_flr_pf_stopreq_scn73xx;
+};
+
+#define CVMX_SPEMX_CFG_WR(offset)  0x00011800C028ull
+#define CVMX_SPEMX_CFG_RD(offset)  0x00011800C030ull
+#define CVMX_SPEMX_FLR_PF_STOPREQ(offset)  0x00011800C218ull
+
+#define DTX_SELECT_LTSSM   0x0
+#define DTX_SELECT_LTSSM_ENA   0x3ff
+#define LTSSM_L0   0x11
+
 #define NIC23_DEF_DRAM_FREQ800
 
+static u32 pci_cfgspace_reg0[2] = { 0, 0 };
+
 static u8 octeon_nic23_cfg0_spd_values[512] = {
OCTEON_NIC23_CFG0_SPD_VALUES
 };
@@ -145,8 +226,118 @@ void board_configure_qlms(void)
  cvmx_qlm_measure_clock(4), cvmx_qlm_measure_clock(5));
 }
 
+/**
+ * If there is a PF FLR then the PCI EEPROM is not re-read.  In this case
+ * we need to re-program the vendor and device ID immediately after hardware
+ * completes FLR.
+ *
+ * PCI spec requires FLR to be completed within 100ms.  The user who triggered
+ * FLR expects hardware to finish FLR within 100ms, otherwise the user will
+ * end up reading DEVICE_ID incorrectly from the reset value.
+ * CN23XX exits FLR at any point between 66 and 99ms, so U-Boot has to wait
+ * 99ms to let hardware finish its part, then finish reprogramming the
+ * correct device ID before the end of 100ms.
+ *
+ * Note: this solution only works properly when there is no other activi

[PATCH v6 0/8] Add support for cyclic function execution infrastruture

2022-09-02 Thread Stefan Roese
This patchset adds the basic infrastructure to periodically execute
code, e.g. all 100ms. Examples for such functions might be LED blinking
etc. The functions that are hooked into this cyclic list should be
small timewise as otherwise the execution of the other code that relies
on a high frequent polling (e.g. UART rx char ready check) might be
delayed too much. This patch also adds the Kconfig option
CONFIG_CYCLIC_MAX_CPU_TIME_US, which configures the max allowed time
for such a cyclic function. If it's execution time exceeds this time,
this cyclic function will get removed from the cyclic list.

How is this cyclic functionality executed?
This patchset integrates the main function responsible for calling all
registered cyclic functions cyclic_run() into the common WATCHDOG_RESET
macro. This guarantees that cyclic_run() is executed very often, which
is necessary for the cyclic functions to get scheduled and executed at
their configured periods.

This cyclic infrastructure will be used by a board specific function on
the NIC23 MIPS Octeon board, which needs to check periodically, if a
PCIe FLR has occurred.

Ideas how to continue:
One idea is to rename WATCHDOG_RESET to something like SCHEDULE and
move the watchdog_reset call into this cyclic infrastructure as well.
Or to perhaps move the shell UART RX ready polling to a cyclic
function.

It's also possible to extend the "cyclic" command, to support the
creation of periodically executed shell commands (for testing etc).

Here the Azure build, without any issues:
https://dev.azure.com/sr0718/u-boot/_build/results?buildId=256&view=results

Aaron Williams (1):
  mips: octeon_nic23: Add PCIe FLR fixup via cyclic infrastructure

Stefan Roese (7):
  time: Import time_after64() and friends from Linux
  cyclic: Add basic support for cyclic function execution infrastruture
  cyclic: Integrate cyclic infrastructure into WATCHDOG_RESET
  cyclic: Integrate cyclic functionality at bootup in board_r/f
  cyclic: Add 'cyclic list' and 'cyclic demo' commands
  cyclic: Add documentation
  cyclic: Add a simple test

 MAINTAINERS|   7 +
 board/Marvell/octeon_nic23/board.c | 197 +
 cmd/Kconfig|  16 +++
 cmd/Makefile   |   1 +
 cmd/cyclic.c   |  84 
 common/Kconfig |  20 +++
 common/Makefile|   1 +
 common/board_f.c   |   2 +
 common/board_r.c   |   2 +
 common/cyclic.c| 123 ++
 configs/octeon_nic23_defconfig |   3 +
 doc/develop/cyclic.rst |  50 
 doc/develop/index.rst  |   1 +
 doc/usage/cmd/cyclic.rst   |  45 +++
 doc/usage/index.rst|   1 +
 fs/cramfs/uncompress.c |   2 +-
 include/asm-generic/global_data.h  |   7 +
 include/cyclic.h   | 138 
 include/time.h |  19 +++
 include/watchdog.h |  23 +++-
 test/common/Makefile   |   1 +
 test/common/cyclic.c   |  35 +
 test/test-main.c   |   3 +
 23 files changed, 777 insertions(+), 4 deletions(-)
 create mode 100644 cmd/cyclic.c
 create mode 100644 common/cyclic.c
 create mode 100644 doc/develop/cyclic.rst
 create mode 100644 doc/usage/cmd/cyclic.rst
 create mode 100644 include/cyclic.h
 create mode 100644 test/common/cyclic.c

-- 
2.37.3



[PATCH v6 1/8] time: Import time_after64() and friends from Linux

2022-09-02 Thread Stefan Roese
When using us times it makes sense to use 64bit variables for storage.
The currently implemented time_after() and friends functions only handle
32bit variables. This patch now includes the 64bit variants as well
from Linux. This will be used by the upcoming generic cyclic function
infrastructure.

These macros were copied from include/linux/jiffies.h of Linux 5.18.

Signed-off-by: Stefan Roese 
Reviewed-by: Simon Glass 
---
v6:
- No change

v5:
- No change

v4:
- Added Simon's RB tag

v3:
- No change

v2:
- No change

 include/time.h | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/include/time.h b/include/time.h
index 9deb2cf61cc4..3b2ba0912470 100644
--- a/include/time.h
+++ b/include/time.h
@@ -83,6 +83,25 @@ uint64_t usec_to_tick(unsigned long usec);
(time_after_eq(a,b) && \
 time_before(a,c))
 
+/* Same as above, but does so with platform independent 64bit types.
+ * These must be used when utilizing jiffies_64 (i.e. return value of
+ * get_jiffies_64() */
+#define time_after64(a,b)  \
+   (typecheck(__u64, a) && \
+typecheck(__u64, b) && \
+((__s64)((b) - (a)) < 0))
+#define time_before64(a,b) time_after64(b,a)
+
+#define time_after_eq64(a,b)   \
+   (typecheck(__u64, a) && \
+typecheck(__u64, b) && \
+((__s64)((a) - (b)) >= 0))
+#define time_before_eq64(a,b)  time_after_eq64(b,a)
+
+#define time_in_range64(a, b, c) \
+   (time_after_eq64(a, b) && \
+time_before_eq64(a, c))
+
 /**
  * usec2ticks() - Convert microseconds to internal ticks
  *
-- 
2.37.3



Re: [PATCH] ddr: socfpga: Fix integer overflow

2022-09-02 Thread Marek Vasut

On 8/30/22 08:42, Jit Loon Lim wrote:

From: Tien Fong Chee 

dramaddrw data structure are defined as u32. Compiler assume 32-bit
arithmetic on expression and the shifting operation to be done on a
32-bit value. So, the expression would overflow if the shifting
is more than 32-bit.

Signed-off-by: Tien Fong Chee 
---
  drivers/ddr/altera/sdram_soc64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ddr/altera/sdram_soc64.c b/drivers/ddr/altera/sdram_soc64.c
index 9b1710c135..81ad02118b 100644
--- a/drivers/ddr/altera/sdram_soc64.c
+++ b/drivers/ddr/altera/sdram_soc64.c
@@ -246,7 +246,7 @@ phys_size_t sdram_calculate_size(struct altera_sdram_plat 
*plat)
 DRAMADDRW_CFG_ROW_ADDR_WIDTH(dramaddrw) +
 DRAMADDRW_CFG_COL_ADDR_WIDTH(dramaddrw));
  
-	size *= (2 << (hmc_ecc_readl(plat, DDRIOCTRL) &

+   size *= ((phys_size_t)2 << (hmc_ecc_readl(plat, DDRIOCTRL) &


What about using 2UL or 2ULL here, would that work too ?


[PATCH 4/4] configs: roc-pc-rk3399:Set the maximum slave SPI speed to 30MHz

2022-09-02 Thread Manoj Sai
-While the SPI controller speed is defined by DTS, the maximum
slave speed (connected devices) is limited by the pre-defined
configuration value CONFIG_SF_DEFAULT_SPEED from 10 MHz to 30Mhz.

-set the Value of SPI flash max frequency for environment to 30Mhz.

This patch increases this maximum SPI slave device speed and
SPI flash max frequency for environment  to 30MHz .

difference in time of erase and update a region of SPI flash from memory
with 10Mhz and 30Mhz frequencey range updation  :

=> sf update 0x30 0x80 0x40

with 10 Mhz frequency updation :-
4194304 bytes written, 0 bytes skipped in 36.819s, speed 119837 B/s

with 30Mhz frequency updation  :-
4194304 bytes written, 0 bytes skipped in 20.319s, speed 220752 B/s

Signed-off-by: Manoj Sai 
Signed-off-by: Da Xue 
Signed-off-by: dsx724 
---
 configs/roc-pc-rk3399_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/roc-pc-rk3399_defconfig b/configs/roc-pc-rk3399_defconfig
index 84e72e8b60..7754cb8388 100644
--- a/configs/roc-pc-rk3399_defconfig
+++ b/configs/roc-pc-rk3399_defconfig
@@ -45,6 +45,7 @@ CONFIG_CMD_TIME=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_SPL_REMOVE_PROPS="pinctrl-0 pinctrl-names clock-names 
interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_ENV_SPI_MAX_HZ=3000
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
 CONFIG_ROCKCHIP_GPIO=y
@@ -55,6 +56,7 @@ CONFIG_MMC_DW_ROCKCHIP=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_ROCKCHIP=y
 CONFIG_SF_DEFAULT_BUS=1
+CONFIG_SF_DEFAULT_SPEED=3000
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_GMAC_ROCKCHIP=y
-- 
2.25.1



[PATCH 3/4] configs:roc-pc-rk3399 :Enable crypto RNG support

2022-09-02 Thread Manoj Sai
enable crypto RNG support for roc-pc-rk3399.

Signed-off-by: Manoj Sai 
Signed-off-by: Da Xue 
Signed-off-by: dsx724 

[PATCH 2/4] configs: roc-pc-rk3399:fix up USB support

2022-09-02 Thread Manoj Sai
- Fix up USB config options so keyboards and other USB devices work .

- Update the number of ports of the Usb root hub to configuration of
  CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS .

USB device tree:
  1  Hub (12 Mb/s, 0mA)
  U-Boot Root Hub
  1  Hub (12 Mb/s, 0mA)
  |   U-Boot Root Hub
  |
  +-2  Hub (12 Mb/s, 100mA)
USB 2.0 Hub [MTT]

 1  Hub (5 Gb/s, 0mA)
U-Boot XHCI Host Controller

Signed-off-by: Manoj Sai 
Signed-off-by: Da Xue 
Signed-off-by: dsx724 
---
 configs/roc-pc-rk3399_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/configs/roc-pc-rk3399_defconfig b/configs/roc-pc-rk3399_defconfig
index 84e82da3cf..ffd809687b 100644
--- a/configs/roc-pc-rk3399_defconfig
+++ b/configs/roc-pc-rk3399_defconfig
@@ -76,6 +76,9 @@ CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_GENERIC=y
+CONFIG_USB_OHCI_HCD=y
+CONFIG_USB_OHCI_GENERIC=y
+CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS=2
 CONFIG_USB_DWC3=y
 CONFIG_USB_DWC3_GENERIC=y
 CONFIG_USB_KEYBOARD=y
-- 
2.25.1



[PATCH 1/4] configs:roc-pc-rk3399 :Enable CONFIG_USE_PREBOOT

2022-09-02 Thread Manoj Sai
use preboot configuration to enable usb devices

Signed-off-by: Manoj Sai 
Signed-off-by: Da Xue 
---
 configs/roc-pc-rk3399_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/roc-pc-rk3399_defconfig b/configs/roc-pc-rk3399_defconfig
index 4625e47537..84e82da3cf 100644
--- a/configs/roc-pc-rk3399_defconfig
+++ b/configs/roc-pc-rk3399_defconfig
@@ -20,6 +20,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x30
 # CONFIG_ANDROID_BOOT_IMAGE is not set
+CONFIG_USE_PREBOOT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3399-roc-pc.dtb"
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x2e000
-- 
2.25.1



[PATCH 0/4] addition of configs for rockchip based roc-pc-rk3399 board

2022-09-02 Thread Manoj Sai
Patch 1/4 use preboot configuration to enable usb devices
Patch 2/4 fix up USB support which can recognize any USB1.1 devices
Patch 3/4 Enable crypto RNG support
Patch 4/4 Set the maximum slave SPI speed to 30MHz

Manoj Sai (4):
  configs: roc-pc-rk3399 :Enable preboot config .
  configs: roc-pc-rk3399:fix up USB support .
  configs: roc-pc-rk3399 :Enable crypto RNG support.
  configs: roc-pc-rk3399:Set the maximum slave SPI speed  and
spi flash max frequency for environment to 30MHz.

 configs/roc-pc-rk3399_defconfig | 8 
 1 file changed, 8 insertions(+)

-- 
2.25.1


[PATCH] distro_bootcmd: Always check for custom boot scripts first

2022-09-02 Thread Andrey Skvortsov
If extlinux.conf is used, then it's not possible to customize boot
environment, because scripts are not loaded.
Usually it's possible to make some changes manually using command line
and save boot environment. But if exlinux.conf is loaded
from ext4 partition (for example on PinePhone), then environment are
not saved/loaded at boot time from boot partition and it's not
possible to persistently change boot environment without recompiling
u-boot.

Signed-off-by: Andrey Skvortsov 
---

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

diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
index 5506f3168f..7f4ef960a1 100644
--- a/include/config_distro_bootcmd.h
+++ b/include/config_distro_bootcmd.h
@@ -477,8 +477,8 @@
"echo Scanning ${devtype} "   \
"${devnum}:${distro_bootpart}...; "   \
"for prefix in ${boot_prefixes}; do " \
-   "run scan_dev_for_extlinux; " \
"run scan_dev_for_scripts; "  \
+   "run scan_dev_for_extlinux; " \
"done;"   \
SCAN_DEV_FOR_EFI  \
"\0"  \
-- 
2.20.1



Re: [RFC PATCH 1/1] net: xilinx: handle internal PHY/PCS

2022-09-02 Thread Nikita Shubin
Hello Harini!

Sorry for long response time.

On Wed, 24 Aug 2022 12:51:08 +
"Katakam, Harini"  wrote:


> Hi Nikita,
> 
> > -Original Message-
> > From: Simek, Michal 
> > Sent: Thursday, August 11, 2022 1:16 PM
> > To: Nikita Shubin ; Agarwal, Swati
> > ; Pandey, Radhey Shyam
> > 
> > Cc: li...@yadro.com; Nikita Shubin ; Joe
> > Hershberger ; Ramon Fried
> > ; u-boot@lists.denx.de
> > Subject: Re: [RFC PATCH 1/1] net: xilinx: handle internal PHY/PCS
> > 
> > Hi Nikita,
> > 
> > On 8/2/22 12:53, Nikita Shubin wrote:  
> > > From: Nikita Shubin 
> > >
> > > In SGMII/1000BaseX Xilinx AXI Ethernet may also have an Internal
> > > PHY (PCS) in addition to external PHY, in that case we should
> > > also set at least BMCR_ANENABLE.
> > >
> > > PCS are not visible until axinet bringup, so init should be done
> > > after, controller is brought up, then we should poll
> > > BMSR_ANEGCOMPLETE prior to polling the external PHY.
> > >
> > > The PCS handling relies on "pcs-handle" device tree handle which
> > > serves the similar purpose in Linux device tree.
> > >
> > > Signed-off-by: Nikita Shubin 
> > > ---  
> 
> > > @@ -540,6 +565,20 @@ static int axiemac_start(struct udevice *dev)
> > >   return -1;
> > >   }
> > >
> > > + if (pcsdev) {
> > > + /* It looks like we need a bit of delay for core
> > > to come up
> > > +  * may be we could poll MgtRdy or PhyRstCmplt bit
> > > +  * in 0x0010, but 1 msec is no a big deal.
> > > +  */
> > > + udelay(1000);
> > > + ret = phywrite(priv, pcsdev->addr, MII_BMCR,
> > > + BMCR_ANENABLE | BMCR_FULLDPLX |  
> > BMCR_SPEED1000);  
> 
> Thanks for the patch.
> Could you please confirm that BMCR_ISOLATE is also being handled in
> the autonegotiation path? For ex., the equivalent in linux can be
> found here:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/phy/phylink.c#n3050

For linux BMCR_ISOLATE is cleared and BMCR_ANENABLE is set (if mode is
MLO_AN_INBAND which is definitely our case) in
phylink_mii_c22_pcs_config. 

In current patch BMCR_ISOLATE is cleared by write, may be indeed
something like:
phyread(priv, pcsdev->addr, MII_BMCR, &val);
val &= ~(BMCR_ISOLATE);
val |= BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000;
phywrite(priv, pcsdev->addr, MII_BMCR, val);

Whould make more sense.

> 
> Could you also please handle the SGMII/1000BaseX standard selection
> in the PCS PMA IP? For reference, please see:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/xilinx/xilinx_axienet_main.c#n1619

You mean to handle "xlnx,switch-x-sgmii" device tree property in same
manner as linux does? No problem then.

Yours,
Nikita Shubin.


> 
> Regards,
> Harini



[PATCH v3] spl: introduce SPL_XIP to config

2022-09-02 Thread Nikita Shubin
From: Nikita Shubin 

U-Boot and SPL don't necessary share the same location, so we might end
with U-Boot SPL in read-only memory (XIP) and U-Boot in read-write memory.

In case of non XIP boot mode, we rely on such variables as "hart_lottery"
and "available_harts_lock" which we use as atomics.

The problem is that CONFIG_XIP also propagate to main U-Boot, not only SPL,
so we need CONFIG_SPL_XIP to distinguish SPL XIP from other XIP modes.

This adds an option special for SPL to behave it in XIP manner and we don't
use hart_lottery and available_harts_lock, during start proccess.

Signed-off-by: Nikita Shubin 
---
v2->v3:
Rick Chen:
- move SPL_XIP to arch/riscv/Kconfig right after XIP
- change ae350_spl defconfig's to use SPL_XIP instead of XIP
---
 arch/riscv/Kconfig   | 7 +++
 arch/riscv/cpu/cpu.c | 2 +-
 arch/riscv/cpu/start.S   | 4 ++--
 arch/riscv/include/asm/global_data.h | 2 +-
 arch/riscv/lib/asm-offsets.c | 2 +-
 arch/riscv/lib/smp.c | 2 +-
 configs/ae350_rv32_spl_xip_defconfig | 2 +-
 configs/ae350_rv64_spl_xip_defconfig | 2 +-
 8 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 78e964db12..c042506a64 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -269,6 +269,13 @@ config XIP
  from a NOR flash memory without copying the code to ram.
  Say yes here if U-Boot boots from flash directly.
 
+config SPL_XIP
+   bool "Enable XIP mode for SPL"
+   help
+ If SPL starts in read-only memory (XIP for example) then we shouldn't
+ rely on lock variables (for example hart_lottery and 
available_harts_lock),
+ this affects only SPL, other stages should proceed as non-XIP.
+
 config SHOW_REGS
bool "Show registers on unhandled exception"
 
diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
index 3ffcbbd23f..0f323b26b3 100644
--- a/arch/riscv/cpu/cpu.c
+++ b/arch/riscv/cpu/cpu.c
@@ -19,7 +19,7 @@
  * The variables here must be stored in the data section since they are used
  * before the bss section is available.
  */
-#ifndef CONFIG_XIP
+#if !CONFIG_IS_ENABLED(XIP)
 u32 hart_lottery __section(".data") = 0;
 
 /*
diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S
index b7f21ab63e..de9d078da1 100644
--- a/arch/riscv/cpu/start.S
+++ b/arch/riscv/cpu/start.S
@@ -122,7 +122,7 @@ call_board_init_f_0:
 call_harts_early_init:
jal harts_early_init
 
-#ifndef CONFIG_XIP
+#if !CONFIG_IS_ENABLED(XIP)
/*
 * Pick hart to initialize global data and run U-Boot. The other harts
 * wait for initialization to complete.
@@ -152,7 +152,7 @@ call_harts_early_init:
/* save the boot hart id to global_data */
SREGtp, GD_BOOT_HART(gp)
 
-#ifndef CONFIG_XIP
+#if !CONFIG_IS_ENABLED(XIP)
la  t0, available_harts_lock
amoswap.w.rl zero, zero, 0(t0)
 
diff --git a/arch/riscv/include/asm/global_data.h 
b/arch/riscv/include/asm/global_data.h
index 095484a635..b3c79e1760 100644
--- a/arch/riscv/include/asm/global_data.h
+++ b/arch/riscv/include/asm/global_data.h
@@ -27,7 +27,7 @@ struct arch_global_data {
 #if CONFIG_IS_ENABLED(SMP)
struct ipi_data ipi[CONFIG_NR_CPUS];
 #endif
-#ifndef CONFIG_XIP
+#if !CONFIG_IS_ENABLED(XIP)
ulong available_harts;
 #endif
 };
diff --git a/arch/riscv/lib/asm-offsets.c b/arch/riscv/lib/asm-offsets.c
index f1fe089b3d..c4f48c8373 100644
--- a/arch/riscv/lib/asm-offsets.c
+++ b/arch/riscv/lib/asm-offsets.c
@@ -16,7 +16,7 @@ int main(void)
 {
DEFINE(GD_BOOT_HART, offsetof(gd_t, arch.boot_hart));
DEFINE(GD_FIRMWARE_FDT_ADDR, offsetof(gd_t, arch.firmware_fdt_addr));
-#ifndef CONFIG_XIP
+#if !CONFIG_IS_ENABLED(XIP)
DEFINE(GD_AVAILABLE_HARTS, offsetof(gd_t, arch.available_harts));
 #endif
 
diff --git a/arch/riscv/lib/smp.c b/arch/riscv/lib/smp.c
index ba992100ad..f8b756291f 100644
--- a/arch/riscv/lib/smp.c
+++ b/arch/riscv/lib/smp.c
@@ -45,7 +45,7 @@ static int send_ipi_many(struct ipi_data *ipi, int wait)
continue;
}
 
-#ifndef CONFIG_XIP
+#if !CONFIG_IS_ENABLED(XIP)
/* skip if hart is not available */
if (!(gd->arch.available_harts & (1 << reg)))
continue;
diff --git a/configs/ae350_rv32_spl_xip_defconfig 
b/configs/ae350_rv32_spl_xip_defconfig
index c7b6ea4730..67c1e35c55 100644
--- a/configs/ae350_rv32_spl_xip_defconfig
+++ b/configs/ae350_rv32_spl_xip_defconfig
@@ -11,7 +11,7 @@ CONFIG_SPL=y
 CONFIG_SYS_LOAD_ADDR=0x10
 CONFIG_TARGET_AX25_AE350=y
 CONFIG_RISCV_SMODE=y
-CONFIG_XIP=y
+CONFIG_SPL_XIP=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x00
diff --git a/configs/ae350_rv64_spl_xip_defconfig 
b/configs/ae350_rv64_spl_xip_defconfig
index a197c97736..baee9bfe4a 100644
--- a/configs/ae350_rv64_spl_xip_defconfig
+++ b/conf

Re: [PATCH v2] spl: introduce SPL_XIP to config

2022-09-02 Thread Nikita Shubin
On Fri, 2 Sep 2022 15:25:06 +0800
Rick Chen  wrote:

Hello Rick!

> Hi Nikita,
> 
> > From: Nikita Shubin 
> > Sent: Wednesday, August 31, 2022 3:25 PM
> > To: u-boot@lists.denx.de
> > Cc: li...@yadro.com; Nikita Shubin ; Rick
> > Jian-Zhi Chen(陳建志) ; Leo Yu-Chi
> > Liang(梁育齊) ; Simon Glass
> > ; Bin Meng ; Heinrich
> > Schuchardt ; Ilias Apalodimas
> > ; Alexandru Gagniuc
> > ; Andrew Davis ; Alper Nebi Yasak
> >  Subject: [PATCH v2] spl: introduce
> > SPL_XIP to config
> >
> > From: Nikita Shubin 
> >
> > U-Boot and SPL don't necessary share the same location, so we might
> > end with U-Boot SPL in read-only memory (XIP) and U-Boot in
> > read-write memory.
> >
> > In case of non XIP boot mode, we rely on such variables as
> > "hart_lottery" and "available_harts_lock" which we use as atomics.
> >
> > The problem is that CONFIG_XIP also propagate to main U-Boot, not
> > only SPL, so we need CONFIG_SPL_XIP to distinguish SPL XIP from
> > other XIP modes.
> >
> > This adds an option special for SPL to behave it in XIP manner and
> > we don't use hart_lottery and available_harts_lock, during start
> > proccess.
> >
> > Signed-off-by: Nikita Shubin 
> > ---
> > v1->v2:
> > Sean Anderson:
> > - used Kconfig description suggested by Sean - indeed more
> > cleaner and understandable ---
> >  arch/riscv/cpu/cpu.c | 2 +-
> >  arch/riscv/cpu/start.S   | 4 ++--
> >  arch/riscv/include/asm/global_data.h | 2 +-
> >  arch/riscv/lib/asm-offsets.c | 2 +-
> >  arch/riscv/lib/smp.c | 2 +-
> >  common/spl/Kconfig   | 7 +++
> >  6 files changed, 13 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c index
> > 9f5fa0bcb3..5d8163b19f 100644 --- a/arch/riscv/cpu/cpu.c
> > +++ b/arch/riscv/cpu/cpu.c
> > @@ -19,7 +19,7 @@
> >   * The variables here must be stored in the data section since
> > they are used
> >   * before the bss section is available.
> >   */
> > -#ifndef CONFIG_XIP
> > +#if !CONFIG_IS_ENABLED(XIP)
> >  u32 hart_lottery __section(".data") = 0;
> >
> >  /*
> > diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index
> > ac81783a90..c3c859e667 100644 --- a/arch/riscv/cpu/start.S
> > +++ b/arch/riscv/cpu/start.S
> > @@ -122,7 +122,7 @@ call_board_init_f_0:
> >  call_harts_early_init:
> > jal harts_early_init
> >
> > -#ifndef CONFIG_XIP
> > +#if !CONFIG_IS_ENABLED(XIP)
> > /*
> >  * Pick hart to initialize global data and run U-Boot. The
> > other harts
> >  * wait for initialization to complete.
> > @@ -150,7 +150,7 @@ call_harts_early_init:
> > /* save the boot hart id to global_data */
> > SREGtp, GD_BOOT_HART(gp)
> >
> > -#ifndef CONFIG_XIP
> > +#if !CONFIG_IS_ENABLED(XIP)
> > la  t0, available_harts_lock
> > amoswap.w.rl zero, zero, 0(t0)
> >
> > diff --git a/arch/riscv/include/asm/global_data.h
> > b/arch/riscv/include/asm/global_data.h index 9a146d1d49..a4d3cf430b
> > 100644 --- a/arch/riscv/include/asm/global_data.h
> > +++ b/arch/riscv/include/asm/global_data.h
> > @@ -30,7 +30,7 @@ int iccm[CONFIG_NR_CPUS];  #if
> > CONFIG_IS_ENABLED(SMP) struct ipi_data ipi[CONFIG_NR_CPUS];
> >  #endif
> > -#ifndef CONFIG_XIP
> > +#if !CONFIG_IS_ENABLED(XIP)
> > ulong available_harts;
> >  #endif
> >  };
> > diff --git a/arch/riscv/lib/asm-offsets.c
> > b/arch/riscv/lib/asm-offsets.c index f1fe089b3d..c4f48c8373 100644
> > --- a/arch/riscv/lib/asm-offsets.c +++
> > b/arch/riscv/lib/asm-offsets.c @@ -16,7 +16,7 @@ int main(void)
> >  {
> > DEFINE(GD_BOOT_HART, offsetof(gd_t, arch.boot_hart));
> > DEFINE(GD_FIRMWARE_FDT_ADDR, offsetof(gd_t,
> > arch.firmware_fdt_addr)); -#ifndef CONFIG_XIP +#if
> > !CONFIG_IS_ENABLED(XIP) DEFINE(GD_AVAILABLE_HARTS, offsetof(gd_t,
> > arch.available_harts));  #endif
> >
> > diff --git a/arch/riscv/lib/smp.c b/arch/riscv/lib/smp.c index
> > ba992100ad..f8b756291f 100644 --- a/arch/riscv/lib/smp.c
> > +++ b/arch/riscv/lib/smp.c
> > @@ -45,7 +45,7 @@ static int send_ipi_many(struct ipi_data *ipi,
> > int wait) continue;
> > }
> >
> > -#ifndef CONFIG_XIP
> > +#if !CONFIG_IS_ENABLED(XIP)
> > /* skip if hart is not available */
> > if (!(gd->arch.available_harts & (1 << reg)))
> > continue;
> > diff --git a/common/spl/Kconfig b/common/spl/Kconfig index
> > 07c03d611d..777eff5e47 100644 --- a/common/spl/Kconfig
> > +++ b/common/spl/Kconfig
> > @@ -27,6 +27,13 @@ config SPL_FRAMEWORK
> >   supports MMC, NAND and YMODEM and other methods loading
> > of U-Boot and the Linux Kernel.  If unsure, say Y.
> >  
> 
> Would you please move the below SPL_XIP to arch/riscv/Kconfig and
> aside the CONFIG_XIP.
> Since hart_lottery and available_harts_lock only be used by RISC-V
> currently.
> 
> And also please help to change CONFIG_XIP to CONFIG_SPL_XIP in the
> following defconfig, or the behavior will b

Re: [PATCH] RockPi4: Add UEFI capsule update support

2022-09-02 Thread Sughosh Ganu
hi Kever,

On Wed, 29 Jun 2022 at 09:11, Kever Yang  wrote:
>
> Hi Sughosh,
>
>   Thanks for your patch.
>
> On 2022/5/16 14:12, Sughosh Ganu wrote:
> > hi Peter,
> >
> > On Sat, 14 May 2022 at 13:44, Peter Robinson  wrote:
> >> On Fri, May 13, 2022 at 7:50 AM Sughosh Ganu  
> >> wrote:
> >>> Add support for updating the idbloader and u-boot images through the
> >>> UEFI capsule update functionality. Enable the modules required for
> >>> supporting the functionality.
> >>>
> >>> The implementation is for the updatable images placed on a GPT
> >>> partitioned storage device. With the GPT partition devices, the
> >>> partition information can be obtained at runtime, and hence the
> >>> dfu_alt_info variable needed for the updates is being populated at
> >>> runtime.
> >>>
> >>> This requires the partitions containing the idbloader and u-boot
> >>> images to be created with the PartitionTypeGUID values set to the
> >>> corresponding image type GUID values defined in the platform's config
> >>> header(ROCKPI_4{B,C}_IDBLOADER_IMAGE_GUID and
> >>> ROCKPI_4{B,C}_UBOOT_IMAGE_GUID).
> >> I think it would be useful to break this patch down into more than one
> >> patch. At least the core changes to evb_rk3399/evb-rk3399.c and the
> >> board specific changes. Also given these changes arre likely of
> >> interest to other boards should  they go to somewhere more central
> >> than evb_rk3399/evb-rk3399.c to enable less code duplication across
> >> rk3399 or even rockchip devices as a whole?
> > I believe I can move the logic to set dfu_alt_info to some place like
> > arch/arm/mach-rockchip/board.c. The definition of rk_board_late_init()
> > can stay in evb-rk3399.c since it is populating the capsule update
> > structures for the rk3399 family of platforms. Does that sound okay to
> > you? If so, I will make the changes and send a V2, or if  you have
> > some other solution in mind, please let me know. Thanks.
>
> Other than Peter's command, please make sure:
>
> All the source code relate to rockpi should go to board/radxa instead of
> board/rockchip/evb-rk3399.c

Apologies for the late reply. I was working on some other stuff and
hence this got put on the backburner. With regards to your review
comment of putting the board code under board/radxa/, how do I get the
code under board/radxa to compile. The RockPi4 boards have
CONFIG_SYS_VENDOR="rockchip" and CONFIG_SYS_BOARD="evb_rk3399". With
these configs, code under board/rockchip/evb_rk3399/ gets built. Is
there some way I can get code under some other board directory to
build?

I was thinking of putting the common code under
arch/arm/mach-rockchip/board.c, and the board specific declarations
under board/rockchip/evb_rk3399/evb_rk3399.c, along with the splitting
of the changes in two patches. Is that fine with you?

-sughosh

>
>
> Thanks,
>
> - Kever
>
> >
> > -sughosh
> >
> >> Peter
> >>
> >>> Signed-off-by: Sughosh Ganu 
> >>> ---
> >>>   arch/arm/mach-rockchip/Kconfig |   1 +
> >>>   board/rockchip/evb_rk3399/evb-rk3399.c | 190 -
> >>>   configs/rock-pi-4-rk3399_defconfig |   4 +
> >>>   configs/rock-pi-4c-rk3399_defconfig|   4 +
> >>>   include/configs/rk3399_common.h|  16 +++
> >>>   5 files changed, 214 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/arch/arm/mach-rockchip/Kconfig 
> >>> b/arch/arm/mach-rockchip/Kconfig
> >>> index 18aff5480b..6d13e7b92e 100644
> >>> --- a/arch/arm/mach-rockchip/Kconfig
> >>> +++ b/arch/arm/mach-rockchip/Kconfig
> >>> @@ -246,6 +246,7 @@ config ROCKCHIP_RK3399
> >>>  select DM_PMIC
> >>>  select DM_REGULATOR_FIXED
> >>>  select BOARD_LATE_INIT
> >>> +   imply PARTITION_TYPE_GUID
> >>>  imply PRE_CONSOLE_BUFFER
> >>>  imply ROCKCHIP_COMMON_BOARD
> >>>  imply ROCKCHIP_SDRAM_COMMON
> >>> diff --git a/board/rockchip/evb_rk3399/evb-rk3399.c 
> >>> b/board/rockchip/evb_rk3399/evb-rk3399.c
> >>> index abb76585cf..cc976d9471 100644
> >>> --- a/board/rockchip/evb_rk3399/evb-rk3399.c
> >>> +++ b/board/rockchip/evb_rk3399/evb-rk3399.c
> >>> @@ -5,11 +5,27 @@
> >>>
> >>>   #include 
> >>>   #include 
> >>> +#include 
> >>>   #include 
> >>>   #include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>>   #include 
> >>>   #include 
> >>>
> >>> +#define ROCKPI4_UPDATABLE_IMAGES   2
> >>> +
> >>> +#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
> >>> +struct efi_fw_image fw_images[ROCKPI4_UPDATABLE_IMAGES] = {0};
> >>> +
> >>> +struct efi_capsule_update_info update_info = {
> >>> +   .images = fw_images,
> >>> +};
> >>> +
> >>> +u8 num_image_type_guids = ARRAY_SIZE(fw_images);
> >>> +#endif
> >>> +
> >>>   #ifndef CONFIG_SPL_BUILD
> >>>   int board_early_init_f(void)
> >>>   {
> >>> @@ -29,4 +45,176 @@ int board_early_init_f(void)
> >>>   out:
> >>>  return 0;
> >>>   }
> >>> -#endif
> >>> +
> >>> +#if defined(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && 
> >>> defined(CONFIG_EFI_PARTITION)
> >>> +
> >>> +#define DFU_ALT

Re: [PATCH v2 1/8] timer: orion-timer: Use timer_conv_64() to fix timer wrap around

2022-09-02 Thread Stefan Roese

On 02.09.22 09:44, Michael Walle wrote:

Am 2022-09-02 08:25, schrieb Stefan Roese:

While testing on some Kirkwood platforms it was noticed that the timer
did not function correctly all the time. The driver did not correctly
handle 32bit timer value wrap arounds. Using the timer_conv_64()
conversion function fixes this issue.


Fixes: e9e73d78a8fb ("timer: add orion-timer support")

Ahh. Sorry about that. I've missed that conversation which is also
in lib/time.c in a different call tree.

Maybe this can be picked to master (if this series is going into
next)?


That's my plan. To pull this patch only in this release cycle and
queue the rest for next.

Thanks,
Stefan


Re: [RFC PATCH 8/8] WIP: .azure-pipelines.yml: Remove evb-ast2600

2022-09-02 Thread Stefan Roese

Hi Joel,

On 02.09.22 08:14, Stefan Roese wrote:

Hi Joel,

On 02.09.22 08:00, Joel Stanley wrote:

On Fri, 2 Sept 2022 at 04:09, Joel Stanley  wrote:


On Mon, 29 Aug 2022 at 06:23, Stefan Roese  wrote:


The evb-ast2600 target always runs into an timeout error when run via
Azure CI. For test purpose only, this patch removes this CI build
target so that the world build can be run.

Joel, Chia-Wei, could you perhaps take a look at this and help to fix
the problems that I'm seeing with this build target here?


Where does it hang? Can you attach the logs?


The hang appears to be in the timer code, where the spl hangs due to a
div by zero. When inspecting, gd->arch.timer_rate_hz is zero at this
point.

However I also noticed the cycling code introduces a symbol that ends
up in BSS. If I give cyclic_running a non-zero value it moves back
into the data section, and the SPL and u-boot proper make it all the
way through.


I might rework the code a bit, so that cyclic does not introduce new
static variables but uses a new data pointer in struct global_data
instead.


This suggests there's still something wrong with the BSS handling for
the 2600 SPL (not resolved by f6810b749f2e ("aspeed/ast2600: Fix SPL
linker script") or the follow up fix). If I use the common arm spl
linker script, the system boots.


Thanks for looking into this.


Using the GD for the cyclic data and instead of new static variables in
this cyclic code seems to fix this CI build issue AFAICT. I'll send an
updates patchset later today.

Thanks,
Stefan




Chai Wei, I think we need a different solution for placing the BSS
outside of the flash.


Thanks,
Stefan


Cheers,

Joel



What kind of debugging have you tried to date?

Cheers,

Joel



Signed-off-by: Stefan Roese 
Cc: Joel Stanley 
Cc: Chia-Wei Wang 
---
  .azure-pipelines.yml | 3 ---
  1 file changed, 3 deletions(-)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 0fa92479b4c4..e48f1667f8de 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -261,9 +261,6 @@ stages:
  evb_ast2500:
    TEST_PY_BD: "evb-ast2500"
    TEST_PY_ID: "--id qemu"
-    evb_ast2600:
-  TEST_PY_BD: "evb-ast2600"
-  TEST_PY_ID: "--id qemu"
  vexpress_ca9x4:
    TEST_PY_BD: "vexpress_ca9x4"
    TEST_PY_ID: "--id qemu"
--
2.37.2



Viele Grüße,
Stefan Roese



Viele Grüße,
Stefan Roese

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH v2 1/8] timer: orion-timer: Use timer_conv_64() to fix timer wrap around

2022-09-02 Thread Michael Walle

Am 2022-09-02 08:25, schrieb Stefan Roese:

While testing on some Kirkwood platforms it was noticed that the timer
did not function correctly all the time. The driver did not correctly
handle 32bit timer value wrap arounds. Using the timer_conv_64()
conversion function fixes this issue.


Fixes: e9e73d78a8fb ("timer: add orion-timer support")

Ahh. Sorry about that. I've missed that conversation which is also
in lib/time.c in a different call tree.

Maybe this can be picked to master (if this series is going into
next)?

-michael


[PATCH] mmc: ftsdc010: make command timeout 250 ms as in the comment

2022-09-02 Thread Sergei Antonov
Get rid of discrepancy beween comment /* 250 ms */ and code
which shifts by 4 thus dividing by 16.
So change code to shift by 2 and make the timeout value 250 ms.

Signed-off-by: Sergei Antonov 
---
 drivers/mmc/ftsdc010_mci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/ftsdc010_mci.c b/drivers/mmc/ftsdc010_mci.c
index 570d54cf9d8f..cabb747fbbdb 100644
--- a/drivers/mmc/ftsdc010_mci.c
+++ b/drivers/mmc/ftsdc010_mci.c
@@ -30,7 +30,7 @@
 #include 
 #include 
 
-#define CFG_CMD_TIMEOUT (CONFIG_SYS_HZ >> 4) /* 250 ms */
+#define CFG_CMD_TIMEOUT (CONFIG_SYS_HZ >> 2) /* 250 ms */
 #define CFG_RST_TIMEOUT CONFIG_SYS_HZ /* 1 sec reset timeout */
 
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
-- 
2.34.1



Re: [PATCH v2] spl: introduce SPL_XIP to config

2022-09-02 Thread Rick Chen
Hi Nikita,

> From: Nikita Shubin 
> Sent: Wednesday, August 31, 2022 3:25 PM
> To: u-boot@lists.denx.de
> Cc: li...@yadro.com; Nikita Shubin ; Rick Jian-Zhi 
> Chen(陳建志) ; Leo Yu-Chi Liang(梁育齊) 
> ; Simon Glass ; Bin Meng 
> ; Heinrich Schuchardt ; Ilias 
> Apalodimas ; Alexandru Gagniuc 
> ; Andrew Davis ; Alper Nebi Yasak 
> 
> Subject: [PATCH v2] spl: introduce SPL_XIP to config
>
> From: Nikita Shubin 
>
> U-Boot and SPL don't necessary share the same location, so we might end with 
> U-Boot SPL in read-only memory (XIP) and U-Boot in read-write memory.
>
> In case of non XIP boot mode, we rely on such variables as "hart_lottery"
> and "available_harts_lock" which we use as atomics.
>
> The problem is that CONFIG_XIP also propagate to main U-Boot, not only SPL, 
> so we need CONFIG_SPL_XIP to distinguish SPL XIP from other XIP modes.
>
> This adds an option special for SPL to behave it in XIP manner and we don't 
> use hart_lottery and available_harts_lock, during start proccess.
>
> Signed-off-by: Nikita Shubin 
> ---
> v1->v2:
> Sean Anderson:
> - used Kconfig description suggested by Sean - indeed more cleaner 
> and understandable
> ---
>  arch/riscv/cpu/cpu.c | 2 +-
>  arch/riscv/cpu/start.S   | 4 ++--
>  arch/riscv/include/asm/global_data.h | 2 +-
>  arch/riscv/lib/asm-offsets.c | 2 +-
>  arch/riscv/lib/smp.c | 2 +-
>  common/spl/Kconfig   | 7 +++
>  6 files changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c index 
> 9f5fa0bcb3..5d8163b19f 100644
> --- a/arch/riscv/cpu/cpu.c
> +++ b/arch/riscv/cpu/cpu.c
> @@ -19,7 +19,7 @@
>   * The variables here must be stored in the data section since they are used
>   * before the bss section is available.
>   */
> -#ifndef CONFIG_XIP
> +#if !CONFIG_IS_ENABLED(XIP)
>  u32 hart_lottery __section(".data") = 0;
>
>  /*
> diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index 
> ac81783a90..c3c859e667 100644
> --- a/arch/riscv/cpu/start.S
> +++ b/arch/riscv/cpu/start.S
> @@ -122,7 +122,7 @@ call_board_init_f_0:
>  call_harts_early_init:
> jal harts_early_init
>
> -#ifndef CONFIG_XIP
> +#if !CONFIG_IS_ENABLED(XIP)
> /*
>  * Pick hart to initialize global data and run U-Boot. The other harts
>  * wait for initialization to complete.
> @@ -150,7 +150,7 @@ call_harts_early_init:
> /* save the boot hart id to global_data */
> SREGtp, GD_BOOT_HART(gp)
>
> -#ifndef CONFIG_XIP
> +#if !CONFIG_IS_ENABLED(XIP)
> la  t0, available_harts_lock
> amoswap.w.rl zero, zero, 0(t0)
>
> diff --git a/arch/riscv/include/asm/global_data.h 
> b/arch/riscv/include/asm/global_data.h
> index 9a146d1d49..a4d3cf430b 100644
> --- a/arch/riscv/include/asm/global_data.h
> +++ b/arch/riscv/include/asm/global_data.h
> @@ -30,7 +30,7 @@ int iccm[CONFIG_NR_CPUS];  #if CONFIG_IS_ENABLED(SMP)
> struct ipi_data ipi[CONFIG_NR_CPUS];
>  #endif
> -#ifndef CONFIG_XIP
> +#if !CONFIG_IS_ENABLED(XIP)
> ulong available_harts;
>  #endif
>  };
> diff --git a/arch/riscv/lib/asm-offsets.c b/arch/riscv/lib/asm-offsets.c 
> index f1fe089b3d..c4f48c8373 100644
> --- a/arch/riscv/lib/asm-offsets.c
> +++ b/arch/riscv/lib/asm-offsets.c
> @@ -16,7 +16,7 @@ int main(void)
>  {
> DEFINE(GD_BOOT_HART, offsetof(gd_t, arch.boot_hart));
> DEFINE(GD_FIRMWARE_FDT_ADDR, offsetof(gd_t, arch.firmware_fdt_addr)); 
> -#ifndef CONFIG_XIP
> +#if !CONFIG_IS_ENABLED(XIP)
> DEFINE(GD_AVAILABLE_HARTS, offsetof(gd_t, arch.available_harts));  
> #endif
>
> diff --git a/arch/riscv/lib/smp.c b/arch/riscv/lib/smp.c index 
> ba992100ad..f8b756291f 100644
> --- a/arch/riscv/lib/smp.c
> +++ b/arch/riscv/lib/smp.c
> @@ -45,7 +45,7 @@ static int send_ipi_many(struct ipi_data *ipi, int wait)
> continue;
> }
>
> -#ifndef CONFIG_XIP
> +#if !CONFIG_IS_ENABLED(XIP)
> /* skip if hart is not available */
> if (!(gd->arch.available_harts & (1 << reg)))
> continue;
> diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 
> 07c03d611d..777eff5e47 100644
> --- a/common/spl/Kconfig
> +++ b/common/spl/Kconfig
> @@ -27,6 +27,13 @@ config SPL_FRAMEWORK
>   supports MMC, NAND and YMODEM and other methods loading of U-Boot
>   and the Linux Kernel.  If unsure, say Y.
>

Would you please move the below SPL_XIP to arch/riscv/Kconfig and
aside the CONFIG_XIP.
Since hart_lottery and available_harts_lock only be used by RISC-V currently.

And also please help to change CONFIG_XIP to CONFIG_SPL_XIP in the
following defconfig, or the behavior will be unexpected for AE350.
./ae350_rv64_spl_xip_defconfig:CONFIG_XIP=y
./ae350_rv32_spl_xip_defconfig:CONFIG_XIP=y

Other looks great for me.

Thanks,
Rick

> +config SPL_XIP
> +   bool "Enable XIP mode for SPL"
> +   help
> + Support booting SP

Re: [PATCH] fdt_support: add optional board_rng_seed() hook

2022-09-02 Thread Rasmus Villemoes
On 02/09/2022 01.52, Simon Glass wrote:
> Hi Rasmus,
> 
> On Sat, 27 Aug 2022 at 19:52, Simon Glass  wrote:
>>
>> Hi Rasmus,
>>
>> On Wed, 24 Aug 2022 at 19:25, Simon Glass  wrote:

>> I'm looking at adding full support to ofnode for reading/writing any
>> tree, not just the control FDT. I should have a series out before the
>> end of next week.
> 
> Well, I sent it and I think you saw it.

Yeah, I saw it, but unfortunately I don't have time to give it a
thorough review. But please do keep me cc'ed in case you send a new
revision.

> What shall we do with this patch? Apply it?

Well, that's probably not for me to decide (I guess Tom is), but I'd
still like it applied. It's simple, and works now, and it can always be
removed again if there's a demonstrated viable alternative.

Rasmus