Re: [PATCH 1/2] virtio: New virtio_gpu driver

2024-05-16 Thread Jiaxun Yang



在2024年5月17日五月 上午2:56,Heinrich Schuchardt写道:
[...]
>>+config VIRTIO_GPU_SIZE_X
>>+ int "Width of display (X resolution)"
>>+ default 1280
>
> 1920x1080 would look like a reasonable default for me.

1280x1024 was chosen because it is the largest resolution being defined in
VESA VBE, hence guaranteed compatibility everywhere. I think it's Linux's
behaviour as well.

Carving out a huge framebuffer out of memory might be a challenge on
some platforms, so I'd like to keep it small.

>
>
>>+ help
>>+   Sets the width of the display.
>>+
>>+   These two options control the size of the display set up by QEMU.
>>+   Typical sizes are 1024 x 768 or 1280 x 1024.
>>+
>>+config VIRTIO_GPU_SIZE_Y
>>+ int "High of display (Y resolution)"
>>+ default 1024
>>+ help
>>+   Sets the height of the display.
>>+
>>+   These two options control the size of the display set up by QEMU.
>>+   Typical sizes are 1024 x 768 or 1280 x 1024.
>
> Haven't had such small monitors for a while. Why should this be typical?

Haha I copied this from bochs driver's help text, I can replace it with
more reasonable text.

>
> Doesn't QEMU allow to read the size of the output window at runtime?

Unfortunately, it's always guest to determine the size of display.
VIRTIO_GPU_CMD_GET_DISPLAY_INFO simply returned 0 as size of the scanout
before guest initialize it first.

It is possible to parse EDID provided by QEMU to get a resolution list,
but I found implementing the whole modesetting procdure here is a little
bit unnecessary.

I think resizing display in OS is generally done with VMM's guest agent.

>
> Best regards
>
> Heinrich
>

-- 
- Jiaxun


Re: [PATCH 2/2] efi: gop: Mark pixel_format as BLTONLY if we have sync hook

2024-05-16 Thread Jiaxun Yang



在2024年5月17日五月 上午2:44,Heinrich Schuchardt写道:
[...]
Hi Heinrich,
>> 
>>  plat = dev_get_uclass_plat(vdev);
>>+ ops = video_get_ops(vid);
>>  fb_base = IS_ENABLED(CONFIG_VIDEO_COPY) ? plat->copy_base : plat->base;
>
> Wasn't this line introduced to handle the video sync case by pointing 
> the EFI application to target framebuffer?

This is used to handle the case that U-Boot itself is performing a copy
from U-Boot's shadow buffer to the target buffer.

However, in virtio-gpu (and some other driver like syncoam,seps525, ste,mcde)
cases hardware needs to be notified for any update to the framebuffer.

For those hardwares if application just write to target framebuffer the display
won't be updated. Hence we must direct applications to call BLT to allow 
hardware
being notified when framebuffer is changed.

Thanks

>
> Best regards
>
> Heinrich
>
-- 
- Jiaxun


Re: [PATCH 1/2] virtio: New virtio_gpu driver

2024-05-16 Thread Heinrich Schuchardt



Am 17. Mai 2024 01:03:24 MESZ schrieb Jiaxun Yang :
>This driver is implemened based on latest VirtIO spec.
>It follows operation prodcure as defined in the spec.
>
>It implemented multihead (mirroring) support as well.
>
>Signed-off-by: Jiaxun Yang 
>---
> drivers/virtio/Kconfig |  29 +++
> drivers/virtio/Makefile|   1 +
> drivers/virtio/virtio-uclass.c |   1 +
> drivers/virtio/virtio_gpu.c| 298 
> drivers/virtio/virtio_gpu.h| 428 +
> include/virtio.h   |   4 +-
> 6 files changed, 760 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
>index 1de68867d52e..b75572c4ad13 100644
>--- a/drivers/virtio/Kconfig
>+++ b/drivers/virtio/Kconfig
>@@ -76,4 +76,33 @@ config VIRTIO_RNG
>   help
> This is the virtual random number generator driver. It can be used
> with QEMU based targets.
>+
>+ config VIRTIO_GPU
>+  bool "virtio GPU driver"
>+  depends on VIRTIO && VIDEO
>+  default y
>+  help
>+This is the virtual GPU display for virtio. It can be used with QEMU
>+based targets.
>+
>+if VIRTIO_GPU
>+config VIRTIO_GPU_SIZE_X
>+  int "Width of display (X resolution)"
>+  default 1280

1920x1080 would look like a reasonable default for me.


>+  help
>+Sets the width of the display.
>+
>+These two options control the size of the display set up by QEMU.
>+Typical sizes are 1024 x 768 or 1280 x 1024.
>+
>+config VIRTIO_GPU_SIZE_Y
>+  int "High of display (Y resolution)"
>+  default 1024
>+  help
>+Sets the height of the display.
>+
>+These two options control the size of the display set up by QEMU.
>+Typical sizes are 1024 x 768 or 1280 x 1024.

Haven't had such small monitors for a while. Why should this be typical?

Doesn't QEMU allow to read the size of the output window at runtime?

Best regards

Heinrich

