Re: [PATCH 11/18] console: kconfig: Drop the redundant VIDEO dependency

2023-07-22 Thread Heinrich Schuchardt

On 7/23/23 06:40, Bin Meng wrote:

The VIDEO dependency is described twice in CONSOLE_MUX.

Signed-off-by: Bin Meng 


Reviewed-by: Heinrich Schuchardt 


---

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

diff --git a/common/Kconfig b/common/Kconfig
index 973482f075..d103bc6ddb 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -226,7 +226,7 @@ config CONSOLE_FLUSH_SUPPORT

  config CONSOLE_MUX
bool "Enable console multiplexing"
-   default y if VIDEO || VIDEO || LCD
+   default y if VIDEO || LCD
help
  This allows multiple devices to be used for each console 'file'.
  For example, stdout can be set to go to serial and video.




Re: [PATCH 13/18] console: Refactor stdio_print_current_devices() a little bit

2023-07-22 Thread Heinrich Schuchardt

On 7/23/23 06:40, Bin Meng wrote:

In preparation to future changes, refactor this routine a little bit.

Signed-off-by: Bin Meng 
---

  common/console.c | 30 +++---
  1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/common/console.c b/common/console.c
index d0640ba05a..af52897ec3 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1012,27 +1012,27 @@ int console_init_f(void)

  static void stdio_print_current_devices(void)
  {
+   char *stdinname, *stdoutname, *stderrname;
+
+   stdinname = stdio_devices[stdin] ?
+   stdio_devices[stdin]->name :
+   "No input devices available!";
+   stdoutname = stdio_devices[stdout] ?
+stdio_devices[stdout]->name :
+"No output devices available!";


This string will never be printed as you have no output device.

Best regards

Heinrich


+   stderrname = stdio_devices[stderr] ?
+stdio_devices[stderr]->name :
+"No error devices available!";
+
/* Print information */
puts("In:");
-   if (stdio_devices[stdin] == NULL) {
-   puts("No input devices available!\n");
-   } else {
-   printf ("%s\n", stdio_devices[stdin]->name);
-   }
+   printf("%s\n", stdinname);

puts("Out:   ");
-   if (stdio_devices[stdout] == NULL) {
-   puts("No output devices available!\n");
-   } else {
-   printf ("%s\n", stdio_devices[stdout]->name);
-   }
+   printf("%s\n", stdoutname);

puts("Err:   ");
-   if (stdio_devices[stderr] == NULL) {
-   puts("No error devices available!\n");
-   } else {
-   printf ("%s\n", stdio_devices[stderr]->name);
-   }
+   printf("%s\n", stderrname);
  }

  #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)




Re: [PATCH 14/18] console: Print out complete stdio device list

2023-07-22 Thread Heinrich Schuchardt

On 7/23/23 06:40, Bin Meng wrote:

At present if both CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are on,
during boot, the printed out stdio devices are incomplete, e.g.:
with "stdout=serial,vidconsole", only "vidconsole" is printed.

For such case, we can print out the stdio device name from the
environment variables.

Signed-off-by: Bin Meng 
---

  common/console.c | 30 +-
  1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/common/console.c b/common/console.c
index af52897ec3..98c3ee6ca6 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1014,15 +1014,27 @@ static void stdio_print_current_devices(void)
  {
char *stdinname, *stdoutname, *stderrname;

-   stdinname = stdio_devices[stdin] ?
-   stdio_devices[stdin]->name :
-   "No input devices available!";
-   stdoutname = stdio_devices[stdout] ?
-stdio_devices[stdout]->name :
-"No output devices available!";
-   stderrname = stdio_devices[stderr] ?
-stdio_devices[stderr]->name :
-"No error devices available!";
+   if (CONFIG_IS_ENABLED(CONSOLE_MUX) &&
+   CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)) {
+   /* stdin stdout and stderr are in environment */
+   stdinname  = env_get("stdin");
+   stdoutname = env_get("stdout");
+   stderrname = env_get("stderr");
+
+   stdinname = stdinname ? : "No input devices available!";
+   stdoutname = stdoutname ? : "No output devices available!";


This string will never be printed as you have no output device.


+   stderrname = stderrname ? : "No error devices available!";
+   } else {
+   stdinname = stdio_devices[stdin] ?
+   stdio_devices[stdin]->name :
+   "No input devices available!";
+   stdoutname = stdio_devices[stdout] ?
+   stdio_devices[stdout]->name :
+   "No output devices available!";


ditto


+   stderrname = stdio_devices[stderr] ?
+   stdio_devices[stderr]->name :
+   "No error devices available!";
+   }


do_coninfo() shows how to print all muxed devices irrespective of
SYS_CONSOLE_IS_IN_ENV.

Best regards

Heinrich



/* Print information */
puts("In:");




Re: [PATCH 18/18] riscv: qemu: Enable usb keyboard as an input device

2023-07-22 Thread Heinrich Schuchardt



Am 23. Juli 2023 06:40:41 MESZ schrieb Bin Meng :
>This brings PCI xHCI support to QEMU RISC-V and uses a usb keyboard
>as one of the input devices.
>
>Signed-off-by: Bin Meng 
>
>---
>
> board/emulation/qemu-riscv/Kconfig  | 5 +
> board/emulation/qemu-riscv/qemu-riscv.c | 5 +
> doc/board/emulation/qemu-riscv.rst  | 5 +
> include/configs/qemu-riscv.h| 2 +-
> 4 files changed, 16 insertions(+), 1 deletion(-)
>
>diff --git a/board/emulation/qemu-riscv/Kconfig 
>b/board/emulation/qemu-riscv/Kconfig
>index 7220c55350..b503578d27 100644
>--- a/board/emulation/qemu-riscv/Kconfig
>+++ b/board/emulation/qemu-riscv/Kconfig
>@@ -76,5 +76,10 @@ config BOARD_SPECIFIC_OPTIONS # dummy
>   imply VIDEO_BOCHS
>   imply SYS_WHITE_ON_BLACK
>   imply PRE_CONSOLE_BUFFER
>+  imply USB
>+  imply USB_XHCI_HCD
>+  imply USB_XHCI_PCI

QEMU could alternatively use EHCI or OHCI for the keyboard. Does enabling XHCI 
add support for these too?

Best regards

Heinrich 

>+  imply USB_KEYBOARD
>+  imply CMD_USB
> 
> endif
>diff --git a/board/emulation/qemu-riscv/qemu-riscv.c 
>b/board/emulation/qemu-riscv/qemu-riscv.c
>index f39f3be366..181abbbf97 100644
>--- a/board/emulation/qemu-riscv/qemu-riscv.c
>+++ b/board/emulation/qemu-riscv/qemu-riscv.c
>@@ -12,6 +12,7 @@
> #include 
> #include 
> #include 
>+#include 
> #include 
> #include 
> 
>@@ -41,6 +42,10 @@ int board_init(void)
> 
> int board_late_init(void)
> {
>+  /* start usb so that usb keyboard can be used as input device */
>+  if (CONFIG_IS_ENABLED(USB_KEYBOARD))
>+  usb_init();
>+
>   return 0;
> }
> 
>diff --git a/doc/board/emulation/qemu-riscv.rst 
>b/doc/board/emulation/qemu-riscv.rst
>index 9d21f3270c..61137bcbf1 100644
>--- a/doc/board/emulation/qemu-riscv.rst
>+++ b/doc/board/emulation/qemu-riscv.rst
>@@ -138,6 +138,11 @@ and adding::
> 
> -serial stdio -device VGA
> 
>+In addition, a usb keyboard can be attached to an emulated xHCI controller in
>+RISC-V virt machine as an option of input devices by adding::
>+
>+-device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0
>+
> Running with KVM
> 
> 
>diff --git a/include/configs/qemu-riscv.h b/include/configs/qemu-riscv.h
>index d5146e70f7..584559cfa3 100644
>--- a/include/configs/qemu-riscv.h
>+++ b/include/configs/qemu-riscv.h
>@@ -17,7 +17,7 @@
> 
> /* Environment options */
> 
>-#define CFG_STD_DEVICES_SETTINGS  "stdin=serial\0" \
>+#define CFG_STD_DEVICES_SETTINGS  "stdin=serial,usbkbd\0" \
>   "stdout=serial,vidconsole\0" \
>   "stderr=serial,vidconsole\0"
> 


[PATCH 13/18] console: Refactor stdio_print_current_devices() a little bit

2023-07-22 Thread Bin Meng
In preparation to future changes, refactor this routine a little bit.

Signed-off-by: Bin Meng 
---

 common/console.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/common/console.c b/common/console.c
index d0640ba05a..af52897ec3 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1012,27 +1012,27 @@ int console_init_f(void)
 
 static void stdio_print_current_devices(void)
 {
+   char *stdinname, *stdoutname, *stderrname;
+
+   stdinname = stdio_devices[stdin] ?
+   stdio_devices[stdin]->name :
+   "No input devices available!";
+   stdoutname = stdio_devices[stdout] ?
+stdio_devices[stdout]->name :
+"No output devices available!";
+   stderrname = stdio_devices[stderr] ?
+stdio_devices[stderr]->name :
+"No error devices available!";
+
/* Print information */
puts("In:");
-   if (stdio_devices[stdin] == NULL) {
-   puts("No input devices available!\n");
-   } else {
-   printf ("%s\n", stdio_devices[stdin]->name);
-   }
+   printf("%s\n", stdinname);
 
puts("Out:   ");
-   if (stdio_devices[stdout] == NULL) {
-   puts("No output devices available!\n");
-   } else {
-   printf ("%s\n", stdio_devices[stdout]->name);
-   }
+   printf("%s\n", stdoutname);
 
puts("Err:   ");
-   if (stdio_devices[stderr] == NULL) {
-   puts("No error devices available!\n");
-   } else {
-   printf ("%s\n", stdio_devices[stderr]->name);
-   }
+   printf("%s\n", stderrname);
 }
 
 #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
-- 
2.34.1



[PATCH 14/18] console: Print out complete stdio device list

2023-07-22 Thread Bin Meng
At present if both CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are on,
during boot, the printed out stdio devices are incomplete, e.g.:
with "stdout=serial,vidconsole", only "vidconsole" is printed.

For such case, we can print out the stdio device name from the
environment variables.

Signed-off-by: Bin Meng 
---

 common/console.c | 30 +-
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/common/console.c b/common/console.c
index af52897ec3..98c3ee6ca6 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1014,15 +1014,27 @@ static void stdio_print_current_devices(void)
 {
char *stdinname, *stdoutname, *stderrname;
 
-   stdinname = stdio_devices[stdin] ?
-   stdio_devices[stdin]->name :
-   "No input devices available!";
-   stdoutname = stdio_devices[stdout] ?
-stdio_devices[stdout]->name :
-"No output devices available!";
-   stderrname = stdio_devices[stderr] ?
-stdio_devices[stderr]->name :
-"No error devices available!";
+   if (CONFIG_IS_ENABLED(CONSOLE_MUX) &&
+   CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)) {
+   /* stdin stdout and stderr are in environment */
+   stdinname  = env_get("stdin");
+   stdoutname = env_get("stdout");
+   stderrname = env_get("stderr");
+
+   stdinname = stdinname ? : "No input devices available!";
+   stdoutname = stdoutname ? : "No output devices available!";
+   stderrname = stderrname ? : "No error devices available!";
+   } else {
+   stdinname = stdio_devices[stdin] ?
+   stdio_devices[stdin]->name :
+   "No input devices available!";
+   stdoutname = stdio_devices[stdout] ?
+   stdio_devices[stdout]->name :
+   "No output devices available!";
+   stderrname = stdio_devices[stderr] ?
+   stdio_devices[stderr]->name :
+   "No error devices available!";
+   }
 
/* Print information */
puts("In:");
-- 
2.34.1



[PATCH 12/18] console: Make stdio_print_current_devices() static

2023-07-22 Thread Bin Meng
As it is only called in common/console.c

Signed-off-by: Bin Meng 
---

 common/console.c| 2 +-
 include/stdio_dev.h | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/common/console.c b/common/console.c
index 71ad8efd6f..d0640ba05a 100644
--- a/common/console.c
+++ b/common/console.c
@@ -1010,7 +1010,7 @@ int console_init_f(void)
return 0;
 }
 
-void stdio_print_current_devices(void)
+static void stdio_print_current_devices(void)
 {
/* Print information */
puts("In:");
diff --git a/include/stdio_dev.h b/include/stdio_dev.h
index 77bf8a8970..7f18102052 100644
--- a/include/stdio_dev.h
+++ b/include/stdio_dev.h
@@ -84,8 +84,6 @@ int stdio_init_tables(void);
  */
 int stdio_add_devices(void);
 
-void stdio_print_current_devices(void);
-
 /**
  * stdio_deregister_dev() - deregister the device "devname".
  *
-- 
2.34.1



[PATCH 00/18] video: bochs: Remove the x86 limitation

2023-07-22 Thread Bin Meng
The Bochs VGA card emulated by QEMU does not enforce any architecture.
It was first introduced on x86 and indeed the x86 IO instruction is
used to access the legacy VGA IO ports, but that does not mean it has
to be done like this.

The first half of this series enhances the bochs video driver to
remove the x86 limitation.

The second half of this series enables bochs video as the output
console for QEMU RISC-V, to prove that the bochs video driver can
indeed work on a non-x86 architecture. To make it actually useful,
enable a usb keyboard as well, otherwise we can't just type anything :-)

This series is available at u-boot-x86/bochs for testing.


Bin Meng (17):
  dm: video: Cosmetic style fix
  video: bochs: Drop inclusion of 
  video: bochs: Drop the useless argument of bochs_vga_write()
  video: bochs: Avoid using IO instructions to access VGA IO port
  video: bochs: Remove the x86 dependency
  video: kconfig: Fix wrong text for the PCI default FB size
  video: kconfig: Drop the superfluous dependency
  video: kconfig: Set default FB size for Bochs
  video: bochs: Set the frame buffer size per configuration
  riscv: qemu: Enable Bochs video support
  console: kconfig: Drop the redundant VIDEO dependency
  console: Make stdio_print_current_devices() static
  console: Refactor stdio_print_current_devices() a little bit
  console: Print out complete stdio device list
  riscv: qemu: Enable PRE_CONSOLE_BUFFER
  riscv: qemu: Remove out-of-date "riscv,kernel-start" handling
  riscv: qemu: Enable usb keyboard as an input device

Heinrich Schuchardt (1):
  riscv: define a cache line size for the generic CPU

 arch/riscv/cpu/generic/Kconfig  |  1 +
 board/emulation/qemu-riscv/Kconfig  | 13 
 board/emulation/qemu-riscv/qemu-riscv.c | 27 +++
 common/Kconfig  |  2 +-
 common/console.c| 44 -
 doc/board/emulation/qemu-riscv.rst  | 10 ++
 drivers/video/Kconfig   | 15 +
 drivers/video/bochs.c   | 12 +++
 drivers/video/bochs.h   |  7 ++--
 drivers/video/video-uclass.c|  6 ++--
 include/configs/qemu-riscv.h| 15 +++--
 include/stdio_dev.h |  2 --
 12 files changed, 84 insertions(+), 70 deletions(-)

-- 
2.34.1



[PATCH 11/18] console: kconfig: Drop the redundant VIDEO dependency

2023-07-22 Thread Bin Meng
The VIDEO dependency is described twice in CONSOLE_MUX.

Signed-off-by: Bin Meng 
---

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

diff --git a/common/Kconfig b/common/Kconfig
index 973482f075..d103bc6ddb 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -226,7 +226,7 @@ config CONSOLE_FLUSH_SUPPORT
 
 config CONSOLE_MUX
bool "Enable console multiplexing"
-   default y if VIDEO || VIDEO || LCD
+   default y if VIDEO || LCD
help
  This allows multiple devices to be used for each console 'file'.
  For example, stdout can be set to go to serial and video.
-- 
2.34.1



[PATCH 16/18] riscv: define a cache line size for the generic CPU

2023-07-22 Thread Bin Meng
From: Heinrich Schuchardt 

The USB 3.0 driver xhci-mem.c requires CONFIG_SYS_CACHELINE_SIZE to be set.

Define the cache line size for QEMU on RISC-V to be 64 bytes.

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

 arch/riscv/cpu/generic/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/cpu/generic/Kconfig b/arch/riscv/cpu/generic/Kconfig
index 897765c3c6..2baba22992 100644
--- a/arch/riscv/cpu/generic/Kconfig
+++ b/arch/riscv/cpu/generic/Kconfig
@@ -6,6 +6,7 @@ config GENERIC_RISCV
bool
select BINMAN if SPL
select ARCH_EARLY_INIT_R
+   select SYS_CACHE_SHIFT_6
imply CPU
imply CPU_RISCV
imply RISCV_TIMER if (RISCV_SMODE || SPL_RISCV_SMODE)
-- 
2.34.1



[PATCH 18/18] riscv: qemu: Enable usb keyboard as an input device

2023-07-22 Thread Bin Meng
This brings PCI xHCI support to QEMU RISC-V and uses a usb keyboard
as one of the input devices.

Signed-off-by: Bin Meng 

---

 board/emulation/qemu-riscv/Kconfig  | 5 +
 board/emulation/qemu-riscv/qemu-riscv.c | 5 +
 doc/board/emulation/qemu-riscv.rst  | 5 +
 include/configs/qemu-riscv.h| 2 +-
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/board/emulation/qemu-riscv/Kconfig 
b/board/emulation/qemu-riscv/Kconfig
index 7220c55350..b503578d27 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -76,5 +76,10 @@ config BOARD_SPECIFIC_OPTIONS # dummy
imply VIDEO_BOCHS
imply SYS_WHITE_ON_BLACK
imply PRE_CONSOLE_BUFFER
+   imply USB
+   imply USB_XHCI_HCD
+   imply USB_XHCI_PCI
+   imply USB_KEYBOARD
+   imply CMD_USB
 
 endif
diff --git a/board/emulation/qemu-riscv/qemu-riscv.c 
b/board/emulation/qemu-riscv/qemu-riscv.c
index f39f3be366..181abbbf97 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -41,6 +42,10 @@ int board_init(void)
 
 int board_late_init(void)
 {
+   /* start usb so that usb keyboard can be used as input device */
+   if (CONFIG_IS_ENABLED(USB_KEYBOARD))
+   usb_init();
+
return 0;
 }
 
diff --git a/doc/board/emulation/qemu-riscv.rst 
b/doc/board/emulation/qemu-riscv.rst
index 9d21f3270c..61137bcbf1 100644
--- a/doc/board/emulation/qemu-riscv.rst
+++ b/doc/board/emulation/qemu-riscv.rst
@@ -138,6 +138,11 @@ and adding::
 
 -serial stdio -device VGA
 
+In addition, a usb keyboard can be attached to an emulated xHCI controller in
+RISC-V virt machine as an option of input devices by adding::
+
+-device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0
+
 Running with KVM
 
 
diff --git a/include/configs/qemu-riscv.h b/include/configs/qemu-riscv.h
index d5146e70f7..584559cfa3 100644
--- a/include/configs/qemu-riscv.h
+++ b/include/configs/qemu-riscv.h
@@ -17,7 +17,7 @@
 
 /* Environment options */
 
-#define CFG_STD_DEVICES_SETTINGS   "stdin=serial\0" \
+#define CFG_STD_DEVICES_SETTINGS   "stdin=serial,usbkbd\0" \
"stdout=serial,vidconsole\0" \
"stderr=serial,vidconsole\0"
 
-- 
2.34.1



[PATCH 17/18] riscv: qemu: Remove out-of-date "riscv, kernel-start" handling

2023-07-22 Thread Bin Meng
Commit 66ffe57 ("riscv: qemu: detect and boot the kernel passed by QEMU")
added some logic to handle "riscv,kernel-start" in DT and stored the
address to an environment variable kernel_start.

However this "riscv,kernel-start" has never been an upstream DT binding.
The upstream QEMU never generates such a DT either. Presumably U-Boot
development was based on a downstream QEMU fork.

Now we drop all codes in commit 66ffe57, except that BOARD_LATE_INIT
is kept for later use.

Signed-off-by: Bin Meng 
---

 board/emulation/qemu-riscv/qemu-riscv.c | 24 
 include/configs/qemu-riscv.h| 10 --
 2 files changed, 34 deletions(-)

diff --git a/board/emulation/qemu-riscv/qemu-riscv.c 
b/board/emulation/qemu-riscv/qemu-riscv.c
index ae3b7a3295..f39f3be366 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -41,30 +41,6 @@ int board_init(void)
 
 int board_late_init(void)
 {
-   ulong kernel_start;
-   ofnode chosen_node;
-   int ret;
-
-   chosen_node = ofnode_path("/chosen");
-   if (!ofnode_valid(chosen_node)) {
-   debug("No chosen node found, can't get kernel start address\n");
-   return 0;
-   }
-
-#ifdef CONFIG_ARCH_RV64I
-   ret = ofnode_read_u64(chosen_node, "riscv,kernel-start",
- (u64 *)&kernel_start);
-#else
-   ret = ofnode_read_u32(chosen_node, "riscv,kernel-start",
- (u32 *)&kernel_start);
-#endif
-   if (ret) {
-   debug("Can't find kernel start address in device tree\n");
-   return 0;
-   }
-
-   env_set_hex("kernel_start", kernel_start);
-
return 0;
 }
 
diff --git a/include/configs/qemu-riscv.h b/include/configs/qemu-riscv.h
index 7ec3d12ce1..d5146e70f7 100644
--- a/include/configs/qemu-riscv.h
+++ b/include/configs/qemu-riscv.h
@@ -22,22 +22,12 @@
"stderr=serial,vidconsole\0"
 
 #define BOOT_TARGET_DEVICES(func) \
-   func(QEMU, qemu, na) \
func(VIRTIO, virtio, 0) \
func(SCSI, scsi, 0) \
func(DHCP, dhcp, na)
 
 #include 
 
-#define BOOTENV_DEV_QEMU(devtypeu, devtypel, instance) \
-   "bootcmd_qemu=" \
-   "if env exists kernel_start; then " \
-   "bootm ${kernel_start} - ${fdtcontroladdr};" \
-   "fi;\0"
-
-#define BOOTENV_DEV_NAME_QEMU(devtypeu, devtypel, instance) \
-   "qemu "
-
 #define CFG_EXTRA_ENV_SETTINGS \
CFG_STD_DEVICES_SETTINGS \
"fdt_high=0x\0" \
-- 
2.34.1



