RE: [PATCH] Revert "mmc: sdhci: set to INT_DATA_END when there are data"

2021-03-17 Thread Andy.Wu
Reviewed-by: Andy Wu 

Best Regards
Andy Wu

> -Original Message-
> From: U-Boot  On Behalf Of
> yuezhang...@sony.com
> Sent: Wednesday, March 17, 2021 2:45 PM
> To: u-boot@lists.denx.de
> Cc: peng@nxp.com; pa...@antoniou-consulting.com
> Subject: [PATCH] Revert "mmc: sdhci: set to INT_DATA_END when there are
> data"
> 
> This reverts commit 17ea3c862865c0d704646f67dbf8412f9ff54f59.
> 
> In eMMC specification, for the response-with-busy(R1b, R5b) command, the
> DAT0 will driven to LOW as BUSY status, and in sdhci specification, the 
> transfer
> complete bit should be wait for BUSY status de-assert.
> 
> All response-with-busy commands don't contain data, the data judgement is no
> need.
> 
> Signed-off-by: Yuezhang.Mo 
> ---
>  drivers/mmc/sdhci.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index
> d9ab6a0a83..8568f65b18 100644
> --- a/drivers/mmc/sdhci.c
> +++ b/drivers/mmc/sdhci.c
> @@ -258,8 +258,7 @@ static int sdhci_send_command(struct mmc *mmc,
> struct mmc_cmd *cmd,
>   flags = SDHCI_CMD_RESP_LONG;
>   else if (cmd->resp_type & MMC_RSP_BUSY) {
>   flags = SDHCI_CMD_RESP_SHORT_BUSY;
> - if (data)
> - mask |= SDHCI_INT_DATA_END;
> + mask |= SDHCI_INT_DATA_END;
>   } else
>   flags = SDHCI_CMD_RESP_SHORT;
> 
> --
> 2.25.1


Re: [PATCH 3/6 v3] efi_loader: Add helper functions for EFI

2021-03-17 Thread Heinrich Schuchardt

On 3/14/21 8:05 PM, Ilias Apalodimas wrote:

A following patch introduces a different logic for loading initrd's
based on the EFI_LOAD_FILE2_PROTOCOL.
Since similar logic can be applied in the future for other system files
(i.e DTBs), let's add some helper functions which will retrieve and
parse file paths stored in EFI variables.

Signed-off-by: Ilias Apalodimas 
---
  include/efi_loader.h|  7 +++
  lib/efi_loader/Makefile |  1 +
  lib/efi_loader/efi_file.c   | 39 +
  lib/efi_loader/efi_helper.c | 98 +
  lib/efi_loader/efi_var_common.c | 33 +++
  5 files changed, 178 insertions(+)
  create mode 100644 lib/efi_loader/efi_helper.c

diff --git a/include/efi_loader.h b/include/efi_loader.h
index eb11a8c7d4b1..25302628d8a8 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -552,6 +552,11 @@ struct efi_simple_file_system_protocol 
*efi_simple_file_system(
  /* open file from device-path: */
  struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);

+efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size);
+
+/* get a device path from a Boot option */
+struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid);
+
  /**
   * efi_size_in_pages() - convert size in bytes to size in pages
   *
@@ -717,6 +722,8 @@ efi_status_t EFIAPI efi_query_variable_info(
u64 *remaining_variable_storage_size,
u64 *maximum_variable_size);

+void *efi_get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size);
+
  /*
   * See section 3.1.3 in the v2.7 UEFI spec for more details on
   * the layout of EFI_LOAD_OPTION.  In short it is:
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 10b42e8847bf..da2741adecfa 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -23,6 +23,7 @@ endif
  obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
  obj-$(CONFIG_CMD_BOOTEFI_BOOTMGR) += efi_bootmgr.o
  obj-y += efi_boottime.o
+obj-y += efi_helper.o
  obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
  obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_firmware.o
  obj-y += efi_console.o
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index 8ece8e71ee1c..bebcb520272a 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -409,6 +409,45 @@ static efi_status_t efi_get_file_size(struct file_handle 
*fh,
return EFI_SUCCESS;
  }

+/**
+ * efi_file_size() - Get the size of a file using an EFI file handle
+ *
+ * @handle:EFI file handle
+ * @size:  buffer to fill in the discovered size
+ *


'make htmldocs' fails to build.

./lib/efi_loader/efi_file.c:421: warning: Function parameter or member
'fh' not described in 'efi_file_size'
./lib/efi_loader/efi_file.c:421: warning: Excess function parameter
'handle' description in 'efi_file_size'

Best regards

Heinrich


+ * Return: size of the file
+ */
+efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size)
+{
+   struct efi_file_info *info = NULL;
+   efi_uintn_t bs = 0;
+   efi_status_t ret;
+
+   *size = 0;
+   ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs,
+  info));
+   if (ret != EFI_BUFFER_TOO_SMALL) {
+   ret = EFI_DEVICE_ERROR;
+   goto out;
+   }
+
+   info = malloc(bs);
+   if (!info) {
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
+   ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs,
+  info));
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   *size = info->file_size;
+
+out:
+   free(info);
+   return ret;
+}
+
  static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size,