>+
>+endif
> endmenu
>diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
>index 4c63a6c69043..c830fb6e6049 100644
>--- a/drivers/virtio/Makefile
>+++ b/drivers/virtio/Makefile
>@@ -11,3 +11,4 @@ obj-$(CONFIG_VIRTIO_SANDBOX) += virtio_sandbox.o
> obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
> obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
> obj-$(CONFIG_VIRTIO_RNG) += virtio_rng.o
>+obj-$(CONFIG_VIRTIO_GPU) += virtio_gpu.o
>diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c
>index 1dbc1a56aa21..1f3cdbf689c4 100644
>--- a/drivers/virtio/virtio-uclass.c
>+++ b/drivers/virtio/virtio-uclass.c
>@@ -30,6 +30,7 @@ static const char *const virtio_drv_name[VIRTIO_ID_MAX_NUM] 
>= {
>   [VIRTIO_ID_NET] = VIRTIO_NET_DRV_NAME,
>   [VIRTIO_ID_BLOCK]   = VIRTIO_BLK_DRV_NAME,
>   [VIRTIO_ID_RNG] = VIRTIO_RNG_DRV_NAME,
>+  [VIRTIO_ID_GPU] = VIRTIO_GPU_DRV_NAME,
> };
> 
> int virtio_get_config(struct udevice *vdev, unsigned int offset,
>diff --git a/drivers/virtio/virtio_gpu.c b/drivers/virtio/virtio_gpu.c
>new file mode 100644
>index ..d798562ecba2
>--- /dev/null
>+++ b/drivers/virtio/virtio_gpu.c
>@@ -0,0 +1,298 @@
>+// SPDX-License-Identifier: GPL-2.0+
>+/*
>+ * Copyright (C) 2024, Jiaxun Yang 
>+ */
>+
>+#define pr_fmt(fmt) "virtio_gpu: " fmt
>+
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include 
>+#include "virtio_gpu.h"
>+#include 
>+
>+struct virtio_gpu_priv {
>+  struct virtqueue *vq;
>+  u32 scanout_res_id;
>+  u64 fence_id;
>+  bool in_sync;
>+};
>+
>+static int virtio_gpu_do_req(struct udevice *dev,
>+   enum virtio_gpu_ctrl_type type,
>+   void *in, size_t in_size,
>+   void *out, size_t out_size, bool flush)
>+{
>+  int ret;
>+  uint len;
>+  struct virtio_gpu_priv *priv = dev_get_priv(dev);
>+  struct virtio_sg in_sg;
>+  struct virtio_sg out_sg;
>+  struct virtio_sg *sgs[] = { _sg, _sg };
>+  struct virtio_gpu_ctrl_hdr *ctrl_hdr_in = in;
>+  struct virtio_gpu_ctrl_hdr *ctrl_hdr_out = out;
>+
>+  ctrl_hdr_in->type = cpu_to_virtio32(dev, (u32)type);
>+  if (flush) {
>+  ctrl_hdr_in->flags = cpu_to_virtio32(dev, 
>VIRTIO_GPU_FLAG_FENCE);
>+  ctrl_hdr_in->fence_id = cpu_to_virtio64(dev, priv->fence_id++);
>+  } else {
>+  ctrl_hdr_in->flags = 0;
>+  ctrl_hdr_in->fence_id = 0;
>+  }
>+  ctrl_hdr_in->ctx_id = 0;
>+  ctrl_hdr_in->ring_idx = 0;
>+  in_sg.addr = in;
>+  in_sg.length = in_size;
>+  out_sg.addr = out;
>+  out_sg.length = out_size;
>+
>+  ret = virtqueue_add(priv->vq, sgs, 1, 1);
>+  if (ret) {
>+  log_debug("virtqueue_add failed %d\n", ret);
>+  return ret;
>+  }
>+  virtqueue_kick(priv->vq);
>+
>+  debug("wait...");
>+  while (!virtqueue_get_buf(priv->vq, ))
>+  ;
>+

Re: [PATCH 2/2] efi: gop: Mark pixel_format as BLTONLY if we have sync hook

2024-05-16 Thread Heinrich Schuchardt



Am 17. Mai 2024 01:03:25 MESZ schrieb Jiaxun Yang :
>If a video device has a video_sync hook, it means some software
>intervene is required to scanout framebuffer up on change.
>
>That means EFI application can't just use it as raw framebuffer,
>it should call BLT operation to let U-Boot help with scanout.
>
>Mark pixel format as BLTONLY as per UEFI spec to reflect this
>nature.
>
>Signed-off-by: Jiaxun Yang 
>---
> include/efi_api.h| 1 +
> lib/efi_loader/efi_gop.c | 9 -
> 2 files changed, 9 insertions(+), 1 deletion(-)
>
>diff --git a/include/efi_api.h b/include/efi_api.h
>index ab40b1b5ddf6..3eaefb322878 100644
>--- a/include/efi_api.h
>+++ b/include/efi_api.h
>@@ -1399,6 +1399,7 @@ struct efi_hii_config_access_protocol {
> #define EFI_GOT_RGBA8 0
> #define EFI_GOT_BGRA8 1
> #define EFI_GOT_BITMASK   2
>+#define EFI_GOT_BLTONLY   3
> 
> struct efi_gop_mode_info {
>   u32 version;
>diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
>index 41e12fa72460..784d43d3d39b 100644
>--- a/lib/efi_loader/efi_gop.c
>+++ b/lib/efi_loader/efi_gop.c
>@@ -467,10 +467,12 @@ efi_status_t efi_gop_register(void)
>   struct efi_gop_obj *gopobj;
>   u32 bpix, format, col, row;
>   u64 fb_base, fb_size;
>+  bool needs_sync;
>   efi_status_t ret;
>   struct udevice *vdev;
>   struct video_priv *priv;
>   struct video_uc_plat *plat;
>+  struct video_ops *ops;
> 
>   /* We only support a single video output device for now */
>   if (uclass_first_device_err(UCLASS_VIDEO, )) {
>@@ -485,6 +487,7 @@ efi_status_t efi_gop_register(void)
>   row = video_get_ysize(vdev);
> 
>   plat = dev_get_uclass_plat(vdev);
>+  ops = video_get_ops(vid);
>   fb_base = IS_ENABLED(CONFIG_VIDEO_COPY) ? plat->copy_base : plat->base;

Wasn't this line introduced to handle the video sync case by pointing the EFI 
application to target framebuffer?

Best regards

Heinrich

>   fb_size = plat->size;
> 
>@@ -529,7 +532,11 @@ efi_status_t efi_gop_register(void)
>   gopobj->info.version = 0;
>   gopobj->info.width = col;
>   gopobj->info.height = row;
>-  if (bpix == VIDEO_BPP32)
>+
>+  if (ops && ops->video_sync) {
>+  /* Applications can't really use it as framebuffer */
>+  gopobj->info.pixel_format = EFI_GOT_BLTONLY;
>+  } else if (bpix == VIDEO_BPP32)
>   {
>   if (format == VIDEO_X2R10G10B10) {
>   gopobj->info.pixel_format = EFI_GOT_BITMASK;
>


Re: [PATCH v3 4/4] imx: hab: Use nxp_imx8mcst etype for i.MX8M flash.bin signing

2024-05-16 Thread Marek Vasut

On 5/16/24 11:40 PM, Tim Harvey wrote:

[...]


-The entire script is available in doc/imx/habv4/csf_examples/mx8m/csf.sh
-and can be used as follows to modify flash.bin to be signed
-(adjust paths as needed):
-```
-export CST_DIR=/usr/src/cst-3.3.1/
-export CSF_KEY=$CST_DIR/crts/CSF1_1_sha256_4096_65537_v3_usr_crt.pem
-export IMG_KEY=$CST_DIR/crts/IMG1_1_sha256_4096_65537_v3_usr_crt.pem
-export SRK_TABLE=$CST_DIR/crts/SRK_1_2_3_4_table.bin
-export PATH=$CST_DIR/linux64/bin:$PATH


Hi Marek,

I thought you were going to leave the above env setting examples in
the documentation.

I suggest showing how to specify using env (by just leaving the above
in) as well as by copying them directly to the build directory if
wanted.. otherwise the documentation is lacking.


If the tool can do env vars now, I would like to avoid copying key 
material around. So what about this:


diff --git a/doc/imx/habv4/guides/mx8m_spl_secure_boot.txt 
b/doc/imx/habv4/guides/mx8m_spl_secure_boot.txt

index 1eb1fb0aa61..257ffb45656 100644
--- a/doc/imx/habv4/guides/mx8m_spl_secure_boot.txt
+++ b/doc/imx/habv4/guides/mx8m_spl_secure_boot.txt
@@ -144,6 +144,8 @@ The signing is activated by wrapping SPL and 
fitImage sections into nxp-imx8mcst
 etype, which is done automatically in 
arch/arm/dts/imx8m{m,n,p,q}-u-boot.dtsi

 in case CONFIG_IMX_HAB Kconfig symbol is enabled.

+Build of flash.bin target then produces a signed flash.bin automatically.
+
 The nxp-imx8mcst etype is configurable using either DT properties or 
environment
 variables. The following DT properties and environment variables are 
supported.

 Note that environment variables override DT properties.
@@ -160,7 +162,15 @@ Note that environment variables override DT properties.
 | nxp,img-crt| IMG_KEY   | full path to the IMG Key 
IMG1_1_sha256_4096_65537_v3_usr_crt.pem |


++---+--+

-Build of flash.bin target then produces a signed flash.bin automatically.
+Environment variables can be set as follows to point the build process
+to external key material:
+```
+export CST_DIR=/usr/src/cst-3.3.1/
+export CSF_KEY=$CST_DIR/crts/CSF1_1_sha256_4096_65537_v3_usr_crt.pem
+export IMG_KEY=$CST_DIR/crts/IMG1_1_sha256_4096_65537_v3_usr_crt.pem
+export SRK_TABLE=$CST_DIR/crts/SRK_1_2_3_4_table.bin
+make flash.bin
+```

 1.4 Closing the device
 ---



[PATCH] ARM: dts: stm32: Add generic SoM compatible to STM32MP15xx DH electronics DHSOM

2024-05-16 Thread Marek Vasut
Add generic SoM compatible string into machine compatible string
for all STM32MP15xx based DH electronics DHSOM. This way, common
board code can match on this compatible. No functional change.

Signed-off-by: Marek Vasut 
---
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
Cc: Simon Glass 
Cc: Tom Rini 
Cc: u-b...@dh-electronics.com
Cc: u-boot@lists.denx.de
Cc: uboot-st...@st-md-mailman.stormreply.com
---
 arch/arm/dts/stm32mp15xx-dhcom-drc02.dts   | 4 +++-
 arch/arm/dts/stm32mp15xx-dhcom-pdk2.dts| 4 +++-
 arch/arm/dts/stm32mp15xx-dhcom-picoitx.dts | 4 +++-
 arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts   | 4 +++-
 arch/arm/dts/stm32mp15xx-dhcor-drc-compact.dts | 4 +++-
 arch/arm/dts/stm32mp15xx-dhcor-testbench.dts   | 4 +++-
 6 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/arch/arm/dts/stm32mp15xx-dhcom-drc02.dts 
b/arch/arm/dts/stm32mp15xx-dhcom-drc02.dts
index 1ef9ac29cea..90625bf6b60 100644
--- a/arch/arm/dts/stm32mp15xx-dhcom-drc02.dts
+++ b/arch/arm/dts/stm32mp15xx-dhcom-drc02.dts
@@ -11,5 +11,7 @@
 
 / {
model = "DH Electronics STM32MP15xx DHCOM DRC02";
-   compatible = "dh,stm32mp15xx-dhcom-drc02", "st,stm32mp1xx";
+   compatible = "dh,stm32mp15xx-dhcom-drc02",
+"dh,stm32mp15xx-dhcom-som",
+"st,stm32mp1xx";
 };
diff --git a/arch/arm/dts/stm32mp15xx-dhcom-pdk2.dts 
b/arch/arm/dts/stm32mp15xx-dhcom-pdk2.dts
index e2e01e2146c..b2e450aa13b 100644
--- a/arch/arm/dts/stm32mp15xx-dhcom-pdk2.dts
+++ b/arch/arm/dts/stm32mp15xx-dhcom-pdk2.dts
@@ -11,5 +11,7 @@
 
 / {
model = "STMicroelectronics STM32MP15xx DHCOM Premium Developer Kit 
(2)";
-   compatible = "dh,stm32mp15xx-dhcom-pdk2", "st,stm32mp15x";
+   compatible = "dh,stm32mp15xx-dhcom-pdk2",
+"dh,stm32mp15xx-dhcom-som",
+"st,stm32mp15x";
 };
diff --git a/arch/arm/dts/stm32mp15xx-dhcom-picoitx.dts 
b/arch/arm/dts/stm32mp15xx-dhcom-picoitx.dts
index 06770b47873..3e908102f61 100644
--- a/arch/arm/dts/stm32mp15xx-dhcom-picoitx.dts
+++ b/arch/arm/dts/stm32mp15xx-dhcom-picoitx.dts
@@ -11,5 +11,7 @@
 
 / {
model = "DH Electronics STM32MP15xx DHCOM PicoITX";
-   compatible = "dh,stm32mp15xx-dhcom-picoitx", "st,stm32mp1xx";
+   compatible = "dh,stm32mp15xx-dhcom-picoitx",
+"dh,stm32mp15xx-dhcom-som",
+"st,stm32mp1xx";
 };
diff --git a/arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts 
b/arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts
index 76ac5a873c1..dd8fcecbca5 100644
--- a/arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts
+++ b/arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts
@@ -14,5 +14,7 @@
 
 / {
model = "Arrow Electronics STM32MP15xx Avenger96 board";
-   compatible = "arrow,stm32mp15xx-avenger96", "st,stm32mp15x";
+   compatible = "arrow,stm32mp15xx-avenger96",
+"dh,stm32mp15xx-dhcor-som",
+"st,stm32mp15x";
 };
diff --git a/arch/arm/dts/stm32mp15xx-dhcor-drc-compact.dts 
b/arch/arm/dts/stm32mp15xx-dhcor-drc-compact.dts
index 77dd944ff53..c1f99c1685e 100644
--- a/arch/arm/dts/stm32mp15xx-dhcor-drc-compact.dts
+++ b/arch/arm/dts/stm32mp15xx-dhcor-drc-compact.dts
@@ -12,5 +12,7 @@
 
 / {
model = "DH electronics STM32MP15xx DHCOR DRC Compact";
-   compatible = "dh,stm32mp15xx-dhcor-drc-compact", "st,stm32mp1xx";
+   compatible = "dh,stm32mp15xx-dhcor-drc-compact",
+"dh,stm32mp15xx-dhcor-som",
+"st,stm32mp1xx";
 };
diff --git a/arch/arm/dts/stm32mp15xx-dhcor-testbench.dts 
b/arch/arm/dts/stm32mp15xx-dhcor-testbench.dts
index c9163e1c028..5fdd762ddbf 100644
--- a/arch/arm/dts/stm32mp15xx-dhcor-testbench.dts
+++ b/arch/arm/dts/stm32mp15xx-dhcor-testbench.dts
@@ -9,7 +9,9 @@
 
 / {
model = "DH electronics STM32MP15xx DHCOR Testbench";
-   compatible = "dh,stm32mp15xx-dhcor-testbench", "st,stm32mp1xx";
+   compatible = "dh,stm32mp15xx-dhcor-testbench",
+"dh,stm32mp15xx-dhcor-som",
+"st,stm32mp1xx";
 
aliases {
ethernet0 = 
-- 
2.43.0



Re: [PATCH 0/2] virtio_gpu driver and relevant fix

2024-05-16 Thread Jiaxun Yang



在2024年5月17日五月 上午12:03,Jiaxun Yang写道:
> Hi all,
>
> This series added support for virtio-gpu device, it has been
> tested on QEMU riscv64 and aarch64.
>
> I also fixed a problem in EFI GOP so it works with EFI applications
> as well.
>
> There is a problem remaining. virtio_init() is being called too
> late to allow virtio-gpu to be selected as a vidconsole. My current
> appraoch is to register virtio_init in init_sequence_r, just after
> pci_init. Is this a viable approach? Should I introduce a config
> like CONFIG_VIRTIO_INIT_R to allow it to be selected by boards?

Just realized I made a mistake on preparing patches to be sent.

Two tiny modifications are missing from this series, dual endian
handling in patch 1 and removing an unused variable in patch 2.

I'll update a reversion, meanwhile fell free to review the current
version.

Apologize for the noise.

Thanks
- Jiaxun

>
> Thanks
>
> Signed-off-by: Jiaxun Yang 
> ---
> Jiaxun Yang (2):
>   virtio: New virtio_gpu driver
>   efi: gop: Mark pixel_format as BLTONLY if we have sync hook
>
>  drivers/virtio/Kconfig |  29 +++
>  drivers/virtio/Makefile|   1 +
>  drivers/virtio/virtio-uclass.c |   1 +
>  drivers/virtio/virtio_gpu.c| 298 
>  drivers/virtio/virtio_gpu.h| 428 
> +
>  include/efi_api.h  |   1 +
>  include/virtio.h   |   4 +-
>  lib/efi_loader/efi_gop.c   |   9 +-
>  8 files changed, 769 insertions(+), 2 deletions(-)
> ---
> base-commit: 21aa37ec1cd4a12e01e0e863ec9e99d703ce4d52
> change-id: 20240513-virtio_gpu-abb4de685808
>
> Best regards,
> -- 
> Jiaxun Yang 

-- 
- Jiaxun


[PATCH 2/2] efi: gop: Mark pixel_format as BLTONLY if we have sync hook

2024-05-16 Thread Jiaxun Yang
If a video device has a video_sync hook, it means some software
intervene is required to scanout framebuffer up on change.

That means EFI application can't just use it as raw framebuffer,
it should call BLT operation to let U-Boot help with scanout.

Mark pixel format as BLTONLY as per UEFI spec to reflect this
nature.

Signed-off-by: Jiaxun Yang 
---
 include/efi_api.h| 1 +
 lib/efi_loader/efi_gop.c | 9 -
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/efi_api.h b/include/efi_api.h
index ab40b1b5ddf6..3eaefb322878 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1399,6 +1399,7 @@ struct efi_hii_config_access_protocol {
 #define EFI_GOT_RGBA8  0
 #define EFI_GOT_BGRA8  1
 #define EFI_GOT_BITMASK2
+#define EFI_GOT_BLTONLY3
 
 struct efi_gop_mode_info {
u32 version;
diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c
index 41e12fa72460..784d43d3d39b 100644
--- a/lib/efi_loader/efi_gop.c
+++ b/lib/efi_loader/efi_gop.c
@@ -467,10 +467,12 @@ efi_status_t efi_gop_register(void)
struct efi_gop_obj *gopobj;
u32 bpix, format, col, row;
u64 fb_base, fb_size;
+   bool needs_sync;
efi_status_t ret;
struct udevice *vdev;
struct video_priv *priv;
struct video_uc_plat *plat;
+   struct video_ops *ops;
 
/* We only support a single video output device for now */
if (uclass_first_device_err(UCLASS_VIDEO, )) {
@@ -485,6 +487,7 @@ efi_status_t efi_gop_register(void)
row = video_get_ysize(vdev);
 
plat = dev_get_uclass_plat(vdev);
+   ops = video_get_ops(vid);
fb_base = IS_ENABLED(CONFIG_VIDEO_COPY) ? plat->copy_base : plat->base;
fb_size = plat->size;
 
@@ -529,7 +532,11 @@ efi_status_t efi_gop_register(void)
gopobj->info.version = 0;
gopobj->info.width = col;
gopobj->info.height = row;
-   if (bpix == VIDEO_BPP32)
+
+   if (ops && ops->video_sync) {
+   /* Applications can't really use it as framebuffer */
+   gopobj->info.pixel_format = EFI_GOT_BLTONLY;
+   } else if (bpix == VIDEO_BPP32)
{
if (format == VIDEO_X2R10G10B10) {
gopobj->info.pixel_format = EFI_GOT_BITMASK;

-- 
2.34.1



[PATCH 1/2] virtio: New virtio_gpu driver

2024-05-16 Thread Jiaxun Yang
This driver is implemened based on latest VirtIO spec.
It follows operation prodcure as defined in the spec.

It implemented multihead (mirroring) support as well.

Signed-off-by: Jiaxun Yang 
---
 drivers/virtio/Kconfig |  29 +++
 drivers/virtio/Makefile|   1 +
 drivers/virtio/virtio-uclass.c |   1 +
 drivers/virtio/virtio_gpu.c| 298 
 drivers/virtio/virtio_gpu.h| 428 +
 include/virtio.h   |   4 +-
 6 files changed, 760 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 1de68867d52e..b75572c4ad13 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -76,4 +76,33 @@ config VIRTIO_RNG
help
  This is the virtual random number generator driver. It can be used
  with QEMU based targets.
+
+ config VIRTIO_GPU
+   bool "virtio GPU driver"
+   depends on VIRTIO && VIDEO
+   default y
+   help
+ This is the virtual GPU display for virtio. It can be used with QEMU
+ based targets.
+
+if VIRTIO_GPU
+config VIRTIO_GPU_SIZE_X
+   int "Width of display (X resolution)"
+   default 1280
+   help
+ Sets the width of the display.
+
+ These two options control the size of the display set up by QEMU.
+ Typical sizes are 1024 x 768 or 1280 x 1024.
+
+config VIRTIO_GPU_SIZE_Y
+   int "High of display (Y resolution)"
+   default 1024
+   help
+ Sets the height of the display.
+
+ These two options control the size of the display set up by QEMU.
+ Typical sizes are 1024 x 768 or 1280 x 1024.
+
+endif
 endmenu
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 4c63a6c69043..c830fb6e6049 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_VIRTIO_SANDBOX) += virtio_sandbox.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio_rng.o
+obj-$(CONFIG_VIRTIO_GPU) += virtio_gpu.o
diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c
index 1dbc1a56aa21..1f3cdbf689c4 100644
--- a/drivers/virtio/virtio-uclass.c
+++ b/drivers/virtio/virtio-uclass.c
@@ -30,6 +30,7 @@ static const char *const virtio_drv_name[VIRTIO_ID_MAX_NUM] = 
{
[VIRTIO_ID_NET] = VIRTIO_NET_DRV_NAME,
[VIRTIO_ID_BLOCK]   = VIRTIO_BLK_DRV_NAME,
[VIRTIO_ID_RNG] = VIRTIO_RNG_DRV_NAME,
+   [VIRTIO_ID_GPU] = VIRTIO_GPU_DRV_NAME,
 };
 
 int virtio_get_config(struct udevice *vdev, unsigned int offset,
diff --git a/drivers/virtio/virtio_gpu.c b/drivers/virtio/virtio_gpu.c
new file mode 100644
index ..d798562ecba2
--- /dev/null
+++ b/drivers/virtio/virtio_gpu.c
@@ -0,0 +1,298 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2024, Jiaxun Yang 
+ */
+
+#define pr_fmt(fmt) "virtio_gpu: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "virtio_gpu.h"
+#include 
+
+struct virtio_gpu_priv {
+   struct virtqueue *vq;
+   u32 scanout_res_id;
+   u64 fence_id;
+   bool in_sync;
+};
+
+static int virtio_gpu_do_req(struct udevice *dev,
+enum virtio_gpu_ctrl_type type,
+void *in, size_t in_size,
+void *out, size_t out_size, bool flush)
+{
+   int ret;
+   uint len;
+   struct virtio_gpu_priv *priv = dev_get_priv(dev);
+   struct virtio_sg in_sg;
+   struct virtio_sg out_sg;
+   struct virtio_sg *sgs[] = { _sg, _sg };
+   struct virtio_gpu_ctrl_hdr *ctrl_hdr_in = in;
+   struct virtio_gpu_ctrl_hdr *ctrl_hdr_out = out;
+
+   ctrl_hdr_in->type = cpu_to_virtio32(dev, (u32)type);
+   if (flush) {
+   ctrl_hdr_in->flags = cpu_to_virtio32(dev, 
VIRTIO_GPU_FLAG_FENCE);
+   ctrl_hdr_in->fence_id = cpu_to_virtio64(dev, priv->fence_id++);
+   } else {
+   ctrl_hdr_in->flags = 0;
+   ctrl_hdr_in->fence_id = 0;
+   }
+   ctrl_hdr_in->ctx_id = 0;
+   ctrl_hdr_in->ring_idx = 0;
+   in_sg.addr = in;
+   in_sg.length = in_size;
+   out_sg.addr = out;
+   out_sg.length = out_size;
+
+   ret = virtqueue_add(priv->vq, sgs, 1, 1);
+   if (ret) {
+   log_debug("virtqueue_add failed %d\n", ret);
+   return ret;
+   }
+   virtqueue_kick(priv->vq);
+
+   debug("wait...");
+   while (!virtqueue_get_buf(priv->vq, ))
+   ;
+   debug("done\n");
+
+   if (out_size != len) {
+   log_debug("Invalid response size %d, expected %d\n",
+ len, (uint)out_size);
+   }
+
+   return virtio32_to_cpu(dev, ctrl_hdr_out->type);
+}
+
+static int virtio_gpu_probe(struct udevice *dev)
+{
+   struct virtio_gpu_priv *priv = dev_get_priv(dev);
+   

[PATCH 0/2] virtio_gpu driver and relevant fix

2024-05-16 Thread Jiaxun Yang
Hi all,

This series added support for virtio-gpu device, it has been
tested on QEMU riscv64 and aarch64.

I also fixed a problem in EFI GOP so it works with EFI applications
as well.

There is a problem remaining. virtio_init() is being called too
late to allow virtio-gpu to be selected as a vidconsole. My current
appraoch is to register virtio_init in init_sequence_r, just after
pci_init. Is this a viable approach? Should I introduce a config
like CONFIG_VIRTIO_INIT_R to allow it to be selected by boards?

Thanks

Signed-off-by: Jiaxun Yang 
---
Jiaxun Yang (2):
  virtio: New virtio_gpu driver
  efi: gop: Mark pixel_format as BLTONLY if we have sync hook

 drivers/virtio/Kconfig |  29 +++
 drivers/virtio/Makefile|   1 +
 drivers/virtio/virtio-uclass.c |   1 +
 drivers/virtio/virtio_gpu.c| 298 
 drivers/virtio/virtio_gpu.h| 428 +
 include/efi_api.h  |   1 +
 include/virtio.h   |   4 +-
 lib/efi_loader/efi_gop.c   |   9 +-
 8 files changed, 769 insertions(+), 2 deletions(-)
---
base-commit: 21aa37ec1cd4a12e01e0e863ec9e99d703ce4d52
change-id: 20240513-virtio_gpu-abb4de685808

Best regards,
-- 
Jiaxun Yang 



Re: [PATCH 1/6] video: Move generated bmp headers to include/generated

2024-05-16 Thread Tom Rini
On Thu, May 16, 2024 at 11:16:41PM +0100, Jiaxun Yang wrote:

> Emphasis that those headers are generated.
> Also naturally gitignore them.
> 
> Signed-off-by: Jiaxun Yang 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


[PATCH 6/6] video: bochs: Setup framebuffer endian

2024-05-16 Thread Jiaxun Yang
So the current situation on endian of bochs framebufer
is a little bit complex. QEMU defaulted to little endian
for both endian hardware except on powerpc, but provided
an endian swich register allows OS to switch endian.

Since we can't guarantee the endian switch register is
functional, my approach is to default to little endian
framebuffer for ISAs except powerpc and perform endian
switch to match this assumption.

Signed-off-by: Jiaxun Yang 
---
 drivers/video/bochs.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/video/bochs.c b/drivers/video/bochs.c
index 00e673a4db08..c315c5477b14 100644
--- a/drivers/video/bochs.c
+++ b/drivers/video/bochs.c
@@ -65,6 +65,14 @@ static int bochs_init_fb(struct udevice *dev)
uc_priv->ysize = ysize;
uc_priv->bpix = VIDEO_BPP32;
 
+#if defined(__powerpc__) && defined(__BIG_ENDIAN)
+   uc_priv->format = VIDEO_XRGB_BE;
+   writel(0xbebebebe, mmio + 0x604);
+#else
+   uc_priv->format = VIDEO_XRGB;
+   writel(0x1e1e1e1e, mmio + 0x604);
+#endif
+
/* setup video mode */
bochs_write(mmio, INDEX_ENABLE,  0);
bochs_write(mmio, INDEX_BANK,  0);

-- 
2.34.1



[PATCH 5/6] video: sandbox_sdl: Implement more pixel formats

2024-05-16 Thread Jiaxun Yang
Support most of possible pixel formats so we can test them
in sandbox.

Signed-off-by: Jiaxun Yang 
---
 arch/sandbox/cpu/sdl.c | 58 +-
 arch/sandbox/include/asm/sdl.h | 17 -
 drivers/video/sandbox_sdl.c| 16 +++-
 include/dm/test.h  |  2 ++
 test/dm/video.c| 14 +-
 5 files changed, 81 insertions(+), 26 deletions(-)

diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index ed84646bdab7..436c0448de1f 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -5,8 +5,10 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -69,6 +71,47 @@ static struct sdl_info {
int src_depth;
 } sdl;
 
+static inline SDL_PixelFormatEnum sandbox_video_format(int l2bbp, int format)
+{
+   switch (l2bbp) {
+   case VIDEO_BPP8:
+   switch (format) {
+   case VIDEO_DEFAULT:
+   case VIDEO_RGB332:
+   return SDL_PIXELFORMAT_RGB332;
+   }
+   case VIDEO_BPP16:
+   switch (format) {
+   case VIDEO_DEFAULT:
+   case VIDEO_RGB565:
+   return SDL_PIXELFORMAT_RGB565;
+   default:
+   break;
+   }
+   break;
+   case VIDEO_BPP32:
+   switch (format) {
+   case VIDEO_DEFAULT:
+   case VIDEO_XRGB:
+   return SDL_PIXELFORMAT_RGB888;
+   case VIDEO_BGRX:
+   return SDL_PIXELFORMAT_BGRX;
+   case VIDEO_XBGR:
+   return SDL_PIXELFORMAT_BGR888;
+   case VIDEO_RGBA:
+   return SDL_PIXELFORMAT_RGBA;
+   case VIDEO_XRGB2101010:
+   return SDL_PIXELFORMAT_ARGB2101010;
+   default:
+   break;
+   }
+   default:
+   break;
+   }
+
+   return SDL_PIXELFORMAT_UNKNOWN;
+}
+
 static void sandbox_sdl_poll_events(void)
 {
/*
@@ -122,9 +165,10 @@ int sandbox_sdl_remove_display(void)
 }
 
 int sandbox_sdl_init_display(int width, int height, int log2_bpp,
-bool double_size)
+int format, bool double_size)
 {
struct sandbox_state *state = state_get_current();
+   SDL_PixelFormatEnum sdl_format;
int err;
 
if (!width || !state->show_lcd)
@@ -135,6 +179,12 @@ int sandbox_sdl_init_display(int width, int height, int 
log2_bpp,
if (sdl.renderer)
sandbox_sdl_remove_display();
 
+   sdl_format = sandbox_video_format(log2_bpp, format);
+   if (sdl_format == SDL_PIXELFORMAT_UNKNOWN) {
+   printf("Unsupported video format\n");
+   return -EINVAL;
+   }
+
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
printf("Unable to initialise SDL LCD: %s\n", SDL_GetError());
return -EPERM;
@@ -153,8 +203,6 @@ int sandbox_sdl_init_display(int width, int height, int 
log2_bpp,
printf("Unable to init hinting: %s", SDL_GetError());
 
sdl.src_depth = 1 << log2_bpp;
-   if (log2_bpp != 4 && log2_bpp != 5)
-   log2_bpp = 5;
sdl.depth = 1 << log2_bpp;
sdl.pitch = sdl.width * sdl.depth / 8;
sdl.screen = SDL_CreateWindow("U-Boot", SDL_WINDOWPOS_UNDEFINED,
@@ -174,9 +222,7 @@ int sandbox_sdl_init_display(int width, int height, int 
log2_bpp,
return -EIO;
}
 
-   sdl.texture = SDL_CreateTexture(sdl.renderer, log2_bpp == 4 ?
-   SDL_PIXELFORMAT_RGB565 :
-   SDL_PIXELFORMAT_RGB888,
+   sdl.texture = SDL_CreateTexture(sdl.renderer, sdl_format,
SDL_TEXTUREACCESS_STREAMING,
width, height);
if (!sdl.texture) {
diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h
index ee4991f7c24a..7b4f26f994da 100644
--- a/arch/sandbox/include/asm/sdl.h
+++ b/arch/sandbox/include/asm/sdl.h
@@ -24,7 +24,7 @@
  * and -EPERM if the video failed to come up.
  */
 int sandbox_sdl_init_display(int width, int height, int log2_bpp,
-bool double_size);
+int format, bool double_size);
 
 /**
  * sandbox_sdl_remove_display() - Remove the SDL screen
@@ -89,12 +89,13 @@ int sandbox_sdl_sound_stop(void);
 int sandbox_sdl_sound_init(int rate, int channels);
 
 /**
- * sandbox_sdl_set_bpp() - Set the depth of the sandbox display
+ * sandbox_sdl_set_pixel() - Set depth and format of the sandbox display
  *
  * The device must not be active when this function is called. It activiates it
  * before returning.
  *
- * This updates the depth value and adjusts a 

[PATCH 4/6] video: bmp: Rework with video_rgb_to_pixel_*

2024-05-16 Thread Jiaxun Yang
Using RGB to pixel conversion function provided in previous
patch to implement frame buffer writing functions.

Massively simplifed the code, also get rid of limitations
on bmp_bpix vs display_bpix.

Test cases are also corrected to refect a tiny change in
color quantization.

Signed-off-by: Jiaxun Yang 
---
 drivers/video/video_bmp.c | 201 +-
 test/dm/video.c   |   4 +-
 2 files changed, 59 insertions(+), 146 deletions(-)

diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 83380a87fd2b..80c276aaf231 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -17,42 +17,6 @@
 #define BMP_RLE8_EOBMP 1
 #define BMP_RLE8_DELTA 2
 
-/**
- * get_bmp_col_16bpp() - Convert a colour-table entry into a 16bpp pixel value
- *
- * Return: value to write to the 16bpp frame buffer for this palette entry
- */
-static uint get_bmp_col_16bpp(struct bmp_color_table_entry cte)
-{
-   return ((cte.red   << 8) & 0xf800) |
-   ((cte.green << 3) & 0x07e0) |
-   ((cte.blue  >> 3) & 0x001f);
-}
-
-/**
- * get_bmp_col_x2r10g10b10() - Convert a colour-table entry into a x2r10g10b10 
 pixel value
- *
- * Return: value to write to the x2r10g10b10 frame buffer for this palette 
entry
- */
-static u32 get_bmp_col_x2r10g10b10(struct bmp_color_table_entry *cte)
-{
-   return ((cte->red << 22U) |
-   (cte->green << 12U) |
-   (cte->blue << 2U));
-}
-
-/**
- * get_bmp_col_rgba() - Convert a colour-table entry into a rgba pixel 
value
- *
- * Return: value to write to the rgba frame buffer for this palette entry
- */
-static u32 get_bmp_col_rgba(struct bmp_color_table_entry *cte)
-{
-   return ((cte->red) |
-   (cte->green << 8U) |
-   (cte->blue << 16U) | 0xff << 24U);
-}
-
 /**
  * write_pix8() - Write a pixel from a BMP image into the framebuffer
  *
@@ -63,33 +27,37 @@ static u32 get_bmp_col_rgba(struct 
bmp_color_table_entry *cte)
  * @palette: BMP palette table
  * @bmap: Pointer to BMP bitmap position to write. This contains a single byte
  * which is either written directly (bpix == 8) or used to look up the
- * palette to get a colour to write
+ * palette to get a colour to write, NULL if it's a pseudo palette with 
one entry.
  */
 static void write_pix8(u8 *fb, uint bpix, enum video_format eformat,
   struct bmp_color_table_entry *palette, u8 *bmap)
 {
-   if (bpix == 8) {
-   *fb++ = *bmap;
-   } else if (bpix == 16) {
-   *(u16 *)fb = get_bmp_col_16bpp(palette[*bmap]);
-   } else {
-   /* Only support big endian */
-   struct bmp_color_table_entry *cte = [*bmap];
-
-   if (bpix == 24) {
-   *fb++ = cte->red;
-   *fb++ = cte->green;
-   *fb++ = cte->blue;
-   } else if (eformat == VIDEO_XRGB2101010) {
-   *(u32 *)fb = get_bmp_col_x2r10g10b10(cte);
-   } else if (eformat == VIDEO_RGBA) {
-   *(u32 *)fb = get_bmp_col_rgba(cte);
-   } else {
-   *fb++ = cte->blue;
-   *fb++ = cte->green;
-   *fb++ = cte->red;
-   *fb++ = 0;
-   }
+   const int entry = bmap ? *bmap : 0;
+   const struct video_rgb rgb = {
+   .r = palette[entry].red,
+   .g = palette[entry].green,
+   .b = palette[entry].blue
+   };
+
+   switch (bpix) {
+#if CONFIG_IS_ENABLED(VIDEO_BPP8)
+   case 8:
+   *(u8 *)fb = video_rgb_to_pixel8(eformat, rgb);
+   break;
+#endif
+#if CONFIG_IS_ENABLED(VIDEO_BPP16)
+   case 16:
+   *(u16 *)fb = video_rgb_to_pixel16(eformat, rgb);
+   break;
+#endif
+#if CONFIG_IS_ENABLED(VIDEO_BPP32)
+   case 32:
+   *(u32 *)fb = video_rgb_to_pixel32(eformat, rgb);
+   break;
+#endif
+   default:
+   log_debug("Unsupported BPP %d for BMP\n", bpix);
+   break;
}
 }
 
@@ -266,6 +234,7 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, 
int x, int y,
unsigned colours, bpix, bmp_bpix;
enum video_format eformat;
struct bmp_color_table_entry *palette;
+   struct bmp_color_table_entry pseudo_cte __maybe_unused;
int hdr_size;
int ret;
 
@@ -293,21 +262,6 @@ int video_bmp_display(struct udevice *dev, ulong 
bmp_image, int x, int y,
return -EINVAL;
}
 
-   /*
-* We support displaying 8bpp and 24bpp BMPs on 16bpp LCDs
-* and displaying 24bpp BMPs on 32bpp LCDs
-*/
-   if (bpix != bmp_bpix &&
-   !(bmp_bpix == 8 && bpix == 16) &&
-   !(bmp_bpix == 8 && bpix == 24) &&
-   !(bmp_bpix == 8 && bpix == 32) &&
-   

[PATCH 3/6] video: Rework pixel format handling

2024-05-16 Thread Jiaxun Yang
Our current approach on naming pixel formats and handling them
is a little bit confusing, we don't consider endian for framebuffers.

Using Linux's naming approach instead to improve robustness of the
system, also consider both endians for all pixel formats.

Formats and RGB->Pixel conversion functions are stripped to
video_format.h so we can include them in sdl.c without pull in all
u-boot headers, and inline those conversion functions everywhere.

Signed-off-by: Jiaxun Yang 
---
 drivers/video/console_truetype.c |   4 +-
 drivers/video/simplefb.c |   2 +-
 drivers/video/video-uclass.c |  38 +++--
 drivers/video/video_bmp.c|   6 +-
 include/video.h  |  31 +---
 include/video_format.h   | 161 +++
 lib/efi_loader/efi_gop.c |   2 +-
 7 files changed, 179 insertions(+), 65 deletions(-)

diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index c435162d3f94..ac0556ba1352 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -397,7 +397,7 @@ static int console_truetype_putc_xy(struct udevice *dev, 
uint x, uint y,
 
if (vid_priv->colour_bg)
val = 255 - val;
-   if (vid_priv->format == 
VIDEO_X2R10G10B10)
+   if (vid_priv->format == 
VIDEO_XRGB2101010)
out = val << 2 | val << 12 | 
val << 22;
else
out = val | val << 8 | val << 
16;
@@ -923,7 +923,7 @@ static int truetype_set_cursor_visible(struct udevice *dev, 
bool visible,
for (i = 0; i < width; i++) {
int out;
 
-   if (vid_priv->format == 
VIDEO_X2R10G10B10)
+   if (vid_priv->format == 
VIDEO_XRGB2101010)
out = val << 2 | val << 12 | 
val << 22;
else
out = val | val << 8 | val << 
16;
diff --git a/drivers/video/simplefb.c b/drivers/video/simplefb.c
index cb518b149cb5..5bbde0e8a9f9 100644
--- a/drivers/video/simplefb.c
+++ b/drivers/video/simplefb.c
@@ -72,7 +72,7 @@ static int simple_video_probe(struct udevice *dev)
} else if (strcmp(format, "a2r10g10b10") == 0 ||
   strcmp(format, "x2r10g10b10") == 0) {
uc_priv->bpix = VIDEO_BPP32;
-   uc_priv->format = VIDEO_X2R10G10B10;
+   uc_priv->format = VIDEO_XRGB2101010;
} else {
log_err("%s: invalid format: %s\n", __func__, format);
return -EINVAL;
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index ff1382f4a43b..513766b30fb1 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -65,13 +65,6 @@ struct video_uc_priv {
ulong video_ptr;
 };
 
-/** struct vid_rgb - Describes a video colour */
-struct vid_rgb {
-   u32 r;
-   u32 g;
-   u32 b;
-};
-
 void video_set_flush_dcache(struct udevice *dev, bool flush)
 {
struct video_priv *priv = dev_get_uclass_priv(dev);
@@ -259,7 +252,7 @@ int video_clear(struct udevice *dev)
return 0;
 }
 
-static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
+static const struct video_rgb colours[VID_COLOUR_COUNT] = {
{ 0x00, 0x00, 0x00 },  /* black */
{ 0xc0, 0x00, 0x00 },  /* red */
{ 0x00, 0xc0, 0x00 },  /* green */
@@ -281,30 +274,17 @@ static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
 u32 video_index_to_colour(struct video_priv *priv, enum colour_idx idx)
 {
switch (priv->bpix) {
+   case VIDEO_BPP8:
+   if (CONFIG_IS_ENABLED(VIDEO_BPP8))
+   return video_rgb_to_pixel8(priv->format, colours[idx]);
+   break;
case VIDEO_BPP16:
-   if (CONFIG_IS_ENABLED(VIDEO_BPP16)) {
-   return ((colours[idx].r >> 3) << 11) |
-  ((colours[idx].g >> 2) <<  5) |
-  ((colours[idx].b >> 3) <<  0);
-   }
+   if (CONFIG_IS_ENABLED(VIDEO_BPP16))
+   return video_rgb_to_pixel16(priv->format, colours[idx]);
break;
case VIDEO_BPP32:
-   if (CONFIG_IS_ENABLED(VIDEO_BPP32)) {
-   switch (priv->format) {
-   case VIDEO_X2R10G10B10:
-   return (colours[idx].r << 22) |
-  (colours[idx].g << 12) |
-  (colours[idx].b <<  2);
-   case VIDEO_RGBA:
-   

[PATCH 1/6] video: Move generated bmp headers to include/generated

2024-05-16 Thread Jiaxun Yang
Emphasis that those headers are generated.
Also naturally gitignore them.

Signed-off-by: Jiaxun Yang 
---
 Makefile  | 2 +-
 board/aristainetos/aristainetos.c | 2 +-
 board/toradex/common/tdx-common.c | 2 +-
 common/splash.c   | 4 ++--
 tools/Makefile| 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 44deb339af19..77f3fead7f26 100644
--- a/Makefile
+++ b/Makefile
@@ -2191,7 +2191,7 @@ CLEAN_DIRS  += $(MODVERDIR) \
   $(foreach d, spl tpl vpl, $(patsubst %,$d/%, \
$(filter-out include, $(shell ls -1 $d 2>/dev/null
 
-CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h include/bmp_logo_data.h 
\
+CLEAN_FILES += include/autoconf.mk* include/generated/bmp_*.h \
   include/config.h include/generated/env.* 
drivers/video/u_boot_logo.S \
   tools/version.h u-boot* MLO* SPL System.map fit-dtb.blob* \
   u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log \
diff --git a/board/aristainetos/aristainetos.c 
b/board/aristainetos/aristainetos.c
index 8cfac9fbb342..bd7f00dfc0fe 100644
--- a/board/aristainetos/aristainetos.c
+++ b/board/aristainetos/aristainetos.c
@@ -27,7 +27,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -40,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
diff --git a/board/toradex/common/tdx-common.c 
b/board/toradex/common/tdx-common.c
index a6b45cdab810..ffd5946b4ec8 100644
--- a/board/toradex/common/tdx-common.c
+++ b/board/toradex/common/tdx-common.c
@@ -12,9 +12,9 @@
 #include 
 
 #ifdef CONFIG_VIDEO
-#include 
 #include 
 #include 
+#include 
 #endif
 
 #include "tdx-cfg-block.h"
diff --git a/common/splash.c b/common/splash.c
index c5591293634a..096fcba09913 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -62,7 +62,7 @@ static struct splash_location default_splash_locations[] = {
 
 #ifdef CONFIG_VIDEO_LOGO
 
-#include 
+#include 
 
 static int splash_video_logo_load(void)
 {
@@ -121,7 +121,7 @@ void splash_get_pos(int *x, int *y)
 #if CONFIG_IS_ENABLED(VIDEO) && !CONFIG_IS_ENABLED(HIDE_LOGO_VERSION)
 
 #ifdef CONFIG_VIDEO_LOGO
-#include 
+#include 
 #endif
 #include 
 #include 
diff --git a/tools/Makefile b/tools/Makefile
index 6a4280e3668f..edbe3fabc105 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -283,8 +283,8 @@ always := $(hostprogs-y)
 hostprogs-y += printinitialenv
 
 # Generated LCD/video logo
-LOGO_H = $(objtree)/include/bmp_logo.h
-LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
+LOGO_H = $(objtree)/include/generated/bmp_logo.h
+LOGO_DATA_H = $(objtree)/include/generated/bmp_logo_data.h
 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_H)
 LOGO-$(CONFIG_VIDEO_LOGO) += $(LOGO_DATA_H)
 

-- 
2.34.1



[PATCH 2/6] video: Add gitignore for u_boot_logo.S

2024-05-16 Thread Jiaxun Yang
We don't want this generated file to be tracked by git.

Signed-off-by: Jiaxun Yang 
---
 drivers/video/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/video/.gitignore b/drivers/video/.gitignore
new file mode 100644
index ..163c491c7630
--- /dev/null
+++ b/drivers/video/.gitignore
@@ -0,0 +1 @@
+u_boot_logo.S

-- 
2.34.1



[PATCH 0/6] video: pixel format handling fixes and improvements

2024-05-16 Thread Jiaxun Yang
Hi all,

This series fixes endian related problem I found in general
video system when testing my fresh virtio-gpu driver on big
endian target.

It also removed a lot of duplicated code on pixel handling,
and make implementation of new pixel formats easier. Further
more, it removed limitation on bpc for BMP display, now we
can display any image depth on any target display controller.

Please review.
Thanks

Signed-off-by: Jiaxun Yang 
---
Jiaxun Yang (6):
  video: Move generated bmp headers to include/generated
  video: Add gitignore for u_boot_logo.S
  video: Rework pixel format handling
  video: bmp: Rework with video_rgb_to_pixel_*
  video: sandbox_sdl: Implement more pixel formats
  video: bochs: Setup framebuffer endian

 Makefile  |   2 +-
 arch/sandbox/cpu/sdl.c|  58 +--
 arch/sandbox/include/asm/sdl.h|  17 ++--
 board/aristainetos/aristainetos.c |   2 +-
 board/toradex/common/tdx-common.c |   2 +-
 common/splash.c   |   4 +-
 drivers/video/.gitignore  |   1 +
 drivers/video/bochs.c |   8 ++
 drivers/video/console_truetype.c  |   4 +-
 drivers/video/sandbox_sdl.c   |  16 +--
 drivers/video/simplefb.c  |   2 +-
 drivers/video/video-uclass.c  |  38 ++-
 drivers/video/video_bmp.c | 201 +++---
 include/dm/test.h |   2 +
 include/video.h   |  31 +-
 include/video_format.h| 161 ++
 lib/efi_loader/efi_gop.c  |   2 +-
 test/dm/video.c   |  18 ++--
 tools/Makefile|   4 +-
 19 files changed, 332 insertions(+), 241 deletions(-)
---
base-commit: ad7dce5abd49ef3b5c93da5303e15449c8c162b4
change-id: 20240516-rework-video-format-ae8afadc45a5

Best regards,
-- 
Jiaxun Yang 



Re: [PATCH v3 0/6] Enable OF_UPSTREAM for J721s2 and AM68

2024-05-16 Thread Tom Rini
On Fri, 10 May 2024 10:20:19 +0530, Manorit Chawdhry wrote:

> Series splits AM68 and J721s2 support along with enabling OF_UPSTREAM
> and adding stdboot support for both the platforms.
> 
> Boot logs: 
> https://gist.github.com/manorit2001/6c669e4273933bc46c3b28a631a96ae3
> 
> 

Applied to u-boot/next, thanks!

-- 
Tom




Re: [PATCH v3 4/4] imx: hab: Use nxp_imx8mcst etype for i.MX8M flash.bin signing

2024-05-16 Thread Tim Harvey
On Thu, May 16, 2024 at 2:31 PM Marek Vasut  wrote:
>
> Update documentation and use nxp_imx8mcst binman etype for signing
> of flash.bin instead of previous horrible shell scripting.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: "NXP i.MX U-Boot Team" 
> Cc: Adam Ford 
> Cc: Alper Nebi Yasak 
> Cc: Andrejs Cainikovs 
> Cc: Angus Ainslie 
> Cc: Emanuele Ghidoli 
> Cc: Fabio Estevam 
> Cc: Francesco Dolcini 
> Cc: Marcel Ziswiler 
> Cc: Rasmus Villemoes 
> Cc: Simon Glass 
> Cc: Stefan Eichenberger 
> Cc: Stefano Babic 
> Cc: Tim Harvey 
> Cc: Tom Rini 
> Cc: ker...@puri.sm
> Cc: u-b...@dh-electronics.com
> Cc: u-boot@lists.denx.de
> ---
> V2: Document the automatic signing in case CONFIG_IMX_HAB is enabled
> V3: Document configuration of imx8mcst
> ---
>  doc/imx/habv4/csf_examples/mx8m/csf.sh|  92 --
>  doc/imx/habv4/csf_examples/mx8m/csf_fit.txt   |  30 -
>  doc/imx/habv4/csf_examples/mx8m/csf_spl.txt   |  33 -
>  doc/imx/habv4/guides/mx8m_spl_secure_boot.txt | 116 +-
>  4 files changed, 30 insertions(+), 241 deletions(-)
>  delete mode 100644 doc/imx/habv4/csf_examples/mx8m/csf.sh
>  delete mode 100644 doc/imx/habv4/csf_examples/mx8m/csf_fit.txt
>  delete mode 100644 doc/imx/habv4/csf_examples/mx8m/csf_spl.txt
>
> diff --git a/doc/imx/habv4/csf_examples/mx8m/csf.sh 
> b/doc/imx/habv4/csf_examples/mx8m/csf.sh
> deleted file mode 100644
> index cd3b2614a2f..000
> --- a/doc/imx/habv4/csf_examples/mx8m/csf.sh
> +++ /dev/null
> @@ -1,92 +0,0 @@
> -#!/bin/sh
> -
> -# 0) Generate keys
> -#
> -# WARNING: ECDSA keys are only supported by HAB 4.5 and newer (i.e. i.MX8M 
> Plus)
> -#
> -# cd /path/to/cst-3.3.1/keys/
> -#./hab4_pki_tree.sh -existing-ca n -use-ecc n -kl 4096 -duration 10 
> -num-srk 4 -srk-ca y
> -# cd /path/to/cst-3.3.1/crts/
> -#   ../linux64/bin/srktool -h 4 -t SRK_1_2_3_4_table.bin -e 
> SRK_1_2_3_4_fuse.bin -d sha256 -c 
> ./SRK1_sha256_4096_65537_v3_ca_crt.pem,./SRK2_sha256_4096_65537_v3_ca_crt.pem,./SRK3_sha256_4096_65537_v3_ca_crt.pem,./SRK4_sha256_4096_65537_v3_ca_crt.pem
>  -f 1
> -
> -# 1) Build U-Boot (e.g. for i.MX8MM)
> -#
> -# cp -Lv /path/to/arm-trusted-firmware/build/imx8mm/release/bl31.bin .
> -# cp -Lv /path/to/firmware-imx-8.14/firmware/ddr/synopsys/ddr3* .
> -# make -j imx8mm_board_defconfig
> -# make -j`nproc` flash.bin
> -
> -# 2) Sign SPL and DRAM blobs
> -
> -cp doc/imx/habv4/csf_examples/mx8m/csf_spl.txt csf_spl.tmp
> -cp doc/imx/habv4/csf_examples/mx8m/csf_fit.txt csf_fit.tmp
> -
> -# update File Paths from env vars
> -if ! [ -r $CSF_KEY ]; then
> -   echo "Error: \$CSF_KEY not found"
> -   exit 1
> -fi
> -if ! [ -r $IMG_KEY ]; then
> -   echo "Error: \$IMG_KEY not found"
> -   exit 1
> -fi
> -if ! [ -r $SRK_TABLE ]; then
> -   echo "Error: \$SRK_TABLE not found"
> -   exit 1
> -fi
> -sed -i "s:\$CSF_KEY:$CSF_KEY:" csf_spl.tmp
> -sed -i "s:\$IMG_KEY:$IMG_KEY:" csf_spl.tmp
> -sed -i "s:\$SRK_TABLE:$SRK_TABLE:" csf_spl.tmp
> -sed -i "s:\$CSF_KEY:$CSF_KEY:" csf_fit.tmp
> -sed -i "s:\$IMG_KEY:$IMG_KEY:" csf_fit.tmp
> -sed -i "s:\$SRK_TABLE:$SRK_TABLE:" csf_fit.tmp
> -
> -# update SPL Blocks
> -spl_block_base=$(printf "0x%x" $(( $(sed -n "/CONFIG_SPL_TEXT_BASE=/ 
> s@.*=@@p" .config) - 0x40)) )
> -spl_block_size=$(printf "0x%x" $(stat -tc %s u-boot-spl-ddr.bin))
> -sed -i "/Blocks = / s@.*@  Blocks = $spl_block_base 0x0 $spl_block_size 
> \"flash.bin\"@" csf_spl.tmp
> -
> -# Generate CSF blob
> -cst -i csf_spl.tmp -o csf_spl.bin
> -
> -# Patch CSF blob into flash.bin
> -spl_csf_offset=$(xxd -s 24 -l 4 -e flash.bin | cut -d " " -f 2 | sed 
> "s@^@0x@")
> -spl_bin_offset=$(xxd -s 4 -l 4 -e flash.bin | cut -d " " -f 2 | sed 
> "s@^@0x@")
> -spl_dd_offset=$((${spl_csf_offset} - ${spl_bin_offset} + 0x40))
> -dd if=csf_spl.bin of=flash.bin bs=1 seek=${spl_dd_offset} conv=notrunc
> -
> -# 3) Sign u-boot.itb
> -
> -# fitImage
> -fit_block_base=$(printf "0x%x" $(sed -n "/CONFIG_SPL_LOAD_FIT_ADDRESS=/ 
> s@.*=@@p" .config) )
> -fit_block_offset=$(printf "0x%s" $(fdtget -t x u-boot.dtb 
> /binman/imx-boot/uboot offset))
> -fit_block_size=$(printf "0x%x" $(( ( ( $(stat -tc %s u-boot.itb) + 0x1000 - 
> 0x1 ) & ~(0x1000 - 0x1)) + 0x20 )) )
> -sed -i "/Blocks = / s@.*@  Blocks = $fit_block_base $fit_block_offset 
> $fit_block_size \"flash.bin\"@" csf_fit.tmp
> -
> -# IVT
> -ivt_ptr_base=$(printf "%08x" ${fit_block_base} | sed 
> "s@\(..\)\(..\)\(..\)\(..\)@0x\4\3\2\1@")
> -ivt_block_base=$(printf "%08x" $(( ${fit_block_base} + ${fit_block_size} - 
> 0x20 )) | sed "s@\(..\)\(..\)\(..\)\(..\)@0x\4\3\2\1@")
> -csf_block_base=$(printf "%08x" $(( ${fit_block_base} + ${fit_block_size} )) 
> | sed "s@\(..\)\(..\)\(..\)\(..\)@0x\4\3\2\1@")
> -ivt_block_offset=$((${fit_block_offset} + ${fit_block_size} - 0x20))
> -csf_block_offset=$((${ivt_block_offset} + 0x20))
> -
> -echo "0xd1002041 ${ivt_block_base} 0x 0x 0x 
> ${ivt_block_base} ${csf_block_base} 0x" | xxd -r -p > ivt.bin
> -dd if=ivt.bin 

[PATCH v3 4/4] imx: hab: Use nxp_imx8mcst etype for i.MX8M flash.bin signing

2024-05-16 Thread Marek Vasut
Update documentation and use nxp_imx8mcst binman etype for signing
of flash.bin instead of previous horrible shell scripting.

Signed-off-by: Marek Vasut 
---
Cc: "NXP i.MX U-Boot Team" 
Cc: Adam Ford 
Cc: Alper Nebi Yasak 
Cc: Andrejs Cainikovs 
Cc: Angus Ainslie 
Cc: Emanuele Ghidoli 
Cc: Fabio Estevam 
Cc: Francesco Dolcini 
Cc: Marcel Ziswiler 
Cc: Rasmus Villemoes 
Cc: Simon Glass 
Cc: Stefan Eichenberger 
Cc: Stefano Babic 
Cc: Tim Harvey 
Cc: Tom Rini 
Cc: ker...@puri.sm
Cc: u-b...@dh-electronics.com
Cc: u-boot@lists.denx.de
---
V2: Document the automatic signing in case CONFIG_IMX_HAB is enabled
V3: Document configuration of imx8mcst
---
 doc/imx/habv4/csf_examples/mx8m/csf.sh|  92 --
 doc/imx/habv4/csf_examples/mx8m/csf_fit.txt   |  30 -
 doc/imx/habv4/csf_examples/mx8m/csf_spl.txt   |  33 -
 doc/imx/habv4/guides/mx8m_spl_secure_boot.txt | 116 +-
 4 files changed, 30 insertions(+), 241 deletions(-)
 delete mode 100644 doc/imx/habv4/csf_examples/mx8m/csf.sh
 delete mode 100644 doc/imx/habv4/csf_examples/mx8m/csf_fit.txt
 delete mode 100644 doc/imx/habv4/csf_examples/mx8m/csf_spl.txt

diff --git a/doc/imx/habv4/csf_examples/mx8m/csf.sh 
b/doc/imx/habv4/csf_examples/mx8m/csf.sh
deleted file mode 100644
index cd3b2614a2f..000
--- a/doc/imx/habv4/csf_examples/mx8m/csf.sh
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/bin/sh
-
-# 0) Generate keys
-#
-# WARNING: ECDSA keys are only supported by HAB 4.5 and newer (i.e. i.MX8M 
Plus)
-#
-# cd /path/to/cst-3.3.1/keys/
-#./hab4_pki_tree.sh -existing-ca n -use-ecc n -kl 4096 -duration 10 
-num-srk 4 -srk-ca y
-# cd /path/to/cst-3.3.1/crts/
-#   ../linux64/bin/srktool -h 4 -t SRK_1_2_3_4_table.bin -e 
SRK_1_2_3_4_fuse.bin -d sha256 -c 
./SRK1_sha256_4096_65537_v3_ca_crt.pem,./SRK2_sha256_4096_65537_v3_ca_crt.pem,./SRK3_sha256_4096_65537_v3_ca_crt.pem,./SRK4_sha256_4096_65537_v3_ca_crt.pem
 -f 1
-
-# 1) Build U-Boot (e.g. for i.MX8MM)
-#
-# cp -Lv /path/to/arm-trusted-firmware/build/imx8mm/release/bl31.bin .
-# cp -Lv /path/to/firmware-imx-8.14/firmware/ddr/synopsys/ddr3* .
-# make -j imx8mm_board_defconfig
-# make -j`nproc` flash.bin
-
-# 2) Sign SPL and DRAM blobs
-
-cp doc/imx/habv4/csf_examples/mx8m/csf_spl.txt csf_spl.tmp
-cp doc/imx/habv4/csf_examples/mx8m/csf_fit.txt csf_fit.tmp
-
-# update File Paths from env vars
-if ! [ -r $CSF_KEY ]; then
-   echo "Error: \$CSF_KEY not found"
-   exit 1
-fi
-if ! [ -r $IMG_KEY ]; then
-   echo "Error: \$IMG_KEY not found"
-   exit 1
-fi
-if ! [ -r $SRK_TABLE ]; then
-   echo "Error: \$SRK_TABLE not found"
-   exit 1
-fi
-sed -i "s:\$CSF_KEY:$CSF_KEY:" csf_spl.tmp
-sed -i "s:\$IMG_KEY:$IMG_KEY:" csf_spl.tmp
-sed -i "s:\$SRK_TABLE:$SRK_TABLE:" csf_spl.tmp
-sed -i "s:\$CSF_KEY:$CSF_KEY:" csf_fit.tmp
-sed -i "s:\$IMG_KEY:$IMG_KEY:" csf_fit.tmp
-sed -i "s:\$SRK_TABLE:$SRK_TABLE:" csf_fit.tmp
-
-# update SPL Blocks
-spl_block_base=$(printf "0x%x" $(( $(sed -n "/CONFIG_SPL_TEXT_BASE=/ s@.*=@@p" 
.config) - 0x40)) )
-spl_block_size=$(printf "0x%x" $(stat -tc %s u-boot-spl-ddr.bin))
-sed -i "/Blocks = / s@.*@  Blocks = $spl_block_base 0x0 $spl_block_size 
\"flash.bin\"@" csf_spl.tmp
-
-# Generate CSF blob
-cst -i csf_spl.tmp -o csf_spl.bin
-
-# Patch CSF blob into flash.bin
-spl_csf_offset=$(xxd -s 24 -l 4 -e flash.bin | cut -d " " -f 2 | sed "s@^@0x@")
-spl_bin_offset=$(xxd -s 4 -l 4 -e flash.bin | cut -d " " -f 2 | sed "s@^@0x@")
-spl_dd_offset=$((${spl_csf_offset} - ${spl_bin_offset} + 0x40))
-dd if=csf_spl.bin of=flash.bin bs=1 seek=${spl_dd_offset} conv=notrunc
-
-# 3) Sign u-boot.itb
-
-# fitImage
-fit_block_base=$(printf "0x%x" $(sed -n "/CONFIG_SPL_LOAD_FIT_ADDRESS=/ 
s@.*=@@p" .config) )
-fit_block_offset=$(printf "0x%s" $(fdtget -t x u-boot.dtb 
/binman/imx-boot/uboot offset))
-fit_block_size=$(printf "0x%x" $(( ( ( $(stat -tc %s u-boot.itb) + 0x1000 - 
0x1 ) & ~(0x1000 - 0x1)) + 0x20 )) )
-sed -i "/Blocks = / s@.*@  Blocks = $fit_block_base $fit_block_offset 
$fit_block_size \"flash.bin\"@" csf_fit.tmp
-
-# IVT
-ivt_ptr_base=$(printf "%08x" ${fit_block_base} | sed 
"s@\(..\)\(..\)\(..\)\(..\)@0x\4\3\2\1@")
-ivt_block_base=$(printf "%08x" $(( ${fit_block_base} + ${fit_block_size} - 
0x20 )) | sed "s@\(..\)\(..\)\(..\)\(..\)@0x\4\3\2\1@")
-csf_block_base=$(printf "%08x" $(( ${fit_block_base} + ${fit_block_size} )) | 
sed "s@\(..\)\(..\)\(..\)\(..\)@0x\4\3\2\1@")
-ivt_block_offset=$((${fit_block_offset} + ${fit_block_size} - 0x20))
-csf_block_offset=$((${ivt_block_offset} + 0x20))
-
-echo "0xd1002041 ${ivt_block_base} 0x 0x 0x 
${ivt_block_base} ${csf_block_base} 0x" | xxd -r -p > ivt.bin
-dd if=ivt.bin of=flash.bin bs=1 seek=${ivt_block_offset} conv=notrunc
-
-# Generate CSF blob
-cst -i csf_fit.tmp -o csf_fit.bin
-
-# When loading flash.bin via USB, we must ensure that the file being
-# served is as large as the target expects (see
-# board_spl_fit_size_align()), otherwise the target will hang in
-# 

[PATCH v3 3/4] ARM: dts: imx: Wrap i.MX8M binman SPL and FIT nodes in CST node if IMX_HAB enabled

2024-05-16 Thread Marek Vasut
In case CONFIG_IMX_HAB is enabled, extend the binman image description for
all of i.MX8M{Q,M,N,P} with CST wrapper node. This way, if CONFIG_IMX_HAB
is enabled, binman will be automatically used to sign SPL and fitImage.

Signed-off-by: Marek Vasut 
---
Cc: "NXP i.MX U-Boot Team" 
Cc: Adam Ford 
Cc: Alper Nebi Yasak 
Cc: Andrejs Cainikovs 
Cc: Angus Ainslie 
Cc: Emanuele Ghidoli 
Cc: Fabio Estevam 
Cc: Francesco Dolcini 
Cc: Marcel Ziswiler 
Cc: Rasmus Villemoes 
Cc: Simon Glass 
Cc: Stefan Eichenberger 
Cc: Stefano Babic 
Cc: Tim Harvey 
Cc: Tom Rini 
Cc: ker...@puri.sm
Cc: u-b...@dh-electronics.com
Cc: u-boot@lists.denx.de
---
V2: New patch
V3: No change
---
 arch/arm/dts/imx8mm-u-boot.dtsi | 195 -
 arch/arm/dts/imx8mn-u-boot.dtsi | 209 ++--
 arch/arm/dts/imx8mp-u-boot.dtsi | 172 ++
 arch/arm/dts/imx8mq-u-boot.dtsi | 182 ++-
 4 files changed, 424 insertions(+), 334 deletions(-)

diff --git a/arch/arm/dts/imx8mm-u-boot.dtsi b/arch/arm/dts/imx8mm-u-boot.dtsi
index b9b1193823a..c02e11def5f 100644
--- a/arch/arm/dts/imx8mm-u-boot.dtsi
+++ b/arch/arm/dts/imx8mm-u-boot.dtsi
@@ -54,126 +54,151 @@
};
 #endif
 
-   binman_imx_spl: nxp-imx8mimage {
-   filename = "u-boot-spl-mkimage.bin";
-   nxp,boot-from = "sd";
-   nxp,rom-version = <1>;
+#ifdef CONFIG_IMX_HAB
+   nxp-imx8mcst@0 {
+   filename = "u-boot-spl-mkimage.signed.bin";
nxp,loader-address = ;
+   nxp,unlock;
args;   /* Needed by mkimage etype superclass */
+#endif
 
-   section {
-   align = <4>;
-   align-size = <4>;
-   filename = "u-boot-spl-ddr.bin";
-   pad-byte = <0xff>;
-
-   u-boot-spl {
-   align-end = <4>;
-   filename = "u-boot-spl.bin";
-   };
+   binman_imx_spl: nxp-imx8mimage {
+   filename = "u-boot-spl-mkimage.bin";
+   nxp,boot-from = "sd";
+   nxp,rom-version = <1>;
+   nxp,loader-address = ;
+   args;   /* Needed by mkimage etype superclass */
+
+   section {
+   align = <4>;
+   align-size = <4>;
+   filename = "u-boot-spl-ddr.bin";
+   pad-byte = <0xff>;
+
+   u-boot-spl {
+   align-end = <4>;
+   filename = "u-boot-spl.bin";
+   };
 
-   ddr-1d-imem-fw {
-   filename = 
"lpddr4_pmu_train_1d_imem.bin";
-   align-end = <4>;
-   type = "blob-ext";
-   };
+   ddr-1d-imem-fw {
+   filename = 
"lpddr4_pmu_train_1d_imem.bin";
+   align-end = <4>;
+   type = "blob-ext";
+   };
 
-   ddr-1d-dmem-fw {
-   filename = 
"lpddr4_pmu_train_1d_dmem.bin";
-   align-end = <4>;
-   type = "blob-ext";
-   };
+   ddr-1d-dmem-fw {
+   filename = 
"lpddr4_pmu_train_1d_dmem.bin";
+   align-end = <4>;
+   type = "blob-ext";
+   };
 
-   ddr-2d-imem-fw {
-   filename = 
"lpddr4_pmu_train_2d_imem.bin";
-   align-end = <4>;
-   type = "blob-ext";
-   };
+   ddr-2d-imem-fw {
+   filename = 
"lpddr4_pmu_train_2d_imem.bin";
+   align-end = <4>;
+   type = "blob-ext";
+   };
 
-   ddr-2d-dmem-fw {
-   

[PATCH v3 2/4] ARM: dts: imx: Introduce SPL and FIT labels to i.MX8M DTs binman nodes

2024-05-16 Thread Marek Vasut
Add binman_imx_spl and binman_imx_fit labels to nxp-imx8mimage {} and fit {}
nodes respectively, so they can be referened in board DTs no matter how deep
in the top level binman image description they are. Update current board DTs
to use those labels.

Signed-off-by: Marek Vasut 
---
Cc: "NXP i.MX U-Boot Team" 
Cc: Adam Ford 
Cc: Alper Nebi Yasak 
Cc: Andrejs Cainikovs 
Cc: Angus Ainslie 
Cc: Emanuele Ghidoli 
Cc: Fabio Estevam 
Cc: Francesco Dolcini 
Cc: Marcel Ziswiler 
Cc: Rasmus Villemoes 
Cc: Simon Glass 
Cc: Stefan Eichenberger 
Cc: Stefano Babic 
Cc: Tim Harvey 
Cc: Tom Rini 
Cc: ker...@puri.sm
Cc: u-b...@dh-electronics.com
Cc: u-boot@lists.denx.de
---
V2: New patch
V3: No change
---
 arch/arm/dts/imx8mm-u-boot.dtsi   |   4 +-
 .../dts/imx8mm-verdin-wifi-dev-u-boot.dtsi|   8 +-
 arch/arm/dts/imx8mn-u-boot.dtsi   |   4 +-
 arch/arm/dts/imx8mp-dhcom-u-boot.dtsi | 124 +-
 arch/arm/dts/imx8mp-rsb3720-a1-u-boot.dtsi|  26 ++--
 arch/arm/dts/imx8mp-u-boot.dtsi   |   4 +-
 arch/arm/dts/imx8mq-librem5-r4-u-boot.dtsi|  10 +-
 arch/arm/dts/imx8mq-u-boot.dtsi   |   4 +-
 8 files changed, 84 insertions(+), 100 deletions(-)

diff --git a/arch/arm/dts/imx8mm-u-boot.dtsi b/arch/arm/dts/imx8mm-u-boot.dtsi
index 6ab8f66256e..b9b1193823a 100644
--- a/arch/arm/dts/imx8mm-u-boot.dtsi
+++ b/arch/arm/dts/imx8mm-u-boot.dtsi
@@ -54,7 +54,7 @@
};
 #endif
 
-   nxp-imx8mimage {
+   binman_imx_spl: nxp-imx8mimage {
filename = "u-boot-spl-mkimage.bin";
nxp,boot-from = "sd";
nxp,rom-version = <1>;
@@ -98,7 +98,7 @@
};
};
 
-   fit {
+   binman_imx_fit: fit {
description = "Configuration to load ATF before U-Boot";
 #ifndef CONFIG_IMX_HAB
fit,external-offset = ;
diff --git a/arch/arm/dts/imx8mm-verdin-wifi-dev-u-boot.dtsi 
b/arch/arm/dts/imx8mm-verdin-wifi-dev-u-boot.dtsi
index 90183aff8bc..183de46f66a 100644
--- a/arch/arm/dts/imx8mm-verdin-wifi-dev-u-boot.dtsi
+++ b/arch/arm/dts/imx8mm-verdin-wifi-dev-u-boot.dtsi
@@ -35,12 +35,8 @@
bootph-pre-ram;
 };
 
- {
-   section {
-   fit {
-   offset = <0x5fc00>;
-   };
-   };
+_imx_fit {
+   offset = <0x5fc00>;
 };
 
  {
diff --git a/arch/arm/dts/imx8mn-u-boot.dtsi b/arch/arm/dts/imx8mn-u-boot.dtsi
index ba9967dbe4a..c9fb33cfb73 100644
--- a/arch/arm/dts/imx8mn-u-boot.dtsi
+++ b/arch/arm/dts/imx8mn-u-boot.dtsi
@@ -103,7 +103,7 @@
};
 #endif
 
-   nxp-imx8mimage {
+   binman_imx_spl: nxp-imx8mimage {
filename = "u-boot-spl-mkimage.bin";
nxp,boot-from = "sd";
nxp,rom-version = <2>;
@@ -169,7 +169,7 @@
};
};
 
-   fit {
+   binman_imx_fit: fit {
description = "Configuration to load ATF before U-Boot";
 #ifndef CONFIG_IMX_HAB
fit,external-offset = ;
diff --git a/arch/arm/dts/imx8mp-dhcom-u-boot.dtsi 
b/arch/arm/dts/imx8mp-dhcom-u-boot.dtsi
index cb37e28f28f..c065fb82994 100644
--- a/arch/arm/dts/imx8mp-dhcom-u-boot.dtsi
+++ b/arch/arm/dts/imx8mp-dhcom-u-boot.dtsi
@@ -135,73 +135,69 @@
bootph-pre-ram;
 };
 
- {
-   section {
-   fit {
-   images {
-   fdt-dto-imx8mp-dhcom-som-overlay-eth1xfast {
-   description = 
"imx8mp-dhcom-som-overlay-eth1xfast";
-   type = "flat_dt";
-   compression = "none";
-
-   blob-ext {
-   filename = 
"imx8mp-dhcom-som-overlay-eth1xfast.dtbo";
-   };
-   };
-
-   fdt-dto-imx8mp-dhcom-som-overlay-eth2xfast {
-   description = 
"imx8mp-dhcom-som-overlay-eth2xfast";
-   type = "flat_dt";
-   compression = "none";
-
-   blob-ext {
-   filename = 
"imx8mp-dhcom-som-overlay-eth2xfast.dtbo";
-   };
-   };
-
-   fdt-dto-imx8mp-dhcom-pdk-overlay-eth2xfast {
-   description = 
"imx8mp-dhcom-pdk-overlay-eth2xfast";
-   type = "flat_dt";
-   compression = "none";
-
-   blob-ext {
-   

[PATCH v3 1/4] binman: Add nxp_imx8mcst etype for i.MX8M flash.bin signing

2024-05-16 Thread Marek Vasut
Add new binman etype which allows signing both the SPL and fitImage sections
of i.MX8M flash.bin using CST. There are multiple DT properties which govern
the signing process, nxp,loader-address is the only mandatory one which sets
the SPL signature start address without the imx8mimage header, this should be
SPL text base. The key material can be configured using optional DT properties
nxp,srk-table, nxp,csf-crt, nxp,img-crt, all of which default the key material
names generated by CST tool scripts. The nxp,unlock property can be used to
unlock CAAM access in SPL section.

Signed-off-by: Marek Vasut 
---
Cc: "NXP i.MX U-Boot Team" 
Cc: Adam Ford 
Cc: Alper Nebi Yasak 
Cc: Andrejs Cainikovs 
Cc: Angus Ainslie 
Cc: Emanuele Ghidoli 
Cc: Fabio Estevam 
Cc: Francesco Dolcini 
Cc: Marcel Ziswiler 
Cc: Rasmus Villemoes 
Cc: Simon Glass 
Cc: Stefan Eichenberger 
Cc: Stefano Babic 
Cc: Tim Harvey 
Cc: Tom Rini 
Cc: ker...@puri.sm
Cc: u-b...@dh-electronics.com
Cc: u-boot@lists.denx.de
---
V2: - Use configparser module for generating the configuration INI file
- Use config template as an input, parse it, modify only keys of interest
- Pull magic values into top level variables
- Rename nxp,csf-key and nxp,img-key to nxp,csf-crt and nxp,img-crt
- Return unmodified data if signing unrecognized (non-SPL/non-FIT) section
V3: - Introduce SRK_TABLE/CSF_KEY/IMG_KEY env variables as alternative
  option for specifying the key material paths
- Clean up imx8mimage and imx8mcsf files and add them to gitignore
---
 .gitignore |   2 +
 Makefile   |   2 +-
 tools/binman/btool/cst.py  |  48 +
 tools/binman/etype/nxp_imx8mcst.py | 164 +
 4 files changed, 215 insertions(+), 1 deletion(-)
 create mode 100644 tools/binman/btool/cst.py
 create mode 100644 tools/binman/etype/nxp_imx8mcst.py

diff --git a/.gitignore b/.gitignore
index 37f71c275c3..502a7e6ec70 100644
--- a/.gitignore
+++ b/.gitignore
@@ -73,6 +73,8 @@ fit-dtb.blob*
 /capsule.*.efi-capsule
 /capsule*.map
 /keep-syms-lto.*
+/*imx8mimage*
+/*imx8mcst*
 
 #
 # Generated include files
diff --git a/Makefile b/Makefile
index 44deb339af1..026a6014a48 100644
--- a/Makefile
+++ b/Makefile
@@ -2210,7 +2210,7 @@ MRPROPER_DIRS  += include/config include/generated spl 
tpl vpl \
 # Remove include/asm symlink created by U-Boot before v2014.01
 MRPROPER_FILES += .config .config.old include/autoconf.mk* include/config.h \
  ctags etags tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
- drivers/video/fonts/*.S include/asm
+ drivers/video/fonts/*.S include/asm *imx8mimage* *imx8mcst*
 
 # clean - Delete most, but leave enough to build external modules
 #
diff --git a/tools/binman/btool/cst.py b/tools/binman/btool/cst.py
new file mode 100644
index 000..30e78bdbbd9
--- /dev/null
+++ b/tools/binman/btool/cst.py
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2024 Marek Vasut 
+#
+"""Bintool implementation for cst"""
+
+import re
+
+from binman import bintool
+
+class Bintoolcst(bintool.Bintool):
+"""Image generation for U-Boot
+
+This bintool supports running `cst` with some basic parameters as
+needed by binman.
+"""
+def __init__(self, name):
+super().__init__(name, 'Sign NXP i.MX image')
+
+# pylint: disable=R0913
+def run(self, output_fname=None):
+"""Run cst
+
+Args:
+output_fname: Output filename to write to
+"""
+args = []
+if output_fname:
+args += ['-o', output_fname]
+return self.run_cmd(*args)
+
+def fetch(self, method):
+"""Fetch handler for cst
+
+This installs cst using the apt utility.
+
+Args:
+method (FETCH_...): Method to use
+
+Returns:
+True if the file was fetched and now installed, None if a method
+other than FETCH_BIN was requested
+
+Raises:
+Valuerror: Fetching could not be completed
+"""
+if method != bintool.FETCH_BIN:
+return None
+return self.apt_install('imx-code-signing-tool')
diff --git a/tools/binman/etype/nxp_imx8mcst.py 
b/tools/binman/etype/nxp_imx8mcst.py
new file mode 100644
index 000..8221517b0c4
--- /dev/null
+++ b/tools/binman/etype/nxp_imx8mcst.py
@@ -0,0 +1,164 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2023-2024 Marek Vasut 
+# Written with much help from Simon Glass 
+#
+# Entry-type module for generating the i.MX8M code signing tool
+# input configuration file and invocation of cst on generated
+# input configuration file and input data to be signed.
+#
+
+import configparser
+import os
+import struct
+
+from collections import OrderedDict
+
+from binman.entry import Entry
+from binman.etype.mkimage import Entry_mkimage
+from binman.etype.section import Entry_section
+from binman import elf
+from dtoc import 

Re: [PATCH v3 4/4] include: Move snprintf to stdio.h

2024-05-16 Thread Tom Rini
On Thu, May 16, 2024 at 02:11:52PM -0700, Raymond Mao wrote:

> Move snprintf to stdio.h since it is needed by exteranl libraries.
> 
> Signed-off-by: Raymond Mao 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v3 4/4] include: Move snprintf to stdio.h

2024-05-16 Thread Raymond Mao
Move snprintf to stdio.h since it is needed by exteranl libraries.

Signed-off-by: Raymond Mao 
---
Changes in v2
- New patch.
Changes in v3
- Move comments and attributes of snprintf.

 arch/arc/lib/cpu.c |  2 +-
 board/Synology/common/legacy.c |  1 +
 board/ti/common/fdt_ops.c  |  2 +-
 cmd/part.c |  1 +
 common/button_cmd.c|  2 +-
 drivers/cpu/mpc83xx_cpu.c  |  2 +-
 include/stdio.h| 17 +
 include/vsprintf.h | 17 -
 lib/display_options.c  |  1 +
 lib/fwu_updates/fwu_mtd.c  |  2 +-
 lib/hexdump.c  |  2 +-
 lib/vsprintf.c |  1 +
 test/dm/scmi.c |  2 +-
 test/print_ut.c|  1 +
 14 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/arch/arc/lib/cpu.c b/arch/arc/lib/cpu.c
index 593950449f2..269b4dbdd15 100644
--- a/arch/arc/lib/cpu.c
+++ b/arch/arc/lib/cpu.c
@@ -7,7 +7,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/Synology/common/legacy.c b/board/Synology/common/legacy.c
index a0bace7b46c..2e3aa660eaa 100644
--- a/board/Synology/common/legacy.c
+++ b/board/Synology/common/legacy.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/board/ti/common/fdt_ops.c b/board/ti/common/fdt_ops.c
index eb917be9e0d..8a3300993ed 100644
--- a/board/ti/common/fdt_ops.c
+++ b/board/ti/common/fdt_ops.c
@@ -6,7 +6,7 @@
  */
 
 #include 
-#include 
+#include 
 #include "fdt_ops.h"
 
 void ti_set_fdt_env(const char *board_name, struct ti_fdt_map *fdt_map)
diff --git a/cmd/part.c b/cmd/part.c
index d140a1eddb9..db7bc5819c0 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 enum cmd_part_info {
diff --git a/common/button_cmd.c b/common/button_cmd.c
index 8642c26735c..72dac1f9ef6 100644
--- a/common/button_cmd.c
+++ b/common/button_cmd.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 /* Some sane limit "just in case" */
 #define MAX_BTN_CMDS 32
diff --git a/drivers/cpu/mpc83xx_cpu.c b/drivers/cpu/mpc83xx_cpu.c
index 9a7b5fd7c42..127d3c3af08 100644
--- a/drivers/cpu/mpc83xx_cpu.c
+++ b/drivers/cpu/mpc83xx_cpu.c
@@ -9,7 +9,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 
 #include "mpc83xx_cpu.h"
diff --git a/include/stdio.h b/include/stdio.h
index 3241e2d493f..7b999a519ba 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -46,6 +46,23 @@ static inline int vprintf(const char *fmt, va_list args)
 }
 #endif
 
+/**
+ * Format a string and place it in a buffer
+ *
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ * @...: Arguments for the format string
+ * Return: the number of characters which would be
+ * generated for the given input, excluding the trailing null,
+ * as per ISO C99.  If the return is greater than or equal to
+ * @size, the resulting string is truncated.
+ *
+ * See the vsprintf() documentation for format string extensions over C99.
+ */
+int snprintf(char *buf, size_t size, const char *fmt, ...)
+__attribute__ ((format (__printf__, 3, 4)));
+
 /*
  * FILE based functions (can only be used AFTER relocation!)
  */
diff --git a/include/vsprintf.h b/include/vsprintf.h
index ed8a060ee17..fe951471426 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -218,23 +218,6 @@ char *simple_itoa(ulong val);
  */
 char *simple_xtoa(ulong num);
 
-/**
- * Format a string and place it in a buffer
- *
- * @buf: The buffer to place the result into
- * @size: The size of the buffer, including the trailing null space
- * @fmt: The format string to use
- * @...: Arguments for the format string
- * Return: the number of characters which would be
- * generated for the given input, excluding the trailing null,
- * as per ISO C99.  If the return is greater than or equal to
- * @size, the resulting string is truncated.
- *
- * See the vsprintf() documentation for format string extensions over C99.
- */
-int snprintf(char *buf, size_t size, const char *fmt, ...)
-   __attribute__ ((format (__printf__, 3, 4)));
-
 /**
  * Format a string and place it in a buffer
  *
diff --git a/lib/display_options.c b/lib/display_options.c
index d6b93553dcb..d5df53ab15f 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 char *display_options_get_banner_priv(bool newlines, const char *build_tag,
diff --git a/lib/fwu_updates/fwu_mtd.c b/lib/fwu_updates/fwu_mtd.c
index 69cd3d7001f..4a52834b61a 100644
--- a/lib/fwu_updates/fwu_mtd.c
+++ b/lib/fwu_updates/fwu_mtd.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include 
 
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 33e3e6e5182..2bc508ff504 100644

[PATCH v3 3/4] md5: Use typedef for MD5 context

2024-05-16 Thread Raymond Mao
Use of typedef is beneficial for porting with other crypto libs
without changing the API callers.
Secondly, it is for the code consistency with other digest libs.
SHA1, SHA256 and SHA512 are all using typedef for their context.

Signed-off-by: Raymond Mao 
Reviewed-by: Tom Rini 
Reviewed-by: Ilias Apalodimas 
---
Changes in v2
- None.
Changes in v3
- None.

 drivers/crypto/hash/hash_sw.c |  8 
 include/u-boot/md5.h  | 10 +-
 lib/md5.c | 10 +-
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/crypto/hash/hash_sw.c b/drivers/crypto/hash/hash_sw.c
index ffd4ab149ff..4590e225481 100644
--- a/drivers/crypto/hash/hash_sw.c
+++ b/drivers/crypto/hash/hash_sw.c
@@ -50,17 +50,17 @@ static void hash_finish_crc32(void *ctx, void *obuf)
 /* MD5 */
 static void hash_init_md5(void *ctx)
 {
-   MD5Init((struct MD5Context *)ctx);
+   MD5Init((MD5Context *)ctx);
 }
 
 static void hash_update_md5(void *ctx, const void *ibuf, uint32_t ilen)
 {
-   MD5Update((struct MD5Context *)ctx, ibuf, ilen);
+   MD5Update((MD5Context *)ctx, ibuf, ilen);
 }
 
 static void hash_finish_md5(void *ctx, void *obuf)
 {
-   MD5Final(obuf, (struct MD5Context *)ctx);
+   MD5Final(obuf, (MD5Context *)ctx);
 }
 
 /* SHA1 */
@@ -158,7 +158,7 @@ static struct sw_hash_impl sw_hash_impl[HASH_ALGO_NUM] = {
.init = hash_init_md5,
.update = hash_update_md5,
.finish = hash_finish_md5,
-   .ctx_alloc_sz = sizeof(struct MD5Context),
+   .ctx_alloc_sz = sizeof(MD5Context),
},
 
[HASH_ALGO_SHA1] = {
diff --git a/include/u-boot/md5.h b/include/u-boot/md5.h
index d61364c0ae3..c465925ea8d 100644
--- a/include/u-boot/md5.h
+++ b/include/u-boot/md5.h
@@ -10,18 +10,18 @@
 
 #define MD5_SUM_LEN16
 
-struct MD5Context {
+typedef struct MD5Context {
__u32 buf[4];
__u32 bits[2];
union {
unsigned char in[64];
__u32 in32[16];
};
-};
+} MD5Context;
 
-void MD5Init(struct MD5Context *ctx);
-void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len);
-void MD5Final(unsigned char digest[16], struct MD5Context *ctx);
+void MD5Init(MD5Context *ctx);
+void MD5Update(MD5Context *ctx, unsigned char const *buf, unsigned int len);
+void MD5Final(unsigned char digest[16], MD5Context *ctx);
 
 /*
  * Calculate and store in 'output' the MD5 digest of 'len' bytes at
diff --git a/lib/md5.c b/lib/md5.c
index faf3f78ab1e..34343cf8e23 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -55,7 +55,7 @@ byteReverse(unsigned char *buf, unsigned longs)
  * initialization constants.
  */
 void
-MD5Init(struct MD5Context *ctx)
+MD5Init(MD5Context *ctx)
 {
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
@@ -71,7 +71,7 @@ MD5Init(struct MD5Context *ctx)
  * of bytes.
  */
 void
-MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
+MD5Update(MD5Context *ctx, unsigned char const *buf, unsigned int len)
 {
register __u32 t;
 
@@ -120,7 +120,7 @@ MD5Update(struct MD5Context *ctx, unsigned char const *buf, 
unsigned len)
  * 1 0* (64-bit count of bits processed, MSB-first)
  */
 void
-MD5Final(unsigned char digest[16], struct MD5Context *ctx)
+MD5Final(unsigned char digest[16], MD5Context *ctx)
 {
unsigned int count;
unsigned char *p;
@@ -269,7 +269,7 @@ MD5Transform(__u32 buf[4], __u32 const in[16])
 void
 md5 (unsigned char *input, int len, unsigned char output[16])
 {
-   struct MD5Context context;
+   MD5Context context;
 
MD5Init();
MD5Update(, input, len);
@@ -286,7 +286,7 @@ void
 md5_wd(const unsigned char *input, unsigned int len, unsigned char output[16],
unsigned int chunk_sz)
 {
-   struct MD5Context context;
+   MD5Context context;
 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
const unsigned char *end, *curr;
int chunk;
-- 
2.25.1



[PATCH v3 2/4] efi_loader: remove redundant hash includes

2024-05-16 Thread Raymond Mao
Remove the redundant includes of u-boot/sha1.h, u-boot/sha256.h
and u-boot/sha512.h

Signed-off-by: Raymond Mao 
Reviewed-by: Tom Rini 
Reviewed-by: Ilias Apalodimas 
---
Changes in v2
- None.
Changes in v3
- None.

 lib/efi_loader/efi_signature.c | 1 -
 lib/efi_loader/efi_tcg2.c  | 3 ---
 2 files changed, 4 deletions(-)

diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c
index f338e732759..184eac8cddb 100644
--- a/lib/efi_loader/efi_signature.c
+++ b/lib/efi_loader/efi_signature.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 
 const efi_guid_t efi_guid_sha256 = EFI_CERT_SHA256_GUID;
 const efi_guid_t efi_guid_cert_rsa2048 = EFI_CERT_RSA2048_GUID;
diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index b07e0099c27..ac056dcfc55 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -19,9 +19,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
-- 
2.25.1



[PATCH v3 1/4] image: remove redundant hash includes

2024-05-16 Thread Raymond Mao
Remove the redundant includes of u-boot/md5.h, u-boot/sha1.h,
u-boot/sha256.h and u-boot/sha512.h

Signed-off-by: Raymond Mao 
Reviewed-by: Tom Rini 
Reviewed-by: Igor Opaniuk 
Reviewed-by: Ilias Apalodimas 
---
Changes in v2
- None.
Changes in v3
- None.

 boot/image-fit.c | 4 
 boot/image.c | 2 --
 2 files changed, 6 deletions(-)

diff --git a/boot/image-fit.c b/boot/image-fit.c
index fb03cab831b..f6464bcf620 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -37,10 +37,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
 
 /*/
 /* New uImage format routines */
diff --git a/boot/image.c b/boot/image.c
index eb12e4be04a..bacf5146e13 100644
--- a/boot/image.c
+++ b/boot/image.c
@@ -25,8 +25,6 @@
 #endif
 
 #include 
-#include 
-#include 
 #include 
 #include 
 
-- 
2.25.1



[PATCH v3 0/4] Clean-up patch set for MbedTLS integration

2024-05-16 Thread Raymond Mao
This patch set is picked from the previously posted serie:
"[RFC] Integrate MbedTLS v3.6 LTS with U-Boot"

They are not directly related to MbedTLS integration, but the
prerequisite for a few clean-up, refactoring and minor fixes.

For V2, the linker script patch is dropped and added one patch
to move the snprintf to stdio.h

Raymond Mao (4):
  image: remove redundant hash includes
  efi_loader: remove redundant hash includes
  md5: Use typedef for MD5 context
  include: Move snprintf to stdio.h

 arch/arc/lib/cpu.c |  2 +-
 board/Synology/common/legacy.c |  1 +
 board/ti/common/fdt_ops.c  |  2 +-
 boot/image-fit.c   |  4 
 boot/image.c   |  2 --
 cmd/part.c |  1 +
 common/button_cmd.c|  2 +-
 drivers/cpu/mpc83xx_cpu.c  |  2 +-
 drivers/crypto/hash/hash_sw.c  |  8 
 include/stdio.h| 17 +
 include/u-boot/md5.h   | 10 +-
 include/vsprintf.h | 17 -
 lib/display_options.c  |  1 +
 lib/efi_loader/efi_signature.c |  1 -
 lib/efi_loader/efi_tcg2.c  |  3 ---
 lib/fwu_updates/fwu_mtd.c  |  2 +-
 lib/hexdump.c  |  2 +-
 lib/md5.c  | 10 +-
 lib/vsprintf.c |  1 +
 test/dm/scmi.c |  2 +-
 test/print_ut.c|  1 +
 21 files changed, 43 insertions(+), 48 deletions(-)

-- 
2.25.1



[PATCH 2/2] doc: process.rst: Document device tree resync rules

2024-05-16 Thread Tom Rini
Document the logic of when we do a full resync of the device trees used
by OF_UPSTREAM as well as that cherry-picking is allowed as needed.

Signed-off-by: Tom Rini 
---
Cc: Heinrich Schuchardt 
---
 doc/develop/process.rst | 13 +
 1 file changed, 13 insertions(+)

diff --git a/doc/develop/process.rst b/doc/develop/process.rst
index a66540a698c1..0542b3fc1245 100644
--- a/doc/develop/process.rst
+++ b/doc/develop/process.rst
@@ -108,6 +108,19 @@ Differences to the Linux Development Process
   In U-Boot, ``"-rc1"`` will only be released after all (or at least most of
   the) patches that were submitted during the merge window have been applied.
 
+Resyncing of the device tree subtree
+
+
+As explained in :doc:`devicetree/control` some platforms make use of device 
tree
+files which come from a git subtree that mirrors the Linux Kernel sources
+itself. For our purposes, we only track releases and not release candidates for
+merging in our tree. These merges follow the normal merge window rules.
+
+In the case of specific changes, such as bug fixes or new platform support,
+these can be "cherry-picked" and are subject to the normal merge rules. For
+example, a bug fix can come in later in the window but a full re-sync only
+happens within the merge window itself.
+
 .. _custodians:
 
 Custodians
-- 
2.34.1



[PATCH 1/2] doc: process.rst: Use subsubheading for "Phases of the Development Process"

2024-05-16 Thread Tom Rini
These sections which talk about the different phases of the development
process should be using the subsubheading identifier.

Signed-off-by: Tom Rini 
---
Cc: Heinrich Schuchardt 
---
 doc/develop/process.rst | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/develop/process.rst b/doc/develop/process.rst
index 92477d05dd85..a66540a698c1 100644
--- a/doc/develop/process.rst
+++ b/doc/develop/process.rst
@@ -34,7 +34,7 @@ It is followed by a *Stabilization Period*.
 The end of a Release Cycle is marked by the release of a new U-Boot version.
 
 Merge Window
-
+
 
 The Merge Window is the period when new patches get submitted (and hopefully
 accepted) for inclusion into U-Boot mainline. This period lasts for 21 days (3
@@ -44,7 +44,7 @@ This is the only time when new code (like support for new 
processors or new
 boards, or other new features or reorganization of code) is accepted.
 
 Twilight Time
--
+^
 
 Usually patches do not get accepted as they are - the peer review that takes
 place will usually require changes and resubmissions of the patches before they
@@ -65,13 +65,13 @@ the Merge Window does not preclude patches that were 
already posted from being
 merged for the upcoming release.
 
 Stabilization Period
-
+
 
 During the Stabilization Period only patches containing bug fixes get
 applied.
 
 Corner Cases
-
+
 
 Sometimes it is not clear if a patch contains a bug fix or not.
 For example, changes that remove dead code, unused macros etc. or
-- 
2.34.1



Re: [PATCH v2 1/2] doc: Detailed example for netconsole setup

2024-05-16 Thread Tony Dinh
Hi Fiona,

On Thu, May 16, 2024 at 3:43 AM Fiona Klute  wrote:
>
> This adds details that I would have liked to have readily available,
> in particular how to activate the network interface before enabling
> netconsole, and how to integrate netconsole so you can use the U-Boot
> prompt.
>
> Signed-off-by: Fiona Klute 
> ---
> Changes in v2:
> * Include stderr redirection
> * Use 4 spaces instead of tabs for code block to avoid overflowing
>   lines
>
>  doc/usage/netconsole.rst | 33 -
>  1 file changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/doc/usage/netconsole.rst b/doc/usage/netconsole.rst
> index 2aa3b9ccc5..647f0c220b 100644
> --- a/doc/usage/netconsole.rst
> +++ b/doc/usage/netconsole.rst
> @@ -18,7 +18,9 @@ broadcast address and port  are used. If it is set to 
> an IP
>  address of 0 (or 0.0.0.0) then no messages are sent to the network.
>  The source / listening port can be configured separately by setting
>  the 'ncinport' environment variable and the destination port can be
> -configured by setting the 'ncoutport' environment variable.
> +configured by setting the 'ncoutport' environment variable. Note that
> +you need to set up the network interface (e.g. using DHCP) before it
> +can be used for network console.
>
>  For example, if your server IP is 192.168.1.1, you could use::
>
> @@ -107,3 +109,32 @@ as follows:
>
>  Note that unlike the U-Boot implementation the Linux netconsole is
>  unidirectional, i. e. you have console output only in Linux.
> +
> +Setup via environment
> +-
> +
> +If persistent environment is enabled in your U-Boot configuration, you
> +can configure the network console using the environment. For example::
> +
> +=> env set autoload no
> +=> env set hostname "u-boot"
> +=> env set bootdelay 5
> +=> env set nc 'dhcp; env set stdout nc; env set stderr nc; env set stdin 
> nc'
> +=> env set ncip 192.168.1.1
> +=> env set preboot "${preboot}; run nc;"
> +=> env save
> +=> reset
> +
> +``autoload no`` tells the ``dhcp`` command to configure the network
> +interface without trying to load an image. ``hostname "u-boot"`` sets
> +the hostname to be sent in DHCP requests, so they are easy to
> +recognize in the DHCP server log. The command in ``nc`` calls ``dhcp``
> +to make sure the network interface is set up before enabling
> +netconsole.
> +
> +Adding ``nc`` to ``preboot`` tells U-Boot to activate netconsole
> +before trying to find any boot options, so you can interact with it if
> +desired.
> +
> +``env save`` stores the settings persistently, and ``reset`` then
> +triggers a fresh start that will use the changed settings.
> --
> 2.43.0
>

Just for information, if the board uses static IP then the example
would be slightly different. I usually use static IP and ping the
netconsole server to make sure it is up. However, I think this DHCP
example is good enough to show how to prepare and activate netconsole.

Reviewed-by: Tony Dinh 

All the best,
Tony


Re: [PATCH v2 2/2] doc: Update netconsole examples, mention stderr

2024-05-16 Thread Tony Dinh
Hi Fiona,

On Thu, May 16, 2024 at 3:43 AM Fiona Klute  wrote:
>
> Stderr was missing from the initial description and example.
>
> As I understand the env command documentation the subcommand style is
> preferred, though the old format is still fully supported.
>
> Signed-off-by: Fiona Klute 
> ---
> Changes in v2:
> * Mention stderr redirection
> * Use 4 spaces instead of tabs for code block to avoid overflowing
>   lines
>
>  doc/usage/netconsole.rst | 16 
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/doc/usage/netconsole.rst b/doc/usage/netconsole.rst
> index 647f0c220b..f745615d9a 100644
> --- a/doc/usage/netconsole.rst
> +++ b/doc/usage/netconsole.rst
> @@ -3,10 +3,10 @@ Network console
>
>  In U-Boot, we implemented the networked console via the standard
>  "devices" mechanism, which means that you can switch between the
> -serial and network input/output devices by adjusting the 'stdin' and
> -'stdout' environment variables. To switch to the networked console,
> -set either of these variables to "nc". Input and output can be
> -switched independently.
> +serial and network input/output devices by adjusting the 'stdin',
> +'stdout', and 'stderr' environment variables. To switch to the
> +networked console, set either of these variables to "nc". Input and
> +output can be switched independently.
>
>  The default buffer size can be overridden by setting
>  CFG_NETCONSOLE_BUFFER_SIZE.
> @@ -24,10 +24,10 @@ can be used for network console.
>
>  For example, if your server IP is 192.168.1.1, you could use::
>
> -   => setenv nc 'setenv stdout nc;setenv stdin nc'
> -   => setenv ncip 192.168.1.1
> -   => saveenv
> -   => run nc
> +=> env set nc 'env set stdout nc; env set stderr nc; env set stdin nc'
> +=> env set ncip 192.168.1.1
> +=> env save
> +=> run nc
>
>  On the host side, please use this script to access the console
>
> --
> 2.43.0
>

Reviewed-by: Tony Dinh 

All the best,
Tony


Re: [GIT PULL] Please pull u-boot-dfu-20240516

2024-05-16 Thread Tom Rini
On Thu, May 16, 2024 at 05:12:33PM +0200, Mattijs Korpershoek wrote:

> Hi Tom, everyone,
> 
> Sorry for the double email, I missed to include the list :(
> 
> Please find some fixes for master:
> 
> - Fix cdns3 low power hang via fast access bit
> - Multiple dwc3 gadget fixes, mainly for USB support on TI AM6232
> - Consistent USB_GADGET_MANUFACTURER for PHYTEC boards
> - MAINTAINERS file update for u-boot-dfu
> 
> The CI job is at 
> https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/20737
> 
> Thanks,
> Mattijs
> 
> The following changes since commit c8ffd1356d42223cbb8c86280a083cc3c93e6426:
> 
>   Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet" 
> (2024-05-13 09:15:51 -0600)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-dfu.git 
> tags/u-boot-dfu-20240516
> 
> for you to fetch changes up to efbc11ccef89030ed54b7368458eeaf9ec687c77:
> 
>   MAINTAINERS: add USB gadget regex to u-boot-dfu tree (2024-05-16 13:28:45 
> +0200)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/1] Squashed 'dts/upstream/' changes from b35b9bd1d4ee..7e08733c96c8

2024-05-16 Thread Heiko Stübner
Am Dienstag, 14. Mai 2024, 18:42:36 CEST schrieb Tom Rini:

[...]

> git-subtree-dir: dts/upstream
> git-subtree-split: 7e08733c96c84eb323f47e9b248c924e2ac6272a
> ---
> This moves OF_UPSTREAM to be tracking the v6.9 release and is for the
> -next branch. To test these changes yourself locally, either use my
> "WIP/14May2024-next" branch or run:
> ./dts/update-dts-subtree.sh pull v6.9-dts
> yourself locally. I intend to wait a few days to apply this to -next, to
> give people time to test.

On
- rk3588-rock5b
- rk3588-jaguar
- rk3588-tiger (pending patch)

Tested-by: Heiko Stuebner 




Re: [PATCH v3 2/2] configs: add defconfigs for the am625-lp-sk

2024-05-16 Thread Tom Rini
On Thu, May 16, 2024 at 10:41:58AM -0500, Bryan Brattlof wrote:
> On May 15, 2024 thus sayeth Andrew Davis:
> > On 5/15/24 1:21 PM, Tom Rini wrote:
> > > On Fri, May 03, 2024 at 11:44:29AM -0500, Bryan Brattlof wrote:
> > > 
> > > > The am62x-lp-sk is a package and reference board spin of the am62x-sk to
> > > > showcase the low-power features of the am62x SoC family. Because it so
> > > > closely resembles the am62x-sk board, use the preprocessor to inherit
> > > > its configuration making the needed changes for this board where
> > > > necessary.
> > > > 
> > > > Reviewed-by: Dhruva Gole 
> > > > Signed-off-by: Bryan Brattlof 
> > > > ---
> > > >   configs/am62x_lp_sk_a53_defconfig | 3 +++
> > > >   configs/am62x_lp_sk_r5_defconfig  | 2 ++
> > > >   2 files changed, 5 insertions(+)
> > > > 
> > > > diff --git a/configs/am62x_lp_sk_a53_defconfig 
> > > > b/configs/am62x_lp_sk_a53_defconfig
> > > > new file mode 100644
> > > > index 0..904b2142b2f53
> > > > --- /dev/null
> > > > +++ b/configs/am62x_lp_sk_a53_defconfig
> > > > @@ -0,0 +1,3 @@
> > > > +#include 
> > > > +CONFIG_DEFAULT_DEVICE_TREE="ti/k3-am62-lp-sk"
> > > > +CONFIG_OF_UPSTREAM=y
> > > 
> > > So, there's a problem here. The #include trick for defconfig files isn't
> > > working as intended, exactly. The example here doesn't work right.
> > > First, it shows up as a variant of "sandbox" (as buildman will show and
> > > leads to https://source.denx.de/u-boot/u-boot/-/jobs/835067#L119)
> > > 
> > > And this becomes clearer if you look at configs/am69_sk_r5_defconfig
> > > which has to set some symbols already found in
> > > configs/j784s4_evm_r5_defconfig in order to work. This is seemingly very
> > > not equivalent to invoking "make foo_defconfig bar.config" to combine
> > > things.
> > > 
> > 
> > This is equivalent when running make. The issue is with buildman which
> > manually checks the content of the defconfig to find what ARCH it should
> > run the defconfig with. buildman doesn't understand the #include yet.
> > Until buildman can be fixed, you'll need to do what we did with
> > am69_sk_r5_defconfig and redefine the ARCH/SOC/TARGET info in the
> > defconfig file so buildman can find it without following the #include.
> 
> Ah Okay, I'll take a stab at the buildman fix. Also noticed in the logs 
> I didn't add the configs to a MAINTAINERS entry.

Thanks. And re MAINTAINERS, I just fixed that up in-place before seeing
this bigger problem.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] fdt: automatically add /chosen/kaslr-seed if DM_RNG is enabled

2024-05-16 Thread Tom Rini
On Thu, May 16, 2024 at 08:58:09AM -0700, Tim Harvey wrote:
> On Wed, May 15, 2024 at 1:50 PM Tim Harvey  wrote:
> >
> > If RANDOMIZE_BASE is enabled in the Linux kernel instructing it to
> > randomize the virtual address at which the kernel image is loaded, it
> > expects entropy to be provided by the bootloader by populating
> > /chosen/kaslr-seed with a 64-bit value from source of entropy at boot.
> >
> > If we have DM_RNG enabled populate this value automatically when
> > fdt_chosen is called unless ARMV8_SEC_FIRMWARE_SUPPORT is enabled as
> > it's implementation uses a different source of entropy.
> >
> > As this fdt node is added elsewhere create a library function and
> > use it to deduplicate code.
> >
> > Note that the kalsrseed command (CMD_KASLRSEED) is likely pointless now
> > but left in place in case boot scripts exist that rely on this command
> > existing and returning success. An informational message is printed to
> > alert users of this command that it is likely no longer needed.
> >
> > Signed-off-by: Tim Harvey 
> > ---
> > v2:
> >  - fix typo in commit msg
> >  - use stack for seed to avoid unecessary malloc/free
> >  - move to a library function and deduplicate code by using it elsewhere
> > ---
> >  board/xilinx/common/board.c | 35 -
> >  boot/fdt_support.c  | 10 +
> >  boot/pxe_utils.c| 35 +++--
> >  cmd/kaslrseed.c | 45 ++---
> >  include/kaslrseed.h | 17 ++
> >  lib/Makefile|  1 +
> >  lib/kaslrseed.c | 34 
> >  7 files changed, 72 insertions(+), 105 deletions(-)
> >  create mode 100644 include/kaslrseed.h
> >  create mode 100644 lib/kaslrseed.c
> >
> > diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
> > index 30a81376ac41..f741e8957818 100644
> > --- a/board/xilinx/common/board.c
> > +++ b/board/xilinx/common/board.c
> > @@ -713,41 +713,6 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> > if (IS_ENABLED(CONFIG_FDT_FIXUP_PARTITIONS) && 
> > IS_ENABLED(CONFIG_NAND_ZYNQ))
> > fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
> >
> > -   if (uclass_get_device(UCLASS_RNG, 0, ) || !dev) {
> > -   debug("No RNG device\n");
> > -   return 0;
> > -   }
> > -
> > -   if (dm_rng_read(dev, buf, n)) {
> > -   debug("Reading RNG failed\n");
> > -   return 0;
> > -   }
> > -
> > -   if (!blob) {
> > -   debug("No FDT memory address configured. Please configure\n"
> > - "the FDT address via \"fdt addr \" 
> > command.\n"
> > - "Aborting!\n");
> > -   return 0;
> > -   }
> > -
> > -   ret = fdt_check_header(blob);
> > -   if (ret < 0) {
> > -   debug("fdt_chosen: %s\n", fdt_strerror(ret));
> > -   return ret;
> > -   }
> > -
> > -   nodeoffset = fdt_find_or_add_subnode(blob, 0, "chosen");
> > -   if (nodeoffset < 0) {
> > -   debug("Reading chosen node failed\n");
> > -   return nodeoffset;
> > -   }
> > -
> > -   ret = fdt_setprop(blob, nodeoffset, "kaslr-seed", buf, sizeof(buf));
> > -   if (ret < 0) {
> > -   debug("Unable to set kaslr-seed on chosen node: %s\n", 
> > fdt_strerror(ret));
> > -   return ret;
> > -   }
> > -
> > return 0;
> >  }
> >  #endif
> > diff --git a/boot/fdt_support.c b/boot/fdt_support.c
> > index 874ca4d6f5af..3455d60d69dc 100644
> > --- a/boot/fdt_support.c
> > +++ b/boot/fdt_support.c
> > @@ -8,6 +8,7 @@
> >
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -300,6 +301,15 @@ int fdt_chosen(void *fdt)
> > if (nodeoffset < 0)
> > return nodeoffset;
> >
> > +   if (IS_ENABLED(CONFIG_DM_RNG) && 
> > !IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)) {
> > +   err = fdt_kaslrseed(fdt);
> > +   if (err) {
> > +   printf("WARNING: could not set kaslr-seed %s.\n",
> > +  fdt_strerror(err));
> > +   return err;
> > +   }
> > +   }
> > +
> > if (IS_ENABLED(CONFIG_BOARD_RNG_SEED) && !board_rng_seed()) {
> > err = fdt_setprop(fdt, nodeoffset, "rng-seed",
> >   abuf_data(), abuf_size());
> > diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
> > index 4b22bb6f525a..8d70233fc08d 100644
> > --- a/boot/pxe_utils.c
> > +++ b/boot/pxe_utils.c
> > @@ -8,6 +8,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -323,10 +324,6 @@ static void label_boot_kaslrseed(void)
> >  #if CONFIG_IS_ENABLED(DM_RNG)
> > ulong fdt_addr;
> > struct fdt_header *working_fdt;
> > -   size_t n = 0x8;
> 

Re: [PATCH v2] fdt: automatically add /chosen/kaslr-seed if DM_RNG is enabled

2024-05-16 Thread Tim Harvey
On Wed, May 15, 2024 at 1:50 PM Tim Harvey  wrote:
>
> If RANDOMIZE_BASE is enabled in the Linux kernel instructing it to
> randomize the virtual address at which the kernel image is loaded, it
> expects entropy to be provided by the bootloader by populating
> /chosen/kaslr-seed with a 64-bit value from source of entropy at boot.
>
> If we have DM_RNG enabled populate this value automatically when
> fdt_chosen is called unless ARMV8_SEC_FIRMWARE_SUPPORT is enabled as
> it's implementation uses a different source of entropy.
>
> As this fdt node is added elsewhere create a library function and
> use it to deduplicate code.
>
> Note that the kalsrseed command (CMD_KASLRSEED) is likely pointless now
> but left in place in case boot scripts exist that rely on this command
> existing and returning success. An informational message is printed to
> alert users of this command that it is likely no longer needed.
>
> Signed-off-by: Tim Harvey 
> ---
> v2:
>  - fix typo in commit msg
>  - use stack for seed to avoid unecessary malloc/free
>  - move to a library function and deduplicate code by using it elsewhere
> ---
>  board/xilinx/common/board.c | 35 -
>  boot/fdt_support.c  | 10 +
>  boot/pxe_utils.c| 35 +++--
>  cmd/kaslrseed.c | 45 ++---
>  include/kaslrseed.h | 17 ++
>  lib/Makefile|  1 +
>  lib/kaslrseed.c | 34 
>  7 files changed, 72 insertions(+), 105 deletions(-)
>  create mode 100644 include/kaslrseed.h
>  create mode 100644 lib/kaslrseed.c
>
> diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
> index 30a81376ac41..f741e8957818 100644
> --- a/board/xilinx/common/board.c
> +++ b/board/xilinx/common/board.c
> @@ -713,41 +713,6 @@ int ft_board_setup(void *blob, struct bd_info *bd)
> if (IS_ENABLED(CONFIG_FDT_FIXUP_PARTITIONS) && 
> IS_ENABLED(CONFIG_NAND_ZYNQ))
> fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
>
> -   if (uclass_get_device(UCLASS_RNG, 0, ) || !dev) {
> -   debug("No RNG device\n");
> -   return 0;
> -   }
> -
> -   if (dm_rng_read(dev, buf, n)) {
> -   debug("Reading RNG failed\n");
> -   return 0;
> -   }
> -
> -   if (!blob) {
> -   debug("No FDT memory address configured. Please configure\n"
> - "the FDT address via \"fdt addr \" command.\n"
> - "Aborting!\n");
> -   return 0;
> -   }
> -
> -   ret = fdt_check_header(blob);
> -   if (ret < 0) {
> -   debug("fdt_chosen: %s\n", fdt_strerror(ret));
> -   return ret;
> -   }
> -
> -   nodeoffset = fdt_find_or_add_subnode(blob, 0, "chosen");
> -   if (nodeoffset < 0) {
> -   debug("Reading chosen node failed\n");
> -   return nodeoffset;
> -   }
> -
> -   ret = fdt_setprop(blob, nodeoffset, "kaslr-seed", buf, sizeof(buf));
> -   if (ret < 0) {
> -   debug("Unable to set kaslr-seed on chosen node: %s\n", 
> fdt_strerror(ret));
> -   return ret;
> -   }
> -
> return 0;
>  }
>  #endif
> diff --git a/boot/fdt_support.c b/boot/fdt_support.c
> index 874ca4d6f5af..3455d60d69dc 100644
> --- a/boot/fdt_support.c
> +++ b/boot/fdt_support.c
> @@ -8,6 +8,7 @@
>
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -300,6 +301,15 @@ int fdt_chosen(void *fdt)
> if (nodeoffset < 0)
> return nodeoffset;
>
> +   if (IS_ENABLED(CONFIG_DM_RNG) && 
> !IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)) {
> +   err = fdt_kaslrseed(fdt);
> +   if (err) {
> +   printf("WARNING: could not set kaslr-seed %s.\n",
> +  fdt_strerror(err));
> +   return err;
> +   }
> +   }
> +
> if (IS_ENABLED(CONFIG_BOARD_RNG_SEED) && !board_rng_seed()) {
> err = fdt_setprop(fdt, nodeoffset, "rng-seed",
>   abuf_data(), abuf_size());
> diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
> index 4b22bb6f525a..8d70233fc08d 100644
> --- a/boot/pxe_utils.c
> +++ b/boot/pxe_utils.c
> @@ -8,6 +8,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -323,10 +324,6 @@ static void label_boot_kaslrseed(void)
>  #if CONFIG_IS_ENABLED(DM_RNG)
> ulong fdt_addr;
> struct fdt_header *working_fdt;
> -   size_t n = 0x8;
> -   struct udevice *dev;
> -   u64 *buf;
> -   int nodeoffset;
> int err;
>
> /* Get the main fdt and map it */
> @@ -342,35 +339,9 @@ static void label_boot_kaslrseed(void)
> if (err <= 0)
> return;
>
> -   if (uclass_get_device(UCLASS_RNG, 0, ) || !dev) {
> -  

Re: [PATCH v3 2/2] configs: add defconfigs for the am625-lp-sk

2024-05-16 Thread Bryan Brattlof
On May 15, 2024 thus sayeth Andrew Davis:
> On 5/15/24 1:21 PM, Tom Rini wrote:
> > On Fri, May 03, 2024 at 11:44:29AM -0500, Bryan Brattlof wrote:
> > 
> > > The am62x-lp-sk is a package and reference board spin of the am62x-sk to
> > > showcase the low-power features of the am62x SoC family. Because it so
> > > closely resembles the am62x-sk board, use the preprocessor to inherit
> > > its configuration making the needed changes for this board where
> > > necessary.
> > > 
> > > Reviewed-by: Dhruva Gole 
> > > Signed-off-by: Bryan Brattlof 
> > > ---
> > >   configs/am62x_lp_sk_a53_defconfig | 3 +++
> > >   configs/am62x_lp_sk_r5_defconfig  | 2 ++
> > >   2 files changed, 5 insertions(+)
> > > 
> > > diff --git a/configs/am62x_lp_sk_a53_defconfig 
> > > b/configs/am62x_lp_sk_a53_defconfig
> > > new file mode 100644
> > > index 0..904b2142b2f53
> > > --- /dev/null
> > > +++ b/configs/am62x_lp_sk_a53_defconfig
> > > @@ -0,0 +1,3 @@
> > > +#include 
> > > +CONFIG_DEFAULT_DEVICE_TREE="ti/k3-am62-lp-sk"
> > > +CONFIG_OF_UPSTREAM=y
> > 
> > So, there's a problem here. The #include trick for defconfig files isn't
> > working as intended, exactly. The example here doesn't work right.
> > First, it shows up as a variant of "sandbox" (as buildman will show and
> > leads to https://source.denx.de/u-boot/u-boot/-/jobs/835067#L119)
> > 
> > And this becomes clearer if you look at configs/am69_sk_r5_defconfig
> > which has to set some symbols already found in
> > configs/j784s4_evm_r5_defconfig in order to work. This is seemingly very
> > not equivalent to invoking "make foo_defconfig bar.config" to combine
> > things.
> > 
> 
> This is equivalent when running make. The issue is with buildman which
> manually checks the content of the defconfig to find what ARCH it should
> run the defconfig with. buildman doesn't understand the #include yet.
> Until buildman can be fixed, you'll need to do what we did with
> am69_sk_r5_defconfig and redefine the ARCH/SOC/TARGET info in the
> defconfig file so buildman can find it without following the #include.

Ah Okay, I'll take a stab at the buildman fix. Also noticed in the logs 
I didn't add the configs to a MAINTAINERS entry.

~Bryan


Re: [PATCH v2] rockchip: add support for Theobroma Systems SOM-RK3588-Q7 Tiger module

2024-05-16 Thread Heiko Stübner
Am Mittwoch, 8. Mai 2024, 10:34:57 CEST schrieb Quentin Schulz:
> Hi Kever,
> 
> On 5/8/24 4:42 AM, Kever Yang wrote:
> > Hi Quentin,
> > 
> >  Could you please update this patch with OF_UPSTREAM support?
> > 
> 
> No, I cannot yet :/
> 
> Tiger is only available in Linux kernel v6.9-rcX and dts/ in U-Boot is 
> currently at v6.8.

Looks like Tom plans on updating the dts in -next soon'ish [0]
With the patch adapted to the OF_UPSTREAM situation
(dropping rk3588-tiger.dtsi and rk3588-tiger-haikou.dts and dropping
one usbdp node in -uboot.dtsi):

Tested-by: Heiko Stuebner 



[0] https://lore.kernel.org/all/20240514164236.516595-1-tr...@konsulko.com/




Re: [PATCH v2 4/4] imx: hab: Use nxp_imx8mcst etype for i.MX8M flash.bin signing

2024-05-16 Thread Tim Harvey
On Wed, May 15, 2024 at 6:53 PM Marek Vasut  wrote:
>
> On 5/16/24 12:31 AM, Tim Harvey wrote:
>
> Hi,
>
> > (this is a resend... apologies if its a duplicate. I got some strange
> > bounce that mime types were included so I'm resending with the otuput
> > of strace cliped out)
> >
> > strace was a good idea and showed me what was going on.
> >
> > The previous documentation stated to pass your keys via env vars that
> > were full paths to key certificates. Using strace shows me that it
> > will use the directory the KEY certificate is in and try to open up
> > ../keys/*_usr_key.pem if the key path is specified. So apparently the
> > 'File' in the CST config file is used indirectly. Pointing to the
> > usr_key.pem isn't enough either by the way, it seems to need both of
> > these:
> >
> > so if I hack the path to my certs in like this it works:diff --git
> > a/tools/binman/etype/nxp_imx8mcst.py
> > b/tools/binman/etype/nxp_imx8mcst.py
> > index 132127ad4827..b432200960df 100644
> > --- a/tools/binman/etype/nxp_imx8mcst.py
> > +++ b/tools/binman/etype/nxp_imx8mcst.py
> > @@ -67,10 +67,11 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
> >
> >   def ReadNode(self):
> >   super().ReadNode()
> > +self.certpath =3D '/usr/src/nxp/cst-3.3.2/crts/';
>
> =3D , seems like your email is acting funny today indeed.
>
> >   self.loader_address =3D fdt_util.GetInt(self._node, 
> > 'nxp,loader-ad=
> > dress')
> >   self.srk_table =3D fdt_util.GetString(self._node,
> > 'nxp,srk-table', 'SRK_1_2_3_4_table.bin')
> > -self.csf_crt =3D fdt_util.GetString(self._node, 'nxp,csf-crt',
> > 'CSF1_1_sha256_4096_65537_v3_usr_crt.pem')
> > -self.img_crt =3D fdt_util.GetString(self._node, 'nxp,img-crt',
> > 'IMG1_1_sha256_4096_65537_v3_usr_crt.pem')
> > +self.csf_crt =3D fdt_util.GetString(self._node, 'nxp,csf-crt',
> > self.certpath + '/CSF1_1_sha256_4096_65537_v3_usr_crt.pem')
> > +self.img_crt =3D fdt_util.GetString(self._node, 'nxp,img-crt',
> > self.certpath + '/IMG1_1_sha256_4096_65537_v3_usr_crt.pem')
>
> What about this:
>
> diff --git a/tools/binman/etype/nxp_imx8mcst.py
> b/tools/binman/etype/nxp_imx8mcst.py
> index 132127ad482..9ead7488a2d 100644
> --- a/tools/binman/etype/nxp_imx8mcst.py
> +++ b/tools/binman/etype/nxp_imx8mcst.py
> @@ -68,9 +68,9 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
>   def ReadNode(self):
>   super().ReadNode()
>   self.loader_address = fdt_util.GetInt(self._node,
> 'nxp,loader-address')
> -self.srk_table = fdt_util.GetString(self._node,
> 'nxp,srk-table', 'SRK_1_2_3_4_table.bin')
> -self.csf_crt = fdt_util.GetString(self._node, 'nxp,csf-crt',
> 'CSF1_1_sha256_4096_65537_v3_usr_crt.pem')
> -self.img_crt = fdt_util.GetString(self._node, 'nxp,img-crt',
> 'IMG1_1_sha256_4096_65537_v3_usr_crt.pem')
> +self.srk_table = os.getenv('SRK_TABLE',
> fdt_util.GetString(self._node, 'nxp,srk-table', 'SRK_1_2_3_4_table.bin'))
> +self.csf_crt = os.getenv('CSF_KEY',
> fdt_util.GetString(self._node, 'nxp,csf-crt',
> 'CSF1_1_sha256_4096_65537_v3_usr_crt.pem'))
> +self.img_crt = os.getenv('IMG_KEY',
> fdt_util.GetString(self._node, 'nxp,img-crt',
> 'IMG1_1_sha256_4096_65537_v3_usr_crt.pem'))
>   self.unlock = fdt_util.GetBool(self._node, 'nxp,unlock')
>   self.ReadEntries()
>
> Then you can also use the old behavior with keys supplied via env vars.
>
> This might in fact be useful for build systems too.
>

yes, I like that (with an added 'import os')

> >   self.unlock =3D fdt_util.GetBool(self._node, 'nxp,unlock')
> >   self.ReadEntries()
> >
> > $ make -j8
> >BINMAN  .binman_stamp
> >OFCHK   .config
> >
> > Strace indicatest the following with the above patch:
> > openat(AT_FDCWD,
> > "/usr/src/nxp/cst-3.3.2/crts//IMG1_1_sha256_4096_65537_v3_usr_crt.pem",
> > O_RDONLY)
> > ...
> > openat(AT_FDCWD,
> > "/usr/src/nxp/cst-3.3.2/keys//IMG1_1_sha256_4096_65537_v3_usr_key.pem",
> > O_RDONLY)
> > ^^^ look how it sneakily changes the PATH!
> >
> > And without the above patch using a key file without a path:
> > openat(AT_FDCWD, "IMG1_1_sha256_4096_65537_v3_usr_crt.pem", O_RDONLY)
> > ...
> > openat(AT_FDCWD, "IMG1_1_sha256_4096_65537_v3_usr_key.pem", O_RDONLY)
> > ENOENT (No such file or directory)
> > ^^^ fails
> >
> > Simply copying both usr_crt.pem and usr_key.pem to the build directory
> > still fails:
> > binman: Error 1 running 'cst -i
> > ./nxp.csf-config-txt.section.nxp-imx8mcst@0 -o
> > ./nxp.csf-output-blob.section.nxp-imx8mcst@0': Error:
> > Cannot open key file IMG1_1_sha256_4096_65537_v3_usr_key.pem
> > 0:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad
> > decrypt:crypto/evp/evp_enc.c:612:
> > 0:error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal
> > error:crypto/pkcs12/p12_decr.c:62:
> > 0:error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe
> > crypt error:crypto/pkcs12/p12_decr.c:93:
> > 

[GIT PULL] Please pull u-boot-dfu-20240516

2024-05-16 Thread Mattijs Korpershoek
Hi Tom, everyone,

Sorry for the double email, I missed to include the list :(

Please find some fixes for master:

- Fix cdns3 low power hang via fast access bit
- Multiple dwc3 gadget fixes, mainly for USB support on TI AM6232
- Consistent USB_GADGET_MANUFACTURER for PHYTEC boards
- MAINTAINERS file update for u-boot-dfu

The CI job is at 
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/pipelines/20737

Thanks,
Mattijs

The following changes since commit c8ffd1356d42223cbb8c86280a083cc3c93e6426:

  Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet" 
(2024-05-13 09:15:51 -0600)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-dfu.git 
tags/u-boot-dfu-20240516

for you to fetch changes up to efbc11ccef89030ed54b7368458eeaf9ec687c77:

  MAINTAINERS: add USB gadget regex to u-boot-dfu tree (2024-05-16 13:28:45 
+0200)


u-boot-dfu-20240516

- Fix cdns3 low power hang via fast access bit
- Multiple dwc3 gadget fixes, mainly for USB support on TI AM6232
- Consistent USB_GADGET_MANUFACTURER for PHYTEC boards
- MAINTAINERS file update for u-boot-dfu


Aswath Govindraju (1):
  usb: cdns3: gadget.c: Set fast access bit

Benjamin Hahn (1):
  configs: Make USB_GADGET_MANUFACTURER consistent over all PHYTEC boards

Felipe Balbi (4):
  usb: dwc3: gadget: combine return points into a single one
  usb: dwc3: gadget: clear SUSPHY bit before ep cmds
  usb: dwc3: gadget: only resume USB2 PHY in <=HIGHSPEED
  usb: dwc3: gadget: properly check ep cmd

Mattijs Korpershoek (2):
  MAINTAINERS: add tree link for fastboot
  MAINTAINERS: add USB gadget regex to u-boot-dfu tree

Thinh Nguyen (2):
  usb: dwc3: gadget: Check ENBLSLPM before sending ep command
  usb: dwc3: gadget: Disable GUSB2PHYCFG.SUSPHY for End Transfer

 MAINTAINERS  |  4 +++
 configs/phycore-imx8mp_defconfig |  2 +-
 configs/phycore_am64x_a53_defconfig  |  2 +-
 configs/phycore_am64x_r5_defconfig   |  2 +-
 configs/phycore_pcl063_defconfig |  2 +-
 configs/phycore_pcl063_ull_defconfig |  2 +-
 drivers/usb/cdns3/gadget.c   |  4 +++
 drivers/usb/dwc3/core.h  |  2 ++
 drivers/usb/dwc3/gadget.c| 47 +---
 9 files changed, 59 insertions(+), 8 deletions(-)


Re: [PATCH v2 09/12] clk: boston: Allow to get regmap from parent device

2024-05-16 Thread Jiaxun Yang



在2024年5月16日五月 下午3:00,Jonas Karlman写道:
> Hi Jiaxun,
>
> On 2024-05-16 13:40, Jiaxun Yang wrote:
>> In upstream devicetree, clk_boston is a child of syscon node
>> and there is no "regmap" property for clk_boston node.
>> 
>> Try to check parent device first to look for syscon.
>> 
>> Signed-off-by: Jiaxun Yang 
>> ---
>> v2: Move syscon_get_regmap to probe
>> ---
>>  drivers/clk/clk_boston.c | 37 +
>>  1 file changed, 25 insertions(+), 12 deletions(-)
>> 
>> diff --git a/drivers/clk/clk_boston.c b/drivers/clk/clk_boston.c
>> index 030ff7cc58ec..1985bb0ec334 100644
>> --- a/drivers/clk/clk_boston.c
>> +++ b/drivers/clk/clk_boston.c
>> @@ -12,6 +12,7 @@
>>  #include 
>>  
>>  struct clk_boston {
>> +struct udevice *syscon;
>>  struct regmap *regmap;
>>  };
>>  
>> @@ -58,23 +59,33 @@ const struct clk_ops clk_boston_ops = {
>>  .get_rate = clk_boston_get_rate,
>>  };
>>  
>> -static int clk_boston_of_to_plat(struct udevice *dev)
>> +static int clk_boston_probe(struct udevice *dev)
>>  {
>>  struct clk_boston *state = dev_get_plat(dev);
>> -struct udevice *syscon;
>> -int err;
>>  
>> -err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
>> -   "regmap", );
>> -if (err) {
>> -pr_err("unable to find syscon device\n");
>> -return err;
>> +state->regmap = syscon_get_regmap(state->syscon);
>> +if (IS_ERR(state->regmap)) {
>> +pr_err("unable to find regmap\n");
>> +return PTR_ERR(state->regmap);
>>  }
>>  
>> -state->regmap = syscon_get_regmap(syscon);
>> -if (!state->regmap) {
>> -pr_err("unable to find regmap\n");
>> -return -ENODEV;
>> +return 0;
>> +}
>> +
>> +static int clk_boston_of_to_plat(struct udevice *dev)
>> +{
>> +struct clk_boston *state = dev_get_plat(dev);
>> +int err;
>> +
>> +if (dev->parent && device_get_uclass_id(dev->parent) == UCLASS_SYSCON) {
>> +state->syscon = dev->parent;
>> +} else {
>> +err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
>> +   "regmap", >syscon);
>
> This will trigger a probe of the referenced regmap phandle. To simplify
> and avoid probing devices at of_to_plat() stage, you can probably just
> rename of_to_plat() to probe() and skip of_to_plat() stage completely.

Thanks, will fix in next version.

>
> Regards,
> Jonas

-- 
- Jiaxun


Re: [PATCH v1 6/9] rockchip: RK3568: Read the reset cause from clock reset unit for RK356x SoC

2024-05-16 Thread Jonas Karlman
Hi Anand,

On 2024-05-16 10:59, Anand Moon wrote:
> Read the reset cause from clock reset unit for RK356x SoC.
> 
> Cc: Jagan Teki 
> Signed-off-by: Anand Moon 
> ---
>  arch/arm/mach-rockchip/cpu-info.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/arm/mach-rockchip/cpu-info.c 
> b/arch/arm/mach-rockchip/cpu-info.c
> index 77833c8fce..114608b506 100644
> --- a/arch/arm/mach-rockchip/cpu-info.c
> +++ b/arch/arm/mach-rockchip/cpu-info.c
> @@ -12,6 +12,8 @@
>  #include 
>  #elif IS_ENABLED(CONFIG_ROCKCHIP_RK3399)
>  #include 
> +#elif IS_ENABLED(CONFIG_ROCKCHIP_RK33568)
> +#include 
>  #endif
>  #include 
>  #include 
> @@ -22,6 +24,8 @@ char *get_reset_cause(void)
>   struct rk3328_cru *cru = rockchip_get_cru();
>  #elif IS_ENABLED(CONFIG_ROCKCHIP_RK3399)
>   struct rockchip_cru *cru = rockchip_get_cru();
> +#elif IS_ENABLED(CONFIG_ROCKCHIP_RK3568)
> + struct rk3568_cru *cru = rockchip_get_cru();

This is strictly not needed for RK3568 after the commit 6e710897aa31
("rockchip: cru: Enable cpu info support for rk3568").

Suggest you use same/similar workaround or cleanup the include/define
statement in arch/arm/include/asm/arch-rockchip/cru.h for all SoCs.

Also at least one RK SoC have other bits set in the glb_rst_st reg.

Suggest you add following:

  GLB_RST_MASK  = GENMASK(5, 0),

and use something like:

  switch (cru->glb_rst_st & GLB_RST_MASK) {

or "unknown reset" is reported on affected SoCs.

I have also seen POR always being reported even after a reboot so please
confirm that reset reason works on the SoCs/boards you enable this on.

Regards,
Jonas

>  #endif
>   char *cause = NULL;
>  



Re: [PATCH v1 5/9] arm: rockchip: Enable display cpuinfo to be build with SPL_BUILD

2024-05-16 Thread Jonas Karlman
Hi Anand,

On 2024-05-16 10:59, Anand Moon wrote:
> Changes help enable CONFIG_DISPLAY_CPUINFO to build with SPL_BUILD for
> SoC RK356x and RK3588.
> 
> Cc: Jagan Teki 
> Signed-off-by: Anand Moon 
> ---
>  arch/arm/mach-rockchip/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
> index c07bdaee4c..6722e7c9ea 100644
> --- a/arch/arm/mach-rockchip/Makefile
> +++ b/arch/arm/mach-rockchip/Makefile
> @@ -25,7 +25,7 @@ obj-y += boot_mode.o
>  obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o
>  endif
>  
> -ifeq ($(CONFIG_TPL_BUILD),)
> +ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)

Suggest you move the cpu-info.o line inside the ifeq/endif block above.

Regards,
Jonas

>  obj-$(CONFIG_DISPLAY_CPUINFO) += cpu-info.o
>  endif
>  



Re: [PATCH v2 09/12] clk: boston: Allow to get regmap from parent device

2024-05-16 Thread Jonas Karlman
Hi Jiaxun,

On 2024-05-16 13:40, Jiaxun Yang wrote:
> In upstream devicetree, clk_boston is a child of syscon node
> and there is no "regmap" property for clk_boston node.
> 
> Try to check parent device first to look for syscon.
> 
> Signed-off-by: Jiaxun Yang 
> ---
> v2: Move syscon_get_regmap to probe
> ---
>  drivers/clk/clk_boston.c | 37 +
>  1 file changed, 25 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/clk/clk_boston.c b/drivers/clk/clk_boston.c
> index 030ff7cc58ec..1985bb0ec334 100644
> --- a/drivers/clk/clk_boston.c
> +++ b/drivers/clk/clk_boston.c
> @@ -12,6 +12,7 @@
>  #include 
>  
>  struct clk_boston {
> + struct udevice *syscon;
>   struct regmap *regmap;
>  };
>  
> @@ -58,23 +59,33 @@ const struct clk_ops clk_boston_ops = {
>   .get_rate = clk_boston_get_rate,
>  };
>  
> -static int clk_boston_of_to_plat(struct udevice *dev)
> +static int clk_boston_probe(struct udevice *dev)
>  {
>   struct clk_boston *state = dev_get_plat(dev);
> - struct udevice *syscon;
> - int err;
>  
> - err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
> -"regmap", );
> - if (err) {
> - pr_err("unable to find syscon device\n");
> - return err;
> + state->regmap = syscon_get_regmap(state->syscon);
> + if (IS_ERR(state->regmap)) {
> + pr_err("unable to find regmap\n");
> + return PTR_ERR(state->regmap);
>   }
>  
> - state->regmap = syscon_get_regmap(syscon);
> - if (!state->regmap) {
> - pr_err("unable to find regmap\n");
> - return -ENODEV;
> + return 0;
> +}
> +
> +static int clk_boston_of_to_plat(struct udevice *dev)
> +{
> + struct clk_boston *state = dev_get_plat(dev);
> + int err;
> +
> + if (dev->parent && device_get_uclass_id(dev->parent) == UCLASS_SYSCON) {
> + state->syscon = dev->parent;
> + } else {
> + err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
> +"regmap", >syscon);

This will trigger a probe of the referenced regmap phandle. To simplify
and avoid probing devices at of_to_plat() stage, you can probably just
rename of_to_plat() to probe() and skip of_to_plat() stage completely.

Regards,
Jonas

> + if (err) {
> + pr_err("unable to find syscon device\n");
> + return err;
> + }
>   }
>  
>   return 0;
> @@ -92,6 +103,8 @@ U_BOOT_DRIVER(clk_boston) = {
>   .id = UCLASS_CLK,
>   .of_match = clk_boston_match,
>   .of_to_plat = clk_boston_of_to_plat,
> + .probe = clk_boston_probe,
>   .plat_auto  = sizeof(struct clk_boston),
>   .ops = _boston_ops,
> + .flags = DM_FLAG_PRE_RELOC,
>  };
> 



Re: [PATCH v1 5/9] arm: rockchip: Enable display cpuinfo to be build with SPL_BUILD

2024-05-16 Thread Quentin Schulz

Hi Anand,

On 5/16/24 10:59 AM, Anand Moon wrote:

Changes help enable CONFIG_DISPLAY_CPUINFO to build with SPL_BUILD for
SoC RK356x and RK3588.
 > Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
  arch/arm/mach-rockchip/Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index c07bdaee4c..6722e7c9ea 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -25,7 +25,7 @@ obj-y += boot_mode.o
  obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o
  endif
  
-ifeq ($(CONFIG_TPL_BUILD),)

+ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)


If I'm not mistaken, this is a way for disabling building cpu-info.o if 
either in TPL or SPL build mode (therefore only compiling for proper 
build mode).


I think it'd make more sense to convert CONFIG_DISPLAY_CPUINFO into 
three symbols, e.g. CONFIG_TPL_DISPLAY_CPUINFO, CONFIG_SPL_DISPLAY_INFO 
and then use


"""
obj-$(CONFIG_$(TPL_SPL_)DISPLAY_CPUINFO) += cpu-info.o
"""

Also... considering the mail I sent to your first patch in this patch 
series, if we migrate to using sysreset driver to print the reset 
reason, we wouldn't need this file anymore so we could remove it and not 
have to care about this.


Cheers,
Quentin


Re: [PATCH v1 1/9] rockchip: RK3328: Read the reset cause from clock reset unit for RK3328 SoC

2024-05-16 Thread Quentin Schulz

Hi Anand,

On 5/16/24 10:59 AM, Anand Moon wrote:

Read the reset cause from clock reset unit for RK3328 SoC.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
  arch/arm/mach-rockchip/cpu-info.c | 7 ++-
  1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-rockchip/cpu-info.c 
b/arch/arm/mach-rockchip/cpu-info.c
index 14c7331e1a..fce4bd7541 100644
--- a/arch/arm/mach-rockchip/cpu-info.c
+++ b/arch/arm/mach-rockchip/cpu-info.c
@@ -8,12 +8,17 @@
  #include 
  #include 
  #include 
+#if IS_ENABLED(CONFIG_ROCKCHIP_RK3328)
+#include 
+#endif
  #include 
  #include 
  
  char *get_reset_cause(void)

  {
-   struct rockchip_cru *cru = rockchip_get_cru();
+#if IS_ENABLED(CONFIG_ROCKCHIP_RK3328)
+   struct rk3328_cru *cru = rockchip_get_cru();
+#endif


NACK.

If I only apply this patch, it breaks support for rk3288 and rk3399 (the 
ones which have a rockchip_cru struct).


Do:

"""

#if IS_ENABLED(CONFIG_ROCKCHIP_RK3328)
struct rk3328_cru *cru = rockchip_get_cru();
#else
struct rockchip_cru *cru = rockchip_get_cru();
#endif
"""

instead to keep the current support and add stuff.

However, I very much don't like this. There's no need for cpuinfo.c to 
become SoC-specific.


I would recommend to move get_reset_cause() in some file that is SoC 
specific, and out of the DISPLAY_CPUINFO ifdef since it may be useful 
outside of this very specific print_cpuinfo function (c.f. the rk3399 
firefly board).


Yes there's a bit of code duplication then, BUT, nothing guarantees us 
the reset reason will always be stored in that glb_rst_st register and 
moreover, RK3588 already has more reasons that currently supported, and 
this prevents us from expanding it.


You can have a

"""
__weak char *get_reset_cause(void)
{
return "could not get reset cause";
}
"""
in replacement and let SoC-specific files expand it by overriding it.

And to think even further than that, maybe we should actually expand 
drivers/sysreset/sysreset_rockchip.c to support more SoCs.


Then we could get the status via get_status callback from sysreset_ops in

https://elixir.bootlin.com/u-boot/latest/source/common/board_f.c#L904

and remove this cpu-info.c file from the arch/arm/mach-rockchip.

Reporting the SoC could be done with a CPU UCLASS (c.f. what's done for 
IMX8 already), from 
https://elixir.bootlin.com/u-boot/latest/source/common/board_f.c#L176.


This honestly makes more sense to me.

Cheers,
Quentin


[PATCH v2 2/2] doc: Update netconsole examples, mention stderr

2024-05-16 Thread Fiona Klute
Stderr was missing from the initial description and example.

As I understand the env command documentation the subcommand style is
preferred, though the old format is still fully supported.

Signed-off-by: Fiona Klute 
---
Changes in v2:
* Mention stderr redirection
* Use 4 spaces instead of tabs for code block to avoid overflowing
  lines

 doc/usage/netconsole.rst | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/doc/usage/netconsole.rst b/doc/usage/netconsole.rst
index 647f0c220b..f745615d9a 100644
--- a/doc/usage/netconsole.rst
+++ b/doc/usage/netconsole.rst
@@ -3,10 +3,10 @@ Network console

 In U-Boot, we implemented the networked console via the standard
 "devices" mechanism, which means that you can switch between the
-serial and network input/output devices by adjusting the 'stdin' and
-'stdout' environment variables. To switch to the networked console,
-set either of these variables to "nc". Input and output can be
-switched independently.
+serial and network input/output devices by adjusting the 'stdin',
+'stdout', and 'stderr' environment variables. To switch to the
+networked console, set either of these variables to "nc". Input and
+output can be switched independently.

 The default buffer size can be overridden by setting
 CFG_NETCONSOLE_BUFFER_SIZE.
@@ -24,10 +24,10 @@ can be used for network console.

 For example, if your server IP is 192.168.1.1, you could use::

-   => setenv nc 'setenv stdout nc;setenv stdin nc'
-   => setenv ncip 192.168.1.1
-   => saveenv
-   => run nc
+=> env set nc 'env set stdout nc; env set stderr nc; env set stdin nc'
+=> env set ncip 192.168.1.1
+=> env save
+=> run nc

 On the host side, please use this script to access the console

--
2.43.0



[PATCH v2 1/2] doc: Detailed example for netconsole setup

2024-05-16 Thread Fiona Klute
This adds details that I would have liked to have readily available,
in particular how to activate the network interface before enabling
netconsole, and how to integrate netconsole so you can use the U-Boot
prompt.

Signed-off-by: Fiona Klute 
---
Changes in v2:
* Include stderr redirection
* Use 4 spaces instead of tabs for code block to avoid overflowing
  lines

 doc/usage/netconsole.rst | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/doc/usage/netconsole.rst b/doc/usage/netconsole.rst
index 2aa3b9ccc5..647f0c220b 100644
--- a/doc/usage/netconsole.rst
+++ b/doc/usage/netconsole.rst
@@ -18,7 +18,9 @@ broadcast address and port  are used. If it is set to an 
IP
 address of 0 (or 0.0.0.0) then no messages are sent to the network.
 The source / listening port can be configured separately by setting
 the 'ncinport' environment variable and the destination port can be
-configured by setting the 'ncoutport' environment variable.
+configured by setting the 'ncoutport' environment variable. Note that
+you need to set up the network interface (e.g. using DHCP) before it
+can be used for network console.

 For example, if your server IP is 192.168.1.1, you could use::

@@ -107,3 +109,32 @@ as follows:

 Note that unlike the U-Boot implementation the Linux netconsole is
 unidirectional, i. e. you have console output only in Linux.
+
+Setup via environment
+-
+
+If persistent environment is enabled in your U-Boot configuration, you
+can configure the network console using the environment. For example::
+
+=> env set autoload no
+=> env set hostname "u-boot"
+=> env set bootdelay 5
+=> env set nc 'dhcp; env set stdout nc; env set stderr nc; env set stdin 
nc'
+=> env set ncip 192.168.1.1
+=> env set preboot "${preboot}; run nc;"
+=> env save
+=> reset
+
+``autoload no`` tells the ``dhcp`` command to configure the network
+interface without trying to load an image. ``hostname "u-boot"`` sets
+the hostname to be sent in DHCP requests, so they are easy to
+recognize in the DHCP server log. The command in ``nc`` calls ``dhcp``
+to make sure the network interface is set up before enabling
+netconsole.
+
+Adding ``nc`` to ``preboot`` tells U-Boot to activate netconsole
+before trying to find any boot options, so you can interact with it if
+desired.
+
+``env save`` stores the settings persistently, and ``reset`` then
+triggers a fresh start that will use the changed settings.
--
2.43.0



Re: [PATCH 1/2] doc: Detailed example for netconsole setup

2024-05-16 Thread Fiona Klute

Am 15.05.24 um 21:05 schrieb Tony Dinh:

Hi Fiona,

On Tue, May 14, 2024 at 5:28 PM Fiona Klute  wrote:


This adds details that I would have liked to have readily available,
in particular how to activate the network interface before enabling
netconsole, and how to integrate netconsole so you can use the U-Boot
prompt.

Signed-off-by: Fiona Klute 
---
  doc/usage/netconsole.rst | 33 -
  1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/doc/usage/netconsole.rst b/doc/usage/netconsole.rst
index 2aa3b9ccc5..0c983e6970 100644
--- a/doc/usage/netconsole.rst
+++ b/doc/usage/netconsole.rst
@@ -18,7 +18,9 @@ broadcast address and port  are used. If it is set to an 
IP
  address of 0 (or 0.0.0.0) then no messages are sent to the network.
  The source / listening port can be configured separately by setting
  the 'ncinport' environment variable and the destination port can be
-configured by setting the 'ncoutport' environment variable.
+configured by setting the 'ncoutport' environment variable. Note that
+you need to set up the network interface (e.g. using DHCP) before it
+can be used for network console.

  For example, if your server IP is 192.168.1.1, you could use::

@@ -107,3 +109,32 @@ as follows:

  Note that unlike the U-Boot implementation the Linux netconsole is
  unidirectional, i. e. you have console output only in Linux.
+
+Setup via environment
+-
+
+If persistent environment is enabled in your U-Boot configuration, you
+can configure the network console using the environment. For example::
+
+   => env set autoload no
+   => env set hostname "u-boot"
+   => env set bootdelay 5
+   => env set nc 'dhcp; env set stdout nc; env set stdin nc'


We would need "env set stderr nc" here, too.


Thanks, I guess I should add that to the existing description and
example as well then. I'll test it and then send an update.

Best regards,
Fiona



[PATCH v1 9/9] rockchip: RK3588: Enable display cpuinfo support on all boards

2024-05-16 Thread Anand Moon
Imply DISPLAY_CPUINFO Kconfig options to support on all RK3588s and
RK3588 boards, Its used to determine the reset cause of the board.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/Kconfig   | 1 +
 configs/coolpi-4b-rk3588s_defconfig  | 1 -
 configs/coolpi-cm5-evb-rk3588_defconfig  | 1 -
 configs/evb-rk3588_defconfig | 1 -
 configs/generic-rk3588_defconfig | 1 -
 configs/jaguar-rk3588_defconfig  | 1 -
 configs/nanopc-t6-rk3588_defconfig   | 1 -
 configs/neu6a-io-rk3588_defconfig| 1 -
 configs/neu6b-io-rk3588_defconfig| 1 -
 configs/orangepi-5-plus-rk3588_defconfig | 1 -
 configs/orangepi-5-rk3588s_defconfig | 1 -
 configs/quartzpro64-rk3588_defconfig | 1 -
 configs/rock5a-rk3588s_defconfig | 1 -
 configs/rock5b-rk3588_defconfig  | 1 -
 configs/toybrick-rk3588_defconfig| 1 -
 configs/turing-rk1-rk3588_defconfig  | 1 -
 16 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index 2e9c71138e..1b5cc34f99 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -366,6 +366,7 @@ config ROCKCHIP_RK3588
imply SCMI_FIRMWARE
imply SPL_ATF_NO_PLATFORM_PARAM if SPL_ATF
imply SPL_MMC_HS200_SUPPORT if SPL_MMC && MMC_HS200_SUPPORT
+   imply DISPLAY_CPUINFO
help
  The Rockchip RK3588 is a ARM-based SoC with quad-core Cortex-A76 and
  quad-core Cortex-A55 including NEON and GPU, 6TOPS NPU, Mali-G610 MP4,
diff --git a/configs/coolpi-4b-rk3588s_defconfig 
b/configs/coolpi-4b-rk3588s_defconfig
index 3d45d939ab..b094224f6e 100644
--- a/configs/coolpi-4b-rk3588s_defconfig
+++ b/configs/coolpi-4b-rk3588s_defconfig
@@ -23,7 +23,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588s-coolpi-4b.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/coolpi-cm5-evb-rk3588_defconfig 
b/configs/coolpi-cm5-evb-rk3588_defconfig
index 5190d69c1c..382ee97fc9 100644
--- a/configs/coolpi-cm5-evb-rk3588_defconfig
+++ b/configs/coolpi-cm5-evb-rk3588_defconfig
@@ -23,7 +23,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-coolpi-cm5-evb.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/evb-rk3588_defconfig b/configs/evb-rk3588_defconfig
index 1d5585677a..bfc505a4b7 100644
--- a/configs/evb-rk3588_defconfig
+++ b/configs/evb-rk3588_defconfig
@@ -16,7 +16,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-evb1-v10.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/generic-rk3588_defconfig b/configs/generic-rk3588_defconfig
index 42bc2c9a76..ddb23b035b 100644
--- a/configs/generic-rk3588_defconfig
+++ b/configs/generic-rk3588_defconfig
@@ -17,7 +17,6 @@ CONFIG_SPL_LOAD_FIT=y
 # CONFIG_BOOTMETH_VBE is not set
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-generic.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/jaguar-rk3588_defconfig b/configs/jaguar-rk3588_defconfig
index b69cf4cd05..712a936539 100644
--- a/configs/jaguar-rk3588_defconfig
+++ b/configs/jaguar-rk3588_defconfig
@@ -22,7 +22,6 @@ CONFIG_SPL_LOAD_FIT=y
 # CONFIG_BOOTMETH_VBE is not set
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-jaguar.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_CYCLIC=y
 CONFIG_SPL_MAX_SIZE=0x4
diff --git a/configs/nanopc-t6-rk3588_defconfig 
b/configs/nanopc-t6-rk3588_defconfig
index 926267f93a..978c62aee6 100644
--- a/configs/nanopc-t6-rk3588_defconfig
+++ b/configs/nanopc-t6-rk3588_defconfig
@@ -23,7 +23,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-nanopc-t6.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/neu6a-io-rk3588_defconfig 
b/configs/neu6a-io-rk3588_defconfig
index ac281e6539..6f2765c640 100644
--- a/configs/neu6a-io-rk3588_defconfig
+++ b/configs/neu6a-io-rk3588_defconfig
@@ -16,7 +16,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-edgeble-neu6a-io.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git 

[PATCH v1 8/9] rockchip: RK3588: Read the reset cause from clock reset unit for RK3588 SoC

2024-05-16 Thread Anand Moon
Read the reset cause from clock reset unit for RK3588 SoC.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/cpu-info.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/mach-rockchip/cpu-info.c 
b/arch/arm/mach-rockchip/cpu-info.c
index 114608b506..8415009fc5 100644
--- a/arch/arm/mach-rockchip/cpu-info.c
+++ b/arch/arm/mach-rockchip/cpu-info.c
@@ -14,6 +14,8 @@
 #include 
 #elif IS_ENABLED(CONFIG_ROCKCHIP_RK33568)
 #include 
+#elif IS_ENABLED(CONFIG_ROCKCHIP_RK3588)
+#include 
 #endif
 #include 
 #include 
@@ -26,6 +28,8 @@ char *get_reset_cause(void)
struct rockchip_cru *cru = rockchip_get_cru();
 #elif IS_ENABLED(CONFIG_ROCKCHIP_RK3568)
struct rk3568_cru *cru = rockchip_get_cru();
+#elif IS_ENABLED(CONFIG_ROCKCHIP_RK3588)
+   struct rk3588_cru *cru = rockchip_get_cru();
 #endif
char *cause = NULL;
 
-- 
2.45.0



[PATCH v1 7/9] rockchip: RK356x: Enable display cpuinfo support on all boards

2024-05-16 Thread Anand Moon
Imply DISPLAY_CPUINFO Kconfig options to support on all RK3566 and
RK3568 boards, Its used to determine the reset cause of the board.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/Kconfig| 1 +
 configs/anbernic-rgxx3-rk3566_defconfig   | 1 -
 configs/bpi-r2-pro-rk3568_defconfig   | 1 -
 configs/evb-rk3568_defconfig  | 1 -
 configs/generic-rk3568_defconfig  | 1 -
 configs/lubancat-2-rk3568_defconfig   | 1 -
 configs/nanopi-r5c-rk3568_defconfig   | 1 -
 configs/nanopi-r5s-rk3568_defconfig   | 1 -
 configs/odroid-m1-rk3568_defconfig| 1 -
 configs/pinetab2-rk3566_defconfig | 1 -
 configs/quartz64-a-rk3566_defconfig   | 1 -
 configs/quartz64-b-rk3566_defconfig   | 1 -
 configs/radxa-cm3-io-rk3566_defconfig | 1 -
 configs/radxa-e25-rk3568_defconfig| 1 -
 configs/rock-3a-rk3568_defconfig  | 1 -
 configs/soquartz-blade-rk3566_defconfig   | 1 -
 configs/soquartz-cm4-rk3566_defconfig | 1 -
 configs/soquartz-model-a-rk3566_defconfig | 1 -
 18 files changed, 1 insertion(+), 17 deletions(-)

diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index 1fd482e43b..2e9c71138e 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -331,6 +331,7 @@ config ROCKCHIP_RK3568
imply ROCKCHIP_OTP
imply SPL_ATF_NO_PLATFORM_PARAM if SPL_ATF
imply SPL_MMC_HS200_SUPPORT if SPL_MMC && MMC_HS200_SUPPORT
+   imply DISPLAY_CPUINFO
help
  The Rockchip RK3568 is a ARM-based SoC with quad-core Cortex-A55,
  including NEON and GPU, 512K L3 cache, Mali-G52 based graphics,
diff --git a/configs/anbernic-rgxx3-rk3566_defconfig 
b/configs/anbernic-rgxx3-rk3566_defconfig
index a03509bf46..95f7cf0739 100644
--- a/configs/anbernic-rgxx3-rk3566_defconfig
+++ b/configs/anbernic-rgxx3-rk3566_defconfig
@@ -21,7 +21,6 @@ CONFIG_OF_BOARD_SETUP=y
 CONFIG_OF_STDOUT_VIA_ALIAS=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3566-anbernic-rgxx3.dtb"
 # CONFIG_CONSOLE_MUX is not set
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_BOARD_RNG_SEED=y
 CONFIG_SPL_MAX_SIZE=0x4
diff --git a/configs/bpi-r2-pro-rk3568_defconfig 
b/configs/bpi-r2-pro-rk3568_defconfig
index eccc15a0ae..4955fd907c 100644
--- a/configs/bpi-r2-pro-rk3568_defconfig
+++ b/configs/bpi-r2-pro-rk3568_defconfig
@@ -16,7 +16,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-bpi-r2-pro.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/evb-rk3568_defconfig b/configs/evb-rk3568_defconfig
index 2076f55122..e6da8fd246 100644
--- a/configs/evb-rk3568_defconfig
+++ b/configs/evb-rk3568_defconfig
@@ -15,7 +15,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-evb1-v10.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/generic-rk3568_defconfig b/configs/generic-rk3568_defconfig
index 66a33afbba..ba2d995cdc 100644
--- a/configs/generic-rk3568_defconfig
+++ b/configs/generic-rk3568_defconfig
@@ -20,7 +20,6 @@ CONFIG_SPL_LOAD_FIT=y
 # CONFIG_BOOTMETH_VBE is not set
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-generic.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/lubancat-2-rk3568_defconfig 
b/configs/lubancat-2-rk3568_defconfig
index 88593bfa70..384d0ecfc5 100644
--- a/configs/lubancat-2-rk3568_defconfig
+++ b/configs/lubancat-2-rk3568_defconfig
@@ -15,7 +15,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-lubancat-2.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/nanopi-r5c-rk3568_defconfig 
b/configs/nanopi-r5c-rk3568_defconfig
index 4a6c320faf..b83796083d 100644
--- a/configs/nanopi-r5c-rk3568_defconfig
+++ b/configs/nanopi-r5c-rk3568_defconfig
@@ -17,7 +17,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-nanopi-r5c.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/nanopi-r5s-rk3568_defconfig 
b/configs/nanopi-r5s-rk3568_defconfig
index 7ab12e619a..5d500963a2 100644
--- a/configs/nanopi-r5s-rk3568_defconfig
+++ b/configs/nanopi-r5s-rk3568_defconfig
@@ -17,7 +17,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-nanopi-r5s.dtb"
-# 

[PATCH v1 6/9] rockchip: RK3568: Read the reset cause from clock reset unit for RK356x SoC

2024-05-16 Thread Anand Moon
Read the reset cause from clock reset unit for RK356x SoC.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/cpu-info.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/mach-rockchip/cpu-info.c 
b/arch/arm/mach-rockchip/cpu-info.c
index 77833c8fce..114608b506 100644
--- a/arch/arm/mach-rockchip/cpu-info.c
+++ b/arch/arm/mach-rockchip/cpu-info.c
@@ -12,6 +12,8 @@
 #include 
 #elif IS_ENABLED(CONFIG_ROCKCHIP_RK3399)
 #include 
+#elif IS_ENABLED(CONFIG_ROCKCHIP_RK33568)
+#include 
 #endif
 #include 
 #include 
@@ -22,6 +24,8 @@ char *get_reset_cause(void)
struct rk3328_cru *cru = rockchip_get_cru();
 #elif IS_ENABLED(CONFIG_ROCKCHIP_RK3399)
struct rockchip_cru *cru = rockchip_get_cru();
+#elif IS_ENABLED(CONFIG_ROCKCHIP_RK3568)
+   struct rk3568_cru *cru = rockchip_get_cru();
 #endif
char *cause = NULL;
 
-- 
2.45.0



[PATCH v1 5/9] arm: rockchip: Enable display cpuinfo to be build with SPL_BUILD

2024-05-16 Thread Anand Moon
Changes help enable CONFIG_DISPLAY_CPUINFO to build with SPL_BUILD for
SoC RK356x and RK3588.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index c07bdaee4c..6722e7c9ea 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -25,7 +25,7 @@ obj-y += boot_mode.o
 obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o
 endif
 
-ifeq ($(CONFIG_TPL_BUILD),)
+ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
 obj-$(CONFIG_DISPLAY_CPUINFO) += cpu-info.o
 endif
 
-- 
2.45.0



[PATCH v1 4/9] rockchip: RK3399: Enable display cpuinfo support on all boards

2024-05-16 Thread Anand Moon
Imply DISPLAY_CPUINFO Kconfig options to support on all RK3399
boards, Its used to determine the reset cause of the board.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/Kconfig | 1 +
 configs/chromebook_bob_defconfig   | 1 -
 configs/chromebook_kevin_defconfig | 1 -
 3 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index ba1474bb9e..1fd482e43b 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -297,6 +297,7 @@ config ROCKCHIP_RK3399
imply TPL_SYS_MALLOC_SIMPLE
imply TPL_SYSCON
imply TPL_TINY_MEMSET
+   imply DISPLAY_CPUINFO
help
  The Rockchip RK3399 is a ARM-based SoC with a dual-core Cortex-A72
  and quad-core Cortex-A53.
diff --git a/configs/chromebook_bob_defconfig b/configs/chromebook_bob_defconfig
index acfe393410..2c1a8141c0 100644
--- a/configs/chromebook_bob_defconfig
+++ b/configs/chromebook_bob_defconfig
@@ -30,7 +30,6 @@ CONFIG_SYS_LOAD_ADDR=0x800800
 CONFIG_DEBUG_UART=y
 # CONFIG_SPL_FIT_SIGNATURE is not set
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3399-gru-bob.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_BLOBLIST=y
diff --git a/configs/chromebook_kevin_defconfig 
b/configs/chromebook_kevin_defconfig
index 95fdb418d8..f6649804c7 100644
--- a/configs/chromebook_kevin_defconfig
+++ b/configs/chromebook_kevin_defconfig
@@ -31,7 +31,6 @@ CONFIG_SYS_LOAD_ADDR=0x800800
 CONFIG_DEBUG_UART=y
 # CONFIG_SPL_FIT_SIGNATURE is not set
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3399-gru-kevin.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_BLOBLIST=y
-- 
2.45.0



[PATCH v1 3/9] rockchip: RK3399: Read the reset cause from clock reset unit for RK3399 SoC

2024-05-16 Thread Anand Moon
Read the reset cause from clock reset unit for RK3399 SoC.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/cpu-info.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/mach-rockchip/cpu-info.c 
b/arch/arm/mach-rockchip/cpu-info.c
index fce4bd7541..77833c8fce 100644
--- a/arch/arm/mach-rockchip/cpu-info.c
+++ b/arch/arm/mach-rockchip/cpu-info.c
@@ -10,6 +10,8 @@
 #include 
 #if IS_ENABLED(CONFIG_ROCKCHIP_RK3328)
 #include 
+#elif IS_ENABLED(CONFIG_ROCKCHIP_RK3399)
+#include 
 #endif
 #include 
 #include 
@@ -18,6 +20,8 @@ char *get_reset_cause(void)
 {
 #if IS_ENABLED(CONFIG_ROCKCHIP_RK3328)
struct rk3328_cru *cru = rockchip_get_cru();
+#elif IS_ENABLED(CONFIG_ROCKCHIP_RK3399)
+   struct rockchip_cru *cru = rockchip_get_cru();
 #endif
char *cause = NULL;
 
-- 
2.45.0



[PATCH v1 2/9] rockchip: RK3328: Enable display cpuinfo support on all boards

2024-05-16 Thread Anand Moon
Imply DISPLAY_CPUINFO Kconfig options to support on all RK3328
boards, Its used to determine the reset cause of the board.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/Kconfig| 1 +
 configs/evb-rk3328_defconfig  | 1 -
 configs/nanopi-r2c-plus-rk3328_defconfig  | 1 -
 configs/nanopi-r2c-rk3328_defconfig   | 1 -
 configs/nanopi-r2s-rk3328_defconfig   | 1 -
 configs/orangepi-r1-plus-lts-rk3328_defconfig | 1 -
 configs/orangepi-r1-plus-rk3328_defconfig | 1 -
 configs/roc-cc-rk3328_defconfig   | 1 -
 configs/rock-pi-e-rk3328_defconfig| 1 -
 configs/rock64-rk3328_defconfig   | 1 -
 10 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index ec3697f358..ba1474bb9e 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -206,6 +206,7 @@ config ROCKCHIP_RK3328
imply SPL_SEPARATE_BSS
imply SPL_SERIAL
imply TPL_SERIAL
+   imply DISPLAY_CPUINFO
help
  The Rockchip RK3328 is a ARM-based SoC with a quad-core Cortex-A53.
  including NEON and GPU, 1MB L2 cache, Mali-T7 graphics, two
diff --git a/configs/evb-rk3328_defconfig b/configs/evb-rk3328_defconfig
index bfb8522343..e1c2016cb3 100644
--- a/configs/evb-rk3328_defconfig
+++ b/configs/evb-rk3328_defconfig
@@ -19,7 +19,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3328-evb.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/nanopi-r2c-plus-rk3328_defconfig 
b/configs/nanopi-r2c-plus-rk3328_defconfig
index f311a0a80b..700ce47696 100644
--- a/configs/nanopi-r2c-plus-rk3328_defconfig
+++ b/configs/nanopi-r2c-plus-rk3328_defconfig
@@ -20,7 +20,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3328-nanopi-r2c-plus.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/nanopi-r2c-rk3328_defconfig 
b/configs/nanopi-r2c-rk3328_defconfig
index 533dc1029f..a594f329bf 100644
--- a/configs/nanopi-r2c-rk3328_defconfig
+++ b/configs/nanopi-r2c-rk3328_defconfig
@@ -20,7 +20,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3328-nanopi-r2c.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/nanopi-r2s-rk3328_defconfig 
b/configs/nanopi-r2s-rk3328_defconfig
index 2591a9cc8a..c1d0a1f396 100644
--- a/configs/nanopi-r2s-rk3328_defconfig
+++ b/configs/nanopi-r2s-rk3328_defconfig
@@ -20,7 +20,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3328-nanopi-r2s.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/orangepi-r1-plus-lts-rk3328_defconfig 
b/configs/orangepi-r1-plus-lts-rk3328_defconfig
index 14cdbd813c..7e0b1b2773 100644
--- a/configs/orangepi-r1-plus-lts-rk3328_defconfig
+++ b/configs/orangepi-r1-plus-lts-rk3328_defconfig
@@ -23,7 +23,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3328-orangepi-r1-plus-lts.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/orangepi-r1-plus-rk3328_defconfig 
b/configs/orangepi-r1-plus-rk3328_defconfig
index 7fe58e7a14..4525c99ca2 100644
--- a/configs/orangepi-r1-plus-rk3328_defconfig
+++ b/configs/orangepi-r1-plus-rk3328_defconfig
@@ -23,7 +23,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3328-orangepi-r1-plus.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/roc-cc-rk3328_defconfig b/configs/roc-cc-rk3328_defconfig
index 91b9422e26..c1eb03c5e8 100644
--- a/configs/roc-cc-rk3328_defconfig
+++ b/configs/roc-cc-rk3328_defconfig
@@ -19,7 +19,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3328-roc-cc.dtb"
-# CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_MAX_SIZE=0x4
 CONFIG_SPL_PAD_TO=0x7f8000
diff --git a/configs/rock-pi-e-rk3328_defconfig 
b/configs/rock-pi-e-rk3328_defconfig
index 5cc54af3ca..bb99670b8c 100644
--- a/configs/rock-pi-e-rk3328_defconfig
+++ b/configs/rock-pi-e-rk3328_defconfig
@@ -19,7 +19,6 @@ CONFIG_SPL_FIT_SIGNATURE=y
 

[PATCH v1 1/9] rockchip: RK3328: Read the reset cause from clock reset unit for RK3328 SoC

2024-05-16 Thread Anand Moon
Read the reset cause from clock reset unit for RK3328 SoC.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
 arch/arm/mach-rockchip/cpu-info.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-rockchip/cpu-info.c 
b/arch/arm/mach-rockchip/cpu-info.c
index 14c7331e1a..fce4bd7541 100644
--- a/arch/arm/mach-rockchip/cpu-info.c
+++ b/arch/arm/mach-rockchip/cpu-info.c
@@ -8,12 +8,17 @@
 #include 
 #include 
 #include 
+#if IS_ENABLED(CONFIG_ROCKCHIP_RK3328)
+#include 
+#endif
 #include 
 #include 
 
 char *get_reset_cause(void)
 {
-   struct rockchip_cru *cru = rockchip_get_cru();
+#if IS_ENABLED(CONFIG_ROCKCHIP_RK3328)
+   struct rk3328_cru *cru = rockchip_get_cru();
+#endif
char *cause = NULL;
 
if (IS_ERR(cru))
-- 
2.45.0



Re: [PATCH 12/13] MIPS: boston: Migrate to OF_UPSTREAM

2024-05-16 Thread Sumit Garg
On Thu, 16 May 2024 at 17:29, Jiaxun Yang  wrote:
>
>
>
> 在2024年5月14日五月 上午6:45,Sumit Garg写道:
> > Hi Jiaxun,
> >
> [...]
> >> @@ -0,0 +1,10 @@
> >> +// SPDX-License-Identifier: GPL-2.0+
> >> +
> >> +_regs {
> >> +   compatible = "img,boston-platform-regs", "syscon", "simple-mfd";
> >> +   bootph-all;
> >> +};
> >> +
> >> +_boston {
> >> +   bootph-all;
> >> +};
> >
> > You can try to push these overrides to upstream DTS as well, so you
> > won't have to maintain them in U-Boot.
>
> Hi Sumit,
>
> Thanks for your comments! For the compatible override, I already sent
> patch to upstream. However, I have a question, Can we really do bootph-all
> in linux upstream?

Yes.

>
> I don't think it's documented in upstream dt bindings.
>

It has been documented as part of core schema DT bindings here [1].

[1] 
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/bootph.yaml

-Sumit


Re: [PATCH 12/13] MIPS: boston: Migrate to OF_UPSTREAM

2024-05-16 Thread Jiaxun Yang



在2024年5月14日五月 上午6:45,Sumit Garg写道:
> Hi Jiaxun,
>
[...]
>> @@ -0,0 +1,10 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +
>> +_regs {
>> +   compatible = "img,boston-platform-regs", "syscon", "simple-mfd";
>> +   bootph-all;
>> +};
>> +
>> +_boston {
>> +   bootph-all;
>> +};
>
> You can try to push these overrides to upstream DTS as well, so you
> won't have to maintain them in U-Boot.

Hi Sumit,

Thanks for your comments! For the compatible override, I already sent
patch to upstream. However, I have a question, Can we really do bootph-all
in linux upstream?

I don't think it's documented in upstream dt bindings.

Thanks
>
> -Sumit
>
[...]

-- 
- Jiaxun


Re: [PATCH v1 9/9] rockchip: RK3588: Enable display cpuinfo support on all boards

2024-05-16 Thread Anand Moon
Hi Quentin

On Thu, 16 May 2024 at 16:13, Quentin Schulz  wrote:
>
> Hi Anand,
>
> On 5/16/24 12:12 PM, Anand Moon wrote:
> > Hi Quentin
> >
> > On Thu, 16 May 2024 at 14:52, Quentin Schulz  
> > wrote:
> >>
> >> Hi Anand,
> >>
> >> This is patch 9/9 but somehow I didn't receive any other patch, nor did
> >> the mailing list? c.f.
> >> https://lists.denx.de/pipermail/u-boot/2024-May/thread.html and
> >> https://lore.kernel.org/u-boot/. Are you registered on the ML?
> >>
> >
> > Thanks for your  review comments.
> >
> > Something went wrong with git sendmail,
> > Your message have not reached my email client (gmail)
> >
>
> A mail server rejected the mail to edgeble.ai domain (both you and
> Jagan) /me shrugs.
>

Yeah, something went wrong. It's Gmail server or u-boot mail server blocked
I don't know the reason for this.

Remove me and Jagan (edgeble.ai) for now as of now.

> >> On 5/16/24 10:59 AM, Anand Moon wrote:
> >>> Imply DISPLAY_CPUINFO Kconfig options to support on all RK3588s and
> >>> RK3588 boards, Its used to determine the reset cause of the board.
> >>>
> >>> diff --git a/arch/arm/mach-rockchip/Kconfig 
> >>> b/arch/arm/mach-rockchip/Kconfig
> >>> index 2e9c71138e..1b5cc34f99 100644
> >>> --- a/arch/arm/mach-rockchip/Kconfig
> >>> +++ b/arch/arm/mach-rockchip/Kconfig
> >>> @@ -366,6 +366,7 @@ config ROCKCHIP_RK3588
> >>>imply SCMI_FIRMWARE
> >>>imply SPL_ATF_NO_PLATFORM_PARAM if SPL_ATF
> >>>imply SPL_MMC_HS200_SUPPORT if SPL_MMC && MMC_HS200_SUPPORT
> >>> + imply DISPLAY_CPUINFO
> >>
> >> This is unnecessary, it's already defaulting to y if building for ARM
> >> boards: https://elixir.bootlin.com/u-boot/latest/source/common/Kconfig#L596
> >>
> > See below...
> >> I also don't think this is SO useful that we need to enable it on all
> >> rk3588 boards? But also, doesn't hurt, so... whatever I guess :) ?
> >>
> >> While looking at the code, I think we can remove the ifdef in
> >> https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-rockchip/cpu-info.c#L47
> >> because this file is anyway only compiled when CONFIG_DISPLAY_CPUINFO is
> >> set, c.f.
> >
> > Oops I missed this changes, my bad
> > I will dop my changes over here.
> >
> >> https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-rockchip/Makefile#L30
> >>
> > On Rockchip SoC CONFIG_DISPLAY_CPUINFO is been disable on most of the
> > configs files.
> >
> > -# CONFIG_DISPLAY_CPUINFO is not set
> >
> > My changes are related to determine the reset cause of the board and
> > display the results.
> > its only enable on selected SoC hence I have to used this logic.
> >
>
> It's enabled for all Aarch64/Aarch32 SoCs by default. People explicitly
> disabled them in their own defconfig, either because the first person
> who added a board based on rk3588 didn't know or didn't care and
> everybody just copied it as a base, or because they don't care about
> it/don't want it.
>
My series focuses on determining the reset cause of the boards
Do we need to enable this feature ?

We are not compiling DISPLAY_CPUINFO for all for RK3568 and RK3588
But with the following changes enable this to be built for SPL_BUILD ( patch v5)
in this series. wow it is built for all SoC.

diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index c07bdaee4c..6722e7c9ea 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -25,7 +25,7 @@ obj-y += boot_mode.o
 obj-$(CONFIG_ROCKCHIP_COMMON_BOARD) += board.o
 endif

-ifeq ($(CONFIG_TPL_BUILD),)
+ifeq ($(CONFIG_SPL_BUILD)$(CONFIG_TPL_BUILD),)
 obj-$(CONFIG_DISPLAY_CPUINFO) += cpu-info.o
 endif

> In any case, you only need to change the defconfigs, nothing else.
>
> > U-Boot 2024.07-rc2-00397-g0370324feb-dirty (May 16 2024 - 13:11:14 +0530)
> >
> > SoC: Rockchip rk3568
> > Reset cause: POR <---
> > Model: Radxa ROCK3 Model A
> > DRAM:  8 GiB (effective 7.7 GiB)
> > PMIC:  RK8090 (on=0x40, off=0x00)
> > Core:  344 devices, 31 uclasses,
> >  >> which also means...
> >>
> >> https://elixir.bootlin.com/u-boot/latest/source/arch/arm/include/asm/arch-rockchip/cru.h#L35
> >> should probably be ifdef'ed
> >>
> >> which means...
> >>
> >> https://elixir.bootlin.com/u-boot/latest/source/board/firefly/roc-pc-rk3399/roc-pc-rk3399.c#L64
> >> should probably also be ifdef'ed (but the config is enabled already
> >> (well... it wouldn't compile otherwsie), so I guess this is fine?).
> >
> > This code changes will not affect this feature by default its enable
> > on RK3399 boards.
> >
>
> Yes, but if you disable it, it won't compile anymore. (I'm not asking
> you to fix anything I've reported here though).
>
Ok I will check this.
> Cheers,
> Quentin
Thanks
-Anand


[PATCH v2 12/12] mailmap: Update email for Paul Burton

2024-05-16 Thread Jiaxun Yang
Paul had left MIPS a couple of years ago, his email address is
no longer valid.

Replace it with his kenrel.org email, which has been used in
kernel and QEMU, in case we still want to reach him.

Signed-off-by: Jiaxun Yang 
---
 .mailmap| 3 ++-
 board/imgtec/boston/MAINTAINERS | 2 +-
 board/imgtec/malta/MAINTAINERS  | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/.mailmap b/.mailmap
index 8049856d41c3..bb7c1c3869ab 100644
--- a/.mailmap
+++ b/.mailmap
@@ -87,7 +87,8 @@ This contributor prefers not to receive mails 
  

 Patrice Chotard  
 Patrick Delaunay  
-Paul Burton  
+Paul Burton  
+Paul Burton  
 Piyush Mehta  
 Prabhakar Kushwaha 
 Punnaiah Choudary Kalluri  

diff --git a/board/imgtec/boston/MAINTAINERS b/board/imgtec/boston/MAINTAINERS
index 12e1652858bb..b03a6487db29 100644
--- a/board/imgtec/boston/MAINTAINERS
+++ b/board/imgtec/boston/MAINTAINERS
@@ -1,5 +1,5 @@
 BOSTON BOARD
-M: Paul Burton 
+M: Paul Burton 
 S: Maintained
 F:  arch/mips/dts/boston-u-boot.dtsi
 F: board/imgtec/boston/
diff --git a/board/imgtec/malta/MAINTAINERS b/board/imgtec/malta/MAINTAINERS
index b1cf297f4fac..252c5e45ab56 100644
--- a/board/imgtec/malta/MAINTAINERS
+++ b/board/imgtec/malta/MAINTAINERS
@@ -1,5 +1,5 @@
 MALTA BOARD
-M: Paul Burton 
+M: Paul Burton 
 S: Maintained
 F: board/imgtec/malta/
 F: include/configs/malta.h

-- 
2.34.1



[PATCH v2 10/12] dts/upstream: Add Makefile for MIPS

2024-05-16 Thread Jiaxun Yang
It is required to make OF_UPSTREAM work.

Reviewed-by: Sumit Garg 
Signed-off-by: Jiaxun Yang 
---
 dts/upstream/src/mips/Makefile | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/dts/upstream/src/mips/Makefile b/dts/upstream/src/mips/Makefile
new file mode 100644
index ..9a8f6aa35846
--- /dev/null
+++ b/dts/upstream/src/mips/Makefile
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+include $(srctree)/scripts/Makefile.dts
+
+targets += $(dtb-y)
+
+# Add any required device tree compiler flags here
+DTC_FLAGS += -a 0x8
+
+PHONY += dtbs
+dtbs: $(addprefix $(obj)/, $(dtb-y))
+   @:
+
+clean-files := */*.dtb */*.dtbo

-- 
2.34.1



[PATCH v2 09/12] clk: boston: Allow to get regmap from parent device

2024-05-16 Thread Jiaxun Yang
In upstream devicetree, clk_boston is a child of syscon node
and there is no "regmap" property for clk_boston node.

Try to check parent device first to look for syscon.

Signed-off-by: Jiaxun Yang 
---
v2: Move syscon_get_regmap to probe
---
 drivers/clk/clk_boston.c | 37 +
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/drivers/clk/clk_boston.c b/drivers/clk/clk_boston.c
index 030ff7cc58ec..1985bb0ec334 100644
--- a/drivers/clk/clk_boston.c
+++ b/drivers/clk/clk_boston.c
@@ -12,6 +12,7 @@
 #include 
 
 struct clk_boston {
+   struct udevice *syscon;
struct regmap *regmap;
 };
 
@@ -58,23 +59,33 @@ const struct clk_ops clk_boston_ops = {
.get_rate = clk_boston_get_rate,
 };
 
-static int clk_boston_of_to_plat(struct udevice *dev)
+static int clk_boston_probe(struct udevice *dev)
 {
struct clk_boston *state = dev_get_plat(dev);
-   struct udevice *syscon;
-   int err;
 
-   err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
-  "regmap", );
-   if (err) {
-   pr_err("unable to find syscon device\n");
-   return err;
+   state->regmap = syscon_get_regmap(state->syscon);
+   if (IS_ERR(state->regmap)) {
+   pr_err("unable to find regmap\n");
+   return PTR_ERR(state->regmap);
}
 
-   state->regmap = syscon_get_regmap(syscon);
-   if (!state->regmap) {
-   pr_err("unable to find regmap\n");
-   return -ENODEV;
+   return 0;
+}
+
+static int clk_boston_of_to_plat(struct udevice *dev)
+{
+   struct clk_boston *state = dev_get_plat(dev);
+   int err;
+
+   if (dev->parent && device_get_uclass_id(dev->parent) == UCLASS_SYSCON) {
+   state->syscon = dev->parent;
+   } else {
+   err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
+  "regmap", >syscon);
+   if (err) {
+   pr_err("unable to find syscon device\n");
+   return err;
+   }
}
 
return 0;
@@ -92,6 +103,8 @@ U_BOOT_DRIVER(clk_boston) = {
.id = UCLASS_CLK,
.of_match = clk_boston_match,
.of_to_plat = clk_boston_of_to_plat,
+   .probe = clk_boston_probe,
.plat_auto  = sizeof(struct clk_boston),
.ops = _boston_ops,
+   .flags = DM_FLAG_PRE_RELOC,
 };

-- 
2.34.1



[PATCH v2 11/12] MIPS: boston: Migrate to OF_UPSTREAM

2024-05-16 Thread Jiaxun Yang
We can now boot with upstream devicetree.

Reviewed-by: Sumit Garg 
Signed-off-by: Jiaxun Yang 
---
 arch/mips/Kconfig|   1 +
 arch/mips/dts/Makefile   |   1 -
 arch/mips/dts/boston-u-boot.dtsi |  10 ++
 arch/mips/dts/img,boston.dts | 222 ---
 board/imgtec/boston/MAINTAINERS  |   1 +
 configs/boston32r2_defconfig |   2 +-
 configs/boston32r2el_defconfig   |   2 +-
 configs/boston32r6_defconfig |   2 +-
 configs/boston32r6el_defconfig   |   2 +-
 configs/boston64r2_defconfig |   2 +-
 configs/boston64r2el_defconfig   |   2 +-
 configs/boston64r6_defconfig |   2 +-
 configs/boston64r6el_defconfig   |   2 +-
 13 files changed, 20 insertions(+), 231 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 748b5175b2eb..733a8de4fb83 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -146,6 +146,7 @@ config TARGET_BOSTON
select SUPPORTS_CPU_MIPS64_R2
select SUPPORTS_CPU_MIPS64_R6
select SUPPORTS_LITTLE_ENDIAN
+   imply OF_UPSTREAM
imply BOOTSTD_FULL
imply CLK
imply CLK_BOSTON
diff --git a/arch/mips/dts/Makefile b/arch/mips/dts/Makefile
index 14fbce597b9e..5478dcd8d025 100644
--- a/arch/mips/dts/Makefile
+++ b/arch/mips/dts/Makefile
@@ -3,7 +3,6 @@
 dtb-$(CONFIG_TARGET_AP121) += ap121.dtb
 dtb-$(CONFIG_TARGET_AP143) += ap143.dtb
 dtb-$(CONFIG_TARGET_AP152) += ap152.dtb
-dtb-$(CONFIG_TARGET_BOSTON) += img,boston.dtb
 dtb-$(CONFIG_TARGET_MALTA) += mti,malta.dtb
 dtb-$(CONFIG_TARGET_PIC32MZDASK) += pic32mzda_sk.dtb
 dtb-$(CONFIG_TARGET_XILFPGA) += nexys4ddr.dtb
diff --git a/arch/mips/dts/boston-u-boot.dtsi b/arch/mips/dts/boston-u-boot.dtsi
new file mode 100644
index ..1b0c0a289613
--- /dev/null
+++ b/arch/mips/dts/boston-u-boot.dtsi
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+_regs {
+   compatible = "img,boston-platform-regs", "syscon", "simple-mfd";
+   bootph-all;
+};
+
+_boston {
+   bootph-all;
+};
diff --git a/arch/mips/dts/img,boston.dts b/arch/mips/dts/img,boston.dts
deleted file mode 100644
index c1a73963037d..
--- a/arch/mips/dts/img,boston.dts
+++ /dev/null
@@ -1,222 +0,0 @@
-/dts-v1/;
-
-#include 
-#include 
-#include 
-#include 
-
-/ {
-   #address-cells = <1>;
-   #size-cells = <1>;
-   compatible = "img,boston";
-
-   chosen {
-   stdout-path = 
-   };
-
-   cpus {
-   #address-cells = <1>;
-   #size-cells = <0>;
-
-   cpu@0 {
-   device_type = "cpu";
-   compatible = "img,mips";
-   reg = <0>;
-   clocks = <_boston BOSTON_CLK_CPU>;
-   };
-   };
-
-   memory@0 {
-   device_type = "memory";
-   reg = <0x 0x1000>;
-   };
-
-   gic: interrupt-controller {
-   compatible = "mti,gic";
-
-   interrupt-controller;
-   #interrupt-cells = <3>;
-
-   timer {
-   compatible = "mti,gic-timer";
-   interrupts = ;
-   clocks = <_boston BOSTON_CLK_CPU>;
-   };
-   };
-
-   pci0: pci@1000 {
-   status = "disabled";
-   compatible = "xlnx,axi-pcie-host-1.00.a";
-   device_type = "pci";
-   reg = <0x1000 0x200>;
-
-   #address-cells = <3>;
-   #size-cells = <2>;
-   #interrupt-cells = <1>;
-
-   interrupt-parent = <>;
-   interrupts = ;
-
-   ranges = <0x0200 0 0x4000
- 0x4000 0 0x4000>;
-
-   interrupt-map-mask = <0 0 0 7>;
-   interrupt-map = <0 0 0 1 _intc 0>,
-   <0 0 0 2 _intc 1>,
-   <0 0 0 3 _intc 2>,
-   <0 0 0 4 _intc 3>;
-
-   pci0_intc: interrupt-controller {
-   interrupt-controller;
-   #address-cells = <0>;
-   #interrupt-cells = <1>;
-   };
-   };
-
-   pci1: pci@1200 {
-   status = "disabled";
-   compatible = "xlnx,axi-pcie-host-1.00.a";
-   device_type = "pci";
-   reg = <0x1200 0x200>;
-
-   #address-cells = <3>;
-   #size-cells = <2>;
-   #interrupt-cells = <1>;
-
-   interrupt-parent = <>;
-   interrupts = ;
-
-   ranges = <0x0200 0 0x2000
- 0x2000 0 0x2000>;
-
-   interrupt-map-mask = <0 0 0 7>;
-   interrupt-map = <0 0 0 1 _intc 0>,
-   <0 0 0 2 _intc 1>,
-   <0 0 0 3 _intc 2>,
-   <0 0 0 4 _intc 3>;
-
-   

[PATCH v2 08/12] MIPS: boston: Provide default env vars

2024-05-16 Thread Jiaxun Yang
Provide default environment variables on image loading address
to make the board useful.

Signed-off-by: Jiaxun Yang 
---
 board/imgtec/boston/Kconfig| 4 
 board/imgtec/boston/boston.env | 9 +
 2 files changed, 13 insertions(+)

diff --git a/board/imgtec/boston/Kconfig b/board/imgtec/boston/Kconfig
index 5537788001a3..965847d9650d 100644
--- a/board/imgtec/boston/Kconfig
+++ b/board/imgtec/boston/Kconfig
@@ -9,6 +9,10 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
default "boston"
 
+
+config ENV_SOURCE_FILE
+   default "boston"
+
 config TEXT_BASE
default 0x9fc0 if 32BIT
default 0x9fc0 if 64BIT
diff --git a/board/imgtec/boston/boston.env b/board/imgtec/boston/boston.env
new file mode 100644
index ..796e0fd6bf98
--- /dev/null
+++ b/board/imgtec/boston/boston.env
@@ -0,0 +1,9 @@
+#ifdef CONFIG_64BIT
+fdt_addr_r=0x80001000
+kernel_addr_r=0x8800
+ramdisk_addr_r=0x8b00
+#else
+fdt_addr_r=0x80001000
+kernel_addr_r=0x8800
+ramdisk_addr_r=0x8b00
+#endif

-- 
2.34.1



[PATCH v2 07/12] MIPS: boston: Imply various options

2024-05-16 Thread Jiaxun Yang
This is a PC-like platform board.
Enable drivers for most on-board devices to make it useful.

Signed-off-by: Jiaxun Yang 
---
 arch/mips/Kconfig | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index eb7f3ad23762..748b5175b2eb 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -146,7 +146,34 @@ config TARGET_BOSTON
select SUPPORTS_CPU_MIPS64_R2
select SUPPORTS_CPU_MIPS64_R6
select SUPPORTS_LITTLE_ENDIAN
+   imply BOOTSTD_FULL
+   imply CLK
+   imply CLK_BOSTON
imply CMD_DM
+   imply AHCI
+   imply AHCI_PCI
+   imply CFI_FLASH
+   imply MTD_NOR_FLASH
+   imply MMC
+   imply MMC_PCI
+   imply MMC_SDHCI
+   imply MMC_SDHCI_SDMA
+   imply PCH_GBE
+   imply PCI
+   imply PCI_XILINX
+   imply PCI_INIT_R
+   imply SCSI
+   imply SCSI_AHCI
+   imply SYS_NS16550
+   imply SYSRESET
+   imply SYSRESET_CMD_POWEROFF
+   imply SYSRESET_SYSCON
+   imply USB
+   imply USB_EHCI_HCD
+   imply USB_EHCI_PCI
+   imply USB_XHCI_HCD
+   imply USB_XHCI_PCI
+   imply CMD_USB
 
 config TARGET_XILFPGA
bool "Support Imagination Xilfpga"

-- 
2.34.1



[PATCH v2 06/12] MIPS: Provide dummy acpi_table.h

2024-05-16 Thread Jiaxun Yang
Some drivers need this header.
Provide this dummy header as riscv did.

Signed-off-by: Jiaxun Yang 
---
 arch/mips/include/asm/acpi_table.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/mips/include/asm/acpi_table.h 
b/arch/mips/include/asm/acpi_table.h
new file mode 100644
index ..b4139d0ba328
--- /dev/null
+++ b/arch/mips/include/asm/acpi_table.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __ASM_ACPI_TABLE_H__
+#define __ASM_ACPI_TABLE_H__
+
+/*
+ * This file is needed by some drivers.
+ */
+
+#endif /* __ASM_ACPI_TABLE_H__ */

-- 
2.34.1



[PATCH v2 04/12] ahci: DMA addressing fixes

2024-05-16 Thread Jiaxun Yang
Ensure that we are using correct physical/virtual address for
DMA buffer write and hardware register settings.

The convention is: in ahci_ioports all pointers are virtual,
that will be converted to physical address when writing to
hardware registers or into sg/cmd_tbl.

Also fixed 64bit physical address support for dwc_ahsata, ensure
higher bits are written into registers/sg properly.

Use memalign for allocating aligned buffer in dwc_ahsata so we
don't have to do our own alignment in driver.

Signed-off-by: Jiaxun Yang 
---
 drivers/ata/ahci.c| 34 -
 drivers/ata/dwc_ahsata.c  | 44 +++
 drivers/ata/dwc_ahsata_priv.h |  2 --
 include/ahci.h|  4 ++--
 4 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index ac869296d525..21b13fedac50 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -421,7 +421,7 @@ static int ahci_fill_sg(struct ahci_uc_priv *uc_priv, u8 
port,
 
 static void ahci_fill_cmd_slot(struct ahci_ioports *pp, u32 opts)
 {
-   phys_addr_t pa = virt_to_phys((void *)pp->cmd_tbl);
+   phys_addr_t pa = virt_to_phys(pp->cmd_tbl);
 
pp->cmd_slot->opts = cpu_to_le32(opts);
pp->cmd_slot->status = 0;
@@ -450,7 +450,7 @@ static int ahci_port_start(struct ahci_uc_priv *uc_priv, u8 
port)
 {
struct ahci_ioports *pp = &(uc_priv->port[port]);
void __iomem *port_mmio = pp->port_mmio;
-   u64 dma_addr;
+   phys_addr_t dma_addr;
u32 port_status;
void __iomem *mem;
 
@@ -474,34 +474,32 @@ static int ahci_port_start(struct ahci_uc_priv *uc_priv, 
u8 port)
 * First item in chunk of DMA memory: 32-slot command table,
 * 32 bytes each in size
 */
-   pp->cmd_slot =
-   (struct ahci_cmd_hdr *)(uintptr_t)virt_to_phys((void *)mem);
-   debug("cmd_slot = %p\n", pp->cmd_slot);
-   mem += (AHCI_CMD_SLOT_SZ + 224);
+   pp->cmd_slot = (struct ahci_cmd_hdr *)mem;
+   mem += AHCI_CMD_SLOT_SZ * AHCI_MAX_CMD_SLOT;
 
/*
 * Second item: Received-FIS area
 */
-   pp->rx_fis = virt_to_phys((void *)mem);
+   pp->rx_fis = mem;
mem += AHCI_RX_FIS_SZ;
 
/*
 * Third item: data area for storing a single command
 * and its scatter-gather table
 */
-   pp->cmd_tbl = virt_to_phys((void *)mem);
-   debug("cmd_tbl_dma = %lx\n", pp->cmd_tbl);
+   pp->cmd_tbl = mem;
 
mem += AHCI_CMD_TBL_HDR;
-   pp->cmd_tbl_sg =
-   (struct ahci_sg *)(uintptr_t)virt_to_phys((void *)mem);
-
-   dma_addr = (ulong)pp->cmd_slot;
-   writel_with_flush(dma_addr, port_mmio + PORT_LST_ADDR);
-   writel_with_flush(dma_addr >> 32, port_mmio + PORT_LST_ADDR_HI);
-   dma_addr = (ulong)pp->rx_fis;
-   writel_with_flush(dma_addr, port_mmio + PORT_FIS_ADDR);
-   writel_with_flush(dma_addr >> 32, port_mmio + PORT_FIS_ADDR_HI);
+   pp->cmd_tbl_sg = (struct ahci_sg *)(mem);
+
+   dma_addr = virt_to_phys(pp->cmd_slot);
+   debug("cmd_slot_dma = 0x%08llx\n", (u64)dma_addr);
+   writel_with_flush(lower_32_bits(dma_addr), port_mmio + PORT_LST_ADDR);
+   writel_with_flush(upper_32_bits(dma_addr), port_mmio + 
PORT_LST_ADDR_HI);
+   dma_addr = virt_to_phys(pp->rx_fis);
+   debug("rx_fis_dma = 0x%08llx\n", (u64)dma_addr);
+   writel_with_flush(lower_32_bits(dma_addr), port_mmio + PORT_FIS_ADDR);
+   writel_with_flush(upper_32_bits(dma_addr), port_mmio + 
PORT_FIS_ADDR_HI);
 
 #ifdef CONFIG_SUNXI_AHCI
sunxi_dma_init(port_mmio);
diff --git a/drivers/ata/dwc_ahsata.c b/drivers/ata/dwc_ahsata.c
index a29d641343ed..c2cde48c0b55 100644
--- a/drivers/ata/dwc_ahsata.c
+++ b/drivers/ata/dwc_ahsata.c
@@ -329,6 +329,7 @@ static int ahci_fill_sg(struct ahci_uc_priv *uc_priv, u8 
port,
 {
struct ahci_ioports *pp = _priv->port[port];
struct ahci_sg *ahci_sg = pp->cmd_tbl_sg;
+   phys_addr_t pa = virt_to_phys(buf);
u32 sg_count, max_bytes;
int i;
 
@@ -340,9 +341,8 @@ static int ahci_fill_sg(struct ahci_uc_priv *uc_priv, u8 
port,
}
 
for (i = 0; i < sg_count; i++) {
-   ahci_sg->addr =
-   cpu_to_le32((u32)buf + i * max_bytes);
-   ahci_sg->addr_hi = 0;
+   ahci_sg->addr = cpu_to_le32(lower_32_bits(pa));
+   ahci_sg->addr_hi = cpu_to_le32(upper_32_bits(pa));
ahci_sg->flags_size = cpu_to_le32(0x3f &
(buf_len < max_bytes
? (buf_len - 1)
@@ -358,14 +358,14 @@ static void ahci_fill_cmd_slot(struct ahci_ioports *pp, 
u32 cmd_slot, u32 opts)
 {
struct ahci_cmd_hdr *cmd_hdr = (struct ahci_cmd_hdr *)(pp->cmd_slot +
AHCI_CMD_SLOT_SZ * cmd_slot);
+   phys_addr_t pa = 

[PATCH v2 05/12] ahci: dwc_ahsata: Generalize the driver

2024-05-16 Thread Jiaxun Yang
Remove hard dependencies to arch headers, get clock from clk
subsystem if arch clock function is not available, align
compatible strings with devicetree binding.

No functional change on existing platforms, just get it build
on other platforms.

Signed-off-by: Jiaxun Yang 
---
 drivers/ata/dwc_ahsata.c | 38 --
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/drivers/ata/dwc_ahsata.c b/drivers/ata/dwc_ahsata.c
index c2cde48c0b55..27c24228ef89 100644
--- a/drivers/ata/dwc_ahsata.c
+++ b/drivers/ata/dwc_ahsata.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -18,9 +19,11 @@
 #include 
 #include 
 #include 
+#if IS_ENABLED(CONFIG_ARCH_MX5) || IS_ENABLED(CONFIG_ARCH_MX6)
 #include 
 #include 
 #include 
+#endif
 #include 
 #include 
 #include 
@@ -115,13 +118,12 @@ static int ahci_setup_oobr(struct ahci_uc_priv *uc_priv, 
int clk)
return 0;
 }
 
-static int ahci_host_init(struct ahci_uc_priv *uc_priv)
+static int ahci_host_init(struct ahci_uc_priv *uc_priv, int clk)
 {
u32 tmp, cap_save, num_ports;
int i, j, timeout = 1000;
struct sata_port_regs *port_mmio = NULL;
struct sata_host_regs *host_mmio = uc_priv->mmio_base;
-   int clk = mxc_get_clock(MXC_SATA_CLK);
 
cap_save = readl(_mmio->cap);
cap_save |= SATA_HOST_CAP_SSS;
@@ -909,17 +911,41 @@ int dwc_ahsata_scan(struct udevice *dev)
 int dwc_ahsata_probe(struct udevice *dev)
 {
struct ahci_uc_priv *uc_priv = dev_get_uclass_priv(dev);
+   struct clk_bulk clk_bulk __maybe_unused;
+   struct clk clk __maybe_unused;
+   int sataclk;
int ret;
 
-#if defined(CONFIG_MX6)
+#if IS_ENABLED(CONFIG_MX6)
setup_sata();
 #endif
+#if IS_ENABLED(CONFIG_MX5) || IS_ENABLED(CONFIG_MX6)
+   sataclk = mxc_get_clock(MXC_SATA_CLK);
+#else
+   ret = clk_get_bulk(dev, _bulk);
+   if (ret)
+   return ret;
+
+   ret = clk_enable_bulk(_bulk);
+   if (ret)
+   return ret;
+
+   ret = clk_get_by_name(dev, "sata", );
+   if (ret)
+   return ret;
+
+   sataclk = clk_get_rate();
+#endif
+   if (IS_ERR_VALUE(sataclk)) {
+   log_err("Unable to get SATA clock rate\n");
+   return -EINVAL;
+   }
uc_priv->host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | ATA_FLAG_NO_ATAPI;
uc_priv->mmio_base = dev_read_addr_ptr(dev);
 
/* initialize adapter */
-   ret = ahci_host_init(uc_priv);
+   ret = ahci_host_init(uc_priv, sataclk);
if (ret)
return ret;
 
@@ -961,7 +987,6 @@ U_BOOT_DRIVER(dwc_ahsata_blk) = {
.ops= _ahsata_blk_ops,
 };
 
-#if CONFIG_IS_ENABLED(DWC_AHSATA_AHCI)
 struct ahci_ops dwc_ahsata_ahci_ops = {
.port_status = dwc_ahsata_port_status,
.reset   = dwc_ahsata_bus_reset,
@@ -969,7 +994,9 @@ struct ahci_ops dwc_ahsata_ahci_ops = {
 };
 
 static const struct udevice_id dwc_ahsata_ahci_ids[] = {
+   { .compatible = "fsl,imx53-ahci" },
{ .compatible = "fsl,imx6q-ahci" },
+   { .compatible = "fsl,imx6qp-ahci" },
{ }
 };
 
@@ -980,4 +1007,3 @@ U_BOOT_DRIVER(dwc_ahsata_ahci) = {
.ops  = _ahsata_ahci_ops,
.probe= dwc_ahsata_probe,
 };
-#endif

-- 
2.34.1



[PATCH v2 03/12] pci: Enable PCI_MAP_SYSTEM_MEMORY when ARCH_MAP_SYSMEM is not set

2024-05-16 Thread Jiaxun Yang
For MIPS we are always looking gd->dram in virtual address so
PCI_MAP_SYSTEM_MEMORY should always be enabled.

If in future we ever want to make it physical we have to set
ARCH_MAP_SYSMEM.

Signed-off-by: Jiaxun Yang 
---
 drivers/pci/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 289d1deb38b6..14f6067fa29b 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -67,6 +67,7 @@ config PCI_CONFIG_HOST_BRIDGE
 config PCI_MAP_SYSTEM_MEMORY
bool "Map local system memory from a virtual base address"
depends on MIPS
+   default y if !ARCH_MAP_SYSMEM
help
  Say Y if base address of system memory is being used as a virtual 
address
  instead of a physical address (e.g. on MIPS). The PCI core will then 
remap

-- 
2.34.1



[PATCH v2 02/12] pci: auto: Reduce bridge mem alignment boundary for boston

2024-05-16 Thread Jiaxun Yang
Boston has a very limited memory range for PCI controllers, where
1MB can't easily fit into it.

Make alignment boundary of PCI memory resource allocation a Kconfig
option and default to 0x1 for boston.

Signed-off-by: Jiaxun Yang 
---
 drivers/pci/Kconfig|  9 +
 drivers/pci/pci_auto.c | 16 
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 8d02ab82ad9f..289d1deb38b6 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -75,6 +75,15 @@ config PCI_MAP_SYSTEM_MEMORY
  This should only be required on MIPS where CFG_SYS_SDRAM_BASE is still
  being used as virtual address.
 
+config PCI_BRIDGE_MEM_ALIGNMENT
+   hex "Alignment boundary of PCI memory resource allocation"
+   default 0x1 if TARGET_BOSTON
+   default 0x10
+   help
+ Specify a boundary for alignment of PCI memory resource allocation,
+ this is normally 0x10 (1MB) but can be reduced to accommodate
+ hardware with tight bridge range if hardware allows.
+
 config PCI_SRIOV
bool "Enable Single Root I/O Virtualization support for PCI"
help
diff --git a/drivers/pci/pci_auto.c b/drivers/pci/pci_auto.c
index 90f818864457..b2c76b25801a 100644
--- a/drivers/pci/pci_auto.c
+++ b/drivers/pci/pci_auto.c
@@ -372,8 +372,8 @@ void dm_pciauto_prescan_setup_bridge(struct udevice *dev, 
int sub_bus)
dm_pci_write_config8(dev, PCI_SUBORDINATE_BUS, 0xff);
 
if (pci_mem) {
-   /* Round memory allocator to 1MB boundary */
-   pciauto_region_align(pci_mem, 0x10);
+   /* Round memory allocator */
+   pciauto_region_align(pci_mem, CONFIG_PCI_BRIDGE_MEM_ALIGNMENT);
 
/*
 * Set up memory and I/O filter limits, assume 32-bit
@@ -387,8 +387,8 @@ void dm_pciauto_prescan_setup_bridge(struct udevice *dev, 
int sub_bus)
}
 
if (pci_prefetch) {
-   /* Round memory allocator to 1MB boundary */
-   pciauto_region_align(pci_prefetch, 0x10);
+   /* Round memory allocator */
+   pciauto_region_align(pci_prefetch, 
CONFIG_PCI_BRIDGE_MEM_ALIGNMENT);
 
/*
 * Set up memory and I/O filter limits, assume 32-bit
@@ -465,8 +465,8 @@ void dm_pciauto_postscan_setup_bridge(struct udevice *dev, 
int sub_bus)
dm_pci_write_config8(dev, PCI_SUBORDINATE_BUS, sub_bus - dev_seq(ctlr));
 
if (pci_mem) {
-   /* Round memory allocator to 1MB boundary */
-   pciauto_region_align(pci_mem, 0x10);
+   /* Round memory allocator */
+   pciauto_region_align(pci_mem, CONFIG_PCI_BRIDGE_MEM_ALIGNMENT);
 
dm_pci_write_config16(dev, PCI_MEMORY_LIMIT,
  ((pci_mem->bus_lower - 1) >> 16) &
@@ -480,8 +480,8 @@ void dm_pciauto_postscan_setup_bridge(struct udevice *dev, 
int sub_bus)
 _64);
prefechable_64 &= PCI_PREF_RANGE_TYPE_MASK;
 
-   /* Round memory allocator to 1MB boundary */
-   pciauto_region_align(pci_prefetch, 0x10);
+   /* Round memory allocator */
+   pciauto_region_align(pci_prefetch, 
CONFIG_PCI_BRIDGE_MEM_ALIGNMENT);
 
dm_pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT,
  (((pci_prefetch->bus_lower - 1) >> 16) &

-- 
2.34.1



[PATCH v2 01/12] pci: xilinx: Handle size of ecam region properly

2024-05-16 Thread Jiaxun Yang
Probe size of ecam from devicetree properly and cap accessible
bus number accorading to ecam region size to ensure we don't go
beyond hardware address space.

Also disable all interrupts to ensure errors are handled silently.

Signed-off-by: Jiaxun Yang 
---
 drivers/pci/pcie_xilinx.c | 53 +++
 1 file changed, 40 insertions(+), 13 deletions(-)

diff --git a/drivers/pci/pcie_xilinx.c b/drivers/pci/pcie_xilinx.c
index a674ab04beee..63058e8e7c5d 100644
--- a/drivers/pci/pcie_xilinx.c
+++ b/drivers/pci/pcie_xilinx.c
@@ -18,14 +18,19 @@
  */
 struct xilinx_pcie {
void *cfg_base;
+   pci_size_t size;
+   int first_busno;
 };
 
 /* Register definitions */
-#define XILINX_PCIE_REG_PSCR   0x144
-#define XILINX_PCIE_REG_PSCR_LNKUP BIT(11)
-#define XILINX_PCIE_REG_RPSC   0x148
-#define XILINX_PCIE_REG_RPSC_BEN   BIT(0)
-
+#define XILINX_PCIE_REG_BRIDGE_INFO0x130
+#define  XILINX_PCIE_REG_BRIDGE_INFO_ECAMSZ_SHIFT  16
+#define  XILINX_PCIE_REG_BRIDGE_INFO_ECAMSZ_MASK   (0x7 << 16)
+#define XILINX_PCIE_REG_INT_MASK   0x13c
+#define XILINX_PCIE_REG_PSCR   0x144
+#define  XILINX_PCIE_REG_PSCR_LNKUPBIT(11)
+#define XILINX_PCIE_REG_RPSC   0x148
+#define  XILINX_PCIE_REG_RPSC_BEN  BIT(0)
 /**
  * pcie_xilinx_link_up() - Check whether the PCIe link is up
  * @pcie: Pointer to the PCI controller state
@@ -61,14 +66,18 @@ static int pcie_xilinx_config_address(const struct udevice 
*udev, pci_dev_t bdf,
  uint offset, void **paddress)
 {
struct xilinx_pcie *pcie = dev_get_priv(udev);
-   unsigned int bus = PCI_BUS(bdf);
+   unsigned int bus = PCI_BUS(bdf) - pcie->first_busno;
unsigned int dev = PCI_DEV(bdf);
unsigned int func = PCI_FUNC(bdf);
+   int num_buses = DIV_ROUND_UP(pcie->size, 1 << 16);
void *addr;
 
if ((bus > 0) && !pcie_xilinx_link_up(pcie))
return -ENODEV;
 
+   if (bus > num_buses)
+   return -ENODEV;
+
/*
 * Busses 0 (host-PCIe bridge) & 1 (its immediate child) are
 * limited to a single device each.
@@ -142,20 +151,37 @@ static int pcie_xilinx_of_to_plat(struct udevice *dev)
struct xilinx_pcie *pcie = dev_get_priv(dev);
fdt_addr_t addr;
fdt_size_t size;
-   u32 rpsc;
 
addr = dev_read_addr_size(dev, );
if (addr == FDT_ADDR_T_NONE)
return -EINVAL;
 
-   pcie->cfg_base = devm_ioremap(dev, addr, size);
-   if (IS_ERR(pcie->cfg_base))
-   return PTR_ERR(pcie->cfg_base);
+   pcie->cfg_base = map_physmem(addr, size, MAP_NOCACHE);
+   if (!pcie->cfg_base)
+   return -ENOMEM;
+   pcie->size = size;
+   return 0;
+}
 
-   /* Enable the Bridge enable bit */
-   rpsc = __raw_readl(pcie->cfg_base + XILINX_PCIE_REG_RPSC);
+static int pci_xilinx_probe(struct udevice *dev)
+{
+   struct xilinx_pcie *pcie = dev_get_priv(dev);
+   u32 rpsc;
+   int num_buses = DIV_ROUND_UP(pcie->size, 1 << 16);
+
+   pcie->first_busno = dev_seq(dev);
+
+   /* Disable all interrupts */
+   writel(0, pcie->cfg_base + XILINX_PCIE_REG_INT_MASK);
+
+   /* Enable the bridge */
+   rpsc = readl(pcie->cfg_base + XILINX_PCIE_REG_RPSC);
rpsc |= XILINX_PCIE_REG_RPSC_BEN;
-   __raw_writel(rpsc, pcie->cfg_base + XILINX_PCIE_REG_RPSC);
+   writel(rpsc, pcie->cfg_base + XILINX_PCIE_REG_RPSC);
+
+   /* Enable access to all possible subordinate buses */
+   writel((0 << 0) | (1 << 8) | (num_buses << 16),
+  pcie->cfg_base + PCI_PRIMARY_BUS);
 
return 0;
 }
@@ -176,5 +202,6 @@ U_BOOT_DRIVER(pcie_xilinx) = {
.of_match   = pcie_xilinx_ids,
.ops= _xilinx_ops,
.of_to_plat = pcie_xilinx_of_to_plat,
+   .probe  = pci_xilinx_probe,
.priv_auto  = sizeof(struct xilinx_pcie),
 };

-- 
2.34.1



[PATCH v2 00/12] MIPS: Boston: Various enhancements

2024-05-16 Thread Jiaxun Yang
Hi all,

This is a huge series which promoted MIPS/Boston target into a
usable state, with fixes to drivers and general framework issues
I found in this process.

I also converted the target to OF_UPSTREAM.

This target is covered by QEMU, to test on QEMU:
```
make boston64r6el_defconfig
make
qemu-system-mips64el -M boston -cpu I6500 -bios ./u-boot.bin -nographic
```

This is my first u-boot contribution, please kindly advise if you
have any comments.

Thanks

Signed-off-by: Jiaxun Yang 
---
Changes in v2:
- Drop "[PATCH 09/13] syscon: Probe device first in syscon_get_regmap"
  in flavour of fixing the driver device life cycle (Jonas)
- Link to v1: 
https://lore.kernel.org/r/20240513-boston-v1-0-fac969384...@flygoat.com

---
Jiaxun Yang (12):
  pci: xilinx: Handle size of ecam region properly
  pci: auto: Reduce bridge mem alignment boundary for boston
  pci: Enable PCI_MAP_SYSTEM_MEMORY when ARCH_MAP_SYSMEM is not set
  ahci: DMA addressing fixes
  ahci: dwc_ahsata: Generalize the driver
  MIPS: Provide dummy acpi_table.h
  MIPS: boston: Imply various options
  MIPS: boston: Provide default env vars
  clk: boston: Allow to get regmap from parent device
  dts/upstream: Add Makefile for MIPS
  MIPS: boston: Migrate to OF_UPSTREAM
  mailmap: Update email for Paul Burton

 .mailmap   |   3 +-
 arch/mips/Kconfig  |  28 +
 arch/mips/dts/Makefile |   1 -
 arch/mips/dts/boston-u-boot.dtsi   |  10 ++
 arch/mips/dts/img,boston.dts   | 222 -
 arch/mips/include/asm/acpi_table.h |  10 ++
 board/imgtec/boston/Kconfig|   4 +
 board/imgtec/boston/MAINTAINERS|   3 +-
 board/imgtec/boston/boston.env |   9 ++
 board/imgtec/malta/MAINTAINERS |   2 +-
 configs/boston32r2_defconfig   |   2 +-
 configs/boston32r2el_defconfig |   2 +-
 configs/boston32r6_defconfig   |   2 +-
 configs/boston32r6el_defconfig |   2 +-
 configs/boston64r2_defconfig   |   2 +-
 configs/boston64r2el_defconfig |   2 +-
 configs/boston64r6_defconfig   |   2 +-
 configs/boston64r6el_defconfig |   2 +-
 drivers/ata/ahci.c |  34 +++---
 drivers/ata/dwc_ahsata.c   |  82 +-
 drivers/ata/dwc_ahsata_priv.h  |   2 -
 drivers/clk/clk_boston.c   |  37 +--
 drivers/pci/Kconfig|  10 ++
 drivers/pci/pci_auto.c |  16 +--
 drivers/pci/pcie_xilinx.c  |  53 ++---
 dts/upstream/src/mips/Makefile |  14 +++
 include/ahci.h |   4 +-
 27 files changed, 245 insertions(+), 315 deletions(-)
---
base-commit: c8ffd1356d42223cbb8c86280a083cc3c93e6426
change-id: 20240513-boston-45ef6edc219f

Best regards,
-- 
Jiaxun Yang 



Re: [v2][PATCH 0/2] MAINTAINERS: updates for fastboot and USB gadget

2024-05-16 Thread Mattijs Korpershoek
Hi,

On Thu, 16 May 2024 11:15:40 +0200, Mattijs Korpershoek wrote:
> I've noticed that I'm missing quite some USB gadget patches such as [1]
> since I'm not always cc'ed.
> 
> With Marek, we agreed on the following split:
> - I take care of USB gadget side
> - Marek handles the rest
> 
> [...]

Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu 
(u-boot-dfu)

[1/2] MAINTAINERS: add tree link for fastboot
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/5738a44f88d65c2847ad204e6ba9f4a5f12f7d4e
[2/2] MAINTAINERS: add USB gadget regex to u-boot-dfu tree
  
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/efbc11ccef89030ed54b7368458eeaf9ec687c77

--
Mattijs


Re: [v2][PATCH 2/2] MAINTAINERS: add USB gadget regex to u-boot-dfu tree

2024-05-16 Thread Mattijs Korpershoek
Hi Marek,

Thank you for the review.

On jeu., mai 16, 2024 at 12:23, Marek Vasut  wrote:

> On 5/16/24 11:15 AM, Mattijs Korpershoek wrote:
>> We try to split work with Marek on USB as following:
>> - Mattijs handles USB gadget
>> - Marek handles the rest of USB
>> 
>> Add additional gadget patterns to the maintainers file so that I
>> get cc'ed more often on USB gadget patches.
>> 
>> Signed-off-by: Mattijs Korpershoek 
>
> Acked-by: Marek Vasut 
>
> You can try and look at the N: instead of F: (see top of MAINTAINERS for 
> meaning), but that should be separate clean up patch.

Noted, will review the differences and consider a later clean up patch!


Re: [PATCH] imx: hab: add documentation about the required keys/certs

2024-05-16 Thread Claudius Heine

Hi Rasmus,

On 2024-05-16 11:50 am, Rasmus Villemoes wrote:

On 16/05/2024 10.25, Claudius Heine wrote:

Hi Tim and Marek,

On 2024-05-16 12:46 am, Tim Harvey wrote:

On Tue, May 14, 2024 at 11:50 AM Tim Harvey 
wrote:

On Sun, May 12, 2024 at 10:08 PM Marek Vasut  wrote:

On 5/8/24 9:23 AM, Claudius Heine wrote:

On 2024-05-07 3:28 pm, Marek Vasut wrote:

It would be good to mention the DT properties which govern the crypto
material paths -- nxp,srk-table, nxp,csf-crt, nxp,img-crt --
somewhere
around this sentence.


This is something that should be documented with the changes where
that
code was added, IMO. I only documented here what I found out and have
used myself, I haven't used those.

I would be interested in reading how to best overwrite those paths and
the image structured from board u-boot.dtsi files myself.

If you want to can pickup my patch and integrate it into your
series and
extend it.


I'll keep it in mind for V3.


Hi Marek,

The documentation patch here by Claudius does resolve my issues
discussed in the other thread and I can confirm symlinks work fine so
I think something like the following should be added:

CST_DIR=/usr/src/cst-3.3.2/
ln -s $CST_DIR/crts .
ln -s $CST_DIR/keys .


`keys` and `crts` are very short and generic names, and putting them
into the build directory might cause issues at some point. But I would
not be against putting them into a sub directory (`imx-hab/{keys,crts}`?).


It is probably useful to be aware of the quality of the cst code. For
reference, I quote get_key_file()

int32_t get_key_file(const char* cert_file, char* key_file)
{
 /* Algorithm to locate key file from given cert file  */
 /* for now just assume the key to present in the  */
 /* same folder as cert file. The crt in the name will */
 /* will be replaced with key */
 char * folder;
 int32_t i = strlen(cert_file);  /**< Index into key filename,
initialized
  to filename length */

 strcpy(key_file, cert_file);
 key_file[i] = 0;

 key_file[i-5] = 'y';
 key_file[i-6] = 'e';
 key_file[i-7] = 'k';

 /* Search for folder name "certs" in the file and replace it with
"keys" */
 /* Keys are found in "keys" folder and certs are in "certs" folder
 */

 folder = strstr(key_file, "crts");
 if(folder)
 {
 folder[0] = 'k';
 folder[1] = 'e';
 folder[2] = 'y';
 folder[3] = 's';
 }
 return CAL_SUCCESS;
}

Ignoring the inconsistencies in the comments, obviously there are a lot
of implicit assumptions on file names and paths. First, the assumption
that the filename of they key corresponding to the certificate can be
obtained by replacing [-7:-5] by "key". Second, and much more egregious,
is the use of strstr() on key_file searching for "crts", and just
blindly replacing the first such with "keys", and ignoring it if not
found. So if that string appears anywhere in the path (say, my homedir
is /home/dcrts/ and I have the key material somewhere below that) this
will replace the wrong occurrence (and look in /home/dkeys/ ).

And of course it was unthinkable that this could have been written using
the much shorter memcpy(..., "keys", 4) so that one could actually `git
grep 'keys'` and figure out what was going on.


Exactly. I had the pleasure to read cst code a bit as well to figure out 
some issue. This is also a reason I suggested to just set the base path 
to the CST/HAB files instead of setting the individual paths to the 
keys/certs in the hope that this is a more robust way for cst to find 
its implicitly required files.


regards,
Claudius

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


Re: [v2][PATCH 2/2] MAINTAINERS: add USB gadget regex to u-boot-dfu tree

2024-05-16 Thread Marek Vasut

On 5/16/24 11:15 AM, Mattijs Korpershoek wrote:

We try to split work with Marek on USB as following:
- Mattijs handles USB gadget
- Marek handles the rest of USB

Add additional gadget patterns to the maintainers file so that I
get cc'ed more often on USB gadget patches.

Signed-off-by: Mattijs Korpershoek 


Acked-by: Marek Vasut 

You can try and look at the N: instead of F: (see top of MAINTAINERS for 
meaning), but that should be separate clean up patch.


AW: [NFS] fetching kernel via nfs

2024-05-16 Thread Johannes Kirchmair - SKIDATA
Hello Sébastien,

missed that because was testing on v2024.4.
And did not think about looking at master branch because it seemed to be broken 
for quite a while.

Anyways, thanks for the quick response and for fixing this thing.

Best regards

-Ursprüngliche Nachricht-
Von: Sébastien Szymanski 
Gesendet: Mittwoch, 15. Mai 2024 18:53
An: Johannes Kirchmair - SKIDATA ; 
u-boot@lists.denx.de
Cc: joe.hershber...@ni.com; rfried@gmail.com
Betreff: Re: [NFS] fetching kernel via nfs

[Sie erhalten nicht häufig E-Mails von sebastien.szyman...@armadeus.com. 
Weitere Informationen, warum dies wichtig ist, finden Sie unter 
https://aka.ms/LearnAboutSenderIdentification ]

EXTERNAL EMAIL


Hello,

On 5/15/24 14:40, Johannes Kirchmair - SKIDATA wrote:
> Dear u-boot people,
>
> I encountered some problems trying to fetch the Linux kernel via nfs (v3).
> One problem was that the nfs file lookup always returned NFS3ERR_BADHANDLE.

I have fixed this. See:

https://source.denx.de/u-boot/u-boot/-/commit/d2986567b27dae764b19886bcda1d24b7c41d075

Regards,

> This is due to the following line in nfs_lookup_req() function (net/nfs.c):
>
>   len = (uint32_t *)p - (uint32_t *)&(data[0]);
>   rpc_req(PROG_NFS, NFS_LOOKUP, data, len);
>   } else {  /* NFS_V3 */
>   *p++ = htonl(NFS_FHSIZE);   /* Dir handle length */
> <=  this line
>   memcpy(p, dirfh, NFS_FHSIZE);
>   p += (NFS_FHSIZE / 4);
>   *p++ = htonl(fnamelen);
>
> In the NFS_V3 case we add the dir file handle  size to data and then the dir 
> file handle.
> IUC, this is not correct here because dirfh includes already the size of the 
> handle in the first 4 bytes.
> Feel free to correct me if I am wrong.
>
> As a result, if I remove the line "*p++ = htonl(NFS_FHSIZE);", it works fine.
>
> Don't have an in deps understanding of nfs, so I am not sure if this is the 
> root problem here.
>
> Best regards Johannes

--
Sébastien Szymanski, Armadeus Systems
Software engineer



Re: [PATCH v1 9/9] rockchip: RK3588: Enable display cpuinfo support on all boards

2024-05-16 Thread Quentin Schulz

Hi Anand,

On 5/16/24 12:12 PM, Anand Moon wrote:

Hi Quentin

On Thu, 16 May 2024 at 14:52, Quentin Schulz  wrote:


Hi Anand,

This is patch 9/9 but somehow I didn't receive any other patch, nor did
the mailing list? c.f.
https://lists.denx.de/pipermail/u-boot/2024-May/thread.html and
https://lore.kernel.org/u-boot/. Are you registered on the ML?



Thanks for your  review comments.

Something went wrong with git sendmail,
Your message have not reached my email client (gmail)



A mail server rejected the mail to edgeble.ai domain (both you and 
Jagan) /me shrugs.



On 5/16/24 10:59 AM, Anand Moon wrote:

Imply DISPLAY_CPUINFO Kconfig options to support on all RK3588s and
RK3588 boards, Its used to determine the reset cause of the board.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
   arch/arm/mach-rockchip/Kconfig   | 1 +
   configs/coolpi-4b-rk3588s_defconfig  | 1 -
   configs/coolpi-cm5-evb-rk3588_defconfig  | 1 -
   configs/evb-rk3588_defconfig | 1 -
   configs/generic-rk3588_defconfig | 1 -
   configs/jaguar-rk3588_defconfig  | 1 -
   configs/nanopc-t6-rk3588_defconfig   | 1 -
   configs/neu6a-io-rk3588_defconfig| 1 -
   configs/neu6b-io-rk3588_defconfig| 1 -
   configs/orangepi-5-plus-rk3588_defconfig | 1 -
   configs/orangepi-5-rk3588s_defconfig | 1 -
   configs/quartzpro64-rk3588_defconfig | 1 -
   configs/rock5a-rk3588s_defconfig | 1 -
   configs/rock5b-rk3588_defconfig  | 1 -
   configs/toybrick-rk3588_defconfig| 1 -
   configs/turing-rk1-rk3588_defconfig  | 1 -
   16 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index 2e9c71138e..1b5cc34f99 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -366,6 +366,7 @@ config ROCKCHIP_RK3588
   imply SCMI_FIRMWARE
   imply SPL_ATF_NO_PLATFORM_PARAM if SPL_ATF
   imply SPL_MMC_HS200_SUPPORT if SPL_MMC && MMC_HS200_SUPPORT
+ imply DISPLAY_CPUINFO


This is unnecessary, it's already defaulting to y if building for ARM
boards: https://elixir.bootlin.com/u-boot/latest/source/common/Kconfig#L596


See below...

I also don't think this is SO useful that we need to enable it on all
rk3588 boards? But also, doesn't hurt, so... whatever I guess :) ?

While looking at the code, I think we can remove the ifdef in
https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-rockchip/cpu-info.c#L47
because this file is anyway only compiled when CONFIG_DISPLAY_CPUINFO is
set, c.f.


Oops I missed this changes, my bad
I will dop my changes over here.


https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-rockchip/Makefile#L30


On Rockchip SoC CONFIG_DISPLAY_CPUINFO is been disable on most of the
configs files.

-# CONFIG_DISPLAY_CPUINFO is not set

My changes are related to determine the reset cause of the board and
display the results.
its only enable on selected SoC hence I have to used this logic.



It's enabled for all Aarch64/Aarch32 SoCs by default. People explicitly 
disabled them in their own defconfig, either because the first person 
who added a board based on rk3588 didn't know or didn't care and 
everybody just copied it as a base, or because they don't care about 
it/don't want it.


In any case, you only need to change the defconfigs, nothing else.


U-Boot 2024.07-rc2-00397-g0370324feb-dirty (May 16 2024 - 13:11:14 +0530)

SoC: Rockchip rk3568
Reset cause: POR <---
Model: Radxa ROCK3 Model A
DRAM:  8 GiB (effective 7.7 GiB)
PMIC:  RK8090 (on=0x40, off=0x00)
Core:  344 devices, 31 uclasses,
 >> which also means...


https://elixir.bootlin.com/u-boot/latest/source/arch/arm/include/asm/arch-rockchip/cru.h#L35
should probably be ifdef'ed

which means...

https://elixir.bootlin.com/u-boot/latest/source/board/firefly/roc-pc-rk3399/roc-pc-rk3399.c#L64
should probably also be ifdef'ed (but the config is enabled already
(well... it wouldn't compile otherwsie), so I guess this is fine?).


This code changes will not affect this feature by default its enable
on RK3399 boards.



Yes, but if you disable it, it won't compile anymore. (I'm not asking 
you to fix anything I've reported here though).


Cheers,
Quentin


Re: [PATCH v3] tpm: display warning if using gpio reset with TPM

2024-05-16 Thread Miquel Raynal


> > > Signed-off-by: Jorge Ramirez-Ortiz   
> > 
> > You cannot send your SoB like this. SoB means you are carrying some
> > code which complies with the license, etc.
> > 
> > Either you were part of the original writing and want to be credited
> > for that (you can be the author and first SoB, or suggest Tim to use
> > Co-developed-by). Or you reviewed the change (Reviewed-by), you tested
> > the change (Tested-by), or you are maintainer/responsible for some part
> > that is touched and you agree with the change (Acked-by).  
> 
> right, however there is some lenience in the process: some projects accept
> the signed off, some others add the acked or reviewed and so on...
> 
> but I agree with you and I certainly do not need/want/expect to be
> credited for this work. it is all good on my end :)
> 
> > 
> > Thanks,
> > Miquèl  
> 
> btw you could have simply ignored my note btw : notice the "if needed"
> part in my response. for reference, I noticed my name in CC, checked the
> change, thought it was a good idea and tried to move it a long - just
> chose the wrong tag for sure...

And this is likely a good habit :) But now you need to send your
Reviewed-by because these tags are usually collected by the tools. If
you don't write it properly, there are very little chances it will
ever be picked-up.

Thanks,
Miquèl


Re: [PATCH v1 9/9] rockchip: RK3588: Enable display cpuinfo support on all boards

2024-05-16 Thread Anand Moon
Hi Quentin

On Thu, 16 May 2024 at 14:52, Quentin Schulz  wrote:
>
> Hi Anand,
>
> This is patch 9/9 but somehow I didn't receive any other patch, nor did
> the mailing list? c.f.
> https://lists.denx.de/pipermail/u-boot/2024-May/thread.html and
> https://lore.kernel.org/u-boot/. Are you registered on the ML?
>

Thanks for your  review comments.

Something went wrong with git sendmail,
Your message have not reached my email client (gmail)

> On 5/16/24 10:59 AM, Anand Moon wrote:
> > Imply DISPLAY_CPUINFO Kconfig options to support on all RK3588s and
> > RK3588 boards, Its used to determine the reset cause of the board.
> >
> > Cc: Jagan Teki 
> > Signed-off-by: Anand Moon 
> > ---
> >   arch/arm/mach-rockchip/Kconfig   | 1 +
> >   configs/coolpi-4b-rk3588s_defconfig  | 1 -
> >   configs/coolpi-cm5-evb-rk3588_defconfig  | 1 -
> >   configs/evb-rk3588_defconfig | 1 -
> >   configs/generic-rk3588_defconfig | 1 -
> >   configs/jaguar-rk3588_defconfig  | 1 -
> >   configs/nanopc-t6-rk3588_defconfig   | 1 -
> >   configs/neu6a-io-rk3588_defconfig| 1 -
> >   configs/neu6b-io-rk3588_defconfig| 1 -
> >   configs/orangepi-5-plus-rk3588_defconfig | 1 -
> >   configs/orangepi-5-rk3588s_defconfig | 1 -
> >   configs/quartzpro64-rk3588_defconfig | 1 -
> >   configs/rock5a-rk3588s_defconfig | 1 -
> >   configs/rock5b-rk3588_defconfig  | 1 -
> >   configs/toybrick-rk3588_defconfig| 1 -
> >   configs/turing-rk1-rk3588_defconfig  | 1 -
> >   16 files changed, 1 insertion(+), 15 deletions(-)
> >
> > diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
> > index 2e9c71138e..1b5cc34f99 100644
> > --- a/arch/arm/mach-rockchip/Kconfig
> > +++ b/arch/arm/mach-rockchip/Kconfig
> > @@ -366,6 +366,7 @@ config ROCKCHIP_RK3588
> >   imply SCMI_FIRMWARE
> >   imply SPL_ATF_NO_PLATFORM_PARAM if SPL_ATF
> >   imply SPL_MMC_HS200_SUPPORT if SPL_MMC && MMC_HS200_SUPPORT
> > + imply DISPLAY_CPUINFO
>
> This is unnecessary, it's already defaulting to y if building for ARM
> boards: https://elixir.bootlin.com/u-boot/latest/source/common/Kconfig#L596
>
See below...
> I also don't think this is SO useful that we need to enable it on all
> rk3588 boards? But also, doesn't hurt, so... whatever I guess :) ?
>
> While looking at the code, I think we can remove the ifdef in
> https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-rockchip/cpu-info.c#L47
> because this file is anyway only compiled when CONFIG_DISPLAY_CPUINFO is
> set, c.f.

Oops I missed this changes, my bad
I will dop my changes over here.

> https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-rockchip/Makefile#L30
>
On Rockchip SoC CONFIG_DISPLAY_CPUINFO is been disable on most of the
configs files.

-# CONFIG_DISPLAY_CPUINFO is not set

My changes are related to determine the reset cause of the board and
display the results.
its only enable on selected SoC hence I have to used this logic.

U-Boot 2024.07-rc2-00397-g0370324feb-dirty (May 16 2024 - 13:11:14 +0530)

SoC: Rockchip rk3568
Reset cause: POR <---
Model: Radxa ROCK3 Model A
DRAM:  8 GiB (effective 7.7 GiB)
PMIC:  RK8090 (on=0x40, off=0x00)
Core:  344 devices, 31 uclasses,

> which also means...
>
> https://elixir.bootlin.com/u-boot/latest/source/arch/arm/include/asm/arch-rockchip/cru.h#L35
> should probably be ifdef'ed
>
> which means...
>
> https://elixir.bootlin.com/u-boot/latest/source/board/firefly/roc-pc-rk3399/roc-pc-rk3399.c#L64
> should probably also be ifdef'ed (but the config is enabled already
> (well... it wouldn't compile otherwsie), so I guess this is fine?).

This code changes will not affect this feature by default its enable
on RK3399 boards.

>
> Cheers,
> Quentin

Thanks

-Anand


Re: [PATCH] imx: hab: add documentation about the required keys/certs

2024-05-16 Thread Rasmus Villemoes
On 16/05/2024 10.25, Claudius Heine wrote:
> Hi Tim and Marek,
> 
> On 2024-05-16 12:46 am, Tim Harvey wrote:
>> On Tue, May 14, 2024 at 11:50 AM Tim Harvey 
>> wrote:
>>> On Sun, May 12, 2024 at 10:08 PM Marek Vasut  wrote:
 On 5/8/24 9:23 AM, Claudius Heine wrote:
> On 2024-05-07 3:28 pm, Marek Vasut wrote:
>> It would be good to mention the DT properties which govern the crypto
>> material paths -- nxp,srk-table, nxp,csf-crt, nxp,img-crt --
>> somewhere
>> around this sentence.
>
> This is something that should be documented with the changes where
> that
> code was added, IMO. I only documented here what I found out and have
> used myself, I haven't used those.
>
> I would be interested in reading how to best overwrite those paths and
> the image structured from board u-boot.dtsi files myself.
>
> If you want to can pickup my patch and integrate it into your
> series and
> extend it.

 I'll keep it in mind for V3.
>>
>> Hi Marek,
>>
>> The documentation patch here by Claudius does resolve my issues
>> discussed in the other thread and I can confirm symlinks work fine so
>> I think something like the following should be added:
>>
>> CST_DIR=/usr/src/cst-3.3.2/
>> ln -s $CST_DIR/crts .
>> ln -s $CST_DIR/keys .
> 
> `keys` and `crts` are very short and generic names, and putting them
> into the build directory might cause issues at some point. But I would
> not be against putting them into a sub directory (`imx-hab/{keys,crts}`?).

It is probably useful to be aware of the quality of the cst code. For
reference, I quote get_key_file()

int32_t get_key_file(const char* cert_file, char* key_file)
{
/* Algorithm to locate key file from given cert file  */
/* for now just assume the key to present in the  */
/* same folder as cert file. The crt in the name will */
/* will be replaced with key */
char * folder;
int32_t i = strlen(cert_file);  /**< Index into key filename,
initialized
 to filename length */

strcpy(key_file, cert_file);
key_file[i] = 0;

key_file[i-5] = 'y';
key_file[i-6] = 'e';
key_file[i-7] = 'k';

/* Search for folder name "certs" in the file and replace it with
"keys" */
/* Keys are found in "keys" folder and certs are in "certs" folder
*/

folder = strstr(key_file, "crts");
if(folder)
{
folder[0] = 'k';
folder[1] = 'e';
folder[2] = 'y';
folder[3] = 's';
}
return CAL_SUCCESS;
}

Ignoring the inconsistencies in the comments, obviously there are a lot
of implicit assumptions on file names and paths. First, the assumption
that the filename of they key corresponding to the certificate can be
obtained by replacing [-7:-5] by "key". Second, and much more egregious,
is the use of strstr() on key_file searching for "crts", and just
blindly replacing the first such with "keys", and ignoring it if not
found. So if that string appears anywhere in the path (say, my homedir
is /home/dcrts/ and I have the key material somewhere below that) this
will replace the wrong occurrence (and look in /home/dkeys/ ).

And of course it was unthinkable that this could have been written using
the much shorter memcpy(..., "keys", 4) so that one could actually `git
grep 'keys'` and figure out what was going on.

Rasmus



Re: [PATCH v3] tpm: display warning if using gpio reset with TPM

2024-05-16 Thread Jorge Ramirez-Ortiz, Foundries
On 16/05/24 11:34:14, Miquel Raynal wrote:
> Hi Jorge,
> 
> ...
> 
> > > >  - board with no reset gpio
> > > > u-boot=> tpm init && tpm info
> > > > tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> > > >  - board with a reset gpio
> > > > u-boot=> tpm init && tpm info
> > > > tpm@1: TPM gpio reset should not be used on secure production devices
> > > > tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> > > > 
> > > > [1] 
> > > > https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientTPMInterfaceSpecification_TIS__1-3_27_03212013.pdf
> > > > 
> > > > Signed-off-by: Tim Harvey   
> > > 
> > > Looks way cleaner, thanks.
> > > 
> > > Reviewed-by: Miquel Raynal 
> > > 
> > > Miquèl  
> > 
> > nice. if needed
> > 
> > Signed-off-by: Jorge Ramirez-Ortiz 
> 
> You cannot send your SoB like this. SoB means you are carrying some
> code which complies with the license, etc.
> 
> Either you were part of the original writing and want to be credited
> for that (you can be the author and first SoB, or suggest Tim to use
> Co-developed-by). Or you reviewed the change (Reviewed-by), you tested
> the change (Tested-by), or you are maintainer/responsible for some part
> that is touched and you agree with the change (Acked-by).

right, however there is some lenience in the process: some projects accept
the signed off, some others add the acked or reviewed and so on...

but I agree with you and I certainly do not need/want/expect to be
credited for this work. it is all good on my end :)

> 
> Thanks,
> Miquèl

btw you could have simply ignored my note btw : notice the "if needed"
part in my response. for reference, I noticed my name in CC, checked the
change, thought it was a good idea and tried to move it a long - just
chose the wrong tag for sure...





Re: [PATCH v3] tpm: display warning if using gpio reset with TPM

2024-05-16 Thread Miquel Raynal
Hi Jorge,

...

> > >  - board with no reset gpio
> > > u-boot=> tpm init && tpm info
> > > tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> > >  - board with a reset gpio
> > > u-boot=> tpm init && tpm info
> > > tpm@1: TPM gpio reset should not be used on secure production devices
> > > tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> > > 
> > > [1] 
> > > https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientTPMInterfaceSpecification_TIS__1-3_27_03212013.pdf
> > > 
> > > Signed-off-by: Tim Harvey   
> > 
> > Looks way cleaner, thanks.
> > 
> > Reviewed-by: Miquel Raynal 
> > 
> > Miquèl  
> 
> nice. if needed
> 
> Signed-off-by: Jorge Ramirez-Ortiz 

You cannot send your SoB like this. SoB means you are carrying some
code which complies with the license, etc.

Either you were part of the original writing and want to be credited
for that (you can be the author and first SoB, or suggest Tim to use
Co-developed-by). Or you reviewed the change (Reviewed-by), you tested
the change (Tested-by), or you are maintainer/responsible for some part
that is touched and you agree with the change (Acked-by).

Thanks,
Miquèl


Re: [PATCH v1 9/9] rockchip: RK3588: Enable display cpuinfo support on all boards

2024-05-16 Thread Quentin Schulz

Hi Anand,

This is patch 9/9 but somehow I didn't receive any other patch, nor did 
the mailing list? c.f. 
https://lists.denx.de/pipermail/u-boot/2024-May/thread.html and 
https://lore.kernel.org/u-boot/. Are you registered on the ML?


On 5/16/24 10:59 AM, Anand Moon wrote:

Imply DISPLAY_CPUINFO Kconfig options to support on all RK3588s and
RK3588 boards, Its used to determine the reset cause of the board.

Cc: Jagan Teki 
Signed-off-by: Anand Moon 
---
  arch/arm/mach-rockchip/Kconfig   | 1 +
  configs/coolpi-4b-rk3588s_defconfig  | 1 -
  configs/coolpi-cm5-evb-rk3588_defconfig  | 1 -
  configs/evb-rk3588_defconfig | 1 -
  configs/generic-rk3588_defconfig | 1 -
  configs/jaguar-rk3588_defconfig  | 1 -
  configs/nanopc-t6-rk3588_defconfig   | 1 -
  configs/neu6a-io-rk3588_defconfig| 1 -
  configs/neu6b-io-rk3588_defconfig| 1 -
  configs/orangepi-5-plus-rk3588_defconfig | 1 -
  configs/orangepi-5-rk3588s_defconfig | 1 -
  configs/quartzpro64-rk3588_defconfig | 1 -
  configs/rock5a-rk3588s_defconfig | 1 -
  configs/rock5b-rk3588_defconfig  | 1 -
  configs/toybrick-rk3588_defconfig| 1 -
  configs/turing-rk1-rk3588_defconfig  | 1 -
  16 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index 2e9c71138e..1b5cc34f99 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -366,6 +366,7 @@ config ROCKCHIP_RK3588
imply SCMI_FIRMWARE
imply SPL_ATF_NO_PLATFORM_PARAM if SPL_ATF
imply SPL_MMC_HS200_SUPPORT if SPL_MMC && MMC_HS200_SUPPORT
+   imply DISPLAY_CPUINFO


This is unnecessary, it's already defaulting to y if building for ARM 
boards: https://elixir.bootlin.com/u-boot/latest/source/common/Kconfig#L596


I also don't think this is SO useful that we need to enable it on all 
rk3588 boards? But also, doesn't hurt, so... whatever I guess :) ?


While looking at the code, I think we can remove the ifdef in 
https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-rockchip/cpu-info.c#L47 
because this file is anyway only compiled when CONFIG_DISPLAY_CPUINFO is 
set, c.f. 
https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-rockchip/Makefile#L30


which also means...

https://elixir.bootlin.com/u-boot/latest/source/arch/arm/include/asm/arch-rockchip/cru.h#L35 
should probably be ifdef'ed


which means...

https://elixir.bootlin.com/u-boot/latest/source/board/firefly/roc-pc-rk3399/roc-pc-rk3399.c#L64 
should probably also be ifdef'ed (but the config is enabled already 
(well... it wouldn't compile otherwsie), so I guess this is fine?).


Cheers,
Quentin


[v2][PATCH 2/2] MAINTAINERS: add USB gadget regex to u-boot-dfu tree

2024-05-16 Thread Mattijs Korpershoek
We try to split work with Marek on USB as following:
- Mattijs handles USB gadget
- Marek handles the rest of USB

Add additional gadget patterns to the maintainers file so that I
get cc'ed more often on USB gadget patches.

Signed-off-by: Mattijs Korpershoek 
---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 05217db79f7e..6d021763a62a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1017,8 +1017,11 @@ F:   common/update.c
 F: doc/api/dfu.rst
 F: doc/usage/dfu.rst
 F: drivers/dfu/
+F: drivers/usb/*/*gadget*
 F: drivers/usb/gadget/
 F: include/dfu.h
+F: include/linux/usb/ch9.h
+F: include/linux/usb/gadget.h
 
 DRIVER MODEL
 M: Simon Glass 

-- 
2.44.0



[v2][PATCH 1/2] MAINTAINERS: add tree link for fastboot

2024-05-16 Thread Mattijs Korpershoek
Fastboot patches go through the u-boot-dfu tree.

Add a link in the maintainers file for it.

Signed-off-by: Mattijs Korpershoek 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 6853288975c0..05217db79f7e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1118,6 +1118,7 @@ F:test/py/tests/test_event_dump.py
 FASTBOOT
 M: Mattijs Korpershoek 
 S: Maintained
+T: git https://source.denx.de/u-boot/custodians/u-boot-dfu.git
 F: cmd/fastboot.c
 F: doc/android/fastboot*.rst
 F: include/fastboot.h

-- 
2.44.0



[v2][PATCH 0/2] MAINTAINERS: updates for fastboot and USB gadget

2024-05-16 Thread Mattijs Korpershoek
I've noticed that I'm missing quite some USB gadget patches such as [1]
since I'm not always cc'ed.

With Marek, we agreed on the following split:
- I take care of USB gadget side
- Marek handles the rest

Update the maintainers file to make sure I get included on gadget
related patches.

While at it, also update FASTBOOT entry to point towards the u-boot-dfu
tree.

[1] 
https://lore.kernel.org/all/20240412202611.3565052-1-alexander.sverd...@siemens.com/

Signed-off-by: Mattijs Korpershoek 
---
Changes in v2:
- Updated commit message (s/usb/USB) for patch 2
- Added ch9 include to USB gadget list
- Link to v1: 
https://lore.kernel.org/r/20240514-gadget-maintainer-v1-0-b170f291d...@baylibre.com

---
Mattijs Korpershoek (2):
  MAINTAINERS: add tree link for fastboot
  MAINTAINERS: add USB gadget regex to u-boot-dfu tree

 MAINTAINERS | 4 
 1 file changed, 4 insertions(+)
---
base-commit: c8ffd1356d42223cbb8c86280a083cc3c93e6426
change-id: 20240514-gadget-maintainer-cf40fcf2bab4

Best regards,
-- 
Mattijs Korpershoek 



Re: [PATCH v3] tpm: display warning if using gpio reset with TPM

2024-05-16 Thread Jorge Ramirez-Ortiz, Foundries
On 16/05/24 09:09:50, Miquel Raynal wrote:
> Hi Tim,
> 
> thar...@gateworks.com wrote on Wed, 15 May 2024 16:21:38 -0700:
> 
> > Instead of displaying what looks like an error message if a
> > gpio-reset dt prop is missing for a TPM display a warning that
> > having a gpio reset on a TPM should not be used for a secure production
> > device.
> > 
> > TCG TIS spec [1] says:
> > "The TPM_Init (LRESET#/SPI_RST#) signal MUST be connected to the
> > platform CPU Reset signal such that it complies with the requirements
> > specified in section 1.2.7 HOST Platform Reset in the PC Client
> > Implementation Specification for Conventional BIOS."
> > 
> > The reasoning is that you should not be able to toggle a GPIO and reset
> > the TPM without resetting the CPU as well because if an attacker can
> > break into your OS via an OS level security flaw they can then reset the
> > TPM via GPIO and replay the measurements required to unseal keys
> > that you have otherwise protected.
> > 
> > Additionally restructure the code for improved readability allowing for
> > removal of the init label.
> > 
> > Before:
> >  - board with no reset gpio
> > u-boot=> tpm init && tpm info
> > tpm_tis_spi_probe: missing reset GPIO
> > tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> >  - board with a reset gpio
> > u-boot=> tpm init && tpm info
> > tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> > 
> > After:
> >  - board with no reset gpio
> > u-boot=> tpm init && tpm info
> > tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> >  - board with a reset gpio
> > u-boot=> tpm init && tpm info
> > tpm@1: TPM gpio reset should not be used on secure production devices
> > tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> > 
> > [1] 
> > https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientTPMInterfaceSpecification_TIS__1-3_27_03212013.pdf
> > 
> > Signed-off-by: Tim Harvey 
> 
> Looks way cleaner, thanks.
> 
> Reviewed-by: Miquel Raynal 
> 
> Miquèl

nice. if needed

Signed-off-by: Jorge Ramirez-Ortiz 


[PATCH v2] imx: hab: add documentation about the required keys/certs

2024-05-16 Thread Claudius Heine
For CST to find the certificates and keys for signing, some keys and
certs need to be copied into the u-boot build directory.

Signed-off-by: Claudius Heine 
---
Hi,

this patch documents some changes of the
'<20240503010518.263458-1-ma...@denx.de>' patchset. So am posting it as
a reply to my earlier patch in that thread.

Changed from v1:
 - added 'symbolic link' option for making keys/certs available in build
 - `node` -> `node(s)`

---
 doc/imx/habv4/guides/mx8m_spl_secure_boot.txt | 17 +
 1 file changed, 17 insertions(+)

diff --git a/doc/imx/habv4/guides/mx8m_spl_secure_boot.txt 
b/doc/imx/habv4/guides/mx8m_spl_secure_boot.txt
index ce1de659d8..75089fba4d 100644
--- a/doc/imx/habv4/guides/mx8m_spl_secure_boot.txt
+++ b/doc/imx/habv4/guides/mx8m_spl_secure_boot.txt
@@ -144,6 +144,23 @@ The signing is activated by wrapping SPL and fitImage 
sections into nxp-imx8mcst
 etype, which is done automatically in arch/arm/dts/imx8m{m,n,p,q}-u-boot.dtsi
 in case CONFIG_IMX_HAB Kconfig symbol is enabled.
 
+Per default the HAB keys and certificates need to be located in the build
+directory, this means creating a symbolic link or copying the following files
+from the HAB keys directory flat (e.g. removing the `keys` and `cert`
+subdirectory) into the u-boot build directory for the CST Code Signing Tool to
+locate them:
+
+- `crts/SRK_1_2_3_4_table.bin`
+- `crts/CSF1_1_sha256_4096_65537_v3_usr_crt.pem`
+- `keys/CSF1_1_sha256_4096_65537_v3_usr_key.pem`
+- `crts/IMG1_1_sha256_4096_65537_v3_usr_crt.pem`
+- `keys/IMG1_1_sha256_4096_65537_v3_usr_key.pem`
+- `keys/key_pass.txt`
+
+The paths to the SRK table and the certificates can be modified via changes to
+the nxp_imx8mcst device tree node(s), however the other files are required by
+the CST tools as well, and will be searched for in relation to them.
+
 Build of flash.bin target then produces a signed flash.bin automatically.
 
 1.4 Closing the device
-- 
2.42.0



Re: [PATCH] imx: hab: add documentation about the required keys/certs

2024-05-16 Thread Claudius Heine

Hi Tim and Marek,

On 2024-05-16 12:46 am, Tim Harvey wrote:

On Tue, May 14, 2024 at 11:50 AM Tim Harvey  wrote:

On Sun, May 12, 2024 at 10:08 PM Marek Vasut  wrote:

On 5/8/24 9:23 AM, Claudius Heine wrote:

On 2024-05-07 3:28 pm, Marek Vasut wrote:

It would be good to mention the DT properties which govern the crypto
material paths -- nxp,srk-table, nxp,csf-crt, nxp,img-crt -- somewhere
around this sentence.


This is something that should be documented with the changes where that
code was added, IMO. I only documented here what I found out and have
used myself, I haven't used those.

I would be interested in reading how to best overwrite those paths and
the image structured from board u-boot.dtsi files myself.

If you want to can pickup my patch and integrate it into your series and
extend it.


I'll keep it in mind for V3.


Hi Marek,

The documentation patch here by Claudius does resolve my issues
discussed in the other thread and I can confirm symlinks work fine so
I think something like the following should be added:

CST_DIR=/usr/src/cst-3.3.2/
ln -s $CST_DIR/crts .
ln -s $CST_DIR/keys .


`keys` and `crts` are very short and generic names, and putting them 
into the build directory might cause issues at some point. But I would 
not be against putting them into a sub directory (`imx-hab/{keys,crts}`?).




then with the following change to nxp_imx8mcst.py you can build a
signed image without code modification:
diff --git a/tools/binman/etype/nxp_imx8mcst.py
b/tools/binman/etype/nxp_imx8mcst.py
index 132127ad4827..7d8abc78fc89 100644
--- a/tools/binman/etype/nxp_imx8mcst.py
+++ b/tools/binman/etype/nxp_imx8mcst.py
@@ -68,9 +68,9 @@ class Entry_nxp_imx8mcst(Entry_mkimage):
  def ReadNode(self):
  super().ReadNode()
  self.loader_address = fdt_util.GetInt(self._node, 
'nxp,loader-address')
-self.srk_table = fdt_util.GetString(self._node,
'nxp,srk-table', 'SRK_1_2_3_4_table.bin')
-self.csf_crt = fdt_util.GetString(self._node, 'nxp,csf-crt',
'CSF1_1_sha256_4096_65537_v3_usr_crt.pem')
-self.img_crt = fdt_util.GetString(self._node, 'nxp,img-crt',
'IMG1_1_sha256_4096_65537_v3_usr_crt.pem')
+self.srk_table = fdt_util.GetString(self._node,
'nxp,srk-table', 'crts/SRK_1_2_3_4_table.bin')
+self.csf_crt = fdt_util.GetString(self._node, 'nxp,csf-crt',
'crts/CSF1_1_sha256_4096_65537_v3_usr_crt.pem')
+self.img_crt = fdt_util.GetString(self._node, 'nxp,img-crt',
'crts/IMG1_1_sha256_4096_65537_v3_usr_crt.pem')
  self.unlock = fdt_util.GetBool(self._node, 'nxp,unlock')
  self.ReadEntries()

If copying or symlinking the keys/certs directory is not desired are
env vars exposed to binman's python classes? If so you can just
require CST_DIR to be specified and use that for the paths?


I personally would prefer using (one) environment variable(s) to specify 
the path to all keys, that way whatever `cst` needs, it will find it 
there, and explicit symlinking/copying can be avoided.


I would probably rather call it `HAB_DIR`/`HAB_BASE_DIR` or something, 
because it doesn't need to be pointing to the whole `cst` stuff just a 
directory for the keys and certs for the HAB. `CST_DIR` might leave the 
impression that the `cst` from that directory is used.


And you can still allow environment variables like (`SRK_TABLE`, 
`CSF_KEY` and `IMG_KEY`) to overwrite the name of each, relative to the 
`HAB_DIR/{keys,certs}` if a `HAB_DIR` is set.


This would be somewhat backwards compatible and allows simpler usage by 
setting just one variable (`HAB_DIR`) and leaving the rest to the dtb.


kind regards,
Claudius

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


[PATCH v2 3/3] cyclic: make clients embed a struct cyclic_info in their own data structure

2024-05-16 Thread Rasmus Villemoes
There are of course not a whole lot of examples in-tree yet, but
before they appear, let's make this API change: Instead of separately
allocating a 'struct cyclic_info', make the users embed such an
instance in their own structure, and make the convention that the
callback simply receives the 'struct cyclic_info *', from which the
clients can get their own data using the container_of() macro.

This has a number of advantages.

First, it means cyclic_register() simply cannot fail, simplifying the
code. The necessary storage will simply be allocated automatically
when the client's own structure is allocated (often via
uclass_priv_auto or similar).

Second, code for which CONFIG_CYCLIC is just an option can more easily
be written without #ifdefs, if we just provide an empty struct
cyclic_info {}. For example, the nested CONFIG_IS_ENABLED()s in
https://lore.kernel.org/u-boot/20240316201416.211480-1-marek.vasut+rene...@mailbox.org/
are mostly due to the existence of the 'struct cyclic_info *' member
being guarded by #ifdef CONFIG_CYCLIC.

And we do probably want to avoid the extra memory overhead of that
member when !CONFIG_CYCLIC. But that is automatic if, instead of a
'struct cyclic_info *', one simply embeds a 'struct cyclic_info',
which will have size 0 when !CONFIG_CYCLIC. Also, the no-op
cyclic_register() function can just unconditionally be called, and the
compiler will see that (1) the callback is referenced, so not emit a
warning for a maybe-unused function and (2) see that it can actually
never be reached, so not emit any code for it.

Reviewed-by: Stefan Roese 
Signed-off-by: Rasmus Villemoes 
---
 board/Marvell/octeon_nic23/board.c |  9 +---
 cmd/cyclic.c   | 12 +--
 common/cyclic.c| 22 +--
 doc/develop/cyclic.rst | 26 ++-
 drivers/watchdog/wdt-uclass.c  | 33 +
 include/cyclic.h   | 34 +++---
 6 files changed, 64 insertions(+), 72 deletions(-)

diff --git a/board/Marvell/octeon_nic23/board.c 
b/board/Marvell/octeon_nic23/board.c
index bc9332cb74a..74b9c741b7b 100644
--- a/board/Marvell/octeon_nic23/board.c
+++ b/board/Marvell/octeon_nic23/board.c
@@ -357,10 +357,13 @@ int board_late_init(void)
board_configure_qlms();
 
/* Register cyclic function for PCIe FLR fixup */
-   cyclic = cyclic_register(octeon_board_restore_pf, 100,
-"pcie_flr_fix", NULL);
-   if (!cyclic)
+   cyclic = calloc(1, sizeof(*cyclic));
+   if (cyclic) {
+   cyclic_register(cyclic, octeon_board_restore_pf, 100,
+   "pcie_flr_fix");
+   } else {
printf("Registering of cyclic function failed\n");
+   }
 
return 0;
 }
diff --git a/cmd/cyclic.c b/cmd/cyclic.c
index 40e966de9aa..339dd4a7bce 100644
--- a/cmd/cyclic.c
+++ b/cmd/cyclic.c
@@ -15,14 +15,16 @@
 #include 
 #include 
 #include 
+#include 
 
 struct cyclic_demo_info {
+   struct cyclic_info cyclic;
uint delay_us;
 };
 
-static void cyclic_demo(void *ctx)
+static void cyclic_demo(struct cyclic_info *c)
 {
-   struct cyclic_demo_info *info = ctx;
+   struct cyclic_demo_info *info = container_of(c, struct 
cyclic_demo_info, cyclic);
 
/* Just a small dummy delay here */
udelay(info->delay_us);
@@ -32,7 +34,6 @@ static int do_cyclic_demo(struct cmd_tbl *cmdtp, int flag, 
int argc,
  char *const argv[])
 {
struct cyclic_demo_info *info;
-   struct cyclic_info *cyclic;
uint time_ms;
 
if (argc < 3)
@@ -48,10 +49,7 @@ static int do_cyclic_demo(struct cmd_tbl *cmdtp, int flag, 
int argc,
info->delay_us = simple_strtoul(argv[2], NULL, 0);
 
/* Register demo cyclic function */
-   cyclic = cyclic_register(cyclic_demo, time_ms * 1000, "cyclic_demo",
-info);
-   if (!cyclic)
-   printf("Registering of cyclic_demo failed\n");
+   cyclic_register(>cyclic, cyclic_demo, time_ms * 1000, 
"cyclic_demo");
 
printf("Registered function \"%s\" to be executed all %dms\n",
   "cyclic_demo", time_ms);
diff --git a/common/cyclic.c b/common/cyclic.c
index c62e7fa7d19..ec38fad6775 100644
--- a/common/cyclic.c
+++ b/common/cyclic.c
@@ -26,34 +26,22 @@ struct hlist_head *cyclic_get_list(void)
return (struct hlist_head *)>cyclic_list;
 }
 
-struct cyclic_info *cyclic_register(cyclic_func_t func, uint64_t delay_us,
-   const char *name, void *ctx)
+void cyclic_register(struct cyclic_info *cyclic, cyclic_func_t func,
+uint64_t delay_us, const char *name)
 {
-   struct cyclic_info *cyclic;
-
-   cyclic = calloc(1, sizeof(struct cyclic_info));
-   if (!cyclic) {
-   pr_debug("Memory allocation error\n");
-   return NULL;
-   }
+ 

[PATCH v2 2/3] wdt-uclass: prevent multiple cyclic_register calls

2024-05-16 Thread Rasmus Villemoes
Currently, the cyclic_register() done in wdt_start() is not undone in
wdt_stop(). Moreover, calling wdt_start multiple times (which is
perfectly allowed on an already started device, e.g. to change the
timeout value) will result in another struct cyclic_info being
registered, referring to the same watchdog device.

This can easily be seen on e.g. a wandboard:

=> cyclic list
function: watchdog@20bc000, cpu-time: 22 us, frequency: 1.01 times/s
=> wdt list
watchdog@20bc000 (imx_wdt)
=> wdt dev watchdog@20bc000
=> wdt start 5
WDT:   Started watchdog@20bc000 with servicing every 1000ms (50s timeout)
=> cyclic list
function: watchdog@20bc000, cpu-time: 37 us, frequency: 1.03 times/s
function: watchdog@20bc000, cpu-time: 241 us, frequency: 1.01 times/s
=> wdt start 12345
WDT:   Started watchdog@20bc000 with servicing every 1000ms (12s timeout)
=> cyclic list
function: watchdog@20bc000, cpu-time: 36 us, frequency: 1.03 times/s
function: watchdog@20bc000, cpu-time: 100 us, frequency: 1.04 times/s
function: watchdog@20bc000, cpu-time: 299 us, frequency: 1.00 times/s

So properly unregister the watchdog device from the cyclic framework
in wdt_stop(). In wdt_start(), we cannot just skip the registration,
as the (new) timeout value may mean that we have to ask the cyclic
framework to call us more often. So if we're already running,
first unregister the old cyclic instance.

Reviewed-by: Stefan Roese 
Signed-off-by: Rasmus Villemoes 
---
 drivers/watchdog/wdt-uclass.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c
index c88312ec721..12850016c93 100644
--- a/drivers/watchdog/wdt-uclass.c
+++ b/drivers/watchdog/wdt-uclass.c
@@ -121,10 +121,11 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong 
flags)
struct wdt_priv *priv = dev_get_uclass_priv(dev);
char str[16];
 
-   priv->running = true;
-
memset(str, 0, 16);
if (IS_ENABLED(CONFIG_WATCHDOG)) {
+   if (priv->running)
+   cyclic_unregister(priv->cyclic);
+
/* Register the watchdog driver as a cyclic function */
priv->cyclic = cyclic_register(wdt_cyclic,
   priv->reset_period * 
1000,
@@ -139,6 +140,7 @@ int wdt_start(struct udevice *dev, u64 timeout_ms, ulong 
flags)
}
}
 
+   priv->running = true;
printf("WDT:   Started %s with%s servicing %s (%ds timeout)\n",
   dev->name, IS_ENABLED(CONFIG_WATCHDOG) ? "" : "out",
   str, (u32)lldiv(timeout_ms, 1000));
@@ -159,6 +161,9 @@ int wdt_stop(struct udevice *dev)
if (ret == 0) {
struct wdt_priv *priv = dev_get_uclass_priv(dev);
 
+   if (IS_ENABLED(CONFIG_WATCHDOG) && priv->running)
+   cyclic_unregister(priv->cyclic);
+
priv->running = false;
}
 
-- 
2.40.1.1.g1c60b9335d



[PATCH v2 0/3] cyclic/watchdog patches

2024-05-16 Thread Rasmus Villemoes
A bit of a mixed bag. I've been wanting to submit something like 3/3
for a while. So when I stumbled on Marek's patch
https://lore.kernel.org/u-boot/20240316201416.211480-1-marek.vasut+rene...@mailbox.org/
, I got reminded of that plan, and I think that patch could be more
readable if we adopt this model.

While actually doing those mostly mechanical changes, I stumbled on
two separate issues that probably want fixing regardless of the fate
of 3/3.

For now only compile-tested.

v2: Add R-bs from Stefan. Fixup whitespace in the doc/ part. Rebase
to current master (676903c1b97), fixing trivial conflict with
301bac6047c8.

Rasmus Villemoes (3):
  cyclic: stop strdup'ing name in cyclic_register()
  wdt-uclass: prevent multiple cyclic_register calls
  cyclic: make clients embed a struct cyclic_info in their own data
structure

 board/Marvell/octeon_nic23/board.c |  9 ---
 cmd/cyclic.c   | 12 --
 common/cyclic.c| 24 +--
 doc/develop/cyclic.rst | 26 
 drivers/watchdog/wdt-uclass.c  | 38 --
 include/cyclic.h   | 36 ++--
 6 files changed, 71 insertions(+), 74 deletions(-)

-- 
2.40.1.1.g1c60b9335d



[PATCH v2 1/3] cyclic: stop strdup'ing name in cyclic_register()

2024-05-16 Thread Rasmus Villemoes
We are not checking the return value of strdup(), nor
freeing the string in cyclic_unregister().

However, all current users either pass a string literal or the
dev->name of the client device. So in all cases the name string will
live at least as long as the cyclic_info is registered, so just make
that a requirement.

Reviewed-by: Stefan Roese 
Signed-off-by: Rasmus Villemoes 
---
 common/cyclic.c  | 2 +-
 include/cyclic.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/cyclic.c b/common/cyclic.c
index a49bfc88f5c..c62e7fa7d19 100644
--- a/common/cyclic.c
+++ b/common/cyclic.c
@@ -40,7 +40,7 @@ struct cyclic_info *cyclic_register(cyclic_func_t func, 
uint64_t delay_us,
/* Store values in struct */
cyclic->func = func;
cyclic->ctx = ctx;
-   cyclic->name = strdup(name);
+   cyclic->name = name;
cyclic->delay_us = delay_us;
cyclic->start_time_us = timer_get_us();
hlist_add_head(>list, cyclic_get_list());
diff --git a/include/cyclic.h b/include/cyclic.h
index 44ad3cb6b80..38946216fb8 100644
--- a/include/cyclic.h
+++ b/include/cyclic.h
@@ -31,7 +31,7 @@
 struct cyclic_info {
void (*func)(void *ctx);
void *ctx;
-   char *name;
+   const char *name;
uint64_t delay_us;
uint64_t start_time_us;
uint64_t cpu_time_us;
-- 
2.40.1.1.g1c60b9335d



Re: [PATCH v3] tpm: display warning if using gpio reset with TPM

2024-05-16 Thread Miquel Raynal
Hi Tim,

thar...@gateworks.com wrote on Wed, 15 May 2024 16:21:38 -0700:

> Instead of displaying what looks like an error message if a
> gpio-reset dt prop is missing for a TPM display a warning that
> having a gpio reset on a TPM should not be used for a secure production
> device.
> 
> TCG TIS spec [1] says:
> "The TPM_Init (LRESET#/SPI_RST#) signal MUST be connected to the
> platform CPU Reset signal such that it complies with the requirements
> specified in section 1.2.7 HOST Platform Reset in the PC Client
> Implementation Specification for Conventional BIOS."
> 
> The reasoning is that you should not be able to toggle a GPIO and reset
> the TPM without resetting the CPU as well because if an attacker can
> break into your OS via an OS level security flaw they can then reset the
> TPM via GPIO and replay the measurements required to unseal keys
> that you have otherwise protected.
> 
> Additionally restructure the code for improved readability allowing for
> removal of the init label.
> 
> Before:
>  - board with no reset gpio
> u-boot=> tpm init && tpm info
> tpm_tis_spi_probe: missing reset GPIO
> tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
>  - board with a reset gpio
> u-boot=> tpm init && tpm info
> tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> 
> After:
>  - board with no reset gpio
> u-boot=> tpm init && tpm info
> tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
>  - board with a reset gpio
> u-boot=> tpm init && tpm info
> tpm@1: TPM gpio reset should not be used on secure production devices
> tpm@1 v2.0: VendorID 0x1114, DeviceID 0x3205, RevisionID 0x01 [open]
> 
> [1] 
> https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientTPMInterfaceSpecification_TIS__1-3_27_03212013.pdf
> 
> Signed-off-by: Tim Harvey 

Looks way cleaner, thanks.

Reviewed-by: Miquel Raynal 

Miquèl


  1   2   >