[PATCH 15/18] riscv: qemu: Enable PRE_CONSOLE_BUFFER

2023-07-22 Thread Bin Meng
By default the video console only outputs messages after it's ready.
Messages before that won't show on the video console, but U-Boot has
an option to buffer the console messages before it's ready.

Enable this support, and carefully select an address for the buffer.

Signed-off-by: Bin Meng 
---

 board/emulation/qemu-riscv/Kconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/board/emulation/qemu-riscv/Kconfig 
b/board/emulation/qemu-riscv/Kconfig
index 976c350e50..7220c55350 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -25,6 +25,10 @@ config SPL_OPENSBI_LOAD_ADDR
hex
default 0x8010
 
+config PRE_CON_BUF_ADDR
+   hex
+   default 0x8100
+
 config BOARD_SPECIFIC_OPTIONS # dummy
def_bool y
select GENERIC_RISCV
@@ -71,5 +75,6 @@ config BOARD_SPECIFIC_OPTIONS # dummy
imply VIDEO
imply VIDEO_BOCHS
imply SYS_WHITE_ON_BLACK
+   imply PRE_CONSOLE_BUFFER
 
 endif
-- 
2.34.1



[PATCH 10/18] riscv: qemu: Enable Bochs video support

2023-07-22 Thread Bin Meng
Enable video console using the emulated Bochs VGA card.

Signed-off-by: Bin Meng 
---

 board/emulation/qemu-riscv/Kconfig | 3 +++
 doc/board/emulation/qemu-riscv.rst | 5 +
 include/configs/qemu-riscv.h   | 5 +
 3 files changed, 13 insertions(+)

diff --git a/board/emulation/qemu-riscv/Kconfig 
b/board/emulation/qemu-riscv/Kconfig
index 6114e1b812..976c350e50 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -68,5 +68,8 @@ config BOARD_SPECIFIC_OPTIONS # dummy
imply MTD_NOR_FLASH
imply CFI_FLASH
imply OF_HAS_PRIOR_STAGE
+   imply VIDEO
+   imply VIDEO_BOCHS
+   imply SYS_WHITE_ON_BLACK
 
 endif
diff --git a/doc/board/emulation/qemu-riscv.rst 
b/doc/board/emulation/qemu-riscv.rst
index 509bf7c4a6..9d21f3270c 100644
--- a/doc/board/emulation/qemu-riscv.rst
+++ b/doc/board/emulation/qemu-riscv.rst
@@ -133,6 +133,11 @@ An attached disk can be emulated in RISC-V virt machine by 
adding::
 
 You will have to run 'scsi scan' to use it.
 
+A video console can be emulated in RISC-V virt machine by removing "-nographic"
+and adding::
+
+-serial stdio -device VGA
+
 Running with KVM
 
 
diff --git a/include/configs/qemu-riscv.h b/include/configs/qemu-riscv.h
index f6d326bda0..7ec3d12ce1 100644
--- a/include/configs/qemu-riscv.h
+++ b/include/configs/qemu-riscv.h
@@ -17,6 +17,10 @@
 
 /* Environment options */
 
+#define CFG_STD_DEVICES_SETTINGS   "stdin=serial\0" \
+   "stdout=serial,vidconsole\0" \
+   "stderr=serial,vidconsole\0"
+
 #define BOOT_TARGET_DEVICES(func) \
func(QEMU, qemu, na) \
func(VIRTIO, virtio, 0) \
@@ -35,6 +39,7 @@
"qemu "
 
 #define CFG_EXTRA_ENV_SETTINGS \
+   CFG_STD_DEVICES_SETTINGS \
"fdt_high=0x\0" \
"initrd_high=0x\0" \
"kernel_addr_r=0x8400\0" \
-- 
2.34.1



[PATCH 09/18] video: bochs: Set the frame buffer size per configuration

2023-07-22 Thread Bin Meng
At present the uclass stored frame buffer size is set to a hard
coded value, but we can calculate the correct value based on what
is configured.

Signed-off-by: Bin Meng 
---

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

diff --git a/drivers/video/bochs.c b/drivers/video/bochs.c
index 5923ff81c6..022ea38d4c 100644
--- a/drivers/video/bochs.c
+++ b/drivers/video/bochs.c
@@ -101,8 +101,8 @@ static int bochs_video_bind(struct udevice *dev)
 {
struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev);
 
-   /* Set the maximum supported resolution */
-   uc_plat->size = 2560 * 1600 * 4;
+   /* Set the frame buffer size per configuration */
+   uc_plat->size = xsize * ysize * 32 / 8;
log_debug("%s: Frame buffer size %x\n", __func__, uc_plat->size);
 
return 0;
-- 
2.34.1



[PATCH 08/18] video: kconfig: Set default FB size for Bochs

2023-07-22 Thread Bin Meng
Set up a default frame buffer size of 8MiB for Bochs for non-x86
architecturs as PCI is normally not enumerated before relocation
on these architectures.

Signed-off-by: Bin Meng 
---

 drivers/video/Kconfig | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 3f6b7d71b8..e32ce13fb6 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -65,7 +65,8 @@ config BACKLIGHT
 config VIDEO_PCI_DEFAULT_FB_SIZE
hex "Default framebuffer size to use if no drivers request it"
default 0x100 if X86
-   default 0 if !X86
+   default 0x80 if !X86 && VIDEO_BOCHS
+   default 0 if !X86 && !VIDEO_BOCHS
help
  Generally, video drivers request the amount of memory they need for
  the frame buffer when they are bound, by setting the size field in
@@ -1037,7 +1038,8 @@ config SPL_SYS_WHITE_ON_BLACK
 config SPL_VIDEO_PCI_DEFAULT_FB_SIZE
hex "Default framebuffer size to use if no drivers request it at SPL"
default 0x100 if X86
-   default 0 if !X86
+   default 0x80 if !X86 && VIDEO_BOCHS
+   default 0 if !X86 && !VIDEO_BOCHS
help
  Generally, video drivers request the amount of memory they need for
  the frame buffer when they are bound, by setting the size field in
-- 
2.34.1



[PATCH 07/18] video: kconfig: Drop the superfluous dependency

2023-07-22 Thread Bin Meng
PCI is always selected by X86 architecture hence "X86 && PCI" does
not make it better.

Signed-off-by: Bin Meng 
---

 drivers/video/Kconfig | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 43ec7e6695..3f6b7d71b8 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -64,8 +64,8 @@ config BACKLIGHT
 
 config VIDEO_PCI_DEFAULT_FB_SIZE
hex "Default framebuffer size to use if no drivers request it"
-   default 0x100 if X86 && PCI
-   default 0 if !(X86 && PCI)
+   default 0x100 if X86
+   default 0 if !X86
help
  Generally, video drivers request the amount of memory they need for
  the frame buffer when they are bound, by setting the size field in
@@ -1036,8 +1036,8 @@ config SPL_SYS_WHITE_ON_BLACK
 
 config SPL_VIDEO_PCI_DEFAULT_FB_SIZE
hex "Default framebuffer size to use if no drivers request it at SPL"
-   default 0x100 if X86 && PCI
-   default 0 if !(X86 && PCI)
+   default 0x100 if X86
+   default 0 if !X86
help
  Generally, video drivers request the amount of memory they need for
  the frame buffer when they are bound, by setting the size field in
-- 
2.34.1



[PATCH 06/18] video: kconfig: Fix wrong text for the PCI default FB size

2023-07-22 Thread Bin Meng
There is an example in the VIDEO_PCI_DEFAULT_FB_SIZE help text to
tell people how to calculate its value but the resolution given
does not match the value. Fix it.

Signed-off-by: Bin Meng 
---

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

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 3cdaa5ff27..43ec7e6695 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -77,7 +77,7 @@ config VIDEO_PCI_DEFAULT_FB_SIZE
  devices to have a framebuffer allocated by U-Boot.
 
  Note: the framebuffer needs to be large enough to store all pixels at
- maximum resolution. For example, at 1920 x 1200 with 32 bits per
+ maximum resolution. For example, at 2560 x 1600 with 32 bits per
  pixel, 2560 * 1600 * 32 / 8 = 0xfa bytes are needed.
 
 config VIDEO_COPY
@@ -1049,7 +1049,7 @@ config SPL_VIDEO_PCI_DEFAULT_FB_SIZE
  devices to have a framebuffer allocated by U-Boot.
 
  Note: the framebuffer needs to be large enough to store all pixels at
- maximum resolution. For example, at 1920 x 1200 with 32 bits per
+ maximum resolution. For example, at 2560 x 1600 with 32 bits per
  pixel, 2560 * 1600 * 32 / 8 = 0xfa bytes are needed.
 
 config SPL_CONSOLE_SCROLL_LINES
-- 
2.34.1



[PATCH 05/18] video: bochs: Remove the x86 dependency

2023-07-22 Thread Bin Meng
Now that the driver is legacy free, remove the x86 dependency so
that it can be used on non-x86 architectures.

Signed-off-by: Bin Meng 
---

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

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index b41dc60cec..3cdaa5ff27 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -280,7 +280,6 @@ config VIDCONSOLE_AS_NAME
 
 config VIDEO_BOCHS
bool "Enable Bochs video emulation for QEMU"
-   depends on X86
help
  Enable this to use the Bochs video support provided in the QEMU
  emulator. This appears as a PCI device which U-Boot can set up to
-- 
2.34.1



[PATCH 04/18] video: bochs: Avoid using IO instructions to access VGA IO port

2023-07-22 Thread Bin Meng
At present the driver uses IO instructions to access the legacy
VGA IO ports, which unfortunately limits the driver to work only
on x86. It turns out the IO instruction is not necessary as Bochs
VGA card remaps the legacy VGA IO ports (0x3c0 -> 0x3df) to its
memory mapped register space from offset 0x400.

Update the driver to use MMIO access for VGA IO port.

Signed-off-by: Bin Meng 
---

 drivers/video/bochs.c | 6 +++---
 drivers/video/bochs.h | 4 +---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/video/bochs.c b/drivers/video/bochs.c
index 2d4526c714..5923ff81c6 100644
--- a/drivers/video/bochs.c
+++ b/drivers/video/bochs.c
@@ -27,9 +27,9 @@ static int bochs_read(void *mmio, int index)
return readw(mmio + MMIO_BASE + index * 2);
 }
 
-static void bochs_vga_write(uint8_t val)
+static void bochs_vga_write(void *mmio, int index, uint8_t val)
 {
-   outb(val, VGA_ATT_W);
+   writeb(val, mmio + VGA_BASE + index);
 }
 
 static int bochs_init_fb(struct udevice *dev)
@@ -79,7 +79,7 @@ static int bochs_init_fb(struct udevice *dev)
bochs_write(mmio, INDEX_ENABLE, ENABLED | LFB_ENABLED);
 
/* disable blanking */
-   bochs_vga_write(VGA_AR_ENABLE_DISPLAY);
+   bochs_vga_write(mmio, VGA_ATT_W - VGA_INDEX, VGA_AR_ENABLE_DISPLAY);
 
plat->base = fb;
 
diff --git a/drivers/video/bochs.h b/drivers/video/bochs.h
index 71d3d60141..3facf690e5 100644
--- a/drivers/video/bochs.h
+++ b/drivers/video/bochs.h
@@ -11,9 +11,6 @@
 #define VGA_ATT_W  0x3c0
 #define VGA_AR_ENABLE_DISPLAY  0x20
 
