Re: [PATCH v6 06/22] mtd: nand: add support for the Sandisk SDTNQGAMA chip

2023-03-08 Thread Michael Nazzareno Trimarchi
On Fri, Mar 3, 2023 at 1:13 AM Johan Jonker  wrote:
>
> Sandisk SDTNQGAMA is a 8GB size, 3.3V 8 bit chip with 16KB page size,
> 1KB write size and 40 bit ecc support
>
> Signed-off-by: Paweł Jarosz 
> Signed-off-by: Johan Jonker 
> Reviewed-by: Kever Yang 
> ---
>  drivers/mtd/nand/raw/nand_ids.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c
> index d0cfacc6..22ea5e2f 100644
> --- a/drivers/mtd/nand/raw/nand_ids.c
> +++ b/drivers/mtd/nand/raw/nand_ids.c
> @@ -48,6 +48,9 @@ struct nand_flash_dev nand_flash_ids[] = {
> {"TC58NVG6D2 64G 3.3V 8-bit",
> { .id = {0x98, 0xde, 0x94, 0x82, 0x76, 0x56, 0x04, 0x20} },
>   SZ_8K, SZ_8K, SZ_2M, 0, 8, 640, NAND_ECC_INFO(40, SZ_1K) },
> +   {"SDTNQGAMA 64G 3.3V 8-bit",
> +   { .id = {0x45, 0xde, 0x94, 0x93, 0x76, 0x57} },
> + SZ_16K, SZ_8K, SZ_4M, 0, 6, 1280, NAND_ECC_INFO(40, SZ_1K) 
> },
> {"SDTNRGAMA 64G 3.3V 8-bit",
> { .id = {0x45, 0xde, 0x94, 0x93, 0x76, 0x50} },
>   SZ_16K, SZ_8K, SZ_4M, 0, 6, 1280, NAND_ECC_INFO(40, SZ_1K) 
> },
> --
> 2.20.1
>

Acked-by: Michael Trimarchi 


[PATCH 0/1] lib/vsprintf.c: fix integer overflow in vsprintf

2023-03-08 Thread Ying-Chun Liu (PaulLiu)
vsnprintf_internal() adds 'size' to 'buf' and vsprintf() sets 'size'
to 'INT_MAX' which can overflow.  This causes sprintf() to fail when
initializing the environment on 8GB.

Instead of using 'INT_MAX', we use SIZE_MAX - buf, which is the
largest possible string that could fit without overflowing 'size'.

Tom Cherry (1):
  lib/vsprintf.c: fix integer overflow in vsprintf

 lib/vsprintf.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

-- 
2.39.2



[PATCH 1/1] lib/vsprintf.c: fix integer overflow in vsprintf

2023-03-08 Thread Ying-Chun Liu (PaulLiu)
From: Tom Cherry 

vsnprintf_internal() adds 'size' to 'buf' and vsprintf() sets 'size'
to 'INT_MAX' which can overflow.  This causes sprintf() to fail when
initializing the environment on 8GB.

Instead of using 'INT_MAX', we use SIZE_MAX - buf, which is the
largest possible string that could fit without overflowing 'size'.

Signed-off-by: Tom Cherry 
[ Paul: pick from the Android tree. Rebase to the upstream ]
Signed-off-by: Ying-Chun Liu (PaulLiu) 
Cc: Tom Rini 
Link: 
https://android.googlesource.com/platform/external/u-boot/+/43aae5d4415e0f9d744fb798acd52429d09957ce
---
 lib/vsprintf.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 2d13e68b57..cd89c56a8f 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -794,7 +794,12 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...)
  */
 int vsprintf(char *buf, const char *fmt, va_list args)
 {
-   return vsnprintf_internal(buf, INT_MAX, fmt, args);
+   /* vsnprintf_internal adds size to buf, so use a size that won't
+* overflow.
+*/
+   size_t max_size = SIZE_MAX - (size_t)buf;
+
+   return vsnprintf_internal(buf, max_size, fmt, args);
 }
 
 int sprintf(char *buf, const char *fmt, ...)
-- 
2.39.2



[PATCH] rockchip: sdhci: rk3568: bypass DLL when clk <= 52 MHz

2023-03-08 Thread Vasily Khoruzhick
For Rockchip platform, DLL bypass bit and start bit need to be set if
DLL is not locked.

With this change applied eMMC in my NanoPi R5S can run at 52 MHz.

