Re: [EXTERNAL] Re: [PATCH] common: Kconfig: Fix CMD_BMP/BMP dependency

2023-07-14 Thread Samuel Dionne-Riel
Please do!

On 7/14/23, Nikhil M Jain  wrote:
>
>
> On 10/07/23 20:36, Tom Rini wrote:
>> On Sun, Jul 09, 2023 at 07:18:10PM -0400, Samuel Dionne-Riel wrote:
>>
>>> Using `default y` will not select BMP when CMD_BMP has been enabled, if
>>> it was already configured.
>>>
>>> By using `select`, if `CMD_BMP` is turned on, it will force the presence
>>> of `BMP`.
>>>
>>> Fixes: 072b0e16c482114d242580dd7a3197db5966705f
>>
>> The fixes tag should be the "git log -n1 --oneline" version of the
>> commit, btw.
>>
>>> Signed-off-by: Samuel Dionne-Riel 
>>> ---
>>>   cmd/Kconfig| 1 +
>>>   common/Kconfig | 2 +-
>>>   2 files changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/cmd/Kconfig b/cmd/Kconfig
>>> index 02e54f1e50..94c54b2359 100644
>>> --- a/cmd/Kconfig
>>> +++ b/cmd/Kconfig
>>> @@ -1988,6 +1988,7 @@ config CMD_2048
>>>   config CMD_BMP
>>> bool "Enable 'bmp' command"
>>> depends on VIDEO
>>> +   select BMP
>>> help
>>>   This provides a way to obtain information about a BMP-format image
>>>   and to display it. BMP (which presumably stands for BitMaP) is a
>>> diff --git a/common/Kconfig b/common/Kconfig
>>> index bbabadb35e..d0117e3dc8 100644
>>> --- a/common/Kconfig
>>> +++ b/common/Kconfig
>>> @@ -1157,7 +1157,7 @@ config IO_TRACE
>>>
>>>   config BMP
>>> bool "Enable bmp image display"
>>> -   default y if CMD_BMP
>>> +   default n
>>> help
>>>   Enable bmp functions to display bmp image and get bmp info.
>>
>> Since this is something that can be resolved by correcting the resulting
>> .config file (or storing a new defconfig in your build system, or what
>> have you) I'm not grabbing this for the release I'll be doing later
>> today.  Also in a v2, "default n" is the default. And I'm not entirely
>> sure if BMP (and SPL_BMP) end up being things that should be asked, or
>> should be select'd because they're library functions. Finally, this
>> should perhaps be part of
>> https://patchwork.ozlabs.org/project/uboot/list/?series=360683=*
>> but I'm not sure and will wait for Nikhil to chime in.
>>
> @Samuel, is it okay if I pick this patch and send it as a patch as part
> of my above mentioned series with the changes suggested by Tom?
>


-- 
— Samuel Dionne-Riel


Re: [PATCH v2 0/6] introduce EFI_RAM_DISK_PROTOCOL

2023-07-14 Thread Tobias Waldekranz


Hi Masahisa,

On fre, jul 14, 2023 at 14:44, Masahisa Kojima  
wrote:
> This series introduces the EFI_RAM_DISK_PROTOCOL implementation.
> The major purpose of this series is a preparation for EFI HTTP(S) boot.
>
> Now U-Boot can download the distro installer ISO image
> via wget or tftpboot commands, but U-Boot can not mount
> the downloaded ISO image.

A while back, I added the blkmap command and backend to U-Boot, which
is, among other things, capable of creating ramdisks. What exactly does
this series add that can't be supported by a block map? There is some
documentation available here:

https://u-boot.readthedocs.io/en/latest/usage/blkmap.html


Re: [PATCH] configs: k2x_evm: Always include FIT loading support

2023-07-14 Thread Nishanth Menon
On 14:00-20230714, Andrew Davis wrote:
> Non-HS boards can use FIT images so include the env var commands
> for these unconditionally.
> 
> Signed-off-by: Andrew Davis 

Reviewed-by: Nishanth Menon 

> ---
>  include/configs/k2e_evm.h  | 11 ++-
>  include/configs/k2hk_evm.h | 11 ++-
>  include/configs/k2l_evm.h  | 11 ++-
>  3 files changed, 6 insertions(+), 27 deletions(-)
> 
> diff --git a/include/configs/k2e_evm.h b/include/configs/k2e_evm.h
> index 929c9a26de1..630dfdc5b7f 100644
> --- a/include/configs/k2e_evm.h
> +++ b/include/configs/k2e_evm.h
> @@ -11,18 +11,11 @@
>  
>  #include 
>  
> -#ifdef CONFIG_TI_SECURE_DEVICE
> -#define DEFAULT_SEC_BOOT_ENV \
> - DEFAULT_FIT_TI_ARGS \
> - "findfdt=setenv fdtfile ${name_fdt}\0"
> -#else
> -#define DEFAULT_SEC_BOOT_ENV
> -#endif
> -
>  /* U-Boot general configuration */
>  #define ENV_KS2_BOARD_SETTINGS   
> \
>   DEFAULT_FW_INITRAMFS_BOOT_ENV   \
> - DEFAULT_SEC_BOOT_ENV\
> + DEFAULT_FIT_TI_ARGS \
> + "findfdt=setenv fdtfile ${name_fdt}\0"  \
>   "boot=ubi\0"\
>   "args_ubi=setenv bootargs ${bootargs} rootfstype=ubifs "\
>   "root=ubi0:rootfs rootflags=sync rw ubi.mtd=ubifs,2048\0"   \
> diff --git a/include/configs/k2hk_evm.h b/include/configs/k2hk_evm.h
> index 05b4a3c204d..ed54be839ff 100644
> --- a/include/configs/k2hk_evm.h
> +++ b/include/configs/k2hk_evm.h
> @@ -11,18 +11,11 @@
>  
>  #include 
>  
> -#ifdef CONFIG_TI_SECURE_DEVICE
> -#define DEFAULT_SEC_BOOT_ENV \
> - DEFAULT_FIT_TI_ARGS \
> - "findfdt=setenv fdtfile ${name_fdt}\0"
> -#else
> -#define DEFAULT_SEC_BOOT_ENV
> -#endif
> -
>  /* U-Boot general configuration */
>  #define ENV_KS2_BOARD_SETTINGS   
> \
>   DEFAULT_FW_INITRAMFS_BOOT_ENV   \
> - DEFAULT_SEC_BOOT_ENV\
> + DEFAULT_FIT_TI_ARGS \
> + "findfdt=setenv fdtfile ${name_fdt}\0"  \
>   "boot=ubi\0"\
>   "args_ubi=setenv bootargs ${bootargs} rootfstype=ubifs "\
>   "root=ubi0:rootfs rootflags=sync rw ubi.mtd=ubifs,2048\0"   \
> diff --git a/include/configs/k2l_evm.h b/include/configs/k2l_evm.h
> index b1b839b5043..69d42eaf9f1 100644
> --- a/include/configs/k2l_evm.h
> +++ b/include/configs/k2l_evm.h
> @@ -11,18 +11,11 @@
>  
>  #include 
>  
> -#ifdef CONFIG_TI_SECURE_DEVICE
> -#define DEFAULT_SEC_BOOT_ENV \
> - DEFAULT_FIT_TI_ARGS \
> - "findfdt=setenv fdtfile ${name_fdt}\0"
> -#else
> -#define DEFAULT_SEC_BOOT_ENV
> -#endif
> -
>  /* U-Boot general configuration */
>  #define ENV_KS2_BOARD_SETTINGS   
> \
>   DEFAULT_FW_INITRAMFS_BOOT_ENV   \
> - DEFAULT_SEC_BOOT_ENV\
> + DEFAULT_FIT_TI_ARGS \
> + "findfdt=setenv fdtfile ${name_fdt}\0"  \
>   "boot=ubi\0"\
>   "args_ubi=setenv bootargs ${bootargs} rootfstype=ubifs "\
>   "root=ubi0:rootfs rootflags=sync rw ubi.mtd=ubifs,4096\0"   \
> -- 
> 2.39.2
> 

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH 3/3] usb: xhci-pci: Load ASMedia XHCI controller firmware

2023-07-14 Thread Marek Vasut

On 7/14/23 22:43, Mark Kettenis wrote:

The ASMedia XHCI controller found on some of the Apple Silicon
machines needs firmware to operate.  Use the file system
firmware loader interface to read the firmware and load it
onto the controller.  This allows keyboards connected to the
type-A ports on these machines to function in U-Boot.

Signed-off-by: Mark Kettenis 
---
  MAINTAINERS |   1 +
  drivers/usb/host/Kconfig|  11 +
  drivers/usb/host/Makefile   |   1 +
  drivers/usb/host/xhci-pci-asmedia.c | 394 
  drivers/usb/host/xhci-pci.c |   9 +
  include/usb/xhci.h  |   3 +
  6 files changed, 419 insertions(+)
  create mode 100644 drivers/usb/host/xhci-pci-asmedia.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 2477923a52..0acf04fff8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -124,6 +124,7 @@ F:  drivers/iommu/apple_dart.c
  F:drivers/nvme/nvme_apple.c
  F:drivers/pci/pcie_apple.c
  F:drivers/pinctrl/pinctrl-apple.c
+F: drivers/usb/host/xhci-pci-asmedia.c
  F:drivers/watchdog/apple_wdt.c
  F:include/configs/apple.h
  
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig

index 1a883babf4..ad8dfabeeb 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -95,6 +95,17 @@ config USB_XHCI_PCI
help
  Enables support for the PCI-based xHCI controller.
  
+config USB_XHCI_PCI_ASMEDIA

+   bool "Support for ASMedia xHCI USB controller"
+   depends on USB_XHCI_PCI
+   default y if ARCH_APPLE
+   imply FS_LOADER
+   help
+ Enables support for loading firmware for the ASMedia xHCI
+ controller.  This is needed on Apple Silicon machines that
+ contain ASMedia xHCI controllers without the full USB
+ firmware.
+
  config USB_XHCI_RCAR
bool "Renesas RCar USB 3.0 support"
default y
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 8dad36f936..2aa2d80263 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o
  obj-$(CONFIG_USB_XHCI_MVEBU) += xhci-mvebu.o
  obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
  obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
+obj-$(CONFIG_USB_XHCI_PCI_ASMEDIA) += xhci-pci-asmedia.o
  obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
  obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
  obj-$(CONFIG_USB_XHCI_OCTEON) += dwc3-octeon-glue.o
diff --git a/drivers/usb/host/xhci-pci-asmedia.c 
b/drivers/usb/host/xhci-pci-asmedia.c
new file mode 100644
index 00..cc1d25bde2
--- /dev/null
+++ b/drivers/usb/host/xhci-pci-asmedia.c
@@ -0,0 +1,394 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * ASMedia xHCI firmware loader
+ * Copyright (C) The Asahi Linux Contributors
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Configuration space registers */
+#define ASMT_CFG_CONTROL   0xe0
+#define ASMT_CFG_CONTROL_WRITE BIT(1)
+#define ASMT_CFG_CONTROL_READ  BIT(0)
+
+#define ASMT_CFG_SRAM_ADDR 0xe2
+
+#define ASMT_CFG_SRAM_ACCESS   0xef
+#define ASMT_CFG_SRAM_ACCESS_READ  BIT(6)
+#define ASMT_CFG_SRAM_ACCESS_ENABLEBIT(7)
+
+#define ASMT_CFG_DATA_READ00xf0
+#define ASMT_CFG_DATA_READ10xf4
+
+#define ASMT_CFG_DATA_WRITE0   0xf8
+#define ASMT_CFG_DATA_WRITE1   0xfc
+
+#define ASMT_CMD_GET_FWVER 0x860840
+#define ASMT_FWVER_ROM 0x010250090816
+
+/* BAR0 registers */
+#define ASMT_REG_ADDR  0x3000
+
+#define ASMT_REG_WDATA 0x3004
+#define ASMT_REG_RDATA 0x3008
+
+#define ASMT_REG_STATUS0x3009
+#define ASMT_REG_STATUS_BUSY   BIT(7)
+
+#define ASMT_REG_CODE_WDATA0x3010
+#define ASMT_REG_CODE_RDATA0x3018
+
+#define ASMT_MMIO_CPU_MISC 0x500e
+#define ASMT_MMIO_CPU_MISC_CODE_RAM_WR BIT(0)
+
+#define ASMT_MMIO_CPU_MODE_NEXT0x5040
+#define ASMT_MMIO_CPU_MODE_CUR 0x5041
+
+#define ASMT_MMIO_CPU_MODE_RAM BIT(0)
+#define ASMT_MMIO_CPU_MODE_HALFSPEED   BIT(1)
+
+#define ASMT_MMIO_CPU_EXEC_CTRL0x5042
+#define ASMT_MMIO_CPU_EXEC_CTRL_RESET  BIT(0)
+#define ASMT_MMIO_CPU_EXEC_CTRL_HALT   BIT(1)
+
+#define TIMEOUT_USEC   1
+#define RESET_TIMEOUT_USEC 50
+
+static int asmedia_mbox_tx(struct udevice *pdev, u64 data)
+{
+   u8 op;
+   int i;
+
+   for (i = 0; i < TIMEOUT_USEC; i++) {
+   dm_pci_read_config8(pdev, ASMT_CFG_CONTROL, );
+   if (!(op & ASMT_CFG_CONTROL_WRITE))
+   break;
+   udelay(1);


Would it be possible to use the wait_for_bit*() here ?
Or read*poll*timeout() ?


+   }
+
+   if (op & ASMT_CFG_CONTROL_WRITE) {
+   dev_err(pdev,
+ 

Re: [PATCH 1/3] apple: Set up file system firmware loader

2023-07-14 Thread Marek Vasut

On 7/14/23 22:43, Mark Kettenis wrote:

Find the appropriate EFI system partition on the internal NVMe
storage and set the U-Boot environment variables such that
the file system firmware loader can load firmware from it.

Signed-off-by: Mark Kettenis 
---
  arch/arm/mach-apple/board.c | 60 +
  1 file changed, 60 insertions(+)

diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c
index d501948118..7799a0f916 100644
--- a/arch/arm/mach-apple/board.c
+++ b/arch/arm/mach-apple/board.c
@@ -8,6 +8,8 @@
  #include 
  #include 
  #include 
+#include 
+#include 
  
  #include 

  #include 
@@ -539,6 +541,60 @@ u64 get_page_table_size(void)
return SZ_256K;
  }
  
+static char *asahi_esp_devpart(void)

+{
+   struct disk_partition info;
+   struct blk_desc *nvme_blk;
+   const char *uuid = NULL;
+   int devnum, len, p, part, ret;
+   static char devpart[64];
+   struct udevice *dev;
+   ofnode node;
+
+   if (devpart[0])
+   return devpart;
+
+   node = ofnode_path("/chosen");
+   if (ofnode_valid(node)) {
+   uuid = ofnode_get_property(node, "asahi,efi-system-partition",
+  );
+   }
+
+   nvme_scan_namespace();
+   for (devnum = 0, part = 0;; devnum++) {
+   nvme_blk = blk_get_devnum_by_uclass_id(UCLASS_NVME, devnum);
+   if (nvme_blk == NULL)
+   break;
+
+   dev = dev_get_parent(nvme_blk->bdev);
+   if (!device_is_compatible(dev, "apple,nvme-ans2"))


Can we somehow use ofnode_for_each_compatible_node() here ?
That might simplify this code.


+   continue;
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(nvme_blk, p, );
+   if (ret < 0)
+   break;
+
+   if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+   if (uuid && strcasecmp(uuid, info.uuid) == 0) {
+   part = p;
+   break;
+   }
+   if (part == 0)
+   part = p;
+   }
+   }
+
+   if (part > 0)
+   break;
+   }
+
+   if (part > 0)
+   snprintf(devpart, sizeof(devpart), "%d:%d", devnum, part);
+
+   return devpart;
+}
+
  #define KERNEL_COMP_SIZE  SZ_128M
  
  int board_late_init(void)

@@ -546,6 +602,10 @@ int board_late_init(void)
struct lmb lmb;
u32 status = 0;
  
+	status |= env_set("storage_interface",

+ blk_get_uclass_name(UCLASS_NVME));
+   status |= env_set("fw_dev_part", asahi_esp_devpart());


I think env_set() returns integer (and this could be negative too), so 
you might want to check the return value instead of casting it to 
unsigned integer.


Re: [PATCH 2/3] iopoll: Add readb_poll_sleep_timeout

2023-07-14 Thread Marek Vasut

On 7/14/23 22:43, Mark Kettenis wrote:

Add a variant of readl_poll_sleep_timeout that reads a single
byte to match the readb_poll_timeout API that Linux has.

Signed-off-by: Mark Kettenis 
---
  include/linux/iopoll.h | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
index 0ee2bddaa8..89990e95e9 100644
--- a/include/linux/iopoll.h
+++ b/include/linux/iopoll.h
@@ -49,6 +49,9 @@
  #define readl_poll_sleep_timeout(addr, val, cond, sleep_us, timeout_us) \
readx_poll_sleep_timeout(readl, addr, val, cond, sleep_us, timeout_us)
  
+#define readb_poll_sleep_timeout(addr, val, cond, sleep_us, timeout_us) \

+   readx_poll_sleep_timeout(readb, addr, val, cond, sleep_us, timeout_us)


readb variant should go before readl variant I think.


Re: [PATCH] bootstd: Make efi_mgr bootmeth work for non-sandbox setups

2023-07-14 Thread Heinrich Schuchardt

On 7/14/23 21:56, Mark Kettenis wrote:

Enable the bootflow based on this bootmeth if the BootOrder EFI
variable is set.

Signed-off-by: Mark Kettenis 
---
  boot/bootmeth_efi_mgr.c | 12 +++-
  1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
index e9d973429f..db650861ff 100644
--- a/boot/bootmeth_efi_mgr.c
+++ b/boot/bootmeth_efi_mgr.c
@@ -14,6 +14,8 @@
  #include 
  #include 
  #include 
+#include 
+#include 

  /**
   * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,21 @@ static int efi_mgr_check(struct udevice *dev, struct 
bootflow_iter *iter)
  static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
  {
struct efi_mgr_priv *priv = dev_get_priv(dev);
+   efi_uintn_t size;
+   u16 *bootorder;

if (priv->fake_dev) {
bflow->state = BOOTFLOWST_READY;
return 0;
}

-   /* To be implemented */
+   /* Enable this method if the "BootOrder" UEFI exists. */
+   bootorder = efi_get_var(u"BootOrder", _global_variable_guid,
+   );
+   if (bootorder) {
+   bflow->state = BOOTFLOWST_READY;
+   return 0;
+   }

return -EINVAL;
  }


There is no device-tree with compatible "u-boot,efi-bootmgr". So this
looks like dead code up to now. Please, provide a unit test.

@Simon
Where is the documentation that describes the "u-boot,distro-efi" and
"u-boot,efi-bootmgr" boot methods? Current
doc/device-tree-bindings/bootmeth.txt is not sufficient and not included
in the generated online documentation.

doc/device-tree-bindings/bootmeth.txt should be converted to yaml format
so that it can be used for validation of device-trees.

Best regards

Heinrich


[PATCH 3/3] usb: xhci-pci: Load ASMedia XHCI controller firmware

2023-07-14 Thread Mark Kettenis
The ASMedia XHCI controller found on some of the Apple Silicon
machines needs firmware to operate.  Use the file system
firmware loader interface to read the firmware and load it
onto the controller.  This allows keyboards connected to the
type-A ports on these machines to function in U-Boot.

Signed-off-by: Mark Kettenis 
---
 MAINTAINERS |   1 +
 drivers/usb/host/Kconfig|  11 +
 drivers/usb/host/Makefile   |   1 +
 drivers/usb/host/xhci-pci-asmedia.c | 394 
 drivers/usb/host/xhci-pci.c |   9 +
 include/usb/xhci.h  |   3 +
 6 files changed, 419 insertions(+)
 create mode 100644 drivers/usb/host/xhci-pci-asmedia.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 2477923a52..0acf04fff8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -124,6 +124,7 @@ F:  drivers/iommu/apple_dart.c
 F: drivers/nvme/nvme_apple.c
 F: drivers/pci/pcie_apple.c
 F: drivers/pinctrl/pinctrl-apple.c
+F: drivers/usb/host/xhci-pci-asmedia.c
 F: drivers/watchdog/apple_wdt.c
 F: include/configs/apple.h
 
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 1a883babf4..ad8dfabeeb 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -95,6 +95,17 @@ config USB_XHCI_PCI
help
  Enables support for the PCI-based xHCI controller.
 
+config USB_XHCI_PCI_ASMEDIA
+   bool "Support for ASMedia xHCI USB controller"
+   depends on USB_XHCI_PCI
+   default y if ARCH_APPLE
+   imply FS_LOADER
+   help
+ Enables support for loading firmware for the ASMedia xHCI
+ controller.  This is needed on Apple Silicon machines that
+ contain ASMedia xHCI controllers without the full USB
+ firmware.
+
 config USB_XHCI_RCAR
bool "Renesas RCar USB 3.0 support"
default y
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 8dad36f936..2aa2d80263 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o
 obj-$(CONFIG_USB_XHCI_MVEBU) += xhci-mvebu.o
 obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
+obj-$(CONFIG_USB_XHCI_PCI_ASMEDIA) += xhci-pci-asmedia.o
 obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
 obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
 obj-$(CONFIG_USB_XHCI_OCTEON) += dwc3-octeon-glue.o
diff --git a/drivers/usb/host/xhci-pci-asmedia.c 
b/drivers/usb/host/xhci-pci-asmedia.c
new file mode 100644
index 00..cc1d25bde2
--- /dev/null
+++ b/drivers/usb/host/xhci-pci-asmedia.c
@@ -0,0 +1,394 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * ASMedia xHCI firmware loader
+ * Copyright (C) The Asahi Linux Contributors
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Configuration space registers */
+#define ASMT_CFG_CONTROL   0xe0
+#define ASMT_CFG_CONTROL_WRITE BIT(1)
+#define ASMT_CFG_CONTROL_READ  BIT(0)
+
+#define ASMT_CFG_SRAM_ADDR 0xe2
+
+#define ASMT_CFG_SRAM_ACCESS   0xef
+#define ASMT_CFG_SRAM_ACCESS_READ  BIT(6)
+#define ASMT_CFG_SRAM_ACCESS_ENABLEBIT(7)
+
+#define ASMT_CFG_DATA_READ00xf0
+#define ASMT_CFG_DATA_READ10xf4
+
+#define ASMT_CFG_DATA_WRITE0   0xf8
+#define ASMT_CFG_DATA_WRITE1   0xfc
+
+#define ASMT_CMD_GET_FWVER 0x860840
+#define ASMT_FWVER_ROM 0x010250090816
+
+/* BAR0 registers */
+#define ASMT_REG_ADDR  0x3000
+
+#define ASMT_REG_WDATA 0x3004
+#define ASMT_REG_RDATA 0x3008
+
+#define ASMT_REG_STATUS0x3009
+#define ASMT_REG_STATUS_BUSY   BIT(7)
+
+#define ASMT_REG_CODE_WDATA0x3010
+#define ASMT_REG_CODE_RDATA0x3018
+
+#define ASMT_MMIO_CPU_MISC 0x500e
+#define ASMT_MMIO_CPU_MISC_CODE_RAM_WR BIT(0)
+
+#define ASMT_MMIO_CPU_MODE_NEXT0x5040
+#define ASMT_MMIO_CPU_MODE_CUR 0x5041
+
+#define ASMT_MMIO_CPU_MODE_RAM BIT(0)
+#define ASMT_MMIO_CPU_MODE_HALFSPEED   BIT(1)
+
+#define ASMT_MMIO_CPU_EXEC_CTRL0x5042
+#define ASMT_MMIO_CPU_EXEC_CTRL_RESET  BIT(0)
+#define ASMT_MMIO_CPU_EXEC_CTRL_HALT   BIT(1)
+
+#define TIMEOUT_USEC   1
+#define RESET_TIMEOUT_USEC 50
+
+static int asmedia_mbox_tx(struct udevice *pdev, u64 data)
+{
+   u8 op;
+   int i;
+
+   for (i = 0; i < TIMEOUT_USEC; i++) {
+   dm_pci_read_config8(pdev, ASMT_CFG_CONTROL, );
+   if (!(op & ASMT_CFG_CONTROL_WRITE))
+   break;
+   udelay(1);
+   }
+
+   if (op & ASMT_CFG_CONTROL_WRITE) {
+   dev_err(pdev,
+   "Timed out on mailbox tx: 0x%llx\n",
+   data);
+   return -ETIMEDOUT;
+   }
+
+   

[PATCH 2/3] iopoll: Add readb_poll_sleep_timeout

2023-07-14 Thread Mark Kettenis
Add a variant of readl_poll_sleep_timeout that reads a single
byte to match the readb_poll_timeout API that Linux has.

Signed-off-by: Mark Kettenis 
---
 include/linux/iopoll.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
index 0ee2bddaa8..89990e95e9 100644
--- a/include/linux/iopoll.h
+++ b/include/linux/iopoll.h
@@ -49,6 +49,9 @@
 #define readl_poll_sleep_timeout(addr, val, cond, sleep_us, timeout_us) \
readx_poll_sleep_timeout(readl, addr, val, cond, sleep_us, timeout_us)
 
+#define readb_poll_sleep_timeout(addr, val, cond, sleep_us, timeout_us) \
+   readx_poll_sleep_timeout(readb, addr, val, cond, sleep_us, timeout_us)
+
 #define readx_poll_timeout(op, addr, val, cond, timeout_us) \
read_poll_timeout(op, val, cond, false, timeout_us, addr)
 
-- 
2.41.0



[PATCH 1/3] apple: Set up file system firmware loader

2023-07-14 Thread Mark Kettenis
Find the appropriate EFI system partition on the internal NVMe
storage and set the U-Boot environment variables such that
the file system firmware loader can load firmware from it.

Signed-off-by: Mark Kettenis 
---
 arch/arm/mach-apple/board.c | 60 +
 1 file changed, 60 insertions(+)

diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c
index d501948118..7799a0f916 100644
--- a/arch/arm/mach-apple/board.c
+++ b/arch/arm/mach-apple/board.c
@@ -8,6 +8,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -539,6 +541,60 @@ u64 get_page_table_size(void)
return SZ_256K;
 }
 
+static char *asahi_esp_devpart(void)
+{
+   struct disk_partition info;
+   struct blk_desc *nvme_blk;
+   const char *uuid = NULL;
+   int devnum, len, p, part, ret;
+   static char devpart[64];
+   struct udevice *dev;
+   ofnode node;
+
+   if (devpart[0])
+   return devpart;
+
+   node = ofnode_path("/chosen");
+   if (ofnode_valid(node)) {
+   uuid = ofnode_get_property(node, "asahi,efi-system-partition",
+  );
+   }
+
+   nvme_scan_namespace();
+   for (devnum = 0, part = 0;; devnum++) {
+   nvme_blk = blk_get_devnum_by_uclass_id(UCLASS_NVME, devnum);
+   if (nvme_blk == NULL)
+   break;
+
+   dev = dev_get_parent(nvme_blk->bdev);
+   if (!device_is_compatible(dev, "apple,nvme-ans2"))
+   continue;
+
+   for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+   ret = part_get_info(nvme_blk, p, );
+   if (ret < 0)
+   break;
+
+   if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
+   if (uuid && strcasecmp(uuid, info.uuid) == 0) {
+   part = p;
+   break;
+   }
+   if (part == 0)
+   part = p;
+   }
+   }
+
+   if (part > 0)
+   break;
+   }
+
+   if (part > 0)
+   snprintf(devpart, sizeof(devpart), "%d:%d", devnum, part);
+
+   return devpart;
+}
+
 #define KERNEL_COMP_SIZE   SZ_128M
 
 int board_late_init(void)
@@ -546,6 +602,10 @@ int board_late_init(void)
struct lmb lmb;
u32 status = 0;
 
+   status |= env_set("storage_interface",
+ blk_get_uclass_name(UCLASS_NVME));
+   status |= env_set("fw_dev_part", asahi_esp_devpart());
+
lmb_init_and_reserve(, gd->bd, (void *)gd->fdt_blob);
 
/* somewhat based on the Linux Kernel boot requirements:
-- 
2.41.0



[PATCH 0/3] Load ASMedia XHCI controller firmware

2023-07-14 Thread Mark Kettenis
Some of the Apple desktop machine have a PCI ASMedia XHCI controller
that needs firmware to be uploaded to function.  This firmware is
placed on the EFI system partition by the Asahi installer.  So this
series sets up a file system firmware loader that reads from that
partition and ports the Linux driver that uploads this firmware to
the controller.  With this series, users can use USB devices (such
as a keyboard) when they are connected to USB ports handled by the
ASMedia XHCI controller.  This includes the type-A ports on the
M2 Mac mini for example.

Mark Kettenis (3):
  apple: Set up file system firmware loader
  iopoll: Add readb_poll_sleep_timeout
  usb: xhci-pci: Load ASMedia XHCI controller firmware

 MAINTAINERS |   1 +
 arch/arm/mach-apple/board.c |  60 +
 drivers/usb/host/Kconfig|  11 +
 drivers/usb/host/Makefile   |   1 +
 drivers/usb/host/xhci-pci-asmedia.c | 394 
 drivers/usb/host/xhci-pci.c |   9 +
 include/linux/iopoll.h  |   3 +
 include/usb/xhci.h  |   3 +
 8 files changed, 482 insertions(+)
 create mode 100644 drivers/usb/host/xhci-pci-asmedia.c

-- 
2.41.0



[PATCH] phy: Add support for the Apple Type-C PHY

2023-07-14 Thread Mark Kettenis
This is merely a dummy driver that makes sure the DWC3 XHCI driver
finds its reset and PHY controllers.  We rely on iBoot to set up
the PHY for us.

Signed-off-by: Mark Kettenis 
---
 MAINTAINERS |  1 +
 arch/arm/Kconfig|  1 +
 configs/apple_m1_defconfig  |  1 +
 drivers/phy/Kconfig | 10 +++
 drivers/phy/Makefile|  1 +
 drivers/phy/phy-apple-atc.c | 56 +
 6 files changed, 70 insertions(+)
 create mode 100644 drivers/phy/phy-apple-atc.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 2477923a52..ebe7305395 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -123,6 +123,7 @@ F:  configs/apple_m1_defconfig
 F: drivers/iommu/apple_dart.c
 F: drivers/nvme/nvme_apple.c
 F: drivers/pci/pcie_apple.c
+F: drivers/phy/phy-apple-atc.c
 F: drivers/pinctrl/pinctrl-apple.c
 F: drivers/watchdog/apple_wdt.c
 F: include/configs/apple.h
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 99264a6478..bcfce8ed86 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1011,6 +1011,7 @@ config ARCH_APPLE
select OF_BOARD_SETUP
select OF_CONTROL
select PCI
+   select PHY
select PINCTRL
select POSITION_INDEPENDENT
select POWER_DOMAIN
diff --git a/configs/apple_m1_defconfig b/configs/apple_m1_defconfig
index 755560971e..d58a9030db 100644
--- a/configs/apple_m1_defconfig
+++ b/configs/apple_m1_defconfig
@@ -16,6 +16,7 @@ CONFIG_NVME_APPLE=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_DWC3=y
 CONFIG_USB_XHCI_PCI=y
+CONFIG_USB_DWC3=y
 CONFIG_USB_KEYBOARD=y
 CONFIG_SYS_WHITE_ON_BLACK=y
 CONFIG_NO_FB_CLEAR=y
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 7a2d54f71d..8ac5769ed9 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -70,6 +70,16 @@ config AB8500_USB_PHY
help
  Support for the USB OTG PHY in ST-Ericsson AB8500.
 
+config APPLE_ATCPHY
+   bool "Apple Type-C PHY Driver"
+   depends on PHY && ARCH_APPLE
+   default y
+   help
+ Support for the Apple Type-C PHY.
+
+This is a dummy driver since the PHY is initialized
+sufficiently by previous stage firmware.
+
 config BCM6318_USBH_PHY
bool "BCM6318 USBH PHY support"
depends on PHY && ARCH_BMIPS
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index aca365d219..5d4de86e71 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_$(SPL_)PHY) += phy-uclass.o
 obj-$(CONFIG_$(SPL_)NOP_PHY) += nop-phy.o
 obj-$(CONFIG_MIPI_DPHY_HELPERS) += phy-core-mipi-dphy.o
 obj-$(CONFIG_AB8500_USB_PHY) += phy-ab8500-usb.o
+obj-$(CONFIG_APPLE_ATCPHY) += phy-apple-atc.o
 obj-$(CONFIG_BCM6318_USBH_PHY) += bcm6318-usbh-phy.o
 obj-$(CONFIG_BCM6348_USBH_PHY) += bcm6348-usbh-phy.o
 obj-$(CONFIG_BCM6358_USBH_PHY) += bcm6358-usbh-phy.o
diff --git a/drivers/phy/phy-apple-atc.c b/drivers/phy/phy-apple-atc.c
new file mode 100644
index 00..15c5b8a1c2
--- /dev/null
+++ b/drivers/phy/phy-apple-atc.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 Mark Kettenis 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const struct phy_ops apple_atcphy_ops = {
+};
+
+static struct driver apple_atcphy_driver = {
+   .name = "apple-atcphy",
+   .id = UCLASS_PHY,
+   .ops = _atcphy_ops,
+};
+
+static int apple_atcphy_reset_of_xlate(struct reset_ctl *reset_ctl,
+  struct ofnode_phandle_args *args)
+{
+   if (args->args_count != 0)
+   return -EINVAL;
+
+   return 0;
+}
+
+static const struct reset_ops apple_atcphy_reset_ops = {
+   .of_xlate = apple_atcphy_reset_of_xlate,
+};
+
+static int apple_atcphy_reset_probe(struct udevice *dev)
+{
+   struct udevice *child;
+
+   device_bind(dev, _atcphy_driver, "apple-atcphy", NULL,
+   dev_ofnode(dev), );
+
+   return 0;
+}
+
+static const struct udevice_id apple_atcphy_ids[] = {
+   { .compatible = "apple,t6000-atcphy" },
+   { .compatible = "apple,t8103-atcphy" },
+   { }
+};
+
+U_BOOT_DRIVER(apple_atcphy_reset) = {
+   .name = "apple-atcphy-reset",
+   .id = UCLASS_RESET,
+   .of_match = apple_atcphy_ids,
+   .ops = _atcphy_reset_ops,
+   .probe = apple_atcphy_reset_probe,
+};
-- 
2.41.0



Re: [PATCH] bootstd: Make efi_mgr bootmeth work for non-sandbox setups

2023-07-14 Thread Heinrich Schuchardt



Am 14. Juli 2023 21:56:02 MESZ schrieb Mark Kettenis :
>Enable the bootflow based on this bootmeth if the BootOrder EFI
>variable is set.
>
>Signed-off-by: Mark Kettenis 
>---
> boot/bootmeth_efi_mgr.c | 12 +++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
>diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
>index e9d973429f..db650861ff 100644
>--- a/boot/bootmeth_efi_mgr.c
>+++ b/boot/bootmeth_efi_mgr.c
>@@ -14,6 +14,8 @@
> #include 
> #include 
> #include 
>+#include 
>+#include 
> 
> /**
>  * struct efi_mgr_priv - private info for the efi-mgr driver
>@@ -46,13 +48,21 @@ static int efi_mgr_check(struct udevice *dev, struct 
>bootflow_iter *iter)
> static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
> {
>   struct efi_mgr_priv *priv = dev_get_priv(dev);
>+  efi_uintn_t size;
>+  u16 *bootorder;
> 
>   if (priv->fake_dev) {
>   bflow->state = BOOTFLOWST_READY;
>   return 0;
>   }
> 
>-  /* To be implemented */
>+  /* Enable this method if the "BootOrder" UEFI exists. */
>+  bootorder = efi_get_var(u"BootOrder", _global_variable_guid,
>+  );

Are EFI variables already loaded when you hit this code?

Even if the variable Boot Order is not set we must boot EFI/BOOT/BOOT.EFI.

Best regards

Heinrich 



>+  if (bootorder) {
>+  bflow->state = BOOTFLOWST_READY;
>+  return 0;
>+  }
> 
>   return -EINVAL;
> }


[PATCH] bootstd: Make efi_mgr bootmeth work for non-sandbox setups

2023-07-14 Thread Mark Kettenis
Enable the bootflow based on this bootmeth if the BootOrder EFI
variable is set.

Signed-off-by: Mark Kettenis 
---
 boot/bootmeth_efi_mgr.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
index e9d973429f..db650861ff 100644
--- a/boot/bootmeth_efi_mgr.c
+++ b/boot/bootmeth_efi_mgr.c
@@ -14,6 +14,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,21 @@ static int efi_mgr_check(struct udevice *dev, struct 
bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
struct efi_mgr_priv *priv = dev_get_priv(dev);
+   efi_uintn_t size;
+   u16 *bootorder;
 
if (priv->fake_dev) {
bflow->state = BOOTFLOWST_READY;
return 0;
}
 
-   /* To be implemented */
+   /* Enable this method if the "BootOrder" UEFI exists. */
+   bootorder = efi_get_var(u"BootOrder", _global_variable_guid,
+   );
+   if (bootorder) {
+   bflow->state = BOOTFLOWST_READY;
+   return 0;
+   }
 
return -EINVAL;
 }
-- 
2.41.0



Re: [PATCH 1/2] cmd: thordown: Add proper dependency for CMD_THOR_DOWNLOAD

2023-07-14 Thread Tom Rini
On Sun, Jul 09, 2023 at 07:09:57AM -0600, Ashok Reddy Soma wrote:
> When CONFIG_CMD_USB and CONFIG_USB are disabled some compilation errors
> are seen as below.
> 
> cmd/thordown.o: in function `usb_gadget_initialize':
> include/linux/usb/gadget.h:981: undefined reference to `board_usb_init'
> cmd/thordown.o: in function `do_thor_down':
> cmd/thordown.c:68: undefined reference to `g_dnl_unregister'
> cmd/thordown.o: in function `usb_gadget_release':
> include/linux/usb/gadget.h:986: undefined reference to `board_usb_cleanup'
> cmd/thordown.o: in function `do_thor_down':
> cmd/thordown.c:41: undefined reference to `g_dnl_register'
> cmd/thordown.c:48: undefined reference to `thor_init'
> cmd/thordown.c:56: undefined reference to `thor_handle'
> gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-ld.bfd: line 4:  8485
> Segmentation fault  (core dumped) $CC --sysroot=$LIBC
> --no-warn-rwx-segment "$@"
> Makefile:1779: recipe for target 'u-boot' failed
> make: *** [u-boot] Error 139
> make: *** Deleting file 'u-boot'
> 
> Add dependency of CMD_USB for CONFIG_CMD_THOR_DOWNLOAD to fix the errors.
> 
> Signed-off-by: Ashok Reddy Soma 
> ---
> 
>  cmd/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 02e54f1e50..b44df9d67a 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -526,6 +526,7 @@ config CMD_SPL_WRITE_SIZE
>  
>  config CMD_THOR_DOWNLOAD
>   bool "thor - TIZEN 'thor' download"
> + depends on CMD_USB
>   select DFU
>   help
> Implements the 'thor' download protocol. This is a way of

This isn't right, and removes the command from s5p_goni. The issue is
that CMD_USB is for host support, and this is a gadget command. Likely
the best answer is to make this depend on USB_FUNCTION_THOR, or select
USB_FUNCTION_THOR but depend on USB_GADGET_DOWNLOAD.

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] pci: apple: Enable CONFIG_SYS_PCI_64BIT

2023-07-14 Thread Mark Kettenis
The Apple hardware supports 64-bit prefetchable memory windows so
enable CONFIG_SYS_PCI_64BIT. This fixes BAR assignments for the
Broadcom Ethernet controller used in some of the desktop machines.

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

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index ef328d2652..126ef5dd12 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -109,6 +109,7 @@ config PCIE_APPLE
bool "Enable Apple PCIe driver"
depends on ARCH_APPLE
imply PCI_INIT_R
+   select SYS_PCI_64BIT
default y
help
  Say Y here if you want to enable PCIe controller support on
-- 
2.41.0



[PATCH] configs: k2x_evm: Always include FIT loading support

2023-07-14 Thread Andrew Davis
Non-HS boards can use FIT images so include the env var commands
for these unconditionally.

Signed-off-by: Andrew Davis 
---
 include/configs/k2e_evm.h  | 11 ++-
 include/configs/k2hk_evm.h | 11 ++-
 include/configs/k2l_evm.h  | 11 ++-
 3 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/include/configs/k2e_evm.h b/include/configs/k2e_evm.h
index 929c9a26de1..630dfdc5b7f 100644
--- a/include/configs/k2e_evm.h
+++ b/include/configs/k2e_evm.h
@@ -11,18 +11,11 @@
 
 #include 
 
-#ifdef CONFIG_TI_SECURE_DEVICE
-#define DEFAULT_SEC_BOOT_ENV   \
-   DEFAULT_FIT_TI_ARGS \
-   "findfdt=setenv fdtfile ${name_fdt}\0"
-#else
-#define DEFAULT_SEC_BOOT_ENV
-#endif
-
 /* U-Boot general configuration */
 #define ENV_KS2_BOARD_SETTINGS \
DEFAULT_FW_INITRAMFS_BOOT_ENV   \
-   DEFAULT_SEC_BOOT_ENV\
+   DEFAULT_FIT_TI_ARGS \
+   "findfdt=setenv fdtfile ${name_fdt}\0"  \
"boot=ubi\0"\
"args_ubi=setenv bootargs ${bootargs} rootfstype=ubifs "\
"root=ubi0:rootfs rootflags=sync rw ubi.mtd=ubifs,2048\0"   \
diff --git a/include/configs/k2hk_evm.h b/include/configs/k2hk_evm.h
index 05b4a3c204d..ed54be839ff 100644
--- a/include/configs/k2hk_evm.h
+++ b/include/configs/k2hk_evm.h
@@ -11,18 +11,11 @@
 
 #include 
 
-#ifdef CONFIG_TI_SECURE_DEVICE
-#define DEFAULT_SEC_BOOT_ENV   \
-   DEFAULT_FIT_TI_ARGS \
-   "findfdt=setenv fdtfile ${name_fdt}\0"
-#else
-#define DEFAULT_SEC_BOOT_ENV
-#endif
-
 /* U-Boot general configuration */
 #define ENV_KS2_BOARD_SETTINGS \
DEFAULT_FW_INITRAMFS_BOOT_ENV   \
-   DEFAULT_SEC_BOOT_ENV\
+   DEFAULT_FIT_TI_ARGS \
+   "findfdt=setenv fdtfile ${name_fdt}\0"  \
"boot=ubi\0"\
"args_ubi=setenv bootargs ${bootargs} rootfstype=ubifs "\
"root=ubi0:rootfs rootflags=sync rw ubi.mtd=ubifs,2048\0"   \
diff --git a/include/configs/k2l_evm.h b/include/configs/k2l_evm.h
index b1b839b5043..69d42eaf9f1 100644
--- a/include/configs/k2l_evm.h
+++ b/include/configs/k2l_evm.h
@@ -11,18 +11,11 @@
 
 #include 
 
-#ifdef CONFIG_TI_SECURE_DEVICE
-#define DEFAULT_SEC_BOOT_ENV   \
-   DEFAULT_FIT_TI_ARGS \
-   "findfdt=setenv fdtfile ${name_fdt}\0"
-#else
-#define DEFAULT_SEC_BOOT_ENV
-#endif
-
 /* U-Boot general configuration */
 #define ENV_KS2_BOARD_SETTINGS \
DEFAULT_FW_INITRAMFS_BOOT_ENV   \
-   DEFAULT_SEC_BOOT_ENV\
+   DEFAULT_FIT_TI_ARGS \
+   "findfdt=setenv fdtfile ${name_fdt}\0"  \
"boot=ubi\0"\
"args_ubi=setenv bootargs ${bootargs} rootfstype=ubifs "\
"root=ubi0:rootfs rootflags=sync rw ubi.mtd=ubifs,4096\0"   \
-- 
2.39.2



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

2023-07-14 Thread Detlev Casanova
On Friday, July 14, 2023 1:33:01 P.M. EDT Marek Vasut wrote:
> On 7/14/23 18:43, Detlev Casanova wrote:
> > To be used with the sysinfo command, revision values must be considered
> > as integers, not chars as some boards will implement BOARD_REVISION_*
> > and might use numbers greater than 9.
> > 
> > Signed-off-by: Detlev Casanova 
> > ---
> > 
> >   drivers/sysinfo/rcar3.c | 104 
> >   1 file changed, 62 insertions(+), 42 deletions(-)
> > 
> > diff --git a/drivers/sysinfo/rcar3.c b/drivers/sysinfo/rcar3.c
> > index 7b127986da7..450a4c26773 100644
> > --- a/drivers/sysinfo/rcar3.c
> > +++ b/drivers/sysinfo/rcar3.c
> > @@ -68,90 +68,110 @@ static void sysinfo_rcar_parse(struct
> > sysinfo_rcar_priv *priv)> 
> > bool salvator_xs = false;
> > bool ebisu_4d = false;
> > bool condor_i = false;
> > 
> > -   char rev_major = '?';
> > -   char rev_minor = '?';
> > +   char model[64];
> > +   char rev[4] = "?.?";
> > +   u8 rev_major = 0;
> > +   u8 rev_minor = 0;
> > 
> > switch (board_id) {
> > 
> > case BOARD_SALVATOR_XS:
> > salvator_xs = true;
> > fallthrough;
> > 
> > case BOARD_SALVATOR_X:
> > +   snprintf(model, sizeof(model),
> > +"Renesas Salvator-X%s board", salvator_xs ? 
"S" : "");
> > 
> > if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid 
*/
> > 
> > -   rev_major = '1';
> > -   rev_minor = '0' + (board_rev & BIT(0));
> > +   rev_major = 1;
> > +   rev_minor = board_rev & BIT(0);
> > +   snprintf(rev, sizeof(rev), "%u.%u", 
rev_major, rev_minor);
> > 
> > }
> > 
> > -   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
> > -"Renesas Salvator-X%s board rev %c.%c",
> > -salvator_xs ? "S" : "", rev_major, 
rev_minor);
> > +
> > +   snprintf(priv->boardmodel, sizeof(priv->boardmodel), 
"%s rev %s",
> > +model, rev);
> 
> Is there really no way to do this with single snprintf() call instead of
> two snprintf() calls ?

I find it more readable like this, as opposed to have an snprintf in the if and 
one in an else block for each switch case.





Re: [PATCH 1/2] schemas: Add firmware node schema

2023-07-14 Thread Simon Glass
Hi Rob,

On Fri, 14 Jul 2023 at 10:58, Rob Herring  wrote:
>
> On Tue, Jul 11, 2023 at 3:18 PM Simon Glass  wrote:
> >
> > Add a motivation and purpose for this new proposed node.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  dtschema/schemas/firmware.yaml | 83 ++
> >  1 file changed, 83 insertions(+)
> >  create mode 100644 dtschema/schemas/firmware.yaml
> >
> > diff --git a/dtschema/schemas/firmware.yaml b/dtschema/schemas/firmware.yaml
> > new file mode 100644
> > index 000..4439a70
> > --- /dev/null
> > +++ b/dtschema/schemas/firmware.yaml
> > @@ -0,0 +1,83 @@
> > +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-clause
> > +# Copyright 2023 Google LLC
> > +#
> > +
> > +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/firmware.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: /firmware Node
> > +
> > +maintainers:
> > +  - Simon Glass 
> > +
> > +description: |
> > +  The '/firmware' node does not represent a real device, but serves as a 
> > place
> > +  for recording information about the main firmware used on the device, 
> > such as
> > +  a map of its contents. This is used by the Operating System (OS), user 
> > space
> > +  programs and possibly other firmware components. Data in the '/firmware' 
> > node
> > +  does not itself represent the hardware.
> > +
> > +  Properties in this node should be common to (and used by) at least two
> > +  firmware projects, such as U-Boot and TF-A. Project-specific subnodes 
> > can be
> > +  used for properties which are specific to a single project.
> > +
> > +  Purpose of '/firmware' node
> > +  ---
> > +
> > +  Firmware has traditionally been fairly opaque to the OS, with the OS 
> > taking
> > +  no interest in its contents, version, layout or how it might be updated. 
> > This
> > +  is less than ideal, since firmware is an important part of the system and
> > +  visibility into its operation is every bit as important as visbility 
> > into the
> > +  OS and user-space programs within the system.
> > +
> > +  The traditional approach has been to let firmware deal with firmware, 
> > and the
> > +  OS deal with everything else. Updating firmware has been handled by 
> > firmware.
> > +  For example, the UEFI spec defines a way for the OS to post a 'capsule' 
> > which
> > +  is discovered next time the system boots, permitting firmware updates. 
> > But
> > +  firmware updates in firmware are highly problematic. They require a 
> > reboot
> > +  and a sometimes-lengthy wait with a strange-looking interface unfamiliar
> > +  to most users. It seems better to make the update as transparent as 
> > possible
> > +  to the user. As an example of that, ChromeOS has full knowledge of the
> > +  firmware version and layout, updates it in the background from user 
> > space and
> > +  instantly selects the new firmware when the user reboots or logs out.
>
> Perhaps if OS based firmware updates are useful, then UEFI should gain
> that capability rather than inventing some way to do it with DT. Seems
> like a worthy goal, just needs wider review IMO.

Perhaps it should, although it would involve changing the spec, etc.
In any case it would be a very strange world if we mandated UEFI
everywhere.

Yes I am looking for wider review, partly since the work to document
all the firmware-image complexity is happening mostly in U-Boot at
present.

>
> > +  A common objection to considering the system holistically is that some 
> > parts
> > +  of the system are inaccessible to the OS, such as a secure enclave. 
> > However
> > +  this does not preclude providing visibility into what is present in that
> > +  enclave. Firmware-version information is still useful. Firmware updates 
> > are
> > +  still needed and can still be initiated from user space.
> > +
> > +  Another objection is that firmware should provide an interface to the OS,
> > +  while keeping its structure private. This thinking is largely driven by
> > +  extrapolating from how firmware has been handled in the 'BIOS' days.
>
> It's also the case that the OS may not have direct access to the h/w needed.

I tried to cover that in the paragraph you quote immediately
above...what is missing?

>
> > +  It should be considered a degenerate case rather than the norm. As 
> > complexity
> > +  increases, it creates an artificial boundary between two pieces of the 
> > whole.
> > +  Mechanisms then need to be invented to cross this unnecessary chasm. An
> > +  example of this is Intel's Dynamic Platform and Thermal Framework (DPTF),
> > +  which consists of user-space, OS and firmware components all working 
> > towards
> > +  a shared goal. We need a standard description of these cross-system 
> > pieces.
> > +
> > +  In order to 'teach the OS about firmware', we need a place to put this
> > +  information. That is the purpose of this node.
> > +
> > +  In an Open Source world the entire model of firmware 

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

2023-07-14 Thread Marek Vasut

On 7/14/23 18:43, Detlev Casanova wrote:

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

Signed-off-by: Detlev Casanova 
---
  drivers/sysinfo/rcar3.c | 104 
  1 file changed, 62 insertions(+), 42 deletions(-)

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

case BOARD_SALVATOR_XS:
salvator_xs = true;
fallthrough;
case BOARD_SALVATOR_X:
+   snprintf(model, sizeof(model),
+"Renesas Salvator-X%s board", salvator_xs ? "S" : "");
if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
-   rev_major = '1';
-   rev_minor = '0' + (board_rev & BIT(0));
+   rev_major = 1;
+   rev_minor = board_rev & BIT(0);
+   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
}
-   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
-"Renesas Salvator-X%s board rev %c.%c",
-salvator_xs ? "S" : "", rev_major, rev_minor);
+
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel), "%s rev 
%s",
+model, rev);


Is there really no way to do this with single snprintf() call instead of 
two snprintf() calls ?


Re: [PATCH v3 4/6] sysinfo: Add documentation

2023-07-14 Thread Marek Vasut

On 7/14/23 18:43, Detlev Casanova wrote:

[...]


+Return value
+
+
+The return value $? is set to 0 (true) if the command succededd


succeeded -- typo

. If an

+error occurs, the return value $? is set to 1 (false).


With that fixed:

Reviewed-by: Marek Vasut 


Re: [PATCH v3 3/6] sysinfo: Add a test

2023-07-14 Thread Marek Vasut

On 7/14/23 18:43, Detlev Casanova wrote:

The test runs one of each subcommand and checks that the output matches
the values in the sandbox sysinfo driver.

Signed-off-by: Detlev Casanova 


Nice

Reviewed-by: Marek Vasut 


Re: [PATCH v3 2/6] cmd: Add a sysinfo command

2023-07-14 Thread Marek Vasut

On 7/14/23 18:43, Detlev Casanova wrote:

The command is able to show different information for the running
system:
* Model name
* Board ID
* Revision

This command can be used by boot shell scripts to select configurations
depending on the specific running system.

Signed-off-by: Detlev Casanova 


Reviewed-by: Marek Vasut 


Re: [PATCH v3 1/6] sysinfo: Add IDs for board id and revision

2023-07-14 Thread Marek Vasut

On 7/14/23 18:43, Detlev Casanova wrote:

These IDs will be used by the sysinfo command. The new IDs are:
  * SYSINFO_ID_BOARD_ID: The board ID as an integer
  * SYSINFO_ID_BOARD_REV_MAJOR: The board major revision as int
  * SYSINFO_ID_BOARD_REV_MINOR: The board minor revision as int

Signed-off-by: Detlev Casanova 


Reviewed-by: Marek Vasut 


Re: [PATCH v3 00/18] bootstd: Add a bootmeth for ChromiumOS on x86

2023-07-14 Thread Tom Rini
On Fri, Jul 14, 2023 at 05:29:40PM +0800, Bin Meng wrote:
> Hi Simon,
> 
> On Thu, Jul 13, 2023 at 9:14 PM Bin Meng  wrote:
> >
> > On Wed, Jul 12, 2023 at 11:04 PM Simon Glass  wrote:
> > >
> > > This series adds a simple bootmeth for ChromiumOS on x86. It uses zimage
> > > to boot the kernel.
> > >
> > > Full verified boot is not included at this stage - that is still a
> > > separate chunk of code to be brought into standard boot at some point.
> > > For now it just obtains the kernel and command line and boots. This should
> > > be enough to boot Chrome OS from coreboot on all x86 machines in
> > > circulation, although only Brya (2022) and Coral (2017) have been tested.
> > >
> > > ChromiumOS needs quite large kernel parameters, to hold the DM verity
> > > settings and other pieces. This makes it painful to modify just one
> > > parameter, since the whole cmdline must be adjusted at once. To cope with
> > > this, a new cmdline-editing feature is provided: the 'bootflow cmdline'
> > > command allows individual parameters to be added, modified and deleted.
> > >
> > > To deal with enabling debug console, a variant supports setting 'earlycon'
> > > and 'console' automatically. The 'bdinfo' command is updated to show
> > > serial-port info also.
> > >
> > > Booting the zimage is now done programmatically, rather than running
> > > through the command-line interface. Minor tweaks are made to the coreboot
> > > and coral config so that booting works correctly.
> > >
> > > Note that the ACPI tables are not updated with the required firmware
> > > information in this series, so a warning is shown on boot. This will be
> > > addressed later since it requires quite a bit of configuration.
> > >
> > > Finally, this fixes a recently introduced bug in unit testing and updates
> > > the algorithm to avoid running flat-tree tests which don't actually use
> > > the devicetree.
> > >
> > > Changes in v3:
> > > - Drop CONFIG_MISC and CONFIG_NVMEM
> > > - Update commit message
> > > - Separate out patch to restore test behaviour on failure
> > >
> >
> > series applied to u-boot-x86, thanks!
> 
> Could you please look at the CI failure?
> https://source.denx.de/u-boot/custodians/u-boot-x86/-/pipelines/16890/failures

I _think_ if you rebase on master this should be fixed with
https://patchwork.ozlabs.org/project/uboot/patch/20230712024632.2365887-1-...@chromium.org/
applied.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] bdinfo: Correct use of assertions

2023-07-14 Thread Tom Rini
On Tue, 11 Jul 2023 20:46:30 -0600, Simon Glass wrote:

> This test was written for the incorrect use of assertions. Update it to
> build with the previous approach, where tests fail at the first
> assertion.
> 
> All assertion functions return 0 on success and non-zero on failure.
> They can be nested into functions simply by declaring a function that
> returns an int and using ut_assertok() to call it.
> 
> [...]

Applied to u-boot/master, thanks!

-- 
Tom



Re: [PATCH 00/40] expo: Add an initial configuration editor

2023-07-14 Thread Tom Rini
On Thu, 01 Jun 2023 10:22:24 -0600, Simon Glass wrote:

> This series provides a means to edit board configuration in U-Boot in a
> graphical manner. It supports multiple menu items and allows moving
> between them and selecting items. The configuration is defined in a
> data format so that code is not needed in most cases. This allows the
> board configuration to be provided in the devicetree.
> 
> This is still at an early stage, since it only supports menus. Numeric
> values are not supported. Most importantly it does not yet support
> loading or saving the configuration selected by the user.
> 
> [...]

Applied to u-boot/master, thanks!

-- 
Tom



[PATCH] crc32: Drop duplicates crc header includes

2023-07-14 Thread Ilya Lukin
Fixes: 3db711085752 ("crc32: Use the crc.h header for crc functions")
Signed-off-by: Ilya Lukin <4.sh...@gmail.com>
---
 board/sunxi/board.c   | 1 -
 boot/android_ab.c | 1 -
 common/hash.c | 1 -
 lib/crc32.c   | 1 -
 tools/default_image.c | 1 -
 5 files changed, 5 deletions(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index f321cd58a6..de0f3505e5 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -33,7 +33,6 @@
 #include 
 #include 
 #include 
-#include 
 #ifndef CONFIG_ARM64
 #include 
 #endif
diff --git a/boot/android_ab.c b/boot/android_ab.c
index 2d7b392666..271df273e1 100644
--- a/boot/android_ab.c
+++ b/boot/android_ab.c
@@ -12,7 +12,6 @@
 #include 
 #include 
 #include 
-#include 
 
 /**
  * Compute the CRC-32 of the bootloader control struct.
diff --git a/common/hash.c b/common/hash.c
index 9a52d6073c..7d8ec75318 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 #else
 #include "mkimage.h"
 #include 
diff --git a/lib/crc32.c b/lib/crc32.c
index aa94d70ef3..f6fad8c15d 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -10,7 +10,6 @@
 
 #ifdef USE_HOSTCC
 #include 
-#include 
 #else
 #include 
 #include 
diff --git a/tools/default_image.c b/tools/default_image.c
index 0e49ab3301..04bc85bf93 100644
--- a/tools/default_image.c
+++ b/tools/default_image.c
@@ -15,7 +15,6 @@
 
 #include "imagetool.h"
 #include "mkimage.h"
-#include 
 
 #include 
 #include 
-- 
2.40.1



Re: [PATCH 1/2] schemas: Add firmware node schema

2023-07-14 Thread Rob Herring
On Tue, Jul 11, 2023 at 3:18 PM Simon Glass  wrote:
>
> Add a motivation and purpose for this new proposed node.
>
> Signed-off-by: Simon Glass 
> ---
>
>  dtschema/schemas/firmware.yaml | 83 ++
>  1 file changed, 83 insertions(+)
>  create mode 100644 dtschema/schemas/firmware.yaml
>
> diff --git a/dtschema/schemas/firmware.yaml b/dtschema/schemas/firmware.yaml
> new file mode 100644
> index 000..4439a70
> --- /dev/null
> +++ b/dtschema/schemas/firmware.yaml
> @@ -0,0 +1,83 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-clause
> +# Copyright 2023 Google LLC
> +#
> +
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/firmware.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: /firmware Node
> +
> +maintainers:
> +  - Simon Glass 
> +
> +description: |
> +  The '/firmware' node does not represent a real device, but serves as a 
> place
> +  for recording information about the main firmware used on the device, such 
> as
> +  a map of its contents. This is used by the Operating System (OS), user 
> space
> +  programs and possibly other firmware components. Data in the '/firmware' 
> node
> +  does not itself represent the hardware.
> +
> +  Properties in this node should be common to (and used by) at least two
> +  firmware projects, such as U-Boot and TF-A. Project-specific subnodes can 
> be
> +  used for properties which are specific to a single project.
> +
> +  Purpose of '/firmware' node
> +  ---
> +
> +  Firmware has traditionally been fairly opaque to the OS, with the OS taking
> +  no interest in its contents, version, layout or how it might be updated. 
> This
> +  is less than ideal, since firmware is an important part of the system and
> +  visibility into its operation is every bit as important as visbility into 
> the
> +  OS and user-space programs within the system.
> +
> +  The traditional approach has been to let firmware deal with firmware, and 
> the
> +  OS deal with everything else. Updating firmware has been handled by 
> firmware.
> +  For example, the UEFI spec defines a way for the OS to post a 'capsule' 
> which
> +  is discovered next time the system boots, permitting firmware updates. But
> +  firmware updates in firmware are highly problematic. They require a reboot
> +  and a sometimes-lengthy wait with a strange-looking interface unfamiliar
> +  to most users. It seems better to make the update as transparent as 
> possible
> +  to the user. As an example of that, ChromeOS has full knowledge of the
> +  firmware version and layout, updates it in the background from user space 
> and
> +  instantly selects the new firmware when the user reboots or logs out.

Perhaps if OS based firmware updates are useful, then UEFI should gain
that capability rather than inventing some way to do it with DT. Seems
like a worthy goal, just needs wider review IMO.

> +  A common objection to considering the system holistically is that some 
> parts
> +  of the system are inaccessible to the OS, such as a secure enclave. However
> +  this does not preclude providing visibility into what is present in that
> +  enclave. Firmware-version information is still useful. Firmware updates are
> +  still needed and can still be initiated from user space.
> +
> +  Another objection is that firmware should provide an interface to the OS,
> +  while keeping its structure private. This thinking is largely driven by
> +  extrapolating from how firmware has been handled in the 'BIOS' days.

It's also the case that the OS may not have direct access to the h/w needed.

> +  It should be considered a degenerate case rather than the norm. As 
> complexity
> +  increases, it creates an artificial boundary between two pieces of the 
> whole.
> +  Mechanisms then need to be invented to cross this unnecessary chasm. An
> +  example of this is Intel's Dynamic Platform and Thermal Framework (DPTF),
> +  which consists of user-space, OS and firmware components all working 
> towards
> +  a shared goal. We need a standard description of these cross-system pieces.
> +
> +  In order to 'teach the OS about firmware', we need a place to put this
> +  information. That is the purpose of this node.
> +
> +  In an Open Source world the entire model of firmware needs to adjust to be
> +  more open, more visible and managed just like any other part of the system.
> +  The major goal is to standardise how firmware is presented to the OS and 
> user
> +  space, so that common utilities can be used to manage the entire system,
> +  including the firmware. For example, fwupd can look in this node for
> +  information on how to update the firmware, similar to how VBE works. [1]
> +  It is likely that other purposes will come to light over time.

It's good we're documenting /firmware, but your use seems different to
what's already in place. Generally, /firmware has been for providers
which are implemented by firmware and are not on any 

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

2023-07-14 Thread Detlev Casanova
Expose that information to the sysinfo command to let scripts make
decisions based on the board id and revision.

Signed-off-by: Detlev Casanova 
---
 drivers/sysinfo/rcar3.c | 103 +++-
 1 file changed, 70 insertions(+), 33 deletions(-)

diff --git a/drivers/sysinfo/rcar3.c b/drivers/sysinfo/rcar3.c
index 450a4c26773..1a99642bf75 100644
--- a/drivers/sysinfo/rcar3.c
+++ b/drivers/sysinfo/rcar3.c
@@ -32,6 +32,10 @@
  */
 struct sysinfo_rcar_priv {
charboardmodel[64];
+   u8  id;
+   u8  rev_major;
+   u8  rev_minor;
+   boolhas_rev;
u8  val;
 };
 
@@ -56,9 +60,33 @@ static int sysinfo_rcar_get_str(struct udevice *dev, int id, 
size_t size, char *
};
 }
 
+static int sysinfo_rcar_get_int(struct udevice *dev, int id, int *val)
+{
+   struct sysinfo_rcar_priv *priv = dev_get_priv(dev);
+
+   switch (id) {
+   case SYSINFO_ID_BOARD_ID:
+   *val = priv->id;
+   return 0;
+   case SYSINFO_ID_BOARD_REVISION_MAJOR:
+   if (!priv->has_rev)
+   return -EINVAL;
+   *val = priv->rev_major;
+   return 0;
+   case SYSINFO_ID_BOARD_REVISION_MINOR:
+   if (!priv->has_rev)
+   return -EINVAL;
+   *val = priv->rev_minor;
+   return 0;
+   default:
+   return -EINVAL;
+   };
+}
+
 static const struct sysinfo_ops sysinfo_rcar_ops = {
.detect = sysinfo_rcar_detect,
.get_str = sysinfo_rcar_get_str,
+   .get_int = sysinfo_rcar_get_int,
 };
 
 static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
@@ -70,8 +98,9 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
bool condor_i = false;
char model[64];
char rev[4] = "?.?";
-   u8 rev_major = 0;
-   u8 rev_minor = 0;
+
+   priv->id = board_id;
+   priv->has_rev = false;
 
switch (board_id) {
case BOARD_SALVATOR_XS:
@@ -81,9 +110,10 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv 
*priv)
snprintf(model, sizeof(model),
 "Renesas Salvator-X%s board", salvator_xs ? "S" : "");
if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
-   rev_major = 1;
-   rev_minor = board_rev & BIT(0);
-   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
+   priv->rev_major = 1;
+   priv->rev_minor = board_rev & BIT(0);
+   priv->has_rev = true;
+   snprintf(rev, sizeof(rev), "%u.%u", priv->rev_major, 
priv->rev_minor);
}
 
snprintf(priv->boardmodel, sizeof(priv->boardmodel), "%s rev 
%s",
@@ -91,34 +121,37 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv 
*priv)
 
return;
case BOARD_STARTER_KIT:
-   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
+   snprintf(model, sizeof(model),
 "Renesas Starter Kit board");
if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
-   rev_major = (board_rev & BIT(0)) ? 3 : 1;
-   rev_minor = 0;
-   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
+   priv->rev_major = (board_rev & BIT(0)) ? 3 : 1;
+   priv->rev_minor = 0;
+   snprintf(rev, sizeof(rev), "%u.%u", priv->rev_major, 
priv->rev_minor);
+   priv->has_rev = true;
}
snprintf(priv->boardmodel, sizeof(priv->boardmodel), "%s rev 
%s",
 model, rev);
return;
case BOARD_STARTER_KIT_PRE:
-   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
+   snprintf(model, sizeof(model),
 "Renesas Starter Kit Premier board");
if (!(board_rev & ~3)) { /* Only rev 0..3 is valid */
-   rev_major = (board_rev & BIT(1)) ? 2 : 1;
-   rev_minor = (board_rev == 3) ? 1 : 0;
-   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
+   priv->rev_major = (board_rev & BIT(1)) ? 2 : 1;
+   priv->rev_minor = (board_rev == 3) ? 1 : 0;
+   snprintf(rev, sizeof(rev), "%u.%u", priv->rev_major, 
priv->rev_minor);
+   priv->has_rev = true;
}
snprintf(priv->boardmodel, sizeof(priv->boardmodel), "%s rev 
%s",
 model, rev);
return;
case BOARD_EAGLE:
-   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
+   snprintf(model, sizeof(model),
 "Renesas Eagle board");

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

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

Signed-off-by: Detlev Casanova 
---
 drivers/sysinfo/rcar3.c | 104 
 1 file changed, 62 insertions(+), 42 deletions(-)

diff --git a/drivers/sysinfo/rcar3.c b/drivers/sysinfo/rcar3.c
index 7b127986da7..450a4c26773 100644
--- a/drivers/sysinfo/rcar3.c
+++ b/drivers/sysinfo/rcar3.c
@@ -68,90 +68,110 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv 
*priv)
bool salvator_xs = false;
bool ebisu_4d = false;
bool condor_i = false;
-   char rev_major = '?';
-   char rev_minor = '?';
+   char model[64];
+   char rev[4] = "?.?";
+   u8 rev_major = 0;
+   u8 rev_minor = 0;
 
switch (board_id) {
case BOARD_SALVATOR_XS:
salvator_xs = true;
fallthrough;
case BOARD_SALVATOR_X:
+   snprintf(model, sizeof(model),
+"Renesas Salvator-X%s board", salvator_xs ? "S" : "");
if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
-   rev_major = '1';
-   rev_minor = '0' + (board_rev & BIT(0));
+   rev_major = 1;
+   rev_minor = board_rev & BIT(0);
+   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
}
-   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
-"Renesas Salvator-X%s board rev %c.%c",
-salvator_xs ? "S" : "", rev_major, rev_minor);
+
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel), "%s rev 
%s",
+model, rev);
+
return;
case BOARD_STARTER_KIT:
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
+"Renesas Starter Kit board");
if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
-   rev_major = (board_rev & BIT(0)) ? '3' : '1';
-   rev_minor = '0';
+   rev_major = (board_rev & BIT(0)) ? 3 : 1;
+   rev_minor = 0;
+   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
}
-   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
-"Renesas Starter Kit board rev %c.%c",
-rev_major, rev_minor);
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel), "%s rev 
%s",
+model, rev);
return;
case BOARD_STARTER_KIT_PRE:
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
+"Renesas Starter Kit Premier board");
if (!(board_rev & ~3)) { /* Only rev 0..3 is valid */
-   rev_major = (board_rev & BIT(1)) ? '2' : '1';
-   rev_minor = (board_rev == 3) ? '1' : '0';
+   rev_major = (board_rev & BIT(1)) ? 2 : 1;
+   rev_minor = (board_rev == 3) ? 1 : 0;
+   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
}
-   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
-"Renesas Starter Kit Premier board rev %c.%c",
-rev_major, rev_minor);
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel), "%s rev 
%s",
+model, rev);
return;
case BOARD_EAGLE:
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
+"Renesas Eagle board");
if (!board_rev) { /* Only rev 0 is valid */
-   rev_major = '1';
-   rev_minor = '0';
+   rev_major = 1;
+   rev_minor = 0;
+   snprintf(rev, sizeof(rev), "%u.%u", rev_major, 
rev_minor);
}
-   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
-"Renesas Eagle board rev %c.%c",
-rev_major, rev_minor);
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel), "%s rev 
%s",
+model, rev);
return;
case BOARD_EBISU_4D:
ebisu_4d = true;
fallthrough;
case BOARD_EBISU:
+   snprintf(priv->boardmodel, sizeof(priv->boardmodel),
+"Renesas Ebisu%s board", ebisu_4d ? "-4D" : "");
if (!board_rev) { /* Only rev 0 is valid */
-   rev_major = '1';
-   rev_minor = '0';
+   rev_major = 1;
+   rev_minor = 0;
+   snprintf(rev, sizeof(rev), 

[PATCH v3 4/6] sysinfo: Add documentation

2023-07-14 Thread Detlev Casanova
Add documentation for the sysinfo command with examples.

Signed-off-by: Detlev Casanova 
---
 doc/usage/cmd/sysinfo.rst | 56 +++
 1 file changed, 56 insertions(+)
 create mode 100644 doc/usage/cmd/sysinfo.rst

diff --git a/doc/usage/cmd/sysinfo.rst b/doc/usage/cmd/sysinfo.rst
new file mode 100644
index 000..3dad1f4f38d
--- /dev/null
+++ b/doc/usage/cmd/sysinfo.rst
@@ -0,0 +1,56 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+sysinfo command
+===
+
+Synopis
+---
+
+::
+
+sysinfo id 
+sysinfo model 
+sysinfo revision 
+
+Description
+---
+
+The `sysinfo` command is used to show information about the running system
+
+The `sysinfo id` command prints or sets an environment variable to the board id
+as an hex value.
+
+varname
+an optional environment variable to store the board id into.
+
+The `sysinfo model` command prints or sets an environment variable to the board
+model name as a string value.
+
+varname
+an optional environment variable to store the board model name into.
+
+The `sysinfo revision` command prints or sets an environment variable to the
+board revision in the . format, where MINOR and MINOR are int
+values.
+
+varname
+an optional environment variable to store the board revision into.
+
+Examples
+
+
+::
+
+=> sysinfo id
+0x0b
+=> sysinfo model
+Renesas Starter Kit Premier board rev 2.1
+=> sysinfo revision varname
+=> env print varname
+2.1
+
+Return value
+
+
+The return value $? is set to 0 (true) if the command succededd. If an
+error occurs, the return value $? is set to 1 (false).
-- 
2.41.0



[PATCH v3 3/6] sysinfo: Add a test

2023-07-14 Thread Detlev Casanova
The test runs one of each subcommand and checks that the output matches
the values in the sandbox sysinfo driver.

Signed-off-by: Detlev Casanova 
---
 configs/sandbox_defconfig |  1 +
 drivers/sysinfo/sandbox.c | 17 +
 test/cmd/Makefile |  1 +
 test/cmd/test_sysinfo.c   | 51 +++
 4 files changed, 70 insertions(+)
 create mode 100644 test/cmd/test_sysinfo.c

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 1ec44d5b33b..bdaac205d02 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -128,6 +128,7 @@ CONFIG_CMD_EROFS=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_SQUASHFS=y
 CONFIG_CMD_MTDPARTS=y
+CONFIG_CMD_SYSINFO=y
 CONFIG_CMD_STACKPROTECTOR_TEST=y
 CONFIG_MAC_PARTITION=y
 CONFIG_AMIGA_PARTITION=y
diff --git a/drivers/sysinfo/sandbox.c b/drivers/sysinfo/sandbox.c
index d270a26aa43..cc7783907a9 100644
--- a/drivers/sysinfo/sandbox.c
+++ b/drivers/sysinfo/sandbox.c
@@ -7,9 +7,14 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "sandbox.h"
 
+#define SANDBOX_BOARD_ID   0x42
+#define SANDBOX_BOARD_REV_MAJORU_BOOT_VERSION_NUM
+#define SANDBOX_BOARD_REV_MINORU_BOOT_VERSION_NUM_PATCH
+
 struct sysinfo_sandbox_priv {
bool called_detect;
int test_i1;
@@ -48,6 +53,15 @@ int sysinfo_sandbox_get_int(struct udevice *dev, int id, int 
*val)
struct sysinfo_sandbox_priv *priv = dev_get_priv(dev);
 
switch (id) {
+   case SYSINFO_ID_BOARD_ID:
+   *val = SANDBOX_BOARD_ID;
+   return 0;
+   case SYSINFO_ID_BOARD_REV_MAJOR:
+   *val = SANDBOX_BOARD_REV_MAJOR;
+   return 0;
+   case SYSINFO_ID_BOARD_REV_MINOR:
+   *val = SANDBOX_BOARD_REV_MINOR;
+   return 0;
case INT_TEST1:
*val = priv->test_i1;
/* Increments with every call */
@@ -71,6 +85,9 @@ int sysinfo_sandbox_get_str(struct udevice *dev, int id, 
size_t size, char *val)
int index = (i1 * i2) % ARRAY_SIZE(vacation_spots);
 
switch (id) {
+   case SYSINFO_ID_BOARD_MODEL:
+   snprintf(val, size, "sandbox");
+   return 0;
case STR_VACATIONSPOT:
/* Picks a vacation spot depending on i1 and i2 */
snprintf(val, size, vacation_spots[index]);
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index a3cf983739e..d3ac5bf2d5e 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_CMD_SEAMA) += seama.o
 ifdef CONFIG_SANDBOX
 obj-$(CONFIG_CMD_READ) += rw.o
 obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
+obj-$(CONFIG_CMD_SYSINFO) += test_sysinfo.o
 endif
 obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
 obj-$(CONFIG_CMD_WGET) += wget.o
diff --git a/test/cmd/test_sysinfo.c b/test/cmd/test_sysinfo.c
new file mode 100644
index 000..7ba6dd0df89
--- /dev/null
+++ b/test/cmd/test_sysinfo.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for sysinfo command
+ *
+ * Copyright 2023, Detlev Casanova 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define REV_(x, y) #x "." #y
+#define REV(x, y) REV_(x, y)
+
+struct test_data {
+   char *cmd;
+   char *expected;
+};
+
+static struct test_data sysinfo_data[] = {
+   {"sysinfo model", "sandbox"},
+   {"sysinfo id", "0x42"},
+   {"sysinfo revision", REV(U_BOOT_VERSION_NUM, U_BOOT_VERSION_NUM_PATCH)},
+};
+
+static int lib_test_sysinfo(struct unit_test_state *uts)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(sysinfo_data); ++i) {
+   ut_silence_console(uts);
+   console_record_reset_enable();
+   ut_assertok(run_command(sysinfo_data[i].cmd, 0));
+   ut_unsilence_console(uts);
+   console_record_readline(uts->actual_str,
+   sizeof(uts->actual_str));
+   ut_asserteq_str(sysinfo_data[i].expected, uts->actual_str);
+   ut_assertok(ut_check_console_end(uts));
+   }
+
+   return 0;
+}
+
+LIB_TEST(lib_test_sysinfo, 0);
-- 
2.41.0



[PATCH v3 2/6] cmd: Add a sysinfo command

2023-07-14 Thread Detlev Casanova
The command is able to show different information for the running
system:
* Model name
* Board ID
* Revision

This command can be used by boot shell scripts to select configurations
depending on the specific running system.

Signed-off-by: Detlev Casanova 
---
 cmd/Kconfig   |   6 +++
 cmd/Makefile  |   1 +
 cmd/sysinfo.c | 133 ++
 3 files changed, 140 insertions(+)
 create mode 100644 cmd/sysinfo.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index c1941849f98..0df6d7e8bb7 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -210,6 +210,12 @@ config CMD_SBI
help
  Display information about the SBI implementation.
 
+config CMD_SYSINFO
+   bool "sysinfo"
+   depends on SYSINFO
+   help
+ Display information about the system.
+
 endmenu
 
 menu "Boot commands"
diff --git a/cmd/Makefile b/cmd/Makefile
index 6c37521b4e2..ba4d6de9a1b 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -165,6 +165,7 @@ obj-$(CONFIG_CMD_SPI) += spi.o
 obj-$(CONFIG_CMD_STRINGS) += strings.o
 obj-$(CONFIG_CMD_SMC) += smccc.o
 obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o
+obj-$(CONFIG_CMD_SYSINFO) += sysinfo.o
 obj-$(CONFIG_CMD_STACKPROTECTOR_TEST) += stackprot_test.o
 obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
 obj-$(CONFIG_CMD_TERMINAL) += terminal.o
diff --git a/cmd/sysinfo.c b/cmd/sysinfo.c
new file mode 100644
index 000..46369ff9ac7
--- /dev/null
+++ b/cmd/sysinfo.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2023
+ * Detlev Casanova 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static int get_sysinfo(struct udevice **devp)
+{
+   int ret = sysinfo_get(devp);
+
+   if (ret) {
+   printf("Cannot get sysinfo: %d\n", ret);
+   return ret;
+   }
+
+   ret = sysinfo_detect(*devp);
+   if (ret) {
+   printf("Cannot detect sysinfo: %d\n", ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+static int do_sysinfo_model(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   struct udevice *dev;
+   char model[64];
+   int ret = get_sysinfo();
+
+   if (ret)
+   return CMD_RET_FAILURE;
+
+   ret = sysinfo_get_str(dev,
+ SYSINFO_ID_BOARD_MODEL,
+ sizeof(model),
+ model);
+   if (ret) {
+   printf("Cannot get sysinfo str: %d\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   if (argc == 2)
+   ret = env_set(argv[1], model);
+   else
+   printf("%s\n", model);
+
+   if (ret)
+   return CMD_RET_FAILURE;
+   else
+   return CMD_RET_SUCCESS;
+}
+
+static int do_sysinfo_id(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   struct udevice *dev;
+   u32 board_id;
+   int ret = get_sysinfo();
+
+   if (ret)
+   return CMD_RET_FAILURE;
+
+   ret = sysinfo_get_int(dev, SYSINFO_ID_BOARD_ID, _id);
+   if (ret) {
+   printf("Cannot get sysinfo int: %d\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   if (argc == 2)
+   ret = env_set_hex(argv[1], board_id);
+   else
+   printf("0x%02x\n", board_id);
+
+   if (ret)
+   return CMD_RET_FAILURE;
+   else
+   return CMD_RET_SUCCESS;
+}
+
+static int do_sysinfo_revision(struct cmd_tbl *cmdtp, int flag, int argc,
+  char *const argv[])
+{
+   struct udevice *dev;
+   int rev_major;
+   int rev_minor;
+   char rev[64];
+   int ret = get_sysinfo();
+
+   if (ret)
+   return CMD_RET_FAILURE;
+
+   ret = sysinfo_get_int(dev, SYSINFO_ID_BOARD_REV_MAJOR, _major);
+   if (ret) {
+   printf("Cannot get sysinfo int: %d\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   ret = sysinfo_get_int(dev, SYSINFO_ID_BOARD_REV_MINOR, _minor);
+   if (ret) {
+   printf("Cannot get sysinfo int: %d\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   snprintf(rev, sizeof(rev), "%d.%d", rev_major, rev_minor);
+
+   if (argc == 2)
+   ret = env_set(argv[1], rev);
+   else
+   printf("%s\n", rev);
+
+   if (ret)
+   return CMD_RET_FAILURE;
+   else
+   return CMD_RET_SUCCESS;
+}
+
+static char sysinfo_help_text[] =
+   "model  - Show or set the board model in varname\n"
+   "sysinfo id - Show or set the board id in varname (in 
format 0xHH)\n"
+   "sysinfo revision   - Show or set the board revision in 
varname";
+
+U_BOOT_CMD_WITH_SUBCMDS(sysinfo, "System information", sysinfo_help_text,
+   U_BOOT_SUBCMD_MKENT(model, 2, 1, do_sysinfo_model),
+   U_BOOT_SUBCMD_MKENT(id, 2, 

[PATCH v3 1/6] sysinfo: Add IDs for board id and revision

2023-07-14 Thread Detlev Casanova
These IDs will be used by the sysinfo command. The new IDs are:
 * SYSINFO_ID_BOARD_ID: The board ID as an integer
 * SYSINFO_ID_BOARD_REV_MAJOR: The board major revision as int
 * SYSINFO_ID_BOARD_REV_MINOR: The board minor revision as int

Signed-off-by: Detlev Casanova 
---
 include/sysinfo.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/sysinfo.h b/include/sysinfo.h
index b140d742e93..13815600ae6 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -47,6 +47,11 @@ enum sysinfo_id {
/* For show_board_info() */
SYSINFO_ID_BOARD_MODEL,
 
+   /* For sysinfo command (all int) */
+   SYSINFO_ID_BOARD_ID,
+   SYSINFO_ID_BOARD_REV_MAJOR,
+   SYSINFO_ID_BOARD_REV_MINOR,
+
/* First value available for downstream/board used */
SYSINFO_ID_USER = 0x1000,
 };
-- 
2.41.0



[PATCH v3 0/5] Introduce the sysinfo command

2023-07-14 Thread Detlev Casanova
The command can be used to show various information that can be used to
identify the running system.

Currently supported subcommands are:
* model: A string representing the model
* id: The id of the board
* revision: The revision of this board.


Changes since v2:
 - Fix code style.
 - Use printf() instead of debug().
 - Clarify sysinfo new ids types (int).
 - Add a test for sysinfo command.
 - Add documentation for sysinfo command.
Changes since v1:
 - Removed shell function to select linux device tree. This will be
   distributions job.
 - Break revision in rev_major and rev_minor in the sysinfo driver.

Detlev Casanova (6):
  sysinfo: Add IDs for board id and revision
  cmd: Add a sysinfo command
  sysinfo: Add a test
  sysinfo: Add documentation
  sysinfo: rcar3: Use int instead of char for revision
  sysinfo: rcar3: Implement BOARD_ID and BOARD_REV_*

 cmd/Kconfig   |   6 ++
 cmd/Makefile  |   1 +
 cmd/sysinfo.c | 133 +++
 configs/sandbox_defconfig |   1 +
 doc/usage/cmd/sysinfo.rst |  56 +++
 drivers/sysinfo/rcar3.c   | 141 ++
 drivers/sysinfo/sandbox.c |  17 +
 include/sysinfo.h |   5 ++
 test/cmd/Makefile |   1 +
 test/cmd/test_sysinfo.c   |  51 ++
 10 files changed, 370 insertions(+), 42 deletions(-)
 create mode 100644 cmd/sysinfo.c
 create mode 100644 doc/usage/cmd/sysinfo.rst
 create mode 100644 test/cmd/test_sysinfo.c

-- 
2.41.0



[PATCH v1 6/6] power: regulator: tps65911: add regulator support

2023-07-14 Thread Svyatoslav Ryhel
The driver provides regulator set/get voltage enable/disable
functions for TI TPS5911 PMIC.

Signed-off-by: Svyatoslav Ryhel 
---
 drivers/power/regulator/Kconfig  |   8 +
 drivers/power/regulator/Makefile |   1 +
 drivers/power/regulator/tps65911_regulator.c | 375 +++
 3 files changed, 384 insertions(+)
 create mode 100644 drivers/power/regulator/tps65911_regulator.c

diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index f297e408cd..3398f0fbee 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -345,6 +345,14 @@ config DM_REGULATOR_TPS65910
regulator types of the TPS65910 (BUCK, BOOST and LDO). It implements
the get/set api for value and enable.
 
+config DM_REGULATOR_TPS65911
+   bool "Enable driver for TPS65911 PMIC regulators"
+   depends on DM_PMIC_TPS65910
+   ---help---
+   The TPS65911 PMIC provides 4 SMPSs and 8 LDOs. This driver supports all
+   regulator types of the TPS65911. It implements the get/set api for value
+   and enable.
+
 config DM_REGULATOR_TPS62360
bool "Enable driver for TPS6236x Power Regulator"
depends on DM_REGULATOR
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile
index 3ef55dc534..c2ab1b7721 100644
--- a/drivers/power/regulator/Makefile
+++ b/drivers/power/regulator/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP873X) += lp873x_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += lp87565_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_DM_REGULATOR_TPS65910) += tps65910_regulator.o
+obj-$(CONFIG_DM_REGULATOR_TPS65911) += tps65911_regulator.o
 obj-$(CONFIG_DM_REGULATOR_TPS62360) += tps62360_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_TPS80031) += tps80031_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_STPMIC1) += stpmic1.o
diff --git a/drivers/power/regulator/tps65911_regulator.c 
b/drivers/power/regulator/tps65911_regulator.c
new file mode 100644
index 00..84ae52c888
--- /dev/null
+++ b/drivers/power/regulator/tps65911_regulator.c
@@ -0,0 +1,375 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  Copyright(C) 2023 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* fist row is control registers, second is voltage registers */
+static const char tps65911_vdd_reg[][TPS65911_VDD_NUM] = {
+   { TPS65911_REG_VDD1, TPS65911_REG_VDD2,
+ TPS65911_REG_VDDCTRL, TPS65911_REG_VIO },
+   { TPS65911_REG_VDD1_OP, TPS65911_REG_VDD2_OP,
+ TPS65911_REG_VDDCTRL_OP, 0x00 },
+};
+
+static const u32 tps65911_vio_range[] = {
+   150, 180, 250, 330
+};
+
+static const char tps65911_ldo_reg[TPS65911_LDO_NUM] = {
+   TPS65911_REG_LDO1, TPS65911_REG_LDO2, TPS65911_REG_LDO3,
+   TPS65911_REG_LDO4, TPS65911_REG_LDO5, TPS65911_REG_LDO6,
+   TPS65911_REG_LDO7, TPS65911_REG_LDO8
+};
+
+static int tps65911_regulator_enable(struct udevice *dev, int op, bool *enable)
+{
+   struct dm_regulator_uclass_plat *uc_pdata =
+   dev_get_uclass_plat(dev);
+   u32 adr = uc_pdata->ctrl_reg;
+   int ret;
+
+   ret = pmic_reg_read(dev->parent, adr);
+   if (ret < 0)
+   return ret;
+
+   if (op == PMIC_OP_GET) {
+   if (ret & TPS65910_SUPPLY_STATE_ON)
+   *enable = true;
+   else
+   *enable = false;
+
+   return 0;
+   } else if (op == PMIC_OP_SET) {
+   ret &= ~(TPS65910_SUPPLY_STATE_MASK);
+
+   if (*enable)
+   ret |= TPS65910_SUPPLY_STATE_ON;
+
+   ret = pmic_reg_write(dev->parent, adr, ret);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
+static int tps65911_get_enable(struct udevice *dev)
+{
+   bool enable = false;
+   int ret;
+
+   ret = tps65911_regulator_enable(dev, PMIC_OP_GET, );
+   if (ret)
+   return ret;
+
+   return enable;
+}
+
+static int tps65911_set_enable(struct udevice *dev, bool enable)
+{
+   return tps65911_regulator_enable(dev, PMIC_OP_SET, );
+}
+
+static int tps65911_vdd_volt2hex(int uV)
+{
+   if (uV > TPS65911_VDD_VOLT_MAX)
+   return -EINVAL;
+
+   if (uV < TPS65911_VDD_VOLT_MIN)
+   uV = TPS65911_VDD_VOLT_MIN;
+
+   return (uV - TPS65911_VDD_VOLT_BASE) / 12500;
+}
+
+static int tps65911_vdd_hex2volt(int hex)
+{
+   if (hex > TPS65910_VDD_SEL_MAX)
+   return -EINVAL;
+
+   if (hex < TPS65910_VDD_SEL_MIN)
+   hex = TPS65910_VDD_SEL_MIN;
+
+   return TPS65911_VDD_VOLT_BASE + hex * 12500;
+}
+
+static int tps65911_vio_val(struct udevice *dev, int op, int *uV)
+{
+   struct dm_regulator_uclass_plat *uc_pdata =
+   

[PATCH v1 3/6] power: pmic: add the base TPS80031 PMIC support

2023-07-14 Thread Svyatoslav Ryhel
Add support to bind the regulators/child nodes with the pmic.
Also adds the pmic i2c based read/write functions to access pmic
registers.

Signed-off-by: Svyatoslav Ryhel 
---
 doc/device-tree-bindings/pmic/tps80031.txt | 76 
 drivers/power/pmic/Kconfig |  6 ++
 drivers/power/pmic/Makefile|  1 +
 drivers/power/pmic/tps80031.c  | 82 ++
 include/power/tps80031.h   | 42 +++
 5 files changed, 207 insertions(+)
 create mode 100644 doc/device-tree-bindings/pmic/tps80031.txt
 create mode 100644 drivers/power/pmic/tps80031.c
 create mode 100644 include/power/tps80031.h

diff --git a/doc/device-tree-bindings/pmic/tps80031.txt 
b/doc/device-tree-bindings/pmic/tps80031.txt
new file mode 100644
index 00..577e6de1c1
--- /dev/null
+++ b/doc/device-tree-bindings/pmic/tps80031.txt
@@ -0,0 +1,76 @@
+Texas Instruments, TPS80031/TPS80032 PMIC
+
+This device uses two drivers:
+- drivers/power/pmic/tps80031.c (for parent device)
+- drivers/power/regulator/tps80031_regulator.c (for child regulators)
+
+This chapter describes the binding info for the PMIC driver and regulators.
+
+Required properties for PMIC:
+- compatible: "ti,tps80031" or "ti,tps80032"
+- reg: 0x48
+
+With those two properties, the pmic device can be used for read/write only.
+To bind each regulator, the optional regulators subnode should exists.
+
+Optional subnode:
+- name: regulators (subnode list of each device's regulator)
+
+Regulators subnode contains set on supported regulators.
+
+Required properties:
+- regulator-name: used for regulator uclass platform data '.name',
+
+List of supported regulator nodes names for tps80031/tps80032:
+- smps1, smps2, smps3, smps4, smps5
+- ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldoln, ldousb
+
+SMPS5 in Linux 3.1.10 is referred as vio, but datasheet clearly names it SMPS5.
+
+Optional:
+- regulator-min-microvolt: minimum allowed Voltage to set
+- regulator-max-microvolt: minimum allowed Voltage to set
+- regulator-always-on: regulator should be never disabled
+- regulator-boot-on: regulator should be enabled by the bootloader
+
+Example:
+
+tps80032@48 {
+   compatible = "ti,tps80032";
+   reg = <0x48>;
+
+   regulators {
+   smps1 {
+   regulator-name = "vdd_cpu";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <125>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   ...
+
+   smps5 {
+   regulator-name = "vdd_1v8_gen";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   ldo1 {
+   regulator-name = "avdd_dsi_csi";
+   regulator-min-microvolt = <120>;
+   regulator-max-microvolt = <120>;
+   regulator-boot-on;
+   };
+
+   ...
+
+   ldousb {
+   regulator-name = "avdd_usb";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   };
+   };
+};
diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index abea0fe4ed..d25fe1ce0d 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -347,6 +347,12 @@ config DM_PMIC_TPS65910
DC-DC converter, 8 LDOs and a RTC. This driver binds the SMPS and LDO
pmic children.
 
+config DM_PMIC_TPS80031
+   bool "Enable driver for Texas Instruments TPS80031/TPS80032 PMIC"
+   ---help---
+   The TPS80031/TPS80032 are PMIC's containing several LDOs, SMPS.
+   This driver binds the pmic children.
+
 config PMIC_STPMIC1
bool "Enable support for STMicroelectronics STPMIC1 PMIC"
depends on DM_I2C
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 414a9d8225..55ee614364 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_$(SPL_)PMIC_RN5T567) += rn5t567.o
 obj-$(CONFIG_PMIC_TPS65090) += tps65090.o
 obj-$(CONFIG_PMIC_S5M8767) += s5m8767.o
 obj-$(CONFIG_DM_PMIC_TPS65910) += pmic_tps65910_dm.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_TPS80031) += tps80031.o
 obj-$(CONFIG_$(SPL_)PMIC_PALMAS) += palmas.o
 obj-$(CONFIG_$(SPL_)PMIC_LP873X) += lp873x.o
 obj-$(CONFIG_$(SPL_)PMIC_LP87565) += lp87565.o
diff --git a/drivers/power/pmic/tps80031.c b/drivers/power/pmic/tps80031.c
new file mode 100644
index 00..b5f9370860
--- /dev/null
+++ b/drivers/power/pmic/tps80031.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  Copyright(C) 2023 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 

[PATCH v1 5/6] power: pmic: tps65910: add TPS65911 PMIC support

2023-07-14 Thread Svyatoslav Ryhel
Add support to bind the regulators/child nodes with the pmic.
Also adds the pmic i2c based read/write functions to access pmic
registers.

Signed-off-by: Svyatoslav Ryhel 
---
 doc/device-tree-bindings/pmic/tps65911.txt | 78 ++
 drivers/power/pmic/pmic_tps65910_dm.c  | 26 +++-
 include/power/tps65910_pmic.h  | 47 +
 3 files changed, 148 insertions(+), 3 deletions(-)
 create mode 100644 doc/device-tree-bindings/pmic/tps65911.txt

diff --git a/doc/device-tree-bindings/pmic/tps65911.txt 
b/doc/device-tree-bindings/pmic/tps65911.txt
new file mode 100644
index 00..29270efbfe
--- /dev/null
+++ b/doc/device-tree-bindings/pmic/tps65911.txt
@@ -0,0 +1,78 @@
+Texas Instruments, TPS65911 PMIC
+
+This device uses two drivers:
+- drivers/power/pmic/tps65910.c (for parent device)
+- drivers/power/regulator/tps65911_regulator.c (for child regulators)
+
+This chapter describes the binding info for the PMIC driver and regulators.
+
+Required properties for PMIC:
+- compatible: "ti,tps65911"
+- reg: 0x2d
+
+With those two properties, the pmic device can be used for read/write only.
+To bind each regulator, the optional regulators subnode should exists.
+
+Optional subnode:
+- name: regulators (subnode list of each device's regulator)
+
+Regulators subnode contains set on supported regulators.
+
+Required properties:
+- regulator-name: used for regulator uclass platform data '.name',
+
+List of supported regulator nodes names for tps65911:
+- vdd1, vdd2, vddctrl, vddio
+- ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldo8
+
+vddio in datasheet is referred as vio, but for reduction of code and
+unification of smps regulators it is named vddio.
+
+Optional:
+- regulator-min-microvolt: minimum allowed Voltage to set
+- regulator-max-microvolt: minimum allowed Voltage to set
+- regulator-always-on: regulator should be never disabled
+- regulator-boot-on: regulator should be enabled by the bootloader
+
+Example:
+
+tps65911@2d {
+   compatible = "ti,tps65911";
+   reg = <0x2d>;
+
+   regulators {
+   vdd1 {
+   regulator-name = "vdd_1v2_backlight";
+   regulator-min-microvolt = <120>;
+   regulator-max-microvolt = <120>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   ...
+
+   vddio {
+   regulator-name = "vdd_1v8_gen";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   ldo1 {
+   regulator-name = "vdd_emmc_core";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   ...
+
+   ldo8 {
+   regulator-name = "vdd_ddr_hs";
+   regulator-min-microvolt = <100>;
+   regulator-max-microvolt = <100>;
+   };
+   };
+};
diff --git a/drivers/power/pmic/pmic_tps65910_dm.c 
b/drivers/power/pmic/pmic_tps65910_dm.c
index e03ddc98d7..fb72344ee0 100644
--- a/drivers/power/pmic/pmic_tps65910_dm.c
+++ b/drivers/power/pmic/pmic_tps65910_dm.c
@@ -11,13 +11,19 @@
 #include 
 #include 
 
-static const struct pmic_child_info pmic_children_info[] = {
+static const struct pmic_child_info tps65910_children_info[] = {
{ .prefix = "ldo_", .driver = TPS65910_LDO_DRIVER },
{ .prefix = "buck_", .driver = TPS65910_BUCK_DRIVER },
{ .prefix = "boost_", .driver = TPS65910_BOOST_DRIVER },
{ },
 };
 
+static const struct pmic_child_info tps65911_children_info[] = {
+   { .prefix = "vdd", .driver = TPS65911_VDD_DRIVER },
+   { .prefix = "ldo", .driver = TPS65911_LDO_DRIVER },
+   { },
+};
+
 static int pmic_tps65910_reg_count(struct udevice *dev)
 {
return TPS65910_NUM_REGS;
@@ -51,6 +57,7 @@ static int pmic_tps65910_bind(struct udevice *dev)
 {
ofnode regulators_node;
int children;
+   int type = dev_get_driver_data(dev);
 
regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
@@ -58,7 +65,19 @@ static int pmic_tps65910_bind(struct udevice *dev)
return -EINVAL;
}
 
-   children = pmic_bind_children(dev, regulators_node, pmic_children_info);
+   switch (type) {
+   case TPS65910:
+   children = pmic_bind_children(dev, regulators_node,
+ tps65910_children_info);
+   break;
+   case TPS65911:
+   children = pmic_bind_children(dev, regulators_node,
+ 

[PATCH v1 4/6] power: regulator: tps80031: add regulator support

2023-07-14 Thread Svyatoslav Ryhel
The driver provides regulator set/get voltage enable/disable
functions for TI TPS80031/TPS80032 PMICs.

Signed-off-by: Svyatoslav Ryhel 
---
 drivers/power/regulator/Kconfig  |   8 +
 drivers/power/regulator/Makefile |   1 +
 drivers/power/regulator/tps80031_regulator.c | 296 +++
 3 files changed, 305 insertions(+)
 create mode 100644 drivers/power/regulator/tps80031_regulator.c

diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index 571debd54e..f297e408cd 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -355,6 +355,14 @@ config DM_REGULATOR_TPS62360
implements the get/set api for value only, as the power line is
always on.
 
+config DM_REGULATOR_TPS80031
+   bool "Enable driver for TPS80031/TPS80032 PMIC regulators"
+   depends on DM_PMIC_TPS80031
+   ---help---
+   This enables implementation of driver-model regulator uclass
+   features for TPS80031/TPS80032 PMICs. The driver implements
+   get/set api for: value and enable.
+
 config DM_REGULATOR_STPMIC1
bool "Enable driver for STPMIC1 regulators"
depends on DM_REGULATOR && PMIC_STPMIC1
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile
index 8d73169b50..3ef55dc534 100644
--- a/drivers/power/regulator/Makefile
+++ b/drivers/power/regulator/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_$(SPL_)DM_REGULATOR_LP87565) += 
lp87565_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_DM_REGULATOR_TPS65910) += tps65910_regulator.o
 obj-$(CONFIG_DM_REGULATOR_TPS62360) += tps62360_regulator.o
+obj-$(CONFIG_$(SPL_)DM_REGULATOR_TPS80031) += tps80031_regulator.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_STPMIC1) += stpmic1.o
 obj-$(CONFIG_DM_REGULATOR_TPS65941) += tps65941_regulator.o
 obj-$(CONFIG_DM_REGULATOR_SCMI) += scmi_regulator.o
diff --git a/drivers/power/regulator/tps80031_regulator.c 
b/drivers/power/regulator/tps80031_regulator.c
new file mode 100644
index 00..c970f5a92d
--- /dev/null
+++ b/drivers/power/regulator/tps80031_regulator.c
@@ -0,0 +1,296 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  Copyright(C) 2023 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const char tps80031_smps_reg[][TPS80031_SMPS_NUM] = {
+   {   0x54,   0x5a,   0x66,   0x42,   0x48 },
+   {   0x56,   0x5c,   0x68,   0x44,   0x4a },
+   { BIT(3), BIT(4), BIT(6), BIT(0), BIT(1) },
+};
+
+static const char tps80031_ldo_reg[][TPS80031_LDO_NUM] = {
+   { 0x9e, 0x86, 0x8e, 0x8a, 0x9a, 0x92, 0xa6, 0x96, 0xa2 },
+   { 0x9f, 0x87, 0x8f, 0x8b, 0x9b, 0x93, 0xa7, 0x97, 0xa3 },
+};
+
+static int tps80031_regulator_enable(struct udevice *dev, int op, bool *enable)
+{
+   struct dm_regulator_uclass_plat *uc_pdata =
+   dev_get_uclass_plat(dev);
+   u32 adr = uc_pdata->ctrl_reg;
+   int ret;
+
+   ret = pmic_reg_read(dev->parent, adr);
+   if (ret < 0)
+   return ret;
+
+   if (op == PMIC_OP_GET) {
+   if (ret & TPS80031_REGULATOR_MODE_ON)
+   *enable = true;
+   else
+   *enable = false;
+
+   return 0;
+   } else if (op == PMIC_OP_SET) {
+   ret &= ~(TPS80031_REGULATOR_STATUS_MASK);
+
+   if (*enable)
+   ret |= TPS80031_REGULATOR_MODE_ON;
+
+   ret = pmic_reg_write(dev->parent, adr, ret);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
+static int tps80031_get_enable(struct udevice *dev)
+{
+   bool enable = false;
+   int ret;
+
+   ret = tps80031_regulator_enable(dev, PMIC_OP_GET, );
+   if (ret)
+   return ret;
+
+   return enable;
+}
+
+static int tps80031_set_enable(struct udevice *dev, bool enable)
+{
+   return tps80031_regulator_enable(dev, PMIC_OP_SET, );
+}
+
+static int tps80031_ldo_volt2hex(int uV)
+{
+   if (uV > TPS80031_LDO_VOLT_MAX)
+   return -EINVAL;
+
+   if (uV < TPS80031_LDO_VOLT_MIN)
+   uV = TPS80031_LDO_VOLT_MIN;
+
+   return DIV_ROUND_UP(uV - TPS80031_LDO_VOLT_BASE, 102000);
+}
+
+static int tps80031_ldo_hex2volt(int hex)
+{
+   if (hex > TPS80031_LDO_VOLT_MAX_HEX)
+   return -EINVAL;
+
+   if (hex < TPS80031_LDO_VOLT_MIN_HEX)
+   hex = TPS80031_LDO_VOLT_MIN_HEX;
+
+   return TPS80031_LDO_VOLT_BASE + hex * 102000;
+}
+
+static int tps80031_ldo_val(struct udevice *dev, int op, int *uV)
+{
+   struct dm_regulator_uclass_plat *uc_pdata =
+   dev_get_uclass_plat(dev);
+   u32 adr = uc_pdata->volt_reg;
+   int hex, ret;
+
+   ret = pmic_reg_read(dev->parent, adr);
+   if (ret < 0)
+   return ret;
+
+   if (op == PMIC_OP_GET) {
+   

[PATCH v1 2/6] power: regulator: max77663: add regulator support

2023-07-14 Thread Svyatoslav Ryhel
The driver provides regulator set/get voltage
enable/disable functions for MAXIM MAX77663 PMICs.

Signed-off-by: Svyatoslav Ryhel 
---
 drivers/power/regulator/Kconfig  |   8 +
 drivers/power/regulator/Makefile |   1 +
 drivers/power/regulator/max77663_regulator.c | 362 +++
 3 files changed, 371 insertions(+)
 create mode 100644 drivers/power/regulator/max77663_regulator.c

diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index eb5aa38c1c..571debd54e 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -141,6 +141,14 @@ config SPL_REGULATOR_PWM
  This config enables implementation of driver-model regulator uclass
  features for PWM regulators in SPL.
 
+config DM_REGULATOR_MAX77663
+   bool "Enable Driver Model for REGULATOR MAX77663"
+   depends on DM_REGULATOR && DM_PMIC_MAX77663
+   ---help---
+   This config enables implementation of driver-model regulator uclass
+   features for REGULATOR MAX77663. The driver implements get/set api for:
+   value and enable.
+
 config DM_REGULATOR_MAX77686
bool "Enable Driver Model for REGULATOR MAX77686"
depends on DM_REGULATOR && DM_PMIC_MAX77686
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile
index d9e0cd5949..8d73169b50 100644
--- a/drivers/power/regulator/Makefile
+++ b/drivers/power/regulator/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_REGULATOR_AS3722)+= as3722_regulator.o
 obj-$(CONFIG_$(SPL_)REGULATOR_AXP) += axp_regulator.o
 obj-$(CONFIG_$(SPL_)REGULATOR_AXP_USB_POWER) += axp_usb_power.o
 obj-$(CONFIG_$(SPL_)DM_REGULATOR_DA9063) += da9063.o
+obj-$(CONFIG_$(SPL_)DM_REGULATOR_MAX77663) += max77663_regulator.o
 obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
 obj-$(CONFIG_DM_REGULATOR_NPCM8XX) += npcm8xx_regulator.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_PFUZE100) += pfuze100.o
diff --git a/drivers/power/regulator/max77663_regulator.c 
b/drivers/power/regulator/max77663_regulator.c
new file mode 100644
index 00..80501d2792
--- /dev/null
+++ b/drivers/power/regulator/max77663_regulator.c
@@ -0,0 +1,362 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  Copyright(C) 2023 Svyatoslav Ryhel 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* fist row is control registers, second is voltage registers */
+static const char max77663_sd_reg[][MAX77663_SD_NUM] = {
+   { 0x1d, 0x1e, 0x1f, 0x20, 0x21 },
+   { 0x16, 0x17, 0x18, 0x19, 0x2a },
+};
+
+static const char max77663_ldo_reg[MAX77663_LDO_NUM] = {
+   0x23, 0x25, 0x27, 0x29, 0x2b, 0x2d, 0x2f, 0x31, 0x33
+};
+
+static int max77663_sd_enable(struct udevice *dev, int op, bool *enable)
+{
+   struct dm_regulator_uclass_plat *uc_pdata =
+   dev_get_uclass_plat(dev);
+   u32 adr = uc_pdata->ctrl_reg;
+   int ret;
+
+   ret = pmic_reg_read(dev->parent, adr);
+   if (ret < 0)
+   return ret;
+
+   if (op == PMIC_OP_GET) {
+   if (ret & MAX77663_SD_STATUS_MASK)
+   *enable = true;
+   else
+   *enable = false;
+
+   return 0;
+   } else if (op == PMIC_OP_SET) {
+   ret &= ~(MAX77663_SD_STATUS_MASK);
+
+   if (*enable)
+   ret |= MAX77663_SD_STATUS_MASK;
+
+   ret = pmic_reg_write(dev->parent, adr, ret);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
+static int max77663_sd_volt2hex(int sd, int uV)
+{
+   switch (sd) {
+   case 0:
+   /* SD0 has max voltage 1.4V */
+   if (uV > MAX77663_SD0_VOLT_MAX)
+   return -EINVAL;
+   break;
+   case 1:
+   /* SD1 has max voltage 1.55V */
+   if (uV > MAX77663_SD1_VOLT_MAX)
+   return -EINVAL;
+   break;
+   default:
+   /* SD2 and SD3 have max voltage 3.79V */
+   if (uV > MAX77663_SD_VOLT_MAX)
+   return -EINVAL;
+   break;
+   };
+
+   if (uV < MAX77663_SD_VOLT_MIN)
+   uV = MAX77663_SD_VOLT_MIN;
+
+   return (uV - MAX77663_SD_VOLT_BASE) / 12500;
+}
+
+static int max77663_sd_hex2volt(int sd, int hex)
+{
+   switch (sd) {
+   case 0:
+   /* SD0 has max voltage 1.4V */
+   if (hex > MAX77663_SD0_VOLT_MAX_HEX)
+   return -EINVAL;
+   break;
+   case 1:
+   /* SD1 has max voltage 1.55V */
+   if (hex > MAX77663_SD1_VOLT_MAX_HEX)
+   return -EINVAL;
+   break;
+   default:
+   /* SD2 and SD3 have max voltage 3.79V */
+   if (hex > MAX77663_SD_VOLT_MAX_HEX)
+   return -EINVAL;
+   break;
+   };
+
+   if 

[PATCH v1 1/6] power: pmic: add the base max77663 pmic support

2023-07-14 Thread Svyatoslav Ryhel
Add support to bind the regulators/child nodes with the pmic.
Also adds the pmic i2c based read/write functions to access pmic
registers.

Signed-off-by: Svyatoslav Ryhel 
---
 doc/device-tree-bindings/pmic/max77663.txt | 84 ++
 drivers/power/pmic/Kconfig |  6 ++
 drivers/power/pmic/Makefile|  1 +
 drivers/power/pmic/max77663.c  | 81 +
 include/power/max77663.h   | 40 +++
 5 files changed, 212 insertions(+)
 create mode 100644 doc/device-tree-bindings/pmic/max77663.txt
 create mode 100644 drivers/power/pmic/max77663.c
 create mode 100644 include/power/max77663.h

diff --git a/doc/device-tree-bindings/pmic/max77663.txt 
b/doc/device-tree-bindings/pmic/max77663.txt
new file mode 100644
index 00..ddb7d3eb14
--- /dev/null
+++ b/doc/device-tree-bindings/pmic/max77663.txt
@@ -0,0 +1,84 @@
+MAXIM, MAX77663 PMIC
+
+This device uses two drivers:
+- drivers/power/pmic/max77663.c (for parent device)
+- drivers/power/regulator/max77663_regulator.c (for child regulators)
+
+This chapter describes the binding info for the PMIC driver and regulators.
+
+Required properties for PMIC:
+- compatible: "maxim,max77663"
+- reg: usually 0x1c or 0x3c
+
+With those two properties, the pmic device can be used for read/write only.
+To bind each regulator, the optional regulators subnode should exists.
+
+Optional subnode:
+- name: regulators (subnode list of each device's regulator)
+
+Regulators subnode contains set on supported regulators.
+
+Required properties:
+- regulator-name: used for regulator uclass platform data '.name',
+
+List of supported regulator nodes names for max77663:
+- sd0, sd1, sd2, sd3, ldo0, ldo1, ldo2, ldo3, ldo4, ldo5, ldo6, ldo7, ldo8
+
+Optional:
+- regulator-min-microvolt: minimum allowed Voltage to set
+- regulator-max-microvolt: minimum allowed Voltage to set
+- regulator-always-on: regulator should be never disabled
+- regulator-boot-on: regulator should be enabled by the bootloader
+
+Linux driver binding for this driver is compatible.
+
+Example:
+
+max77663@1c {
+   compatible = "maxim,max77663";
+   reg = <0x1c>;
+
+   regulators {
+   sd0 {
+   regulator-name = "vdd_cpu";
+   regulator-min-microvolt = <80>;
+   regulator-max-microvolt = <125>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   ...
+
+   ldo0 {
+   regulator-name = "avdd_pll";
+   regulator-min-microvolt = <120>;
+   regulator-max-microvolt = <120>;
+   };
+
+   ...
+
+   ldo2 {
+   regulator-name = "avdd_usb";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   ldo3 {
+   regulator-name = "vdd_sdmmc3";
+   regulator-min-microvolt = <300>;
+   regulator-max-microvolt = <300>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   ...
+
+   ldo8 {
+   regulator-name = "avdd_dsi_csi";
+   regulator-min-microvolt = <120>;
+   regulator-max-microvolt = <120>;
+   };
+   };
+};
diff --git a/drivers/power/pmic/Kconfig b/drivers/power/pmic/Kconfig
index 176fb07c65..abea0fe4ed 100644
--- a/drivers/power/pmic/Kconfig
+++ b/drivers/power/pmic/Kconfig
@@ -184,6 +184,12 @@ config SPL_DM_PMIC_PFUZE100
This config enables implementation of driver-model pmic uclass features
for PMIC PFUZE100 in SPL. The driver implements read/write operations.
 
+config DM_PMIC_MAX77663
+   bool "Enable Driver Model for PMIC MAX77663"
+   ---help---
+   This config enables implementation of driver-model pmic uclass features
+   for PMIC MAX77663. The driver implements read/write operations.
+
 config DM_PMIC_MAX77686
bool "Enable Driver Model for PMIC MAX77686"
---help---
diff --git a/drivers/power/pmic/Makefile b/drivers/power/pmic/Makefile
index 0b3b3d62d0..414a9d8225 100644
--- a/drivers/power/pmic/Makefile
+++ b/drivers/power/pmic/Makefile
@@ -6,6 +6,7 @@
 obj-$(CONFIG_$(SPL_TPL_)DM_PMIC) += pmic-uclass.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_FAN53555) += fan53555.o
 obj-$(CONFIG_$(SPL_)DM_PMIC_DA9063) += da9063.o
+obj-$(CONFIG_$(SPL_)DM_PMIC_MAX77663) += max77663.o
 obj-$(CONFIG_DM_PMIC_MAX77686) += max77686.o
 obj-$(CONFIG_DM_PMIC_MAX8998) += max8998.o
 obj-$(CONFIG_DM_PMIC_MC34708) += mc34708.o
diff --git a/drivers/power/pmic/max77663.c b/drivers/power/pmic/max77663.c
new file mode 

[PATCH v1 0/6] Add support for PMICs used on Tegra 3 devices

2023-07-14 Thread Svyatoslav Ryhel
Patch set adds basic support for PMICs used in many Tegra 3 devices.
All PMIC drivers are based on datasheets provided by vendors.
Implemented API include regulator set/get voltage enable/disable and
basic PMIC r/w capabilities.

Drivers were tested by me on LG P895 (max77663), HTC One X (TPS80032)
and ASUS TF300T (tps65911). Calculations and behavior were correct,
predictable and reproducible.

Svyatoslav Ryhel (6):
  power: pmic: add the base max77663 pmic support
  power: regulator: max77663: add regulator support
  power: pmic: add the base TPS80031 PMIC support
  power: regulator: tps80031: add regulator support
  power: pmic: tps65910: add TPS65911 PMIC support
  power: regulator: tps65911: add regulator support

 doc/device-tree-bindings/pmic/max77663.txt   |  84 +
 doc/device-tree-bindings/pmic/tps65911.txt   |  78 
 doc/device-tree-bindings/pmic/tps80031.txt   |  76 
 drivers/power/pmic/Kconfig   |  12 +
 drivers/power/pmic/Makefile  |   2 +
 drivers/power/pmic/max77663.c|  81 
 drivers/power/pmic/pmic_tps65910_dm.c|  26 +-
 drivers/power/pmic/tps80031.c|  82 
 drivers/power/regulator/Kconfig  |  24 ++
 drivers/power/regulator/Makefile |   3 +
 drivers/power/regulator/max77663_regulator.c | 362 ++
 drivers/power/regulator/tps65911_regulator.c | 375 +++
 drivers/power/regulator/tps80031_regulator.c | 296 +++
 include/power/max77663.h |  40 ++
 include/power/tps65910_pmic.h|  47 +++
 include/power/tps80031.h |  42 +++
 16 files changed, 1627 insertions(+), 3 deletions(-)
 create mode 100644 doc/device-tree-bindings/pmic/max77663.txt
 create mode 100644 doc/device-tree-bindings/pmic/tps65911.txt
 create mode 100644 doc/device-tree-bindings/pmic/tps80031.txt
 create mode 100644 drivers/power/pmic/max77663.c
 create mode 100644 drivers/power/pmic/tps80031.c
 create mode 100644 drivers/power/regulator/max77663_regulator.c
 create mode 100644 drivers/power/regulator/tps65911_regulator.c
 create mode 100644 drivers/power/regulator/tps80031_regulator.c
 create mode 100644 include/power/max77663.h
 create mode 100644 include/power/tps80031.h

-- 
2.39.2



Re: Pull request: u-boot-spi/master

2023-07-14 Thread Tom Rini
On Thu, Jul 13, 2023 at 10:06:28PM +0530, Jagan Teki wrote:

> Hi Tom,
> 
> Please pull this PR.
> 
> Summary:
> - Add xtxtech spi-nor chip parts (Bruce Suen)
> - Add bcm63xx-hsspi driver fixes (William Zhang)
> 
> CI:
> https://source.denx.de/u-boot/custodians/u-boot-spi/-/pipelines/16886
> 
> thanks!
> Jagan.
> 
> The following changes since commit bf5152d0108683bbaabf9d7a7988f61649fc33f4:
> 
>   Merge branch 'master' of 
> https://source.denx.de/u-boot/custodians/u-boot-riscv (2023-07-12 13:10:04 
> -0400)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-spi master
> 
> for you to fetch changes up to 4a31e145217cecc3d421f96eafcd2cfd9c670929:
> 
>   mtd: spi-nor: Add support for w25q256jwm (2023-07-13 14:17:40 +0530)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: Please pull u-boot-marvell/master

2023-07-14 Thread Tom Rini
On Thu, Jul 13, 2023 at 04:03:08PM +0200, Stefan Roese wrote:

> Hi Tom,
> 
> please pull the following Marvell MVEBU related patches into master:
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: Pull request: please pull u-boot-imx-20230713

2023-07-14 Thread Tom Rini
On Thu, Jul 13, 2023 at 02:00:53PM +0200, Stefano Babic wrote:

> Hi Tom,
> 
> please pull from u-boot-imx, thanks !
> 
> The following changes since commit 146a82c017d51eb2c3b8be33854f200f1e52a1cb:
> 
>   Merge branch 'next' (2023-07-10 14:29:14 -0400)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-imx.git
> tags/u-boot-imx-20230713
> 
> for you to fetch changes up to cdbef023e2538da12b3ca4a2b8a5b7bd1c3ada02:
> 
>   mx7dsabresd: Retrieve the second MAC address from fuses (2023-07-13
> 11:58:18 +0200)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


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

2023-07-14 Thread Ying-Chun Liu (PaulLiu)

Reviewed-by: Ying-Chun Liu (PaulLiu) 


On 2023/5/11 00:59, Dmitrii Merkurev wrote:

Command to start IP6 only TCP fastboot:
fastboot tcp -ipv6

Signed-off-by: Dmitrii Merkurev 
Cc: Ying-Chun Liu (PaulLiu) 
Cc: Simon Glass 
Сс: Joe Hershberger 
Сс: Ramon Fried 
---
  cmd/fastboot.c   | 29 +
  doc/android/fastboot.rst |  8 +++-
  2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/cmd/fastboot.c b/cmd/fastboot.c
index 3d5ff951eb..36f744ae01 100644
--- a/cmd/fastboot.c
+++ b/cmd/fastboot.c
@@ -12,6 +12,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -121,10 +122,23 @@ static int do_fastboot(struct cmd_tbl *cmdtp, int flag, 
int argc,
  {
uintptr_t buf_addr = (uintptr_t)NULL;
size_t buf_size = 0;
+   bool is_ipv6_only = false;
+   bool is_usb = false;
+   bool is_udp = false;
+   bool is_tcp = false;
  
  	if (argc < 2)

return CMD_RET_USAGE;
  
+	if (IS_ENABLED(CONFIG_IPV6)) {

+   use_ip6 = false;
+   /* IPv6 parameter has to be always *last* */
+   if (!strcmp(argv[argc - 1], USE_IP6_CMD_PARAM)) {
+   is_ipv6_only = true;
+   --argc;
+   }
+   }
+
while (argc > 1 && **(argv + 1) == '-') {
char *arg = *++argv;
  
@@ -159,11 +173,18 @@ NXTARG:
  
  	fastboot_init((void *)buf_addr, buf_size);
  
-	if (!strcmp(argv[1], "udp"))

+   is_usb = strcmp(argv[1], "usb") == 0;
+   is_udp = strcmp(argv[1], "udp") == 0;
+   is_tcp = strcmp(argv[1], "tcp") == 0;
+
+   if (is_ipv6_only && is_tcp)
+   use_ip6 = true;
+
+   if (is_udp)
return do_fastboot_udp(argc, argv, buf_addr, buf_size);
-   if (!strcmp(argv[1], "tcp"))
+   if (is_tcp)
return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
-   if (!strcmp(argv[1], "usb")) {
+   if (is_usb) {
argv++;
argc--;
}
@@ -174,7 +195,7 @@ NXTARG:
  U_BOOT_CMD(
fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
"run as a fastboot usb or udp device",
-   "[-l addr] [-s size] usb  | udp\n"
+   "[-l addr] [-s size] usb  | udp [-ipv6] | tcp [-ipv6]\n"
"\taddr - address of buffer used during data transfers ("
__stringify(CONFIG_FASTBOOT_BUF_ADDR) ")\n"
"\tsize - size of buffer used during data transfers ("
diff --git a/doc/android/fastboot.rst b/doc/android/fastboot.rst
index 1ad8a897c8..aa6e9e5a9e 100644
--- a/doc/android/fastboot.rst
+++ b/doc/android/fastboot.rst
@@ -181,13 +181,19 @@ Enter into fastboot by executing the fastboot command in 
U-Boot for either USB::
  
 => fastboot usb 0
  
-or UDP::

+UDP::
  
 => fastboot udp

 link up on port 0, speed 100, full duplex
 Using ethernet@4a10 device
 Listening for fastboot command on 192.168.0.102
  
+or TCP::

+
+   => fastboot tcp
+   Using ethernet@4a10 device
+   Listening for fastboot command on 192.168.0.102
+
  On the client side you can fetch the bootloader version for instance::
  
 $ fastboot getvar version-bootloader


[PATCH v3 6/7] clk: treewide: switch to clock dump from clk_ops

2023-07-14 Thread Igor Prusov
Switch to using new dump operation in clock provider drivers instead of
overriding soc_clk_dump.

Signed-off-by: Igor Prusov 
---
 arch/mips/mach-pic32/cpu.c | 23 ---
 drivers/clk/aspeed/clk_ast2600.c   | 13 -
 drivers/clk/clk_k210.c | 11 +++-
 drivers/clk/clk_pic32.c| 39 ++
 drivers/clk/clk_versal.c   |  7 -
 drivers/clk/clk_zynq.c | 19 -
 drivers/clk/clk_zynqmp.c   | 13 -
 drivers/clk/imx/clk-imx8.c | 11 +++-
 drivers/clk/mvebu/armada-37xx-periph.c |  5 +++-
 drivers/clk/stm32/clk-stm32mp1.c   | 29 ++-
 10 files changed, 83 insertions(+), 87 deletions(-)

diff --git a/arch/mips/mach-pic32/cpu.c b/arch/mips/mach-pic32/cpu.c
index ec3c250531..99401745da 100644
--- a/arch/mips/mach-pic32/cpu.c
+++ b/arch/mips/mach-pic32/cpu.c
@@ -148,26 +148,3 @@ const char *get_core_name(void)
return str;
 }
 #endif
-#ifdef CONFIG_CMD_CLK
-
-int soc_clk_dump(void)
-{
-   int i;
-
-   printf("PLL Speed: %lu MHz\n",
-  CLK_MHZ(rate(PLLCLK)));
-
-   printf("CPU Speed: %lu MHz\n", CLK_MHZ(rate(PB7CLK)));
-
-   printf("MPLL Speed: %lu MHz\n", CLK_MHZ(rate(MPLL)));
-
-   for (i = PB1CLK; i <= PB7CLK; i++)
-   printf("PB%d Clock Speed: %lu MHz\n", i - PB1CLK + 1,
-  CLK_MHZ(rate(i)));
-
-   for (i = REF1CLK; i <= REF5CLK; i++)
-   printf("REFO%d Clock Speed: %lu MHz\n", i - REF1CLK + 1,
-  CLK_MHZ(rate(i)));
-   return 0;
-}
-#endif
diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c
index b3cc8392fa..e1365d3f81 100644
--- a/drivers/clk/aspeed/clk_ast2600.c
+++ b/drivers/clk/aspeed/clk_ast2600.c
@@ -1109,6 +1109,7 @@ struct aspeed_clks {
const char *name;
 };
 
+#if IS_ENABLED(CONFIG_CMD_CLK)
 static struct aspeed_clks aspeed_clk_names[] = {
{ ASPEED_CLK_HPLL, "hpll" },
{ ASPEED_CLK_MPLL, "mpll" },
@@ -1123,18 +1124,12 @@ static struct aspeed_clks aspeed_clk_names[] = {
{ ASPEED_CLK_HUARTX, "huxclk" },
 };
 
-int soc_clk_dump(void)
+static int ast2600_clk_dump(struct udevice *dev)
 {
-   struct udevice *dev;
struct clk clk;
unsigned long rate;
int i, ret;
 
-   ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(aspeed_scu),
- );
-   if (ret)
-   return ret;
-
printf("Clk\t\tHz\n");
 
for (i = 0; i < ARRAY_SIZE(aspeed_clk_names); i++) {
@@ -1167,11 +1162,15 @@ int soc_clk_dump(void)
 
return 0;
 }
+#endif
 
 struct clk_ops ast2600_clk_ops = {
.get_rate = ast2600_clk_get_rate,
.set_rate = ast2600_clk_set_rate,
.enable = ast2600_clk_enable,
+#if IS_ENABLED(CONFIG_CMD_CLK)
+   .dump = ast2600_clk_dump,
+#endif
 };
 
 static int ast2600_clk_probe(struct udevice *dev)
diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c
index 2f17152021..058940b828 100644
--- a/drivers/clk/clk_k210.c
+++ b/drivers/clk/clk_k210.c
@@ -1276,16 +1276,10 @@ static void show_clks(struct k210_clk_priv *priv, int 
id, int depth)
}
 }
 
-int soc_clk_dump(void)
+static int k210_clk_dump(struct udevice *dev)
 {
-   int ret;
-   struct udevice *dev;
struct k210_clk_priv *priv;
 
-   ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(k210_clk),
- );
-   if (ret)
-   return ret;
priv = dev_get_priv(dev);
 
puts(" Rate  Enabled Name\n");
@@ -1304,6 +1298,9 @@ static const struct clk_ops k210_clk_ops = {
.set_parent = k210_clk_set_parent,
.enable = k210_clk_enable,
.disable = k210_clk_disable,
+#if IS_ENABLED(CONFIG_CMD_CLK)
+   .dump = k210_clk_dump,
+#endif
 };
 
 static int k210_clk_probe(struct udevice *dev)
diff --git a/drivers/clk/clk_pic32.c b/drivers/clk/clk_pic32.c
index ef06a7fb9f..f756fc88f0 100644
--- a/drivers/clk/clk_pic32.c
+++ b/drivers/clk/clk_pic32.c
@@ -20,6 +20,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#define CLK_MHZ(x) ((x) / 100)
+
 /* Primary oscillator */
 #define SYS_POSC_CLK_HZ2400
 
@@ -385,9 +387,46 @@ static ulong pic32_set_rate(struct clk *clk, ulong rate)
return rate;
 }
 
+#if IS_ENABLED(CONFIG_CMD_CLK)
+static int pic32_dump(struct udevice *dev)
+{
+   int i;
+   struct clk clk;
+
+   clk.dev = dev;
+
+   clk.id = PLLCLK;
+   printf("PLL Speed: %lu MHz\n",
+  CLK_MHZ(pic32_get_rate()));
+
+   clk.id = PB7CLK;
+   printf("CPU Speed: %lu MHz\n", CLK_MHZ(pic32_get_rate()));
+
+   clk.id = MPLL;
+   printf("MPLL Speed: %lu MHz\n", CLK_MHZ(pic32_get_rate()));
+
+   for (i = PB1CLK; i <= PB7CLK; i++) {
+   clk.id = i;
+   printf("PB%d Clock Speed: %lu MHz\n", i - PB1CLK + 1,
+  

[PATCH v3 7/7] cmd: clk: Make soc_clk_dump static

2023-07-14 Thread Igor Prusov
After introducing dump to clk_ops there is no need to override or expose
this symbol anymore.

Signed-off-by: Igor Prusov 
---
 cmd/clk.c | 4 ++--
 include/clk.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/cmd/clk.c b/cmd/clk.c
index 55fb96e631..59155d7902 100644
--- a/cmd/clk.c
+++ b/cmd/clk.c
@@ -59,7 +59,7 @@ static void show_clks(struct udevice *dev, int depth, int 
last_flag)
}
 }
 
-int __weak soc_clk_dump(void)
+static int soc_clk_dump(void)
 {
struct udevice *dev;
const struct clk_ops *ops;
@@ -81,7 +81,7 @@ int __weak soc_clk_dump(void)
return 0;
 }
 #else
-int __weak soc_clk_dump(void)
+static int soc_clk_dump(void)
 {
puts("Not implemented\n");
return 1;
diff --git a/include/clk.h b/include/clk.h
index d91285235f..bf0d9c9d7f 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -674,8 +674,6 @@ static inline bool clk_valid(struct clk *clk)
return clk && !!clk->dev;
 }
 
-int soc_clk_dump(void);
-
 #endif
 
 #define clk_prepare_enable(clk) clk_enable(clk)
-- 
2.34.1



[PATCH v3 5/7] cmd: clk: Use dump function from clk_ops

2023-07-14 Thread Igor Prusov
Add another loop to dump additional info from clock providers that
implement dump operation.

Signed-off-by: Igor Prusov 
---
 cmd/clk.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/cmd/clk.c b/cmd/clk.c
index ff7c7649a1..55fb96e631 100644
--- a/cmd/clk.c
+++ b/cmd/clk.c
@@ -62,6 +62,7 @@ static void show_clks(struct udevice *dev, int depth, int 
last_flag)
 int __weak soc_clk_dump(void)
 {
struct udevice *dev;
+   const struct clk_ops *ops;
 
printf(" Rate   Usecnt  Name\n");
printf("--\n");
@@ -69,6 +70,14 @@ int __weak soc_clk_dump(void)
uclass_foreach_dev_probe(UCLASS_CLK, dev)
show_clks(dev, -1, 0);
 
+   uclass_foreach_dev_probe(UCLASS_CLK, dev) {
+   ops = dev_get_driver_ops(dev);
+   if (ops && ops->dump) {
+   printf("--\n");
+   ops->dump(dev);
+   }
+   }
+
return 0;
 }
 #else
-- 
2.34.1



[PATCH v3 4/7] clk: Add dump operation to clk_ops

2023-07-14 Thread Igor Prusov
This adds dump function to struct clk_ops which should replace
soc_clk_dump. It allows clock drivers to provide custom dump
implementation without overriding generic CCF dump function.

Signed-off-by: Igor Prusov 
---
 include/clk-uclass.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/clk-uclass.h b/include/clk-uclass.h
index 65ebff9ed2..f29f4c0d01 100644
--- a/include/clk-uclass.h
+++ b/include/clk-uclass.h
@@ -39,6 +39,9 @@ struct clk_ops {
int (*set_parent)(struct clk *clk, struct clk *parent);
int (*enable)(struct clk *clk);
int (*disable)(struct clk *clk);
+#if IS_ENABLED(CONFIG_CMD_CLK)
+   int (*dump)(struct udevice *dev);
+#endif
 };
 
 #if 0 /* For documentation only */
-- 
2.34.1



[PATCH v3 3/7] clk: k210: Move soc_clk_dump function

2023-07-14 Thread Igor Prusov
Move clock dump function to avoid forward declaration after switching to
dump in clk_ops.

Signed-off-by: Igor Prusov 
---
 drivers/clk/clk_k210.c | 92 +-
 1 file changed, 46 insertions(+), 46 deletions(-)

diff --git a/drivers/clk/clk_k210.c b/drivers/clk/clk_k210.c
index c534cc07e0..2f17152021 100644
--- a/drivers/clk/clk_k210.c
+++ b/drivers/clk/clk_k210.c
@@ -1238,52 +1238,6 @@ static int k210_clk_request(struct clk *clk)
return 0;
 }
 
-static const struct clk_ops k210_clk_ops = {
-   .request = k210_clk_request,
-   .set_rate = k210_clk_set_rate,
-   .get_rate = k210_clk_get_rate,
-   .set_parent = k210_clk_set_parent,
-   .enable = k210_clk_enable,
-   .disable = k210_clk_disable,
-};
-
-static int k210_clk_probe(struct udevice *dev)
-{
-   int ret;
-   struct k210_clk_priv *priv = dev_get_priv(dev);
-
-   priv->base = dev_read_addr_ptr(dev_get_parent(dev));
-   if (!priv->base)
-   return -EINVAL;
-
-   ret = clk_get_by_index(dev, 0, >in0);
-   if (ret)
-   return ret;
-
-   /*
-* Force setting defaults, even before relocation. This is so we can
-* set the clock rate for PLL1 before we relocate into aisram.
-*/
-   if (!(gd->flags & GD_FLG_RELOC))
-   clk_set_defaults(dev, CLK_DEFAULTS_POST_FORCE);
-
-   return 0;
-}
-
-static const struct udevice_id k210_clk_ids[] = {
-   { .compatible = "canaan,k210-clk" },
-   { },
-};
-
-U_BOOT_DRIVER(k210_clk) = {
-   .name = "k210_clk",
-   .id = UCLASS_CLK,
-   .of_match = k210_clk_ids,
-   .ops = _clk_ops,
-   .probe = k210_clk_probe,
-   .priv_auto = sizeof(struct k210_clk_priv),
-};
-
 #if IS_ENABLED(CONFIG_CMD_CLK)
 static char show_enabled(struct k210_clk_priv *priv, int id)
 {
@@ -1342,3 +1296,49 @@ int soc_clk_dump(void)
return 0;
 }
 #endif
+
+static const struct clk_ops k210_clk_ops = {
+   .request = k210_clk_request,
+   .set_rate = k210_clk_set_rate,
+   .get_rate = k210_clk_get_rate,
+   .set_parent = k210_clk_set_parent,
+   .enable = k210_clk_enable,
+   .disable = k210_clk_disable,
+};
+
+static int k210_clk_probe(struct udevice *dev)
+{
+   int ret;
+   struct k210_clk_priv *priv = dev_get_priv(dev);
+
+   priv->base = dev_read_addr_ptr(dev_get_parent(dev));
+   if (!priv->base)
+   return -EINVAL;
+
+   ret = clk_get_by_index(dev, 0, >in0);
+   if (ret)
+   return ret;
+
+   /*
+* Force setting defaults, even before relocation. This is so we can
+* set the clock rate for PLL1 before we relocate into aisram.
+*/
+   if (!(gd->flags & GD_FLG_RELOC))
+   clk_set_defaults(dev, CLK_DEFAULTS_POST_FORCE);
+
+   return 0;
+}
+
+static const struct udevice_id k210_clk_ids[] = {
+   { .compatible = "canaan,k210-clk" },
+   { },
+};
+
+U_BOOT_DRIVER(k210_clk) = {
+   .name = "k210_clk",
+   .id = UCLASS_CLK,
+   .of_match = k210_clk_ids,
+   .ops = _clk_ops,
+   .probe = k210_clk_probe,
+   .priv_auto = sizeof(struct k210_clk_priv),
+};
-- 
2.34.1



[PATCH v3 0/7] clk: Switch from soc_clk_dump to clk_ops function

2023-07-14 Thread Igor Prusov
Currently clock providers may override default implementation of
soc_clk_dump function to replace clk dump command output. This causes
confusing behaviour when u-boot is built with one of such drivers
enabled but still has clocks defined using CCF. For example, enabling
CMD_CLK and using clk dump on sandbox target will not show CCF clocks
because k210 driver overrides common soc_clk_dump.

Changelog:
 v1 -> v2:
 - Add missing static to dump functions
 v2 -> v3:
 - Make soc_clk_dump in cmd/clk.c static instead of removing __weak

Igor Prusov (7):
  clk: zynq: Move soc_clk_dump to Zynq clock driver
  clk: ast2600: Move soc_clk_dump function
  clk: k210: Move soc_clk_dump function
  clk: Add dump operation to clk_ops
  cmd: clk: Use dump function from clk_ops
  clk: treewide: switch to clock dump from clk_ops
  cmd: clk: Make soc_clk_dump static

 arch/arm/mach-zynq/clk.c   |  57 --
 arch/mips/mach-pic32/cpu.c |  23 --
 cmd/clk.c  |  13 +++-
 drivers/clk/aspeed/clk_ast2600.c   |  83 ++--
 drivers/clk/clk_k210.c | 103 -
 drivers/clk/clk_pic32.c|  39 ++
 drivers/clk/clk_versal.c   |   7 +-
 drivers/clk/clk_zynq.c |  51 
 drivers/clk/clk_zynqmp.c   |  13 ++--
 drivers/clk/imx/clk-imx8.c |  11 +--
 drivers/clk/mvebu/armada-37xx-periph.c |   5 +-
 drivers/clk/stm32/clk-stm32mp1.c   |  29 ++-
 include/clk-uclass.h   |   3 +
 include/clk.h  |   2 -
 14 files changed, 223 insertions(+), 216 deletions(-)

-- 
2.34.1



[PATCH v3 1/7] clk: zynq: Move soc_clk_dump to Zynq clock driver

2023-07-14 Thread Igor Prusov
Move clock dump function in preparation for switching to dump function
in clk_ops.

Signed-off-by: Igor Prusov 
Acked-by: Michal Simek 
---
 arch/arm/mach-zynq/clk.c | 57 ---
 drivers/clk/clk_zynq.c   | 58 
 2 files changed, 58 insertions(+), 57 deletions(-)

diff --git a/arch/arm/mach-zynq/clk.c b/arch/arm/mach-zynq/clk.c
index 1945f60e08..e6a67326dd 100644
--- a/arch/arm/mach-zynq/clk.c
+++ b/arch/arm/mach-zynq/clk.c
@@ -13,20 +13,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static const char * const clk_names[clk_max] = {
-   "armpll", "ddrpll", "iopll",
-   "cpu_6or4x", "cpu_3or2x", "cpu_2x", "cpu_1x",
-   "ddr2x", "ddr3x", "dci",
-   "lqspi", "smc", "pcap", "gem0", "gem1",
-   "fclk0", "fclk1", "fclk2", "fclk3", "can0", "can1",
-   "sdio0", "sdio1", "uart0", "uart1", "spi0", "spi1", "dma",
-   "usb0_aper", "usb1_aper", "gem0_aper", "gem1_aper",
-   "sdio0_aper", "sdio1_aper", "spi0_aper", "spi1_aper",
-   "can0_aper", "can1_aper", "i2c0_aper", "i2c1_aper",
-   "uart0_aper", "uart1_aper", "gpio_aper", "lqspi_aper",
-   "smc_aper", "swdt", "dbg_trc", "dbg_apb"
-};
-
 /**
  * set_cpu_clk_info() - Setup clock information
  *
@@ -65,46 +51,3 @@ int set_cpu_clk_info(void)
 
return 0;
 }
-
-/**
- * soc_clk_dump() - Print clock frequencies
- * Returns zero on success
- *
- * Implementation for the clk dump command.
- */
-int soc_clk_dump(void)
-{
-   struct udevice *dev;
-   int i, ret;
-
-   ret = uclass_get_device_by_driver(UCLASS_CLK,
-   DM_DRIVER_GET(zynq_clk), );
-   if (ret)
-   return ret;
-
-   printf("clk\t\tfrequency\n");
-   for (i = 0; i < clk_max; i++) {
-   const char *name = clk_names[i];
-   if (name) {
-   struct clk clk;
-   unsigned long rate;
-
-   clk.id = i;
-   ret = clk_request(dev, );
-   if (ret < 0)
-   return ret;
-
-   rate = clk_get_rate();
-
-   clk_free();
-
-   if ((rate == (unsigned long)-ENOSYS) ||
-   (rate == (unsigned long)-ENXIO))
-   printf("%10s%20s\n", name, "unknown");
-   else
-   printf("%10s%20lu\n", name, rate);
-   }
-   }
-
-   return 0;
-}
diff --git a/drivers/clk/clk_zynq.c b/drivers/clk/clk_zynq.c
index e80500e382..be5226175f 100644
--- a/drivers/clk/clk_zynq.c
+++ b/drivers/clk/clk_zynq.c
@@ -454,6 +454,64 @@ static int dummy_enable(struct clk *clk)
return 0;
 }
 
+static const char * const clk_names[clk_max] = {
+   "armpll", "ddrpll", "iopll",
+   "cpu_6or4x", "cpu_3or2x", "cpu_2x", "cpu_1x",
+   "ddr2x", "ddr3x", "dci",
+   "lqspi", "smc", "pcap", "gem0", "gem1",
+   "fclk0", "fclk1", "fclk2", "fclk3", "can0", "can1",
+   "sdio0", "sdio1", "uart0", "uart1", "spi0", "spi1", "dma",
+   "usb0_aper", "usb1_aper", "gem0_aper", "gem1_aper",
+   "sdio0_aper", "sdio1_aper", "spi0_aper", "spi1_aper",
+   "can0_aper", "can1_aper", "i2c0_aper", "i2c1_aper",
+   "uart0_aper", "uart1_aper", "gpio_aper", "lqspi_aper",
+   "smc_aper", "swdt", "dbg_trc", "dbg_apb"
+};
+
+/**
+ * soc_clk_dump() - Print clock frequencies
+ * Returns zero on success
+ *
+ * Implementation for the clk dump command.
+ */
+int soc_clk_dump(void)
+{
+   struct udevice *dev;
+   int i, ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_CLK,
+ DM_DRIVER_GET(zynq_clk), );
+   if (ret)
+   return ret;
+
+   printf("clk\t\tfrequency\n");
+   for (i = 0; i < clk_max; i++) {
+   const char *name = clk_names[i];
+
+   if (name) {
+   struct clk clk;
+   unsigned long rate;
+
+   clk.id = i;
+   ret = clk_request(dev, );
+   if (ret < 0)
+   return ret;
+
+   rate = clk_get_rate();
+
+   clk_free();
+
+   if ((rate == (unsigned long)-ENOSYS) ||
+   (rate == (unsigned long)-ENXIO))
+   printf("%10s%20s\n", name, "unknown");
+   else
+   printf("%10s%20lu\n", name, rate);
+   }
+   }
+
+   return 0;
+}
+
 static struct clk_ops zynq_clk_ops = {
.get_rate = zynq_clk_get_rate,
 #ifndef CONFIG_SPL_BUILD
-- 
2.34.1



[PATCH v3 2/7] clk: ast2600: Move soc_clk_dump function

2023-07-14 Thread Igor Prusov
Move clock dump function to avoid forward declaration after switching to
dump in clk_ops.

Signed-off-by: Igor Prusov 
---
 drivers/clk/aspeed/clk_ast2600.c | 70 
 1 file changed, 35 insertions(+), 35 deletions(-)

diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c
index e5ada5b6d4..b3cc8392fa 100644
--- a/drivers/clk/aspeed/clk_ast2600.c
+++ b/drivers/clk/aspeed/clk_ast2600.c
@@ -1104,41 +1104,6 @@ static int ast2600_clk_enable(struct clk *clk)
return 0;
 }
 
-struct clk_ops ast2600_clk_ops = {
-   .get_rate = ast2600_clk_get_rate,
-   .set_rate = ast2600_clk_set_rate,
-   .enable = ast2600_clk_enable,
-};
-
-static int ast2600_clk_probe(struct udevice *dev)
-{
-   struct ast2600_clk_priv *priv = dev_get_priv(dev);
-
-   priv->scu = devfdt_get_addr_ptr(dev);
-   if (IS_ERR(priv->scu))
-   return PTR_ERR(priv->scu);
-
-   ast2600_init_rgmii_clk(priv->scu, _clk_defconfig);
-   ast2600_init_rmii_clk(priv->scu, _clk_defconfig);
-   ast2600_configure_mac12_clk(priv->scu);
-   ast2600_configure_mac34_clk(priv->scu);
-   ast2600_configure_rsa_ecc_clk(priv->scu);
-
-   return 0;
-}
-
-static int ast2600_clk_bind(struct udevice *dev)
-{
-   int ret;
-
-   /* The reset driver does not have a device node, so bind it here */
-   ret = device_bind_driver(gd->dm_root, "ast_sysreset", "reset", );
-   if (ret)
-   debug("Warning: No reset driver: ret=%d\n", ret);
-
-   return 0;
-}
-
 struct aspeed_clks {
ulong id;
const char *name;
@@ -1203,6 +1168,41 @@ int soc_clk_dump(void)
return 0;
 }
 
+struct clk_ops ast2600_clk_ops = {
+   .get_rate = ast2600_clk_get_rate,
+   .set_rate = ast2600_clk_set_rate,
+   .enable = ast2600_clk_enable,
+};
+
+static int ast2600_clk_probe(struct udevice *dev)
+{
+   struct ast2600_clk_priv *priv = dev_get_priv(dev);
+
+   priv->scu = devfdt_get_addr_ptr(dev);
+   if (IS_ERR(priv->scu))
+   return PTR_ERR(priv->scu);
+
+   ast2600_init_rgmii_clk(priv->scu, _clk_defconfig);
+   ast2600_init_rmii_clk(priv->scu, _clk_defconfig);
+   ast2600_configure_mac12_clk(priv->scu);
+   ast2600_configure_mac34_clk(priv->scu);
+   ast2600_configure_rsa_ecc_clk(priv->scu);
+
+   return 0;
+}
+
+static int ast2600_clk_bind(struct udevice *dev)
+{
+   int ret;
+
+   /* The reset driver does not have a device node, so bind it here */
+   ret = device_bind_driver(gd->dm_root, "ast_sysreset", "reset", );
+   if (ret)
+   debug("Warning: No reset driver: ret=%d\n", ret);
+
+   return 0;
+}
+
 static const struct udevice_id ast2600_clk_ids[] = {
{ .compatible = "aspeed,ast2600-scu", },
{ },
-- 
2.34.1



[PATCH v2 3/3] arm: mach-k3: am62: Fixup CPU core, gpu and pru nodes in fdt

2023-07-14 Thread Francesco Dolcini
From: Emanuele Ghidoli 

AM62x SoC is available in multiple variant:
- CPU cores (Cortex-A) AM62x1 (1 core), AM62x2 (2 cores), AM62x4 (4 cores)
- GPU AM625x with GPU, AM623x without GPU
- PRU (Programmable RT unit) can be present or not on AM62x2/AM62x4

Remove the relevant FDT nodes by reading the actual configuration
from the SoC registers, with that change is possible to have a single
dts/dtb file handling the different variant at runtime.
While removing GPU node and CPU nodes also the watchdog node
in the same Module Domain is removed.

A similar approach is implemented for example on i.MX8 and STM32MP1 SoC.

Signed-off-by: Emanuele Ghidoli 
Signed-off-by: Francesco Dolcini 
---
v2:
 - add GPU/PRU fixups
---
 arch/arm/mach-k3/Makefile |  1 +
 arch/arm/mach-k3/am625_fdt.c  | 71 +++
 arch/arm/mach-k3/common_fdt.c | 18 +
 3 files changed, 90 insertions(+)
 create mode 100644 arch/arm/mach-k3/am625_fdt.c

diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
index 499bdaa7153d..fd77b8bbba5c 100644
--- a/arch/arm/mach-k3/Makefile
+++ b/arch/arm/mach-k3/Makefile
@@ -15,6 +15,7 @@ ifeq ($(CONFIG_OF_LIBFDT)$(CONFIG_OF_SYSTEM_SETUP),yy)
 obj-$(CONFIG_SOC_K3_AM654) += am654_fdt.o
 obj-$(CONFIG_SOC_K3_J721E) += j721e_fdt.o
 obj-$(CONFIG_SOC_K3_J721S2) += j721s2_fdt.o
+obj-$(CONFIG_SOC_K3_AM625) += am625_fdt.o
 endif
 ifeq ($(CONFIG_SPL_BUILD),y)
 obj-$(CONFIG_SOC_K3_AM654) += am654_init.o
diff --git a/arch/arm/mach-k3/am625_fdt.c b/arch/arm/mach-k3/am625_fdt.c
new file mode 100644
index ..37806907af1a
--- /dev/null
+++ b/arch/arm/mach-k3/am625_fdt.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2023 Toradex - https://www.toradex.com/
+ */
+
+#include 
+#include "common_fdt.h"
+#include 
+
+static void fdt_fixup_cores_nodes_am625(void *blob, int core_nr)
+{
+   char node_path[32];
+
+   if (core_nr < 1)
+   return;
+
+   for (; core_nr < 4; core_nr++) {
+   snprintf(node_path, sizeof(node_path), "/cpus/cpu@%d", core_nr);
+   fdt_del_node_path(blob, node_path);
+   snprintf(node_path, sizeof(node_path), 
"/cpus/cpu-map/cluster0/core%d", core_nr);
+   fdt_del_node_path(blob, node_path);
+   snprintf(node_path, sizeof(node_path), 
"/bus@f/watchdog@e0%d", core_nr);
+   fdt_del_node_path(blob, node_path);
+   }
+}
+
+static void fdt_fixup_gpu_nodes_am625(void *blob, int has_gpu)
+{
+   if (!has_gpu) {
+   fdt_del_node_path(blob, "/bus@f/gpu@fd0");
+   fdt_del_node_path(blob, "/bus@f/watchdog@e0f");
+   }
+}
+
+static void fdt_fixup_pru_node_am625(void *blob, int has_pru)
+{
+   if (!has_pru)
+   fdt_del_node_path(blob, "/bus@f/pruss@3004");
+}
+
+static int k3_get_core_nr(void)
+{
+   u32 full_devid = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+
+   return (full_devid & JTAG_DEV_CORE_NR_MASK) >> JTAG_DEV_CORE_NR_SHIFT;
+}
+
+static int k3_has_pru(void)
+{
+   u32 full_devid = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+   u32 feature_mask = (full_devid & JTAG_DEV_FEATURES_MASK) >>
+  JTAG_DEV_FEATURES_SHIFT;
+
+   return !(feature_mask & JTAG_DEV_FEATURE_NO_PRU);
+}
+
+static int k3_has_gpu(void)
+{
+   u32 full_devid = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+
+   return (full_devid & JTAG_DEV_GPU_MASK) >> JTAG_DEV_GPU_SHIFT;
+}
+
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+   fdt_fixup_cores_nodes_am625(blob, k3_get_core_nr());
+   fdt_fixup_gpu_nodes_am625(blob, k3_has_gpu());
+   fdt_fixup_pru_node_am625(blob, k3_has_pru());
+
+   return 0;
+}
diff --git a/arch/arm/mach-k3/common_fdt.c b/arch/arm/mach-k3/common_fdt.c
index c86fe3a5890b..9478f605441f 100644
--- a/arch/arm/mach-k3/common_fdt.c
+++ b/arch/arm/mach-k3/common_fdt.c
@@ -93,3 +93,21 @@ int fdt_fixup_msmc_ram_k3(void *blob)
 
return ret;
 }
+
+int fdt_del_node_path(void *blob, const char *path)
+{
+   int ret;
+   int nodeoff;
+
+   nodeoff = fdt_path_offset(blob, path);
+   if (nodeoff < 0)
+   return 0; /* Not found, skip it */
+
+   ret = fdt_del_node(blob, nodeoff);
+   if (ret < 0)
+   printf("Unable to delete node %s, err=%s\n", path, 
fdt_strerror(ret));
+   else
+   debug("Deleted node %s\n", path);
+
+   return ret;
+}
-- 
2.25.1



[PATCH v2 2/3] arm: mach-k3: am62: Add CTRLMMR_WKUP_JTAG_DEVICE_ID register definition

2023-07-14 Thread Francesco Dolcini
From: Emanuele Ghidoli 

Add register address and relevant bitmasks and shifts.
Allow reading these information:
- device identification
- number of cores (part of device identification)
- features (currently: PRU / no PRU)
- security
- functional safety
- speed grade
- temperature grade
- package

Signed-off-by: Emanuele Ghidoli 
Signed-off-by: Francesco Dolcini 
Reviewed-by: Andrew Davis 
---
v2:
 - added reviewed-by afd
 - added GPU/PRU mask
---
 arch/arm/mach-k3/include/mach/am62_hardware.h | 22 +++
 1 file changed, 22 insertions(+)

diff --git a/arch/arm/mach-k3/include/mach/am62_hardware.h 
b/arch/arm/mach-k3/include/mach/am62_hardware.h
index 88d58947269a..acd2d109c2c5 100644
--- a/arch/arm/mach-k3/include/mach/am62_hardware.h
+++ b/arch/arm/mach-k3/include/mach/am62_hardware.h
@@ -20,6 +20,28 @@
 #define MCU_CTRL_MMR0_BASE 0x0450
 #define WKUP_CTRL_MMR0_BASE0x4300
 
+#define CTRLMMR_WKUP_JTAG_DEVICE_ID(WKUP_CTRL_MMR0_BASE + 0x18)
+#define JTAG_DEV_ID_MASK   GENMASK(31, 18)
+#define JTAG_DEV_ID_SHIFT  18
+#define JTAG_DEV_CORE_NR_MASK  GENMASK(21, 19)
+#define JTAG_DEV_CORE_NR_SHIFT 19
+#define JTAG_DEV_GPU_MASK  BIT(18)
+#define JTAG_DEV_GPU_SHIFT 18
+#define JTAG_DEV_FEATURES_MASK GENMASK(17, 13)
+#define JTAG_DEV_FEATURES_SHIFT13
+#define JTAG_DEV_SECURITY_MASK BIT(12)
+#define JTAG_DEV_SECURITY_SHIFT12
+#define JTAG_DEV_SAFETY_MASK   BIT(11)
+#define JTAG_DEV_SAFETY_SHIFT  11
+#define JTAG_DEV_SPEED_MASKGENMASK(10, 6)
+#define JTAG_DEV_SPEED_SHIFT   6
+#define JTAG_DEV_TEMP_MASK GENMASK(5, 3)
+#define JTAG_DEV_TEMP_SHIFT3
+#define JTAG_DEV_PKG_MASK  GENMASK(2, 0)
+#define JTAG_DEV_PKG_SHIFT 0
+
+#define JTAG_DEV_FEATURE_NO_PRU0x4
+
 #define CTRLMMR_MAIN_DEVSTAT   (WKUP_CTRL_MMR0_BASE + 0x30)
 #define MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK GENMASK(6, 3)
 #define MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT3
-- 
2.25.1



[PATCH v2 1/3] arm: k3: Fix ft_system_setup so it can be enabled on any SoC

2023-07-14 Thread Francesco Dolcini
From: Emanuele Ghidoli 

ft_system_setup cannot be enabled on SoC without msmc sram otherwise
fdt_fixup_msmc_ram function fails causing system reset.

Fix by moving fdt_fixup_msmc_ram to common_fdt.c file and creating
SoC (AM654, J721E and J721S2) specific files for fdt fixups.

This change was verified to not change anything on any existing board
(all the J721S2, AM654 and J721E boards requires it,
none of the remaining k3 boards require it).

Fixes: 30e96a240156 ("arm: mach-k3: Move MSMC fixup to SoC level")
Signed-off-by: Emanuele Ghidoli 
Signed-off-by: Francesco Dolcini 
---
v2:
 - Moved fdt common functions to to common_fdt.c and ft_system_setup function
   to specific SoC files (eg. am654_fdt.c) and compile them using relevant
   configuration
---
 arch/arm/mach-k3/Makefile |  6 +++
 arch/arm/mach-k3/am654_fdt.c  | 12 +
 arch/arm/mach-k3/common.c | 91 -
 arch/arm/mach-k3/common_fdt.c | 95 +++
 arch/arm/mach-k3/common_fdt.h | 11 
 arch/arm/mach-k3/j721e_fdt.c  | 12 +
 arch/arm/mach-k3/j721s2_fdt.c | 12 +
 7 files changed, 148 insertions(+), 91 deletions(-)
 create mode 100644 arch/arm/mach-k3/am654_fdt.c
 create mode 100644 arch/arm/mach-k3/common_fdt.c
 create mode 100644 arch/arm/mach-k3/common_fdt.h
 create mode 100644 arch/arm/mach-k3/j721e_fdt.c
 create mode 100644 arch/arm/mach-k3/j721s2_fdt.c

diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
index b5bc2367813c..499bdaa7153d 100644
--- a/arch/arm/mach-k3/Makefile
+++ b/arch/arm/mach-k3/Makefile
@@ -10,6 +10,12 @@ obj-$(CONFIG_SOC_K3_AM62A7) += am62ax/
 obj-$(CONFIG_ARM64) += arm64-mmu.o
 obj-$(CONFIG_CPU_V7R) += r5_mpu.o lowlevel_init.o
 obj-$(CONFIG_ARM64) += cache.o
+obj-$(CONFIG_OF_LIBFDT) += common_fdt.o
+ifeq ($(CONFIG_OF_LIBFDT)$(CONFIG_OF_SYSTEM_SETUP),yy)
+obj-$(CONFIG_SOC_K3_AM654) += am654_fdt.o
+obj-$(CONFIG_SOC_K3_J721E) += j721e_fdt.o
+obj-$(CONFIG_SOC_K3_J721S2) += j721s2_fdt.o
+endif
 ifeq ($(CONFIG_SPL_BUILD),y)
 obj-$(CONFIG_SOC_K3_AM654) += am654_init.o
 obj-$(CONFIG_SOC_K3_J721E) += j721e_init.o
diff --git a/arch/arm/mach-k3/am654_fdt.c b/arch/arm/mach-k3/am654_fdt.c
new file mode 100644
index ..652fe8d32bbb
--- /dev/null
+++ b/arch/arm/mach-k3/am654_fdt.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2023 Toradex - https://www.toradex.com/
+ */
+
+#include "common_fdt.h"
+#include 
+
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+   return fdt_fixup_msmc_ram_k3(blob);
+}
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 34737a43aa08..93c0e49e49b7 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -357,97 +357,6 @@ void board_fit_image_post_process(const void *fit, int 
node, void **p_image,
 }
 #endif
 
-#if defined(CONFIG_OF_LIBFDT)
-int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
-{
-   u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
-   struct ti_sci_handle *ti_sci = get_ti_sci_handle();
-   int ret, node, subnode, len, prev_node;
-   u32 range[4], addr, size;
-   const fdt32_t *sub_reg;
-
-   ti_sci->ops.core_ops.query_msmc(ti_sci, _start, _end);
-   msmc_size = msmc_end - msmc_start + 1;
-   debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
- msmc_start, msmc_size);
-
-   /* find or create "msmc_sram node */
-   ret = fdt_path_offset(blob, parent_path);
-   if (ret < 0)
-   return ret;
-
-   node = fdt_find_or_add_subnode(blob, ret, node_name);
-   if (node < 0)
-   return node;
-
-   ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
-   if (ret < 0)
-   return ret;
-
-   reg[0] = cpu_to_fdt64(msmc_start);
-   reg[1] = cpu_to_fdt64(msmc_size);
-   ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
-   if (ret < 0)
-   return ret;
-
-   fdt_setprop_cell(blob, node, "#address-cells", 1);
-   fdt_setprop_cell(blob, node, "#size-cells", 1);
-
-   range[0] = 0;
-   range[1] = cpu_to_fdt32(msmc_start >> 32);
-   range[2] = cpu_to_fdt32(msmc_start & 0x);
-   range[3] = cpu_to_fdt32(msmc_size);
-   ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
-   if (ret < 0)
-   return ret;
-
-   subnode = fdt_first_subnode(blob, node);
-   prev_node = 0;
-
-   /* Look for invalid subnodes and delete them */
-   while (subnode >= 0) {
-   sub_reg = fdt_getprop(blob, subnode, "reg", );
-   addr = fdt_read_number(sub_reg, 1);
-   sub_reg++;
-   size = fdt_read_number(sub_reg, 1);
-   debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
- subnode, addr, size);
-   if (addr + size > msmc_size ||
-   !strncmp(fdt_get_name(blob, subnode, ), 

[PATCH v2 0/3] arm: mach-k3: am62: Add core number, gpu and pru autodetection FDT fixups

2023-07-14 Thread Francesco Dolcini
From: Francesco Dolcini 

AM62x SoC is available in multiple variant:
 - CPU cores (Cortex-A) AM62x1 (1 core), AM62x2 (2 cores), AM62x4 (4 cores)
 - GPU AM625x with GPU, AM623x without GPU
 - PRU (Programmable RT unit) can be present or not on AM62x2/AM62x4

Remove the relevant FDT nodes by reading the actual configuration from the SoC
registers, with that change is possible to have a single dts/dtb file handling
the different variant at runtime.  While removing GPU node and CPU nodes also
the watchdog node in the same Module Domain is removed.

A similar approach is implemented for example on i.MX8 and STM32MP1 SoC.

Since we start using ft_system_setup on a SoC without msmc ram and
fdt_fixup_msmc_ram function fails on those SoC (triggering a reset loop) the
first commit fix it by calling that function only on specific SoC.


v2:
 - Moved fdt common functions to to common_fdt.c and ft_system_setup function
   to specific SoC files (eg. am654_fdt.c) and compile them using relevant
   configuration
 - Add GPU and PRU fdt fixup

v1: https://lore.kernel.org/all/20230712134730.30229-1-france...@dolcini.it/


Emanuele Ghidoli (3):
  arm: k3: Fix ft_system_setup so it can be enabled on any SoC
  arm: mach-k3: am62: Add CTRLMMR_WKUP_JTAG_DEVICE_ID register
definition
  arm: mach-k3: am62: Fixup CPU core, gpu and pru nodes in fdt

 arch/arm/mach-k3/Makefile |   7 ++
 arch/arm/mach-k3/am625_fdt.c  |  71 +++
 arch/arm/mach-k3/am654_fdt.c  |  12 ++
 arch/arm/mach-k3/common.c |  91 --
 arch/arm/mach-k3/common_fdt.c | 113 ++
 arch/arm/mach-k3/common_fdt.h |  11 ++
 arch/arm/mach-k3/include/mach/am62_hardware.h |  22 
 arch/arm/mach-k3/j721e_fdt.c  |  12 ++
 arch/arm/mach-k3/j721s2_fdt.c |  12 ++
 9 files changed, 260 insertions(+), 91 deletions(-)
 create mode 100644 arch/arm/mach-k3/am625_fdt.c
 create mode 100644 arch/arm/mach-k3/am654_fdt.c
 create mode 100644 arch/arm/mach-k3/common_fdt.c
 create mode 100644 arch/arm/mach-k3/common_fdt.h
 create mode 100644 arch/arm/mach-k3/j721e_fdt.c
 create mode 100644 arch/arm/mach-k3/j721s2_fdt.c

-- 
2.25.1



Re: [PATCH 14/18] board: ti: keys: add .key and .crt for fit signature signing

2023-07-14 Thread Andrew Davis

On 7/14/23 12:52 AM, Manorit Chawdhry wrote:

Fit signature mechanism through the standards require the presence of
.key and .crt in the folder with the same name, since we are using our
custMpk only for the signing, update the format to that of standards to
be compatible for packaging easily.

Signed-off-by: Manorit Chawdhry 
---
  board/ti/keys/custMpk.crt | 33 ++
  board/ti/keys/custMpk.key | 51 +++


The key file should be the same as board/ti/keys/custMpk.pem, right?
If so why do we need this new name?

Also the crt contains information about the person signing the
images, it should be generated at build time from a template,
not provided here in binary format. Certs also have an expiration
data, so this would become invalid at some point.

This whole series needs split up, the first half seems like mostly
reasonable cleanups. But the second half I'm not so sure about and
depends on the binman patches.

Andrew


  2 files changed, 84 insertions(+)

diff --git a/board/ti/keys/custMpk.crt b/board/ti/keys/custMpk.crt
new file mode 100644
index ..01bd64aae577
--- /dev/null
+++ b/board/ti/keys/custMpk.crt
@@ -0,0 +1,33 @@
+-BEGIN CERTIFICATE-
+MIIFwzCCA6sCFHKW0ueol0+vsilVaZyqKhppo9ryMA0GCSqGSIb3DQEBCwUAMIGd
+MQswCQYDVQQGEwJVUzELMAkGA1UECAwCVFgxDzANBgNVBAcMBkRhbGxhczEnMCUG
+A1UECgweVGV4YXMgSW5zdHJ1bWVudHMgSW5jb3Jwb3JhdGVkMRMwEQYDVQQLDApQ
+cm9jZXNzb3JzMRMwEQYDVQQDDApUSSBTdXBwb3J0MR0wGwYJKoZIhvcNAQkBFg5z
+dXBwb3J0QHRpLmNvbTAeFw0yMzA2MDEwNTIxMTZaFw0zMzA1MjkwNTIxMTZaMIGd
+MQswCQYDVQQGEwJVUzELMAkGA1UECAwCVFgxDzANBgNVBAcMBkRhbGxhczEnMCUG
+A1UECgweVGV4YXMgSW5zdHJ1bWVudHMgSW5jb3Jwb3JhdGVkMRMwEQYDVQQLDApQ
+cm9jZXNzb3JzMRMwEQYDVQQDDApUSSBTdXBwb3J0MR0wGwYJKoZIhvcNAQkBFg5z
+dXBwb3J0QHRpLmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAL8U
+rknYf3LTayPN60gOZdwiTfIOT4L27bXy3dt8kfpuWf/V97beBB2KzNKV2dHgxMH4
+UL//SAyRIlCaTHuL85YKKCazpNngqVVBGvs+Wydsv8rAca8vciLuRgElYq0+xwT2
+sRi2LMASbg/imz7lpqCoBkUDQRdOFh+pdNaETtZ5pxC4EakOkh8l3X+x8tG58mjY
+M1lLgn13zNGc+iO0+1iI8s3q1RbyLHUt+mLDwQlu4AZw4LUHCZli2dbk52xtyIIH
+UJP34tjt0V/j0J7Pk1TZX91dzjdg8asUigR7Zae6f99FRXxLoVuuTsaUPYxOh9KU
+PKTzn9r88jZ85w2tWkI38SqB0G6hp2cDHoftALtzSmgoMaKCmqMEweiH/0V+qsGf
+1DsFx4P9IXH+vX84yRYZUg7mAzONHR7JNhzNTp2CKYjNmyq+bF97srI6eQBqffWt
+Gp0ezVgqz170ToCrO0/d+NTeNKLEINlZGS2FAl4faLFMjbkRBuktdrVYjFCoN25m
+eG+DMEZNNJ+0GEq5u/p7xa7WMhCEhGw/moAzNfxNvNVuYFRQz35tgJcE+o8LIP29
+mCuhN71Z/UrsRaEJixfJchQztwVeEl3iWh3OIVT24erVVaon600J3xlAgi5miRdl
+2W6z1jhOjWEW1nTU3hZfURnVQriD0sjeS6lpl7aNAgMBAAEwDQYJKoZIhvcNAQEL
+BQADggIBAHy+h1FQKedFTJWgqGJkTwtcym5LyXD6ig8LyhJpVEbXmqK7ZKY2F2hB
+PqVbfCZNogszIvl8q3ykz+tcGbfBk3rq+KMUwbk5E29mSMmAJ9DNNozudgKkKq9w
+RmcO1bXCEspFgNvNEkYAQCBvMOyH/nCyFu9QzOzN35XIzf0fI3jM6rueLxSXq3xO
+7yHUZ3mzAZp6e1Qo6cuABAw1q6KqKYJCnJ3Nq6F42bmGp8mSD+2AuGV8cU+7Z3sh
+k/ooFMCsulj1R5+TlKgEfqspQXbefEsvRW3n3ZD8bcQF0ytiX7XVmDMFVpQkTzps
+92fjZ08Zcj7bCZQsFXXACIQkMiTiiMW6NwLFZDyq11/B1oe1bhjFUuqqUkHC/PKx
+gdWRwluGRt+onFRD5/upXnugKT99j/hQ7sy80a64A1xoCcKVbwcHU7YBQG1vLk6D
+idg0vI3gj7v+/jZEPkv/KrqAI6YuvpplkcHkEKuAUFAkozvVJ5pPK3K0xHBJGNMK
+kJ9FMAakFj6jfZaR5Ay3ZuOAn5oPMwd6RaauNOzVpBll6DFOyw2rU6fbId/gi841
+drmBfM6ufue6ecslkp9zSOpPLXhjt2g9NRVKPE20CmRetVSDLcMFet7ZImbxqggw
+yjDxA7oR+Px+o+xr+djcDlfj6500Rys6W1SNHe99HXOCcpQqivX0
+-END CERTIFICATE-
diff --git a/board/ti/keys/custMpk.key b/board/ti/keys/custMpk.key
new file mode 100644
index ..adba378c8008
--- /dev/null
+++ b/board/ti/keys/custMpk.key
@@ -0,0 +1,51 @@
+-BEGIN RSA PRIVATE KEY-
+MIIJKQIBAAKCAgEAvxSuSdh/ctNrI83rSA5l3CJN8g5PgvbttfLd23yR+m5Z/9X3
+tt4EHYrM0pXZ0eDEwfhQv/9IDJEiUJpMe4vzlgooJrOk2eCpVUEa+z5bJ2y/ysBx
+ry9yIu5GASVirT7HBPaxGLYswBJuD+KbPuWmoKgGRQNBF04WH6l01oRO1nmnELgR
+qQ6SHyXdf7Hy0bnyaNgzWUuCfXfM0Zz6I7T7WIjyzerVFvIsdS36YsPBCW7gBnDg
+tQcJmWLZ1uTnbG3IggdQk/fi2O3RX+PQns+TVNlf3V3ON2DxqxSKBHtlp7p/30VF
+fEuhW65OxpQ9jE6H0pQ8pPOf2vzyNnznDa1aQjfxKoHQbqGnZwMeh+0Au3NKaCgx
+ooKaowTB6If/RX6qwZ/UOwXHg/0hcf69fzjJFhlSDuYDM40dHsk2HM1OnYIpiM2b
+Kr5sX3uysjp5AGp99a0anR7NWCrPXvROgKs7T9341N40osQg2VkZLYUCXh9osUyN
+uREG6S12tViMUKg3bmZ4b4MwRk00n7QYSrm7+nvFrtYyEISEbD+agDM1/E281W5g
+VFDPfm2AlwT6jwsg/b2YK6E3vVn9SuxFoQmLF8lyFDO3BV4SXeJaHc4hVPbh6tVV
+qifrTQnfGUCCLmaJF2XZbrPWOE6NYRbWdNTeFl9RGdVCuIPSyN5LqWmXto0CAwEA
+AQKCAgAzkAwcJ0z1GnId/lJQZno8NhGckRoJuEKbR8dwlCP8VUz6Ca5H7Y9kvXDa
+Hs/hn+rYgP6hYOz7XyrIX2rmJ/T6dxEwqGeC1+o59FConcIRWHpE5zuGT6JYJL5F
+TuZa48bm4v8VMQvQZOjIZpkIFwao8c6HTwKAnHTB5IN/48I2hCt+Cn3RhfoOZ7Rm
+4gkpaSkt+7GXlhXHb82YfujNO+hbktEamhUYlQ9EK70Wa8aqmf3gHxO0JgsEFjW8
+lJaSnultlTW8SDcx3LMUUjCYumECk4oX/VlJfmKYjPlVjkr3QQ+Cm3nNucb4K4hc
+c+JL+2ERhSj8RjXL7VgbNgdPnIjvQDJuTNqecTU8xWPYrkOLQpNibbLjnutLkhJz
+fMyRtmDtrsey8WiCDuCHkPJ8/f8RjL2zWI9fzTDDIzdlEKouUFGOovaHVnbua6pn
+hymcu9d9FV3p2rcbj0ivCs7e8j+vhSxFJEJoAbcQdXCTi/n2uR7pLtoMNiUzsejy
+d46Uz+KEU920NTwE2z6JJq8I2vegnxjc7PDDrV3/5rK04B93aXiqvwWseCpxelrI
+xaMkRHbXrIXRO6MXQ3N+zNq8Dg3hjGTTvaBKuwgvqLwlXY8+Aa3ooFzEOInIOSsI
+XcWqXxt/tgZgsj9RwpC42t8kbA+BkbNk9EIUa+P5kEr2P/fO7QKCAQEA4EtArnOX

[PATCHv4 5/5] net/lwip: apps/http: add dns support

2023-07-14 Thread Maxim Uvarov
provide hostname to client and allow lwip to resolve it.

Signed-off-by: Maxim Uvarov 
---
 lib/lwip/apps/http/lwip-wget.c | 59 ++
 1 file changed, 53 insertions(+), 6 deletions(-)

diff --git a/lib/lwip/apps/http/lwip-wget.c b/lib/lwip/apps/http/lwip-wget.c
index 0308b0b04a..db553a0f14 100644
--- a/lib/lwip/apps/http/lwip-wget.c
+++ b/lib/lwip/apps/http/lwip-wget.c
@@ -45,18 +45,65 @@ static void httpc_result(void *arg, httpc_result_t 
httpc_result, u32_t rx_conten
}
 }
 
+/* http://hostname:port/url */
+static int parse_url(char *url, char *host, int *port)
+{
+   int ret;
+   char *p, *pp;
+
+   p = strstr(url, "http://;);
+   if (!p) {
+   printf("err: no http://!\n;);
+   return -1;
+   }
+
+   p += strlen("http://;);
+
+   /* parse hostname */
+   pp = strchr(p, ':');
+   if (pp) {
+   char portstr[5];
+
+   memcpy(host, p, pp - p);
+   host[pp - p + 1] = '\0';
+
+   p = pp + 1;
+   pp = strchr(p, '/');
+   if (!pp) {
+   printf("wrong url\n");
+   return -2;
+   }
+
+   memcpy(portstr, p, pp - p);
+   portstr[pp - p] = '\0';
+   *port = atoi(portstr);
+   } else {
+   pp = strchr(p, '/');
+   if (!pp) {
+   printf("wrong url\n");
+   return -3;
+   }
+   memcpy(host, p, pp - p);
+   host[pp - p + 1] = '\0';
+   *port = 80; /* default */
+   }
+
+   return 0;
+}
+
 int lwip_wget(ulong addr, char *url)
 {
err_t err;
-   int port = 80;
-   char *server_name;
+   int port;
+   char server_name[80];
httpc_state_t *connection;
 
daddr = addr;
-   server_name = env_get("serverip");
-   if (!server_name) {
-   printf("error: serverip variable has to be set\n");
-   return CMD_RET_FAILURE;
+
+   err = parse_url(url, server_name, );
+   if (err) {
+   printf("error parse_url\n");
+   return -1;
}
 
printf("downloading %s to addr 0x%lx\n", url, addr);
-- 
2.30.2



[PATCHv4 4/5] net/lwip: add dns command

2023-07-14 Thread Maxim Uvarov
dns lwip version of the command. This commmit might be
good example how to enable new network command.

Signed-off-by: Maxim Uvarov 
---
 cmd/net.c| 41 +++-
 lib/lwip/Kconfig |  2 +-
 lib/lwip/Makefile|  2 ++
 lib/lwip/apps/dns/lwip-dns.c | 46 
 lib/lwip/apps/dns/lwip-dns.h |  3 +++
 lib/lwip/cmd-lwip.c  | 39 ++
 lib/lwip/lwipopts.h  |  2 +-
 7 files changed, 95 insertions(+), 40 deletions(-)
 create mode 100644 lib/lwip/apps/dns/lwip-dns.c
 create mode 100644 lib/lwip/apps/dns/lwip-dns.h

diff --git a/cmd/net.c b/cmd/net.c
index 6d704fba86..2a68477aae 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -491,45 +491,10 @@ U_BOOT_CMD(
 #endif
 
 #if defined(CONFIG_CMD_DNS)
-int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
-   if (argc == 1)
-   return CMD_RET_USAGE;
-
-   /*
-* We should check for a valid hostname:
-* - Each label must be between 1 and 63 characters long
-* - the entire hostname has a maximum of 255 characters
-* - only the ASCII letters 'a' through 'z' (case-insensitive),
-*   the digits '0' through '9', and the hyphen
-* - cannot begin or end with a hyphen
-* - no other symbols, punctuation characters, or blank spaces are
-*   permitted
-* but hey - this is a minimalist implmentation, so only check length
-* and let the name server deal with things.
-*/
-   if (strlen(argv[1]) >= 255) {
-   printf("dns error: hostname too long\n");
-   return CMD_RET_FAILURE;
-   }
-
-   net_dns_resolve = argv[1];
-
-   if (argc == 3)
-   net_dns_env_var = argv[2];
-   else
-   net_dns_env_var = NULL;
-
-   if (net_loop(DNS) < 0) {
-   printf("dns lookup of %s failed, check setup\n", argv[1]);
-   return CMD_RET_FAILURE;
-   }
-
-   return CMD_RET_SUCCESS;
-}
-
+extern int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
+  char *const argv[]);
 U_BOOT_CMD(
-   dns,3,  1,  do_dns,
+   dns,3,  1,  do_lwip_dns,
"lookup the IP of a hostname",
"hostname [envvar]"
 );
diff --git a/lib/lwip/Kconfig b/lib/lwip/Kconfig
index 3688ac3305..5e9062a6da 100644
--- a/lib/lwip/Kconfig
+++ b/lib/lwip/Kconfig
@@ -26,7 +26,7 @@ config LWIP_LIB_UDP
 
 config LWIP_LIB_DNS
 bool "dns"
-default n
+default y
 
 config LWIP_LIB_DHCP
 bool "dhcp"
diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile
index e1a8a2a7b7..d6e511dff1 100644
--- a/lib/lwip/Makefile
+++ b/lib/lwip/Makefile
@@ -99,3 +99,5 @@ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/tftp.o
 obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/lwip-tftp.o
 
 obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o
+
+obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o
diff --git a/lib/lwip/apps/dns/lwip-dns.c b/lib/lwip/apps/dns/lwip-dns.c
new file mode 100644
index 00..04fd53bfcb
--- /dev/null
+++ b/lib/lwip/apps/dns/lwip-dns.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. 
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "../../../lwip/ulwip.h"
+
+static void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void 
*callback_arg)
+{
+   char *varname = (char *)callback_arg;
+
+   if (varname)
+   env_set(varname, ip4addr_ntoa(ipaddr));
+
+   printf("resolved %s to %s\n",  name, ip4addr_ntoa(ipaddr));
+   ulwip_exit(0);
+}
+
+int ulwip_dns(char *name, char *varname)
+{
+   int err;
+   ip_addr_t ipaddr; /* not used */
+   ip_addr_t dns1;
+   ip_addr_t dns2;
+
+   ipaddr_aton(env_get("dnsip"), );
+   ipaddr_aton(env_get("dnsip2"), );
+
+   dns_init();
+   dns_setserver(0, );
+   dns_setserver(1, );
+
+   err = dns_gethostbyname(name, , dns_found_cb, varname);
+   if (err == ERR_OK)
+   dns_found_cb(name, , varname);
+
+   return err;
+}
diff --git a/lib/lwip/apps/dns/lwip-dns.h b/lib/lwip/apps/dns/lwip-dns.h
new file mode 100644
index 00..c59f99e099
--- /dev/null
+++ b/lib/lwip/apps/dns/lwip-dns.h
@@ -0,0 +1,3 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+int ulwip_dns(char *name, char *varname);
diff --git a/lib/lwip/cmd-lwip.c b/lib/lwip/cmd-lwip.c
index 625c8c53b8..86b35ccff8 100644
--- a/lib/lwip/cmd-lwip.c
+++ b/lib/lwip/cmd-lwip.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 
+#include "apps/dns/lwip-dns.h"
 #include "apps/ping/lwip_ping.h"
 #include "ulwip.h"
 
@@ -208,6 +209,39 @@ static int _do_lwip_dhcp(struct cmd_tbl *cmdtp, int flag, 
int argc,
 }
 #endif /* CONFIG_CMD_DHCP */
 
+#if defined(CONFIG_CMD_DNS)
+int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   int ret;
+   char 

[PATCHv4 2/5] net/lwip: add lwip library for the network stack

2023-07-14 Thread Maxim Uvarov
This commit adds lwip library for the U-boot network
stack. Supported commands: ping, tftp, dhcp and wget.

Signed-off-by: Maxim Uvarov 
---
 .gitignore|   9 +
 boot/bootmeth_pxe.c   |   2 +-
 cmd/net.c |  48 +
 cmd/pxe.c |   2 +-
 include/net.h |   8 +-
 lib/Kconfig   |   2 +
 lib/Makefile  |   2 +
 lib/lwip/Kconfig  |  63 ++
 lib/lwip/Makefile | 101 ++
 lib/lwip/apps/dhcp/lwip-dhcp.c|  52 +
 lib/lwip/apps/http/lwip-wget.c|  74 +++
 lib/lwip/apps/ping/lwip_ping.c|  37 
 lib/lwip/apps/ping/lwip_ping.h|  24 +++
 lib/lwip/apps/ping/ping.h |  35 
 lib/lwip/apps/tftp/lwip-tftp.c| 124 
 lib/lwip/cmd-lwip.c   | 269 ++
 lib/lwip/lwipopts.h   | 203 +++
 lib/lwip/port/if.c| 260 +
 lib/lwip/port/include/arch/cc.h   |  46 +
 lib/lwip/port/include/arch/sys_arch.h |  59 ++
 lib/lwip/port/include/limits.h|   0
 lib/lwip/port/sys-arch.c  |  20 ++
 lib/lwip/ulwip.h  |   9 +
 net/Kconfig   |   1 +
 net/net.c |  24 +++
 25 files changed, 1430 insertions(+), 44 deletions(-)
 create mode 100644 lib/lwip/Kconfig
 create mode 100644 lib/lwip/Makefile
 create mode 100644 lib/lwip/apps/dhcp/lwip-dhcp.c
 create mode 100644 lib/lwip/apps/http/lwip-wget.c
 create mode 100644 lib/lwip/apps/ping/lwip_ping.c
 create mode 100644 lib/lwip/apps/ping/lwip_ping.h
 create mode 100644 lib/lwip/apps/ping/ping.h
 create mode 100644 lib/lwip/apps/tftp/lwip-tftp.c
 create mode 100644 lib/lwip/cmd-lwip.c
 create mode 100644 lib/lwip/lwipopts.h
 create mode 100644 lib/lwip/port/if.c
 create mode 100644 lib/lwip/port/include/arch/cc.h
 create mode 100644 lib/lwip/port/include/arch/sys_arch.h
 create mode 100644 lib/lwip/port/include/limits.h
 create mode 100644 lib/lwip/port/sys-arch.c
 create mode 100644 lib/lwip/ulwip.h

diff --git a/.gitignore b/.gitignore
index eb769f144c..be3676c59e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -104,3 +104,12 @@ __pycache__
 # pylint files
 /pylint.cur
 /pylint.out/
+
+lib/lwip/lwip-external
+lib/lwip/apps/ping/ping.c
+lib/lwip/apps/http/http_client.c
+lib/lwip/apps/http/http_client.h
+lib/lwip/apps/tftp/tftp.c
+lib/lwip/apps/tftp/tftp_client.h
+lib/lwip/apps/tftp/tftp_common.h
+lib/lwip/apps/tftp/tftp_example.h
diff --git a/boot/bootmeth_pxe.c b/boot/bootmeth_pxe.c
index e6992168c0..30331a9806 100644
--- a/boot/bootmeth_pxe.c
+++ b/boot/bootmeth_pxe.c
@@ -118,7 +118,7 @@ static int distro_pxe_read_file(struct udevice *dev, struct 
bootflow *bflow,
tftp_argv[1] = file_addr;
tftp_argv[2] = (void *)file_path;
 
-   if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv))
+   if (do_lwip_tftp(ctx->cmdtp, 0, 3, tftp_argv))
return -ENOENT;
ret = pxe_get_file_size();
if (ret)
diff --git a/cmd/net.c b/cmd/net.c
index 0e9f200ca9..6d704fba86 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -36,19 +36,9 @@ U_BOOT_CMD(
 #endif
 
 #ifdef CONFIG_CMD_TFTPBOOT
-int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
-   int ret;
-
-   bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
-   ret = netboot_common(TFTPGET, cmdtp, argc, argv);
-   bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
-   return ret;
-}
-
 #if IS_ENABLED(CONFIG_IPV6)
 U_BOOT_CMD(
-   tftpboot,   4,  1,  do_tftpb,
+   tftpboot,   4,  1, do_lwip_tftp,
"boot image via network using TFTP protocol\n"
"To use IPv6 add -ipv6 parameter or use IPv6 hostIPaddr framed "
"with [] brackets",
@@ -56,7 +46,7 @@ U_BOOT_CMD(
 );
 #else
 U_BOOT_CMD(
-   tftpboot,   3,  1,  do_tftpb,
+   tftpboot,   3,  1,  do_lwip_tftp,
"load file via network using TFTP protocol",
"[loadAddress] [[hostIPaddr:]bootfilename]"
 );
@@ -112,7 +102,7 @@ U_BOOT_CMD(
 static int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc,
   char *const argv[])
 {
-   return netboot_common(DHCP, cmdtp, argc, argv);
+   return do_lwip_dhcp();
 }
 
 U_BOOT_CMD(
@@ -137,13 +127,11 @@ U_BOOT_CMD(
 #endif
 
 #if defined(CONFIG_CMD_WGET)
-static int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const 
argv[])
-{
-   return netboot_common(WGET, cmdtp, argc, argv);
-}
+int do_lwip_wget(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[]);
 
 U_BOOT_CMD(
-   wget,   3,  1,  do_wget,
+   wget,   3,  1, do_lwip_wget,
"boot image via network using HTTP protocol",
"[loadAddress] [[hostIPaddr:]path and image 

[PATCHv4 3/5] net/lwip: add doc/develop/net_lwip.rst

2023-07-14 Thread Maxim Uvarov
Just add inital doc.

Signed-off-by: Maxim Uvarov 
---
 doc/develop/index.rst|  1 +
 doc/develop/net_lwip.rst | 59 
 2 files changed, 60 insertions(+)
 create mode 100644 doc/develop/net_lwip.rst

diff --git a/doc/develop/index.rst b/doc/develop/index.rst
index 97c526e997..a092c33df0 100644
--- a/doc/develop/index.rst
+++ b/doc/develop/index.rst
@@ -43,6 +43,7 @@ Implementation
smbios
spl
uefi/index
+   net_lwip
vbe
version
 
diff --git a/doc/develop/net_lwip.rst b/doc/develop/net_lwip.rst
new file mode 100644
index 00..567234fff2
--- /dev/null
+++ b/doc/develop/net_lwip.rst
@@ -0,0 +1,59 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+LWIP IP stack intergation for U-Boot
+
+
+Intro
+-
+
+LWIP is a library for implementation network protocols, which is commonly used
+on embedded devices.
+
+https://savannah.nongnu.org/projects/lwip/
+
+LwIP  license:
+LwIP is licensed under a BSD-style license: http://lwip.wikia.com/wiki/License.
+
+Main features include:
+
+* Protocols: IP, IPv6, ICMP, ND, MLD, UDP, TCP, IGMP, ARP, PPPoS, PPPoE
+
+* DHCP client, DNS client (incl. mDNS hostname resolver), AutoIP/APIPA 
(Zeroconf), SNMP agent (v1, v2c, v3, private MIB support & MIB compiler)
+
+* APIs: specialized APIs for enhanced performance, optional Berkeley-alike 
socket API
+
+* Extended features: IP forwarding over multiple network interfaces, TCP 
congestion control, RTT estimation and fast recovery/fast retransmit
+
+* Addon applications: HTTP(S) server, SNTP client, SMTP(S) client, ping, 
NetBIOS nameserver, mDNS responder, MQTT client, TFTP server
+
+U-Boot implementation details
+-
+
+1. In general we can build lwIP as .a library and link it against u-boot or 
compile it in
+the U-Boot tree in the same way as other U-Boot files. There are few reasons 
why I selected
+the second variant: LwIP is very customizable with defines for features, 
memory size, types of
+allocation, some internal types and platform specific code. And it was more 
easy to enable/disable
+debug which is also done with defines, and is needed periodically.
+
+2. lwIP has 2 APIs - raw mode and sequential (as lwIP names it, or socket API 
as we name it in Linux).
+For now only raw API is supported.
+
+Raw IP means that the call back function for RX path is registered and will be 
called when packet
+data passes the IP stack and is ready for the application.
+
+Example is unmodified working ping example from lwip sources which registeres 
the callback:
+
+.. code-block:: c
+
+ping_pcb = raw_new(IP_PROTO_ICMP);
+raw_recv(ping_pcb, ping_recv, NULL); <- ping_recv is app callback.
+raw_bind(ping_pcb, IP_ADDR_ANY)
+
+Socket API also gives nice advantages due it will be easy to port linux socket 
applications to u-boot.
+I.e. LwIP sockets compatible with the linux ones. But that will require RX 
thread running in the background.
+So that means we need some kind of scheduler, locking and threading support or 
find some other solution.
+
+3.  Input and output
+
+RX packet path is injected to U-Boot eth_rx() polling loop and TX patch is in 
eth_send() accordingly.
+So we do not touch any drivers code and just eat packets when they are ready.
-- 
2.30.2



[PATCHv4 1/5] net/lwip: add lwip-external submodule

2023-07-14 Thread Maxim Uvarov
This commit adds the lwip library as a git submodule. I think
there has to be advantages to compile lwip inside U-boot,
i.e. use the same compiler and flags as the main code.
One of them is LTO and the other is to enable additional debug
options for network protocol during development. Also we can
copy lwip library code inside U-boot, but for now I don't want
to send all lwip code to the mailing list. So it's git submodule.

Signed-off-by: Maxim Uvarov 
---
 .gitmodules| 3 +++
 lib/lwip/lwip-external | 1 +
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 16 lib/lwip/lwip-external

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00..afc709af10
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "lib/lwip/lwip-external"]
+   path = lib/lwip/lwip-external
+   url = https://git.savannah.nongnu.org/git/lwip.git
diff --git a/lib/lwip/lwip-external b/lib/lwip/lwip-external
new file mode 16
index 00..3fe8d2fc43
--- /dev/null
+++ b/lib/lwip/lwip-external
@@ -0,0 +1 @@
+Subproject commit 3fe8d2fc43a9b69f7ed28c63d44a7744f9c0def9
-- 
2.30.2



Re: [PATCH 01/18] arch: mach-k3: security: fix the check for authentication

2023-07-14 Thread Andrew Davis

On 7/14/23 12:52 AM, Manorit Chawdhry wrote:

Fix regression occurred during refactoring for the mentioned commit.

Fixes: bd6a24759374 ("arm: mach-k3: security: separate out validating binary 
logic")

Signed-off-by: Manorit Chawdhry 
---
  arch/arm/mach-k3/security.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-k3/security.c b/arch/arm/mach-k3/security.c
index 02a2c12dbd6f..6038c9665ecb 100644
--- a/arch/arm/mach-k3/security.c
+++ b/arch/arm/mach-k3/security.c
@@ -91,8 +91,9 @@ void ti_secure_image_post_process(void **p_image, size_t 
*p_size)
return;
}
  
-	if (get_device_type() != K3_DEVICE_TYPE_HS_SE &&

-   get_device_type() != K3_DEVICE_TYPE_HS_FS)
+   if (get_device_type() == K3_DEVICE_TYPE_GP &&
+   (get_device_type() != K3_DEVICE_TYPE_HS_SE &&


Why check for both == GP and != HS-SE? Seems like this logic could still
be buggy. Could you explain here exactly what you are trying to do here.

Andrew


+!ti_secure_cert_detected(*p_image)))
return;
  
  	/* Clean out image so it can be seen by system firmware */




[PATCHv4 0/5] net/lwip: add lwip library for the network stack

2023-07-14 Thread Maxim Uvarov
changelog:
v4: - tested with tests/py/ did some minor fixes (out of tree
build, variables set after downloads).
- accounted review comments for documentation.
- implemented dns command
- corrected wget command to not use serverip variable and use just
url string.
v3: - use lwip commands for ping,tftp,wget,dhcp if this patch
  applied. Drop CONFIG_LIB_LWIP_REPLACE_ option.
- docs: use rst variant and drop references to RFC.

build:
git submodule init
git submodule update
make 

I tested with qemu and ubuntu host for the server manually and with
./test/py/test -bd qemu_arm64 --build -k net.

Maxim Uvarov (5):
  net/lwip: add lwip-external submodule
  net/lwip: add lwip library for the network stack
  net/lwip: add doc/develop/net_lwip.rst
  net/lwip: add dns command
  net/lwip: apps/http: add dns support

 .gitignore|   9 +
 .gitmodules   |   3 +
 boot/bootmeth_pxe.c   |   2 +-
 cmd/net.c |  89 +---
 cmd/pxe.c |   2 +-
 doc/develop/index.rst |   1 +
 doc/develop/net_lwip.rst  |  59 +
 include/net.h |   8 +-
 lib/Kconfig   |   2 +
 lib/Makefile  |   2 +
 lib/lwip/Kconfig  |  63 ++
 lib/lwip/Makefile | 103 +
 lib/lwip/apps/dhcp/lwip-dhcp.c|  52 +
 lib/lwip/apps/dns/lwip-dns.c  |  46 
 lib/lwip/apps/dns/lwip-dns.h  |   3 +
 lib/lwip/apps/http/lwip-wget.c| 121 ++
 lib/lwip/apps/ping/lwip_ping.c|  37 
 lib/lwip/apps/ping/lwip_ping.h|  24 ++
 lib/lwip/apps/ping/ping.h |  35 +++
 lib/lwip/apps/tftp/lwip-tftp.c| 124 +++
 lib/lwip/cmd-lwip.c   | 308 ++
 lib/lwip/lwip-external|   1 +
 lib/lwip/lwipopts.h   | 203 +
 lib/lwip/port/if.c| 260 ++
 lib/lwip/port/include/arch/cc.h   |  46 
 lib/lwip/port/include/arch/sys_arch.h |  59 +
 lib/lwip/port/include/limits.h|   0
 lib/lwip/port/sys-arch.c  |  20 ++
 lib/lwip/ulwip.h  |   9 +
 net/Kconfig   |   1 +
 net/net.c |  24 ++
 31 files changed, 1634 insertions(+), 82 deletions(-)
 create mode 100644 .gitmodules
 create mode 100644 doc/develop/net_lwip.rst
 create mode 100644 lib/lwip/Kconfig
 create mode 100644 lib/lwip/Makefile
 create mode 100644 lib/lwip/apps/dhcp/lwip-dhcp.c
 create mode 100644 lib/lwip/apps/dns/lwip-dns.c
 create mode 100644 lib/lwip/apps/dns/lwip-dns.h
 create mode 100644 lib/lwip/apps/http/lwip-wget.c
 create mode 100644 lib/lwip/apps/ping/lwip_ping.c
 create mode 100644 lib/lwip/apps/ping/lwip_ping.h
 create mode 100644 lib/lwip/apps/ping/ping.h
 create mode 100644 lib/lwip/apps/tftp/lwip-tftp.c
 create mode 100644 lib/lwip/cmd-lwip.c
 create mode 16 lib/lwip/lwip-external
 create mode 100644 lib/lwip/lwipopts.h
 create mode 100644 lib/lwip/port/if.c
 create mode 100644 lib/lwip/port/include/arch/cc.h
 create mode 100644 lib/lwip/port/include/arch/sys_arch.h
 create mode 100644 lib/lwip/port/include/limits.h
 create mode 100644 lib/lwip/port/sys-arch.c
 create mode 100644 lib/lwip/ulwip.h

-- 
2.30.2



Re: [PATCH 4/5] CI: Update to gcc-13.1.0

2023-07-14 Thread Tom Rini
On Fri, Jul 14, 2023 at 01:52:09PM +, Alexey Brodkin wrote:
> Hi Tom,
> 
> > As this is the current version of the public cross toolchains we use,
> > upgrade to this now.
> > 
> > Suggested-by: Alexey Brodkin 
> > Signed-off-by: Tom Rini 
> > ---
> > Cc: Heinrich Schuchardt 
> > 
> > Heinrich, at this point is there a newer grub we should be testing?
> > There's now 2 changes for RISC-V that we're cherry-picking for newer
> > toolchains.
> 
> That's what I noticed as well - grub fails to build for RISCV
> with the following message, I guess you saw that as well:
> --->8--
> ./grub-mkimage: error: relocation 0x13 is not implemented yet.
> --->8--

Yup, but since it's been solved upstream it's an easy fix, if 2.06 is
the right one to keep for now.

> > ---
> >  .azure-pipelines.yml|  2 +-
> >  .gitlab-ci.yml  |  2 +-
> >  tools/buildman/toolchain.py |  2 +-
> >  tools/docker/Dockerfile | 57 +++--
> >  4 files changed, 32 insertions(+), 31 deletions(-)
> > 
> > diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
> > index 76982ec3e52e..83cc6176e7b4 100644
> > --- a/.azure-pipelines.yml
> > +++ b/.azure-pipelines.yml
> > @@ -194,7 +194,7 @@ stages:
> >ln -s /opt/nokia/libc6_2.5.1-1eglibc27+0m5_armel.deb 
> > nokia_rx51_tmp/
> >ln -s /opt/nokia/busybox_1.10.2.legal-1osso30+0m5_armel.deb 
> > nokia_rx51_tmp/
> >ln -s /opt/nokia/qemu-system-arm nokia_rx51_tmp/
> > -  export PATH=/opt/gcc-12.2.0-nolibc/arm-linux-gnueabi/bin:$PATH
> > +  export PATH=/opt/gcc-13.1.0-nolibc/arm-linux-gnueabi/bin:$PATH
> >test/nokia_rx51_test.sh
> >  
> >- job: pylint
> > diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> > index f7ffb8f5dfdc..5300813cf511 100644
> > --- a/.gitlab-ci.yml
> > +++ b/.gitlab-ci.yml
> > @@ -232,7 +232,7 @@ Run tests for Nokia RX-51 (aka N900):
> >ln -s /opt/nokia/libc6_2.5.1-1eglibc27+0m5_armel.deb nokia_rx51_tmp/;
> >ln -s /opt/nokia/busybox_1.10.2.legal-1osso30+0m5_armel.deb 
> > nokia_rx51_tmp/;
> >ln -s /opt/nokia/qemu-system-arm nokia_rx51_tmp/;
> > -  export PATH=/opt/gcc-12.2.0-nolibc/arm-linux-gnueabi/bin:$PATH;
> > +  export PATH=/opt/gcc-13.1.0-nolibc/arm-linux-gnueabi/bin:$PATH;
> >test/nokia_rx51_test.sh
> >  
> >  # Check for any pylint regressions
> > diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
> > index 0ecd8458b912..1001b612086f 100644
> > --- a/tools/buildman/toolchain.py
> > +++ b/tools/buildman/toolchain.py
> > @@ -499,7 +499,7 @@ class Toolchains:
> >  if arch == 'aarch64':
> >  arch = 'arm64'
> >  base = 'https://www.kernel.org/pub/tools/crosstool/files/bin'
> > -versions = ['12.2.0', '11.1.0']
> > +versions = ['13.1.0', '12.2.0']
> >  links = []
> >  for version in versions:
> >  url = '%s/%s/%s/' % (base, arch, version)
> > diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
> > index f72cba0b8cc4..2f2ace2e6554 100644
> > --- a/tools/docker/Dockerfile
> > +++ b/tools/docker/Dockerfile
> > @@ -14,18 +14,18 @@ RUN apt-get update && apt-get install -y gnupg2 wget 
> > xz-utils && rm -rf /var/lib
> >  RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
> >  RUN echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main | tee 
> > /etc/apt/sources.list.d/llvm.list
> >  
> > -# Manually install the kernel.org "Crosstool" based toolchains for 
> > gcc-12.2.0
> > -RUN wget -O - 
> > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-aarch64-linux.tar.xz
> >  | tar -C /opt -xJ
> > -RUN wget -O - 
> > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-arm-linux-gnueabi.tar.xz
> >  | tar -C /opt -xJ
> > -RUN wget -O - 
> > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-i386-linux.tar.xz
> >  | tar -C /opt -xJ
> > -RUN wget -O - 
> > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-m68k-linux.tar.xz
> >  | tar -C /opt -xJ
> > -RUN wget -O - 
> > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-mips-linux.tar.xz
> >  | tar -C /opt -xJ
> > -RUN wget -O - 
> > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-microblaze-linux.tar.xz
> >  | tar -C /opt -xJ
> > -RUN wget -O - 
> > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-nios2-linux.tar.xz
> >  | tar -C /opt -xJ
> > -RUN wget -O - 
> > https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-powerpc-linux.tar.xz
> >  | tar -C /opt -xJ
> > -RUN wget -O - 
> > 

Re: [PATCH v7 00/23] Migration to using binman for bootloader

2023-07-14 Thread Jerome Forissier



On 7/14/23 15:50, Neha Malcom Francis wrote:
> This series aims to eliminate the use of additional custom repositories
> such as k3-image-gen (K3 Image Generation) repo and core-secdev-k3 (K3
> Security Development Tools) that was plumbed into the U-Boot build flow
> to generate boot images for TI K3 platform devices. And instead, we move
> towards using binman that aligns better with the community standard build
> flow.
> 
> This series uses binman for all K3 platforms supported on U-Boot currently;
> both HS (High Security, both SE and FS) and GP (General Purpose) devices.
> 
> Background on using k3-image-gen:
>   * TI K3 devices require a SYSFW (System Firmware) image consisting
>   of a signed system firmware image and board configuration binaries,
>   this is needed to bring up system firmware during U-Boot R5 SPL
>   startup.
>   * Board configuration data contain board-specific information
>   such as resource management, power management and security.
> 
> Background on using core-secdev-k3:
>   * Contains resources to sign x509 certificates for HS devices
> 
> Series intends to use binman to take over the packaging and signing for
> the R5 bootloader images tiboot3.bin (and sysfw.itb, for non-combined
> boot flow) instead of k3-image-gen.
> 
> Series also packages the A72/A53 bootloader images (tispl.bin and
> u-boot.img) using ATF, OPTEE and DM (Device Manager)
> 
> Changes in v7:
>   - corrected Texas Instruments copyright year
>   - k3-am65-iot2050 image fit@0x18 filename retained as
> tispl.bin
> 
> Changes in v6:
>   - addressed whitespace warnings
>   - added testcase for overwriting symlink functionality
>   - %s/Arm Trusted Firmware/Trusted Firmware-A
>   - %s/tee-pager_v2.bin/tee-raw.bin

I can still find quite a few occurrences of tee-pager_v2.bin in the patch
set (and in v7 too). Did you forget to change?

Another note applicable to several patches in v7:
'description = "OPTEE"' should be
'description = "OP-TEE"' (the official spelling has a hyphen). 

-- 
Jerome


[PATCH v7 04/23] j721e: schema: yaml: Add general schema and J721E board config files

2023-07-14 Thread Neha Malcom Francis
Schema file in YAML must be provided in board/ti/common for validating
input config files and packaging system firmware. The schema includes
entries for rm-cfg, board-cfg, pm-cfg and sec-cfg.

Board config files must be provided in board/ti/ in YAML.
These can then be consumed for generation of binaries to package system
firmware. Added YAML configs for J721E in particular.

Signed-off-by: Tarun Sahu 
[n-fran...@ti.com: prepared patch for upstreaming]
Signed-off-by: Neha Malcom Francis 
---
 board/ti/common/schema.yaml   |  436 +
 board/ti/j721e/board-cfg.yaml |   36 +
 board/ti/j721e/pm-cfg.yaml|   12 +
 board/ti/j721e/rm-cfg.yaml| 3174 +
 board/ti/j721e/sec-cfg.yaml   |  380 
 5 files changed, 4038 insertions(+)
 create mode 100644 board/ti/common/schema.yaml
 create mode 100644 board/ti/j721e/board-cfg.yaml
 create mode 100644 board/ti/j721e/pm-cfg.yaml
 create mode 100644 board/ti/j721e/rm-cfg.yaml
 create mode 100644 board/ti/j721e/sec-cfg.yaml

diff --git a/board/ti/common/schema.yaml b/board/ti/common/schema.yaml
new file mode 100644
index 00..c8dd2e79e7
--- /dev/null
+++ b/board/ti/common/schema.yaml
@@ -0,0 +1,436 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Config schema for TI K3 devices
+#
+
+---
+
+definitions:
+u8:
+type: integer
+minimum: 0
+maximum: 0xff
+u16:
+type: integer
+minimum: 0
+maximum: 0x
+u32:
+type: integer
+minimum: 0
+maximum: 0x
+
+
+
+type: object
+properties:
+pm-cfg:
+type: object
+properties:
+rev:
+type: object
+properties:
+boardcfg_abi_maj:
+$ref: "#/definitions/u8"
+boardcfg_abi_min:
+$ref: "#/definitions/u8"
+board-cfg:
+type: object
+properties:
+rev:
+type: object
+properties:
+boardcfg_abi_maj:
+$ref: "#/definitions/u8"
+boardcfg_abi_min:
+$ref: "#/definitions/u8"
+control:
+type: object
+properties:
+subhdr:
+type: object
+properties:
+magic:
+$ref: "#/definitions/u16"
+size:
+$ref: "#/definitions/u16"
+main_isolation_enable:
+$ref: "#/definitions/u8"
+main_isolation_hostid:
+$ref: "#/definitions/u16"
+
+
+secproxy:
+type: object
+properties:
+subhdr:
+type: object
+properties:
+magic:
+$ref: "#/definitions/u16"
+size:
+$ref: "#/definitions/u16"
+scaling_factor:
+$ref: "#/definitions/u8"
+scaling_profile:
+$ref: "#/definitions/u8"
+disable_main_nav_secure_proxy:
+$ref: "#/definitions/u8"
+
+msmc:
+type: object
+properties:
+subhdr:
+type: object
+properties:
+magic:
+$ref: "#/definitions/u16"
+size:
+$ref: "#/definitions/u16"
+msmc_cache_size:
+$ref: "#/definitions/u8"
+debug_cfg:
+type: object
+properties:
+subhdr:
+type: object
+properties:
+magic:
+$ref: "#/definitions/u16"
+size:
+$ref: "#/definitions/u16"
+trace_dst_enables:
+$ref: "#/definitions/u16"
+trace_src_enables:
+$ref: "#/definitions/u16"
+
+sec-cfg:
+type: object
+properties:
+rev:
+type: object
+properties:
+boardcfg_abi_maj:
+$ref: "#/definitions/u8"
+boardcfg_abi_min:
+$ref: "#/definitions/u8"
+
+processor_acl_list:
+type: object
+properties:
+subhdr:
+type: object
+   

[PATCH 1/2] configs: visionfive2: add a trailing space to prompt

2023-07-14 Thread Chanho Park
Adds a trailing space to SYS_PROMPT to make it easier to distinguish
between commands and the prompt.

Signed-off-by: Chanho Park 
---
 configs/starfive_visionfive2_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 570a1f53a19b..75b727472da4 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -9,7 +9,7 @@ CONFIG_SF_DEFAULT_SPEED=1
 CONFIG_SPL_DM_SPI=y
 CONFIG_DEFAULT_DEVICE_TREE="jh7110-starfive-visionfive-2"
 CONFIG_SPL_TEXT_BASE=0x800
-CONFIG_SYS_PROMPT="StarFive #"
+CONFIG_SYS_PROMPT="StarFive # "
 CONFIG_OF_LIBFDT_OVERLAY=y
 CONFIG_DM_RESET=y
 CONFIG_SPL_MMC=y
-- 
2.39.2



[PATCH 2/2] doc: visionfive2: apply a trailing space to the prompt

2023-07-14 Thread Chanho Park
Apply the trailing space changes in the guide document.

Signed-off-by: Chanho Park 
---
 doc/board/starfive/visionfive2.rst | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/doc/board/starfive/visionfive2.rst 
b/doc/board/starfive/visionfive2.rst
index 951e0d80fb9d..941899a0a4e9 100644
--- a/doc/board/starfive/visionfive2.rst
+++ b/doc/board/starfive/visionfive2.rst
@@ -206,16 +206,16 @@ Sample boot log from StarFive VisionFive2 board
Working FDT set to ff74a340
Hit any key to stop autoboot:  0
StarFive #
-   StarFive #version
+   StarFive # version
U-Boot 2023.04-rc2-00055-gfc43b9c51a-dirty (Mar 02 2023 - 10:51:39 
+0800)
 
riscv64-buildroot-linux-gnu-gcc.br_real (Buildroot VF2_515_v1.0.0_rc4) 
10.3.0
GNU ld (GNU Binutils) 2.36.1
StarFive #
-   StarFive #mmc dev 1
+   StarFive # mmc dev 1
switch to partitions #0, OK
mmc1 is current device
-   StarFive #mmc info
+   StarFive # mmc info
Device: mmc@1602
Manufacturer ID: 9f
OEM: 5449
@@ -229,7 +229,7 @@ Sample boot log from StarFive VisionFive2 board
Bus Width: 4-bit
Erase Group Size: 512 Bytes
StarFive #
-   StarFive #mmc part
+   StarFive # mmc part
 
Partition Map for MMC device 1  --   Partition Type: EFI
 
@@ -253,7 +253,7 @@ Sample boot log from StarFive VisionFive2 board
(data)
guid:   539a6df9-4655-4953-8541-733ca36eb1db
StarFive #
-   StarFive #fatls mmc 1:3
+   StarFive # fatls mmc 1:3
6429424   Image.gz
717705   u-boot.itb
125437   u-boot-spl.bin.normal.out
@@ -262,13 +262,13 @@ Sample boot log from StarFive VisionFive2 board
 
5 file(s), 0 dir(s)
 
-   StarFive #fatload mmc 1:3 ${kernel_addr_r} Image.gz
+   StarFive # fatload mmc 1:3 ${kernel_addr_r} Image.gz
6429424 bytes read in 394 ms (15.6 MiB/s)
-   StarFive #fatload mmc 1:3 ${fdt_addr_r} jh7110-starfive-visionfive-2.dtb
+   StarFive # fatload mmc 1:3 ${fdt_addr_r} 
jh7110-starfive-visionfive-2.dtb
11285 bytes read in 5 ms (2.2 MiB/s)
-   StarFive #fatload mmc 1:3 ${ramdisk_addr_r} initramfs.cpio.gz
+   StarFive # fatload mmc 1:3 ${ramdisk_addr_r} initramfs.cpio.gz
152848495 bytes read in 9271 ms (15.7 MiB/s)
-   StarFive #booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} 
${fdt_addr_r}
+   StarFive # booti ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} 
${fdt_addr_r}
Uncompressing Kernel Image
## Flattened Device Tree blob at 4600
Booting using the fdt blob at 0x4600
-- 
2.39.2



[PATCH 0/2] add a trailing space to prompt for visionfive2 board

2023-07-14 Thread Chanho Park
Adds a trailing space to SYS_PROMPT to make it easier to distinguish
between commands and the prompt.

Chanho Park (2):
  configs: visionfive2: add a trailing space to prompt
  doc: visionfive2: apply a trailing space to the prompt

 configs/starfive_visionfive2_defconfig |  2 +-
 doc/board/starfive/visionfive2.rst | 18 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

-- 
2.39.2



[PATCH v7 23/23] CI: Make use of buildman requirements.txt

2023-07-14 Thread Neha Malcom Francis
From: Tom Rini 

Now that buildman has a requirements.txt file we need to make use of it.

Signed-off-by: Tom Rini 
Reviewed-by: Simon Glass 
[n-fran...@ti.com: Adding missing command from .azure-pipelines.yml]
Signed-off-by: Neha Malcom Francis 
---
 .azure-pipelines.yml | 4 
 .gitlab-ci.yml   | 4 
 2 files changed, 8 insertions(+)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 06c46b681c..8626b27d4b 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -162,6 +162,7 @@ stages:
   virtualenv -p /usr/bin/python3 /tmp/venv
   . /tmp/venv/bin/activate
   pip install -r test/py/requirements.txt
+  pip install -r tools/buildman/requirements.txt
   export UBOOT_TRAVIS_BUILD_DIR=/tmp/sandbox_spl
   export PYTHONPATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt
   export PATH=${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}
@@ -209,6 +210,7 @@ stages:
   git config --global --add safe.directory $(work_dir)
   export USER=azure
   pip install -r test/py/requirements.txt
+  pip install -r tools/buildman/requirements.txt
   pip install asteval pylint==2.12.2 pyopenssl
   export PATH=${PATH}:~/.local/bin
   echo "[MASTER]" >> .pylintrc
@@ -404,6 +406,7 @@ stages:
   if [ -n "${BUILD_ENV}" ]; then
   export ${BUILD_ENV};
   fi
+  pip install -r tools/buildman/requirements.txt
   tools/buildman/buildman -o ${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e 
--board ${TEST_PY_BD} ${OVERRIDE}
   cp ~/grub_x86.efi ${UBOOT_TRAVIS_BUILD_DIR}/
   cp ~/grub_x64.efi ${UBOOT_TRAVIS_BUILD_DIR}/
@@ -583,6 +586,7 @@ stages:
   # make environment variables available as tests are running inside a 
container
   export BUILDMAN="${BUILDMAN}"
   git config --global --add safe.directory ${WORK_DIR}
+  pip install -r tools/buildman/requirements.txt
   EOF
   cat << "EOF" >> build.sh
   if [[ "${BUILDMAN}" != "" ]]; then
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cfd58513c3..07d8ba5ac2 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -97,6 +97,7 @@ build all 32bit ARM platforms:
   script:
 - ret=0;
   git config --global --add safe.directory "${CI_PROJECT_DIR}";
+  pip install -r tools/buildman/requirements.txt;
   ./tools/buildman/buildman -o /tmp -PEWM arm -x aarch64 || ret=$?;
   if [[ $ret -ne 0 ]]; then
 ./tools/buildman/buildman -o /tmp -seP;
@@ -110,6 +111,7 @@ build all 64bit ARM platforms:
 - . /tmp/venv/bin/activate
 - ret=0;
   git config --global --add safe.directory "${CI_PROJECT_DIR}";
+  pip install -r tools/buildman/requirements.txt;
   ./tools/buildman/buildman -o /tmp -PEWM aarch64 || ret=$?;
   if [[ $ret -ne 0 ]]; then
 ./tools/buildman/buildman -o /tmp -seP;
@@ -208,6 +210,7 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites:
   virtualenv -p /usr/bin/python3 /tmp/venv;
   . /tmp/venv/bin/activate;
   pip install -r test/py/requirements.txt;
+  pip install -r tools/buildman/requirements.txt;
   export UBOOT_TRAVIS_BUILD_DIR=/tmp/sandbox_spl;
   export PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt";
   export PATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}";
@@ -240,6 +243,7 @@ Run pylint:
   script:
 - git config --global --add safe.directory "${CI_PROJECT_DIR}"
 - pip install -r test/py/requirements.txt
+- pip install -r tools/buildman/requirements.txt
 - pip install asteval pylint==2.12.2 pyopenssl
 - export PATH=${PATH}:~/.local/bin
 - echo "[MASTER]" >> .pylintrc
-- 
2.34.1



[PATCH v7 22/23] buildman: Create a requirements.txt file

2023-07-14 Thread Neha Malcom Francis
From: Tom Rini 

At this point, buildman requires a few different modules and so we need
a requirements.txt to track what modules are needed.

Cc: Simon Glass 
Cc: Neha Malcom Francis 
Signed-off-by: Tom Rini 
Reviewed-by: Simon Glass 
Signed-off-by: Neha Malcom Francis 
---
 tools/buildman/requirements.txt | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 tools/buildman/requirements.txt

diff --git a/tools/buildman/requirements.txt b/tools/buildman/requirements.txt
new file mode 100644
index 00..a1efcb9d4b
--- /dev/null
+++ b/tools/buildman/requirements.txt
@@ -0,0 +1,2 @@
+jsonschema==4.17.3
+pyyaml==6.0
-- 
2.34.1



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

2023-07-14 Thread Neha Malcom Francis
From: Andrew Davis 

Without this re-building will fail with an error when trying to create
the symlink for the second time with an already exists error.

Signed-off-by: Andrew Davis 
[n-fran...@ti.com: Added support for test output dir and testcase]
Signed-off-by: Neha Malcom Francis 
---
 tools/binman/ftest.py | 18 --
 tools/binman/image.py |  2 ++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index f4bff50aaf..6280eb92c4 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -353,7 +353,7 @@ class TestFunctional(unittest.TestCase):
 use_expanded=False, verbosity=None, allow_missing=False,
 allow_fake_blobs=False, extra_indirs=None, threads=None,
 test_section_timeout=False, update_fdt_in_elf=None,
-force_missing_bintools='', ignore_missing=False):
+force_missing_bintools='', ignore_missing=False, 
output_dir=None):
 """Run binman with a given test file
 
 Args:
@@ -384,6 +384,7 @@ class TestFunctional(unittest.TestCase):
 update_fdt_in_elf: Value to pass with --update-fdt-in-elf=xxx
 force_missing_tools (str): comma-separated list of bintools to
 regard as missing
+output_dir: Specific output directory to use for image using -O
 
 Returns:
 int return code, 0 on success
@@ -430,6 +431,8 @@ class TestFunctional(unittest.TestCase):
 if extra_indirs:
 for indir in extra_indirs:
 args += ['-I', indir]
+if output_dir:
+args += ['-O', output_dir]
 return self._DoBinman(*args)
 
 def _SetupDtb(self, fname, outfile='u-boot.dtb'):
@@ -6113,7 +6116,7 @@ fdt fdtmapExtract the devicetree 
blob from the fdtmap
   str(e.exception))
 
 def testSymlink(self):
-"""Test that image files can be named"""
+"""Test that image files can be symlinked"""
 retcode = self._DoTestFile('259_symlink.dts', debug=True, map=True)
 self.assertEqual(0, retcode)
 image = control.images['test_image']
@@ -6122,6 +6125,17 @@ fdt fdtmapExtract the devicetree 
blob from the fdtmap
 self.assertTrue(os.path.islink(sname))
 self.assertEqual(os.readlink(sname), fname)
 
+def testSymlinkOverwrite(self):
+"""Test that symlinked images can be overwritten"""
+testdir = TestFunctional._MakeInputDir('symlinktest')
+self._DoTestFile('259_symlink.dts', debug=True, map=True, 
output_dir=testdir)
+# build the same image again in the same directory so that existing 
symlink is present
+self._DoTestFile('259_symlink.dts', debug=True, map=True, 
output_dir=testdir)
+fname = tools.get_output_filename('test_image.bin')
+sname = tools.get_output_filename('symlink_to_test.bin')
+self.assertTrue(os.path.islink(sname))
+self.assertEqual(os.readlink(sname), fname)
+
 def testSymbolsElf(self):
 """Test binman can assign symbols embedded in an ELF file"""
 if not elf.ELF_TOOLS:
diff --git a/tools/binman/image.py b/tools/binman/image.py
index 8ebf71d61a..e77b5d0d97 100644
--- a/tools/binman/image.py
+++ b/tools/binman/image.py
@@ -182,6 +182,8 @@ class Image(section.Entry_section):
 # Create symlink to file if symlink given
 if self._symlink is not None:
 sname = tools.get_output_filename(self._symlink)
+if os.path.islink(sname):
+os.remove(sname)
 os.symlink(fname, sname)
 
 def WriteMap(self):
-- 
2.34.1



[PATCH v7 20/23] doc: board: ti: Update documentation for binman flow

2023-07-14 Thread Neha Malcom Francis
Earlier documentation specified builds for generating bootloader images
using an external TI repository k3-image-gen and core-secdev-k3. Modify
this to using the binman flow so that user understands how to build the
final boot images.

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
---
 doc/board/ti/am62x_sk.rst  |  54 +--
 doc/board/ti/j7200_evm.rst |  55 +--
 doc/board/ti/j721e_evm.rst |  58 +---
 doc/board/ti/k3.rst| 107 +
 4 files changed, 113 insertions(+), 161 deletions(-)

diff --git a/doc/board/ti/am62x_sk.rst b/doc/board/ti/am62x_sk.rst
index 27d7b527c6..bf23022b95 100644
--- a/doc/board/ti/am62x_sk.rst
+++ b/doc/board/ti/am62x_sk.rst
@@ -90,9 +90,9 @@ Below is the pictorial representation of boot flow:
  |||--|---|>| Reset rls | |
  |||  |   | +---+ |
  ||  TIFS  |  |   |  :|
- ||Services|  |   | +---+ |
- |||<-|---|>|*ATF/OPTEE*| |
- |||  |   | +---+ |
+ ||Services|  |   | ++|
+ |||<-|---|>|*TF-A/OPTEE*||
+ |||  |   | ++|
  |||  |   |  :|
  |||  |   | +---+ |
  |||<-|---|>| *A53 SPL* | |
@@ -115,59 +115,57 @@ Below is the pictorial representation of boot flow:
 
 Sources:
 
-1. SYSFW:
-   Tree: git://git.ti.com/k3-image-gen/k3-image-gen.git
-   Branch: master
-
-2. ATF:
-   Tree: https://github.com/ARM-software/arm-trusted-firmware.git
+1. Trusted Firmware-A:
+   Tree: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/
Branch: master
 
-3. OPTEE:
+2. OPTEE:
Tree: https://github.com/OP-TEE/optee_os.git
Branch: master
 
-4. U-Boot:
+3. U-Boot:
Tree: https://source.denx.de/u-boot/u-boot
Branch: master
 
-5. TI Linux Firmware:
+4. TI Linux Firmware:
Tree: git://git.ti.com/processor-firmware/ti-linux-firmware.git
Branch: ti-linux-firmware
 
 Build procedure:
 
-1. ATF:
+1. Trusted Firmware-A:
 
-.. code-block:: text
+.. code-block:: bash
 
- $ make CROSS_COMPILE=aarch64-none-linux-gnu- ARCH=aarch64 PLAT=k3 
TARGET_BOARD=lite SPD=opteed
+ $ make CROSS_COMPILE=aarch64-none-linux-gnu- ARCH=aarch64 PLAT=k3 \
+TARGET_BOARD=lite SPD=opteed
 
 2. OPTEE:
 
-.. code-block:: text
+.. code-block:: bash
 
- $ make PLATFORM=k3 CFG_ARM64_core=y CROSS_COMPILE=arm-none-linux-gnueabihf- 
CROSS_COMPILE64=aarch64-none-linux-gnu-
+ $ make PLATFORM=k3 CFG_ARM64_core=y CROSS_COMPILE=arm-none-linux-gnueabihf- \
+CROSS_COMPILE64=aarch64-none-linux-gnu-
 
 3. U-Boot:
 
 * 3.1 R5:
 
-.. code-block:: text
+.. code-block:: bash
 
- $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- 
am62x_evm_r5_defconfig O=/tmp/r5
- $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- O=/tmp/r5
- $ cd 
- $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- SOC=am62x 
SBL=/tmp/r5/spl/u-boot-spl.bin SYSFW_PATH=/ti-sysfw/ti-fs-firmware-am62x-gp.bin
-
-Use the tiboot3.bin generated from last command
+ $ make ARCH=arm am62x_evm_r5_defconfig
+ $ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabihf- \
+BINMAN_INDIRS=
 
 * 3.2 A53:
 
-.. code-block:: text
+.. code-block:: bash
 
- $ make ARCH=arm CROSS_COMPILE=aarch64-none-linux-gnu- am62x_evm_a53_defconfig 
O=/tmp/a53
- $ make ARCH=arm CROSS_COMPILE=aarch64-none-linux-gnu- ATF=/build/k3/lite/release/bl31.bin TEE=/out/arm-plat-k3/core/tee-pager_v2.bin DM=/ti-dm/am62xx/ipc_echo_testb_mcu1_0_release_strip.xer5f 
O=/tmp/a53
+ $ make ARCH=arm am62x_evm_a53_defconfig
+ $ make ARCH=arm CROSS_COMPILE=aarch64-none-linux-gnu- \
+BL31=/build/k3/lite/release/bl31.bin \
+TEE=/out/arm-plat-k3/core/tee-raw.bin \
+BINMAN_INDIRS=
 
 Target Images
 --
@@ -214,7 +212,7 @@ Image formats:
 |   FIT HEADER  |
 | +---+ |
 | |   | |
-| |  A53 ATF  | |
+| | A53 TF-A  | |
 | +---+ |
 | |   | |
 | | A53 OPTEE | |
diff --git a/doc/board/ti/j7200_evm.rst b/doc/board/ti/j7200_evm.rst
index 0d3a526516..8f6d13ab8c 100644
--- a/doc/board/ti/j7200_evm.rst
+++ b/doc/board/ti/j7200_evm.rst
@@ -83,9 +83,9 @@ Below is the pictorial representation of boot flow:
  || |-|---|>| 

[PATCH v7 19/23] k3: tools: config.mk: Update makefile and remove scripts

2023-07-14 Thread Neha Malcom Francis
Since binman is used to package bootloader images for all K3 devices, we
do not have to rely on the earlier methods to package them.

Scripts that were used to generate x509 certificate for tiboot3.bin and
generate tispl.bin, u-boot.img have been removed.

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
---
 arch/arm/mach-k3/config.mk | 103 ---
 tools/k3_fit_atf.sh| 123 -
 tools/k3_gen_x509_cert.sh  | 262 -
 3 files changed, 488 deletions(-)
 delete mode 100644 arch/arm/mach-k3/config.mk
 delete mode 100755 tools/k3_fit_atf.sh
 delete mode 100755 tools/k3_gen_x509_cert.sh

diff --git a/arch/arm/mach-k3/config.mk b/arch/arm/mach-k3/config.mk
deleted file mode 100644
index cbf9c10210..00
--- a/arch/arm/mach-k3/config.mk
+++ /dev/null
@@ -1,103 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-#
-# Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
-#  Lokesh Vutla 
-
-ifdef CONFIG_SPL_BUILD
-
-# Openssl is required to generate x509 certificate.
-# Error out if openssl is not available.
-ifeq ($(shell which openssl),)
-$(error "No openssl in $(PATH), consider installing openssl")
-endif
-
-IMAGE_SIZE= $(shell cat $(obj)/u-boot-spl.bin | wc -c)
-MAX_SIZE= $(shell printf "%d" $(CONFIG_SYS_K3_MAX_DOWNLODABLE_IMAGE_SIZE))
-
-ifeq ($(CONFIG_SYS_K3_KEY), "")
-KEY=""
-# On HS use real key or warn if not available
-ifeq ($(CONFIG_TI_SECURE_DEVICE),y)
-ifneq ($(wildcard $(TI_SECURE_DEV_PKG)/keys/custMpk.pem),)
-KEY=$(TI_SECURE_DEV_PKG)/keys/custMpk.pem
-else
-$(warning "WARNING: signing key not found. Random key will NOT work on HS 
hardware!")
-endif
-endif
-else
-KEY=$(patsubst "%",$(srctree)/%,$(CONFIG_SYS_K3_KEY))
-endif
-
-# X509 SWRV default
-SWRV = $(CONFIG_K3_X509_SWRV)
-# On HS use SECDEV provided software revision or warn if not available
-ifeq ($(CONFIG_TI_SECURE_DEVICE),y)
-ifneq ($(wildcard $(TI_SECURE_DEV_PKG)/keys/swrv.txt),)
-SWRV= $(shell cat $(TI_SECURE_DEV_PKG)/keys/swrv.txt)
-else
-$(warning "WARNING: Software revision file not found. Default may not work on 
HS hardware.")
-endif
-endif
-
-# tiboot3.bin is mandated by ROM and ROM only supports R5 boot.
-# So restrict tiboot3.bin creation for CPU_V7R.
-ifdef CONFIG_CPU_V7R
-image_check: $(obj)/u-boot-spl.bin FORCE
-   @if [ $(IMAGE_SIZE) -gt $(MAX_SIZE) ]; then \
-   echo "===" >&2; \
-   echo "ERROR: Final Image too big. " >&2;\
-   echo "$< size = $(IMAGE_SIZE), max size = $(MAX_SIZE)" >&2; \
-   echo "===" >&2; \
-   exit 1; \
-   fi
-
-tiboot3.bin: image_check FORCE
-   $(srctree)/tools/k3_gen_x509_cert.sh -c 16 -b $(obj)/u-boot-spl.bin \
-   -o $@ -l $(CONFIG_SPL_TEXT_BASE) -r $(SWRV) -k 
$(KEY)
-
-INPUTS-y   += tiboot3.bin
-endif
-
-ifdef CONFIG_ARM64
-
-ifeq ($(CONFIG_SOC_K3_J721E),)
-export DM := /dev/null
-endif
-
-ifeq ($(CONFIG_TI_SECURE_DEVICE),y)
-SPL_ITS := u-boot-spl-k3_HS.its
-$(SPL_ITS): export IS_HS=1
-INPUTS-y   += tispl.bin_HS
-INPUTS-y   += tispl.bin
-tispl.bin: $(obj)/u-boot-spl-nodtb.bin_HS $(patsubst 
%,$(obj)/dts/%.dtb_HS,$(subst ",,$(CONFIG_SPL_OF_LIST)))
-else
-SPL_ITS := u-boot-spl-k3.its
-INPUTS-y   += tispl.bin
-endif
-
-ifeq ($(CONFIG_SPL_OF_LIST),)
-LIST_OF_DTB := $(CONFIG_DEFAULT_DEVICE_TREE)
-else
-LIST_OF_DTB := $(CONFIG_SPL_OF_LIST)
-endif
-
-quiet_cmd_k3_mkits = MKITS   $@
-cmd_k3_mkits = \
-   $(srctree)/tools/k3_fit_atf.sh \
-   $(CONFIG_K3_ATF_LOAD_ADDR) \
-   $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(LIST_OF_DTB))) > $@
-
-$(SPL_ITS): FORCE
-   $(call cmd,k3_mkits)
-endif
-
-else
-
-ifeq ($(CONFIG_TI_SECURE_DEVICE),y)
-INPUTS-y   += u-boot.img_HS
-else
-INPUTS-y   += u-boot.img
-endif
-endif
-
-include $(srctree)/arch/arm/mach-k3/config_secure.mk
diff --git a/tools/k3_fit_atf.sh b/tools/k3_fit_atf.sh
deleted file mode 100755
index 7bc07ad074..00
--- a/tools/k3_fit_atf.sh
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0+
-#
-# script to generate FIT image source for K3 Family boards with
-# ATF, OPTEE, SPL and multiple device trees (given on the command line).
-# Inspired from board/sunxi/mksunxi_fit_atf.sh
-#
-# usage: $0   [ [&2
-   ATF=/dev/null
-fi
-
-[ -z "$TEE" ] && TEE="bl32.bin"
-
-if [ ! -f $TEE ]; then
-   echo "WARNING OPTEE file $TEE NOT found, resulting might be 
non-functional" >&2
-   TEE=/dev/null
-fi
-
-[ -z "$DM" ] && DM="dm.bin"
-
-if [ ! -e $DM ]; then
-   echo "WARNING DM file $DM NOT found, resulting might be non-functional" 
>&2
-   DM=/dev/null
-fi
-
-if [ ! -z "$IS_HS" ]; then
-   HS_APPEND=_HS
-fi
-
-cat << __HEADER_EOF
-/dts-v1/;
-
-/ {
-   description = "Configuration to load 

[PATCH v7 18/23] arm: k3-am65x-iot2050: Use binman for tispl.bin for iot2050

2023-07-14 Thread Neha Malcom Francis
Move to using binman to generate tispl.bin which is used to generate the
final flash.bin bootloader for iot2050 boards.

Signed-off-by: Neha Malcom Francis 
Cc: Jan Kiszka 
Reviewed-by: Simon Glass 
---
 arch/arm/dts/k3-am65-iot2050-boot-image.dtsi | 75 +++-
 1 file changed, 74 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/k3-am65-iot2050-boot-image.dtsi 
b/arch/arm/dts/k3-am65-iot2050-boot-image.dtsi
index 03ccc54329..4e14c0fb82 100644
--- a/arch/arm/dts/k3-am65-iot2050-boot-image.dtsi
+++ b/arch/arm/dts/k3-am65-iot2050-boot-image.dtsi
@@ -26,9 +26,82 @@
missing-msg = "iot2050-seboot";
};
 
-   blob@0x18 {
+   fit@0x18 {
offset = <0x18>;
filename = "tispl.bin";
+   pad-byte = <0xff>;
+   description = "Configuration to load ATF and SPL";
+
+   images {
+   atf {
+   description = "ARM Trusted Firmware";
+   type = "firmware";
+   arch = "arm64";
+   compression = "none";
+   os = "arm-trusted-firmware";
+   load = ;
+   entry = ;
+   atf: atf-bl31 {
+   };
+   };
+
+   tee {
+   description = "OPTEE";
+   type = "tee";
+   arch = "arm64";
+   compression = "none";
+   os = "tee";
+   load = <0x9e80>;
+   entry = <0x9e80>;
+   tee: tee-os {
+   };
+   };
+
+   dm {
+   description = "DM binary";
+   type = "firmware";
+   arch = "arm32";
+   compression = "none";
+   os = "DM";
+   load = <0x8900>;
+   entry = <0x8900>;
+   blob-ext {
+   filename = "/dev/null";
+   };
+   };
+
+   spl {
+   description = "SPL (64-bit)";
+   type = "standalone";
+   os = "U-Boot";
+   arch = "arm64";
+   compression = "none";
+   load = ;
+   entry = ;
+   u_boot_spl_nodtb: blob-ext {
+   filename = 
"spl/u-boot-spl-nodtb.bin";
+   };
+   };
+
+   fdt-0 {
+   description = "k3-am65-iot2050-spl.dtb";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   spl_am65x_evm_dtb: blob-ext {
+   filename = 
"spl/dts/k3-am65-iot2050-spl.dtb";
+   };
+   };
+   };
+
+   configurations {
+   default = "spl";
+   spl {
+   fdt = "fdt-0";
+   firmware = "atf";
+   loadables = "tee", "dm", "spl";
+   };
+   };
};
 
fit@0x38 {
-- 
2.34.1



[PATCH v7 17/23] am62a: dts: binman: Package tiboot3.bin, tispl.bin, u-boot.img

2023-07-14 Thread Neha Malcom Francis
Support added for HS-SE, HS-FS and GP boot binaries for AM62ax.

HS-SE:
* tiboot3-am62ax-hs-evm.bin
* tispl.bin
* u-boot.img

HS-FS:
* tiboot3-am62ax-hs-fs-evm.bin
* tispl.bin
* u-boot.img

GP:
* tiboot3.bin --> tiboot3-am62ax-gp-evm.bin
* tispl.bin_unsigned
* u-boot.img_unsigned

It is to be noted that the bootflow followed by AM62ax requires:

tiboot3.bin:
* R5 SPL
* R5 SPL dtbs
* TIFS
* board-cfg
* pm-cfg
* sec-cfg
* rm-cfg

tispl.bin:
* DM
* ATF
* OPTEE
* A72 SPL
* A72 SPL dtbs

u-boot.img:
* A72 U-Boot
* A72 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
[a...@ti.com: changed output binary names appropriately]
Signed-off-by: Andrew Davis 
---
 arch/arm/dts/k3-am62a-sk-binman.dtsi | 466 +++
 arch/arm/dts/k3-am62a7-r5-sk.dts |   1 +
 arch/arm/dts/k3-am62a7-sk.dts|   1 +
 board/ti/am62ax/Kconfig  |   2 +
 4 files changed, 470 insertions(+)
 create mode 100644 arch/arm/dts/k3-am62a-sk-binman.dtsi

diff --git a/arch/arm/dts/k3-am62a-sk-binman.dtsi 
b/arch/arm/dts/k3-am62a-sk-binman.dtsi
new file mode 100644
index 00..a1c9ef6fa4
--- /dev/null
+++ b/arch/arm/dts/k3-am62a-sk-binman.dtsi
@@ -0,0 +1,466 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "k3-binman.dtsi"
+
+#ifdef CONFIG_TARGET_AM62A7_R5_EVM
+
+_yaml_tifs {
+   config = "tifs-rm-cfg.yaml";
+};
+
+ {
+   tiboot3-am62ax-hs-evm.bin {
+   filename = "tiboot3-am62ax-hs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl>, <_fs_enc>, 
<_tifs_cfg>,
+   <_dm_cfg>, <_inner_cert>;
+   combined;
+   dm-data;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl>;
+   content-sysfw = <_fs_enc>;
+   content-sysfw-data = <_tifs_cfg>;
+   content-sysfw-inner-cert = <_inner_cert>;
+   content-dm-data = <_dm_cfg>;
+   load = <0x43c0>;
+   load-sysfw = <0x4>;
+   load-sysfw-data = <0x67000>;
+   load-dm-data = <0x43c3a800>;
+   };
+   u_boot_spl: u-boot-spl {
+   no-expanded;
+   };
+   ti_fs_enc: ti-fs-enc.bin {
+   filename = "ti-sysfw/ti-fs-firmware-am62ax-hs-enc.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_tifs_cfg: combined-tifs-cfg.bin {
+   filename = "combined-tifs-cfg.bin";
+   type = "blob-ext";
+   };
+   sysfw_inner_cert: sysfw-inner-cert {
+   filename = "ti-sysfw/ti-fs-firmware-am62ax-hs-cert.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_dm_cfg: combined-dm-cfg.bin {
+   filename = "combined-dm-cfg.bin";
+   type = "blob-ext";
+   };
+   };
+};
+
+ {
+   tiboot3-am62ax-hs-fs-evm.bin {
+   filename = "tiboot3-am62ax-hs-fs-evm.bin";
+   symlink = "tiboot3.bin";
+   ti-secure-rom {
+   content = <_boot_spl_fs>, <_fs_enc_fs>, 
<_tifs_cfg_fs>,
+   <_dm_cfg_fs>, <_inner_cert_fs>;
+   combined;
+   dm-data;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl_fs>;
+   content-sysfw = <_fs_enc_fs>;
+   content-sysfw-data = <_tifs_cfg_fs>;
+   content-sysfw-inner-cert = <_inner_cert_fs>;
+   content-dm-data = <_dm_cfg_fs>;
+   load = <0x43c0>;
+   load-sysfw = <0x4>;
+   load-sysfw-data = <0x67000>;
+   load-dm-data = <0x43c3a800>;
+   };
+   u_boot_spl_fs: u-boot-spl {
+   no-expanded;
+   };
+   ti_fs_enc_fs: ti-fs-enc.bin {
+   filename = 
"ti-sysfw/ti-fs-firmware-am62ax-hs-fs-enc.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_tifs_cfg_fs: combined-tifs-cfg.bin {
+   filename = "combined-tifs-cfg.bin";
+   type = "blob-ext";
+ 

[PATCH v7 16/23] am62a: yaml: Add board configs for AM62ax

2023-07-14 Thread Neha Malcom Francis
Added YAML configs for AM62ax

Signed-off-by: Neha Malcom Francis 
---
 board/ti/am62ax/board-cfg.yaml   |   36 +
 board/ti/am62ax/pm-cfg.yaml  |   12 +
 board/ti/am62ax/rm-cfg.yaml  | 1151 ++
 board/ti/am62ax/sec-cfg.yaml |  379 ++
 board/ti/am62ax/tifs-rm-cfg.yaml | 1011 ++
 5 files changed, 2589 insertions(+)
 create mode 100644 board/ti/am62ax/board-cfg.yaml
 create mode 100644 board/ti/am62ax/pm-cfg.yaml
 create mode 100644 board/ti/am62ax/rm-cfg.yaml
 create mode 100644 board/ti/am62ax/sec-cfg.yaml
 create mode 100644 board/ti/am62ax/tifs-rm-cfg.yaml

diff --git a/board/ti/am62ax/board-cfg.yaml b/board/ti/am62ax/board-cfg.yaml
new file mode 100644
index 00..4aa8ddd104
--- /dev/null
+++ b/board/ti/am62ax/board-cfg.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Board configuration for AM62ax
+#
+
+---
+
+board-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+control:
+subhdr:
+magic: 0xC1D3
+size: 7
+main_isolation_enable : 0x5A
+main_isolation_hostid : 0x2
+secproxy:
+subhdr:
+magic: 0x1207
+size: 7
+scaling_factor : 0x1
+scaling_profile : 0x1
+disable_main_nav_secure_proxy : 0
+msmc:
+subhdr:
+magic: 0xA5C3
+size: 5
+msmc_cache_size : 0x10
+debug_cfg:
+subhdr:
+magic: 0x020C
+size: 8
+trace_dst_enables : 0x00
+trace_src_enables : 0x00
diff --git a/board/ti/am62ax/pm-cfg.yaml b/board/ti/am62ax/pm-cfg.yaml
new file mode 100644
index 00..3ad182ae17
--- /dev/null
+++ b/board/ti/am62ax/pm-cfg.yaml
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Power management configuration for AM62ax
+#
+
+---
+
+pm-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
diff --git a/board/ti/am62ax/rm-cfg.yaml b/board/ti/am62ax/rm-cfg.yaml
new file mode 100644
index 00..15c4017bda
--- /dev/null
+++ b/board/ti/am62ax/rm-cfg.yaml
@@ -0,0 +1,1151 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Resource management configuration for AM62ax
+#
+
+---
+
+rm-cfg:
+rm_boardcfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+host_cfg:
+subhdr:
+magic: 0x4C41
+size : 356
+host_cfg_entries:
+- #1
+host_id: 12
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #2
+host_id: 30
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #3
+host_id: 36
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #4
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #5
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #6
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #7
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #8
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #9
+host_id: 0
+allowed_atype : 0
+

[PATCH v7 15/23] am625: dts: binman: Package tiboot3.bin, tispl.bin and u-boot.img

2023-07-14 Thread Neha Malcom Francis
Support added for HS-SE, HS-FS and GP boot binaries for AM62.

HS-SE:
* tiboot3-am62x-hs-evm.bin
* tispl.bin
* u-boot.img

HS-FS:
* tiboot3-am62x-hs-fs-evm.bin
* tispl.bin
* u-boot.img

GP:
* tiboot3.bin --> tiboot3-am62x-gp-evm.bin
* tispl.bin_unsigned
* u-boot.img_unsigned

It is to be noted that the bootflow followed by AM62 requires:

tiboot3.bin:
* R5 SPL
* R5 SPL dtbs
* TIFS
* board-cfg
* pm-cfg
* sec-cfg
* rm-cfg

tispl.bin:
* DM
* ATF
* OPTEE
* A72 SPL
* A72 SPL dtbs

u-boot.img:
* A72 U-Boot
* A72 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
[a...@ti.com: changed output binary names appropriately]
Signed-off-by: Andrew Davis 
---
 arch/arm/dts/k3-am625-r5-sk.dts  |   1 +
 arch/arm/dts/k3-am625-sk-binman.dtsi | 463 +++
 arch/arm/dts/k3-am625-sk-u-boot.dtsi |   2 +
 board/ti/am62x/Kconfig   |   2 +
 4 files changed, 468 insertions(+)
 create mode 100644 arch/arm/dts/k3-am625-sk-binman.dtsi

diff --git a/arch/arm/dts/k3-am625-r5-sk.dts b/arch/arm/dts/k3-am625-r5-sk.dts
index 78df7cec3f..3ec5bad735 100644
--- a/arch/arm/dts/k3-am625-r5-sk.dts
+++ b/arch/arm/dts/k3-am625-r5-sk.dts
@@ -9,6 +9,7 @@
 #include "k3-am62-ddr.dtsi"
 
 #include "k3-am625-sk-u-boot.dtsi"
+#include "k3-am625-sk-binman.dtsi"
 
 / {
aliases {
diff --git a/arch/arm/dts/k3-am625-sk-binman.dtsi 
b/arch/arm/dts/k3-am625-sk-binman.dtsi
new file mode 100644
index 00..5bdf685c20
--- /dev/null
+++ b/arch/arm/dts/k3-am625-sk-binman.dtsi
@@ -0,0 +1,463 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "k3-binman.dtsi"
+
+#ifdef CONFIG_TARGET_AM625_R5_EVM
+
+ {
+   tiboot3-am62x-hs-evm.bin {
+   filename = "tiboot3-am62x-hs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl>, <_fs_enc>, 
<_tifs_cfg>,
+   <_dm_cfg>, <_inner_cert>;
+   combined;
+   dm-data;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl>;
+   content-sysfw = <_fs_enc>;
+   content-sysfw-data = <_tifs_cfg>;
+   content-sysfw-inner-cert = <_inner_cert>;
+   content-dm-data = <_dm_cfg>;
+   load = <0x43c0>;
+   load-sysfw = <0x4>;
+   load-sysfw-data = <0x67000>;
+   load-dm-data = <0x43c3a800>;
+   };
+   u_boot_spl: u-boot-spl {
+   no-expanded;
+   };
+   ti_fs_enc: ti-fs-enc.bin {
+   filename = "ti-sysfw/ti-fs-firmware-am62x-hs-enc.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_tifs_cfg: combined-tifs-cfg.bin {
+   filename = "combined-tifs-cfg.bin";
+   type = "blob-ext";
+   };
+   sysfw_inner_cert: sysfw-inner-cert {
+   filename = "ti-sysfw/ti-fs-firmware-am62x-hs-cert.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_dm_cfg: combined-dm-cfg.bin {
+   filename = "combined-dm-cfg.bin";
+   type = "blob-ext";
+   };
+   };
+};
+
+ {
+   tiboot3-am62x-hs-fs-evm.bin {
+   filename = "tiboot3-am62x-hs-fs-evm.bin";
+   symlink = "tiboot3.bin";
+   ti-secure-rom {
+   content = <_boot_spl_fs>, <_fs_enc_fs>, 
<_tifs_cfg_fs>,
+   <_dm_cfg_fs>, <_inner_cert_fs>;
+   combined;
+   dm-data;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl_fs>;
+   content-sysfw = <_fs_enc_fs>;
+   content-sysfw-data = <_tifs_cfg_fs>;
+   content-sysfw-inner-cert = <_inner_cert_fs>;
+   content-dm-data = <_dm_cfg_fs>;
+   load = <0x43c0>;
+   load-sysfw = <0x4>;
+   load-sysfw-data = <0x67000>;
+   load-dm-data = <0x43c3a800>;
+   };
+   u_boot_spl_fs: u-boot-spl {
+   no-expanded;
+   };
+   ti_fs_enc_fs: ti-fs-enc.bin {
+   filename = 
"ti-sysfw/ti-fs-firmware-am62x-hs-fs-enc.bin";
+   

[PATCH v7 14/23] am62: yaml: Add board configs for AM62

2023-07-14 Thread Neha Malcom Francis
Added YAML configs for AM62

Signed-off-by: Neha Malcom Francis 
---
 board/ti/am62x/board-cfg.yaml |   36 ++
 board/ti/am62x/pm-cfg.yaml|   12 +
 board/ti/am62x/rm-cfg.yaml| 1088 +
 board/ti/am62x/sec-cfg.yaml   |  379 
 4 files changed, 1515 insertions(+)
 create mode 100644 board/ti/am62x/board-cfg.yaml
 create mode 100644 board/ti/am62x/pm-cfg.yaml
 create mode 100644 board/ti/am62x/rm-cfg.yaml
 create mode 100644 board/ti/am62x/sec-cfg.yaml

diff --git a/board/ti/am62x/board-cfg.yaml b/board/ti/am62x/board-cfg.yaml
new file mode 100644
index 00..36cfb550ad
--- /dev/null
+++ b/board/ti/am62x/board-cfg.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Board configuration for AM62
+#
+
+---
+
+board-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+control:
+subhdr:
+magic: 0xC1D3
+size: 7
+main_isolation_enable : 0x5A
+main_isolation_hostid : 0x2
+secproxy:
+subhdr:
+magic: 0x1207
+size: 7
+scaling_factor : 0x1
+scaling_profile : 0x1
+disable_main_nav_secure_proxy : 0
+msmc:
+subhdr:
+magic: 0xA5C3
+size: 5
+msmc_cache_size : 0x0
+debug_cfg:
+subhdr:
+magic: 0x020C
+size: 8
+trace_dst_enables : 0x00
+trace_src_enables : 0x00
diff --git a/board/ti/am62x/pm-cfg.yaml b/board/ti/am62x/pm-cfg.yaml
new file mode 100644
index 00..5d04cf82ef
--- /dev/null
+++ b/board/ti/am62x/pm-cfg.yaml
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Power management configuration for AM62
+#
+
+---
+
+pm-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
diff --git a/board/ti/am62x/rm-cfg.yaml b/board/ti/am62x/rm-cfg.yaml
new file mode 100644
index 00..c28707be8e
--- /dev/null
+++ b/board/ti/am62x/rm-cfg.yaml
@@ -0,0 +1,1088 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Resource management configuration for AM62
+#
+
+---
+
+rm-cfg:
+rm_boardcfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+host_cfg:
+subhdr:
+magic: 0x4C41
+size : 356
+host_cfg_entries:
+- #1
+host_id: 12
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #2
+host_id: 30
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #3
+host_id: 36
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #4
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #5
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #6
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #7
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #8
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #9
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+

[PATCH v7 13/23] j721s2: dts: binman: Package tiboot3.bin, tispl.bin and u-boot.img

2023-07-14 Thread Neha Malcom Francis
Support has been added for both HS-SE, HS-FS  and GP images.

HS-SE:
* tiboot3-j721s2-hs-evm.bin
* tispl.bin
* u-boot.img

HS-FS:
* tiboot3-j721s2-hs-fs-evm.bin
* tispl.bin
* u-boot.img

GP:
* tiboot3.bin --> tiboot3-j721s2-gp-evm.bin
* tispl.bin_unsigned
* u-boot.img_unsigned

It is to be noted that the bootflow followed by J721S2 requires:

tiboot3.bin:
* R5 SPL
* R5 SPL dtbs
* TIFS
* board-cfg
* pm-cfg
* sec-cfg
* rm-cfg

tispl.bin:
* DM
* ATF
* OPTEE
* A72 SPL
* A72 SPL dtbs

u-boot.img:
* A72 U-Boot
* A72 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
[a...@ti.com: changed output binary names appropriately]
Signed-off-by: Andrew Davis 
---
 .../arm/dts/k3-am68-sk-base-board-u-boot.dtsi |   2 +
 arch/arm/dts/k3-j721s2-binman.dtsi| 546 ++
 .../k3-j721s2-common-proc-board-u-boot.dtsi   |   2 +
 .../dts/k3-j721s2-r5-common-proc-board.dts|   1 +
 board/ti/j721s2/Kconfig   |   2 +
 5 files changed, 553 insertions(+)
 create mode 100644 arch/arm/dts/k3-j721s2-binman.dtsi

diff --git a/arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi 
b/arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi
index ee31b1ebe7..79faa1b573 100644
--- a/arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-am68-sk-base-board-u-boot.dtsi
@@ -3,6 +3,8 @@
  * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
  */
 
+#include "k3-j721s2-binman.dtsi"
+
 / {
chosen {
stdout-path = "serial2:115200n8";
diff --git a/arch/arm/dts/k3-j721s2-binman.dtsi 
b/arch/arm/dts/k3-j721s2-binman.dtsi
new file mode 100644
index 00..e0307e596b
--- /dev/null
+++ b/arch/arm/dts/k3-j721s2-binman.dtsi
@@ -0,0 +1,546 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "k3-binman.dtsi"
+
+#ifdef CONFIG_TARGET_J721S2_R5_EVM
+
+ {
+   tiboot3-j721s2-hs-evm.bin {
+   filename = "tiboot3-j721s2-hs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl>, <_fs_enc>, 
<_tifs_cfg>,
+   <_dm_cfg>, <_inner_cert>;
+   combined;
+   dm-data;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl>;
+   content-sysfw = <_fs_enc>;
+   content-sysfw-data = <_tifs_cfg>;
+   content-sysfw-inner-cert = <_inner_cert>;
+   content-dm-data = <_dm_cfg>;
+   load = <0x41c0>;
+   load-sysfw = <0x4>;
+   load-sysfw-data = <0x67000>;
+   load-dm-data = <0x41c8>;
+   };
+   u_boot_spl: u-boot-spl {
+   no-expanded;
+   };
+   ti_fs_enc: ti-fs-enc.bin {
+   filename = "ti-sysfw/ti-fs-firmware-j721s2-hs-enc.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_tifs_cfg: combined-tifs-cfg.bin {
+   filename = "combined-tifs-cfg.bin";
+   type = "blob-ext";
+   };
+   sysfw_inner_cert: sysfw-inner-cert {
+   filename = "ti-sysfw/ti-fs-firmware-j721s2-hs-cert.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_dm_cfg: combined-dm-cfg.bin {
+   filename = "combined-dm-cfg.bin";
+   type = "blob-ext";
+   };
+   };
+};
+
+ {
+   tiboot3-j721s2-hs-fs-evm.bin {
+   filename = "tiboot3-j721s2-hs-fs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl_fs>, <_fs_enc_fs>, 
<_tifs_cfg_fs>,
+   <_dm_cfg_fs>, <_inner_cert_fs>;
+   combined;
+   dm-data;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl_fs>;
+   content-sysfw = <_fs_enc_fs>;
+   content-sysfw-data = <_tifs_cfg_fs>;
+   content-sysfw-inner-cert = <_inner_cert_fs>;
+   content-dm-data = <_dm_cfg_fs>;
+   load = <0x41c0>;
+   load-sysfw = <0x4>;
+   load-sysfw-data = <0x67000>;
+   load-dm-data = <0x41c8>;
+   };
+   u_boot_spl_fs: u-boot-spl {
+

[PATCH v7 12/23] j721s2: yaml: Add board configs for J721S2

2023-07-14 Thread Neha Malcom Francis
Added YAML configs for J721S2

Signed-off-by: Neha Malcom Francis 
---
 board/ti/j721s2/board-cfg.yaml |   36 +
 board/ti/j721s2/pm-cfg.yaml|   12 +
 board/ti/j721s2/rm-cfg.yaml| 2901 
 board/ti/j721s2/sec-cfg.yaml   |  379 +
 4 files changed, 3328 insertions(+)
 create mode 100644 board/ti/j721s2/board-cfg.yaml
 create mode 100644 board/ti/j721s2/pm-cfg.yaml
 create mode 100644 board/ti/j721s2/rm-cfg.yaml
 create mode 100644 board/ti/j721s2/sec-cfg.yaml

diff --git a/board/ti/j721s2/board-cfg.yaml b/board/ti/j721s2/board-cfg.yaml
new file mode 100644
index 00..dd024110e7
--- /dev/null
+++ b/board/ti/j721s2/board-cfg.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Board configuration for J721S2
+#
+
+---
+
+board-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+control:
+subhdr:
+magic: 0xC1D3
+size: 7
+main_isolation_enable : 0x5A
+main_isolation_hostid : 0x2
+secproxy:
+subhdr:
+magic: 0x1207
+size: 7
+scaling_factor : 0x1
+scaling_profile : 0x1
+disable_main_nav_secure_proxy : 0
+msmc:
+subhdr:
+magic: 0xA5C3
+size: 5
+msmc_cache_size : 0x0
+debug_cfg:
+subhdr:
+magic: 0x020C
+size: 8
+trace_dst_enables : 0x00
+trace_src_enables : 0x00
diff --git a/board/ti/j721s2/pm-cfg.yaml b/board/ti/j721s2/pm-cfg.yaml
new file mode 100644
index 00..a640460d30
--- /dev/null
+++ b/board/ti/j721s2/pm-cfg.yaml
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Power management configuration for J721S2
+#
+
+---
+
+pm-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
diff --git a/board/ti/j721s2/rm-cfg.yaml b/board/ti/j721s2/rm-cfg.yaml
new file mode 100644
index 00..f772832f19
--- /dev/null
+++ b/board/ti/j721s2/rm-cfg.yaml
@@ -0,0 +1,2901 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Resource management configuration for J721S2
+#
+
+---
+
+rm-cfg:
+rm_boardcfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+host_cfg:
+subhdr:
+magic: 0x4C41
+size : 356
+host_cfg_entries:
+- #1
+host_id: 3
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #2
+host_id: 5
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #3
+host_id: 12
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #4
+host_id: 13
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #5
+host_id: 21
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #6
+host_id: 23
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #7
+host_id: 35
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #8
+host_id: 37
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #9
+host_id: 40
+allowed_atype : 0x2A
+ 

[PATCH v7 11/23] am64x: dts: binman: Package tiboot3.bin, tispl.bin u-boot.img

2023-07-14 Thread Neha Malcom Francis
Support added for HS and GP boot binaries for AM64x.

HS-SE:
* tiboot3-am64x_sr2-hs-evm.bin
* tispl.bin
* u-boot.img

HS-FS:
* tiboot3-am64x_sr2-hs-fs-evm.bin
* tispl.bin
* u-boot.img

GP:
* tiboot3.bin --> tiboot3-am64x-gp-evm.bin
* tispl.bin_unsigned
* u-boot.img_unsigned

Note that the bootflow followed by AM64x requires:

tiboot3.bin:
* R5 SPL
* R5 SPL dtbs
* sysfw
* board-cfg
* pm-cfg
* sec-cfg
* rm-cfg

tispl.bin:
* ATF
* OPTEE
* A53 SPL
* A53 SPL dtbs

u-boot.img:
* A53 U-Boot
* A53 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
[a...@ti.com: changed output binary names appropriately]
Signed-off-by: Andrew Davis 
---
 arch/arm/dts/k3-am642-evm-u-boot.dtsi |   2 +
 arch/arm/dts/k3-am642-r5-evm.dts  |   1 +
 arch/arm/dts/k3-am642-sk-u-boot.dtsi  |   2 +
 arch/arm/dts/k3-am64x-binman.dtsi | 515 ++
 board/ti/am64x/Kconfig|   2 +
 5 files changed, 522 insertions(+)
 create mode 100644 arch/arm/dts/k3-am64x-binman.dtsi

diff --git a/arch/arm/dts/k3-am642-evm-u-boot.dtsi 
b/arch/arm/dts/k3-am642-evm-u-boot.dtsi
index 64857b0909..73577e8cfd 100644
--- a/arch/arm/dts/k3-am642-evm-u-boot.dtsi
+++ b/arch/arm/dts/k3-am642-evm-u-boot.dtsi
@@ -3,6 +3,8 @@
  * Copyright (C) 2020-2021 Texas Instruments Incorporated - https://www.ti.com/
  */
 
+#include "k3-am64x-binman.dtsi"
+
 / {
chosen {
stdout-path = "serial2:115200n8";
diff --git a/arch/arm/dts/k3-am642-r5-evm.dts b/arch/arm/dts/k3-am642-r5-evm.dts
index e870492a69..b49064181a 100644
--- a/arch/arm/dts/k3-am642-r5-evm.dts
+++ b/arch/arm/dts/k3-am642-r5-evm.dts
@@ -8,6 +8,7 @@
 #include "k3-am642.dtsi"
 #include "k3-am64-evm-ddr4-1600MTs.dtsi"
 #include "k3-am64-ddr.dtsi"
+#include "k3-am64x-binman.dtsi"
 
 / {
chosen {
diff --git a/arch/arm/dts/k3-am642-sk-u-boot.dtsi 
b/arch/arm/dts/k3-am642-sk-u-boot.dtsi
index 69dbe943bd..3d6be025bd 100644
--- a/arch/arm/dts/k3-am642-sk-u-boot.dtsi
+++ b/arch/arm/dts/k3-am642-sk-u-boot.dtsi
@@ -3,6 +3,8 @@
  * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/
  */
 
+#include "k3-am64x-binman.dtsi"
+
 / {
chosen {
stdout-path = "serial2:115200n8";
diff --git a/arch/arm/dts/k3-am64x-binman.dtsi 
b/arch/arm/dts/k3-am64x-binman.dtsi
new file mode 100644
index 00..ebc8101ee0
--- /dev/null
+++ b/arch/arm/dts/k3-am64x-binman.dtsi
@@ -0,0 +1,515 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+
+#include "k3-binman.dtsi"
+
+#ifdef CONFIG_TARGET_AM642_R5_EVM
+
+ {
+   tiboot3-am64x_sr2-hs-evm.bin {
+   filename = "tiboot3-am64x_sr2-hs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl>, <_sci_enc>,
+   <_sysfw_cfg>, <_inner_cert>;
+   combined;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl>;
+   content-sysfw = <_sci_enc>;
+   content-sysfw-data = <_sysfw_cfg>;
+   content-sysfw-inner-cert = <_inner_cert>;
+   load = <0x7000>;
+   load-sysfw = <0x44000>;
+   load-sysfw-data = <0x7b000>;
+   };
+   u_boot_spl: u-boot-spl {
+   no-expanded;
+   };
+   ti_sci_enc: ti-fs-enc.bin {
+   filename = 
"ti-sysfw/ti-sci-firmware-am64x_sr2-hs-enc.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_sysfw_cfg: combined-sysfw-cfg.bin {
+   filename = "combined-sysfw-cfg.bin";
+   type = "blob-ext";
+   };
+   sysfw_inner_cert: sysfw-inner-cert {
+   filename = 
"ti-sysfw/ti-sci-firmware-am64x_sr2-hs-cert.bin";
+   type = "blob-ext";
+   optional;
+   };
+
+   };
+};
+
+ {
+   tiboot3-am64x_sr2-hs-fs-evm.bin {
+   filename = "tiboot3-am64x_sr2-hs-fs-evm.bin";
+   symlink = "tiboot3.bin";
+   ti-secure-rom {
+   content = <_boot_spl_fs>, <_sci_enc_fs>,
+   <_sysfw_cfg_fs>, 
<_inner_cert_fs>;
+   combined;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl_fs>;
+   content-sysfw = <_sci_enc_fs>;
+   content-sysfw-data = <_sysfw_cfg_fs>;
+   

[PATCH v7 10/23] am64x: yaml: Add board configs for AM64x

2023-07-14 Thread Neha Malcom Francis
Added YAML configs for AM64xx

Signed-off-by: Neha Malcom Francis 
---
 board/ti/am64x/board-cfg.yaml |   36 +
 board/ti/am64x/pm-cfg.yaml|   12 +
 board/ti/am64x/rm-cfg.yaml| 1400 +
 board/ti/am64x/sec-cfg.yaml   |  380 +
 4 files changed, 1828 insertions(+)
 create mode 100644 board/ti/am64x/board-cfg.yaml
 create mode 100644 board/ti/am64x/pm-cfg.yaml
 create mode 100644 board/ti/am64x/rm-cfg.yaml
 create mode 100644 board/ti/am64x/sec-cfg.yaml

diff --git a/board/ti/am64x/board-cfg.yaml b/board/ti/am64x/board-cfg.yaml
new file mode 100644
index 00..62947c0820
--- /dev/null
+++ b/board/ti/am64x/board-cfg.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Board configuration for AM64x
+#
+
+---
+
+board-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+control:
+subhdr:
+magic: 0xC1D3
+size: 7
+main_isolation_enable : 0x5A
+main_isolation_hostid : 0x2
+secproxy:
+subhdr:
+magic: 0x1207
+size: 7
+scaling_factor : 0x1
+scaling_profile : 0x1
+disable_main_nav_secure_proxy : 0
+msmc:
+subhdr:
+magic: 0xA5C3
+size: 5
+msmc_cache_size : 0x0
+debug_cfg:
+subhdr:
+magic: 0x020C
+size: 8
+trace_dst_enables : 0x00
+trace_src_enables : 0x00
diff --git a/board/ti/am64x/pm-cfg.yaml b/board/ti/am64x/pm-cfg.yaml
new file mode 100644
index 00..83c6a039f2
--- /dev/null
+++ b/board/ti/am64x/pm-cfg.yaml
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Power management configuration for AM64x
+#
+
+---
+
+pm-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
diff --git a/board/ti/am64x/rm-cfg.yaml b/board/ti/am64x/rm-cfg.yaml
new file mode 100644
index 00..1f4c6cf770
--- /dev/null
+++ b/board/ti/am64x/rm-cfg.yaml
@@ -0,0 +1,1400 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Resource management configuration for AM64x
+#
+
+---
+
+rm-cfg:
+rm_boardcfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+host_cfg:
+subhdr:
+magic: 0x4C41
+size : 356
+host_cfg_entries:
+- #1
+host_id: 12
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #2
+host_id: 30
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #3
+host_id: 36
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #4
+host_id: 38
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #5
+host_id: 41
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+   

[PATCH v7 09/23] am65: dts: binman: Package tiboot3.bin, sysfw.itb, tispl.bin, u-boot.img

2023-07-14 Thread Neha Malcom Francis
Support has been added for both HS-SE(SR 2.0) and GP(SR 2.0) images.

HS-SE:
* tiboot3-am65x_sr2-hs-evm.bin
* sysfw-am65x_sr2-hs-evm.itb
* tispl.bin
* u-boot.img

GP:
* tiboot3.bin --> tiboot3-am65x_sr2-gp-evm.bin
* sysfw.itb --> sysfw-am65x_sr2-gp-evm.itb
* tispl.bin_unsigned
* u-boot.img_unsigned

Note that the bootflow followed by AM65x requires:

tiboot3.bin:
* R5 SPL
* R5 SPL dtbs
sysfw.itb:
* sysfw
* board-cfg
* pm-cfg
* sec-cfg
* rm-cfg

tispl.bin:
* ATF
* OPTEE
* A53 SPL
* A53 SPL dtbs

u-boot.img:
* A53 U-Boot
* A53 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
[a...@ti.com: changed output binary names appropriately]
Signed-off-by: Andrew Davis 
---
 arch/arm/dts/k3-am654-base-board-u-boot.dtsi  |   1 +
 .../dts/k3-am654-r5-base-board-u-boot.dtsi|   1 +
 arch/arm/dts/k3-am65x-binman.dtsi | 518 ++
 board/ti/am65x/Kconfig|   2 +
 4 files changed, 522 insertions(+)
 create mode 100644 arch/arm/dts/k3-am65x-binman.dtsi

diff --git a/arch/arm/dts/k3-am654-base-board-u-boot.dtsi 
b/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
index 0c1305df7e..e4cbc47c2a 100644
--- a/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-am654-base-board-u-boot.dtsi
@@ -4,6 +4,7 @@
  */
 
 #include "k3-am654-r5-base-board-u-boot.dtsi"
+#include "k3-am65x-binman.dtsi"
 
 _0 {
remoteproc-name = "pru0_0";
diff --git a/arch/arm/dts/k3-am654-r5-base-board-u-boot.dtsi 
b/arch/arm/dts/k3-am654-r5-base-board-u-boot.dtsi
index 4516ab1437..949320c91d 100644
--- a/arch/arm/dts/k3-am654-r5-base-board-u-boot.dtsi
+++ b/arch/arm/dts/k3-am654-r5-base-board-u-boot.dtsi
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include "k3-am65x-binman.dtsi"
 
 / {
chosen {
diff --git a/arch/arm/dts/k3-am65x-binman.dtsi 
b/arch/arm/dts/k3-am65x-binman.dtsi
new file mode 100644
index 00..ff36ae35d6
--- /dev/null
+++ b/arch/arm/dts/k3-am65x-binman.dtsi
@@ -0,0 +1,518 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "k3-binman.dtsi"
+
+#ifdef CONFIG_TARGET_AM654_R5_EVM
+
+ {
+   tiboot3-am65x_sr2-hs-evm.bin {
+   filename = "tiboot3-am65x_sr2-hs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl>;
+   core = "public";
+   load = ;
+   keyfile = "custMpk.pem";
+   };
+   u_boot_spl: u-boot-spl {
+   no-expanded;
+   };
+   };
+   sysfw {
+   filename = "sysfw.bin";
+   ti-secure-rom {
+   content = <_sci_cert>;
+   core = "secure";
+   load = <0x4>;
+   keyfile = "custMpk.pem";
+   countersign;
+   };
+   ti_sci_cert: ti-sci-cert.bin {
+   filename = 
"ti-sysfw/ti-sci-firmware-am65x_sr2-hs-cert.bin";
+   type = "blob-ext";
+   optional;
+   };
+   ti-sci-firmware-am65x-hs-enc.bin {
+   filename = 
"ti-sysfw/ti-sci-firmware-am65x_sr2-hs-enc.bin";
+   type = "blob-ext";
+   optional;
+   };
+   };
+   itb {
+   filename = "sysfw-am65x_sr2-hs-evm.itb";
+   fit {
+   description = "SYSFW and Config fragments";
+   #address-cells = <1>;
+   images {
+   sysfw.bin {
+   description = "sysfw";
+   type = "firmware";
+   arch = "arm";
+   compression = "none";
+   blob-ext {
+   filename = "sysfw.bin";
+   };
+   };
+   board-cfg.bin {
+   description = "board-cfg";
+   type = "firmware";
+   arch = "arm";
+   compression = "none";
+   ti-secure {
+   content = <_cfg>;
+   keyfile = "custMpk.pem";
+   };
+   board_cfg: board-cfg {
+   filename = "board-cfg.bin";
+   type 

Re: [PATCH 4/5] CI: Update to gcc-13.1.0

2023-07-14 Thread Alexey Brodkin
Hi Tom,

> As this is the current version of the public cross toolchains we use,
> upgrade to this now.
> 
> Suggested-by: Alexey Brodkin 
> Signed-off-by: Tom Rini 
> ---
> Cc: Heinrich Schuchardt 
> 
> Heinrich, at this point is there a newer grub we should be testing?
> There's now 2 changes for RISC-V that we're cherry-picking for newer
> toolchains.

That's what I noticed as well - grub fails to build for RISCV
with the following message, I guess you saw that as well:
--->8--
./grub-mkimage: error: relocation 0x13 is not implemented yet.
--->8--

> ---
>  .azure-pipelines.yml|  2 +-
>  .gitlab-ci.yml  |  2 +-
>  tools/buildman/toolchain.py |  2 +-
>  tools/docker/Dockerfile | 57 +++--
>  4 files changed, 32 insertions(+), 31 deletions(-)
> 
> diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
> index 76982ec3e52e..83cc6176e7b4 100644
> --- a/.azure-pipelines.yml
> +++ b/.azure-pipelines.yml
> @@ -194,7 +194,7 @@ stages:
>ln -s /opt/nokia/libc6_2.5.1-1eglibc27+0m5_armel.deb 
> nokia_rx51_tmp/
>ln -s /opt/nokia/busybox_1.10.2.legal-1osso30+0m5_armel.deb 
> nokia_rx51_tmp/
>ln -s /opt/nokia/qemu-system-arm nokia_rx51_tmp/
> -  export PATH=/opt/gcc-12.2.0-nolibc/arm-linux-gnueabi/bin:$PATH
> +  export PATH=/opt/gcc-13.1.0-nolibc/arm-linux-gnueabi/bin:$PATH
>test/nokia_rx51_test.sh
>  
>- job: pylint
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index f7ffb8f5dfdc..5300813cf511 100644
> --- a/.gitlab-ci.yml
> +++ b/.gitlab-ci.yml
> @@ -232,7 +232,7 @@ Run tests for Nokia RX-51 (aka N900):
>ln -s /opt/nokia/libc6_2.5.1-1eglibc27+0m5_armel.deb nokia_rx51_tmp/;
>ln -s /opt/nokia/busybox_1.10.2.legal-1osso30+0m5_armel.deb 
> nokia_rx51_tmp/;
>ln -s /opt/nokia/qemu-system-arm nokia_rx51_tmp/;
> -  export PATH=/opt/gcc-12.2.0-nolibc/arm-linux-gnueabi/bin:$PATH;
> +  export PATH=/opt/gcc-13.1.0-nolibc/arm-linux-gnueabi/bin:$PATH;
>test/nokia_rx51_test.sh
>  
>  # Check for any pylint regressions
> diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
> index 0ecd8458b912..1001b612086f 100644
> --- a/tools/buildman/toolchain.py
> +++ b/tools/buildman/toolchain.py
> @@ -499,7 +499,7 @@ class Toolchains:
>  if arch == 'aarch64':
>  arch = 'arm64'
>  base = 'https://www.kernel.org/pub/tools/crosstool/files/bin'
> -versions = ['12.2.0', '11.1.0']
> +versions = ['13.1.0', '12.2.0']
>  links = []
>  for version in versions:
>  url = '%s/%s/%s/' % (base, arch, version)
> diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
> index f72cba0b8cc4..2f2ace2e6554 100644
> --- a/tools/docker/Dockerfile
> +++ b/tools/docker/Dockerfile
> @@ -14,18 +14,18 @@ RUN apt-get update && apt-get install -y gnupg2 wget 
> xz-utils && rm -rf /var/lib
>  RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
>  RUN echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main | tee 
> /etc/apt/sources.list.d/llvm.list
>  
> -# Manually install the kernel.org "Crosstool" based toolchains for gcc-12.2.0
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-aarch64-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-arm-linux-gnueabi.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-i386-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-m68k-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-mips-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-microblaze-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-nios2-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-powerpc-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-riscv64-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/12.2.0/x86_64-gcc-12.2.0-nolibc-riscv32-linux.tar.xz
>  | tar -C /opt -xJ
> -RUN wget -O - 
> 

[PATCH v7 08/23] am65x: yaml: Add AM65x board config files

2023-07-14 Thread Neha Malcom Francis
Added YAML configs for AM65x

Signed-off-by: Neha Malcom Francis 
---
 board/ti/am65x/board-cfg.yaml |   36 +
 board/ti/am65x/pm-cfg.yaml|   12 +
 board/ti/am65x/rm-cfg.yaml| 2068 +
 board/ti/am65x/sec-cfg.yaml   |  379 ++
 4 files changed, 2495 insertions(+)
 create mode 100644 board/ti/am65x/board-cfg.yaml
 create mode 100644 board/ti/am65x/pm-cfg.yaml
 create mode 100644 board/ti/am65x/rm-cfg.yaml
 create mode 100644 board/ti/am65x/sec-cfg.yaml

diff --git a/board/ti/am65x/board-cfg.yaml b/board/ti/am65x/board-cfg.yaml
new file mode 100644
index 00..a8e06166d5
--- /dev/null
+++ b/board/ti/am65x/board-cfg.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Board configuration for AM65x
+#
+
+---
+
+board-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+control:
+subhdr:
+magic: 0xC1D3
+size: 7
+main_isolation_enable : 0x5A
+main_isolation_hostid : 0x2
+secproxy:
+subhdr:
+magic: 0x1207
+size: 7
+scaling_factor : 0x1
+scaling_profile : 0x1
+disable_main_nav_secure_proxy : 0
+msmc:
+subhdr:
+magic: 0xA5C3
+size: 5
+msmc_cache_size : 0x10
+debug_cfg:
+subhdr:
+magic: 0x020C
+size: 8
+trace_dst_enables : 0x00
+trace_src_enables : 0x00
diff --git a/board/ti/am65x/pm-cfg.yaml b/board/ti/am65x/pm-cfg.yaml
new file mode 100644
index 00..73fe86c29a
--- /dev/null
+++ b/board/ti/am65x/pm-cfg.yaml
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Power management configuration for AM65x
+#
+
+---
+
+pm-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
diff --git a/board/ti/am65x/rm-cfg.yaml b/board/ti/am65x/rm-cfg.yaml
new file mode 100644
index 00..5903773e81
--- /dev/null
+++ b/board/ti/am65x/rm-cfg.yaml
@@ -0,0 +1,2068 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Resource management configuration for AM65x
+#
+
+---
+
+rm-cfg:
+rm_boardcfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+host_cfg:
+subhdr:
+magic: 0x4C41
+size : 356
+host_cfg_entries:
+- #1
+host_id: 3
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #2
+host_id: 5
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #3
+host_id: 12
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #4
+host_id: 13
+allowed_atype : 0x2A
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #5
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #6
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #7
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #8
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+allowed_sched_priority : 0
+- #9
+host_id: 0
+allowed_atype : 0
+allowed_qos : 0
+allowed_orderid : 0
+allowed_priority : 0
+   

[PATCH v7 07/23] j7200: dts: binman: Package tiboot3.bin, tispl.bin, u-boot.img

2023-07-14 Thread Neha Malcom Francis
Support has been added for both HS-SE(SR 2.0), HS-FS(SR 2.0) and GP
images.

HS-SE:
* tiboot3-j7200_sr2-hs-evm.bin
* tispl.bin
* u-boot.img

HS-FS:
* tiboot3-j7200_sr2-hs-fs-evm.bin
* tispl.bin
* u-boot.img

GP:
* tiboot3.bin --> tiboot3-j7200-gp-evm.bin
* tispl.bin_unsigned
* u-boot.img_unsigned

It is to be noted that the bootflow followed by J7200 requires:

tiboot3.bin:
* R5 SPL
* R5 SPL dtbs
* TIFS
* board-cfg
* pm-cfg
* sec-cfg
* rm-cfg

tispl.bin:
* DM
* ATF
* OPTEE
* A72 SPL
* A72 SPL dtbs

u-boot.img:
* A72 U-Boot
* A72 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
[a...@ti.com: changed output binary names appropriately]
Signed-off-by: Andrew Davis 
---
 arch/arm/dts/k3-j7200-binman.dtsi | 502 ++
 .../k3-j7200-common-proc-board-u-boot.dtsi|   2 +
 board/ti/j721e/Kconfig|   2 +
 3 files changed, 506 insertions(+)
 create mode 100644 arch/arm/dts/k3-j7200-binman.dtsi

diff --git a/arch/arm/dts/k3-j7200-binman.dtsi 
b/arch/arm/dts/k3-j7200-binman.dtsi
new file mode 100644
index 00..4b055773bf
--- /dev/null
+++ b/arch/arm/dts/k3-j7200-binman.dtsi
@@ -0,0 +1,502 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "k3-binman.dtsi"
+
+#ifdef CONFIG_TARGET_J7200_R5_EVM
+
+_yaml {
+   config = "board-cfg_j7200.yaml";
+};
+
+_yaml {
+   config = "rm-cfg_j7200.yaml";
+};
+
+_yaml {
+   config = "pm-cfg_j7200.yaml";
+};
+
+_yaml {
+   config = "sec-cfg_j7200.yaml";
+};
+
+_yaml_tifs {
+   config = "board-cfg_j7200.yaml";
+};
+
+_yaml_tifs {
+   config = "rm-cfg_j7200.yaml";
+};
+
+_yaml_tifs {
+   config = "pm-cfg_j7200.yaml";
+};
+
+_yaml_tifs {
+   config = "sec-cfg_j7200.yaml";
+};
+
+_yaml_dm {
+   config = "rm-cfg_j7200.yaml";
+};
+
+_yaml_dm {
+   config = "pm-cfg_j7200.yaml";
+};
+
+ {
+   tiboot3-j7200_sr2-hs-evm.bin {
+   filename = "tiboot3-j7200_sr2-hs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl>, <_fs_enc>, 
<_tifs_cfg>,
+   <_dm_cfg>, <_inner_cert>;
+   combined;
+   dm-data;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl>;
+   content-sysfw = <_fs_enc>;
+   content-sysfw-data = <_tifs_cfg>;
+   content-sysfw-inner-cert = <_inner_cert>;
+   content-dm-data = <_dm_cfg>;
+   load = <0x41c0>;
+   load-sysfw = <0x4>;
+   load-sysfw-data = <0x7f000>;
+   load-dm-data = <0x41c8>;
+   };
+   u_boot_spl: u-boot-spl {
+   no-expanded;
+   };
+   ti_fs_enc: ti-fs-enc.bin {
+   filename = 
"ti-sysfw/ti-fs-firmware-j7200_sr2-hs-enc.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_tifs_cfg: combined-tifs-cfg.bin {
+   filename = "combined-tifs-cfg.bin";
+   type = "blob-ext";
+   };
+   sysfw_inner_cert: sysfw-inner-cert {
+   filename = 
"ti-sysfw/ti-fs-firmware-j7200_sr2-hs-cert.bin";
+   type = "blob-ext";
+   optional;
+   };
+   combined_dm_cfg: combined-dm-cfg.bin {
+   filename = "combined-dm-cfg.bin";
+   type = "blob-ext";
+   };
+   };
+};
+
+ {
+   tiboot3-j7200_sr2-hs-fs-evm.bin {
+   filename = "tiboot3-j7200_sr2-hs-fs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl_fs>, <_fs_enc_fs>, 
<_tifs_cfg_fs>,
+   <_dm_cfg_fs>, <_inner_cert_fs>;
+   combined;
+   dm-data;
+   sysfw-inner-cert;
+   keyfile = "custMpk.pem";
+   sw-rev = <1>;
+   content-sbl = <_boot_spl_fs>;
+   content-sysfw = <_fs_enc_fs>;
+   content-sysfw-data = <_tifs_cfg_fs>;
+   content-sysfw-inner-cert = <_inner_cert_fs>;
+   content-dm-data = <_dm_cfg_fs>;
+   load = <0x41c0>;
+   load-sysfw = <0x4>;
+   load-sysfw-data = <0x7f000>;
+   load-dm-data = <0x41c8>;
+   };

[PATCH v7 06/23] j7200: yaml: Add J7200 board config files

2023-07-14 Thread Neha Malcom Francis
Added YAML configs for J7200

Signed-off-by: Neha Malcom Francis 
---
 board/ti/j721e/board-cfg_j7200.yaml |   36 +
 board/ti/j721e/pm-cfg_j7200.yaml|   12 +
 board/ti/j721e/rm-cfg_j7200.yaml| 2065 +++
 board/ti/j721e/sec-cfg_j7200.yaml   |  380 +
 4 files changed, 2493 insertions(+)
 create mode 100644 board/ti/j721e/board-cfg_j7200.yaml
 create mode 100644 board/ti/j721e/pm-cfg_j7200.yaml
 create mode 100644 board/ti/j721e/rm-cfg_j7200.yaml
 create mode 100644 board/ti/j721e/sec-cfg_j7200.yaml

diff --git a/board/ti/j721e/board-cfg_j7200.yaml 
b/board/ti/j721e/board-cfg_j7200.yaml
new file mode 100644
index 00..0ac1ae93fe
--- /dev/null
+++ b/board/ti/j721e/board-cfg_j7200.yaml
@@ -0,0 +1,36 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Board configuration for J7200
+#
+
+---
+
+board-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+control:
+subhdr:
+magic: 0xC1D3
+size: 7
+main_isolation_enable : 0x5A
+main_isolation_hostid : 0x2
+secproxy:
+subhdr:
+magic: 0x1207
+size: 7
+scaling_factor : 0x1
+scaling_profile : 0x1
+disable_main_nav_secure_proxy : 0
+msmc:
+subhdr:
+magic: 0xA5C3
+size: 5
+msmc_cache_size : 0x10
+debug_cfg:
+subhdr:
+magic: 0x020C
+size: 8
+trace_dst_enables : 0x00
+trace_src_enables : 0x00
diff --git a/board/ti/j721e/pm-cfg_j7200.yaml b/board/ti/j721e/pm-cfg_j7200.yaml
new file mode 100644
index 00..daaefb1318
--- /dev/null
+++ b/board/ti/j721e/pm-cfg_j7200.yaml
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Power management configuration for J7200
+#
+
+---
+
+pm-cfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
diff --git a/board/ti/j721e/rm-cfg_j7200.yaml b/board/ti/j721e/rm-cfg_j7200.yaml
new file mode 100644
index 00..263285ff42
--- /dev/null
+++ b/board/ti/j721e/rm-cfg_j7200.yaml
@@ -0,0 +1,2065 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+#
+# Resource management configuration for J7200
+#
+
+---
+
+rm-cfg:
+rm_boardcfg:
+rev:
+boardcfg_abi_maj : 0x0
+boardcfg_abi_min : 0x1
+host_cfg:
+subhdr:
+magic: 0x4C41
+size : 356
+host_cfg_entries:
+- #1
+host_id: 3
+allowed_atype : 0b101010
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #2
+host_id: 5
+allowed_atype : 0b101010
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #3
+host_id: 12
+allowed_atype : 0b101010
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #4
+host_id: 13
+allowed_atype : 0b101010
+allowed_qos : 0x
+allowed_orderid : 0x
+allowed_priority : 0x
+allowed_sched_priority : 0xAA
+- #5
+host_id: 35
+allowed_atype : 0b101010
+allowed_qos : 0x
+

[PATCH v7 05/23] j721e: dts: binman: Package tiboot3.bin, sysfw.itb, tispl.bin, u-boot.img

2023-07-14 Thread Neha Malcom Francis
By providing entries in the binman node of the device tree, binman will
be able to find and package board config artifacts generated by
TIBoardConfig with sysfw.bin and generate the final image sysfw.itb.
It will also pick out the R5 SPL and sign it with the help of TI signing
entry and generate the final tiboot3.bin.

Entries for A72 build have been added to k3-j721e-binman.dtsi to
generate tispl.bin and u-boot.img.

Support has been added for both HS-SE(SR 1.1), HS-FS(SR 2.0) and GP images
In HS-SE, the encrypted system firmware binary must be signed along with
the signed certificate binary.

HS-SE:
* tiboot3-j721e_sr1_1-hs-evm.bin
* sysfw-j721e_sr1_1-hs-evm.itb
* tispl.bin
* u-boot.img

HS-FS:
* tiboot3-j721e_sr2-hs-fs-evm.bin
* sysfw-j721e_sr2-hs-fs-evm.itb
* tispl.bin
* u-boot.img

GP:
* tiboot3.bin -->tiboot3-j721e-gp-evm.bin
* sysfw.itb --> sysfw-j721e-gp-evm.itb
* tispl.bin_unsigned
* u-boot.img_unsigned

It is to be noted that the bootflow followed by J721E requires:

tiboot3.bin:
* R5 SPL
* R5 SPL dtbs

sysfw.itb:
* TIFS
* board-cfg
* pm-cfg
* sec-cfg
* rm-cfg

tispl.bin:
* DM
* ATF
* OPTEE
* A72 SPL
* A72 SPL dtbs

u-boot.img:
* A72 U-Boot
* A72 U-Boot dtbs

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
[a...@ti.com: changed output binary names appropriately]
Signed-off-by: Andrew Davis 
---
 arch/arm/dts/k3-j721e-binman.dtsi | 701 ++
 .../k3-j721e-common-proc-board-u-boot.dtsi|   1 +
 .../arm/dts/k3-j721e-r5-common-proc-board.dts |   1 +
 arch/arm/dts/k3-j721e-sk-u-boot.dtsi  |   1 +
 board/ti/j721e/Kconfig|   2 +
 5 files changed, 706 insertions(+)
 create mode 100644 arch/arm/dts/k3-j721e-binman.dtsi

diff --git a/arch/arm/dts/k3-j721e-binman.dtsi 
b/arch/arm/dts/k3-j721e-binman.dtsi
new file mode 100644
index 00..339e909501
--- /dev/null
+++ b/arch/arm/dts/k3-j721e-binman.dtsi
@@ -0,0 +1,701 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+#include "k3-binman.dtsi"
+
+#ifdef CONFIG_TARGET_J721E_R5_EVM
+
+ {
+   tiboot3-j721e_sr1_1-hs-evm.bin {
+   filename = "tiboot3-j721e_sr1_1-hs-evm.bin";
+   ti-secure-rom {
+   content = <_boot_spl>;
+   core = "public";
+   load = ;
+   keyfile = "custMpk.pem";
+   };
+   u_boot_spl: u-boot-spl {
+   no-expanded;
+   };
+   };
+   sysfw {
+   filename = "sysfw.bin";
+   ti-secure-rom {
+   content = <_fs_cert>;
+   core = "secure";
+   load = <0x4>;
+   keyfile = "custMpk.pem";
+   countersign;
+   };
+   ti_fs_cert: ti-fs-cert.bin {
+   filename = 
"ti-sysfw/ti-fs-firmware-j721e_sr1_1-hs-cert.bin";
+   type = "blob-ext";
+   optional;
+   };
+   ti-fs-firmware-j721e_sr1_1-hs-enc.bin {
+   filename = 
"ti-sysfw/ti-fs-firmware-j721e_sr1_1-hs-enc.bin";
+   type = "blob-ext";
+   optional;
+   };
+   };
+   itb {
+   filename = "sysfw-j721e_sr1_1-hs-evm.itb";
+   fit {
+   description = "SYSFW and Config fragments";
+   #address-cells = <1>;
+   images {
+   sysfw.bin {
+   description = "sysfw";
+   type = "firmware";
+   arch = "arm";
+   compression = "none";
+   blob-ext {
+   filename = "sysfw.bin";
+   };
+   };
+   board-cfg.bin {
+   description = "board-cfg";
+   type = "firmware";
+   arch = "arm";
+   compression = "none";
+   ti-secure {
+   content = <_cfg>;
+   keyfile = "custMpk.pem";
+   };
+   board_cfg: board-cfg {
+   filename = "board-cfg.bin";
+   

[PATCH v7 02/23] binman: ti-secure: Add support for TI signing

2023-07-14 Thread Neha Malcom Francis
The ti-secure entry contains certificate for binaries that will be
loaded or booted by system firmware whereas the ti-secure-rom entry
contains certificate for binaries that will be booted by ROM. Support
for both these types of certificates is necessary for booting of K3
devices.

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
[vigne...@ti.com: fixed inconsist cert generation by multiple packing]
Signed-off-by: Vignesh Raghavendra 
---
 board/ti/keys/custMpk.pem |  51 
 board/ti/keys/ti-degenerate-key.pem   |  10 +
 tools/binman/btool/openssl.py | 244 +
 tools/binman/entries.rst  |  65 +
 tools/binman/etype/ti_secure.py   |  78 ++
 tools/binman/etype/ti_secure_rom.py   | 249 ++
 tools/binman/etype/x509_cert.py   |  87 +-
 tools/binman/ftest.py |  52 
 tools/binman/test/279_ti_secure.dts   |  17 ++
 tools/binman/test/280_ti_secure_rom.dts   |  17 ++
 .../test/281_ti_secure_rom_combined.dts   |  25 ++
 tools/binman/test/288_ti_secure_rom_a.dts |  19 ++
 tools/binman/test/289_ti_secure_rom_b.dts |  18 ++
 13 files changed, 924 insertions(+), 8 deletions(-)
 create mode 100644 board/ti/keys/custMpk.pem
 create mode 100644 board/ti/keys/ti-degenerate-key.pem
 create mode 100644 tools/binman/etype/ti_secure.py
 create mode 100644 tools/binman/etype/ti_secure_rom.py
 create mode 100644 tools/binman/test/279_ti_secure.dts
 create mode 100644 tools/binman/test/280_ti_secure_rom.dts
 create mode 100644 tools/binman/test/281_ti_secure_rom_combined.dts
 create mode 100644 tools/binman/test/288_ti_secure_rom_a.dts
 create mode 100644 tools/binman/test/289_ti_secure_rom_b.dts

diff --git a/board/ti/keys/custMpk.pem b/board/ti/keys/custMpk.pem
new file mode 100644
index 00..adba378c80
--- /dev/null
+++ b/board/ti/keys/custMpk.pem
@@ -0,0 +1,51 @@
+-BEGIN RSA PRIVATE KEY-
+MIIJKQIBAAKCAgEAvxSuSdh/ctNrI83rSA5l3CJN8g5PgvbttfLd23yR+m5Z/9X3
+tt4EHYrM0pXZ0eDEwfhQv/9IDJEiUJpMe4vzlgooJrOk2eCpVUEa+z5bJ2y/ysBx
+ry9yIu5GASVirT7HBPaxGLYswBJuD+KbPuWmoKgGRQNBF04WH6l01oRO1nmnELgR
+qQ6SHyXdf7Hy0bnyaNgzWUuCfXfM0Zz6I7T7WIjyzerVFvIsdS36YsPBCW7gBnDg
+tQcJmWLZ1uTnbG3IggdQk/fi2O3RX+PQns+TVNlf3V3ON2DxqxSKBHtlp7p/30VF
+fEuhW65OxpQ9jE6H0pQ8pPOf2vzyNnznDa1aQjfxKoHQbqGnZwMeh+0Au3NKaCgx
+ooKaowTB6If/RX6qwZ/UOwXHg/0hcf69fzjJFhlSDuYDM40dHsk2HM1OnYIpiM2b
+Kr5sX3uysjp5AGp99a0anR7NWCrPXvROgKs7T9341N40osQg2VkZLYUCXh9osUyN
+uREG6S12tViMUKg3bmZ4b4MwRk00n7QYSrm7+nvFrtYyEISEbD+agDM1/E281W5g
+VFDPfm2AlwT6jwsg/b2YK6E3vVn9SuxFoQmLF8lyFDO3BV4SXeJaHc4hVPbh6tVV
+qifrTQnfGUCCLmaJF2XZbrPWOE6NYRbWdNTeFl9RGdVCuIPSyN5LqWmXto0CAwEA
+AQKCAgAzkAwcJ0z1GnId/lJQZno8NhGckRoJuEKbR8dwlCP8VUz6Ca5H7Y9kvXDa
+Hs/hn+rYgP6hYOz7XyrIX2rmJ/T6dxEwqGeC1+o59FConcIRWHpE5zuGT6JYJL5F
+TuZa48bm4v8VMQvQZOjIZpkIFwao8c6HTwKAnHTB5IN/48I2hCt+Cn3RhfoOZ7Rm
+4gkpaSkt+7GXlhXHb82YfujNO+hbktEamhUYlQ9EK70Wa8aqmf3gHxO0JgsEFjW8
+lJaSnultlTW8SDcx3LMUUjCYumECk4oX/VlJfmKYjPlVjkr3QQ+Cm3nNucb4K4hc
+c+JL+2ERhSj8RjXL7VgbNgdPnIjvQDJuTNqecTU8xWPYrkOLQpNibbLjnutLkhJz
+fMyRtmDtrsey8WiCDuCHkPJ8/f8RjL2zWI9fzTDDIzdlEKouUFGOovaHVnbua6pn
+hymcu9d9FV3p2rcbj0ivCs7e8j+vhSxFJEJoAbcQdXCTi/n2uR7pLtoMNiUzsejy
+d46Uz+KEU920NTwE2z6JJq8I2vegnxjc7PDDrV3/5rK04B93aXiqvwWseCpxelrI
+xaMkRHbXrIXRO6MXQ3N+zNq8Dg3hjGTTvaBKuwgvqLwlXY8+Aa3ooFzEOInIOSsI
+XcWqXxt/tgZgsj9RwpC42t8kbA+BkbNk9EIUa+P5kEr2P/fO7QKCAQEA4EtArnOX
+D6tQF8uTw8USOZC2P9s/ez1z4jRq3oKP0Kv4tJiuIObJ/dUvGVD7aM5v2xaCfhm8
+xpk09VPUgghfG5jR5qVvQr75kCNToJQudWi4ngk1HwKJzzTO11giFEdybvTUA+Pj
+fmxCM0dYYqRWZoj0hLqXlUCwxE74BFIhJVjeYbf+nTQrqpllTLoW7MTZHzGx5SXx
+4dNzyVAUH49Yt2D8mgXXCkf5sGLh762wj34b/rR10Kr4O5utGMZrfTRIbuQ1pNjU
+m66baPzq+mC0BzqZEW70TgEb7lOr8rcVXLOi3r36omfd9/MHx7iZD6o3K1axSO15
+grD4ZrN7Ac3QJwKCAQEA2heCoBdpvy6YUk8AO2k8qDygTdmPQRuwjjT+Z2fMslBt
+D7DkpKwZ6Bl9OclcpiiLHmH+hv65KqYg+tR0RRb7PcogB9El9x7yKkGTPZEYWGky
+n8P84rJpKwjnwWQvPQktI1cs3YGvZA9DQTFBavRrwuzgd1oSJq5aPQ2tme0kMvWp
+l1/B/cPK+PKCi/Wfisaze1TjijP9qIeUwkdNN6WLrLU3QgsGppcg2I7RQtAIikT6
+GkuiOQAvWMsrJVV6PNrVKz4fJDJ59Rz6jbDHZNi1MEYNxQoB/Pl7QIakbfjWpHLv
+8Ey7cB2JKxjQy8tmyl8WNQVbXbE6daPXcMTUmaRAKwKCAQBv1lYMJmq+T2eCVen6
+BbvOpE+bi5EdvEiaFBTtmiBnpjg+pJq+oRU60h/H+c9CNR0lGxY6Fk9An4f+g6xE
+ojP6KLsQzJCrsVny+wpp2TlJJcxYULMCIVvhy60PR0zG29E9biqBPhJjKUvhEcQK
+e3LxcXyq6fdHXphFajLUxLbuTl+kTgBRFoBnclFGbsubh5PTsA3J+p+fQLZNPPar
+veg4l82cZykQYU8pGkUaI3sUMYd3+zd7sqRP5JHs9pMGPRmY4YW2CsAIWIn5UZNB
+ARMDP76vKKn8cyUgMuxb+9pU/OVLN2NPs4bEaZQJjAwV+YPEwldny7F47xEM9JVz
+EtKlAoIBAQDUt62u3GdGE/p5/ZgqWoDRTyDEDfmN9aYFbmbdEP80xQE7FrxMaZhz
+K7laja6SWmUm40nQ/c45bQQp4uLtKHcxU15egX7YRBTLZl5o5IasZR79ebnEm2O8
+l9kEZeU1USf3mmWmP4GExOZCRfqaiYA6BbUCdJXTqKdXeWnkAssV8UrS3JFoJHpq
+yo7OWGqefyQ8nRW6jO9SW7uaqtUD+7H6aF5XSk3YWvusfdBZrHNH+fM/hpnZovaL
+Us7ogTDS/laA8PyK37jYfMVdQhmZoU1Iomt3zkUWK3gt/aWPpfAlQf4Jka4YspZB
+tNiijefaZ1hPqsPs5Joyd/YAhdsfaHc1AoIBAQCn/9j6RRjRaw0ip756oad4AXHz
+XBwVB2CrY96qT6Hj9Sq7tGgdskqGkOQkAivBLBizUdcWv0t1yenOsSgasQeMlvlh

[PATCH v7 03/23] arm: dts: k3: Add support for packaging sysfw.itb and tiboot3.bin

2023-07-14 Thread Neha Malcom Francis
Board config binary artifacts must be generated to be used by binman to
package sysfw.itb and tiboot3.bin for all K3 devices.

For devices that follow combined flow, these board configuration
binaries must again be packaged into a combined board configuration
blobs to be used by binman to package tiboot3.bin.

Add common k3-binman.dtsi to generate all the board configuration
binaries needed.

Also add custMpk.pem and ti-degenerate-key.pem needed for signing GP and
HS bootloader images common to all K3 devices.

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
---
 arch/arm/dts/k3-binman.dtsi | 116 
 1 file changed, 116 insertions(+)
 create mode 100644 arch/arm/dts/k3-binman.dtsi

diff --git a/arch/arm/dts/k3-binman.dtsi b/arch/arm/dts/k3-binman.dtsi
new file mode 100644
index 00..2a67cebf94
--- /dev/null
+++ b/arch/arm/dts/k3-binman.dtsi
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+/ {
+   binman: binman {
+   multiple-images;
+   };
+};
+
+ {
+   custMpk {
+   filename = "custMpk.pem";
+   blob-ext {
+   filename = "../keys/custMpk.pem";
+   };
+   };
+
+   ti-degenerate-key {
+   filename = "ti-degenerate-key.pem";
+   blob-ext {
+   filename = "../keys/ti-degenerate-key.pem";
+   };
+   };
+};
+
+#ifndef CONFIG_ARM64
+
+ {
+   board-cfg {
+   filename = "board-cfg.bin";
+   bcfg_yaml: ti-board-config {
+   config = "board-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   };
+   pm-cfg {
+   filename = "pm-cfg.bin";
+   rcfg_yaml: ti-board-config {
+   config = "pm-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   };
+   rm-cfg {
+   filename = "rm-cfg.bin";
+   pcfg_yaml: ti-board-config {
+   config = "rm-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   };
+   sec-cfg {
+   filename = "sec-cfg.bin";
+   scfg_yaml: ti-board-config {
+   config = "sec-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   };
+   combined-tifs-cfg {
+   filename = "combined-tifs-cfg.bin";
+   ti-board-config {
+   bcfg_yaml_tifs: board-cfg {
+   config = "board-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   scfg_yaml_tifs: sec-cfg {
+   config = "sec-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   pcfg_yaml_tifs: pm-cfg {
+   config = "pm-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   rcfg_yaml_tifs: rm-cfg {
+   config = "rm-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   };
+   };
+   combined-dm-cfg {
+   filename = "combined-dm-cfg.bin";
+   ti-board-config {
+   pcfg_yaml_dm: pm-cfg {
+   config = "pm-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   rcfg_yaml_dm: rm-cfg {
+   config = "rm-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   };
+   };
+   combined-sysfw-cfg {
+   filename = "combined-sysfw-cfg.bin";
+   ti-board-config {
+   board-cfg {
+   config = "board-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   sec-cfg {
+   config = "sec-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   pm-cfg {
+   config = "pm-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   rm-cfg {
+   config = "rm-cfg.yaml";
+   schema = "../common/schema.yaml";
+   };
+   };
+   };
+};
+
+#endif
-- 
2.34.1



[PATCH v7 01/23] binman: ti-board-config: Add support for TI board config binaries

2023-07-14 Thread Neha Malcom Francis
The ti-board-config entry loads and validates a given YAML config file
against a given schema, and generates the board config binary. K3
devices require these binaries to be packed into the final system
firmware images.

Signed-off-by: Neha Malcom Francis 
Reviewed-by: Simon Glass 
---
 tools/binman/entries.rst  |  48 
 tools/binman/etype/ti_board_config.py | 259 ++
 tools/binman/ftest.py |  20 ++
 tools/binman/test/277_ti_board_cfg.dts|  14 +
 .../binman/test/278_ti_board_cfg_combined.dts |  25 ++
 .../binman/test/279_ti_board_cfg_no_type.dts  |  11 +
 tools/binman/test/yaml/config.yaml|  18 ++
 tools/binman/test/yaml/schema.yaml|  49 
 tools/binman/test/yaml/schema_notype.yaml |  38 +++
 9 files changed, 482 insertions(+)
 create mode 100644 tools/binman/etype/ti_board_config.py
 create mode 100644 tools/binman/test/277_ti_board_cfg.dts
 create mode 100644 tools/binman/test/278_ti_board_cfg_combined.dts
 create mode 100644 tools/binman/test/279_ti_board_cfg_no_type.dts
 create mode 100644 tools/binman/test/yaml/config.yaml
 create mode 100644 tools/binman/test/yaml/schema.yaml
 create mode 100644 tools/binman/test/yaml/schema_notype.yaml

diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index b71af801fd..14a2d03fad 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -1658,6 +1658,54 @@ by setting the size of the entry to something larger 
than the text.
 
 
 
+.. _etype_ti_board_config:
+
+Entry: ti-board-config: An entry containing a TI schema validated board config 
binary
+-
+
+This etype supports generation of two kinds of board configuration
+binaries: singular board config binary as well as combined board config
+binary.
+
+Properties / Entry arguments:
+- config-file: File containing board configuration data in YAML
+- schema-file: File containing board configuration YAML schema against
+  which the config file is validated
+
+Output files:
+- board config binary: File containing board configuration binary
+
+These above parameters are used only when the generated binary is
+intended to be a single board configuration binary. Example::
+
+my-ti-board-config {
+ti-board-config {
+config = "board-config.yaml";
+schema = "schema.yaml";
+};
+};
+
+To generate a combined board configuration binary, we pack the
+needed individual binaries into a ti-board-config binary. In this case,
+the available supported subnode names are board-cfg, pm-cfg, sec-cfg and
+rm-cfg. The final binary is prepended with a header containing details about
+the included board config binaries. Example::
+
+my-combined-ti-board-config {
+ti-board-config {
+board-cfg {
+config = "board-cfg.yaml";
+schema = "schema.yaml";
+};
+sec-cfg {
+config = "sec-cfg.yaml";
+schema = "schema.yaml";
+};
+}
+}
+
+
+
 .. _etype_u_boot:
 
 Entry: u-boot: U-Boot flat binary
diff --git a/tools/binman/etype/ti_board_config.py 
b/tools/binman/etype/ti_board_config.py
new file mode 100644
index 00..94f894c281
--- /dev/null
+++ b/tools/binman/etype/ti_board_config.py
@@ -0,0 +1,259 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2022-2023 Texas Instruments Incorporated - https://www.ti.com/
+# Written by Neha Malcom Francis 
+#
+# Entry-type module for generating schema validated TI board
+# configuration binary
+#
+
+import os
+import struct
+import yaml
+
+from collections import OrderedDict
+from jsonschema import validate
+from shutil import copyfileobj
+
+from binman.entry import Entry
+from binman.etype.section import Entry_section
+from dtoc import fdt_util
+from u_boot_pylib import tools
+
+BOARDCFG = 0xB
+BOARDCFG_SEC = 0xD
+BOARDCFG_PM = 0xE
+BOARDCFG_RM = 0xC
+BOARDCFG_NUM_ELEMS = 4
+
+class Entry_ti_board_config(Entry_section):
+"""An entry containing a TI schema validated board config binary
+
+This etype supports generation of two kinds of board configuration
+binaries: singular board config binary as well as combined board config
+binary.
+
+Properties / Entry arguments:
+- config-file: File containing board configuration data in YAML
+- schema-file: File containing board configuration YAML schema against
+  which the config file is validated
+
+Output files:
+- board config binary: File containing board configuration binary
+
+These above parameters are used only when the generated binary is
+intended to be a single board configuration binary. Example::
+
+my-ti-board-config {
+ti-board-config {
+config = "board-config.yaml";
+schema = "schema.yaml";
+};
+};
+
+  

[PATCH v7 00/23] Migration to using binman for bootloader

2023-07-14 Thread Neha Malcom Francis
This series aims to eliminate the use of additional custom repositories
such as k3-image-gen (K3 Image Generation) repo and core-secdev-k3 (K3
Security Development Tools) that was plumbed into the U-Boot build flow
to generate boot images for TI K3 platform devices. And instead, we move
towards using binman that aligns better with the community standard build
flow.

This series uses binman for all K3 platforms supported on U-Boot currently;
both HS (High Security, both SE and FS) and GP (General Purpose) devices.

Background on using k3-image-gen:
* TI K3 devices require a SYSFW (System Firmware) image consisting
of a signed system firmware image and board configuration binaries,
this is needed to bring up system firmware during U-Boot R5 SPL
startup.
* Board configuration data contain board-specific information
such as resource management, power management and security.

Background on using core-secdev-k3:
* Contains resources to sign x509 certificates for HS devices

Series intends to use binman to take over the packaging and signing for
the R5 bootloader images tiboot3.bin (and sysfw.itb, for non-combined
boot flow) instead of k3-image-gen.

Series also packages the A72/A53 bootloader images (tispl.bin and
u-boot.img) using ATF, OPTEE and DM (Device Manager)

Changes in v7:
- corrected Texas Instruments copyright year
- k3-am65-iot2050 image fit@0x18 filename retained as
  tispl.bin

Changes in v6:
- addressed whitespace warnings
- added testcase for overwriting symlink functionality
- %s/Arm Trusted Firmware/Trusted Firmware-A
- %s/tee-pager_v2.bin/tee-raw.bin

Changes in v5:
- updated all board configurations to latest
- changed output binary filenames
- fixed multiple certificate generation leading to packaging
  inconsistency in ti-secure*.py
- added patch to overwrite symlink if exists, patch 21/23
  ("binman: Overwrite symlink if it already exists")

Changes in v4:
- added support for iot2050
- documentation fixes
- move to using self.Raise in ti-board-config etype
- introduced common k3-binman.dtsi (further reduction in code
  duplication can be targeted, this as first step)

Changes in v3:
- added support for HS-FS devices
- added support for AM68-sk
- added back dropped documentation patch
- changed prefix for SYSFW and DM files to expected directory
  name
- extended test coverage to 100%
- documentation fixes
- corrected formatting changes

Changes in v2:
- removed all external scripts
- created ti-board-config etype to support generation of board
  config binaries
- created ti-secure and ti-secure-rom etypes to handle signing
  instead of using external TI_SECURE_DEV_PKG
- updated openssl btool to support x509 certificate generation
- dropped Makefile changes to obtain external binary components,
  moving to using BINMAN_INDIRS to achieve the same

CI/CD passes 100% (series based on -next) [1]

v1: 
https://patchwork.ozlabs.org/project/uboot/cover/20230120101903.179959-1-n-fran...@ti.com/
v2: 
https://patchwork.ozlabs.org/project/uboot/cover/20230404121342.446935-1-n-fran...@ti.com/
v3: 
https://patchwork.ozlabs.org/project/uboot/cover/20230421123203.1315330-1-n-fran...@ti.com/
 
v4: 
https://patchwork.ozlabs.org/project/uboot/cover/20230518142713.184164-1-n-fran...@ti.com/
v5: 
https://patchwork.ozlabs.org/project/uboot/cover/20230707123450.30329-1-n-fran...@ti.com/
v6: 
https://patchwork.ozlabs.org/project/uboot/cover/20230712183453.7623-1-n-fran...@ti.com/

[1] https://github.com/u-boot/u-boot/pull/363

Andrew Davis (1):
  binman: Overwrite symlink if it already exists

Neha Malcom Francis (20):
  binman: ti-board-config: Add support for TI board config binaries
  binman: ti-secure: Add support for TI signing
  arm: dts: k3: Add support for packaging sysfw.itb and tiboot3.bin
  j721e: schema: yaml: Add general schema and J721E board config files
  j721e: dts: binman: Package tiboot3.bin, sysfw.itb, tispl.bin,
u-boot.img
  j7200: yaml: Add J7200 board config files
  j7200: dts: binman: Package tiboot3.bin, tispl.bin, u-boot.img
  am65x: yaml: Add AM65x board config files
  am65: dts: binman: Package tiboot3.bin, sysfw.itb, tispl.bin,
u-boot.img
  am64x: yaml: Add board configs for AM64x
  am64x: dts: binman: Package tiboot3.bin, tispl.bin u-boot.img
  j721s2: yaml: Add board configs for J721S2
  j721s2: dts: binman: Package tiboot3.bin, tispl.bin and u-boot.img
  am62: yaml: Add board configs for AM62
  am625: dts: binman: Package tiboot3.bin, tispl.bin and u-boot.img
  am62a: yaml: Add board configs for AM62ax
  am62a: dts: binman: Package tiboot3.bin, tispl.bin, u-boot.img
  arm: k3-am65x-iot2050: Use binman for tispl.bin for iot2050
  k3: tools: 

Re: [PATCH v2 1/6] efi_loader: add RAM disk device path

2023-07-14 Thread Heinrich Schuchardt

On 14.07.23 07:44, Masahisa Kojima wrote:

This is a preparation to add the EFI_RAM_DISK_PROTOCOL.
This commit adds the RAM disk device path structure
and text conversion to Device Path to Text Protocol.

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

  include/efi_api.h| 19 +++
  lib/efi_loader/efi_device_path_to_text.c | 14 ++
  2 files changed, 33 insertions(+)

diff --git a/include/efi_api.h b/include/efi_api.h
index 55a4c989fc..4ee4a1b5e9 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -682,6 +682,7 @@ struct efi_device_path_uri {
  #  define DEVICE_PATH_SUB_TYPE_CDROM_PATH 0x02
  #  define DEVICE_PATH_SUB_TYPE_VENDOR_PATH0x03
  #  define DEVICE_PATH_SUB_TYPE_FILE_PATH  0x04
+#  define DEVICE_PATH_SUB_TYPE_RAM_DISK_PATH   0x09

  struct efi_device_path_hard_drive_path {
struct efi_device_path dp;
@@ -705,6 +706,24 @@ struct efi_device_path_file_path {
u16 str[];
  } __packed;

+/* This GUID defines a RAM Disk supporting a raw disk format in volatile 
memory */
+#define EFI_VIRTUAL_DISK_GUID \
+   EFI_GUID(0x77ab535a, 0x45fc, 0x624b, \
+   0x55, 0x60, 0xf7, 0xb2, 0x81, 0xd1, 0xf9, 0x6e)
+
+/* This GUID defines a RAM Disk supporting an ISO image in volatile memory */
+#define EFI_VIRTUAL_CD_GUID \
+   EFI_GUID(0x3d5abd30, 0x4175, 0x87ce, \
+0x6d, 0x64, 0xd2, 0xad, 0xe5, 0x23, 0xc4, 0xbb)
+
+struct efi_device_path_ram_disk_path {
+   struct efi_device_path dp;
+   u64 starting_address;
+   u64 ending_address;
+   efi_guid_t disk_type_guid;
+   u16 disk_instance;
+} __packed;
+
  #define EFI_BLOCK_IO_PROTOCOL_GUID \
EFI_GUID(0x964e5b21, 0x6459, 0x11d2, \
 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
diff --git a/lib/efi_loader/efi_device_path_to_text.c 
b/lib/efi_loader/efi_device_path_to_text.c
index 8c76d8be60..4395e79f33 100644
--- a/lib/efi_loader/efi_device_path_to_text.c
+++ b/lib/efi_loader/efi_device_path_to_text.c
@@ -324,6 +324,20 @@ static char *dp_media(char *s, struct efi_device_path *dp)
free(buffer);
break;
}
+   case DEVICE_PATH_SUB_TYPE_RAM_DISK_PATH: {
+   struct efi_device_path_ram_disk_path *rddp =
+   (struct efi_device_path_ram_disk_path *)dp;
+   u64 start;
+   u64 end;
+
+   /* Copy from packed structure to aligned memory */
+   memcpy(, >starting_address, sizeof(start));
+   memcpy(, >ending_address, sizeof(end));
+
+   s += sprintf(s, "RamDisk(0x%llx,%llx,%pUl,0x%x)", start, end,
+>disk_type_guid, rddp->disk_instance);


If there is no alignment guarantee for starting_address, then the same
is true for disk_instance which may spread over two u64 blocks.

In case of DEVICE_PATH_SUB_TYPE_MEMORY we don't use memcpy() to align u64.

I don't think we call device_path_to_text before allow_unaligned().

There is a family of functions like get_unaligned_le64() if we should
ever need to a align a value. Or we could copy the whole device path node.

Best regards

Heinrich


+   break;
+   }
default:
s = dp_unknown(s, dp);
break;




[PATCH 1/2] Revert "lib: string: Fix strlcpy return value", fix callers

2023-07-14 Thread Matthias Schiffer
Both the Linux kernel and libbsd agree that strlcpy() should always
return strlen(src) and not include the NUL termination. The incorrect
U-Boot implementation makes it impossible to check the return value for
truncation, and breaks code written with the usual implementation in
mind (for example, fdtdec_add_reserved_memory() was subtly broken).

I reviewed all callers of strlcpy() and strlcat() and fixed them
according to my understanding of the intended function.

This reverts commit d3358ecc54be0bc3b4dd11f7a63eab0a2842f772 and adds
related fixes.

Fixes: d3358ecc54be ("lib: string: Fix strlcpy return value")
Signed-off-by: Matthias Schiffer 
---
 board/amlogic/vim3/vim3.c|  6 +++---
 drivers/fastboot/fb_getvar.c |  2 +-
 lib/string.c | 14 +++---
 test/lib/strlcat.c   |  4 ++--
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/board/amlogic/vim3/vim3.c b/board/amlogic/vim3/vim3.c
index fcd60ab1e05..8bdfb302f72 100644
--- a/board/amlogic/vim3/vim3.c
+++ b/board/amlogic/vim3/vim3.c
@@ -104,8 +104,8 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
}
 
/* Update PHY names (mandatory to disable USB3.0) */
-   len = strlcpy(data, "usb2-phy0", 32);
-   len += strlcpy([len], "usb2-phy1", 32 - len);
+   len = strlcpy(data, "usb2-phy0", 32) + 1;
+   len += strlcpy([len], "usb2-phy1", 32 - len) + 1;
ret = fdt_setprop(blob, node, "phy-names", data, len);
if (ret < 0) {
printf("vim3: failed to update usb phy names property 
(%d)\n", ret);
@@ -132,7 +132,7 @@ int meson_ft_board_setup(void *blob, struct bd_info *bd)
}
 
/* Enable PCIe */
-   len = strlcpy(data, "okay", 32);
+   len = strlcpy(data, "okay", 32) + 1;
ret = fdt_setprop(blob, node, "status", data, len);
if (ret < 0) {
printf("vim3: failed to enable pcie node (%d)\n", ret);
diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
index dd3475e0a8b..d9f0f07b2bc 100644
--- a/drivers/fastboot/fb_getvar.c
+++ b/drivers/fastboot/fb_getvar.c
@@ -183,7 +183,7 @@ static void __maybe_unused getvar_has_slot(char *part_name, 
char *response)
 
/* part_name_wslot = part_name + "_a" */
len = strlcpy(part_name_wslot, part_name, PART_NAME_LEN - 3);
-   if (len > PART_NAME_LEN - 3)
+   if (len >= PART_NAME_LEN - 3)
goto fail;
strcat(part_name_wslot, "_a");
 
diff --git a/lib/string.c b/lib/string.c
index ecea755f405..f2c61471288 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -116,20 +116,18 @@ char * strncpy(char * dest,const char *src,size_t count)
  * of course, the buffer size is zero). It does not pad
  * out the result like strncpy() does.
  *
- * Return: the number of bytes copied
+ * Return: strlen(src)
  */
 size_t strlcpy(char *dest, const char *src, size_t size)
 {
-   if (size) {
-   size_t srclen = strlen(src);
-   size_t len = (srclen >= size) ? size - 1 : srclen;
+   size_t ret = strlen(src);
 
+   if (size) {
+   size_t len = (ret >= size) ? size - 1 : ret;
memcpy(dest, src, len);
dest[len] = '\0';
-   return len + 1;
}
-
-   return 0;
+   return ret;
 }
 #endif
 
@@ -191,6 +189,8 @@ char * strncat(char *dest, const char *src, size_t count)
  * Compatible with *BSD: the result is always a valid NUL-terminated string 
that
  * fits in the buffer (unless, of course, the buffer size is zero). It does not
  * write past @size like strncat() does.
+ *
+ * Return: min(strlen(dest), size) + strlen(src)
  */
 size_t strlcat(char *dest, const char *src, size_t size)
 {
diff --git a/test/lib/strlcat.c b/test/lib/strlcat.c
index a0ec037388b..d8453fe78e2 100644
--- a/test/lib/strlcat.c
+++ b/test/lib/strlcat.c
@@ -43,11 +43,11 @@ static int do_test_strlcat(struct unit_test_state *uts, int 
line, size_t align1,
s2[i] = 32 + 23 * i % (127 - 32);
s2[len2 - 1] = '\0';
 
-   expected = len2 < n ? min(len1 + len2 - 1, n) : n;
+   expected = min(strlen(s2), n) + strlen(s1);
actual = strlcat(s2, s1, n);
if (expected != actual) {
ut_failf(uts, __FILE__, line, __func__,
-"strlcat(s2, s1, 2) == len2 < n ? min(len1 + len2, n) 
: n",
+"strlcat(s2, s1, n) == min(len2, n) + len1",
 "Expected %#zx (%zd), got %#zx (%zd)",
 expected, expected, actual, actual);
return CMD_RET_FAILURE;
-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/



[PATCH 2/2] lib/charset: fix u16_strlcat() return value

2023-07-14 Thread Matthias Schiffer
strlcat returns min(strlen(dest), count)+strlen(src). Make u16_strlcat's
behaviour the same for consistency.

Fixes: eca08ce94ceb ("lib/charset: add u16_strlcat() function")
Signed-off-by: Matthias Schiffer 
---
 lib/charset.c | 8 
 test/unicode_ut.c | 8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/charset.c b/lib/charset.c
index b1842755eb1..5e4c4f948a4 100644
--- a/lib/charset.c
+++ b/lib/charset.c
@@ -444,14 +444,14 @@ u16 *u16_strdup(const void *src)
 
 size_t u16_strlcat(u16 *dest, const u16 *src, size_t count)
 {
-   size_t destlen = u16_strlen(dest);
+   size_t destlen = u16_strnlen(dest, count);
size_t srclen = u16_strlen(src);
-   size_t ret = destlen + srclen + 1;
+   size_t ret = destlen + srclen;
 
if (destlen >= count)
return ret;
-   if (ret > count)
-   srclen -= ret - count;
+   if (ret >= count)
+   srclen -= (ret - count + 1);
memcpy([destlen], src, 2 * srclen);
dest[destlen + srclen] = 0x;
 
diff --git a/test/unicode_ut.c b/test/unicode_ut.c
index b27d7116b9e..a9356e2b60d 100644
--- a/test/unicode_ut.c
+++ b/test/unicode_ut.c
@@ -808,12 +808,12 @@ static int unicode_test_u16_strlcat(struct 
unit_test_state *uts)
/* dest and src are empty string */
memset(buf, 0, sizeof(buf));
ret = u16_strlcat(buf, _src, sizeof(buf));
-   ut_asserteq(1, ret);
+   ut_asserteq(0, ret);
 
/* dest is empty string */
memset(buf, 0, sizeof(buf));
ret = u16_strlcat(buf, src, sizeof(buf));
-   ut_asserteq(5, ret);
+   ut_asserteq(4, ret);
ut_assert(!unicode_test_u16_strcmp(buf, src, 40));
 
/* src is empty string */
@@ -821,14 +821,14 @@ static int unicode_test_u16_strlcat(struct 
unit_test_state *uts)
buf[39] = 0;
memcpy(buf, dest, sizeof(dest));
ret = u16_strlcat(buf, _src, sizeof(buf));
-   ut_asserteq(6, ret);
+   ut_asserteq(5, ret);
ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
 
for (i = 0; i <= 40; i++) {
memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
buf[39] = 0;
memcpy(buf, dest, sizeof(dest));
-   expected = 10;
+   expected = min(5, i) + 4;
ret = u16_strlcat(buf, src, i);
ut_asserteq(expected, ret);
if (i <= 6) {
-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/



  1   2   >