Re: [PATCH 3/3] mmc: fsl_esdhc_imx: correct the actual card clock

2022-07-22 Thread Tim Harvey
On Fri, Feb 11, 2022 at 3:48 AM  wrote:
>
> From: Haibo Chen 
>
> The original code logic can not show the correct card clock, and also
> has one risk when the div is 0. Because there is div -=1 before.
>
> So move the operation before div -=1, and also involve ddr_pre_div
> to get the correct value.
>
> Signed-off-by: Haibo Chen 
> ---
>  drivers/mmc/fsl_esdhc_imx.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c
> index 0be7cae1e5..0ea7b0b50c 100644
> --- a/drivers/mmc/fsl_esdhc_imx.c
> +++ b/drivers/mmc/fsl_esdhc_imx.c
> @@ -609,6 +609,8 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, 
> struct mmc *mmc, uint clock)
> while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
> div++;
>
> +   mmc->clock = sdhc_clk / pre_div / div / ddr_pre_div;
> +
> pre_div >>= 1;
> div -= 1;
>
> @@ -630,7 +632,6 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, 
> struct mmc *mmc, uint clock)
> else
> esdhc_setbits32(>sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
>
> -   mmc->clock = sdhc_clk / pre_div / div;
> priv->clock = clock;
>  }
>
> --
> 2.17.1
>

Haibo,

I found that this particular patch keeps an imx8mm-venice-gw7901 board
that has a viking vwsdinbdg4 eMMC from booting to Linux. While u-boot
appears to work ok, as soon as I load a kernel (from emmc or even
network) and boot to it I hang at 'starting kernel' even with early
debug turned on.

u-boot=> mmc list
FSL_SDHC: 0
FSL_SDHC: 1
FSL_SDHC: 2 (eMMC)
u-boot=> mmc dev 2
switch to partitions #0, OK
mmc2(part 0) is current device
u-boot=> mmc info
Device: FSL_SDHC
Manufacturer ID: 45
OEM: 0
Name: DG4008
Bus Speed: 2
Mode: HS400ES (200MHz)
Rd Block Len: 512
MMC version 5.1
High Capacity: Yes
Capacity: 7.3 GiB
Bus Width: 8-bit DDR
Erase Group Size: 512 KiB
HC WP Group Size: 8 MiB
User Capacity: 7.3 GiB WRREL
Boot Capacity: 4 MiB ENH
RPMB Capacity: 4 MiB ENH
Boot area 0 is not write protected
Boot area 1 is not write protected

I have other boards with a Micron MTFC8GAKAJCN non HS400ES that don't
have any issue so it appears to be something to do with HS400ES
support and I find if I disable CONFIG_MMC_HS400_ES_SUPPORT or revert
this patch the issue goes away.

Any idea what might be going on here?

Best Regards,

Tim


Re: [PATCH] sunxi-mmc: increase stabilization delay from 1ms to 20ms

2022-07-22 Thread Da Xue
On Fri, Jul 22, 2022 at 1:56 PM Jernej Škrabec  wrote:
>
> Dne petek, 22. julij 2022 ob 18:55:14 CEST je Andre Przywara napisal(a):
> > On 21/07/2022 23:08, Da Xue wrote:
> >
> > Hi,
> >
> > > Some users experienced problems booting u-boot from SPL hanging here:
> > >
> > > Trying to boot from MMC1 or Trying to boot from MMC2
> > >
> > > This seems to occur with both MicroSD and eMMC modules on ALL-H3-CC.
> > > Increasing the delay after mmc reset fixes these boot problems.
> > > Some MicroSD cards are impacted more than others so it is possible that
> > > MicroSD internals need time to stabilize. Below is some failure data.
> > >
> > > sandisk ultra   64gb 9/20 with 1ms,  20/20 with 10ms
> > > sandisk ultra   16gb 2/20 with 1ms,  20/20 with 10ms
> > > sandisk extreme 16gb 6/20 with 10ms, 20/20 with 20ms
> > >
> > > A quick comparison of schematics show series resistors for ESD
> > > protection on the MicroSD GPIOs not present on all H3/H5 boards.
> > > It is not known if this is related to the issue.
> > >
> > > This patch adds a fixed 20ms delay to mmc init to mitigate the problem.
> > > If boot time optimization is required and the platform does not require
> > > the delay. The delay can be replaced with:
> > >
> > > writel(SUNXI_MMC_GCTRL_RESET, >reg->gctrl);
> > > if (wait_for_bit_le32( >reg->gctrl,
> > > SUNXI_MMC_GCTRL_RESET, false, 20, false)) {
> > > printf("%s: Timeout\n", __func__);
> > > return -ETIMEDOUT;
> > > }
> >
> > So what about adding this for everyone (we should have it regardless) then?

I think it would be good to add for everyone. This only happens in SPL
so the impact is limited in terms of time cost.

> >
> > And then have an extra Kconfig option to specify an extra delay, and
> > define this only in your board defconfig? Because IIUC this is specific
> > to your board?

I only have my boards to test. I'm sure there are other devices that have the
same issue. I don't think it's exclusive to our boards.

> >
> > And as I mentioned: it looks odd to have this here and have it fixing
> > your SD card problems:
> > - The soft reset should reset just the internal controller logic (MMC
> > state machine and FIFOs), this shouldn't affect cards. IIUC, nothing
> > should happen on the MMC *pins* because of this operation.
> > - Why isn't this a problem for U-Boot proper, and Linux, FWIW?
>
> As I said before, I have issue only at cold boot in SPL. Once I pass this
> point, it works all the time, even if rebooted. Why is that so it's unclear.
>
> Thinking about this a bit, I have another question. How is it possible that
> BROM manages to read SD card just fine and loads SPL beforehand? Is it using
> lower speed? It also couldn't be power issue, since card must have been
> properly powered up by BROM...

Is the bootrom using SPI mode on first boot? If that is the case, a transition
would take time and may explain the necessity of this.

>
> Best regards,
> Jernej
>
> >
> > Cheers,
> > Andre
> >
> > > Signed-off-by: Da Xue 
> > > ---
> > >
> > >   drivers/mmc/sunxi_mmc.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
> > > index 1bb7b6d0e9..f7942b69ce 100644
> > > --- a/drivers/mmc/sunxi_mmc.c
> > > +++ b/drivers/mmc/sunxi_mmc.c
> > > @@ -297,7 +297,7 @@ static int sunxi_mmc_core_init(struct mmc *mmc)
> > >
> > >/* Reset controller */
> > >writel(SUNXI_MMC_GCTRL_RESET, >reg->gctrl);
> > >
> > > - udelay(1000);
> > > + udelay(2);
> > >
> > >return 0;
> > >
> > >   }
>
>
>
>


Re: [PATCH] fastboot: release usb_gadget on reboot commands

2022-07-22 Thread Marek Vasut

On 7/21/22 15:59, Mattijs Korpershoek wrote:

[...]


diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 8ba55aab9f8f..a00d1ca571d1 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -420,7 +420,8 @@ static int fastboot_tx_write_str(const char *buffer)
  
  static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)

  {
-   do_reset(NULL, 0, 0, NULL);
+   g_dnl_trigger_detach();
+   g_dnl_trigger_reset_request();


Wouldn't it be enough to call usb_gadget_release() before do_reset() 
here ? Or actually fix up the hardware state in your platform reset 
implementation, which would cover all such odd states for every other 
USB UDC mode of operation, not just fastboot ?


Re: [PATCH 01/17] Convert CONFIG_FSL_FIXED_MMC_LOCATION et al to Kconfig

2022-07-22 Thread Tom Rini
On Fri, Jul 22, 2022 at 01:05:38PM -0700, Tim Harvey wrote:
> On Fri, Jul 22, 2022 at 12:06 PM Tom Rini  wrote:
> >
> > On Fri, Jul 22, 2022 at 11:01:52AM -0700, Tim Harvey wrote:
> > > On Mon, Jun 20, 2022 at 5:08 AM Tom Rini  wrote:
> > > >
> > > > This converts the following to Kconfig:
> > > >CONFIG_FSL_FIXED_MMC_LOCATION
> > > >CONFIG_ESDHC_HC_BLK_ADDR
> > > >
> > > > Signed-off-by: Tom Rini 
> > [snip]
> > > Tom,
> > >
> > > I'm not sure this patch had the intended results. I just noticed that
> > > default bootcmd was changed due to this for the the imx8m*venice
> > > boards I maintain.
> > >
> > > How did you go about generating this? In my case
> > > CONFIG_USE_BOOTCOMMAND is not set and prior to this patch was getting
> > > defaulted in include/config_distro_bootcmd.h but now that is removed
> > > and its getting set in tools/env/fw_env_private.h to something
> > > different.
> > >
> > > To fix this, I'll have to submit a patch that does the following for
> > > configs/imx8m*_venice_defconfig
> > > +CONFIG_USE_BOOTCOMMAND=y
> > > +CONFIG_BOOTCOMMAND="run distro_bootcmd"
> > >
> > > I figured it was worth mentioning and asking for others that run into 
> > > this.
> >
> > It's this commit, specifically?  Looking at u-boot-initial-env (and
> > disabling LTO for the moment), I don't see bootcmd set before nor after.
> > I could see this being a merge related problem or similar from
> > 970bf8603b877e2b66170290f751f9c23c120838 where I finished moving
> > everyone that was in-tree at the time that should have been setting
> > CONFIG_USE_BOOTCOMMAND and then CONFIG_BOOTCOMMAND (if not using the
> > default) leading to this kind of problem.
> >
> 
> Tom,
> 
> I apologize... not sure how I ended up replying to the wrong patch.
> 
> Indeed it is commit 970bf8603b87 ("Convert CONFIG_USE_BOOTCOMMAND et
> al to Kconfig") that I was referring to.
> 
> It looks like any board that specifically did not define
> CONFIG_USE_BOOTCOMMAND was likely affected and if I simply remove '#
> CONFIG_USE_BOOTCOMMAND is not set' from my defconfigs it fixes it.
> 
> This is what I was going to submit but if the above assumption is
> correct there would be a lot of other boards affected.
> 
> imx8m*_venice_defconfig: fix default bootcmd
> 
> commit 970bf8603b87 ("Convert CONFIG_USE_BOOTCOMMAND et al to Kconfig")
> had an unintended side effect of resulting in a bootcmd env var change
> for boards like venice that did not have CONFIG_USE_BOOTCOMMAND defined
> and relied on it being defaulted in include/config_distro_bootcmd.h.
> Following that patch it instead got defaulted in 
> tools/env/fw_env_private.h
> 
> Fix this by enabling CONFIG_USE_BOOTCOMMAND for venice.
> 
> Fixes: commit 970bf8603b87 ("Convert CONFIG_USE_BOOTCOMMAND et al to 
> Kconfig
> ")
> Signed-off-by: Tim Harvey 
> 

OK, yeah, makes more sense.  I'm not quite sure how I missed this
platform in the migration but apparently I did.  A patch to fix up other
platforms you can see were also broken would be appreciated, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 01/17] Convert CONFIG_FSL_FIXED_MMC_LOCATION et al to Kconfig

2022-07-22 Thread Tim Harvey
On Fri, Jul 22, 2022 at 12:06 PM Tom Rini  wrote:
>
> On Fri, Jul 22, 2022 at 11:01:52AM -0700, Tim Harvey wrote:
> > On Mon, Jun 20, 2022 at 5:08 AM Tom Rini  wrote:
> > >
> > > This converts the following to Kconfig:
> > >CONFIG_FSL_FIXED_MMC_LOCATION
> > >CONFIG_ESDHC_HC_BLK_ADDR
> > >
> > > Signed-off-by: Tom Rini 
> [snip]
> > Tom,
> >
> > I'm not sure this patch had the intended results. I just noticed that
> > default bootcmd was changed due to this for the the imx8m*venice
> > boards I maintain.
> >
> > How did you go about generating this? In my case
> > CONFIG_USE_BOOTCOMMAND is not set and prior to this patch was getting
> > defaulted in include/config_distro_bootcmd.h but now that is removed
> > and its getting set in tools/env/fw_env_private.h to something
> > different.
> >
> > To fix this, I'll have to submit a patch that does the following for
> > configs/imx8m*_venice_defconfig
> > +CONFIG_USE_BOOTCOMMAND=y
> > +CONFIG_BOOTCOMMAND="run distro_bootcmd"
> >
> > I figured it was worth mentioning and asking for others that run into this.
>
> It's this commit, specifically?  Looking at u-boot-initial-env (and
> disabling LTO for the moment), I don't see bootcmd set before nor after.
> I could see this being a merge related problem or similar from
> 970bf8603b877e2b66170290f751f9c23c120838 where I finished moving
> everyone that was in-tree at the time that should have been setting
> CONFIG_USE_BOOTCOMMAND and then CONFIG_BOOTCOMMAND (if not using the
> default) leading to this kind of problem.
>

Tom,

I apologize... not sure how I ended up replying to the wrong patch.

Indeed it is commit 970bf8603b87 ("Convert CONFIG_USE_BOOTCOMMAND et
al to Kconfig") that I was referring to.

It looks like any board that specifically did not define
CONFIG_USE_BOOTCOMMAND was likely affected and if I simply remove '#
CONFIG_USE_BOOTCOMMAND is not set' from my defconfigs it fixes it.

This is what I was going to submit but if the above assumption is
correct there would be a lot of other boards affected.

imx8m*_venice_defconfig: fix default bootcmd

commit 970bf8603b87 ("Convert CONFIG_USE_BOOTCOMMAND et al to Kconfig")
had an unintended side effect of resulting in a bootcmd env var change
for boards like venice that did not have CONFIG_USE_BOOTCOMMAND defined
and relied on it being defaulted in include/config_distro_bootcmd.h.
Following that patch it instead got defaulted in tools/env/fw_env_private.h

Fix this by enabling CONFIG_USE_BOOTCOMMAND for venice.

Fixes: commit 970bf8603b87 ("Convert CONFIG_USE_BOOTCOMMAND et al to Kconfig
")
Signed-off-by: Tim Harvey 

diff --git a/configs/imx8mm_venice_defconfig b/configs/imx8mm_venice_defconfig
index 0165a4e5df08..c0fff026fbbc 100644
--- a/configs/imx8mm_venice_defconfig
+++ b/configs/imx8mm_venice_defconfig
@@ -27,7 +27,6 @@ CONFIG_SPL_LOAD_FIT=y
 # CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_OF_SYSTEM_SETUP=y
-# CONFIG_USE_BOOTCOMMAND is not set
 CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="gsc wd-disable"
 CONFIG_BOARD_LATE_INIT=y
diff --git a/configs/imx8mn_venice_defconfig b/configs/imx8mn_venice_defconfig
index 63a654973710..4bbf9ded74ad 100644
--- a/configs/imx8mn_venice_defconfig
+++ b/configs/imx8mn_venice_defconfig
@@ -28,7 +28,6 @@ CONFIG_SPL_LOAD_FIT=y
 # CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_OF_SYSTEM_SETUP=y
-# CONFIG_USE_BOOTCOMMAND is not set
 CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="gsc wd-disable"
 CONFIG_BOARD_LATE_INIT=y
diff --git a/configs/imx8mp_venice_defconfig b/configs/imx8mp_venice_defconfig
index 6758cd251e60..398875ae323a 100644
--- a/configs/imx8mp_venice_defconfig
+++ b/configs/imx8mp_venice_defconfig
@@ -28,7 +28,6 @@ CONFIG_SPL_LOAD_FIT=y
 # CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_OF_BOARD_SETUP=y
 CONFIG_OF_SYSTEM_SETUP=y
-# CONFIG_USE_BOOTCOMMAND is not set
 CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="gsc wd-disable"
 CONFIG_BOARD_LATE_INIT=y

Best Regards,

Tim


Re: [PATCH 01/17] Convert CONFIG_FSL_FIXED_MMC_LOCATION et al to Kconfig

2022-07-22 Thread Tom Rini
On Fri, Jul 22, 2022 at 11:01:52AM -0700, Tim Harvey wrote:
> On Mon, Jun 20, 2022 at 5:08 AM Tom Rini  wrote:
> >
> > This converts the following to Kconfig:
> >CONFIG_FSL_FIXED_MMC_LOCATION
> >CONFIG_ESDHC_HC_BLK_ADDR
> >
> > Signed-off-by: Tom Rini 
[snip]
> Tom,
> 
> I'm not sure this patch had the intended results. I just noticed that
> default bootcmd was changed due to this for the the imx8m*venice
> boards I maintain.
> 
> How did you go about generating this? In my case
> CONFIG_USE_BOOTCOMMAND is not set and prior to this patch was getting
> defaulted in include/config_distro_bootcmd.h but now that is removed
> and its getting set in tools/env/fw_env_private.h to something
> different.
> 
> To fix this, I'll have to submit a patch that does the following for
> configs/imx8m*_venice_defconfig
> +CONFIG_USE_BOOTCOMMAND=y
> +CONFIG_BOOTCOMMAND="run distro_bootcmd"
> 
> I figured it was worth mentioning and asking for others that run into this.

It's this commit, specifically?  Looking at u-boot-initial-env (and
disabling LTO for the moment), I don't see bootcmd set before nor after.
I could see this being a merge related problem or similar from
970bf8603b877e2b66170290f751f9c23c120838 where I finished moving
everyone that was in-tree at the time that should have been setting
CONFIG_USE_BOOTCOMMAND and then CONFIG_BOOTCOMMAND (if not using the
default) leading to this kind of problem.

-- 
Tom


signature.asc
Description: PGP signature


Pull request for efi-2022-10-rc1-2

2022-07-22 Thread Heinrich Schuchardt

Dear Tom,

The following changes since commit 26f6f7fb5c0651d65afdee6d8ed36063606179a8:

  Merge branch '2022-07-14-migrate-wiki-to-sphinx' (2022-07-14 18:43:51 
-0400)


are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-efi.git 
tags/efi-2022-10-rc1-2


for you to fetch changes up to 052e8ca421cc8697f8cf7de16253627c4c92f4dc:

  efi: test/py: repair authenticated capsules tests (2022-07-18 
17:21:49 +0200)


Gitlab CI showed no issues:
https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/12783


Pull request for efi-2022-10-rc1-2

Documentation:

* doc: add package uuid-dev to build dependencies

UEFI:

* remove support for CONFIG_LCD
* fix authenticated capsules tests

Others:

* pxe: simplify label_boot()
* cli: support bracketed paste


Heinrich Schuchardt (5):
  pxe: simplify label_boot()
  cli: support bracketed paste
  doc: add package uuid-dev to build dependencies
  doc: typo 'formatted' in codingstyle.rst
  efi_loader: remove support for CONFIG_LCD

Vincent Stehlé (1):
  efi: test/py: repair authenticated capsules tests

 boot/pxe_utils.c   |  9 -
 common/cli_readline.c  | 22 
--

 doc/build/gcc.rst  |  2 +-
 doc/develop/codingstyle.rst|  2 +-
 lib/efi_loader/Makefile|  1 -
 lib/efi_loader/efi_gop.c   |  5 -
 .../test_capsule_firmware_signed_fit.py|  3 +++
 .../test_capsule_firmware_signed_raw.py|  2 ++
 8 files changed, 31 insertions(+), 15 deletions(-)


Re: [PATCH 01/17] Convert CONFIG_FSL_FIXED_MMC_LOCATION et al to Kconfig

2022-07-22 Thread Tim Harvey
On Mon, Jun 20, 2022 at 5:08 AM Tom Rini  wrote:
>
> This converts the following to Kconfig:
>CONFIG_FSL_FIXED_MMC_LOCATION
>CONFIG_ESDHC_HC_BLK_ADDR
>
> Signed-off-by: Tom Rini 
> ---
>  arch/powerpc/include/asm/config_mpc85xx.h  |  3 ---
>  boot/Kconfig   | 13 +
>  configs/P1010RDB-PA_36BIT_NOR_defconfig|  1 +
>  configs/P1010RDB-PA_36BIT_SDCARD_defconfig |  1 +
>  configs/P1010RDB-PA_NOR_defconfig  |  1 +
>  configs/P1010RDB-PA_SDCARD_defconfig   |  1 +
>  configs/P1010RDB-PB_36BIT_NOR_defconfig|  1 +
>  configs/P1010RDB-PB_36BIT_SDCARD_defconfig |  1 +
>  configs/P1010RDB-PB_NOR_defconfig  |  1 +
>  configs/P1010RDB-PB_SDCARD_defconfig   |  1 +
>  configs/P1020RDB-PC_36BIT_SDCARD_defconfig |  1 +
>  configs/P1020RDB-PC_36BIT_defconfig|  1 +
>  configs/P1020RDB-PC_SDCARD_defconfig   |  1 +
>  configs/P1020RDB-PC_defconfig  |  1 +
>  configs/P1020RDB-PD_SDCARD_defconfig   |  1 +
>  configs/P1020RDB-PD_defconfig  |  1 +
>  configs/P2020RDB-PC_36BIT_SDCARD_defconfig |  1 +
>  configs/P2020RDB-PC_36BIT_defconfig|  1 +
>  configs/P2020RDB-PC_SDCARD_defconfig   |  1 +
>  configs/P2020RDB-PC_defconfig  |  1 +
>  include/configs/P1010RDB.h |  4 +---
>  include/configs/P2041RDB.h |  5 -
>  include/configs/corenet_ds.h   |  5 -
>  include/configs/p1_p2_rdb_pc.h |  4 +---
>  24 files changed, 33 insertions(+), 19 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/config_mpc85xx.h 
> b/arch/powerpc/include/asm/config_mpc85xx.h
> index e82adc6b4545..ce3a776c7e88 100644
> --- a/arch/powerpc/include/asm/config_mpc85xx.h
> +++ b/arch/powerpc/include/asm/config_mpc85xx.h
> @@ -33,7 +33,6 @@
>  #define CONFIG_SYS_FSL_PCIE_COMPAT "fsl,qoriq-pcie-v2.2"
>  #define CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
>  #define CONFIG_SYS_FSL_USB1_PHY_ENABLE
> -#define CONFIG_ESDHC_HC_BLK_ADDR
>
>  /* P1011 is single core version of P1020 */
>  #elif defined(CONFIG_ARCH_P1011)
> @@ -148,7 +147,6 @@
>  #define CONFIG_SYS_FSL_DSP_M2_RAM_ADDR 0xb000
>  #define CONFIG_SYS_FSL_DSP_CCSRBAR_DEFAULT 0xff60
>  #define CONFIG_SYS_FSL_IFC_BANK_COUNT  3
> -#define CONFIG_ESDHC_HC_BLK_ADDR
>
>  #elif defined(CONFIG_ARCH_BSC9132)
>  #define CONFIG_FSL_SDHC_V2_3
> @@ -160,7 +158,6 @@
>  #define CONFIG_SYS_FSL_IFC_BANK_COUNT  3
>  #define CONFIG_SYS_FSL_ESDHC_P1010_BROKEN_SDCLK
>  #define CONFIG_SYS_FSL_PCIE_COMPAT "fsl,qoriq-pcie-v2.2"
> -#define CONFIG_ESDHC_HC_BLK_ADDR
>
>  #elif defined(CONFIG_ARCH_T4240)
>  #define CONFIG_FSL_CORENET /* Freescale CoreNet platform */
> diff --git a/boot/Kconfig b/boot/Kconfig
> index 63dacc0d14f4..ee0dc90e93cc 100644
> --- a/boot/Kconfig
> +++ b/boot/Kconfig
> @@ -575,6 +575,19 @@ config SPIFLASH
>
>  endchoice
>
> +config FSL_FIXED_MMC_LOCATION
> +   bool "PBL MMC is at a fixed location"
> +   depends on SDCARD && !RAMBOOT_PBL
> +
> +config ESDHC_HC_BLK_ADDR
> +   def_bool y
> +   depends on FSL_FIXED_MMC_LOCATION && (ARCH_BSC9131 || ARCH_BSC9132 || 
> ARCH_P1010)
> +   help
> + In High Capacity SD Cards (> 2 GBytes), the 32-bit source address 
> and
> + code length of these soc specify the memory address in block address
> + format. Block length is fixed to 512 bytes as per the SD High
> + Capacity specification.
> +
>  config SYS_FSL_PBL_PBI
> string "PBI(pre-boot instructions) commands for the PBL image"
> depends on RAMBOOT_PBL
> diff --git a/configs/P1010RDB-PA_36BIT_NOR_defconfig 
> b/configs/P1010RDB-PA_36BIT_NOR_defconfig
> index 81bfd7ae518c..481c69d2d33b 100644
> --- a/configs/P1010RDB-PA_36BIT_NOR_defconfig
> +++ b/configs/P1010RDB-PA_36BIT_NOR_defconfig
> @@ -16,6 +16,7 @@ CONFIG_FIT=y
>  CONFIG_FIT_VERBOSE=y
>  CONFIG_OF_BOARD_SETUP=y
>  CONFIG_OF_STDOUT_VIA_ALIAS=y
> +CONFIG_FSL_FIXED_MMC_LOCATION=y
>  CONFIG_BOOTDELAY=10
>  CONFIG_USE_BOOTCOMMAND=y
>  CONFIG_BOOTCOMMAND="setenv bootargs root=/dev/ram rw 
> console=$consoledev,$baudrate $othbootargs ramdisk_size=$ramdisk_size;tftp 
> $ramdiskaddr $ramdiskfile;tftp $loadaddr $bootfile;tftp $fdtaddr 
> $fdtfile;bootm $loadaddr $ramdiskaddr $fdtaddr"
> diff --git a/configs/P1010RDB-PA_36BIT_SDCARD_defconfig 
> b/configs/P1010RDB-PA_36BIT_SDCARD_defconfig
> index 1ebfdec719e8..92bb8cdedf66 100644
> --- a/configs/P1010RDB-PA_36BIT_SDCARD_defconfig
> +++ b/configs/P1010RDB-PA_36BIT_SDCARD_defconfig
> @@ -22,6 +22,7 @@ CONFIG_FIT=y
>  CONFIG_FIT_VERBOSE=y
>  CONFIG_OF_BOARD_SETUP=y
>  CONFIG_OF_STDOUT_VIA_ALIAS=y
> +CONFIG_FSL_FIXED_MMC_LOCATION=y
>  CONFIG_BOOTDELAY=10
>  CONFIG_USE_BOOTCOMMAND=y
>  CONFIG_BOOTCOMMAND="setenv bootargs root=/dev/ram rw 
> console=$consoledev,$baudrate $othbootargs ramdisk_size=$ramdisk_size;tftp 
> $ramdiskaddr $ramdiskfile;tftp $loadaddr $bootfile;tftp $fdtaddr 
> $fdtfile;bootm $loadaddr $ramdiskaddr $fdtaddr"
> diff 

Re: [PATCH] sunxi-mmc: increase stabilization delay from 1ms to 20ms

2022-07-22 Thread Jernej Škrabec
Dne petek, 22. julij 2022 ob 18:55:14 CEST je Andre Przywara napisal(a):
> On 21/07/2022 23:08, Da Xue wrote:
> 
> Hi,
> 
> > Some users experienced problems booting u-boot from SPL hanging here:
> > 
> > Trying to boot from MMC1 or Trying to boot from MMC2
> > 
> > This seems to occur with both MicroSD and eMMC modules on ALL-H3-CC.
> > Increasing the delay after mmc reset fixes these boot problems.
> > Some MicroSD cards are impacted more than others so it is possible that
> > MicroSD internals need time to stabilize. Below is some failure data.
> > 
> > sandisk ultra   64gb 9/20 with 1ms,  20/20 with 10ms
> > sandisk ultra   16gb 2/20 with 1ms,  20/20 with 10ms
> > sandisk extreme 16gb 6/20 with 10ms, 20/20 with 20ms
> > 
> > A quick comparison of schematics show series resistors for ESD
> > protection on the MicroSD GPIOs not present on all H3/H5 boards.
> > It is not known if this is related to the issue.
> > 
> > This patch adds a fixed 20ms delay to mmc init to mitigate the problem.
> > If boot time optimization is required and the platform does not require
> > the delay. The delay can be replaced with:
> > 
> > writel(SUNXI_MMC_GCTRL_RESET, >reg->gctrl);
> > if (wait_for_bit_le32( >reg->gctrl,
> > SUNXI_MMC_GCTRL_RESET, false, 20, false)) {
> > printf("%s: Timeout\n", __func__);
> > return -ETIMEDOUT;
> > }
> 
> So what about adding this for everyone (we should have it regardless) then?
> 
> And then have an extra Kconfig option to specify an extra delay, and
> define this only in your board defconfig? Because IIUC this is specific
> to your board?
> 
> And as I mentioned: it looks odd to have this here and have it fixing
> your SD card problems:
> - The soft reset should reset just the internal controller logic (MMC
> state machine and FIFOs), this shouldn't affect cards. IIUC, nothing
> should happen on the MMC *pins* because of this operation.
> - Why isn't this a problem for U-Boot proper, and Linux, FWIW?

As I said before, I have issue only at cold boot in SPL. Once I pass this 
point, it works all the time, even if rebooted. Why is that so it's unclear.

Thinking about this a bit, I have another question. How is it possible that 
BROM manages to read SD card just fine and loads SPL beforehand? Is it using 
lower speed? It also couldn't be power issue, since card must have been 
properly powered up by BROM...

Best regards,
Jernej

> 
> Cheers,
> Andre
> 
> > Signed-off-by: Da Xue 
> > ---
> > 
> >   drivers/mmc/sunxi_mmc.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
> > index 1bb7b6d0e9..f7942b69ce 100644
> > --- a/drivers/mmc/sunxi_mmc.c
> > +++ b/drivers/mmc/sunxi_mmc.c
> > @@ -297,7 +297,7 @@ static int sunxi_mmc_core_init(struct mmc *mmc)
> > 
> >/* Reset controller */
> >writel(SUNXI_MMC_GCTRL_RESET, >reg->gctrl);
> > 
> > - udelay(1000);
> > + udelay(2);
> > 
> >return 0;
> >   
> >   }






[PATCH 5/5] fwu: DeveloperBox: add support for FWU

2022-07-22 Thread jassisinghbrar
From: Jassi Brar 

Add code to support FWU_MULTI_BANK_UPDATE.
The platform does not have gpt-partition storage for
Banks and MetaData, rather it used SPI-NOR backed
mtd regions for the purpose.

Signed-off-by: Masami Hiramatsu 
Signed-off-by: Jassi Brar 
---
 board/socionext/developerbox/Makefile   |  1 +
 board/socionext/developerbox/developerbox.c | 13 +++
 board/socionext/developerbox/fwu_plat.c | 95 
 configs/synquacer_developerbox_defconfig| 13 ++-
 doc/board/socionext/developerbox.rst| 96 +
 include/configs/synquacer.h | 10 +++
 6 files changed, 226 insertions(+), 2 deletions(-)
 create mode 100644 board/socionext/developerbox/fwu_plat.c

diff --git a/board/socionext/developerbox/Makefile 
b/board/socionext/developerbox/Makefile
index 4a46de995a..9b80ee38e7 100644
--- a/board/socionext/developerbox/Makefile
+++ b/board/socionext/developerbox/Makefile
@@ -7,3 +7,4 @@
 #
 
 obj-y  := developerbox.o
+obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu_plat.o
diff --git a/board/socionext/developerbox/developerbox.c 
b/board/socionext/developerbox/developerbox.c
index f5a5fe0121..ad2260e3d7 100644
--- a/board/socionext/developerbox/developerbox.c
+++ b/board/socionext/developerbox/developerbox.c
@@ -20,6 +20,13 @@
 
 #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
 struct efi_fw_image fw_images[] = {
+#if defined(CONFIG_FWU_MULTI_BANK_UPDATE)
+   {
+   .image_type_id = DEVELOPERBOX_FIP_IMAGE_GUID,
+   .fw_name = u"DEVELOPERBOX-FIP",
+   .image_index = 1,
+   },
+#else
{
.image_type_id = DEVELOPERBOX_UBOOT_IMAGE_GUID,
.fw_name = u"DEVELOPERBOX-UBOOT",
@@ -35,12 +42,18 @@ struct efi_fw_image fw_images[] = {
.fw_name = u"DEVELOPERBOX-OPTEE",
.image_index = 3,
},
+#endif
 };
 
 struct efi_capsule_update_info update_info = {
+#if defined(CONFIG_FWU_MULTI_BANK_UPDATE)
+   .dfu_string = "mtd nor1=bank0 raw 60 40;"
+   "bank1 raw a0 40;",
+#else
.dfu_string = "mtd nor1=u-boot.bin raw 20 10;"
"fip.bin raw 18 78000;"
"optee.bin raw 50 10",
+#endif
.images = fw_images,
 };
 
diff --git a/board/socionext/developerbox/fwu_plat.c 
b/board/socionext/developerbox/fwu_plat.c
new file mode 100644
index 00..9fb5cb28b3
--- /dev/null
+++ b/board/socionext/developerbox/fwu_plat.c
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define DFU_ALT_BUF_LEN 256
+#define DFU_ALT_NUM_MAX (CONFIG_FWU_NUM_IMAGES_PER_BANK * CONFIG_FWU_NUM_BANKS)
+
+/* Generate dfu_alt_info from partitions */
+void set_dfu_alt_info(char *interface, char *devstr)
+{
+   int ret;
+   struct mtd_info *mtd;
+   static char *buf = NULL;
+
+   if (!buf) {
+   buf = malloc_cache_aligned(DFU_ALT_BUF_LEN);
+   memset(buf, 0, DFU_ALT_BUF_LEN);
+
+   mtd_probe_devices();
+
+   mtd = get_mtd_device_nm("nor1");
+   if (IS_ERR_OR_NULL(mtd))
+   return;
+
+   ret = fwu_gen_alt_info_from_mtd(buf, DFU_ALT_BUF_LEN, mtd);
+   if (ret < 0) {
+   log_err("Error: Failed to generate dfu_alt_info. 
(%d)\n", ret);
+   return;
+   }
+   log_debug("Make dfu_alt_info: '%s'\n", buf);
+   }
+   env_set("dfu_alt_info", buf);
+}
+
+int fwu_plat_get_alt_num(struct udevice __always_unused *dev,
+efi_guid_t *image_id, int *alt_num)
+{
+   return mtd_plat_get_alt_num(image_id, alt_num, "nor1", 0);
+}
+
+int fwu_plat_get_update_index(u32 *update_idx)
+{
+   int ret;
+   u32 active_idx;
+
+   ret = fwu_get_active_index(_idx);
+
+   if (ret < 0)
+   return ret;
+
+   *update_idx = 1 - active_idx;
+
+   return ret;
+}
+
+void fwu_plat_get_bootidx(void *boot_idx)
+{
+   int ret;
+   u32 active_idx;
+   u32 *bootidx = boot_idx;
+
+   ret = fwu_get_active_index(_idx);
+
+   if (ret < 0)
+   *bootidx = -1;
+
+   *bootidx = active_idx;
+}
+
+int board_late_init(void)
+{
+   /* Make mmc available for EFI, otherwise efi subsystem
+* complains "No EFI system partition" during bootup.
+*/
+   run_command("mmc dev 0", 0);
+
+   return 0;
+}
diff --git a/configs/synquacer_developerbox_defconfig 
b/configs/synquacer_developerbox_defconfig
index add6041e27..ded31ada6e 100644
--- a/configs/synquacer_developerbox_defconfig
+++ b/configs/synquacer_developerbox_defconfig
@@ -1,10 +1,11 @@
 CONFIG_ARM=y
 CONFIG_ARCH_SYNQUACER=y
-CONFIG_SYS_TEXT_BASE=0x0820

[PATCH 4/5] dt: fwu: developerbox: enable fwu banks and mdata regions

2022-07-22 Thread jassisinghbrar
From: Jassi Brar 

specify Bank-0/1 and fwu metadata mtd regions.

Signed-off-by: Masami Hiramatsu 
Signed-off-by: Jassi Brar 
---
 .../synquacer-sc2a11-developerbox-u-boot.dtsi | 22 ++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi 
b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi
index 7a56116d6f..62eee0aaf0 100644
--- a/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi
+++ b/arch/arm/dts/synquacer-sc2a11-developerbox-u-boot.dtsi
@@ -23,7 +23,7 @@
active_clk_edges;
chipselect_num = <1>;
 
-   spi-flash@0 {
+   spi_flash: spi-flash@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "jedec,spi-nor";
@@ -36,6 +36,7 @@
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
+   uuid = "17e86d77-41f9-4fd7-87ec-a55df9842de5";
 
partition@0 {
label = "BootStrap-BL1";
@@ -79,6 +80,19 @@
label = "Ex-OPTEE";
reg = <0x50 0x20>;
};
+
+   /* FWU Multi bank update partitions */
+   partition@60 {
+   label = "FIP-Bank0";
+   reg = <0x60 0x40>;
+   uuid = 
"5a66a702-99fd-4fef-a392-c26e261a2828";
+   };
+
+   partition@a0 {
+   label = "FIP-Bank1";
+   reg = <0xa0 0x40>;
+   uuid = 
"a8f868a1-6e5c-4757-878d-ce63375ef2c0";
+   };
};
};
};
@@ -104,6 +118,12 @@
optee {
status = "okay";
};
+
+   fwu-mdata {
+   compatible = "u-boot,fwu-mdata-mtd";
+   fwu-mdata-store = <_flash>;
+   mdata-offsets = <0x50 0x53>;
+   };
};
 };
 