Based on linux commit b75a52b0dda3 ("mmc: sdhci-of-dwcmshc: Update DLL
and pre-change delay for rockchip platform")

Signed-off-by: Vasily Khoruzhick 
---
 drivers/mmc/rockchip_sdhci.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/rockchip_sdhci.c b/drivers/mmc/rockchip_sdhci.c
index 1ac95f32b3..fef23f593e 100644
--- a/drivers/mmc/rockchip_sdhci.c
+++ b/drivers/mmc/rockchip_sdhci.c
@@ -61,6 +61,7 @@
 #define DWCMSHC_EMMC_DLL_RXCLK 0x804
 #define DWCMSHC_EMMC_DLL_TXCLK 0x808
 #define DWCMSHC_EMMC_DLL_STRBIN0x80c
+#define DECMSHC_EMMC_DLL_CMDOUT0x810
 #define DWCMSHC_EMMC_DLL_STATUS0   0x840
 #define DWCMSHC_EMMC_DLL_STATUS1   0x844
 #define DWCMSHC_EMMC_DLL_START BIT(0)
@@ -69,6 +70,7 @@
 #define DWCMSHC_EMMC_DLL_START_DEFAULT 5
 #define DWCMSHC_EMMC_DLL_INC_VALUE 2
 #define DWCMSHC_EMMC_DLL_INC   8
+#define DWCMSHC_EMMC_DLL_BYPASSBIT(24)
 #define DWCMSHC_EMMC_DLL_DLYENABIT(27)
 #define DLL_TXCLK_TAPNUM_DEFAULT   0xA
 
@@ -83,6 +85,7 @@
 #define DWCMSHC_EMMC_DLL_TIMEOUT   BIT(9)
 #define DLL_RXCLK_NO_INVERTER  1
 #define DLL_RXCLK_INVERTER 0
+#define DLL_RXCLK_ORI_GATE BIT(31)
 #define DWCMSHC_ENHANCED_STROBEBIT(8)
 #define DLL_LOCK_WO_TMOUT(x) \
x) & DWCMSHC_EMMC_DLL_LOCKED) == DWCMSHC_EMMC_DLL_LOCKED) && \
@@ -348,10 +351,14 @@ static int rk3568_sdhci_emmc_set_clock(struct sdhci_host 
*host, unsigned int clo
DLL_STRBIN_TAPNUM_FROM_SW;
sdhci_writel(host, extra, DWCMSHC_EMMC_DLL_STRBIN);
} else {
-   /* reset the clock phase when the frequency is lower than 
100MHz */
-   sdhci_writel(host, 0, DWCMSHC_EMMC_DLL_CTRL);
-   extra = DLL_RXCLK_NO_INVERTER << DWCMSHC_EMMC_DLL_RXCLK_SRCSEL;
-   sdhci_writel(host, extra, DWCMSHC_EMMC_DLL_RXCLK);
+   /*
+* Disable DLL and reset both of sample and drive clock.
+* The bypass bit and start bit need to be set if DLL is not 
locked.
+*/
+   sdhci_writel(host, DWCMSHC_EMMC_DLL_BYPASS | 
DWCMSHC_EMMC_DLL_START,
+DWCMSHC_EMMC_DLL_CTRL);
+   sdhci_writel(host, DLL_RXCLK_ORI_GATE, DWCMSHC_EMMC_DLL_RXCLK);
+   sdhci_writel(host, 0, DECMSHC_EMMC_DLL_CMDOUT);
sdhci_writel(host, 0, DWCMSHC_EMMC_DLL_TXCLK);
/*
 * Before switching to hs400es mode, the driver will enable
-- 
2.39.2



Re: [PATCH v2 28/32] test: cmd: fdt: Test fdt memory

2023-03-08 Thread Marek Vasut

On 3/8/23 23:23, Simon Glass wrote:

Hi Marek,

On Wed, 1 Mar 2023 at 19:09, Marek Vasut
 wrote:


Add 'fdt memory' test which works as follows:
- Create custom FDT with /memory node, with select #*cells, map it to sysmem
- Perform memory fixup
- Read back the /memory node and validate its content

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
  test/cmd/fdt.c | 83 ++
  1 file changed, 83 insertions(+)



This patch and some others cause test failures. I applied those that I
could to u-boot-dm/next

Can you please rebase and take a look?


Does it work any better if you also apply:

[PATCH] console: Use only 0x00 as line separator for console recording

?

If so, then just pick the aforementioned patch and the rest of this series.


Re: [PATCH v2 02/32] cmd: fdt: Fix handling of empty properties for fdt get addr and fdt get size

2023-03-08 Thread Marek Vasut

On 3/8/23 23:17, Simon Glass wrote:

Hi Marek,

On Wed, 1 Mar 2023 at 20:09, Marek Vasut
 wrote:


It is perfectly valid to request an address or size of FDT property
without value, the only special case if requesting of the value of
FDT property without value. Invert the test such, that properties
without value still set the variable from 'fdt get addr/size' to
address of the property or size of the property, where the later
is 0.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon


BTW 'patman status' can collect review tags and add them to your
commits automatically.

Regards,
Simon

Applied to u-boot-dm/next, thanks!


Shouldn't this be applied to current release, since those are fixes ?
(or at least the first 10 or so are, the rest are tests for those fixes obv)


Re: [PATCH v2] mtd: rawnand: nand_base: Handle algorithm selection

2023-03-08 Thread Michael Nazzareno Trimarchi
Hi

On Wed, Mar 8, 2023 at 10:29 PM Linus Walleij  wrote:
>
> For BRCMNAND with 1-bit BCH ECC (BCH-1) such as used on the
> D-Link DIR-885L and DIR-890L routers, we need to explicitly
> select the ECC like this in the device tree:
>
>   nand-ecc-algo = "bch";
>   nand-ecc-strength = <1>;
>   nand-ecc-step-size = <512>;
>
> This is handled by the Linux kernel but U-Boot core does
> not respect this. Fix it up by parsing the algorithm and
> preserve the behaviour using this property to select
> software BCH as far as possible.
>
> Signed-off-by: Linus Walleij 
> ---
> ChangeLog v1->v2:
> - Drop pointless check for ecc_algo >= 0, it is always
>   >= 0.
> ---
>  drivers/mtd/nand/raw/nand_base.c | 12 +---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/nand_base.c 
> b/drivers/mtd/nand/raw/nand_base.c
> index 9eba360d55f3..c173fd09237a 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -4487,6 +4487,7 @@ EXPORT_SYMBOL(nand_detect);
>  static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode 
> node)
>  {
> int ret, ecc_mode = -1, ecc_strength, ecc_step;
> +   int ecc_algo = NAND_ECC_UNKNOWN;
> const char *str;
>
> ret = ofnode_read_s32_default(node, "nand-bus-width", -1);
> @@ -4512,10 +4513,13 @@ static int nand_dt_init(struct mtd_info *mtd, struct 
> nand_chip *chip, ofnode nod
> ecc_mode = NAND_ECC_SOFT_BCH;
> }
>
> -   if (ecc_mode == NAND_ECC_SOFT) {
> -   str = ofnode_read_string(node, "nand-ecc-algo");
> -   if (str && !strcmp(str, "bch"))
> +   str = ofnode_read_string(node, "nand-ecc-algo");
> +   if (str && !strcmp(str, "bch")) {
> +   ecc_algo = NAND_ECC_BCH;
> +   if (ecc_mode == NAND_ECC_SOFT)
> ecc_mode = NAND_ECC_SOFT_BCH;
> +   } else if (!strcmp(str, "hamming")) {
> +   ecc_algo = NAND_ECC_HAMMING;
> }
>
> ecc_strength = ofnode_read_s32_default(node,
> @@ -4529,6 +4533,8 @@ static int nand_dt_init(struct mtd_info *mtd, struct 
> nand_chip *chip, ofnode nod
> return -EINVAL;
> }
>
> +   chip->ecc.algo = ecc_algo;
> +
> if (ecc_mode >= 0)
> chip->ecc.mode = ecc_mode;
>
> --
> 2.39.1
>
Reviewed-by: Michael Trimarchi 

Michael


Please pull u-boot-dm into -next

2023-03-08 Thread Simon Glass
Hi Tom,

This is for the -next branch


https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/15499


The following changes since commit 70ed05ce6c051e55e126e67e72ab20409134c953:

  Merge tag 'next-20230307' of
https://source.denx.de/u-boot/custodians/u-boot-video into next
(2023-03-07 12:54:01 -0500)

are available in the Git repository at:

  git://git.denx.de/u-boot-dm.git tags/dm-next-9mar23

for you to fetch changes up to 953d4177afa0bee0ba0db4b81036d3197595b997:

  binman: Support generation of x509 certificates (2023-03-08 13:15:15 -0800)


binman x509, separate tools dir and other improvements
patman parallel patch generation
fdt fixes and tests
PyPi support for U-Boot tools
buildman reproducible builds


Jonas Karlman (3):
  binman: Remove redundant SetAllowFakeBlob from blob-ext entry
  binman: Fix spelling of nodes in code comments
  binman: Use correct argument name in docstrings

Marek Vasut (26):
  cmd: fdt: Import is_printable_string() from DTC to fix u32 misprint
  cmd: fdt: Fix handling of empty properties for fdt get addr and
fdt get size
  cmd: fdt: Fix fdt rm behavior on non-existent property and error
message space
  cmd: fdt: Fix fdt rsvmem behavior on non-existent index and
error message space
  cmd: fdt: Check argc before accessing argv in fdt bootcpu
  cmd: fdt: Check argc before accessing argv in fdt memory
  cmd: fdt: Align checksign parameter names in help text
  cmd: fdt: Handle 64bit pointers in fdt get addr
  cmd: fdt: Map address returned from fdt get addr to sysmem
  cmd: fdt: Add support for integer arrays in fdt get value with index
  test: Add ut_assert_nextline_empty() empty line helper
  test: cmd: fdt: Rename fdt_test_resize() to fdt_test_addr_resize()
  test: cmd: fdt: Rename fdt_test_get() to fdt_test_get_value()
  test: cmd: fdt: Generate fuller DT internally and switch fdt get
value to it
  test: cmd: fdt: Test alias resolution in 'fdt get value'
  test: cmd: fdt: Test both string and integer arrays in 'fdt get value'
  test: cmd: fdt: Test fdt move
  test: cmd: fdt: Test fdt resize
  test: cmd: fdt: Test fdt get name
  test: cmd: fdt: Test fdt get addr
  test: cmd: fdt: Test fdt get size
  test: cmd: fdt: Test fdt set
  test: cmd: fdt: Test fdt mknode
  test: cmd: fdt: Test fdt rm
  test: cmd: fdt: Test fdt bootcpu
  test: cmd: fdt: Add list of remaining missing tests

Simon Glass (46):
  binman: Avoid requiring a home directory on startup
  binman: Support marking FMAP areas as preserved
  buildman: Add a note about the out-env file
  buildman: Write out the build command used
  buildman: Support disabling LTO
  buildman: Add a flag for reproducible builds
  binman: Correct an 'aot' typo
  binman: Update bintools documentation
  binman: Move the tools directory into the Bintool class
  binman: Use a private directory for bintools
  binman: Make the tooldir configurable
  bootflow: Rename bootflow_flags_t
  bootstd: Replicate the dtb-filename quirks of distroboot
  binman: Avoid unwanted output in testFitFirmwareLoadables()
  Revert "patman: test_util: Print test stdout/stderr within test summaries"
  Remove concurrencytest
  patman: Move library functions into a library directory
  script: Add a script to build a PyPi package
  patman: Add support for building a u_boot_tools PyPi package
  patman: Avoid importing test_checkpatch before it is needed
  patman: Add support for building a patman PyPi package
  buildman: Move the main code into a function
  buildman: Hide the test options unless test code is available
  buildman: Fix use of a type as a variable
  buildman: Use importlib to find the help
  buildman: Add support for building a buildman PyPi package
  dtoc: Hide the test options unless test code is available
  dtoc: Move the main code into a function
  dtoc: Use pathlib to find the test directory
  dtoc: Add support for building a dtoc PyPi package
  binman: Move the main code into a function
  binman: Hide the 'test' command unless test code is available
  binman: Use importlib to find the help
  binman: Add support for building a binmanu PyPi package
  test: Add concurrencytest to the requirements
  doc: Add notes on how to install patman and binman
  CI: Add a check for building tools for PyPi
  patman: Drop an incorrect comment about git am
  patman: Refactor MakeCcFile() into two functions
  patman: Run get_maintainer.pl in parallel
  patman: Check patches in parallel
  buildman: Correct CROSS_COMPILE output for sandbox
  binman: Allow preserving the output dir when replacing
  binman: Handle missing bintools correctly in fit
 

Re: [PATCH v2 1/5] binman: Correct an 'aot' typo

2023-03-08 Thread Simon Glass
Fix this typo.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/bintool.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 21/32] test: cmd: fdt: Test fdt get addr

2023-03-08 Thread Simon Glass
Add 'fdt get addr' test which works as follows:
- Create fuller FDT, map it to sysmem
- Get address of various properties
- Compare addresses calculated by UT and fdt command

This test is special in that it has to go through gruesome remapping scheme
where the test calculates:
- pointer offsets of the generated FDT root and the property being tested
- map_sysmem() result of environment variable "fdtaddr" and the one set
  by the test matching address of property being tested
- difference between the later and the former, to obtain offset of the
  DT property from start of DT
The offsets must match in both the UT and the tested U-Boot, if they do
not, the test fails.

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Do assignment first, assert second
Add RB from Simon
---
 test/cmd/fdt.c | 67 ++
 1 file changed, 67 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 28/32] test: cmd: fdt: Test fdt memory

2023-03-08 Thread Simon Glass
Hi Marek,

On Wed, 1 Mar 2023 at 19:09, Marek Vasut
 wrote:
>
> Add 'fdt memory' test which works as follows:
> - Create custom FDT with /memory node, with select #*cells, map it to sysmem
> - Perform memory fixup
> - Read back the /memory node and validate its content
>
> The test case can be triggered using:
> "
> ./u-boot -Dc 'ut fdt'
> "
> To dump the full output from commands used during test, add '-v' flag.
>
> Signed-off-by: Marek Vasut 
> Reviewed-by: Simon Glass 
> ---
> Cc: Heinrich Schuchardt 
> Cc: Simon Glass 
> Cc: Tom Rini 
> ---
> V2: Add RB from Simon
> ---
>  test/cmd/fdt.c | 83 ++
>  1 file changed, 83 insertions(+)
>

This patch and some others cause test failures. I applied those that I
could to u-boot-dm/next

Can you please rebase and take a look?

Regards,
Simon


Re: [PATCH v2 2/5] binman: Update bintools documentation

2023-03-08 Thread Simon Glass
This was not regenerated with recent changes. Update it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/bintools.rst | 70 +++
 1 file changed, 70 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH] binman: Avoid requiring a home directory on startup

2023-03-08 Thread Simon Glass
Hi Quentin,

On Mon, 20 Feb 2023 at 04:15, Quentin Schulz
 wrote:
>
> Hi Simon,
>
> On 2/18/23 00:49, Simon Glass wrote:
> > Hi Quentin,
> >
> > On Fri, 17 Feb 2023 at 05:21, Quentin Schulz
> >  wrote:
> >>
> >> Hi all,
> >>
> >> On 2/17/23 03:55, Simon Glass wrote:
> >>> Hi Tom,
> >>>
> >>> On Thu, 16 Feb 2023 at 17:19, Tom Rini  wrote:
> 
>  On Thu, Feb 16, 2023 at 05:12:33PM -0700, Simon Glass wrote:
> > Hi Tom,
> >
> > On Tue, 14 Feb 2023 at 13:27, Tom Rini  wrote:
> >>
> >> On Tue, Feb 14, 2023 at 03:12:46PM -0500, Mike Frysinger wrote:
> >>> On Tue, Feb 14, 2023 at 3:08 PM Tom Rini  wrote:
>  Downloading things from the internet and putting them in to the 
>  default
>  PATH always and forever is also kinda not great?
> >>>
> >>> you just described a standard distribution.  this is like literally
> >>> how all of them work.  not to mention every other language-specific
> >>> distro tool out there (e.g. Python pip, Perl cpan, Go, etc...).
> >>>
> >>> maybe you'd like more guarantees on top (e.g. signature verification)
> >>> which is reasonable.
> >>>
> >>> but to be clear, this script is already merged & in the tree, so your
> >>> feedback doesn't block this patch.
> >>
> >> Yes, exactly. This is a fix on top of what we do today, so it should go
> >> in. But modern distributions only install signed packages, and
> >> language-specific tools tend to be a hive of bad examples. Looking over
> >> binman right now, I see that we're either using apt (and oh, there's
> >> "aot" typo in one spot) or downloading from a known Google drive, for
> >> only a few less common tools.
> >>
> >> So yes, I would like to see some ideas on how to improve things in the
> >> future so we aren't putting the binaries somewhere that's not a default
> >> (or frequently common) PATH location.
> >
> > Are you thinking they should go in ~/.binman-tools or something like
> > that? Then we would need to tell people to add it to their path. But
> > we could make binman look there automatically.
> 
>  We should document that it's where we're putting stuff, not so much
>  "tell" them, unless you mean as a note when downloading.  But yes,
>  ~/.binman-tools sounds reasonable.  Maybe a flag to point elsewhere?
> >>>
> >>> OK I will take a look.
> >>>
> >>
> >> I think this should be directly put into the output/build directory used
> >> by U-Boot, because what happens when you have two U-Boot git repos with
> >> different version requirements for those host tools? Then you need to
> >> make sure you're not building both at the same time, that you update
> >> them properly before each build, etc.
> >
> > My advice: *Don't do that*
> >
> > So far as binman is concerned, a tool is a tool. Tools should be
> > backwards compatible so updating to the new one should fix all the
> > problems.
> >
>
> That's a very bold claim :)
>
> > The problem with using the output dir is we then have to download them
> > for each build, or cache them somewhere. To my mind, the 'binman tool'
> > feature is a convenience to reduce the pain involved in obtaining
> > tools needed to build. It is a not a panacea for strange situations.
> >
>
> Have the default in the build directory and allow the user to define an
> out-of-tree directory if they want to cache them somewhere? Similar to
> Yocto with SSTATE_DIR/DL_DIR, Buildroot with BR2_DL_DIR for example.

OK, but why do you want to use the build directory at all? It seems
like a hassle to set up. With the series I sent it is automatic and
all that is needed is to add ~/.binman-tools to your path.

Regards,
Simon

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 3/5] binman: Move the tools directory into the Bintool class

2023-03-08 Thread Simon Glass
We want to be able to change this directory. Use a class member to hold
the value, since changing a constant is not good.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/bintool.py  | 7 ---
 tools/binman/bintool_test.py | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 1/4] buildman: Add a note about the out-env file

2023-03-08 Thread Simon Glass
This file holds the environment used when doing a build. Add a note
about it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/buildman/buildman.rst | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v4 2/2] bootstd: Replicate the dtb-filename quirks of distroboot

2023-03-08 Thread Simon Glass
For EFI, the distro boot scripts search in three different directories
for the .dtb file. The SOC-based filename fallback is supported only for
32-bit ARM.

Adjust the code to mirror this behaviour.

Also some boards can use a prior-stage FDT if one is not found in the
normal way. Support this and show a message in that case.

Signed-off-by: Simon Glass 
Suggested-by: Mark Kettenis 
---

Changes in v4:
- Update commit message to avoid mentioning a warning
- Rebase to -master instead of -next

Changes in v3:
- Change the message from a warning to a statement

Changes in v2:
- Allow use of the prior-stage FDT if nothing else is found
- Warn about using a prior-stage FDT

 boot/bootflow.c |  3 ++
 boot/bootmeth_efi.c | 70 +++--
 include/bootflow.h  | 14 +
 3 files changed, 78 insertions(+), 9 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 02/24] Revert "patman: test_util: Print test stdout/stderr within test summaries"

2023-03-08 Thread Simon Glass
Unfortunately this adds a new feature to concurrencytest and it has not
made it upstream to the project[1].

Drop it for now so we can use the upstream module. Once it is applied we
can bring this functionality back.

[1] https://github.com/cgoldberg/concurrencytest

This reverts commit ebcaafcded40da8ae6cb4234c2ba9901c7bee644.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/concurrencytest/concurrencytest.py | 83 +---
 tools/patman/test_util.py| 33 +-
 2 files changed, 4 insertions(+), 112 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 04/24] patman: Move library functions into a library directory

2023-03-08 Thread Simon Glass
The patman directory has a number of modules which are used by other tools
in U-Boot. This makes it hard to package the tools using pypi since the
common files must be copied along with the tool that uses them.

To address this, move these files into a new u_boot_pylib library. This
can be packaged separately and listed as a dependency of each tool.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 scripts/event_dump.py |  2 +-
 test/run  |  1 +
 tools/binman/bintool.py   |  8 +++
 tools/binman/bintool_test.py  |  8 +++
 tools/binman/btool/lz4.py |  2 +-
 tools/binman/btool/lzma_alone.py  |  2 +-
 tools/binman/cbfs_util.py |  4 ++--
 tools/binman/cbfs_util_test.py|  4 ++--
 tools/binman/control.py   |  6 ++---
 tools/binman/elf.py   |  6 ++---
 tools/binman/elf_test.py  |  8 +++
 tools/binman/entry.py |  6 ++---
 tools/binman/entry_test.py|  2 +-
 tools/binman/etype/_testing.py|  2 +-
 tools/binman/etype/atf_fip.py |  2 +-
 tools/binman/etype/blob.py|  4 ++--
 tools/binman/etype/blob_ext.py|  4 ++--
 tools/binman/etype/blob_ext_list.py   |  4 ++--
 tools/binman/etype/fdtmap.py  |  4 ++--
 tools/binman/etype/files.py   |  2 +-
 tools/binman/etype/fill.py|  2 +-
 tools/binman/etype/fit.py |  2 +-
 tools/binman/etype/fmap.py|  6 ++---
 tools/binman/etype/gbb.py |  4 ++--
 tools/binman/etype/intel_ifwi.py  |  2 +-
 tools/binman/etype/mkimage.py |  2 +-
 tools/binman/etype/null.py|  2 +-
 tools/binman/etype/pre_load.py|  2 +-
 tools/binman/etype/section.py |  6 ++---
 tools/binman/etype/text.py|  2 +-
 tools/binman/etype/u_boot_dtb_with_ucode.py   |  2 +-
 tools/binman/etype/u_boot_elf.py  |  2 +-
 tools/binman/etype/u_boot_env.py  |  2 +-
 tools/binman/etype/u_boot_spl_bss_pad.py  |  2 +-
 tools/binman/etype/u_boot_spl_expanded.py |  2 +-
 tools/binman/etype/u_boot_tpl_bss_pad.py  |  2 +-
 tools/binman/etype/u_boot_tpl_expanded.py |  2 +-
 .../binman/etype/u_boot_tpl_with_ucode_ptr.py |  4 ++--
 tools/binman/etype/u_boot_ucode.py|  2 +-
 tools/binman/etype/u_boot_vpl_bss_pad.py  |  2 +-
 tools/binman/etype/u_boot_vpl_expanded.py |  2 +-
 tools/binman/etype/u_boot_with_ucode_ptr.py   |  4 ++--
 tools/binman/etype/vblock.py  |  2 +-
 tools/binman/fdt_test.py  |  2 +-
 tools/binman/fip_util.py  |  4 ++--
 tools/binman/fip_util_test.py |  4 ++--
 tools/binman/fmap_util.py |  2 +-
 tools/binman/ftest.py |  8 +++
 tools/binman/image.py |  4 ++--
 tools/binman/image_test.py|  2 +-
 tools/binman/main.py  |  7 +++---
 tools/binman/state.py |  4 ++--
 tools/buildman/builder.py |  6 ++---
 tools/buildman/builderthread.py   |  2 +-
 tools/buildman/cfgutil.py |  2 +-
 tools/buildman/control.py |  8 +++
 tools/buildman/func_test.py   |  8 +++
 tools/buildman/main.py|  4 ++--
 tools/buildman/test.py|  8 +++
 tools/buildman/toolchain.py   |  6 ++---
 tools/dtoc/fdt.py |  2 +-
 tools/dtoc/fdt_util.py|  4 ++--
 tools/dtoc/main.py|  5 ++--
 tools/dtoc/test_dtoc.py   |  4 ++--
 tools/dtoc/test_fdt.py|  7 +++---
 tools/dtoc/test_src_scan.py   |  4 ++--
 tools/patman/__init__.py  |  7 +++---
 tools/patman/__main__.py  |  8 +++
 tools/patman/checkpatch.py|  4 ++--
 tools/patman/control.py   |  2 +-
 tools/patman/func_test.py |  6 ++---
 tools/patman/get_maintainer.py|  2 +-
 tools/patman/gitutil.py   |  4 ++--
 tools/patman/patchstream.py   |  2 +-
 tools/patman/series.py|  4 ++--
 tools/patman/status.py|  4 ++--
 tools/patman/test_settings.py |  2 +-
 tools/rmboard.py  |  2 +-
 tools/u_boot_pylib/__init__.py|  4 
 tools/u_boot_pylib/__main__.py| 23 +++
 tools/{patman => u_boot_pylib}/command.py |  2 

Re: [PATCH v4 1/2] bootflow: Rename bootflow_flags_t

2023-03-08 Thread Simon Glass
These flags actually relate to the iterator, not the bootflow struct
itself. Rename them.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/bootdev-uclass.c   | 16 ++---
 boot/bootflow.c | 20 
 cmd/bootflow.c  |  8 +++
 doc/develop/bootstd.rst | 12 +-
 include/bootflow.h  | 51 +
 test/boot/bootdev.c | 10 
 test/boot/bootflow.c|  2 +-
 7 files changed, 60 insertions(+), 59 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 05/24] script: Add a script to build a PyPi package

2023-03-08 Thread Simon Glass
Create a script which can package a tool for use with PyPi and the 'pip'
tool. This involves quite a few steps so is best automated. Future work
will enable use of this for some of the tools in U-Boot.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop test files
- Fix removable of the /tmp dir
- Quite a few updates to make things work with the new names

 scripts/make_pip.sh | 117 
 1 file changed, 117 insertions(+)
 create mode 100755 scripts/make_pip.sh

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 06/24] patman: Add support for building a u_boot_tools PyPi package

2023-03-08 Thread Simon Glass
Create the necessary files to build this new package.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile  |  18 +-
 tools/u_boot_pylib/LICENSE| 339 ++
 tools/u_boot_pylib/README.rst |  15 ++
 tools/u_boot_pylib/pyproject.toml |  22 ++
 4 files changed, 393 insertions(+), 1 deletion(-)
 create mode 100644 tools/u_boot_pylib/LICENSE
 create mode 100644 tools/u_boot_pylib/README.rst
 create mode 100644 tools/u_boot_pylib/pyproject.toml

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 01/24] binman: Avoid unwanted output in testFitFirmwareLoadables()

2023-03-08 Thread Simon Glass
This prints a message about the missing tee-os generated by the test. This
is confusing, so suppress it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/ftest.py | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 08/24] patman: Add support for building a patman PyPi package

2023-03-08 Thread Simon Glass
Create the necessary files to build this new package.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Rename the package to patch-manager

 Makefile|  1 +
 tools/patman/pyproject.toml | 29 +
 2 files changed, 30 insertions(+)
 create mode 100644 tools/patman/pyproject.toml

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 12/24] buildman: Use importlib to find the help

2023-03-08 Thread Simon Glass
Use this function so that the help can be found even when buildman is
running from a package.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to use importlib to find the help

 tools/buildman/control.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH 3/9] binman: Use correct argument name in docstrings

2023-03-08 Thread Simon Glass
On Sun, 19 Feb 2023 at 15:02, Jonas Karlman  wrote:
>
> Use correct argument name in docstrings.
>
> Signed-off-by: Jonas Karlman 
> ---
>  tools/binman/entry.py | 2 +-
>  tools/binman/etype/blob.py| 2 +-
>  tools/binman/etype/section.py | 4 ++--
>  3 files changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm/next, thanks!


Re: [PATCH 2/9] binman: Fix spelling of nodes in code comments

2023-03-08 Thread Simon Glass
On Sun, 19 Feb 2023 at 15:02, Jonas Karlman  wrote:
>
> Replace notes with nodes in code comments and docstrings.
>
> Signed-off-by: Jonas Karlman 
> ---
>  tools/binman/etype/fit.py | 2 +-
>  tools/binman/etype/section.py | 2 +-
>  tools/binman/state.py | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm/next, thanks!


Re: [PATCH 1/9] binman: Remove redundant SetAllowFakeBlob from blob-ext entry

2023-03-08 Thread Simon Glass
On Sun, 19 Feb 2023 at 15:02, Jonas Karlman  wrote:
>
> Entry_blob_ext contains an implementation of SetAllowFakeBlob that is
> identical to the one in the base Entry class, remove it.
>
> Signed-off-by: Jonas Karlman 
> ---
>  tools/binman/etype/blob_ext.py | 8 
>  1 file changed, 8 deletions(-)
>

Reviewed-by: Simon Glass 

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 07/24] patman: Avoid importing test_checkpatch before it is needed

2023-03-08 Thread Simon Glass
Tests are not packaged with patman so this file will not be accessible
when installing with pip. Move the import later in the file, when we
know the file is present.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to avoid importing test_checkpatch before it is needed

 tools/patman/__main__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 2/4] buildman: Write out the build command used

2023-03-08 Thread Simon Glass
It is sometimes useful to see the exact 'make' command used by buildman
for a commit. Add an output file for this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/buildman/builderthread.py | 13 +
 tools/buildman/buildman.rst |  8 
 tools/buildman/func_test.py | 13 +
 3 files changed, 34 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 3/4] buildman: Support disabling LTO

2023-03-08 Thread Simon Glass
This cuts down build performance considerably and is not always needed,
when checking for build errors, etc.

Add a flag to disable it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/buildman/builder.py   |  5 -
 tools/buildman/builderthread.py |  2 ++
 tools/buildman/buildman.rst | 14 ++
 tools/buildman/cmdline.py   |  2 ++
 tools/buildman/control.py   |  2 +-
 tools/buildman/func_test.py | 25 +
 6 files changed, 44 insertions(+), 6 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 4/4] buildman: Add a flag for reproducible builds

2023-03-08 Thread Simon Glass
This is quite a useful thing to use when building since it avoids small
size changes between commits. Add a -r flag for it.

Also undefine CONFIG_LOCALVERSION_AUTO since this appends the git hash
to the version string, causing every build to be slightly different.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop CONFIG_LOCALVERSION_AUTO also

 doc/build/reproducible.rst  |  2 ++
 tools/buildman/builder.py   |  4 +++-
 tools/buildman/builderthread.py |  2 ++
 tools/buildman/buildman.rst |  7 +++---
 tools/buildman/cmdline.py   |  2 ++
 tools/buildman/control.py   | 11 -
 tools/buildman/func_test.py | 40 +++--
 7 files changed, 56 insertions(+), 12 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 09/24] buildman: Move the main code into a function

2023-03-08 Thread Simon Glass
Put this code into a function so it is easy for it be run when packaged.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add patch to split out the main code into a function

 tools/buildman/main.py | 27 ---
 1 file changed, 16 insertions(+), 11 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 5/5] binman: Make the tooldir configurable

2023-03-08 Thread Simon Glass
Add a command-line argument for setting the tooldir, so that the default
can be overridden. Add this directory to the toolpath automatically.
Create the directory if it does not already exist.

Put the default in the argument parser instead of the class, so that it
is more obvious.

Update a few tests that expect the utility name to be provided without
any path (e.g. 'futility'), so they can accept a path, e.g.
/path/to/futility

Update the documentation and add a few tests.

Improve the help for --toolpath while we are here.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add comment about setting of tooldir
- Change default tooldir to an empty string
- Use exist_ok with os.makedirs()

 tools/binman/binman.rst  | 19 +++
 tools/binman/bintool.py  | 11 +--
 tools/binman/bintool_test.py | 11 ---
 tools/binman/cmdline.py  |  6 +-
 tools/binman/control.py  | 10 --
 tools/binman/ftest.py| 21 +++--
 6 files changed, 64 insertions(+), 14 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 03/24] Remove concurrencytest

2023-03-08 Thread Simon Glass
While our version is better, it is tricky to use it when we are trying
to package things with pip. Drop it.

Somewhat reduced functionality is provided by the upstream version[1],
along with a rather annoying message each time it is used[2] [3].

[1] pip install concurrencytest
[2] https://github.com/cgoldberg/concurrencytest/issues/12
[3] https://github.com/cgoldberg/concurrencytest/pull/14

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/concurrencytest/.gitignore |   1 -
 tools/concurrencytest/README.md  |  74 
 tools/concurrencytest/__init__.py|   0
 tools/concurrencytest/concurrencytest.py | 144 ---
 tools/patman/test_util.py|   4 +-
 5 files changed, 2 insertions(+), 221 deletions(-)
 delete mode 100644 tools/concurrencytest/.gitignore
 delete mode 100644 tools/concurrencytest/README.md
 delete mode 100644 tools/concurrencytest/__init__.py
 delete mode 100644 tools/concurrencytest/concurrencytest.py

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 04/32] cmd: fdt: Fix fdt rsvmem behavior on non-existent index and error message space

2023-03-08 Thread Simon Glass
In case 'fdt rsvmem delete index' is passed a non-existent index, one
which does not exist in 'fdt rsvmem print', then the following command
triggers a print of help message for 'fdt' command instead of erroring
out:
=> fdt rsvmem delete 1234
This is because the subcommand errornously returns 'err' instead of
CMD_RET_FAILURE, fix it. Furthermore, align the number of spaces past
fdt_del_mem_rsv() and fdt_add_mem_rsv() in error message with the rest
of the code.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 11/24] buildman: Fix use of a type as a variable

2023-03-08 Thread Simon Glass
Using 'str' as a variable makes it impossible to use it as a type in the
same function. Fix this by using a different name.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add patch to fix use of a type as a variable

 tools/buildman/control.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 13/24] buildman: Add support for building a buildman PyPi package

2023-03-08 Thread Simon Glass
Create the necessary files to build this new package.

It is not actually clear whether this is useful, since buildman has no
purpose outside U-Boot. It is included for completeness, since adding
this later would be more trouble.

Move the main program into a function so that it can easily be called by
the PyPi-created script.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile  |  1 +
 tools/buildman/pyproject.toml | 29 +
 2 files changed, 30 insertions(+)
 create mode 100644 tools/buildman/pyproject.toml

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 10/24] buildman: Hide the test options unless test code is available

2023-03-08 Thread Simon Glass
It doesn't make much sense to expose tests when buildman is running
outside of the U-Boot git checkout. Hide the option in this case

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add a patch to hide the test options unless test code is available

 tools/buildman/cmdline.py | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 14/24] dtoc: Hide the test options unless test code is available

2023-03-08 Thread Simon Glass
It doesn't make much sense to expose tests when dtoc is running
outside of the U-Boot git checkout. Hide the option in this case.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add a patch to hide the test options unless test code is available

 tools/dtoc/main.py | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 15/24] dtoc: Move the main code into a function

2023-03-08 Thread Simon Glass
Put this code into a function so it is easy for it be run when packaged.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add patch to split out the main code into a function

 tools/dtoc/main.py | 100 +++--
 1 file changed, 52 insertions(+), 48 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 17/24] dtoc: Add support for building a dtoc PyPi package

2023-03-08 Thread Simon Glass
Create the necessary files to build this new package.

This is needed for binman.

Move the main program into a function so that it can easily be called by
the PyPi-created script.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile  |  1 +
 tools/dtoc/README.rst | 15 +++
 tools/dtoc/pyproject.toml | 26 ++
 3 files changed, 42 insertions(+)
 create mode 100644 tools/dtoc/README.rst
 create mode 100644 tools/dtoc/pyproject.toml

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 18/24] binman: Move the main code into a function

2023-03-08 Thread Simon Glass
Put this code into a function so it is easy for it be run when packaged.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add patch to split out the main code into a function

 tools/binman/main.py | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 16/24] dtoc: Use pathlib to find the test directory

2023-03-08 Thread Simon Glass
Update this so that the directory being used is declared at the top of
the file. Use pathlib as it seems to be more modern.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/test_dtoc.py | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 19/24] binman: Hide the 'test' command unless test code is available

2023-03-08 Thread Simon Glass
It doesn't make much sense to expose tests when dtoc is running
outside of the U-Boot git checkout. Hide the option in this case.

Fix a long line while we are here.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add a patch to hide the test options unless test code is available

 tools/binman/cmdline.py | 34 +-
 1 file changed, 21 insertions(+), 13 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 20/24] binman: Use importlib to find the help

2023-03-08 Thread Simon Glass
Use this function so that the help can be found even when binman is
running from a package.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to use importlib to find the help

 tools/binman/control.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 23/24] doc: Add notes on how to install patman and binman

2023-03-08 Thread Simon Glass
These can be installed with 'pip' now. Add the details for those who are
interested.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/binman.rst | 13 +
 tools/patman/patman.rst | 12 
 2 files changed, 25 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 03/32] cmd: fdt: Fix fdt rm behavior on non-existent property and error message space

2023-03-08 Thread Simon Glass
In case an FDT contains a node '/test-node@1234' , with no property
called 'noprop' in that node, the following command triggers a print
of help message for 'fdt' command instead of erroring out:
=> fdt rm /test-node@1234 noprop
This is because the subcommand errornously returns 'err' instead of
CMD_RET_FAILURE, fix it. Furthermore, align the number of spaces past
fdt_delprop() in error message with the rest of the code.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 06/32] cmd: fdt: Check argc before accessing argv in fdt memory

2023-03-08 Thread Simon Glass
On case 'fdt memory' is invoked without parameters, argv[2]/argv[3]
is not valid and this command would SEGFAULT in sandbox environment.
Add missing argc test to avoid the crash and rather print usage help
message.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 4 
 1 file changed, 4 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 22/24] test: Add concurrencytest to the requirements

2023-03-08 Thread Simon Glass
This allows tests to run in parallel and speeds up some tests markedly,
particularly with binman. Add it to the requirements.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 test/py/requirements.txt | 1 +
 1 file changed, 1 insertion(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 02/32] cmd: fdt: Fix handling of empty properties for fdt get addr and fdt get size

2023-03-08 Thread Simon Glass
Hi Marek,

On Wed, 1 Mar 2023 at 20:09, Marek Vasut
 wrote:
>
> It is perfectly valid to request an address or size of FDT property
> without value, the only special case if requesting of the value of
> FDT property without value. Invert the test such, that properties
> without value still set the variable from 'fdt get addr/size' to
> address of the property or size of the property, where the later
> is 0.
>
> Signed-off-by: Marek Vasut 
> Reviewed-by: Simon Glass 
> ---
> Cc: Heinrich Schuchardt 
> Cc: Simon Glass 
> Cc: Tom Rini 
> ---
> V2: Add RB from Simon

BTW 'patman status' can collect review tags and add them to your
commits automatically.

Regards,
Simon

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 21/24] binman: Add support for building a binmanu PyPi package

2023-03-08 Thread Simon Glass
Create the necessary files to build this new package.

It is not actually clear whether this is useful, since buildman has no
purpose outside U-Boot.

Move the main program into a function so that it can easily be called by
the PyPi-created script.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile|  1 +
 tools/binman/pyproject.toml | 29 +
 2 files changed, 30 insertions(+)
 create mode 100644 tools/binman/pyproject.toml

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 24/24] CI: Add a check for building tools for PyPi

2023-03-08 Thread Simon Glass
Add a simple check that the PyPi packages can be built.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Update the cover letter

 .azure-pipelines.yml | 10 ++
 .gitlab-ci.yml   |  6 ++
 2 files changed, 16 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 01/32] cmd: fdt: Import is_printable_string() from DTC to fix u32 misprint

2023-03-08 Thread Simon Glass
Import is_printable_string() implementation from DTC 1.7.0 as of
DTC commit 039a994 ("Bump version to v1.7.0") . This fixes a print
of u32 property which so far used to be printed as string by U-Boot
fdt print command.

We might see the case where the parsed property value, in this case
it is a 32-bit integer, identified as a printable string or a null byte
(concatenated strings) because of its last character happens to be:
  0x00 (null character), 0xB (vertical tab character) or
  0x10 (line feed character)
In this situation, if the string is identified as printable string,
it will be displayed as character instead of hex value

When the isprint() condition is true, there are two possibilities:
  1) The character is ASCII character (except the first 32)
  2) The character is extended ASCII character

For example,
NG property in device tree:
clock-frequency = <1664>;
by default, would be displayed as
clock-frequency = "", "ýè";
and with this patch applied, would be displayed as
clock-frequency = <0x00fde800>;

Full investigation was done by Nam and Hai, patch reworked by Marek
to use common code from DTC.

Signed-off-by: Hai Pham 
Signed-off-by: Nam Nguyen 
Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 36 ++--
 1 file changed, 14 insertions(+), 22 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 18/32] test: cmd: fdt: Test fdt resize

2023-03-08 Thread Simon Glass
Add 'fdt resize' test which works as follows:
- Create simple FDT with extra size 0, map it to sysmem
- 'resize' the FDT by 0x2000 bytes
- Verify the new space has been added to the FDT

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 24 
 1 file changed, 24 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 07/32] cmd: fdt: Align checksign parameter names in help text

2023-03-08 Thread Simon Glass
The help text references 'addr' as an optional key start address,
but the explanation references the same as 'start', make sure they
both read as 'addr'. Also update the abbreviated 'addr' in the
explanation to 'address'.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 25/32] test: cmd: fdt: Test fdt rm

2023-03-08 Thread Simon Glass
Add 'fdt rm' test which works as follows:
- Create fuller FDT, map it to sysmem
- Selectively delete nodes or properties by both path and aliases
- Verify created nodes or properties using fdt print command

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 84 ++
 1 file changed, 84 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 05/32] cmd: fdt: Check argc before accessing argv in fdt bootcpu

2023-03-08 Thread Simon Glass
On case 'fdt bootcpu' is invoked without parameters, argv[2] is not
valid and this command would SEGFAULT in sandbox environment. Add
missing argc test to avoid the crash and rather print usage help
message.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 14/32] test: cmd: fdt: Generate fuller DT internally and switch fdt get value to it

2023-03-08 Thread Simon Glass
Implement function to generate internal test DT fragment and switch
the 'fdt get value' test to this instead of depending on the sandbox
DT. Rename clk-test node to test-node node. This FDT fragment will be
reused by other tests. No functional change.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 124 +++--
 1 file changed, 111 insertions(+), 13 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 17/32] test: cmd: fdt: Test fdt move

2023-03-08 Thread Simon Glass
Add 'fdt move' test which works as follows:
- Create simple FDT, map it to sysmem
- 'move' the FDT into new zeroed out sysmem location
- Verify newly active FDT is in the new location
- Compare both locations

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 34 ++
 1 file changed, 34 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 22/32] test: cmd: fdt: Test fdt get size

2023-03-08 Thread Simon Glass
Add 'fdt get size' test which works as follows:
- Create fuller FDT, map it to sysmem
- Get size of various properties
- Get node count of available nodes
- Test non-existent nodes and properties

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 87 ++
 1 file changed, 87 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 08/32] cmd: fdt: Handle 64bit pointers in fdt get addr

2023-03-08 Thread Simon Glass
The command assumed 32bit pointers so far, with 64bit pointer the
command would overwrite a piece of stack. Fix it by extending the
array size to cater for 64bit pointer, and use snprintf() to avoid
writing past the end of the array ever again.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 10/32] cmd: fdt: Add support for integer arrays in fdt get value with index

2023-03-08 Thread Simon Glass
Currently any integer array value is set as long up-to-40 character
hexadecimal string into environment variable when extracted from an
FDT using 'fdt get value path prop index', because the support for
handling integer arrays is not implemented, and fdt_value_env_set()
code falls back into the hash handling behavior instead.

Implement this support simply by checking whether user supplied any
index. If index is set and the property length is multiple of four,
then this is an integer array, and the code would extract value at
specified index.

There is a subtle change where default index is set to -1 instead of 0.
This is OK, since the only place which checks for index to be less or
equal zero is the string array handling code in fdt_value_env_set() and
that code would work perfectly well with index -1 too.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 12/32] test: cmd: fdt: Rename fdt_test_resize() to fdt_test_addr_resize()

2023-03-08 Thread Simon Glass
The 'fdt' command has a 'resize' subcommand, rename the fdt_test_resize()
to fdt_test_addr_resize() to avoid confusion about what it is testing.
There is currently no resize test.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 09/32] cmd: fdt: Map address returned from fdt get addr to sysmem

2023-03-08 Thread Simon Glass
The address returned from 'fdt get addr' command must be mapped
into sysmem, as this is a working FDT. Access to this address
without mapping it would lead to crash e.g. in sandbox.

The following command triggers the crash:
"
./u-boot -Dc 'fdt addr $fdtcontroladdr ; fdt get addr var / compatible
; md $var'
"

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 cmd/fdt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 15/32] test: cmd: fdt: Test alias resolution in 'fdt get value'

2023-03-08 Thread Simon Glass
The 'fdt' command help contains the following note:
"
Dereference aliases by omitting the leading '/', e.g. fdt print ethernet0.
"
Add test for it.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 65 ++
 1 file changed, 45 insertions(+), 20 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 11/32] test: Add ut_assert_nextline_empty() empty line helper

2023-03-08 Thread Simon Glass
Add helper macro to test for empty lines, which is an inobvious
wrapper around ut_assert_nextline("%s", "") .

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 include/test/ut.h | 4 
 1 file changed, 4 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 16/32] test: cmd: fdt: Test both string and integer arrays in 'fdt get value'

2023-03-08 Thread Simon Glass
The 'fdt get value' subcommand now supports extraction of integer value
from integer arrays, add test for it, including a test for special case
unindexed integer array read, which is handled as hash and treated as a
long string instead of integer.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 58 --
 1 file changed, 42 insertions(+), 16 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 13/32] test: cmd: fdt: Rename fdt_test_get() to fdt_test_get_value()

2023-03-08 Thread Simon Glass
The 'fdt get' command has a 'get value' subcommand, rename the fdt_test_get()
to fdt_test_get_value() to avoid confusion about what it is testing. There is
currently no get 'get name', 'get addr', 'get size' subcommand test.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 20/32] test: cmd: fdt: Test fdt get name

2023-03-08 Thread Simon Glass
Add 'fdt get name' test which works as follows:
- Create fuller FDT, map it to sysmem
- Get name of / node 0, 1 and /clk-test node 0
- Compare output and validate the node name
- Get name of / node 2 and /clk-test node 1
- Compare output and validate the node is not present
- Get name of / node -1 and /clk-test node -1
- Compare output and validate the node name equals node 0 name
- Check nonexistent node, verify the command errors out

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 79 ++
 1 file changed, 79 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 23/32] test: cmd: fdt: Test fdt set

2023-03-08 Thread Simon Glass
Add 'fdt set' test which works as follows:
- Create fuller FDT, map it to sysmem
- Set either existing property to overwrite it, or new property
- Test setting both single properties as well as string and integer arrays
- Test setting to non-existent nodes and aliases
- Verify set values using 'fdt get value'

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add comments
---
 test/cmd/fdt.c | 144 +
 1 file changed, 144 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 32/32] test: cmd: fdt: Add list of remaining missing tests

2023-03-08 Thread Simon Glass
Add list of missing tests for the 'fdt' command, currently
the missing sandbox tests are only 'fdt boardsetup' and
'fdt checksign' .

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 7 +++
 1 file changed, 7 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 27/32] test: cmd: fdt: Test fdt bootcpu

2023-03-08 Thread Simon Glass
Add 'fdt bootcpu' test which works as follows:
- Create basic FDT, map it to sysmem
- Print the FDT bootcpu
- Set the FDT bootcpu and read the value back using 'fdt header get'
- Perform the previous step twice to validate bootcpu overwrite

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 33 +
 1 file changed, 33 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v2 24/32] test: cmd: fdt: Test fdt mknode

2023-03-08 Thread Simon Glass
Add 'fdt mknode' test which works as follows:
- Create fuller FDT, map it to sysmem
- Create node either in / or subnode
- Attempt to create node over existing node, which fails
- Attempt to create subnodes in non-existing nodes or aliases
- Verify created nodes using fdt list command

The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.

Signed-off-by: Marek Vasut 
Reviewed-by: Simon Glass 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
V2: Add RB from Simon
---
 test/cmd/fdt.c | 68 ++
 1 file changed, 68 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 1/4] patman: Drop an incorrect comment about git am

2023-03-08 Thread Simon Glass
Patman does not do this anymore, as of this commit:

   7428dc14b0f ("patman: Remove the -a option")

Drop the comment.

Signed-off-by: Simon Glass 
Reviewed-by: Douglas Anderson 
---

Changes in v3:
- Mention the commit where the -a option was dropped

Changes in v2:
- Fix 'uncorrect' typo in subject

 tools/patmanu/control.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH] buildman: Correct CROSS_COMPILE output for sandbox

2023-03-08 Thread Simon Glass
At present, 'buildman -A sandbox' adds the path containing the
toolchain at present. We can assume that this is in the path and
we don't want to set CROSS_COMPILE=/bin/ so change this to align
with what MakeEnvironment() does.

Signed-off-by: Simon Glass 
---

 tools/buildman/toolchain.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 2/4] patman: Refactor MakeCcFile() into two functions

2023-03-08 Thread Simon Glass
This function is quite long. Moving the handling of a commit into a
separate function. This will make it easier to do the work in parallel.

Update function comments while we are here.

Signed-off-by: Simon Glass 
Reviewed-by: Douglas Anderson 
---

Changes in v3:
- Reword comment for all_skips
- Sort the set directly instead of converting it to a list first

Changes in v2:
- Fix missing 'f' on format string

 tools/patmanu/series.py | 81 +
 1 file changed, 57 insertions(+), 24 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 4/4] patman: Check patches in parallel

2023-03-08 Thread Simon Glass
For large series this can take a while. Run checkpatch in parallel to
try to reduce the time. The checkpatch information is still reported in
sequential order, so a very slow patch at the start can still slow
things down. But overall this gives good results.

Signed-off-by: Simon Glass 
Reviewed-by: Douglas Anderson 
---

(no changes since v1)

 tools/patmanu/checkpatch.py | 46 +
 1 file changed, 26 insertions(+), 20 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 3/4] patman: Run get_maintainer.pl in parallel

2023-03-08 Thread Simon Glass
This script can take ages on some series. Try to limit the time by
using threads. If a few stubborn patches remain, show progress so the
user has some idea what is going on.

Signed-off-by: Simon Glass 
Reviewed-by: Douglas Anderson 
---

(no changes since v1)

 tools/patmanu/func_test.py |  2 ++
 tools/patmanu/series.py| 33 ++---
 2 files changed, 32 insertions(+), 3 deletions(-)

Applied to u-boot-dm/next, thanks!


[PATCH v2] nand: brcmnand: add iproc support

2023-03-08 Thread Linus Walleij
Add support for the iproc Broadcom NAND controller,
used in Northstar SoCs for example. Based on the Linux
driver.

Cc: Philippe Reynes 
Cc: Dario Binacchi 
Reviewed-by: Michael Trimarchi 
Signed-off-by: Linus Walleij 
---
ChangeLog v1->v2:
- Check return value of dev_read_resource()
- Use devm_ioremap()
- Collect Michael's Review tag
---
 drivers/mtd/nand/raw/Kconfig   |   7 +
 drivers/mtd/nand/raw/brcmnand/Makefile |   1 +
 drivers/mtd/nand/raw/brcmnand/iproc_nand.c | 148 +
 3 files changed, 156 insertions(+)
 create mode 100644 drivers/mtd/nand/raw/brcmnand/iproc_nand.c

diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
index 5b35da45f584..6a13bc1e228a 100644
--- a/drivers/mtd/nand/raw/Kconfig
+++ b/drivers/mtd/nand/raw/Kconfig
@@ -156,6 +156,13 @@ config NAND_BRCMNAND_63158
help
  Enable support for broadcom nand driver on bcm63158.
 
+config NAND_BRCMNAND_IPROC
+   bool "Support Broadcom NAND controller on the iproc family"
+   depends on NAND_BRCMNAND
+   help
+ Enable support for broadcom nand driver on the Broadcom
+ iproc family such as Northstar (BCM5301x, BCM4708...)
+
 config NAND_DAVINCI
bool "Support TI Davinci NAND controller"
select SYS_NAND_SELF_INIT if TARGET_DA850EVM
diff --git a/drivers/mtd/nand/raw/brcmnand/Makefile 
b/drivers/mtd/nand/raw/brcmnand/Makefile
index f46a7edae321..0c6325aaa618 100644
--- a/drivers/mtd/nand/raw/brcmnand/Makefile
+++ b/drivers/mtd/nand/raw/brcmnand/Makefile
@@ -6,5 +6,6 @@ obj-$(CONFIG_NAND_BRCMNAND_6753) += bcm6753_nand.o
 obj-$(CONFIG_NAND_BRCMNAND_68360) += bcm68360_nand.o
 obj-$(CONFIG_NAND_BRCMNAND_6838) += bcm6838_nand.o
 obj-$(CONFIG_NAND_BRCMNAND_6858) += bcm6858_nand.o
+obj-$(CONFIG_NAND_BRCMNAND_IPROC) += iproc_nand.o
 obj-$(CONFIG_NAND_BRCMNAND) += brcmnand.o
 obj-$(CONFIG_NAND_BRCMNAND) += brcmnand_compat.o
diff --git a/drivers/mtd/nand/raw/brcmnand/iproc_nand.c 
b/drivers/mtd/nand/raw/brcmnand/iproc_nand.c
new file mode 100644
index ..69711d98ce1b
--- /dev/null
+++ b/drivers/mtd/nand/raw/brcmnand/iproc_nand.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Code borrowed from the Linux driver
+ * Copyright (C) 2015 Broadcom Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "brcmnand.h"
+
+struct iproc_nand_soc {
+   struct brcmnand_soc soc;
+   void __iomem *idm_base;
+   void __iomem *ext_base;
+};
+
+#define IPROC_NAND_CTLR_READY_OFFSET   0x10
+#define IPROC_NAND_CTLR_READY  BIT(0)
+
+#define IPROC_NAND_IO_CTRL_OFFSET  0x00
+#define IPROC_NAND_APB_LE_MODE BIT(24)
+#define IPROC_NAND_INT_CTRL_READ_ENABLEBIT(6)
+
+static bool iproc_nand_intc_ack(struct brcmnand_soc *soc)
+{
+   struct iproc_nand_soc *priv =
+   container_of(soc, struct iproc_nand_soc, soc);
+   void __iomem *mmio = priv->ext_base + IPROC_NAND_CTLR_READY_OFFSET;
+   u32 val = brcmnand_readl(mmio);
+
+   if (val & IPROC_NAND_CTLR_READY) {
+   brcmnand_writel(IPROC_NAND_CTLR_READY, mmio);
+   return true;
+   }
+
+   return false;
+}
+
+static void iproc_nand_intc_set(struct brcmnand_soc *soc, bool en)
+{
+   struct iproc_nand_soc *priv =
+   container_of(soc, struct iproc_nand_soc, soc);
+   void __iomem *mmio = priv->idm_base + IPROC_NAND_IO_CTRL_OFFSET;
+   u32 val = brcmnand_readl(mmio);
+
+   if (en)
+   val |= IPROC_NAND_INT_CTRL_READ_ENABLE;
+   else
+   val &= ~IPROC_NAND_INT_CTRL_READ_ENABLE;
+
+   brcmnand_writel(val, mmio);
+}
+
+static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare,
+ bool is_param)
+{
+   struct iproc_nand_soc *priv =
+   container_of(soc, struct iproc_nand_soc, soc);
+   void __iomem *mmio = priv->idm_base + IPROC_NAND_IO_CTRL_OFFSET;
+   u32 val;
+
+   val = brcmnand_readl(mmio);
+
+   /*
+* In the case of BE or when dealing with NAND data, always configure
+* the APB bus to LE mode before accessing the FIFO and back to BE mode
+* after the access is done
+*/
+   if (IS_ENABLED(CONFIG_SYS_BIG_ENDIAN) || !is_param) {
+   if (prepare)
+   val |= IPROC_NAND_APB_LE_MODE;
+   else
+   val &= ~IPROC_NAND_APB_LE_MODE;
+   } else { /* when in LE accessing the parameter page, keep APB in BE */
+   val &= ~IPROC_NAND_APB_LE_MODE;
+   }
+
+   brcmnand_writel(val, mmio);
+}
+
+static int iproc_nand_probe(struct udevice *dev)
+{
+   struct udevice *pdev = dev;
+   struct iproc_nand_soc *priv = dev_get_priv(dev);
+   struct brcmnand_soc *soc;
+   struct resource res;
+   int ret;
+
+   soc = &priv->soc;
+
+   ret = dev_read_resou

[PATCH v2] mtd: rawnand: nand_base: Handle algorithm selection

2023-03-08 Thread Linus Walleij
For BRCMNAND with 1-bit BCH ECC (BCH-1) such as used on the
D-Link DIR-885L and DIR-890L routers, we need to explicitly
select the ECC like this in the device tree:

  nand-ecc-algo = "bch";
  nand-ecc-strength = <1>;
  nand-ecc-step-size = <512>;

This is handled by the Linux kernel but U-Boot core does
not respect this. Fix it up by parsing the algorithm and
preserve the behaviour using this property to select
software BCH as far as possible.

Signed-off-by: Linus Walleij 
---
ChangeLog v1->v2:
- Drop pointless check for ecc_algo >= 0, it is always
  >= 0.
---
 drivers/mtd/nand/raw/nand_base.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 9eba360d55f3..c173fd09237a 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4487,6 +4487,7 @@ EXPORT_SYMBOL(nand_detect);
 static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode 
node)
 {
int ret, ecc_mode = -1, ecc_strength, ecc_step;
+   int ecc_algo = NAND_ECC_UNKNOWN;
const char *str;
 
ret = ofnode_read_s32_default(node, "nand-bus-width", -1);
@@ -4512,10 +4513,13 @@ static int nand_dt_init(struct mtd_info *mtd, struct 
nand_chip *chip, ofnode nod
ecc_mode = NAND_ECC_SOFT_BCH;
}
 
-   if (ecc_mode == NAND_ECC_SOFT) {
-   str = ofnode_read_string(node, "nand-ecc-algo");
-   if (str && !strcmp(str, "bch"))
+   str = ofnode_read_string(node, "nand-ecc-algo");
+   if (str && !strcmp(str, "bch")) {
+   ecc_algo = NAND_ECC_BCH;
+   if (ecc_mode == NAND_ECC_SOFT)
ecc_mode = NAND_ECC_SOFT_BCH;
+   } else if (!strcmp(str, "hamming")) {
+   ecc_algo = NAND_ECC_HAMMING;
}
 
ecc_strength = ofnode_read_s32_default(node,
@@ -4529,6 +4533,8 @@ static int nand_dt_init(struct mtd_info *mtd, struct 
nand_chip *chip, ofnode nod
return -EINVAL;
}
 
+   chip->ecc.algo = ecc_algo;
+
if (ecc_mode >= 0)
chip->ecc.mode = ecc_mode;
 
-- 
2.39.1



[PATCH v9 3/6] tpm: Support boot measurements

2023-03-08 Thread Eddie James
Add TPM2 functions to support boot measurement. This includes
starting up the TPM, initializing/appending the event log, and
measuring the U-Boot version. Much of the code was used in the
EFI subsystem, so remove it there and use the common functions.

Signed-off-by: Eddie James 
---
Changes since v8:
 - Fix log parsing again - any data corruption seen while replaying the
   event log was failing the entire measurement.
 - Added an option to ignore the existing log. This should only be used
   for systems that know that U-Boot is the first stage bootloader. This
   is necessary because the reserved memory region may persist through
   resets and so U-Boot attempts to append to the previous boot's log.

Changes since v7:
 - Change name of tcg2_init_log and add more documentation
 - Add a check, when parsing the event log header, to ensure that the
   previous stage bootloader used all the active PCRs.
 - Change name of tcg2_log_find_end
 - Fix the greater than or equal to check to exit the log parsing
 - Make sure log_position is 0 if there is any error discovering the log
 - Return errors parsing the log if the data is corrupt so that we don't
   end up with half a log

Changes since v6:
 - Added Linaro copyright for all the EFI moved code
 - Changed tcg2_init_log (and by extension, tcg2_measurement_init) to
   copy any discovered event log to the user's log if passed in.

Changes since v5:
 - Remove unused platform_get_eventlog in efi_tcg2.c
 - First look for tpm_event_log_* properties instead of linux,sml-*
 - Fix efi_tcg2.c compilation
 - Select SHA* configs

Changes since v4:
 - Remove tcg2_measure_event function and check for NULL data in
   tcg2_measure_data
 - Use tpm_auto_startup
 - Fix efi_tcg2.c compilation for removing tcg2_pcr_read function

Changes since v3:
 - Reordered headers
 - Refactored more of EFI code into common code
Removed digest_info structure and instead used the common alg_to_mask
  and alg_to_len
Improved event log parsing in common code to get it equivalent to EFI
  Common code now extends PCR if previous bootloader stage couldn't
  No need to allocate memory in the common code, so EFI copies the
  discovered buffer like it did before
Rename efi measure_event function

Changes since v1:
 - Refactor TPM layer functions to allow EFI system to use them, and
   remove duplicate EFI functions

 include/efi_tcg2.h|   44 --
 include/tpm-v2.h  |  259 +
 lib/Kconfig   |4 +
 lib/efi_loader/efi_tcg2.c | 1054 +++--
 lib/tpm-v2.c  |  814 
 5 files changed, 1154 insertions(+), 1021 deletions(-)

diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h
index b1c3abd097..b21c5cb3dd 100644
--- a/include/efi_tcg2.h
+++ b/include/efi_tcg2.h
@@ -129,50 +129,6 @@ struct efi_tcg2_boot_service_capability {
 #define BOOT_SERVICE_CAPABILITY_MIN \
offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
 
-#define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03"
-#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2
-#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0
-#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2
-
-/**
- *  struct TCG_EfiSpecIdEventAlgorithmSize - hashing algorithm information
- *
- *  @algorithm_id: algorithm defined in enum tpm2_algorithms
- *  @digest_size:  size of the algorithm
- */
-struct tcg_efi_spec_id_event_algorithm_size {
-   u16  algorithm_id;
-   u16  digest_size;
-} __packed;
-
-/**
- * struct TCG_EfiSpecIDEventStruct - content of the event log header
- *
- * @signature: signature, set to Spec ID Event03
- * @platform_class:class defined in TCG ACPI Specification
- * Client  Common Header.
- * @spec_version_minor:minor version
- * @spec_version_major:major version
- * @spec_version_errata:   major version
- * @uintn_size:size of the efi_uintn_t fields used in 
various
- * data structures used in this specification.
- * 0x01 indicates u32  and 0x02  indicates u64
- * @number_of_algorithms:  hashing algorithms used in this event log
- * @digest_sizes:  array of number_of_algorithms pairs
- * 1st member defines the algorithm id
- * 2nd member defines the algorithm size
- */
-struct tcg_efi_spec_id_event {
-   u8 signature[16];
-   u32 platform_class;
-   u8 spec_version_minor;
-   u8 spec_version_major;
-   u8 spec_errata;
-   u8 uintn_size;
-   u32 number_of_algorithms;
-   struct tcg_efi_spec_id_event_algorithm_size digest_sizes[];
-} __packed;
-
 /**
  * struct tdEFI_TCG2_FINAL_EVENTS_TABLE - log entries after Get Event Log
  * @version:   version number for this structure
diff --git a/includ

[PATCH v9 6/6] doc: Add measured boot documentation

2023-03-08 Thread Eddie James
Briefly describe the feature and specify the requirements.

Signed-off-by: Eddie James 
Reviewed-by: Simon Glass 
---
 doc/usage/index.rst |  1 +
 doc/usage/measured_boot.rst | 23 +++
 2 files changed, 24 insertions(+)
 create mode 100644 doc/usage/measured_boot.rst

diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 840c20c934..1cb6988d8a 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -12,6 +12,7 @@ Use U-Boot
partitions
cmdline
semihosting
+   measured_boot
 
 Shell commands
 --
diff --git a/doc/usage/measured_boot.rst b/doc/usage/measured_boot.rst
new file mode 100644
index 00..8357b1f480
--- /dev/null
+++ b/doc/usage/measured_boot.rst
@@ -0,0 +1,23 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Measured Boot
+=
+
+U-Boot can perform a measured boot, the process of hashing various components
+of the boot process, extending the results in the TPM and logging the
+component's measurement in memory for the operating system to consume.
+
+Requirements
+-
+
+* A hardware TPM 2.0 supported by the U-Boot drivers
+* CONFIG_TPM=y
+* CONFIG_MEASURED_BOOT=y
+* Device-tree configuration of the TPM device to specify the memory area
+  for event logging. The TPM device node must either contain a phandle to
+  a reserved memory region or "linux,sml-base" and "linux,sml-size"
+  indicating the address and size of the memory region. An example can be
+  found in arch/sandbox/dts/test.dts
+* The operating system must also be configured to use the memory regions
+  specified in the U-Boot device-tree in order to make use of the event
+  log.
-- 
2.31.1



[PATCH v9 4/6] bootm: Support boot measurement

2023-03-08 Thread Eddie James
Add a configuration option to measure the boot through the bootm
function. Add the measurement state to the booti and bootz paths
as well.

Signed-off-by: Eddie James 
Reviewed-by: Simon Glass 
---
Changes since v8:
 - Added a configuration option to select to ignore any existing
   event log. This would only be selected for systems that know
   that U-Boot is the first stage bootloader. This is necessary
   because the reserved memory region may persist through resets
   and so U-Boot attempts to append to the previous boot's log.

Changes since v6:
 - Added comment for bootm_measure
 - Fixed line length in bootm_measure

 boot/Kconfig| 32 +
 boot/bootm.c| 74 +
 cmd/booti.c |  1 +
 cmd/bootm.c |  2 ++
 cmd/bootz.c |  1 +
 include/bootm.h | 11 
 include/image.h |  1 +
 7 files changed, 122 insertions(+)

diff --git a/boot/Kconfig b/boot/Kconfig
index 5f491625c8..8119519c9f 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -629,6 +629,38 @@ config LEGACY_IMAGE_FORMAT
  loaded. If a board needs the legacy image format support in this
  case, enable it here.
 
+config MEASURED_BOOT
+   bool "Measure boot images and configuration to TPM and event log"
+   depends on HASH && TPM_V2
+   help
+ This option enables measurement of the boot process. Measurement
+ involves creating cryptographic hashes of the binary images that
+ are booting and storing them in the TPM. In addition, a log of
+ these hashes is stored in memory for the OS to verify the booted
+ images and configuration. Enable this if the OS has configured
+ some memory area for the event log and you intend to use some
+ attestation tools on your system.
+
+if MEASURED_BOOT
+   config MEASURE_DEVICETREE
+   bool "Measure the devicetree image"
+   default y if MEASURED_BOOT
+   help
+ On some platforms, the devicetree is not static as it may contain
+ random MAC addresses or other such data that changes each boot.
+ Therefore, it should not be measured into the TPM. In that case,
+ disable the measurement here.
+
+   config MEASURE_IGNORE_LOG
+   bool "Ignore the existing event log"
+   default n
+   help
+ On platforms that use an event log memory region that persists
+ through system resets and are the first stage bootloader, then
+ this option should be enabled to ignore any existing data in the
+ event log memory region.
+endif # MEASURED_BOOT
+
 config SUPPORT_RAW_INITRD
bool "Enable raw initrd images"
help
diff --git a/boot/bootm.c b/boot/bootm.c
index 2eec60ec7b..2685bdbd74 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #if defined(CONFIG_CMD_USB)
 #include 
 #endif
@@ -659,6 +660,75 @@ int bootm_process_cmdline_env(int flags)
return 0;
 }
 
+int bootm_measure(struct bootm_headers *images)
+{
+   int ret = 0;
+
+   /* Skip measurement if EFI is going to do it */
+   if (images->os.os == IH_OS_EFI &&
+   IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL) &&
+   IS_ENABLED(CONFIG_BOOTM_EFI))
+   return ret;
+
+   if (IS_ENABLED(CONFIG_MEASURED_BOOT)) {
+   struct tcg2_event_log elog;
+   struct udevice *dev;
+   void *initrd_buf;
+   void *image_buf;
+   const char *s;
+   u32 rd_len;
+   bool ign;
+
+   elog.log_size = 0;
+   ign = IS_ENABLED(CONFIG_MEASURE_IGNORE_LOG);
+   ret = tcg2_measurement_init(&dev, &elog, ign);
+   if (ret)
+   return ret;
+
+   image_buf = map_sysmem(images->os.image_start,
+  images->os.image_len);
+   ret = tcg2_measure_data(dev, &elog, 8, images->os.image_len,
+   image_buf, EV_COMPACT_HASH,
+   strlen("linux") + 1, (u8 *)"linux");
+   if (ret)
+   goto unmap_image;
+
+   rd_len = images->rd_end - images->rd_start;
+   initrd_buf = map_sysmem(images->rd_start, rd_len);
+   ret = tcg2_measure_data(dev, &elog, 9, rd_len, initrd_buf,
+   EV_COMPACT_HASH, strlen("initrd") + 1,
+   (u8 *)"initrd");
+   if (ret)
+   goto unmap_initrd;
+
+   if (IS_ENABLED(CONFIG_MEASURE_DEVICETREE)) {
+   ret = tcg2_measure_data(dev, &elog, 0, images->ft_len,
+   (u8 *)images->ft_addr,
+   EV_TABLE_OF_DEVICES,
+   strlen("dts") + 1,
+ 

[PATCH v9 2/6] tpm: sandbox: Update for needed TPM2 capabilities

2023-03-08 Thread Eddie James
The driver needs to support getting the PCRs in the capabilities
command. Fix various other things and support the max number
of PCRs for TPM2.
Remove the !SANDBOX dependency for EFI TCG2 as well.

Signed-off-by: Eddie James 
Reviewed-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---
Changes since v8:
 - Use >= for checking the property against TPM2_PROPERTIES_OFFSET

Changes since v5:
 - Remove the !SANDBOX dependency for EFI TCG2

 drivers/tpm/tpm2_tis_sandbox.c | 100 -
 lib/efi_loader/Kconfig |   2 -
 2 files changed, 72 insertions(+), 30 deletions(-)

diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index e4004cfcca..d15a28d9fc 100644
--- a/drivers/tpm/tpm2_tis_sandbox.c
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -22,11 +22,6 @@ enum tpm2_hierarchy {
TPM2_HIERARCHY_NB,
 };
 
-/* Subset of supported capabilities */
-enum tpm2_capability {
-   TPM_CAP_TPM_PROPERTIES = 0x6,
-};
-
 /* Subset of supported properties */
 #define TPM2_PROPERTIES_OFFSET 0x020E
 
@@ -38,7 +33,8 @@ enum tpm2_cap_tpm_property {
TPM2_PROPERTY_NB,
 };
 
-#define SANDBOX_TPM_PCR_NB 1
+#define SANDBOX_TPM_PCR_NB TPM2_MAX_PCRS
+#define SANDBOX_TPM_PCR_SELECT_MAX ((SANDBOX_TPM_PCR_NB + 7) / 8)
 
 /*
  * Information about our TPM emulation. This is preserved in the sandbox
@@ -433,7 +429,7 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
int i, j;
 
/* TPM2_GetProperty */
-   u32 capability, property, property_count;
+   u32 capability, property, property_count, val;
 
/* TPM2_PCR_Read/Extend variables */
int pcr_index = 0;
@@ -542,19 +538,32 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const 
u8 *sendbuf,
case TPM2_CC_GET_CAPABILITY:
capability = get_unaligned_be32(sent);
sent += sizeof(capability);
-   if (capability != TPM_CAP_TPM_PROPERTIES) {
-   printf("Sandbox TPM only support TPM_CAPABILITIES\n");
-   return TPM2_RC_HANDLE;
-   }
-
property = get_unaligned_be32(sent);
sent += sizeof(property);
-   property -= TPM2_PROPERTIES_OFFSET;
-
property_count = get_unaligned_be32(sent);
sent += sizeof(property_count);
-   if (!property_count ||
-   property + property_count > TPM2_PROPERTY_NB) {
+
+   switch (capability) {
+   case TPM2_CAP_PCRS:
+   break;
+   case TPM2_CAP_TPM_PROPERTIES:
+   if (!property_count) {
+   rc = TPM2_RC_HANDLE;
+   return sandbox_tpm2_fill_buf(recv, recv_len,
+tag, rc);
+   }
+
+   if (property >= TPM2_PROPERTIES_OFFSET &&
+   ((property - TPM2_PROPERTIES_OFFSET) +
+property_count > TPM2_PROPERTY_NB)) {
+   rc = TPM2_RC_HANDLE;
+   return sandbox_tpm2_fill_buf(recv, recv_len,
+tag, rc);
+   }
+   break;
+   default:
+   printf("Sandbox TPM2 only supports TPM2_CAP_PCRS or "
+  "TPM2_CAP_TPM_PROPERTIES\n");
rc = TPM2_RC_HANDLE;
return sandbox_tpm2_fill_buf(recv, recv_len, tag, rc);
}
@@ -578,18 +587,53 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const 
u8 *sendbuf,
put_unaligned_be32(capability, recv);
recv += sizeof(capability);
 
-   /* Give the number of properties that follow */
-   put_unaligned_be32(property_count, recv);
-   recv += sizeof(property_count);
-
-   /* Fill with the properties */
-   for (i = 0; i < property_count; i++) {
-   put_unaligned_be32(TPM2_PROPERTIES_OFFSET + property +
-  i, recv);
-   recv += sizeof(property);
-   put_unaligned_be32(tpm->properties[property + i],
-  recv);
-   recv += sizeof(property);
+   switch (capability) {
+   case TPM2_CAP_PCRS:
+   /* Give the number of algorithms supported - just 
SHA256 */
+   put_unaligned_be32(1, recv);
+   recv += sizeof(u32);
+
+   /* Give SHA256 algorithm */
+   put_unaligned_be16(TPM2_ALG_SHA256, recv);
+   recv += sizeof(u16);
+
+   /* Select the PCRs supported */
+   *recv =

[PATCH v9 5/6] test: Add sandbox TPM boot measurement

2023-03-08 Thread Eddie James
Use the sandbox TPM driver to measure some boot images in a unit
test case.

Signed-off-by: Eddie James 
Reviewed-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---
Changes since v5:
 - Only compile in the measurement u-boot command when
   CONFIG_MEASURED_BOOT is enabled.

 arch/sandbox/dts/sandbox.dtsi | 13 +++
 arch/sandbox/dts/test.dts | 13 +++
 configs/sandbox_defconfig |  1 +
 include/test/suites.h |  1 +
 test/boot/Makefile|  1 +
 test/boot/measurement.c   | 66 +++
 test/cmd_ut.c |  4 +++
 7 files changed, 99 insertions(+)
 create mode 100644 test/boot/measurement.c

diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
index 7e7fcff6d2..3442be7634 100644
--- a/arch/sandbox/dts/sandbox.dtsi
+++ b/arch/sandbox/dts/sandbox.dtsi
@@ -4,11 +4,23 @@
  * and sandbox64 builds.
  */
 
+#include 
 #include 
 
 #define USB_CLASS_HUB  9
 
 / {
+   reserved-memory {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+
+   event_log: tcg_event_log {
+   no-map;
+   reg = <(CFG_SYS_SDRAM_SIZE - 0x2000) 0x2000>;
+   };
+   };
+
binman {
};
 
@@ -336,6 +348,7 @@
 
tpm2 {
compatible = "sandbox,tpm2";
+   memory-region = <&event_log>;
};
 
triangle {
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 9717103f10..7659effa71 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -9,6 +9,7 @@
 
 /dts-v1/;
 
+#include 
 #include 
 #include 
 #include 
@@ -66,6 +67,17 @@
osd0 = "/osd";
};
 
+   reserved-memory {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges;
+
+   event_log: tcg_event_log {
+   no-map;
+   reg = <(CFG_SYS_SDRAM_SIZE - 0x2000) 0x2000>;
+   };
+   };
+
binman: binman {
};
 
@@ -1365,6 +1377,7 @@
 
tpm2 {
compatible = "sandbox,tpm2";
+   memory-region = <&event_log>;
};
 
tpm {
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 77ade1f1d8..43b15b8446 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -335,3 +335,4 @@ CONFIG_TEST_FDTDEC=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+CONFIG_MEASURED_BOOT=y
diff --git a/include/test/suites.h b/include/test/suites.h
index 7c4960c004..b552fea9a9 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -44,6 +44,7 @@ int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, 
char *const argv[]);
 int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);
+int do_ut_measurement(struct cmd_tbl *cmdtp, int flag, int argc, char * const 
argv[]);
 int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc,
diff --git a/test/boot/Makefile b/test/boot/Makefile
index 22ed61c8fa..2dbb032a7e 100644
--- a/test/boot/Makefile
+++ b/test/boot/Makefile
@@ -4,6 +4,7 @@
 
 obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o
 obj-$(CONFIG_FIT) += image.o
+obj-$(CONFIG_MEASURED_BOOT) += measurement.o
 
 obj-$(CONFIG_EXPO) += expo.o
 
diff --git a/test/boot/measurement.c b/test/boot/measurement.c
new file mode 100644
index 00..9db2ed324c
--- /dev/null
+++ b/test/boot/measurement.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for measured boot functions
+ *
+ * Copyright 2023 IBM Corp.
+ * Written by Eddie James 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MEASUREMENT_TEST(_name, _flags)\
+   UNIT_TEST(_name, _flags, measurement_test)
+
+static int measure(struct unit_test_state *uts)
+{
+   struct bootm_headers images;
+   const size_t size = 1024;
+   u8 *kernel;
+   u8 *initrd;
+   size_t i;
+
+   kernel = malloc(size);
+   initrd = malloc(size);
+
+   images.os.image_start = map_to_sysmem(kernel);
+   images.os.image_len = size;
+
+   images.rd_start = map_to_sysmem(initrd);
+   images.rd_end = images.rd_start + size;
+
+   images.ft_addr = malloc(size);
+   images.ft_len = size;
+
+   env_set("bootargs", "measurement testing");
+
+   for (i = 0; i < size; ++i) {
+   kernel[i] = 0xf0 | (i & 0xf);
+   initrd[i] = (i & 0xf0) | 0xf;
+   images.ft_addr[i] = i & 0xff;
+   }
+
+   ut_assertok(bootm_measure(&images));
+
+ 

[PATCH v9 0/6] tpm: Support boot measurements

2023-03-08 Thread Eddie James
This series adds support for measuring the boot images more generically
than the existing EFI support. Several EFI functions have been moved to
the TPM layer. The series includes optional measurement from the bootm 
command.
A new test case has been added for the bootm measurement to test the new
path, and the sandbox TPM2 driver has been updated to support this use
case.
This series is based on Ilias' auto-startup series and Simon's additions.

Changes since v8:
 - Fix a sandbox driver off-by-one error in checking the property type.
 - Fix log parsing again - any data corruption seen while replaying the
   event log was failing the entire measurement.
 - Added an option to ignore the existing log and a configuration option
   for systems to select that for the bootm measurement. This would only
   be selected for systems that know that U-Boot is the first stage
   bootloader. This is necessary because the reserved memory region may
   persist through resets and so U-Boot attempts to append to the
   previous boot's log.

Changes since v7:
 - Change name of tcg2_init_log and add more documentation
 - Add a check, when parsing the event log header, to ensure that the
   previous stage bootloader used all the active PCRs.
 - Change name of tcg2_log_find_end
 - Fix the greater than or equal to check to exit the log parsing
 - Make sure log_position is 0 if there is any error discovering the log
 - Return errors parsing the log if the data is corrupt so that we don't
   end up with half a log

Changes since v6:
 - Added comment for bootm_measure
 - Fixed line length in bootm_measure
 - Added Linaro copyright for all the EFI moved code
 - Changed tcg2_init_log (and by extension, tcg2_measurement_init) to
   copy any discovered event log to the user's log if passed in.

Changes since v5:
 - Re-ordered the patches to put the sandbox TPM driver patch second
 - Remove unused platform_get_eventlog in efi_tcg2.c
 - First look for tpm_event_log_* properties instead of linux,sml-*
 - Fix efi_tcg2.c compilation
 - Select SHA* configs
 - Remove the !SANDBOX dependency for EFI TCG2
 - Only compile in the measurement u-boot command when CONFIG_MEASURED_BOOT
   is enabled

Changes since v4:
 - Remove tcg2_measure_event function and check for NULL data in
   tcg2_measure_data
 - Use tpm_auto_startup
 - Fix efi_tcg2.c compilation for removing tcg2_pcr_read function
 - Change PCR indexes for initrd and dtb
 - Drop u8 casting in measurement test
 - Use bullets in documentation

Changes since v3:
 - Reordered headers
 - Refactored more of EFI code into common code
Removed digest_info structure and instead used the common alg_to_mask
  and alg_to_len
Improved event log parsing in common code to get it equivalent to EFI
  Common code now extends PCR if previous bootloader stage couldn't
  No need to allocate memory in the common code, so EFI copies the
  discovered buffer like it did before
Rename efi measure_event function

Changes since v2:
 - Add documentation.
 - Changed reserved memory address to the top of the RAM for sandbox dts.
 - Add measure state to booti and bootz.
 - Skip measurement for EFI images that should be measured

Changes since v1:
 - Refactor TPM layer functions to allow EFI system to use them, and
   remove duplicate EFI functions.
 - Add test case
 - Drop #ifdefs for bootm
 - Add devicetree measurement config option
 - Update sandbox TPM driver

Eddie James (6):
  tpm: Fix spelling for tpmu_ha union
  tpm: sandbox: Update for needed TPM2 capabilities
  tpm: Support boot measurements
  bootm: Support boot measurement
  test: Add sandbox TPM boot measurement
  doc: Add measured boot documentation

 arch/sandbox/dts/sandbox.dtsi  |   13 +
 arch/sandbox/dts/test.dts  |   13 +
 boot/Kconfig   |   32 +
 boot/bootm.c   |   74 +++
 cmd/booti.c|1 +
 cmd/bootm.c|2 +
 cmd/bootz.c|1 +
 configs/sandbox_defconfig  |1 +
 doc/usage/index.rst|1 +
 doc/usage/measured_boot.rst|   23 +
 drivers/tpm/tpm2_tis_sandbox.c |  100 ++-
 include/bootm.h|   11 +
 include/efi_tcg2.h |   44 --
 include/image.h|1 +
 include/test/suites.h  |1 +
 include/tpm-v2.h   |  263 +++-
 lib/Kconfig|4 +
 lib/efi_loader/Kconfig |2 -
 lib/efi_loader/efi_tcg2.c  | 1054 +++-
 lib/tpm-v2.c   |  814 
 test/boot/Makefile |1 +
 test/boot/measurement.c|   66 ++
 test/cmd_ut.c  |4 +
 23 files changed, 1473 insertions(+), 1053 deletions(-)
 create mode 100644 doc/usage/measured_boot.rst
 create mode 100644 test/boot/measurement.c

-- 
2.31.1



[PATCH v9 1/6] tpm: Fix spelling for tpmu_ha union

2023-03-08 Thread Eddie James
tmpu -> tpmu

Signed-off-by: Eddie James 
Reviewed-by: Ilias Apalodimas 
---
 include/tpm-v2.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 2b6980e441..6684033deb 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -169,7 +169,7 @@ struct tcg_pcr_event {
 /**
  * Definition of TPMU_HA Union
  */
-union tmpu_ha {
+union tpmu_ha {
u8 sha1[TPM2_SHA1_DIGEST_SIZE];
u8 sha256[TPM2_SHA256_DIGEST_SIZE];
u8 sm3_256[TPM2_SM3_256_DIGEST_SIZE];
@@ -185,7 +185,7 @@ union tmpu_ha {
  */
 struct tpmt_ha {
u16 hash_alg;
-   union tmpu_ha digest;
+   union tpmu_ha digest;
 } __packed;
 
 /**
-- 
2.31.1



Re: [PATCH v8 0/6] tpm: Support boot measurements

2023-03-08 Thread Eddie James



On 3/6/23 00:58, Ilias Apalodimas wrote:

Hi Eddie,

This has a few failures on the CI [0].
Please have a look and let me know if you can't understand the failures



Hi, I think I have fixed the sandbox ones for v9. I'm unsure about the 
EFI selftest one in qemu targets...



Thanks,

Eddie




[0] https://source.denx.de/u-boot/custodians/u-boot-tpm/-/pipelines/15471

Regards
/Ilias
On Fri, Mar 03, 2023 at 01:25:00PM -0600, Eddie James wrote:

This series adds support for measuring the boot images more generically
than the existing EFI support. Several EFI functions have been moved to
the TPM layer. The series includes optional measurement from the bootm
command.
A new test case has been added for the bootm measurement to test the new
path, and the sandbox TPM2 driver has been updated to support this use
case.
This series is based on Ilias' auto-startup series and Simon's additions.

Changes since v7:
  - Change name of tcg2_init_log and add more documentation
  - Add a check, when parsing the event log header, to ensure that the
previous stage bootloader used all the active PCRs.
  - Change name of tcg2_log_find_end
  - Fix the greater than or equal to check to exit the log parsing
  - Make sure log_position is 0 if there is any error discovering the log
  - Return errors parsing the log if the data is corrupt so that we don't
end up with half a log

Changes since v6:
  - Added comment for bootm_measure
  - Fixed line length in bootm_measure
  - Added Linaro copyright for all the EFI moved code
  - Changed tcg2_init_log (and by extension, tcg2_measurement_init) to
copy any discovered event log to the user's log if passed in.

Changes since v5:
  - Re-ordered the patches to put the sandbox TPM driver patch second
  - Remove unused platform_get_eventlog in efi_tcg2.c
  - First look for tpm_event_log_* properties instead of linux,sml-*
  - Fix efi_tcg2.c compilation
  - Select SHA* configs
  - Remove the !SANDBOX dependency for EFI TCG2
  - Only compile in the measurement u-boot command when CONFIG_MEASURED_BOOT
is enabled

Changes since v4:
  - Remove tcg2_measure_event function and check for NULL data in
tcg2_measure_data
  - Use tpm_auto_startup
  - Fix efi_tcg2.c compilation for removing tcg2_pcr_read function
  - Change PCR indexes for initrd and dtb
  - Drop u8 casting in measurement test
  - Use bullets in documentation

Changes since v3:
  - Reordered headers
  - Refactored more of EFI code into common code
 Removed digest_info structure and instead used the common alg_to_mask
   and alg_to_len
 Improved event log parsing in common code to get it equivalent to EFI
   Common code now extends PCR if previous bootloader stage couldn't
   No need to allocate memory in the common code, so EFI copies the
   discovered buffer like it did before
 Rename efi measure_event function

Changes since v2:
  - Add documentation.
  - Changed reserved memory address to the top of the RAM for sandbox dts.
  - Add measure state to booti and bootz.
  - Skip measurement for EFI images that should be measured

Changes since v1:
  - Refactor TPM layer functions to allow EFI system to use them, and
remove duplicate EFI functions.
  - Add test case
  - Drop #ifdefs for bootm
  - Add devicetree measurement config option
  - Update sandbox TPM driver

Eddie James (6):
   tpm: Fix spelling for tpmu_ha union
   tpm: sandbox: Update for needed TPM2 capabilities
   tpm: Support boot measurements
   bootm: Support boot measurement
   test: Add sandbox TPM boot measurement
   doc: Add measured boot documentation

  arch/sandbox/dts/sandbox.dtsi  |   13 +
  arch/sandbox/dts/test.dts  |   13 +
  boot/Kconfig   |   23 +
  boot/bootm.c   |   72 +++
  cmd/booti.c|1 +
  cmd/bootm.c|2 +
  cmd/bootz.c|1 +
  configs/sandbox_defconfig  |1 +
  doc/usage/index.rst|1 +
  doc/usage/measured_boot.rst|   23 +
  drivers/tpm/tpm2_tis_sandbox.c |  100 ++-
  include/bootm.h|   11 +
  include/efi_tcg2.h |   44 --
  include/image.h|1 +
  include/test/suites.h  |1 +
  include/tpm-v2.h   |  255 +++-
  lib/Kconfig|4 +
  lib/efi_loader/Kconfig |2 -
  lib/efi_loader/efi_tcg2.c  | 1054 +++-
  lib/tpm-v2.c   |  815 
  test/boot/Makefile |1 +
  test/boot/measurement.c|   66 ++
  test/cmd_ut.c  |4 +
  23 files changed, 1455 insertions(+), 1053 deletions(-)
  create mode 100644 doc/usage/measured_boot.rst
  create mode 100644 test/boot/measurement.c

--
2.31.1



RE: [PATCH] README.mpc85xx-sd-spi-boot: Suggest the NXP boot format github repo

2023-03-08 Thread Leo Li



> -Original Message-
> From: Pali Rohár 
> Sent: Wednesday, March 8, 2023 2:54 PM
> To: Leo Li 
> Cc: Fabio Estevam ; Priyanka Jain
> ; Fabio Estevam ;
> ka...@kernel.org; u-boot@lists.denx.de
> Subject: Re: [PATCH] README.mpc85xx-sd-spi-boot: Suggest the NXP boot
> format github repo
> 
> On Tuesday 28 February 2023 23:53:02 Leo Li wrote:
> > > -Original Message-
> > > From: Pali Rohár 
> > > Sent: Tuesday, February 28, 2023 9:32 AM
> > > To: Leo Li 
> > > Cc: Fabio Estevam ; Priyanka Jain
> > > ; Fabio Estevam ;
> > > ka...@kernel.org; u-boot@lists.denx.de
> > > Subject: Re: [PATCH] README.mpc85xx-sd-spi-boot: Suggest the NXP
> > > boot format github repo
> > >
> > > On Friday 13 January 2023 09:10:18 Fabio Estevam wrote:
> > > > On Fri, Jan 13, 2023 at 4:53 AM Pali Rohár  wrote:
> > > >
> > > > > >  you can browse it online at:
> > > > > > -https://eur01.safelinks.protection.outlook.com/?url=https%3A%
> > > > > > 2F%2
> > > > > > Fsource.codeaurora.org%2Fexternal%2Fqoriq%2Fqoriq-yocto-
> > > sdk%2Fboot
> > > > > > -
> > >
> format&data=05%7C01%7Cleoyang.li%40nxp.com%7C664a99443c3b4bc3f80d
> > > > > >
> > >
> 08db19a0febf%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638131
> > > 95
> > > > > >
> > >
> 1494370943%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIj
> > > oiV2l
> > > > > >
> > >
> uMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=0Pcm
> > > Yxsc
> > > > > > yUY%2FuvgaxrchWlBlaVezU8nwO1C7%2FFYQr9U%3D&reserved=0
> > > > > > +https://eur01.safelinks.protection.outlook.com/?url=https%3A%
> > > > > > +2F%2
> > > > > > +Fgithub.com%2Fnxp-qoriq-yocto-sdk%2Fboot-
> > > format&data=05%7C01%7Cle
> > > > > >
> > >
> +oyang.li%40nxp.com%7C664a99443c3b4bc3f80d08db19a0febf%7C686ea1d3
> > > b
> > > > > >
> > >
> +c2b4c6fa92cd99c5c301635%7C0%7C0%7C638131951494527177%7CUnknown
> > > %7C
> > > > > >
> > >
> +TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwi
> > > L
> > > > > >
> > >
> +CJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=tM%2BXzNN03DeMVcQL8jc
> > > 2a1nBvsz
> > > > > > +31bHC%2FrKGV7rKGaY%3D&reserved=0
> > > > >
> > > > > This "new" repo contains old broken version of boot-format which
> > > > > is missing important commits and fixes.
> > > >
> > > > Priyanka, can anyone at NXP fix this?
> > >
> > > Leo Li, could you look at NXP boot-format github repository and
> > > import latest version from codeaurora? I see that github repository
> > > is missing more commits which are on codeaurora.
> >
> > Looks like the master branch on codeaurora was not migrated to github.
> Let me talk with the related people on this.
> >
> > Regards,
> > Leo
> 
> I see that now github boot-format repo contains some updates. But there
> are two branches: nxp/master and master. Default one is nxp/master and
> points to the old commit from year 2012.

It mimics the branches on CodeAurora.  I will ask them to update the default 
branch to master.

Regards,
Leo


[PATCH v4 00/10] Renesas RZ/N1 SoC initial support

2023-03-08 Thread Ralph Siemsen
The RZ/N1 is a family of SoC devices from Renesas [1], featuring ARM
Cortex-A7 and/or Cortex-M3 CPU, industrial ethernet protocols,
integrated Ethernet switch, and numerous peripherals.

This is a first step in upstreaming support for the RZ/N1 family.
Currently it contains just enough to boot to the u-boot prompt.
Additional patches will follow to support flash, SD, USB, Ethernet, etc.

This work is based on a vendor-supplied u-boot 2017.01 tree [2],
which supports several eval boards, none of which I have access to.
Instead development has been done on a Schneider RZN1 board, which
is fairly similar to the Renesas RZ/N1D-DB Demo board.

[1] 
https://www.renesas.com/us/en/products/microcontrollers-microprocessors/rz-mpus/rzn1
[2] https://github.com/renesas-rz/rzn1_u-boot/tree/rzn1-stable

Changes in v4:
- rebase to u-boot v2023.04-rc3
- remove RFC prefix
- cc entire series to Marek by request
- clock tables synced with linux (pending patches)
- documentation and comment improvements

Changes in v3:
- many tweaks to clock driver based on reviewer feedback
- rebased to u-boot v2023.04-rc2
- reviewer suggestions added to spkgimage.c
- many small cleanups, checkpatch, FIXMEs resolved

Changes in v2:
- rewrote the stand-alone spkg_utility to integrate into mkimage

Ralph Siemsen (10):
  ARM: armv7: add non-SPL enable for Cortex SMPEN
  clk: renesas: prepare for non-RCAR clock drivers
  clk: renesas: add R906G032 driver
  pinctrl: renesas: add R906G032 driver
  ram: cadence: add driver for Cadence EDAC
  dts: basic devicetree for Renesas RZ/N1 SoC
  ARM: rzn1: basic support for Renesas RZ/N1 SoC
  board: schneider: add RZN1 board support
  tools: spkgimage: add Renesas SPKG format
  doc: renesas: add Renesas board docs

 arch/arm/Kconfig  |   17 +
 arch/arm/Makefile |1 +
 arch/arm/cpu/armv7/Kconfig|5 +
 arch/arm/dts/r9a06g032-rzn1-snarc-u-boot.dtsi |   23 +
 arch/arm/dts/r9a06g032-rzn1-snarc.dts |   51 +
 arch/arm/dts/r9a06g032.dtsi   |  226 
 arch/arm/mach-rzn1/Kconfig|   32 +
 arch/arm/mach-rzn1/Makefile   |3 +
 arch/arm/mach-rzn1/cpu_info.c |   19 +
 board/schneider/rzn1-snarc/Kconfig|   18 +
 board/schneider/rzn1-snarc/Makefile   |3 +
 board/schneider/rzn1-snarc/ddr_timing.c   |  140 +++
 .../jedec_ddr3_2g_x16_1333h_500_cl8.h |  399 ++
 board/schneider/rzn1-snarc/rzn1.c |   39 +
 board/schneider/rzn1-snarc/spkgimage.cfg  |   26 +
 boot/image.c  |1 +
 configs/rzn1_snarc_defconfig  |   21 +
 doc/board/renesas/index.rst   |9 +
 doc/board/renesas/renesas.rst |  115 ++
 doc/mkimage.1 |   45 +
 drivers/clk/renesas/Kconfig   |8 +-
 drivers/clk/renesas/Makefile  |6 +-
 drivers/clk/renesas/r9a06g032-clocks.c| 1096 +
 drivers/pinctrl/Makefile  |1 +
 drivers/pinctrl/renesas/Kconfig   |7 +
 drivers/pinctrl/renesas/Makefile  |1 +
 drivers/pinctrl/renesas/pinctrl-rzn1.c|  379 ++
 drivers/ram/Kconfig   |1 +
 drivers/ram/Makefile  |2 +
 drivers/ram/cadence/Kconfig   |   12 +
 drivers/ram/cadence/Makefile  |1 +
 drivers/ram/cadence/ddr_async.c   |  311 +
 drivers/ram/cadence/ddr_ctrl.c|  414 +++
 drivers/ram/cadence/ddr_ctrl.h|  175 +++
 include/configs/rzn1-snarc.h  |   17 +
 include/dt-bindings/clock/r9a06g032-sysctrl.h |  148 +++
 include/dt-bindings/pinctrl/rzn1-pinctrl.h|  141 +++
 include/image.h   |1 +
 tools/Makefile|1 +
 tools/spkgimage.c |  330 +
 tools/spkgimage.h |   87 ++
 41 files changed, 4328 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/dts/r9a06g032-rzn1-snarc-u-boot.dtsi
 create mode 100644 arch/arm/dts/r9a06g032-rzn1-snarc.dts
 create mode 100644 arch/arm/dts/r9a06g032.dtsi
 create mode 100644 arch/arm/mach-rzn1/Kconfig
 create mode 100644 arch/arm/mach-rzn1/Makefile
 create mode 100644 arch/arm/mach-rzn1/cpu_info.c
 create mode 100644 board/schneider/rzn1-snarc/Kconfig
 create mode 100644 board/schneider/rzn1-snarc/Makefile
 create mode 100644 board/schneider/rzn1-snarc/ddr_timing.c
 create mode 100644 board/schneider/rzn1-snarc/jedec_ddr3_2g_x16_1333h_500_cl8.h
 create mode 100644 board/schneider/rzn1-snarc/rzn1.c
 create mode 100644 board/schneider/rzn1-snarc/spkgimage.cfg
 create mode 100644 configs/rzn1_snarc_defconfig
 create mode 100644 doc/board/renesas/index.rst
 create mode 100644 doc/board/renesas/renesas.rst
 create mode 10064

Re: [PATCH] README.mpc85xx-sd-spi-boot: Suggest the NXP boot format github repo

2023-03-08 Thread Pali Rohár
On Tuesday 28 February 2023 23:53:02 Leo Li wrote:
> > -Original Message-
> > From: Pali Rohár 
> > Sent: Tuesday, February 28, 2023 9:32 AM
> > To: Leo Li 
> > Cc: Fabio Estevam ; Priyanka Jain
> > ; Fabio Estevam ;
> > ka...@kernel.org; u-boot@lists.denx.de
> > Subject: Re: [PATCH] README.mpc85xx-sd-spi-boot: Suggest the NXP boot
> > format github repo
> > 
> > On Friday 13 January 2023 09:10:18 Fabio Estevam wrote:
> > > On Fri, Jan 13, 2023 at 4:53 AM Pali Rohár  wrote:
> > >
> > > > >  you can browse it online at:
> > > > > -https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2
> > > > > Fsource.codeaurora.org%2Fexternal%2Fqoriq%2Fqoriq-yocto-
> > sdk%2Fboot
> > > > > -
> > format&data=05%7C01%7Cleoyang.li%40nxp.com%7C664a99443c3b4bc3f80d
> > > > >
> > 08db19a0febf%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638131
> > 95
> > > > >
> > 1494370943%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIj
> > oiV2l
> > > > >
> > uMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=0Pcm
> > Yxsc
> > > > > yUY%2FuvgaxrchWlBlaVezU8nwO1C7%2FFYQr9U%3D&reserved=0
> > > > > +https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2
> > > > > +Fgithub.com%2Fnxp-qoriq-yocto-sdk%2Fboot-
> > format&data=05%7C01%7Cle
> > > > >
> > +oyang.li%40nxp.com%7C664a99443c3b4bc3f80d08db19a0febf%7C686ea1d3
> > b
> > > > >
> > +c2b4c6fa92cd99c5c301635%7C0%7C0%7C638131951494527177%7CUnknown
> > %7C
> > > > >
> > +TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwi
> > L
> > > > >
> > +CJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=tM%2BXzNN03DeMVcQL8jc
> > 2a1nBvsz
> > > > > +31bHC%2FrKGV7rKGaY%3D&reserved=0
> > > >
> > > > This "new" repo contains old broken version of boot-format which is
> > > > missing important commits and fixes.
> > >
> > > Priyanka, can anyone at NXP fix this?
> > 
> > Leo Li, could you look at NXP boot-format github repository and import 
> > latest
> > version from codeaurora? I see that github repository is missing more
> > commits which are on codeaurora.
> 
> Looks like the master branch on codeaurora was not migrated to github.  Let 
> me talk with the related people on this.
> 
> Regards,
> Leo

I see that now github boot-format repo contains some updates. But there
are two branches: nxp/master and master. Default one is nxp/master and
points to the old commit from year 2012.


kwbimage config file documentation (Was: Re: [PATCH RFC u-boot-mvebu 00/59] arm: mvebu: Various fixes)

2023-03-08 Thread Pali Rohár
On Saturday 25 February 2023 01:18:26 Martin Rowe wrote:
>  - taken a look at the kwbimage documentation, but I don't think I can
> be of much help there

It should be pretty straightforward. Looking at how is documentation for
other format written (in the same manpage ./doc/mkimage.1), then looking
at existing kwbimage config files (find . -name "kwbimage.*cfg") and
looking into tools/kwbimage.c source code into functions which parses
config file (image_create_config_parse_oneline) and generate config file
(kwbimage_generate_config).


[PATCH v4 08/10] board: schneider: add RZN1 board support

2023-03-08 Thread Ralph Siemsen
Add support for Schneider Electronics RZ/N1D and RZ/N1S boards, which
are based on the Reneasas RZ/N1 SoC devices.

The intention is to support both boards using a single defconfig, and to
handle the differences at runtime.

Signed-off-by: Ralph Siemsen 
---

Changes in v4:
- add binman support via r9a06g032-rzn1-snarc-u-boot.dtsi

Changes in v3:
- rename board LCES to rzn1-snarc
- move CONFIG_SYS_NS16550_MEM32 to Kconfig
- define CFG_SYS_INIT_RAM_{ADDR,SIZE}
- removed debug uart settings from defconfig

 arch/arm/dts/r9a06g032-rzn1-snarc-u-boot.dtsi |  23 +
 arch/arm/dts/r9a06g032-rzn1-snarc.dts |  51 +++
 arch/arm/mach-rzn1/Kconfig|  14 +
 board/schneider/rzn1-snarc/Kconfig|  18 +
 board/schneider/rzn1-snarc/Makefile   |   3 +
 board/schneider/rzn1-snarc/ddr_timing.c   | 140 ++
 .../jedec_ddr3_2g_x16_1333h_500_cl8.h | 399 ++
 board/schneider/rzn1-snarc/rzn1.c |  39 ++
 configs/rzn1_snarc_defconfig  |  21 +
 include/configs/rzn1-snarc.h  |  17 +
 10 files changed, 725 insertions(+)
 create mode 100644 arch/arm/dts/r9a06g032-rzn1-snarc-u-boot.dtsi
 create mode 100644 arch/arm/dts/r9a06g032-rzn1-snarc.dts
 create mode 100644 board/schneider/rzn1-snarc/Kconfig
 create mode 100644 board/schneider/rzn1-snarc/Makefile
 create mode 100644 board/schneider/rzn1-snarc/ddr_timing.c
 create mode 100644 board/schneider/rzn1-snarc/jedec_ddr3_2g_x16_1333h_500_cl8.h
 create mode 100644 board/schneider/rzn1-snarc/rzn1.c
 create mode 100644 configs/rzn1_snarc_defconfig
 create mode 100644 include/configs/rzn1-snarc.h

diff --git a/arch/arm/dts/r9a06g032-rzn1-snarc-u-boot.dtsi 
b/arch/arm/dts/r9a06g032-rzn1-snarc-u-boot.dtsi
new file mode 100644
index 00..794e711103
--- /dev/null
+++ b/arch/arm/dts/r9a06g032-rzn1-snarc-u-boot.dtsi
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Configuration file for binman
+ *
+ * After building u-boot, can generate the SPKG output by running:
+ * tools/binman/binman build -d arch/arm/dts/r9a06g032-rzn1-snarc.dtb -O 

+ */
+
+#include 
+
+/ {
+   binman: binman {
+   };
+};
+
+&binman {
+   mkimage {
+   filename = "u-boot.bin.spkg";
+   args = "-n board/schneider/rzn1-snarc/spkgimage.cfg -T 
spkgimage -a 0x2004 -e 0x2004";
+   u-boot {
+   };
+   };
+};
diff --git a/arch/arm/dts/r9a06g032-rzn1-snarc.dts 
b/arch/arm/dts/r9a06g032-rzn1-snarc.dts
new file mode 100644
index 00..abb269cc21
--- /dev/null
+++ b/arch/arm/dts/r9a06g032-rzn1-snarc.dts
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Device Tree Source for Schneider RZ/N1 Board
+ *
+ * Based on r9a06g032-rzn1d400-db.dts
+ */
+
+/dts-v1/;
+
+#include "r9a06g032.dtsi"
+#include 
+
+/ {
+   model = "Schneider RZ/N1 Board";
+   compatible = "schneider,rzn1", "renesas,r9a06g032";
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   aliases {
+   serial0 = &uart0;
+   };
+
+   memory {
+   device_type = "memory";
+   reg = <0x8000 0x1000>;
+   };
+};
+
+&ddrctrl {
+   status = "okay";
+};
+
+&pinctrl {
+   status = "okay";
+
+   pins_uart0: pins_uart0 {
+   pinmux = <
+   RZN1_PINMUX(103, RZN1_FUNC_UART0_I) /* UART0_TXD */
+   RZN1_PINMUX(104, RZN1_FUNC_UART0_I) /* UART0_RXD */
+   >;
+   bias-disable;
+   };
+};
+
+&uart0 {
+   pinctrl-0 = <&pins_uart0>;
+   pinctrl-names = "default";
+   status = "okay";
+};
diff --git a/arch/arm/mach-rzn1/Kconfig b/arch/arm/mach-rzn1/Kconfig
index 707895874d..4b13afbb32 100644
--- a/arch/arm/mach-rzn1/Kconfig
+++ b/arch/arm/mach-rzn1/Kconfig
@@ -15,4 +15,18 @@ endchoice
 config SYS_SOC
default "rzn1"
 
+choice
+   prompt "Board select"
+   default TARGET_SCHNEIDER_RZN1
+
+config TARGET_SCHNEIDER_RZN1
+   bool "Schneider RZN1 board"
+   help
+ Support the Schneider RZN1D and RZN1S boards, which are based
+ on the Renesas RZ/N1 SoC.
+
+endchoice
+
+source "board/schneider/rzn1-snarc/Kconfig"
+
 endif
diff --git a/board/schneider/rzn1-snarc/Kconfig 
b/board/schneider/rzn1-snarc/Kconfig
new file mode 100644
index 00..bb6d394077
--- /dev/null
+++ b/board/schneider/rzn1-snarc/Kconfig
@@ -0,0 +1,18 @@
+if TARGET_SCHNEIDER_RZN1
+
+config TEXT_BASE
+   default 0x2004 if ARCH_RZN1
+
+config SYS_MONITOR_LEN
+   default 524288 if ARCH_RZN1
+
+config SYS_BOARD
+   default "rzn1-snarc"
+
+config SYS_VENDOR
+   default "schneider"
+
+config SYS_CONFIG_NAME
+   default "rzn1-snarc"
+
+endif
diff --git a/board/schneider/rzn1-snarc/Makefile 
b/board/schneider/rzn1-snarc/Makefile
new file mode 100644
index 00..95c151898b
--- /dev/null
+++ b/board/schneider/rzn1-snarc/Makefile
@@ -0,0 +1,3 @

[PATCH v4 10/10] doc: renesas: add Renesas board docs

2023-03-08 Thread Ralph Siemsen
Collect the list of currerently supported Renesas boards.

For the RZ/N1 board, add details about booting and flashing.

Signed-off-by: Ralph Siemsen 
---

(no changes since v1)

 doc/board/renesas/index.rst   |   9 +++
 doc/board/renesas/renesas.rst | 115 ++
 2 files changed, 124 insertions(+)
 create mode 100644 doc/board/renesas/index.rst
 create mode 100644 doc/board/renesas/renesas.rst

diff --git a/doc/board/renesas/index.rst b/doc/board/renesas/index.rst
new file mode 100644
index 00..3244c9d45e
--- /dev/null
+++ b/doc/board/renesas/index.rst
@@ -0,0 +1,9 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Renesas
+===
+
+.. toctree::
+   :maxdepth: 2
+
+   renesas
diff --git a/doc/board/renesas/renesas.rst b/doc/board/renesas/renesas.rst
new file mode 100644
index 00..5ae84004cf
--- /dev/null
+++ b/doc/board/renesas/renesas.rst
@@ -0,0 +1,115 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Renesas
+===
+
+About this
+--
+
+This document describes the information about Renesas supported boards
+and their usage steps.
+
+Renesas boards
+--
+
+Renesas is a SoC solutions provider for industrial applications.
+
+U-boot supports several Renesas SoC families:
+
+* rcar gen1/gen2 (32-bit)
+- Blanche board
+- Gose board
+- Koelsch board
+- Lager board
+- Silk board
+- Porter board
+- Stout board
+* rcar gen3 (64-bit)
+- Condor board
+- Draak board
+- Eagle board
+- Ebisu board
+- Falcon board
+- Salvator-x board
+- Ulcb board
+- Beacon-rzg2 board
+- Hihope-rzg2 board
+- ek874 board
+* rza1 (32-bit)
+- GR-PEACH board
+* rzn1 (32-bit)
+- Schneider rzn1-snarc board
+
+Building
+
+
+NOTE: the following information is for the rzn1 board only.
+
+U-Boot
+^^
+
+Clone the u-boot repository and build it as follows:
+
+.. code-block:: bash
+
+git clone --depth 1 https://source.denx.de/u-boot/u-boot.git
+cd u-boot
+make rzn1_snarc_defconfig
+make CROSS_COMPILE=arm-linux-gnu-
+
+This produces `u-boot` which is an ELF executable, suitable for use with `gdb`
+and JTAG debugging tools.
+
+It also produceds `u-boot.bin` which is a raw binary.
+
+SPKG image
+^^
+
+The BootROM in the RZ/N1 SoC expects to find the boot image in SPKG format.
+This format is documented in Chapter 7.4 of the RZ/N1 User Manual.
+
+The raw u-boot binary can be wrapped into SPKG format as follows:
+
+.. code-block:: bash
+
+tools/mkimage -n board/schneider/rzn1-snarc/spkgimage.cfg \
+-T spkgimage -a 0x2004 -e 0x2004 \
+-d u-boot.bin u-boot.bin.spkg
+
+This produces `u-boot.bin.spkg` which can be flashed into QSPI, NAND, or loaded
+via USB-DFU mode.
+
+Take note of the load and execution address, which are encoded into the SPKG
+headers. For development convenience, mkimage computes the execution offset
+(part of the SPKG header) by subtracting the supplied load address from the
+supplied execution address.
+
+Also note there are other parameters, notably ECC configuration in the case of
+boot from NAND, specified in the `spkgimage.cfg` configuration file.
+
+Binman
+^^
+
+Alternatively `binman` may be used to generate the SPKG format for booting.
+This tool and its pre-requisites must be installed as per
+:doc:`../../../tools/binman/binman.rst``
+
+.. code-block:: bash
+
+binman -d arch/arm/dts/r9a06g032-rzn1-snarc.dtb -o 
+
+This will produce `u-boot.bin.spkg` in the specified  directory.
+
+Flashing
+
+
+The RZ/N1 is able to boot from QSPI, NAND, or via USB (DFU). In all cases the
+on-board BootROM expects for the binary to be wrapped with a "SPKG" header.
+This format is detailed in the RZ/N1 User Manual, and can be produced using
+the u-boot `mkimage` utility.
+
+It is possible to recover a bricked unit by using the USB (DFU) boot mode. This
+allows uploading u-boot into the internal RAM. Thereafter u-boot can be used to
+program the QSPI and/or NAND, making use of u-boot dfu mode.
+
+Otherwise the only other option for recovery is via JTAG.
-- 
2.25.1



[PATCH v4 07/10] ARM: rzn1: basic support for Renesas RZ/N1 SoC

2023-03-08 Thread Ralph Siemsen
The RZ/N1 is a family of SoC devics from Renesas, featuring:

* ARM Cortex-A7 CPU (single/dual core) and/or Cortex-M3
* Integrated SRAM up to 6MB
* Integrated gigabit ethernet switch
* Optional DDR2/3 controller
* I2C, SPI, UART, NAND, QSPI, SDIO, USB, CAN, RTC, LCD

Add basic support in the form of ARCH_RZN1 symbol.

Signed-off-by: Ralph Siemsen 
---

(no changes since v1)

 arch/arm/Kconfig  | 17 +
 arch/arm/Makefile |  1 +
 arch/arm/mach-rzn1/Kconfig| 18 ++
 arch/arm/mach-rzn1/Makefile   |  3 +++
 arch/arm/mach-rzn1/cpu_info.c | 19 +++
 5 files changed, 58 insertions(+)
 create mode 100644 arch/arm/mach-rzn1/Kconfig
 create mode 100644 arch/arm/mach-rzn1/Makefile
 create mode 100644 arch/arm/mach-rzn1/cpu_info.c

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index bd7fffcce0..8e2a30f852 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1031,6 +1031,21 @@ config ARCH_RMOBILE
imply SYS_THUMB_BUILD
imply ARCH_MISC_INIT if DISPLAY_CPUINFO
 
+config ARCH_RZN1
+   bool "Reneasa RZ/N1 SoC"
+   select CLK
+   select CLK_RENESAS
+   select CLK_R9A06G032
+   select DM
+   select DM_ETH
+   select DM_SERIAL
+   select PINCTRL
+   select PINCONF
+   select REGMAP
+   select SYSRESET
+   select SYSRESET_SYSCON
+   imply CMD_DM
+
 config ARCH_SNAPDRAGON
bool "Qualcomm Snapdragon SoCs"
select ARM64
@@ -2207,6 +,8 @@ source "arch/arm/mach-owl/Kconfig"
 
 source "arch/arm/mach-rmobile/Kconfig"
 
+source "arch/arm/mach-rzn1/Kconfig"
+
 source "arch/arm/mach-meson/Kconfig"
 
 source "arch/arm/mach-mediatek/Kconfig"
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index ac602aed9c..1ec95a87e1 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -76,6 +76,7 @@ machine-$(CONFIG_ARCH_ORION5X)+= orion5x
 machine-$(CONFIG_ARCH_OWL) += owl
 machine-$(CONFIG_ARCH_RMOBILE) += rmobile
 machine-$(CONFIG_ARCH_ROCKCHIP)+= rockchip
+machine-$(CONFIG_ARCH_RZN1)+= rzn1
 machine-$(CONFIG_ARCH_S5PC1XX) += s5pc1xx
 machine-$(CONFIG_ARCH_SNAPDRAGON)  += snapdragon
 machine-$(CONFIG_ARCH_SOCFPGA) += socfpga
diff --git a/arch/arm/mach-rzn1/Kconfig b/arch/arm/mach-rzn1/Kconfig
new file mode 100644
index 00..707895874d
--- /dev/null
+++ b/arch/arm/mach-rzn1/Kconfig
@@ -0,0 +1,18 @@
+if ARCH_RZN1
+
+choice
+   prompt "Target Renesas RZ/N1 SoC select"
+   default RZN1
+
+config RZN1
+   bool "Renesas ARM SoCs RZ/N1 (32bit)"
+   select CPU_V7A
+   select ARMV7_SET_CORTEX_SMPEN if !SPL
+   select SPL_ARMV7_SET_CORTEX_SMPEN if SPL
+
+endchoice
+
+config SYS_SOC
+   default "rzn1"
+
+endif
diff --git a/arch/arm/mach-rzn1/Makefile b/arch/arm/mach-rzn1/Makefile
new file mode 100644
index 00..b20f845c0f
--- /dev/null
+++ b/arch/arm/mach-rzn1/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-y = cpu_info.o
diff --git a/arch/arm/mach-rzn1/cpu_info.c b/arch/arm/mach-rzn1/cpu_info.c
new file mode 100644
index 00..37c2492b51
--- /dev/null
+++ b/arch/arm/mach-rzn1/cpu_info.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include 
+#include 
+
+#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
+void enable_caches(void)
+{
+   dcache_enable();
+}
+#endif
+
+#ifdef CONFIG_DISPLAY_CPUINFO
+int print_cpuinfo(void)
+{
+   printf("CPU: Renesas Electronics RZ/N1\n");
+   return 0;
+}
+#endif
-- 
2.25.1



[PATCH v4 09/10] tools: spkgimage: add Renesas SPKG format

2023-03-08 Thread Ralph Siemsen
Renesas RZ/N1 devices contain BootROM code that loads a custom SPKG
image from QSPI, NAND or USB DFU. Support this format in mkimage tool.

SPKGs can optionally be signed, however creation of signed SPKG is not
currently supported.

Example of how to use it:

tools/mkimage -n board/schneider/rzn1-snarc/spkgimage.cfg \
-T spkgimage -a 0x2004 -e 0x2004 \
-d u-boot.bin u-boot.bin.spkg

The config file (spkgimage.cfg in this example) contains additional
parameters such as NAND ECC settings.

Signed-off-by: Ralph Siemsen 
Reviewed-by: Simon Glass 
---

Changes in v4:
- added tags
- add RZ/N1 board documentation
- added binman support

Changes in v3:
- provide definition of __packed (as done in kwbimage.h)
- explain why a local copy of roundup() is needed
- document spkgimage in doc/mkimage.1
- add range checks when parsing config file values
- add line numbers for reporting errors in config file
- rename SPKG_HEADER_SIGNATURE to SPKG_HEADER_MARKER
- fix segfault when image is padded by less than 4 bytes
- minor style and typo fixes

Changes in v2:
- rewrote the stand-alone spkg_utility to integrate into mkimage

 board/schneider/rzn1-snarc/spkgimage.cfg |  26 ++
 boot/image.c |   1 +
 doc/mkimage.1|  45 
 include/image.h  |   1 +
 tools/Makefile   |   1 +
 tools/spkgimage.c| 330 +++
 tools/spkgimage.h|  87 ++
 7 files changed, 491 insertions(+)
 create mode 100644 board/schneider/rzn1-snarc/spkgimage.cfg
 create mode 100644 tools/spkgimage.c
 create mode 100644 tools/spkgimage.h

diff --git a/board/schneider/rzn1-snarc/spkgimage.cfg 
b/board/schneider/rzn1-snarc/spkgimage.cfg
new file mode 100644
index 00..b5faf96b00
--- /dev/null
+++ b/board/schneider/rzn1-snarc/spkgimage.cfg
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2022 Schneider Electric
+#
+# SPKG image header, for booting on RZ/N1
+
+# b[35:32] SPKG version
+VERSION1
+
+# b[42:41]  ECC Block size: 0=256 bytes, 1=512 bytes, 2=1024 bytes
+NAND_ECC_BLOCK_SIZE1
+
+# b[45] NAND enable (boolean)
+NAND_ECC_ENABLE1
+
+# b[50:48]  ECC Scheme: 0=BCH2 1=BCH4 2=BCH8 3=BCH16 4=BCH24 5=BCH32
+NAND_ECC_SCHEME3
+
+# b[63:56]  ECC bytes per block
+NAND_BYTES_PER_ECC_BLOCK 28
+
+# Provide dummy BLp header (boolean)
+ADD_DUMMY_BLP  1
+
+# Pad the image to a multiple of
+PADDING64K
diff --git a/boot/image.c b/boot/image.c
index 958dbf8534..5c4f9b807d 100644
--- a/boot/image.c
+++ b/boot/image.c
@@ -181,6 +181,7 @@ static const table_entry_t uimage_type[] = {
{   IH_TYPE_SUNXI_EGON, "sunxi_egon",  "Allwinner eGON Boot Image" 
},
{   IH_TYPE_SUNXI_TOC0, "sunxi_toc0",  "Allwinner TOC0 Boot Image" 
},
{   IH_TYPE_FDT_LEGACY, "fdt_legacy", "legacy Image with Flat 
Device Tree ", },
+   {   IH_TYPE_RENESAS_SPKG, "spkgimage", "Renesas SPKG Image" },
{   -1, "",   "",   },
 };
 
diff --git a/doc/mkimage.1 b/doc/mkimage.1
index d8727ec73c..76c7859bb0 100644
--- a/doc/mkimage.1
+++ b/doc/mkimage.1
@@ -662,6 +662,51 @@ rk3568
 .TE
 .RE
 .
+.SS spkgimage
+The primary configuration file consists of lines containing key/value pairs
+delimited by whitespace. An example follows.
+.PP
+.RS
+.EX
+# Comments and blank lines may be used
+.I key1 value1
+.I key2 value2
+.EE
+.RE
+.P
+The supported
+.I key
+types are as follows.
+.TP
+.B VERSION
+.TQ
+.B NAND_ECC_BLOCK_SIZE
+.TQ
+.B NAND_ECC_ENABLE
+.TQ
+.B NAND_ECC_SCHEME
+.TQ
+.B NAND_BYTES_PER_ECC_BLOCK
+These all take a positive integer value as their argument.
+The value will be copied directly into the respective field
+of the SPKG header structure. For details on these values,
+refer to Section 7.4 of the Renesas RZ/N1 User's Manual.
+.
+.TP
+.B ADD_DUMMY_BLP
+Takes a numeric argument, which is treated as a boolean. Any nonzero
+value will cause a fake BLp security header to be included in the SPKG
+output.
+.
+.TP
+.B PADDING
+Takes a positive integer value, with an optional
+.B K
+or
+.B M
+suffix, indicating KiB / MiB respectively.
+The output SPKG file will be padded to a multiple of this value.
+.
 .SS sunxi_egon
 The primary configuration is the name to use for the device tree.
 .
diff --git a/include/image.h b/include/image.h
index 7717a4c13d..acfbb6a53a 100644
--- a/include/image.h
+++ b/include/image.h
@@ -230,6 +230,7 @@ enum image_type_t {
IH_TYPE_SUNXI_EGON, /* Allwinner eGON Boot Image */
IH_TYPE_SUNXI_TOC0, /* Allwinner TOC0 Boot Image */
IH_TYPE_FDT_LEGACY, /* Binary Flat Device Tree Blob in a 
Legacy Image */
+   IH_TYPE_RENESAS_SPKG,   /* Renesas SPKG image */
 
IH_TYPE_COUNT,  /* Number of image type

[PATCH v4 03/10] clk: renesas: add R906G032 driver

2023-03-08 Thread Ralph Siemsen
Clock driver for the Renesas RZ/N1 SoC family. This is based on
Linux kernel 6.2.y drivers/clk/renesas/r9a06g032-clocks.c as found in
commit 02693e11611e ("clk: renesas: r9a06g032: Repair grave increment error"),
with the following additional patch series applied:
https://lore.kernel.org/linux-renesas-soc/20230301215520.828455-1-ralph.siem...@linaro.org/

Notable difference: this version avoids allocating a 'struct clk'
for each clock source, as this is problematic before relocation.
Instead, it uses the same approach as existing Renesas RCAR2/3
clock drivers, using a temporary structure filled on-the-fly.

Signed-off-by: Ralph Siemsen 
---

Changes in v4:
- commit message now includes hash of Linux upon which this is based
  as well as the additional patches (clock table cleanups)
- sync changes from review on linux patches, including
  - move RB macro higher up and document it, matching Linux driver
  - use multiply/divide instead of shifts for computing reg address
  - improve comments for clock gate, descriptor structures

Changes in v3:
- convert data table to explicit reg/bit numbers
- drop the unused scon, mirack, mirstat fields
- added some kernel docs to structures
- use enum for type field of struct r9a06g032_clkdesc
- cleanup macros for one assignment per line
- add a macro for top-most clock ID value ~0
- use dev_dbg() instead of debug/print
- minor reformatting, declarations before code, etc
- !foo instead of foo == 0
- IS_ERR / PTR_ERR where appropriate
- implement div_table handling
- remove some #if 0 old test code

 drivers/clk/renesas/Kconfig|6 +
 drivers/clk/renesas/Makefile   |1 +
 drivers/clk/renesas/r9a06g032-clocks.c | 1096 
 3 files changed, 1103 insertions(+)
 create mode 100644 drivers/clk/renesas/r9a06g032-clocks.c

diff --git a/drivers/clk/renesas/Kconfig b/drivers/clk/renesas/Kconfig
index 6788415eed..bbc618f464 100644
--- a/drivers/clk/renesas/Kconfig
+++ b/drivers/clk/renesas/Kconfig
@@ -130,3 +130,9 @@ config CLK_R8A779A0
depends on CLK_RCAR_GEN3
help
  Enable this to support the clocks on Renesas R8A779A0 SoC.
+
+config CLK_R9A06G032
+   bool "Renesas R9A06G032 clock driver"
+   depends on CLK_RENESAS
+   help
+ Enable this to support the clocks on Renesas R9A06G032 SoC.
diff --git a/drivers/clk/renesas/Makefile b/drivers/clk/renesas/Makefile
index a0d8c10bdb..7f0ef28367 100644
--- a/drivers/clk/renesas/Makefile
+++ b/drivers/clk/renesas/Makefile
@@ -19,3 +19,4 @@ obj-$(CONFIG_CLK_R8A77980) += r8a77980-cpg-mssr.o
 obj-$(CONFIG_CLK_R8A77990) += r8a77990-cpg-mssr.o
 obj-$(CONFIG_CLK_R8A77995) += r8a77995-cpg-mssr.o
 obj-$(CONFIG_CLK_R8A779A0) += r8a779a0-cpg-mssr.o
+obj-$(CONFIG_CLK_R9A06G032) += r9a06g032-clocks.o
diff --git a/drivers/clk/renesas/r9a06g032-clocks.c 
b/drivers/clk/renesas/r9a06g032-clocks.c
new file mode 100644
index 00..a2adefc9bb
--- /dev/null
+++ b/drivers/clk/renesas/r9a06g032-clocks.c
@@ -0,0 +1,1096 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * R9A06G032 clock driver
+ *
+ * Copyright (C) 2018 Renesas Electronics Europe Limited
+ *
+ * Michel Pollet , 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/**
+ * struct regbit - describe one bit in a register
+ * @reg: offset of register relative to base address,
+ *  expressed in units of 32-bit words (not bytes),
+ * @bit: which bit (0 to 31) in the register
+ *
+ * This structure is used to compactly encode the location
+ * of a single bit in a register. Five bits are needed to
+ * encode the bit number. With uint16_t data type, this
+ * leaves 11 bits to encode a register offset up to 2047.
+ *
+ * Since registers are aligned on 32-bit boundaries, the
+ * offset will be specified in 32-bit words rather than bytes.
+ * This allows encoding an offset up to 0x1FFC (8188) bytes.
+ *
+ * Helper macro RB() takes care of converting the register
+ * offset from bytes to 32-bit words.
+ */
+struct regbit {
+   u16 reg:11;
+   u16 bit:5;
+};
+
+#define RB(_reg, _bit) ((struct regbit) { \
+   .reg = (_reg) / 4, \
+   .bit = (_bit) \
+})
+
+/**
+ * struct r9a06g032_gate - clock-related control bits
+ * @gate:   clock enable/disable
+ * @reset:  clock module reset (active low)
+ * @ready:  enables NoC forwarding of read/write requests to device,
+ *  (eg. device is ready to handle read/write requests)
+ * @midle:  request to idle the NoC interconnect
+ *
+ * Each of these fields describes a single bit in a register,
+ * which controls some aspect of clock gating. The @gate field
+ * is mandatory, this one enables/disables the clock. The
+ * other fields are optional, with zero indicating "not used".
+ *
+ * In most cases there is a @reset bit which needs to be
+ * de-asserted to bring the module out of reset.
+ *
+ * Modules may also need to signal when the are @ready to
+ * handle requests (read/wr

[PATCH v4 05/10] ram: cadence: add driver for Cadence EDAC

2023-03-08 Thread Ralph Siemsen
Driver for Cadence EDAC DDR controller, as found in the Renesas RZ/N1.

Signed-off-by: Ralph Siemsen 
---

(no changes since v3)

Changes in v3:
- assorted small cleanups
- support version 1.0 silicon (previously #if 0...)

 drivers/ram/Kconfig |   1 +
 drivers/ram/Makefile|   2 +
 drivers/ram/cadence/Kconfig |  12 +
 drivers/ram/cadence/Makefile|   1 +
 drivers/ram/cadence/ddr_async.c | 311 
 drivers/ram/cadence/ddr_ctrl.c  | 414 
 drivers/ram/cadence/ddr_ctrl.h  | 175 ++
 7 files changed, 916 insertions(+)
 create mode 100644 drivers/ram/cadence/Kconfig
 create mode 100644 drivers/ram/cadence/Makefile
 create mode 100644 drivers/ram/cadence/ddr_async.c
 create mode 100644 drivers/ram/cadence/ddr_ctrl.c
 create mode 100644 drivers/ram/cadence/ddr_ctrl.h

diff --git a/drivers/ram/Kconfig b/drivers/ram/Kconfig
index e085119963..2b6d8f1c7b 100644
--- a/drivers/ram/Kconfig
+++ b/drivers/ram/Kconfig
@@ -108,6 +108,7 @@ config IMXRT_SDRAM
  This driver is for the sdram memory interface with the SEMC.
 
 source "drivers/ram/aspeed/Kconfig"
+source "drivers/ram/cadence/Kconfig"
 source "drivers/ram/rockchip/Kconfig"
 source "drivers/ram/sifive/Kconfig"
 source "drivers/ram/stm32mp1/Kconfig"
diff --git a/drivers/ram/Makefile b/drivers/ram/Makefile
index 83948e2c43..e2d5e730d1 100644
--- a/drivers/ram/Makefile
+++ b/drivers/ram/Makefile
@@ -22,3 +22,5 @@ obj-$(CONFIG_IMXRT_SDRAM) += imxrt_sdram.o
 obj-$(CONFIG_RAM_SIFIVE) += sifive/
 
 obj-$(CONFIG_ARCH_OCTEON) += octeon/
+
+obj-$(CONFIG_CADENCE_DDR_CTRL) += cadence/
diff --git a/drivers/ram/cadence/Kconfig b/drivers/ram/cadence/Kconfig
new file mode 100644
index 00..2d5469cb8e
--- /dev/null
+++ b/drivers/ram/cadence/Kconfig
@@ -0,0 +1,12 @@
+if RAM || SPL_RAM
+
+config CADENCE_DDR_CTRL
+   bool "Enable Cadence DDR controller"
+   depends on DM
+   help
+ Enable support for Cadence DDR controller, as found on
+ the Renesas RZ/N1 SoC. This controller has a large number
+ of registers which need to be programmed, mostly using values
+ obtained from Denali SOMA files via a TCL script.
+
+endif
diff --git a/drivers/ram/cadence/Makefile b/drivers/ram/cadence/Makefile
new file mode 100644
index 00..16c7fe8488
--- /dev/null
+++ b/drivers/ram/cadence/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_CADENCE_DDR_CTRL) += ddr_async.o ddr_ctrl.o
diff --git a/drivers/ram/cadence/ddr_async.c b/drivers/ram/cadence/ddr_async.c
new file mode 100644
index 00..444eeb8ac7
--- /dev/null
+++ b/drivers/ram/cadence/ddr_async.c
@@ -0,0 +1,311 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * RZ/N1 DDR Controller initialisation
+ *
+ * The DDR Controller register values for a specific DDR device, mode and
+ * frequency are generated using a Cadence tool.
+ *
+ * Copyright (C) 2015 Renesas Electronics Europe Ltd
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "ddr_ctrl.h"
+
+void clk_rzn1_reset_state(struct clk *clk, int on);
+
+extern u32 ddr_00_87_async[];
+extern u32 ddr_350_374_async[];
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct cadence_ddr_info {
+   struct udevice *dev;
+   void __iomem *ddrc;
+   void __iomem *phy;
+   struct clk clk_ddrc;
+   struct clk hclk_ddrc;
+   struct regmap *syscon;
+   bool enable_ecc;
+   bool enable_8bit;
+};
+
+static inline u32 cadence_readl(void __iomem *addr, unsigned int offset)
+{
+   return readl(addr + offset);
+}
+
+static inline void cadence_writel(void __iomem *addr, unsigned int offset,
+ u32 data)
+{
+   debug("%s: addr = 0x%p, value = 0x%08x\n", __func__, addr + offset, 
data);
+   writel(data, addr + offset);
+}
+
+#define ddrc_readl(off)cadence_readl(priv->ddrc, off)
+#define ddrc_writel(val, off)  cadence_writel(priv->ddrc, off, val)
+
+#define phy_readl(off) cadence_readl(priv->phy, off)
+#define phy_writel(val, off)   cadence_writel(priv->phy, off, val)
+
+#define RZN1_DDR3_SINGLE_BANK 3
+#define RZN1_DDR3_DUAL_BANK 32
+
+#define FUNCCTRL   0x00
+#define  FUNCCTRL_MASKSDLOFS   (0x18 << 16)
+#define  FUNCCTRL_DVDDQ_1_5V   (1 << 8)
+#define  FUNCCTRL_RESET_N  (1 << 0)
+#define DLLCTRL0x04
+#define  DLLCTRL_ASDLLOCK  (1 << 26)
+#define  DLLCTRL_MFSL_500MHz   (2 << 1)
+#define  DLLCTRL_MDLLSTBY  (1 << 0)
+#define ZQCALCTRL  0x08
+#define  ZQCALCTRL_ZQCALEND(1 << 30)
+#define  ZQCALCTRL_ZQCALRSTB   (1 << 0)
+#define ZQODTCTRL  0x0c
+#define RDCTRL 0x10
+#define RDTMG  0x14
+#define FIFOINIT   0x18
+#define  FIFOINIT_RDPTINITEXE  (1 << 8)
+#define  FIFOINIT_WRPTINITEXE  (1 << 0)
+#define OUTCTRL0x1c
+#define  OUTCTRL_ADCMDOE   (1 << 0)
+#define WLCTRL10x40
+#define  WLCTRL1_WLSTR (1 << 24)
+#define DQCALOFS1  0x

[PATCH v4 06/10] dts: basic devicetree for Renesas RZ/N1 SoC

2023-03-08 Thread Ralph Siemsen
This is taken from Linux kernel 5.17, and contains just bare minimum
functionality: CPU, UART and system timer.

Additional functionality (from newer kernel versions) will be added
later. Note that the Linux side is under active development.

Signed-off-by: Ralph Siemsen 
---
The following changes were made, compared with Linux 5.17:

1) Add node for system controller registers.
   Declare it as syscon to provide a regmap interface.

2) In the clock controller node (renesas,r9a06g032-sysctrl),
   replace regs with regmap.

3) Add syscon-reset node, making use of the syscon regmap.

4) Add syscon phandle to ddrctrl. Used for checking h/w version.

5) Simplify the compatible string for all the UARTS, as per
   doc/device-tree-bindings/serial/snps-dw-apb-uart.txt

I could not find a way to avoid 1) and 2). Putting "syscon" in the
compatible string for the clock controller leads to a catch-22,
where the driver fails to initialize, and then boot hangs.

(no changes since v3)

Changes in v3:
- add syscon phandle to ddrctl
- simplify UART compatible strings

 arch/arm/dts/r9a06g032.dtsi   | 226 ++
 include/dt-bindings/clock/r9a06g032-sysctrl.h | 148 
 2 files changed, 374 insertions(+)
 create mode 100644 arch/arm/dts/r9a06g032.dtsi
 create mode 100644 include/dt-bindings/clock/r9a06g032-sysctrl.h

diff --git a/arch/arm/dts/r9a06g032.dtsi b/arch/arm/dts/r9a06g032.dtsi
new file mode 100644
index 00..e0ddffb074
--- /dev/null
+++ b/arch/arm/dts/r9a06g032.dtsi
@@ -0,0 +1,226 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Base Device Tree Source for the Renesas RZ/N1D (R9A06G032)
+ *
+ * Copyright (C) 2018 Renesas Electronics Europe Limited
+ *
+ */
+
+#include 
+#include 
+
+/ {
+   compatible = "renesas,r9a06g032";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   cpus {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   cpu@0 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a7";
+   reg = <0>;
+   clocks = <&sysctrl R9A06G032_CLK_A7MP>;
+   };
+
+   cpu@1 {
+   device_type = "cpu";
+   compatible = "arm,cortex-a7";
+   reg = <1>;
+   clocks = <&sysctrl R9A06G032_CLK_A7MP>;
+   enable-method = "renesas,r9a06g032-smp";
+   cpu-release-addr = <0 0x4000c204>;
+   };
+   };
+
+   ext_jtag_clk: extjtagclk {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <0>;
+   };
+
+   ext_mclk: extmclk {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <4000>;
+   };
+
+   ext_rgmii_ref: extrgmiiref {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <0>;
+   };
+
+   ext_rtc_clk: extrtcclk {
+   #clock-cells = <0>;
+   compatible = "fixed-clock";
+   clock-frequency = <0>;
+   };
+
+   soc {
+   compatible = "simple-bus";
+   #address-cells = <1>;
+   #size-cells = <1>;
+   interrupt-parent = <&gic>;
+   ranges;
+
+   plat_regs: system-controller@4000c000 {
+   compatible = "syscon";
+   reg = <0x4000c000 0x1000>;
+   u-boot,dm-pre-reloc;
+   };
+
+   sysctrl: clock {
+   compatible = "renesas,r9a06g032-sysctrl";
+   #clock-cells = <1>;
+   regmap = <&plat_regs>;
+   u-boot,dm-pre-reloc;
+
+   clocks = <&ext_mclk>, <&ext_rtc_clk>,
+   <&ext_jtag_clk>, <&ext_rgmii_ref>;
+   clock-names = "mclk", "rtc", "jtag", "rgmii_ref_ext";
+   };
+
+   ddrctrl: memory-controller@4000d000 {
+   compatible = "cadence,ddr-ctrl";
+   reg = <0x4000d000 0x1000>, <0x4000e000 0x100>;
+   reg-names = "ddrc", "phy";
+   interrupts = ;
+   clocks = <&sysctrl R9A06G032_CLK_DDRC>, <&sysctrl 
R9A06G032_HCLK_DDRC>;
+   clock-names = "clk_ddrc", "hclk_ddrc";
+   syscon = <&plat_regs>;
+   status = "disabled";
+   };
+
+   uart0: serial@4006 {
+   compatible = "snps,dw-apb-uart";
+   reg = <0x4006 0x400>;
+   interrupts = ;
+   reg-shift = <2>;
+   reg-io-width = <4>;
+   clocks = <&sysctrl R9A06G032_CLK_UAR

[PATCH v4 04/10] pinctrl: renesas: add R906G032 driver

2023-03-08 Thread Ralph Siemsen
Pinctrl/pinconf driver for Renesas RZ/N1 (R906G032) SoC.

This is quite rudimentary right now, and only supports applying a
default pin configuration as specified by the device tree.

Signed-off-by: Ralph Siemsen 
---

(no changes since v1)

 drivers/pinctrl/Makefile   |   1 +
 drivers/pinctrl/renesas/Kconfig|   7 +
 drivers/pinctrl/renesas/Makefile   |   1 +
 drivers/pinctrl/renesas/pinctrl-rzn1.c | 379 +
 include/dt-bindings/pinctrl/rzn1-pinctrl.h | 141 
 5 files changed, 529 insertions(+)
 create mode 100644 drivers/pinctrl/renesas/pinctrl-rzn1.c
 create mode 100644 include/dt-bindings/pinctrl/rzn1-pinctrl.h

diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile
index 3b167d099f..450267732c 100644
--- a/drivers/pinctrl/Makefile
+++ b/drivers/pinctrl/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_PINCTRL_INTEL) += intel/
 obj-$(CONFIG_ARCH_MTMIPS) += mtmips/
 obj-$(CONFIG_ARCH_NPCM) += nuvoton/
 obj-$(CONFIG_ARCH_RMOBILE) += renesas/
+obj-$(CONFIG_ARCH_RZN1) += renesas/
 obj-$(CONFIG_PINCTRL_SANDBOX)  += pinctrl-sandbox.o
 obj-$(CONFIG_PINCTRL_SUNXI)+= sunxi/
 obj-$(CONFIG_PINCTRL_UNIPHIER) += uniphier/
diff --git a/drivers/pinctrl/renesas/Kconfig b/drivers/pinctrl/renesas/Kconfig
index 8f994d8d76..b707d7549b 100644
--- a/drivers/pinctrl/renesas/Kconfig
+++ b/drivers/pinctrl/renesas/Kconfig
@@ -127,3 +127,10 @@ config PINCTRL_PFC_R7S72100
  Support pin multiplexing control on Renesas RZ/A1 R7S72100 SoCs.
 
 endif
+
+config PINCTRL_RZN1
+   bool "Renesas RZ/N1 R906G032 pin control driver"
+   depends on ARCH_RZN1
+   default y if ARCH_RZN1
+   help
+ Support pin multiplexing control on Renesas RZ/N1 R906G032 SoCs.
diff --git a/drivers/pinctrl/renesas/Makefile b/drivers/pinctrl/renesas/Makefile
index 1198c86855..39b2f65f2e 100644
--- a/drivers/pinctrl/renesas/Makefile
+++ b/drivers/pinctrl/renesas/Makefile
@@ -18,3 +18,4 @@ obj-$(CONFIG_PINCTRL_PFC_R8A77990) += pfc-r8a77990.o
 obj-$(CONFIG_PINCTRL_PFC_R8A77995) += pfc-r8a77995.o
 obj-$(CONFIG_PINCTRL_PFC_R8A779A0) += pfc-r8a779a0.o
 obj-$(CONFIG_PINCTRL_PFC_R7S72100) += pfc-r7s72100.o
+obj-$(CONFIG_PINCTRL_RZN1) += pinctrl-rzn1.o
diff --git a/drivers/pinctrl/renesas/pinctrl-rzn1.c 
b/drivers/pinctrl/renesas/pinctrl-rzn1.c
new file mode 100644
index 00..fdc43c8e71
--- /dev/null
+++ b/drivers/pinctrl/renesas/pinctrl-rzn1.c
@@ -0,0 +1,379 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2014-2018 Renesas Electronics Europe Limited
+ *
+ * Phil Edworthy 
+ * Based on a driver originally written by Michel Pollet at Renesas.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Field positions and masks in the pinmux registers */
+#define RZN1_L1_PIN_DRIVE_STRENGTH 10
+#define RZN1_L1_PIN_DRIVE_STRENGTH_4MA 0
+#define RZN1_L1_PIN_DRIVE_STRENGTH_6MA 1
+#define RZN1_L1_PIN_DRIVE_STRENGTH_8MA 2
+#define RZN1_L1_PIN_DRIVE_STRENGTH_12MA3
+#define RZN1_L1_PIN_PULL   8
+#define RZN1_L1_PIN_PULL_NONE  0
+#define RZN1_L1_PIN_PULL_UP1
+#define RZN1_L1_PIN_PULL_DOWN  3
+#define RZN1_L1_FUNCTION   0
+#define RZN1_L1_FUNC_MASK  0xf
+#define RZN1_L1_FUNCTION_L20xf
+
+/*
+ * The hardware manual describes two levels of multiplexing, but it's more
+ * logical to think of the hardware as three levels, with level 3 consisting of
+ * the multiplexing for Ethernet MDIO signals.
+ *
+ * Level 1 functions go from 0 to 9, with level 1 function '15' (0xf) 
specifying
+ * that level 2 functions are used instead. Level 2 has a lot more options,
+ * going from 0 to 61. Level 3 allows selection of MDIO functions which can be
+ * floating, or one of seven internal peripherals. Unfortunately, there are two
+ * level 2 functions that can select MDIO, and two MDIO channels so we have 
four
+ * sets of level 3 functions.
+ *
+ * For this driver, we've compounded the numbers together, so:
+ *0 to   9 is level 1
+ *   10 to  71 is 10 + level 2 number
+ *   72 to  79 is 72 + MDIO0 source for level 2 MDIO function.
+ *   80 to  87 is 80 + MDIO0 source for level 2 MDIO_E1 function.
+ *   88 to  95 is 88 + MDIO1 source for level 2 MDIO function.
+ *   96 to 103 is 96 + MDIO1 source for level 2 MDIO_E1 function.
+ * Examples:
+ *  Function 28 corresponds UART0
+ *  Function 73 corresponds to MDIO0 to GMAC0
+ *
+ * There are 170 configurable pins (called PL_GPIO in the datasheet).
+ */
+
+/*
+ * Structure detailing the HW registers on the RZ/N1 devices.
+ * Both the Level 1 mux registers and Level 2 mux registers have the same
+ * structure. The only difference is that Level 2 has additional MDIO registers
+ * at the end.
+ */
+struct rzn1_pinctrl_regs {
+   u32 conf[170];
+   u32 pad0[86];
+   u32 status_protect; /* 0x400 */
+   /* MDIO mux registers, level2 only */
+   u32 l2_mdio[2];
+};
+
+#define NUM_CONF   

  1   2   >