void *buffer)
  {
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
new file mode 100644
index ..d03a7364615e
--- /dev/null
+++ b/lib/efi_loader/efi_helper.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Linaro Limited
+ */
+
+#define LOG_CATEGORY LOGC_EFI
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * efi_create_current_boot_var() - Return Boot name were  is replaced 
by
+ *the value of BootCurrent
+ *
+ * @var_name:  variable name
+ * @var_name_size: size of var_name
+ *
+ * Return: Status code
+ */
+static efi_status_t efi_create_current_boot_var(u16 var_name[],
+   size_t var_name_size)
+{
+   efi_uintn_t boot_current_size;
+   efi_status_t ret;
+   u16 boot_current;
+   u16 *pos;
+
+   boot_current_size = sizeof(boot_current);
+   ret = efi_get_variable_int(L"BootCurrent",
+  &efi_global_variable_guid

Re: [PATCH v2 15/21] doc: Move UEFI under develop/

2021-03-17 Thread Heinrich Schuchardt

On 3/15/21 8:26 AM, Simon Glass wrote:

Much of the content here is useful only for development. Move it under
that section.


If I apply only this patch:

doc/arch/x86.rst:712:unknown document: ../uefi/u-boot_on_efi

I cannot find any change to x86.rst in the cover letter of your series.

To ease bisecting the change in doc/arch/x86.rst should be in this patch.

Best regards

Heinrich



Signed-off-by: Simon Glass 
---

Changes in v2:
- Move UEFI under develop/ instead

  doc/develop/index.rst|  1 +
  doc/{ => develop}/uefi/index.rst |  4 
  doc/{ => develop}/uefi/iscsi.rst |  0
  doc/{ => develop}/uefi/u-boot_on_efi.rst |  0
  doc/{ => develop}/uefi/uefi.rst  |  0
  doc/index.rst| 12 
  6 files changed, 5 insertions(+), 12 deletions(-)
  rename doc/{ => develop}/uefi/index.rst (51%)
  rename doc/{ => develop}/uefi/iscsi.rst (100%)
  rename doc/{ => develop}/uefi/u-boot_on_efi.rst (100%)
  rename doc/{ => develop}/uefi/uefi.rst (100%)

diff --git a/doc/develop/index.rst b/doc/develop/index.rst
index 41c0ba1ebd9..84914bb47bf 100644
--- a/doc/develop/index.rst
+++ b/doc/develop/index.rst
@@ -13,6 +13,7 @@ Implementation
 global_data
 logging
 menus
+   uefi/index
 version

  Debugging
diff --git a/doc/uefi/index.rst b/doc/develop/uefi/index.rst
similarity index 51%
rename from doc/uefi/index.rst
rename to doc/develop/uefi/index.rst
index b790a91f174..7e65dbc5d5e 100644
--- a/doc/uefi/index.rst
+++ b/doc/develop/uefi/index.rst
@@ -3,6 +3,10 @@
  Unified Extensible Firmware (UEFI)
  ==

+U-Boot provides an implementation of the UEFI API allowing to run UEFI
+compliant software like Linux, GRUB, and iPXE. Furthermore U-Boot itself
+can be run an UEFI payload.
+
  .. toctree::
 :maxdepth: 2

diff --git a/doc/uefi/iscsi.rst b/doc/develop/uefi/iscsi.rst
similarity index 100%
rename from doc/uefi/iscsi.rst
rename to doc/develop/uefi/iscsi.rst
diff --git a/doc/uefi/u-boot_on_efi.rst b/doc/develop/uefi/u-boot_on_efi.rst
similarity index 100%
rename from doc/uefi/u-boot_on_efi.rst
rename to doc/develop/uefi/u-boot_on_efi.rst
diff --git a/doc/uefi/uefi.rst b/doc/develop/uefi/uefi.rst
similarity index 100%
rename from doc/uefi/uefi.rst
rename to doc/develop/uefi/uefi.rst
diff --git a/doc/index.rst b/doc/index.rst
index 4c44955d67f..366963813ac 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -38,18 +38,6 @@ want to contribute to U-Boot.

 develop/index

-Unified Extensible Firmware (UEFI)
---
-
-U-Boot provides an implementation of the UEFI API allowing to run UEFI
-compliant software like Linux, GRUB, and iPXE. Furthermore U-Boot itself
-can be run an UEFI payload.
-
-.. toctree::
-   :maxdepth: 2
-
-   uefi/index
-
  Driver-Model documentation
  --






[PATCH] spi: xilinx_spi: Trivial fixes in axi qspi driver

2021-03-17 Thread Michal Simek
From: T Karthik Reddy 

Use __func__ instead for function name in debug.
Use Linux style u32 instead of uint32_t.

Signed-off-by: T Karthik Reddy 
Acked-by: Ashok Reddy Soma 
Signed-off-by: Michal Simek 
---

 drivers/spi/xilinx_spi.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
index 0274afdc6e0d..b892cdae9bab 100644
--- a/drivers/spi/xilinx_spi.c
+++ b/drivers/spi/xilinx_spi.c
@@ -314,8 +314,7 @@ static int xilinx_spi_set_speed(struct udevice *bus, uint 
speed)
 
priv->freq = speed;
 
-   debug("xilinx_spi_set_speed: regs=%p, speed=%d\n", priv->regs,
- priv->freq);
+   debug("%s: regs=%p, speed=%d\n", __func__, priv->regs, priv->freq);
 
return 0;
 }
@@ -324,7 +323,7 @@ static int xilinx_spi_set_mode(struct udevice *bus, uint 
mode)
 {
struct xilinx_spi_priv *priv = dev_get_priv(bus);
struct xilinx_spi_regs *regs = priv->regs;
-   uint32_t spicr;
+   u32 spicr;
 
spicr = readl(®s->spicr);
if (mode & SPI_LSB_FIRST)
@@ -339,8 +338,7 @@ static int xilinx_spi_set_mode(struct udevice *bus, uint 
mode)
writel(spicr, ®s->spicr);
priv->mode = mode;
 
-   debug("xilinx_spi_set_mode: regs=%p, mode=%d\n", priv->regs,
- priv->mode);
+   debug("%s: regs=%p, mode=%d\n", __func__, priv->regs, priv->mode);
 
return 0;
 }
-- 
2.30.1



[PATCH] spi: spi-uclass: Add support to manually relocate spi memory ops

2021-03-17 Thread Michal Simek
From: T Karthik Reddy 

Add spi memory operations to relocate manually when
CONFIG_NEEDS_MANUAL_RELOC is enabled.

Signed-off-by: T Karthik Reddy 
Acked-by: Ashok Reddy Soma 
Signed-off-by: Michal Simek 
---

 drivers/spi/spi-uclass.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 7155d4aebd6d..e24a0ff9544b 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -182,6 +183,8 @@ static int spi_post_probe(struct udevice *bus)
 #endif
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
struct dm_spi_ops *ops = spi_get_ops(bus);
+   struct spi_controller_mem_ops *mem_ops =
+   (struct spi_controller_mem_ops *)ops->mem_ops;
static int reloc_done;
 
if (!reloc_done) {
@@ -199,6 +202,12 @@ static int spi_post_probe(struct udevice *bus)
ops->set_mode += gd->reloc_off;
if (ops->cs_info)
ops->cs_info += gd->reloc_off;
+   if (mem_ops->adjust_op_size)
+   mem_ops->adjust_op_size += gd->reloc_off;
+   if (mem_ops->supports_op)
+   mem_ops->supports_op += gd->reloc_off;
+   if (mem_ops->exec_op)
+   mem_ops->exec_op += gd->reloc_off;
reloc_done++;
}
 #endif
-- 
2.30.1



Re: [PATCH v2] riscv: sifive: Rename fu540 board to unleashed

2021-03-17 Thread Leo Liang
On Wed, Mar 17, 2021 at 11:10:58AM +0800, Bin Meng wrote:
> In preparation to add SiFive Unmatched board support, let's rename
> the existing fu540 board to unleashed.
> 
> Signed-off-by: Bin Meng 
> 
> ---
> 
> Changes in v2:
> - fix a typo in the commit message
> - rename fu540.rst
> 
>  arch/riscv/Kconfig |  6 +++---
>  arch/riscv/dts/Makefile|  2 +-
>  board/sifive/{fu540 => unleashed}/Kconfig  |  6 +++---
>  board/sifive/{fu540 => unleashed}/MAINTAINERS  | 10 +-
>  board/sifive/{fu540 => unleashed}/Makefile |  2 +-
>  board/sifive/{fu540 => unleashed}/spl.c|  0
>  board/sifive/{fu540/fu540.c => unleashed/unleashed.c}  |  0
>  common/spl/Kconfig |  5 +++--
>  ...five_fu540_defconfig => sifive_unleashed_defconfig} |  2 +-
>  doc/board/sifive/index.rst |  2 +-
>  doc/board/sifive/{fu540.rst => unleashed.rst}  |  0
>  drivers/ram/sifive/Kconfig |  2 +-
>  drivers/reset/Kconfig  |  2 +-
>  include/configs/{sifive-fu540.h => sifive-unleashed.h} |  0
>  14 files changed, 20 insertions(+), 19 deletions(-)
>  rename board/sifive/{fu540 => unleashed}/Kconfig (91%)
>  rename board/sifive/{fu540 => unleashed}/MAINTAINERS (50%)
>  rename board/sifive/{fu540 => unleashed}/Makefile (87%)
>  rename board/sifive/{fu540 => unleashed}/spl.c (100%)
>  rename board/sifive/{fu540/fu540.c => unleashed/unleashed.c} (100%)
>  rename configs/{sifive_fu540_defconfig => sifive_unleashed_defconfig} (95%)
>  rename doc/board/sifive/{fu540.rst => unleashed.rst} (100%)
>  rename include/configs/{sifive-fu540.h => sifive-unleashed.h} (100%)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 55eaee2da6..e8494c2a49 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -17,8 +17,8 @@ config TARGET_MICROCHIP_ICICLE
>  config TARGET_QEMU_VIRT
>   bool "Support QEMU Virt Board"
>  
> -config TARGET_SIFIVE_FU540
> - bool "Support SiFive FU540 Board"
> +config TARGET_SIFIVE_UNLEASHED
> + bool "Support SiFive Unleashed Board"
>  
>  config TARGET_SIPEED_MAIX
>   bool "Support Sipeed Maix Board"
> @@ -55,7 +55,7 @@ config SPL_SYS_DCACHE_OFF
>  source "board/AndesTech/ax25-ae350/Kconfig"
>  source "board/emulation/qemu-riscv/Kconfig"
>  source "board/microchip/mpfs_icicle/Kconfig"
> -source "board/sifive/fu540/Kconfig"
> +source "board/sifive/unleashed/Kconfig"
>  source "board/sipeed/maix/Kconfig"
>  
>  # platform-specific options below
> diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
> index 01331b0aa1..8138d89d84 100644
> --- a/arch/riscv/dts/Makefile
> +++ b/arch/riscv/dts/Makefile
> @@ -1,7 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0+
>  
>  dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
> -dtb-$(CONFIG_TARGET_SIFIVE_FU540) += hifive-unleashed-a00.dtb
> +dtb-$(CONFIG_TARGET_SIFIVE_UNLEASHED) += hifive-unleashed-a00.dtb
>  dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
>  dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-mpfs-icicle-kit.dtb
>  
> diff --git a/board/sifive/fu540/Kconfig b/board/sifive/unleashed/Kconfig
> similarity index 91%
> rename from board/sifive/fu540/Kconfig
> rename to board/sifive/unleashed/Kconfig
> index 64fdbd44b4..dbffd59c98 100644
> --- a/board/sifive/fu540/Kconfig
> +++ b/board/sifive/unleashed/Kconfig
> @@ -1,7 +1,7 @@
> -if TARGET_SIFIVE_FU540
> +if TARGET_SIFIVE_UNLEASHED
>  
>  config SYS_BOARD
> - default "fu540"
> + default "unleashed"
>  
>  config SYS_VENDOR
>   default "sifive"
> @@ -10,7 +10,7 @@ config SYS_CPU
>   default "fu540"
>  
>  config SYS_CONFIG_NAME
> - default "sifive-fu540"
> + default "sifive-unleashed"
>  
>  config SYS_TEXT_BASE
>   default 0x8020 if SPL
> diff --git a/board/sifive/fu540/MAINTAINERS 
> b/board/sifive/unleashed/MAINTAINERS
> similarity index 50%
> rename from board/sifive/fu540/MAINTAINERS
> rename to board/sifive/unleashed/MAINTAINERS
> index 27620727bd..2ea00749cb 100644
> --- a/board/sifive/fu540/MAINTAINERS
> +++ b/board/sifive/unleashed/MAINTAINERS
> @@ -1,10 +1,10 @@
> -SiFive FU540 BOARD
> +SiFive HiFive Unleashed BOARD
>  M:   Paul Walmsley 
>  M:   Palmer Dabbelt 
>  M:   Anup Patel 
>  M:   Atish Patra 
>  S:   Maintained
> -F:   board/sifive/fu540/
> -F:   doc/board/sifive/fu540.rst
> -F:   include/configs/sifive-fu540.h
> -F:   configs/sifive_fu540_defconfig
> +F:   board/sifive/unleashed/
> +F:   doc/board/sifive/unleashed.rst
> +F:   include/configs/sifive-unleashed.h
> +F:   configs/sifive_unleashed_defconfig
> diff --git a/board/sifive/fu540/Makefile b/board/sifive/unleashed/Makefile
> similarity index 87%
> rename from board/sifive/fu540/Makefile
> rename to board/sifive/unleashed/Makefile
> index b05e2f5807..5821679dd9 100644
> --- a/board/sifive/fu540/Makefile
> +++ b/board/sifive/unle

Re: [PATCH] spi: spi-uclass: Add support to manually relocate spi memory ops

2021-03-17 Thread Pratyush Yadav
On 17/03/21 09:19AM, Michal Simek wrote:
> From: T Karthik Reddy 
> 
> Add spi memory operations to relocate manually when
> CONFIG_NEEDS_MANUAL_RELOC is enabled.
> 
> Signed-off-by: T Karthik Reddy 
> Acked-by: Ashok Reddy Soma 
> Signed-off-by: Michal Simek 
> ---
> 
>  drivers/spi/spi-uclass.c | 9 +
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
> index 7155d4aebd6d..e24a0ff9544b 100644
> --- a/drivers/spi/spi-uclass.c
> +++ b/drivers/spi/spi-uclass.c
> @@ -11,6 +11,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -182,6 +183,8 @@ static int spi_post_probe(struct udevice *bus)
>  #endif
>  #if defined(CONFIG_NEEDS_MANUAL_RELOC)
>   struct dm_spi_ops *ops = spi_get_ops(bus);
> + struct spi_controller_mem_ops *mem_ops =
> + (struct spi_controller_mem_ops *)ops->mem_ops;
>   static int reloc_done;
>  
>   if (!reloc_done) {
> @@ -199,6 +202,12 @@ static int spi_post_probe(struct udevice *bus)
>   ops->set_mode += gd->reloc_off;
>   if (ops->cs_info)
>   ops->cs_info += gd->reloc_off;
> + if (mem_ops->adjust_op_size)
> + mem_ops->adjust_op_size += gd->reloc_off;
> + if (mem_ops->supports_op)
> + mem_ops->supports_op += gd->reloc_off;
> + if (mem_ops->exec_op)
> + mem_ops->exec_op += gd->reloc_off;

The comment above mem_ops says "This field is optional and should only 
be implemented if the controller has native support for memory-like 
operations". So you should do a NULL check before accessing it.

>   reloc_done++;
>   }
>  #endif
> -- 
> 2.30.1
> 

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.


Re: [PATCH] spi: spi-uclass: Add support to manually relocate spi memory ops

2021-03-17 Thread Michal Simek



On 3/17/21 10:12 AM, Pratyush Yadav wrote:
> On 17/03/21 09:19AM, Michal Simek wrote:
>> From: T Karthik Reddy 
>>
>> Add spi memory operations to relocate manually when
>> CONFIG_NEEDS_MANUAL_RELOC is enabled.
>>
>> Signed-off-by: T Karthik Reddy 
>> Acked-by: Ashok Reddy Soma 
>> Signed-off-by: Michal Simek 
>> ---
>>
>>  drivers/spi/spi-uclass.c | 9 +
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
>> index 7155d4aebd6d..e24a0ff9544b 100644
>> --- a/drivers/spi/spi-uclass.c
>> +++ b/drivers/spi/spi-uclass.c
>> @@ -11,6 +11,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -182,6 +183,8 @@ static int spi_post_probe(struct udevice *bus)
>>  #endif
>>  #if defined(CONFIG_NEEDS_MANUAL_RELOC)
>>  struct dm_spi_ops *ops = spi_get_ops(bus);
>> +struct spi_controller_mem_ops *mem_ops =
>> +(struct spi_controller_mem_ops *)ops->mem_ops;
>>  static int reloc_done;
>>  
>>  if (!reloc_done) {
>> @@ -199,6 +202,12 @@ static int spi_post_probe(struct udevice *bus)
>>  ops->set_mode += gd->reloc_off;
>>  if (ops->cs_info)
>>  ops->cs_info += gd->reloc_off;
>> +if (mem_ops->adjust_op_size)
>> +mem_ops->adjust_op_size += gd->reloc_off;
>> +if (mem_ops->supports_op)
>> +mem_ops->supports_op += gd->reloc_off;
>> +if (mem_ops->exec_op)
>> +mem_ops->exec_op += gd->reloc_off;
> 
> The comment above mem_ops says "This field is optional and should only 
> be implemented if the controller has native support for memory-like 
> operations". So you should do a NULL check before accessing it.

Karthik: Can you please take a look and retest?

M


RE: [PATCH] net: gem: Fix setting PCS auto-negotiation statee

2021-03-17 Thread Ashok Reddy Soma
Reviewed-by: Ashok Reddy Soma 

> -Original Message-
> From: Michal Simek 
> Sent: Monday, March 15, 2021 2:38 PM
> To: Robert Hancock ; Michal Simek
> ; T Karthik Reddy ; Ashok Reddy
> Soma 
> Cc: joe.hershber...@ni.com; rfried@gmail.com; u-boot@lists.denx.de
> Subject: Re: [PATCH] net: gem: Fix setting PCS auto-negotiation statee
> 
> 
> 
> On 3/11/21 11:55 PM, Robert Hancock wrote:
> > The code was trying to disable PCS auto-negotiation when a fixed-link
> > node is present and enable it otherwise. However, the PCS registers
> > were being written before the PCSSEL bit was set in the network
> > configuration register, and it appears that in this state, PCS
> > register writes are ignored. The result is that the intended change
> > only took effect on the second network operation that was performed,
> > since at that time PCSSEL is already enabled.
> >
> > Fix the order of register writes so that PCS registers are only
> > written to after the PCS is enabled.
> >
> > Fixes: 26e62cc971 ("net: gem: Disable PCS autonegotiation in case of
> > fixed-link")
> >
> > Signed-off-by: Robert Hancock 
> > ---
> >  drivers/net/zynq_gem.c | 25 +
> >  1 file changed, 17 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c index
> > baf06a2ad8..ff59982267 100644
> > --- a/drivers/net/zynq_gem.c
> > +++ b/drivers/net/zynq_gem.c
> > @@ -454,14 +454,6 @@ static int zynq_gem_init(struct udevice *dev)
> > priv->int_pcs) {
> > nwconfig |= ZYNQ_GEM_NWCFG_SGMII_ENBL |
> > ZYNQ_GEM_NWCFG_PCS_SEL;
> > -#ifdef CONFIG_ARM64
> > -   if (priv->phydev->phy_id != PHY_FIXED_ID)
> > -   writel(readl(®s->pcscntrl) |
> ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
> > -  ®s->pcscntrl);
> > -   else
> > -   writel(readl(®s->pcscntrl) &
> ~ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
> > -  ®s->pcscntrl);
> > -#endif
> > }
> >
> > switch (priv->phydev->speed) {
> > @@ -480,6 +472,23 @@ static int zynq_gem_init(struct udevice *dev)
> > break;
> > }
> >
> > +#ifdef CONFIG_ARM64
> > +   if (priv->interface == PHY_INTERFACE_MODE_SGMII &&
> > +   priv->int_pcs) {
> > +   /*
> > +* Disable AN for fixed link configuration, enable otherwise.
> > +* Must be written after PCS_SEL is set in nwconfig,
> > +* otherwise writes will not take effect.
> > +*/
> > +   if (priv->phydev->phy_id != PHY_FIXED_ID)
> > +   writel(readl(®s->pcscntrl) |
> ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
> > +  ®s->pcscntrl);
> > +   else
> > +   writel(readl(®s->pcscntrl) &
> ~ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
> > +  ®s->pcscntrl);
> > +   }
> > +#endif
> > +
> > ret = clk_set_rate(&priv->tx_clk, clk_rate);
> > if (IS_ERR_VALUE(ret)) {
> > dev_err(dev, "failed to set tx clock rate\n");
> >
> 
> Karthik/Ashok: Please retest it and reply.

Looks good.

> 
> Thanks,
> Michal


[PATCH] smbios: Fix table when no string is present

2021-03-17 Thread matthias . bgg
From: Matthias Brugger 

When no string is present in a table, next_ptr points to the same
location as eos. When calculating the string table length, we would only
reserve one \0. By spec a SMBIOS table has to end with two \0\0 when no
strings a present.

Signed-off-by: Matthias Brugger 

---

 lib/smbios.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/smbios.c b/lib/smbios.c
index 7d463c84a9..d21d37cdac 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -153,7 +153,7 @@ static int smbios_add_prop(struct smbios_ctx *ctx, const 
char *prop)
 static void smbios_set_eos(struct smbios_ctx *ctx, char *eos)
 {
ctx->eos = eos;
-   ctx->next_ptr = eos;
+   ctx->next_ptr = eos + 1;
ctx->last_str = NULL;
 }
 
-- 
2.30.2



[PATCH v2] spi: spi-uclass: Add support to manually relocate spi memory ops

2021-03-17 Thread Michal Simek
From: T Karthik Reddy 

Add spi memory operations to relocate manually when
CONFIG_NEEDS_MANUAL_RELOC is enabled.

Signed-off-by: T Karthik Reddy 
Acked-by: Ashok Reddy Soma 
Signed-off-by: Michal Simek 
---

Changes in v2:
- Check if mem_ops is defined before relocation - reported-by
 Pratyush Yadav 

 drivers/spi/spi-uclass.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 7155d4aebd6d..ee30110b5658 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -199,6 +200,16 @@ static int spi_post_probe(struct udevice *bus)
ops->set_mode += gd->reloc_off;
if (ops->cs_info)
ops->cs_info += gd->reloc_off;
+   if (ops->mem_ops) {
+   struct spi_controller_mem_ops *mem_ops =
+   (struct spi_controller_mem_ops *)ops->mem_ops;
+   if (mem_ops->adjust_op_size)
+   mem_ops->adjust_op_size += gd->reloc_off;
+   if (mem_ops->supports_op)
+   mem_ops->supports_op += gd->reloc_off;
+   if (mem_ops->exec_op)
+   mem_ops->exec_op += gd->reloc_off;
+   }
reloc_done++;
}
 #endif
-- 
2.30.1



Re: [PATCH] net: gem: Fix setting PCS auto-negotiation state

2021-03-17 Thread Michal Simek



On 3/11/21 11:55 PM, Robert Hancock wrote:
> The code was trying to disable PCS auto-negotiation when a fixed-link node
> is present and enable it otherwise. However, the PCS registers were being
> written before the PCSSEL bit was set in the network configuration
> register, and it appears that in this state, PCS register writes are
> ignored. The result is that the intended change only took effect on the
> second network operation that was performed, since at that time PCSSEL is
> already enabled.
> 
> Fix the order of register writes so that PCS registers are only written to
> after the PCS is enabled.
> 
> Fixes: 26e62cc971 ("net: gem: Disable PCS autonegotiation in case of 
> fixed-link")
> 
> Signed-off-by: Robert Hancock 
> ---
>  drivers/net/zynq_gem.c | 25 +
>  1 file changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c
> index baf06a2ad8..ff59982267 100644
> --- a/drivers/net/zynq_gem.c
> +++ b/drivers/net/zynq_gem.c
> @@ -454,14 +454,6 @@ static int zynq_gem_init(struct udevice *dev)
>   priv->int_pcs) {
>   nwconfig |= ZYNQ_GEM_NWCFG_SGMII_ENBL |
>   ZYNQ_GEM_NWCFG_PCS_SEL;
> -#ifdef CONFIG_ARM64
> - if (priv->phydev->phy_id != PHY_FIXED_ID)
> - writel(readl(®s->pcscntrl) | ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
> -®s->pcscntrl);
> - else
> - writel(readl(®s->pcscntrl) & ~ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
> -®s->pcscntrl);
> -#endif
>   }
>  
>   switch (priv->phydev->speed) {
> @@ -480,6 +472,23 @@ static int zynq_gem_init(struct udevice *dev)
>   break;
>   }
>  
> +#ifdef CONFIG_ARM64
> + if (priv->interface == PHY_INTERFACE_MODE_SGMII &&
> + priv->int_pcs) {
> + /*
> +  * Disable AN for fixed link configuration, enable otherwise.
> +  * Must be written after PCS_SEL is set in nwconfig,
> +  * otherwise writes will not take effect.
> +  */
> + if (priv->phydev->phy_id != PHY_FIXED_ID)
> + writel(readl(®s->pcscntrl) | 
> ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
> +®s->pcscntrl);
> + else
> + writel(readl(®s->pcscntrl) & 
> ~ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
> +®s->pcscntrl);
> + }
> +#endif
> +
>   ret = clk_set_rate(&priv->tx_clk, clk_rate);
>   if (IS_ERR_VALUE(ret)) {
>   dev_err(dev, "failed to set tx clock rate\n");
> 

Applied.
M


Re: [PATCH] Avoid delay when inializing USB peripheral by dwc2.c

2021-03-17 Thread Marek Vasut

On 3/17/21 12:51 PM, João Loureiro wrote:

When `usb start` is called, the dwc2 driver will try to start every
USB device as host first, even if it is explicitly configured as
peripheral in the device tree, as the documentation explains (`dr_mode
= "peripheral"`).

So to avoid an unwanted 15 seconds delay when initializing the usb
(one second per channel = 1s x 15), this patch adds a check to the
initialization, and will skip a host initialization of the device,
when it is explicitly set as peripheral. The checking is already done
similarly in the `drivers/usb/gadget/dwc2_udc_otg.c` driver.

An example device tree entry:
&usb0 {
   compatible = "snps,dwc2";
   status = "okay";
   dr_mode = "peripheral";
};


+CC Lukasz.

The patch looks OK, except you need SoB line, see e.g.
https://www.kernel.org/doc/html/v5.10/process/submitting-patches.html

When in doubt, git format-patch -1 -o /tmp the patch and then run 
./scripts/checkpatch.pl /tmp/00*patch on it, this will tell you what to do.



Proposed patch below:
diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index ec643e9f45..c6ade25f53 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -21,6 +21,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 

@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice
*dev, struct dwc2_priv *priv)
  #endif

  dwc_otg_core_init(dev);
-dwc_otg_core_host_init(dev, regs);
+
+if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping host_init.\n",\
+dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+}
+else
+dwc_otg_core_host_init(dev, regs);

  clrsetbits_le32(®s->hprt0, DWC2_HPRT0_PRTENA |
  DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |

---
Excuse me if I missed any detail; That's my first patch to u-boot.




--
Best regards,
Marek Vasut


Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Trevor Woerner
On Mon 2021-03-15 @ 12:07:44 PM, Tom Rini wrote:
> - Once v2021.04 is released I will be pushing a large number of board
>   removals for things that will be then 2 years past their "migrate this
>   by ... or it might be removed" date which is also around 3 years total
>   of notice.

FWIW I'm working on updating the lpc32xx platforms (devkit3250 and work_92105)
to DM. Hopefully I'll get that in sooner rather than later :-)


Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Marek Vasut

On 3/15/21 5:07 PM, Tom Rini wrote:

Hey all,

It's release day, and here's v2021.04-rc4.  Not a whole lot of change
since last time in master, and -next has been and is still open.  I just
want to repeat a few things from -rc3:

- We've moved from "gitlab.denx.de" (and also "git.denx.de") to
   "source.denx.de", please make sure to update your scripts and tools
   and so forth.  If you send me pull requests, now is a good time to
   switch to url/pushurl if you haven't already.
- Once v2021.04 is released I will be pushing a large number of board
   removals for things that will be then 2 years past their "migrate this
   by ... or it might be removed" date which is also around 3 years total
   of notice.


Which ones ?


Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Tom Rini
On Wed, Mar 17, 2021 at 01:13:57PM +0100, Marek Vasut wrote:
> On 3/15/21 5:07 PM, Tom Rini wrote:
> > Hey all,
> > 
> > It's release day, and here's v2021.04-rc4.  Not a whole lot of change
> > since last time in master, and -next has been and is still open.  I just
> > want to repeat a few things from -rc3:
> > 
> > - We've moved from "gitlab.denx.de" (and also "git.denx.de") to
> >"source.denx.de", please make sure to update your scripts and tools
> >and so forth.  If you send me pull requests, now is a good time to
> >switch to url/pushurl if you haven't already.
> > - Once v2021.04 is released I will be pushing a large number of board
> >removals for things that will be then 2 years past their "migrate this
> >by ... or it might be removed" date which is also around 3 years total
> >of notice.
> 
> Which ones ?

All of the ones I've sent out removal patches for over the last month,
CC'ing the maintainers.  That's basically:
https://patchwork.ozlabs.org/project/uboot/list/?series=228850
https://patchwork.ozlabs.org/project/uboot/list/?series=230325
along with I believe I need to v2 dropping some defconfigs for I believe
mx28evk once Stefano picks up Fabio's patch to update and maintain the
main defconfig (he already ack'd such a removal).

-- 
Tom


signature.asc
Description: PGP signature


Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Trevor Woerner
On Wed 2021-03-17 @ 08:55:59 AM, Tom Rini wrote:
> On Wed, Mar 17, 2021 at 01:13:57PM +0100, Marek Vasut wrote:
> > On 3/15/21 5:07 PM, Tom Rini wrote:
> > > Hey all,
> > > 
> > > It's release day, and here's v2021.04-rc4.  Not a whole lot of change
> > > since last time in master, and -next has been and is still open.  I just
> > > want to repeat a few things from -rc3:
> > > 
> > > - We've moved from "gitlab.denx.de" (and also "git.denx.de") to
> > >"source.denx.de", please make sure to update your scripts and tools
> > >and so forth.  If you send me pull requests, now is a good time to
> > >switch to url/pushurl if you haven't already.
> > > - Once v2021.04 is released I will be pushing a large number of board
> > >removals for things that will be then 2 years past their "migrate this
> > >by ... or it might be removed" date which is also around 3 years total
> > >of notice.
> > 
> > Which ones ?
> 
> All of the ones I've sent out removal patches for over the last month,
> CC'ing the maintainers.  That's basically:
> https://patchwork.ozlabs.org/project/uboot/list/?series=228850
> https://patchwork.ozlabs.org/project/uboot/list/?series=230325
> along with I believe I need to v2 dropping some defconfigs for I believe
> mx28evk once Stefano picks up Fabio's patch to update and maintain the
> main defconfig (he already ack'd such a removal).

Ah okay, just DM_MMC for now, so the lpc32xx boards aren't on the block… yet.

However, I am interested in preserving the olimex board (i.e.
configs/mx23_olinuxino_defconfig). So I could take a look at that one first
unless, Marek, you would like to take a look?


Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Tom Rini
On Wed, Mar 17, 2021 at 09:21:45AM -0400, Trevor Woerner wrote:
> On Wed 2021-03-17 @ 08:55:59 AM, Tom Rini wrote:
> > On Wed, Mar 17, 2021 at 01:13:57PM +0100, Marek Vasut wrote:
> > > On 3/15/21 5:07 PM, Tom Rini wrote:
> > > > Hey all,
> > > > 
> > > > It's release day, and here's v2021.04-rc4.  Not a whole lot of change
> > > > since last time in master, and -next has been and is still open.  I just
> > > > want to repeat a few things from -rc3:
> > > > 
> > > > - We've moved from "gitlab.denx.de" (and also "git.denx.de") to
> > > >"source.denx.de", please make sure to update your scripts and tools
> > > >and so forth.  If you send me pull requests, now is a good time to
> > > >switch to url/pushurl if you haven't already.
> > > > - Once v2021.04 is released I will be pushing a large number of board
> > > >removals for things that will be then 2 years past their "migrate 
> > > > this
> > > >by ... or it might be removed" date which is also around 3 years 
> > > > total
> > > >of notice.
> > > 
> > > Which ones ?
> > 
> > All of the ones I've sent out removal patches for over the last month,
> > CC'ing the maintainers.  That's basically:
> > https://patchwork.ozlabs.org/project/uboot/list/?series=228850
> > https://patchwork.ozlabs.org/project/uboot/list/?series=230325
> > along with I believe I need to v2 dropping some defconfigs for I believe
> > mx28evk once Stefano picks up Fabio's patch to update and maintain the
> > main defconfig (he already ack'd such a removal).
> 
> Ah okay, just DM_MMC for now, so the lpc32xx boards aren't on the block… yet.

I would emphasize that yet.  v2021.07 is just around the corner and
marks 3 years of DM_USB being a loud "please migrate me".  We're going
to be hitting that milestone every release in 2021.

> However, I am interested in preserving the olimex board (i.e.
> configs/mx23_olinuxino_defconfig). So I could take a look at that one first
> unless, Marek, you would like to take a look?

https://patchwork.ozlabs.org/project/uboot/patch/20210218233230.506201-2-feste...@gmail.com/
is likely a handy patch to look at for whomever is interested in the
board.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] spi: spi-uclass: Add support to manually relocate spi memory ops

2021-03-17 Thread Pratyush Yadav
On 17/03/21 12:31PM, Michal Simek wrote:
> From: T Karthik Reddy 
> 
> Add spi memory operations to relocate manually when
> CONFIG_NEEDS_MANUAL_RELOC is enabled.
> 
> Signed-off-by: T Karthik Reddy 
> Acked-by: Ashok Reddy Soma 
> Signed-off-by: Michal Simek 

Reviewed-by: Pratyush Yadav 

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.


Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Marek Vasut

On 3/17/21 2:21 PM, Trevor Woerner wrote:

On Wed 2021-03-17 @ 08:55:59 AM, Tom Rini wrote:

On Wed, Mar 17, 2021 at 01:13:57PM +0100, Marek Vasut wrote:

On 3/15/21 5:07 PM, Tom Rini wrote:

Hey all,

It's release day, and here's v2021.04-rc4.  Not a whole lot of change
since last time in master, and -next has been and is still open.  I just
want to repeat a few things from -rc3:

- We've moved from "gitlab.denx.de" (and also "git.denx.de") to
"source.denx.de", please make sure to update your scripts and tools
and so forth.  If you send me pull requests, now is a good time to
switch to url/pushurl if you haven't already.
- Once v2021.04 is released I will be pushing a large number of board
removals for things that will be then 2 years past their "migrate this
by ... or it might be removed" date which is also around 3 years total
of notice.


Which ones ?


All of the ones I've sent out removal patches for over the last month,
CC'ing the maintainers.  That's basically:
https://patchwork.ozlabs.org/project/uboot/list/?series=228850
https://patchwork.ozlabs.org/project/uboot/list/?series=230325
along with I believe I need to v2 dropping some defconfigs for I believe
mx28evk once Stefano picks up Fabio's patch to update and maintain the
main defconfig (he already ack'd such a removal).


Ah okay, just DM_MMC for now, so the lpc32xx boards aren't on the block… yet.

However, I am interested in preserving the olimex board (i.e.
configs/mx23_olinuxino_defconfig). So I could take a look at that one first
unless, Marek, you would like to take a look?


I don't think I have time to do that now, so feel free to dig in.


Re: [PATCH] Avoid delay when initializing USB peripherals by dwc2

2021-03-17 Thread Marek Vasut

On 3/17/21 2:24 PM, João Loureiro wrote:

When `usb start` is called, the dwc2 driver will try to start every
USB device as host first, even if it is explicitly configured as
peripheral in the device tree, as the documentation explains (`dr_mode
= "peripheral"`).

So to avoid an unwanted 15 seconds delay when initializing the usb
(one second per channel = 1s x 15), this patch adds a check to the
initialization, and will skip a host initialization of the device,
when it is explicitly set as peripheral. The checking is already done
similarly in the `drivers/usb/gadget/dwc2_udc_otg.c` driver.

An example device tree entry:
&usb0 {
   compatible = "snps,dwc2";
   status = "okay";
   dr_mode = "peripheral";
};

Signed-off-by: João Loureiro 
---
drivers/usb/host/dwc2.c | 9 -
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index ec643e9f45..7990060f3c 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -21,6 +21,7 @@
#include 
#include 
#include 
+#include 
#include 
#include 
@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice
*dev, struct dwc2_priv *priv)
#endif
dwc_otg_core_init(dev);
- dwc_otg_core_host_init(dev, regs);
+
+ if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+ dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping host_init.\n",\
+ dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+ } else {
+ dwc_otg_core_host_init(dev, regs);
+ }


The patch is corrupted, please use git send-email if possible.


Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Fabio Estevam
Hi Trevor,

On Wed, Mar 17, 2021 at 10:22 AM Trevor Woerner  wrote:

> However, I am interested in preserving the olimex board (i.e.
> configs/mx23_olinuxino_defconfig). So I could take a look at that one first
> unless, Marek, you would like to take a look?

I have recently converted imx23-evk to DM, so hopefully, the imx23
olinuxino transition will be smooth too:
https://source.denx.de/u-boot/u-boot/-/commit/23013aa9619881290dbeb6217f1fab863869050e

I don't have the imx23 olinuxino board handy, but let us know if you
face any issues in the DM conversion.

Cheers


[PATCH] Avoid delay when initializing USB peripherals by dwc2

2021-03-17 Thread João Loureiro
When `usb start` is called, the dwc2 driver will try to start every
USB device as host first, even if it is explicitly configured as
peripheral in the device tree, as the documentation explains (`dr_mode
= "peripheral"`).

So to avoid an unwanted 15 seconds delay when initializing the usb
(one second per channel = 1s x 15), this patch adds a check to the
initialization, and will skip a host initialization of the device,
when it is explicitly set as peripheral. The checking is already done
similarly in the `drivers/usb/gadget/dwc2_udc_otg.c` driver.

An example device tree entry:
&usb0 {
  compatible = "snps,dwc2";
  status = "okay";
  dr_mode = "peripheral";
};

Signed-off-by: João Loureiro 
---
drivers/usb/host/dwc2.c | 9 -
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index ec643e9f45..7990060f3c 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -21,6 +21,7 @@
#include 
#include 
#include 
+#include 
#include 
#include 
@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice
*dev, struct dwc2_priv *priv)
#endif
dwc_otg_core_init(dev);
- dwc_otg_core_host_init(dev, regs);
+
+ if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+ dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping host_init.\n",\
+ dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+ } else {
+ dwc_otg_core_host_init(dev, regs);
+ }
clrsetbits_le32(®s->hprt0, DWC2_HPRT0_PRTENA |
DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |
-- 
2.25.1


Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Trevor Woerner
On Wed, Mar 17, 2021 at 9:37 AM Fabio Estevam  wrote:
>
> Hi Trevor,
>
> On Wed, Mar 17, 2021 at 10:22 AM Trevor Woerner  wrote:
>
> > However, I am interested in preserving the olimex board (i.e.
> > configs/mx23_olinuxino_defconfig). So I could take a look at that one first
> > unless, Marek, you would like to take a look?
>
> I have recently converted imx23-evk to DM, so hopefully, the imx23
> olinuxino transition will be smooth too:
> https://source.denx.de/u-boot/u-boot/-/commit/23013aa9619881290dbeb6217f1fab863869050e
>
> I don't have the imx23 olinuxino board handy, but let us know if you
> face any issues in the DM conversion.

Okay, I have the -maxi so I'll get on that conversion.

Thanks!


Re: [PATCH v2 8/8] drivers: net: macb: add fu740 support

2021-03-17 Thread David Abdurachmanov
On Tue, Mar 16, 2021 at 6:35 PM Green Wan  wrote:
>
> From: David Abdurachmanov 
>
> Add fu740 support to macb ethernet driver
>
> Signed-off-by: David Abdurachmanov 
> Signed-off-by: Green Wan 
> Reviewed-by: Ramon Fried 
> ---
>  drivers/net/macb.c | 8 +++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/macb.c b/drivers/net/macb.c
> index 57ea45e..df65d82 100644
> --- a/drivers/net/macb.c
> +++ b/drivers/net/macb.c
> @@ -592,7 +592,11 @@ static int macb_sifive_clk_init(struct udevice *dev, 
> ulong rate)
>  * and output clock on GMII output signal GTX_CLK
>  * 1 = MII mode. Use MII input signal TX_CLK in TX logic
>  */
> -   writel(rate != 12500, gemgxl_regs);
> +   if (device_is_compatible(dev, "sifive,fu540-c000-gem"))
> +   writel(rate != 12500, gemgxl_regs);

Could you add a comment here why we need this? (i.e. about the HW quirk)
Note that 125.125 is actually outside of specification for VSC8541XMV-02.

> +   else if (device_is_compatible(dev, "sifive,fu740-c000-gem"))
> +   writel(rate != 125125000, gemgxl_regs);
> +
> return 0;
>  }
>
> @@ -1507,6 +1511,8 @@ static const struct udevice_id macb_eth_ids[] = {
> { .compatible = "cdns,zynq-gem" },
> { .compatible = "sifive,fu540-c000-gem",
>   .data = (ulong)&sifive_config },
> +   { .compatible = "sifive,fu740-c000-gem",
> + .data = (ulong)&sifive_config },
> { .compatible = "microchip,mpfs-mss-gem",
>   .data = (ulong)µchip_config },
> { }
> --
> 2.7.4
>


[PATCH 0/4] mmc: fsl_esdhc: ls1028a workarounds

2021-03-17 Thread Michael Walle
This patchset fixes HS400 mode on LS1028A SoC which is broken since commit
8ee802f899ef ("mmc: fsl_esdhc: make sure delay chain locked for HS400").
Well, before it might just have worked by accident.

=> run bootcmd_mmc0
fsl_esdhc: delay chain lock timeout
Select HS400 failed -110
unable to select a mode : -5

Because the sl28 board already uses that mode, MMC boot is broken. The
first patch disables HS400 mode on this board.
Tom, patch 1 should go into the master branch for the 2021.04 release.

Patches 2 and 3 introduce the actual workarounds, patch 4 will then
reenable the HS400 mode on the sl28 board. I don't expect that this will
make it into the next release.

Michael Walle (4):
  board: sl28: disable HS400 mode
  mmc: fsl_esdhc: add workaround for erratum A-011334
  mmc: fsl_esdhc: add pulse width detection workaround
  board: sl28: enable HS400 mode again

 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  2 ++
 drivers/mmc/Kconfig   |  6 +
 drivers/mmc/fsl_esdhc.c   | 31 +--
 include/fsl_esdhc.h   |  3 +++
 4 files changed, 40 insertions(+), 2 deletions(-)

-- 
2.20.1



[PATCH 2/4] mmc: fsl_esdhc: add workaround for erratum A-011334

2021-03-17 Thread Michael Walle
LS1028A SoCs are restricted in what divider values are allowed for HS400
mode. This is basically a port from the corresponding linux driver.

Signed-off-by: Michael Walle 
---
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  1 +
 drivers/mmc/Kconfig   |  3 +++
 drivers/mmc/fsl_esdhc.c   | 25 ++-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index ae0b7b21e8..c0190a233e 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -47,6 +47,7 @@ config ARCH_LS1028A
select SYS_FSL_ERRATUM_A009663 if !TFABOOT
select SYS_FSL_ERRATUM_A009942 if !TFABOOT
select SYS_FSL_ERRATUM_A050382
+   select SYS_FSL_ERRATUM_A011334
select RESV_RAM if GIC_V3_ITS
imply PANIC_HANG
 
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index f8ca52efb6..0b6755fd90 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -812,3 +812,6 @@ config SYS_FSL_ERRATUM_ESDHC135
 
 config SYS_FSL_ERRATUM_ESDHC_A001
bool
+
+config SYS_FSL_ERRATUM_A011334
+   bool
diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index 6014e1c5ca..09ea1a9de9 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -518,6 +518,24 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct 
mmc *mmc, uint clock)
while (sdhc_clk / (div * pre_div) > clock && div < 16)
div++;
 
+   if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_A011334) &&
+   clock == 2 && mmc->selected_mode == MMC_HS_400) {
+   u32 div_ratio = pre_div * div;
+
+   if (div_ratio <= 4) {
+   pre_div = 4;
+   div = 1;
+   } else if (div_ratio <= 8) {
+   pre_div = 4;
+   div = 2;
+   } else if (div_ratio <= 12) {
+   pre_div = 4;
+   div = 3;
+   } else {
+   printf("unsupported clock division.\n");
+   }
+   }
+
mmc->clock = sdhc_clk / pre_div / div;
priv->clock = mmc->clock;
 
@@ -1063,9 +1081,14 @@ static int fsl_esdhc_execute_tuning(struct udevice *dev, 
uint32_t opcode)
struct fsl_esdhc_plat *plat = dev_get_plat(dev);
struct fsl_esdhc_priv *priv = dev_get_priv(dev);
struct fsl_esdhc *regs = priv->esdhc_regs;
+   struct mmc *mmc = &plat->mmc;
u32 val, irqstaten;
int i;
 
+   if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_A011334) &&
+   plat->mmc.hs400_tuning)
+   set_sysctl(priv, mmc, mmc->clock);
+
esdhc_tuning_block_enable(priv, true);
esdhc_setbits32(®s->autoc12err, EXECUTE_TUNING);
 
@@ -1073,7 +1096,7 @@ static int fsl_esdhc_execute_tuning(struct udevice *dev, 
uint32_t opcode)
esdhc_write32(®s->irqstaten, IRQSTATEN_BRR);
 