-#define IOPORT_INDEX   0x01ce
-#define IOPORT_DATA0x01cf
-
 enum {
INDEX_ID,
INDEX_XRES,
@@ -34,6 +31,7 @@ enum {
 #define LFB_ENABLEDBIT(6)
 #define NOCLEARMEM BIT(7)
 
+#define VGA_BASE   0x400
 #define MMIO_BASE  0x500
 
 #endif
-- 
2.34.1



[PATCH 03/18] video: bochs: Drop the useless argument of bochs_vga_write()

2023-07-22 Thread Bin Meng
bochs_vga_write() takes 'index' as one argument, but never uses it.

While we are here, use macros instead of magic numbers for the
VGA IO port register name and value.

Signed-off-by: Bin Meng 
---

 drivers/video/bochs.c | 7 ---
 drivers/video/bochs.h | 5 -
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/video/bochs.c b/drivers/video/bochs.c
index fa0283c158..2d4526c714 100644
--- a/drivers/video/bochs.c
+++ b/drivers/video/bochs.c
@@ -27,9 +27,9 @@ static int bochs_read(void *mmio, int index)
return readw(mmio + MMIO_BASE + index * 2);
 }
 
-static void bochs_vga_write(int index, uint8_t val)
+static void bochs_vga_write(uint8_t val)
 {
-   outb(val, VGA_INDEX);
+   outb(val, VGA_ATT_W);
 }
 
 static int bochs_init_fb(struct udevice *dev)
@@ -78,7 +78,8 @@ static int bochs_init_fb(struct udevice *dev)
bochs_write(mmio, INDEX_Y_OFFSET, 0);
bochs_write(mmio, INDEX_ENABLE, ENABLED | LFB_ENABLED);
 
-   bochs_vga_write(0, 0x20);   /* disable blanking */
+   /* disable blanking */
+   bochs_vga_write(VGA_AR_ENABLE_DISPLAY);
 
plat->base = fb;
 
diff --git a/drivers/video/bochs.h b/drivers/video/bochs.h
index 4c8ec83a55..71d3d60141 100644
--- a/drivers/video/bochs.h
+++ b/drivers/video/bochs.h
@@ -6,7 +6,10 @@
 #ifndef __BOCHS_H
 #define __BOCHS_H
 
-#define VGA_INDEX  0x3c0
+#define VGA_INDEX  0x3c0
+
+#define VGA_ATT_W  0x3c0
+#define VGA_AR_ENABLE_DISPLAY  0x20
 
 #define IOPORT_INDEX   0x01ce
 #define IOPORT_DATA0x01cf
-- 
2.34.1




[PATCH 02/18] video: bochs: Drop inclusion of

2023-07-22 Thread Bin Meng
The driver does not call any MTRR APIs.

Signed-off-by: Bin Meng 
---

 drivers/video/bochs.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/video/bochs.c b/drivers/video/bochs.c
index 2136b51193..fa0283c158 100644
--- a/drivers/video/bochs.c
+++ b/drivers/video/bochs.c
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include "bochs.h"
 
-- 
2.34.1



[PATCH 01/18] dm: video: Cosmetic style fix

2023-07-22 Thread Bin Meng
Some coding convention fixes for video_post_bind().

Signed-off-by: Bin Meng 
---

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

diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 949595f1bc..8f268fc406 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -626,10 +626,12 @@ static int video_post_bind(struct udevice *dev)
addr = uc_priv->video_ptr;
size = alloc_fb(dev, &addr);
if (addr < gd->video_bottom) {
-   /* Device tree node may need the 'bootph-all' or
+   /*
+* Device tree node may need the 'bootph-all' or
 * 'bootph-some-ram' tag
 */
-   printf("Video device '%s' cannot allocate frame buffer memory 
-ensure the device is set up before relocation\n",
+   printf("Video device '%s' cannot allocate frame buffer memory "
+  "- ensure the device is set up before relocation\n",
   dev->name);
return -ENOSPC;
}
-- 
2.34.1



Re: [PATCH v2 3/6] net: introduce TCP/IP6 support

2023-07-22 Thread Simon Glass
Hi Dmitrii,

On Wed, 10 May 2023 at 11:00, Dmitrii Merkurev  wrote:
>
> Add TCP/IP6 related headers and reuse refactored TCP/IP
> implementation
>
> Signed-off-by: Dmitrii Merkurev 
> Cc: Ying-Chun Liu (PaulLiu) 
> Cc: Simon Glass 
> Сс: Joe Hershberger 
> Сс: Ramon Fried 
> ---
>  include/net/tcp6.h | 106 +
>  include/net6.h |  14 ++
>  net/Makefile   |   1 +
>  net/net.c  |   6 +++
>  net/net6.c |  72 +-
>  net/tcp6.c |  99 ++
>  6 files changed, 288 insertions(+), 10 deletions(-)
>  create mode 100644 include/net/tcp6.h
>  create mode 100644 net/tcp6.c

Reviewed-by: Simon Glass 

Comments below.

>
> diff --git a/include/net/tcp6.h b/include/net/tcp6.h
> new file mode 100644
> index 00..3db125ecc5
> --- /dev/null
> +++ b/include/net/tcp6.h
> @@ -0,0 +1,106 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2022 The Android Open Source Project
> + */
> +
> +#ifndef __TCP6_H__
> +#define __TCP6_H__
> +
> +#if defined(CONFIG_PROT_TCP)

Is there anything that can be done to get rid of these, at least in
the source code?

> +
> +#include 
> +#include 
> +
> +/**
> + * typedef rxhand_tcp6_f() - An incoming TCP IPv6 packet handler.
> + * @pkt: pointer to the application packet
> + * @dport: destination TCP port
> + * @sip: source IP6 address
> + * @sport: source TCP port
> + * @tcp_seq_num: TCP sequential number
> + * @tcp_ack_num: TCP acknowledgment number
> + * @action: TCP packet type (SYN, ACK, FIN, etc)
> + */
> +typedef void rxhand_tcp6_f(uchar *pkt, u16 dport,
> +  struct in6_addr sip, u16 sport,
> +  u32 tcp_seq_num, u32 tcp_ack_num,
> +  u8 action, unsigned int len);
> +
> +/**
> + * struct ip6_tcp_hdr_o - IP6 + TCP header + TCP options
> + * @ip_hdr: IP6 + TCP header
> + * @tcp_hdr: TCP header
> + * @tcp_o: TCP options
> + * @end: end of IP6/TCP header
> + */
> +struct ip6_tcp_hdr_o {
> +   struct  ip6_hdrip_hdr;
> +   struct  tcp_hdrtcp_hdr;
> +   struct  tcp_hdr_o  tcp_o;
> +   u8  end;
> +} __packed;
> +
> +#define IP6_TCP_O_SIZE (sizeof(struct ip6_tcp_hdr_o))
> +
> +/**
> + * struct ip6_tcp_hdr_s - IP6 + TCP header + TCP options
> + * @ip_hdr: IP6 + TCP header
> + * @tcp_hdr: TCP header
> + * @t_opt: TCP Timestamp Option
> + * @sack_v: TCP SACK Option
> + * @end: end of options
> + */
> +struct ip6_tcp_hdr_s {
> +   struct  ip6_hdrip_hdr;
> +   struct  tcp_hdrtcp_hdr;
> +   struct  tcp_t_opt  t_opt;
> +   struct  tcp_sack_v sack_v;
> +   u8  end;
> +} __packed;
> +
> +#define IP6_TCP_SACK_SIZE (sizeof(struct ip6_tcp_hdr_s))
> +
> +/**
> + * union tcp6_build_pkt - union for building TCP/IP6 packet.
> + * @ip: IP6 and TCP header plus TCP options
> + * @sack: IP6 and TCP header plus SACK options
> + * @raw: buffer
> + */
> +union tcp6_build_pkt {
> +   struct ip6_tcp_hdr_o ip;
> +   struct ip6_tcp_hdr_s sack;
> +   uchar  raw[1600];
> +} __packed;
> +
> +/**
> + * net_set_tcp6_handler6() - set application TCP6 packet handler
> + * @param f pointer to callback function
> + */
> +void net_set_tcp_handler6(rxhand_tcp6_f *f);
> +
> +/**
> + * net_set_tcp_header6() - set
> + * @pkt: pointer to IP6/TCP headers
> + * @dport: destination TCP port
> + * @sport: source TCP port
> + * @payload_len: payload length
> + * @action: TCP packet type (SYN, ACK, FIN, etc)
> + * @tcp_seq_num: TCP sequential number
> + * @tcp_ack_num: TCP acknowledgment number
> + *
> + * returns TCP header size
> + */
> +int net_set_tcp_header6(uchar *pkt, u16 dport, u16 sport, int payload_len,
> +   u8 action, u32 tcp_seq_num, u32 tcp_ack_num);

Please add a full comment. We need full comments on all exported
functions and any non-trivial internal ones.

> +
> +void net_set_tcp_handler6(rxhand_tcp6_f *f);
> +
> +/**
> + * rxhand_tcp6() - handle incoming IP6 TCP packet
> + * @param b pointer to IP6/TCP packet builder struct
> + * @param len full packet length
> + */
> +void rxhand_tcp6(union tcp6_build_pkt *b, unsigned int len);
> +
> +#endif // CONFIG_PROT_TCP
> +#endif // __TCP6_H__
> diff --git a/include/net6.h b/include/net6.h
> index beafc05338..fa926f07ac 100644
> --- a/include/net6.h
> +++ b/include/net6.h
> @@ -344,6 +344,20 @@ int ip6_add_hdr(uchar *xip, struct in6_addr *src, struct 
> in6_addr *dest,
>  int net_send_udp_packet6(uchar *ether, struct in6_addr *dest, int dport,
>  int sport, int len);
>
> +/**
> + * net_send_tcp_packet6() - Make up TCP packet and send it
> + *
> + * @payload_len: TCP payload length
> + * @dport:  destination port
> + * @sport:  source port
> + * @action: TCP flag (SYN, ACL, PUSH, etc)
> + * @tcp_seq_num: TCP sequence number
> + * @tcp_ack_num: TCP ackno
> + * Return: 0 if send successfully, -1 otherwise
> + */
> +int net_send

Re: [PATCH 1/1] efi_loader: simplify dp_fill()

2023-07-22 Thread Simon Glass
Hi Heinrich,

On Fri, 21 Jul 2023 at 00:34, Heinrich Schuchardt
 wrote:
>
> Move the recursive dp_fill(dev->parent) call to a single location.
> Determine uclass_id only once.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  lib/efi_loader/efi_device_path.c | 45 +---
>  1 file changed, 18 insertions(+), 27 deletions(-)
>
> diff --git a/lib/efi_loader/efi_device_path.c 
> b/lib/efi_loader/efi_device_path.c
> index 5b050fa17c..ed7214f3a3 100644
> --- a/lib/efi_loader/efi_device_path.c
> +++ b/lib/efi_loader/efi_device_path.c
> @@ -548,14 +548,19 @@ __maybe_unused static unsigned int dp_size(struct 
> udevice *dev)
>   */
>  __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
>  {
> +   enum uclass_id uclass_id;
> +
> if (!dev || !dev->driver)
> return buf;
>
> -   switch (device_get_uclass_id(dev)) {
> +   uclass_id = device_get_uclass_id(dev);
> +   if (uclass_id != UCLASS_ROOT)

Can we fix this one now? We should use EFI_MEDIA here I think?

> +   buf = dp_fill(buf, dev->parent);
> +
> +   switch (uclass_id) {
>  #ifdef CONFIG_NETDEVICES
> case UCLASS_ETH: {
> -   struct efi_device_path_mac_addr *dp =
> -   dp_fill(buf, dev->parent);

So how does the parent part get added? I am missing something
here...or it was it never needed??

> +   struct efi_device_path_mac_addr *dp = buf;
> struct eth_pdata *pdata = dev_get_plat(dev);
>
[..]

Regards,
Simon


Re: [PATCH v2 5/6] net: add fastboot TCP documentation and IP6-only mode

2023-07-22 Thread Simon Glass
Hi Dmitrii,

On Wed, 10 May 2023 at 11:00, Dmitrii Merkurev  wrote:
>
> Command to start IP6 only TCP fastboot:
> fastboot tcp -ipv6
>
> Signed-off-by: Dmitrii Merkurev 
> Cc: Ying-Chun Liu (PaulLiu) 
> Cc: Simon Glass 
> Сс: Joe Hershberger 
> Сс: Ramon Fried 
> ---
>  cmd/fastboot.c   | 29 +
>  doc/android/fastboot.rst |  8 +++-
>  2 files changed, 32 insertions(+), 5 deletions(-)

Reviewed-by: Simon Glass 

Can you please add a doc/usage/cmd/fastboot.rst as well? Can be a
separate patch.

Regards,
Simon


Re: [PATCH v8 21/23] binman: Overwrite symlink if it already exists

2023-07-22 Thread Simon Glass
On Fri, 21 Jul 2023 at 12:47, Neha Malcom Francis  wrote:
>
> From: Andrew Davis 
>
> Without this re-building will fail with an error when trying to create
> the symlink for the second time with an already exists error.
>
> Signed-off-by: Andrew Davis 
> [n-fran...@ti.com: Added support for test output dir and testcase]
> Signed-off-by: Neha Malcom Francis 
> ---
>  tools/binman/ftest.py | 18 --
>  tools/binman/image.py |  2 ++
>  2 files changed, 18 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH] board_f: Cosmetic style fix

2023-07-22 Thread Simon Glass
On Fri, 21 Jul 2023 at 10:15, Bin Meng  wrote:
>
> Some coding convention fixes for print_resetinfo().
>
> Signed-off-by: Bin Meng 
> ---
>
>  common/board_f.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH 1/1] spl: blk: partition numbers are hexadecimal

2023-07-22 Thread Simon Glass
On Sat, 22 Jul 2023 at 04:46, Heinrich Schuchardt
 wrote:
>
> Loading u-boot.itb from device 0x00, partition 0x0f fails with:
>
> Trying to boot from NVME
>
> Device 0: Vendor: 0x4x Rev: 8.0.50   Prod: nvme-1
> Type: Hard Disk
> Capacity: 3814.6 MB = 3.7 GB (7812500 x 512)
> ** Invalid partition 21 **
> Couldn't find partition nvme 0:15
>
> Like the command line interface fs_det_blk_dev() expects that the device
> number and the partition number are hexadecimal.
>
> Fixes: 8ce6a2e17577 ("spl: blk: Support loading images from fs")
> Signed-off-by: Heinrich Schuchardt 
> ---
>  common/spl/spl_blk_fs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH] rockchip: veyron: Enable Winbond SPI flash

2023-07-22 Thread Simon Glass
On Fri, 21 Jul 2023 at 02:46, Alper Nebi Yasak  wrote:
>
> Some veyron boards seem to have Winbond SPI flash chips instead of
> GigaDevice ones. At the very least, coreboot builds for veyron boards
> have them enabled [1]. Enable support for them here as well.
>
> [1] https://review.coreboot.org/c/coreboot/+/9719
>
> Signed-off-by: Alper Nebi Yasak 
> ---
>
>  configs/chromebit_mickey_defconfig  | 1 +
>  configs/chromebook_jerry_defconfig  | 1 +
>  configs/chromebook_minnie_defconfig | 1 +
>  configs/chromebook_speedy_defconfig | 1 +
>  4 files changed, 4 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH v2 6/6] net: update net_ip6 from link_local address when eth device is changed

2023-07-22 Thread Simon Glass
On Wed, 10 May 2023 at 11:00, Dmitrii Merkurev  wrote:
>
> Current active eth device may be changed (due to ethprime), so make
> sure current net_ip6 is updated as a reaction.
>
> Signed-off-by: Dmitrii Merkurev 
> Cc: Ying-Chun Liu (PaulLiu) 
> Cc: Simon Glass 
> Сс: Joe Hershberger 
> Сс: Ramon Fried 
> ---
>  net/net.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 4/6] net: add fastboot TCP6 support

2023-07-22 Thread Simon Glass
Hi Dmitrii,

On Wed, 10 May 2023 at 11:00, Dmitrii Merkurev  wrote:
>
> fastboot tcp command remains the same, but started
> listening IP6 in case it's enabled.
>
> Signed-off-by: Dmitrii Merkurev 
> Cc: Ying-Chun Liu (PaulLiu) 
> Cc: Simon Glass 
> Сс: Joe Hershberger 
> Сс: Ramon Fried 
> ---
>  include/net/fastboot_tcp.h |  2 +-
>  net/fastboot_tcp.c | 72 --
>  2 files changed, 62 insertions(+), 12 deletions(-)
>
> diff --git a/include/net/fastboot_tcp.h b/include/net/fastboot_tcp.h
> index 6cf29d52e9..98986fa10a 100644
> --- a/include/net/fastboot_tcp.h
> +++ b/include/net/fastboot_tcp.h
> @@ -7,7 +7,7 @@
>  #define __NET_FASTBOOT_TCP_H__
>
>  /**
> - * Wait for incoming tcp fastboot comands.
> + * Wait for incoming TCP fastboot comands.
>   */
>  void fastboot_tcp_start_server(void);
>
> diff --git a/net/fastboot_tcp.c b/net/fastboot_tcp.c
> index 2eb52ea256..d93b52ede5 100644
> --- a/net/fastboot_tcp.c
> +++ b/net/fastboot_tcp.c
> @@ -6,8 +6,10 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
> +#include 
>
>  static char command[FASTBOOT_COMMAND_LEN] = {0};
>  static char response[FASTBOOT_RESPONSE_LEN] = {0};
> @@ -20,18 +22,30 @@ static u16 curr_dport;
>  static u32 curr_tcp_seq_num;
>  static u32 curr_tcp_ack_num;
>  static unsigned int curr_request_len;
> +static bool is_ipv6;
> +static size_t ip_header_size;
>  static enum fastboot_tcp_state {
> FASTBOOT_CLOSED,
> FASTBOOT_CONNECTED,
> FASTBOOT_DISCONNECTING
>  } state = FASTBOOT_CLOSED;
>
> +static int command_handled_id;
> +static bool command_handled_success;
> +
>  static void fastboot_tcp_answer(u8 action, unsigned int len)
>  {
> const u32 response_seq_num = curr_tcp_ack_num;
> const u32 response_ack_num = curr_tcp_seq_num +
>   (curr_request_len > 0 ? curr_request_len : 1);
>
> +#if defined(CONFIG_IPV6)

Can you use if() here?

> +   if (is_ipv6) {
> +   net_send_tcp_packet6(len, htons(curr_sport), 
> htons(curr_dport),
> +action, response_seq_num, 
> response_ack_num);
> +   return;
> +   }
> +#endif
> net_send_tcp_packet(len, htons(curr_sport), htons(curr_dport),
> action, response_seq_num, response_ack_num);
>  }
> @@ -47,7 +61,7 @@ static void fastboot_tcp_send_packet(u8 action, const uchar 
> *data, unsigned int
> uchar *pkt = net_get_async_tx_pkt_buf();
>
> memset(pkt, '\0', PKTSIZE);
> -   pkt += net_eth_hdr_size() + IP_TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2;
> +   pkt += net_eth_hdr_size() + ip_header_size + TCP_HDR_SIZE + 
> TCP_TSOPT_SIZE + 2;
> memcpy(pkt, data, len);
> fastboot_tcp_answer(action, len);
> memset(pkt, '\0', PKTSIZE);
> @@ -59,7 +73,7 @@ static void fastboot_tcp_send_message(const char *message, 
> unsigned int len)
> uchar *pkt = net_get_async_tx_pkt_buf();
>
> memset(pkt, '\0', PKTSIZE);
> -   pkt += net_eth_hdr_size() + IP_TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2;
> +   pkt += net_eth_hdr_size() + ip_header_size + TCP_HDR_SIZE + 
> TCP_TSOPT_SIZE + 2;
> // Put first 8 bytes as a big endian message length
> memcpy(pkt, &len_be, 8);
> pkt += 8;
> @@ -68,10 +82,9 @@ static void fastboot_tcp_send_message(const char *message, 
> unsigned int len)
> memset(pkt, '\0', PKTSIZE);
>  }
>

[..]
 +
>  void fastboot_tcp_start_server(void)
>  {
> printf("Using %s device\n", eth_get_name());
> -   printf("Listening for fastboot command on tcp %pI4\n", &net_ip);
>
> +   printf("Listening for fastboot command on tcp %pI4\n", &net_ip);
> tcp_set_tcp_handler(fastboot_tcp_handler_ipv4);
> +
> +#if defined(CONFIG_IPV6)
> +   printf("Listening for fastboot command on %pI6\n", &net_ip6);
> +   net_set_tcp_handler6(fastboot_tcp_handler_ipv6);
> +#endif

and here. This needs some thought as we don't want to add #if to C
code where possible.

Regards,
Simon


Re: [PATCH v2 2/6] net: prepare existing TCP stack to be reused by IP6

2023-07-22 Thread Simon Glass
Hi Dmitrii,

On Wed, 10 May 2023 at 11:00, Dmitrii Merkurev  wrote:
>
> Changes:
> 1. Separate reusable part from net_set_tcp_header to
> net_set_tcp_header_common
> 2. Make TCP signatures reusable by receiving particular
> IP agnostic TCP headers
> 3. Extract net_send_ip_packet6 from net_send_udp_packet6
> to reuse the code
> 4. Expose TCP state machine related functions
>
> This allows us to reuse TCP logic between IP and IP6 stack.
>
> Signed-off-by: Dmitrii Merkurev 
> Cc: Ying-Chun Liu (PaulLiu) 
> Cc: Simon Glass 
> Сс: Joe Hershberger 
> Сс: Ramon Fried 
> ---
>  include/net/tcp.h | 109 +--
>  net/net.c |  18 ++-
>  net/net6.c|  78 ---
>  net/tcp.c | 337 --
>  4 files changed, 372 insertions(+), 170 deletions(-)

Reviewed-by: Simon Glass 

While you are here, or in a follow-up patch, can you please add full
comments to net_set_ip_header(), e,g. what is the pkt param exactly?
The whole packet, before any headers?


Re: [PATCH v2 1/6] net: split IP_TCP header into separate IP/IP6 and TCP headers

2023-07-22 Thread Simon Glass
On Wed, 24 May 2023 at 15:19, Ying-Chun Liu (PaulLiu)
 wrote:
>
> Reviewed-by: Ying-Chun Liu (PaulLiu) 
>
> On 2023/5/11 00:59, Dmitrii Merkurev wrote:
> > This allows us to reuse TCP logic between IP and IP6 stack.
> >
> > Signed-off-by: Dmitrii Merkurev 
> > Cc: Ying-Chun Liu (PaulLiu) 
> > Cc: Simon Glass 
> > Сс: Joe Hershberger 
> > Сс: Ramon Fried 
> > ---
> >   include/net/tcp.h | 54 
> >   net/tcp.c | 70 +++
> >   test/cmd/wget.c   | 48 ++--
> >   3 files changed, 85 insertions(+), 87 deletions(-)
> >

Reviewed-by: Simon Glass 


Re: [PATCH v2 1/7] power: regulator: expand basic reference counter onto all uclass

2023-07-22 Thread Simon Glass
Hi Svyatoslav,

On Thu, 20 Jul 2023 at 23:23, Svyatoslav Ryhel  wrote:
>
> чт, 20 лип. 2023 р. о 22:43 Simon Glass  пише:
> >
> > Hi Svyatoslav,
> >
> > On Thu, 20 Jul 2023 at 06:38, Svyatoslav Ryhel  wrote:
> > >
> > > Commit is based on 4fcba5d ("regulator: implement basic reference
> > > counter") but expands the idea to all regulators instead of just
> > > fixed/gpio regulators.
> > >
> > > Signed-off-by: Svyatoslav Ryhel 
> > > ---
> > >  drivers/power/regulator/regulator-uclass.c | 41 ++
> > >  drivers/power/regulator/regulator_common.c | 22 
> > >  drivers/power/regulator/regulator_common.h | 21 ---
> > >  include/power/regulator.h  |  2 ++
> > >  4 files changed, 43 insertions(+), 43 deletions(-)
> >
> > Reviewed-by: Simon Glass 
> >
> > nit below
> >
> > >
> > > diff --git a/drivers/power/regulator/regulator-uclass.c 
> > > b/drivers/power/regulator/regulator-uclass.c
> > > index 3a6ba69f6d..fc7a4631b4 100644
> > > --- a/drivers/power/regulator/regulator-uclass.c
> > > +++ b/drivers/power/regulator/regulator-uclass.c
> > > @@ -159,6 +159,25 @@ int regulator_get_enable(struct udevice *dev)
> > > return ops->get_enable(dev);
> > >  }
> > >
> > > +/*
> > > + * Enable or Disable a regulator
> > > + *
> > > + * This is a reentrant function and subsequent calls that enable will
> > > + * increase an internal counter, and disable calls will decrease the 
> > > counter.
> > > + * The actual resource will be enabled when the counter gets to 1 coming 
> > > from 0,
> > > + * and disabled when it reaches 0 coming from 1.
> > > + *
> > > + * @dev: regulator device
> > > + * @enable: bool indicating whether to enable or disable the regulator
> > > + * @return:
> > > + * 0 on Success
> > > + * -EBUSY if the regulator cannot be disabled because it's requested by
> > > + *another device
> > > + * -EALREADY if the regulator has already been enabled or has already 
> > > been
> > > + *disabled
> > > + * -EACCES if there is no possibility to enable/disable the regulator
> > > + * -ve on different error situation
> > > + */
> > >  int regulator_set_enable(struct udevice *dev, bool enable)
> > >  {
> > > const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
> > > @@ -172,6 +191,23 @@ int regulator_set_enable(struct udevice *dev, bool 
> > > enable)
> > > if (!enable && uc_pdata->always_on)
> > > return -EACCES;
> > >
> > > +   /* If previously enabled, increase count */
> > > +   if (enable && uc_pdata->enable_count > 0) {
> > > +   uc_pdata->enable_count++;
> > > +   return -EALREADY;
> > > +   }
> > > +
> > > +   if (!enable) {
> > > +   if (uc_pdata->enable_count > 1) {
> > > +   /* If enabled multiple times, decrease count */
> > > +   uc_pdata->enable_count--;
> > > +   return -EBUSY;
> > > +   } else if (!uc_pdata->enable_count) {
> > > +   /* If already disabled, do nothing */
> > > +   return -EALREADY;
> > > +   }
> > > +   }
> > > +
> > > if (uc_pdata->ramp_delay)
> > > old_enable = regulator_get_enable(dev);
> > >
> > > @@ -187,6 +223,11 @@ int regulator_set_enable(struct udevice *dev, bool 
> > > enable)
> > > }
> > > }
> > >
> > > +   if (enable)
> > > +   uc_pdata->enable_count++;
> > > +   else
> > > +   uc_pdata->enable_count--;
> > > +
> > > return ret;
> > >  }
> > >
> > > diff --git a/drivers/power/regulator/regulator_common.c 
> > > b/drivers/power/regulator/regulator_common.c
> > > index e26f5ebec3..d88bc6f6de 100644
> > > --- a/drivers/power/regulator/regulator_common.c
> > > +++ b/drivers/power/regulator/regulator_common.c
> > > @@ -72,23 +72,6 @@ int regulator_common_set_enable(const struct udevice 
> > > *dev,
> > > return 0;
> > > }
> > >
> > > -   /* If previously enabled, increase count */
> > > -   if (enable && plat->enable_count > 0) {
> > > -   plat->enable_count++;
> > > -   return -EALREADY;
> > > -   }
> > > -
> > > -   if (!enable) {
> > > -   if (plat->enable_count > 1) {
> > > -   /* If enabled multiple times, decrease count */
> > > -   plat->enable_count--;
> > > -   return -EBUSY;
> > > -   } else if (!plat->enable_count) {
> > > -   /* If already disabled, do nothing */
> > > -   return -EALREADY;
> > > -   }
> > > -   }
> > > -
> > > ret = dm_gpio_set_value(&plat->gpio, enable);
> > > if (ret) {
> > > pr_err("Can't set regulator : %s gpio to: %d\n", 
> > > dev->name,
> > > @@ -103,10 +86,5 @@ int regulator_common_set_enable(const struct udevice 
> > > *dev,
> > > 

Re: [PATCH v3 00/11] Sign Xilinx ZynqMP SPL/FSBL boot images using binman

2023-07-22 Thread Simon Glass
Hi Michal,

On Fri, 21 Jul 2023 at 08:41, Michal Simek  wrote:
>
>
>
> On 7/18/23 13:53, lukas.funke-...@weidmueller.com wrote:
> > From: Lukas Funke 
> >
> >
> > This series adds two etypes to create a verified boot chain for
> > Xilinx ZynqMP devices. The first etype 'xilinx-fsbl-auth' is used to
> > create a bootable, signed image for ZynqMP boards using the Xilinx
> > Bootgen tool. The second etype 'u-boot-spl-pubkey-dtb' is used to add
> > a '/signature' node to the SPL. The public key in the signature is read
> > from a certificate file and added using the 'fdt_add_pubkey' tool. The
> > series also contains the corresponding btool for calling 'bootgen' and
> > 'fdt_add_pubkey'.
> >
> > The following block shows an example on how to use this functionality:
> >
> >  spl {
> >  filename = "boot.signed.bin";
> >
> >  xilinx-fsbl-auth {
> >  psk-key-name-hint = "psk0";
> >  ssk-key-name-hint = "ssk0";
> >  auth-params = "ppk_select=0", "spk_id=0x";
> >
> >  u-boot-spl-nodtb {
> >  };
> >  u-boot-spl-pubkey-dtb {
> >  algo = "sha384,rsa4096";
> >  required = "conf";
> >  key-name-hint = "dev";
> >  };
> >  };
> >  };
> >
>
> I was looking at binman couple of times in past but never had time to do any
> development with it. Maybe it is good opportunity to look at it now with this
> series.
> Is there a way to see more verbose output?
>

https://u-boot.readthedocs.io/en/latest/develop/package/binman.html#logging

> I expect that keys should be generated as is described here.
>
> https://docs.xilinx.com/r/en-US/ug1283-bootgen-user-guide/Key-Generation?tocId=yf_PWbWVciRyrDMi2g1H1w
>
> Anyway I tried to use u-boot-spl-nodtb like this.
>
> &binman {
> spl {
> filename = "boot.signed.bin";
>
> xilinx-fsbl-auth {
> psk-key-name-hint = "/tmp/ddd/psk0";
> ssk-key-name-hint = "/tmp/ddd/ssk0";
> auth-params = "ppk_select=0", "spk_id=0x";
> pmufw-filename = 
> "/mnt/disk/u-boot-bins/zynqmp/zynqmp-zcu102-revA/pmufw.elf";
>
> u-boot-spl-nodtb {
> };
> };
> };
> };
>
> but getting error
>BINMAN  .binman_stamp
> Using input directories ['.', '.', './board/xilinx/zynqmp', 'arch/arm/dts']
> Using output directory '.'
> Processing entry args:
>  of-list = avnet-ultra96-rev1 zynqmp-a2197-revA
> zynqmp-e-a2197-00-revA zynqmp-g-a2197-00-revA zynqmp-m-a2197-01-revA
> zynqmp-m-a2197-02-revA zynqmp-m-a2197-03-revA zynqmp-p-a2197-00-revA
> zynqmp-zc1232-revA zynqmp-zc1254-revA zynqmp-zc1751-xm015-dc1
> zynqmp-zc1751-xm016-dc2 zynqmp-zc1751-xm017-dc3 zynqmp-zc1751-xm018-dc4
> zynqmp-zc1751-xm019-dc5 zynqmp-zcu100-revC zynqmp-zcu102-rev1.1
> zynqmp-zcu102-rev1.0 zynqmp-zcu102-revA zynqmp-zcu102-revB zynqmp-zcu104-revA
> zynqmp-zcu104-revC zynqmp-zcu106-revA zynqmp-zcu106-rev1.0 zynqmp-zcu111-revA
> zynqmp-zcu1275-revA zynqmp-zcu1275-revB zynqmp-zcu1285-revA zynqmp-zcu208-revA
> zynqmp-zcu216-revA zynqmp-topic-miamimp-xilinx-xdp-v1r1 zynqmp-sm-k26-revA
> zynqmp-smk-k26-revA zynqmp-dlc21-revA
>atf-bl31-path = /tftpboot/bl31.bin
>  tee-os-path = /tftpboot/tee.bin
> opensbi-path =
>   default-dt = zynqmp-zcu100-revC
> scp-path =
>rockchip-tpl-path =
>  spl-bss-pad =
>  tpl-bss-pad = 1
>  spl-dtb = y
>  tpl-dtb =
>pre-load-key-path =
> Processing entry args done
> Node '/binman/spl/xilinx-fsbl-auth/u-boot-spl-nodtb': Packing: offset=None,
> size=None, content_size=240d8
> Node '/binman/spl/xilinx-fsbl-auth/u-boot-spl-nodtb':- packed: offset=0x0,
> size=0x240d8, content_size=0x240d8, next_offset=240d8
> Node '/binman/spl/xilinx-fsbl-auth/u-boot-spl-nodtb': GetData: size 0x240d8
> Node '/binman/spl/xilinx-fsbl-auth': GetPaddedDataForEntry: size None
> Node '/binman/spl/xilinx-fsbl-auth': GetData: 1 entries, total size 0x240d8
> bintool: bootgen -arch zynqmp -image ./bootgen-in.sign.bif -w -o
> ./boot.spl.xilinx-fsbl-auth.bin
>
>
> ** Xilinx Bootgen v2022.2.0
> Build date : Oct 13 2022-12:22:43
>  ** Copyright 1986-2022 Xilinx, Inc. All Rights Reserved.
>
> [WARNING]: Authentication padding scheme will be as per silicon 2.0(ES2) and
> above. The image generated will NOT work for 1.0(ES1).
>Use '-zynqmpes1' to generate image for 1.0(ES1)
>
> [INFO]   : Bootimage generated successfully

BTW tools are not allowed to generate output normally, so this will
need to be suppressed somehow by the binman btool.

Regards,
Simon


Re: [PATCH v2 2/9] cmd: boot: implement PMIC based poweroff

2023-07-22 Thread Simon Glass
Hi Svyatoslav,

On Thu, 20 Jul 2023 at 02:48, Svyatoslav Ryhel  wrote:
>
> Use new PMIC ops to perform device poweroff.
>
> Signed-off-by: Svyatoslav Ryhel 
> ---
>  cmd/Kconfig |  6 ++
>  cmd/boot.c  | 40 
>  2 files changed, 46 insertions(+)
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index ecfd575237..47654297f8 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1439,6 +1439,12 @@ config CMD_POWEROFF
> help
>   Poweroff/Shutdown the system
>
> +config CMD_PMIC_POWEROFF
> +   bool "PMIC poweroff"
> +   select CMD_POWEROFF
> +   help
> + Shutdown the system using PMIC poweroff sequence.
> +
>  config CMD_READ
> bool "read - Read binary data from a partition"
> help
> diff --git a/cmd/boot.c b/cmd/boot.c
> index 14839c1ced..4270034194 100644
> --- a/cmd/boot.c
> +++ b/cmd/boot.c
> @@ -9,7 +9,13 @@
>   */
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
> +#include 
> +#include 
> +#include 
> +#include 
>
>  #ifdef CONFIG_CMD_GO
>
> @@ -64,6 +70,40 @@ U_BOOT_CMD(
>  );
>
>  #ifdef CONFIG_CMD_POWEROFF
> +#ifdef CONFIG_CMD_PMIC_POWEROFF
> +int do_poweroff(struct cmd_tbl *cmdtp, int flag,
> +   int argc, char *const argv[])
> +{
> +   struct uc_pmic_priv *pmic_priv;
> +   struct udevice *dev;
> +   int ret;
> +
> +   for (uclass_find_first_device(UCLASS_PMIC, &dev);
> +dev;
> +uclass_find_next_device(&dev)) {
> +   if (dev && !device_active(dev)) {
> +   ret = device_probe(dev);
> +   if (ret)
> +   return ret;
> +   }
> +
> +   /* value we need to check is set after probe */
> +   pmic_priv = dev_get_uclass_priv(dev);
> +   if (pmic_priv->sys_pow_ctrl) {
> +   ret = pmic_poweroff(dev);
> +
> +   /* wait some time and then print error */
> +   mdelay(5000);
> +   log_err("Failed to power off!!!\n");
> +   return ret;
> +   }
> +   }
> +
> +   /* no device should reach here */
> +   return 1;
> +}
> +#endif
> +
>  U_BOOT_CMD(
> poweroff, 1, 0, do_poweroff,
> "Perform POWEROFF of the device",
> --
> 2.39.2
>

How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and
do_poweroff() in cmd/boot.c?

Regards,
Simon


Re: [PATCH 1/1] doc: update coc/sphinx/requirements.txt

2023-07-22 Thread Simon Glass
On Thu, 20 Jul 2023 at 14:13, Heinrich Schuchardt
 wrote:

subject: doc:


>
> Update the following requirements to their latest version:
>
> * Pygments - syntax highlighting
> * pytz - world timezone definitions
> * certifi  - Mozilla's CA bundle
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  doc/sphinx/requirements.txt | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/doc/sphinx/requirements.txt b/doc/sphinx/requirements.txt
> index aed4492117..b74661ad3f 100644
> --- a/doc/sphinx/requirements.txt
> +++ b/doc/sphinx/requirements.txt
> @@ -1,6 +1,6 @@
>  alabaster==0.7.12
>  Babel==2.9.1
> -certifi==2022.12.7
> +certifi==2023.5.7
>  charset-normalizer==2.0.12
>  docutils==0.16
>  idna==3.3
> @@ -8,9 +8,9 @@ imagesize==1.3.0
>  Jinja2==3.0.3
>  MarkupSafe==2.1.1
>  packaging==21.3
> -Pygments==2.11.2
> +Pygments==2.15.1
>  pyparsing==3.0.7
> -pytz==2022.1
> +pytz==2023.3
>  requests==2.31.0
>  six==1.16.0
>  snowballstemmer==2.2.0
> --
> 2.40.1
>


Strange construct in binman description

2023-07-22 Thread Simon Glass
Hi Marcel,

I just noticed this in an imx8 description:

binman_configuration: @config-SEQ {

Since this is a generator node, binman blindly generates a phandle for
each not it generates. This means that if there is more than one
config node, then they will have duplicate phandles.

I have sent a series to correct this, but it fails the build on:
imx8mm_venice imx8mn_venice imx8mp_venice

I am a bit unsure about what this is supposed to do. Could you please
take a look?

Regards,
Simon


[PATCH v2 6/6] binman: Support templates containing phandles

2023-07-22 Thread Simon Glass
This provides support for phandles to be copied over from templates. This
is not quite safe, since if the template is instantiated twice (i.e. in
two different nodes), then duplicate phandles will be found. This will
result in an error.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Refine support for phandles to deal with duplicates
- Add a test that deals with duplicate phandles

 tools/binman/binman.rst   | 18 +
 tools/binman/control.py   |  4 ++
 tools/binman/ftest.py | 27 
 tools/binman/test/291_template_phandle.dts| 51 +++
 .../binman/test/292_template_phandle_dup.dts  | 65 +++
 5 files changed, 165 insertions(+)
 create mode 100644 tools/binman/test/291_template_phandle.dts
 create mode 100644 tools/binman/test/292_template_phandle_dup.dts

diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index 147fbc5ff1b9..aeea33fddb95 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -1264,6 +1264,24 @@ The initial devicetree produced by the templating 
process is written to the
 a failure before the final `u-boot.dtb.out` file is written. A second
 `u-boot.dtb.tmpl2` file is written when the templates themselves are removed.
 
+Dealing with phandles
+-
+
+Templates can contain phandles and these are copied to the destination node.
+However this should be used with care, since if a template is instantiated 
twice
+then the phandle will be copied twice, resulting in a devicetree with duplicate
+phandles, i.e. the same phandle used by two different nodes. Binman detects 
this
+situation and produces an error, for example::
+
+  Duplicate phandle 1 in nodes /binman/image/fit/images/atf/atf-bl31 and
+  /binman/image-2/fit/images/atf/atf-bl31
+
+In this case an atf-bl31 node containing a phandle has been copied into two
+different target nodes, resulting in the same phandle for each. See
+testTemplatePhandleDup() for the test case.
+
+The solution is typically to put the phandles in the corresponding target nodes
+(one for each) and remove the phandle from the template.
 
 Updating an ELF file
 
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 3857f50e6436..6a6d247e6969 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -567,6 +567,10 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, 
update_fdt, use_expanded):
 
 _RemoveTemplates(node)
 dtb.Sync(True)
+
+# Rescan the dtb to pick up the new phandles
+dtb.Scan()
+node = _FindBinmanNode(dtb)
 fname = tools.get_output_filename('u-boot.dtb.tmpl2')
 tools.write_file(fname, dtb.GetContents())
 
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 7ea4797ad6ac..5a2cf9baf9cf 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -6900,6 +6900,33 @@ fdt fdtmapExtract the devicetree 
blob from the fdtmap
 # Move to next
 spl_data = content[:0x18]
 
+def testTemplatePhandle(self):
+"""Test using a template in a node containing a phandle"""
+entry_args = {
+'atf-bl31-path': 'bl31.elf',
+}
+data = self._DoReadFileDtb('291_template_phandle.dts',
+   entry_args=entry_args)
+fname = tools.get_output_filename('image.bin')
+out = tools.run('dumpimage', '-l', fname)
+
+# We should see the FIT description and one for each of the two images
+lines = out.splitlines()
+descs = [line.split()[-1] for line in lines if 'escription' in line]
+self.assertEqual(['test-desc', 'atf', 'fdt'], descs)
+
+def testTemplatePhandleDup(self):
+"""Test using a template in a node containing a phandle"""
+entry_args = {
+'atf-bl31-path': 'bl31.elf',
+}
+with self.assertRaises(ValueError) as e:
+self._DoReadFileDtb('292_template_phandle_dup.dts',
+entry_args=entry_args)
+self.assertIn(
+'Duplicate phandle 1 in nodes 
/binman/image/fit/images/atf/atf-bl31 and 
/binman/image-2/fit/images/atf/atf-bl31',
+str(e.exception))
+
 
 if __name__ == "__main__":
 unittest.main()
diff --git a/tools/binman/test/291_template_phandle.dts 
b/tools/binman/test/291_template_phandle.dts
new file mode 100644
index ..c4ec1dd41bed
--- /dev/null
+++ b/tools/binman/test/291_template_phandle.dts
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   binman {
+   multiple-images;
+
+   ti_spl_template: template-1 {
+   fit {
+   description = "test-desc";
+   #address-cells = <1>;
+   images {
+

[PATCH v2 5/6] binman: Remove templates after use

2023-07-22 Thread Simon Glass
It is not necessary to keep templates around after they have been
processed. They can cause confusion and potentially duplicate phandles.

Remove them.

Use the same means of detecting a template node in _ReadImageDesc so that
the two places are consistent.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/binman.rst |  8 +---
 tools/binman/control.py | 14 +-
 tools/binman/ftest.py   |  7 +++
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index 67bc3e87531b..147fbc5ff1b9 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -1256,11 +1256,13 @@ Properties in the template node are inserted into the 
destination node if they
 do not exist there. In the example above, `some-property` is added to each of
 `spi-image` and `mmc-image`.
 
+Note that template nodes are removed from the binman description after
+processing and before binman builds the image descriptions.
+
 The initial devicetree produced by the templating process is written to the
 `u-boot.dtb.tmpl1` file. This can be useful to see what is going on if there is
-a failure before the final `u-boot.dtb.out` file is written.
-
-Note that template nodes are not removed from the binman description at 
present.
+a failure before the final `u-boot.dtb.out` file is written. A second
+`u-boot.dtb.tmpl2` file is written when the templates themselves are removed.
 
 
 Updating an ELF file
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 9a9a4817eeaf..3857f50e6436 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -57,7 +57,7 @@ def _ReadImageDesc(binman_node, use_expanded):
 images = OrderedDict()
 if 'multiple-images' in binman_node.props:
 for node in binman_node.subnodes:
-if 'template' not in node.name:
+if not node.name.startswith('template'):
 images[node.name] = Image(node.name, node,
   use_expanded=use_expanded)
 else:
@@ -511,6 +511,13 @@ def _ProcessTemplates(parent):
 found |= _ProcessTemplates(node)
 return found
 
+def _RemoveTemplates(parent):
+"""Remove any templates in the binman description
+"""
+for node in parent.subnodes:
+if node.name.startswith('template'):
+node.Delete()
+
 def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded):
 """Prepare the images to be processed and select the device tree
 
@@ -558,6 +565,11 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, 
update_fdt, use_expanded):
 fname = tools.get_output_filename('u-boot.dtb.tmpl1')
 tools.write_file(fname, dtb.GetContents())
 
+_RemoveTemplates(node)
+dtb.Sync(True)
+fname = tools.get_output_filename('u-boot.dtb.tmpl2')
+tools.write_file(fname, dtb.GetContents())
+
 images = _ReadImageDesc(node, use_expanded)
 
 if select_images:
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 80d41cf5c35f..7ea4797ad6ac 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -6802,6 +6802,13 @@ fdt fdtmapExtract the devicetree 
blob from the fdtmap
 vga = dtb.GetNode('/binman/first/intel-vga')
 self.assertTrue(vga)
 
+dtb_fname2 = tools.get_output_filename('u-boot.dtb.tmpl2')
+self.assertTrue(os.path.exists(dtb_fname2))
+dtb2 = fdt.Fdt.FromData(tools.read_file(dtb_fname2))
+dtb2.Scan()
+node2 = dtb2.GetNode('/binman/template')
+self.assertFalse(node2)
+
 def testTemplateBlobMulti(self):
 """Test using a template with 'multiple-images' enabled"""
 TestFunctional._MakeInputFile('my-blob.bin', b'blob')
-- 
2.41.0.487.g6d72f3e995-goog



[PATCH v2 4/6] fdt: Allow copying phandles into templates

2023-07-22 Thread Simon Glass
Allow phandles to be copied over from a template. This can potentially
cause duplicate phandles, so detect this and report an error.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Handle phandle copying property and report duplicates

 tools/dtoc/fdt.py  | 28 +++-
 tools/dtoc/test_fdt.py | 21 +
 2 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index f6a9dee0db12..5963925146a5 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -337,6 +337,11 @@ class Node:
 self.props = self._fdt.GetProps(self)
 phandle = fdt_obj.get_phandle(self.Offset())
 if phandle:
+dup = self._fdt.phandle_to_node.get(phandle)
+if dup:
+raise ValueError(
+f'Duplicate phandle {phandle} in nodes {dup.path} and 
{self.path}')
+
 self._fdt.phandle_to_node[phandle] = self
 
 offset = fdt_obj.first_subnode(self.Offset(), QUIET_NOTFOUND)
@@ -707,11 +712,12 @@ class Node:
 prop.Sync(auto_resize)
 return added
 
-def merge_props(self, src):
+def merge_props(self, src, copy_phandles):
 """Copy missing properties (except 'phandle') from another node
 
 Args:
 src (Node): Node containing properties to copy
+copy_phandles (bool): True to copy phandle properties in nodes
 
 Adds properties which are present in src but not in this node. Any
 'phandle' property is not copied since this might result in two nodes
@@ -720,21 +726,24 @@ class Node:
 tout.debug(f'copy to {self.path}: {src.path}')
 for name, src_prop in src.props.items():
 done = False
-if name != 'phandle' and name not in self.props:
-self.props[name] = Prop(self, None, name, src_prop.bytes)
-done = True
+if name not in self.props:
+if copy_phandles or name != 'phandle':
+self.props[name] = Prop(self, None, name, src_prop.bytes)
+done = True
 tout.debug(f"  {name}{'' if done else '  - ignored'}")
 
-def copy_node(self, src):
+def copy_node(self, src, copy_phandles=False):
 """Copy a node and all its subnodes into this node
 
 Args:
 src (Node): Node to copy
+copy_phandles (bool): True to copy phandle properties in nodes
 
 Returns:
 Node: Resulting destination node
 
-This works recursively.
+This works recursively, with copy_phandles being set to True for the
+recursive calls
 
 The new node is put before all other nodes. If the node already
 exists, just its subnodes and properties are copied, placing them 
before
@@ -746,12 +755,12 @@ class Node:
 dst.move_to_first()
 else:
 dst = self.insert_subnode(src.name)
-dst.merge_props(src)
+dst.merge_props(src, copy_phandles)
 
 # Process in reverse order so that they appear correctly in the result,
 # since copy_node() puts the node first in the list
 for node in reversed(src.subnodes):
-dst.copy_node(node)
+dst.copy_node(node, True)
 return dst
 
 def copy_subnodes_from_phandles(self, phandle_list):
@@ -774,7 +783,7 @@ class Node:
 dst = self.copy_node(node)
 
 tout.debug(f'merge props from {parent.path} to {dst.path}')
-self.merge_props(parent)
+self.merge_props(parent, False)
 
 
 class Fdt:
@@ -835,6 +844,7 @@ class Fdt:
 
 TODO(s...@chromium.org): Implement the 'root' parameter
 """
+self.phandle_to_node = {}
 self._cached_offsets = True
 self._root = self.Node(self, None, 0, '/', '/')
 self._root.Scan()
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index f77e48b54eaf..0b01518f3a5b 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -340,8 +340,8 @@ class TestNode(unittest.TestCase):
 over = dtb.GetNode('/dest/base/over')
 self.assertTrue(over)
 
-# Make sure that the phandle for 'over' is not copied
-self.assertNotIn('phandle', over.props.keys())
+# Make sure that the phandle for 'over' is copied
+self.assertIn('phandle', over.props.keys())
 
 second = dtb.GetNode('/dest/base/second')
 self.assertTrue(second)
@@ -349,7 +349,7 @@ class TestNode(unittest.TestCase):
  [n.name for n in chk.subnodes])
 self.assertEqual(chk, over.parent)
 self.assertEqual(
-{'bootph-all', 'compatible', 'reg', 'low-power'},
+{'bootph-all', 'compatible', 'reg', 'low-power', 'phandle'},
 over.props.keys())
 
 if expect_none:
@@ -385,9 +385,22 @@ class TestNode(unittest.TestCa

[PATCH v2 3/6] dtoc: Add some debugging when copying nodes

2023-07-22 Thread Simon Glass
Show the operations being performed, when debugging is enabled.

Convert a mistaken 'print' in test_copy_subnodes_from_phandles() while we
are here.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Use a 'done' variable to reduce code duplication

 tools/dtoc/fdt.py  | 5 +
 tools/dtoc/test_fdt.py | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 2589be990ae9..f6a9dee0db12 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -249,6 +249,7 @@ class Prop:
 """
 if self.dirty:
 node = self._node
+tout.debug(f'sync {node.path}: {self.name}')
 fdt_obj = node._fdt._fdt_obj
 node_name = fdt_obj.get_name(node._offset)
 if node_name and node_name != node.name:
@@ -716,9 +717,13 @@ class Node:
 'phandle' property is not copied since this might result in two nodes
 with the same phandle, thus making phandle references ambiguous.
 """
+tout.debug(f'copy to {self.path}: {src.path}')
 for name, src_prop in src.props.items():
+done = False
 if name != 'phandle' and name not in self.props:
 self.props[name] = Prop(self, None, name, src_prop.bytes)
+done = True
+tout.debug(f"  {name}{'' if done else '  - ignored'}")
 
 def copy_node(self, src):
 """Copy a node and all its subnodes into this node
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 84dcd8b5caa5..f77e48b54eaf 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -32,6 +32,7 @@ from dtoc.fdt import Type, BytesToValue
 import libfdt
 from u_boot_pylib import test_util
 from u_boot_pylib import tools
+from u_boot_pylib import tout
 
 #pylint: disable=protected-access
 
@@ -414,7 +415,7 @@ class TestNode(unittest.TestCase):
 
 # Make sure that the phandle for 'over' is not copied
 over = dst.FindNode('over')
-print('keys', over.props.keys())
+tout.debug(f'keys: {over.props.keys()}')
 self.assertNotIn('phandle', over.props.keys())
 
 # Check the merged properties, first the base ones in '/dest'
-- 
2.41.0.487.g6d72f3e995-goog



[PATCH v2 2/6] dtoc: Make properties dirty when purging them

2023-07-22 Thread Simon Glass
Without the 'dirty' flag properties are not written back to the
devicetree when synced. This means that new properties copied over to a
node are not always written out.

Fix this and add a test.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/fdt.py  |  1 +
 tools/dtoc/test/dtoc_test_copy.dts |  6 --
 tools/dtoc/test_fdt.py | 16 +---
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index fd0f3e94f5c0..2589be990ae9 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -272,6 +272,7 @@ class Prop:
 the FDT is synced
 """
 self._offset = None
+self.dirty = True
 
 class Node:
 """A device tree node
diff --git a/tools/dtoc/test/dtoc_test_copy.dts 
b/tools/dtoc/test/dtoc_test_copy.dts
index 36faa9b72b56..8e50c7565928 100644
--- a/tools/dtoc/test/dtoc_test_copy.dts
+++ b/tools/dtoc/test/dtoc_test_copy.dts
@@ -37,11 +37,12 @@
new-prop;
};
 
-   second1 {
+   second1: second1 {
new-prop;
};
 
second4 {
+   use_second1 = <&second1>;
};
};
};
@@ -65,12 +66,13 @@
};
 
second: second {
-   second1 {
+   second_1_bad: second1 {
some-prop;
};
 
second2 {
some-prop;
+   use_second1_bad = <&second_1_bad>;
};
};
};
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 3e54694eec9f..84dcd8b5caa5 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -308,7 +308,7 @@ class TestNode(unittest.TestCase):
 
 def test_copy_node(self):
 """Test copy_node() function"""
-def do_copy_checks(dtb, dst, expect_none):
+def do_copy_checks(dtb, dst, second1_ph_val, expect_none):
 self.assertEqual(
 ['/dest/base', '/dest/first@0', '/dest/existing'],
 [n.path for n in dst.subnodes])
@@ -365,12 +365,22 @@ class TestNode(unittest.TestCase):
 ['second1', 'second2', 'second3', 'second4'],
 [n.name for n in second.subnodes])
 
+# Check the 'second_1_bad' phandle is not copied over
+second1 = second.FindNode('second1')
+self.assertTrue(second1)
+sph = second1.props.get('phandle')
+self.assertTrue(sph)
+self.assertEqual(second1_ph_val, sph.bytes)
+
+
 dtb = fdt.FdtScan(find_dtb_file('dtoc_test_copy.dts'))
 tmpl = dtb.GetNode('/base')
 dst = dtb.GetNode('/dest')
+second1_ph_val = (dtb.GetNode('/dest/base/second/second1').
+  props['phandle'].bytes)
 dst.copy_node(tmpl)
 
-do_copy_checks(dtb, dst, expect_none=True)
+do_copy_checks(dtb, dst, second1_ph_val, expect_none=True)
 
 dtb.Sync(auto_resize=True)
 
@@ -378,7 +388,7 @@ class TestNode(unittest.TestCase):
 new_dtb = fdt.Fdt.FromData(dtb.GetContents())
 new_dtb.Scan()
 dst = new_dtb.GetNode('/dest')
-do_copy_checks(new_dtb, dst, expect_none=False)
+do_copy_checks(new_dtb, dst, second1_ph_val, expect_none=False)
 
 def test_copy_subnodes_from_phandles(self):
 """Test copy_node() function"""
-- 
2.41.0.487.g6d72f3e995-goog



[PATCH v2 1/6] binman: Produce a template-file after processing

2023-07-22 Thread Simon Glass
This file aids debugging when binman fails to get far enough to write out
the final devicetree file. Write it immediate after template processing.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/binman.rst |  4 
 tools/binman/control.py | 14 --
 tools/binman/ftest.py   |  9 +
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index 8f57b6cfc76f..67bc3e87531b 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -1256,6 +1256,10 @@ Properties in the template node are inserted into the 
destination node if they
 do not exist there. In the example above, `some-property` is added to each of
 `spi-image` and `mmc-image`.
 
+The initial devicetree produced by the templating process is written to the
+`u-boot.dtb.tmpl1` file. This can be useful to see what is going on if there is
+a failure before the final `u-boot.dtb.out` file is written.
+
 Note that template nodes are not removed from the binman description at 
present.
 
 
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 25e66814837d..9a9a4817eeaf 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -486,6 +486,9 @@ def _ProcessTemplates(parent):
 Args:
 parent: Binman node to process (typically /binman)
 
+Returns:
+bool: True if any templates were processed
+
 Search though each target node looking for those with an 'insert-template'
 property. Use that as a list of references to template nodes to use to
 adjust the target node.
@@ -498,11 +501,15 @@ def _ProcessTemplates(parent):
 
 See 'Templates' in the Binman documnentation for details.
 """
+found = False
 for node in parent.subnodes:
 tmpl = fdt_util.GetPhandleList(node, 'insert-template')
 if tmpl:
 node.copy_subnodes_from_phandles(tmpl)
-_ProcessTemplates(node)
+found = True
+
+found |= _ProcessTemplates(node)
+return found
 
 def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded):
 """Prepare the images to be processed and select the device tree
@@ -546,7 +553,10 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, 
update_fdt, use_expanded):
 raise ValueError("Device tree '%s' does not have a 'binman' "
 "node" % dtb_fname)
 
-_ProcessTemplates(node)
+if _ProcessTemplates(node):
+dtb.Sync(True)
+fname = tools.get_output_filename('u-boot.dtb.tmpl1')
+tools.write_file(fname, dtb.GetContents())
 
 images = _ReadImageDesc(node, use_expanded)
 
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index e53181afb78a..80d41cf5c35f 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -6793,6 +6793,15 @@ fdt fdtmapExtract the devicetree 
blob from the fdtmap
 second = U_BOOT_DATA + b'#' + VGA_DATA + U_BOOT_DTB_DATA
 self.assertEqual(U_BOOT_IMG_DATA + first + second, data)
 
+dtb_fname1 = tools.get_output_filename('u-boot.dtb.tmpl1')
+self.assertTrue(os.path.exists(dtb_fname1))
+dtb = fdt.Fdt.FromData(tools.read_file(dtb_fname1))
+dtb.Scan()
+node1 = dtb.GetNode('/binman/template')
+self.assertTrue(node1)
+vga = dtb.GetNode('/binman/first/intel-vga')
+self.assertTrue(vga)
+
 def testTemplateBlobMulti(self):
 """Test using a template with 'multiple-images' enabled"""
 TestFunctional._MakeInputFile('my-blob.bin', b'blob')
-- 
2.41.0.487.g6d72f3e995-goog



[PATCH v2 0/6] binman: Template fixes and improvements

2023-07-22 Thread Simon Glass
With the basic template feature in place, some problems have come to
light.

Firstly, keeping the template around while processing entries seems
unnecessary and perhaps confusing, so this is removed.

Secondly this series aims to support phandles in a more intuitive way,
rather than just ignoring them in templates. It includes an experimental
patch to copy phandles from template so that it is possible to so
something like:

   template {
  some_node: some-node {
  };
   };

   image {
  insert-template = <&template>;
   };

with the some_node phandle being copied to the 'image' node, to result in:

   image {
  insert-template = <&template>;

  some_node: some-node {
  };
   };


Changes in v2:
- Use a 'done' variable to reduce code duplication
- Handle phandle copying property and report duplicates
- Refine support for phandles to deal with duplicates
- Add a test that deals with duplicate phandles

Simon Glass (6):
  binman: Produce a template-file after processing
  dtoc: Make properties dirty when purging them
  dtoc: Add some debugging when copying nodes
  fdt: Allow copying phandles into templates
  binman: Remove templates after use
  binman: Support templates containing phandles

 tools/binman/binman.rst   | 26 +++-
 tools/binman/control.py   | 32 -
 tools/binman/ftest.py | 43 
 tools/binman/test/291_template_phandle.dts| 51 +++
 .../binman/test/292_template_phandle_dup.dts  | 65 +++
 tools/dtoc/fdt.py | 34 +++---
 tools/dtoc/test/dtoc_test_copy.dts|  6 +-
 tools/dtoc/test_fdt.py| 40 +---
 8 files changed, 274 insertions(+), 23 deletions(-)
 create mode 100644 tools/binman/test/291_template_phandle.dts
 create mode 100644 tools/binman/test/292_template_phandle_dup.dts

-- 
2.41.0.487.g6d72f3e995-goog



Re: [PATCH 1/5] x86: fsp: Use mtrr_set_next_var() for graphics memory

2023-07-22 Thread Simon Glass
Hi Bin,

On Fri, 21 Jul 2023 at 10:12, Bin Meng  wrote:
>
> At present this uses mtrr_add_request() & mtrr_commit() combination
> to program the MTRR for graphics memory. This usage has two major
> issues as below:
>
> - mtrr_commit() will re-initialize all MTRR registers from index 0,
>   using the settings previously added by mtrr_add_request() and saved
>   in gd->arch.mtrr_req[], which won't cause any issue but is unnecessary
> - The way such combination works is based on the assumption that U-Boot
>   has full control with MTRR programming (e.g.: U-Boot without any blob
>   that does all low-level initialization on its own, or using FSP2 which
>   does not touch MTRR), but this is not the case with FSP. FSP programs
>   some MTRRs during its execution but U-Boot does not have the settings
>   saved in gd->arch.mtrr_req[] and when doing mtrr_commit() it will
>   corrupt what was already programmed previously.
>
> Correct this to use mtrr_set_next_var() instead.
>
> Signed-off-by: Bin Meng 
> ---
>
>  arch/x86/lib/fsp/fsp_graphics.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

Thanks for looking into this. The series works fine on link. I suspect
it will be find on samus too, but I cannot test right now. Sadly
minnowmax is also dead right now but I hope to fix it soon. I don't
expect any problems there.

However, for coral, this first patch breaks the mtrrs. With master we get:

=> mtrr
CPU 0:
Reg Valid Write-type   Base   ||Mask   ||Size   ||
0   Y Back fef0 0078 0008
1   Y Back fef8 007c 0004
2   Y Back  007f8000 8000
3   Y Combine  b000 007ff000 1000
4   Y Back 0001 007f8000 8000
5   N Uncacheable    0080
6   N Uncacheable    0080
7   N Uncacheable    0080
8   N Uncacheable    0080
9   N Uncacheable    0080

with this patch on coral we get:

=> mtrr
CPU 0:
Reg Valid Write-type   Base   ||Mask   ||Size   ||
0   Y Back fef0 0078 0008
1   Y Back fef8 007c 0004
2   Y Combine  b000 007ff000 1000
3   N Uncacheable    0080

At present coral expects to handle the MTRRs itself, and it seems that
perhaps the APL FSPv2 does not? Do we need a new Kconfig for dealing
with FSPv2 perhaps?

Regards,
Simon


Re: [PATCH 1/1] riscv: qemu: provide more SPL boot methods

2023-07-22 Thread Heinrich Schuchardt




On 7/22/23 16:22, Bin Meng wrote:

Hi Heinrich,

On Sat, Jul 22, 2023 at 7:10 PM Heinrich Schuchardt
 wrote:


QEMU can supply block devices or semihosting to U-Boot SPL. Allow booting
from these.

Signed-off-by: Heinrich Schuchardt 
---
  board/emulation/qemu-riscv/qemu-riscv.c | 17 ++---
  1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/board/emulation/qemu-riscv/qemu-riscv.c 
b/board/emulation/qemu-riscv/qemu-riscv.c
index ae3b7a3295..b2fe3e9f0c 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -69,10 +69,21 @@ int board_late_init(void)
  }

  #ifdef CONFIG_SPL
-u32 spl_boot_device(void)
+void board_boot_order(u32 *spl_boot_list)
  {
-   /* RISC-V QEMU only supports RAM as SPL boot device */
-   return BOOT_DEVICE_RAM;
+   int index = 0;
+
+   if (IS_ENABLED(CONFIG_SPL_NVME))
+   spl_boot_list[index++] = BOOT_DEVICE_NVME;
+   if (IS_ENABLED(CONFIG_SPL_SATA))
+   spl_boot_list[index++] = BOOT_DEVICE_SATA;
+   if (IS_ENABLED(CONFIG_SPL_USB_STORAGE))
+   spl_boot_list[index++] = BOOT_DEVICE_USB;
+   if (IS_ENABLED(CONFIG_SPL_SEMIHOSTING))
+   spl_boot_list[index++] = BOOT_DEVICE_SMH;
+   /* RAM last as CONFIG_SPL_RAW_IMAGE_SUPPORT=y may lead to crash */
+   if (IS_ENABLED(CONFIG_SPL_RAM_SUPPORT))
+   spl_boot_list[index++] = BOOT_DEVICE_RAM;
  }
  #endif



Please include instructions on how to boot U-Boot proper from these
additional devices in qemu-riscv.rst


A general description of SPL boot methods seems to be lacking. This 
should include relevant configuration settings. But as this is not QEMU 
or RISC-V specific this information should live in a different place 
(doc/usage/).


There are a few fixes that should be accepted before writing the 
documentation:


Partition code has a bug:

part: check CONFIG_IS_ENABLED(ENV_SUPPORT)
https://lore.kernel.org/u-boot/20230721233418.GG3630934@bill-the-cat/T/#t

For Semihosting FIT support is missing:

[PATCH 1/1] spl: add FIT support to semihosting boot method
https://lore.kernel.org/u-boot/20230722192748.52856-1-heinrich.schucha...@canonical.com/T/#u

NVMe uses the wrong configuration variable:

[PATCH 1/1] spl: blk: use CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
https://lore.kernel.org/u-boot/20230721120943.23931-1-heinrich.schucha...@canonical.com/T/#u

NVMe uses incorrect partition numbers:

[PATCH 1/1] spl: blk: partition numbers are hexadecimal
https://lore.kernel.org/u-boot/20230722104544.52217-1-heinrich.schucha...@canonical.com/T/#u

SATA must call pci_init():

[PATCH 1/1] spl: initialize PCI before booting from SATA
https://lore.kernel.org/u-boot/20230722215702.125114-1-heinrich.schucha...@canonical.com/T/#u

With the fixes I am able to boot u-boot.itb with any of the boot methods 
in this patch.


Best regards

Heinrich


[PATCH 1/1] spl: initialize PCI before booting from SATA

2023-07-22 Thread Heinrich Schuchardt
Many SATA controllers are PCI bus devices. Before calling scsi_scan() we
must bind the PCI devices.

Signed-off-by: Heinrich Schuchardt 
---
 common/spl/spl_sata.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c
index 32746ce9f3..060da49006 100644
--- a/common/spl/spl_sata.c
+++ b/common/spl/spl_sata.c
@@ -61,6 +61,8 @@ static int spl_sata_load_image(struct spl_image_info 
*spl_image,
struct blk_desc *stor_dev;
 
/* try to recognize storage devices immediately */
+   if (IS_ENABLED(CONFIG_SPL_PCI))
+   pci_init();
scsi_scan(false);
stor_dev = blk_get_devnum_by_uclass_id(UCLASS_SCSI, 0);
if (!stor_dev)
-- 
2.40.1



Re: [PATCH 1/1] spl: spl_legacy: simplify spl_parse_legacy_validate

2023-07-22 Thread Heinrich Schuchardt




On 7/22/23 21:09, Marek Vasut wrote:

On 7/22/23 20:46, Heinrich Schuchardt wrote:

The check for an overlap of the loaded image and SPL is overly
complicated.

Fixes: 77aed22b48ab ("spl: spl_legacy: Add extra address checks")
Signed-off-by: Heinrich Schuchardt 
---
  common/spl/spl_legacy.c | 5 +
  1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index 095443c63d..9246f555e3 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -22,10 +22,7 @@ static void spl_parse_legacy_validate(uintptr_t 
start, uintptr_t size)

  uintptr_t spl_end = (uintptr_t)_image_binary_end;
  uintptr_t end = start + size;
-    if ((start >= spl_start && start < spl_end) ||
-    (end > spl_start && end <= spl_end) ||
-    (start < spl_start && end >= spl_end) ||
-    (start > end && end > spl_start))
+    if (end > spl_start && start < spl_end)
  panic("SPL: Image overlaps SPL\n");
  if (size > CONFIG_SYS_BOOTM_LEN)


Does this handle address space wrap around ? This:

=blob=|..|=blob=
.|==spl==|..

Hint: it does not.


The replaced code does not handle wrap around where end is below 
spl_start. The following code would cover all cases of image wrap around:


+   if (end > spl_start && start < spl_end
+   panic("SPL: Image overlaps SPL\n");
+   if (start >= end)
+   panic("SPL: Image wraps around\n");

I guess we don't have to test for spl_start >= spl_end.



+CC Rasmus.

Look at all the other checks in U-Boot which do, and first factor them 


Which other instances do you refer to?

The lmb library does not to check for wrap around but the wrap around 
checks would have to be in other places than lmb_addrs_overlap().


Best regards

Heinrich

out into one check functions, so we can improve on that one. Second, use 
that function all over the place. Third, improve on it.


[RFC PATCH v2 4/4] arm: dts: k3-am625-sk-u-boot.dtsi: drop cpsw-phy-sel property

2023-07-22 Thread Roger Quadros
This was a custom property and we don't need it anymore.
We are now using the standard property "phys" to get the
PHY port control register.

Signed-off-by: Roger Quadros 
---
 arch/arm/dts/k3-am625-sk-u-boot.dtsi | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/arch/arm/dts/k3-am625-sk-u-boot.dtsi 
b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
index 54fdabdb8e..d33c2fca3d 100644
--- a/arch/arm/dts/k3-am625-sk-u-boot.dtsi
+++ b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
@@ -128,14 +128,7 @@
 };
 
 &cpsw3g {
-   /delete-property/ ranges;
bootph-pre-ram;
-
-   cpsw-phy-sel@04044 {
-   compatible = "ti,am64-phy-gmii-sel";
-   reg = <0x0 0x00104044 0x0 0x8>;
-   bootph-pre-ram;
-   };
 };
 
 &cpsw_port1 {
-- 
2.34.1



[RFC PATCH v2 3/4] arm: dts: k3-am625-sk-u-boot.dtsi: drop mac_efuse

2023-07-22 Thread Roger Quadros
This was a custom property and we don't need it anymore.
We are now using the standard property "ti,syscon-efuse".

Signed-off-by: Roger Quadros 
---
 arch/arm/dts/k3-am625-sk-u-boot.dtsi | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/arm/dts/k3-am625-sk-u-boot.dtsi 
b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
index 249155733a..54fdabdb8e 100644
--- a/arch/arm/dts/k3-am625-sk-u-boot.dtsi
+++ b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
@@ -128,9 +128,6 @@
 };
 
 &cpsw3g {
-   reg = <0x0 0x800 0x0 0x20>,
- <0x0 0x43000200 0x0 0x8>;
-   reg-names = "cpsw_nuss", "mac_efuse";
/delete-property/ ranges;
bootph-pre-ram;
 
-- 
2.34.1



[PATCH v2 2/4] net: ti: am65-cpsw-nuss: Get port mode register from standard "phys" property

2023-07-22 Thread Roger Quadros
Approved DT binding has the port mode register in the
"phys" property. Get it from there instead of the custom
"cpsw-phy-sel" property.

This will allow us to keep DT in sync with Linux.

Signed-off-by: Roger Quadros 
---
 drivers/net/ti/am65-cpsw-nuss.c | 63 +++--
 1 file changed, 37 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
index ee46676ec8..ce52106e52 100644
--- a/drivers/net/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ti/am65-cpsw-nuss.c
@@ -102,7 +102,6 @@ struct am65_cpsw_common {
fdt_addr_t  cpsw_base;
fdt_addr_t  mdio_base;
fdt_addr_t  ale_base;
-   fdt_addr_t  gmii_sel;
 
struct clk  fclk;
struct power_domain pwrdmn;
@@ -232,18 +231,37 @@ out:
 
 #define AM65_GMII_SEL_RGMII_IDMODE BIT(4)
 
-static void am65_cpsw_gmii_sel_k3(struct am65_cpsw_priv *priv,
- phy_interface_t phy_mode, int slave)
+static int am65_cpsw_gmii_sel_k3(struct am65_cpsw_priv *priv,
+phy_interface_t phy_mode)
 {
-   struct am65_cpsw_common *common = priv->cpsw_common;
-   fdt_addr_t gmii_sel = common->gmii_sel + AM65_GMII_SEL_PORT_OFFS(slave);
-   u32 reg;
-   u32 mode = 0;
+   struct udevice *dev = priv->dev;
+   u32 offset, reg, phandle;
bool rgmii_id = false;
+   fdt_addr_t gmii_sel;
+   u32 mode = 0;
+   ofnode node;
+   int ret;
+
+   ret = ofnode_read_u32(dev_ofnode(dev), "phys", &phandle);
+   if (ret)
+   return ret;
+
+   ret = ofnode_read_u32_index(dev_ofnode(dev), "phys", 1, &offset);
+   if (ret)
+   return ret;
+
+   node = ofnode_get_by_phandle(phandle);
+   if (!ofnode_valid(node))
+   return -ENODEV;
+
+   gmii_sel = ofnode_get_addr(node);
+   if (gmii_sel == FDT_ADDR_T_NONE)
+   return -ENODEV;
 
+   gmii_sel += AM65_GMII_SEL_PORT_OFFS(offset);
reg = readl(gmii_sel);
 
-   dev_dbg(common->dev, "old gmii_sel: %08x\n", reg);
+   dev_dbg(dev, "old gmii_sel: %08x\n", reg);
 
switch (phy_mode) {
case PHY_INTERFACE_MODE_RMII:
@@ -262,7 +280,7 @@ static void am65_cpsw_gmii_sel_k3(struct am65_cpsw_priv 
*priv,
break;
 
default:
-   dev_warn(common->dev,
+   dev_warn(dev,
 "Unsupported PHY mode: %u. Defaulting to MII.\n",
 phy_mode);
/* fallthrough */
@@ -275,15 +293,19 @@ static void am65_cpsw_gmii_sel_k3(struct am65_cpsw_priv 
*priv,
mode |= AM65_GMII_SEL_RGMII_IDMODE;
 
reg = mode;
-   dev_dbg(common->dev, "gmii_sel PHY mode: %u, new gmii_sel: %08x\n",
+   dev_dbg(dev, "gmii_sel PHY mode: %u, new gmii_sel: %08x\n",
phy_mode, reg);
writel(reg, gmii_sel);
 
reg = readl(gmii_sel);
-   if (reg != mode)
-   dev_err(common->dev,
+   if (reg != mode) {
+   dev_err(dev,
"gmii_sel PHY mode NOT SET!: requested: %08x, gmii_sel: 
%08x\n",
mode, reg);
+   return 0;
+   }
+
+   return 0;
 }
 
 static int am65_cpsw_start(struct udevice *dev)
@@ -708,7 +730,9 @@ static int am65_cpsw_port_probe(struct udevice *dev)
if (ret)
goto out;
 
-   am65_cpsw_gmii_sel_k3(priv, pdata->phy_interface, priv->port_id);
+   ret = am65_cpsw_gmii_sel_k3(priv, pdata->phy_interface);
+   if (ret)
+   goto out;
 
ret = am65_cpsw_mdio_init(dev);
if (ret)
@@ -803,19 +827,6 @@ static int am65_cpsw_probe_nuss(struct udevice *dev)
   AM65_CPSW_CPSW_NU_PORT_MACSL_OFFSET;
}
 
-   node = dev_read_subnode(dev, "cpsw-phy-sel");
-   if (!ofnode_valid(node)) {
-   dev_err(dev, "can't find cpsw-phy-sel\n");
-   ret = -ENOENT;
-   goto out;
-   }
-
-   cpsw_common->gmii_sel = ofnode_get_addr(node);
-   if (cpsw_common->gmii_sel == FDT_ADDR_T_NONE) {
-   dev_err(dev, "failed to get gmii_sel base\n");
-   goto out;
-   }
-
cpsw_common->bus_freq =
dev_read_u32_default(dev, "bus_freq",
 AM65_CPSW_MDIO_BUS_FREQ_DEF);
-- 
2.34.1



[PATCH v2 1/4] net: ti: am65-cpsw-nuss: Use approved property to get efuse address

2023-07-22 Thread Roger Quadros
The approved DT property for MAC efuse (ROM) address is
"ti,syscon-efuse".

Use that and drop custom property "mac_efuse".

Signed-off-by: Roger Quadros 
---
 drivers/net/ti/Kconfig  |  1 +
 drivers/net/ti/am65-cpsw-nuss.c | 52 +++--
 2 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index e13dbc9401..d9f1c019a8 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -43,6 +43,7 @@ config TI_AM65_CPSW_NUSS
depends on ARCH_K3
imply MISC_INIT_R
imply MISC
+   imply SYSCON
select PHYLIB
help
  This driver supports TI K3 MCU CPSW Nuss Ethernet controller
diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
index 523a4c9f91..ee46676ec8 100644
--- a/drivers/net/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ti/am65-cpsw-nuss.c
@@ -21,7 +21,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 
@@ -101,7 +103,6 @@ struct am65_cpsw_common {
fdt_addr_t  mdio_base;
fdt_addr_t  ale_base;
fdt_addr_t  gmii_sel;
-   fdt_addr_t  mac_efuse;
 
struct clk  fclk;
struct power_domain pwrdmn;
@@ -516,24 +517,45 @@ static void am65_cpsw_stop(struct udevice *dev)
common->started = false;
 }
 
+static int am65_cpsw_am654_get_efuse_macid(struct udevice *dev,
+  int slave, u8 *mac_addr)
+{
+   u32 mac_lo, mac_hi, offset;
+   struct regmap *syscon;
+   int ret;
+
+   syscon = syscon_regmap_lookup_by_phandle(dev, "ti,syscon-efuse");
+   if (IS_ERR(syscon)) {
+   if (PTR_ERR(syscon) == -ENODEV)
+   return 0;
+   return PTR_ERR(syscon);
+   }
+
+   ret = dev_read_u32_index(dev, "ti,syscon-efuse", 1, &offset);
+   if (ret)
+   return ret;
+
+   regmap_read(syscon, offset, &mac_lo);
+   regmap_read(syscon, offset + 4, &mac_hi);
+
+   mac_addr[0] = (mac_hi >> 8) & 0xff;
+   mac_addr[1] = mac_hi & 0xff;
+   mac_addr[2] = (mac_lo >> 24) & 0xff;
+   mac_addr[3] = (mac_lo >> 16) & 0xff;
+   mac_addr[4] = (mac_lo >> 8) & 0xff;
+   mac_addr[5] = mac_lo & 0xff;
+
+   return 0;
+}
+
 static int am65_cpsw_read_rom_hwaddr(struct udevice *dev)
 {
struct am65_cpsw_priv *priv = dev_get_priv(dev);
-   struct am65_cpsw_common *common = priv->cpsw_common;
struct eth_pdata *pdata = dev_get_plat(dev);
-   u32 mac_hi, mac_lo;
-
-   if (common->mac_efuse == FDT_ADDR_T_NONE)
-   return -1;
 
-   mac_lo = readl(common->mac_efuse);
-   mac_hi = readl(common->mac_efuse + 4);
-   pdata->enetaddr[0] = (mac_hi >> 8) & 0xff;
-   pdata->enetaddr[1] = mac_hi & 0xff;
-   pdata->enetaddr[2] = (mac_lo >> 24) & 0xff;
-   pdata->enetaddr[3] = (mac_lo >> 16) & 0xff;
-   pdata->enetaddr[4] = (mac_lo >> 8) & 0xff;
-   pdata->enetaddr[5] = mac_lo & 0xff;
+   am65_cpsw_am654_get_efuse_macid(dev,
+   priv->port_id,
+   pdata->enetaddr);
 
return 0;
 }
@@ -710,8 +732,6 @@ static int am65_cpsw_probe_nuss(struct udevice *dev)
cpsw_common->ss_base = dev_read_addr(dev);
if (cpsw_common->ss_base == FDT_ADDR_T_NONE)
return -EINVAL;
-   cpsw_common->mac_efuse = devfdt_get_addr_name(dev, "mac_efuse");
-   /* no err check - optional */
 
ret = power_domain_get_by_index(dev, &cpsw_common->pwrdmn, 0);
if (ret) {
-- 
2.34.1



[PATCH v2 0/4] net: ti: am65-cpsw-nuss: Drop custom properties

2023-07-22 Thread Roger Quadros
Hi,

This series gets rid of 2 custom properties (mac_efuse and cpsw-phy-sel)
that were used in u-boot for the cpsw3g node.

This makes it easier for us to have u-boot DT in sync with Linux.

Last 2 patches are RFC so they can come separately. i.e. squashed with
DT cleanup series from Nishanth.

cheers,
-roger

Changelog:
v2:
- drop enabling CONFIG_SYSCON from defconfig. Use imply in Kconfig instead.
- add patch to drop cpsw-phy-sel custom DT property.

Roger Quadros (4):
  net: ti: am65-cpsw-nuss: Use approved property to get efuse address
  net: ti: am65-cpsw-nuss: Get port mode register from standard "phys"
property
  arm: dts: k3-am625-sk-u-boot.dtsi: drop mac_efuse
  arm: dts: k3-am625-sk-u-boot.dtsi: drop cpsw-phy-sel property

 arch/arm/dts/k3-am625-sk-u-boot.dtsi |  10 ---
 drivers/net/ti/Kconfig   |   1 +
 drivers/net/ti/am65-cpsw-nuss.c  | 115 +--
 3 files changed, 74 insertions(+), 52 deletions(-)

-- 
2.34.1



[PATCH 1/1] spl: add FIT support to semihosting boot method

2023-07-22 Thread Heinrich Schuchardt
Allow loading a FIT image via semihosting in SPL.

Signed-off-by: Heinrich Schuchardt 
---
 common/spl/spl_semihosting.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
index 5b5e842a11..f7dd289286 100644
--- a/common/spl/spl_semihosting.c
+++ b/common/spl/spl_semihosting.c
@@ -21,6 +21,23 @@ static int smh_read_full(long fd, void *memp, size_t len)
return 0;
 }
 
+static ulong smh_fit_read(struct spl_load_info *load, ulong file_offset,
+ ulong size, void *buf)
+{
+   long fd;
+   ulong ret;
+
+   fd = smh_open(load->filename, MODE_READ | MODE_BINARY);
+   if (fd < 0) {
+   log_debug("could not open %s: %ld\n", load->filename, fd);
+   return 0;
+   }
+   ret = smh_read(fd, buf, size);
+   smh_close(fd);
+
+   return ret;
+}
+
 static int spl_smh_load_image(struct spl_image_info *spl_image,
  struct spl_boot_device *bootdev)
 {
@@ -49,6 +66,20 @@ static int spl_smh_load_image(struct spl_image_info 
*spl_image,
goto out;
}
 
+   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
+   image_get_magic(header) == FDT_MAGIC) {
+   struct spl_load_info load;
+
+   debug("Found FIT\n");
+   load.read = smh_fit_read;
+   load.bl_len = 1;
+   load.filename = filename;
+   load.priv = NULL;
+   smh_close(fd);
+
+   return spl_load_simple_fit(spl_image, &load, 0, header);
+   }
+
ret = spl_parse_image_header(spl_image, bootdev, header);
if (ret) {
log_debug("failed to parse image header: %d\n", ret);
-- 
2.40.1



Re: [PATCH 1/1] spl: spl_legacy: simplify spl_parse_legacy_validate

2023-07-22 Thread Marek Vasut

On 7/22/23 20:46, Heinrich Schuchardt wrote:

The check for an overlap of the loaded image and SPL is overly
complicated.

Fixes: 77aed22b48ab ("spl: spl_legacy: Add extra address checks")
Signed-off-by: Heinrich Schuchardt 
---
  common/spl/spl_legacy.c | 5 +
  1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index 095443c63d..9246f555e3 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -22,10 +22,7 @@ static void spl_parse_legacy_validate(uintptr_t start, 
uintptr_t size)
uintptr_t spl_end = (uintptr_t)_image_binary_end;
uintptr_t end = start + size;
  
-	if ((start >= spl_start && start < spl_end) ||

-   (end > spl_start && end <= spl_end) ||
-   (start < spl_start && end >= spl_end) ||
-   (start > end && end > spl_start))
+   if (end > spl_start && start < spl_end)
panic("SPL: Image overlaps SPL\n");
  
  	if (size > CONFIG_SYS_BOOTM_LEN)


Does this handle address space wrap around ? This:

=blob=|..|=blob=
.|==spl==|..

Hint: it does not.

+CC Rasmus.

Look at all the other checks in U-Boot which do, and first factor them 
out into one check functions, so we can improve on that one. Second, use 
that function all over the place. Third, improve on it.


[PATCH 1/1] spl: spl_legacy: simplify spl_parse_legacy_validate

2023-07-22 Thread Heinrich Schuchardt
The check for an overlap of the loaded image and SPL is overly
complicated.

Fixes: 77aed22b48ab ("spl: spl_legacy: Add extra address checks")
Signed-off-by: Heinrich Schuchardt 
---
 common/spl/spl_legacy.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/common/spl/spl_legacy.c b/common/spl/spl_legacy.c
index 095443c63d..9246f555e3 100644
--- a/common/spl/spl_legacy.c
+++ b/common/spl/spl_legacy.c
@@ -22,10 +22,7 @@ static void spl_parse_legacy_validate(uintptr_t start, 
uintptr_t size)
uintptr_t spl_end = (uintptr_t)_image_binary_end;
uintptr_t end = start + size;
 
-   if ((start >= spl_start && start < spl_end) ||
-   (end > spl_start && end <= spl_end) ||
-   (start < spl_start && end >= spl_end) ||
-   (start > end && end > spl_start))
+   if (end > spl_start && start < spl_end)
panic("SPL: Image overlaps SPL\n");
 
if (size > CONFIG_SYS_BOOTM_LEN)
-- 
2.40.1



Re: [PATCH 0/2] Fix network commands w/ USB Eth gadget

2023-07-22 Thread Tom Rini
On Sat, Jul 22, 2023 at 12:25:35AM +0200, Miquel Raynal wrote:

> Hello,
> 
> I recently came across serious issues using U-Boot on Beagle Bone
> Black. The USB Ethernet gadget is behaving in a way that is not
> compliant with the uclass expectations, leading to use-after-free
> accesses often producing data aborts. All network commands are
> affected.
> 
> There are two problems:
> * Any network command after completion could produce a data abort
> * A tftp retrieval with a wrong file name would produce a data abort
> 
> Here is how the major issue (the former one) looks like:
> 
> => tftp 0x8100 zImage
> using musb-hdrc, OUT ep1out IN ep1in STATUS ep2in
> MAC f8:dc:7a:00:00:02
> HOST MAC f8:dc:7a:00:00:01
> RNDIS ready
> musb-hdrc: peripheral reset irq lost!
> high speed config #2: 2 mA, Ethernet Gadget, using RNDIS
> USB RNDIS network up!
> Using usb_ether device
> TFTP from server 192.168.0.1; our IP address is 192.168.0.100
> Filename 'zImage'.
> Load address: 0x8100
> Loading: ##  13 MiB
>  4.2 MiB/s
> done
> Bytes transferred = 13634360 (d00b38 hex)
> data abort
> pc : [<9ff80fba>]  lr : [<9ff7abd9>]
> reloc pc : [<8081bfba>]lr : [<80815bd9>]
> sp : 9df2f9f8  ip : 0020 fp : 0003
> r10: 0200  r9 : 9df44ea0 r8 : 9df2fa68
> r7 : 9df2fa68  r6 : 9ffdbabc r5 : 9ffcdbcd  r4 : 0018
> r3 : 0018  r2 : 9ffdba00 r1 : 0001  r0 : 9df4d348
> Flags: Nzcv  IRQs off  FIQs on  Mode SVC_32 (T)
> Code: 68c2 6881 f023 0303 (60ca) 4403 
> Resetting CPU ...
> 
> While debugging this issue, I came across Qianfan's bug report which
> raised this issue one year ago. Qianfan nicely pointed at two of his
> patches sent on the mailing list following his investigations, which
> IMHO got refused for a wrong reason.
> 
> Link: 
> https://lore.kernel.org/all/7536b9e1-de7a-a492-6951-485d4eb75...@163.com/
> Link: 
> https://patchwork.ozlabs.org/project/uboot/patch/20220402025836.19374-1-qianfangui...@163.com/
> Link: 
> https://patchwork.ozlabs.org/project/uboot/patch/20220402025836.19374-2-qianfangui...@163.com/
> 
> I've taken over Qianfan's two patches, I took the liberty to explain a
> bit more what these issues were about and why they were serious,
> rewording his first patch, and trying to fix the second issue
> differently, because I believe the second issue should be avoided rather
> than workarounded.
> 
> Once ready to send this series, I noticed that two other people already
> tried to fix this:
> Link: https://lore.kernel.org/all/20221212204411.2247170-1-b...@baylibre.com/
> Link: https://lists.denx.de/pipermail/u-boot/2022-December/502055.html
> 
> I have no idea why this is still an open issue, I hope the "code
> reorganization" reason that was mentioned in one of the above threads
> does not stand anymore given how serious these issues are, so whatever
> solution is preferred, I hope one will soon be picked-up :-)

So, the original series was also the wrong direction for the problem,
overall.  Fortunately Marek was able to address the problem quite
recently:
https://patchwork.ozlabs.org/project/uboot/list/?series=364209&state=*

Please test that series, thanks.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/1] riscv: qemu: provide more SPL boot methods

2023-07-22 Thread Bin Meng
Hi Heinrich,

On Sat, Jul 22, 2023 at 7:10 PM Heinrich Schuchardt
 wrote:
>
> QEMU can supply block devices or semihosting to U-Boot SPL. Allow booting
> from these.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  board/emulation/qemu-riscv/qemu-riscv.c | 17 ++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/board/emulation/qemu-riscv/qemu-riscv.c 
> b/board/emulation/qemu-riscv/qemu-riscv.c
> index ae3b7a3295..b2fe3e9f0c 100644
> --- a/board/emulation/qemu-riscv/qemu-riscv.c
> +++ b/board/emulation/qemu-riscv/qemu-riscv.c
> @@ -69,10 +69,21 @@ int board_late_init(void)
>  }
>
>  #ifdef CONFIG_SPL
> -u32 spl_boot_device(void)
> +void board_boot_order(u32 *spl_boot_list)
>  {
> -   /* RISC-V QEMU only supports RAM as SPL boot device */
> -   return BOOT_DEVICE_RAM;
> +   int index = 0;
> +
> +   if (IS_ENABLED(CONFIG_SPL_NVME))
> +   spl_boot_list[index++] = BOOT_DEVICE_NVME;
> +   if (IS_ENABLED(CONFIG_SPL_SATA))
> +   spl_boot_list[index++] = BOOT_DEVICE_SATA;
> +   if (IS_ENABLED(CONFIG_SPL_USB_STORAGE))
> +   spl_boot_list[index++] = BOOT_DEVICE_USB;
> +   if (IS_ENABLED(CONFIG_SPL_SEMIHOSTING))
> +   spl_boot_list[index++] = BOOT_DEVICE_SMH;
> +   /* RAM last as CONFIG_SPL_RAW_IMAGE_SUPPORT=y may lead to crash */
> +   if (IS_ENABLED(CONFIG_SPL_RAM_SUPPORT))
> +   spl_boot_list[index++] = BOOT_DEVICE_RAM;
>  }
>  #endif
>

Please include instructions on how to boot U-Boot proper from these
additional devices in qemu-riscv.rst

Regards,
Bin


[PATCH v3 3/3] board: rockchip: Add Hardkernel ODROID-M1

2023-07-22 Thread Jonas Karlman
Hardkernel ODROID-M1 is a single board computer with a RK3568B2 SoC,
a slightly modified version of the RK3568 SoC.

Features tested on a ODROID-M1 8GB v1.0 2022-06-13:
- SD-card boot
- eMMC boot
- SPI Flash boot
- PCIe/NVMe/AHCI
- SATA port
- USB host

Device tree is imported from linux v6.4.

Signed-off-by: Jonas Karlman 
Reviewed-by: Stefan Agner 
Tested-by: Stefan Agner 
---
v3:
- Remove vcc5v0_usb_host regulator-always-on workaround
- Remove CONFIG_ETH_DESIGNWARE=y and CONFIG_GMAC_ROCKCHIP=y

v2:
- Enable CMD_MTD, CMD_INI and CMD_CRAMFS to closer
  match downstream legacy U-Boot
- Do not override spi0 alias, use SF_DEFAULT_BUS=4
- Collect r-b and t-b tags

 arch/arm/dts/Makefile |   1 +
 arch/arm/dts/rk3568-odroid-m1-u-boot.dtsi |  37 ++
 arch/arm/dts/rk3568-odroid-m1.dts | 744 ++
 arch/arm/mach-rockchip/rk3568/Kconfig |   6 +
 board/hardkernel/odroid_m1/Kconfig|  15 +
 board/hardkernel/odroid_m1/MAINTAINERS|   8 +
 board/hardkernel/odroid_m1/Makefile   |   3 +
 board/hardkernel/odroid_m1/odroid_m1.c|   1 +
 configs/odroid-m1-rk3568_defconfig| 111 
 doc/board/rockchip/rockchip.rst   |   1 +
 include/configs/odroid_m1.h   |  11 +
 11 files changed, 938 insertions(+)
 create mode 100644 arch/arm/dts/rk3568-odroid-m1-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3568-odroid-m1.dts
 create mode 100644 board/hardkernel/odroid_m1/Kconfig
 create mode 100644 board/hardkernel/odroid_m1/MAINTAINERS
 create mode 100644 board/hardkernel/odroid_m1/Makefile
 create mode 100644 board/hardkernel/odroid_m1/odroid_m1.c
 create mode 100644 configs/odroid-m1-rk3568_defconfig
 create mode 100644 include/configs/odroid_m1.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index b7780de776b6..6764ded580ab 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -169,6 +169,7 @@ dtb-$(CONFIG_ROCKCHIP_RK3568) += \
rk3566-anbernic-rgxx3.dtb \
rk3566-radxa-cm3-io.dtb \
rk3568-evb.dtb \
+   rk3568-odroid-m1.dtb \
rk3568-rock-3a.dtb
 
 dtb-$(CONFIG_ROCKCHIP_RK3588) += \
diff --git a/arch/arm/dts/rk3568-odroid-m1-u-boot.dtsi 
b/arch/arm/dts/rk3568-odroid-m1-u-boot.dtsi
new file mode 100644
index ..0fc360b06df7
--- /dev/null
+++ b/arch/arm/dts/rk3568-odroid-m1-u-boot.dtsi
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include "rk356x-u-boot.dtsi"
+
+/ {
+   chosen {
+   stdout-path = &uart2;
+   };
+};
+
+&fspi_dual_io_pins {
+   bootph-all;
+};
+
+&sdhci {
+   cap-mmc-highspeed;
+   mmc-ddr-1_8v;
+   mmc-hs200-1_8v;
+   mmc-hs400-1_8v;
+   mmc-hs400-enhanced-strobe;
+   pinctrl-0 = <&emmc_bus8 &emmc_clk &emmc_cmd &emmc_datastrobe>;
+};
+
+&sfc {
+   bootph-pre-ram;
+   u-boot,spl-sfc-no-dma;
+
+   flash@0 {
+   bootph-pre-ram;
+   };
+};
+
+&uart2 {
+   bootph-all;
+   clock-frequency = <2400>;
+   status = "okay";
+};
diff --git a/arch/arm/dts/rk3568-odroid-m1.dts 
b/arch/arm/dts/rk3568-odroid-m1.dts
new file mode 100644
index ..59ecf868dbd0
--- /dev/null
+++ b/arch/arm/dts/rk3568-odroid-m1.dts
@@ -0,0 +1,744 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2022 Hardkernel Co., Ltd.
+ *
+ */
+
+/dts-v1/;
+#include 
+#include 
+#include 
+#include 
+#include "rk3568.dtsi"
+
+/ {
+   model = "Hardkernel ODROID-M1";
+   compatible = "rockchip,rk3568-odroid-m1", "rockchip,rk3568";
+
+   aliases {
+   ethernet0 = &gmac0;
+   i2c0 = &i2c3;
+   i2c3 = &i2c0;
+   mmc0 = &sdhci;
+   mmc1 = &sdmmc0;
+   serial0 = &uart1;
+   serial1 = &uart0;
+   };
+
+   chosen {
+   stdout-path = "serial2:150n8";
+   };
+
+   dc_12v: dc-12v-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "dc_12v";
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <1200>;
+   regulator-max-microvolt = <1200>;
+   };
+
+   hdmi-con {
+   compatible = "hdmi-connector";
+   type = "a";
+
+   port {
+   hdmi_con_in: endpoint {
+   remote-endpoint = <&hdmi_out_con>;
+   };
+   };
+   };
+
+   ir-receiver {
+   compatible = "gpio-ir-receiver";
+   gpios = <&gpio0 RK_PC2 GPIO_ACTIVE_LOW>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&ir_receiver_pin>;
+   };
+
+   leds {
+   compatible = "gpio-leds";
+
+   led_power: led-0 {
+   gpios = <&gpio0 RK_PC6 GPIO_ACTIVE_HIGH>;
+   function = LED_FUNCTION_POWER;
+   color = ;
+   default-

[PATCH v3 2/3] cmd: ini: Fix build warning

2023-07-22 Thread Jonas Karlman
Building U-Boot with CMD_INI=y result in following build warning:

  cmd/ini.c: In function 'memgets':
  include/linux/kernel.h:184:24: warning: comparison of distinct pointer types 
lacks a cast
184 | (void) (&_min1 == &_min2);  \
|^~
  cmd/ini.c:92:15: note: in expansion of macro 'min'
 92 | len = min((end - *mem) + newline, num);
|   ^~~

Fix this by adding an int cast to the pointer arithmetic result.

Signed-off-by: Jonas Karlman 
---
v3:
- No changes

v2:
- New patch

 cmd/ini.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/ini.c b/cmd/ini.c
index 81dfc4c4e83d..35de2373e602 100644
--- a/cmd/ini.c
+++ b/cmd/ini.c
@@ -89,7 +89,7 @@ static char *memgets(char *str, int num, char **mem, size_t 
*memsize)
end = *mem + *memsize;
newline = 0;
}
-   len = min((end - *mem) + newline, num);
+   len = min((int)(end - *mem) + newline, num);
memcpy(str, *mem, len);
if (len < num)
str[len] = '\0';
-- 
2.41.0



[PATCH v3 0/3] board: rockchip: Add Hardkernel ODROID-M1

2023-07-22 Thread Jonas Karlman
This series add support for Hardkernel ODROID-M1, a single board
computer with a RK3568B2 SoC.

First patch fixes a build issue in the dwc_ahci driver.

Second patch fixes a build warning in the ini command.

Third patch import the device tree from linux v6.4 and add a defconfig
for Hardkernel ODROID-M1.

Following was tested on a ODROID-M1 8GB v1.0 2022-06-13:
- SD-card boot
- eMMC boot
- SPI Flash boot
- PCIe/NVMe/AHCI
- SATA port
- USB host

Changes in v3:
- Remove vcc5v0_usb_host regulator-always-on workaround
- Remove CONFIG_ETH_DESIGNWARE=y and CONFIG_GMAC_ROCKCHIP=y

Changes in v2:
- Add new patch to fix build warning in the ini command
- Enable CMD_MTD, CMD_INI and CMD_CRAMFS to closer
  match downstream legacy U-Boot
- Do not override spi0 alias, use SF_DEFAULT_BUS=4
- Collect r-b and t-b tags

With the new options added in v2 it is possible to load downstream
petitboot from SD-card using following commands:

  load mmc 1:1 $fdt_addr_r rk3568-odroid-m1.dtb
  load mmc 1:1 $cramfsaddr ODROIDBIOS.BIN
  cramfsload $scriptaddr boot.scr
  source $scriptaddr

This series have loose dependencies on the following series:
- rockchip: Fix PCIe and NVMe support on RK3568 [1]
- rockchip: rk3568: Use dwc3-generic driver [2]
- rockchip: rk3568: Fix alloc space exhausted in SPL [3]
- rockchip: rk3568: Device Tree updates [4]
- rockchip: rk35xx: Fix SPI Flash alias [5]

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=365195
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=364127
[3] https://patchwork.ozlabs.org/project/uboot/list/?series=361999
[4] https://patchwork.ozlabs.org/project/uboot/list/?series=362030
[5] https://patchwork.ozlabs.org/project/uboot/list/?series=363527

Jonas Karlman (3):
  ata: dwc_ahci: Fix support for other platforms
  cmd: ini: Fix build warning
  board: rockchip: Add Hardkernel ODROID-M1

 arch/arm/dts/Makefile |   1 +
 arch/arm/dts/rk3568-odroid-m1-u-boot.dtsi |  37 ++
 arch/arm/dts/rk3568-odroid-m1.dts | 744 ++
 arch/arm/mach-rockchip/rk3568/Kconfig |   6 +
 board/hardkernel/odroid_m1/Kconfig|  15 +
 board/hardkernel/odroid_m1/MAINTAINERS|   8 +
 board/hardkernel/odroid_m1/Makefile   |   3 +
 board/hardkernel/odroid_m1/odroid_m1.c|   1 +
 cmd/ini.c |   2 +-
 configs/odroid-m1-rk3568_defconfig| 111 
 doc/board/rockchip/rockchip.rst   |   1 +
 drivers/ata/dwc_ahci.c|   4 +
 include/configs/odroid_m1.h   |  11 +
 13 files changed, 943 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/rk3568-odroid-m1-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3568-odroid-m1.dts
 create mode 100644 board/hardkernel/odroid_m1/Kconfig
 create mode 100644 board/hardkernel/odroid_m1/MAINTAINERS
 create mode 100644 board/hardkernel/odroid_m1/Makefile
 create mode 100644 board/hardkernel/odroid_m1/odroid_m1.c
 create mode 100644 configs/odroid-m1-rk3568_defconfig
 create mode 100644 include/configs/odroid_m1.h

-- 
2.41.0



[PATCH v3 1/3] ata: dwc_ahci: Fix support for other platforms

2023-07-22 Thread Jonas Karlman
The dwc_ahci driver use platform specific defines, place the platform
specific code behind a ifdef CONFIG_ARCH_OMAP2PLUS to allow build and
use of the driver on Rockchip platform.

Fixes: 02a4b4297901 ("drivers: block: dwc_ahci: Implement a driver for Synopsys 
DWC sata device")
Signed-off-by: Jonas Karlman 
---
v3:
- No changes

v2:
- No changes

 drivers/ata/dwc_ahci.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/ata/dwc_ahci.c b/drivers/ata/dwc_ahci.c
index 826fea71cc5b..1dc91e7fce70 100644
--- a/drivers/ata/dwc_ahci.c
+++ b/drivers/ata/dwc_ahci.c
@@ -13,7 +13,9 @@
 #include 
 #include 
 #include 
+#ifdef CONFIG_ARCH_OMAP2PLUS
 #include 
+#endif
 #include 
 #include 
 
@@ -72,12 +74,14 @@ static int dwc_ahci_probe(struct udevice *dev)
return ret;
}
 
+#ifdef CONFIG_ARCH_OMAP2PLUS
if (priv->wrapper_base) {
u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO;
 
/* Enable SATA module, No Idle, No Standby */
writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG);
}
+#endif
 
return ahci_probe_scsi(dev, (ulong)priv->base);
 }
-- 
2.41.0



[PATCH v4 9/9] rockchip: rk356x: Update PCIe config, IO and memory regions

2023-07-22 Thread Jonas Karlman
Update config, IO and memory regions used based on [1] with pcie3x2
config reg address and reg size corrected.

Before this change:

  PCI Autoconfig: Bus Memory region: [0-3eef],
  PCI Autoconfig: Bus I/O region: [3ef0-3eff],

After this change:

  PCI Autoconfig: Bus Memory region: [4000-7fff],
  PCI Autoconfig: Bus I/O region: [f010-f01f],

[1] https://lore.kernel.org/lkml/20221112114125.1637543-2-ahol...@omnom.net/

Signed-off-by: Jonas Karlman 
Reviewed-by: Kever Yang 
---
v4:
- No change

v3:
- No change

v2:
- Update commit message
- Collect r-b tag

 arch/arm/dts/rk3568.dtsi | 14 --
 arch/arm/dts/rk356x.dtsi |  7 ---
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/arch/arm/dts/rk3568.dtsi b/arch/arm/dts/rk3568.dtsi
index ba67b58f05b7..f1be76a54ceb 100644
--- a/arch/arm/dts/rk3568.dtsi
+++ b/arch/arm/dts/rk3568.dtsi
@@ -94,9 +94,10 @@
power-domains = <&power RK3568_PD_PIPE>;
reg = <0x3 0xc040 0x0 0x0040>,
  <0x0 0xfe27 0x0 0x0001>,
- <0x3 0x7f00 0x0 0x0100>;
-   ranges = <0x0100 0x0 0x3ef0 0x3 0x7ef0 0x0 
0x0010>,
-<0x0200 0x0 0x 0x3 0x4000 0x0 
0x3ef0>;
+ <0x0 0xf200 0x0 0x0010>;
+   ranges = <0x0100 0x0 0xf210 0x0 0xf210 0x0 
0x0010>,
+<0x0200 0x0 0xf220 0x0 0xf220 0x0 
0x01e0>,
+<0x0300 0x0 0x4000 0x3 0x4000 0x0 
0x4000>;
reg-names = "dbi", "apb", "config";
resets = <&cru SRST_PCIE30X1_POWERUP>;
reset-names = "pipe";
@@ -146,9 +147,10 @@
power-domains = <&power RK3568_PD_PIPE>;
reg = <0x3 0xc080 0x0 0x0040>,
  <0x0 0xfe28 0x0 0x0001>,
- <0x3 0xbf00 0x0 0x0100>;
-   ranges = <0x0100 0x0 0x3ef0 0x3 0xbef0 0x0 
0x0010>,
-<0x0200 0x0 0x 0x3 0x8000 0x0 
0x3ef0>;
+ <0x0 0xf000 0x0 0x0010>;
+   ranges = <0x0100 0x0 0xf010 0x0 0xf010 0x0 
0x0010>,
+<0x0200 0x0 0xf020 0x0 0xf020 0x0 
0x01e0>,
+<0x0300 0x0 0x4000 0x3 0x8000 0x0 
0x4000>;
reg-names = "dbi", "apb", "config";
resets = <&cru SRST_PCIE30X2_POWERUP>;
reset-names = "pipe";
diff --git a/arch/arm/dts/rk356x.dtsi b/arch/arm/dts/rk356x.dtsi
index 6492ace0de6b..e0591c194bec 100644
--- a/arch/arm/dts/rk356x.dtsi
+++ b/arch/arm/dts/rk356x.dtsi
@@ -951,7 +951,7 @@
compatible = "rockchip,rk3568-pcie";
reg = <0x3 0xc000 0x0 0x0040>,
  <0x0 0xfe26 0x0 0x0001>,
- <0x3 0x3f00 0x0 0x0100>;
+ <0x0 0xf400 0x0 0x0010>;
reg-names = "dbi", "apb", "config";
interrupts = ,
 ,
@@ -980,8 +980,9 @@
phys = <&combphy2 PHY_TYPE_PCIE>;
phy-names = "pcie-phy";
power-domains = <&power RK3568_PD_PIPE>;
-   ranges = <0x0100 0x0 0x3ef0 0x3 0x3ef0 0x0 
0x0010
- 0x0200 0x0 0x 0x3 0x 0x0 
0x3ef0>;
+   ranges = <0x0100 0x0 0xf410 0x0 0xf410 0x0 
0x0010>,
+<0x0200 0x0 0xf420 0x0 0xf420 0x0 
0x01e0>,
+<0x0300 0x0 0x4000 0x3 0x 0x0 
0x4000>;
resets = <&cru SRST_PCIE20_POWERUP>;
reset-names = "pipe";
#address-cells = <3>;
-- 
2.41.0



[PATCH v4 7/9] rockchip: clk: clk_rk3568: Add CLK_PCIEPHY2_REF support

2023-07-22 Thread Jonas Karlman
Add dummy support for the CLK_PCIEPHY2_REF clock.

Signed-off-by: Jonas Karlman 
Reviewed-by: Kever Yang 
---
v4:
- No change

v3:
- No change

v2:
- Collect r-b tag

 drivers/clk/rockchip/clk_rk3568.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/clk/rockchip/clk_rk3568.c 
b/drivers/clk/rockchip/clk_rk3568.c
index 6bdd96f35b5c..0df82f597152 100644
--- a/drivers/clk/rockchip/clk_rk3568.c
+++ b/drivers/clk/rockchip/clk_rk3568.c
@@ -427,6 +427,7 @@ static ulong rk3568_pmuclk_set_rate(struct clk *clk, ulong 
rate)
break;
case CLK_PCIEPHY0_REF:
case CLK_PCIEPHY1_REF:
+   case CLK_PCIEPHY2_REF:
return 0;
default:
return -ENOENT;
-- 
2.41.0



[PATCH v4 8/9] rockchip: rk3568-rock-3a: Enable PCIe and NVMe support

2023-07-22 Thread Jonas Karlman
Add missing pinctrl and defconfig options to enable PCIe and NVMe
support on Radxa ROCK 3 Model A.

Use of pcie20m1_pins and pcie30x2m1_pins ensure IO mux selection M1.
The following pcie_reset_h and pcie3x2_reset_h ensure GPIO func is
restored to the perstn pin, a workaround to avoid having to define
a new rockchip,pins.

Signed-off-by: Jonas Karlman 
---
v4:
- No change

v3:
- Drop now unneeded sys freeze workaround
- Enable options for AHCI/SCSI

v2:
- Update commit message
- Disable pcie2x1 to work around a possible sys freeze issue

 arch/arm/dts/rk3568-rock-3a-u-boot.dtsi | 14 ++
 configs/rock-3a-rk3568_defconfig|  9 +
 2 files changed, 23 insertions(+)

diff --git a/arch/arm/dts/rk3568-rock-3a-u-boot.dtsi 
b/arch/arm/dts/rk3568-rock-3a-u-boot.dtsi
index bbf54f888fa0..9ee7b494ee25 100644
--- a/arch/arm/dts/rk3568-rock-3a-u-boot.dtsi
+++ b/arch/arm/dts/rk3568-rock-3a-u-boot.dtsi
@@ -36,8 +36,22 @@
bootph-all;
 };
 
+&pcie2x1 {
+   pinctrl-0 = <&pcie20m1_pins &pcie_reset_h>;
+};
+
+&pcie3x2 {
+   pinctrl-0 = <&pcie30x2m1_pins &pcie3x2_reset_h>;
+};
+
 &pinctrl {
bootph-all;
+
+   pcie {
+   pcie3x2_reset_h: pcie3x2-reset-h {
+   rockchip,pins = <2 RK_PD6 RK_FUNC_GPIO &pcfg_pull_none>;
+   };
+   };
 };
 
 &pcfg_pull_none {
diff --git a/configs/rock-3a-rk3568_defconfig b/configs/rock-3a-rk3568_defconfig
index 753d03914d90..8e3fe0a25e1d 100644
--- a/configs/rock-3a-rk3568_defconfig
+++ b/configs/rock-3a-rk3568_defconfig
@@ -22,7 +22,9 @@ CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0xc00800
+CONFIG_PCI=y
 CONFIG_DEBUG_UART=y
+CONFIG_AHCI=y
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_SPL_FIT_SIGNATURE=y
@@ -46,6 +48,7 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_PMIC=y
@@ -56,6 +59,8 @@ CONFIG_OF_LIVE=y
 CONFIG_OF_SPL_REMOVE_PROPS="clock-names interrupt-parent assigned-clocks 
assigned-clock-rates assigned-clock-parents"
 CONFIG_SPL_REGMAP=y
 CONFIG_SPL_SYSCON=y
+CONFIG_SCSI_AHCI=y
+CONFIG_AHCI_PCI=y
 CONFIG_SPL_CLK=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
@@ -70,6 +75,8 @@ CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_SPI_FLASH_XTX=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_GMAC_ROCKCHIP=y
+CONFIG_NVME_PCI=y
+CONFIG_PCIE_DW_ROCKCHIP=y
 CONFIG_PHY_ROCKCHIP_INNO_USB2=y
 CONFIG_PHY_ROCKCHIP_NANENG_COMBOPHY=y
 CONFIG_SPL_PINCTRL=y
@@ -78,6 +85,8 @@ CONFIG_PMIC_RK8XX=y
 CONFIG_REGULATOR_RK8XX=y
 CONFIG_PWM_ROCKCHIP=y
 CONFIG_SPL_RAM=y
+CONFIG_SCSI=y
+CONFIG_DM_SCSI=y
 CONFIG_BAUDRATE=150
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_SYS_NS16550_MEM32=y
-- 
2.41.0



[PATCH v4 6/9] regulator: fixed: Add support for gpios prop

2023-07-22 Thread Jonas Karlman
The commit 12df2c182ccb ("regulator: dt-bindings: fixed-regulator: allow
gpios property") in linux v6.3-rc1 added support for use of either a
gpios or gpio prop with a fixed-regulator.

This adds support for the new gpios prop to the fixed-regulator driver.
gpios prop is used by vcc3v3-pcie-regulator on Radxa ROCK 3 Model A.

Signed-off-by: Jonas Karlman 
Reviewed-by: Kever Yang 
---
v4:
- No change

v3:
- Rebased on master

v2:
- Update commit message
- Collect r-b tag

 drivers/power/regulator/fixed.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/power/regulator/fixed.c b/drivers/power/regulator/fixed.c
index ad3b4b98d667..f7ddba8b45e4 100644
--- a/drivers/power/regulator/fixed.c
+++ b/drivers/power/regulator/fixed.c
@@ -25,6 +25,7 @@ static int fixed_regulator_of_to_plat(struct udevice *dev)
 {
struct dm_regulator_uclass_plat *uc_pdata;
struct regulator_common_plat *plat;
+   bool gpios;
 
plat = dev_get_plat(dev);
uc_pdata = dev_get_uclass_plat(dev);
@@ -33,7 +34,8 @@ static int fixed_regulator_of_to_plat(struct udevice *dev)
 
uc_pdata->type = REGULATOR_TYPE_FIXED;
 
-   return regulator_common_of_to_plat(dev, plat, "gpio");
+   gpios = dev_read_bool(dev, "gpios");
+   return regulator_common_of_to_plat(dev, plat, gpios ? "gpios" : "gpio");
 }
 
 static int fixed_regulator_get_value(struct udevice *dev)
-- 
2.41.0



[PATCH v4 5/9] pci: pcie_dw_rockchip: Disable unused BARs of the root complex

2023-07-22 Thread Jonas Karlman
From: Jon Lin 

The Root Complex BARs default to claim the full 1 GiB memory region on
RK3568, leaving no space for any attached device.

Fix this by disable the unused BAR 0 and BAR 1 of the RC.

Signed-off-by: Jon Lin 
[jo...@kwiboo.se: Move to rk_pcie_configure and use PCI_BASE_ADDRESS_0/1 const]
Signed-off-by: Jonas Karlman 
---
v4:
- New patch, based on vendor commit 1f4523203c2a ("driver: pci: rockchip:
  Disable RC BAR0 and BAR1")

 drivers/pci/pcie_dw_rockchip.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c
index 82a8b9c96e2b..1a35fae5c3a8 100644
--- a/drivers/pci/pcie_dw_rockchip.c
+++ b/drivers/pci/pcie_dw_rockchip.c
@@ -61,6 +61,8 @@ struct rk_pcie {
 #define PCIE_CLIENT_DBG_TRANSITION_DATA0x
 #define PCIE_CLIENT_DBF_EN 0x0003
 
+#define PCIE_TYPE0_HDR_DBI2_OFFSET 0x10
+
 static int rk_pcie_read(void __iomem *addr, int size, u32 *val)
 {
if ((uintptr_t)addr & (size - 1)) {
@@ -158,6 +160,12 @@ static void rk_pcie_configure(struct rk_pcie *pci, u32 
cap_speed)
 {
dw_pcie_dbi_write_enable(&pci->dw, true);
 
+   /* Disable BAR 0 and BAR 1 */
+   writel(0, pci->dw.dbi_base + PCIE_TYPE0_HDR_DBI2_OFFSET +
+  PCI_BASE_ADDRESS_0);
+   writel(0, pci->dw.dbi_base + PCIE_TYPE0_HDR_DBI2_OFFSET +
+  PCI_BASE_ADDRESS_1);
+
clrsetbits_le32(pci->dw.dbi_base + PCIE_LINK_CAPABILITY,
TARGET_LINK_SPEED_MASK, cap_speed);
 
-- 
2.41.0



[PATCH v4 4/9] pci: pcie_dw_rockchip: Speed up link probe

2023-07-22 Thread Jonas Karlman
Use a similar pattern and delay values as the linux mainline driver to
speed up failing when nothing is connected.

Reduce fail speed from around 5+ seconds down to around one second on a
Radxa ROCK 3 Model A, where pcie2x1 is probed before pcie3x2 M2 slot.

Signed-off-by: Jonas Karlman 
Reviewed-by: Kever Yang 
---
v4:
- No change

v3:
- Collect r-b tag

v2:
- No change

 drivers/pci/pcie_dw_rockchip.c | 68 ++
 1 file changed, 37 insertions(+), 31 deletions(-)

diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c
index 1b8a1409f6df..82a8b9c96e2b 100644
--- a/drivers/pci/pcie_dw_rockchip.c
+++ b/drivers/pci/pcie_dw_rockchip.c
@@ -61,9 +61,6 @@ struct rk_pcie {
 #define PCIE_CLIENT_DBG_TRANSITION_DATA0x
 #define PCIE_CLIENT_DBF_EN 0x0003
 
-/* Parameters for the waiting for #perst signal */
-#define MACRO_US   1000
-
 static int rk_pcie_read(void __iomem *addr, int size, u32 *val)
 {
if ((uintptr_t)addr & (size - 1)) {
@@ -242,43 +239,46 @@ static int rk_pcie_link_up(struct rk_pcie *priv, u32 
cap_speed)
/* DW pre link configurations */
rk_pcie_configure(priv, cap_speed);
 
-   /* Rest the device */
-   if (dm_gpio_is_valid(&priv->rst_gpio)) {
-   dm_gpio_set_value(&priv->rst_gpio, 0);
-   /*
-* Minimal is 100ms from spec but we see
-* some wired devices need much more, such as 600ms.
-* Add a enough delay to cover all cases.
-*/
-   udelay(MACRO_US * 1000);
-   dm_gpio_set_value(&priv->rst_gpio, 1);
-   }
-
rk_pcie_disable_ltssm(priv);
rk_pcie_link_status_clear(priv);
rk_pcie_enable_debug(priv);
 
+   /* Reset the device */
+   if (dm_gpio_is_valid(&priv->rst_gpio))
+   dm_gpio_set_value(&priv->rst_gpio, 0);
+
/* Enable LTSSM */
rk_pcie_enable_ltssm(priv);
 
-   for (retries = 0; retries < 5; retries++) {
-   if (is_link_up(priv)) {
-   dev_info(priv->dw.dev, "PCIe Link up, LTSSM is 0x%x\n",
-rk_pcie_readl_apb(priv, 
PCIE_CLIENT_LTSSM_STATUS));
-   rk_pcie_debug_dump(priv);
-   return 0;
-   }
-
-   dev_info(priv->dw.dev, "PCIe Linking... LTSSM is 0x%x\n",
-rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
-   rk_pcie_debug_dump(priv);
-   udelay(MACRO_US * 1000);
+   /*
+* PCIe requires the refclk to be stable for 100ms prior to releasing
+* PERST. See table 2-4 in section 2.6.2 AC Specifications of the PCI
+* Express Card Electromechanical Specification, 1.1. However, we don't
+* know if the refclk is coming from RC's PHY or external OSC. If it's
+* from RC, so enabling LTSSM is the just right place to release #PERST.
+*/
+   mdelay(100);
+   if (dm_gpio_is_valid(&priv->rst_gpio))
+   dm_gpio_set_value(&priv->rst_gpio, 1);
+
+   /* Check if the link is up or not */
+   for (retries = 0; retries < 10; retries++) {
+   if (is_link_up(priv))
+   break;
+
+   mdelay(100);
+   }
+
+   if (retries >= 10) {
+   dev_err(priv->dw.dev, "PCIe-%d Link Fail\n",
+   dev_seq(priv->dw.dev));
+   return -EIO;
}
 
-   dev_err(priv->dw.dev, "PCIe-%d Link Fail\n", dev_seq(priv->dw.dev));
-   /* Link maybe in Gen switch recovery but we need to wait more 1s */
-   udelay(MACRO_US * 1000);
-   return -EIO;
+   dev_info(priv->dw.dev, "PCIe Link up, LTSSM is 0x%x\n",
+rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
+   rk_pcie_debug_dump(priv);
+   return 0;
 }
 
 static int rockchip_pcie_init_port(struct udevice *dev)
@@ -287,6 +287,12 @@ static int rockchip_pcie_init_port(struct udevice *dev)
u32 val;
struct rk_pcie *priv = dev_get_priv(dev);
 
+   ret = reset_assert_bulk(&priv->rsts);
+   if (ret) {
+   dev_err(dev, "failed to assert resets (ret=%d)\n", ret);
+   return ret;
+   }
+
/* Set power and maybe external ref clk input */
ret = regulator_set_enable_if_allowed(priv->vpcie3v3, true);
if (ret && ret != -ENOSYS) {
-- 
2.41.0



[PATCH v4 3/9] pci: pcie_dw_rockchip: Use regulator_set_enable_if_allowed

2023-07-22 Thread Jonas Karlman
The vpcie3v3 regulator is typically a fixed regulator controlled using
gpio. Change to use enable and disable calls on the regulator instead
of trying to set a voltage value.

Also remove the delay to match linux driver, for a fixed regulator the
startup-delay-us prop can be used in case a startup delay is needed.
Limited testing on ROCK 3A, ROCK 5B, Quartz64, Odroid-M1 has shown that
this delay was not needed.

Signed-off-by: Jonas Karlman 
Reviewed-by: Kever Yang 
---
v4:
- No change

v3:
- Collect r-b tag

v2:
- Update commit message

 drivers/pci/pcie_dw_rockchip.c | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c
index 83737e62bc6a..1b8a1409f6df 100644
--- a/drivers/pci/pcie_dw_rockchip.c
+++ b/drivers/pci/pcie_dw_rockchip.c
@@ -288,21 +288,16 @@ static int rockchip_pcie_init_port(struct udevice *dev)
struct rk_pcie *priv = dev_get_priv(dev);
 
/* Set power and maybe external ref clk input */
-   if (priv->vpcie3v3) {
-   ret = regulator_set_value(priv->vpcie3v3, 330);
-   if (ret) {
-   dev_err(priv->dw.dev, "failed to enable vpcie3v3 
(ret=%d)\n",
-   ret);
-   return ret;
-   }
+   ret = regulator_set_enable_if_allowed(priv->vpcie3v3, true);
+   if (ret && ret != -ENOSYS) {
+   dev_err(dev, "failed to enable vpcie3v3 (ret=%d)\n", ret);
+   return ret;
}
 
-   udelay(MACRO_US * 1000);
-
ret = generic_phy_init(&priv->phy);
if (ret) {
dev_err(dev, "failed to init phy (ret=%d)\n", ret);
-   return ret;
+   goto err_disable_regulator;
}
 
ret = generic_phy_power_on(&priv->phy);
@@ -345,6 +340,8 @@ err_power_off_phy:
generic_phy_power_off(&priv->phy);
 err_exit_phy:
generic_phy_exit(&priv->phy);
+err_disable_regulator:
+   regulator_set_enable_if_allowed(priv->vpcie3v3, false);
 
return ret;
 }
-- 
2.41.0



[PATCH v4 2/9] pci: pcie_dw_rockchip: Get config region from reg prop

2023-07-22 Thread Jonas Karlman
Get the config region to use from the reg prop. Also update the
referenced region index used in comment.

Signed-off-by: Jonas Karlman 
Reviewed-by: Kever Yang 
---
v4:
- No change

v3:
- No change

v2:
- Use dev_read_addr_size_index_ptr
- Collect r-b tag

 drivers/pci/pcie_dw_common.c   | 10 ++
 drivers/pci/pcie_dw_rockchip.c |  7 +++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pcie_dw_common.c b/drivers/pci/pcie_dw_common.c
index 9f8b016d1149..74fb6df412c7 100644
--- a/drivers/pci/pcie_dw_common.c
+++ b/drivers/pci/pcie_dw_common.c
@@ -141,9 +141,9 @@ static uintptr_t set_cfg_address(struct pcie_dw *pcie,
 
/*
 * Not accessing root port configuration space?
-* Region #0 is used for Outbound CFG space access.
+* Region #1 is used for Outbound CFG space access.
 * Direction = Outbound
-* Region Index = 0
+* Region Index = 1
 */
d = PCI_MASK_BUS(d);
d = PCI_ADD_BUS(bus, d);
@@ -328,8 +328,10 @@ void pcie_dw_setup_host(struct pcie_dw *pci)
pci->prefetch.bus_start = hose->regions[ret].bus_start; 
 /* PREFETCH_bus_addr */
pci->prefetch.size = hose->regions[ret].size;   /* 
PREFETCH size */
} else if (hose->regions[ret].flags == PCI_REGION_SYS_MEMORY) {
-   pci->cfg_base = (void *)(pci->io.phys_start - 
pci->io.size);
-   pci->cfg_size = pci->io.size;
+   if (!pci->cfg_base) {
+   pci->cfg_base = (void *)(pci->io.phys_start - 
pci->io.size);
+   pci->cfg_size = pci->io.size;
+   }
} else {
dev_err(pci->dev, "invalid flags type!\n");
}
diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c
index 6da618055cbe..83737e62bc6a 100644
--- a/drivers/pci/pcie_dw_rockchip.c
+++ b/drivers/pci/pcie_dw_rockchip.c
@@ -366,6 +366,13 @@ static int rockchip_pcie_parse_dt(struct udevice *dev)
 
dev_dbg(dev, "APB address is 0x%p\n", priv->apb_base);
 
+   priv->dw.cfg_base = dev_read_addr_size_index_ptr(dev, 2,
+&priv->dw.cfg_size);
+   if (!priv->dw.cfg_base)
+   return -EINVAL;
+
+   dev_dbg(dev, "CFG address is 0x%p\n", priv->dw.cfg_base);
+
ret = gpio_request_by_name(dev, "reset-gpios", 0,
   &priv->rst_gpio, GPIOD_IS_OUT);
if (ret) {
-- 
2.41.0



[PATCH v4 0/9] rockchip: Fix PCIe and NVMe support on RK3568

2023-07-22 Thread Jonas Karlman
This series fixes and enables PCIe and NVMe support on RK3568.

Patch 1 adds a dev_read_addr_size_index_ptr function.
Patch 2-3 fixes main issue in the driver to be usable on RK3568.
Patch 4 fixes a long wait time during probe when no device is attached.
Patch 5 disable BARs of the root complex that could claim the entire
memory region during PCI autoconfig.
Patch 6 adds support for the gpios prop to the fixed regulators driver.
Patch 7 adds a missing clock to the clock driver.
Patch 8 enables PCIe and NVMe support on rk3568-rock-3a.
Patch 9 updates the device tree with new reg and ranges values.

I have tested that a Samsung 970 EVO NVMe is detected on a ROCK 3A,

  BusDevFun  VendorId   DeviceId   Device Class   Sub-Class
  01.00.00   0x1d87 0x3566 Bridge device   0x04
  02.00.00   0x144d 0xa808 Mass storage controller 0x08

and I have also verified that the network controller continues to be
detected on a ROCK 5B.

  BusDevFun  VendorId   DeviceId   Device Class   Sub-Class
  00.00.00   0x1d87 0x3588 Bridge device   0x04
  01.00.00   0x10ec 0x8125 Network controller  0x00

Changes in v4:
- Replace "Hide BARs of the root complex" with "Disable unused BARs of
  the root complex" patch, based on vendor commit 1f4523203c2a ("driver:
  pci: rockchip: Disable RC BAR0 and BAR1")

Changed in v3:
- Rebased on master branch, all dependencies has been merged.
- Remove rk3568-rock-3a pcie2x1 workaround added in v2, basic reference
  counting of gpio regulators series has been merged.
- Enable options for AHCI/SCSI on rk3568-rock-3a.
- Collect r-b tags.

Changes in v2:
- Rebased on custodians/u-boot-rockchip master branch and the defconfig
  and spi v2 series at [1].
- Drop dependency on basic reference counting of gpio regulators series,
  pcie2x1 is disabled for rk3568-rock-3a to avoid a system freeze due to
  disable of a shared vpcie3v3-supply regulator while in use by pcie3x2.
- Add and use dev_read_addr_size_index_ptr function.
- Update commit messages.
- Collect r-b tags.

This series can also be found at [2].

[1] 
https://patchwork.ozlabs.org/project/uboot/cover/20230517182624.1765359-1-jo...@kwiboo.se/
[2] https://github.com/Kwiboo/u-boot-rockchip/commits/rk3568-pcie-v4

Jon Lin (1):
  pci: pcie_dw_rockchip: Disable unused BARs of the root complex

Jonas Karlman (8):
  core: read: add dev_read_addr_size_index_ptr function
  pci: pcie_dw_rockchip: Get config region from reg prop
  pci: pcie_dw_rockchip: Use regulator_set_enable_if_allowed
  pci: pcie_dw_rockchip: Speed up link probe
  regulator: fixed: Add support for gpios prop
  rockchip: clk: clk_rk3568: Add CLK_PCIEPHY2_REF support
  rockchip: rk3568-rock-3a: Enable PCIe and NVMe support
  rockchip: rk356x: Update PCIe config, IO and memory regions

 arch/arm/dts/rk3568-rock-3a-u-boot.dtsi | 14 
 arch/arm/dts/rk3568.dtsi| 14 ++--
 arch/arm/dts/rk356x.dtsi|  7 +-
 configs/rock-3a-rk3568_defconfig|  9 +++
 drivers/clk/rockchip/clk_rk3568.c   |  1 +
 drivers/core/read.c | 11 +++
 drivers/pci/pcie_dw_common.c| 10 ++-
 drivers/pci/pcie_dw_rockchip.c  | 98 +++--
 drivers/power/regulator/fixed.c |  4 +-
 include/dm/read.h   | 21 ++
 10 files changed, 135 insertions(+), 54 deletions(-)

-- 
2.41.0



[PATCH v4 1/9] core: read: add dev_read_addr_size_index_ptr function

2023-07-22 Thread Jonas Karlman
Add dev_read_addr_size_index_ptr function with the same functionality as
dev_read_addr_size_index, but instead a return pointer is given.
Use map_sysmem() function as cast for the return.

Signed-off-by: Jonas Karlman 
Reviewed-by: Kever Yang 
---
v4:
- No change

v3:
- Collect r-b tag

v2:
- New patch

 drivers/core/read.c | 11 +++
 include/dm/read.h   | 21 +
 2 files changed, 32 insertions(+)

diff --git a/drivers/core/read.c b/drivers/core/read.c
index 5749473a6cae..49066b59cdaf 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -150,6 +150,17 @@ fdt_addr_t dev_read_addr_size_index(const struct udevice 
*dev, int index,
return devfdt_get_addr_size_index(dev, index, size);
 }
 
+void *dev_read_addr_size_index_ptr(const struct udevice *dev, int index,
+  fdt_size_t *size)
+{
+   fdt_addr_t addr = dev_read_addr_size_index(dev, index, size);
+
+   if (addr == FDT_ADDR_T_NONE)
+   return NULL;
+
+   return map_sysmem(addr, 0);
+}
+
 void *dev_remap_addr_index(const struct udevice *dev, int index)
 {
fdt_addr_t addr = dev_read_addr_index(dev, index);
diff --git a/include/dm/read.h b/include/dm/read.h
index 137f2a52a298..c2615f72f405 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -246,6 +246,20 @@ void *dev_read_addr_index_ptr(const struct udevice *dev, 
int index);
 fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
fdt_size_t *size);
 
+/**
+ * dev_read_addr_size_index_ptr() - Get the indexed reg property of a device
+ *  as a pointer
+ *
+ * @dev: Device to read from
+ * @index: the 'reg' property can hold a list of  pairs
+ *and @index is used to select which one is required
+ * @size: place to put size value (on success)
+ *
+ * Return: pointer or NULL if not found
+ */
+void *dev_read_addr_size_index_ptr(const struct udevice *dev, int index,
+  fdt_size_t *size);
+
 /**
  * dev_remap_addr_index() - Get the indexed reg property of a device
  *   as a memory-mapped I/O pointer
@@ -952,6 +966,13 @@ static inline fdt_addr_t dev_read_addr_size_index(const 
struct udevice *dev,
return devfdt_get_addr_size_index(dev, index, size);
 }
 
+static inline void *dev_read_addr_size_index_ptr(const struct udevice *dev,
+int index,
+fdt_size_t *size)
+{
+   return devfdt_get_addr_size_index_ptr(dev, index, size);
+}
+
 static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
const char *name)
 {
-- 
2.41.0



[PATCH 1/1] riscv: qemu: provide more SPL boot methods

2023-07-22 Thread Heinrich Schuchardt
QEMU can supply block devices or semihosting to U-Boot SPL. Allow booting
from these.

Signed-off-by: Heinrich Schuchardt 
---
 board/emulation/qemu-riscv/qemu-riscv.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/board/emulation/qemu-riscv/qemu-riscv.c 
b/board/emulation/qemu-riscv/qemu-riscv.c
index ae3b7a3295..b2fe3e9f0c 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -69,10 +69,21 @@ int board_late_init(void)
 }
 
 #ifdef CONFIG_SPL
-u32 spl_boot_device(void)
+void board_boot_order(u32 *spl_boot_list)
 {
-   /* RISC-V QEMU only supports RAM as SPL boot device */
-   return BOOT_DEVICE_RAM;
+   int index = 0;
+
+   if (IS_ENABLED(CONFIG_SPL_NVME))
+   spl_boot_list[index++] = BOOT_DEVICE_NVME;
+   if (IS_ENABLED(CONFIG_SPL_SATA))
+   spl_boot_list[index++] = BOOT_DEVICE_SATA;
+   if (IS_ENABLED(CONFIG_SPL_USB_STORAGE))
+   spl_boot_list[index++] = BOOT_DEVICE_USB;
+   if (IS_ENABLED(CONFIG_SPL_SEMIHOSTING))
+   spl_boot_list[index++] = BOOT_DEVICE_SMH;
+   /* RAM last as CONFIG_SPL_RAW_IMAGE_SUPPORT=y may lead to crash */
+   if (IS_ENABLED(CONFIG_SPL_RAM_SUPPORT))
+   spl_boot_list[index++] = BOOT_DEVICE_RAM;
 }
 #endif
 
-- 
2.40.1



[PATCH 1/1] spl: blk: partition numbers are hexadecimal

2023-07-22 Thread Heinrich Schuchardt
Loading u-boot.itb from device 0x00, partition 0x0f fails with:

Trying to boot from NVME

Device 0: Vendor: 0x4x Rev: 8.0.50   Prod: nvme-1
Type: Hard Disk
Capacity: 3814.6 MB = 3.7 GB (7812500 x 512)
** Invalid partition 21 **
Couldn't find partition nvme 0:15

Like the command line interface fs_det_blk_dev() expects that the device
number and the partition number are hexadecimal.

Fixes: 8ce6a2e17577 ("spl: blk: Support loading images from fs")
Signed-off-by: Heinrich Schuchardt 
---
 common/spl/spl_blk_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/spl/spl_blk_fs.c b/common/spl/spl_blk_fs.c
index d4161fa850..16ecece702 100644
--- a/common/spl/spl_blk_fs.c
+++ b/common/spl/spl_blk_fs.c
@@ -66,7 +66,7 @@ int spl_blk_load_image(struct spl_image_info *spl_image,
}
 
dev.ifname = blk_get_uclass_name(uclass_id);
-   snprintf(dev.dev_part_str, sizeof(dev.dev_part_str) - 1, "%d:%d",
+   snprintf(dev.dev_part_str, sizeof(dev.dev_part_str) - 1, "%x:%x",
 devnum, partnum);
ret = fs_set_blk_dev(dev.ifname, dev.dev_part_str, FS_TYPE_ANY);
if (ret) {
-- 
2.40.1



Re: [PATCH v2 3/3] fixup! arm: dts: k3-am62: Bump dtsi from linux v6.5-rc1

2023-07-22 Thread Roger Quadros



On 21/07/2023 16:07, Maxime Ripard wrote:
> Dropping ranges entirely doesn't work since the register offset on the
> MDIO device node will now be completely off, so we need to adjust it to
> the right value without the translation.
> 
> We also need to have an empty ranges property for the reg address to be
> properly evaluated.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  arch/arm/dts/k3-am625-sk-u-boot.dtsi | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/dts/k3-am625-sk-u-boot.dtsi 
> b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
> index db814ed02a7e..77c9e4cb87f7 100644
> --- a/arch/arm/dts/k3-am625-sk-u-boot.dtsi
> +++ b/arch/arm/dts/k3-am625-sk-u-boot.dtsi
> @@ -119,8 +119,8 @@
>  };
>  
>  &cpsw3g {
> - /delete-property/ ranges;

cpsw-phy-sel will be broken in u-boot after you remove /delete-property/ ranges.
To fix this up we need to teach the am65-cpsw driver to fetch
the cpsw-phy-sel address from the phys property instead and drop
the cpsw-phy-sel child.

>   bootph-pre-ram;
> + ranges;

You don't have to add ranges here. am62-main.dtsi should have it in
the cpsw3g node.

>  
>   cpsw-phy-sel@04044 {
>   compatible = "ti,am64-phy-gmii-sel";
> @@ -129,6 +129,10 @@
>   };
>  };
>  
> +&cpsw3g_mdio {
> + reg = <0x0 0x8000f00 0x0 0x100>;
> +};
> +

This should not be required. The u-boot driver is still hard-coding
the MDIO address and Linux should get the right address based on
address translation of the child cpsw3g_mdio node.

>  &cpsw_port1 {
>   bootph-pre-ram;
>  };
> 

-- 
cheers,
-roger


Re: [PATCH v2 2/3] fixup! arm: dts: k3-am62: Bump dtsi from linux v6.5-rc1

2023-07-22 Thread Roger Quadros



On 21/07/2023 16:07, Maxime Ripard wrote:
> The MDIO pinctrl nodes can't be duplicated between the child and device,
> because if we ever boot Linux with our DT it will try to attach that
> pinctrl configuration to both the MAC and MDIO devices, which will
> result in failure to probe.
> 
> Signed-off-by: Maxime Ripard 

Acked-by: Roger Quadros 


Re: [PATCH v2 1/3] net: ti: am65-cpsw-nuss: Enforce pinctrl state on the MDIO child node

2023-07-22 Thread Roger Quadros
On 21/07/2023 16:07, Maxime Ripard wrote:
> The binding represents the MDIO controller as a child device tree
> node of the MAC device tree node.
> 
> The U-Boot driver mostly ignores that child device tree node and just
> hardcodes the resources it uses to support both the MAC and MDIO in a
> single driver.
> 
> However, some resources like pinctrl muxing states are thus ignored.
> This has been a problem with some device trees that will put some
> pinctrl states on the MDIO device tree node, like the SK-AM62 Device
> Tree does.

You don't clearly explain the problem.

I think you need to mention that there wash a hackish solution in place
that was duplicating MDIO pinctrl node in the CPSW node. And this causes
problems in Linux (if booted with u-boot's device tree)
due to 2 drivers (CPSW and MDIO) racing for the same MDIO pinctrl resource.

Then mention how you are fixing it.

By deleting the duplicate MDIO pinctrl entry from CPSW node.

> 
> Let's rework the driver a bit to create a dummy MDIO driver that we will
> then get during our initialization to force the core to select the right
> muxing.
> 
> Signed-off-by: Maxime Ripard 
> ---
>  drivers/net/ti/Kconfig  |  1 +
>  drivers/net/ti/am65-cpsw-nuss.c | 67 
> +
>  2 files changed, 68 insertions(+)
> 
> diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
> index e13dbc940182..08c81f79adf9 100644
> --- a/drivers/net/ti/Kconfig
> +++ b/drivers/net/ti/Kconfig
> @@ -41,6 +41,7 @@ endchoice
>  config TI_AM65_CPSW_NUSS
>   bool "TI K3 AM65x MCU CPSW Nuss Ethernet controller driver"
>   depends on ARCH_K3
> + imply DM_MDIO
>   imply MISC_INIT_R
>   imply MISC
>   select PHYLIB
> diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
> index 3069550d53c2..ac7907e7ef70 100644
> --- a/drivers/net/ti/am65-cpsw-nuss.c
> +++ b/drivers/net/ti/am65-cpsw-nuss.c
> @@ -15,6 +15,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -580,14 +581,69 @@ static const struct soc_attr k3_mdio_soc_data[] = {
>   { /* sentinel */ },
>  };
>  
> +static ofnode am65_cpsw_find_mdio(ofnode parent)
> +{
> + ofnode node;
> +
> + ofnode_for_each_subnode(node, parent)
> + if (ofnode_device_is_compatible(node, "ti,cpsw-mdio"))
> + return node;
> +
> + return ofnode_null();
> +}
> +
> +static int am65_cpsw_mdio_setup(struct udevice *dev)
> +{
> + struct am65_cpsw_priv *priv = dev_get_priv(dev);
> + struct am65_cpsw_common *cpsw_common = priv->cpsw_common;
> + struct udevice *mdio_dev;
> + ofnode mdio;
> + int ret;
> +
> + mdio = am65_cpsw_find_mdio(dev_ofnode(cpsw_common->dev));
> + if (!ofnode_valid(mdio))
> + return -ENODEV;

Do we really want to treat this as an error?

As per Linux/Documentation/devicetree/bindings/net/ti,k3-am654-cpsw-nuss.yaml
mdio node is not a required property/child.

> +
> + /*
> +  * The MDIO controller is represented in the DT binding by a
> +  * subnode of the MAC controller.
> +  *
> +  * Our driver largely ignores that and supports MDIO by
> +  * hardcoding the register offsets.
> +  *
> +  * However, some resources (clocks, pinctrl) might be tied to
> +  * the MDIO node, and thus ignored.
> +  *
> +  * Clocks are not a concern at the moment since it's shared
> +  * between the MAC and MDIO, so the driver handles both at the
> +  * same time.

I think you can drop the above 3 paras and instead say
"We don't yet have a DM device driver for the MDIO device and so its
pinctrl setting will be ignored."

> +  *
> +  * However, we do need to make sure the pins states tied to the
> +  * MDIO node are configured properly. Fortunately, the core DM
> +  * does that for use when we get a device, so we can work around
> +  * that whole issue by just requesting a dummy MDIO driver to
> +  * probe, and our pins will get muxed.
> +  */
> + ret = uclass_get_device_by_ofnode(UCLASS_MDIO, mdio, &mdio_dev);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
> +
>  static int am65_cpsw_mdio_init(struct udevice *dev)
>  {
>   struct am65_cpsw_priv *priv = dev_get_priv(dev);
>   struct am65_cpsw_common *cpsw_common = priv->cpsw_common;
> + int ret;
>  
>   if (!priv->has_phy || cpsw_common->bus)
>   return 0;
>  
> + ret = am65_cpsw_mdio_setup(dev);
> + if (ret)
> + return ret;
> +
>   cpsw_common->bus = cpsw_mdio_init(dev->name,
> cpsw_common->mdio_base,
> cpsw_common->bus_freq,
> @@ -854,3 +910,14 @@ U_BOOT_DRIVER(am65_cpsw_nuss_port) = {
>   .plat_auto  = sizeof(struct eth_pdata),
>   .flags = DM_FLAG_ALLOC_PRIV_DMA | DM_FLAG_OS_PREPARE,
>  };
> +
> +static const struct udevice_id am65_cpsw_mdio

Re: [PATCH] usb: cdns3: gadget: Configure speed in udc_start

2023-07-22 Thread Roger Quadros



On 19/07/2023 11:59, Ravi Gunasekaran wrote:
> When one of the functions does not support super speed, the composite
> driver forces the gadget to high speed. But the speed is never
> configured in the cdns3 gadget driver. So configure the speed
> in cdns3_gadget_udc_start just like in the kernel.
> 
> Signed-off-by: Ravi Gunasekaran 

Reviewed-by: Roger Quadros