-- 
2.25.1



[PATCH 3/5] FWU: mtd: Add helper functions for accessing FWU metadata

2022-07-22 Thread jassisinghbrar
From: Sughosh Ganu 

Add helper functions needed for accessing the FWU metadata which
contains information on the updatable images.

Signed-off-by: Sughosh Ganu 
Signed-off-by: Jassi Brar 
---
 lib/fwu_updates/Makefile  |   1 +
 lib/fwu_updates/fwu_mtd.c | 173 ++
 2 files changed, 174 insertions(+)
 create mode 100644 lib/fwu_updates/fwu_mtd.c

diff --git a/lib/fwu_updates/Makefile b/lib/fwu_updates/Makefile
index 1993088e5b..c9e3c06b48 100644
--- a/lib/fwu_updates/Makefile
+++ b/lib/fwu_updates/Makefile
@@ -5,3 +5,4 @@
 
 obj-$(CONFIG_FWU_MULTI_BANK_UPDATE) += fwu.o
 obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_gpt.o
+obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mtd.o
diff --git a/lib/fwu_updates/fwu_mtd.c b/lib/fwu_updates/fwu_mtd.c
new file mode 100644
index 00..f13cb149a2
--- /dev/null
+++ b/lib/fwu_updates/fwu_mtd.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+int mtd_plat_get_alt_num(efi_guid_t *image_id, int *alt_num,
+   const char *mtd_dev, bool guid)
+{
+   int i, nalt;
+   int ret = -1;
+   struct mtd_info *mtd;
+   struct dfu_entity *dfu;
+   ofnode node, parts_node;
+   fdt_addr_t offset, size;
+   char uuidbuf[UUID_STR_LEN + 1];
+
+   mtd_probe_devices();
+   mtd = get_mtd_device_nm(mtd_dev);
+
+   /* Find partition node under given MTD device. */
+   parts_node = ofnode_by_compatible(mtd_get_ofnode(mtd),
+ "fixed-partitions");
+
+   uuid_bin_to_str(image_id->b, uuidbuf,
+   guid ? UUID_STR_FORMAT_GUID : UUID_STR_FORMAT_STD);
+   node = ofnode_by_prop_value(parts_node, "uuid", uuidbuf,
+   sizeof(uuidbuf));
+   if (!ofnode_valid(node)) {
+   log_warning("Warning: Failed to find partition by image 
UUID\n");
+   return -ENOENT;
+   }
+
+   offset = ofnode_get_addr_size_index_notrans(node, 0, );
+   if (offset == FDT_ADDR_T_NONE || !size)
+   return -ENOENT;
+
+   dfu_init_env_entities(NULL, NULL);
+
+   nalt = 0;
+   list_for_each_entry(dfu, _list, list) {
+   nalt++;
+   }
+
+   if (!nalt) {
+   log_warning("No entities in dfu_alt_info\n");
+   dfu_free_entities();
+   return -ENOENT;
+   }
+
+   for (i = 0; i < nalt; i++) {
+   dfu = dfu_get_entity(i);
+
+   if (!dfu)
+   continue;
+
+   if (dfu->dev_type != DFU_DEV_MTD)
+   continue;
+
+   if (dfu->layout == DFU_RAW_ADDR &&
+   dfu->data.mtd.start == offset &&
+   dfu->data.mtd.size == size) {
+   *alt_num = dfu->alt;
+   ret = 0;
+   break;
+   }
+   }
+
+   dfu_free_entities();
+
+   return ret;
+}
+
+int gen_image_alt_info(char *buf, size_t len, int sidx,
+  struct fwu_image_entry *img, struct mtd_info *mtd)
+{
+   int i;
+   const char *suuid;
+   ofnode node, parts_node;
+   char uuidbuf[UUID_STR_LEN + 1];
+   char *p = buf, *end = buf + len;
+
+   /* Find partition node under given MTD device. */
+   parts_node = ofnode_by_compatible(mtd_get_ofnode(mtd),
+ "fixed-partitions");
+   if (!ofnode_valid(parts_node))
+   return -ENOENT;
+
+   /* Check the media UUID if exist. */
+   suuid = ofnode_read_string(parts_node, "uuid");
+   if (suuid) {
+   log_debug("Get location uuid %s\n", suuid);
+   uuid_bin_to_str(img->location_uuid.b, uuidbuf,
+   UUID_STR_FORMAT_STD);
+   if (strcasecmp(suuid, uuidbuf))
+   log_warning("Warning: Location UUID does not match!\n");
+   }
+
+   p += snprintf(p, end - p, "mtd %s", mtd->name);
+   if (end < p)
+   return -E2BIG;
+
+   /*
+* List up the image banks in the FWU mdata and search the corresponding
+* partition based on partition's uuid.
+*/
+   for (i = 0; i < CONFIG_FWU_NUM_BANKS; i++) {
+   struct fwu_image_bank_info *bank;
+   fdt_addr_t offset, size;
+
+   /* Query a partition by image UUID */
+   bank = >img_bank_info[i];
+   uuid_bin_to_str(bank->image_uuid.b, uuidbuf,
+   UUID_STR_FORMAT_STD);
+   node = ofnode_by_prop_value(parts_node, "uuid", uuidbuf,
+   sizeof(uuidbuf));
+   if (!ofnode_valid(node)) {
+   log_warning("Warning: Failed to find partition by image 
UUID\n");
+ 

[PATCH 2/5] FWU: Add FWU metadata access driver for MTD storage regions

2022-07-22 Thread jassisinghbrar
From: Sughosh Ganu 

In the FWU Multi Bank Update feature, the information about the
updatable images is stored as part of the metadata, on a separate
region. Add a driver for reading from and writing to the metadata
when the updatable images and the metadata are stored on a raw
MTD region.

Signed-off-by: Sughosh Ganu 
Signed-off-by: Jassi Brar 
---
 drivers/fwu-mdata/Kconfig |   8 +
 drivers/fwu-mdata/Makefile|   1 +
 drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++
 3 files changed, 317 insertions(+)
 create mode 100644 drivers/fwu-mdata/fwu_mdata_mtd.c

diff --git a/drivers/fwu-mdata/Kconfig b/drivers/fwu-mdata/Kconfig
index d5edef19d6..a8fa9ad783 100644
--- a/drivers/fwu-mdata/Kconfig
+++ b/drivers/fwu-mdata/Kconfig
@@ -14,3 +14,11 @@ config FWU_MDATA_GPT_BLK
help
  Enable support for accessing FWU Metadata on GPT partitioned
  block devices.
+
+config FWU_MDATA_MTD
+   bool "FWU Metadata access for non-GPT MTD devices"
+   depends on DM_FWU_MDATA && MTD
+   help
+ Enable support for accessing FWU Metadata on non-partitioned
+ (or non-GPT partitioned, e.g. partition nodes in devicetree)
+ MTD devices.
diff --git a/drivers/fwu-mdata/Makefile b/drivers/fwu-mdata/Makefile
index 313049f67a..58f8023f16 100644
--- a/drivers/fwu-mdata/Makefile
+++ b/drivers/fwu-mdata/Makefile
@@ -5,3 +5,4 @@
 
 obj-$(CONFIG_DM_FWU_MDATA) += fwu-mdata-uclass.o
 obj-$(CONFIG_FWU_MDATA_GPT_BLK) += fwu_mdata_gpt_blk.o
+obj-$(CONFIG_FWU_MDATA_MTD) += fwu_mdata_mtd.o
diff --git a/drivers/fwu-mdata/fwu_mdata_mtd.c 
b/drivers/fwu-mdata/fwu_mdata_mtd.c
new file mode 100644
index 00..d543a419fd
--- /dev/null
+++ b/drivers/fwu-mdata/fwu_mdata_mtd.c
@@ -0,0 +1,308 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+struct fwu_mdata_mtd_priv {
+   struct mtd_info *mtd;
+   u32 pri_offset;
+   u32 sec_offset;
+};
+
+enum fwu_mtd_op {
+   FWU_MTD_READ,
+   FWU_MTD_WRITE,
+};
+
+static bool mtd_is_aligned_with_block_size(struct mtd_info *mtd, u64 size)
+{
+   return !do_div(size, mtd->erasesize);
+}
+
+static int mtd_io_data(struct mtd_info *mtd, u32 offs, u32 size, void *data,
+  enum fwu_mtd_op op)
+{
+   struct mtd_oob_ops io_op ={};
+   u64 lock_offs, lock_len;
+   size_t len;
+   void *buf;
+   int ret;
+
+   if (!mtd_is_aligned_with_block_size(mtd, offs))
+   return -EINVAL;
+   lock_offs = offs;
+   lock_len = round_up(size, mtd->erasesize);
+
+   ret = mtd_unlock(mtd, lock_offs, lock_len);
+   if (ret && ret != -EOPNOTSUPP)
+   return ret;
+
+   if (op == FWU_MTD_WRITE) {
+   struct erase_info erase_op = {};
+
+   /* This will expand erase size to align with the block size */
+   erase_op.mtd = mtd;
+   erase_op.addr = lock_offs;
+   erase_op.len = lock_len;
+   erase_op.scrub = 0;
+
+   ret = mtd_erase(mtd, _op);
+   if (ret)
+   goto lock_out;
+   }
+
+   /* Also, expand the write size to align with the write size */
+   len = round_up(size, mtd->writesize);
+
+   buf = memalign(ARCH_DMA_MINALIGN, len);
+   if (!buf) {
+   ret = -ENOMEM;
+   goto lock_out;
+   }
+   io_op.mode = MTD_OPS_AUTO_OOB;
+   io_op.len = len;
+   io_op.ooblen = 0;
+   io_op.datbuf = buf;
+   io_op.oobbuf = NULL;
+
+   if (op == FWU_MTD_WRITE) {
+   memcpy(buf, data, size);
+   ret = mtd_write_oob(mtd, offs, _op);
+   } else {
+   ret = mtd_read_oob(mtd, offs, _op);
+   if (!ret)
+   memcpy(data, buf, size);
+   }
+   free(buf);
+
+lock_out:
+   mtd_lock(mtd, lock_offs, lock_len);
+
+   return ret;
+}
+
+static int fwu_mtd_load_mdata(struct mtd_info *mtd, struct fwu_mdata **mdata,
+ u32 offs, bool primary)
+{
+   size_t size = sizeof(struct fwu_mdata);
+   int ret;
+
+   *mdata = malloc(size);
+   if (!*mdata)
+   return -ENOMEM;
+
+   ret = mtd_io_data(mtd, offs, size, (void *)*mdata, FWU_MTD_READ);
+   if (ret >= 0) {
+   ret = fwu_verify_mdata(*mdata, primary);
+   if (ret < 0) {
+   free(*mdata);
+   *mdata = NULL;
+   }
+   }
+
+   return ret;
+}
+
+static int fwu_mtd_load_primary_mdata(struct fwu_mdata_mtd_priv *mtd_priv,
+struct fwu_mdata **mdata)
+{
+   return fwu_mtd_load_mdata(mtd_priv->mtd, mdata, mtd_priv->pri_offset, 
true);
+}
+
+static int fwu_mtd_load_secondary_mdata(struct fwu_mdata_mtd_priv 

[PATCH 1/5] dt/bindings: Add bindings for FWU Metadata mtd storage

2022-07-22 Thread jassisinghbrar
From: Sughosh Ganu 

Add bindings needed for accessing the FWU metadata regions.
These include the compatible string which point to the access
method, the actual device which stores the FWU metadata and
the offsets for both metadata regions.

The current patch adds basic bindings needed for accessing the
metadata structure on non-GPT mtd regions.

Signed-off-by: Masami Hiramatsu 
Signed-off-by: Jassi Brar 
---
 .../firmware/fwu-mdata-mtd.yaml   | 38 +++
 1 file changed, 38 insertions(+)
 create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml

diff --git a/doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml 
b/doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml
new file mode 100644
index 00..4f5404f999
--- /dev/null
+++ b/doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/firmware/u-boot,fwu-mdata-sf.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: FWU metadata on MTD device without GPT
+
+maintainers:
+ - Masami Hiramatsu 
+
+properties:
+  compatible:
+items:
+  - const: u-boot,fwu-mdata-mtd
+
+  fwu-mdata-store:
+maxItems: 1
+description: Phandle of the MTD device which contains the FWU medatata.
+
+  mdata-offsets:
+minItems: 2
+description: Offsets of the primary and secondary FWU metadata in the NOR 
flash.
+
+required:
+  - compatible
+  - fwu-mdata-store
+  - mdata-offsets
+
+additionalProperties: false
+
+examples:
+  - |
+fwu-mdata {
+compatible = "u-boot,fwu-mdata-mtd";
+fwu-mdata-store = <>;
+mdata-offsets = <0x50 0x53>;
+};
-- 
2.25.1



[PATCH 0/5] FWU: Add support for mtd backed feature on DeveloperBox

2022-07-22 Thread jassisinghbrar
From: Jassi Brar 

The mtd and synquacer (developerbox) support was dropped from v6[1]
This patchset re-introduces the support over last v7[2] submission of the 
patchset.

All the comments on this code over v5 submission have been addressed. Moving 
forward
a changelog will be maintained.

[1] 
https://lore.kernel.org/all/20220704051658.1085442-1-sughosh.g...@linaro.org/
[2] https://lore.kernel.org/all/20220714183913.118505-1-sughosh.g...@linaro.org/

Jassi Brar (2):
  dt: fwu: developerbox: enable fwu banks and mdata regions
  fwu: DeveloperBox: add support for FWU

Sughosh Ganu (3):
  dt/bindings: Add bindings for FWU Metadata mtd storage
  FWU: Add FWU metadata access driver for MTD storage regions
  FWU: mtd: Add helper functions for accessing FWU metadata

 .../synquacer-sc2a11-developerbox-u-boot.dtsi |  22 +-
 board/socionext/developerbox/Makefile |   1 +
 board/socionext/developerbox/developerbox.c   |  13 +
 board/socionext/developerbox/fwu_plat.c   |  95 ++
 configs/synquacer_developerbox_defconfig  |  13 +-
 doc/board/socionext/developerbox.rst  |  96 ++
 .../firmware/fwu-mdata-mtd.yaml   |  38 +++
 drivers/fwu-mdata/Kconfig |   8 +
 drivers/fwu-mdata/Makefile|   1 +
 drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++
 include/configs/synquacer.h   |  10 +
 lib/fwu_updates/Makefile  |   1 +
 lib/fwu_updates/fwu_mtd.c | 173 ++
 13 files changed, 776 insertions(+), 3 deletions(-)
 create mode 100644 board/socionext/developerbox/fwu_plat.c
 create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml
 create mode 100644 drivers/fwu-mdata/fwu_mdata_mtd.c
 create mode 100644 lib/fwu_updates/fwu_mtd.c

-- 
2.25.1



[PATCH 0/5] FWU: Add support for mtd backed feature on DeveloperBox

2022-07-22 Thread jassisinghbrar
From: Jassi Brar 

The mtd and synquacer (developerbox) support was dropped from v6[1]
This patchset re-introduces the support over last v7[2] submission of the 
patchset.

All the comments on this code over v5 submission have been addressed. Moving 
forward
a changelog will be maintained.

[1] 
https://lore.kernel.org/all/20220704051658.1085442-1-sughosh.g...@linaro.org/
[2] https://lore.kernel.org/all/20220714183913.118505-1-sughosh.g...@linaro.org/

Jassi Brar (2):
  dt: fwu: developerbox: enable fwu banks and mdata regions
  fwu: DeveloperBox: add support for FWU

Sughosh Ganu (3):
  dt/bindings: Add bindings for FWU Metadata mtd storage
  FWU: Add FWU metadata access driver for MTD storage regions
  FWU: mtd: Add helper functions for accessing FWU metadata

 .../synquacer-sc2a11-developerbox-u-boot.dtsi |  22 +-
 board/socionext/developerbox/Makefile |   1 +
 board/socionext/developerbox/developerbox.c   |  13 +
 board/socionext/developerbox/fwu_plat.c   |  95 ++
 configs/synquacer_developerbox_defconfig  |  13 +-
 doc/board/socionext/developerbox.rst  |  96 ++
 .../firmware/fwu-mdata-mtd.yaml   |  38 +++
 drivers/fwu-mdata/Kconfig |   8 +
 drivers/fwu-mdata/Makefile|   1 +
 drivers/fwu-mdata/fwu_mdata_mtd.c | 308 ++
 include/configs/synquacer.h   |  10 +
 lib/fwu_updates/Makefile  |   1 +
 lib/fwu_updates/fwu_mtd.c | 173 ++
 13 files changed, 776 insertions(+), 3 deletions(-)
 create mode 100644 board/socionext/developerbox/fwu_plat.c
 create mode 100644 doc/device-tree-bindings/firmware/fwu-mdata-mtd.yaml
 create mode 100644 drivers/fwu-mdata/fwu_mdata_mtd.c
 create mode 100644 lib/fwu_updates/fwu_mtd.c

-- 
2.25.1



[PATCH] Revert "power: pmic: rk8xx: Support sysreset shutdown method"

2022-07-22 Thread Chris Morgan
From: Chris Morgan 

This reverts commit ad607512f5757f4485968efd5bcf2c0245a8a235.

It was found during extensive testing that this causes problems
on certain boards. I was able to test this patch on a second
device (an Anbernic RG353) and it resulted in similar failures.

Signed-off-by: Chris Morgan 
---
 drivers/power/pmic/rk8xx.c | 50 +-
 1 file changed, 1 insertion(+), 49 deletions(-)

diff --git a/drivers/power/pmic/rk8xx.c b/drivers/power/pmic/rk8xx.c
index 25ef621f8d..8d703112c3 100644
--- a/drivers/power/pmic/rk8xx.c
+++ b/drivers/power/pmic/rk8xx.c
@@ -6,50 +6,10 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
-#include 
-
-static int rk8xx_sysreset_request(struct udevice *dev, enum sysreset_t type)
-{
-   struct rk8xx_priv *priv = dev_get_priv(dev->parent);
-
-   if (type != SYSRESET_POWER_OFF)
-   return -EPROTONOSUPPORT;
-
-   switch (priv->variant) {
-   case RK805_ID:
-   case RK808_ID:
-   case RK816_ID:
-   case RK818_ID:
-   pmic_clrsetbits(dev->parent, REG_DEVCTRL, 0, BIT(0));
-   break;
-   case RK809_ID:
-   case RK817_ID:
-   pmic_clrsetbits(dev->parent, RK817_REG_SYS_CFG3, 0,
-   BIT(0));
-   break;
-   default:
-   printf("Unknown PMIC RK%x: Cannot shutdown\n",
-  priv->variant);
-   return -EPROTONOSUPPORT;
-   };
-
-   return -EINPROGRESS;
-}
-
-static struct sysreset_ops rk8xx_sysreset_ops = {
-   .request= rk8xx_sysreset_request,
-};
-
-U_BOOT_DRIVER(rk8xx_sysreset) = {
-   .name   = "rk8xx_sysreset",
-   .id = UCLASS_SYSRESET,
-   .ops= _sysreset_ops,
-};
 
 /* In the event of a plug-in and the appropriate option has been
  * selected, we simply shutdown instead of continue the normal boot
@@ -133,7 +93,7 @@ static int rk8xx_read(struct udevice *dev, uint reg, uint8_t 
*buff, int len)
 static int rk8xx_bind(struct udevice *dev)
 {
ofnode regulators_node;
-   int children, ret;
+   int children;
 
regulators_node = dev_read_subnode(dev, "regulators");
if (!ofnode_valid(regulators_node)) {
@@ -144,14 +104,6 @@ static int rk8xx_bind(struct udevice *dev)
 
debug("%s: '%s' - found regulators subnode\n", __func__, dev->name);
 
-   if (CONFIG_IS_ENABLED(SYSRESET)) {
-   ret = device_bind_driver_to_node(dev, "rk8xx_sysreset",
-"rk8xx_sysreset",
-dev_ofnode(dev), NULL);
-   if (ret)
-   return ret;
-   }
-
children = pmic_bind_children(dev, regulators_node, pmic_children_info);
if (!children)
debug("%s: %s - no child found\n", __func__, dev->name);
-- 
2.25.1



Re: [PATCH v4 00/14] Port manufacturer specific initialization

2022-07-22 Thread Michael Nazzareno Trimarchi
Hi Dario

On Fri, Jul 22, 2022 at 6:11 PM Dario Binacchi
 wrote:
>
> In preparation of re-sync of mtd stack, we opt to move the current stack
> slowly in order to have a more easy sync and test. We would like to
> prepare uboot to support no-jedec and no-onfi compliant nand so we need
> to clean up a bit the code we have now and upstream some of the support.
> In this series we expect no functional change
>
> Tested on:
>  - imx6ull Micron   MT29F2G08ABAGAH4
>  - imx8mn  Macronix MX30LF4G18AC
>
> Changes in v4:
> - Add the patch "mtd: nand: Fix MediaTek MT7621 SoC build" to the series.
>
> Changes in v3:
> - Use commit sha1 with 13 digits.
> - Use commit sha1 with 13 digits.
> - Fix code style warnings raised by patman.
> - Use commit sha1 with 13 digits.
> - Fix code style warnings raised by patman.
> - Fix code style warnings raised by patman.
> - Use commit sha1 with 13 digits.
> - Fix code style warnings raised by patman.
> - Add the SPDX-License-Identifier tag.
> - Use commit sha1 with 13 digits.
> - Add the SPDX-License-Identifier tag.
> - Fix code style warnings raised by patman.
> - Use commit sha1 with 13 digits.
> - Add the SPDX-License-Identifier tag.
> - Fix code style warnings raised by patman.
> - Use commit sha1 with 13 digits.
> - Add the SPDX-License-Identifier tag.
> - Fix code style warnings raised by patman.
> - Use commit sha1 with 13 digits.
> - Add the SPDX-License-Identifier tag.
> - Fix code style warnings raised by patman.
> - Use commit sha1 with 13 digits.
> - Add the SPDX-License-Identifier tag.
> - Fix code style warnings raised by patman.
> - Use commit sha1 with 13 digits.
> - Use commit sha1 with 13 digits.
> - Wrap commit description to a maximum of 75 chars.
>
> Changes in v2:
> - Use short-commit form.
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Use short-commit form.
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Use short-commit form.
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Use short-commit form.
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Adjust the include file in nand_samsung.
> - Use short-commit form
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Adjust the include file in nand_hynix.
> - Use short-commit form
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Adjust the include file in nand_toshiba.
> - Use short-commit form
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Adjust the include file in nand_micron.
> - Use short-commit form
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Adjust the include file in nand_amd.
> - Use short-commit form
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Adjust the include file in nand_macronix.
> - Use short-commit form
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
> - Use short-commit form.
> - Remove linux info. Uboot seems that backport without add this
>   extra information.
>
> Michael Trimarchi (14):
>   mtd: nand: Get rid of busw parameter
>   mtd: nand: Store nand ID in struct nand_chip
>   mtd: nand: Add manufacturer specific initialization/detection steps
>   mtd: nand: Get rid of mtd variable in function calls
>   mtd: nand: Fix MediaTek MT7621 SoC build
>   mtd: nand: Export symbol nand_decode_ext_id
>   mtd: nand: Move Samsung specific init/detection logic in
> nand_samsung.c
>   mtd: nand: Move Hynix specific init/detection logic in nand_hynix.c
>   mtd: nand: Move Toshiba specific init/detection logic in
> nand_toshiba.c
>   mtd: nand: Move Micron specific init logic in nand_micron.c
>   mtd: nand: Move AMD/Spansion specific init/detection logic in
> nand_amd.c
>   mtd: nand: Move Macronix specific initialization in nand_macronix.c
>   mtd: nand: toshiba: Retrieve ECC requirements from extended ID
>   mtd: decommission the NAND museum
>
>  drivers/mtd/nand/raw/Makefile|  10 +-
>  drivers/mtd/nand/raw/mt7621_nand.c   |   2 +-
>  drivers/mtd/nand/raw/nand_amd.c  |  52 
>  drivers/mtd/nand/raw/nand_base.c | 370 ++-
>  drivers/mtd/nand/raw/nand_hynix.c|  85 ++
>  drivers/mtd/nand/raw/nand_ids.c  |  24 +-
>  drivers/mtd/nand/raw/nand_macronix.c |  31 +++
>  drivers/mtd/nand/raw/nand_micron.c   |  87 +++
>  drivers/mtd/nand/raw/nand_samsung.c  |  90 +++
>  drivers/mtd/nand/raw/nand_toshiba.c  |  79 ++
>  include/linux/mtd/rawnand.h  |  78 --
>  11 files changed, 626 insertions(+), 282 deletions(-)
>  create mode 100644 drivers/mtd/nand/raw/nand_amd.c
>  create mode 100644 drivers/mtd/nand/raw/nand_hynix.c
>  create mode 100644 drivers/mtd/nand/raw/nand_macronix.c
>  

Re: [PATCH v5 19/23] FWU: synquacer: Add FWU Multi bank update support for DeveloperBox

2022-07-22 Thread Jassi Brar
On Fri, Jul 22, 2022 at 3:37 AM Ilias Apalodimas
 wrote:
>
> Hi Jassi
>
> On Wed, 20 Jul 2022 at 17:30, Jassi Brar  wrote:
> >
> > On Wed, Jul 20, 2022 at 2:54 AM Ilias Apalodimas
> >  wrote:
> > >
> > > Hi Jassi,
> > >
> > > On Tue, 19 Jul 2022 at 18:27, Jassi Brar  
> > > wrote:
> > > >
> > > > On Mon, 18 Jul 2022 at 16:00, Tom Rini  wrote:
> > > > > On Mon, Jul 18, 2022 at 10:31:56AM -0500, Jassi Brar wrote:
> > > >
> > > > > > > > > >
> > > > > > > > > > > > +
> > > > > > > > > > > > +#define PLAT_METADATA_OFFSET 0x51
> > > > > > > > > > > > +#define PLAT_METADATA_SIZE   (sizeof(struct 
> > > > > > > > > > > > devbox_metadata))
> > > > > > > > > > > > +
> > > > > > > > > > > > +struct __packed devbox_metadata {
> > > > > > > > > > > > + u32 boot_index;
> > > > > > > > > > > > + u32 boot_count;
> > > > > > > > > > >
> > > > > > > > > > > There is the whole bootcount infrastructure for this. I 
> > > > > > > > > > > think it would be much
> > > > > > > > > > > better to use that framework instead of creating parallel 
> > > > > > > > > > > one.
> > > > > > > > > > >
> > > > > > > > > > Yes, this goes too.
> > > > > > > > >
> > > > > > > > > Is bootcount really suited for this case?
> > > > > > > > > AFAIK bootcount either requires device specific registers 
> > > > > > > > > (which won't
> > > > > > > > > reset on reboots), or an environment you can write data to.
> > > > > > > > > But what if a user wants to disable writing the env variables 
> > > > > > > > > and the
> > > > > > > > > device doesn't have a set of registers we can use?
> > > > > > > > >
> > > > > > > > Maybe it should be moved in 'struct fwu_mdata' ?
> > > > > > >
> > > > > > > I was mostly thinking on moving this count as another 'bootcount'
> > > > > > > method.  So in case the user has disabled writing evn variables 
> > > > > > > but he
> > > > > > > is booting with EFI he can use that.
> > > > > >
> > > > > > Sorry, not sure I understand IIUIC there has to be some 
> > > > > > persistent storage.
> > > > >
> > > > > No, there just has to be "somewhere" to do the counting.  We've got a
> > > > > DDR backed driver, for example.  So yes, I think we should try and use
> > > > > the bootcount framework here.
> > > > >
> > > > OK, for platforms that can preserve ram across reboot, using
> > > > non-persistent storage can work.
> > > > My platform neither preserves ram, nor has any warmreset-proof
> > > > registers. So I have to choose between saving the bootcount in efi-env
> > > > or in vendor specific structure next to the metadata. I prefer
> > > > metadata because it is common to all stages of boot. Any corrections
> > > > to this approach?
> > >
> > > The metadata is defined by a spec and they don't have a field for
> > > bootcounting.  Once Sughosh resends his patches he'll include a
> > > bootcount backend that reuses EFI variables.  Can't we just use that?
> > >
> > Yes, I am aware metadata spec has no provision of vendor data. But
> > there is nothing illegal in appending vendor-data to metadata and that
> > is trivial to implement ... basically use   sizeof(struct fwu_mdata) +
> > sizeof(struct sni_vendor_mdata)  while read/write meta-data. That will
> > also be zero extra-overhead.
> >
> > fwu-mdata {
> >compatible = "u-boot,fwu-mdata-mtd";
> >fwu-mdata-store = <_flash>;
> >mdata-offsets = <0x50 0x53>;
> >vendor-data-size = <0x100>;   // optional
> > };
> >
> > Sure we can use an efi variable, but I see more uses of vendor-data
> > :- shared among BL1/BL2/BL3x/OS so we can emulate reset-syndrome,
> > crash-logging, per-image bootcount etc when the h/w doesn't support
> > these features.
> >
> > Ofcourse, please feel free to implement efi-variables still.
>
> Ok, in that case, you'll still have to implement this as a 'special'
> bootcount method since the A/B updates code will use that API to
> get/set the values.
>
I thought the bootcount mechanism would always be platform specific?
But ok.

thanks.


Re: [PATCH] sunxi-mmc: increase stabilization delay from 1ms to 20ms

2022-07-22 Thread Andre Przywara

On 21/07/2022 23:08, Da Xue wrote:

Hi,


Some users experienced problems booting u-boot from SPL hanging here:

Trying to boot from MMC1 or Trying to boot from MMC2

This seems to occur with both MicroSD and eMMC modules on ALL-H3-CC.
Increasing the delay after mmc reset fixes these boot problems.
Some MicroSD cards are impacted more than others so it is possible that
MicroSD internals need time to stabilize. Below is some failure data.

sandisk ultra   64gb 9/20 with 1ms,  20/20 with 10ms
sandisk ultra   16gb 2/20 with 1ms,  20/20 with 10ms
sandisk extreme 16gb 6/20 with 10ms, 20/20 with 20ms

A quick comparison of schematics show series resistors for ESD
protection on the MicroSD GPIOs not present on all H3/H5 boards.
It is not known if this is related to the issue.

This patch adds a fixed 20ms delay to mmc init to mitigate the problem.
If boot time optimization is required and the platform does not require
the delay. The delay can be replaced with:

writel(SUNXI_MMC_GCTRL_RESET, >reg->gctrl);
if (wait_for_bit_le32( >reg->gctrl,
SUNXI_MMC_GCTRL_RESET, false, 20, false)) {
printf("%s: Timeout\n", __func__);
return -ETIMEDOUT;
}


So what about adding this for everyone (we should have it regardless) then?

And then have an extra Kconfig option to specify an extra delay, and 
define this only in your board defconfig? Because IIUC this is specific

to your board?

And as I mentioned: it looks odd to have this here and have it fixing 
your SD card problems:
- The soft reset should reset just the internal controller logic (MMC 
state machine and FIFOs), this shouldn't affect cards. IIUC, nothing 
should happen on the MMC *pins* because of this operation.

- Why isn't this a problem for U-Boot proper, and Linux, FWIW?

Cheers,
Andre



Signed-off-by: Da Xue 
---
  drivers/mmc/sunxi_mmc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/sunxi_mmc.c b/drivers/mmc/sunxi_mmc.c
index 1bb7b6d0e9..f7942b69ce 100644
--- a/drivers/mmc/sunxi_mmc.c
+++ b/drivers/mmc/sunxi_mmc.c
@@ -297,7 +297,7 @@ static int sunxi_mmc_core_init(struct mmc *mmc)

   /* Reset controller */
   writel(SUNXI_MMC_GCTRL_RESET, >reg->gctrl);
- udelay(1000);
+ udelay(2);

   return 0;
  }




[PATCH v4 12/14] mtd: nand: Move Macronix specific initialization in nand_macronix.c

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit 3b5206f4be9b65.

Move Macronix specific initialization logic into nand_macronix.c. This
is part of the "separate vendor specific code from core" cleanup
process.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.

Changes in v2:
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_macronix.

 drivers/mtd/nand/raw/Makefile|  4 +++-
 drivers/mtd/nand/raw/nand_base.c | 11 --
 drivers/mtd/nand/raw/nand_ids.c  |  2 +-
 drivers/mtd/nand/raw/nand_macronix.c | 31 
 include/linux/mtd/rawnand.h  |  1 +
 5 files changed, 36 insertions(+), 13 deletions(-)
 create mode 100644 drivers/mtd/nand/raw/nand_macronix.c

diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile
index 9c2ced9925d8..a398aa9d8864 100644
--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -14,7 +14,8 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o
 obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o
 obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
-obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_amd.o nand_hynix.o 
nand_micron.o \
+obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_amd.o nand_hynix.o \
+   nand_macronix.o nand_micron.o \
nand_samsung.o nand_toshiba.o
 obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o
 obj-$(CONFIG_TPL_NAND_INIT) += nand.o
@@ -34,6 +35,7 @@ obj-y += nand_ecc.o
 obj-y += nand_base.o
 obj-y += nand_amd.o
 obj-y += nand_hynix.o
+obj-y += nand_macronix.o
 obj-y += nand_micron.o
 obj-y += nand_samsung.o
 obj-y += nand_toshiba.o
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 68e6f4f14347..4b09a1128827 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4217,22 +4217,11 @@ static void nand_decode_id(struct nand_chip *chip, 
struct nand_flash_dev *type)
 static void nand_decode_bbm_options(struct mtd_info *mtd,
struct nand_chip *chip)
 {
-   int maf_id = chip->id.data[0];
-
/* Set the bad block position */
if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16))
chip->badblockpos = NAND_LARGE_BADBLOCK_POS;
else
chip->badblockpos = NAND_SMALL_BADBLOCK_POS;
-
-   /*
-* Bad block marker is stored in the last page of each block on Samsung
-* and Hynix MLC devices; stored in first two pages of each block on
-* Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba,
-* AMD/Spansion, and Macronix.  All others scan only the first page.
-*/
-   if (nand_is_slc(chip) && maf_id == NAND_MFR_MACRONIX)
-   chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
 }
 
 static inline bool is_full_id_nand(struct nand_flash_dev *type)
diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c
index c78f2e088040..7602dd30f169 100644
--- a/drivers/mtd/nand/raw/nand_ids.c
+++ b/drivers/mtd/nand/raw/nand_ids.c
@@ -197,7 +197,7 @@ struct nand_manufacturers nand_manuf_ids[] = {
{NAND_MFR_HYNIX, "Hynix", _nand_manuf_ops},
{NAND_MFR_MICRON, "Micron", _nand_manuf_ops},
{NAND_MFR_AMD, "AMD/Spansion", _nand_manuf_ops},
-   {NAND_MFR_MACRONIX, "Macronix"},
+   {NAND_MFR_MACRONIX, "Macronix", _nand_manuf_ops},
{NAND_MFR_EON, "Eon"},
{NAND_MFR_SANDISK, "SanDisk"},
{NAND_MFR_INTEL, "Intel"},
diff --git a/drivers/mtd/nand/raw/nand_macronix.c 
b/drivers/mtd/nand/raw/nand_macronix.c
new file mode 100644
index ..dc972e590922
--- /dev/null
+++ b/drivers/mtd/nand/raw/nand_macronix.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Free Electrons
+ * Copyright (C) 2017 NextThing Co
+ *
+ * Author: Boris Brezillon 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+
+static int macronix_nand_init(struct nand_chip *chip)
+{
+   if (nand_is_slc(chip))
+   chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
+
+   return 0;
+}
+
+const struct nand_manufacturer_ops macronix_nand_manuf_ops = {
+   .init = 

[PATCH v4 11/14] mtd: nand: Move AMD/Spansion specific init/detection logic in nand_amd.c

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit 229204da53b31d.

Move AMD/Spansion specific initialization/detection logic into
nand_amd.c. This is part of the "separate vendor specific code from
core" cleanup process.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.

Changes in v2:
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_amd.

 drivers/mtd/nand/raw/Makefile|  4 ++-
 drivers/mtd/nand/raw/nand_amd.c  | 52 
 drivers/mtd/nand/raw/nand_base.c | 17 +--
 drivers/mtd/nand/raw/nand_ids.c  |  2 +-
 include/linux/mtd/rawnand.h  |  1 +
 5 files changed, 58 insertions(+), 18 deletions(-)
 create mode 100644 drivers/mtd/nand/raw/nand_amd.c

diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile
index 8ef30b45fd2d..9c2ced9925d8 100644
--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -14,7 +14,8 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o
 obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o
 obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
-obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_micron.o 
nand_samsung.o nand_toshiba.o
+obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_amd.o nand_hynix.o 
nand_micron.o \
+   nand_samsung.o nand_toshiba.o
 obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o
 obj-$(CONFIG_TPL_NAND_INIT) += nand.o
 ifeq ($(CONFIG_SPL_ENV_SUPPORT),y)
@@ -31,6 +32,7 @@ obj-y += nand_ids.o
 obj-y += nand_util.o
 obj-y += nand_ecc.o
 obj-y += nand_base.o
+obj-y += nand_amd.o
 obj-y += nand_hynix.o
 obj-y += nand_micron.o
 obj-y += nand_samsung.o
diff --git a/drivers/mtd/nand/raw/nand_amd.c b/drivers/mtd/nand/raw/nand_amd.c
new file mode 100644
index ..e02b8c79dba2
--- /dev/null
+++ b/drivers/mtd/nand/raw/nand_amd.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Free Electrons
+ * Copyright (C) 2017 NextThing Co
+ *
+ * Author: Boris Brezillon 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+
+static void amd_nand_decode_id(struct nand_chip *chip)
+{
+   struct mtd_info *mtd = nand_to_mtd(chip);
+
+   nand_decode_ext_id(chip);
+
+   /*
+* Check for Spansion/AMD ID + repeating 5th, 6th byte since
+* some Spansion chips have erasesize that conflicts with size
+* listed in nand_ids table.
+* Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39)
+*/
+   if (chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 &&
+   chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 &&
+   mtd->writesize == 512) {
+   mtd->erasesize = 128 * 1024;
+   mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1);
+   }
+}
+
+static int amd_nand_init(struct nand_chip *chip)
+{
+   if (nand_is_slc(chip))
+   chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
+
+   return 0;
+}
+
+const struct nand_manufacturer_ops amd_nand_manuf_ops = {
+   .detect = amd_nand_decode_id,
+   .init = amd_nand_init,
+};
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index fe7e049d4064..68e6f4f14347 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4200,7 +4200,6 @@ static int nand_manufacturer_init(struct nand_chip *chip)
 static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type)
 {
struct mtd_info *mtd = >mtd;
-   int maf_id = chip->id.data[0];
 
mtd->erasesize = type->erasesize;
mtd->writesize = type->pagesize;
@@ -4208,19 +4207,6 @@ static void nand_decode_id(struct nand_chip *chip, 
struct nand_flash_dev *type)
 
/* All legacy ID NAND are small-page, SLC */
chip->bits_per_cell = 1;
-
-   /*
-* Check for Spansion/AMD ID + repeating 5th, 6th byte since
-* some Spansion chips have erasesize that conflicts with size
-* listed in nand_ids table.
-* Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39)
-*/
-   if (maf_id == NAND_MFR_AMD && chip->id.data[4] != 0x00 &&
-   chip->id.data[5] == 0x00 && chip->id.data[6] == 0x00 &&
-   chip->id.data[7] == 0x00 && 

[PATCH v4 10/14] mtd: nand: Move Micron specific init logic in nand_micron.c

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit 10d4e75c36f6c1.

Move Micron specific initialization logic into nand_micron.c. This is
part of the "separate vendor specific code from core" cleanup process.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.

Changes in v2:
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_micron.

 drivers/mtd/nand/raw/Makefile  |  3 +-
 drivers/mtd/nand/raw/nand_base.c   | 33 +---
 drivers/mtd/nand/raw/nand_ids.c|  2 +-
 drivers/mtd/nand/raw/nand_micron.c | 87 ++
 include/linux/mtd/rawnand.h| 21 +---
 5 files changed, 93 insertions(+), 53 deletions(-)
 create mode 100644 drivers/mtd/nand/raw/nand_micron.c

diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile
index 16e0775395a2..8ef30b45fd2d 100644
--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o
 obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o
 obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
-obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.o 
nand_toshiba.o
+obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_micron.o 
nand_samsung.o nand_toshiba.o
 obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o
 obj-$(CONFIG_TPL_NAND_INIT) += nand.o
 ifeq ($(CONFIG_SPL_ENV_SUPPORT),y)
@@ -32,6 +32,7 @@ obj-y += nand_util.o
 obj-y += nand_ecc.o
 obj-y += nand_base.o
 obj-y += nand_hynix.o
+obj-y += nand_micron.o
 obj-y += nand_samsung.o
 obj-y += nand_toshiba.o
 obj-y += nand_timings.o
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 4ea7f10a06fc..fe7e049d4064 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -3871,30 +3871,6 @@ ext_out:
return ret;
 }
 
-static int nand_setup_read_retry_micron(struct mtd_info *mtd, int retry_mode)
-{
-   struct nand_chip *chip = mtd_to_nand(mtd);
-   uint8_t feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode};
-
-   return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY,
-   feature);
-}
-
-/*
- * Configure chip properties from Micron vendor-specific ONFI table
- */
-static void nand_onfi_detect_micron(struct nand_chip *chip,
-   struct nand_onfi_params *p)
-{
-   struct nand_onfi_vendor_micron *micron = (void *)p->vendor;
-
-   if (le16_to_cpu(p->vendor_revision) < 1)
-   return;
-
-   chip->read_retries = micron->read_retry_options;
-   chip->setup_read_retry = nand_setup_read_retry_micron;
-}
-
 /*
  * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise.
  */
@@ -3994,9 +3970,6 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, 
struct nand_chip *chip)
pr_warn("Could not retrieve ONFI ECC requirements\n");
}
 