for (i = 0; i < MAX_TUNING_LOOP; i++) {
-   mmc_send_tuning(&plat->mmc, opcode, NULL);
+   mmc_send_tuning(mmc, opcode, NULL);
mdelay(1);
 
val = esdhc_read32(®s->autoc12err);
-- 
2.20.1



[PATCH 3/4] mmc: fsl_esdhc: add pulse width detection workaround

2021-03-17 Thread Michael Walle
HS400 mode on the LS1028A SoC isn't reliable. The linux driver has a
workaroung for the pulse width detection. Apply this workaround in
u-boot, too.

This will make HS400 mode work reliably on the LS1028A SoC.

Signed-off-by: Michael Walle 
---
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 1 +
 drivers/mmc/Kconfig   | 3 +++
 drivers/mmc/fsl_esdhc.c   | 6 +-
 include/fsl_esdhc.h   | 3 +++
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index c0190a233e..9d1ba4c771 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -48,6 +48,7 @@ config ARCH_LS1028A
select SYS_FSL_ERRATUM_A009942 if !TFABOOT
select SYS_FSL_ERRATUM_A050382
select SYS_FSL_ERRATUM_A011334
+   select SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND
select RESV_RAM if GIC_V3_ITS
imply PANIC_HANG
 
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 0b6755fd90..f7620c9cd1 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -815,3 +815,6 @@ config SYS_FSL_ERRATUM_ESDHC_A001
 
 config SYS_FSL_ERRATUM_A011334
bool
+
+config SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND
+   bool
diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index 09ea1a9de9..7501fdb71e 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -71,7 +71,8 @@ struct fsl_esdhc {
uintsdtimingctl;/* SD timing control register */
charreserved8[20];  /* reserved */
uintdllcfg0;/* DLL config 0 register */
-   charreserved9[12];  /* reserved */
+   uintdllcfg1;/* DLL config 1 register */
+   charreserved9[8];   /* reserved */
uintdllstat0;   /* DLL status 0 register */
charreserved10[664];/* reserved */
uintesdhcctl;   /* eSDHC control register */
@@ -767,6 +768,9 @@ static int esdhc_init_common(struct fsl_esdhc_priv *priv, 
struct mmc *mmc)
/* Set timout to the maximum value */
esdhc_clrsetbits32(®s->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
 
+   if 
(IS_ENABLED(CONFIG_SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND))
+   esdhc_clrbits32(®s->dllcfg1, DLL_PD_PULSE_STRETCH_SEL);
+
return 0;
 }
 
diff --git a/include/fsl_esdhc.h b/include/fsl_esdhc.h
index 850a304bd7..f86afe5dad 100644
--- a/include/fsl_esdhc.h
+++ b/include/fsl_esdhc.h
@@ -190,6 +190,9 @@
 #define DLL_RESET  0x4000
 #define DLL_FREQ_SEL   0x0800
 
+/* DLL config 1 register */
+#define DLL_PD_PULSE_STRETCH_SEL 0x8000
+
 /* DLL status 0 register */
 #define DLL_STS_SLV_LOCK   0x0800
 
-- 
2.20.1



[PATCH 1/4] board: sl28: disable HS400 mode

2021-03-17 Thread Michael Walle
Since commit 8ee802f899ef ("mmc: fsl_esdhc: make sure delay chain locked
for HS400") HS400 mode is unreliable on LS1028A SoCs. Some workarounds are
missing for this SoC.

Disable HS400 mode for now.

Signed-off-by: Michael Walle 
---
 configs/kontron_sl28_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/kontron_sl28_defconfig b/configs/kontron_sl28_defconfig
index 1c781e091c..0c6c1911d9 100644
--- a/configs/kontron_sl28_defconfig
+++ b/configs/kontron_sl28_defconfig
@@ -70,7 +70,7 @@ CONFIG_I2C_SET_DEFAULT_BUS_NUM=y
 CONFIG_I2C_DEFAULT_BUS_NUMBER=0
 CONFIG_I2C_MUX=y
 CONFIG_DM_MMC=y
-CONFIG_MMC_HS400_SUPPORT=y
+CONFIG_MMC_HS200_SUPPORT=y
 CONFIG_FSL_ESDHC=y
 CONFIG_FSL_ESDHC_SUPPORT_ADMA2=y
 CONFIG_DM_SPI_FLASH=y
-- 
2.20.1



[PATCH 4/4] board: sl28: enable HS400 mode again

2021-03-17 Thread Michael Walle
Now that it is working reliable on the LS1028A SoC, reenable support for
it.

Signed-off-by: Michael Walle 
---
 configs/kontron_sl28_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/kontron_sl28_defconfig b/configs/kontron_sl28_defconfig
index 0c6c1911d9..1c781e091c 100644
--- a/configs/kontron_sl28_defconfig
+++ b/configs/kontron_sl28_defconfig
@@ -70,7 +70,7 @@ CONFIG_I2C_SET_DEFAULT_BUS_NUM=y
 CONFIG_I2C_DEFAULT_BUS_NUMBER=0
 CONFIG_I2C_MUX=y
 CONFIG_DM_MMC=y
-CONFIG_MMC_HS200_SUPPORT=y
+CONFIG_MMC_HS400_SUPPORT=y
 CONFIG_FSL_ESDHC=y
 CONFIG_FSL_ESDHC_SUPPORT_ADMA2=y
 CONFIG_DM_SPI_FLASH=y
-- 
2.20.1



[PATCH v2] arm: mach-rmobile: Add CPU info support for RZ/G2

2021-03-17 Thread Biju Das
Add CPU info support for RZ/G2 SoC's.

Signed-off-by: Biju Das 
---
V1-->V2
 * Added support to make CPU info based on tfa is available only
   when CONFIG_RZ_G2 is enabled.
---
 arch/arm/mach-rmobile/Kconfig.64 |  5 +++
 arch/arm/mach-rmobile/Makefile   |  1 +
 arch/arm/mach-rmobile/cpu_info-rzg.c | 41 
 arch/arm/mach-rmobile/cpu_info.c | 21 --
 arch/arm/mach-rmobile/include/mach/rmobile.h |  1 +
 5 files changed, 65 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/mach-rmobile/cpu_info-rzg.c

diff --git a/arch/arm/mach-rmobile/Kconfig.64 b/arch/arm/mach-rmobile/Kconfig.64
index 8127d33f2d..3f7ec05379 100644
--- a/arch/arm/mach-rmobile/Kconfig.64
+++ b/arch/arm/mach-rmobile/Kconfig.64
@@ -57,6 +57,9 @@ config R8A77995
imply CLK_R8A77995
imply PINCTRL_PFC_R8A77995
 
+config RZ_G2
+   bool "Renesas ARM SoCs RZ/G2 (64bit)"
+
 endmenu
 
 choice
@@ -107,6 +110,7 @@ config TARGET_HIHOPE_RZG2
imply R8A774A1
imply R8A774B1
imply R8A774E1
+   imply RZ_G2
imply SYS_MALLOC_F
imply MULTI_DTB_FIT
imply MULTI_DTB_FIT_USER_DEFINED_AREA
@@ -116,6 +120,7 @@ config TARGET_HIHOPE_RZG2
 config TARGET_SILINUX_EK874
bool "Silicon Linux EK874 board"
imply R8A774C0
+   imply RZ_G2
help
   Support for Silicon Linux EK874 platform
 
diff --git a/arch/arm/mach-rmobile/Makefile b/arch/arm/mach-rmobile/Makefile
index 9f56af465e..81a0dedb41 100644
--- a/arch/arm/mach-rmobile/Makefile
+++ b/arch/arm/mach-rmobile/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_SH73A0) += lowlevel_init.o cpu_info-sh73a0.o 
pfc-sh73a0.o
 obj-$(CONFIG_R8A7740) += lowlevel_init.o cpu_info-r8a7740.o pfc-r8a7740.o
 obj-$(CONFIG_RCAR_GEN2) += lowlevel_init_ca15.o cpu_info-rcar.o
 obj-$(CONFIG_RCAR_GEN3) += lowlevel_init_gen3.o cpu_info-rcar.o memmap-gen3.o
+obj-$(CONFIG_RZ_G2) += cpu_info-rzg.o
 
 OBJCOPYFLAGS_u-boot-spl.srec := -O srec
 quiet_cmd_objcopy = OBJCOPY $@
diff --git a/arch/arm/mach-rmobile/cpu_info-rzg.c 
b/arch/arm/mach-rmobile/cpu_info-rzg.c
new file mode 100644
index 00..1c18fd06f0
--- /dev/null
+++ b/arch/arm/mach-rmobile/cpu_info-rzg.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 Renesas Electronics Corporation
+ *
+ */
+#include 
+#include 
+
+/* If the firmware passed a device tree, use it for soc identification. */
+extern u64 rcar_atf_boot_args[];
+
+/* CPU information table */
+static const struct {
+   char *soc_name;
+   u8 cpu_name[10];
+} tfa_info[] = {
+   { "renesas,r8a774a1", "R8A774A1" },
+   { "renesas,r8a774b1", "R8A774B1" },
+   { "renesas,r8a774c0", "R8A774C0" },
+   { "renesas,r8a774e1", "R8A774E1" }
+};
+
+const u8 *rzg_get_cpu_name(void)
+{
+   void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
+   bool ret = false;
+   int i;
+
+   if (fdt_magic(atf_fdt_blob) != FDT_MAGIC)
+   return NULL;
+
+   for (i = 0; i < ARRAY_SIZE(tfa_info); i++) {
+   if (fdt_node_check_compatible(atf_fdt_blob, 0,
+ tfa_info[i].soc_name) == 0) {
+   ret = true;
+   break;
+   }
+   }
+
+   return ret ? tfa_info[i].cpu_name : NULL;
+}
diff --git a/arch/arm/mach-rmobile/cpu_info.c b/arch/arm/mach-rmobile/cpu_info.c
index fdbbd72e28..9ec622bdb5 100644
--- a/arch/arm/mach-rmobile/cpu_info.c
+++ b/arch/arm/mach-rmobile/cpu_info.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2012 Nobuhiro Iwamatsu 
- * (C) Copyright 2012 Renesas Solutions Corp.
+ * (C) Copyright 2012-2021 Renesas Solutions Corp.
  */
 #include 
 #include 
@@ -31,6 +31,11 @@ void enable_caches(void)
 
 #ifdef CONFIG_DISPLAY_CPUINFO
 #ifndef CONFIG_RZA1
+__weak const u8 *rzg_get_cpu_name(void)
+{
+   return 0;
+}
+
 static u32 __rmobile_get_cpu_type(void)
 {
return 0x0;
@@ -52,7 +57,7 @@ static u32 __rmobile_get_cpu_rev_fraction(void)
 u32 rmobile_get_cpu_rev_fraction(void)
__attribute__((weak, alias("__rmobile_get_cpu_rev_fraction")));
 
-/* CPU infomation table */
+/* CPU information table */
 static const struct {
u16 cpu_type;
u8 cpu_name[10];
@@ -86,14 +91,22 @@ static int rmobile_cpuinfo_idx(void)
return i;
 }
 
+static const u8 *get_cpu_name(int idx)
+{
+   const  u8 *cpu_name = rzg_get_cpu_name();
+
+   return cpu_name ? cpu_name : rmobile_cpuinfo[idx].cpu_name;
+}
+
 #ifdef CONFIG_ARCH_MISC_INIT
 int arch_misc_init(void)
 {
int i, idx = rmobile_cpuinfo_idx();
+   const u8 *cpu_name = get_cpu_name(idx);
char cpu[10] = { 0 };
 
for (i = 0; i < sizeof(cpu); i++)
-   cpu[i] = tolower(rmobile_cpuinfo[idx].cpu_name[i]);
+   cpu[i] = tolower(cpu_name[i]);
 
env_set("platform", cpu);
 
@@ -106,7 +119,7 @@ int print_cpuinfo(void)
int i = 

[PATCH v1 0/6] Provide support for mv88e6020 Marvell switch

2021-03-17 Thread Lukasz Majewski
This patch set provides support for mv88e6020 switch. It is a dual chip
device, with direct access to port register on SMI bus. However, PHYs
are accessed indirectly.


Lukasz Majewski (6):
  net: mv88e61xx: Add support for checking addressing mode
  net: mv88e61xx: Configure PHY ports to also pass packets between them
  net: mv88e61xx: Clear temporary structs before using them in
get_phy_id()
  net: mv88e61xx: Directly access the switch chip
  net: mv88e61xx: Set proper offset when R0_LED/ADDR4 is set on
bootstrap
  net: mv88e61xx: Reset switch PHYs when bootstrapped to !NO_CPU

 drivers/net/phy/mv88e61xx.c | 158 
 1 file changed, 142 insertions(+), 16 deletions(-)

-- 
2.20.1



[PATCH v1 1/6] net: mv88e61xx: Add support for checking addressing mode

2021-03-17 Thread Lukasz Majewski
Some Marvell switch devices are dual chip ones, like mv88e6020, which
use direct MDIO addressing to access its ports' registers. Such approach
allows connecting two such devices in a single MDIO bus with simple
addressing scheme.

Signed-off-by: Lukasz Majewski 
---

 drivers/net/phy/mv88e61xx.c | 42 +
 1 file changed, 42 insertions(+)

diff --git a/drivers/net/phy/mv88e61xx.c b/drivers/net/phy/mv88e61xx.c
index 7eff37b24499..69a1dd8f1859 100644
--- a/drivers/net/phy/mv88e61xx.c
+++ b/drivers/net/phy/mv88e61xx.c
@@ -202,6 +202,7 @@ struct mv88e61xx_phy_priv {
u8 phy_ctrl1_en_det_shift; /* 'EDet' bit field offset */
u8 phy_ctrl1_en_det_width; /* Width of 'EDet' bit field */
u8 phy_ctrl1_en_det_ctrl;  /* 'EDet' control value */
+   u8 direct_access;  /* Access switch device directly */
 };
 
 static inline int smi_cmd(int cmd, int addr, int reg)
@@ -928,6 +929,40 @@ static int mv88e61xx_priv_reg_offs_pre_init(struct 
phy_device *phydev)
return -ENODEV;
 }
 
+static int mv88e61xx_check_addressing(struct phy_device *phydev)
+{
+   if (!CONFIG_IS_ENABLED(OF_CONTROL))
+   return 0;
+
+   /*
+* Some devices - like mv88e6020 are dual chip - i.e. two
+* such devices can be directly accessed via SMI bus.
+* The addressing depends on R0_LED/ADDR4 pin value duing
+* bootstrap.
+*
+* This means that there is no need for indirect access.
+*/
+   struct mv88e61xx_phy_priv *priv = phydev->priv;
+
+   /*
+* As this function is called very early and hence the phydev
+* is not yet initialized we use aliast and DTS to asses if
+* device shall be directly accessed or not.
+*/
+   ofnode sw0;
+   int ret;
+
+   sw0 = ofnode_get_aliases_node("switch0");
+   if (!ofnode_valid(sw0))
+   return -ENODEV;
+
+   ret = ofnode_device_is_compatible(sw0, "marvell,mv88e6020");
+   if (ret)
+   priv->direct_access = 1;
+
+   return 0;
+}
+
 static int mv88e61xx_probe(struct phy_device *phydev)
 {
struct mii_dev *smi_wrapper;
@@ -982,6 +1017,8 @@ static int mv88e61xx_probe(struct phy_device *phydev)
 
phydev->priv = priv;
 
+   mv88e61xx_check_addressing(phydev);
+
res = mv88e61xx_priv_reg_offs_pre_init(phydev);
if (res < 0)
return res;
@@ -1197,6 +1234,11 @@ int get_phy_id(struct mii_dev *bus, int smi_addr, int 
devad, u32 *phy_id)
temp_phy.priv = &temp_priv;
temp_mii.priv = &temp_phy;
 
+   mv88e61xx_check_addressing(&temp_phy);
+   /* For direct access the phy address equals to smi_addr */
+   if (temp_priv.direct_access)
+   temp_phy.addr = smi_addr;
+
/*
 * get_phy_id() can be called by framework before mv88e61xx driver
 * probing, in this case the global register offsets are not
-- 
2.20.1



[PATCH v1 2/6] net: mv88e61xx: Configure PHY ports to also pass packets between them

2021-03-17 Thread Lukasz Majewski
After this change PHY ports are able to pass packets between them (and
also to CPU port).

The Kconfig variable - CONFIG_MV88E61XX_PHY_PORTS - is used to get the
PHY ports of the switch and generate proper mask.

Signed-off-by: Lukasz Majewski 
---

 drivers/net/phy/mv88e61xx.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mv88e61xx.c b/drivers/net/phy/mv88e61xx.c
index 69a1dd8f1859..14074c0b82fb 100644
--- a/drivers/net/phy/mv88e61xx.c
+++ b/drivers/net/phy/mv88e61xx.c
@@ -873,14 +873,19 @@ static int mv88e61xx_phy_setup(struct phy_device *phydev, 
u8 phy)
 
 static int mv88e61xx_phy_config_port(struct phy_device *phydev, u8 phy)
 {
+   struct mv88e61xx_phy_priv *priv = phydev->priv;
+   u16 port_mask;
int val;
 
val = mv88e61xx_port_enable(phydev, phy);
if (val < 0)
return val;
 
-   val = mv88e61xx_port_set_vlan(phydev, phy,
-   1 << CONFIG_MV88E61XX_CPU_PORT);
+   port_mask = PORT_MASK(priv->port_count) & CONFIG_MV88E61XX_PHY_PORTS;
+   port_mask &= ~(1 << phy);
+   port_mask |= (1 << CONFIG_MV88E61XX_CPU_PORT);
+
+   val = mv88e61xx_port_set_vlan(phydev, phy, port_mask);
if (val < 0)
return val;
 
-- 
2.20.1



[PATCH v1 3/6] net: mv88e61xx: Clear temporary structs before using them in get_phy_id()

2021-03-17 Thread Lukasz Majewski
Those automatically created structures can have random value.
However, mv88e61xx driver assumes that those are zeroed.

Signed-off-by: Lukasz Majewski 
---

 drivers/net/phy/mv88e61xx.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/phy/mv88e61xx.c b/drivers/net/phy/mv88e61xx.c
index 14074c0b82fb..d8116530700d 100644
--- a/drivers/net/phy/mv88e61xx.c
+++ b/drivers/net/phy/mv88e61xx.c
@@ -1230,6 +1230,10 @@ int get_phy_id(struct mii_dev *bus, int smi_addr, int 
devad, u32 *phy_id)
struct mii_dev temp_mii;
int val;
 
+   memset(&temp_phy, 0, sizeof(temp_phy));
+   memset(&temp_priv, 0, sizeof(temp_priv));
+   memset(&temp_mii, 0, sizeof(temp_mii));
+
/*
 * Buid temporary data structures that the chip reading code needs to
 * read the ID
-- 
2.20.1



[PATCH v1 4/6] net: mv88e61xx: Directly access the switch chip

2021-03-17 Thread Lukasz Majewski
The mv88e6020 is accessed in a direct way (i.e. with direct read and
write to mdio bus). The only necessary indirection is required when
accessing its PHY registers.

Signed-off-by: Lukasz Majewski 
---

 drivers/net/phy/mv88e61xx.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/mv88e61xx.c b/drivers/net/phy/mv88e61xx.c
index d8116530700d..3d846b89fd12 100644
--- a/drivers/net/phy/mv88e61xx.c
+++ b/drivers/net/phy/mv88e61xx.c
@@ -269,8 +269,11 @@ static int mv88e61xx_reg_read(struct phy_device *phydev, 
int dev, int reg)
int smi_addr = priv->smi_addr;
int res;
 
-   /* In single-chip mode, the device can be addressed directly */
-   if (smi_addr == 0)
+   /*
+* In single-chip or dual-chip (like mv88e6020) mode, the device can
+* be addressed directly.
+*/
+   if (smi_addr == 0 || priv->direct_access)
return mdio_bus->read(mdio_bus, dev, MDIO_DEVAD_NONE, reg);
 
/* Wait for the bus to become free */
@@ -306,11 +309,13 @@ static int mv88e61xx_reg_write(struct phy_device *phydev, 
int dev, int reg,
int smi_addr = priv->smi_addr;
int res;
 
-   /* In single-chip mode, the device can be addressed directly */
-   if (smi_addr == 0) {
+   /*
+* In single-chip or dual-chip (like mv88e6020) mode, the device can
+* be addressed directly.
+*/
+   if (smi_addr == 0 || priv->direct_access)
return mdio_bus->write(mdio_bus, dev, MDIO_DEVAD_NONE, reg,
val);
-   }
 
/* Wait for the bus to become free */
res = mv88e61xx_smi_wait(mdio_bus, smi_addr);
-- 
2.20.1



[PATCH v1 5/6] net: mv88e61xx: Set proper offset when R0_LED/ADDR4 is set on bootstrap

2021-03-17 Thread Lukasz Majewski
The mv88e61xx driver need to be adjusted to handle situation when
switch MDIO addresses are switched by offset (0x10 in this case).

Signed-off-by: Lukasz Majewski 
---

 drivers/net/phy/mv88e61xx.c | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/net/phy/mv88e61xx.c b/drivers/net/phy/mv88e61xx.c
index 3d846b89fd12..325d5b56135f 100644
--- a/drivers/net/phy/mv88e61xx.c
+++ b/drivers/net/phy/mv88e61xx.c
@@ -45,7 +45,6 @@
 #define PORT_MASK(port_count)  ((1 << (port_count)) - 1)
 
 /* Device addresses */
-#define DEVADDR_PHY(p) (p)
 #define DEVADDR_SERDES 0x0F
 
 /* SMI indirection registers for multichip addressing mode */
@@ -414,7 +413,7 @@ static int mv88e61xx_phy_write_indirect(struct mii_dev 
*smi_wrapper, int dev,
 /* Wrapper function to make calls to phy_read_indirect simpler */
 static int mv88e61xx_phy_read(struct phy_device *phydev, int phy, int reg)
 {
-   return mv88e61xx_phy_read_indirect(phydev->bus, DEVADDR_PHY(phy),
+   return mv88e61xx_phy_read_indirect(phydev->bus, phydev->addr,
   MDIO_DEVAD_NONE, reg);
 }
 
@@ -422,7 +421,7 @@ static int mv88e61xx_phy_read(struct phy_device *phydev, 
int phy, int reg)
 static int mv88e61xx_phy_write(struct phy_device *phydev, int phy,
int reg, u16 val)
 {
-   return mv88e61xx_phy_write_indirect(phydev->bus, DEVADDR_PHY(phy),
+   return mv88e61xx_phy_write_indirect(phydev->bus, phydev->addr,
MDIO_DEVAD_NONE, reg, val);
 }
 
@@ -926,12 +925,21 @@ static int mv88e61xx_priv_reg_offs_pre_init(struct 
phy_device *phydev)
/*
 * Now try via port registers with device address 0x08
 * (88E6020 and compatible switches).
+*
+* When R0_LED/ADDR4 is set during bootstrap, one needs
+* to add 0x10 offset to switch addresses.
+*
+* The phydev->addr is set according to device tree address
+* of MDIO accessible device:
+*
+* When on board RO_LED/ADDR4 = 1 -> 0x10
+*  0 -> 0x0
 */
-   priv->port_reg_base = 0x08;
+   priv->port_reg_base = 0x08 + phydev->addr;
priv->id = mv88e61xx_get_switch_id(phydev);
if (priv->id != 0xfff0) {
-   priv->global1 = 0x0F;
-   priv->global2 = 0x07;
+   priv->global1 = 0x0F + phydev->addr;
+   priv->global2 = 0x07 + phydev->addr;
return 0;
}
 
@@ -1090,7 +1098,10 @@ static int mv88e61xx_phy_config(struct phy_device 
*phydev)
 
for (i = 0; i < priv->port_count; i++) {
if ((1 << i) & CONFIG_MV88E61XX_PHY_PORTS) {
-   phydev->addr = i;
+   if (phydev->addr)
+   phydev->addr += i;
+   else
+   phydev->addr = i;
 
res = mv88e61xx_phy_enable(phydev, i);
if (res < 0) {
-- 
2.20.1



[PATCH v1 6/6] net: mv88e61xx: Reset switch PHYs when bootstrapped to !NO_CPU

2021-03-17 Thread Lukasz Majewski
Some devices, when configured in bootstrap to 'no cpu' mode require PHY
manual reset to get them operational and responding to reading their ID
registers.

Without this step - the PHYLIB probing will fail.

In more details - the bootstrap configuration from switch must be read.
The value of CONFIG Data1 (0x71) of Scratch and Misc register is read
to check if 'no_cpu' and 'addr4' bits were set.

Signed-off-by: Lukasz Majewski 

---

 drivers/net/phy/mv88e61xx.c | 63 +++--
 1 file changed, 61 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mv88e61xx.c b/drivers/net/phy/mv88e61xx.c
index 325d5b56135f..1fa821ca162b 100644
--- a/drivers/net/phy/mv88e61xx.c
+++ b/drivers/net/phy/mv88e61xx.c
@@ -202,6 +202,17 @@ struct mv88e61xx_phy_priv {
u8 phy_ctrl1_en_det_width; /* Width of 'EDet' bit field */
u8 phy_ctrl1_en_det_ctrl;  /* 'EDet' control value */
u8 direct_access;  /* Access switch device directly */
+   /*
+* Bootstrap configuration:
+*
+* If addr4 = 1 device is accessible from 0x10 address on MDIO bus.
+*/
+   u8 addr4;
+   /*
+* If no_cpu = 1 switch is automatically setup, otherwise PHY reset is
+* required from CPU for normal operation.
+*/
+   u8 no_cpu;
 };
 
 static inline int smi_cmd(int cmd, int addr, int reg)
@@ -1235,6 +1246,33 @@ int phy_mv88e61xx_init(void)
return 0;
 }
 
+static int mv88e61xx_read_bootstrap(struct phy_device *phydev)
+{
+   struct mv88e61xx_phy_priv *priv = phydev->priv;
+   struct mii_dev *mdio_bus = priv->mdio_bus;
+   int val;
+
+   /* mv88e6020 - ID = 0x0200 (REG 3 on non PHY port) */
+   if (priv->id == PORT_SWITCH_ID_6020) {
+   /* Prepare to read scratch and misc register */
+   mdio_bus->write(mdio_bus, priv->global2, 0,
+   0x1a /*MV_SCRATCH_MISC*/,
+   (0x71 /*MV_CONFIG_DATA1*/ << 8));
+
+   val = mdio_bus->read(mdio_bus, priv->global2, 0,
+0x1a /*MV_SCRATCH_MISC*/);
+
+   if (val & (1 << 0))
+   priv->no_cpu = 1;
+   if (val & (1 << 4))
+   priv->addr4 = 1;
+   debug("mv88e6020: no_cpu=%d addr4=%d\n", priv->no_cpu,
+ priv->addr4);
+   }
+
+   return 0;
+}
+
 /*
  * Overload weak get_phy_id definition since we need non-standard functions
  * to read PHY registers
@@ -1274,13 +1312,34 @@ int get_phy_id(struct mii_dev *bus, int smi_addr, int 
devad, u32 *phy_id)
if (val < 0)
return val;
 
-   val = mv88e61xx_phy_read_indirect(&temp_mii, 0, devad, MII_PHYSID1);
+   mv88e61xx_read_bootstrap(&temp_phy);
+
+   /*
+* When switch is configured to work with CPU (i.e. NO_CPU == 0), PHYs
+* require reset (to at least single one) to have its registers
+* accessible.
+*/
+   if (!temp_priv.no_cpu && temp_priv.id == PORT_SWITCH_ID_6020) {
+   /* Reset PHY */
+   val = mv88e61xx_phy_read_indirect(&temp_mii, temp_phy.addr,
+ devad, MII_BMCR);
+   if (val & BMCR_PDOWN)
+   val &= ~BMCR_PDOWN;
+
+   mv88e61xx_phy_write_indirect(&temp_mii, temp_phy.addr, devad,
+MII_BMCR, val);
+   }
+
+   /* Read PHY_ID */
+   val = mv88e61xx_phy_read_indirect(&temp_mii, temp_phy.addr, devad,
+ MII_PHYSID1);
if (val < 0)
return -EIO;
 
*phy_id = val << 16;
 
-   val = mv88e61xx_phy_read_indirect(&temp_mii, 0, devad, MII_PHYSID2);
+   val = mv88e61xx_phy_read_indirect(&temp_mii, temp_phy.addr, devad,
+ MII_PHYSID2);
if (val < 0)
return -EIO;
 
-- 
2.20.1



[PATCH] Avoid delay when inializing USB peripheral by dwc2

2021-03-17 Thread João Loureiro
When `usb start` is called on the terminal, the dwc2 driver will try to start 
every USB device as host first, even if it is explicitly configured as 
peripheral in the device tree (`dr_mode = "peripheral"`).

So to avoid am unwanted 15 seconds delay when initializing the usb (one second 
per channel = 1s x 15), this patch adds a check to the initialization, and will 
skip host initialization of the device is explicitly set as peripheral. The 
checking is already and correctly done similarly in the 
`drivers/usb/gadget/dwc2_udc_otg.c` driver.

Signed-off-by: João Loureiro 
---
 drivers/usb/host/dwc2.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index ec643e9f45..7990060f3c 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice *dev, struct 
dwc2_priv *priv)
 #endif
 
dwc_otg_core_init(dev);
-   dwc_otg_core_host_init(dev, regs);
+
+   if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+   dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping 
host_init.\n",\
+   dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+   } else {
+   dwc_otg_core_host_init(dev, regs);
+   }
 
clrsetbits_le32(®s->hprt0, DWC2_HPRT0_PRTENA |
DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |
-- 
2.25.1



Re: [PATCH] Avoid delay when inializing USB peripheral by dwc2

2021-03-17 Thread Marek Vasut

On 3/17/21 4:19 PM, João Loureiro wrote:

When `usb start` is called on the terminal, the dwc2 driver will try to start every USB 
device as host first, even if it is explicitly configured as peripheral in the device 
tree (`dr_mode = "peripheral"`).

So to avoid am unwanted 15 seconds delay when initializing the usb (one second 
per channel = 1s x 15), this patch adds a check to the initialization, and will 
skip host initialization of the device is explicitly set as peripheral. The 
checking is already and correctly done similarly in the 
`drivers/usb/gadget/dwc2_udc_otg.c` driver.


Can you limit the commit message to 72 chars per line ?
fmt -w 72 can help you here.


@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice *dev, struct 
dwc2_priv *priv)
  #endif
  
  	dwc_otg_core_init(dev);

-   dwc_otg_core_host_init(dev, regs);
+
+   if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+   dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping 
host_init.\n",\


This backslash at the end is not needed.


+   dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+   } else {
+   dwc_otg_core_host_init(dev, regs);
+   }
  
  	clrsetbits_le32(®s->hprt0, DWC2_HPRT0_PRTENA |

DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |



Thanks


[PATCH] Avoid delay when initializing USB peripheral by dwc2

2021-03-17 Thread João Loureiro
From: João Loureiro 

When `usb start` is called on the terminal, the dwc2 driver will try
to start every USB device as host first, even if it is explicitly
configured as peripheral in the device tree (dr_mode = "peripheral").

So to avoid an unwanted 15 seconds delay when initializing the usb
(one second per channel = 1s x 15), this patch adds a check to the
initialization, and will skip host initialization of the device is
explicitly set as peripheral. The checking is already done similarly
in the `drivers/usb/gadget/dwc2_udc_otg.c` driver.

Signed-off-by: João Loureiro 
---
 drivers/usb/host/dwc2.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index ec643e9f45..43cc2e0433 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice *dev, struct 
dwc2_priv *priv)
 #endif
 
dwc_otg_core_init(dev);
-   dwc_otg_core_host_init(dev, regs);
+
+   if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+   dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping 
host_init.\n",
+   dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+   } else {
+   dwc_otg_core_host_init(dev, regs);
+   }
 
clrsetbits_le32(®s->hprt0, DWC2_HPRT0_PRTENA |
DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |
-- 
2.25.1



[PATCH] Avoid delay when initializing USB peripheral by dwc2

2021-03-17 Thread João Loureiro
When `usb start` is called on the terminal, the dwc2 driver will try
to start every USB device as host first, even if it is explicitly
configured as peripheral in the device tree (dr_mode = "peripheral").

So to avoid an unwanted 15 seconds delay when initializing the usb
(one second per channel = 1s x 15), this patch adds a check to the
initialization, and will skip host initialization of the device is
explicitly set as peripheral. The checking is already done similarly
in the `drivers/usb/gadget/dwc2_udc_otg.c` driver.

Signed-off-by: João Loureiro 
---
 drivers/usb/host/dwc2.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index ec643e9f45..43cc2e0433 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -1204,7 +1205,13 @@ static int dwc2_init_common(struct udevice *dev, struct 
dwc2_priv *priv)
 #endif
 
dwc_otg_core_init(dev);
-   dwc_otg_core_host_init(dev, regs);
+
+   if (usb_get_dr_mode(dev_ofnode(dev)) == USB_DR_MODE_PERIPHERAL) {
+   dev_dbg(dev, "USB device %s dr_mode set to %d. Skipping 
host_init.\n",
+   dev->name, usb_get_dr_mode(dev_ofnode(dev)));
+   } else {
+   dwc_otg_core_host_init(dev, regs);
+   }
 
clrsetbits_le32(®s->hprt0, DWC2_HPRT0_PRTENA |
DWC2_HPRT0_PRTCONNDET | DWC2_HPRT0_PRTENCHNG |
-- 
2.25.1



Re: [PATCH] dm: spi: Prevent setting a speed of 0 Hz in spi_post_probe

2021-03-17 Thread Tom Rini
On Tue, Mar 16, 2021 at 01:33:57PM +0100, Michal Simek wrote:

> The commit 12bfb2e05fc2 ("dm: spi: prevent setting a speed of 0 Hz")
> changes default value from 0 to SPI_DEFAULT_SPEED_HZ but spi_post_probe()
> hasn't been updated in the same way. It should be also update to be aligned
> with previous patch.
> 
> Fixes: 12bfb2e05fc2 ("dm: spi: prevent setting a speed of 0 Hz")
> Signed-off-by: Michal Simek 
> Reviewed-by: Pratyush Yadav 

This breaks tests:
=> ut dm spi_claim_bus
Test: dm_test_spi_claim_bus: spi.c
SF: Detected m25p16 with page size 256 Bytes, erase size 64 KiB, total 2 MiB
SF: Detected m25p16 with page size 256 Bytes, erase size 64 KiB, total 2 MiB
test/dm/spi.c:120, dm_test_spi_switch_slaves(): slave_a->max_hz == 
bus_data->speed: Expected 0x2625a00 (4000), got 0x186a0 (10)
test/dm/spi.c:120, dm_test_spi_switch_slaves(): slave_a->max_hz == 
bus_data->speed: Expected 0x2625a00 (4000), got 0x186a0 (10)
test/dm/spi.c:120, dm_test_spi_switch_slaves(): slave_a->max_hz == 
bus_data->speed: Expected 0x2faf080 (5000), got 0x186a0 (10)
Test: dm_test_spi_claim_bus: spi.c (flat tree)
SF: Detected m25p16 with page size 256 Bytes, erase size 64 KiB, total 2 MiB
SF: Detected m25p16 with page size 256 Bytes, erase size 64 KiB, total 2 MiB
test/dm/spi.c:120, dm_test_spi_switch_slaves(): slave_a->max_hz == 
bus_data->speed: Expected 0x2625a00 (4000), got 0x186a0 (10)
test/dm/spi.c:120, dm_test_spi_switch_slaves(): slave_a->max_hz == 
bus_data->speed: Expected 0x2625a00 (4000), got 0x186a0 (10)
test/dm/spi.c:120, dm_test_spi_switch_slaves(): slave_a->max_hz == 
bus_data->speed: Expected 0x2faf080 (5000), got 0x186a0 (10)
Failures: 6

So I assume a test needs updating too.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] arm: omap3: Make secureworld_exit() static

2021-03-17 Thread Adam Ford
On Sat, Mar 6, 2021 at 10:04 PM Adam Ford  wrote:
>
> secureworld_exit() is only used in one file, so make it static
> to that file and remove it from sys_proto.h. This
> may help with some further optimization in the future.
>
> Signed-off-by: Adam Ford 
>

Lokesh,

Is this patch ok as-is, or do you want me to re-post it as V2 with no
changes when I redo patch 2/2?

adam

> diff --git a/arch/arm/include/asm/arch-omap3/sys_proto.h 
> b/arch/arm/include/asm/arch-omap3/sys_proto.h
> index 656f848a73..a6e9ff84aa 100644
> --- a/arch/arm/include/asm/arch-omap3/sys_proto.h
> +++ b/arch/arm/include/asm/arch-omap3/sys_proto.h
> @@ -59,7 +59,6 @@ u32 is_running_in_sdram(void);
>  u32 is_running_in_sram(void);
>  u32 is_running_in_flash(void);
>  u32 get_device_type(void);
> -void secureworld_exit(void);
>  u32 get_boot_type(void);
>  void invalidate_dcache(u32);
>  u32 wait_on_value(u32, u32, void *, u32);
> diff --git a/arch/arm/mach-omap2/omap3/board.c 
> b/arch/arm/mach-omap2/omap3/board.c
> index c621177580..879b0f 100644
> --- a/arch/arm/mach-omap2/omap3/board.c
> +++ b/arch/arm/mach-omap2/omap3/board.c
> @@ -114,7 +114,7 @@ void secure_unlock_mem(void)
>   * configure secure registers and exit secure world
>   *  general use.
>   
> */
> -void secureworld_exit(void)
> +static void secureworld_exit(void)
>  {
> unsigned long i;
>
> --
> 2.25.1
>


[PATCH 00/13] display_options: Start to unify print_buffer() and hexdump

2021-03-17 Thread Simon Glass
At present we have two ways of showing a hex dump. Once has been in U-Boot
since the dawn of time and the other was recently added from Linux.

They both have their own unique features.

This series makes a few changes to bring them closer together. It also
adds support for logging a buffer, which is useful since it can put it
through the same log drivers as other logging output.

Also it adds tests, so we can check the behaviour.

The code-size impact of the main part of this series is 160 bytes on
Thumb2, which seems acceptable. However the final patch adds another 600
bytes or so, which is not.


Simon Glass (13):
  console: Report an error when output buffer is exhausted
  test: Detect when expect_str is too small
  test: Convert print tests to use ut framework
  test: Add a test for print_buffer()
  display_options: Drop two spaces before the ASCII column
  hexdump: Move API to header file
  hexdump: Add support for sandbox
  hexdump: Support any rowsize
  hexdump: Allow ctrl-c to interrupt output
  log: Drop log_nop() functions
  display_options: Split print_buffer() into two functions
  log: Add support for logging a buffer
  RFC: display_options: Use print_hex_dump() for print_buffer()

 common/console.c  |  18 +-
 common/log.c  |  30 
 include/asm-generic/global_data.h |  16 +-
 include/console.h |   3 +-
 include/display_options.h |  25 +++
 include/hexdump.h |  81 -
 include/log.h |  49 +++--
 include/test/suites.h |   1 +
 include/test/test.h   |   4 +-
 lib/display_options.c | 124 -
 lib/hexdump.c | 104 +++
 test/cmd/mem_search.c |  26 +--
 test/cmd_ut.c |   2 +
 test/dm/rtc.c |   9 +-
 test/log/log_test.c   |  27 +++
 test/print_ut.c   | 286 --
 test/ut.c |  55 +-
 17 files changed, 628 insertions(+), 232 deletions(-)

-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 01/13] console: Report an error when output buffer is exhausted

2021-03-17 Thread Simon Glass
If the console output buffer is exhausted, characters are silently dropped
from the end. Detect this condition and report an error when reading back
the characters.

Signed-off-by: Simon Glass 
---

 common/console.c  | 18 +++
 include/asm-generic/global_data.h | 16 -
 include/console.h |  3 ++-
 test/ut.c | 37 ++-
 4 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/common/console.c b/common/console.c
index 561cdf36a74..73edb287992 100644
--- a/common/console.c
+++ b/common/console.c
@@ -95,16 +95,22 @@ static void console_record_putc(const char c)
 {
if (!(gd->flags & GD_FLG_RECORD))
return;
-   if  (gd->console_out.start)
-   membuff_putbyte((struct membuff *)&gd->console_out, c);
+   if  (gd->console_out.start &&
+!membuff_putbyte((struct membuff *)&gd->console_out, c))
+   gd->flags |= GD_FLG_RECORD_OVF;
 }
 
 static void console_record_puts(const char *s)
 {
if (!(gd->flags & GD_FLG_RECORD))
return;
-   if  (gd->console_out.start)
-   membuff_put((struct membuff *)&gd->console_out, s, strlen(s));
+   if  (gd->console_out.start) {
+   int len = strlen(s);
+
+   if (membuff_put((struct membuff *)&gd->console_out, s, len) !=
+   len)
+   gd->flags |= GD_FLG_RECORD_OVF;
+   }
 }
 
 static int console_record_getc(void)
@@ -742,6 +748,7 @@ void console_record_reset(void)
 {
membuff_purge((struct membuff *)&gd->console_out);
membuff_purge((struct membuff *)&gd->console_in);
+   gd->flags &= ~GD_FLG_RECORD_OVF;
 }
 
 int console_record_reset_enable(void)
@@ -754,6 +761,9 @@ int console_record_reset_enable(void)
 
 int console_record_readline(char *str, int maxlen)
 {
+   if (gd->flags & GD_FLG_RECORD_OVF)
+   return -ENOSPC;
+
return membuff_readline((struct membuff *)&gd->console_out, str,
maxlen, ' ');
 }
diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index c24f5e0e973..e60036ab847 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -561,30 +561,34 @@ enum gd_flags {
 * @GD_FLG_RECORD: record console
 */
GD_FLG_RECORD = 0x01000,
+   /**
+* @GD_FLG_RECORD_OVF: record console overflow
+*/
+   GD_FLG_RECORD_OVF = 0x02000,
/**
 * @GD_FLG_ENV_DEFAULT: default variable flag
 */
-   GD_FLG_ENV_DEFAULT = 0x02000,
+   GD_FLG_ENV_DEFAULT = 0x04000,
/**
 * @GD_FLG_SPL_EARLY_INIT: early SPL initialization is done
 */
-   GD_FLG_SPL_EARLY_INIT = 0x04000,
+   GD_FLG_SPL_EARLY_INIT = 0x08000,
/**
 * @GD_FLG_LOG_READY: log system is ready for use
 */
-   GD_FLG_LOG_READY = 0x08000,
+   GD_FLG_LOG_READY = 0x1,
/**
 * @GD_FLG_WDT_READY: watchdog is ready for use
 */
-   GD_FLG_WDT_READY = 0x1,
+   GD_FLG_WDT_READY = 0x2,
/**
 * @GD_FLG_SKIP_LL_INIT: don't perform low-level initialization
 */
-   GD_FLG_SKIP_LL_INIT = 0x2,
+   GD_FLG_SKIP_LL_INIT = 0x4,
/**
 * @GD_FLG_SMP_READY: SMP initialization is complete
 */
-   GD_FLG_SMP_READY = 0x4,
+   GD_FLG_SMP_READY = 0x8,
 };
 
 /**
diff --git a/include/console.h b/include/console.h
index 7e628c0cf83..f848bcbf037 100644
--- a/include/console.h
+++ b/include/console.h
@@ -72,7 +72,8 @@ int console_record_reset_enable(void);
  *
  * @str: Place to put string
  * @maxlen: Maximum length of @str including nul terminator
- * @return length of string returned
+ * @return length of string returned, or -ENOSPC if the console buffer was
+ * overflowed by the output
  */
 int console_record_readline(char *str, int maxlen);
 
diff --git a/test/ut.c b/test/ut.c
index ea0af153e4a..a0fe5facac7 100644
--- a/test/ut.c
+++ b/test/ut.c
@@ -51,14 +51,31 @@ long ut_check_delta(ulong last)
return ut_check_free() - last;
 }
 
+static int readline_check(struct unit_test_state *uts)
+{
+   int ret;
+
+   ret = console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+   if (ret == -ENOSPC) {
+   ut_fail(uts, __FILE__, __LINE__, __func__,
+   "Console record buffer too small - increase 
CONFIG_CONSOLE_RECORD_OUT_SIZE");
+   return ret;
+   }
+
+   return 0;
+}
+
 int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
 {
va_list args;
+   int ret;
 
va_start(args, fmt);
vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
va_end(args);
-   console_record_readline(uts->actual_str, sizeof(uts->actual_str));
+   ret = readline_check(uts);
+ 

[PATCH 02/13] test: Detect when expect_str is too small

2021-03-17 Thread Simon Glass
If a line of more than 256 bytes is generated, the test will fail but the
reason is not clear. Add a check for this condition and print a helpful
message.

Signed-off-by: Simon Glass 
---

 test/ut.c | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/test/ut.c b/test/ut.c
index a0fe5facac7..350509a2926 100644
--- a/test/ut.c
+++ b/test/ut.c
@@ -68,11 +68,17 @@ static int readline_check(struct unit_test_state *uts)
 int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...)
 {
va_list args;
+   int len;
int ret;
 
va_start(args, fmt);
-   vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
+   len = vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
va_end(args);
+   if (len >= sizeof(uts->expect_str)) {
+   ut_fail(uts, __FILE__, __LINE__, __func__,
+   "unit_test_state->expect_str too small");
+   return -EOVERFLOW;
+   }
ret = readline_check(uts);
if (ret < 0)
return ret;
@@ -83,11 +89,17 @@ int ut_check_console_line(struct unit_test_state *uts, 
const char *fmt, ...)
 int ut_check_console_linen(struct unit_test_state *uts, const char *fmt, ...)
 {
va_list args;
+   int len;
int ret;
 
va_start(args, fmt);
-   vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
+   len = vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args);
va_end(args);
+   if (len >= sizeof(uts->expect_str)) {
+   ut_fail(uts, __FILE__, __LINE__, __func__,
+   "unit_test_state->expect_str too small");
+   return -EOVERFLOW;
+   }
ret = readline_check(uts);
if (ret < 0)
return ret;
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 03/13] test: Convert print tests to use ut framework

2021-03-17 Thread Simon Glass
This test predates the test framework in U-Boot. It uses #define DEBUG and
assert() to check the result. Update it to use the framework so it can
report failure constitent with other tests.

Signed-off-by: Simon Glass 
---

 include/test/suites.h |   1 +
 test/cmd_ut.c |   2 +
 test/print_ut.c   | 107 ++
 3 files changed, 58 insertions(+), 52 deletions(-)

diff --git a/include/test/suites.h b/include/test/suites.h
index f5d8e139cee..80b41f188c7 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -41,6 +41,7 @@ int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[]);
 int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[]);
+int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[]);
 int do_ut_str(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index b9c166045da..6f174c6a07f 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -51,6 +51,7 @@ static struct cmd_tbl cmd_ut_sub[] = {
U_BOOT_CMD_MKENT(setexpr, CONFIG_SYS_MAXARGS, 1, do_ut_setexpr, "",
 ""),
 #endif
+   U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_ut_print, "", ""),
 #ifdef CONFIG_UT_TIME
U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
 #endif
@@ -132,6 +133,7 @@ static char ut_help_text[] =
 #ifdef CONFIG_UT_OVERLAY
"ut overlay [test-name]\n"
 #endif
+   "ut print [test-name]  - test printing\n"
"ut setexpr [test-name] - test setexpr command\n"
 #ifdef CONFIG_SANDBOX
"ut str - Basic test of string functions\n"
diff --git a/test/print_ut.c b/test/print_ut.c
index a456a449efa..bb690f2b327 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -3,44 +3,51 @@
  * Copyright (c) 2012, The Chromium Authors
  */
 
-#define DEBUG
-
 #include 
-#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
 #include 
+#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
 #include 
 #endif
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
"and a lot more text to come"
 
+/* Declare a new print test */
+#define PRINT_TEST(_name, _flags)  UNIT_TEST(_name, _flags, print_test)
+
+#if CONFIG_IS_ENABLED(LIB_UUID)
 /* Test printing GUIDs */
-static void guid_ut_print(void)
+static int print_guid(struct unit_test_state *uts)
 {
-#if CONFIG_IS_ENABLED(LIB_UUID)
unsigned char guid[16] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
};
char str[40];
 
sprintf(str, "%pUb", guid);
-   assert(!strcmp("01020304-0506-0708-090a-0b0c0d0e0f10", str));
+   ut_assertok(strcmp("01020304-0506-0708-090a-0b0c0d0e0f10", str));
sprintf(str, "%pUB", guid);
-   assert(!strcmp("01020304-0506-0708-090A-0B0C0D0E0F10", str));
+   ut_assertok(strcmp("01020304-0506-0708-090A-0B0C0D0E0F10", str));
sprintf(str, "%pUl", guid);
-   assert(!strcmp("04030201-0605-0807-090a-0b0c0d0e0f10", str));
+   ut_assertok(strcmp("04030201-0605-0807-090a-0b0c0d0e0f10", str));
sprintf(str, "%pUL", guid);
-   assert(!strcmp("04030201-0605-0807-090A-0B0C0D0E0F10", str));
-#endif
+   ut_assertok(strcmp("04030201-0605-0807-090A-0B0C0D0E0F10", str));
+
+   return 0;
 }
+PRINT_TEST(print_guid, 0);
+#endif
 
+#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
 /* Test efi_loader specific printing */
-static void efi_ut_print(void)
+static int print_efi_ut(struct unit_test_state *uts)
 {
-#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
char str[10];
u8 buf[sizeof(struct efi_device_path_sd_mmc_path) +
   sizeof(struct efi_device_path)];
@@ -62,92 +69,88 @@ static void efi_ut_print(void)
dp_end->length = sizeof(struct efi_device_path);
 
snprintf(str, sizeof(str), "_%pD_", buf);
-   assert(!strcmp("_/SD(3)_", str));
+   ut_assertok(strcmp("_/SD(3)_", str));
 
/* NULL device path */
snprintf(str, sizeof(str), "_%pD_", NULL);
-   assert(!strcmp("__", str));
-#endif
+   ut_assertok(strcmp("__", str));
+
+   return 0;
 }
+PRINT_TEST(print_efi_ut, 0);
+#endif
 
-static int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc,
-  char *const argv[])
+static int print_printf(struct unit_test_state *uts)
 {
char big_str[400];
int big_str_len;
char str[10], *s;
int len;
 
-   printf("%s: Testing print\n", __func__);
-
snprintf(str, sizeof(str), "testing");
-   assert(!strcmp("testing", str));
+   ut_assertok(strcmp("testing", str));
 
snprintf(s

[PATCH 04/13] test: Add a test for print_buffer()

2021-03-17 Thread Simon Glass
Add a test for this function, to cover the various features. Expand the
expect_str length to take acount of the ~300-bytes lines generated in one
case.

Signed-off-by: Simon Glass 
---

 include/test/test.h |  4 +--
 test/print_ut.c | 82 +
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/include/test/test.h b/include/test/test.h
index 0b124edd601..ac91cc13aef 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -32,8 +32,8 @@ struct unit_test_state {
struct udevice *testdev;
int force_fail_alloc;
int skip_post_probe;
-   char expect_str[256];
-   char actual_str[256];
+   char expect_str[512];
+   char actual_str[512];
 };
 
 /* Test flags for each test */
diff --git a/test/print_ut.c b/test/print_ut.c
index bb690f2b327..4c814a306ea 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -10,11 +10,14 @@
 #endif
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 
+#define BUF_SIZE   0x100
+
 #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
"and a lot more text to come"
 
@@ -147,6 +150,85 @@ static int print_printf(struct unit_test_state *uts)
 }
 PRINT_TEST(print_printf, 0);
 
+static int print_display_buffer(struct unit_test_state *uts)
+{
+   u8 *buf;
+   int i;
+
+   buf = map_sysmem(0, BUF_SIZE);
+   memset(buf, '\0', BUF_SIZE);
+   for (i = 0; i < 0x11; i++)
+   buf[i] = i * 0x11;
+
+   /* bytes */
+   console_record_reset();
+   print_buffer(0, buf, 1, 0x12, 0);
+   ut_assert_nextline(": 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff..\"3DUfw");
+   ut_assert_nextline("0010: 10 00 
 ..");
+   ut_assert_console_end();
+
+   /* line length */
+   console_record_reset();
+   print_buffer(0, buf, 1, 0x12, 8);
+   ut_assert_nextline(": 00 11 22 33 44 55 66 77..\"3DUfw");
+   ut_assert_nextline("0008: 88 99 aa bb cc dd ee ff");
+   ut_assert_nextline("0010: 10 00  ..");
+   ut_assert_console_end();
+
+   /* long line */
+   console_record_reset();
+   buf[0x41] = 0x41;
+   print_buffer(0, buf, 1, 0x42, 0x40);
+   ut_assert_nextline(": 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
..\"3DUfw");
+   ut_assert_nextline("0040: 00 41 

 .A");
+   ut_assert_console_end();
+
+   /* address */
+   console_record_reset();
+   print_buffer(0x12345678, buf, 1, 0x12, 0);
+   ut_assert_nextline("12345678: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff..\"3DUfw");
+   ut_assert_nextline("12345688: 10 00 
 ..");
+   ut_assert_console_end();
+
+   /* 16-bit */
+   console_record_reset();
+   print_buffer(0, buf, 2, 9, 0);
+   ut_assert_nextline(": 1100 3322 5544 7766 9988 bbaa ddcc ffee   
 ..\"3DUfw");
+   ut_assert_nextline("0010: 0010  
 ..");
+   ut_assert_console_end();
+
+   /* 32-bit */
+   console_record_reset();
+   print_buffer(0, buf, 4, 5, 0);
+   ut_assert_nextline(": 33221100 77665544 bbaa9988 ffeeddcc
..\"3DUfw");
+   ut_assert_nextline("0010: 0010   
");
+   ut_assert_console_end();
+
+   /* 64-bit */
+   console_record_reset();
+   print_buffer(0, buf, 8, 3, 0);
+   ut_assert_nextline(": 7766554433221100 ffeeddccbbaa9988
..\"3DUfw");
+   ut_assert_nextline("0010: 0010 
");
+   ut_assert_console_end();
+
+   /* ASCII */
+   console_record_reset();
+   buf[1] = 31;
+   buf[2] = 32;
+   buf[3] = 33;
+   for (i = 0; i < 4; i++)
+   buf[4 + i] = 126 + i;
+   buf[8] = 255;
+   print_buffer(0, buf, 1, 10, 0);
+   ut_assert_nextline(": 00 1f 20 21 7e 7f 80 81 ff 99 
 .. !~.");
+   ut_assert_console_end();
+
+   unmap_sysmem(buf);
+
+   return 0;
+}
+PRINT_TEST(print_display_buffer, UT_TESTF_CONSOLE_REC);
+
 int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(print_test);
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 06/13] hexdump: Move API to header file

2021-03-17 Thread Simon Glass
Move the comments to the header file so people can find the function info
without digging in the implementation. Fix up the code style and add an
enum for the first arg.

Signed-off-by: Simon Glass 
---

 include/hexdump.h | 75 -
 lib/hexdump.c | 78 ++-
 2 files changed, 77 insertions(+), 76 deletions(-)

diff --git a/include/hexdump.h b/include/hexdump.h
index f7b76ff7121..62fce7ae7b4 100644
--- a/include/hexdump.h
+++ b/include/hexdump.h
@@ -10,7 +10,7 @@
 #include 
 #include 
 
-enum {
+enum dump_prefix_t {
DUMP_PREFIX_NONE,
DUMP_PREFIX_ADDRESS,
DUMP_PREFIX_OFFSET
@@ -81,10 +81,83 @@ static inline char *bin2hex(char *dst, const void *src, 
size_t count)
return dst;
 }
 
+/**
+ * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
+ * @buf: data blob to dump
+ * @len: number of bytes in the @buf
+ * @rowsize: number of bytes to print per line; must be 16 or 32
+ * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
+ * @linebuf: where to put the converted data
+ * @linebuflen: total size of @linebuf, including space for terminating NUL
+ * @ascii: include ASCII after the hex output
+ *
+ * hex_dump_to_buffer() works on one "line" of output at a time, i.e.,
+ * 16 or 32 bytes of input data converted to hex + ASCII output.
+ *
+ * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data
+ * to a hex + ASCII dump at the supplied memory location.
+ * The converted output is always NUL-terminated.
+ *
+ * E.g.:
+ *   hex_dump_to_buffer(frame->data, frame->len, 16, 1,
+ * linebuf, sizeof(linebuf), true);
+ *
+ * example output buffer:
+ * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
+ *
+ * Return:
+ * The amount of bytes placed in the buffer without terminating NUL. If the
+ * output was truncated, then the return value is the number of bytes
+ * (excluding the terminating NUL) which would have been written to the final
+ * string if enough space had been available.
+ */
 int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize,
   char *linebuf, size_t linebuflen, bool ascii);
+
+/**
+ * print_hex_dump - print a text hex dump to syslog for a binary blob of data
+ * @prefix_str: string to prefix each line with;
+ *  caller supplies trailing spaces for alignment if desired
+ * @prefix_type: controls whether prefix of an offset, address, or none
+ *  is printed (see enum dump_prefix_t)
+ * @rowsize: number of bytes to print per line; must be 16 or 32
+ * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
+ * @buf: data blob to dump
+ * @len: number of bytes in the @buf
+ * @ascii: include ASCII after the hex output
+ *
+ * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump
+ * to the stdio, with an optional leading prefix.
+ *
+ * print_hex_dump() works on one "line" of output at a time, i.e.,
+ * 16 or 32 bytes of input data converted to hex + ASCII output.
+ * print_hex_dump() iterates over the entire input @buf, breaking it into
+ * "line size" chunks to format and print.
+ *
+ * E.g.:
+ *   print_hex_dump("raw data: ", DUMP_PREFIX_ADDRESS, 16, 1, frame->data,
+ *  frame->len, true);
+ *
+ * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode:
+ * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f  @ABCDEFGHIJKLMNO
+ * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode:
+ * 88089af0: 73727170 77767574 7b7a7978 7f7e7d7c  pqrstuvwxyz{|}~.
+ */
 void print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
int groupsize, const void *buf, size_t len, bool ascii);
+
+/**
+ * print_hex_dump_bytes - shorthand form of print_hex_dump() with default 
params
+ * @prefix_str: string to prefix each line with;
+ *  caller supplies trailing spaces for alignment if desired
+ * @prefix_type: controls whether prefix of an offset, address, or none
+ *  is printed (see enum dump_prefix_t)
+ * @buf: data blob to dump
+ * @len: number of bytes in the @buf
+ *
+ * Calls print_hex_dump(), rowsize of 16, groupsize of 1,
+ * and ASCII output included.
+ */
 void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
  const void *buf, size_t len);
 
diff --git a/lib/hexdump.c b/lib/hexdump.c
index a3f219a8741..e31784cc118 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -19,36 +19,6 @@ const char hex_asc[] = "0123456789abcdef";
 const char hex_asc_upper[] = "0123456789ABCDEF";
 
 #if CONFIG_IS_ENABLED(HEXDUMP)
-/**
- * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
- * @buf: data blob to dump
- * @len: number of bytes in the @buf
- * @rowsize: number of bytes to print per line; must be 16 or 32
- * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
- * @linebuf: where to put the converted d

[PATCH 05/13] display_options: Drop two spaces before the ASCII column

2021-03-17 Thread Simon Glass
At present with print_buffer() U-Boot shows four spaces between the hex
and ASCII data. Two seems enough and matches print_hex_dump(). Change it.

Signed-off-by: Simon Glass 
---

 lib/display_options.c |  2 +-
 test/cmd/mem_search.c | 26 +-
 test/dm/rtc.c |  6 +++---
 test/print_ut.c   | 32 
 test/ut.c |  2 +-
 5 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/lib/display_options.c b/lib/display_options.c
index cd48998b6d4..7752baba2bd 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -189,7 +189,7 @@ int print_buffer(ulong addr, const void *data, uint width, 
uint count,
lb.uc[i] = '.';
}
lb.uc[i] = '\0';
-   printf("%s\n", lb.uc);
+   printf("  %s\n", lb.uc);
 
/* update references */
addr += thislinelen * width;
diff --git a/test/cmd/mem_search.c b/test/cmd/mem_search.c
index 94942793a49..f80c9c40687 100644
--- a/test/cmd/mem_search.c
+++ b/test/cmd/mem_search.c
@@ -30,9 +30,9 @@ static int mem_test_ms_b(struct unit_test_state *uts)
buf[0x100] = 0x12;
ut_assertok(console_record_reset_enable());
run_command("ms.b 1 ff 12", 0);
-   ut_assert_nextline("0030: 00 12 00 00 00 00 00 00 00 00 00 00 00 00 
00 00");
+   ut_assert_nextline("0030: 00 12 00 00 00 00 00 00 00 00 00 00 00 00 
00 00  ");
ut_assert_nextline("--");
-   ut_assert_nextline("00f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 12");
+   ut_assert_nextline("00f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 12  ");
ut_assert_nextline("2 matches");
ut_assert_console_end();
 
@@ -57,7 +57,7 @@ static int mem_test_ms_w(struct unit_test_state *uts)
buf[BUF_SIZE / 2] = 0x1234;
ut_assertok(console_record_reset_enable());
run_command("ms.w 0 80 1234", 0);
-   ut_assert_nextline("0030:   1234        
 4...");
+   ut_assert_nextline("0030:   1234       
4...");
ut_assert_nextline("1 match");
ut_assert_console_end();
 
@@ -82,7 +82,7 @@ static int mem_test_ms_l(struct unit_test_state *uts)
buf[BUF_SIZE / 4] = 0x12345678;
ut_assertok(console_record_reset_enable());
run_command("ms 0 40 12345678", 0);
-   ut_assert_nextline("0030:   12345678 
xV4.");
+   ut_assert_nextline("0030:   12345678   
xV4.");
ut_assert_nextline("1 match");
ut_assert_console_end();
 
@@ -212,10 +212,10 @@ static int mem_test_ms_mult(struct unit_test_state *uts)
strcpy(buf + BUF_SIZE - strlen(str) + 1, str);
ut_assertok(console_record_reset_enable());
run_command("ms.b 0 100 68 65 6c 6c 6f", 0);
-   ut_assert_nextline("0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
68 65..he");
-   ut_assert_nextline("0020: 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 
00 00llo.");
+   ut_assert_nextline("0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
68 65  ..he");
+   ut_assert_nextline("0020: 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 
00 00  llo.");
ut_assert_nextline("--");
-   ut_assert_nextline("0060: 00 00 00 68 65 6c 6c 6f 00 00 00 00 00 00 
00 00...hello");
+   ut_assert_nextline("0060: 00 00 00 68 65 6c 6c 6f 00 00 00 00 00 00 
00 00  ...hello");
ut_assert_nextline("2 matches");
ut_assert_console_end();
unmap_sysmem(buf);
@@ -242,12 +242,12 @@ static int mem_test_ms_s(struct unit_test_state *uts)
strcpy(buf + 0xa1, str2);
ut_assertok(console_record_reset_enable());
run_command("ms.s 0 100 hello", 0);
-   ut_assert_nextline("0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
68 65..he");
-   ut_assert_nextline("0020: 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 
00 00llo.");
+   ut_assert_nextline("0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
68 65  ..he");
+   ut_assert_nextline("0020: 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 
00 00  llo.");
ut_assert_nextline("--");
-   ut_assert_nextline("0060: 00 00 00 68 65 6c 6c 6f 00 00 00 00 00 00 
00 00...hello");
+   ut_assert_nextline("0060: 00 00 00 68 65 6c 6c 6f 00 00 00 00 00 00 
00 00  ...hello");
ut_assert_nextline("--");
-   ut_assert_nextline("00a0: 00 68 65 6c 6c 6f 74 68 65 72 65 00 00 00 
00 00.hellothere.");
+   ut_assert_nextline("00a0: 00 68 65 6c 6c 6f 74 68 65 72 65 00 00 00 
00 00  .hellothere.");
ut_assert_ne

[PATCH 07/13] hexdump: Add support for sandbox

2021-03-17 Thread Simon Glass
The current implementation outputs an address as a pointer. Update the
code to use an address instead, respecting the 32/64 nature of the CPU.

Add some initial tests copied from print_test_display_buffer(), just the
ones that can pass with the current implementation.

Note that for this case print_hex_dump() and print_bufffer() produce the
same result. For now the tests are duplicated sine we have separate
functions.

Signed-off-by: Simon Glass 
---

 lib/hexdump.c   |  5 -
 test/print_ut.c | 58 +
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/lib/hexdump.c b/lib/hexdump.c
index e31784cc118..a76ea707b69 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -139,7 +140,9 @@ void print_hex_dump(const char *prefix_str, int 
prefix_type, int rowsize,
 
switch (prefix_type) {
case DUMP_PREFIX_ADDRESS:
-   printf("%s%p: %s\n", prefix_str, ptr + i, linebuf);
+   printf("%s%0*lx: %s\n", prefix_str,
+  IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8,
+  (ulong)map_to_sysmem(ptr) + i, linebuf);
break;
case DUMP_PREFIX_OFFSET:
printf("%s%.8x: %s\n", prefix_str, i, linebuf);
diff --git a/test/print_ut.c b/test/print_ut.c
index 6acb5c569b6..ac9661df2b6 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -229,6 +229,64 @@ static int print_display_buffer(struct unit_test_state 
*uts)
 }
 PRINT_TEST(print_display_buffer, UT_TESTF_CONSOLE_REC);
 
+static int print_hex_dump(struct unit_test_state *uts)
+{
+   u8 *buf;
+   int i;
+
+   buf = map_sysmem(0, BUF_SIZE);
+   memset(buf, '\0', BUF_SIZE);
+   for (i = 0; i < 0x11; i++)
+   buf[i] = i * 0x11;
+
+   /* bytes */
+   console_record_reset();
+   print_hex_dump_bytes("", DUMP_PREFIX_ADDRESS, buf, 0x12);
+   ut_assert_nextline(": 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff  ..\"3DUfw");
+   ut_assert_nextline("0010: 10 00 
   ..");
+   ut_assert_console_end();
+
+   /* 16-bit */
+   console_record_reset();
+   print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 2, buf, 0x12, true);
+   ut_assert_nextline(": 1100 3322 5544 7766 9988 bbaa ddcc ffee  
..\"3DUfw");
+   ut_assert_nextline("0010: 0010 
..");
+   ut_assert_console_end();
+   unmap_sysmem(buf);
+
+   /* 32-bit */
+   console_record_reset();
+   print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 4, buf, 0x14, true);
+   ut_assert_nextline(": 33221100 77665544 bbaa9988 ffeeddcc  
..\"3DUfw");
+   ut_assert_nextline("0010: 0010 
");
+   ut_assert_console_end();
+   unmap_sysmem(buf);
+
+   /* 64-bit */
+   console_record_reset();
+   print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 8, buf, 0x18, true);
+   ut_assert_nextline(": 7766554433221100 ffeeddccbbaa9988  
..\"3DUfw");
+   ut_assert_nextline("0010: 0010   
");
+   ut_assert_console_end();
+   unmap_sysmem(buf);
+
+   /* ASCII */
+   console_record_reset();
+   buf[1] = 31;
+   buf[2] = 32;
+   buf[3] = 33;
+   for (i = 0; i < 4; i++)
+   buf[4 + i] = 126 + i;
+   buf[8] = 255;
+   print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 1, buf, 10, true);
+   ut_assert_nextline(": 00 1f 20 21 7e 7f 80 81 ff 99 
   .. !~.");
+   ut_assert_console_end();
+   unmap_sysmem(buf);
+
+   return 0;
+}
+PRINT_TEST(print_hex_dump, UT_TESTF_CONSOLE_REC);
+
 int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(print_test);
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 08/13] hexdump: Support any rowsize

2021-03-17 Thread Simon Glass
At present print_hex_dump() only supports either 16- or 32-byte lines.
With U-Boot we want to support any line length up to a maximum of 64.
Update the function to support this, with 0 defaulting to 16, as with
print_buffer().

Signed-off-by: Simon Glass 
---

 include/hexdump.h |  4 ++--
 lib/hexdump.c | 12 +---
 test/print_ut.c   | 23 ---
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/include/hexdump.h b/include/hexdump.h
index 62fce7ae7b4..b75e26025a4 100644
--- a/include/hexdump.h
+++ b/include/hexdump.h
@@ -85,7 +85,7 @@ static inline char *bin2hex(char *dst, const void *src, 
size_t count)
  * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
  * @buf: data blob to dump
  * @len: number of bytes in the @buf
- * @rowsize: number of bytes to print per line; must be 16 or 32
+ * @rowsize: number of bytes to print per line; max 64
  * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
  * @linebuf: where to put the converted data
  * @linebuflen: total size of @linebuf, including space for terminating NUL
@@ -120,7 +120,7 @@ int hex_dump_to_buffer(const void *buf, size_t len, int 
rowsize, int groupsize,
  *  caller supplies trailing spaces for alignment if desired
  * @prefix_type: controls whether prefix of an offset, address, or none
  *  is printed (see enum dump_prefix_t)
- * @rowsize: number of bytes to print per line; must be 16 or 32
+ * @rowsize: number of bytes to print per line; max 64
  * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
  * @buf: data blob to dump
  * @len: number of bytes in the @buf
diff --git a/lib/hexdump.c b/lib/hexdump.c
index a76ea707b69..a56e108164d 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -16,6 +16,8 @@
 #include 
 #include 
 
+#define MAX_LINE_LENGTH_BYTES  64
+
 const char hex_asc[] = "0123456789abcdef";
 const char hex_asc_upper[] = "0123456789ABCDEF";
 
@@ -30,8 +32,10 @@ int hex_dump_to_buffer(const void *buf, size_t len, int 
rowsize, int groupsize,
int ascii_column;
int ret;
 
-   if (rowsize != 16 && rowsize != 32)
+   if (!rowsize)
rowsize = 16;
+   else
+   rowsize = min(rowsize, MAX_LINE_LENGTH_BYTES);
 
if (len > rowsize)  /* limit to one line at a time */
len = rowsize;
@@ -126,10 +130,12 @@ void print_hex_dump(const char *prefix_str, int 
prefix_type, int rowsize,
 {
const u8 *ptr = buf;
int i, linelen, remaining = len;
-   char linebuf[32 * 3 + 2 + 32 + 1];
+   char linebuf[MAX_LINE_LENGTH_BYTES * 3 + 2 + MAX_LINE_LENGTH_BYTES + 1];
 
-   if (rowsize != 16 && rowsize != 32)
+   if (!rowsize)
rowsize = 16;
+   else
+   rowsize = min(rowsize, MAX_LINE_LENGTH_BYTES);
 
for (i = 0; i < len; i += rowsize) {
linelen = min(remaining, rowsize);
diff --git a/test/print_ut.c b/test/print_ut.c
index ac9661df2b6..3a3cdf323e1 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -246,9 +246,26 @@ static int print_hex_dump(struct unit_test_state *uts)
ut_assert_nextline("0010: 10 00 
   ..");
ut_assert_console_end();
 
+   /* line length */
+   console_record_reset();
+   print_hex_dump("", DUMP_PREFIX_ADDRESS, 8, 1, buf, 0x12, true);
+   ut_assert_nextline(": 00 11 22 33 44 55 66 77  ..\"3DUfw");
+   ut_assert_nextline("0008: 88 99 aa bb cc dd ee ff  ");
+   ut_assert_nextline("0010: 10 00..");
+   ut_assert_console_end();
+   unmap_sysmem(buf);
+
+   /* long line */
+   console_record_reset();
+   buf[0x41] = 0x41;
+   print_hex_dump("", DUMP_PREFIX_ADDRESS, 0x40, 1, buf, 0x42, true);
+   ut_assert_nextline(": 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
..\"3DUfw");
+   ut_assert_nextline("0040: 00 41 

   .A");
+   ut_assert_console_end();
+
/* 16-bit */
console_record_reset();
-   print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 2, buf, 0x12, true);
+   print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 2, buf, 0x12, true);
ut_assert_nextline(": 1100 3322 5544 7766 9988 bbaa ddcc ffee  
..\"3DUfw");
ut_assert_nextline("0010: 0010 
..");
ut_assert_console_end();
@@ -256,7 +273,7 @@ static int print_hex_dump(struct unit_test_state *uts)
 
/* 32-bit */
console_record_reset();
-   print_hex_dump("", DU

[PATCH 09/13] hexdump: Allow ctrl-c to interrupt output

2021-03-17 Thread Simon Glass
If a long hexdump is initated the user may wish to interrupt it. Add
support for this.

Signed-off-by: Simon Glass 
---

 include/hexdump.h |  6 --
 lib/hexdump.c | 13 +
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/hexdump.h b/include/hexdump.h
index b75e26025a4..f2ca4793d69 100644
--- a/include/hexdump.h
+++ b/include/hexdump.h
@@ -125,6 +125,8 @@ int hex_dump_to_buffer(const void *buf, size_t len, int 
rowsize, int groupsize,
  * @buf: data blob to dump
  * @len: number of bytes in the @buf
  * @ascii: include ASCII after the hex output
+ * Returns: 0 if finished normally, -EINTR if Ctrl-C was pressed, -ENOSYS if 
not
+ * supported
  *
  * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump
  * to the stdio, with an optional leading prefix.
@@ -143,8 +145,8 @@ int hex_dump_to_buffer(const void *buf, size_t len, int 
rowsize, int groupsize,
  * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode:
  * 88089af0: 73727170 77767574 7b7a7978 7f7e7d7c  pqrstuvwxyz{|}~.
  */
-void print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
-   int groupsize, const void *buf, size_t len, bool ascii);
+int print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
+  int groupsize, const void *buf, size_t len, bool ascii);
 
 /**
  * print_hex_dump_bytes - shorthand form of print_hex_dump() with default 
params
diff --git a/lib/hexdump.c b/lib/hexdump.c
index a56e108164d..149c93ead8b 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -125,8 +125,8 @@ overflow1:
return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1;
 }
 
-void print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
-   int groupsize, const void *buf, size_t len, bool ascii)
+int print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
+  int groupsize, const void *buf, size_t len, bool ascii)
 {
const u8 *ptr = buf;
int i, linelen, remaining = len;
@@ -157,7 +157,11 @@ void print_hex_dump(const char *prefix_str, int 
prefix_type, int rowsize,
printf("%s%s\n", prefix_str, linebuf);
break;
}
+   if (!IS_ENABLED(CONFIG_SPL_BUILD) && ctrlc())
+   return -EINTR;
}
+
+   return 0;
 }
 
 void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
@@ -170,9 +174,10 @@ void print_hex_dump_bytes(const char *prefix_str, int 
prefix_type,
  * Some code in U-Boot copy-pasted from Linux kernel uses both
  * functions below so to keep stuff compilable we keep these stubs here.
  */
-void print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
-   int groupsize, const void *buf, size_t len, bool ascii)
+int print_hex_dump(const char *prefix_str, int prefix_type, int rowsize,
+  int groupsize, const void *buf, size_t len, bool ascii)
 {
+   return -ENOSYS;
 }
 
 void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 10/13] log: Drop log_nop() functions

2021-03-17 Thread Simon Glass
These functions are not needed anymore since we now have logic which can
output to the console if logging is disabled. Drop the declarations.

Signed-off-by: Simon Glass 
---

 include/log.h | 18 --
 1 file changed, 18 deletions(-)

diff --git a/include/log.h b/include/log.h
index 748e34d5a26..594a361c613 100644
--- a/include/log.h
+++ b/include/log.h
@@ -128,18 +128,6 @@ int _log(enum log_category_t cat, enum log_level_t level, 
const char *file,
 int line, const char *func, const char *fmt, ...)
__attribute__ ((format (__printf__, 6, 7)));
 
-static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
-  const char *file, int line, const char *func,
-  const char *fmt, ...)
-   __attribute__ ((format (__printf__, 6, 7)));
-
-static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
-  const char *file, int line, const char *func,
-  const char *fmt, ...)
-{
-   return 0;
-}
-
 /* Define this at the top of a file to add a prefix to debug messages */
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
@@ -199,12 +187,6 @@ static inline int _log_nop(enum log_category_t cat, enum 
log_level_t level,
})
 #endif
 
-#define log_nop(_cat, _level, _fmt, _args...) ({ \
-   int _l = _level; \
-   _log_nop((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \
- __func__, pr_fmt(_fmt), ##_args); \
-})
-
 #ifdef DEBUG
 #define _DEBUG 1
 #else
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 11/13] display_options: Split print_buffer() into two functions

2021-03-17 Thread Simon Glass
At present print_buffer() outputs a hex dump but it is not possible to
place this dump in a string. Refactor it into a top-level function which
does the printing and a utility function that dumps a line into a string.
This makes the code more generally useful.

Signed-off-by: Simon Glass 
---

 include/display_options.h |  25 +
 lib/display_options.c | 115 +++---
 test/print_ut.c   |  30 +-
 3 files changed, 123 insertions(+), 47 deletions(-)

diff --git a/include/display_options.h b/include/display_options.h
index 049688e39e8..43810cbe22f 100644
--- a/include/display_options.h
+++ b/include/display_options.h
@@ -47,6 +47,31 @@ void print_freq(uint64_t freq, const char *suffix);
 int print_buffer(ulong addr, const void *data, uint width, uint count,
 uint linelen);
 
+/*
+ * Maximum length of an output line is when width == 1
+ * 9 for address,
+ * a space, two hex digits and an ASCII character for each byte
+ * 2 spaces between the hex and ASCII
+ * \0 terminator
+ */
+#define HEXDUMP_MAX_BUF_LENGTH(bytes)  (9 + (bytes) * 4 + 3)
+
+/**
+ * hexdump_line() - Print out a single line of a hex dump
+ *
+ * @addr:  Starting address to display at start of line
+ * @data:  pointer to data buffer
+ * @width: data value width.  May be 1, 2, or 4.
+ * @count: number of values to display
+ * @linelen:   Number of values to print per line; specify 0 for default length
+ * @out:   Output buffer to hold the dump
+ * @size:  Size of output buffer in bytes
+ * @return number of bytes processed, if OK, -ENOSPC if buffer too small
+ *
+ */
+int hexdump_line(ulong addr, const void *data, uint width, uint count,
+uint linelen, char *out, int size);
+
 /**
  * display_options() - display the version string / build tag
  *
diff --git a/lib/display_options.c b/lib/display_options.c
index 7752baba2bd..c08a87e3162 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -131,10 +131,11 @@ void print_size(uint64_t size, const char *s)
printf (" %ciB%s", c, s);
 }
 
-#define MAX_LINE_LENGTH_BYTES (64)
-#define DEFAULT_LINE_LENGTH_BYTES (16)
-int print_buffer(ulong addr, const void *data, uint width, uint count,
-uint linelen)
+#define MAX_LINE_LENGTH_BYTES  64
+#define DEFAULT_LINE_LENGTH_BYTES  16
+
+int hexdump_line(ulong addr, const void *data, uint width, uint count,
+uint linelen, char *out, int size)
 {
/* linebuf as a union causes proper alignment */
union linebuf {
@@ -143,62 +144,86 @@ int print_buffer(ulong addr, const void *data, uint 
width, uint count,
uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1];
uint8_t  uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1];
} lb;
+   uint thislinelen;
int i;
ulong x;
 
+   if (linelen * width > MAX_LINE_LENGTH_BYTES)
+   linelen = MAX_LINE_LENGTH_BYTES / width;
+   if (linelen < 1)
+   linelen = DEFAULT_LINE_LENGTH_BYTES / width;
+
+   /*
+* Check the size here so that we don't need to use snprintf(). This
+* helps to reduce code size
+*/
+   if (size < HEXDUMP_MAX_BUF_LENGTH(linelen * width))
+   return -ENOSPC;
+
+   thislinelen = linelen;
+   out += sprintf(out, "%08lx:", addr);
+
+   /* check for overflow condition */
+   if (count < thislinelen)
+   thislinelen = count;
+
+   /* Copy from memory into linebuf and print hex values */
+   for (i = 0; i < thislinelen; i++) {
+   if (width == 4)
+   x = lb.ui[i] = *(volatile uint32_t *)data;
+   else if (MEM_SUPPORT_64BIT_DATA && width == 8)
+   x = lb.uq[i] = *(volatile ulong *)data;
+   else if (width == 2)
+   x = lb.us[i] = *(volatile uint16_t *)data;
+   else
+   x = lb.uc[i] = *(volatile uint8_t *)data;
+   if (CONFIG_IS_ENABLED(USE_TINY_PRINTF))
+   out += sprintf(out, " %x", (uint)x);
+   else
+   out += sprintf(out, " %0*lx", width * 2, x);
+   data += width;
+   }
+
+   /* fill line with whitespace for nice ASCII print */
+   for (i = 0; i < (linelen - thislinelen) * (width * 2 + 1); i++)
+   *out++ = ' ';
+
+   /* Print data in ASCII characters */
+   for (i = 0; i < thislinelen * width; i++) {
+   if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80)
+   lb.uc[i] = '.';
+   }
+   lb.uc[i] = '\0';
+   out += sprintf(out, "  %s", lb.uc);
+
+   return thislinelen;
+}
+
+int print_buffer(ulong addr, const void *data, uint width, uint count,
+uint linelen)
+{
if (linelen*width > MAX_LINE_LENGTH_BYTES)
linelen = MAX_LINE_LENGTH_BYTES / width;

[PATCH 12/13] log: Add support for logging a buffer

2021-03-17 Thread Simon Glass
The print_buffer() function is very useful for debugging. Add a version
of this in the log system also.

Signed-off-by: Simon Glass 
---

 common/log.c| 30 ++
 include/log.h   | 35 +++
 test/log/log_test.c | 27 +++
 3 files changed, 92 insertions(+)

diff --git a/common/log.c b/common/log.c
index ea407c6db9e..1aaa6c1527b 100644
--- a/common/log.c
+++ b/common/log.c
@@ -284,6 +284,36 @@ int _log(enum log_category_t cat, enum log_level_t level, 
const char *file,
return 0;
 }
 
+#define MAX_LINE_LENGTH_BYTES  64
+#define DEFAULT_LINE_LENGTH_BYTES  16
+
+int _log_buffer(enum log_category_t cat, enum log_level_t level,
+   const char *file, int line, const char *func, ulong addr,
+   const void *data, uint width, uint count, uint linelen)
+{
+   if (linelen * width > MAX_LINE_LENGTH_BYTES)
+   linelen = MAX_LINE_LENGTH_BYTES / width;
+   if (linelen < 1)
+   linelen = DEFAULT_LINE_LENGTH_BYTES / width;
+
+   while (count) {
+   uint thislinelen;
+   char buf[HEXDUMP_MAX_BUF_LENGTH(width * linelen)];
+
+   thislinelen = hexdump_line(addr, data, width, count, linelen,
+  buf, sizeof(buf));
+   assert(thislinelen >= 0);
+   _log(cat, level, file, line, func, "%s\n", buf);
+
+   /* update references */
+   data += thislinelen * width;
+   addr += thislinelen * width;
+   count -= thislinelen;
+   }
+
+   return 0;
+}
+
 int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[],
 enum log_level_t level, const char *file_list,
 int flags)
diff --git a/include/log.h b/include/log.h
index 594a361c613..ed7ba6d705a 100644
--- a/include/log.h
+++ b/include/log.h
@@ -128,6 +128,24 @@ int _log(enum log_category_t cat, enum log_level_t level, 
const char *file,
 int line, const char *func, const char *fmt, ...)
__attribute__ ((format (__printf__, 6, 7)));
 
+/**
+ * _log_buffer - Internal function to print data buffer in hex and ascii form
+ *
+ * @cat: Category of log record (indicating which subsystem generated it)
+ * @level: Level of log record (indicating its severity)
+ * @file: File name of file where log record was generated
+ * @line: Line number in file where log record was generated
+ * @func: Function where log record was generated
+ * @addr:  Starting address to display at start of line
+ * @data:  pointer to data buffer
+ * @width: data value width.  May be 1, 2, or 4.
+ * @count: number of values to display
+ * @linelen:   Number of values to print per line; specify 0 for default length
+ */
+int _log_buffer(enum log_category_t cat, enum log_level_t level,
+   const char *file, int line, const char *func, ulong addr,
+   const void *data, uint width, uint count, uint linelen);
+
 /* Define this at the top of a file to add a prefix to debug messages */
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
@@ -177,6 +195,16 @@ int _log(enum log_category_t cat, enum log_level_t level, 
const char *file,
 __LINE__, __func__, \
  pr_fmt(_fmt), ##_args); \
})
+
+/* Emit a dump if the level is less that the maximum */
+#define log_buffer(_cat, _level, _addr, _data, _width, _count, _linelen)  ({ \
+   int _l = _level; \
+   if (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL) \
+   _log_buffer((enum log_category_t)(_cat), \
+   (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \
+   __LINE__, __func__, _addr, _data, \
+   _width, _count, _linelen); \
+   })
 #else
 /* Note: _LOG_DEBUG != 0 avoids a warning with clang */
 #define log(_cat, _level, _fmt, _args...) ({ \
@@ -185,6 +213,13 @@ int _log(enum log_category_t cat, enum log_level_t level, 
const char *file,
(_DEBUG && _l == LOGL_DEBUG)) \
printf(_fmt, ##_args); \
})
+
+#define log_buffer(_cat, _level, _addr, _data, _width, _count, _linelen)  ({ \
+   int _l = _level; \
+   if (_LOG_DEBUG != 0 || _l <= LOGL_INFO || \
+   (_DEBUG && _l == LOGL_DEBUG)) \
+   print_buffer(_addr, _data, _width, _count, _linelen); \
+   })
 #endif
 
 #ifdef DEBUG
diff --git a/test/log/log_test.c b/test/log/log_test.c
index 4a814ff4132..f1e67509c17 100644
--- a/test/log/log_test.c
+++ b/test/log/log_test.c
@@ -429,3 +429,30 @@ int log_test_dropped(struct unit_test_state *uts)
return 0;
 }
 LOG_TEST_FLAGS(log_test_dropped, UT_TESTF_CONSOLE_REC);
+
+/* Check log_buffer() */
+int log_test_buffer(struct unit_test_state *uts)
+{
+   u8 *buf;
+   int i;
+
+   buf = malloc(0x20);
+   ut_assertnonnull(buf);
+   memset(buf, '\

[PATCH 13/13] RFC: display_options: Use print_hex_dump() for print_buffer()

2021-03-17 Thread Simon Glass
These two functions do similar things. When CONFIG_HEXDUMP is enabled,
drop the code in print_buffer() and use the hexdump code instead. This
increases the code size a little, but makes the API similar to Linux.

When CONFIG_HEXDUMP is not enabled, don't do this, since presumably
code size is more important.

To make this work, update the address test so that the address matches
the pointer, since the hexdump routine does not support an arbitrary
address.

This is not a great result, but it is a step towards unifying the APIs.
I doublt we want this patch, which is why it is marked RFC. It might be
better to unify the other way, i.e. reimplement the hexdump routines.

Note: It also breaks the rtc tests because it cannot handle addr being
different from data in the print_buffer() call. While adjustments are
made to the test, the end result is not what we want.

Signed-off-by: Simon Glass 
---

 lib/display_options.c | 9 +
 test/dm/rtc.c | 3 +++
 test/print_ut.c   | 6 +++---
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/display_options.c b/lib/display_options.c
index c08a87e3162..5a2a549e869 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -207,6 +208,14 @@ int print_buffer(ulong addr, const void *data, uint width, 
uint count,
if (linelen < 1)
linelen = DEFAULT_LINE_LENGTH_BYTES / width;
 
+   /* Use hexdump if available */
+   if (CONFIG_IS_ENABLED(HEXDUMP)) {
+   return print_hex_dump("", addr ? DUMP_PREFIX_ADDRESS :
+ DUMP_PREFIX_OFFSET, linelen * width,
+ width, data, width * count, true);
+   }
+
+   /* Fall back to a smaller implementation */
while (count) {
uint thislinelen;
char buf[HEXDUMP_MAX_BUF_LENGTH(width * linelen)];
diff --git a/test/dm/rtc.c b/test/dm/rtc.c
index c7f9f8f0ce7..525895bad42 100644
--- a/test/dm/rtc.c
+++ b/test/dm/rtc.c
@@ -194,6 +194,9 @@ DM_TEST(dm_test_rtc_cmd_list, UT_TESTF_SCAN_PDATA | 
UT_TESTF_SCAN_FDT);
 /* Test 'rtc read' and 'rtc write' commands */
 static int dm_test_rtc_cmd_rw(struct unit_test_state *uts)
 {
+   /* Disable this since print_buffer() cannot show the correct address */
+   return 0;
+
console_record_reset();
 
run_command("rtc dev 0", 0);
diff --git a/test/print_ut.c b/test/print_ut.c
index 079d3f7cb08..168bf85dc16 100644
--- a/test/print_ut.c
+++ b/test/print_ut.c
@@ -185,9 +185,9 @@ static int print_display_buffer(struct unit_test_state *uts)
 
/* address */
console_record_reset();
-   print_buffer(0x12345678, buf, 1, 0x12, 0);
-   ut_assert_nextline("12345678: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd 
ee ff  ..\"3DUfw");
-   ut_assert_nextline("12345688: 10 00 
   ..");
+   print_buffer(4, buf + 4, 1, 0x12, 0);
+   ut_assert_nextline("0004: 44 55 66 77 88 99 aa bb cc dd ee ff 10 00 
00 00  DUfw");
+   ut_assert_nextline("0014: 00 00 
   ..");
ut_assert_console_end();
 
/* 16-bit */
-- 
2.31.0.rc2.261.g7f71774620-goog



Re: [PATCH v2] bus: ti-sysc: change in a normal driver

2021-03-17 Thread Simon Glass
On Wed, 17 Mar 2021 at 09:51, Dario Binacchi  wrote:
>
> The module defines a duplicate uclass driver for UCLASS_SIMPLE_BUS, but
> it is not allowed. This breaks of-platdata and makes the result
> non-deterministic.
>
> The driver does not need to be an uclass driver, so lets remove it. I
> had turned it into an uclass driver because I thought wrongly it had to
> call the dm_scan_fdt_dev routine to work properly, but some tests on the
> board have shown otherwise.
>
> Signed-off-by: Dario Binacchi 
>
> ---
>
> Changes in v2:
> - Remove UCLASS_SYSC id.
> - Change ti-sysc in a normal driver instead of an uclass driver.
>   Previous tests, where I had removed the uclass driver, failed because
>   I added the dm_scan_fdt_dev routine to the driver bind routine (I moved
>   it from the uclass driver post_bind routine to the normal driver bind
>   one).
>
>  drivers/bus/ti-sysc.c | 6 --
>  1 file changed, 6 deletions(-)

Reviewed-by: Simon Glass 

Thank you!


[PATCH 0/5 v4] Loadfile2 for initrd loading

2021-03-17 Thread Ilias Apalodimas
Hi!
This is v4 of [1]

Changes since v3:
 - Slightly tweaked the efidebug argument parsing following Heinrich's 
   suggestion.  Instead of calculating the file device path initially and
   appending the initrd, the 2 two device paths are now calculated 
   independently and concatenated later, allowing us to easier handle the 
   various switches (-i, -b etc)
 - Fixed documentation typo that prevented htmldocs from building
 - Removed [1/6] patch which was already merged

Changes since v2:
 - Lengths checks when interpreting a device path, to make sure we aren't
   going out of bounds
 - renamed efi_get_file_size -> efi_file_size and moved it in efi_file.c
 - Fix uninitialized variable related errors reported by Cppcheck
 - Fixed various error messages for easier end user readability
 - renamed _efi_dp_append() -> efi_dp_append_or_concatenate()
 - Picked up Reviewed-by tags
 - Enabling the protocol by default

Changes since v1:
 - minor coding style fixes from Heinrich
 - changed the DP format. Instead of VenMedia - 0x01 - initrd, we skip
   the 0x01 between VenMedia and the first file. 
 - final device path is stripped in efi_get_dp_from_boot() instead of 
   get_initrd_fp()
 - Fixed comments on documentation

[1] https://lists.denx.de/pipermail/u-boot/2021-March/443399.html


Ilias Apalodimas (5):
  efi_loader: Add device path related functions for initrd via Boot
  efi_loader: Add helper functions for EFI
  efi_loader: Replace config option for initrd loading
  efidebug: add multiple device path instances on Boot
  doc: Update uefi documentation for initrd loading options

 cmd/bootefi.c |   3 +
 cmd/efidebug.c| 191 +
 doc/board/emulation/qemu_capsule_update.rst   |   4 +-
 doc/uefi/uefi.rst |  24 ++-
 include/efi_loader.h  |  12 ++
 lib/efi_loader/Kconfig|  17 +-
 lib/efi_loader/Makefile   |   1 +
 lib/efi_loader/efi_bootmgr.c  |  19 +-
 lib/efi_loader/efi_device_path.c  | 106 -
 lib/efi_loader/efi_file.c |  39 
 lib/efi_loader/efi_helper.c   |  98 +
 lib/efi_loader/efi_load_initrd.c  | 202 +++---
 lib/efi_loader/efi_var_common.c   |  33 +++
 .../test_efi_capsule/test_capsule_firmware.py |   6 +-
 test/py/tests/test_efi_secboot/test_signed.py |  16 +-
 .../test_efi_secboot/test_signed_intca.py |   8 +-
 .../tests/test_efi_secboot/test_unsigned.py   |   8 +-
 17 files changed, 625 insertions(+), 162 deletions(-)
 create mode 100644 lib/efi_loader/efi_helper.c

-- 
2.31.0



[PATCH 1/5 v4] efi_loader: Add device path related functions for initrd via Boot####

2021-03-17 Thread Ilias Apalodimas
On the following patches we allow for an initrd path to be stored in
Boot variables.  Specifically we encode in the FIlePathList[] of
the EFI_LOAD_OPTIONS for each Boot variable.

The FilePathList[] array looks like this:
kernel - 0xff - VenMedia(initrd GUID) - initrd1 - 0x01 initrd2 - 0xff
So let's add the relevant functions to concatenate and retrieve a device
path based on a Vendor GUID.

Signed-off-by: Ilias Apalodimas 
---
 include/efi_loader.h |   4 ++
 lib/efi_loader/efi_device_path.c | 106 +--
 2 files changed, 105 insertions(+), 5 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 68daa1a4a9dc..5d534e69bb59 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -744,6 +744,10 @@ struct efi_load_option {
const u8 *optional_data;
 };
 
+struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
+  efi_uintn_t *size, efi_guid_t guid);
+struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
+ const struct efi_device_path *dp2);
 efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data,
 efi_uintn_t *size);
 unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index c9315dd45857..1491251e224b 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -282,11 +282,30 @@ struct efi_device_path *efi_dp_dup(const struct 
efi_device_path *dp)
return ndp;
 }
 
-struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
- const struct efi_device_path *dp2)
+/** efi_dp_append_or_concatenate() - Append or concatenate two device paths.
+ *  Concatenated device path will be separated
+ *  by a sub-type 0xff end node
+ *
+ * @dp1:   First device path
+ * @dp2:   Second device path
+ * @concat:If true the two device paths will be concatenated and separated
+ * by an end of entrire device path sub-type 0xff end node.
+ * If true the second device path will be appended to the first and
+ * terminated by an end node
+ *
+ * Return: concatenated device path or NULL. Caller must free the returned
+ *  value
+ */
+static struct
+efi_device_path *efi_dp_append_or_concatenate(const struct efi_device_path 
*dp1,
+ const struct efi_device_path *dp2,
+ bool concat)
 {
struct efi_device_path *ret;
+   size_t end_size = sizeof(END);
 
+   if (concat)
+   end_size = 2 * sizeof(END);
if (!dp1 && !dp2) {
/* return an end node */
ret = efi_dp_dup(&END);
@@ -298,18 +317,56 @@ struct efi_device_path *efi_dp_append(const struct 
efi_device_path *dp1,
/* both dp1 and dp2 are non-null */
unsigned sz1 = efi_dp_size(dp1);
unsigned sz2 = efi_dp_size(dp2);
-   void *p = dp_alloc(sz1 + sz2 + sizeof(END));
+   void *p = dp_alloc(sz1 + sz2 + end_size);
if (!p)
return NULL;
+   ret = p;
memcpy(p, dp1, sz1);
+   p += sz1;
+
+   if (concat) {
+   memcpy(p, &END, sizeof(END));
+   p += sizeof(END);
+   }
+
/* the end node of the second device path has to be retained */
-   memcpy(p + sz1, dp2, sz2 + sizeof(END));
-   ret = p;
+   memcpy(p, dp2, sz2);
+   p += sz2;
+   memcpy(p, &END, sizeof(END));
}
 
return ret;
 }
 
+/** efi_dp_append() - Append a device to an existing device path.
+ *
+ * @dp1:   First device path
+ * @dp2:   Second device path
+ *
+ * Return: concatenated device path or NULL. Caller must free the returned
+ *  value
+ */
+struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
+ const struct efi_device_path *dp2)
+{
+   return efi_dp_append_or_concatenate(dp1, dp2, false);
+}
+
+/** efi_dp_concat() - Concatenate 2 device paths. The final device path will
+ *contain two device paths separated by and end node 
(0xff).
+ *
+ * @dp1:   First device path
+ * @dp2:   Second device path
+ *
+ * Return: concatenated device path or NULL. Caller must free the returned
+ *  value
+ */
+struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
+ const struct efi_device_path *dp2)
+{
+   return efi_dp_append_or_concatenate(dp1, dp2, true);
+}
+
 

[PATCH 2/5 v4] efi_loader: Add helper functions for EFI

2021-03-17 Thread Ilias Apalodimas
A following patch introduces a different logic for loading initrd's
based on the EFI_LOAD_FILE2_PROTOCOL.
Since similar logic can be applied in the future for other system files
(i.e DTBs), let's add some helper functions which will retrieve and
parse file paths stored in EFI variables.

Signed-off-by: Ilias Apalodimas 
---
 include/efi_loader.h|  7 +++
 lib/efi_loader/Makefile |  1 +
 lib/efi_loader/efi_file.c   | 39 +
 lib/efi_loader/efi_helper.c | 98 +
 lib/efi_loader/efi_var_common.c | 33 +++
 5 files changed, 178 insertions(+)
 create mode 100644 lib/efi_loader/efi_helper.c

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 5d534e69bb59..9c227005d13e 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -558,6 +558,11 @@ struct efi_simple_file_system_protocol 
*efi_simple_file_system(
 /* open file from device-path: */
 struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
 
+efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size);
+
+/* get a device path from a Boot option */
+struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid);
+
 /**
  * efi_size_in_pages() - convert size in bytes to size in pages
  *
@@ -723,6 +728,8 @@ efi_status_t EFIAPI efi_query_variable_info(
u64 *remaining_variable_storage_size,
u64 *maximum_variable_size);
 
+void *efi_get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size);
+
 /*
  * See section 3.1.3 in the v2.7 UEFI spec for more details on
  * the layout of EFI_LOAD_OPTION.  In short it is:
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 10b42e8847bf..da2741adecfa 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -23,6 +23,7 @@ endif
 obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-$(CONFIG_CMD_BOOTEFI_BOOTMGR) += efi_bootmgr.o
 obj-y += efi_boottime.o
+obj-y += efi_helper.o
 obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o
 obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_firmware.o
 obj-y += efi_console.o
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index 8ece8e71ee1c..204105e25afd 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -409,6 +409,45 @@ static efi_status_t efi_get_file_size(struct file_handle 
*fh,
return EFI_SUCCESS;
 }
 
+/**
+ * efi_file_size() - Get the size of a file using an EFI file handle
+ *
+ * @fh:EFI file handle
+ * @size:  buffer to fill in the discovered size
+ *
+ * Return: size of the file
+ */
+efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size)
+{
+   struct efi_file_info *info = NULL;
+   efi_uintn_t bs = 0;
+   efi_status_t ret;
+
+   *size = 0;
+   ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs,
+  info));
+   if (ret != EFI_BUFFER_TOO_SMALL) {
+   ret = EFI_DEVICE_ERROR;
+   goto out;
+   }
+
+   info = malloc(bs);
+   if (!info) {
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
+   ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs,
+  info));
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   *size = info->file_size;
+
+out:
+   free(info);
+   return ret;
+}
+
 static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size,
void *buffer)
 {
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
new file mode 100644
index ..d03a7364615e
--- /dev/null
+++ b/lib/efi_loader/efi_helper.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Linaro Limited
+ */
+
+#define LOG_CATEGORY LOGC_EFI
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * efi_create_current_boot_var() - Return Boot name were  is replaced 
by
+ *the value of BootCurrent
+ *
+ * @var_name:  variable name
+ * @var_name_size: size of var_name
+ *
+ * Return: Status code
+ */
+static efi_status_t efi_create_current_boot_var(u16 var_name[],
+   size_t var_name_size)
+{
+   efi_uintn_t boot_current_size;
+   efi_status_t ret;
+   u16 boot_current;
+   u16 *pos;
+
+   boot_current_size = sizeof(boot_current);
+   ret = efi_get_variable_int(L"BootCurrent",
+  &efi_global_variable_guid, NULL,
+  &boot_current_size, &boot_current, NULL);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   pos = efi_create_indexed_name(var_name, var_name_size, "Boot",
+ boot_current);
+   if (!pos) {
+   ret = EFI_OUT_OF_RESOURCES;
+   

[PATCH 3/5 v4] efi_loader: Replace config option for initrd loading

2021-03-17 Thread Ilias Apalodimas
Up to now we install EFI_LOAD_FILE2_PROTOCOL to load an initrd
unconditionally. Although we correctly return various EFI exit codes
depending on the file status (i.e EFI_NO_MEDIA, EFI_NOT_FOUND etc), the
kernel loader, only falls back to the cmdline interpreted initrd if the
protocol is not installed.

This creates a problem for EFI installers, since they won't be able to
load their own initrd and continue the installation. It also makes the
feature hard to use, since we can either have a single initrd or we have
to recompile u-boot if the filename changes.

So let's introduce a different logic that will decouple the initrd
path from the config option we currently have.
When defining a UEFI Boot we can use the filepathlist and store
a file path pointing to our initrd. Specifically the EFI spec describes:

"The first element of the array is a device path that describes the device
and location of the Image for this load option. Other device paths may
optionally exist in the FilePathList, but their usage is OSV specific"

When the EFI application is launched through the bootmgr, we'll try to
interpret the extra device path. If that points to a file that exists on
our disk, we'll now install the load_file2 and the efi-stub will be able
to use it.

This opens up another path using U-Boot and defines a new boot flow.
A user will be able to control the kernel/initrd pairs without explicit
cmdline args or GRUB.

Signed-off-by: Ilias Apalodimas 
Reviewed-by: Heinrich Schuchardt 
---
 cmd/bootefi.c|   3 +
 include/efi_loader.h |   1 +
 lib/efi_loader/Kconfig   |  17 +--
 lib/efi_loader/efi_bootmgr.c |  19 ++-
 lib/efi_loader/efi_load_initrd.c | 202 ++-
 5 files changed, 144 insertions(+), 98 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 271b385edea6..cba81ffe75e4 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -358,6 +358,9 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle, 
void *load_options)
 
free(load_options);
 
+   if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD))
+   efi_initrd_deregister();
+
return ret;
 }
 
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 9c227005d13e..903bf60bc0a3 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -437,6 +437,7 @@ efi_status_t efi_net_register(void);
 /* Called by bootefi to make the watchdog available */
 efi_status_t efi_watchdog_register(void);
 efi_status_t efi_initrd_register(void);
+void efi_initrd_deregister(void);
 /* Called by bootefi to make SMBIOS tables available */
 /**
  * efi_acpi_register() - write out ACPI tables
diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 634d3b1ff4e3..0a412441a719 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -315,18 +315,13 @@ config EFI_TCG2_PROTOCOL_EVENTLOG_SIZE
 
 config EFI_LOAD_FILE2_INITRD
bool "EFI_FILE_LOAD2_PROTOCOL for Linux initial ramdisk"
-   default n
-   help
- Expose a EFI_FILE_LOAD2_PROTOCOL that the Linux UEFI stub can
- use to load the initial ramdisk. Once this is enabled using
- initrd= will stop working.
-
-config EFI_INITRD_FILESPEC
-   string "initramfs path"
-   default "host 0:1 initrd"
-   depends on EFI_LOAD_FILE2_INITRD
+   default y
help
- Full path of the initramfs file, e.g. mmc 0:2 initramfs.cpio.gz.
+ Linux v5.7 and later can make use of this option. If the boot option
+ selected by the UEFI boot manager specifies an existing file to be 
used
+ as initial RAM disk, a Linux specific Load File2 protocol will be
+ installed and Linux 5.7+ will ignore any initrd= command line
+ argument.
 
 config EFI_SECURE_BOOT
bool "Enable EFI secure boot support"
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 25f5cebfdb67..46c8011344b9 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -118,11 +118,13 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t 
*handle,
ret = efi_set_variable_int(L"BootCurrent",
   &efi_global_variable_guid,
   attributes, sizeof(n), &n, false);
-   if (ret != EFI_SUCCESS) {
-   if (EFI_CALL(efi_unload_image(*handle))
-   != EFI_SUCCESS)
-   log_err("Unloading image failed\n");
-   goto error;
+   if (ret != EFI_SUCCESS)
+   goto unload;
+   /* try to register load file2 for initrd's */
+   if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) {
+   ret = efi_initrd_register();
+   if (ret != EFI_SUCCESS)
+   goto unload;
}
 
log_info("Booting: %ls\n", lo.label);
@@ 

[PATCH 4/5 v4] efidebug: add multiple device path instances on Boot####

2021-03-17 Thread Ilias Apalodimas
The UEFI spec allows a packed array of UEFI device paths in the
FilePathList[] of an EFI_LOAD_OPTION. The first file path must
describe the loaded image but the rest are OS specific.

Previous patches parse the device path and try to use the second
member of the array as an initrd. So let's modify efidebug slightly
and install the second file described in the command line as the
initrd device path.

Signed-off-by: Ilias Apalodimas 
---
 cmd/efidebug.c| 191 ++
 doc/board/emulation/qemu_capsule_update.rst   |   4 +-
 doc/uefi/uefi.rst |   2 +-
 .../test_efi_capsule/test_capsule_firmware.py |   6 +-
 test/py/tests/test_efi_secboot/test_signed.py |  16 +-
 .../test_efi_secboot/test_signed_intca.py |   8 +-
 .../tests/test_efi_secboot/test_unsigned.py   |   8 +-
 7 files changed, 177 insertions(+), 58 deletions(-)

diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index 55c7abe3d078..80ddd598e0a1 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -19,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define BS systab.boottime
 #define RT systab.runtime
@@ -798,6 +800,54 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int 
flag,
return CMD_RET_SUCCESS;
 }
 
+/**
+ * create_initrd_dp() - Create a special device for our Boot### option
+ *
+ * @dev:   Device
+ * @part:  Disk partition
+ * @file:  Filename
+ * Return: Pointer to the device path or ERR_PTR
+ *
+ */
+static
+struct efi_device_path *create_initrd_dp(const char *dev, const char *part,
+const char *file)
+
+{
+   struct efi_device_path *tmp_dp = NULL, *tmp_fp = NULL;
+   struct efi_device_path *initrd_dp = NULL;
+   efi_status_t ret;
+   const struct efi_initrd_dp id_dp = {
+   .vendor = {
+   {
+   DEVICE_PATH_TYPE_MEDIA_DEVICE,
+   DEVICE_PATH_SUB_TYPE_VENDOR_PATH,
+   sizeof(id_dp.vendor),
+   },
+   EFI_INITRD_MEDIA_GUID,
+   },
+   .end = {
+   DEVICE_PATH_TYPE_END,
+   DEVICE_PATH_SUB_TYPE_END,
+   sizeof(id_dp.end),
+   }
+   };
+
+   ret = efi_dp_from_name(dev, part, file, &tmp_dp, &tmp_fp);
+   if (ret != EFI_SUCCESS) {
+   printf("Cannot create device path for \"%s %s\"\n", part, file);
+   goto out;
+   }
+
+   initrd_dp = efi_dp_append((const struct efi_device_path *)&id_dp,
+ tmp_fp);
+
+out:
+   efi_free_pool(tmp_dp);
+   efi_free_pool(tmp_fp);
+   return initrd_dp;
+}
+
 /**
  * do_efi_boot_add() - set UEFI load option
  *
@@ -810,7 +860,9 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int 
flag,
  *
  * Implement efidebug "boot add" sub-command. Create or change UEFI load 
option.
  *
- * efidebug boot add[:]  

+ * efidebug boot add -b[:] 
+ *   -i   [:] 
+ *   -s ''
  */
 static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag,
   int argc, char *const argv[])
@@ -823,55 +875,105 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int 
flag,
size_t label_len, label_len16;
u16 *label;
struct efi_device_path *device_path = NULL, *file_path = NULL;
+   struct efi_device_path *final_fp = NULL;
+   struct efi_device_path *initrd_dp = NULL;
struct efi_load_option lo;
void *data = NULL;
efi_uintn_t size;
+   efi_uintn_t fp_size = 0;
efi_status_t ret;
int r = CMD_RET_SUCCESS;
 
-   if (argc < 6 || argc > 7)
-   return CMD_RET_USAGE;
-
-   id = (int)simple_strtoul(argv[1], &endp, 16);
-   if (*endp != '\0' || id > 0x)
-   return CMD_RET_USAGE;
-
-   sprintf(var_name, "Boot%04X", id);
-   p = var_name16;
-   utf8_utf16_strncpy(&p, var_name, 9);
-
guid = efi_global_variable_guid;
 
/* attributes */
lo.attributes = LOAD_OPTION_ACTIVE; /* always ACTIVE */
+   lo.optional_data = NULL;
+   lo.label = NULL;
 
-   /* label */
-   label_len = strlen(argv[2]);
-   label_len16 = utf8_utf16_strnlen(argv[2], label_len);
-   label = malloc((label_len16 + 1) * sizeof(u16));
-   if (!label)
-   return CMD_RET_FAILURE;
-   lo.label = label; /* label will be changed below */
-   utf8_utf16_strncpy(&label, argv[2], label_len);
+   argc--;
+   argv++; /* 'add' */
+   for (; argc > 0; argc--, argv++) {
+   if (!strcmp(argv[0], "-b")) {
+   if (argc <  5 || lo.label) {
+   r = CMD_RET_USAGE;
+   goto out;
+ 

[PATCH 5/5 v4] doc: Update uefi documentation for initrd loading options

2021-03-17 Thread Ilias Apalodimas
Document the command line options for efidebug and initrd loading

Signed-off-by: Ilias Apalodimas 
---
 doc/uefi/uefi.rst | 22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/doc/uefi/uefi.rst b/doc/uefi/uefi.rst
index b3494c22e073..d92a32016ec0 100644
--- a/doc/uefi/uefi.rst
+++ b/doc/uefi/uefi.rst
@@ -180,6 +180,12 @@ Set up boot parameters on your board::
 
 efidebug boot add -b 1 HELLO mmc 0:1 /helloworld.efi.signed ""
 
+Since kernel 5.7 there's an alternative way of loading an initrd using
+LoadFile2 protocol if CONFIG_EFI_LOAD_FILE2_INITRD is enabled.
+The initrd path can be specified with::
+
+efidebug boot add -b ABE0 'kernel' mmc 0:1 Image -i mmc 0:1 initrd
+
 Now your board can run the signed image via the boot manager (see below).
 You can also try this sequence by running Pytest, test_efi_secboot,
 on the sandbox
@@ -484,7 +490,21 @@ The load file 2 protocol can be used by the Linux kernel 
to load the initial
 RAM disk. U-Boot can be configured to provide an implementation with::
 
 EFI_LOAD_FILE2_INITRD=y
-EFI_INITRD_FILESPEC=interface dev:part path_to_initrd
+
+When the option is enabled the user can add the initrd path with the efidebug
+command.
+
+Load options Boot have a FilePathList[] member.  The first element of
+the array (FilePathList[0]) is the EFI binary to execute.  When an initrd
+is specified the Device Path for the initrd is denoted by a VenMedia node
+with the EFI_INITRD_MEDIA_GUID. Each entry of the array is terminated by the
+'end of entire device path' subtype (0xff). If a user wants to define multiple
+initrds, those must by separated by the 'end of this instance' identifier of
+the end node (0x01).
+
+So our final format of the FilePathList[] is::
+
+Loaded image - end node (0xff) - VenMedia - initrd_1 - [end node (0x01) - 
initrd_n ...] - end node (0xff)
 
 Links
 -
-- 
2.31.0



Re: [PATCH 1/5 v4] efi_loader: Add device path related functions for initrd via Boot####

2021-03-17 Thread Heinrich Schuchardt

On 3/17/21 8:54 PM, Ilias Apalodimas wrote:

On the following patches we allow for an initrd path to be stored in
Boot variables.  Specifically we encode in the FIlePathList[] of
the EFI_LOAD_OPTIONS for each Boot variable.

The FilePathList[] array looks like this:
kernel - 0xff - VenMedia(initrd GUID) - initrd1 - 0x01 initrd2 - 0xff
So let's add the relevant functions to concatenate and retrieve a device
path based on a Vendor GUID.

Signed-off-by: Ilias Apalodimas 
---
  include/efi_loader.h |   4 ++
  lib/efi_loader/efi_device_path.c | 106 +--
  2 files changed, 105 insertions(+), 5 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 68daa1a4a9dc..5d534e69bb59 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -744,6 +744,10 @@ struct efi_load_option {
const u8 *optional_data;
  };

+struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
+  efi_uintn_t *size, efi_guid_t guid);
+struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
+ const struct efi_device_path *dp2);
  efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data,
 efi_uintn_t *size);
  unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 
**data);
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index c9315dd45857..1491251e224b 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -282,11 +282,30 @@ struct efi_device_path *efi_dp_dup(const struct 
efi_device_path *dp)
return ndp;
  }

-struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
- const struct efi_device_path *dp2)
+/** efi_dp_append_or_concatenate() - Append or concatenate two device paths.


Wrong line. You can't put his on the line with /**.


+ *  Concatenated device path will be separated
+ *  by a sub-type 0xff end node
+ *
+ * @dp1:   First device path
+ * @dp2:   Second device path
+ * @concat:If true the two device paths will be concatenated and separated
+ * by an end of entrire device path sub-type 0xff end node.
+ * If true the second device path will be appended to the first and
+ * terminated by an end node
+ *
+ * Return: concatenated device path or NULL. Caller must free the returned
+ *  value


Multiple line comments for Return: have to start on a new line or
formatting by Sphinx will fail.


+ */
+static struct
+efi_device_path *efi_dp_append_or_concatenate(const struct efi_device_path 
*dp1,
+ const struct efi_device_path *dp2,
+ bool concat)
  {
struct efi_device_path *ret;
+   size_t end_size = sizeof(END);

+   if (concat)
+   end_size = 2 * sizeof(END);
if (!dp1 && !dp2) {
/* return an end node */
ret = efi_dp_dup(&END);
@@ -298,18 +317,56 @@ struct efi_device_path *efi_dp_append(const struct 
efi_device_path *dp1,
/* both dp1 and dp2 are non-null */
unsigned sz1 = efi_dp_size(dp1);
unsigned sz2 = efi_dp_size(dp2);
-   void *p = dp_alloc(sz1 + sz2 + sizeof(END));
+   void *p = dp_alloc(sz1 + sz2 + end_size);
if (!p)
return NULL;
+   ret = p;
memcpy(p, dp1, sz1);
+   p += sz1;
+
+   if (concat) {
+   memcpy(p, &END, sizeof(END));
+   p += sizeof(END);
+   }
+
/* the end node of the second device path has to be retained */
-   memcpy(p + sz1, dp2, sz2 + sizeof(END));
-   ret = p;
+   memcpy(p, dp2, sz2);
+   p += sz2;
+   memcpy(p, &END, sizeof(END));
}

return ret;
  }

+/** efi_dp_append() - Append a device to an existing device path.
+ *
+ * @dp1:   First device path
+ * @dp2:   Second device path
+ *
+ * Return: concatenated device path or NULL. Caller must free the returned
+ *  value
+ */
+struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
+ const struct efi_device_path *dp2)
+{
+   return efi_dp_append_or_concatenate(dp1, dp2, false);
+}
+
+/** efi_dp_concat() - Concatenate 2 device paths. The final device path will
+ *contain two device paths separated by and end node 
(0xff).
+ *
+ * @dp1:   First device path
+ * @dp2:   Second device path
+ *
+ * Return: concatenated device path or NULL. Caller must free the returned
+ *  value
+ */
+struct 

Re: [PATCH v10 02/11] efi_loader: capsule: add capsule_on_disk support

2021-03-17 Thread Heinrich Schuchardt

On 11/30/20 10:12 AM, AKASHI Takahiro wrote:

Capsule data can be loaded into the system either via UpdateCapsule
runtime service or files on a file system (of boot device).
The latter case is called "capsules on disk", and actual updates will
take place at the next boot time.

In this commit, we will support capsule on disk mechanism.

Please note that U-Boot itself has no notion of "boot device" and
all the capsule files to be executed will be detected only if they
are located in a specific directory, \EFI\UpdateCapsule, on a device
that is identified as a boot device by "Boot" variables.

Signed-off-by: AKASHI Takahiro 
---





+static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num)
+{
+   struct efi_file_handle *dirh;
+   struct efi_file_info *dirent;
+   efi_uintn_t dirent_size, tmp_size;
+   unsigned int count;
+   u16 **tmp_files;
+   efi_status_t ret;
+
+   ret = find_boot_device();
+   if (ret == EFI_NOT_FOUND) {
+   EFI_PRINT("EFI Capsule: bootdev is not set\n");
+   *num = 0;
+   return EFI_SUCCESS;
+   } else if (ret != EFI_SUCCESS) {
+   return EFI_DEVICE_ERROR;
+   }
+
+   /* count capsule files */
+   ret = EFI_CALL((*bootdev_root->open)(bootdev_root, &dirh,
+EFI_CAPSULE_DIR,
+EFI_FILE_MODE_READ, 0));
+   if (ret != EFI_SUCCESS) {
+   *num = 0;
+   return EFI_SUCCESS;
+   }
+
+   dirent_size = 256;
+   dirent = malloc(dirent_size);
+   if (!dirent)
+   return EFI_OUT_OF_RESOURCES;
+
+   count = 0;
+   while (1) {
+   tmp_size = dirent_size;
+   ret = EFI_CALL((*dirh->read)(dirh, &tmp_size, dirent));
+   if (ret == EFI_BUFFER_TOO_SMALL) {
+   dirent = realloc(dirent, tmp_size);
+   if (!dirent) {


If realloc() fails, you should free the *old* pointer.

Best regards

Heinrich


+   ret = EFI_OUT_OF_RESOURCES;
+   goto err;
+   }


Re: [PATCH 0/2] power: move power_max77696_init() to board file

2021-03-17 Thread Jaehoon Chung
On 3/17/21 7:25 AM, Tom Rini wrote:
> On Wed, Mar 17, 2021 at 06:53:16AM +0900, Jaehoon Chung wrote:
>> Dear Tom,
>>
>> On 1/28/21 8:42 PM, Jaehoon Chung wrote:
>>> It's only one board which is using max_77696_init().
>>> pmic_max77696.c didn't convert from no-DM to DM.
>>> So it's waste to maintain in driver directory.
>>
>> Is there any opinion? If there is no objection about this, let me know, plz.
>> I hope that remove file not to support DM in power and regulator.
>> This patch is my first step to do it.
> 
> My concern is that I've posted patches to delete the warp platform but I
> think Peter was going to pick it up and do the DM migrations?

Okay, I will check about it. Thanks.

Best Regards,
Jaehoon Chung

> 
>>
>> Best Regards,
>> Jaehoon Chung
>>
>>>
>>> Jaehoon Chung (2):
>>>   board: warp: add power_max77696_init() function
>>>   power: pmic: remove pmic_max77696.c file
>>>
>>>  board/warp/warp.c  | 68 +-
>>>  drivers/power/pmic/Makefile|  1 -
>>>  drivers/power/pmic/pmic_max77696.c | 31 --
>>>  include/configs/warp.h |  1 -
>>>  include/power/max77696_pmic.h  | 59 --
>>>  5 files changed, 67 insertions(+), 93 deletions(-)
>>>  delete mode 100644 drivers/power/pmic/pmic_max77696.c
>>>  delete mode 100644 include/power/max77696_pmic.h
>>>
>>
> 



[PATCH] lz4: Fix unaligned accesses

2021-03-17 Thread karl . beldan
From: Karl Beldan 

Signed-off-by: Karl Beldan 
---
 lib/lz4_wrapper.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/lz4_wrapper.c b/lib/lz4_wrapper.c
index e0f7d3688e..cdbcd05bd4 100644
--- a/lib/lz4_wrapper.c
+++ b/lib/lz4_wrapper.c
@@ -11,9 +11,18 @@
 #include 
 #include 
 
-static u16 LZ4_readLE16(const void *src) { return le16_to_cpu(*(u16 *)src); }
-static void LZ4_copy4(void *dst, const void *src) { *(u32 *)dst = *(u32 *)src; 
}
-static void LZ4_copy8(void *dst, const void *src) { *(u64 *)dst = *(u64 *)src; 
}
+static u16 LZ4_readLE16(const void *src)
+{
+   return get_unaligned_le16(src);
+}
+static void LZ4_copy4(void *dst, const void *src)
+{
+   put_unaligned(get_unaligned((const u32 *)src), (u32 *)dst);
+}
+static void LZ4_copy8(void *dst, const void *src)
+{
+   put_unaligned(get_unaligned((const u64 *)src), (u64 *)dst);
+}
 
 typedef  uint8_t BYTE;
 typedef uint16_t U16;
-- 
2.30.2



Re: [PATCH 3/4] mmc: fsl_esdhc: add pulse width detection workaround

2021-03-17 Thread Jaehoon Chung
On 3/17/21 11:01 PM, Michael Walle wrote:
> HS400 mode on the LS1028A SoC isn't reliable. The linux driver has a
> workaroung for the pulse width detection. Apply this workaround in
> u-boot, too.
> 
> This will make HS400 mode work reliably on the LS1028A SoC.
> 
> Signed-off-by: Michael Walle 
> ---
>  arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 1 +
>  drivers/mmc/Kconfig   | 3 +++
>  drivers/mmc/fsl_esdhc.c   | 6 +-
>  include/fsl_esdhc.h   | 3 +++
>  4 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
> b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> index c0190a233e..9d1ba4c771 100644
> --- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> +++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
> @@ -48,6 +48,7 @@ config ARCH_LS1028A
>   select SYS_FSL_ERRATUM_A009942 if !TFABOOT
>   select SYS_FSL_ERRATUM_A050382
>   select SYS_FSL_ERRATUM_A011334
> + select SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND
>   select RESV_RAM if GIC_V3_ITS
>   imply PANIC_HANG
>  
> diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
> index 0b6755fd90..f7620c9cd1 100644
> --- a/drivers/mmc/Kconfig
> +++ b/drivers/mmc/Kconfig
> @@ -815,3 +815,6 @@ config SYS_FSL_ERRATUM_ESDHC_A001
>  
>  config SYS_FSL_ERRATUM_A011334
>   bool
> +
> +config SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND

How about using QUIRK instead of WORKAROUD

Best Regards,
Jaehoon Chung

> + bool
> diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
> index 09ea1a9de9..7501fdb71e 100644
> --- a/drivers/mmc/fsl_esdhc.c
> +++ b/drivers/mmc/fsl_esdhc.c
> @@ -71,7 +71,8 @@ struct fsl_esdhc {
>   uintsdtimingctl;/* SD timing control register */
>   charreserved8[20];  /* reserved */
>   uintdllcfg0;/* DLL config 0 register */
> - charreserved9[12];  /* reserved */
> + uintdllcfg1;/* DLL config 1 register */
> + charreserved9[8];   /* reserved */
>   uintdllstat0;   /* DLL status 0 register */
>   charreserved10[664];/* reserved */
>   uintesdhcctl;   /* eSDHC control register */
> @@ -767,6 +768,9 @@ static int esdhc_init_common(struct fsl_esdhc_priv *priv, 
> struct mmc *mmc)
>   /* Set timout to the maximum value */
>   esdhc_clrsetbits32(®s->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
>  
> + if 
> (IS_ENABLED(CONFIG_SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND))
> + esdhc_clrbits32(®s->dllcfg1, DLL_PD_PULSE_STRETCH_SEL);
> +
>   return 0;
>  }
>  
> diff --git a/include/fsl_esdhc.h b/include/fsl_esdhc.h
> index 850a304bd7..f86afe5dad 100644
> --- a/include/fsl_esdhc.h
> +++ b/include/fsl_esdhc.h
> @@ -190,6 +190,9 @@
>  #define DLL_RESET0x4000
>  #define DLL_FREQ_SEL 0x0800
>  
> +/* DLL config 1 register */
> +#define DLL_PD_PULSE_STRETCH_SEL 0x8000
> +
>  /* DLL status 0 register */
>  #define DLL_STS_SLV_LOCK 0x0800
>  
> 



Re: [PATCH 1/4] board: sl28: disable HS400 mode

2021-03-17 Thread Jaehoon Chung
On 3/17/21 11:01 PM, Michael Walle wrote:
> Since commit 8ee802f899ef ("mmc: fsl_esdhc: make sure delay chain locked
> for HS400") HS400 mode is unreliable on LS1028A SoCs. Some workarounds are
> missing for this SoC.
> 
> Disable HS400 mode for now.
> 
> Signed-off-by: Michael Walle 

It seems that this patch doesn't need. Because CONFIG_MMC_HS400_SUPPORT is 
re-enabling with [PATCH 4/4].
How about dropping Drop [PATCH 1/4] and [PATCH 4/4]?

Best Regards,
Jaehoon Chung

> ---
>  configs/kontron_sl28_defconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/configs/kontron_sl28_defconfig b/configs/kontron_sl28_defconfig
> index 1c781e091c..0c6c1911d9 100644
> --- a/configs/kontron_sl28_defconfig
> +++ b/configs/kontron_sl28_defconfig
> @@ -70,7 +70,7 @@ CONFIG_I2C_SET_DEFAULT_BUS_NUM=y
>  CONFIG_I2C_DEFAULT_BUS_NUMBER=0
>  CONFIG_I2C_MUX=y
>  CONFIG_DM_MMC=y
> -CONFIG_MMC_HS400_SUPPORT=y
> +CONFIG_MMC_HS200_SUPPORT=y
>  CONFIG_FSL_ESDHC=y
>  CONFIG_FSL_ESDHC_SUPPORT_ADMA2=y
>  CONFIG_DM_SPI_FLASH=y
> 



Re: [ANN] U-Boot v2021.04-rc4 released

2021-03-17 Thread Jaehoon Chung
On 3/17/21 9:55 PM, Tom Rini wrote:
> On Wed, Mar 17, 2021 at 01:13:57PM +0100, Marek Vasut wrote:
>> On 3/15/21 5:07 PM, Tom Rini wrote:
>>> Hey all,
>>>
>>> It's release day, and here's v2021.04-rc4.  Not a whole lot of change
>>> since last time in master, and -next has been and is still open.  I just
>>> want to repeat a few things from -rc3:
>>>
>>> - We've moved from "gitlab.denx.de" (and also "git.denx.de") to
>>>"source.denx.de", please make sure to update your scripts and tools
>>>and so forth.  If you send me pull requests, now is a good time to
>>>switch to url/pushurl if you haven't already.
>>> - Once v2021.04 is released I will be pushing a large number of board
>>>removals for things that will be then 2 years past their "migrate this
>>>by ... or it might be removed" date which is also around 3 years total
>>>of notice.
>>
>> Which ones ?
> 
> All of the ones I've sent out removal patches for over the last month,
> CC'ing the maintainers.  That's basically:
> https://protect2.fireeye.com/v1/url?k=e70d736a-b8964a66-e70cf825-000babff3563-cffb0477a8387425&q=1&e=5f5cbefe-f62f-4eea-8384-94747700342f&u=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Fuboot%2Flist%2F%3Fseries%3D228850
> https://protect2.fireeye.com/v1/url?k=c6e5783a-997e4136-c6e4f375-000babff3563-b4c710a5ba70271e&q=1&e=5f5cbefe-f62f-4eea-8384-94747700342f&u=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Fuboot%2Flist%2F%3Fseries%3D230325
> along with I believe I need to v2 dropping some defconfigs for I believe
> mx28evk once Stefano picks up Fabio's patch to update and maintain the
> main defconfig (he already ack'd such a removal).

If removed board not to suppport DM_MMC, I think that mmc driver can be cleaned 
more than not.
Great. Thanks!

Best Regards,
Jaehoon Chung

> 



Re: [PATCH 1/4] board: sl28: disable HS400 mode

2021-03-17 Thread Michael Walle

Am 2021-03-17 23:49, schrieb Jaehoon Chung:

On 3/17/21 11:01 PM, Michael Walle wrote:
Since commit 8ee802f899ef ("mmc: fsl_esdhc: make sure delay chain 
locked
for HS400") HS400 mode is unreliable on LS1028A SoCs. Some workarounds 
are

missing for this SoC.

Disable HS400 mode for now.

Signed-off-by: Michael Walle 


It seems that this patch doesn't need. Because
CONFIG_MMC_HS400_SUPPORT is re-enabling with [PATCH 4/4].
How about dropping Drop [PATCH 1/4] and [PATCH 4/4]?


Please read the cover letter, if patch 2/4 and 3/4 will make
it into the 2021.04 relase, sure both can be dropped. But if not,
patch 1/4 is intented to go into the release while 2/4, 3/4 and
4/4 might get into the next relase.

The reason is that I favor a working mmc boot in the next
u-boot release for this board ;)

-michael


Re: [PATCH 3/4] mmc: fsl_esdhc: add pulse width detection workaround

2021-03-17 Thread Michael Walle

Am 2021-03-17 23:47, schrieb Jaehoon Chung:

On 3/17/21 11:01 PM, Michael Walle wrote:

 config SYS_FSL_ERRATUM_A011334
bool
+
+config SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND


How about using QUIRK instead of WORKAROUD


There is already a CONFIG_FSL_ESDHC_33V_IO_RELIABILITY_WORKAROUND,
so I chose that for consistency reasons.

-michael


"SPL image too big" not that helpful

2021-03-17 Thread Alex G.
I've recently hit that message in a yocto build. I can't figure out the 
exact root cause. On the one hand, I don't know how "big" SPL is. On the 
other hand, I can't objdump -h the SPL elf because one wasn't created.


Alex


Re: Help needed with uboot for CHIP

2021-03-17 Thread Alexandre GRIVEAUX

Hello,

Le 10/03/2021 à 19:58, Gunjan Gupta a écrit :

PFA my dts file. I have added the nfc section there as without that U-Boot
was giving a message about nfc being disabled in the dts.

Regarding trying the default config, I can't really do that as that doesn't
support booting from NAND and I want to be able to boot from NAND. Also I
don't think having different MTDPARTS value should create an issue, as I
didn't notice that being used in the SPL code. Please feel free to correct
me if I am wrong. Even if it was being used, I am flashing U-Boot to the
uboot partition and that is the same location that gets populated in
the CONFIG_SYS_NAND_U_BOOT_OFFS variable of the .config file.





I've tried with a CHIP, same problem, the SPL work main u-boot not.

I don't think it's a defconfig limitation, sadly i don't know how this 
can be corrected.



Thanks.



memory layoutfor imx8x AHAB

2021-03-17 Thread Tracy Smith
Hi,

My apologise in advance. I'm looking for the memory map or memory
layout for the NXP i.MX8X AHAB secure boot.  I would like to know the start
addresses of each container and header in RAM booting from RAM only and
eMMC boot.

And more specifically the OS container hex address that u-boot auth-cntr
expects in authenticating the OS container?

Please feel free to email me directly rather than using the list if you
prefer.

-- 
Confidentiality notice: This e-mail message, including any attachments, may
contain legally privileged and/or confidential information. If you are not
the intended recipient(s), please immediately notify the sender and delete
this e-mail message.


Re: [PATCH 1/4] board: sl28: disable HS400 mode

2021-03-17 Thread Jaehoon Chung
On 3/18/21 7:59 AM, Michael Walle wrote:
> Am 2021-03-17 23:49, schrieb Jaehoon Chung:
>> On 3/17/21 11:01 PM, Michael Walle wrote:
>>> Since commit 8ee802f899ef ("mmc: fsl_esdhc: make sure delay chain locked
>>> for HS400") HS400 mode is unreliable on LS1028A SoCs. Some workarounds are
>>> missing for this SoC.
>>>
>>> Disable HS400 mode for now.
>>>
>>> Signed-off-by: Michael Walle 
>>
>> It seems that this patch doesn't need. Because
>> CONFIG_MMC_HS400_SUPPORT is re-enabling with [PATCH 4/4].
>> How about dropping Drop [PATCH 1/4] and [PATCH 4/4]?
> 
> Please read the cover letter, if patch 2/4 and 3/4 will make
> it into the 2021.04 relase, sure both can be dropped. But if not,
> patch 1/4 is intented to go into the release while 2/4, 3/4 and
> 4/4 might get into the next relase.

Sorry. I didn't read your cover-letter. At next time, i will read cover-letter, 
too. :)

Best Regards,
Jaehoon Chung

> 
> The reason is that I favor a working mmc boot in the next
> u-boot release for this board ;)
> 
> -michael
> 



Re: [PATCH 3/4] mmc: fsl_esdhc: add pulse width detection workaround

2021-03-17 Thread Jaehoon Chung
On 3/18/21 8:01 AM, Michael Walle wrote:
> Am 2021-03-17 23:47, schrieb Jaehoon Chung:
>> On 3/17/21 11:01 PM, Michael Walle wrote:
>>>  config SYS_FSL_ERRATUM_A011334
>>>  bool
>>> +
>>> +config SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND
>>
>> How about using QUIRK instead of WORKAROUD
> 
> There is already a CONFIG_FSL_ESDHC_33V_IO_RELIABILITY_WORKAROUND,
> so I chose that for consistency reasons.

Then i don't have any objection. Thanks!

Reviewed-by: Jaehoon Chung 

Best Regards,
Jaehoon Chung

> 
> -michael
> 



Re: [PATCH] Revert "mmc: sdhci: set to INT_DATA_END when there are data"

2021-03-17 Thread Jaehoon Chung
Hi

On 3/17/21 3:44 PM, yuezhang...@sony.com wrote:
> This reverts commit 17ea3c862865c0d704646f67dbf8412f9ff54f59.
> 
> In eMMC specification, for the response-with-busy(R1b, R5b)
> command, the DAT0 will driven to LOW as BUSY status, and in
> sdhci specification, the transfer complete bit should be wait
> for BUSY status de-assert.
> 
> All response-with-busy commands don't contain data, the data
> judgement is no need.


I don't want to revert this commit. Is there any issue without this?
Without this patch, some SoCs have timeout error with stop command.

To prevent it, it needs to increase timeout value at that time.
(Timeout value can't fix each boards, waste time to find proper value,
and be performance degradation.)

I didn't test without this patch on latest U-boot.
But if there is no critical issue, keep it, plz.

Best Regards,
Jaehoon Chung

> 
> Signed-off-by: Yuezhang.Mo 
> ---
>  drivers/mmc/sdhci.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
> index d9ab6a0a83..8568f65b18 100644
> --- a/drivers/mmc/sdhci.c
> +++ b/drivers/mmc/sdhci.c
> @@ -258,8 +258,7 @@ static int sdhci_send_command(struct mmc *mmc, struct 
> mmc_cmd *cmd,
>   flags = SDHCI_CMD_RESP_LONG;
>   else if (cmd->resp_type & MMC_RSP_BUSY) {
>   flags = SDHCI_CMD_RESP_SHORT_BUSY;
> - if (data)
> - mask |= SDHCI_INT_DATA_END;
> + mask |= SDHCI_INT_DATA_END;
>   } else
>   flags = SDHCI_CMD_RESP_SHORT;
>  
> 




Re: [PATCH v2 8/8] drivers: net: macb: add fu740 support

2021-03-17 Thread Green Wan
On Wed, Mar 17, 2021 at 9:53 PM David Abdurachmanov <
david.abdurachma...@gmail.com> wrote:

> On Tue, Mar 16, 2021 at 6:35 PM Green Wan  wrote:
> >
> > From: David Abdurachmanov 
> >
> > Add fu740 support to macb ethernet driver
> >
> > Signed-off-by: David Abdurachmanov 
> > Signed-off-by: Green Wan 
> > Reviewed-by: Ramon Fried 
> > ---
> >  drivers/net/macb.c | 8 +++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/macb.c b/drivers/net/macb.c
> > index 57ea45e..df65d82 100644
> > --- a/drivers/net/macb.c
> > +++ b/drivers/net/macb.c
> > @@ -592,7 +592,11 @@ static int macb_sifive_clk_init(struct udevice
> *dev, ulong rate)
> >  * and output clock on GMII output signal GTX_CLK
> >  * 1 = MII mode. Use MII input signal TX_CLK in TX logic
> >  */
> > -   writel(rate != 12500, gemgxl_regs);
> > +   if (device_is_compatible(dev, "sifive,fu540-c000-gem"))
> > +   writel(rate != 12500, gemgxl_regs);
>
> Could you add a comment here why we need this? (i.e. about the HW quirk)
> Note that 125.125 is actually outside of specification for VSC8541XMV-02.
>
> Thanks, David. I'll add the comment for it.


> > +   else if (device_is_compatible(dev, "sifive,fu740-c000-gem"))
> > +   writel(rate != 125125000, gemgxl_regs);
> > +
> > return 0;
> >  }
> >
> > @@ -1507,6 +1511,8 @@ static const struct udevice_id macb_eth_ids[] = {
> > { .compatible = "cdns,zynq-gem" },
> > { .compatible = "sifive,fu540-c000-gem",
> >   .data = (ulong)&sifive_config },
> > +   { .compatible = "sifive,fu740-c000-gem",
> > + .data = (ulong)&sifive_config },
> > { .compatible = "microchip,mpfs-mss-gem",
> >   .data = (ulong)µchip_config },
> > { }
> > --
> > 2.7.4
> >
>


Re: [PATCH] sunxi: add fdtoverlay_addr_r environment variable

2021-03-17 Thread Andre Przywara
On Sun, 21 Feb 2021 10:44:47 +0100
Jernej Skrabec  wrote:

> Commit 69076dff2284 ("cmd: pxe: add support for FDT overlays") added
> support for loading DT overlay files to PXE boot. However, it needs
> additional environment variable which points to memory location which
> can be used to temporary store overlay data.
> 
> Add it and in the process unify alignment using spaces.
> 
> Signed-off-by: Jernej Skrabec 

Thanks, looks good. Briefly tested with manually applying a simple
overlay, loaded to that address.
Checked that the other addresses don't change.

One nit below, with that:

Reviewed-by: Andre Przywara 

> ---
>  include/configs/sunxi-common.h | 48 ++
>  1 file changed, 26 insertions(+), 22 deletions(-)
> 
> diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
> index ded5aea551d3..4814e898c6ea 100644
> --- a/include/configs/sunxi-common.h
> +++ b/include/configs/sunxi-common.h
> @@ -62,7 +62,7 @@
>  #define SDRAM_OFFSET(x) 0x2##x
>  #define CONFIG_SYS_SDRAM_BASE0x2000
>  #define CONFIG_SYS_LOAD_ADDR 0x2200 /* default load address */
> -/* Note SPL_STACK_R_ADDR is set through Kconfig, we include it here 
> +/* Note SPL_STACK_R_ADDR is set through Kconfig, we include it here
>   * since it needs to fit in with the other values. By also #defining it
>   * we get warnings if the Kconfig value mismatches. */
>  #define CONFIG_SPL_STACK_R_ADDR  0x2fe0
> @@ -72,7 +72,7 @@
>  #define CONFIG_SYS_SDRAM_BASE0x4000
>  #define CONFIG_SYS_LOAD_ADDR 0x4200 /* default load address */
>  /* V3s do not have enough memory to place code at 0x4a00 */
> -/* Note SPL_STACK_R_ADDR is set through Kconfig, we include it here 
> +/* Note SPL_STACK_R_ADDR is set through Kconfig, we include it here
>   * since it needs to fit in with the other values. By also #defining it
>   * we get warnings if the Kconfig value mismatches. */
>  #define CONFIG_SPL_STACK_R_ADDR  0x4fe0
> @@ -259,38 +259,41 @@ extern int soft_i2c_gpio_scl;
>   * Scripts, PXE and DTBs should go afterwards, leaving the rest for the 
> initrd.
>   * Align the initrd to a 2MB page.

This is no longer true. 
But there is no such requirement, so we can just remove this line.

Cheers,
Andre

>   */
> -#define BOOTM_SIZE   __stringify(0xa00)
> -#define KERNEL_ADDR_R__stringify(SDRAM_OFFSET(008))
> -#define FDT_ADDR_R   __stringify(SDRAM_OFFSET(FA0))
> -#define SCRIPT_ADDR_R__stringify(SDRAM_OFFSET(FC0))
> -#define PXEFILE_ADDR_R   __stringify(SDRAM_OFFSET(FD0))
> -#define RAMDISK_ADDR_R   __stringify(SDRAM_OFFSET(FE0))
> +#define BOOTM_SIZE__stringify(0xa00)
> +#define KERNEL_ADDR_R __stringify(SDRAM_OFFSET(008))
> +#define FDT_ADDR_R__stringify(SDRAM_OFFSET(FA0))
> +#define SCRIPT_ADDR_R __stringify(SDRAM_OFFSET(FC0))
> +#define PXEFILE_ADDR_R__stringify(SDRAM_OFFSET(FD0))
> +#define FDTOVERLAY_ADDR_R __stringify(SDRAM_OFFSET(FE0))
> +#define RAMDISK_ADDR_R__stringify(SDRAM_OFFSET(FF0))
>  
>  #else
>  /*
>   * 160M RAM (256M minimum minus 64MB heap + 32MB for u-boot, stack, fb, etc.
>   * 32M uncompressed kernel, 16M compressed kernel, 1M fdt,
> - * 1M script, 1M pxe and the ramdisk at the end.
> + * 1M script, 1M pxe, 1M dt overlay and the ramdisk at the end.
>   */
>  #ifndef CONFIG_MACH_SUN8I_V3S
> -#define BOOTM_SIZE __stringify(0xa00)
> -#define KERNEL_ADDR_R  __stringify(SDRAM_OFFSET(200))
> -#define FDT_ADDR_R __stringify(SDRAM_OFFSET(300))
> -#define SCRIPT_ADDR_R  __stringify(SDRAM_OFFSET(310))
> -#define PXEFILE_ADDR_R __stringify(SDRAM_OFFSET(320))
> -#define RAMDISK_ADDR_R __stringify(SDRAM_OFFSET(330))
> +#define BOOTM_SIZE__stringify(0xa00)
> +#define KERNEL_ADDR_R __stringify(SDRAM_OFFSET(200))
> +#define FDT_ADDR_R__stringify(SDRAM_OFFSET(300))
> +#define SCRIPT_ADDR_R __stringify(SDRAM_OFFSET(310))
> +#define PXEFILE_ADDR_R__stringify(SDRAM_OFFSET(320))
> +#define FDTOVERLAY_ADDR_R __stringify(SDRAM_OFFSET(330))
> +#define RAMDISK_ADDR_R__stringify(SDRAM_OFFSET(340))
>  #else
>  /*
>   * 64M RAM minus 2MB heap + 16MB for u-boot, stack, fb, etc.
>   * 16M uncompressed kernel, 8M compressed kernel, 1M fdt,
> - * 1M script, 1M pxe and the ramdisk at the end.
> + * 1M script, 1M pxe, 1M dt overlay and the ramdisk at the end.
>   */
> -#define BOOTM_SIZE __stringify(0x2e0)
> -#define KERNEL_ADDR_R  __stringify(SDRAM_OFFSET(100))
> -#define FDT_ADDR_R __stringify(SDRAM_OFFSET(180))
> -#define SCRIPT_ADDR_R  __stringify(SDRAM_OFFSET(190))
> -#define PXEFILE_ADDR_R __stringify(SDRAM_OFFSET(1A0))
> -#define RAMDISK_ADDR_R __stringify(SDRAM_OFFSET(1B0))
> +#define BOOTM_SIZE__stringify(0x2e0)
> +#define KERNEL_ADDR_R __stringify(SDRAM_OFFSET(1

Re: [PATCH 1/2] sunxi: support asymmetric dual rank DRAM on A64/R40

2021-03-17 Thread Andre Przywara
On Fri, 26 Feb 2021 00:13:24 +0800
Icenowy Zheng  wrote:

> Previously we have known that R40 has a configuration register for its
> rank 1, which allows different configuration than rank 0. Reverse
> engineering of newest libdram of A64 from Allwinner shows that A64 has
> this register too. It's bit 0 (which enables dual rank in rank 0
> configuration register) means a dedicated rank size setup is used for
> rank 1.
> 
> Now, Pine64 scheduled to use a 3GiB LPDDR3 DRAM chip (which has 2GiB
> rank 0 and 1GiB rank 1) on PinePhone, that makes asymmetric dual rank
> DRAM support necessary.
> 
> Add this support. The code could support both A64 and R40, but because
> dual rank detection is broken on R40 now, we cannot really use it on R40
> currently.
> 
> Signed-off-by: Icenowy Zheng 

So this looks alright to me.
I tried to re-use the existing mctl_mem_matches() implementation for
the _base() version you introduce, but interestingly this increases the
code size - I guess we reach the limits of the toolchain garbage
collection here. So it's some code duplication, but for the sake of
keeping the SPL small, I am OK with that.

I couldn't test this, but reportedly this makes quite some Pinephone
people happy, so:

Reviewed-by: Andre Przywara 

Cheers,
Andre

> ---
>  .../include/asm/arch-sunxi/dram_sunxi_dw.h| 11 ++-
>  arch/arm/mach-sunxi/dram_sunxi_dw.c   | 94 +++
>  2 files changed, 82 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/arm/include/asm/arch-sunxi/dram_sunxi_dw.h 
> b/arch/arm/include/asm/arch-sunxi/dram_sunxi_dw.h
> index a5a7ebde44..e843c14202 100644
> --- a/arch/arm/include/asm/arch-sunxi/dram_sunxi_dw.h
> +++ b/arch/arm/include/asm/arch-sunxi/dram_sunxi_dw.h
> @@ -215,12 +215,17 @@ struct sunxi_mctl_ctl_reg {
>  #define NR_OF_BYTE_LANES (32 / BITS_PER_BYTE)
>  /* The eight data lines (DQn) plus DM, DQS and DQSN */
>  #define LINES_PER_BYTE_LANE  (BITS_PER_BYTE + 3)
> -struct dram_para {
> +
> +struct rank_para {
>   u16 page_size;
> - u8 bus_full_width;
> - u8 dual_rank;
>   u8 row_bits;
>   u8 bank_bits;
> +};
> +
> +struct dram_para {
> + u8 dual_rank;
> + u8 bus_full_width;
> + struct rank_para ranks[2];
>   const u8 dx_read_delays[NR_OF_BYTE_LANES][LINES_PER_BYTE_LANE];
>   const u8 dx_write_delays[NR_OF_BYTE_LANES][LINES_PER_BYTE_LANE];
>   const u8 ac_delays[31];
> diff --git a/arch/arm/mach-sunxi/dram_sunxi_dw.c 
> b/arch/arm/mach-sunxi/dram_sunxi_dw.c
> index d0600011ff..2b9d631d49 100644
> --- a/arch/arm/mach-sunxi/dram_sunxi_dw.c
> +++ b/arch/arm/mach-sunxi/dram_sunxi_dw.c
> @@ -399,11 +399,19 @@ static void mctl_set_cr(uint16_t socid, struct 
> dram_para *para)
>  #else
>  #error Unsupported DRAM type!
>  #endif
> -(para->bank_bits == 3 ? MCTL_CR_EIGHT_BANKS : 
> MCTL_CR_FOUR_BANKS) |
> +(para->ranks[0].bank_bits == 3 ? MCTL_CR_EIGHT_BANKS : 
> MCTL_CR_FOUR_BANKS) |
>  MCTL_CR_BUS_FULL_WIDTH(para->bus_full_width) |
>  (para->dual_rank ? MCTL_CR_DUAL_RANK : MCTL_CR_SINGLE_RANK) |
> -MCTL_CR_PAGE_SIZE(para->page_size) |
> -MCTL_CR_ROW_BITS(para->row_bits), &mctl_com->cr);
> +MCTL_CR_PAGE_SIZE(para->ranks[0].page_size) |
> +MCTL_CR_ROW_BITS(para->ranks[0].row_bits), &mctl_com->cr);
> +
> + if (para->dual_rank && (socid == SOCID_A64 || socid == SOCID_R40)) {
> + writel((para->ranks[1].bank_bits == 3 ? MCTL_CR_EIGHT_BANKS : 
> MCTL_CR_FOUR_BANKS) |
> +MCTL_CR_BUS_FULL_WIDTH(para->bus_full_width) |
> +MCTL_CR_DUAL_RANK |
> +MCTL_CR_PAGE_SIZE(para->ranks[1].page_size) |
> +MCTL_CR_ROW_BITS(para->ranks[1].row_bits), 
> &mctl_com->cr_r1);
> + }
>  
>   if (socid == SOCID_R40) {
>   if (para->dual_rank)
> @@ -646,35 +654,63 @@ static int mctl_channel_init(uint16_t socid, struct 
> dram_para *para)
>   return 0;
>  }
>  
> -static void mctl_auto_detect_dram_size(uint16_t socid, struct dram_para 
> *para)
> +/*
> + * Test if memory at offset offset matches memory at a certain base
> + */
> +static bool mctl_mem_matches_base(u32 offset, ulong base)
> +{
> + /* Try to write different values to RAM at two addresses */
> + writel(0, base);
> + writel(0xaa55aa55, base + offset);
> + dsb();
> + /* Check if the same value is actually observed when reading back */
> + return readl(base) ==
> +readl(base + offset);
> +}
> +
> +static void mctl_auto_detect_dram_size_rank(uint16_t socid, struct dram_para 
> *para, ulong base, struct rank_para *rank)
>  {
>   /* detect row address bits */
> - para->page_size = 512;
> - para->row_bits = 16;
> - para->bank_bits = 2;
> + rank->page_size = 512;
> + rank->row_bits = 16;
> + rank->bank_bits = 2;
>   mctl_set_cr(socid, para);
>  
> - for (para->row_bits = 11; para->row_bits < 16; para->row_bits++)
> -

Re: [linux-sunxi] Re: [PATCH 2/2] sunxi: enable dual rank memory on R40

2021-03-17 Thread Andre Przywara
On Wed, 03 Mar 2021 01:49:53 +0800
Icenowy Zheng  wrote:

Hi Icenowy,

many thanks for your research on this. I asked some local compiler
buffs, see below ...


> 在 2021-03-02星期二的 15:19 +,Andre Przywara写道:
> > On Tue, 02 Mar 2021 21:50:49 +0800
> > Icenowy Zheng  wrote:
> > 
> > Hi Icenowy,
> >   
> > > 于 2021年3月2日 GMT+08:00 下午9:40:44, Andre Przywara <  
> > > andre.przyw...@arm.com> 写到:
> > > > On Fri, 26 Feb 2021 00:13:25 +0800
> > > > Icenowy Zheng  wrote:
> > > >    
> > > > > Previously we do not have proper dual rank memory detection on
> > > > > R40
> > > > > (because we omitted PIR_QSGATE, which does not work on R40 with
> > > > > our
> > > > > configuration), and dual rank memory is just simply disabled as
> > > > > early
> > > > > R40 boards available (Banana Pi M2 Ultra and Berry) have single
> > > > > rank
> > > > > memory.
> > > > > 
> > > > > As a board with dual rank memory (Forlinx OKA40i-C) is now
> > > > > known to    
> > > > us,    
> > > > > we need to have a way to do memory rank detection to support
> > > > > that    
> > > > board.    
> > > > > 
> > > > > Add some routine to detect memory rank by trying to access the
> > > > > memory
> > > > > in rank 1 and check for error status of the memory controller,
> > > > > and    
> > > > then    
> > > > > enable dual rank memory on R40.
> > > > > 
> > > > > Similar routine can be used to detect half DQ width (which is
> > > > > also
> > > > > detected by PIR_QSGATE on other SoCs), but it's left
> > > > > unimplemented
> > > > > because there's no known R40 board with half DQ width now.    
> > > > 
> > > > So when looking at the SPL size I realised that this patch breaks
> > > > the
> > > > socid constant parameter propagation, especially for
> > > > mctl_set_cr(). I
> > > > don't see immediately why, this whole code here should be
> > > > compiled out
> > > > on any A64 builds, for instance. Instead GCC turns
> > > > ":" into ":", and passes
> > > > 0x1689
> > > > around everytime. I tried GCC 10.2.0 and 9.2.0, also tried adding
> > > > const
> > > > everywhere, to amplify the constant nature of this value. Patch
> > > > 1/2 added to the code size, but kept the const propagation (only
> > > > one
> > > > instance of 0x1689 in the disassembly). This patch here should be
> > > > for
> > > > free on A64, but adds 104 bytes.
> > > > 
> > > > Does anyone have a clue why this is happening? Is this a compiler
> > > > issue?    
> > > 
> > > Maybe the issue is that I assume this codepath is only for R40 and
> > > I didn't add socid to it?  
> > 
> > But that's clearly visible by this function only being called inside
> > "if
> > (socid == SOCID_R40)". And that works very well for the H3 ZQ
> > calibration quirk, for instance.
> >   
> > > Could you try to add a socid parameter to
> > > mctl_r40_detect_rank_count()?  
> > 
> > I just tried that, and apart from looking weird it didn't do
> > anything.
> > 
> > To be clear: Your code is absolutely fine, exactly the way it should
> > be
> > written. It's just that the compiler is playing stupid suddenly. I
> > was
> > thinking that your dummy readl might have upset it, but even with
> > that
> > commented out it's still happening.
> >   
> > > Or maybe it makes mctl_calc_rank_size() not inlined?  
> > 
> > So the assembly looks like everything apart from mctl_set_cr() and
> > mctl_auto_detect_dram_size_rank() is inlined. Those are extra because
> > they are called multiple times and we are using -Os.
> >    
> > > (Well I think the code looks noop on non-R40)  
> > 
> > Exactly that was my thinking: when compiling for the A64, it should
> > be
> > totally compiled out, and the object file should be the same before
> > and
> > after.
> >    
> > > BTW, original rank/width detection part won't get called on R40.
> > > But
> > > R40 is not where we are tight on code size, so I didn't bother to
> > > ignore
> > > it on R40.  
> > 
> > I see. Yeah, I am not concerned about R40 either, but I want to avoid
> > the A64 bloating up. 
> >   
> > > Or should we switch back to #if's and do not rely on compiler
> > > behavior any longer?  
> > 
> > I'd rather not do that. We are doing the right thing, and it works
> > marvellously so far.
> > 
> > To be clear: it's not a show stopper, I was just curious why this
> > happens.
> > The code size is not really critical on the A64 at the moment, so I'd
> > merge it as it, even if we don't find a solution. Maybe just leave a
> > hint about it in the code should people need to come back to this.
> > 
> > I also asked some compiler buffs about it, but it's not exactly the
> > simple reproducer case they like to deal with ;-)
> > 
> > Cheers,
> > Andre
> > 
> > 
> >   
> > >   
> > > > 
> > > > Cheers,
> > > > Andre
> > > >     
> > > > > Signed-off-by: Icenowy Zheng 
> > > > > ---
> > > > >  arch/arm/mach-sunxi/dram_sunxi_dw.c | 55    
> > > > +    
> > > > >  1 file changed, 49 insertions(+), 6 deletions(-)
> > > > > 
> > > > > diff --g

RE: [PATCH] Revert "mmc: sdhci: set to INT_DATA_END when there are data"

2021-03-17 Thread Andy.Wu
Hi 

> I don't want to revert this commit. Is there any issue without this?

Without revert commit 17ea3c86, Some board, like Dragonboard 410c will meet
transfer data timeout error (we used v2018.01):

U-Boot 2018.01 (Nov 26 2020 - 03:31:09 +)
Qualcomm-DragonBoard 410C

DRAM:  986 MiB
MMC:   sdhci@07824000: 0, sdhci@07864000: 1
sdhci_transfer_data: Transfer data timeout
mmc_init: -70, time 10645
*** Warning - No block device, using default environment

And it seems the 17ea3c86 not followed the sdhci specification as
transfer complete bit should be wait for the BUSY status de-assert.

Kernel side code also wait the transfer complete bit for response-with-busy
command.

> Without this patch, some SoCs have timeout error with stop command.

Sorry, we didn't meet this stop command timeout issue, but I guess it maybe
another issue, and can be fixed with modification limited to stop command, 
not for all response-with-busy command.

Does the SDHCI_QUIRK_BROKEN_R1B can be used for this case?

Best Regards
Andy Wu

> -Original Message-
> From: U-Boot  On Behalf Of Jaehoon Chung
> Sent: Thursday, March 18, 2021 6:44 AM
> To: Mo, Yuezhang ; u-boot@lists.denx.de
> Cc: peng@nxp.com; c...@samsung.com
> Subject: Re: [PATCH] Revert "mmc: sdhci: set to INT_DATA_END when there are
> data"
> 
> Hi
> 
> On 3/17/21 3:44 PM, yuezhang...@sony.com wrote:
> > This reverts commit 17ea3c862865c0d704646f67dbf8412f9ff54f59.
> >
> > In eMMC specification, for the response-with-busy(R1b, R5b) command,
> > the DAT0 will driven to LOW as BUSY status, and in sdhci
> > specification, the transfer complete bit should be wait for BUSY
> > status de-assert.
> >
> > All response-with-busy commands don't contain data, the data judgement
> > is no need.
> 
> 
> I don't want to revert this commit. Is there any issue without this?
> Without this patch, some SoCs have timeout error with stop command.
> 
> To prevent it, it needs to increase timeout value at that time.
> (Timeout value can't fix each boards, waste time to find proper value, and be
> performance degradation.)
> 
> I didn't test without this patch on latest U-boot.
> But if there is no critical issue, keep it, plz.
> 
> Best Regards,
> Jaehoon Chung
> 
> >
> > Signed-off-by: Yuezhang.Mo 
> > ---
> >  drivers/mmc/sdhci.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index
> > d9ab6a0a83..8568f65b18 100644
> > --- a/drivers/mmc/sdhci.c
> > +++ b/drivers/mmc/sdhci.c
> > @@ -258,8 +258,7 @@ static int sdhci_send_command(struct mmc *mmc,
> struct mmc_cmd *cmd,
> > flags = SDHCI_CMD_RESP_LONG;
> > else if (cmd->resp_type & MMC_RSP_BUSY) {
> > flags = SDHCI_CMD_RESP_SHORT_BUSY;
> > -   if (data)
> > -   mask |= SDHCI_INT_DATA_END;
> > +   mask |= SDHCI_INT_DATA_END;
> > } else
> > flags = SDHCI_CMD_RESP_SHORT;
> >
> >
> 



Re: [PATCH 1/2] arm: omap3: Make secureworld_exit() static

2021-03-17 Thread Lokesh Vutla



On 17/03/21 11:00 pm, Adam Ford wrote:
> On Sat, Mar 6, 2021 at 10:04 PM Adam Ford  wrote:
>>
>> secureworld_exit() is only used in one file, so make it static
>> to that file and remove it from sys_proto.h. This
>> may help with some further optimization in the future.
>>
>> Signed-off-by: Adam Ford 
>>
> 
> Lokesh,
> 
> Is this patch ok as-is, or do you want me to re-post it as V2 with no
> changes when I redo patch 2/2?

Patch is okay. Please re-post it as V2 as a series.

Thanks and regards,
Lokesh

> 
> adam
> 
>> diff --git a/arch/arm/include/asm/arch-omap3/sys_proto.h 
>> b/arch/arm/include/asm/arch-omap3/sys_proto.h
>> index 656f848a73..a6e9ff84aa 100644
>> --- a/arch/arm/include/asm/arch-omap3/sys_proto.h
>> +++ b/arch/arm/include/asm/arch-omap3/sys_proto.h
>> @@ -59,7 +59,6 @@ u32 is_running_in_sdram(void);
>>  u32 is_running_in_sram(void);
>>  u32 is_running_in_flash(void);
>>  u32 get_device_type(void);
>> -void secureworld_exit(void);
>>  u32 get_boot_type(void);
>>  void invalidate_dcache(u32);
>>  u32 wait_on_value(u32, u32, void *, u32);
>> diff --git a/arch/arm/mach-omap2/omap3/board.c 
>> b/arch/arm/mach-omap2/omap3/board.c
>> index c621177580..879b0f 100644
>> --- a/arch/arm/mach-omap2/omap3/board.c
>> +++ b/arch/arm/mach-omap2/omap3/board.c
>> @@ -114,7 +114,7 @@ void secure_unlock_mem(void)
>>   * configure secure registers and exit secure world
>>   *  general use.
>>   
>> */
>> -void secureworld_exit(void)
>> +static void secureworld_exit(void)
>>  {
>> unsigned long i;
>>
>> --
>> 2.25.1
>>


Re: [PATCH v2 15/21] doc: Move UEFI under develop/

2021-03-17 Thread Simon Glass
Hi Heinrich,

On Wed, 17 Mar 2021 at 20:46, Heinrich Schuchardt  wrote:
>
> On 3/15/21 8:26 AM, Simon Glass wrote:
> > Much of the content here is useful only for development. Move it under
> > that section.
>
> If I apply only this patch:
>
> doc/arch/x86.rst:712:unknown document: ../uefi/u-boot_on_efi
>
> I cannot find any change to x86.rst in the cover letter of your series.
>
> To ease bisecting the change in doc/arch/x86.rst should be in this patch.

OK I didn't notice this because it seems to only regenerate a file if
it is touched.

I've found a few other problems too so I am resending this series.

Regards,
Simon


Re: [PATCH 4/7] spl: fit: Warn if FIT contains "fpga" property in config node

2021-03-17 Thread Simon Glass
Hi Alexandru,

On Thu, 11 Mar 2021 at 07:04, Alexandru Gagniuc  wrote:
>
> Commit 4afc4f37c70e ("doc: FIT image: Clarify format and simplify
> syntax") requires that FPGA images be referenced through the
> "loadables" in the config node. This means that "fpga" properties in
> config nodes are deprecated.
>
> Given that there are likely FIT images which use "fpga", let's not
> break those right away. Print a warning message that such use is
> deprecated, and give users a couple of releases to update their
>
> Signed-off-by: Alexandru Gagniuc 
> ---
>  common/spl/spl_fit.c | 9 +
>  1 file changed, 9 insertions(+)
>
> diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
> index 55fca9f399..68f29c0026 100644
> --- a/common/spl/spl_fit.c
> +++ b/common/spl/spl_fit.c
> @@ -526,6 +526,13 @@ __weak bool spl_load_simple_fit_skip_processing(void)
> return false;
>  }
>
> +static void warn_deprecated(const char *msg)
> +{
> +   printf("DEPRECATED: %s\n", msg);
> +   printf("\tThis will stop working in a future u-boot release\n");
> +   printf("\tSee doc/uImage.FIT/source_file_format.txt\n");

That is a lot of text to add...can it be shorter?

> +}
> +
>  static int spl_fit_upload_fpga(struct spl_fit_info *ctx, int node,
>struct spl_image_info *fpga_image)
>  {
> @@ -558,6 +565,8 @@ static int spl_fit_load_fpga(struct spl_fit_info *ctx,
> if (node < 0)
> return node;
>
> +   warn_deprecated("'fpga' property in config node. Use 'loadables'");
> +
> /* Load the image and set up the fpga_image structure */
> ret = spl_load_fit_image(info, sector, ctx, node, &fpga_image);
> if (ret) {
> --
> 2.26.2
>

Regards,
Simon