-   if (p->jedec_id == NAND_MFR_MICRON)
-   nand_onfi_detect_micron(chip, p);
-
return 1;
 }
 #else
@@ -4272,10 +4245,8 @@ static void nand_decode_bbm_options(struct mtd_info *mtd,
 * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba,
 * AMD/Spansion, and Macronix.  All others scan only the first page.
 */
-   if ((nand_is_slc(chip) &&
-(maf_id == NAND_MFR_AMD ||
- maf_id == NAND_MFR_MACRONIX)) ||
-   (mtd->writesize == 2048 && maf_id == NAND_MFR_MICRON))
+   if (nand_is_slc(chip) &&
+   (maf_id == NAND_MFR_AMD || maf_id == NAND_MFR_MACRONIX))
chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
 }
 
diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c
index 509652c8e26c..bb5ac8337fde 100644
--- a/drivers/mtd/nand/raw/nand_ids.c
+++ b/drivers/mtd/nand/raw/nand_ids.c
@@ -195,7 +195,7 @@ struct nand_manufacturers nand_manuf_ids[] = {
{NAND_MFR_RENESAS, "Renesas"},
{NAND_MFR_STMICRO, "ST Micro"},
{NAND_MFR_HYNIX, "Hynix", _nand_manuf_ops},
-   {NAND_MFR_MICRON, "Micron"},
+   {NAND_MFR_MICRON, "Micron", _nand_manuf_ops},
{NAND_MFR_AMD, "AMD/Spansion"},
{NAND_MFR_MACRONIX, "Macronix"},
{NAND_MFR_EON, "Eon"},
diff --git a/drivers/mtd/nand/raw/nand_micron.c 
b/drivers/mtd/nand/raw/nand_micron.c
new file mode 100644
index ..8b31c6198134
--- /dev/null
+++ b/drivers/mtd/nand/raw/nand_micron.c
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Free Electrons
+ * Copyright (C) 2017 NextThing Co
+ *
+ * Author: Boris Brezillon 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 

[PATCH v4 09/14] mtd: nand: Move Toshiba specific init/detection logic in nand_toshiba.c

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit 9b2d61f80b060c.

Move Toshiba specific initialization and detection logic into
nand_toshiba.c. This is part of the "separate vendor specific code from
core" cleanup process.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.

Changes in v2:
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_toshiba.

 drivers/mtd/nand/raw/Makefile   |  3 +-
 drivers/mtd/nand/raw/nand_base.c| 21 ++--
 drivers/mtd/nand/raw/nand_ids.c |  2 +-
 drivers/mtd/nand/raw/nand_toshiba.c | 53 +
 include/linux/mtd/rawnand.h |  1 +
 5 files changed, 59 insertions(+), 21 deletions(-)
 create mode 100644 drivers/mtd/nand/raw/nand_toshiba.c

diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile
index 86d9b8e8beb8..16e0775395a2 100644
--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o
 obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o
 obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
-obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.o
+obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.o 
nand_toshiba.o
 obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o
 obj-$(CONFIG_TPL_NAND_INIT) += nand.o
 ifeq ($(CONFIG_SPL_ENV_SUPPORT),y)
@@ -33,6 +33,7 @@ obj-y += nand_ecc.o
 obj-y += nand_base.o
 obj-y += nand_hynix.o
 obj-y += nand_samsung.o
+obj-y += nand_toshiba.o
 obj-y += nand_timings.o
 
 endif # not spl
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 5698c1e6a229..4ea7f10a06fc 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4163,12 +4163,11 @@ static int nand_get_bits_per_cell(u8 cellinfo)
 void nand_decode_ext_id(struct nand_chip *chip)
 {
struct mtd_info *mtd = >mtd;
-   int extid, id_len;
+   int extid;
/* The 3rd id byte holds MLC / multichip data */
chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]);
/* The 4th id byte is the important one */
extid = chip->id.data[3];
-   id_len = chip->id.len;
 
/* Calc pagesize */
mtd->writesize = 1024 << (extid & 0x03);
@@ -4184,21 +4183,6 @@ void nand_decode_ext_id(struct nand_chip *chip)
/* Get buswidth information */
if (extid & 0x1)
chip->options |= NAND_BUSWIDTH_16;
-
-   /*
-* Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per
-* 512B page. For Toshiba SLC, we decode the 5th/6th byte as
-* follows:
-* - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm,
-* 110b -> 24nm
-* - ID byte 5, bit[7]:1 -> BENAND, 0 -> raw SLC
-*/
-   if (id_len >= 6 && chip->id.data[0] == NAND_MFR_TOSHIBA &&
-   nand_is_slc(chip) &&
-   (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ &&
-   !(chip->id.data[4] & 0x80) /* !BENAND */) {
-   mtd->oobsize = 32 * mtd->writesize >> 9;
-   }
 }
 EXPORT_SYMBOL_GPL(nand_decode_ext_id);
 
@@ -4289,8 +4273,7 @@ static void nand_decode_bbm_options(struct mtd_info *mtd,
 * AMD/Spansion, and Macronix.  All others scan only the first page.
 */
if ((nand_is_slc(chip) &&
-(maf_id == NAND_MFR_TOSHIBA ||
- maf_id == NAND_MFR_AMD ||
+(maf_id == NAND_MFR_AMD ||
  maf_id == NAND_MFR_MACRONIX)) ||
(mtd->writesize == 2048 && maf_id == NAND_MFR_MICRON))
chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c
index ec263a43279a..509652c8e26c 100644
--- a/drivers/mtd/nand/raw/nand_ids.c
+++ b/drivers/mtd/nand/raw/nand_ids.c
@@ -188,7 +188,7 @@ struct nand_flash_dev nand_flash_ids[] = {
 
 /* Manufacturer IDs */
 struct nand_manufacturers nand_manuf_ids[] = {
-   {NAND_MFR_TOSHIBA, "Toshiba"},
+   {NAND_MFR_TOSHIBA, "Toshiba", _nand_manuf_ops},
{NAND_MFR_SAMSUNG, "Samsung", _nand_manuf_ops},
{NAND_MFR_FUJITSU, "Fujitsu"},
{NAND_MFR_NATIONAL, "National"},
diff --git a/drivers/mtd/nand/raw/nand_toshiba.c 
b/drivers/mtd/nand/raw/nand_toshiba.c
new file mode 100644
index ..f7426fa59f51
--- /dev/null
+++ b/drivers/mtd/nand/raw/nand_toshiba.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Free Electrons
+ * Copyright (C) 2017 NextThing Co
+ *
+ * Author: Boris Brezillon 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public 

[PATCH v4 14/14] mtd: decommission the NAND museum

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit f7025a43a9da26.

The MTD subsystem has its own small museum of ancient NANDs in a form of
the CONFIG_MTD_NAND_MUSEUM_IDS configuration option. The museum contains
stone age NANDs with 256 bytes pages, as well as iron age NANDs with 512
bytes per page and up to 8MiB page size.

It is with great sorrow that I inform you that the museum is being
decommissioned. The MTD subsystem is out of budget for Kconfig options and
already has too many of them, and there is a general kernel trend to
simplify the configuration menu.

We remove the stone age exhibits along with closing the museum

REMARK Don't apply this part from upstream:

Some of the iron age ones are transferred to the regular NAND depot.
Namely, only those which have unique device IDs are transferred, and the
ones which have conflicting device IDs are removed.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Wrap commit description to a maximum of 75 chars.

Changes in v2:
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.

 drivers/mtd/nand/raw/nand_ids.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c
index 7602dd30f169..4dece1b20676 100644
--- a/drivers/mtd/nand/raw/nand_ids.c
+++ b/drivers/mtd/nand/raw/nand_ids.c
@@ -24,16 +24,6 @@
  * extended chip ID.
  */
 struct nand_flash_dev nand_flash_ids[] = {
-#ifdef CONFIG_MTD_NAND_MUSEUM_IDS
-   LEGACY_ID_NAND("NAND 1MiB 5V 8-bit",0x6e, 1, SZ_4K, SP_OPTIONS),
-   LEGACY_ID_NAND("NAND 2MiB 5V 8-bit",0x64, 2, SZ_4K, SP_OPTIONS),
-   LEGACY_ID_NAND("NAND 1MiB 3,3V 8-bit",  0xe8, 1, SZ_4K, SP_OPTIONS),
-   LEGACY_ID_NAND("NAND 1MiB 3,3V 8-bit",  0xec, 1, SZ_4K, SP_OPTIONS),
-   LEGACY_ID_NAND("NAND 2MiB 3,3V 8-bit",  0xea, 2, SZ_4K, SP_OPTIONS),
-   LEGACY_ID_NAND("NAND 4MiB 3,3V 8-bit",  0xd5, 4, SZ_8K, SP_OPTIONS),
-
-   LEGACY_ID_NAND("NAND 8MiB 3,3V 8-bit",  0xe6, 8, SZ_8K, SP_OPTIONS),
-#endif
/*
 * Some incompatible NAND chips share device ID's and so must be
 * listed by full ID. We list them first so that we can easily identify
-- 
2.32.0



[PATCH v4 13/14] mtd: nand: toshiba: Retrieve ECC requirements from extended ID

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit fb3bff5b407e58.

This patch enables support to read the ECC strength and size from the
NAND flash using Toshiba Memory SLC NAND extended-ID. This patch is
based on the information of the 6th ID byte of the Toshiba Memory SLC
NAND.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.

Changes in v2:
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.

 drivers/mtd/nand/raw/nand_toshiba.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/mtd/nand/raw/nand_toshiba.c 
b/drivers/mtd/nand/raw/nand_toshiba.c
index f7426fa59f51..99dc44df671a 100644
--- a/drivers/mtd/nand/raw/nand_toshiba.c
+++ b/drivers/mtd/nand/raw/nand_toshiba.c
@@ -37,6 +37,32 @@ static void toshiba_nand_decode_id(struct nand_chip *chip)
(chip->id.data[5] & 0x7) == 0x6 /* 24nm */ &&
!(chip->id.data[4] & 0x80) /* !BENAND */)
mtd->oobsize = 32 * mtd->writesize >> 9;
+
+   /*
+* Extract ECC requirements from 6th id byte.
+* For Toshiba SLC, ecc requrements are as follows:
+*  - 43nm: 1 bit ECC for each 512Byte is required.
+*  - 32nm: 4 bit ECC for each 512Byte is required.
+*  - 24nm: 8 bit ECC for each 512Byte is required.
+*/
+   if (chip->id.len >= 6 && nand_is_slc(chip)) {
+   chip->ecc_step_ds = 512;
+   switch (chip->id.data[5] & 0x7) {
+   case 0x4:
+   chip->ecc_strength_ds = 1;
+   break;
+   case 0x5:
+   chip->ecc_strength_ds = 4;
+   break;
+   case 0x6:
+   chip->ecc_strength_ds = 8;
+   break;
+   default:
+   WARN(1, "Could not get ECC info");
+   chip->ecc_step_ds = 0;
+   break;
+   }
+   }
 }
 
 static int toshiba_nand_init(struct nand_chip *chip)
-- 
2.32.0



[PATCH v4 08/14] mtd: nand: Move Hynix specific init/detection logic in nand_hynix.c

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit 01389b6bd2f4f7.

Move Hynix specific initialization and detection logic into
nand_hynix.c. This is part of the "separate vendor specific code from
core" cleanup process.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.

Changes in v2:
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_hynix.

 drivers/mtd/nand/raw/Makefile |   3 +-
 drivers/mtd/nand/raw/nand_base.c  | 117 --
 drivers/mtd/nand/raw/nand_hynix.c |  85 ++
 drivers/mtd/nand/raw/nand_ids.c   |   2 +-
 include/linux/mtd/rawnand.h   |   1 +
 5 files changed, 120 insertions(+), 88 deletions(-)
 create mode 100644 drivers/mtd/nand/raw/nand_hynix.c

diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile
index 440290bed0fe..86d9b8e8beb8 100644
--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o
 obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o
 obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
-obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_samsung.o
+obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.o
 obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o
 obj-$(CONFIG_TPL_NAND_INIT) += nand.o
 ifeq ($(CONFIG_SPL_ENV_SUPPORT),y)
@@ -31,6 +31,7 @@ obj-y += nand_ids.o
 obj-y += nand_util.o
 obj-y += nand_ecc.o
 obj-y += nand_base.o
+obj-y += nand_hynix.o
 obj-y += nand_samsung.o
 obj-y += nand_timings.o
 
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index fe59157bc3c4..5698c1e6a229 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4170,85 +4170,34 @@ void nand_decode_ext_id(struct nand_chip *chip)
extid = chip->id.data[3];
id_len = chip->id.len;
 
+   /* Calc pagesize */
+   mtd->writesize = 1024 << (extid & 0x03);
+   extid >>= 2;
+   /* Calc oobsize */
+   mtd->oobsize = (8 << (extid & 0x01)) *
+   (mtd->writesize >> 9);
+   extid >>= 2;
+   /* Calc blocksize. Blocksize is multiples of 64KiB */
+   mtd->erasesize = (64 * 1024) << (extid & 0x03);
+   extid >>= 2;
+   /* Get buswidth information */
+   /* Get buswidth information */
+   if (extid & 0x1)
+   chip->options |= NAND_BUSWIDTH_16;
+
/*
-* Field definitions are in the following datasheets:
-* Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32)
-* Hynix MLC   (6 byte ID): Hynix H27UBG8T2B (p.22)
-*
-* Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung
-* ID to decide what to do.
+* Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per
+* 512B page. For Toshiba SLC, we decode the 5th/6th byte as
+* follows:
+* - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm,
+* 110b -> 24nm
+* - ID byte 5, bit[7]:1 -> BENAND, 0 -> raw SLC
 */
-   if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX &&
-   !nand_is_slc(chip)) {
-   unsigned int tmp;
-
-   /* Calc pagesize */
-   mtd->writesize = 2048 << (extid & 0x03);
-   extid >>= 2;
-   /* Calc oobsize */
-   switch (((extid >> 2) & 0x04) | (extid & 0x03)) {
-   case 0:
-   mtd->oobsize = 128;
-   break;
-   case 1:
-   mtd->oobsize = 224;
-   break;
-   case 2:
-   mtd->oobsize = 448;
-   break;
-   case 3:
-   mtd->oobsize = 64;
-   break;
-   case 4:
-   mtd->oobsize = 32;
-   break;
-   case 5:
-   mtd->oobsize = 16;
-   break;
-   default:
-   mtd->oobsize = 640;
-   break;
-   }
-   extid >>= 2;
-   /* Calc blocksize */
-   tmp = ((extid >> 1) & 0x04) | (extid & 0x03);
-   if (tmp < 0x03)
-   mtd->erasesize = (128 * 1024) << tmp;
-   else if (tmp == 0x03)
-   mtd->erasesize = 768 * 1024;
-   else
-   mtd->erasesize = (64 * 1024) << tmp;
-   } else {
-   /* Calc pagesize */
-   mtd->writesize = 1024 << (extid & 0x03);
-   extid >>= 2;
-   /* Calc oobsize */
-

[PATCH v4 07/14] mtd: nand: Move Samsung specific init/detection logic in nand_samsung.c

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit c51d0ac59f2420.

Move Samsung specific initialization and detection logic into
nand_samsung.c. This is part of the "separate vendor specific code from
core" cleanup process.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Fix code style warnings raised by patman.
- Add the SPDX-License-Identifier tag.

Changes in v2:
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_samsung.

 drivers/mtd/nand/raw/Makefile   |  3 +-
 drivers/mtd/nand/raw/nand_base.c| 52 ++---
 drivers/mtd/nand/raw/nand_ids.c |  4 +-
 drivers/mtd/nand/raw/nand_samsung.c | 90 +
 include/linux/mtd/rawnand.h |  2 +
 5 files changed, 100 insertions(+), 51 deletions(-)
 create mode 100644 drivers/mtd/nand/raw/nand_samsung.c

diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile
index f278f31f5cd5..440290bed0fe 100644
--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -14,7 +14,7 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o
 obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o
 obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o
 obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o
-obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o
+obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_samsung.o
 obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o
 obj-$(CONFIG_TPL_NAND_INIT) += nand.o
 ifeq ($(CONFIG_SPL_ENV_SUPPORT),y)
@@ -31,6 +31,7 @@ obj-y += nand_ids.o
 obj-y += nand_util.o
 obj-y += nand_ecc.o
 obj-y += nand_base.o
+obj-y += nand_samsung.o
 obj-y += nand_timings.o
 
 endif # not spl
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 174c760f3416..fe59157bc3c4 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4173,48 +4173,13 @@ void nand_decode_ext_id(struct nand_chip *chip)
/*
 * Field definitions are in the following datasheets:
 * Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32)
-* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44)
 * Hynix MLC   (6 byte ID): Hynix H27UBG8T2B (p.22)
 *
 * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung
 * ID to decide what to do.
 */
-   if (id_len == 6 && chip->id.data[0] == NAND_MFR_SAMSUNG &&
-   !nand_is_slc(chip) && chip->id.data[5] != 0x00) {
-   /* Calc pagesize */
-   mtd->writesize = 2048 << (extid & 0x03);
-   extid >>= 2;
-   /* Calc oobsize */
-   switch (((extid >> 2) & 0x04) | (extid & 0x03)) {
-   case 1:
-   mtd->oobsize = 128;
-   break;
-   case 2:
-   mtd->oobsize = 218;
-   break;
-   case 3:
-   mtd->oobsize = 400;
-   break;
-   case 4:
-   mtd->oobsize = 436;
-   break;
-   case 5:
-   mtd->oobsize = 512;
-   break;
-   case 6:
-   mtd->oobsize = 640;
-   break;
-   case 7:
-   default: /* Other cases are "reserved" (unknown) */
-   mtd->oobsize = 1024;
-   break;
-   }
-   extid >>= 2;
-   /* Calc blocksize */
-   mtd->erasesize = (128 * 1024) <<
-   (((extid >> 1) & 0x04) | (extid & 0x03));
-   } else if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX &&
-   !nand_is_slc(chip)) {
+   if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX &&
+   !nand_is_slc(chip)) {
unsigned int tmp;
 
/* Calc pagesize */
@@ -4374,13 +4339,10 @@ static void nand_decode_bbm_options(struct mtd_info 
*mtd,
 * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba,
 * AMD/Spansion, and Macronix.  All others scan only the first page.
 */
-   if (!nand_is_slc(chip) &&
-   (maf_id == NAND_MFR_SAMSUNG ||
-maf_id == NAND_MFR_HYNIX))
+   if (!nand_is_slc(chip) && maf_id == NAND_MFR_HYNIX)
chip->bbt_options |= NAND_BBT_SCANLASTPAGE;
else if ((nand_is_slc(chip) &&
-   (maf_id == NAND_MFR_SAMSUNG ||
-maf_id == NAND_MFR_HYNIX ||
+   (maf_id == NAND_MFR_HYNIX ||
 maf_id == NAND_MFR_TOSHIBA ||
 maf_id == NAND_MFR_AMD ||
 maf_id == NAND_MFR_MACRONIX)) ||
@@ 

[PATCH v4 02/14] mtd: nand: Store nand ID in struct nand_chip

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit 7f501f0a72036d.

Store the NAND ID in struct nand_chip to avoid passing id_data and id_len
as function parameters.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Fix code style warnings raised by patman.

Changes in v2:
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.

 drivers/mtd/nand/raw/nand_base.c | 58 
 include/linux/mtd/rawnand.h  | 15 +
 2 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 9a2194ebd3f8..220804c75c87 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4160,16 +4160,14 @@ static int nand_get_bits_per_cell(u8 cellinfo)
  * chip. The rest of the parameters must be decoded according to generic or
  * manufacturer-specific "extended ID" decoding patterns.
  */
-static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
-   u8 id_data[8])
+static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip)
 {
int extid, id_len;
/* The 3rd id byte holds MLC / multichip data */
-   chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]);
+   chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]);
/* The 4th id byte is the important one */
-   extid = id_data[3];
-
-   id_len = nand_id_len(id_data, 8);
+   extid = chip->id.data[3];
+   id_len = chip->id.len;
 
/*
 * Field definitions are in the following datasheets:
@@ -4180,8 +4178,8 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip,
 * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung
 * ID to decide what to do.
 */
-   if (id_len == 6 && id_data[0] == NAND_MFR_SAMSUNG &&
-   !nand_is_slc(chip) && id_data[5] != 0x00) {
+   if (id_len == 6 && chip->id.data[0] == NAND_MFR_SAMSUNG &&
+   !nand_is_slc(chip) && chip->id.data[5] != 0x00) {
/* Calc pagesize */
mtd->writesize = 2048 << (extid & 0x03);
extid >>= 2;
@@ -4214,7 +4212,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip,
/* Calc blocksize */
mtd->erasesize = (128 * 1024) <<
(((extid >> 1) & 0x04) | (extid & 0x03));
-   } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX &&
+   } else if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX &&
!nand_is_slc(chip)) {
unsigned int tmp;
 
@@ -4278,10 +4276,10 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip,
 * 110b -> 24nm
 * - ID byte 5, bit[7]:1 -> BENAND, 0 -> raw SLC
 */
-   if (id_len >= 6 && id_data[0] == NAND_MFR_TOSHIBA &&
-   nand_is_slc(chip) &&
-   (id_data[5] & 0x7) == 0x6 /* 24nm */ &&
-   !(id_data[4] & 0x80) /* !BENAND */) {
+   if (id_len >= 6 && chip->id.data[0] == NAND_MFR_TOSHIBA &&
+   nand_is_slc(chip) &&
+   (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ &&
+   !(chip->id.data[4] & 0x80) /* !BENAND */) {
mtd->oobsize = 32 * mtd->writesize >> 9;
}
 
@@ -4294,9 +4292,9 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip,
  * the chip.
  */
 static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip,
-   struct nand_flash_dev *type, u8 id_data[8])
+   struct nand_flash_dev *type)
 {
-   int maf_id = id_data[0];
+   int maf_id = chip->id.data[0];
 
mtd->erasesize = type->erasesize;
mtd->writesize = type->pagesize;
@@ -4311,11 +4309,11 @@ static void nand_decode_id(struct mtd_info *mtd, struct 
nand_chip *chip,
 * listed in nand_ids table.
 * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39)
 */
-   if (maf_id == NAND_MFR_AMD && id_data[4] != 0x00 && id_data[5] == 0x00
-   && id_data[6] == 0x00 && id_data[7] == 0x00
-   && mtd->writesize == 512) {
+   if (maf_id == NAND_MFR_AMD && chip->id.data[4] != 0x00 &&
+   chip->id.data[5] == 0x00 && chip->id.data[6] == 0x00 &&
+   chip->id.data[7] == 0x00 && mtd->writesize == 512) {
mtd->erasesize = 128 * 1024;
-   mtd->erasesize <<= ((id_data[3] & 0x03) << 1);
+   mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1);
}
 }
 
@@ -4325,9 +4323,9 @@ static 

[PATCH v4 06/14] mtd: nand: Export symbol nand_decode_ext_id

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

In preparation of moving specific nand support that are not jedec
or onfi

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v1)

 drivers/mtd/nand/raw/nand_base.c | 3 ++-
 include/linux/mtd/rawnand.h  | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 145de22be852..174c760f3416 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4160,7 +4160,7 @@ static int nand_get_bits_per_cell(u8 cellinfo)
  * chip. The rest of the parameters must be decoded according to generic or
  * manufacturer-specific "extended ID" decoding patterns.
  */
-static void nand_decode_ext_id(struct nand_chip *chip)
+void nand_decode_ext_id(struct nand_chip *chip)
 {
struct mtd_info *mtd = >mtd;
int extid, id_len;
@@ -4286,6 +4286,7 @@ static void nand_decode_ext_id(struct nand_chip *chip)
 
}
 }
+EXPORT_SYMBOL_GPL(nand_decode_ext_id);
 
 /*
  * Manufacturer detection. Only used when the NAND is not ONFI or JEDEC
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index d8141cb4d114..8fb2a43296f5 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -1374,4 +1374,7 @@ int nand_read_data_op(struct nand_chip *chip, void *buf, 
unsigned int len,
 int nand_write_data_op(struct nand_chip *chip, const void *buf,
   unsigned int len, bool force_8bit);
 
+/* Default extended ID decoding function */
+void nand_decode_ext_id(struct nand_chip *chip);
+
 #endif /* __LINUX_MTD_RAWNAND_H */
-- 
2.32.0



[PATCH v4 05/14] mtd: nand: Fix MediaTek MT7621 SoC build

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

nand_get_flash_type was reworked in commit 1ca6f9483e9ab5. This change
break the Mediatek MT721. Fix it adjust the function call parameters

+include/linux/mtd/rawnand.h:32:62: note: expected 'struct nand_chip *' but 
argument is of type 'struct mtd_info *'
+   32 | struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip,
+  |~~^~~~
+drivers/mtd/nand/raw/mt7621_nand.c:1189:48: error: passing argument 2 of 
'nand_get_flash_type' from incompatible pointer type 
[-Werror=incompatible-pointer-types]
+  |^~~~
+  ||
+  |struct nand_chip *
+include/linux/mtd/rawnand.h:33:49: note: expected 'int *' but argument is of 
type 'struct nand_chip *'
+   33 |int *maf_id, int *dev_id,

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Add the patch to the series.

 drivers/mtd/nand/raw/mt7621_nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/mt7621_nand.c 
b/drivers/mtd/nand/raw/mt7621_nand.c
index 2fd89349392b..9763ae6dc51a 100644
--- a/drivers/mtd/nand/raw/mt7621_nand.c
+++ b/drivers/mtd/nand/raw/mt7621_nand.c
@@ -1186,7 +1186,7 @@ int mt7621_nfc_spl_post_init(struct mt7621_nfc *nfc)
int nand_maf_id, nand_dev_id;
struct nand_flash_dev *type;
 
-   type = nand_get_flash_type(>mtd, nand, _maf_id,
+   type = nand_get_flash_type(nand, _maf_id,
   _dev_id, NULL);
 
if (IS_ERR(type))
-- 
2.32.0



[PATCH v4 04/14] mtd: nand: Get rid of mtd variable in function calls

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

chip points to mtd. Passing chip is enough to have a reference
to mtd when is necessary

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Fix code style warnings raised by patman.

 drivers/mtd/nand/raw/nand_base.c | 25 +
 include/linux/mtd/rawnand.h  |  3 +--
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 0900e6dbf9a6..145de22be852 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4160,8 +4160,9 @@ static int nand_get_bits_per_cell(u8 cellinfo)
  * chip. The rest of the parameters must be decoded according to generic or
  * manufacturer-specific "extended ID" decoding patterns.
  */
-static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip)
+static void nand_decode_ext_id(struct nand_chip *chip)
 {
+   struct mtd_info *mtd = >mtd;
int extid, id_len;
/* The 3rd id byte holds MLC / multichip data */
chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]);
@@ -4291,7 +4292,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip)
  * compliant and does not have a full-id or legacy-id entry in the nand_ids
  * table.
  */
-static void nand_manufacturer_detect(struct mtd_info *mtd, struct nand_chip 
*chip)
+static void nand_manufacturer_detect(struct nand_chip *chip)
 {
/*
 * Try manufacturer detection if available and use
@@ -4301,7 +4302,7 @@ static void nand_manufacturer_detect(struct mtd_info 
*mtd, struct nand_chip *chi
chip->manufacturer.desc->ops->detect)
chip->manufacturer.desc->ops->detect(chip);
else
-   nand_decode_ext_id(mtd, chip);
+   nand_decode_ext_id(chip);
 }
 
 /*
@@ -4324,9 +4325,9 @@ static int nand_manufacturer_init(struct nand_chip *chip)
  * decodes a matching ID table entry and assigns the MTD size parameters for
  * the chip.
  */
-static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip,
-   struct nand_flash_dev *type)
+static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type)
 {
+   struct mtd_info *mtd = >mtd;
int maf_id = chip->id.data[0];
 
mtd->erasesize = type->erasesize;
@@ -4439,11 +4440,11 @@ static const struct nand_manufacturers 
*nand_get_manufacturer_desc(u8 id)
 /*
  * Get the flash and manufacturer id and lookup if the type is supported.
  */
-struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
- struct nand_chip *chip,
- int *maf_id, int *dev_id,
- struct nand_flash_dev *type)
+struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id,
+  int *dev_id,
+  struct nand_flash_dev *type)
 {
+   struct mtd_info *mtd = >mtd;
const struct nand_manufacturers *manufacturer_desc;
int busw, ret;
u8 *id_data = chip->id.data;
@@ -4539,9 +4540,9 @@ struct nand_flash_dev *nand_get_flash_type(struct 
mtd_info *mtd,
chip->chipsize = (uint64_t)type->chipsize << 20;
 
if (!type->pagesize) {
-   nand_manufacturer_detect(mtd, chip);
+   nand_manufacturer_detect(chip);
} else {
-   nand_decode_id(mtd, chip, type);
+   nand_decode_id(chip, type);
}
 
/* Get chip options */
@@ -4729,7 +4730,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16);
 
/* Read the flash type */
-   type = nand_get_flash_type(mtd, chip, _maf_id,
+   type = nand_get_flash_type(chip, _maf_id,
   _dev_id, table);
 
if (IS_ERR(type)) {
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index 57fe7fb47bd8..d8141cb4d114 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -29,8 +29,7 @@ struct nand_flash_dev;
 struct device_node;
 
 /* Get the flash and manufacturer id and lookup if the type is supported. */
-struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
-  struct nand_chip *chip,
+struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip,
   int *maf_id, int *dev_id,
   struct nand_flash_dev *type);
 
-- 
2.32.0



[PATCH v4 03/14] mtd: nand: Add manufacturer specific initialization/detection steps

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit abbe26d144ec22.

A lot of NANDs are implementing generic features in a non-generic way,
or are providing advanced auto-detection logic where the NAND ID bytes
meaning changes with the NAND generation.

Providing this vendor specific initialization step will allow us to get
rid of full-id entries in the nand_ids table or all the vendor specific
cases added over the time in the generic NAND ID decoding logic.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.
- Fix code style warnings raised by patman.

Changes in v2:
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.

 drivers/mtd/nand/raw/nand_base.c | 98 
 include/linux/mtd/rawnand.h  | 30 ++
 2 files changed, 105 insertions(+), 23 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 220804c75c87..0900e6dbf9a6 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4286,6 +4286,39 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip)
}
 }
 
+/*
+ * Manufacturer detection. Only used when the NAND is not ONFI or JEDEC
+ * compliant and does not have a full-id or legacy-id entry in the nand_ids
+ * table.
+ */
+static void nand_manufacturer_detect(struct mtd_info *mtd, struct nand_chip 
*chip)
+{
+   /*
+* Try manufacturer detection if available and use
+* nand_decode_ext_id() otherwise.
+*/
+   if (chip->manufacturer.desc && chip->manufacturer.desc->ops &&
+   chip->manufacturer.desc->ops->detect)
+   chip->manufacturer.desc->ops->detect(chip);
+   else
+   nand_decode_ext_id(mtd, chip);
+}
+
+/*
+ * Manufacturer initialization. This function is called for all NANDs including
+ * ONFI and JEDEC compliant ones.
+ * Manufacturer drivers should put all their specific initialization code in
+ * their ->init() hook.
+ */
+static int nand_manufacturer_init(struct nand_chip *chip)
+{
+   if (!chip->manufacturer.desc || !chip->manufacturer.desc->ops ||
+   !chip->manufacturer.desc->ops->init)
+   return 0;
+
+   return chip->manufacturer.desc->ops->init(chip);
+}
+
 /*
  * Old devices have chip data hardcoded in the device ID table. nand_decode_id
  * decodes a matching ID table entry and assigns the MTD size parameters for
@@ -4383,6 +4416,26 @@ static bool find_full_id_nand(struct mtd_info *mtd, 
struct nand_chip *chip,
return false;
 }
 
+/**
+ * nand_get_manufacturer_desc - Get manufacturer information from the
+ *  manufacturer ID
+ * @id: manufacturer ID
+ *
+ * Returns a nand_manufacturer_desc object if the manufacturer is defined
+ * in the NAND manufacturers database, NULL otherwise.
+ */
+static const struct nand_manufacturers *nand_get_manufacturer_desc(u8 id)
+{
+   int i;
+
+   for (i = 0; nand_manuf_ids[i].id != 0x0; i++) {
+   if (nand_manuf_ids[i].id == id)
+   return _manuf_ids[i];
+   }
+
+   return NULL;
+}
+
 /*
  * Get the flash and manufacturer id and lookup if the type is supported.
  */
@@ -4391,8 +,8 @@ struct nand_flash_dev *nand_get_flash_type(struct 
mtd_info *mtd,
  int *maf_id, int *dev_id,
  struct nand_flash_dev *type)
 {
+   const struct nand_manufacturers *manufacturer_desc;
int busw, ret;
-   int maf_idx;
u8 *id_data = chip->id.data;
 
/*
@@ -4433,6 +4486,12 @@ struct nand_flash_dev *nand_get_flash_type(struct 
mtd_info *mtd,
return ERR_PTR(-ENODEV);
}
 
+   chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data));
+
+   /* Try to identify manufacturer */
+   manufacturer_desc = nand_get_manufacturer_desc(*maf_id);
+   chip->manufacturer.desc = manufacturer_desc;
+
if (!type)
type = nand_flash_ids;
 
@@ -4451,8 +4510,6 @@ struct nand_flash_dev *nand_get_flash_type(struct 
mtd_info *mtd,
 */
chip->options &= ~NAND_BUSWIDTH_16;
 
-   chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data));
-
for (; type->name != NULL; type++) {
if (is_full_id_nand(type)) {
if (find_full_id_nand(mtd, chip, type))
@@ -4482,8 +4539,7 @@ struct nand_flash_dev *nand_get_flash_type(struct 
mtd_info *mtd,
chip->chipsize = (uint64_t)type->chipsize << 20;
 
if (!type->pagesize) {
-   /* Decode parameters from extended ID */
-   nand_decode_ext_id(mtd, chip);
+   nand_manufacturer_detect(mtd, chip);
} else {
nand_decode_id(mtd, chip, type);
}
@@ -4499,12 +4555,6 @@ struct 

[PATCH v4 01/14] mtd: nand: Get rid of busw parameter

2022-07-22 Thread Dario Binacchi
From: Michael Trimarchi 

Upstream linux commit 29a198a1592d83.

Auto-detection functions are passed a busw parameter to retrieve the actual
NAND bus width and eventually set the correct value in chip->options.
Rework the nand_get_flash_type() function to get rid of this extra
parameter and let detection code directly set the NAND_BUSWIDTH_16 flag in
chip->options if needed.

Signed-off-by: Michael Trimarchi 
Signed-off-by: Dario Binacchi 
---

(no changes since v3)

Changes in v3:
- Use commit sha1 with 13 digits.

Changes in v2:
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.

 drivers/mtd/nand/raw/nand_base.c | 59 +---
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index e8ece0a4a0dd..9a2194ebd3f8 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -3898,8 +3898,7 @@ static void nand_onfi_detect_micron(struct nand_chip 
*chip,
 /*
  * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise.
  */
-static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
-   int *busw)
+static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip)
 {
struct nand_onfi_params *p = >onfi_params;
char id[4];
@@ -3971,9 +3970,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, 
struct nand_chip *chip,
chip->bits_per_cell = p->bits_per_cell;
 
if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS)
-   *busw = NAND_BUSWIDTH_16;
-   else
-   *busw = 0;
+   chip->options |= NAND_BUSWIDTH_16;
 
if (p->ecc_bits != 0xff) {
chip->ecc_strength_ds = p->ecc_bits;
@@ -4003,8 +4000,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, 
struct nand_chip *chip,
return 1;
 }
 #else
-static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
-   int *busw)
+static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip)
 {
return 0;
 }
@@ -4013,8 +4009,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, 
struct nand_chip *chip,
 /*
  * Check if the NAND chip is JEDEC compliant, returns 1 if it is, 0 otherwise.
  */
-static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip 
*chip,
-   int *busw)
+static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip 
*chip)
 {
struct nand_jedec_params *p = >jedec_params;
struct jedec_ecc_info *ecc;
@@ -4076,9 +4071,7 @@ static int nand_flash_detect_jedec(struct mtd_info *mtd, 
struct nand_chip *chip,
chip->bits_per_cell = p->bits_per_cell;
 
if (jedec_feature(chip) & JEDEC_FEATURE_16_BIT_BUS)
-   *busw = NAND_BUSWIDTH_16;
-   else
-   *busw = 0;
+   chip->options |= NAND_BUSWIDTH_16;
 
/* ECC info */
ecc = >ecc_info[0];
@@ -4168,7 +4161,7 @@ static int nand_get_bits_per_cell(u8 cellinfo)
  * manufacturer-specific "extended ID" decoding patterns.
  */
 static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip,
-   u8 id_data[8], int *busw)
+   u8 id_data[8])
 {
int extid, id_len;
/* The 3rd id byte holds MLC / multichip data */
@@ -4221,7 +4214,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip,
/* Calc blocksize */
mtd->erasesize = (128 * 1024) <<
(((extid >> 1) & 0x04) | (extid & 0x03));
-   *busw = 0;
} else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX &&
!nand_is_slc(chip)) {
unsigned int tmp;
@@ -4262,7 +4254,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip,
mtd->erasesize = 768 * 1024;
else
mtd->erasesize = (64 * 1024) << tmp;
-   *busw = 0;
} else {
/* Calc pagesize */
mtd->writesize = 1024 << (extid & 0x03);
@@ -4275,7 +4266,9 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip,
mtd->erasesize = (64 * 1024) << (extid & 0x03);
extid >>= 2;
/* Get buswidth information */
-   *busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0;
+   /* Get buswidth information */
+   if (extid & 0x1)
+   chip->options |= NAND_BUSWIDTH_16;
 
/*
 * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per
@@ -4301,15 +4294,13 @@ static void nand_decode_ext_id(struct mtd_info *mtd, 
struct nand_chip *chip,
  * the chip.
  */
 

[PATCH v4 00/14] Port manufacturer specific initialization

2022-07-22 Thread Dario Binacchi
In preparation of re-sync of mtd stack, we opt to move the current stack
slowly in order to have a more easy sync and test. We would like to
prepare uboot to support no-jedec and no-onfi compliant nand so we need
to clean up a bit the code we have now and upstream some of the support.
In this series we expect no functional change

Tested on:
 - imx6ull Micron   MT29F2G08ABAGAH4
 - imx8mn  Macronix MX30LF4G18AC

Changes in v4:
- Add the patch "mtd: nand: Fix MediaTek MT7621 SoC build" to the series.

Changes in v3:
- Use commit sha1 with 13 digits.
- Use commit sha1 with 13 digits.
- Fix code style warnings raised by patman.
- Use commit sha1 with 13 digits.
- Fix code style warnings raised by patman.
- Fix code style warnings raised by patman.
- Use commit sha1 with 13 digits.
- Fix code style warnings raised by patman.
- Add the SPDX-License-Identifier tag.
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.
- Use commit sha1 with 13 digits.
- Add the SPDX-License-Identifier tag.
- Fix code style warnings raised by patman.
- Use commit sha1 with 13 digits.
- Use commit sha1 with 13 digits.
- Wrap commit description to a maximum of 75 chars.

Changes in v2:
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_samsung.
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_hynix.
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_toshiba.
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_micron.
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_amd.
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Adjust the include file in nand_macronix.
- Use short-commit form
- Remove linux info. Uboot seems that backport without add this
  extra information.
- Use short-commit form.
- Remove linux info. Uboot seems that backport without add this
  extra information.

Michael Trimarchi (14):
  mtd: nand: Get rid of busw parameter
  mtd: nand: Store nand ID in struct nand_chip
  mtd: nand: Add manufacturer specific initialization/detection steps
  mtd: nand: Get rid of mtd variable in function calls
  mtd: nand: Fix MediaTek MT7621 SoC build
  mtd: nand: Export symbol nand_decode_ext_id
  mtd: nand: Move Samsung specific init/detection logic in
nand_samsung.c
  mtd: nand: Move Hynix specific init/detection logic in nand_hynix.c
  mtd: nand: Move Toshiba specific init/detection logic in
nand_toshiba.c
  mtd: nand: Move Micron specific init logic in nand_micron.c
  mtd: nand: Move AMD/Spansion specific init/detection logic in
nand_amd.c
  mtd: nand: Move Macronix specific initialization in nand_macronix.c
  mtd: nand: toshiba: Retrieve ECC requirements from extended ID
  mtd: decommission the NAND museum

 drivers/mtd/nand/raw/Makefile|  10 +-
 drivers/mtd/nand/raw/mt7621_nand.c   |   2 +-
 drivers/mtd/nand/raw/nand_amd.c  |  52 
 drivers/mtd/nand/raw/nand_base.c | 370 ++-
 drivers/mtd/nand/raw/nand_hynix.c|  85 ++
 drivers/mtd/nand/raw/nand_ids.c  |  24 +-
 drivers/mtd/nand/raw/nand_macronix.c |  31 +++
 drivers/mtd/nand/raw/nand_micron.c   |  87 +++
 drivers/mtd/nand/raw/nand_samsung.c  |  90 +++
 drivers/mtd/nand/raw/nand_toshiba.c  |  79 ++
 include/linux/mtd/rawnand.h  |  78 --
 11 files changed, 626 insertions(+), 282 deletions(-)
 create mode 100644 drivers/mtd/nand/raw/nand_amd.c
 create mode 100644 drivers/mtd/nand/raw/nand_hynix.c
 create mode 100644 drivers/mtd/nand/raw/nand_macronix.c
 create mode 100644 drivers/mtd/nand/raw/nand_micron.c
 create mode 100644 drivers/mtd/nand/raw/nand_samsung.c
 create mode 100644 drivers/mtd/nand/raw/nand_toshiba.c

-- 
2.32.0



Re: [PATCH v7 06/13] FWU: stm32mp1: Add helper functions for accessing FWU metadata

2022-07-22 Thread Sughosh Ganu
On Fri, 22 Jul 2022 at 09:09, Jassi Brar  wrote:
>
> On Thu, 14 Jul 2022 at 13:40, Sughosh Ganu  wrote:
> >
> > Add helper functions needed for accessing the FWU metadata which
> > contains information on the updatable images. These functions have
> > been added for the STM32MP157C-DK2 board which has the updatable
> > images on the uSD card, formatted as GPT partitions.
> >
> > Signed-off-by: Sughosh Ganu 
> > Reviewed-by: Patrick Delaunay 
> > ---
> > Changes since V6: None
> >
> >  board/st/stm32mp1/stm32mp1.c | 40 
> >  include/fwu.h|  3 ++
> >  lib/fwu_updates/Makefile |  6 +++
> >  lib/fwu_updates/fwu_gpt.c| 88 
> >  4 files changed, 137 insertions(+)
> >  create mode 100644 lib/fwu_updates/Makefile
> >  create mode 100644 lib/fwu_updates/fwu_gpt.c
> >
> fwu_gpt is to be used by all platforms that have the gpt-scheme, not just STM.
>
> So do you want to break this patch into two ? One generic that
> introduces the helper functions and another for stm using that api

Ilias has suggested moving the two API functions to common files and
having them defined as weak functions. I will be making this change in
the next version.

>
> Also, you may want to specify GPL-2.0-or-later everywhere.

I thought I had changed that in this version of the patchset, but
unfortunately these two files have not been changed. I will change
this in the next version.

-sughosh


[PATCH 12/12] rockchip: puma-rk3399: migrate to u-boot-rockchip-spi.bin

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Now that a single binary containing TPL/SPL correctly formatted for SPI
flashes and U-Boot proper, can be generated by binman, let's do it.

Also update the documentation to tell the user to use this newly
generated file instead of manually generating and flashing the binaries.

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

Depends on follwing patch series:
https://lore.kernel.org/u-boot/20220722113505.3875669-1-foss+ub...@0leil.net/

 arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi | 11 +++
 board/theobroma-systems/puma_rk3399/README  | 11 ++-
 configs/puma-rk3399_defconfig   |  1 +
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi 
b/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
index 27a792fe6d..bfc504b952 100644
--- a/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
@@ -44,6 +44,17 @@
};
 };
 
+#ifdef CONFIG_ROCKCHIP_SPI_IMAGE
+ {
+   simple-bin-spi {
+   blob {
+   /* same as u-boot,spl-payload-offset */
+   offset = <0x8>;
+   };
+   };
+};
+#endif
+
  {
u-boot,dm-pre-reloc;
 };
diff --git a/board/theobroma-systems/puma_rk3399/README 
b/board/theobroma-systems/puma_rk3399/README
index 2e3785c986..649aa3c543 100644
--- a/board/theobroma-systems/puma_rk3399/README
+++ b/board/theobroma-systems/puma_rk3399/README
@@ -44,17 +44,11 @@ Compile the U-Boot
   > cd ../u-boot
   > make CROSS_COMPILE=aarch64-linux-gnu- puma-rk3399_defconfig all
 
-Package the image
-=
-
-Creating an SPL image for SPI-NOR:
-  > tools/mkimage -n rk3399 -T rkspi -d tpl/u-boot-tpl.bin:spl/u-boot-spl.bin 
idbloader-spi.img
-
 Flash the image
 ===
 
 Copy u-boot-rockchip.bin to offset 32k for SD/eMMC.
-Copy the SPL to offset 0 and the FIT image to offset 512k for NOR-Flash.
+Copy u-boot-rockchip-spi.bin to offset 0 for NOR-flash.
 
 SD-Card
 ---
@@ -92,5 +86,4 @@ help of the Rockchip loader binary.
   > cd ..
   > ./rkdeveloptool db rkbin/rk3399_loader_spinor_v1.25.114.bin
   > ./rkdeveloptool ef
-  > ./rkdeveloptool wl 0 ../idbloader-spi.img
-  > ./rkdeveloptool wl 1024 ../u-boot.itb
+  > ./rkdeveloptool wl 0 ../u-boot-rockchip-spi.bin
diff --git a/configs/puma-rk3399_defconfig b/configs/puma-rk3399_defconfig
index c70dbe9ed5..0f532b2776 100644
--- a/configs/puma-rk3399_defconfig
+++ b/configs/puma-rk3399_defconfig
@@ -9,6 +9,7 @@ CONFIG_ENV_OFFSET=0x3F8000
 CONFIG_DEFAULT_DEVICE_TREE="rk3399-puma-haikou"
 CONFIG_ROCKCHIP_RK3399=y
 CONFIG_ROCKCHIP_BOOT_MODE_REG=0x0
+CONFIG_ROCKCHIP_SPI_IMAGE=y
 CONFIG_TARGET_PUMA_RK3399=y
 CONFIG_DEBUG_UART_BASE=0xFF18
 CONFIG_DEBUG_UART_CLOCK=2400
-- 
2.37.1



[PATCH 11/12] rockchip: lion-rk3368: migrate to u-boot-rockchip.bin

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Now that the offset for u-boot.itb in the u-boot-rockchip.bin matches
the one required for Lion, let's tell users to use it instead of
flashing the TPL/SPL and U-Boot proper separately.

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

Depends on follwing patch series:
https://lore.kernel.org/u-boot/20220722113505.3875669-1-foss+ub...@0leil.net/

 board/theobroma-systems/lion_rk3368/README | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/board/theobroma-systems/lion_rk3368/README 
b/board/theobroma-systems/lion_rk3368/README
index 7488b18326..3c15a7bb36 100644
--- a/board/theobroma-systems/lion_rk3368/README
+++ b/board/theobroma-systems/lion_rk3368/README
@@ -27,14 +27,12 @@ Build the full U-Boot and a FIT image including the ATF
 Flash the image
 ===
 
-Copy the SPL to offset 32k and the FIT image containing the payloads
-(U-Boot proper, ATF, devicetree) to offset 256k card.
+Copy u-boot-rockchip.bin at offset 32k on SD-Card/eMMC.
 
 SD-Card
 ---
 
-  > dd if=idbloader.img of=/dev/sdb seek=64
-  > dd if=u-boot.itb of=/dev/sdb seek=512
+  > dd if=u-boot-rockchip.bin of=/dev/sdb seekp=64
 
 eMMC
 
@@ -47,8 +45,7 @@ help of the Rockchip loader binary.
   > autoreconf -i && && ./configure && make
   > git clone https://github.com/rockchip-linux/rkbin.git
   > ./rkdeveloptool db rkbin/rk33/rk3368_loader_v2.00.256.bin
-  > ./rkdeveloptool wl 64 ../spl.img
-  > ./rkdeveloptool wl 512 ../u-boot.itb
+  > ./rkdeveloptool wl 64 ../u-boot-rockchip.bin
 
 
 If everything went according to plan, you should see the following
-- 
2.37.1



[PATCH 10/12] rockchip: puma-rk3399: migrate to u-boot-rockchip.bin

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Now that the offset for u-boot.itb in the u-boot-rockchip.bin matches
the one required for Puma, let's tell users to use it instead of
flashing the TPL/SPL and U-Boot proper separately.

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

Depends on follwing patch series:
https://lore.kernel.org/u-boot/20220722113505.3875669-1-foss+ub...@0leil.net/

 board/theobroma-systems/puma_rk3399/README | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/board/theobroma-systems/puma_rk3399/README 
b/board/theobroma-systems/puma_rk3399/README
index 550bdfb1f4..2e3785c986 100644
--- a/board/theobroma-systems/puma_rk3399/README
+++ b/board/theobroma-systems/puma_rk3399/README
@@ -47,23 +47,19 @@ Compile the U-Boot
 Package the image
 =
 
-The SPL image for SD-Card/eMMC is readily available in idbloader.img at the
-root of U-Boot after compilation.
-
 Creating an SPL image for SPI-NOR:
   > tools/mkimage -n rk3399 -T rkspi -d tpl/u-boot-tpl.bin:spl/u-boot-spl.bin 
idbloader-spi.img
 
 Flash the image
 ===
 
-Copy the SPL to offset 32k and the FIT image to offset 256k for SD/eMMC.
+Copy u-boot-rockchip.bin to offset 32k for SD/eMMC.
 Copy the SPL to offset 0 and the FIT image to offset 512k for NOR-Flash.
 
 SD-Card
 ---
 
-  > dd if=idbloader.img of=/dev/sdb seek=64
-  > dd if=u-boot.itb of=/dev/sdb seek=512
+  > dd if=u-boot-rockchip.bin of=/dev/sdb seek=64
 
 eMMC
 
@@ -79,8 +75,7 @@ help of the Rockchip loader binary.
   > ./tools/boot_merger RKBOOT/RK3399MINIALL.ini
   > cd ..
   > ./rkdeveloptool db rkbin/rk3399_loader_v1.25.126.bin
-  > ./rkdeveloptool wl 64 ../idbloader.img
-  > ./rkdeveloptool wl 512 ../u-boot.itb
+  > ./rkdeveloptool wl 64 ../u-boot-rockchip.bin
 
 NOR-Flash
 -
-- 
2.37.1



[PATCH 07/12] rockchip: puma-rk3399: load environment from same medium as one used to load U-Boot proper

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Chances are when one boots U-Boot proper from a given storage medium,
they want the same medium to be used to load and store the environment.

This basically allows to have completely separate U-Boot (TPL/SPL/U-Boot
proper/environment) per storage medium which is convenient when working
with recovery from SD-Card as one would just need to insert a properly
configured SD-Card into the device to have access to their whole debug
setup.

No fallback mechanism is provided as to not dirty other storage medium
environment by mistake. However, since arch_env_get_location() is called
by env_init() which is part of the pre-relocation process, a valid,
non-ENVL_UNKNOWN, value shall be returned otherwise the relocation fails
with the following message:
initcall sequence 002866c0 failed at call 00256b34 (err=-19)

This valid, non-ENVL_UNKNOWN, value is ENVL_NOWHERE which requires to
always select CONFIG_ENV_IS_NOWHERE otherwise this work-around does not
work.

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

Depends on
https://lore.kernel.org/u-boot/20220715151552.953654-1-foss+ub...@0leil.net/
https://lore.kernel.org/u-boot/20220715151552.953654-2-foss+ub...@0leil.net/

 .../puma_rk3399/puma-rk3399.c | 37 +++
 configs/puma-rk3399_defconfig |  1 +
 2 files changed, 38 insertions(+)

diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c 
b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
index 5e5e58c88e..7ef4bac24b 100644
--- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
+++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -135,6 +136,42 @@ int mmc_get_env_dev(void)
return CONFIG_SYS_MMC_ENV_DEV;
 }
 
+#if !IS_ENABLED(CONFIG_ENV_IS_NOWHERE)
+#error Please enable CONFIG_ENV_IS_NOWHERE
+#endif
+
+enum env_location arch_env_get_location(enum env_operation op, int prio)
+{
+   const char *boot_device =
+   ofnode_read_chosen_string("u-boot,spl-boot-device");
+
+   if (prio > 0)
+   return ENVL_UNKNOWN;
+
+   if (!boot_device) {
+   debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+ __func__);
+   return ENVL_NOWHERE;
+   }
+
+   debug("%s: booted from %s\n", __func__, boot_device);
+
+   if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH) &&
+   !strcmp(boot_device, "/spi@ff1d/flash@0"))
+   return ENVL_SPI_FLASH;
+
+   if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC) &&
+   (!strcmp(boot_device, "/mmc@fe32") ||
+!strcmp(boot_device, "/mmc@fe33")))
+   return ENVL_MMC;
+
+   printf("%s: No environment available: booted from %s but U-Boot "
+  "config does not allow loading environment from it.",
+  __func__, boot_device);
+
+   return ENVL_NOWHERE;
+}
+
 int misc_init_r(void)
 {
const u32 cpuid_offset = 0x7;
diff --git a/configs/puma-rk3399_defconfig b/configs/puma-rk3399_defconfig
index 87d7e4f57c..e218532d70 100644
--- a/configs/puma-rk3399_defconfig
+++ b/configs/puma-rk3399_defconfig
@@ -44,6 +44,7 @@ CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_LIVE=y
 CONFIG_OF_SPL_REMOVE_PROPS="interrupt-parent assigned-clocks 
assigned-clock-rates assigned-clock-parents"
 CONFIG_ENV_OVERWRITE=y
+CONFIG_ENV_IS_NOWHERE=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_ENV_SPI_MAX_HZ=5000
-- 
2.37.1



[PATCH 09/12] rockchip: puma-rk3399: migrate to TPL

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Depending on the toolchain used to compile the SPL for Puma RK3399-Q7
module, the board does not boot because the resulting binary is too big
to fit in SRAM.

Let's add a TPL so that there's no need to fiddle with or hack the
defconfig to have a working bootloader.

This follows what's been done for the majority of other RK3399-based
boards.

See the original commit for the first migrations:
bdc00080111f "rockchip: rk3399: update defconfig for TPL"

Unfortunately, the offset in SPI-NOR for U-Boot proper needs to be
modified, since the move from SPL to TPL+SPL for idbloader.img (and the
"only the first 2KB per 4KB blocks are written" "hack" for rkspi format)
increased the size above 256KB. Let's move it to 512KB to, hopefully, be
safe.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi | 2 +-
 board/theobroma-systems/puma_rk3399/README  | 8 
 configs/puma-rk3399_defconfig   | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi 
b/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
index 5dc345bbe8..27a792fe6d 100644
--- a/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
@@ -14,7 +14,7 @@
 
 / {
config {
-   u-boot,spl-payload-offset = <0x4>; /* @ 256KB */
+   u-boot,spl-payload-offset = <0x8>; /* @ 512KB */
u-boot,mmc-env-offset = <0x4000>;  /* @  16KB */
u-boot,efi-partition-entries-offset = <0x20>; /* 2MB */
u-boot,boot-led = "module_led";
diff --git a/board/theobroma-systems/puma_rk3399/README 
b/board/theobroma-systems/puma_rk3399/README
index 254c3bbe96..550bdfb1f4 100644
--- a/board/theobroma-systems/puma_rk3399/README
+++ b/board/theobroma-systems/puma_rk3399/README
@@ -51,13 +51,13 @@ The SPL image for SD-Card/eMMC is readily available in 
idbloader.img at the
 root of U-Boot after compilation.
 
 Creating an SPL image for SPI-NOR:
-  > tools/mkimage -n rk3399 -T rkspi -d spl/u-boot-spl.bin idbloader-spi.img
+  > tools/mkimage -n rk3399 -T rkspi -d tpl/u-boot-tpl.bin:spl/u-boot-spl.bin 
idbloader-spi.img
 
 Flash the image
 ===
 
-Copy the SPL to offset 32k for SD/eMMC, offset 0 for NOR-Flash and the FIT
-image to offset 256k.
+Copy the SPL to offset 32k and the FIT image to offset 256k for SD/eMMC.
+Copy the SPL to offset 0 and the FIT image to offset 512k for NOR-Flash.
 
 SD-Card
 ---
@@ -98,4 +98,4 @@ help of the Rockchip loader binary.
   > ./rkdeveloptool db rkbin/rk3399_loader_spinor_v1.25.114.bin
   > ./rkdeveloptool ef
   > ./rkdeveloptool wl 0 ../idbloader-spi.img
-  > ./rkdeveloptool wl 512 ../u-boot.itb
+  > ./rkdeveloptool wl 1024 ../u-boot.itb
diff --git a/configs/puma-rk3399_defconfig b/configs/puma-rk3399_defconfig
index 3567cd078b..c70dbe9ed5 100644
--- a/configs/puma-rk3399_defconfig
+++ b/configs/puma-rk3399_defconfig
@@ -7,7 +7,6 @@ CONFIG_SPL_GPIO=y
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_OFFSET=0x3F8000
 CONFIG_DEFAULT_DEVICE_TREE="rk3399-puma-haikou"
-CONFIG_SPL_TEXT_BASE=0xff8c2000
 CONFIG_ROCKCHIP_RK3399=y
 CONFIG_ROCKCHIP_BOOT_MODE_REG=0x0
 CONFIG_TARGET_PUMA_RK3399=y
@@ -22,11 +21,12 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_MISC_INIT_R=y
 # CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
 CONFIG_SPL_STACK_R=y
-CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x4000
+CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x1
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x200
 CONFIG_SPL_I2C=y
 CONFIG_SPL_POWER=y
 CONFIG_SPL_SPI_LOAD=y
+CONFIG_TPL=y
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
-- 
2.37.1



[PATCH 08/12] rockchip: puma-rk3399: remove useless CONFIG_SYS_SPI_U_BOOT_OFFS

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

The SPL payload offset when booting from SPI defaults to
CONFIG_SYS_SPI_U_BOOT_OFFS but can be overridden by
u-boot,spl-payload-offset. The Device Tree for Puma Haikou has this
property so there's no need to have this one option in the defconfig,
especially since they are not in sync and therefore confusing.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 configs/puma-rk3399_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/puma-rk3399_defconfig b/configs/puma-rk3399_defconfig
index e218532d70..3567cd078b 100644
--- a/configs/puma-rk3399_defconfig
+++ b/configs/puma-rk3399_defconfig
@@ -27,7 +27,6 @@ CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x200
 CONFIG_SPL_I2C=y
 CONFIG_SPL_POWER=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_SYS_SPI_U_BOOT_OFFS=0x2
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
-- 
2.37.1



[PATCH 06/12] rockchip: puma-rk3399: allow loading environment from SPI-NOR flash

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

There's a SPI-NOR flash available from which SPL and U-Boot proper can
be booted, it makes sense to also allow this medium to store U-Boot
environment so let's enable it.

The Device Tree advertises a max frequency of 50MHz so let's set the
config option appropriately.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 configs/puma-rk3399_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/puma-rk3399_defconfig b/configs/puma-rk3399_defconfig
index 779fe5a5cd..87d7e4f57c 100644
--- a/configs/puma-rk3399_defconfig
+++ b/configs/puma-rk3399_defconfig
@@ -45,6 +45,8 @@ CONFIG_OF_LIVE=y
 CONFIG_OF_SPL_REMOVE_PROPS="interrupt-parent assigned-clocks 
assigned-clock-rates assigned-clock-parents"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
+CONFIG_ENV_IS_IN_SPI_FLASH=y
+CONFIG_ENV_SPI_MAX_HZ=5000
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_SYS_MMC_ENV_DEV=1
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
-- 
2.37.1



[PATCH 05/12] rockchip: puma-rk3399: load environment from same MMC as used for loading U-Boot proper

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Automatically detect which MMC device (SD-Card or eMMC) was used to load
U-Boot proper and load the environment from that MMC device instead of
a hardcoded one.

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

Depends on
https://lore.kernel.org/u-boot/20220715151552.953654-1-foss+ub...@0leil.net/

 .../puma_rk3399/puma-rk3399.c | 22 +++
 1 file changed, 22 insertions(+)

diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c 
b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
index ce3436b770..5e5e58c88e 100644
--- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
+++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
@@ -113,6 +113,28 @@ static int setup_boottargets(void)
return 0;
 }
 
+int mmc_get_env_dev(void)
+{
+   const char *boot_device =
+   ofnode_read_chosen_string("u-boot,spl-boot-device");
+
+   if (!boot_device) {
+   debug("%s: /chosen/u-boot,spl-boot-device not set\n",
+ __func__);
+   return CONFIG_SYS_MMC_ENV_DEV;
+   }
+
+   debug("%s: booted from %s\n", __func__, boot_device);
+
+   if (!strcmp(boot_device, "/mmc@fe32"))
+   return 1;
+
+   if (!strcmp(boot_device, "/mmc@fe33"))
+   return 0;
+
+   return CONFIG_SYS_MMC_ENV_DEV;
+}
+
 int misc_init_r(void)
 {
const u32 cpuid_offset = 0x7;
-- 
2.37.1



[PATCH 04/12] rockchip: puma-rk3399: remove unused default ENV_OFFSET for SPI flashes

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

CONFIG_ENV_OFFSET is set in the defconfig to a different value already
so this isn't used. Let's remove it as to not confuse users.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 board/theobroma-systems/puma_rk3399/Kconfig | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/board/theobroma-systems/puma_rk3399/Kconfig 
b/board/theobroma-systems/puma_rk3399/Kconfig
index 21946d984d..15af55574c 100644
--- a/board/theobroma-systems/puma_rk3399/Kconfig
+++ b/board/theobroma-systems/puma_rk3399/Kconfig
@@ -15,9 +15,6 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 config ENV_SIZE
default 0x4000
 
-config ENV_OFFSET
-   default 0x3fc000 if ENV_IS_IN_SPI_FLASH
-
 choice
prompt "Theobroma Systems RK3399-Q7 DDR Option"
default TARGET_PUMA_RK3399_RAM_DDR3_1333
-- 
2.37.1



[PATCH 03/12] rockchip: puma-rk3399: allow non-SD-Card-loaded SPL to load U-Boot proper from SD-Card

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Trying to load U-Boot proper from SPL when SPL was not loaded from
SD-Card is currently not working because the SDMMC pins aren't muxed
correctly. It is assumed the BootROM is doing this for us when booting
from SD-Card hence why it's not needed when booting TPL/SPL from
SD-Card.

The pinctrl properties are removed from the SPL DT property removal list
and the pinctrl configuration nodes made available in the SPL DT, in
addition to the pull-up configurations to allow loading U-Boot proper
from SD-Card as a fallback mechanism for SPI-NOR and eMMC.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi | 24 +
 configs/puma-rk3399_defconfig   |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi 
b/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
index b9b6ac3f6c..5dc345bbe8 100644
--- a/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
@@ -66,6 +66,30 @@
};
 };
 
+ {
+   u-boot,dm-pre-reloc;
+};
+
  {
u-boot,dm-pre-reloc;
 };
+
+_pull_none {
+   u-boot,dm-pre-reloc;
+};
+
+_pull_up {
+   u-boot,dm-pre-reloc;
+};
+
+_bus4 {
+   u-boot,dm-pre-reloc;
+};
+
+_clk {
+   u-boot,dm-pre-reloc;
+};
+
+_cmd {
+   u-boot,dm-pre-reloc;
+};
diff --git a/configs/puma-rk3399_defconfig b/configs/puma-rk3399_defconfig
index 6093943ee8..779fe5a5cd 100644
--- a/configs/puma-rk3399_defconfig
+++ b/configs/puma-rk3399_defconfig
@@ -42,7 +42,7 @@ CONFIG_CMD_PMIC=y
 CONFIG_CMD_REGULATOR=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_LIVE=y
-CONFIG_OF_SPL_REMOVE_PROPS="pinctrl-0 pinctrl-names interrupt-parent 
assigned-clocks assigned-clock-rates assigned-clock-parents"
+CONFIG_OF_SPL_REMOVE_PROPS="interrupt-parent assigned-clocks 
assigned-clock-rates assigned-clock-parents"
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
-- 
2.37.1



[PATCH 02/12] rockchip: puma-rk3399: use gpio-hog instead of fixed-regulator for enabling eMMC/SPI-NOR

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

On Haikou devkit, it is possible to disable eMMC and SPI-NOR to force
booting from SD card or USB via rkdeveloptool by toggling a switch. This
switch needs to be overridden in software to be able to access eMMC and
SPI-NOR once the device has booted from SD Card. Puma SoM can override
this pin via gpio3_d5.

Until now, fixed regulator device was abused to model this, but since
there's now support for GPIO hogs, let's use it.

Since we want to be able to boot the SPL from SD Card but give it the
ability to load U-Boot proper from a fallback medium such as eMMC and
SPI-NOR, SPL support for GPIO hogs needs to be enabled too. Support for
other kinds of regulators are not needed anymore, so let's disable them.

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

Depends on
https://lore.kernel.org/u-boot/20220712154422.265925-2-foss+ub...@0leil.net/

 arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi | 32 +
 configs/puma-rk3399_defconfig   |  5 ++--
 2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi 
b/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
index e0476ab25c..b9b6ac3f6c 100644
--- a/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi
@@ -31,24 +31,6 @@
spi5 = 
};
 
-   /*
-* The Qseven BIOS_DISABLE signal on the RK3399-Q7 keeps the on-module
-* eMMC and SPI flash powered-down initially (in fact it keeps the
-* reset signal asserted).  Even though it is an enable signal, we
-* model this as a regulator.
-*/
-   bios_enable: bios_enable {
-   compatible = "regulator-fixed";
-   u-boot,dm-pre-reloc;
-   regulator-name = "bios_enable";
-   enable-active-high;
-   gpio = < RK_PD5 GPIO_ACTIVE_LOW>;
-   regulator-always-on;
-   regulator-boot-on;
-   regulator-min-microvolt = <180>;
-   regulator-max-microvolt = <180>;
-   };
-
vdd_log: vdd-log {
compatible = "pwm-regulator";
pwms = < 0 25000 1>;
@@ -68,6 +50,20 @@
 
  {
u-boot,dm-pre-reloc;
+
+   /*
+* The Qseven BIOS_DISABLE signal on the RK3399-Q7 keeps the on-module
+* eMMC and SPI flash powered-down initially (in fact it keeps the
+* reset signal asserted). BIOS_DISABLE_OVERRIDE pin allows to re-enable
+* eMMC and SPI after the SPL has been booted from SD Card.
+*/
+   bios_disable_override {
+   u-boot,dm-pre-reloc;
+   gpios = ;
+   output-high;
+   line-name = "bios_disable_override";
+   gpio-hog;
+   };
 };
 
  {
diff --git a/configs/puma-rk3399_defconfig b/configs/puma-rk3399_defconfig
index 7ce2dc0719..6093943ee8 100644
--- a/configs/puma-rk3399_defconfig
+++ b/configs/puma-rk3399_defconfig
@@ -49,6 +49,8 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_SYS_MMC_ENV_DEV=1
 CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
+CONFIG_GPIO_HOG=y
+CONFIG_SPL_GPIO_HOG=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MISC=y
@@ -72,10 +74,7 @@ CONFIG_PHY_ROCKCHIP_TYPEC=y
 CONFIG_DM_PMIC_FAN53555=y
 CONFIG_PMIC_RK8XX=y
 CONFIG_SPL_PMIC_RK8XX=y
-CONFIG_SPL_DM_REGULATOR=y
 CONFIG_REGULATOR_PWM=y
-CONFIG_SPL_DM_REGULATOR_FIXED=y
-CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_REGULATOR_RK8XX=y
 CONFIG_PWM_ROCKCHIP=y
 CONFIG_DM_RESET=y
-- 
2.37.1



[PATCH 01/12] rockchip: puma-rk3399: fix boot_targets swap depending on U-Boot proper load medium

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

distroboot should try first on the same MMC medium as the one the SPL
loaded U-Boot proper from. This was the case when the introducing commit
was merged because the default order was eMMC first and then SD card.
The check was therefore made only on whether we booted from SD card,
because otherwise the order was the expected one.
However, in commit b212ad24a604 ("rockchip: Fix MMC boot order"), the
order was swapped. Meaning our simple check is now useless.

Let's fix that by accounting for all scenarii: default boot_targets has
mmc0 first but booting from SD Card, mmc1 first but booting from eMMC.

Fixes: b212ad24a604 ("rockchip: Fix MMC boot order")
Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---

Depends on
https://lore.kernel.org/u-boot/20220715151552.953654-1-foss+ub...@0leil.net/
https://lore.kernel.org/u-boot/20220715151552.953654-2-foss+ub...@0leil.net/

 .../puma_rk3399/puma-rk3399.c | 25 ++-
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c 
b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
index deeba3084a..ce3436b770 100644
--- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
+++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
@@ -77,18 +77,16 @@ static int setup_boottargets(void)
}
 
/*
-* Only run, if booting from mmc1 (i.e. /mmc@fe32) and
-* only consider cases where the default boot-order first
-* tries to boot from mmc0 (eMMC) and then from mmc1
-* (i.e. external SD).
-*
-* In other words: the SD card will be moved to earlier in the
-* order, if U-Boot was also loaded from the SD-card.
+* Make the default boot medium between SD Card and eMMC, the one that
+* was used to load U-Boot proper. If SPI-NOR flash was used, keep
+* original default order.
 */
-   if (!strcmp(boot_device, "/mmc@fe32")) {
+   if (strcmp(boot_device, "/spi@ff1d/flash@0")) {
+   bool sd_booted = !strcmp(boot_device, "/mmc@fe32");
char *mmc0, *mmc1;
 
-   debug("%s: booted from SD-Card\n", __func__);
+   debug("%s: booted from %s\n", __func__,
+ sd_booted ? "SD-Card" : "eMMC");
mmc0 = strstr(env, "mmc0");
mmc1 = strstr(env, "mmc1");
 
@@ -98,10 +96,13 @@ static int setup_boottargets(void)
}
 
/*
-* If mmc0 comes first in the boot order, we need to change
-* the strings to make mmc1 first.
+* If mmc0 comes first in the boot order and U-Boot proper was
+* loaded from mmc1, swap mmc0 and mmc1 in the list.
+* If mmc1 comes first in the boot order and U-Boot proper was
+* loaded from mmc0, swap mmc0 and mmc1 in the list.
 */
-   if (mmc0 < mmc1) {
+   if ((mmc0 < mmc1 && sd_booted) ||
+   (mmc0 > mmc1 && !sd_booted)) {
mmc0[3] = '1';
mmc1[3] = '0';
debug("%s: set boot_targets to: %s\n", __func__, env);
-- 
2.37.1



[PATCH 00/12] Puma RK3399 migration to TPL and numerous fixes

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Puma RK3399 SoM struggled for a few releases already to boot because the
SPL was too big. Therefore, let's migrate to TPL like most RK3399-boards
already did a few releases ago.

This also fixes numerous issues around fallback booting (U-Boot proper
corrupted on the storage medium from where TPL/SPL was loaded) and default
order of boot targets.

It also forces the environment storage medium to be the same as the one
from which U-Boot proper was loaded, for a more consistent user
experience.

The environment can also be stored on SPI flash now.

Finally some cleanup and the migration of the flashing instructions to
u-boot-rockchip.bin and u-boot-rockchip-spi.bin.

A small patch for Lion RK3368 also, for migrating the flashing
instructions to u-boot-rockchip.bin.

Patch 1/12 rockchip: puma-rk3399: fix boot_targets swap depending on
U-Boot proper load medium depends on
https://lore.kernel.org/u-boot/20220715151552.953654-1-foss+ub...@0leil.net/
https://lore.kernel.org/u-boot/20220715151552.953654-2-foss+ub...@0leil.net/

Patch 2/12 rockchip: puma-rk3399: use gpio-hog instead of fixed-regulator
for enabling eMMC/SPI-NOR depends on
https://lore.kernel.org/u-boot/20220712154422.265925-2-foss+ub...@0leil.net/

Patch 5/12 rockchip: puma-rk3399: load environment from same MMC as used for
loading U-Boot proper depends on
https://lore.kernel.org/u-boot/20220715151552.953654-1-foss+ub...@0leil.net/

Patch 7/12 rockchip: puma-rk3399: load environment from same medium as
one used to load U-Boot proper depends on
https://lore.kernel.org/u-boot/20220715151552.953654-1-foss+ub...@0leil.net/
https://lore.kernel.org/u-boot/20220715151552.953654-2-foss+ub...@0leil.net/

Patches {10,11,12}/12 depend on the following patch series:
https://lore.kernel.org/u-boot/20220722113505.3875669-1-foss+ub...@0leil.net/

Cheers,
Quentin

Quentin Schulz (12):
  rockchip: puma-rk3399: fix boot_targets swap depending on U-Boot
proper load medium
  rockchip: puma-rk3399: use gpio-hog instead of fixed-regulator for
enabling eMMC/SPI-NOR
  rockchip: puma-rk3399: allow non-SD-Card-loaded SPL to load U-Boot
proper from SD-Card
  rockchip: puma-rk3399: remove unused default ENV_OFFSET for SPI
flashes
  rockchip: puma-rk3399: load environment from same MMC as used for
loading U-Boot proper
  rockchip: puma-rk3399: allow loading environment from SPI-NOR flash
  rockchip: puma-rk3399: load environment from same medium as one used
to load U-Boot proper
  rockchip: puma-rk3399: remove useless CONFIG_SYS_SPI_U_BOOT_OFFS
  rockchip: puma-rk3399: migrate to TPL
  rockchip: puma-rk3399: migrate to u-boot-rockchip.bin
  rockchip: lion-rk3368: migrate to u-boot-rockchip.bin
  rockchip: puma-rk3399: migrate to u-boot-rockchip-spi.bin

 arch/arm/dts/rk3399-puma-haikou-u-boot.dtsi   | 69 ++-
 board/theobroma-systems/lion_rk3368/README|  9 +-
 board/theobroma-systems/puma_rk3399/Kconfig   |  3 -
 board/theobroma-systems/puma_rk3399/README| 22 ++---
 .../puma_rk3399/puma-rk3399.c | 84 ---
 configs/puma-rk3399_defconfig | 16 ++--
 6 files changed, 139 insertions(+), 64 deletions(-)

-- 
2.37.1



[PATCH v8 8/8] test: rng: Add a UT testcase for the rng command

2022-07-22 Thread Sughosh Ganu
The 'rng' command dumps a number of random bytes on the console. Add a
set of tests for the 'rng' command. The test function performs basic
sanity testing of the command.

Since a unit test is being added for the command, enable it by default
in the sandbox platforms.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---
Changes since V7: None

 cmd/Kconfig   |  1 +
 test/dm/rng.c | 29 +
 2 files changed, 30 insertions(+)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index b3820f1e04..b4bf207a2d 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1963,6 +1963,7 @@ config CMD_GETTIME
 config CMD_RNG
bool "rng command"
depends on DM_RNG
+   default y if SANDBOX
select HEXDUMP
help
  Print bytes from the hardware random number generator.
diff --git a/test/dm/rng.c b/test/dm/rng.c
index 5b34c93ed6..6d1f68848d 100644
--- a/test/dm/rng.c
+++ b/test/dm/rng.c
@@ -25,3 +25,32 @@ static int dm_test_rng_read(struct unit_test_state *uts)
return 0;
 }
 DM_TEST(dm_test_rng_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test the rng command */
+static int dm_test_rng_cmd(struct unit_test_state *uts)
+{
+   struct udevice *dev;
+
+   ut_assertok(uclass_get_device(UCLASS_RNG, 0, ));
+   ut_assertnonnull(dev);
+
+   ut_assertok(console_record_reset_enable());
+
+   run_command("rng", 0);
+   ut_assert_nextlinen(":");
+   ut_assert_nextlinen("0010:");
+   ut_assert_nextlinen("0020:");
+   ut_assert_nextlinen("0030:");
+   ut_assert_console_end();
+
+   run_command("rng 0 10", 0);
+   ut_assert_nextlinen(":");
+   ut_assert_console_end();
+
+   run_command("rng 20", 0);
+   ut_assert_nextlinen("No RNG device");
+   ut_assert_console_end();
+
+   return 0;
+}
+DM_TEST(dm_test_rng_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | 
UT_TESTF_CONSOLE_REC);
-- 
2.34.1



[PATCH v8 7/8] doc: rng: Add documentation for the rng command

2022-07-22 Thread Sughosh Ganu
Add a usage document for the 'rng' u-boot command.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Ilias Apalodimas 
Reviewed-by: Simon Glass 
---
Changes since V7: None

 doc/usage/cmd/rng.rst | 26 ++
 doc/usage/index.rst   |  1 +
 2 files changed, 27 insertions(+)
 create mode 100644 doc/usage/cmd/rng.rst

diff --git a/doc/usage/cmd/rng.rst b/doc/usage/cmd/rng.rst
new file mode 100644
index 00..1a352da41a
--- /dev/null
+++ b/doc/usage/cmd/rng.rst
@@ -0,0 +1,26 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+rng command
+===
+
+Synopsis
+
+
+::
+
+rng [devnum [n]]
+
+Description
+---
+
+The *rng* command reads the random number generator(RNG) device and
+prints the random bytes read on the console. A maximum of 64 bytes can
+be read in one invocation of the command.
+
+devnum
+The RNG device from which the random bytes are to be
+read. Defaults to 0.
+
+n
+Number of random bytes to be read and displayed on the
+console. Default value is 0x40. Max value is 0x40.
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 8b98629d6b..366c8bb4b0 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -55,6 +55,7 @@ Shell commands
cmd/pstore
cmd/qfw
cmd/reset
+   cmd/rng
cmd/sbi
cmd/sf
cmd/scp03
-- 
2.34.1



[PATCH v8 6/8] cmd: rng: Use a statically allocated array for random bytes

2022-07-22 Thread Sughosh Ganu
Use a statically allocated buffer on stack instead of using malloc for
reading the random bytes. Using a local array is faster than
allocating heap memory on every initiation of the command.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Ilias Apalodimas 
Reviewed-by: Simon Glass 
---
Changes since V7: None

 cmd/rng.c | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/cmd/rng.c b/cmd/rng.c
index 2ddf27545f..81a23964b8 100644
--- a/cmd/rng.c
+++ b/cmd/rng.c
@@ -14,9 +14,9 @@
 static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
 {
size_t n;
-   struct udevice *dev;
-   void *buf;
+   u8 buf[64];
int devnum;
+   struct udevice *dev;
int ret = CMD_RET_SUCCESS;
 
switch (argc) {
@@ -41,11 +41,10 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
return CMD_RET_FAILURE;
}
 
-   buf = malloc(n);
-   if (!buf) {
-   printf("Out of memory\n");
-   return CMD_RET_FAILURE;
-   }
+   if (!n)
+   return 0;
+
+   n = min(n, sizeof(buf));
 
if (dm_rng_read(dev, buf, n)) {
printf("Reading RNG failed\n");
@@ -54,15 +53,13 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n);
}
 
-   free(buf);
-
return ret;
 }
 
 #ifdef CONFIG_SYS_LONGHELP
 static char rng_help_text[] =
"[dev [n]]\n"
-   "  - print n random bytes read from dev\n";
+   "  - print n random bytes(max 64) read from dev\n";
 #endif
 
 U_BOOT_CMD(
-- 
2.34.1



[PATCH v8 5/8] cmd: rng: Add support for selecting RNG device

2022-07-22 Thread Sughosh Ganu
The 'rng' u-boot command is used for printing a select number of
random bytes on the console. Currently, the RNG device from which the
random bytes are read is fixed. However, a platform can have multiple
RNG devices, one example being qemu, which has a virtio RNG device and
the RNG pseudo device through the TPM chip.

Extend the 'rng' command so that the user can provide the RNG device
number from which the random bytes are to be read. This will be the
device index under the RNG uclass.

Signed-off-by: Sughosh Ganu 
Tested-by: Heinrich Schuchardt 
Reviewed-by: Ilias Apalodimas 
---
Changes since V7: None

 cmd/rng.c | 31 +++
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/cmd/rng.c b/cmd/rng.c
index 1ad5a096c0..2ddf27545f 100644
--- a/cmd/rng.c
+++ b/cmd/rng.c
@@ -13,19 +13,34 @@
 
 static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
 {
-   size_t n = 0x40;
+   size_t n;
struct udevice *dev;
void *buf;
+   int devnum;
int ret = CMD_RET_SUCCESS;
 
-   if (uclass_get_device(UCLASS_RNG, 0, ) || !dev) {
+   switch (argc) {
+   case 1:
+   devnum = 0;
+   n = 0x40;
+   break;
+   case 2:
+   devnum = hextoul(argv[1], NULL);
+   n = 0x40;
+   break;
+   case 3:
+   devnum = hextoul(argv[1], NULL);
+   n = hextoul(argv[2], NULL);
+   break;
+   default:
+   return CMD_RET_USAGE;
+   }
+
+   if (uclass_get_device_by_seq(UCLASS_RNG, devnum, ) || !dev) {
printf("No RNG device\n");
return CMD_RET_FAILURE;
}
 
-   if (argc >= 2)
-   n = hextoul(argv[1], NULL);
-
buf = malloc(n);
if (!buf) {
printf("Out of memory\n");
@@ -46,12 +61,12 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
 
 #ifdef CONFIG_SYS_LONGHELP
 static char rng_help_text[] =
-   "[n]\n"
-   "  - print n random bytes\n";
+   "[dev [n]]\n"
+   "  - print n random bytes read from dev\n";
 #endif
 
 U_BOOT_CMD(
-   rng, 2, 0, do_rng,
+   rng, 3, 0, do_rng,
"print bytes from the hardware random number generator",
rng_help_text
 );
-- 
2.34.1



[PATCH v8 4/8] tpm: Add the RNG child device

2022-07-22 Thread Sughosh Ganu
The TPM device comes with the random number generator(RNG)
functionality which is built into the TPM device. Add logic to add the
RNG child device in the TPM uclass post probe callback.

The RNG device can then be used to pass a set of random bytes to the
linux kernel, need for address space randomisation through the
EFI_RNG_PROTOCOL interface.

No compatible string is provided because this is not available in
the binding defined by Linux. If multiple rand devices are in the
system, then some method of selecting them (other than device tree)
will need to be used, or a binding will need to be added.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Ilias Apalodimas 
---
Changes since V7:
* Added a paragraph in the commit message highlighting the absence of
  the compatible string in the RNG driver, as suggested by Simon.
* Rearranged the inclusion of headers as per the coding style
  guidelines, as suggested by Simon.
* Use TPM_RNG_DRV_NAME for the RNG child name as suggested by Simon.

 drivers/tpm/tpm-uclass.c | 40 ++--
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index f67fe1019b..0eb35f50c4 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -9,12 +9,16 @@
 #include 
 #include 
 #include 
-#include 
-#include 
+#include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include "tpm_internal.h"
 
+#define TPM_RNG_DRV_NAME   "tpm-rng"
+
 int tpm_open(struct udevice *dev)
 {
struct tpm_ops *ops = tpm_get_ops(dev);
@@ -136,12 +140,36 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, 
size_t send_size,
return 0;
 }
 
+static int tpm_uclass_post_probe(struct udevice *dev)
+{
+   int ret;
+   const char *drv = TPM_RNG_DRV_NAME;
+   struct udevice *child;
+
+   if (CONFIG_IS_ENABLED(TPM_RNG)) {
+   ret = device_find_first_child_by_uclass(dev, UCLASS_RNG,
+   );
+
+   if (ret != -ENODEV) {
+   log_debug("RNG child already added to the TPM 
device\n");
+   return ret;
+   }
+
+   ret = device_bind_driver(dev, drv, TPM_RNG_DRV_NAME, );
+   if (ret)
+   return log_msg_ret("bind", ret);
+   }
+
+   return 0;
+}
+
 UCLASS_DRIVER(tpm) = {
-   .id = UCLASS_TPM,
-   .name   = "tpm",
-   .flags  = DM_UC_FLAG_SEQ_ALIAS,
+   .id = UCLASS_TPM,
+   .name   = "tpm",
+   .flags  = DM_UC_FLAG_SEQ_ALIAS,
 #if CONFIG_IS_ENABLED(OF_REAL)
-   .post_bind  = dm_scan_fdt_dev,
+   .post_bind  = dm_scan_fdt_dev,
 #endif
+   .post_probe = tpm_uclass_post_probe,
.per_device_auto= sizeof(struct tpm_chip_priv),
 };
-- 
2.34.1



[PATCH v8 3/8] tpm: rng: Add driver model interface for TPM RNG device

2022-07-22 Thread Sughosh Ganu
The TPM device has a builtin random number generator(RNG)
functionality. Expose the RNG functions of the TPM device to the
driver model so that they can be used by the EFI_RNG_PROTOCOL if the
protocol is installed.

Also change the function arguments and return type of the random
number functions to comply with the driver model api.

Signed-off-by: Sughosh Ganu 
Reviewed-by: Ilias Apalodimas 
---
Changes since V7: None

 drivers/rng/Kconfig   |  9 +
 drivers/rng/Makefile  |  1 +
 drivers/rng/tpm_rng.c | 23 +++
 lib/Kconfig   |  1 +
 lib/tpm_api.c |  6 +++---
 5 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 drivers/rng/tpm_rng.c

diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig
index 21a9ff0195..16143681da 100644
--- a/drivers/rng/Kconfig
+++ b/drivers/rng/Kconfig
@@ -74,4 +74,13 @@ config RNG_SMCCC_TRNG
  Enable random number generator for platforms that support Arm
  SMCCC TRNG interface.
 
+config TPM_RNG
+   bool "Enable random number generator on TPM device"
+   depends on TPM
+   default y
+   help
+ The TPM device has an inbuilt random number generator
+ functionality. Enable random number generator on TPM
+ devices.
+
 endif
diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile
index 2494717d7c..78f61051ac 100644
--- a/drivers/rng/Makefile
+++ b/drivers/rng/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o
 obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rng.o
 obj-$(CONFIG_RNG_IPROC200) += iproc_rng200.o
 obj-$(CONFIG_RNG_SMCCC_TRNG) += smccc_trng.o
+obj-$(CONFIG_TPM_RNG) += tpm_rng.o
diff --git a/drivers/rng/tpm_rng.c b/drivers/rng/tpm_rng.c
new file mode 100644
index 00..1a5e9e2e4b
--- /dev/null
+++ b/drivers/rng/tpm_rng.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+
+static int rng_tpm_random_read(struct udevice *dev, void *data, size_t count)
+{
+   return tpm_get_random(dev_get_parent(dev), data, count);
+}
+
+static const struct dm_rng_ops tpm_rng_ops = {
+   .read = rng_tpm_random_read,
+};
+
+U_BOOT_DRIVER(tpm_rng) = {
+   .name   = "tpm-rng",
+   .id = UCLASS_RNG,
+   .ops= _rng_ops,
+};
diff --git a/lib/Kconfig b/lib/Kconfig
index 7dd777b56a..e888c29245 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -360,6 +360,7 @@ source lib/crypt/Kconfig
 config TPM
bool "Trusted Platform Module (TPM) Support"
depends on DM
+   imply DM_RNG
help
  This enables support for TPMs which can be used to provide security
  features for your board. The TPM can be connected via LPC or I2C
diff --git a/lib/tpm_api.c b/lib/tpm_api.c
index 4ac4612c81..032f383ca0 100644
--- a/lib/tpm_api.c
+++ b/lib/tpm_api.c
@@ -269,7 +269,7 @@ u32 tpm_get_random(struct udevice *dev, void *data, u32 
count)
if (tpm_is_v1(dev))
return tpm1_get_random(dev, data, count);
else if (tpm_is_v2(dev))
-   return -ENOSYS; /* not implemented yet */
-   else
-   return -ENOSYS;
+   return tpm2_get_random(dev, data, count);
+
+   return -ENOSYS;
 }
-- 
2.34.1



[PATCH v8 2/8] efi_loader: initialize the RNG protocol after the TCC2

2022-07-22 Thread Sughosh Ganu
From: Ilias Apalodimas 

Due to U-Boot's lazy binding the RNG presented by the TCG is not available
until the EFI_TCG2 protocol has been initialized.  Since the TPM has a
built-in RNG device we can use for the OS randomization, move the RNG
protocol installation after the TCG.

Signed-off-by: Ilias Apalodimas 
---
Changes since V7: New patch

 lib/efi_loader/efi_setup.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 492ecf4cb1..751beda590 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -246,13 +246,6 @@ efi_status_t efi_init_obj_list(void)
/* Set up console modes */
efi_setup_console_size();
 
-   /* Install EFI_RNG_PROTOCOL */
-   if (IS_ENABLED(CONFIG_EFI_RNG_PROTOCOL)) {
-   ret = efi_rng_register();
-   if (ret != EFI_SUCCESS)
-   goto out;
-   }
-
/* Initialize variable services */
ret = efi_init_variables();
if (ret != EFI_SUCCESS)
@@ -289,6 +282,13 @@ efi_status_t efi_init_obj_list(void)
goto out;
}
 
+   /* Install EFI_RNG_PROTOCOL */
+   if (IS_ENABLED(CONFIG_EFI_RNG_PROTOCOL)) {
+   ret = efi_rng_register();
+   if (ret != EFI_SUCCESS)
+   goto out;
+   }
+
if (IS_ENABLED(CONFIG_EFI_RISCV_BOOT_PROTOCOL)) {
ret = efi_riscv_register();
if (ret != EFI_SUCCESS)
-- 
2.34.1



[PATCH v8 1/8] tpm: Export the TPM-version functions

2022-07-22 Thread Sughosh Ganu
From: Simon Glass 

These functions should really be available outside the TPM code, so that
other callers can find out which version the TPM is. Rename them to have
a tpm_ prefix() and add them to the header file.

Signed-off-by: Simon Glass 
Reviewed-by: Ilias Apalodimas 
---
Changes since V7: None

 include/tpm_api.h | 10 ++
 lib/tpm_api.c | 92 +--
 2 files changed, 51 insertions(+), 51 deletions(-)

diff --git a/include/tpm_api.h b/include/tpm_api.h
index ef45b43a8f..11aa14eb79 100644
--- a/include/tpm_api.h
+++ b/include/tpm_api.h
@@ -319,4 +319,14 @@ u32 tpm_write_lock(struct udevice *dev, u32 index);
  */
 u32 tpm_resume(struct udevice *dev);
 
+static inline bool tpm_is_v1(struct udevice *dev)
+{
+   return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1;
+}
+
+static inline bool tpm_is_v2(struct udevice *dev)
+{
+   return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2;
+}
+
 #endif /* __TPM_API_H */
diff --git a/lib/tpm_api.c b/lib/tpm_api.c
index 4c662640a9..4ac4612c81 100644
--- a/lib/tpm_api.c
+++ b/lib/tpm_api.c
@@ -11,21 +11,11 @@
 #include 
 #include 
 
-static bool is_tpm1(struct udevice *dev)
-{
-   return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1;
-}
-
-static bool is_tpm2(struct udevice *dev)
-{
-   return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2;
-}
-
 u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode)
 {
-   if (is_tpm1(dev)) {
+   if (tpm_is_v1(dev)) {
return tpm1_startup(dev, mode);
-   } else if (is_tpm2(dev)) {
+   } else if (tpm_is_v2(dev)) {
enum tpm2_startup_types type;
 
switch (mode) {
@@ -47,9 +37,9 @@ u32 tpm_startup(struct udevice *dev, enum tpm_startup_type 
mode)
 
 u32 tpm_resume(struct udevice *dev)
 {
-   if (is_tpm1(dev))
+   if (tpm_is_v1(dev))
return tpm1_startup(dev, TPM_ST_STATE);
-   else if (is_tpm2(dev))
+   else if (tpm_is_v2(dev))
return tpm2_startup(dev, TPM2_SU_STATE);
else
return -ENOSYS;
@@ -57,9 +47,9 @@ u32 tpm_resume(struct udevice *dev)
 
 u32 tpm_self_test_full(struct udevice *dev)
 {
-   if (is_tpm1(dev))
+   if (tpm_is_v1(dev))
return tpm1_self_test_full(dev);
-   else if (is_tpm2(dev))
+   else if (tpm_is_v2(dev))
return tpm2_self_test(dev, TPMI_YES);
else
return -ENOSYS;
@@ -67,9 +57,9 @@ u32 tpm_self_test_full(struct udevice *dev)
 
 u32 tpm_continue_self_test(struct udevice *dev)
 {
-   if (is_tpm1(dev))
+   if (tpm_is_v1(dev))
return tpm1_continue_self_test(dev);
-   else if (is_tpm2(dev))
+   else if (tpm_is_v2(dev))
return tpm2_self_test(dev, TPMI_NO);
else
return -ENOSYS;
@@ -86,7 +76,7 @@ u32 tpm_clear_and_reenable(struct udevice *dev)
return ret;
}
 
-   if (is_tpm1(dev)) {
+   if (tpm_is_v1(dev)) {
ret = tpm1_physical_enable(dev);
if (ret != TPM_SUCCESS) {
log_err("TPM: Can't set enabled state\n");
@@ -105,9 +95,9 @@ u32 tpm_clear_and_reenable(struct udevice *dev)
 
 u32 tpm_nv_enable_locking(struct udevice *dev)
 {
-   if (is_tpm1(dev))
+   if (tpm_is_v1(dev))
return tpm1_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0);
-   else if (is_tpm2(dev))
+   else if (tpm_is_v2(dev))
return -ENOSYS;
else
return -ENOSYS;
@@ -115,9 +105,9 @@ u32 tpm_nv_enable_locking(struct udevice *dev)
 
 u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count)
 {
-   if (is_tpm1(dev))
+   if (tpm_is_v1(dev))
return tpm1_nv_read_value(dev, index, data, count);
-   else if (is_tpm2(dev))
+   else if (tpm_is_v2(dev))
return tpm2_nv_read_value(dev, index, data, count);
else
return -ENOSYS;
@@ -126,9 +116,9 @@ u32 tpm_nv_read_value(struct udevice *dev, u32 index, void 
*data, u32 count)
 u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
   u32 count)
 {
-   if (is_tpm1(dev))
+   if (tpm_is_v1(dev))
return tpm1_nv_write_value(dev, index, data, count);
-   else if (is_tpm2(dev))
+   else if (tpm_is_v2(dev))
return tpm2_nv_write_value(dev, index, data, count);
else
return -ENOSYS;
@@ -141,9 +131,9 @@ u32 tpm_set_global_lock(struct udevice *dev)
 
 u32 tpm_write_lock(struct udevice *dev, u32 index)
 {
-   if (is_tpm1(dev))
+   if (tpm_is_v1(dev))
return -ENOSYS;
-   else if (is_tpm2(dev))
+   else if (tpm_is_v2(dev))
return tpm2_write_lock(dev, index);
else
return -ENOSYS;
@@ -152,9 +142,9 @@ u32 tpm_write_lock(struct 

[PATCH v8 0/8] tpm: rng: Move TPM RNG functionality to driver model

2022-07-22 Thread Sughosh Ganu


The TPM device provides the random number generator(RNG)
functionality, whereby sending a command to the TPM device results in
the TPM device responding with random bytes.

There was a discussion on the mailing list earlier[1], where it was
explained that platforms with a TPM device can install the
EFI_RNG_PROTOCOL for getting the random bytes instead of populating
the dtb with the kaslr-seed property. That would make it possible to
measure the dtb.

The TPM uclass driver adds the RNG child device as part of it's
post_probe function.

Some additional changes have also been made to facilitate the
use of the RNG devices, including extending the 'rng' command to take
the RNG device as one of the command-line parameters.

This series depends on a patch[2] from Simon Glass for moving the TPM
device version detection functions to the tpm_api.h header as static
inline functions.

[1] - 
https://lore.kernel.org/u-boot/20220103120738.47835-1-ilias.apalodi...@linaro.org/
[2] - 
https://lore.kernel.org/u-boot/20220301001125.1554442-2-...@chromium.org/T/#u

Changes since V7:
* Added a paragraph in the commit message highlighting the absence of
  the compatible string in the RNG driver, as suggested by Simon.
* Rearranged the inclusion of headers as per the coding style
  guidelines, as suggested by Simon.
* Use TPM_RNG_DRV_NAME for the RNG child name as suggested by Simon.


Ilias Apalodimas (1):
  efi_loader: initialize the RNG protocol after the TCC2

Simon Glass (1):
  tpm: Export the TPM-version functions

Sughosh Ganu (6):
  tpm: rng: Add driver model interface for TPM RNG device
  tpm: Add the RNG child device
  cmd: rng: Add support for selecting RNG device
  cmd: rng: Use a statically allocated array for random bytes
  doc: rng: Add documentation for the rng command
  test: rng: Add a UT testcase for the rng command

 cmd/Kconfig|  1 +
 cmd/rng.c  | 42 ++--
 doc/usage/cmd/rng.rst  | 26 ++
 doc/usage/index.rst|  1 +
 drivers/rng/Kconfig|  9 
 drivers/rng/Makefile   |  1 +
 drivers/rng/tpm_rng.c  | 23 +
 drivers/tpm/tpm-uclass.c   | 40 +---
 include/tpm_api.h  | 10 
 lib/Kconfig|  1 +
 lib/efi_loader/efi_setup.c | 14 +++---
 lib/tpm_api.c  | 98 +-
 test/dm/rng.c  | 29 +++
 13 files changed, 213 insertions(+), 82 deletions(-)
 create mode 100644 doc/usage/cmd/rng.rst
 create mode 100644 drivers/rng/tpm_rng.c

-- 
2.34.1




Re: [PATCH v2 0/4] Deduplicate dhelectronics board files

2022-07-22 Thread Marek Vasut

On 7/22/22 10:26, Philip Oberfichtner wrote:


This series unifies common MAC address code for imx6, imx8 and stm32
based boards by DH. It is thought of as a starting point for more
deduplication in the future.


Entire series

Reviewed-by: Marek Vasut 


[PATCH] video: dw_mipi_dsi: fix vsync active vs back porch

2022-07-22 Thread John Keeping
The wrong fields are pulled out of the timings here so the values
programmed into the DSI_VID_VSA_LINES and DSI_VID_VBP_LINES registers
are swapped.

Use the right fields so that the correct values are programmed.

Fixes: d4f7ea83fc ("video: add MIPI DSI host controller bridge")
Signed-off-by: John Keeping 
---
 drivers/video/dw_mipi_dsi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/dw_mipi_dsi.c b/drivers/video/dw_mipi_dsi.c
index a5b38acabd..c68dd66fdc 100644
--- a/drivers/video/dw_mipi_dsi.c
+++ b/drivers/video/dw_mipi_dsi.c
@@ -644,9 +644,9 @@ static void dw_mipi_dsi_vertical_timing_config(struct 
dw_mipi_dsi *dsi,
u32 vactive, vsa, vfp, vbp;
 
vactive = timings->vactive.typ;
-   vsa =  timings->vback_porch.typ;
+   vsa =  timings->vsync_len.typ;
vfp =  timings->vfront_porch.typ;
-   vbp = timings->vsync_len.typ;
+   vbp = timings->vback_porch.typ;
 
dsi_write(dsi, DSI_VID_VACTIVE_LINES, vactive);
dsi_write(dsi, DSI_VID_VSA_LINES, vsa);
-- 
2.37.1



[PATCH v12 13/13] fpga: zynqmp: support loading encrypted bitfiles

2022-07-22 Thread Oleksandr Suvorov
From: Adrian Fiergolski 

Add supporting new compatible string "u-boot,zynqmp-fpga-enc" to
handle loading encrypted bitfiles.

This feature requires encrypted FSBL, as according to UG1085:
"The CSU automatically locks out the AES key, stored in either BBRAM
 or eFUSEs, as a key source to the AES engine if the FSBL is not
 encrypted. This prevents using the BBRAM or eFUSE as the key source
 to the AES engine during run-time applications."

Signed-off-by: Adrian Fiergolski 
Co-developed-by: Oleksandr Suvorov 
Signed-off-by: Oleksandr Suvorov 
Tested-by: Adrian Fiergolski 
---

Changes in v12:
- reduce the size of SPL if FPGA_LOAD_SECURE disabled.

Changes in v11:
- add Tested-by records.

Changes in v10:
- Support ENC images only if FPGA_LOAD_SECURE enabled.

Changes in v9:
- remove an alien commit from a patchset :)

Changes in v8:
- Michal Simek's suggestions addressed:
-- introduce the compatible flags in xilinx_desc;
-- pass a binary compatible flag instead of "compatible" property to
   an FPGA driver.
- Optimize a zynqmp_load() function.

Changes in v7:
- apply Michal Simek's suggestions
  As I applied changes on Oleksandr's patches, I indicated it by
  specifying myself as co-author in the commits logs. I am not sure
  if that is the convention of marking it.

Changes in v6:
- add support for the encrypted bitfiles.

Changes in v5:
- replace ifdef with if() where it's possible.

Changes in v4:
- change interface to xilinx_desc->operations->open() callback.
- fix a bug from previous version of the patchset in dereferencing
  of a parent fpga_desc structure.

Changes in v3:
- remove the patch which introduced CMD_SPL_FPGA_LOAD_SECURE.
- fix mixing definitions/declarations.
- replace strcmp() calls with more secure strncmp().
- document the "u-boot,zynqmp-fpga-ddrauth" compatible string.
- fix code style by check-patch recommendations.

Changes in v2:
- add function fit_fpga_load() to simplify calls of fpga_load()
  from contexts without a compatible attribute.
- move all ZynqMP-specific logic to drivers/fpga/zynqmppl.c
- prepare for passing a "compatible" FDT property to any fpga driver.

 doc/uImage.FIT/source_file_format.txt | 2 ++
 drivers/fpga/zynqmppl.c   | 8 
 include/fpga.h| 1 +
 include/xilinx.h  | 1 +
 include/zynqmppl.h| 4 +++-
 5 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/doc/uImage.FIT/source_file_format.txt 
b/doc/uImage.FIT/source_file_format.txt
index 461e2af2a84..68701118409 100644
--- a/doc/uImage.FIT/source_file_format.txt
+++ b/doc/uImage.FIT/source_file_format.txt
@@ -188,6 +188,8 @@ the '/images' node should have the following layout:
 "u-boot,fpga-legacy" - the generic fpga loading routine.
 "u-boot,zynqmp-fpga-ddrauth" - signed non-encrypted FPGA bitstream for
 Xilinx Zynq UltraScale+ (ZymqMP) device.
+"u-boot,zynqmp-fpga-enc" - encrypted FPGA bitstream for Xilinx Zynq
+UltraScale+ (ZynqMP) device.
 
   Optional nodes:
   - hash-1 : Each hash sub-node represents separate hash or checksum
diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index 200076c8c6a..a6c8dcdcdcc 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -256,6 +256,11 @@ static int zynqmp_load(xilinx_desc *desc, const void *buf, 
size_t bsize,
info.authflag = ZYNQMP_FPGA_AUTH_DDR;
info.encflag = FPGA_NO_ENC_OR_NO_AUTH;
return desc->operations->loads(desc, buf, bsize, );
+   case FPGA_XILINX_ZYNQMP_ENC:
+   /* Encryption using device key */
+   info.authflag = FPGA_NO_ENC_OR_NO_AUTH;
+   info.encflag = FPGA_ENC_DEV_KEY;
+   return desc->operations->loads(desc, buf, bsize, );
default:
printf("Unsupported bitstream type %d\n", flags);
return FPGA_FAIL;
@@ -358,6 +363,9 @@ static int __maybe_unused zynqmp_str2flag(xilinx_desc 
*desc, const char *str)
 #if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
if (!strncmp(str, "u-boot,zynqmp-fpga-ddrauth", 26))
return FPGA_XILINX_ZYNQMP_DDRAUTH;
+
+   if (!strncmp(str, "u-boot,zynqmp-fpga-enc", 22))
+   return FPGA_XILINX_ZYNQMP_ENC;
 #endif
return 0;
 }
diff --git a/include/fpga.h b/include/fpga.h
index 13b1bbee3ca..a4e16401da7 100644
--- a/include/fpga.h
+++ b/include/fpga.h
@@ -20,6 +20,7 @@
 /* device numbers must be non-negative */
 #define FPGA_INVALID_DEVICE-1
 
+#define FPGA_ENC_DEV_KEY   0
 #define FPGA_ENC_USR_KEY   1
 #define FPGA_NO_ENC_OR_NO_AUTH 2
 
diff --git a/include/xilinx.h b/include/xilinx.h
index 97ee12cec42..e4e29797988 100644
--- a/include/xilinx.h
+++ b/include/xilinx.h
@@ -40,6 +40,7 @@ typedef enum {/* typedef 
xilinx_family */
 /* FPGA bitstream supported types */
 #define FPGA_LEGACYBIT(0)
 #define FPGA_XILINX_ZYNQMP_DDRAUTH BIT(1)
+#define FPGA_XILINX_ZYNQMP_ENC 

[PATCH v12 12/13] fpga: zynqmp: support loading authenticated images

2022-07-22 Thread Oleksandr Suvorov
Add supporting new compatible string "u-boot,zynqmp-fpga-ddrauth" to
handle loading authenticated images (DDR).

Based on solution by Jorge Ramirez-Ortiz 
Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
---

(no changes since v11)

Changes in v11:
- Fix treating an incoming FPGA image with empty flags parameter as
  legacy.

Changes in v10:
- Support DDR images only if FPGA_LOAD_SECURE enabled.

 boot/Kconfig  |  4 ++--
 doc/uImage.FIT/source_file_format.txt |  5 -
 drivers/fpga/zynqmppl.c   | 31 ++-
 include/xilinx.h  |  1 +
 include/zynqmppl.h|  4 
 5 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 17438b566d5..59d0c65c944 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -210,8 +210,8 @@ config SPL_LOAD_FIT
  1. "loadables" images, other than FDTs, which do not have a "load"
 property will not be loaded. This limitation also applies to FPGA
 images with the correct "compatible" string.
- 2. For FPGA images, only the "compatible" = "u-boot,fpga-legacy"
-loading method is supported.
+ 2. For FPGA images, the supported "compatible" list is in the
+doc/uImage.FIT/source_file_format.txt.
  3. FDTs are only loaded for images with an "os" property of "u-boot".
 "linux" images are also supported with Falcon boot mode.
 
diff --git a/doc/uImage.FIT/source_file_format.txt 
b/doc/uImage.FIT/source_file_format.txt
index f93ac6d1c7b..461e2af2a84 100644
--- a/doc/uImage.FIT/source_file_format.txt
+++ b/doc/uImage.FIT/source_file_format.txt
@@ -184,7 +184,10 @@ the '/images' node should have the following layout:
 Mandatory for types: "firmware", and "kernel".
   - compatible : compatible method for loading image.
 Mandatory for types: "fpga", and images that do not specify a load address.
-To use the generic fpga loading routine, use "u-boot,fpga-legacy".
+Supported compatible methods:
+"u-boot,fpga-legacy" - the generic fpga loading routine.
+"u-boot,zynqmp-fpga-ddrauth" - signed non-encrypted FPGA bitstream for
+Xilinx Zynq UltraScale+ (ZymqMP) device.
 
   Optional nodes:
   - hash-1 : Each hash sub-node represents separate hash or checksum
diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index feaf34fff11..200076c8c6a 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -202,9 +203,12 @@ static int zynqmp_validate_bitstream(xilinx_desc *desc, 
const void *buf,
 #if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
 static int zynqmp_check_compatible(xilinx_desc *desc, int flags)
 {
-   /* If no flags set, the image is legacy */
+   /*
+* If no flags set, the image may be legacy, but we need to
+* signal caller this situation with specific error code.
+*/
if (!flags)
-   return 0;
+   return -ENODATA;
 
/* For legacy bitstream images no need for other methods exist */
if ((flags & desc->flags) && flags == FPGA_LEGACY)
@@ -217,7 +221,7 @@ static int zynqmp_check_compatible(xilinx_desc *desc, int 
flags)
if (desc->operations->loads && (flags & desc->flags))
return 0;
 
-   return FPGA_FAIL;
+   return -ENODEV;
 }
 #endif
 
@@ -231,8 +235,9 @@ static int zynqmp_load(xilinx_desc *desc, const void *buf, 
size_t bsize,
u32 buf_lo, buf_hi;
u32 bsize_req = (u32)bsize;
u32 ret_payload[PAYLOAD_ARG_CNT];
-
 #if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+   struct fpga_secure_info info = { 0 };
+
ret = zynqmp_check_compatible(desc, flags);
if (ret) {
if (ret != -ENODATA) {
@@ -242,6 +247,19 @@ static int zynqmp_load(xilinx_desc *desc, const void *buf, 
size_t bsize,
/* If flags is not set, the image treats as legacy */
flags = FPGA_LEGACY;
}
+
+   switch (flags) {
+   case FPGA_LEGACY:
+   break;  /* Handle the legacy image later in this function */
+   case FPGA_XILINX_ZYNQMP_DDRAUTH:
+   /* DDR authentication */
+   info.authflag = ZYNQMP_FPGA_AUTH_DDR;
+   info.encflag = FPGA_NO_ENC_OR_NO_AUTH;
+   return desc->operations->loads(desc, buf, bsize, );
+   default:
+   printf("Unsupported bitstream type %d\n", flags);
+   return FPGA_FAIL;
+   }
 #endif
 
if (zynqmp_firmware_version() <= PMUFW_V1_0) {
@@ -337,7 +355,10 @@ static int __maybe_unused zynqmp_str2flag(xilinx_desc 
*desc, const char *str)
 {
if (!strncmp(str, "u-boot,fpga-legacy", 18))
return FPGA_LEGACY;
-
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+   if (!strncmp(str, "u-boot,zynqmp-fpga-ddrauth", 26))
+   return 

[PATCH v12 09/13] fpga: xilinx: pass compatible flags to load() callback

2022-07-22 Thread Oleksandr Suvorov
These flags may be used to check whether an FPGA driver is able to
load a particular FPGA bitstream image.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

(no changes since v1)

 drivers/fpga/spartan2.c | 2 +-
 drivers/fpga/spartan3.c | 2 +-
 drivers/fpga/versalpl.c | 2 +-
 drivers/fpga/virtex2.c  | 2 +-
 drivers/fpga/xilinx.c   | 2 +-
 drivers/fpga/zynqmppl.c | 2 +-
 drivers/fpga/zynqpl.c   | 2 +-
 include/xilinx.h| 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/fpga/spartan2.c b/drivers/fpga/spartan2.c
index 3435400e58b..328740f3f35 100644
--- a/drivers/fpga/spartan2.c
+++ b/drivers/fpga/spartan2.c
@@ -41,7 +41,7 @@ static int spartan2_ss_dump(xilinx_desc *desc, const void 
*buf, size_t bsize);
 /* - */
 /* Spartan-II Generic Implementation */
 static int spartan2_load(xilinx_desc *desc, const void *buf, size_t bsize,
-bitstream_type bstype)
+bitstream_type bstype, int flags)
 {
int ret_val = FPGA_FAIL;
 
diff --git a/drivers/fpga/spartan3.c b/drivers/fpga/spartan3.c
index 4850c99352d..918f6db5065 100644
--- a/drivers/fpga/spartan3.c
+++ b/drivers/fpga/spartan3.c
@@ -45,7 +45,7 @@ static int spartan3_ss_dump(xilinx_desc *desc, const void 
*buf, size_t bsize);
 /* - */
 /* Spartan-II Generic Implementation */
 static int spartan3_load(xilinx_desc *desc, const void *buf, size_t bsize,
-bitstream_type bstype)
+bitstream_type bstype, int flags)
 {
int ret_val = FPGA_FAIL;
 
diff --git a/drivers/fpga/versalpl.c b/drivers/fpga/versalpl.c
index c44a7d34557..d3876a8f541 100644
--- a/drivers/fpga/versalpl.c
+++ b/drivers/fpga/versalpl.c
@@ -27,7 +27,7 @@ static ulong versal_align_dma_buffer(ulong *buf, u32 len)
 }
 
 static int versal_load(xilinx_desc *desc, const void *buf, size_t bsize,
-  bitstream_type bstype)
+  bitstream_type bstype, int flags)
 {
ulong bin_buf;
int ret;
diff --git a/drivers/fpga/virtex2.c b/drivers/fpga/virtex2.c
index b3e0537bab0..83b90298cad 100644
--- a/drivers/fpga/virtex2.c
+++ b/drivers/fpga/virtex2.c
@@ -94,7 +94,7 @@ static int virtex2_ss_load(xilinx_desc *desc, const void 
*buf, size_t bsize);
 static int virtex2_ss_dump(xilinx_desc *desc, const void *buf, size_t bsize);
 
 static int virtex2_load(xilinx_desc *desc, const void *buf, size_t bsize,
-   bitstream_type bstype)
+   bitstream_type bstype, int flags)
 {
int ret_val = FPGA_FAIL;
 
diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c
index d9951ca3ecf..8170c3368ef 100644
--- a/drivers/fpga/xilinx.c
+++ b/drivers/fpga/xilinx.c
@@ -151,7 +151,7 @@ int xilinx_load(xilinx_desc *desc, const void *buf, size_t 
bsize,
return FPGA_FAIL;
}
 
-   return desc->operations->load(desc, buf, bsize, bstype);
+   return desc->operations->load(desc, buf, bsize, bstype, flags);
 }
 
 #if defined(CONFIG_CMD_FPGA_LOADFS)
diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index 19d079c9d9f..a0624567882 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -200,7 +200,7 @@ static int zynqmp_validate_bitstream(xilinx_desc *desc, 
const void *buf,
 }
 
 static int zynqmp_load(xilinx_desc *desc, const void *buf, size_t bsize,
-bitstream_type bstype)
+bitstream_type bstype, int flags)
 {
ALLOC_CACHE_ALIGN_BUFFER(u32, bsizeptr, 1);
u32 swap = 0;
diff --git a/drivers/fpga/zynqpl.c b/drivers/fpga/zynqpl.c
index 2de40109a81..d8ebd542abd 100644
--- a/drivers/fpga/zynqpl.c
+++ b/drivers/fpga/zynqpl.c
@@ -371,7 +371,7 @@ static int zynq_validate_bitstream(xilinx_desc *desc, const 
void *buf,
 }
 
 static int zynq_load(xilinx_desc *desc, const void *buf, size_t bsize,
-bitstream_type bstype)
+bitstream_type bstype, int flags)
 {
unsigned long ts; /* Timestamp */
u32 isr_status, swap;
diff --git a/include/xilinx.h b/include/xilinx.h
index 0bbf14d8a1d..e5f6db33fa2 100644
--- a/include/xilinx.h
+++ b/include/xilinx.h
@@ -53,7 +53,7 @@ typedef struct {  /* typedef xilinx_desc */
 
 struct xilinx_fpga_op {
int (*load)(xilinx_desc *desc, const void *buf, size_t bsize,
-   bitstream_type bstype);
+   bitstream_type bstype, int flags);
int (*loadfs)(xilinx_desc *desc, const void *buf, size_t bsize,
  fpga_fs_info *fpga_fsinfo);
int (*loads)(xilinx_desc *desc, const void *buf, size_t bsize,
-- 
2.36.1



[PATCH v12 11/13] fpga: zynqmp: add bitstream compatible checking

2022-07-22 Thread Oleksandr Suvorov
Check whether the FPGA ZynqMP driver supports the given bitstream
image type.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

Changes in v12:
- exclude all secure-related code if FPGA_LOAD_SECURE is disabled

Changes in v10:
- fix grammar

 drivers/fpga/zynqmppl.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index 2791f931861..feaf34fff11 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -199,6 +199,28 @@ static int zynqmp_validate_bitstream(xilinx_desc *desc, 
const void *buf,
return 0;
 }
 
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+static int zynqmp_check_compatible(xilinx_desc *desc, int flags)
+{
+   /* If no flags set, the image is legacy */
+   if (!flags)
+   return 0;
+
+   /* For legacy bitstream images no need for other methods exist */
+   if ((flags & desc->flags) && flags == FPGA_LEGACY)
+   return 0;
+
+   /*
+* Other images are handled in secure callback loads(). Check
+* callback existence besides image type support.
+*/
+   if (desc->operations->loads && (flags & desc->flags))
+   return 0;
+
+   return FPGA_FAIL;
+}
+#endif
+
 static int zynqmp_load(xilinx_desc *desc, const void *buf, size_t bsize,
 bitstream_type bstype, int flags)
 {
@@ -210,6 +232,18 @@ static int zynqmp_load(xilinx_desc *desc, const void *buf, 
size_t bsize,
u32 bsize_req = (u32)bsize;
u32 ret_payload[PAYLOAD_ARG_CNT];
 
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+   ret = zynqmp_check_compatible(desc, flags);
+   if (ret) {
+   if (ret != -ENODATA) {
+   puts("Missing loads() operation or unsupported 
bitstream type\n");
+   return FPGA_FAIL;
+   }
+   /* If flags is not set, the image treats as legacy */
+   flags = FPGA_LEGACY;
+   }
+#endif
+
if (zynqmp_firmware_version() <= PMUFW_V1_0) {
puts("WARN: PMUFW v1.0 or less is detected\n");
puts("WARN: Not all bitstream formats are supported\n");
-- 
2.36.1



[PATCH v12 10/13] fpga: zynqmp: reduce zynqmppl_load() code

2022-07-22 Thread Oleksandr Suvorov
Reduce the function code by calling xilinx_pm_request() once only.
Use the same variable bsize_req to store either bstream size in bytes
or an address of bstream size according to a type required by the
firmware version. Remove obsolete debug().

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

Changes in v12:
- fix a commit message
- remove obsolete debug() message

 drivers/fpga/zynqmppl.c | 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index a0624567882..2791f931861 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -207,38 +207,33 @@ static int zynqmp_load(xilinx_desc *desc, const void 
*buf, size_t bsize,
ulong bin_buf;
int ret;
u32 buf_lo, buf_hi;
+   u32 bsize_req = (u32)bsize;
u32 ret_payload[PAYLOAD_ARG_CNT];
-   bool xilfpga_old = false;
 
if (zynqmp_firmware_version() <= PMUFW_V1_0) {
puts("WARN: PMUFW v1.0 or less is detected\n");
puts("WARN: Not all bitstream formats are supported\n");
puts("WARN: Please upgrade PMUFW\n");
-   xilfpga_old = true;
if (zynqmp_validate_bitstream(desc, buf, bsize, bsize, ))
return FPGA_FAIL;
bsizeptr = (u32 *)
flush_dcache_range((ulong)bsizeptr,
   (ulong)bsizeptr + sizeof(size_t));
+   bsize_req = (u32)(uintptr_t)bsizeptr;
bstype |= BIT(ZYNQMP_FPGA_BIT_NS);
+   } else {
+   bstype = 0;
}
 
bin_buf = zynqmp_align_dma_buffer((u32 *)buf, bsize, swap);
 
-   debug("%s called!\n", __func__);
flush_dcache_range(bin_buf, bin_buf + bsize);
 
buf_lo = (u32)bin_buf;
buf_hi = upper_32_bits(bin_buf);
 
-   if (xilfpga_old)
-   ret = xilinx_pm_request(PM_FPGA_LOAD, buf_lo,
-   buf_hi, (u32)(uintptr_t)bsizeptr,
-   bstype, ret_payload);
-   else
-   ret = xilinx_pm_request(PM_FPGA_LOAD, buf_lo,
-   buf_hi, (u32)bsize, 0, ret_payload);
-
+   ret = xilinx_pm_request(PM_FPGA_LOAD, buf_lo, buf_hi,
+   bsize_req, bstype, ret_payload);
if (ret)
printf("PL FPGA LOAD failed with err: 0x%08x\n", ret);
 
-- 
2.36.1



[PATCH v12 08/13] spl: fit: pass real compatible flags to fpga_load()

2022-07-22 Thread Oleksandr Suvorov
Convert taken FPGA image "compatible" string to a binary compatible
flag and pass it to an FPGA driver.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

Changes in v12:
- convert "compatible" to flags only if FPGA_LOAD_SECURE enabled;

Changes in v10:
- made the message about ignoring legacy compatibe option as debug;

 common/spl/spl_fit.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 3c5a91916cc..a35be529656 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -588,10 +588,15 @@ static int spl_fit_upload_fpga(struct spl_fit_info *ctx, 
int node,
  (u32)fpga_image->load_addr, fpga_image->size);
 
compatible = fdt_getprop(ctx->fit, node, "compatible", NULL);
-   if (!compatible)
+   if (!compatible) {
warn_deprecated("'fpga' image without 'compatible' property");
-   else if (strcmp(compatible, "u-boot,fpga-legacy"))
-   printf("Ignoring compatible = %s property\n", compatible);
+   } else {
+   if (CONFIG_IS_ENABLED(FPGA_LOAD_SECURE))
+   flags = fpga_compatible2flag(devnum, compatible);
+   if (strcmp(compatible, "u-boot,fpga-legacy"))
+   debug("Ignoring compatible = %s property\n",
+ compatible);
+   }
 
ret = fpga_load(devnum, (void *)fpga_image->load_addr,
fpga_image->size, BIT_FULL, flags);
-- 
2.36.1



[PATCH v12 07/13] fpga: add fpga_compatible2flag

2022-07-22 Thread Oleksandr Suvorov
Add a "compatible" string to binary flag converter, which uses
a callback str2flag() of given FPGA driver if available.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

Changes in v12:
- define the function only if FPGA_LOAD_SECURE enabled;

Changes in v10:
- fix mixed types of return value;

 drivers/fpga/fpga.c | 26 ++
 include/fpga.h  |  1 +
 2 files changed, 27 insertions(+)

diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index 185bd547cb5..4db5c0a91e9 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -357,3 +357,29 @@ int fpga_info(int devnum)
 
return fpga_dev_info(devnum);
 }
+
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+int fpga_compatible2flag(int devnum, const char *compatible)
+{
+   const fpga_desc * const desc = fpga_get_desc(devnum);
+
+   if (!desc)
+   return 0;
+
+   switch (desc->devtype) {
+#if defined(CONFIG_FPGA_XILINX)
+   case fpga_xilinx:
+   {
+   xilinx_desc *xdesc = (xilinx_desc *)desc->devdesc;
+
+   if (xdesc->operations && xdesc->operations->str2flag)
+   return xdesc->operations->str2flag(xdesc, compatible);
+   }
+#endif
+   default:
+   break;
+   }
+
+   return 0;
+}
+#endif
diff --git a/include/fpga.h b/include/fpga.h
index 6365e1569e3..13b1bbee3ca 100644
--- a/include/fpga.h
+++ b/include/fpga.h
@@ -75,5 +75,6 @@ int fpga_dump(int devnum, const void *buf, size_t bsize);
 int fpga_info(int devnum);
 const fpga_desc *const fpga_validate(int devnum, const void *buf,
 size_t bsize, char *fn);
+int fpga_compatible2flag(int devnum, const char *compatible);
 
 #endif /* _FPGA_H_ */
-- 
2.36.1



[PATCH v12 06/13] fpga: pass compatible flags to fpga_load()

2022-07-22 Thread Oleksandr Suvorov
These flags may be used to check whether an FPGA driver is able to
load a particular FPGA bitstream image.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

(no changes since v1)

 boot/image-board.c| 4 ++--
 cmd/fpga.c| 8 
 common/spl/spl_fit.c  | 6 --
 drivers/fpga/fpga.c   | 5 +++--
 drivers/fpga/xilinx.c | 2 +-
 include/fpga.h| 2 +-
 6 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/boot/image-board.c b/boot/image-board.c
index cfc1c658e3a..9110617be26 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -703,14 +703,14 @@ int boot_get_fpga(int argc, char *const argv[], 
bootm_headers_t *images,
 img_len, BIT_FULL);
if (err)
err = fpga_load(devnum, (const void *)img_data,
-   img_len, BIT_FULL);
+   img_len, BIT_FULL, 0);
} else {
name = "partial";
err = fpga_loadbitstream(devnum, (char *)img_data,
 img_len, BIT_PARTIAL);
if (err)
err = fpga_load(devnum, (const void *)img_data,
-   img_len, BIT_PARTIAL);
+   img_len, BIT_PARTIAL, 0);
}
 
if (err)
diff --git a/cmd/fpga.c b/cmd/fpga.c
index 3fdd0b35e80..c4651dd403e 100644
--- a/cmd/fpga.c
+++ b/cmd/fpga.c
@@ -178,7 +178,7 @@ static int do_fpga_load(struct cmd_tbl *cmdtp, int flag, 
int argc,
if (ret)
return ret;
 
-   return fpga_load(dev, (void *)fpga_data, data_size, BIT_FULL);
+   return fpga_load(dev, (void *)fpga_data, data_size, BIT_FULL, 0);
 }
 
 static int do_fpga_loadb(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -209,7 +209,7 @@ static int do_fpga_loadp(struct cmd_tbl *cmdtp, int flag, 
int argc,
if (ret)
return ret;
 
-   return fpga_load(dev, (void *)fpga_data, data_size, BIT_PARTIAL);
+   return fpga_load(dev, (void *)fpga_data, data_size, BIT_PARTIAL, 0);
 }
 #endif
 
@@ -315,7 +315,7 @@ static int do_fpga_loadmk(struct cmd_tbl *cmdtp, int flag, 
int argc,
data_size = image_get_data_size(hdr);
}
return fpga_load(dev, (void *)data, data_size,
- BIT_FULL);
+ BIT_FULL, 0);
}
 #endif
 #if defined(CONFIG_FIT)
@@ -355,7 +355,7 @@ static int do_fpga_loadmk(struct cmd_tbl *cmdtp, int flag, 
int argc,
return CMD_RET_FAILURE;
}
 
-   return fpga_load(dev, fit_data, data_size, BIT_FULL);
+   return fpga_load(dev, fit_data, data_size, BIT_FULL, 0);
}
 #endif
default:
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 1bbf824684a..3c5a91916cc 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -581,6 +581,8 @@ static int spl_fit_upload_fpga(struct spl_fit_info *ctx, 
int node,
 {
const char *compatible;
int ret;
+   int devnum = 0;
+   int flags = 0;
 
debug("FPGA bitstream at: %x, size: %x\n",
  (u32)fpga_image->load_addr, fpga_image->size);
@@ -591,8 +593,8 @@ static int spl_fit_upload_fpga(struct spl_fit_info *ctx, 
int node,
else if (strcmp(compatible, "u-boot,fpga-legacy"))
printf("Ignoring compatible = %s property\n", compatible);
 
-   ret = fpga_load(0, (void *)fpga_image->load_addr, fpga_image->size,
-   BIT_FULL);
+   ret = fpga_load(devnum, (void *)fpga_image->load_addr,
+   fpga_image->size, BIT_FULL, flags);
if (ret) {
printf("%s: Cannot load the image to the FPGA\n", __func__);
return ret;
diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index efbac9f0c47..185bd547cb5 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -252,7 +252,8 @@ int fpga_loads(int devnum, const void *buf, size_t size,
 /*
  * Generic multiplexing code
  */
-int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype)
+int fpga_load(int devnum, const void *buf, size_t bsize, bitstream_type bstype,
+ int flags)
 {
int ret_val = FPGA_FAIL;   /* assume failure */
const fpga_desc *desc = fpga_validate(devnum, buf, bsize,
@@ -263,7 +264,7 @@ int fpga_load(int devnum, const void *buf, size_t bsize, 
bitstream_type bstype)
case fpga_xilinx:
 #if defined(CONFIG_FPGA_XILINX)
ret_val = xilinx_load(desc->devdesc, buf, bsize,
- bstype, 0);
+ bstype, flags);
 

[PATCH v12 05/13] fpga: xilinx: pass compatible flags to xilinx_load()

2022-07-22 Thread Oleksandr Suvorov
This flag is used to check whether a Xilinx FPGA driver is able to
load a particular FPGA bitstream image.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

(no changes since v1)

 drivers/fpga/fpga.c   | 2 +-
 drivers/fpga/xilinx.c | 2 +-
 include/xilinx.h  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index 3b0a44b2420..efbac9f0c47 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -263,7 +263,7 @@ int fpga_load(int devnum, const void *buf, size_t bsize, 
bitstream_type bstype)
case fpga_xilinx:
 #if defined(CONFIG_FPGA_XILINX)
ret_val = xilinx_load(desc->devdesc, buf, bsize,
- bstype);
+ bstype, 0);
 #else
fpga_no_sup((char *)__func__, "Xilinx devices");
 #endif
diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c
index 6bc1bc491fb..5dd721575ec 100644
--- a/drivers/fpga/xilinx.c
+++ b/drivers/fpga/xilinx.c
@@ -139,7 +139,7 @@ int fpga_loadbitstream(int devnum, char *fpgadata, size_t 
size,
 }
 
 int xilinx_load(xilinx_desc *desc, const void *buf, size_t bsize,
-   bitstream_type bstype)
+   bitstream_type bstype, int flags)
 {
if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
printf ("%s: Invalid device descriptor\n", __FUNCTION__);
diff --git a/include/xilinx.h b/include/xilinx.h
index ff5486d98a7..0bbf14d8a1d 100644
--- a/include/xilinx.h
+++ b/include/xilinx.h
@@ -68,7 +68,7 @@ struct xilinx_fpga_op {
 /* Generic Xilinx Functions
  */
 int xilinx_load(xilinx_desc *desc, const void *image, size_t size,
-   bitstream_type bstype);
+   bitstream_type bstype, int flags);
 int xilinx_dump(xilinx_desc *desc, const void *buf, size_t bsize);
 int xilinx_info(xilinx_desc *desc);
 int xilinx_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
-- 
2.36.1



[PATCH v12 04/13] fpga: zynqmp: add str2flags call

2022-07-22 Thread Oleksandr Suvorov
Add a call to convert FPGA "compatible" string to a binary flag.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

(no changes since v1)

 drivers/fpga/zynqmppl.c | 11 ++-
 include/xilinx.h|  3 +++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index 8ff12bf50a0..19d079c9d9f 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -304,10 +304,19 @@ static int zynqmp_pcap_info(xilinx_desc *desc)
return ret;
 }
 
+static int __maybe_unused zynqmp_str2flag(xilinx_desc *desc, const char *str)
+{
+   if (!strncmp(str, "u-boot,fpga-legacy", 18))
+   return FPGA_LEGACY;
+
+   return 0;
+}
+
 struct xilinx_fpga_op zynqmp_op = {
.load = zynqmp_load,
+   .info = zynqmp_pcap_info,
 #if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
.loads = zynqmp_loads,
+   .str2flag = zynqmp_str2flag,
 #endif
-   .info = zynqmp_pcap_info,
 };
diff --git a/include/xilinx.h b/include/xilinx.h
index d9e4b8da968..ff5486d98a7 100644
--- a/include/xilinx.h
+++ b/include/xilinx.h
@@ -60,6 +60,9 @@ struct xilinx_fpga_op {
 struct fpga_secure_info *fpga_sec_info);
int (*dump)(xilinx_desc *desc, const void *buf, size_t bsize);
int (*info)(xilinx_desc *desc);
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
+   int (*str2flag)(xilinx_desc *desc, const char *string);
+#endif
 };
 
 /* Generic Xilinx Functions
-- 
2.36.1



[PATCH v12 03/13] fpga: xilinx: add bitstream flags to driver desc

2022-07-22 Thread Oleksandr Suvorov
Store a set of supported bitstream types in xilinx_desc structure.
It will be used to determine whether an FPGA image is able to be
loaded with a given driver.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

(no changes since v10)

Changes in v10:
- move FPGA flags to macros;
- initialize xilinx_desc structs directly, removing *_DESC macros;
- initialize flags for mach-zynq;

 arch/arm/mach-zynq/cpu.c | 1 +
 board/xilinx/versal/board.c  | 5 -
 board/xilinx/zynqmp/zynqmp.c | 5 -
 include/versalpl.h   | 3 ---
 include/xilinx.h | 4 
 include/zynqmppl.h   | 3 +--
 6 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-zynq/cpu.c b/arch/arm/mach-zynq/cpu.c
index 69b818f24b8..ac595ee0a27 100644
--- a/arch/arm/mach-zynq/cpu.c
+++ b/arch/arm/mach-zynq/cpu.c
@@ -22,6 +22,7 @@ xilinx_desc fpga = {
.family = xilinx_zynq,
.iface = devcfg,
.operations = _op,
+   .flags = FPGA_LEGACY,
 };
 #endif
 
diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
index 81663e0cd0e..d8f39be56c8 100644
--- a/board/xilinx/versal/board.c
+++ b/board/xilinx/versal/board.c
@@ -27,7 +27,10 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 #if defined(CONFIG_FPGA_VERSALPL)
-static xilinx_desc versalpl = XILINX_VERSAL_DESC;
+static xilinx_desc versalpl = {
+   xilinx_versal, csu_dma, 1, _op, 0, _op, NULL,
+   FPGA_LEGACY
+};
 #endif
 
 int board_init(void)
diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 106c3953e1f..3faa3a00fc9 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -48,7 +48,10 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL)
-static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC;
+static xilinx_desc zynqmppl = {
+   xilinx_zynqmp, csu_dma, 1, _op, 0, _op, NULL,
+   ZYNQMP_FPGA_FLAGS
+};
 #endif
 
 int __maybe_unused psu_uboot_init(void)
diff --git a/include/versalpl.h b/include/versalpl.h
index b94c82e6e66..0cc101be2f8 100644
--- a/include/versalpl.h
+++ b/include/versalpl.h
@@ -14,7 +14,4 @@
 
 extern struct xilinx_fpga_op versal_op;
 
-#define XILINX_VERSAL_DESC \
-{ xilinx_versal, csu_dma, 1, _op, 0, _op }
-
 #endif /* _VERSALPL_H_ */
diff --git a/include/xilinx.h b/include/xilinx.h
index 362943bc717..d9e4b8da968 100644
--- a/include/xilinx.h
+++ b/include/xilinx.h
@@ -37,6 +37,9 @@ typedef enum {/* typedef 
xilinx_family */
max_xilinx_type /* insert all new types before this */
 } xilinx_family;   /* end, typedef xilinx_family */
 
+/* FPGA bitstream supported types */
+#define FPGA_LEGACYBIT(0)
+
 typedef struct {   /* typedef xilinx_desc */
xilinx_family family;   /* part type */
xilinx_iface iface; /* interface type */
@@ -45,6 +48,7 @@ typedef struct {  /* typedef xilinx_desc */
int cookie; /* implementation specific cookie */
struct xilinx_fpga_op *operations; /* operations */
char *name; /* device name in bitstream */
+   int flags;  /* compatible flags */
 } xilinx_desc; /* end, typedef xilinx_desc */
 
 struct xilinx_fpga_op {
diff --git a/include/zynqmppl.h b/include/zynqmppl.h
index 35cfe17d444..8401a850afb 100644
--- a/include/zynqmppl.h
+++ b/include/zynqmppl.h
@@ -25,7 +25,6 @@
 
 extern struct xilinx_fpga_op zynqmp_op;
 
-#define XILINX_ZYNQMP_DESC \
-{ xilinx_zynqmp, csu_dma, 1, _op, 0, _op }
+#define ZYNQMP_FPGA_FLAGS  (FPGA_LEGACY)
 
 #endif /* _ZYNQMPPL_H_ */
-- 
2.36.1



[PATCH v12 02/13] fpga: xilinx: add missed identifier names

2022-07-22 Thread Oleksandr Suvorov
Function definition arguments should also have identifier names.
Add missed ones to struct xilinx_fpga_op callbacks, unifying code.

Signed-off-by: Oleksandr Suvorov 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

(no changes since v1)

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

diff --git a/include/xilinx.h b/include/xilinx.h
index ab4537becfa..362943bc717 100644
--- a/include/xilinx.h
+++ b/include/xilinx.h
@@ -48,12 +48,14 @@ typedef struct {/* typedef xilinx_desc */
 } xilinx_desc; /* end, typedef xilinx_desc */
 
 struct xilinx_fpga_op {
-   int (*load)(xilinx_desc *, const void *, size_t, bitstream_type);
-   int (*loadfs)(xilinx_desc *, const void *, size_t, fpga_fs_info *);
+   int (*load)(xilinx_desc *desc, const void *buf, size_t bsize,
+   bitstream_type bstype);
+   int (*loadfs)(xilinx_desc *desc, const void *buf, size_t bsize,
+ fpga_fs_info *fpga_fsinfo);
int (*loads)(xilinx_desc *desc, const void *buf, size_t bsize,
 struct fpga_secure_info *fpga_sec_info);
-   int (*dump)(xilinx_desc *, const void *, size_t);
-   int (*info)(xilinx_desc *);
+   int (*dump)(xilinx_desc *desc, const void *buf, size_t bsize);
+   int (*info)(xilinx_desc *desc);
 };
 
 /* Generic Xilinx Functions
-- 
2.36.1



[PATCH v12 01/13] fpga: add option for loading FPGA secure bitstreams

2022-07-22 Thread Oleksandr Suvorov
It allows using this feature without enabling the "fpga loads"
command.

Signed-off-by: Oleksandr Suvorov 
Co-developed-by: Adrian Fiergolski 
Signed-off-by: Adrian Fiergolski 
Tested-by: Ricardo Salveti 
Tested-by: Adrian Fiergolski 
---

(no changes since v1)

 cmd/Kconfig |  3 ++-
 drivers/fpga/Kconfig| 14 ++
 drivers/fpga/fpga.c |  2 +-
 drivers/fpga/xilinx.c   |  2 +-
 drivers/fpga/zynqmppl.c |  4 ++--
 5 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index d5f842136cf..cefeca018d2 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1036,8 +1036,9 @@ config CMD_FPGA_LOADP
  a partial bitstream.
 
 config CMD_FPGA_LOAD_SECURE
-   bool "fpga loads - loads secure bitstreams (Xilinx only)"
+   bool "fpga loads - loads secure bitstreams"
depends on CMD_FPGA
+   select FPGA_LOAD_SECURE
help
  Enables the fpga loads command which is used to load secure
  (authenticated or encrypted or both) bitstreams on to FPGA.
diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig
index 76719517f54..4561ee72dd0 100644
--- a/drivers/fpga/Kconfig
+++ b/drivers/fpga/Kconfig
@@ -91,4 +91,18 @@ config FPGA_ZYNQPL
  Enable FPGA driver for loading bitstream in BIT and BIN format
  on Xilinx Zynq devices.
 
+config FPGA_LOAD_SECURE
+   bool "Enable loading secure bitstreams"
+   depends on FPGA
+   help
+ Enables the fpga loads() functions that are used to load secure
+ (authenticated or encrypted or both) bitstreams on to FPGA.
+
+config SPL_FPGA_LOAD_SECURE
+   bool "Enable loading secure bitstreams for SPL"
+   depends on SPL_FPGA
+   help
+ Enables the fpga loads() functions that are used to load secure
+ (authenticated or encrypted or both) bitstreams on to FPGA.
+
 endmenu
diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index fe3dfa12335..3b0a44b2420 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -220,7 +220,7 @@ int fpga_fsload(int devnum, const void *buf, size_t size,
 }
 #endif
 
-#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
 int fpga_loads(int devnum, const void *buf, size_t size,
   struct fpga_secure_info *fpga_sec_info)
 {
diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c
index cbebefb55fe..6bc1bc491fb 100644
--- a/drivers/fpga/xilinx.c
+++ b/drivers/fpga/xilinx.c
@@ -172,7 +172,7 @@ int xilinx_loadfs(xilinx_desc *desc, const void *buf, 
size_t bsize,
 }
 #endif
 
-#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
 int xilinx_loads(xilinx_desc *desc, const void *buf, size_t bsize,
 struct fpga_secure_info *fpga_sec_info)
 {
diff --git a/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index 6b394869dbf..8ff12bf50a0 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -245,7 +245,7 @@ static int zynqmp_load(xilinx_desc *desc, const void *buf, 
size_t bsize,
return ret;
 }
 
-#if defined(CONFIG_CMD_FPGA_LOAD_SECURE) && !defined(CONFIG_SPL_BUILD)
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
 static int zynqmp_loads(xilinx_desc *desc, const void *buf, size_t bsize,
struct fpga_secure_info *fpga_sec_info)
 {
@@ -306,7 +306,7 @@ static int zynqmp_pcap_info(xilinx_desc *desc)
 
 struct xilinx_fpga_op zynqmp_op = {
.load = zynqmp_load,
-#if defined(CONFIG_CMD_FPGA_LOAD_SECURE) && !defined(CONFIG_SPL_BUILD)
+#if CONFIG_IS_ENABLED(FPGA_LOAD_SECURE)
.loads = zynqmp_loads,
 #endif
.info = zynqmp_pcap_info,
-- 
2.36.1



[PATCH v12 00/13] fpga: zynqmp: Adding support of loading authenticated images

2022-07-22 Thread Oleksandr Suvorov


This patchset introduces support for the authenticated and encrypted
FPGA images on ZynqMP boards, besides that introducing common way to
pass the compatible property to any fpga driver.

It bases on the initial work by Jorge Ramirez-Ortiz 
https://patchwork.ozlabs.org/project/uboot/patch/20211015091506.2602-1-jo...@foundries.io/
https://patchwork.ozlabs.org/project/uboot/patch/20211005111324.19749-3-jo...@foundries.io/

Changes in v12:
- define the function only if FPGA_LOAD_SECURE enabled;
- convert "compatible" to flags only if FPGA_LOAD_SECURE enabled;
- fix a commit message
- remove obsolete debug() message
- exclude all secure-related code if FPGA_LOAD_SECURE is disabled
- reduce the size of SPL if FPGA_LOAD_SECURE disabled.

Changes in v11:
- Fix treating an incoming FPGA image with empty flags parameter as
  legacy.
- add Tested-by records.

Changes in v10:
- move FPGA flags to macros;
- initialize xilinx_desc structs directly, removing *_DESC macros;
- initialize flags for mach-zynq;
- fix mixed types of return value;
- made the message about ignoring legacy compatibe option as debug;
- fix grammar
- Support DDR images only if FPGA_LOAD_SECURE enabled.
- Support ENC images only if FPGA_LOAD_SECURE enabled.

Changes in v9:
- remove an alien commit from a patchset :)

Changes in v8:
- Michal Simek's suggestions addressed:
-- introduce the compatible flags in xilinx_desc;
-- pass a binary compatible flag instead of "compatible" property to
   an FPGA driver.
- Optimize a zynqmp_load() function.

Changes in v7:
- apply Michal Simek's suggestions
  As I applied changes on Oleksandr's patches, I indicated it by
  specifying myself as co-author in the commits logs. I am not sure
  if that is the convention of marking it.

Changes in v6:
- add support for the encrypted bitfiles.

Changes in v5:
- replace ifdef with if() where it's possible.

Changes in v4:
- change interface to xilinx_desc->operations->open() callback.
- fix a bug from previous version of the patchset in dereferencing
  of a parent fpga_desc structure.

Changes in v3:
- remove the patch which introduced CMD_SPL_FPGA_LOAD_SECURE.
- fix mixing definitions/declarations.
- replace strcmp() calls with more secure strncmp().
- document the "u-boot,zynqmp-fpga-ddrauth" compatible string.
- fix code style by check-patch recommendations.

Changes in v2:
- add function fit_fpga_load() to simplify calls of fpga_load()
  from contexts without a compatible attribute.
- move all ZynqMP-specific logic to drivers/fpga/zynqmppl.c
- prepare for passing a "compatible" FDT property to any fpga driver.

Adrian Fiergolski (1):
  fpga: zynqmp: support loading encrypted bitfiles

Oleksandr Suvorov (12):
  fpga: add option for loading FPGA secure bitstreams
  fpga: xilinx: add missed identifier names
  fpga: xilinx: add bitstream flags to driver desc
  fpga: zynqmp: add str2flags call
  fpga: xilinx: pass compatible flags to xilinx_load()
  fpga: pass compatible flags to fpga_load()
  fpga: add fpga_compatible2flag
  spl: fit: pass real compatible flags to fpga_load()
  fpga: xilinx: pass compatible flags to load() callback
  fpga: zynqmp: reduce zynqmppl_load() code
  fpga: zynqmp: add bitstream compatible checking
  fpga: zynqmp: support loading authenticated images

 arch/arm/mach-zynq/cpu.c  |  1 +
 board/xilinx/versal/board.c   |  5 +-
 board/xilinx/zynqmp/zynqmp.c  |  5 +-
 boot/Kconfig  |  4 +-
 boot/image-board.c|  4 +-
 cmd/Kconfig   |  3 +-
 cmd/fpga.c|  8 +--
 common/spl/spl_fit.c  | 17 +++--
 doc/uImage.FIT/source_file_format.txt |  7 +-
 drivers/fpga/Kconfig  | 14 
 drivers/fpga/fpga.c   | 33 -
 drivers/fpga/spartan2.c   |  2 +-
 drivers/fpga/spartan3.c   |  2 +-
 drivers/fpga/versalpl.c   |  2 +-
 drivers/fpga/virtex2.c|  2 +-
 drivers/fpga/xilinx.c |  8 +--
 drivers/fpga/zynqmppl.c   | 99 ++-
 drivers/fpga/zynqpl.c |  2 +-
 include/fpga.h|  4 +-
 include/versalpl.h|  3 -
 include/xilinx.h  | 21 --
 include/zynqmppl.h|  9 ++-
 22 files changed, 199 insertions(+), 56 deletions(-)

-- 
2.36.1



Re: [PATCH 01/19] video: Renname vbe.h to vesa.h

2022-07-22 Thread Bin Meng
Hi Simon,

On Fri, Jul 22, 2022 at 5:00 PM Simon Glass  wrote:
>
> Hi Bin,
>
> On Wed, 20 Jul 2022 at 19:25, Bin Meng  wrote:
> >
> > Hi Simon,
> >
> > On Thu, Jul 21, 2022 at 1:00 AM Simon Glass  wrote:
> > >
> > > We want to use VBE to mean Verfiied Boot for Embedded in U-Boot. Rename
> >
> > typo: Verified
> >
> > Is there a doc link to describe the Verified Boot for Embedded ? Just
> > want to make sure if this acronym is the correct one to replace
> > another existing and old VBE.
>
> Yes: 
> https://docs.google.com/document/d/e/2PACX-1vQjXLPWMIyVktaTMf8edHZYDrEvMYD_iNzIj1FgPmKF37fpglAC47Tt5cvPBC5fvTdoK-GA5Zv1wifo/pub
>
> Also this has more links:
> https://github.com/fwupd/fwupd/tree/main/plugins/vbe#documentation
>

Thanks for the links. I suggest we put these links in the commit
message and/or code for reference.

Regards,
Bin


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

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

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

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/dts/rockchip-u-boot.dtsi | 29 +
 1 file changed, 29 insertions(+)

diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
b/arch/arm/dts/rockchip-u-boot.dtsi
index fc28ce5187..4c26caa92a 100644
--- a/arch/arm/dts/rockchip-u-boot.dtsi
+++ b/arch/arm/dts/rockchip-u-boot.dtsi
@@ -41,5 +41,34 @@
offset = <((CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR - 
64) * 512)>;
};
};
+
+#ifdef CONFIG_ROCKCHIP_SPI_IMAGE
+   simple-bin-spi {
+   filename = "u-boot-rockchip-spi.bin";
+   pad-byte = <0xff>;
+
+   mkimage {
+   args = "-n", CONFIG_SYS_SOC, "-T", "rkspi";
+#ifdef CONFIG_TPL
+   multiple-data-files;
+
+   u-boot-tpl {
+   };
+#endif
+   u-boot-spl {
+   };
+   };
+
+#ifdef CONFIG_ARM64
+   blob {
+   filename = "u-boot.itb";
+#else
+   u-boot-img {
+#endif
+   /* Sync with u-boot,spl-payload-offset if present */
+   offset = ;
+   };
+   };
+#endif
 };
 #endif
-- 
2.37.1



[PATCH v2 6/7] binman: add support for skipping file concatenation for mkimage

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

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

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

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

Cc: Quentin Schulz 
Reviewed-by: Simon Glass 
Signed-off-by: Quentin Schulz 
---
 tools/binman/entries.rst  | 22 +++
 tools/binman/etype/mkimage.py | 41 +++
 2 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index ae4305c99e..60c89aec59 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -1101,6 +1101,9 @@ Entry: mkimage: Binary produced by mkimage
 
 Properties / Entry arguments:
 - datafile: Filename for -d argument
+- multiple-data-files: boolean to tell binman to pass all files as
+  datafiles to mkimage instead of creating a temporary file the result
+  of datafiles concatenation
 - args: Other arguments to pass
 
 The data passed to mkimage is collected from subnodes of the mkimage node,
@@ -1117,6 +1120,25 @@ This calls mkimage to create an imximage with 
u-boot-spl.bin as the input
 file. The output from mkimage then becomes part of the image produced by
 binman.
 
+To pass all datafiles untouched to mkimage::
+
+mkimage {
+args = "-n rk3399 -T rkspi";
+multiple-data-files;
+
+u-boot-tpl {
+};
+
+u-boot-spl {
+};
+};
+
+This calls mkimage to create a Rockchip RK3399-specific first stage
+bootloader, made of TPL+SPL. Since this first stage bootloader requires to
+align the TPL and SPL but also some weird hacks that is handled by mkimage
+directly, binman is told to not perform the concatenation of datafiles prior
+to passing the data to mkimage.
+
 To use CONFIG options in the arguments, use a string list instead, as in
 this example which also produces four arguments::
 
diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py
index 5f6def2287..52297c23ea 100644
--- a/tools/binman/etype/mkimage.py
+++ b/tools/binman/etype/mkimage.py
@@ -16,6 +16,9 @@ class Entry_mkimage(Entry):
 
 Properties / Entry arguments:
 - datafile: Filename for -d argument
+- multiple-data-files: boolean to tell binman to pass all files as
+  datafiles to mkimage instead of creating a temporary file the result
+  of datafiles concatenation
 - args: Other arguments to pass
 
 The data passed to mkimage is collected from subnodes of the mkimage node,
@@ -32,6 +35,25 @@ class Entry_mkimage(Entry):
 file. The output from mkimage then becomes part of the image produced by
 binman.
 
+   To pass all datafiles untouched to mkimage::
+
+   mkimage {
+   args = "-n rk3399 -T rkspi";
+   multiple-data-files;
+
+   u-boot-tpl {
+   };
+
+   u-boot-spl {
+   };
+   };
+
+   This calls mkimage to create a Rockchip RK3399-specific first stage
+   bootloader, made of TPL+SPL. Since this first stage bootloader requires 
to
+   align the TPL and SPL but also some weird hacks that is handled by 
mkimage
+   directly, binman is told to not perform the concatenation of datafiles 
prior
+   to passing the data to mkimage.
+
 To use CONFIG options in the arguments, use a string list instead, as in
 this example which also produces four arguments::
 
@@ -46,16 +68,27 @@ class Entry_mkimage(Entry):
 def __init__(self, section, etype, node):
 super().__init__(section, etype, node)
 self._args = fdt_util.GetArgs(self._node, 'args')
+self._multiple_data_files = fdt_util.GetBool(self._node, 
'multiple-data-files')
 self._mkimage_entries = OrderedDict()
 self.align_default = None
 self.ReadEntries()
 
 def ObtainContents(self):
 # Use a non-zero size for any fake files to keep mkimage happy
-data, input_fname, uniq = self.collect_contents_to_file(
-self._mkimage_entries.values(), 'mkimage', 1024)
-if data is None:
-return False
+fake_size = 1024
+if self._multiple_data_files:
+fnames = []
+uniq = self.GetUniqueName()
+for entry in self._mkimage_entries.values():
+if not entry.ObtainContents(fake_size=fake_size):
+return False
+fnames.append(entry.GetDefaultFilename())
+input_fname = ":".join(fnames)
+else:
+data, input_fname, uniq = self.collect_contents_to_file(

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

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

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

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 arch/arm/dts/rk3288-u-boot.dtsi | 2 +-
 arch/arm/dts/rk3399-u-boot.dtsi | 2 +-
 arch/arm/mach-rockchip/Kconfig  | 6 ++
 3 files changed, 4 insertions(+), 6 deletions(-)

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



[PATCH v2 4/7] rockchip: simplify binman image dependencies addition to INPUTS

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

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

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 Makefile | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

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



[PATCH v2 3/7] rockchip: remove unneeded CONFIG_SPL_PAD_TO

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

Since binman takes care of setting the appropriate offset for the SPL
payload, there's no need to use this variable anymore.

Moreover, it is technically incorrect since the padding is different
depending on whether the first stage bootloader is for a SPI flash or
MMC storage medium.

Finally, this allows to use the CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
config option without redefining CONFIG_SPL_PAD_TO in other board header
files.

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

v2:
 - rebased on top of master, CONFIG_SPL_PAD_TO is now a Kconfig option
 so let's remove it from defconfigs,
 - the remove was done with: sed -i '/CONFIG_SPL_PAD_TO=0x7f8000/d'
 configs/*, since 0x7f8000 was the original default value for Rockchip
 boards and it seems none were overriding it before commit ca8a329a1b7f
 ("Convert CONFIG_SPL_PAD_TO et al to Kconfig"),

 arch/arm/dts/rockchip-u-boot.dtsi | 2 +-
 configs/chromebit_mickey_defconfig| 1 -
 configs/chromebook_bob_defconfig  | 1 -
 configs/chromebook_jerry_defconfig| 1 -
 configs/chromebook_kevin_defconfig| 1 -
 configs/chromebook_minnie_defconfig   | 1 -
 configs/chromebook_speedy_defconfig   | 1 -
 configs/evb-px30_defconfig| 1 -
 configs/evb-px5_defconfig | 1 -
 configs/evb-rk3036_defconfig  | 1 -
 configs/evb-rk3229_defconfig  | 1 -
 configs/evb-rk3288_defconfig  | 1 -
 configs/evb-rk3308_defconfig  | 1 -
 configs/evb-rk3328_defconfig  | 1 -
 configs/evb-rk3399_defconfig  | 1 -
 configs/evb-rk3568_defconfig  | 1 -
 configs/ficus-rk3399_defconfig| 1 -
 configs/firefly-px30_defconfig| 1 -
 configs/firefly-rk3288_defconfig  | 1 -
 configs/firefly-rk3399_defconfig  | 1 -
 configs/khadas-edge-captain-rk3399_defconfig  | 1 -
 configs/khadas-edge-rk3399_defconfig  | 1 -
 configs/khadas-edge-v-rk3399_defconfig| 1 -
 configs/kylin-rk3036_defconfig| 1 -
 configs/leez-rk3399_defconfig | 1 -
 configs/lion-rk3368_defconfig | 1 -
 configs/miqi-rk3288_defconfig | 1 -
 configs/mk808_defconfig   | 1 -
 configs/nanopc-t4-rk3399_defconfig| 1 -
 configs/nanopi-m4-2gb-rk3399_defconfig| 1 -
 configs/nanopi-m4-rk3399_defconfig| 1 -
 configs/nanopi-m4b-rk3399_defconfig   | 1 -
 configs/nanopi-neo4-rk3399_defconfig  | 1 -
 configs/nanopi-r2s-rk3328_defconfig   | 1 -
 configs/nanopi-r4s-rk3399_defconfig   | 1 -
 configs/odroid-go2_defconfig  | 1 -
 configs/orangepi-rk3399_defconfig | 1 -
 configs/phycore-rk3288_defconfig  | 1 -
 configs/pinebook-pro-rk3399_defconfig | 1 -
 configs/popmetal-rk3288_defconfig | 1 -
 configs/puma-rk3399_defconfig | 1 -
 configs/px30-core-ctouch2-of10-px30_defconfig | 1 -
 configs/px30-core-ctouch2-px30_defconfig  | 1 -
 configs/px30-core-edimm2.2-px30_defconfig | 1 -
 configs/roc-cc-rk3308_defconfig   | 1 -
 configs/roc-cc-rk3328_defconfig   | 1 -
 configs/roc-pc-mezzanine-rk3399_defconfig | 1 -
 configs/roc-pc-rk3399_defconfig   | 1 -
 configs/rock-pi-4-rk3399_defconfig| 1 -
 configs/rock-pi-4c-rk3399_defconfig   | 1 -
 configs/rock-pi-e-rk3328_defconfig| 1 -
 configs/rock-pi-n10-rk3399pro_defconfig   | 1 -
 configs/rock-pi-n8-rk3288_defconfig   | 1 -
 configs/rock2_defconfig   | 1 -
 configs/rock64-rk3328_defconfig   | 1 -
 configs/rock960-rk3399_defconfig  | 1 -
 configs/rock_defconfig| 1 -
 configs/rockpro64-rk3399_defconfig| 1 -
 configs/tinker-rk3288_defconfig   | 1 -
 configs/tinker-s-rk3288_defconfig | 1 -
 configs/vyasa-rk3288_defconfig| 1 -
 include/configs/rockchip-common.h | 2 --
 62 files changed, 1 insertion(+), 63 deletions(-)

diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
b/arch/arm/dts/rockchip-u-boot.dtsi
index aef6c379e2..fc28ce5187 100644
--- a/arch/arm/dts/rockchip-u-boot.dtsi
+++ b/arch/arm/dts/rockchip-u-boot.dtsi
@@ -38,7 +38,7 @@
 #else
u-boot-img {
 #endif
-   offset = ;
+   offset = <((CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR - 
64) * 512)>;
};
};
 };
diff --git a/configs/chromebit_mickey_defconfig 
b/configs/chromebit_mickey_defconfig
index dad3b36b99..8a18937564 100644
--- a/configs/chromebit_mickey_defconfig
+++ b/configs/chromebit_mickey_defconfig
@@ -25,7 +25,6 @@ CONFIG_DEFAULT_FDT_FILE="rk3288-veyron-mickey.dtb"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 

[PATCH v2 2/7] rockchip: generate u-boot-rockchip.bin with binman for ARM64 boards

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

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

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 Makefile  | 28 ++--
 arch/arm/Kconfig  |  2 +-
 arch/arm/dts/rockchip-u-boot.dtsi |  5 +
 3 files changed, 8 insertions(+), 27 deletions(-)

diff --git a/Makefile b/Makefile
index f780bfe211..7761a10b11 100644
--- a/Makefile
+++ b/Makefile
@@ -999,8 +999,7 @@ ifeq ($(CONFIG_ARCH_ROCKCHIP),y)
 # On ARM64 this target is produced by binman so we don't need this dep
 ifeq ($(CONFIG_ARM64),y)
 ifeq ($(CONFIG_SPL),y)
-# TODO: Get binman to generate this too
-INPUTS-y += u-boot-rockchip.bin
+INPUTS-y += u-boot.itb
 endif
 else
 ifeq ($(CONFIG_SPL),y)
@@ -1493,29 +1492,6 @@ OBJCOPYFLAGS_u-boot-with-spl.bin = -I binary -O binary \
 u-boot-with-spl.bin: $(SPL_IMAGE) $(SPL_PAYLOAD) FORCE
$(call if_changed,pad_cat)
 
-ifeq ($(CONFIG_ARCH_ROCKCHIP),y)
-
-# TPL + SPL
-ifeq ($(CONFIG_SPL)$(CONFIG_TPL),yy)
-MKIMAGEFLAGS_u-boot-tpl-rockchip.bin = -n $(CONFIG_SYS_SOC) -T rksd
-tpl/u-boot-tpl-rockchip.bin: tpl/u-boot-tpl.bin FORCE
-   $(call if_changed,mkimage)
-idbloader.img: tpl/u-boot-tpl-rockchip.bin spl/u-boot-spl.bin FORCE
-   $(call if_changed,cat)
-else
-MKIMAGEFLAGS_idbloader.img = -n $(CONFIG_SYS_SOC) -T rksd
-idbloader.img: spl/u-boot-spl.bin FORCE
-   $(call if_changed,mkimage)
-endif
-
-ifeq ($(CONFIG_ARM64),y)
-OBJCOPYFLAGS_u-boot-rockchip.bin = -I binary -O binary \
-   --pad-to=$(CONFIG_SPL_PAD_TO) --gap-fill=0xff
-u-boot-rockchip.bin: idbloader.img u-boot.itb FORCE
-   $(call if_changed,pad_cat)
-endif # CONFIG_ARM64
-
-endif # CONFIG_ARCH_ROCKCHIP
 
 ifeq ($(CONFIG_ARCH_LPC32XX)$(CONFIG_SPL),yy)
 MKIMAGEFLAGS_lpc32xx-spl.img = -T lpc32xximage -a $(CONFIG_SPL_TEXT_BASE)
@@ -2218,7 +2194,7 @@ CLEAN_FILES += include/bmp_logo.h include/bmp_logo_data.h 
\
   tools/version.h u-boot* MLO* SPL System.map fit-dtb.blob* \
   u-boot-ivt.img.log u-boot-dtb.imx.log SPL.log u-boot.imx.log \
   lpc32xx-* bl31.c bl31.elf bl31_*.bin image.map tispl.bin* \
-  idbloader.img flash.bin flash.log defconfig keep-syms-lto.c \
+  flash.bin flash.log defconfig keep-syms-lto.c \
   mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
   itb.fit.fit itb.fit.itb itb.map spl.map
 
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index d4fc83318a..64e90575d1 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1960,7 +1960,7 @@ config ARCH_STM32MP
 config ARCH_ROCKCHIP
bool "Support Rockchip SoCs"
select BLK
-   select BINMAN if SPL_OPTEE || (SPL && !ARM64)
+   select BINMAN if SPL_OPTEE || SPL
select DM
select DM_GPIO
select DM_I2C
diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
b/arch/arm/dts/rockchip-u-boot.dtsi
index 0362c97e0b..aef6c379e2 100644
--- a/arch/arm/dts/rockchip-u-boot.dtsi
+++ b/arch/arm/dts/rockchip-u-boot.dtsi
@@ -32,7 +32,12 @@
};
 #endif
 
+#ifdef CONFIG_ARM64
+   blob {
+   filename = "u-boot.itb";
+#else
u-boot-img {
+#endif
offset = ;
};
};
-- 
2.37.1



[PATCH v2 1/7] rockchip: generate idbloader.img content for u-boot-rockchip.bin with binman for ARM

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

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

So let's do that for Rockchip ARM platforms.

Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---
 Makefile  |  2 +-
 arch/arm/dts/rockchip-u-boot.dtsi | 15 +--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index d76ec69b52..f780bfe211 100644
--- a/Makefile
+++ b/Makefile
@@ -1005,7 +1005,7 @@ endif
 else
 ifeq ($(CONFIG_SPL),y)
 # Generate these inputs for binman which will create the output files
-INPUTS-y += idbloader.img u-boot.img
+INPUTS-y += u-boot.img
 endif
 endif
 endif
diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
b/arch/arm/dts/rockchip-u-boot.dtsi
index eae3ee715d..0362c97e0b 100644
--- a/arch/arm/dts/rockchip-u-boot.dtsi
+++ b/arch/arm/dts/rockchip-u-boot.dtsi
@@ -17,9 +17,20 @@
filename = "u-boot-rockchip.bin";
pad-byte = <0xff>;
 
-   blob {
-   filename = "idbloader.img";
+   mkimage {
+   args = "-n", CONFIG_SYS_SOC, "-T", "rksd";
+#ifndef CONFIG_TPL
+   u-boot-spl {
+   };
};
+#else
+   u-boot-tpl {
+   };
+   };
+
+   u-boot-spl {
+   };
+#endif
 
u-boot-img {
offset = ;
-- 
2.37.1



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

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

This migrates the generation of u-boot-rockchip.bin from Makefile to binman
completely. There is therefore no idbloader.img anymore as it is created on
the fly by binman.

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

This has been tested on Puma RK3399 with patches soon to be sent to the
ML.

This also helped removing the hardcoded value for the u-boot.itb offset
in u-boot-rockchip.bin which prevented Puma SoM to be migrated to it.

Cheers,
Quentin

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

Quentin Schulz (7):
  rockchip: generate idbloader.img content for u-boot-rockchip.bin with
binman for ARM
  rockchip: generate u-boot-rockchip.bin with binman for ARM64 boards
  rockchip: remove unneeded CONFIG_SPL_PAD_TO
  rockchip: simplify binman image dependencies addition to INPUTS
  rockchip: allow to build SPI images even without HAS_ROM option
  binman: add support for skipping file concatenation for mkimage
  rockchip: add u-boot-rockchip-spi.bin image for booting from SPI-NOR
flash

 Makefile  | 39 ++-
 arch/arm/Kconfig  |  2 +-
 arch/arm/dts/rk3288-u-boot.dtsi   |  2 +-
 arch/arm/dts/rk3399-u-boot.dtsi   |  2 +-
 arch/arm/dts/rockchip-u-boot.dtsi | 49 ++-
 arch/arm/mach-rockchip/Kconfig|  6 +--
 configs/chromebit_mickey_defconfig|  1 -
 configs/chromebook_bob_defconfig  |  1 -
 configs/chromebook_jerry_defconfig|  1 -
 configs/chromebook_kevin_defconfig|  1 -
 configs/chromebook_minnie_defconfig   |  1 -
 configs/chromebook_speedy_defconfig   |  1 -
 configs/evb-px30_defconfig|  1 -
 configs/evb-px5_defconfig |  1 -
 configs/evb-rk3036_defconfig  |  1 -
 configs/evb-rk3229_defconfig  |  1 -
 configs/evb-rk3288_defconfig  |  1 -
 configs/evb-rk3308_defconfig  |  1 -
 configs/evb-rk3328_defconfig  |  1 -
 configs/evb-rk3399_defconfig  |  1 -
 configs/evb-rk3568_defconfig  |  1 -
 configs/ficus-rk3399_defconfig|  1 -
 configs/firefly-px30_defconfig|  1 -
 configs/firefly-rk3288_defconfig  |  1 -
 configs/firefly-rk3399_defconfig  |  1 -
 configs/khadas-edge-captain-rk3399_defconfig  |  1 -
 configs/khadas-edge-rk3399_defconfig  |  1 -
 configs/khadas-edge-v-rk3399_defconfig|  1 -
 configs/kylin-rk3036_defconfig|  1 -
 configs/leez-rk3399_defconfig |  1 -
 configs/lion-rk3368_defconfig |  1 -
 configs/miqi-rk3288_defconfig |  1 -
 configs/mk808_defconfig   |  1 -
 configs/nanopc-t4-rk3399_defconfig|  1 -
 configs/nanopi-m4-2gb-rk3399_defconfig|  1 -
 configs/nanopi-m4-rk3399_defconfig|  1 -
 configs/nanopi-m4b-rk3399_defconfig   |  1 -
 configs/nanopi-neo4-rk3399_defconfig  |  1 -
 configs/nanopi-r2s-rk3328_defconfig   |  1 -
 configs/nanopi-r4s-rk3399_defconfig   |  1 -
 configs/odroid-go2_defconfig  |  1 -
 configs/orangepi-rk3399_defconfig |  1 -
 configs/phycore-rk3288_defconfig  |  1 -
 configs/pinebook-pro-rk3399_defconfig |  1 -
 configs/popmetal-rk3288_defconfig |  1 -
 configs/puma-rk3399_defconfig |  1 -
 configs/px30-core-ctouch2-of10-px30_defconfig |  1 -
 configs/px30-core-ctouch2-px30_defconfig  |  1 -
 configs/px30-core-edimm2.2-px30_defconfig |  1 -
 configs/roc-cc-rk3308_defconfig   |  1 -
 configs/roc-cc-rk3328_defconfig   |  1 -
 configs/roc-pc-mezzanine-rk3399_defconfig |  1 -
 configs/roc-pc-rk3399_defconfig   |  1 -
 configs/rock-pi-4-rk3399_defconfig|  1 -
 configs/rock-pi-4c-rk3399_defconfig   |  1 -
 configs/rock-pi-e-rk3328_defconfig|  1 -
 configs/rock-pi-n10-rk3399pro_defconfig   |  1 -
 configs/rock-pi-n8-rk3288_defconfig   |  1 -
 configs/rock2_defconfig   |  1 -
 configs/rock64-rk3328_defconfig   |  1 -
 configs/rock960-rk3399_defconfig  |  1 -
 configs/rock_defconfig|  1 -
 configs/rockpro64-rk3399_defconfig|  1 -
 configs/tinker-rk3288_defconfig   |  1 -
 configs/tinker-s-rk3288_defconfig |  1 

[PATCH v2 2/2] rockchip: rk3399: remove duplicate call to regulators_enable_boot_on

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

An earlier commit makes the common SPL code call
regulators_enable_boot_on and regulators_enable_boot_off before
iterating over possible boot media for U-Boot proper. There is therefore
no need to do this in the rk3399-specific code, so let's remove it.

Cc: Quentin Schulz 
Tested-by: Xavier Drudis Ferran 
Signed-off-by: Quentin Schulz 
---

This patch depends on:
 - https://lore.kernel.org/u-boot/20220722093014.3850165-1-foss+ub...@0leil.net/
 - https://lore.kernel.org/u-boot/20220722093014.3850165-2-foss+ub...@0leil.net/

v2:
 - added Tested-by,

 arch/arm/mach-rockchip/rk3399/rk3399.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c 
b/arch/arm/mach-rockchip/rk3399/rk3399.c
index fc1acaf4bd..94d0fa58c4 100644
--- a/arch/arm/mach-rockchip/rk3399/rk3399.c
+++ b/arch/arm/mach-rockchip/rk3399/rk3399.c
@@ -280,15 +280,5 @@ void spl_board_init(void)
if (cru->glb_rst_st != 0)
rk3399_force_power_on_reset();
}
-
-   if (IS_ENABLED(CONFIG_SPL_DM_REGULATOR)) {
-   /*
-* Turning the eMMC and SPI back on (if disabled via the Qseven
-* BIOS_ENABLE) signal is done through a always-on regulator).
-*/
-   if (regulators_enable_boot_on(false))
-   debug("%s: Cannot enable boot on regulator\n",
- __func__);
-   }
 }
 #endif
-- 
2.37.1



[PATCH v2 1/2] spl: enable regulator-boot-on and disable regulator-force-boot-off

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

This makes sure regulators that need to be turned on or off at boot are
turned on or off in the SPL.

This may be required for the SPL to do some operations, such as finding
possible loading media for U-Boot proper.

Cc: Quentin Schulz 
Tested-by: Xavier Drudis Ferran 
Signed-off-by: Quentin Schulz 
---

v2:
 - added Tested-by,
 - fixed build for boards with SPL_DM_REGULATOR disabled by always
 included power/regulator.h and defining a dummy implementation for
 regulators_enable_boot_off,

 common/spl/spl.c  | 10 ++
 include/power/regulator.h |  5 +
 2 files changed, 15 insertions(+)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 29e0898f03..6ab997279d 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 DECLARE_BINMAN_MAGIC_SYM;
@@ -773,6 +774,15 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
if (CONFIG_IS_ENABLED(GPIO_HOG))
gpio_hog_probe_all();
 
+   if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
+   if (regulators_enable_boot_on(false))
+   debug("%s: Cannot enable boot on regulator\n",
+ __func__);
+   if (regulators_enable_boot_off(false))
+   debug("%s: Cannot enable boot off regulator\n",
+ __func__);
+   }
+
 #if CONFIG_IS_ENABLED(BOARD_INIT)
spl_board_init();
 #endif
diff --git a/include/power/regulator.h b/include/power/regulator.h
index ff1bfc2435..4bce61dd9f 100644
--- a/include/power/regulator.h
+++ b/include/power/regulator.h
@@ -631,6 +631,11 @@ static inline int regulators_enable_boot_on(bool verbose)
return -ENOSYS;
 }
 
+static inline int regulators_enable_boot_off(bool verbose)
+{
+   return -ENOSYS;
+}
+
 static inline int regulator_autoset(struct udevice *dev)
 {
return -ENOSYS;
-- 
2.37.1



[PATCH v3 2/2] rockchip: rk3399: fix incorrect ifdef check on SPL_GPIO

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

The check to perform is on CONFIG_SPL_GPIO and not SPL_GPIO.
Because this was never compiled in, it missed an include of cru.h that
was not detected before. Let's include it too.

Also switch to IS_ENABLED in-code check as it is the preferred
inclusion/exclusion mechanism.

Fixes: 07586ee4322a ("rockchip: rk3399: Support common spl_board_init")
Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---

v3:
 - always include header to fix compilation for boards with
 CONFIG_SPL_GPIO disabled,
 - always define rk3399_force_power_on_reset function by using an
 in-code IS_ENABLED check instead of an ifdef to fix compilation for
 boards with CONFIG_SPL_GPIO disabled,

v2:
 - use IS_ENABLED checks,

 arch/arm/mach-rockchip/rk3399/rk3399.c | 50 ++
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c 
b/arch/arm/mach-rockchip/rk3399/rk3399.c
index 8205511c25..fc1acaf4bd 100644
--- a/arch/arm/mach-rockchip/rk3399/rk3399.c
+++ b/arch/arm/mach-rockchip/rk3399/rk3399.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -221,12 +222,17 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
   "u-boot,spl-boot-device", boot_ofpath);
 }
 
-#if defined(SPL_GPIO)
 static void rk3399_force_power_on_reset(void)
 {
ofnode node;
struct gpio_desc sysreset_gpio;
 
+   if (!IS_ENABLED(CONFIG_SPL_GPIO)) {
+   debug("%s: trying to force a power-on reset but no GPIO "
+ "support in SPL!\n", __func__);
+   return;
+   }
+
debug("%s: trying to force a power-on reset\n", __func__);
 
node = ofnode_path("/config");
@@ -243,7 +249,6 @@ static void rk3399_force_power_on_reset(void)
 
dm_gpio_set_value(_gpio, 1);
 }
-#endif
 
 void __weak led_setup(void)
 {
@@ -253,27 +258,28 @@ void spl_board_init(void)
 {
led_setup();
 
-#if defined(SPL_GPIO)
-   struct rockchip_cru *cru = rockchip_get_cru();
+   if (IS_ENABLED(CONFIG_SPL_GPIO)) {
+   struct rockchip_cru *cru = rockchip_get_cru();
 
-   /*
-* The RK3399 resets only 'almost all logic' (see also in the TRM
-* "3.9.4 Global software reset"), when issuing a software reset.
-* This may cause issues during boot-up for some configurations of
-* the application software stack.
-*
-* To work around this, we test whether the last reset reason was
-* a power-on reset and (if not) issue an overtemp-reset to reset
-* the entire module.
-*
-* While this was previously fixed by modifying the various places
-* that could generate a software reset (e.g. U-Boot's sysreset
-* driver, the ATF or Linux), we now have it here to ensure that
-* we no longer have to track this through the various components.
-*/
-   if (cru->glb_rst_st != 0)
-   rk3399_force_power_on_reset();
-#endif
+   /*
+* The RK3399 resets only 'almost all logic' (see also in the
+* TRM "3.9.4 Global software reset"), when issuing a software
+* reset. This may cause issues during boot-up for some
+* configurations of the application software stack.
+*
+* To work around this, we test whether the last reset reason
+* was a power-on reset and (if not) issue an overtemp-reset to
+* reset the entire module.
+*
+* While this was previously fixed by modifying the various
+* places that could generate a software reset (e.g. U-Boot's
+* sysreset driver, the ATF or Linux), we now have it here to
+* ensure that we no longer have to track this through the
+* various components.
+*/
+   if (cru->glb_rst_st != 0)
+   rk3399_force_power_on_reset();
+   }
 
if (IS_ENABLED(CONFIG_SPL_DM_REGULATOR)) {
/*
-- 
2.37.1



[PATCH v3 1/2] rockchip: rk3399: fix incorrect ifdef check on SPL_DM_REGULATOR

2022-07-22 Thread Quentin Schulz
From: Quentin Schulz 

The check to perform is on CONFIG_SPL_DM_REGULATOR and not
SPL_DM_REGULATOR. Also switch to in-code check instead of ifdefs.

Fixes: 07586ee4322a ("rockchip: rk3399: Support common spl_board_init")
Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 
---

v2:
 - use IS_ENABLED checks,

 arch/arm/mach-rockchip/rk3399/rk3399.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/arm/mach-rockchip/rk3399/rk3399.c 
b/arch/arm/mach-rockchip/rk3399/rk3399.c
index 01a05599cd..8205511c25 100644
--- a/arch/arm/mach-rockchip/rk3399/rk3399.c
+++ b/arch/arm/mach-rockchip/rk3399/rk3399.c
@@ -275,13 +275,14 @@ void spl_board_init(void)
rk3399_force_power_on_reset();
 #endif
 
-#if defined(SPL_DM_REGULATOR)
-   /*
-* Turning the eMMC and SPI back on (if disabled via the Qseven
-* BIOS_ENABLE) signal is done through a always-on regulator).
-*/
-   if (regulators_enable_boot_on(false))
-   debug("%s: Cannot enable boot on regulator\n", __func__);
-#endif
+   if (IS_ENABLED(CONFIG_SPL_DM_REGULATOR)) {
+   /*
+* Turning the eMMC and SPI back on (if disabled via the Qseven
+* BIOS_ENABLE) signal is done through a always-on regulator).
+*/
+   if (regulators_enable_boot_on(false))
+   debug("%s: Cannot enable boot on regulator\n",
+ __func__);
+   }
 }
 #endif
-- 
2.37.1



Re: [PATCH v7 3/7] tpm: Add the RNG child device

2022-07-22 Thread Ilias Apalodimas
Hi Simon,

On Fri, 22 Jul 2022 at 12:00, Simon Glass  wrote:
>
> Hi Sughosh,
>
> On Wed, 20 Jul 2022 at 06:30, Sughosh Ganu  wrote:
> >
> > The TPM device comes with the random number generator(RNG)
> > functionality which is built into the TPM device. Add logic to add the
> > RNG child device in the TPM uclass post probe callback.
> >
> > The RNG device can then be used to pass a set of random bytes to the
> > linux kernel, need for address space randomisation through the
> > EFI_RNG_PROTOCOL interface.
>
> Ilias has asked me to review this patch again.
>
> I don't want my review tag on it since it is not correct, so far as
> driver model / device tree go. But I have no objection to it going in
> since my understanding is we can disable TPM_RNG later as needed.

Yes you can

>
> I prefer to have some acknowledgement of the previous discussion, e.g.:

Sure

>
>No compatible string is provided because this is not available in
> the binding defined by Linux. If multiple rand devices are in the
> system, then some method of selecting them (other than device tree)
> will need to be used, or a binding will need to be added.
>
> since I cannot imagine people remembering to look up the previous
> version in patchwork.

Comment in the code or commit message?  I'd prefer adding it as a comment

>
> But if you don't want that, then that's fine.

No I am fine that makes sense.  What I was looking for was basically
your acknowledgement that we are going to pick this up.

Shall I carry it on the TPM tree?

Thanks
/Ilias
>
> >
> > Signed-off-by: Sughosh Ganu 
> > ---
> > Changes since V6: None
> >
> >  drivers/tpm/tpm-uclass.c | 37 +
> >  1 file changed, 33 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
> > index f67fe1019b..e1f1ef01e1 100644
> > --- a/drivers/tpm/tpm-uclass.c
> > +++ b/drivers/tpm/tpm-uclass.c
> > @@ -11,10 +11,15 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include "tpm_internal.h"
> >
> > +#include 
>
> BTW this should be above the previous header.
>
> > +
> > +#define TPM_RNG_DRV_NAME   "tpm-rng"
> > +
> >  int tpm_open(struct udevice *dev)
> >  {
> > struct tpm_ops *ops = tpm_get_ops(dev);
> > @@ -136,12 +141,36 @@ int tpm_xfer(struct udevice *dev, const uint8_t 
> > *sendbuf, size_t send_size,
> > return 0;
> >  }
> >
> > +static int tpm_uclass_post_probe(struct udevice *dev)
> > +{
> > +   int ret;
> > +   const char *drv = TPM_RNG_DRV_NAME;
> > +   struct udevice *child;
> > +
> > +   if (CONFIG_IS_ENABLED(TPM_RNG)) {
> > +   ret = device_find_first_child_by_uclass(dev, UCLASS_RNG,
> > +   );
> > +
> > +   if (ret != -ENODEV) {
> > +   log_debug("RNG child already added to the TPM 
> > device\n");
> > +   return ret;
> > +   }
> > +
> > +   ret = device_bind_driver(dev, drv, "tpm-rng0", );
>
> If this does get re-issued, I think this could just use
> TPM_RNG_DRV_NAME directory.
>
> > +   if (ret)
> > +   return log_msg_ret("bind", ret);
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> >  UCLASS_DRIVER(tpm) = {
> > -   .id = UCLASS_TPM,
> > -   .name   = "tpm",
> > -   .flags  = DM_UC_FLAG_SEQ_ALIAS,
> > +   .id = UCLASS_TPM,
> > +   .name   = "tpm",
> > +   .flags  = DM_UC_FLAG_SEQ_ALIAS,
> >  #if CONFIG_IS_ENABLED(OF_REAL)
> > -   .post_bind  = dm_scan_fdt_dev,
> > +   .post_bind  = dm_scan_fdt_dev,
> >  #endif
> > +   .post_probe = tpm_uclass_post_probe,
> > .per_device_auto= sizeof(struct tpm_chip_priv),
> >  };
> > --
> > 2.34.1
> >
>
> Regards,
> Simon


Re: [PATCH] tools: mkimage: don't use deprecated openssl funcs

2022-07-22 Thread Simon Glass
Hi Michal,

On Thu, 21 Jul 2022 at 11:14, Michal Vasilek  wrote:
>
> RSA_get0_* functions are not available in LibreSSL and deprecated in
> OpenSSL. This fixes build with LibreSSL and removes deprecation warnings
> with OpenSSL 3
>
> Signed-off-by: Michal Vasilek 
> ---
>  tools/sunxi_toc0.c | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)

Reviewed-by: Simon Glass 

It looks like this should be backwards compatible to older versions, also?

Regards,
Simon


Re: [PATCH 01/19] video: Renname vbe.h to vesa.h

2022-07-22 Thread Simon Glass
Hi Bin,

On Wed, 20 Jul 2022 at 19:25, Bin Meng  wrote:
>
> Hi Simon,
>
> On Thu, Jul 21, 2022 at 1:00 AM Simon Glass  wrote:
> >
> > We want to use VBE to mean Verfiied Boot for Embedded in U-Boot. Rename
>
> typo: Verified
>
> Is there a doc link to describe the Verified Boot for Embedded ? Just
> want to make sure if this acronym is the correct one to replace
> another existing and old VBE.

Yes: 
https://docs.google.com/document/d/e/2PACX-1vQjXLPWMIyVktaTMf8edHZYDrEvMYD_iNzIj1FgPmKF37fpglAC47Tt5cvPBC5fvTdoK-GA5Zv1wifo/pub

Also this has more links:
https://github.com/fwupd/fwupd/tree/main/plugins/vbe#documentation

>
> > the existing VBE (Vesa BIOS extensions) to allow this.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >

Regards,
Simon


Re: [bug] uboot 2022.07 hangs on rpi 2 with attached usb storage

2022-07-22 Thread Simon Glass
Hi Jan,

On Mon, 18 Jul 2022 at 11:48, Jan Palus  wrote:
>
> u-boot 2022.07 boots fine without any USB devices attached to
> RaspberryPi 2 however it hangs early on if external USB drive is
> connected, right after:
>
>Request Sense returned 02 04 01
>
> git bisect indicates first commit to cause regression is:
>
>   8c9812a5d557c4eacf164147d7380b3af1b222ec is the first bad commit
>   commit 8c9812a5d557c4eacf164147d7380b3af1b222ec
>   Author: AKASHI Takahiro 
>   Date:   Tue Mar 8 20:36:40 2022 +0900
>
>   usb: storage: call device_probe() after scanning
>
>   Every time a usb bus/port is scanned and a new device is detected,
>   we want to call device_probe() as it will give us a chance to run
>   additional post-processings for some purposes.
>
>   In particular, support for creating partitions on a device will be 
> added.
>
>   Signed-off-by: AKASHI Takahiro 
>   Reviewed-by: Simon Glass 
>
> Reverting this commit fixes the issue.
>
> Note that USB drive is TOSHIBA MQ04UBD200 and it's not used for booting.
> Also note that without this change 0 storage devices are detected even
> when drive is attached.

I am not sure what is going on here. Can you provide the full console
trace of the boot? Any idea where it is hanging?

Regards,
Simon


Re: Reading GPIOs with DM_GPIO before device tree is loaded

2022-07-22 Thread Simon Glass
Hi Hugo,

On Thu, 21 Jul 2022 at 11:14, Hugo Villeneuve  wrote:
>
> On Wed, 20 Jul 2022 09:01:01 -0600
> Simon Glass  wrote:
>
> > Hi Hugo,
> >
> > On Wed, 20 Jul 2022 at 04:54, Hugo Villeneuve  wrote:
> > >
> > > Hi,
> > > in board_early_init_f(), i call a custom function get_som_revision() to 
> > > read some GPIOs that are used to determine the SOM revision. This 
> > > function basically sets the iomux, and then uses 
> > > gpio_request/gpio_direction_input/gpio_get_value functions to read the 
> > > GPIOs. Then, this SOM revision information is used in  
> > > board_fit_config_name_match() to decide which device tree to load.
> > >
> > > This works perfectly fine without CONFIG_DM_GPIO. However, if I enable 
> > > CONFIG_DM_GPIO, it doesn't work anymore. There is an error when calling 
> > > gpio_request().
> > >
> > > What is the correct way to read GPIOs BEFORE any device tree is loaded?
> > >
> > > My board uses an MX6Q SOM.
> > >
> > > Here is part of the code I am using:
> > >
> > > 
> > > static iomux_v3_cfg_t const boardcfg_pads[] = {
> > > MX6_PAD_DISP0_DAT15__GPIO5_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
> > > MX6_PAD_DISP0_DAT8__GPIO4_IO29  | MUX_PAD_CTRL(NO_PAD_CTRL),
> > > MX6_PAD_DISP0_DAT0__GPIO4_IO21  | MUX_PAD_CTRL(NO_PAD_CTRL),
> > > MX6_PAD_ENET_RXD0__GPIO1_IO27   | MUX_PAD_CTRL(NO_PAD_CTRL),
> > > MX6_PAD_ENET_RXD1__GPIO1_IO26   | MUX_PAD_CTRL(NO_PAD_CTRL),
> > > };
> > >
> > > static int som_revision = -1;
> > >
> > > static const int boardcfg_gpio[] = {
> > > IMX_GPIO_NR(5, 9),
> > > IMX_GPIO_NR(4, 29),
> > > IMX_GPIO_NR(4, 21),
> > > IMX_GPIO_NR(1, 27),
> > > IMX_GPIO_NR(1, 26),
> > > };
> > >
> > > static void get_som_revision(void)
> > > {
> > > int i;
> > > int rc;
> > >
> > > som_revision = 0;
> > >
> > > SETUP_IOMUX_PADS(boardcfg_pads);
> > >
> > > for (i = 0; i < ARRAY_SIZE(boardcfg_gpio); ++i) {
> > > int v;
> > >
> > > rc = gpio_request(boardcfg_gpio[i], "som-revision-gpio");
> > > if (rc) {
> > > printf("%s(): gpio request %d failed\n", 
> > > __func__, i);
> > > som_revision = -1;
> > > return;
> > > }
> > >
> > > gpio_direction_input(boardcfg_gpio[i]);
> > > v = gpio_get_value(boardcfg_gpio[i]);
> > >
> > > if ((v == 0) || (v == 1))
> > > som_revision |= v << i;
> > > else {
> > > som_revision = -1;
> > > return;
> > > }
> > > }
> > > }
> > >
> > > int board_early_init_f(void)
> > > {
> > > setup_iomux_uart();
> > > get_som_revision();
> > >
> > > return 0;
> > > }
> > >
> > > 
> >
> > Well driver model needs the device tree to init, for example DM_GPIO
> > cannot operate without one unless you are hacking around with
> > platdata, which is a bit of a pain.
> >
> > One option you might have is to use a general DT before relocation,
> > then figure out which one you really want to use and select that for
> > post relocation. That works better with driver model.
> >
> > Regards,
> > Simon
>
> Hi Simon,
> I finally fixed the problem by hacking the mxc_gpio driver and simply 
> enabling the DM_FLAG_PRE_RELOC flag with this simple patch:
>
> diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
> index 3cc0e7f353..be2bc6d655 100644
> --- a/drivers/gpio/mxc_gpio.c
> +++ b/drivers/gpio/mxc_gpio.c
> @@ -396,6 +396,7 @@ U_BOOT_DRIVER(gpio_mxc) = {
> .priv_auto  = sizeof(struct mxc_bank_info),
> .of_match = mxc_gpio_ids,
> .bind   = mxc_gpio_bind,
> +   .flags  = DM_FLAG_PRE_RELOC,
>  };
>
>  DM_DRIVER_ALIAS(gpio_mxc, fsl_imx6q_gpio)
>
> No other changes were required.
>
> However, this is probably not a solution that would get accepted into 
> mainline U-Boot, or not?

Seems fine to me. You can also put a u-boot,dm-... tag in the device
tree for that device, just for your board, if you don't want to affect
all boards.

See also dm_gpio_get_values_as_int() and I suspect I don't quite
understand what phase of U-Boot is selecting the DT. Is it SPL or
pre-reloc U-Boot?

Regards,
Simon


Re: [PATCH 10/19] buildman: Incorporate the genboardscfg.py tool

2022-07-22 Thread Simon Glass
Hi Tom,

On Wed, 20 Jul 2022 at 11:16, Tom Rini  wrote:
>
> On Wed, Jul 20, 2022 at 09:01:04AM -0600, Simon Glass wrote:
> > Hi Tom,
> >
> > On Mon, 18 Jul 2022 at 06:11, Tom Rini  wrote:
> > >
> > > On Thu, Jul 14, 2022 at 04:21:57AM -0600, Simon Glass wrote:
> > > > Hi Tom,
> > > >
> > > > On Wed, 13 Jul 2022 at 12:21, Tom Rini  wrote:
> > > > >
> > > > > On Wed, Jul 13, 2022 at 09:28:06AM -0600, Simon Glass wrote:
> > > > > > Hi Tom,
> > > > > >
> > > > > > On Tue, 12 Jul 2022 at 15:38, Tom Rini  wrote:
> > > > > > >
> > > > > > > On Mon, Jul 11, 2022 at 07:04:04PM -0600, Simon Glass wrote:
> > > > > > > > Bring this tool into buildman, so we don't have to run it 
> > > > > > > > separately. The
> > > > > > > > board.cfg file is still produced as part of the build, to save 
> > > > > > > > time when
> > > > > > > > doing another build in the same working directory. If it is out 
> > > > > > > > of date
> > > > > > > > with respect to the Kconfig, it is updated.
> > > > > > > >
> > > > > > > > Time to regenerate on a recent single-thread machine is 4.6s 
> > > > > > > > (1.3s on a
> > > > > > > > 32-thread machine), so we do need some sort of cache if we want 
> > > > > > > > buildman
> > > > > > > > to be useful on incremental builds. We could use Python's 
> > > > > > > > pickle format
> > > > > > > > but:
> > > > > > > >
> > > > > > > > - it seems useful to allow boards.cfg to be regenerated, at 
> > > > > > > > least for a
> > > > > > > >   while, in case other tools use it
> > > > > > > > - it is possible to grep the file easily, e.g. to find boards 
> > > > > > > > which use
> > > > > > > >   a particular SoC (similar to 'buildman -nv '
> > > > > > >
> > > > > > > While I don't think other tools still use boards.cfg, this will 
> > > > > > > make it
> > > > > > > easier to find out that I'm wrong.  Perhaps once the CONFIG to 
> > > > > > > Kconfig
> > > > > > > migration is done we can move to just pickle'ing the data or 
> > > > > > > similar
> > > > > > > since I find the main use of what was in boards.cfg can be 
> > > > > > > figured out
> > > > > > > with some other git grep'ing, and in turn that's mainly for me 
> > > > > > > when
> > > > > > > trying to convert stuff.  Thanks for doing this.
> > > > > >
> > > > > > Yes. I'm excited to hear that Kconfig migration might be done - any
> > > > > > forecast as to when?
> > > > >
> > > > > Not yet.  I'm auditing CONFIG_SYS_* now, with a notion to move
> > > > > everything that's not really configurable just out of CONFIG namespace
> > > > > as the starting point.  That'll drop us down to ~500 to migrate, which
> > > > > feels a bit less daunting.
> > > > >
> > > > > > One thing we could to is provide an option for buildman to spit out
> > > > > > the various fields that go into boards.cfg
> > > > >
> > > > > Right.  So I might not have said this before, but one reason I wanted
> > > > > buildman to natively know kconfiglib and have everything was that 
> > > > > while
> > > > > we can do a lot of good matching on what to build, it would be 
> > > > > amazingly
> > > > > good to be able to say "build every platform with NVME_PCI set" (and 
> > > > > if
> > > > > it's not too hard hex/int options with a specific value).
> > > >
> > > > Ah OK. At present moveconfig has the functionality to list the boards
> > > > that have particular options (-b and -f). It is expensive to build the
> > > > database though - over a minute on a 32-thread machine. So we would
> > > > have to cache it. Also just about any change would invalidate the
> > > > cache and I'm not sure if it possible to detect which changes have no
> > > > effect on which cache entries...
> > >
> > > Ah, maybe it will take some more thinking about then.  Maybe an
> > > "advanced" match option, and also seeing how to have Azure generate the db
> > > in one job and pass it as an artifact to every other job in the world
> > > build stage.  Not an immediate need.
> >
> > Well I suppose having that logic in moveconfig doesn't make a lot of
> > sense. So we could move it to buildman and have a way of creating the
> > database, as you say. But bear in mind that every commit being built
> > has the potential to change the Kconfig. It may be possible to hash
> > the files or detect changes using timestamps.
>
> Yeah, we can revisit this later on down the line.  I don't think (and we
> don't do it today either, fwiw) we need to ensure the list of boards to
> build is right for each step of the commit, and might even be
> counter-productive, at least for my use case.  Build the list of boards
> on top of tree, tell me how it changed over N commits (which commit
> caused the size change) is how I use things.  Then the CI case is only
> for top of tree anyhow.

OK, yes, actually that's the decision I came to for the original board
selection, i.e. the board selection comes from the current commits.

Regards,
Simon


Re: [PATCH v7 3/7] tpm: Add the RNG child device

2022-07-22 Thread Simon Glass
Hi Sughosh,

On Wed, 20 Jul 2022 at 06:30, Sughosh Ganu  wrote:
>
> The TPM device comes with the random number generator(RNG)
> functionality which is built into the TPM device. Add logic to add the
> RNG child device in the TPM uclass post probe callback.
>
> The RNG device can then be used to pass a set of random bytes to the
> linux kernel, need for address space randomisation through the
> EFI_RNG_PROTOCOL interface.

Ilias has asked me to review this patch again.

I don't want my review tag on it since it is not correct, so far as
driver model / device tree go. But I have no objection to it going in
since my understanding is we can disable TPM_RNG later as needed.

I prefer to have some acknowledgement of the previous discussion, e.g.:

   No compatible string is provided because this is not available in
the binding defined by Linux. If multiple rand devices are in the
system, then some method of selecting them (other than device tree)
will need to be used, or a binding will need to be added.

since I cannot imagine people remembering to look up the previous
version in patchwork.

But if you don't want that, then that's fine.

>
> Signed-off-by: Sughosh Ganu 
> ---
> Changes since V6: None
>
>  drivers/tpm/tpm-uclass.c | 37 +
>  1 file changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
> index f67fe1019b..e1f1ef01e1 100644
> --- a/drivers/tpm/tpm-uclass.c
> +++ b/drivers/tpm/tpm-uclass.c
> @@ -11,10 +11,15 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include "tpm_internal.h"
>
> +#include 

BTW this should be above the previous header.

> +
> +#define TPM_RNG_DRV_NAME   "tpm-rng"
> +
>  int tpm_open(struct udevice *dev)
>  {
> struct tpm_ops *ops = tpm_get_ops(dev);
> @@ -136,12 +141,36 @@ int tpm_xfer(struct udevice *dev, const uint8_t 
> *sendbuf, size_t send_size,
> return 0;
>  }
>
> +static int tpm_uclass_post_probe(struct udevice *dev)
> +{
> +   int ret;
> +   const char *drv = TPM_RNG_DRV_NAME;
> +   struct udevice *child;
> +
> +   if (CONFIG_IS_ENABLED(TPM_RNG)) {
> +   ret = device_find_first_child_by_uclass(dev, UCLASS_RNG,
> +   );
> +
> +   if (ret != -ENODEV) {
> +   log_debug("RNG child already added to the TPM 
> device\n");
> +   return ret;
> +   }
> +
> +   ret = device_bind_driver(dev, drv, "tpm-rng0", );

If this does get re-issued, I think this could just use
TPM_RNG_DRV_NAME directory.

> +   if (ret)
> +   return log_msg_ret("bind", ret);
> +   }
> +
> +   return 0;
> +}
> +
>  UCLASS_DRIVER(tpm) = {
> -   .id = UCLASS_TPM,
> -   .name   = "tpm",
> -   .flags  = DM_UC_FLAG_SEQ_ALIAS,
> +   .id = UCLASS_TPM,
> +   .name   = "tpm",
> +   .flags  = DM_UC_FLAG_SEQ_ALIAS,
>  #if CONFIG_IS_ENABLED(OF_REAL)
> -   .post_bind  = dm_scan_fdt_dev,
> +   .post_bind  = dm_scan_fdt_dev,
>  #endif
> +   .post_probe = tpm_uclass_post_probe,
> .per_device_auto= sizeof(struct tpm_chip_priv),
>  };
> --
> 2.34.1
>

Regards,
Simon


Re: [PATCH v2] drivers: xen: unmap Enlighten page before jumping to Linux

2022-07-22 Thread Dmytro Firsov
On 21.07.22 18:11, Oleksandr wrote:
>
> On 19.07.22 17:55, Dmytro Firsov wrote:
>
> Hello Dmytro
>
>
> First of all, thanks for fixing this issue.
>
> Patch looks good, just a nit below.
>
Hello Oleksandr,
>> +    reservation.domid = DOMID_SELF;
>> +    reservation.extent_order = 0;
>> +    reservation.address_bits = 0;
>
> I think the explicit field's zeroing could be dropped now.
>
>
Per my understanding, both of this zeros matters, so I decided to set 
them explicitly (even with struct zeroing):

- for `extent_order` - zero means "no additional shift for PFN_SHIFT", 
so we are using 4K pages;

- for `address_bits` - zero means "the user has no addressing restriction".


Best regards,

Dmytro.


[PATCH v2 5/5] arm64: versal: Enable power domain driver and its dependencies

2022-07-22 Thread Ashok Reddy Soma
Enable power domain driver to configure pmufw config object and request
node for all the IP's that are enabled in DT.

This driver depends on mailbox and IPI driver, hence enable them as well.
Add ARCH_VERSAL in the depends on of mailbox Kconfig to compile for
Versal platforms.

Signed-off-by: Ashok Reddy Soma 
---

(no changes since v1)

 configs/xilinx_versal_virt_defconfig | 4 
 drivers/mailbox/Kconfig  | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/configs/xilinx_versal_virt_defconfig 
b/configs/xilinx_versal_virt_defconfig
index 0419992be4..a2d4debbf5 100644
--- a/configs/xilinx_versal_virt_defconfig
+++ b/configs/xilinx_versal_virt_defconfig
@@ -66,6 +66,8 @@ CONFIG_FPGA_XILINX=y
 CONFIG_FPGA_VERSALPL=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_CADENCE=y
+CONFIG_DM_MAILBOX=y
+CONFIG_ZYNQMP_IPI=y
 CONFIG_MISC=y
 CONFIG_I2C_EEPROM=y
 CONFIG_SUPPORT_EMMC_BOOT=y
@@ -96,6 +98,8 @@ CONFIG_PHY_GIGE=y
 CONFIG_XILINX_AXIEMAC=y
 CONFIG_XILINX_AXIMRMAC=y
 CONFIG_ZYNQ_GEM=y
+CONFIG_POWER_DOMAIN=y
+CONFIG_ZYNQMP_POWER_DOMAIN=y
 CONFIG_ARM_DCC=y
 CONFIG_PL01X_SERIAL=y
 CONFIG_XILINX_UARTLITE=y
diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
index 73db2af0b8..acbdce11b7 100644
--- a/drivers/mailbox/Kconfig
+++ b/drivers/mailbox/Kconfig
@@ -54,7 +54,7 @@ config K3_SEC_PROXY
 
 config ZYNQMP_IPI
bool "Xilinx ZynqMP IPI controller support"
-   depends on DM_MAILBOX && ARCH_ZYNQMP
+   depends on DM_MAILBOX && (ARCH_ZYNQMP || ARCH_VERSAL)
help
  This enables support for the Xilinx ZynqMP Inter Processor Interrupt
  communication controller.
-- 
2.17.1



[PATCH v2 4/5] mailbox: zynqmp: Move struct zynqmp_ipi_msg from sys_proto.h

2022-07-22 Thread Ashok Reddy Soma
Mailbox driver might be need for Versal and other future platforms.
To remove the dependency, move struct zynqmp_ipi_msg to
zynqmp_firmware.h so that mailbox driver compiles for other platforms
easily.

Signed-off-by: Ashok Reddy Soma 
---

(no changes since v1)

 arch/arm/mach-zynqmp/include/mach/sys_proto.h | 5 -
 drivers/mailbox/zynqmp-ipi.c  | 2 +-
 include/zynqmp_firmware.h | 5 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-zynqmp/include/mach/sys_proto.h 
b/arch/arm/mach-zynqmp/include/mach/sys_proto.h
index 1c12eac715..9fffb4e541 100644
--- a/arch/arm/mach-zynqmp/include/mach/sys_proto.h
+++ b/arch/arm/mach-zynqmp/include/mach/sys_proto.h
@@ -46,11 +46,6 @@ enum {
TCM_SPLIT,
 };
 
-struct zynqmp_ipi_msg {
-   size_t len;
-   u32 *buf;
-};
-
 int zynq_board_read_rom_ethaddr(unsigned char *ethaddr);
 unsigned int zynqmp_get_silicon_version(void);
 
diff --git a/drivers/mailbox/zynqmp-ipi.c b/drivers/mailbox/zynqmp-ipi.c
index 959cce923c..3e4ec47389 100644
--- a/drivers/mailbox/zynqmp-ipi.c
+++ b/drivers/mailbox/zynqmp-ipi.c
@@ -11,10 +11,10 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
+#include 
 
 /* IPI bitmasks, register base */
 /* TODO: move reg base to DT */
diff --git a/include/zynqmp_firmware.h b/include/zynqmp_firmware.h
index 1c22a62207..fa969bf336 100644
--- a/include/zynqmp_firmware.h
+++ b/include/zynqmp_firmware.h
@@ -492,4 +492,9 @@ enum zynqmp_pm_request_ack {
 /* PM API versions */
 #define PM_API_VERSION_2   2
 
+struct zynqmp_ipi_msg {
+   size_t len;
+   u32 *buf;
+};
+
 #endif /* _ZYNQMP_FIRMWARE_H_ */
-- 
2.17.1



[PATCH v2 3/5] arm64: zynqmp: Enable power domain driver

2022-07-22 Thread Ashok Reddy Soma
Enable power domain driver to configure pmufw config object and request
node for all the IP's that are enabled in DT.

Signed-off-by: Ashok Reddy Soma 
---

(no changes since v1)

 configs/xilinx_zynqmp_virt_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/xilinx_zynqmp_virt_defconfig 
b/configs/xilinx_zynqmp_virt_defconfig
index 35894076c5..85cd5d6d9e 100644
--- a/configs/xilinx_zynqmp_virt_defconfig
+++ b/configs/xilinx_zynqmp_virt_defconfig
@@ -162,6 +162,8 @@ CONFIG_PHY_XILINX_GMII2RGMII=y
 CONFIG_PHY_FIXED=y
 CONFIG_XILINX_AXIEMAC=y
 CONFIG_ZYNQ_GEM=y
+CONFIG_POWER_DOMAIN=y
+CONFIG_ZYNQMP_POWER_DOMAIN=y
 CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_PWM=y
-- 
2.17.1



[PATCH v2 2/5] firmware: zynqmp: Load config overlay for core0 to pmufw

2022-07-22 Thread Ashok Reddy Soma
Try loading pmufw config overlay for core0, if it doesn't return any
error it means pmufw is accepting nodes for other IP's. Otherwise dont
try to load config object for any other IP, just return from
zynqmp_pmufw_node function.

Signed-off-by: Ashok Reddy Soma 
---

Changes in v2:
 - Move static variable to inside zynqmp_pmufw_node and change name to
   skip_config from config_enabled
 - Use zynqmp_pmufw_node() in zynqmp_power_probe() to check for APU_0
   config loading instead of calling zynqmp_pmufw_load_config_object()

 drivers/firmware/firmware-zynqmp.c | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/firmware-zynqmp.c 
b/drivers/firmware/firmware-zynqmp.c
index 34d9b47003..aedc4dd2df 100644
--- a/drivers/firmware/firmware-zynqmp.c
+++ b/drivers/firmware/firmware-zynqmp.c
@@ -70,11 +70,20 @@ int zynqmp_pmufw_config_close(void)
 
 int zynqmp_pmufw_node(u32 id)
 {
+   static bool skip_config;
+   int ret;
+
+   if (skip_config)
+   return 0;
+
/* Record power domain id */
xpm_configobject[NODE_ID_LOCATION] = id;
 
-   zynqmp_pmufw_load_config_object(xpm_configobject,
-   sizeof(xpm_configobject));
+   ret = zynqmp_pmufw_load_config_object(xpm_configobject,
+ sizeof(xpm_configobject));
+
+   if (ret && id == NODE_APU_0)
+   skip_config = true;
 
return 0;
 }
@@ -267,6 +276,9 @@ static int zynqmp_power_probe(struct udevice *dev)
   ret >> ZYNQMP_PM_VERSION_MAJOR_SHIFT,
   ret & ZYNQMP_PM_VERSION_MINOR_MASK);
 
+   if (IS_ENABLED(CONFIG_ARCH_ZYNQMP))
+   zynqmp_pmufw_node(NODE_APU_0);
+
return 0;
 };
 
-- 
2.17.1



[PATCH v2 1/5] firmware: zynqmp: Change prototype of zynqmp_pmufw_load_config_object()

2022-07-22 Thread Ashok Reddy Soma
zynqmp_pmufw_load_config_object() has some error cases and it is better
to return those errors. Change prototype of this function to return
errors.

Signed-off-by: Ashok Reddy Soma 
---

(no changes since v1)

 drivers/firmware/firmware-zynqmp.c | 8 +---
 include/zynqmp_firmware.h  | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/firmware-zynqmp.c 
b/drivers/firmware/firmware-zynqmp.c
index 0f0d2b07c0..34d9b47003 100644
--- a/drivers/firmware/firmware-zynqmp.c
+++ b/drivers/firmware/firmware-zynqmp.c
@@ -210,7 +210,7 @@ int zynqmp_pm_is_function_supported(const u32 api_id, const 
u32 id)
  * @cfg_obj: Pointer to the configuration object
  * @size:Size of @cfg_obj in bytes
  */
-void zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size)
+int zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size)
 {
int err;
u32 ret_payload[PAYLOAD_ARG_CNT];
@@ -224,12 +224,12 @@ void zynqmp_pmufw_load_config_object(const void *cfg_obj, 
size_t size)
0, ret_payload);
if (err == XST_PM_NO_ACCESS) {
printf("PMUFW no permission to change config object\n");
-   return;
+   return -EACCES;
}
 
if (err == XST_PM_ALREADY_CONFIGURED) {
debug("PMUFW Node is already configured\n");
-   return;
+   return -ENODEV;
}
 
if (err)
@@ -240,6 +240,8 @@ void zynqmp_pmufw_load_config_object(const void *cfg_obj, 
size_t size)
 
if ((err || ret_payload[0]) && IS_ENABLED(CONFIG_SPL_BUILD))
panic("PMUFW config object loading failed in EL3\n");
+
+   return 0;
 }
 
 static int zynqmp_power_probe(struct udevice *dev)
diff --git a/include/zynqmp_firmware.h b/include/zynqmp_firmware.h
index 6c4fd9a6c5..1c22a62207 100644
--- a/include/zynqmp_firmware.h
+++ b/include/zynqmp_firmware.h
@@ -449,7 +449,7 @@ enum pm_gem_config_type {
 unsigned int zynqmp_firmware_version(void);
 int zynqmp_pmufw_node(u32 id);
 int zynqmp_pmufw_config_close(void);
-void zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size);
+int zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size);
 int xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2,
  u32 arg3, u32 *ret_payload);
 int zynqmp_pm_set_sd_config(u32 node, enum pm_sd_config_type config, u32 
value);
-- 
2.17.1



  1   2   >