Re: [RESEND PATCH] kconfig: Proposed language extension for multiple builds

2023-03-10 Thread Randy Dunlap
Hi--

On 3/10/23 18:37, Simon Glass wrote:
> (I am sending this again to get more feedback)
> 
> In the case of Linux, only one build is produced so there is only a
> single configuration. For other projects, such as U-Boot and Zephyr, the
> same code is used to produce multiple builds, each with related (but
> different) options enabled.
> 
> This can be handled with the existing kconfig language, but it is quite
> verbose, somewhat tedious and very error-prone, since there is a lot of
> duplication. The result is hard to maintain.
> 
> Describe an extension to the Kconfig language to support easier handling
> of this use case.
> 
> Signed-off-by: Simon Glass 

IMO Masahiro has already answered this multiple times and I agree with his 
answers.

For others, the full previous thread is at
  
https://lore.kernel.org/all/20230219145453.1.Idaaf79c3e768b85750d5a7eb732052576c5e07e5@changeid/


> ---
> 
>  Documentation/kbuild/kconfig-language.rst | 134 ++
>  1 file changed, 134 insertions(+)


-- 
~Randy


[RESEND PATCH] kconfig: Proposed language extension for multiple builds

2023-03-10 Thread Simon Glass
(I am sending this again to get more feedback)

In the case of Linux, only one build is produced so there is only a
single configuration. For other projects, such as U-Boot and Zephyr, the
same code is used to produce multiple builds, each with related (but
different) options enabled.

This can be handled with the existing kconfig language, but it is quite
verbose, somewhat tedious and very error-prone, since there is a lot of
duplication. The result is hard to maintain.

Describe an extension to the Kconfig language to support easier handling
of this use case.

Signed-off-by: Simon Glass 
---

 Documentation/kbuild/kconfig-language.rst | 134 ++
 1 file changed, 134 insertions(+)

diff --git a/Documentation/kbuild/kconfig-language.rst 
b/Documentation/kbuild/kconfig-language.rst
index 858ed5d80defe..73fb016a5533f 100644
--- a/Documentation/kbuild/kconfig-language.rst
+++ b/Documentation/kbuild/kconfig-language.rst
@@ -228,6 +228,24 @@ applicable everywhere (see syntax).
   enables the third modular state for all config symbols.
   At most one symbol may have the "modules" option set.
 
+- phase declaration: "defphase"
+  This defines a new build phase. See `Build Phases`_.
+
+- default phase: "phasedefault"
+  This indicates the default build phase. See `Build Phases`_.
+
+- add entries for phases: "addphases"
+  This creates new phase-specific entries based on a template entry and adds
+  the same attributes to it. See `Build Phases`_.
+
+- set entries for phases: "setphases"
+  This sets the phases which need an entry. This allows creating an entry that
+  only has a primary phase. See `Build Phases`_.
+
+- indicate a phase-specific attribute: "forphases"
+  This marks an attribute as being applicable only to a particular phase or
+  group of phases.  See `Build Phases`_.
+
 Menu dependencies
 -
 
@@ -319,6 +337,119 @@ MODVERSIONS directly depends on MODULES, this means it's 
only visible if
 MODULES is different from 'n'. The comment on the other hand is only
 visible when MODULES is set to 'n'.
 
+Build Phases
+
+
+Some projects use Kconfig to control multiple build phases, each phase
+resulting in a separate set of object files and executable. This is the
+case in U-Boot [12]_. Zephyr OS seems to be heading this way too [13]_.
+
+Generally the phases are related, so that enabling an entry in the primary
+phase also enables it by default in the others. But in some cases it may
+be desirable to use separate conditions for each phase.
+
+All phases have a phase name, for example `SPL`. This name is used as a
+prefix to each entry used in that phase, with an underscore in between.
+So if FOO is the primary entry, the equivalent entry for the SPL phase
+is SPL_FOO. The primary phase is marked with a "phasedefault" entry.
+
+Phases are declared like any other menu entry except that also have a
+"defphase" keyword. Phase entries are normally hidden so do not have a
+prompt::
+
+config PPL
+bool
+defphase "Primary Program Loader"
+phasedefault
+help
+  This is the primary bootloader.
+
+config SPL
+bool
+defphase "Secondary Program Loader"
+help
+  This is used to set up memory and load the primary bootloader.
+
+The default phase (here PPL) is assumed for all entries, in the sense that
+all entries are present in PPL by default and no prefix is needed on these
+entries. So FOO means that it applies to PPL. There must be exactly one
+default phase.
+
+The resulting menu entries can be used normally throughout the Kconfig. With
+this technique, the different build phases can be fully and individually
+controlled from Kconfig.
+
+However it is not ideal. Often the secondary phases have far fewer entries than
+the primary phase, since they offer fewer features. Even so, each FOO that is
+needed in a phase must have an SPL_FOO, etc. To avoid an explosion of entries,
+it is possible to indicate which are enabled, as a shortcut for creating new
+entries::
+
+config FOO
+bool "Enable foo feature"
+addphases SPL
+depends on %BAR
+depends on QUX
+forphases SPL depends on FIZZ
+
+Note that "%" expands to the phase, so this is equivalent to (ignoring BAR)::
+
+config FOO
+bool "Enable foo feature"
+depends on BAR
+depends on QUX
+
+config SPL_FOO# Phase is prepended
+bool "Enable foo feature (SPL)"# Suffix is added
+depends on SPL_BAR # "%" dependency is expanded
+depends on QUX
+depends on FIZZ# Added only for SPL
+depends on SPL # Added automatically
+
+Attributes declared in the primary symbol FOO (such as "depends on BAR") also
+apply to the secondary ones.
+
+An entry without any 'addphases' attribute applies to all phases. Individual
+phase entries are not available in that case. If the 

Re: [PATCH v2 3/5] binman: add tests for sign option

2023-03-10 Thread Simon Glass
Hi Ivan,

On Fri, 10 Mar 2023 at 17:47, Simon Glass  wrote:
>
> Add the test which provides sequence of actions:
>   1. create the image from binman dts
>   2. create public and private keys
>   3. add public key into dtb with fdt_add_pubkey
>   4. 1. sign FIT container with new sign option with extracting from
> image
>  2. sign exact FIT container with replacing of it in image
>   5. check with fit_check_sign
>
> Signed-off-by: Ivan Mikhaylov 
> ---
>  tools/binman/ftest.py  | 61 +
>  tools/binman/test/277_fit_sign.dts | 63 ++
>  2 files changed, 124 insertions(+)
>  create mode 100644 tools/binman/test/277_fit_sign.dts
>
> Applied to u-boot-dm/next, thanks!

As mentioned on the other email I had a bit of trouble getting this
over the line Here is what I did:

Renumber test file from 277 to 280
Move UpdateSignatures() to Entry base class
Don't allow missing mkimage as it doesn't make sense
Propagate --toolpath for CI
Call mark_build_done() to avoid regenerating FIT

Regards,
Simon


Re: [PATCH v2 3/5] binman: add tests for sign option

2023-03-10 Thread Simon Glass
Add the test which provides sequence of actions:
  1. create the image from binman dts
  2. create public and private keys
  3. add public key into dtb with fdt_add_pubkey
  4. 1. sign FIT container with new sign option with extracting from
image
 2. sign exact FIT container with replacing of it in image
  5. check with fit_check_sign

Signed-off-by: Ivan Mikhaylov 
---
 tools/binman/ftest.py  | 61 +
 tools/binman/test/277_fit_sign.dts | 63 ++
 2 files changed, 124 insertions(+)
 create mode 100644 tools/binman/test/277_fit_sign.dts

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


Re: [PATCH v3] binman: bintool: Add support for tool directories

2023-03-10 Thread Simon Glass
Hi Neha,

On Fri, 24 Feb 2023 at 03:51, Neha Malcom Francis  wrote:
>
> Currently, bintool supports external compilable tools as single
> executable files. Adding support for git repos that can be used to run
> non-compilable scripting tools that cannot otherwise be present in
> binman.
>
> Signed-off-by: Neha Malcom Francis 
> ---
> Changes in v3:
> - moved back to using DOWNLOAD_DIR as community is making
>   relevant changes
> - extended coverage for bintool_test.py
> - added function comment for new parameter
>
> Changes in v2:
> - added parameter to obtain path to download the directory
>   optionally, enables flexibility to avoid using
>   DOWNLOAD_DESTDIR
> - added test to bintool_test.py
> - s/FETCH_NO_BUILD/FETCH_SOURCE
> - code reformatting
>
>  tools/binman/bintool.py| 47 +-
>  tools/binman/bintool_test.py   | 43 +++
>  tools/binman/btool/_testing.py |  4 +++
>  tools/patman/tools.py  |  2 +-
>  4 files changed, 88 insertions(+), 8 deletions(-)

I am OK with doing this but worried that it will be used for shell
scripts, which we are trying to avoid.

The code looks OK for now. Perhaps we can revisit this when we have a
use case? I also think we should have each tool individually shown in
the list, rather than having them be 'hidden' behind a btool.

Regards,
Simon


Re: [PATCH] x86: Revert "x86: minnowmax: Adjust CONFIG_TEXT_BASE"

2023-03-10 Thread Simon Glass
Hi Bin,

On Sun, 5 Feb 2023 at 19:35, Bin Meng  wrote:
>
> Hi Simon,
>
> On Mon, Feb 6, 2023 at 8:54 AM Simon Glass  wrote:
> >
> > This causes Minnowmax to stop booting. I am not sure why though.
> >
> > Drop the EFI_LOADER feature instead, since it is not needed.
> >
> > This reverts commit 66e2c665f3b60d726e1c26ad44ac97aa76ead6f5.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  configs/minnowmax_defconfig | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
>
> This is weird. Can you do some debugging?

I think I got to the bottom of it. I sent a v2.

Regards,
Simon


Re: [PATCH v2 1/5] binman: add documentation for binman sign option

2023-03-10 Thread Simon Glass
Add the documentation about binman sign option and providing an
example.

Signed-off-by: Ivan Mikhaylov 
---
 tools/binman/binman.rst | 18 ++
 1 file changed, 18 insertions(+)

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


Re: [PATCH v2 2/5] binman: add sign option for binman

2023-03-10 Thread Simon Glass
Hi Ivan,

On Tue, 7 Mar 2023 at 14:13, Ivan Mikhaylov  wrote:
>
> Introduce proof of concept for binman's new option which provides sign
> and replace FIT containers in binary images.
>
> Usage as example:
>
> from:
> mkimage -G privateky -r -o sha256,rsa4096 -F fit
> binman replace -i flash.bin -f fit.fit fit
>
> to:
> binman sign -i flash.bin -k privatekey -a sha256,rsa4096 -f fit.fit fit
>
> and to this one if it's need to be extracted, signed with key and put it
> back in image:
> binman sign -i flash.bin -k privatekey -a sha256,rsa4096 fit
>
> Signed-off-by: Ivan Mikhaylov 
> ---
>  tools/binman/cmdline.py   | 13 +
>  tools/binman/control.py   | 29 -
>  tools/binman/etype/fit.py | 18 ++
>  tools/binman/etype/section.py |  3 +++
>  4 files changed, 62 insertions(+), 1 deletion(-)

This needs a few tweaks to get the test coverage up to 100% and use
the mark_build_done() feature added a few days ago.

I have taken the liberty of updating it and will apply it soon, since
this has been outstanding for a while.

Regards,
Simon

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


Re: [PATCH v2 4/5] tools: add fdt_add_pubkey

2023-03-10 Thread Simon Glass
From: Roman Kopytin 

Having to use the -K option to mkimage to populate U-Boot's .dtb with the
public key while signing the kernel FIT image is often a little
awkward. In particular, when using a meta-build system such as
bitbake/Yocto, having the tasks of the kernel and U-Boot recipes
intertwined, modifying deployed artifacts and rebuilding U-Boot with
an updated .dtb is quite cumbersome. Also, in some scenarios one may
wish to build U-Boot complete with the public key(s) embedded in the
.dtb without the corresponding private keys being present on the same
build host.

So this adds a simple tool that allows one to disentangle the kernel
and U-Boot builds, by simply copy-pasting just enough of the mkimage
code to allow one to add a public key to a .dtb. When using mkimage,
some of the information is taken from the .its used to build the
kernel (algorithm and key name), so that of course needs to be
supplied on the command line.

Signed-off-by: Roman Kopytin 
Signed-off-by: Ivan Mikhaylov 
Signed-off-by: Jan Kiszka 
Cc: Rasmus Villemoes 
---
 tools/.gitignore   |   1 +
 tools/Makefile |   3 +
 tools/fdt_add_pubkey.c | 138 +
 3 files changed, 142 insertions(+)
 create mode 100644 tools/fdt_add_pubkey.c

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


Re: [PATCH v2 5/5] test_vboot.py: include test of fdt_add_pubkey tool

2023-03-10 Thread Simon Glass
Hi Ivan,

On Tue, 7 Mar 2023 at 14:13, Ivan Mikhaylov  wrote:
>
> From: Roman Kopytin 
>
> Signed-off-by: Roman Kopytin 
> Cc: Rasmus Villemoes 
> ---
>  test/py/tests/test_vboot.py | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
> index e3e7ca4b21..956b8fcd43 100644
> --- a/test/py/tests/test_vboot.py
> +++ b/test/py/tests/test_vboot.py
> @@ -313,6 +313,13 @@ def test_vboot(u_boot_console, name, sha_algo, padding, 
> sign_options, required,
>
>  util.run_and_log(cons, [fit_check_sign, '-f', fit, '-k', dtb])
>
> +# Create a fresh .dtb without the public keys
> +dtc('sandbox-u-boot.dts')
> +# Then add the dev key via the fdt_add_pubkey tool
> +util.run_and_log(cons, [fdt_add_pubkey, '-a', '%s,rsa2048' % 
> sha_algo,
> +'-k', tmpdir, '-n', 'dev', '-r', 'conf', 
> dtb])
> +util.run_and_log(cons, [fit_check_sign, '-f', fit, '-k', dtb])
> +
>  if full_test:
>  # Make sure that U-Boot checks that the config is in the list of
>  # hashed nodes. If it isn't, a security bypass is possible.
> @@ -500,6 +507,7 @@ def test_vboot(u_boot_console, name, sha_algo, padding, 
> sign_options, required,
>  mkimage = cons.config.build_dir + '/tools/mkimage'
>  binman = cons.config.source_dir + '/tools/binman/binman'
>  fit_check_sign = cons.config.build_dir + '/tools/fit_check_sign'
> +fdt_add_pubkey = cons.config.build_dir + '/tools/fdt_add_pubkey'
>  dtc_args = '-I dts -O dtb -i %s' % tmpdir
>  dtb = '%ssandbox-u-boot.dtb' % tmpdir
>  sig_node = '/configurations/conf-1/signature'
> --
> 2.39.1
>

Unfortunately this test fails on sandbox:

https://source.denx.de/u-boot/custodians/u-boot-dm/-/jobs/591975

I think it would be better to put it in its own test (perhaps in the
same file) so we are not doing it on every test run. Also you could
check (in a very basic way) that it adds the key correctly since we
don't really need another test of the logic of doing that. We are just
checking that your tool calls that logic correctly.

I'll drop this one when applying, for now. Please take a look.

Regards,
Simon


Re: [PATCH V5 08/12] iot2050: Add script for signing artifacts

2023-03-10 Thread Simon Glass
Hi Jan,

On Sun, 12 Feb 2023 at 22:33, Jan Kiszka  wrote:
>
> On 13.02.23 05:26, Simon Glass wrote:
> > Hi Jan,
> >
> > On Tue, 7 Feb 2023 at 11:39, Simon Glass  wrote:
> >>
> >> Hi Jan,
> >>
> >> On Tue, 7 Feb 2023 at 09:45, Jan Kiszka  wrote:
> >>>
> >>> On 07.02.23 16:28, Simon Glass wrote:
>  Hi Jan,
> 
>  On Mon, 6 Feb 2023 at 04:57, Jan Kiszka  wrote:
> >
> > On 06.02.23 11:47, Jan Kiszka wrote:
> >> On 04.02.23 23:26, Simon Glass wrote:
> >>> Hi Jan,
> >>>
> >>> On Fri, 3 Feb 2023 at 23:35, Jan Kiszka  
> >>> wrote:
> 
>  On 03.02.23 19:51, Tom Rini wrote:
> > On Fri, Feb 03, 2023 at 01:26:37PM +0100, Jan Kiszka wrote:
> >
> >> From: Jan Kiszka 
> >>
> >> There are many ways to get a signed firmware for the IOT2050 
> >> devices,
> >> namely for the parts under user-control. This script documents one 
> >> way
> >> of doing it, given a signing key. Augment the board documentation 
> >> with
> >> the required procedure around it.
> >>
> >> Signed-off-by: Jan Kiszka 
> > [snip]
> >> +# currently broken in upstream
> >> +#source/tools/binman/binman replace -i flash.bin -f 
> >> f...@0x38.fit fit@0x38
> >> +dd if=f...@0x38.fit of=flash.bin bs=$((0x1000)) 
> >> seek=$((0x38/0x1000)) conv=notrunc
> >
> > Is that still a true comment?
> >
> 
>  binman: Node '/fit@0x38/images/u-boot': Offset 0x0 (0) size 
>  0xb8870
>  (755824) is outside the section '/fit@0x38' starting at 0x0 (0) 
>  of
>  size 0x400 (1024)
> 
>  And for the second call:
> 
>  binman: Node '/fit@0x38': Replacing sections is not implemented 
>  yet
> >>>
> >>> I sent a patch to implement that.
> >>>
> >>> I'm not quite sure if this resolves the first problem, too. If not,
> >>> can you please provide a binman test for the case you need, or
> >>> instructions on how to cause the failure?
> >>
> >> Instructions to reproduce are basically
> >>  - apply this series
> >>  - build flash.bin according to doc/board/siemens/iot2050.rst
> >>  - drop the dd calls and activate binman in this signing script
> >>  - run it
> >>
> >> But I'll try your patch ASAP on my setup.
> >
> > Still left with
> >
> > binman: Node '/fit@0x38/images/u-boot': Offset 0x0 (0) size 0xb8928
> > (756008) is outside the section '/fit@0x38' starting at 0x0 (0) of
> > size 0x400 (1024)
> >
> > and
> >
> > binman: 'NoneType' object has no attribute 'props'
> >
> > That was for the second call of binman (source/tools/binman/binman
> > replace -i flash.bin -f f...@0x38.fit fit@0x38). The "not
> > implemented messages is gone.
> >
> > I've switched back to dd for the first call, but that did not work yet.
> > So the message above indicates a relevant error.
> >
> > Jan
> 
>  I thought I was able to follow all the steps (gosh, so many blobs) but
>  I got something different from the first 'binman' call in your script.
> 
>  binman: Error 1 running 'mkimage -t -F
>  /tmp/binman.l_xl69mi/f...@0x38.fit': mkimage: verify_header failed
>  for FIT Image support with exit code 1
> 
>  I will take a look at that...it is trying to rebuild the FIT and it
>  should not. It is another case of rebuilding sections that I didn't
>  think of.
> 
>  But actually, you need to create a new entry type for your signing
>  scheme. It looks like the signature is created by openssl and (rather
>  than putting it in a separate file) it creates a new file containing
>  both the signature and the file contents. That is a bit of a pain, but
>  can be made to work.
> 
>  Basically you need a new entry type (of which the FIT is a child) that
>  gets the contents of its child, signs it and returns that as the
>  contents. You can see vblock for an example, and
>  collection_contents_to_file(). Let me know if you want me to create an
>  example.
> 
>  The way it should work is that you run binman once (as part of the
>  U-Boot build) and it produces a final image. No messing about with
>  scripts, etc. In this case it looks like the key.pem file should be an
>  input to your new entry type.
> 
>  Using binman replace to sign something later is fine, but it is not
>  the intended use. Binman is supposed to be a single-pass image
>  builder.
> >>>
> >>> I strongly suspect we will need split build/sign also in the future
> >>> because those steps are generally separate in corporate production envs.
> >>> Maybe even 3 steps: assemble, extract hashes that should be signed and
> >>> embed signatures 

Re: [PATCH v7 13/23] core: fdtaddr: add devfdt_get_addr_size_index_ptr function

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 08:44, Johan Jonker  wrote:
>
> Add devfdt_get_addr_size_index_ptr function with the same
> functionality as devfdt_get_addr_size_index, but instead
> a return pointer is given.
> Use map_sysmem() function as cast for the return.
> Make same fix for devfdt_get_addr_index_ptr() function.
>
> Suggested-by: Michael Nazzareno Trimarchi 
> Signed-off-by: Johan Jonker 
> Reviewed-by: Michael Trimarchi 
> ---
>
> Changed V7:
>   use map_sysmem()
>
> Changed V5:
>   fix spelling
>   use tabs
> ---
>  drivers/core/fdtaddr.c | 17 -
>  include/dm/fdtaddr.h   | 17 -
>  2 files changed, 32 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v6 15/22] drivers: use dev_read_addr_index_ptr when cast to pointer

2023-03-10 Thread Simon Glass
Hi Johan,

On Mon, 6 Mar 2023 at 12:32, Johan Jonker  wrote:
>
>
>
> On 3/6/23 19:20, Simon Glass wrote:
> > Hi Johan,
> >
> > On Thu, 2 Mar 2023 at 17:15, Johan Jonker  wrote:
> >>
> >> The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU
> >> can expect 64-bit data from the device tree parser, so use
> >
> > Why is that? It seems quite inefficient.
> 1:
> ===
> Because the device tree does describes more then just only the internal 
> io/mem range.
> When a NAND chip is connected it must be able to describe partitions far 
> beyond that 32bit range.
> This change only changes the PARSE capacity defined by fdt_addr_t and 
> fdt_size_t and not the phys_addr_t and phys_size_t.
> Most drivers make a little mess when taking a DT reg value and then trying to 
> make it fit in a structure of multiple registers with various offsets.
> Fixing all of that is beyond my capacity/this serie and more a MAINTAINER 
> task.
>
> https://elixir.bootlin.com/u-boot/latest/source/drivers/mtd/mtdpart.c#L933
>
> struct mtd_partition {
> const char *name;   /* identifier string */
> uint64_t size;  /* partition size */
> uint64_t offset;/* offset within the master MTD space 
> */
> uint32_t mask_flags;/* master MTD flags to mask out for 
> this partition */
> struct nand_ecclayout *ecclayout;   /* out of band layout for 
> this partition (NAND only) */
> };
>
> int add_mtd_partitions_of(struct mtd_info *master)
> struct mtd_partition part = { 0 };
> fdt_addr_t offset;
> fdt_size_t size;
>
> [..]
> part.offset = offset;
> part.size = size;
>
> While the mtd_partition structure is ready with uint64_t size all the parse 
> functions that export this reg value were typedef to a 32bit value.
>
> ===
> Given mk808 rk3066a with NAND:
>
> [   38.750789] nand: Hynix H27UCG8T2ATR-BC 64G 3.3V 8-bit
> [   38.756650] nand: 8192 MiB, MLC, erase size: 2048 KiB, page size: 8192, 
> OOB size: 640
>
> ===
> BEFORE:
>
> List of MTD devices:
> * nand0
>   - type: MLC NAND flash
>   - block size: 0x20 bytes
>   - min I/O: 0x2000 bytes
>   - OOB size: 640 bytes
>   - OOB available: 4294967290 bytes
>   - ECC strength: 40 bits
>   - ECC step size: 1024 bytes
>   - bitflip threshold: 30 bits
>   - 0x-0x0002 : "nand0"
>   - 0x0040-0x0060 : "boot-blk-0"
>   - 0x0060-0x0080 : "boot-blk-1"
>   - 0x0080-0x00a0 : "boot-blk-2"
>   - 0x00a0-0x00c0 : "boot-blk-3"
>   - 0x00c0-0x00e0 : "boot-blk-4"
>   - 0x0100-0xfe00 : "rootfs"
>   - 0xfe00-0x0001 : "bbt"
>
> # This output is corrupted.
>
> ===
> AFTER:
>
> List of MTD devices:
> * nand0
>   - type: MLC NAND flash
>   - block size: 0x20 bytes
>   - min I/O: 0x2000 bytes
>   - OOB size: 640 bytes
>   - OOB available: 4294967290 bytes
>   - ECC strength: 40 bits
>   - ECC step size: 1024 bytes
>   - bitflip threshold: 30 bits
>   - 0x-0x0002 : "nand0"
>   - 0x0040-0x0060 : "boot-blk-0"
>   - 0x0060-0x0080 : "boot-blk-1"
>   - 0x0080-0x00a0 : "boot-blk-2"
>   - 0x00a0-0x00c0 : "boot-blk-3"
>   - 0x00c0-0x00e0 : "boot-blk-4"
>   - 0x0100-0x0001fe00 : "rootfs"
>   - 0x0001fe00-0x0002 : "bbt"
> ===
> Example:
> partitions {
> compatible = "fixed-partitions";
> #address-cells = <2>;
> #size-cells = <2>;
>
> partition@40 {
> reg = <0x0 0x0040 0x0 0x0020>;
> label = "boot-blk-0";
> };
>
> partition@60 {
> reg = <0x0 0x0060 0x0 0x0020>;
> label = "boot-blk-1";
> };
>
> partition@80 {
> reg = <0x0 0x0080 0x0 0x0020>;
> label = "boot-blk-2";
> };
>
> partition@a0 {
> reg = <0x0 0x00a0 0x0 0x0020>;
> label = "boot-blk-3";
> };
>
> partition@c0 {
> reg = <0x0 0x00c0 0x0 0x0020>;
> label = "boot-blk-4";
> };
>
> partition@100 {
> reg = <0x0 0x0100 0x1 0xfd00>;
> label = 

Re: [PATCH v6 12/22] core: fdtaddr: add devfdt_get_addr_size_index_ptr function

2023-03-10 Thread Simon Glass
Hi Johan,

On Mon, 6 Mar 2023 at 12:55, Johan Jonker  wrote:
>
>
>
> On 3/6/23 18:53, Simon Glass wrote:
> > Hi Johan,
> >
> > On Thu, 2 Mar 2023 at 17:15, Johan Jonker  wrote:
> >>
> >> Add devfdt_get_addr_size_index_ptr function with the same
> >> functionality as devfdt_get_addr_size_index, but instead
> >> a return pointer is given.
> >>
> >> Suggested-by: Michael Nazzareno Trimarchi 
> >> Signed-off-by: Johan Jonker 
> >> Reviewed-by: Michael Trimarchi 
> >> ---
> >>
> >> Changed V5:
> >>   fix spelling
> >>   use tabs
> >> ---
> >>  drivers/core/fdtaddr.c |  8 
> >>  include/dm/fdtaddr.h   | 17 -
> >>  2 files changed, 24 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c
> >> index 91bcd1a2..f5906ff9 100644
> >> --- a/drivers/core/fdtaddr.c
> >> +++ b/drivers/core/fdtaddr.c
> >> @@ -122,6 +122,14 @@ fdt_addr_t devfdt_get_addr_size_index(const struct 
> >> udevice *dev, int index,
> >>  #endif
> >>  }
> >>
> >> +void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index,
> >> +fdt_size_t *size)
> >> +{
> >> +   fdt_addr_t addr = devfdt_get_addr_size_index(dev, index, size);
> >> +
> >> +   return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
> >
> Just wondering, as a side question:
> Why is Uboot maintaining/exporting 2 sets of functions that do the do the 
> more or less the same thing.
>
> For example:
> devfdt_get_addr_size_index_ptr vs. dev_read_addr_size_index_ptr
>
> Or should we standardize and replace all by dev_read_addr_size_index_ptr if 
> possible?

Yes that is a bit wonky. The flat/live tree selection is supposed to
be in ofnode.c, so we could change it to call the ofnode version in
both cases, moving the logic into there. That is how other functions
work.

Regards,
Simon


sandbox_spl build warning

2023-03-10 Thread Simon Glass
Hi Marek,

I see this in CI for -next:

Building current source for 1 boards (0 threads, 64 jobs per thread)
   sandbox:  w+   sandbox_spl
+ 1159 | fdt_test_header_get(uts, fdt, "magic", fdt_magic(fdt));
+  | ^
+test/cmd/fdt.c:1159:9: note: referencing argument 2 of type ‘char *’
+test/cmd/fdt.c:1115:12: note: in a call to function ‘fdt_test_header_get’
+ 1115 | static int fdt_test_header_get(struct unit_test_state *uts,
char fdt[4096],
+  |^
+ 1160 | fdt_test_header_get(uts, fdt, "totalsize", fdt_totalsize(fdt));

here:

https://source.denx.de/u-boot/custodians/u-boot-dm/-/jobs/591918

Could you please take a look?

Regards,
Simon


Re: [PATCH V7 08/15] tools: Add script for converting public key into device tree include

2023-03-10 Thread Simon Glass
Hi Jan,

On Tue, 28 Feb 2023 at 10:22, Jan Kiszka  wrote:
>
> From: Jan Kiszka 
>
> Allows to create a public key device tree dtsi for inclusion into U-Boot
> SPL and proper during first build already. This can be achieved via
> CONFIG_DEVICE_TREE_INCLUDES.
>
> Signed-off-by: Jan Kiszka 
> ---
>  tools/key2dtsi.py | 64 +++
>  1 file changed, 64 insertions(+)
>  create mode 100755 tools/key2dtsi.py

Instead of this can you take a look at the binman support I added? It
has x509 support now in -next

Regards,
Simon


Re: [PATCH v2 2/5] binman: add sign option for binman

2023-03-10 Thread Simon Glass
Hi Ivan,

On Tue, 7 Mar 2023 at 14:13, Ivan Mikhaylov  wrote:
>
> Introduce proof of concept for binman's new option which provides sign
> and replace FIT containers in binary images.
>
> Usage as example:
>
> from:
> mkimage -G privateky -r -o sha256,rsa4096 -F fit
> binman replace -i flash.bin -f fit.fit fit
>
> to:
> binman sign -i flash.bin -k privatekey -a sha256,rsa4096 -f fit.fit fit
>
> and to this one if it's need to be extracted, signed with key and put it
> back in image:
> binman sign -i flash.bin -k privatekey -a sha256,rsa4096 fit
>
> Signed-off-by: Ivan Mikhaylov 
> ---
>  tools/binman/cmdline.py   | 13 +
>  tools/binman/control.py   | 29 -
>  tools/binman/etype/fit.py | 18 ++
>  tools/binman/etype/section.py |  3 +++
>  4 files changed, 62 insertions(+), 1 deletion(-)

This needs a few tweaks to get the test coverage up to 100% and use
the mark_build_done() feature added a few days ago.

I have taken the liberty of updating it and will apply it soon, since
this has been outstanding for a while.

Regards,
Simon


Re: [PATCH 09/10] efi: Support showing tables

2023-03-10 Thread Simon Glass
Hi Heinrich,

On Mon, 6 Mar 2023 at 01:39, Heinrich Schuchardt  wrote:
>
> On 2/26/23 02:33, Simon Glass wrote:
> > Add a command to display the tables provided by EFI.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >   cmd/efi.c | 40 +++-
> >   doc/usage/cmd/efi.rst | 22 ++
> >   2 files changed, 61 insertions(+), 1 deletion(-)
> >
> > diff --git a/cmd/efi.c b/cmd/efi.c
> > index c0384e0db28..86988d9e9e2 100644
> > --- a/cmd/efi.c
> > +++ b/cmd/efi.c
> > @@ -7,10 +7,12 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include 
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> >   #include 
> >
> >   DECLARE_GLOBAL_DATA_PTR;
> > @@ -273,8 +275,43 @@ done:
> >   return ret ? CMD_RET_FAILURE : 0;
> >   }
> >
> > +static int do_efi_tables(struct cmd_tbl *cmdtp, int flag, int argc,
> > +  char *const argv[])
>
>
> We already have function do_efi_show_tables() to print the list of EFI
> configuration tables. Please, avoid code duplication.

OK I created a separate file.

Of course the 'efidebug' command cannot be used in the app or payload,
since it did not create the systab.

>
> > +{
> > + struct efi_system_table *systab;
> > + int i;
> > +
> > + if (IS_ENABLED(CONFIG_EFI_APP)) {
> > + systab = efi_get_sys_table();
> > + if (!systab) {
> > + printf("Cannot read system table\n");
> > + return CMD_RET_FAILURE;
> > + }
> > + } else {
> > + int size;
> > + int ret;
> > +
> > + ret = efi_info_get(EFIET_SYS_TABLE, (void **), );
> > + if (ret) {
> > + printf("Cannot find EFI system table (err=%d)\n", 
> > ret);
> > + return CMD_RET_FAILURE;
> > + }
> > + }
> > + for (i = 0; i < systab->nr_tables; i++) {
> > + struct efi_configuration_table *tab = >tables[i];
> > + char guid_str[37];
> > +
> > + uuid_bin_to_str(tab->guid.b, guid_str, 1);
> > + printf("%p  %s  %s\n", tab->table, guid_str,
> > +uuid_guid_get_str(tab->guid.b));
>
>
> do_efi_show_tables() does this with printf("%pUl (%pUs)\n",..).
>
> > + }
> > +
> > + return 0;
> > +}
> > +
> >   static struct cmd_tbl efi_commands[] = {
> >   U_BOOT_CMD_MKENT(mem, 1, 1, do_efi_mem, "", ""),
> > + U_BOOT_CMD_MKENT(tables, 1, 1, do_efi_tables, "", ""),
> >   };
> >
> >   static int do_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> > argv[])
> > @@ -298,5 +335,6 @@ static int do_efi(struct cmd_tbl *cmdtp, int flag, int 
> > argc, char *const argv[])
> >   U_BOOT_CMD(
> >   efi, 3,  1,  do_efi,
> >   "EFI access",
> > - "mem [all]Dump memory information [include boot services]"
> > + "mem [all]Dump memory information [include boot services]\n"
> > + "tables   Dump tables"
> >   );
> > diff --git a/doc/usage/cmd/efi.rst b/doc/usage/cmd/efi.rst
> > index c029c423879..2424d3bb587 100644
> > --- a/doc/usage/cmd/efi.rst
> > +++ b/doc/usage/cmd/efi.rst
> > @@ -10,6 +10,7 @@ Synopsis
> >   ::
> >
> >   efi mem [all]
> > +efi tables
> >
> >   Description
> >   ---
> > @@ -54,6 +55,14 @@ Attributes
> >   Shows a code for memory attributes. The key for this is shown below 
> > the
> >   table.
> >
> > +efi tables
> > +~~
> > +
> > +This shows a list of the EFI tables provided in the system table. These use
> > +GUIDs so it is not possible in general to show the name of a table. But 
> > some
> > +effort is made to provide a useful table, where the GUID is known by 
> > U-Boot.
> > +
> > +
> >   Example
> >   ---
> >
> > @@ -195,3 +204,16 @@ Example
> >f: uncached, write-coalescing, write-through, write-back
> >   rf: uncached, write-coalescing, write-through, write-back, needs 
> > runtime mapping
> >1: uncached
> > +
> > +
> > +=> efi tables
> > +1f8eda98  ee4e5898-3914-4259-9d6e-dc7bd79403cf  
> > EFI_LZMA_COMPRESSED
> > +1ff2ace0  05ad34ba-6f02-4214-952e-4da0398e2bb9  
> > EFI_DXE_SERVICES
> > +1f8ea018  7739f24c-93d7-11d4-9a3a-0090273fc14d  EFI_HOB_LIST
> > +1ff2bac0  4c19049f-4137-4dd3-9c10-8b97a83ffdfa  EFI_MEMORY_TYPE
> > +1ff2cb10  49152e77-1ada-4764-b7a2-7afefed95e8b  
>
> This is what 'efi tables' / printf("%pUl (%pUs)\n",..). would output for
> an unknown table:
>
> 8868e871-e4f1-11d3-bc22-0080c73c8881 (8868e871-e4f1-11d3-bc22-0080c73c8881)
>
> Maybe uuid_guid_get_str() should return an empty string in case of an
> unknown GUID.

OK

>
> > +1f9ac018  060cc026-4c0d-4dda-8f41-595fef00a502  
> > EFI_MEM_STATUS_CODE_REC
> > +1f9ab000  eb9d2d31-2d88-11d3-9a16-0090273fc14d  EFI_SMBIOS
> > +1fb7e000  eb9d2d30-2d88-11d3-9a16-0090273fc14d  
> > 

Re: [PATCH v7 16/23] drivers: use dev_read_addr_index_ptr when cast to pointer

2023-03-10 Thread Simon Glass
Hi Johan,

On Fri, 10 Mar 2023 at 08:45, Johan Jonker  wrote:
>
> The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU
> can expect 64-bit data from the device tree parser, so use
> dev_read_addr_index_ptr instead of the dev_read_addr_index function
> in the various files in the drivers directory that cast to a pointer.

Can you mention that you are fixing some -ENODEV stuff at the same time?

>
> Signed-off-by: Johan Jonker 
> Reviewed-by: Michael Trimarchi 
> ---
>
> Changed V6:
>   use -EINVAL on return
>   drop cast
> ---
>  drivers/mtd/nand/raw/cortina_nand.c |  4 ++--
>  drivers/net/dm9000x.c   |  2 +-
>  drivers/net/dwmac_meson8b.c |  4 ++--
>  drivers/pci/pcie_dw_meson.c |  8 
>  drivers/pci/pcie_dw_rockchip.c  |  8 
>  drivers/watchdog/sbsa_gwdt.c| 12 ++--
>  6 files changed, 19 insertions(+), 19 deletions(-)
>

Regards,
Simon


Re: [PATCH v7 22/23] arm: stm32mp: spl: fix function with fdt_addr_t input

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 08:47, Johan Jonker  wrote:
>
> The fdt_addr_t and phys_addr_t size have been decoupled.
> A 32bit CPU can expect 64-bit data from the device tree parser,
> so fix ofnode_get_addr_size function with fdt_addr_t input to
> be able to handle both sizes for stm32mp SoC in spl.c file.
>
> Signed-off-by: Johan Jonker 
> ---
>
> Changed V7:
>   remove cast
> ---
>  arch/arm/mach-stm32mp/spl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH v7 11/23] core: remap: fix regmap_init_mem_plat() reg size handeling

2023-03-10 Thread Simon Glass
Hi Johan,

On Fri, 10 Mar 2023 at 08:42, Johan Jonker  wrote:
>
> The fdt_addr_t and phys_addr_t size have been decoupled.
> A 32bit CPU can expect 64-bit data from the device tree parser,

Sorry if you already responded and I missed it.

I don't understand this line. It looks like sizeof(fdt_addr_t) is
still 4 on 32-bit machines. So what does this actually mean?

> so convert regmap_init_mem_plat() input to handel both. The
> syscon class driver also makes use of the regmap_init_mem_plat()
> function, but has no way of knowing the format of the
> device-specific platform data. In case of odd reg structures other
> then that the syscon class driver assumes the regmap must be
> filled in the individual syscon driver before pre-probe.
> Also fix the ARRAY_SIZE divider in the syscon class driver.


Regards,
Simon

> Signed-off-by: Johan Jonker 
> ---
>
> Changed V7:
>   changed title
>   add reg size input
>   rework function calls
> ---
>  drivers/core/regmap.c   | 23 +++
>  drivers/core/syscon-uclass.c| 21 -
>  drivers/ram/rockchip/sdram_rk3066.c |  2 +-
>  drivers/ram/rockchip/sdram_rk3188.c |  2 +-
>  drivers/ram/rockchip/sdram_rk322x.c |  2 +-
>  drivers/ram/rockchip/sdram_rk3288.c |  2 +-
>  drivers/ram/rockchip/sdram_rk3328.c |  2 +-
>  drivers/ram/rockchip/sdram_rk3399.c |  2 +-
>  include/regmap.h|  5 +++--
>  include/syscon.h| 13 -
>  10 files changed, 44 insertions(+), 30 deletions(-)
>

[..]


Re: [PATCH 3/6] examples: Don't use LTO for hello_world

2023-03-10 Thread Simon Glass
On Thu, 9 Mar 2023 at 08:22, Tom Rini  wrote:
>
> If we're building U-Boot with LTO, we don't want to use that for
> examples as it's more work than required.
>
> Signed-off-by: Tom Rini 
> ---
>  examples/standalone/Makefile | 4 
>  1 file changed, 4 insertions(+)

Reviewed-by: Simon Glass 

BTW linux has a reduced LTO which doesn't take so long to build, but
still gets a lot of the benefits.


Re: [PATCH v2] nand: brcmnand: add iproc support

2023-03-10 Thread William Zhang



On 03/08/2023 01:42 PM, Linus Walleij wrote:

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;
+   

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

2023-03-10 Thread William Zhang


On 03/08/2023 01:28 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;
  



Acked-by: William Zhang 


smime.p7s
Description: S/MIME Cryptographic Signature


[PATCH v2 2/2] x86: minnowmax: Adjust CONFIG_TEXT_BASE et at

2023-03-10 Thread Simon Glass
At present U-Boot no longer builds as a complete rom for minnowmaxs since
it is too big for the section.

Adjust CONFIG_TEXT_BASE and CONFIG_SYS_MONITOR_LEN to allow more code
space. Move the MRC cache out of the way too.

Add documentation on how to make this change safely.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch which boots while still enabling EFI_LOADER

 arch/x86/dts/minnowmax.dts|  2 +-
 configs/minnowmax_defconfig   |  3 ++-
 doc/board/intel/minnowmax.rst | 15 +--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/arch/x86/dts/minnowmax.dts b/arch/x86/dts/minnowmax.dts
index 68e0510c68d..466309f2b8d 100644
--- a/arch/x86/dts/minnowmax.dts
+++ b/arch/x86/dts/minnowmax.dts
@@ -206,7 +206,7 @@
memory-map = <0xff80 0x0080>;
rw-mrc-cache {
label = "rw-mrc-cache";
-   reg = <0x006f 0x0001>;
+   reg = <0x005f 0x0001>;
};
};
};
diff --git a/configs/minnowmax_defconfig b/configs/minnowmax_defconfig
index b3b15d86e17..b93c0d729f8 100644
--- a/configs/minnowmax_defconfig
+++ b/configs/minnowmax_defconfig
@@ -1,5 +1,5 @@
 CONFIG_X86=y
-CONFIG_TEXT_BASE=0xFFF0
+CONFIG_TEXT_BASE=0xFFE0
 CONFIG_NR_DRAM_BANKS=8
 CONFIG_ENV_SIZE=0x1000
 CONFIG_ENV_OFFSET=0x6EF000
@@ -18,6 +18,7 @@ CONFIG_GENERATE_PIRQ_TABLE=y
 CONFIG_GENERATE_MP_TABLE=y
 CONFIG_HAVE_ACPI_RESUME=y
 CONFIG_SEABIOS=y
+CONFIG_SYS_MONITOR_LEN=2097152
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_BOOTSTAGE=y
diff --git a/doc/board/intel/minnowmax.rst b/doc/board/intel/minnowmax.rst
index 1ba25b50d21..db20d966f06 100644
--- a/doc/board/intel/minnowmax.rst
+++ b/doc/board/intel/minnowmax.rst
@@ -55,8 +55,8 @@ Offset   Description Controlling config
 001000   me.bin  Set by the descriptor
 50   
 6ef000   Environment CONFIG_ENV_OFFSET
-6f   MRC cache   CONFIG_ENABLE_MRC_CACHE
-70   u-boot-dtb.bin  CONFIG_TEXT_BASE
+5f   MRC cache   CONFIG_ENABLE_MRC_CACHE
+60   u-boot-dtb.bin  CONFIG_TEXT_BASE
 7b   vga.bin CONFIG_VGA_BIOS_ADDR
 7c   fsp.bin CONFIG_FSP_ADDR
 7f8000(depends on size of fsp.bin)
@@ -68,3 +68,14 @@ Overall ROM image size is controlled by CONFIG_ROM_SIZE.
 Note that the debug version of the FSP is bigger in size. If this version
 is used, CONFIG_FSP_ADDR needs to be configured to 0xfffb instead of
 the default value 0xfffc.
+
+If you want to change CONFIG_TEXT_BASE from the current value of 0x60
+you need to check a few other things. CONFIG_SYS_MONITOR_BASE should
+automatically update to be the same as CONFIG_TEXT_BASE but
+CONFIG_SYS_MONITOR_LEN may need to be adjusted too. It must cover the space
+from the start of U-Boot to the end of the RAM, since the 16-bit boot needs to
+be able to jump to U-Boot. See the end of arch/x86/lib/fsp1/fsp_car.S which
+has these values.
+
+Also check the MRC cache address in the devicetree ("rw-mrc-cache"). It must
+not overlap with U-Boot.
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 1/2] x86: Revert "x86: minnowmax: Adjust CONFIG_TEXT_BASE"

2023-03-10 Thread Simon Glass
This causes Minnowmax to stop booting. Revert it so we have a good
example of how to do this fully.

This reverts commit 66e2c665f3b60d726e1c26ad44ac97aa76ead6f5.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/minnowmax_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/minnowmax_defconfig b/configs/minnowmax_defconfig
index 679b6e3de53..b3b15d86e17 100644
--- a/configs/minnowmax_defconfig
+++ b/configs/minnowmax_defconfig
@@ -1,5 +1,5 @@
 CONFIG_X86=y
-CONFIG_TEXT_BASE=0xFFE0
+CONFIG_TEXT_BASE=0xFFF0
 CONFIG_NR_DRAM_BANKS=8
 CONFIG_ENV_SIZE=0x1000
 CONFIG_ENV_OFFSET=0x6EF000
-- 
2.40.0.rc1.284.g88254d51c5-goog



Re: [PATCH v2 02/26] cmd: nvedit: check for ENV_SUPPORT

2023-03-10 Thread Tom Rini
On Thu, Mar 09, 2023 at 12:45:14PM -0800, Troy Kisky wrote:
> On Thu, Mar 9, 2023 at 11:36 AM Tom Rini  wrote:
> 
> > On Thu, Mar 09, 2023 at 11:20:33AM -0800, Troy Kisky wrote:
> > > On Wed, Mar 1, 2023 at 7:33 AM Tom Rini  wrote:
> > >
> > > > On Fri, Feb 24, 2023 at 10:10:23AM -0800, Troy Kisky wrote:
> > > > > Avoid error messages when SPL,TPL,VPL build don't
> > > > > have the environment options of the main build.
> > > > > This is needed when defined(CONFIG_ENV_IS_IN_xxx) is changed
> > > > > to CONFIG_IS_ENABLED(ENV_IS_IN_xxx).
> > > > >
> > > > > Signed-off-by: Troy Kisky 
> > > > > Reviewed-by: Simon Glass 
> > > > > ---
> > > > >
> > > > > (no changes since v1)
> > > > >
> > > > >  cmd/nvedit.c | 5 -
> > > > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/cmd/nvedit.c b/cmd/nvedit.c
> > > > > index 7cbc3fd573a..ef0fe55431c 100644
> > > > > --- a/cmd/nvedit.c
> > > > > +++ b/cmd/nvedit.c
> > > > > @@ -43,6 +43,7 @@
> > > > >
> > > > >  DECLARE_GLOBAL_DATA_PTR;
> > > > >
> > > > > +#if CONFIG_IS_ENABLED(ENV_SUPPORT)
> > > > >  #if  defined(CONFIG_ENV_IS_IN_EEPROM)|| \
> > > > >   defined(CONFIG_ENV_IS_IN_FLASH) || \
> > > > >   defined(CONFIG_ENV_IS_IN_MMC)   || \
> > > > > @@ -60,10 +61,12 @@ DECLARE_GLOBAL_DATA_PTR;
> > > > >  #endif
> > > > >
> > > > >  #if  !defined(ENV_IS_IN_DEVICE)  && \
> > > > > - !defined(CONFIG_ENV_IS_NOWHERE)
> > > > > + !defined(CONFIG_ENV_IS_NOWHERE) && \
> > > > > + !defined(CONFIG_VPL_BUILD)
> > > > >  # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|MMC|FAT|EXT4|\
> > > > >  NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or
> > CONFIG_ENV_IS_NOWHERE
> > > > >  #endif
> > > > > +#endif
> > > >
> > > > This is one of the #error messes that we no longer need with Kconfig,
> > > > where we can ensure things happen. Maybe we can use def_bool y if ..
> > > > instead of default y if ..., in the ENV_IS_NOWHERE choice ?
> > > >
> > > > --
> > > > Tom
> > > >
> > >
> > > Hi Tom
> > >
> > > There is some weirdness here
> > > git grep -A1 CONFIG_ENV_IS_NOWHERE *
> > [snip]
> > > Should I force  CONFIG_ENV_IS_NOWHERE=n in these cases?
> >
> > No, we support more than one env location being enabled at a time, with
> > nowhere being the location of last resort (at run time).
> >
> >
> >
> Okay, this help text is misleading then.
> 
> config ENV_IS_NOWHERE
> bool "Environment is not stored"
> default y if !ENV_IS_IN_EEPROM && !ENV_IS_IN_EXT4 && \
> !ENV_IS_IN_FAT && !ENV_IS_IN_FLASH && \
> !ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
> !ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
> !ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
> !ENV_IS_IN_UBI
> help
>  Define this if you don't want to or can't have an environment stored
>  on a storage medium. In this case the environment will still exist
>  while U-Boot is running, but once U-Boot exits it will not be
>  stored. U-Boot will therefore always start up with a default
>  environment.

Yes, rewording this was missed when updating the support.

> __
> 
> Perhaps this is better ?
> 
> config ENV_IS_NOT_IN_DEVICE
> def_bool y if !ENV_IS_IN_EEPROM && !ENV_IS_IN_EXT4 && \
> !ENV_IS_IN_FAT && !ENV_IS_IN_FLASH && \
> !ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
> !ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
> !ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
> !ENV_IS_IN_UBI
> select ENV_IS_NOWHERE
> 
> config ENV_IS_NOWHERE
> bool "Environment is not stored"
> help
>  Define this if you don't care whether or not an environment is stored
>  on a storage medium. In this case the environment will still exist
>  while U-Boot is running, but once U-Boot exits it may not be
>  stored. If no other ENV_IS_IN_ is defined, U-Boot will always start up
>  with a default  environment.
> 

Seems reasonable, thanks.

-- 
Tom


signature.asc
Description: PGP signature


Re: Please pull u-boot-dm

2023-03-10 Thread Tom Rini
On Fri, Mar 10, 2023 at 12:54:57PM -0800, Simon Glass wrote:

> Hi Tom,
> 
> https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/15515
> 
> Marek pointed out that these are bug fixes and tests so should
> probably go into -master.
> 
> The following changes since commit b08ffdffdce95e267e782366f4a77bf6b5537b28:
> 
>   Merge https://source.denx.de/u-boot/custodians/u-boot-marvell
> (2023-03-06 14:56:05 -0500)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-dm.git tags/dm-pull-10mar23
> 
> for you to fetch changes up to aa89aebb17531a3e8b6729c812a68d5e37008730:
> 
>   test: cmd: fdt: Test fdt bootcpu (2023-03-09 08:50:48 -0800)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PULL] u-boot-usb/master

2023-03-10 Thread Marek Vasut

Two minimal Kconfig/Makefile fixes for USB below.

The following changes since commit b08ffdffdce95e267e782366f4a77bf6b5537b28:

  Merge https://source.denx.de/u-boot/custodians/u-boot-marvell 
(2023-03-06 14:56:05 -0500)


are available in the Git repository at:

  git://source.denx.de/u-boot-usb.git master

for you to fetch changes up to 4042ce73c8bee9077d80a42b27aa21f98636b780:

  usb: move CONFIG_USB_HUB_DEBOUNCE_TIMEOUT to USB (2023-03-10 17:31:31 
+0100)



Heinrich Schuchardt (2):
  usb: USB hubs require host mode
  usb: move CONFIG_USB_HUB_DEBOUNCE_TIMEOUT to USB

 common/Kconfig  | 12 
 common/Makefile |  2 +-
 drivers/usb/Kconfig | 11 +++
 3 files changed, 12 insertions(+), 13 deletions(-)


[PULL] u-boot-sh/master

2023-03-10 Thread Marek Vasut
Assorted Renesas fixes below, namely MMC clocking breakage fix, clock 
Kconfig fix, pin control unused symbols removal, and sysinfo fix and 
enablement on now fixed platforms.


The following changes since commit b08ffdffdce95e267e782366f4a77bf6b5537b28:

  Merge https://source.denx.de/u-boot/custodians/u-boot-marvell 
(2023-03-06 14:56:05 -0500)


are available in the Git repository at:

  git://source.denx.de/u-boot-sh.git master

for you to fetch changes up to ae08097faac226a951f4258c481e3e62d6ed8ac2:

  ARM: dts: renesas: Enable sysinfo on R-Car D3 Draak (2023-03-10 
17:46:09 +0100)



Marek Vasut (4):
  mmc: renesas-sdhi: Always configure default SDnH clock rate to 
800 MHz

  mmc: renesas-sdhi: Add proper probe error fail path
  clk: renesas: Always select DM_RESET to prevent inobvious failure 
of rst_gen3 subdriver

  pinctrl: renesas: Drop non-existent PFC info table entries

Tam Nguyen (3):
  sysinfo: rcar3: Fix Draak and Eagle board code
  ARM: dts: renesas: Enable sysinfo on R-Car V3H Condor/Condor-I
  ARM: dts: renesas: Enable sysinfo on R-Car D3 Draak

 arch/arm/dts/r8a77980-condor-u-boot.dts | 17 +
 arch/arm/dts/r8a77995-draak-u-boot.dts  | 19 +++
 configs/r8a77980_condor_defconfig   |  5 +
 configs/r8a77995_draak_defconfig|  5 +
 drivers/clk/renesas/Kconfig |  1 +
 drivers/mmc/renesas-sdhi.c  | 30 
+++---

 drivers/pinctrl/renesas/sh_pfc.h| 15 ---
 drivers/sysinfo/rcar3.c | 19 +--
 8 files changed, 87 insertions(+), 24 deletions(-)


[PATCH v2 12/12] efI: Allow packaging a kernel in the debugging script

2023-03-10 Thread Simon Glass
Add an option to package a kernel into the debugging script used for
EFI.

The name of the kernel must be added to the script. By default it is
assumed that the kernel is built in the /tmp/kernel directory.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Fix typos in commit message

 scripts/build-efi.sh | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/scripts/build-efi.sh b/scripts/build-efi.sh
index 46c28807ef1..6b7df2e9bfe 100755
--- a/scripts/build-efi.sh
+++ b/scripts/build-efi.sh
@@ -18,12 +18,15 @@
 # OVMF-pure-efi.x64.fd at
 # 
https://drive.google.com/file/d/1c39YI9QtpByGQ4V0UNNQtGqttEzS-eFV/view?usp=sharing
 
+bzimage_fname=/tmp/kernel/arch/x86/boot/bzImage
+
 set -e
 
 usage() {
echo "Usage: $0 [-a | -p] [other opts]" 1>&2
echo 1>&2
echo "   -a   - Package up the app" 1>&2
+   echo "   -k   - Add a kernel" 1>&2
echo "   -o   - Use old EFI app build (before 32/64 split)" 1>&2
echo "   -p   - Package up the payload" 1>&2
echo "   -P   - Create a partition table" 1>&2
@@ -52,11 +55,14 @@ serial=
 # before the 32/64 split of the app
 old=
 
+# package up a kernel as well
+kernel=
+
 # Set ubdir to the build directory where you build U-Boot out-of-tree
 # We avoid in-tree build because it gets confusing trying different builds
 ubdir=/tmp/b/
 
-while getopts "aopPrsw" opt; do
+while getopts "akopPrsw" opt; do
case "${opt}" in
a)
type=app
@@ -64,6 +70,9 @@ while getopts "aopPrsw" opt; do
p)
type=payload
;;
+   k)
+   kernel=1
+   ;;
r)
run=1
;;
@@ -124,6 +133,9 @@ EOF
 # Copy files into the filesystem
 copy_files() {
sudo cp $TMP/* $MNT
+   if [[ -n "${kernel}" ]]; then
+   sudo cp ${bzimage_fname} $MNT/vmlinuz
+   fi
 }
 
 # Create a filesystem on a raw device and copy in the files
-- 
2.40.0.rc1.284.g88254d51c5-goog



Please pull u-boot-dm

2023-03-10 Thread Simon Glass
Hi Tom,

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

Marek pointed out that these are bug fixes and tests so should
probably go into -master.

The following changes since commit b08ffdffdce95e267e782366f4a77bf6b5537b28:

  Merge https://source.denx.de/u-boot/custodians/u-boot-marvell
(2023-03-06 14:56:05 -0500)

are available in the Git repository at:

  git://git.denx.de/u-boot-dm.git tags/dm-pull-10mar23

for you to fetch changes up to aa89aebb17531a3e8b6729c812a68d5e37008730:

  test: cmd: fdt: Test fdt bootcpu (2023-03-09 08:50:48 -0800)


fixes and tests for the fdt command


Marek Vasut (25):
  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

 cmd/fdt.c |  98 +++-
 include/test/ut.h |   4 +
 test/cmd/fdt.c| 815
+++---
 3 files changed, 852 insertions(+), 65 deletions(-)

Regards,
Simon


Re: [PATCH 1/2] CI: Allow job tag to be optionally set globally

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 01:54, Peter Hoyes  wrote:
>
> From: Peter Hoyes 
>
> The default behavior of Gitlab runners is to only run jobs which match
> the configured tag, although there is an option to run untagged jobs
> [1].
>
> To support running the CI in more complex environments where different
> types of runners may be present that support different tags, allow the
> DEFAULT_TAG for all jobs in the pipeline to be set globally using an
> environment variable. An empty default value is provided to retain
> support for untagged runners.
>
> [1] 
> https://docs.gitlab.com/ee/ci/runners/configure_runners.html#use-tags-to-control-which-jobs-a-runner-can-run
>
> Signed-off-by: Peter Hoyes 
> ---
>  .gitlab-ci.yml | 7 +++
>  1 file changed, 7 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH v9 05/10] arm_ffa: introduce armffa command

2023-03-10 Thread Simon Glass
Hi Abdellatif,

On Fri, 10 Mar 2023 at 06:10, Abdellatif El Khlifi
 wrote:
>
> Provide armffa command showcasing the use of the FF-A driver
>
> armffa is a command showcasing how to use the FF-A driver and how to invoke
> its operations. This provides a guidance to the client developers on how to
> call the FF-A bus interfaces. The command also allows to gather secure
> partitions information and ping these  partitions. The command is also
> helpful in testing the communication with secure partitions.
>
> For more details please refer to the command documentation [1].
>
> [1]: doc/usage/cmd/armffa.rst
>
> Signed-off-by: Abdellatif El Khlifi 
> Cc: Tom Rini 
> Cc: Simon Glass 
> Cc: Ilias Apalodimas 
> Cc: Jens Wiklander 
>
> ---
> Changelog:
> ===
>
> v9:
>
> * remove manual FF-A discovery and use DM
> * use DM class APIs to probe and interact with the FF-A bus
> * add doc/usage/cmd/armffa.rst
>
> v8:
>
> * update partition_info_get() second argument to be an SP count
> * pass NULL device pointer to the FF-A bus discovery and operations
>
> v7:
>
> * adapt do_ffa_dev_list() following the recent update on
>   uclass_first_device/uclass_next_device functions (they return void now)
> * set armffa command to use 64-bit direct messaging
>
> v4:
>
> * remove pattern data in do_ffa_msg_send_direct_req
>
> v3:
>
> * use the new driver interfaces (partition_info_get, sync_send_receive)
>   in armffa command
>
> v2:
>
> * replace use of ffa_helper_init_device function by
>  ffa_helper_bus_discover
>
> v1:
>
> * introduce armffa command
>
>  MAINTAINERS  |   2 +
>  cmd/Kconfig  |  10 ++
>  cmd/Makefile |   2 +
>  cmd/armffa.c | 264 +++
>  doc/usage/cmd/armffa.rst | 118 ++
>  doc/usage/index.rst  |   1 +

+Heinrich Schuchardt for docs

>  drivers/firmware/arm-ffa/Kconfig |   1 +
>  7 files changed, 398 insertions(+)
>  create mode 100644 cmd/armffa.c
>  create mode 100644 doc/usage/cmd/armffa.rst
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 1dfa23c1f0..18e9c2ce99 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -269,7 +269,9 @@ F:  configs/cortina_presidio-asic-pnand_defconfig
>  ARM FF-A
>  M: Abdellatif El Khlifi 
>  S: Maintained
> +F: cmd/armffa.c
>  F: doc/arch/arm64.ffa.rst
> +F: doc/usage/cmd/armffa.rst
>  F: drivers/firmware/arm-ffa/
>  F: include/arm_ffa.h
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index a3512836c1..f24c52def4 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -934,6 +934,16 @@ endmenu
>
>  menu "Device access commands"
>
> +config CMD_ARMFFA
> +   bool "Arm FF-A test command"
> +   depends on ARM_FFA_TRANSPORT
> +   help
> + Provides a test command for the Arm FF-A driver
> + supported options:
> +   - Listing the partition(s) info
> +   - Sending a data pattern to the specified partition
> +   - Displaying the arm_ffa device info
> +
>  config CMD_ARMFLASH
> #depends on FLASH_CFI_DRIVER
> bool "armflash"
> diff --git a/cmd/Makefile b/cmd/Makefile
> index 2d8bb4fc05..a59ab55ad0 100644
> --- a/cmd/Makefile
> +++ b/cmd/Makefile
> @@ -12,6 +12,8 @@ obj-y += panic.o
>  obj-y += version.o
>
>  # command
> +
> +obj-$(CONFIG_CMD_ARMFFA) += armffa.o
>  obj-$(CONFIG_CMD_ACPI) += acpi.o
>  obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
>  obj-$(CONFIG_CMD_AES) += aes.o
> diff --git a/cmd/armffa.c b/cmd/armffa.c
> new file mode 100644
> index 00..f6c017542d
> --- /dev/null
> +++ b/cmd/armffa.c
> @@ -0,0 +1,264 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright 2022-2023 Arm Limited and/or its affiliates 
> 
> + *
> + * Authors:
> + *   Abdellatif El Khlifi 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/**
> + * do_ffa_getpart() - implementation of the getpart subcommand
> + * @cmdtp: Command Table
> + * @flag:  flags
> + * @argc:  number of arguments
> + * @argv:  arguments
> + *
> + * This function queries the secure partition information which the UUID is 
> provided
> + * as an argument. The function uses the arm_ffa driver partition_info_get 
> operation
> + * which implements FFA_PARTITION_INFO_GET ABI to retrieve the data.
> + * The input UUID string is expected to be in big endian format.
> + *
> + * Return:
> + *
> + * CMD_RET_SUCCESS: on success, otherwise failure
> + */
> +static int do_ffa_getpart(struct cmd_tbl *cmdtp, int flag, int argc, char 
> *const argv[])
> +{
> +   u32 count = 0;
> +   int ret;
> +   struct ffa_partition_info *parts_info;
> +   u32 info_idx;
> +   struct udevice *dev = NULL;
> +   struct ffa_bus_ops *ffa_ops = NULL;
> +
> +   if (argc != 1)
> +   return -EINVAL;
> +
> +   uclass_get_device_by_name(UCLASS_FFA, "arm_ffa", );


Re: [PATCH v9 09/10] arm_ffa: efi: introduce FF-A MM communication

2023-03-10 Thread Simon Glass
Hi Abdellatif,

On Fri, 10 Mar 2023 at 06:11, Abdellatif El Khlifi
 wrote:
>
> Add MM communication support using FF-A transport
>
> This feature allows accessing MM partitions services through
> EFI MM communication protocol. MM partitions such as StandAlonneMM
> or smm-gateway secure partitions which reside in secure world.
>
> An MM shared buffer and a door bell event are used to exchange
> the data.
>
> The data is used by EFI services such as GetVariable()/SetVariable()
> and copied from the communication buffer to the MM shared buffer.
>
> The secure partition is notified about availability of data in the
> MM shared buffer by an FF-A message (door bell).
>
> On such event, MM SP can read the data and updates the MM shared
> buffer with the response data.
>
> The response data is copied back to the communication buffer and
> consumed by the EFI subsystem.
>
> MM communication protocol supports FF-A 64-bit direct messaging.
>
> Signed-off-by: Abdellatif El Khlifi 
> Signed-off-by: Gowtham Suresh Kumar 
> Cc: Tom Rini 
> Cc: Simon Glass 
> Cc: Ilias Apalodimas 
> Cc: Jens Wiklander 
>
> ---
> Changelog:
> ===
>
> v9: align how FF-A is used with FF-A discovery through DM
>
> v8:
>
> * isolate the compilation choices between FF-A and OP-TEE
> * update partition_info_get() second argument to be an SP count
> * pass NULL device pointer to the FF-A bus discovery and operations
>
> v7:
>
> * set the MM door bell event to use 64-bit direct messaging
> * issue a compile time error when one of these macros are not found :
>   FFA_SHARED_MM_BUFFER_SIZE, FFA_SHARED_MM_BUFFER_OFFSET, 
> FFA_SHARED_MM_BUFFER_ADDR
> * make mm_sp_svc_uuid static
> * replace EINVAL with ENOMEM in ffa_discover_mm_sp_id() when calloc() fails
> * improve use of unmap_sysmem() in ffa_mm_communicate()
>
> v6:
>
> * add FF-A runtime discovery at MM communication level
> * drop EFI runtime support for FF-A MM communication
> * revert the changes in include/mm_communication.h for
>   efi_mm_communicate_header and smm_variable_access structures
>
> v4:
>
> * use the new FF-A driver interfaces
> * discover MM partitions at runtime
> * copy FF-A driver private data to EFI runtime section at
>   ExitBootServices()
> * drop use of FFA_ERR_STAT_SUCCESS error code
> * replace EFI_BUFFER_TOO_SMALL with EFI_OUT_OF_RESOURCES
>   in ffa_mm_communicate(). No need for efi_memcpy_runtime() anymore
> * revert the error log in mm_communicate() in case of failure
> * remove packed attribute from efi_mm_communicate_header and
>   smm_variable_communicate_header
>
> v2:
>
> * set default values to 0 for FFA_SHARED_MM_BUFFER_SIZE, 
> FFA_SHARED_MM_BUFFER_ADDR and MM_SP_UUID_DATA and add warnings
>
> v1:
>
> * introduce FF-A MM communication
>
>  include/mm_communication.h|   6 +
>  lib/efi_loader/Kconfig|  14 +-
>  lib/efi_loader/efi_variable_tee.c | 317 +-
>  3 files changed, 331 insertions(+), 6 deletions(-)
>
> diff --git a/include/mm_communication.h b/include/mm_communication.h
> index e65fbde60d..87509fec3f 100644
> --- a/include/mm_communication.h
> +++ b/include/mm_communication.h
> @@ -6,6 +6,9 @@
>   *  Copyright (c) 2017, Intel Corporation. All rights reserved.
>   *  Copyright (C) 2020 Linaro Ltd. 
>   *  Copyright (C) 2020 Linaro Ltd. 
> + *  Copyright 2022-2023 Arm Limited and/or its affiliates 
> 
> + *Authors:
> + *  Abdellatif El Khlifi 
>   */
>
>  #ifndef _MM_COMMUNICATION_H_
> @@ -13,6 +16,9 @@
>
>  #include 
>
> +/* MM service UUID string (big-endian format). This UUID is  common across 
> all MM SPs */
> +#define MM_SP_UUID "33d532ed-e699-0942-c09c-a798d9cd722d"
> +
>  /*
>   * Interface to the pseudo Trusted Application (TA), which provides a
>   * communication channel with the Standalone MM (Management Mode)
> diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
> index c5835e6ef6..08a6b84101 100644
> --- a/lib/efi_loader/Kconfig
> +++ b/lib/efi_loader/Kconfig
> @@ -55,13 +55,23 @@ config EFI_VARIABLE_FILE_STORE
>   stored as file /ubootefi.var on the EFI system partition.
>
>  config EFI_MM_COMM_TEE
> -   bool "UEFI variables storage service via OP-TEE"
> -   depends on OPTEE
> +   bool "UEFI variables storage service via the trusted world"
> +   depends on OPTEE || ARM_FFA_TRANSPORT
> help
> + Allowing access to the MM SP services (SPs such as  StandAlonneMM, 
> smm-gateway).
> + When using the u-boot OP-TEE driver, StandAlonneMM is supported.
> + When using the u-boot FF-A  driver any MM SP is supported.
> +
>   If OP-TEE is present and running StandAloneMM, dispatch all UEFI
>   variable related operations to that. The application will verify,
>   authenticate and store the variables on an RPMB.
>
> + When ARM_FFA_TRANSPORT is used, dispatch all UEFI variable related
> + operations to the MM SP running in the secure world.
> + A door bell mechanism is 

Re: [PATCH v9 00/10] introduce Arm FF-A support

2023-03-10 Thread Simon Glass
Hi Abdellatif,

On Fri, 10 Mar 2023 at 06:12, Abdellatif El Khlifi
 wrote:
>
> Adding support for Arm FF-A v1.0 (Arm Firmware Framework for Armv8-A) [A].
>
> FF-A describes interfaces (ABIs) that standardize communication
> between the Secure World and Normal World. These interfaces enable a pair of
> software sandboxes to communicate with each other. A sandbox aka partition 
> could
> be a VM in the Normal or Secure world, an application in S-EL0, or a
> Trusted OS in S-EL1.
>
> FF-A is a discoverable bus and similar to architecture features.
> FF-A bus is discovered using ARM_SMCCC_FEATURES mechanism performed
> by the PSCI driver.
>
>=> dm tree
>
> Class Index  Probed  DriverName
>---
>...
> firmware  0  [ + ]   psci  |-- psci
> ffa   0  [   ]   arm_ffa   |   `-- arm_ffa
>...
>
> Clients are able to probe then use the FF-A bus by calling the DM class
> searching APIs (e.g: uclass_get_device_by_name).
>
> This implementation of the specification provides support for Aarch64.
>
> The FF-A driver uses the SMC ABIs defined by the FF-A specification to:
>
> - Discover the presence of secure partitions (SPs) of interest
> - Access an SP's service through communication protocols
>   e.g. EFI MM communication protocol
>
> The FF-A support provides the following features:
>
> - Being generic by design and can be used by any Arm 64-bit platform
> - The FF-A core driver
> - The driver provides driver operations to be used by clients to access 
> the FF-A bus
> - FF-A driver can be compiled and used without EFI
> - Support for SMCCCv1.2 x0-x17 registers
> - Support for SMC32 calling convention
> - Support for 32-bit and 64-bit FF-A direct messaging
> - A new command called armffa is provided as an example of how to access 
> the
>   FF-A bus
> - An FF-A Sandbox driver is provided with test cases
> - Support for FF-A MM communication (compatible with EFI boot time)
> - Enabling FF-A and MM communication in Corstone1000 platform as a use 
> case
>
> For more details about the FF-A core driver please refer to [B] and refer to 
> [C] for
> how to use the armffa command.
>
> Please find at [D] an example of the expected boot logs when enabling
> FF-A support for a platform. In this example the platform is
> Corstone1000. But it can be any Arm 64-bit platform.
>
> Changelog of the major changes:
> ===
>
> v9:
>
> * integrate the FF-A bus discovery in the DM and use ARM_SMCCC_FEATURES for 
> binding
> * align FF-A sandbox driver with FF-A discovery through DM
> * use DM class APIs to probe and interact with the FF-A bus (in FF-A MM 
> comms,  armffa command, sandbox tests)
> * add documentation for the armffa command: doc/usage/cmd/armffa.rst
> * introduce testcase for uuid_str_to_le_bin

This version looks a lot better. Things I noticed:

- fix up uclass to use operations
- tidy up emulator binding to use DT

Both should be fairly easy.

Other than that I just have code-style nits.

Regards,
Simon


Re: [PATCH v9 02/10] lib: uuid: introduce uuid_str_to_le_bin function

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 06:10, Abdellatif El Khlifi
 wrote:
>
> convert UUID string to little endian binary data
>
> Signed-off-by: Abdellatif El Khlifi 
> Cc: Tom Rini 
> Cc: Simon Glass 
> Cc: Ilias Apalodimas 
> Cc: Jens Wiklander 
>
> ---
> Changelog:
> ===
>
> v9:
>
> * add a full function prototype description in uuid.h
>
> v8:
>
> * use simple_strtoull() in uuid_str_to_le_bin() to support 32-bit platforms
>
> v7:
>
> * rename be_uuid_str_to_le_bin() to uuid_str_to_le_bin()
> * make uuid_str_to_le_bin() implementation similar to uuid_str_to_bin()
>   by using same APIs
>
> v4:
>
> * rename ffa_uuid_str_to_bin to be_uuid_str_to_le_bin and put in
>   a standalone commit (the current)
>
> v3:
>
> * introduce ffa_uuid_str_to_bin (provided by
>   arm_ffa: introduce Arm FF-A low-level driver)
>
>  include/uuid.h | 15 +++
>  lib/uuid.c | 48 
>  2 files changed, 63 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH v1 4/4] test: exit: fix run_commandf() warnings

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 10:55, Evgeny Bachinin  wrote:
>
> Fix warnings after adding printf-like attribute format for
> run_commandf():
> warning: too many arguments for format [-Wformat-extra-args]
>
> Signed-off-by: Evgeny Bachinin 
> ---
>  test/cmd/exit.c | 18 +-
>  1 file changed, 9 insertions(+), 9 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v9 06/10] arm_ffa: introduce the FF-A Sandbox driver

2023-03-10 Thread Simon Glass
Hi Abdellatif,

On Fri, 10 Mar 2023 at 06:10, Abdellatif El Khlifi
 wrote:
>
> Provide a Sandbox driver to emulate the FF-A ABIs
>
> The emulated ABIs are those supported by the FF-A core driver
> and according to FF-A specification v1.0.
>
> The Sandbox driver provides operations allowing the test
> application to read the status of all the inspected ABIs
> and perform functional tests based on that.
>
> sandbox driver supports only 64-bit direct messaging.
>
> Signed-off-by: Abdellatif El Khlifi 
> Cc: Tom Rini 
> Cc: Simon Glass 
> Cc: Ilias Apalodimas 
> Cc: Jens Wiklander 
>
> ---
> Changelog:
> ===
>
> v9: align FF-A sandbox driver with FF-A discovery through DM
>
> v8: update ffa_bus_prvdata_get() to return a pointer rather than
> a pointer address
>
> v7: state that sandbox driver supports only 64-bit direct messaging
>
> v4: align sandbox driver with the new FF-A driver interfaces
> and new way of error handling
>
> v1: introduce the sandbox driver
>
>  MAINTAINERS   |   1 +
>  arch/sandbox/dts/sandbox.dtsi |   4 +
>  arch/sandbox/dts/test.dts |   4 +
>  configs/sandbox64_defconfig   |   2 +
>  configs/sandbox_defconfig |   2 +
>  doc/arch/arm64.ffa.rst|   4 +
>  doc/arch/sandbox/sandbox.rst  |   1 +
>  drivers/firmware/arm-ffa/Kconfig  |  11 +-
>  drivers/firmware/arm-ffa/Makefile |   1 +
>  drivers/firmware/arm-ffa/core.c   |  36 +-
>  drivers/firmware/arm-ffa/sandbox.c| 610 ++
>  .../firmware/arm-ffa/sandbox_arm_ffa_priv.h   | 129 
>  include/arm_ffa.h |   5 +-
>  include/sandbox_arm_ffa.h | 124 
>  14 files changed, 928 insertions(+), 6 deletions(-)
>  create mode 100644 drivers/firmware/arm-ffa/sandbox.c
>  create mode 100644 drivers/firmware/arm-ffa/sandbox_arm_ffa_priv.h
>  create mode 100644 include/sandbox_arm_ffa.h
>

Could you use 80 columns where possible? There seem to be a lot of
things that extend beyond that without much of a reason.

Also you can use 'ulong' instead of 'unsigned long'. It is less
verbose and a U-Boot standard.

> diff --git a/MAINTAINERS b/MAINTAINERS
> index 18e9c2ce99..2b9d33e964 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -274,6 +274,7 @@ F:  doc/arch/arm64.ffa.rst
>  F: doc/usage/cmd/armffa.rst
>  F: drivers/firmware/arm-ffa/
>  F: include/arm_ffa.h
> +F: include/sandbox_arm_ffa.h
>
>  ARM FREESCALE IMX
>  M: Stefano Babic 
> diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
> index 30a305c4d2..059c273277 100644
> --- a/arch/sandbox/dts/sandbox.dtsi
> +++ b/arch/sandbox/dts/sandbox.dtsi
> @@ -445,6 +445,10 @@
> thermal {
> compatible = "sandbox,thermal";
> };
> +
> +   sandbox_arm_ffa {
> +   compatible = "sandbox,arm_ffa";
> +   };
>  };
>
>  _ec {
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index d72d7a567a..11dc6ed0d9 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -1802,6 +1802,10 @@
> compatible = "u-boot,fwu-mdata-gpt";
> fwu-mdata-store = <>;
> };
> +
> +   sandbox_arm_ffa {
> +   compatible = "sandbox,arm_ffa";
> +   };

I see that you have this, so the driver should bind automatically.

Is the problem that you are trying to bind the sandbox emulator?
Again, you can actually add that to the DT. See how this works for
i2c, SPI, PCI, for example.

>  };
>
>  #include "sandbox_pmic.dtsi"
> diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
> index ccbc18aad0..35d4676cf7 100644
> --- a/configs/sandbox64_defconfig
> +++ b/configs/sandbox64_defconfig
> @@ -259,3 +259,5 @@ CONFIG_FWU_MULTI_BANK_UPDATE=y
>  CONFIG_UNIT_TEST=y
>  CONFIG_UT_TIME=y
>  CONFIG_UT_DM=y
> +CONFIG_ARM_FFA_TRANSPORT=y
> +CONFIG_SANDBOX_FFA=y
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index a0fbdad20a..8aab8dda31 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -336,3 +336,5 @@ CONFIG_TEST_FDTDEC=y
>  CONFIG_UNIT_TEST=y
>  CONFIG_UT_TIME=y
>  CONFIG_UT_DM=y
> +CONFIG_ARM_FFA_TRANSPORT=y
> +CONFIG_SANDBOX_FFA=y
> \ No newline at end of file
> diff --git a/doc/arch/arm64.ffa.rst b/doc/arch/arm64.ffa.rst
> index 8fad9ef3d0..555ee9a6ae 100644
> --- a/doc/arch/arm64.ffa.rst
> +++ b/doc/arch/arm64.ffa.rst
> @@ -64,6 +64,10 @@ CONFIG_ARM_FFA_TRANSPORT
>  Enables the FF-A bus driver. Turn this on if you want to use FF-A
>  communication.
>
> +CONFIG_SANDBOX_FFA
> +Enables FF-A Sandbox driver. This emulates the FF-A ABIs handling under
> +Sandbox and provides functional tests for FF-A.

OK that is why I am confused. Please don't call this a driver. It is
an emulator. When you have an emulator and a 

Re: [PATCH v9 07/10] arm_ffa: introduce Sandbox test cases for UCLASS_FFA

2023-03-10 Thread Simon Glass
Hi Abdellatif,

On Fri, 10 Mar 2023 at 06:10, Abdellatif El Khlifi
 wrote:
>
> Add functional test cases for the FF-A core driver
>
> These tests rely on the FF-A Sandbox driver which helps in
>  inspecting the FF-A core driver.
>
> Signed-off-by: Abdellatif El Khlifi 
> Cc: Tom Rini 
> Cc: Simon Glass 
> Cc: Ilias Apalodimas 
> Cc: Jens Wiklander 
>
> ---
> Changelog:
> ===
>
> v9: align FF-A sandbox tests with FF-A discovery through DM
>
> v8:
>
>   * update partition_info_get() second argument to be an SP count
>   * pass NULL device pointer to the FF-A bus discovery and operations
>
> v7: set the tests to use 64-bit direct messaging
>
> v4: align sandbox tests with the new FF-A driver interfaces
>  and new way of error handling
>
> v1: introduce sandbox tests
>
>  MAINTAINERS  |   1 +
>  test/dm/Makefile |   2 +
>  test/dm/ffa.c| 380 +++
>  3 files changed, 383 insertions(+)
>  create mode 100644 test/dm/ffa.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 2b9d33e964..6939b832e4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -275,6 +275,7 @@ F:  doc/usage/cmd/armffa.rst
>  F: drivers/firmware/arm-ffa/
>  F: include/arm_ffa.h
>  F: include/sandbox_arm_ffa.h
> +F: test/dm/ffa.c
>
>  ARM FREESCALE IMX
>  M: Stefano Babic 
> diff --git a/test/dm/Makefile b/test/dm/Makefile
> index 7a79b6e1a2..b554b170db 100644
> --- a/test/dm/Makefile
> +++ b/test/dm/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0+
>  #
>  # Copyright (c) 2013 Google, Inc
> +# Copyright 2022-2023 Arm Limited and/or its affiliates 
> 
>
>  obj-$(CONFIG_UT_DM) += test-dm.o
>
> @@ -85,6 +86,7 @@ obj-$(CONFIG_POWER_DOMAIN) += power-domain.o
>  obj-$(CONFIG_ACPI_PMC) += pmc.o
>  obj-$(CONFIG_DM_PMIC) += pmic.o
>  obj-$(CONFIG_DM_PWM) += pwm.o
> +obj-$(CONFIG_SANDBOX_FFA) += ffa.o
>  obj-$(CONFIG_QFW) += qfw.o
>  obj-$(CONFIG_RAM) += ram.o
>  obj-y += regmap.o
> diff --git a/test/dm/ffa.c b/test/dm/ffa.c
> new file mode 100644
> index 00..d978feda72
> --- /dev/null
> +++ b/test/dm/ffa.c
> @@ -0,0 +1,380 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Functional tests for UCLASS_FFA  class
> + *
> + * Copyright 2022-2023 Arm Limited and/or its affiliates 
> 
> + *
> + * Authors:
> + *   Abdellatif El Khlifi 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "../../drivers/firmware/arm-ffa/sandbox_arm_ffa_priv.h"

I suppose this is OK, but you could put is in arch/sandbox/include/asm/ perhaps?

> +#include 
> +#include 
> +#include 
> +
> +/* Macros */
> +
> +#define LOG_MSG_SZ (100)
> +#define LOG_CMD_SZ (LOG_MSG_SZ * 2)
> +
> +/* Functional tests for the UCLASS_FFA */
> +
> +static int dm_test_ffa_log(struct unit_test_state *uts, char *msg)
> +{
> +   char cmd[LOG_CMD_SZ] = {0};
> +
> +   console_record_reset();
> +
> +   snprintf(cmd, LOG_CMD_SZ, "echo \"%s\"", msg);
> +   run_command(cmd, 0);
> +
> +   ut_assert_console_end();
> +
> +   return 0;
> +}
> +
> +static int check_fwk_version(struct ffa_priv *priv, struct sandbox_ffa_priv 
> *sdx_priv,
> +struct unit_test_state *uts)
> +{
> +   if (priv->dscvry_info.fwk_version != sdx_priv->fwk_version) {
> +   char msg[LOG_MSG_SZ] = {0};
> +
> +   snprintf(msg, LOG_MSG_SZ,
> +"[%s]: Error: framework version: core = 0x%x , 
> sandbox  = 0x%x", __func__,
> +priv->dscvry_info.fwk_version,
> +   sdx_priv->fwk_version);
> +
> +   dm_test_ffa_log(uts, msg);
> +   return CMD_RET_FAILURE;
> +   }
> +   return 0;
> +}
> +
> +static int check_endpoint_id(struct ffa_priv *priv, struct unit_test_state 
> *uts)
> +{
> +   if (priv->id) {
> +   char msg[LOG_MSG_SZ] = {0};
> +
> +   snprintf(msg, LOG_MSG_SZ,
> +"[%s]: Error: endpoint id: core = 0x%x", __func__, 
> priv->id);
> +   dm_test_ffa_log(uts, msg);
> +   return CMD_RET_FAILURE;
> +   }
> +   return 0;
> +}
> +
> +static int check_rxtxbuf(struct ffa_priv *priv, struct unit_test_state *uts)
> +{
> +   if (!priv->pair.rxbuf && priv->pair.txbuf) {
> +   char msg[LOG_MSG_SZ] = {0};
> +
> +   snprintf(msg, LOG_MSG_SZ, "[%s]: Error: rxbuf = %p txbuf = 
> %p", __func__,
> +priv->pair.rxbuf,
> +priv->pair.txbuf);
> +   dm_test_ffa_log(uts, msg);
> +   return CMD_RET_FAILURE;
> +   }
> +   return 0;
> +}
> +
> +static int check_features(struct ffa_priv *priv, struct unit_test_state *uts)
> +{
> +   char msg[LOG_MSG_SZ] = {0};
> +
> +   if (priv->pair.rxtx_min_pages != RXTX_4K &&
> +   priv->pair.rxtx_min_pages != RXTX_16K &&
> +   priv->pair.rxtx_min_pages != RXTX_64K) {
> +   snprintf(msg,
> +   

Re: [PATCH v1 3/4] test: fdt: fix run_commandf() warnings

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 10:55, Evgeny Bachinin  wrote:
>
> Fix warnings both for 32bit and 64bit architecture after adding
> printf-like attribute format for run_commandf():
> warning: format ‘%x’ expects argument of type ‘unsigned int’, but
>   argument 2 has type ‘ulong {aka long unsigned int}’ [-Wformat=]
>   ret = run_commandf("fdt addr -c %08x", addr);
>  ^
> Signed-off-by: Evgeny Bachinin 
> ---
>  test/cmd/fdt.c | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v1 1/4] cli: run_commandf(): small fixups

2023-03-10 Thread Simon Glass
Hi Evgeny,

On Fri, 10 Mar 2023 at 10:55, Evgeny Bachinin  wrote:
>
> * vsnprintf() can truncate cmd, hence it makes no sense to launch such
> command (it's broken). Moreover, it's better to signalize to the caller
> about such case (for facilitating debugging or bug hunting).
>
> * Fix kernel-doc warnings:
>   include/command.h:264: info: Scanning doc for run_commandf
>   include/command.h:268: warning: contents before sections
>   include/command.h:271: warning: No description found for return value
>   of 'run_commandf'
>
> * Add printf-like format attribute to validate at compile-time the format
> string against parameters's type.
>
> * Fix compilation error in case of -Wall, -Werror, -Wextra:
> error: variable ‘i’ set but not used [-Werror=unused-but-set-variable]
>
> * Drop extra ret variable.
>
> Signed-off-by: Evgeny Bachinin 
> ---
>  common/cli.c  | 19 ++-
>  include/command.h | 13 ++---
>  2 files changed, 24 insertions(+), 8 deletions(-)

Reviewed-by: Simon Glass 

People are more used to using CONFIG_SYS_CBSIZE for the max cmdline
size, but I suppose this is fine. You could perhaps do a follow-on to
adjust this to use console_buffer[] ?

nits below

>
> diff --git a/common/cli.c b/common/cli.c
> index 9451e6a142..3db4e0f0b7 100644
> --- a/common/cli.c
> +++ b/common/cli.c
> @@ -8,6 +8,8 @@
>   * JinHua Luo, GuangDong Linux Center, 
>   */
>
> +#define pr_fmt(fmt) "cli: %s: " fmt, __func__
> +
>  #include 
>  #include 
>  #include 
> @@ -20,6 +22,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #ifdef CONFIG_CMDLINE
>  /*
> @@ -130,15 +133,21 @@ int run_commandf(const char *fmt, ...)
>  {
> va_list args;
> char cmd[128];
> -   int i, ret;
> +   int nbytes;
>
> va_start(args, fmt);
> -   i = vsnprintf(cmd, sizeof(cmd), fmt, args);
> +   nbytes = vsnprintf(cmd, sizeof(cmd), fmt, args);
> va_end(args);
>
> -   ret = run_command(cmd, 0);
> -
> -   return ret;
> +   if (nbytes < 0) {
> +   pr_err("I/O internal error occurred.\n");
> +   return -EIO;

This can't really happen, so to reduce code size, how about pr_debug() ?

> +   } else if ((size_t)nbytes >= sizeof(cmd)) {
> +   pr_err("'fmt' size:%d exceeds the limit(%zu)\n",
> +  nbytes, sizeof(cmd));
> +   return -EINVAL;

-ENOSPC perhaps? Then the caller can handle the message and this can
become pr_debug() as well.


> +   }
> +   return run_command(cmd, 0);
>  }
>
>  
> //
> diff --git a/include/command.h b/include/command.h
> index 0db4898062..6c0c97054c 100644
> --- a/include/command.h
> +++ b/include/command.h
> @@ -13,6 +13,8 @@
>  #include 
>  #include 
>
> +#include 
> +
>  #ifndef NULL
>  #define NULL   0
>  #endif
> @@ -260,12 +262,17 @@ int run_command_repeatable(const char *cmd, int flag);
>  /**
>   * run_commandf() - Run a command created by a format string
>   *
> - * The command cannot be larger than 127 characters
> - *
>   * @fmt: printf() format string
>   * @...: Arguments to use (flag is always 0)
> + *
> + * The command cannot be larger than 127 characters
> + *
> + * Return:
> + * Returns 0 on success, -EIO if internal output error occurred, -EINVAL in
> + * case of 'fmt' string truncation, or != 0 on error, specific for
> + * run_command().
>   */
> -int run_commandf(const char *fmt, ...);
> +int run_commandf(const char *fmt, ...) __printf(1, 2);
>
>  /**
>   * Run a list of commands separated by ; or even \0
> --
> 2.17.1
>


Re: [PATCH 2/2] CI: Allow a mirror to be specified for Docker Hub

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 01:55, Peter Hoyes  wrote:
>
> From: Peter Hoyes 
>
> To conserve bandwidth and potentially avoid rate limits, allow a local
> mirror of Docker Hub to be specified globally. The default value is
> unchanged.
>
> Signed-off-by: Peter Hoyes 
> ---
>  .gitlab-ci.yml | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [PATCH v9 08/10] arm_ffa: introduce armffa command Sandbox test

2023-03-10 Thread Simon Glass
Hi Abdellatif,

On Fri, 10 Mar 2023 at 06:11, Abdellatif El Khlifi
 wrote:
>
> Add Sandbox test for the armffa command
>
> Signed-off-by: Abdellatif El Khlifi 
> Cc: Tom Rini 
> Cc: Simon Glass 
> Cc: Ilias Apalodimas 
> Cc: Jens Wiklander 
>
> ---
> Changelog:
> ===
>
> v9: align the test with FF-A discovery through DM
>
> v4: drop use of helper APIs
>
> v1: introduce armffa command sandbox test
>
>  MAINTAINERS   |  1 +
>  test/cmd/Makefile |  2 ++
>  test/cmd/armffa.c | 39 +++
>  3 files changed, 42 insertions(+)
>  create mode 100644 test/cmd/armffa.c

Reviewed-by: Simon Glass 

>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 6939b832e4..b36fb41668 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -275,6 +275,7 @@ F:  doc/usage/cmd/armffa.rst
>  F: drivers/firmware/arm-ffa/
>  F: include/arm_ffa.h
>  F: include/sandbox_arm_ffa.h
> +F: test/cmd/armffa.c
>  F: test/dm/ffa.c
>
>  ARM FREESCALE IMX
> diff --git a/test/cmd/Makefile b/test/cmd/Makefile
> index 2ffde8703a..e74da56a29 100644
> --- a/test/cmd/Makefile
> +++ b/test/cmd/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0+
>  #
>  # Copyright (c) 2013 Google, Inc
> +# Copyright 2022-2023 Arm Limited and/or its affiliates 
> 
>
>  ifdef CONFIG_HUSH_PARSER
>  obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o
> @@ -19,6 +20,7 @@ obj-$(CONFIG_CMD_PWM) += pwm.o
>  obj-$(CONFIG_CMD_SEAMA) += seama.o
>  ifdef CONFIG_SANDBOX
>  obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
> +obj-$(CONFIG_SANDBOX_FFA) += armffa.o
>  endif
>  obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
>  obj-$(CONFIG_CMD_WGET) += wget.o
> diff --git a/test/cmd/armffa.c b/test/cmd/armffa.c
> new file mode 100644
> index 00..73c895f182
> --- /dev/null
> +++ b/test/cmd/armffa.c
> @@ -0,0 +1,39 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Test for armffa command
> + *
> + * Copyright 2022-2023 Arm Limited and/or its affiliates 
> 
> + *
> + * Authors:
> + *   Abdellatif El Khlifi 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define PING_CMD_SIZE 19
> +
> +/* Basic test of 'armffa' command */
> +static int dm_test_armffa_cmd(struct unit_test_state *uts)
> +{
> +   char ping_cmd[PING_CMD_SIZE] = {0};
> +
> +   /* armffa getpart  */
> +   ut_assertok(run_command("armffa getpart " SANDBOX_SERVICE1_UUID, 0));
> +
> +   snprintf(ping_cmd, PING_CMD_SIZE, "armffa ping 0x%x", SANDBOX_SP1_ID);
> +
> +   /* armffa ping  */
> +   ut_assertok(run_command(ping_cmd, 0));
> +
> +   /* armffa devlist */
> +   ut_assertok(run_command("armffa devlist", 0));
> +
> +   return CMD_RET_SUCCESS;

return 0

(this isn't even a command, it is a test)

> +}
> +
> +DM_TEST(dm_test_armffa_cmd, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
> --
> 2.25.1
>

Regards,
Simon


Re: [PATCH v1 2/4] unit-test: cover run_commandf() by test-cases

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 10:55, Evgeny Bachinin  wrote:
>
> As run_commandf() is variadic version of run_command() and just a wrapper,
> hence apply similar run_command's test-cases.
>
> Let's avoid warning about empty string passing:
> warning: zero-length gnu_printf format string [-Wformat-zero-length]
>assert(run_commandf("") == 0);
>
> Signed-off-by: Evgeny Bachinin 
> ---
>  test/command_ut.c | 35 +++
>  1 file changed, 35 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 2/3] drivers: pci: sandbox: Add stub sandbox PCI MPS support

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 11:08,  wrote:
>
> From: Stephen Carlson 
>
> Reports the sandbox swapcase PCI Express device to support a 256 byte
> Maximum Payload Size for MPS tuning tests.
>
> Signed-off-by: Stephen Carlson 
> ---
>  drivers/misc/swap_case.c | 3 +++
>  1 file changed, 3 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH 0/9] binman: Show missing blob message when building U-Boot

2023-03-10 Thread Simon Glass
Hi Jonas,

On Sun, 19 Feb 2023 at 14:02, Jonas Karlman  wrote:
>
> binman currently support showing a helpful missing blob message, but
> only when the --allow-missing flag is used.
>
> This changes so that binman is invoked with the --allow-missing flag
> and the helpful message can be shown by default when building U-Boot.
>
> Using the following:
>
>   make rockpro64-rk3399_defconfig
>   make CROSS_COMPILE="aarch64-linux-gnu-"
>
> Before this series a build fails with:
>
>   binman: Filename 'atf-bl31' not found in input path (...)
>
> After this series a build fails with:
>
>   Image 'simple-bin' is missing external blobs and is non-functional: atf-bl31
>
>   /binman/simple-bin/fit/images/@atf-SEQ/atf-bl31 (atf-bl31):
>  See the documentation for your board. You may need to build ARM Trusted
>  Firmware and build with BL31=/path/to/bl31.bin
>
>   Image 'simple-bin' is missing external blobs but is still functional: tee-os
>
>   /binman/simple-bin/fit/images/@tee-SEQ/tee-os (tee-os):
>  See the documentation for your board. You may need to build Open Portable
>  Trusted Execution Environment (OP-TEE) with TEE=/path/to/tee.bin
>
>   Some images are invalid
>
> Builds will continue to fail when there is missing blobs, and the use of
> BINMAN_ALLOW_MISSING=1 now only enables the --ignore-missing flag.
>
> This series also fixes a few minor issues that prevented some missing
> and optional blobs to be detected for fit and mkimage entries.
>
> Patch 1-3 contains spelling fixes and code cleanup for related parts.
> Patch 4-6 improve missing/optional detection for fit and mkimage entries.
> Patch 7-8 improve the missing blob warning message output.
> Patch 9 finally update Makefile to always pass the --allow-missing flag.
>
> The series is based on top of [1], and is the follow-up series meant to
> address the issue with missing blob message for mkimage entries.
>
> [1] 
> https://patchwork.ozlabs.org/project/uboot/cover/20230219150629.4012377-1-jo...@kwiboo.se/
>
> Jonas Karlman (9):
>   binman: Remove redundant SetAllowFakeBlob from blob-ext entry
>   binman: Fix spelling of nodes in code comments
>   binman: Use correct argument name in docstrings
>   binman: Override CheckOptional in fit entry
>   binman: Implement missing check functions in mkimage entry
>   binman: Mark mkimage entry missing when its subnodes is missing
>   binman: Fix blank line usage for invalid images warning text
>   binman: Show filename in missing blob help message
>   Makefile: Show binman missing blob message
>
>  Makefile  |  2 +-
>  tools/binman/control.py   | 24 ++---
>  tools/binman/entry.py |  2 +-
>  tools/binman/etype/blob.py|  2 +-
>  tools/binman/etype/blob_ext.py|  8 ---
>  tools/binman/etype/fit.py |  9 +++-
>  tools/binman/etype/mkimage.py | 54 ++-
>  tools/binman/etype/section.py |  6 +--
>  tools/binman/ftest.py |  9 
>  tools/binman/state.py |  2 +-
>  .../test/278_mkimage_missing_multiple.dts | 19 +++
>  11 files changed, 111 insertions(+), 26 deletions(-)
>  create mode 100644 tools/binman/test/278_mkimage_missing_multiple.dts
>
> --
> 2.39.2
>

I applied what I could of this to -next

Could you please take another look and see if we can get the rest in?

Regards,
Simon


Re: [RFC PATCH] binman: bintool: etype: Add support for ti-secure entry

2023-03-10 Thread Simon Glass
Hi,

On Thu, 9 Mar 2023 at 21:35, Neha Malcom Francis  wrote:
>
> Hi Andrew, Simon
>
> On 01/03/23 22:41, Andrew Davis wrote:
> > On 2/28/23 9:10 AM, Simon Glass wrote:
> >> Hi Neha,
> >>
> >> On Tue, 28 Feb 2023 at 02:50, Neha Malcom Francis 
> >> wrote:
> >>>
> >>> Hi Simon,
> >>>
> >>> On 28/02/23 06:05, Simon Glass wrote:
>  Hi Neha,
> 
>  On Fri, 24 Feb 2023 at 05:03, Neha Malcom Francis 
>  wrote:
> >
> > core-secdev-k3 is the TI security development package provided for K3
> > platform devices. This tool helps sign bootloader images with the x509
> > ceritificate header.
> >
> > Signed-off-by: Neha Malcom Francis 
> > ---
> > This patch depends on
> > https://patchwork.ozlabs.org/project/uboot/patch/20230224115101.563729-1-n-fran...@ti.com/
> > and on ongoing development in
> > https://git.ti.com/cgit/security-development-tools/core-secdev-k3
> >
> >tools/binman/btool/tisecuretool.py|  72 +++
> >tools/binman/etype/ti_secure.py   | 114
> > ++
> >tools/binman/ftest.py |  36 ++
> >tools/binman/test/278_ti_secure_rom.dts   |  11 ++
> >tools/binman/test/279_ti_secure.dts   |  11 ++
> >.../binman/test/280_ti_secure_nofilename.dts  |  10 ++
> >tools/binman/test/281_ti_secure_combined.dts  |  12 ++
> >7 files changed, 266 insertions(+)
> >create mode 100644 tools/binman/btool/tisecuretool.py
> >create mode 100644 tools/binman/etype/ti_secure.py
> >create mode 100644 tools/binman/test/278_ti_secure_rom.dts
> >create mode 100644 tools/binman/test/279_ti_secure.dts
> >create mode 100644 tools/binman/test/280_ti_secure_nofilename.dts
> >create mode 100644 tools/binman/test/281_ti_secure_combined.dts
> 
>  Now that I see what you are doing, this it not quite the right way.
> 
>  See this hack-up of how you can call the openssl thing. Basically you
>  should not have a shell script in the way, but instead make your
>  bintool do it.
> 
>  https://github.com/sjg20/u-boot/commit/03c0d74f81106570b18d8e4fe7a3355bfeb0d5da#r100378804
> 
>  I suppose we can have an openssl bintool that others build on top of?
> 
>  Regards,
>  Simon
> 
> 
> >>>
> >>> That is possible, maybe ti-secure extends from x509_cert etype so as to
> >>> support the TI specific certificate extensions. I'll start working on
> >>> this.
> >>>
> >>> However the patches I've sent support external production flow where
> >>> signing need not necessarily be carried out from U-Boot. An external
> >>> repo that acts as what is core-secdev-k3 here, would be the repo
> >>> responsible for signing.
> >>>
> >>> Could we find a way to combine both so as to support production flow
> >>> mandating an external agency, as well as a completely within U-Boot flow
> >>> using bintool? i.e. we modify ti-secure etype to be able to support both
> >>> external git repo/executable script signing as well as default signing
> >>> using openssl bintool.
> >>
> >> Yes that seems important.
> >>
> >> One option is to have binman emit some instructions on how to sign the
> >> image, perhaps a simple data format similar to an fdtmap, with a basic
> >> shell script plus whatever the etype provides. Then the signer can
> >> follow the instructions or run the script.
> >>
> >> Another option is to run binman on the signer and have it do the
> >> signing. Would that work?
> >>
> >
> > I'd like to keep the dependencies needed on the signing server as
> > minimal as possible. We do require the "u-boot-tools" package on
> > the key servers if folks want to re-package signed FIT images, so
> > if binman could be reasonably packaged in that package someday
> > it could be an option.

At present binman is packaged as binary-manager (with 'pip install').
Is that good enough? We could add it to u-boot-tools, perhaps, but I
have found that packing Python things together with non-Python things
seems to be tricky. We gave up with libfdt and ended up using a
separate package for pylibfdt.

> >
> > For now, if binman could generate the x509 file and leave it with the
> > other boot artifacts then if one needs to re-sign with real keys they
> > will only need to have openssl sign that cert and append to the image
> > on the key server, that is simple enough document.

I sent a patch to add x509 cert using the openssl tool[1]. If there is
more needed, can you take a look or let me know what is missing?

> >
> > The more difficult part is in re-packaging these signed images.
> > Our security tools already have a tool to disasemble a FIT image,
> > sign the components, then re-assemble it[0]. This would work for
> > u-boot.img and the kernel FIT images, but we would need something
> > new for re-assembling boot3.bin and tispl.bin. The first boot files
> > (boot3.bin) is also 

Re: [PATCH] sysinfo: gpio: fix loop over DT "revisions" array

2023-03-10 Thread Simon Glass
On Fri, 10 Mar 2023 at 02:58, Rasmus Villemoes
 wrote:
>
> There can certainly be a lot more elements in the "revisions" (and
> "names") arrays than there are gpios used to form the trinary number
> we're searching for; we simply don't know the array size up-front.
>
> Nor do we need to, because the loop body already knows to recognize
> -EOVERFLOW as "not that many elements present" (and we have a test
> that specifically ensures that dev_read_u32_index() returns exactly
> that). So just drop the i < priv->gpio_num condition.
>
> While in here, fix the weird placement of the default: keyword.
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  drivers/sysinfo/gpio.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass 


[PATCH v2 11/12] efi: Support showing tables

2023-03-10 Thread Simon Glass
Add a command (for the app and payload) to display the tables provided
by EFI.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Make use of common code

 cmd/Makefile  |  2 +-
 cmd/efi.c | 33 -
 doc/usage/cmd/efi.rst | 22 ++
 3 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/cmd/Makefile b/cmd/Makefile
index 1c5c6f3c00c..a0bfa2acefe 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -62,7 +62,7 @@ obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
 obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
-obj-$(CONFIG_EFI) += efi.o
+obj-$(CONFIG_EFI) += efi.o efi_common.o
 obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
 obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
 ifdef CONFIG_CMD_EFICONFIG
diff --git a/cmd/efi.c b/cmd/efi.c
index c0384e0db28..4d0edfa7f27 100644
--- a/cmd/efi.c
+++ b/cmd/efi.c
@@ -7,10 +7,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -273,8 +275,36 @@ done:
return ret ? CMD_RET_FAILURE : 0;
 }
 
+static int do_efi_tables(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   struct efi_system_table *systab;
+
+   if (IS_ENABLED(CONFIG_EFI_APP)) {
+   systab = efi_get_sys_table();
+   if (!systab) {
+   printf("Cannot read system table\n");
+   return CMD_RET_FAILURE;
+   }
+   } else {
+   int size;
+   int ret;
+
+   ret = efi_info_get(EFIET_SYS_TABLE, (void **), );
+   if (ret) {
+   printf("Cannot find EFI system table (err=%d)\n", ret);
+   return CMD_RET_FAILURE;
+   }
+   }
+
+   efi_show_tables(systab);
+
+   return 0;
+}
+
 static struct cmd_tbl efi_commands[] = {
U_BOOT_CMD_MKENT(mem, 1, 1, do_efi_mem, "", ""),
+   U_BOOT_CMD_MKENT(tables, 1, 1, do_efi_tables, "", ""),
 };
 
 static int do_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
@@ -298,5 +328,6 @@ static int do_efi(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
 U_BOOT_CMD(
efi, 3,  1,  do_efi,
"EFI access",
-   "mem [all]Dump memory information [include boot services]"
+   "mem [all]Dump memory information [include boot services]\n"
+   "tables   Dump tables"
 );
diff --git a/doc/usage/cmd/efi.rst b/doc/usage/cmd/efi.rst
index c029c423879..ef37ff2f4c1 100644
--- a/doc/usage/cmd/efi.rst
+++ b/doc/usage/cmd/efi.rst
@@ -10,6 +10,7 @@ Synopsis
 ::
 
 efi mem [all]
+efi tables
 
 Description
 ---
@@ -54,6 +55,14 @@ Attributes
 Shows a code for memory attributes. The key for this is shown below the
 table.
 
+efi tables
+~~
+
+This shows a list of the EFI tables provided in the system table. These use
+GUIDs so it is not possible in general to show the name of a table. But some
+effort is made to provide a useful table, where the GUID is known by U-Boot.
+
+
 Example
 ---
 
@@ -195,3 +204,16 @@ Example
  f: uncached, write-coalescing, write-through, write-back
 rf: uncached, write-coalescing, write-through, write-back, needs runtime 
mapping
  1: uncached
+
+
+=> efi tables
+1f8edf98  ee4e5898-3914-4259-9d6e-dc7bd79403cf  EFI_LZMA_COMPRESSED
+1ff2ace0  05ad34ba-6f02-4214-952e-4da0398e2bb9  EFI_DXE_SERVICES
+1f8ea018  7739f24c-93d7-11d4-9a3a-0090273fc14d  EFI_HOB_LIST
+1ff2bac0  4c19049f-4137-4dd3-9c10-8b97a83ffdfa  EFI_MEMORY_TYPE
+1ff2cb10  49152e77-1ada-4764-b7a2-7afefed95e8b  (unknown)
+1f9ac018  060cc026-4c0d-4dda-8f41-595fef00a502  
EFI_MEM_STATUS_CODE_REC
+1f9ab000  eb9d2d31-2d88-11d3-9a16-0090273fc14d  SMBIOS table
+1fb7e000  eb9d2d30-2d88-11d3-9a16-0090273fc14d  EFI_GUID_EFI_ACPI1
+1fb7e014  8868e871-e4f1-11d3-bc22-0080c73c8881  ACPI table
+1e654018  dcfa911d-26eb-469f-a220-38b7dc461220  (unknown)
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 10/12] efi: Split out table-listing code into a new file

2023-03-10 Thread Simon Glass
This code is used with EFI_LOADER but is also useful (with some
modifications) for the EFI app and payload. Move it into a shared
file.

Show the address of the table so it can be examined if needed. Also show
the table name as unknown if necessary. Our list of GUIDs is fairly
small.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to split out table-listing code into a new file

 cmd/Makefile |  2 +-
 cmd/efi_common.c | 26 ++
 cmd/efidebug.c   |  6 +-
 include/efi.h|  9 +
 4 files changed, 37 insertions(+), 6 deletions(-)
 create mode 100644 cmd/efi_common.c

diff --git a/cmd/Makefile b/cmd/Makefile
index 2d8bb4fc052..1c5c6f3c00c 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -63,7 +63,7 @@ obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
 obj-$(CONFIG_EFI) += efi.o
-obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o
+obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o efi_common.o
 obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o
 ifdef CONFIG_CMD_EFICONFIG
 ifdef CONFIG_EFI_MM_COMM_TEE
diff --git a/cmd/efi_common.c b/cmd/efi_common.c
new file mode 100644
index 000..7eedf0726a7
--- /dev/null
+++ b/cmd/efi_common.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Common code for EFI commands
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+void efi_show_tables(struct efi_system_table *systab)
+{
+   int i;
+
+   for (i = 0; i < systab->nr_tables; i++) {
+   struct efi_configuration_table *tab = >tables[i];
+   char guid_str[37];
+
+   uuid_bin_to_str(tab->guid.b, guid_str, 1);
+   printf("%p  %s  %s\n", tab->table, guid_str,
+  uuid_guid_get_str(tab->guid.b) ?: "(unknown)");
+   }
+}
diff --git a/cmd/efidebug.c b/cmd/efidebug.c
index e6959ede930..9622430c475 100644
--- a/cmd/efidebug.c
+++ b/cmd/efidebug.c
@@ -649,11 +649,7 @@ static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int 
flag,
 static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag,
  int argc, char *const argv[])
 {
-   efi_uintn_t i;
-
-   for (i = 0; i < systab.nr_tables; ++i)
-   printf("%pUl (%pUs)\n",
-  [i].guid, [i].guid);
+   efi_show_tables();
 
return CMD_RET_SUCCESS;
 }
diff --git a/include/efi.h b/include/efi.h
index c3087d3da28..342dd52fed9 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -637,4 +637,13 @@ int efi_call_exit_boot_services(void);
 int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
 int *desc_sizep, uint *versionp);
 
+/**
+ * efi_show_tables() - Show a list of available tables
+ *
+ * Shows the address, GUID (and name where known) for each table
+ *
+ * @systab: System table containing the list of tables
+ */
+void efi_show_tables(struct efi_system_table *systab);
+
 #endif /* _LINUX_EFI_H */
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 09/12] doc: Add help for the efi command

2023-03-10 Thread Simon Glass
This command currently has no help. Add some.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/usage/cmd/efi.rst | 197 ++
 doc/usage/index.rst   |   1 +
 2 files changed, 198 insertions(+)
 create mode 100644 doc/usage/cmd/efi.rst

diff --git a/doc/usage/cmd/efi.rst b/doc/usage/cmd/efi.rst
new file mode 100644
index 000..c029c423879
--- /dev/null
+++ b/doc/usage/cmd/efi.rst
@@ -0,0 +1,197 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. Copyright 2020, Heinrich Schuchardt 
+
+efi command
+===
+
+Synopsis
+
+
+::
+
+efi mem [all]
+
+Description
+---
+
+The *efi* command provides information about the EFI environment U-Boot is
+running in, when it is started from EFI.
+
+When running as an EFI app, this command queries EFI boot services for the
+information. When running as an EFI payload, EFI boot services have been
+stopped, so it uses the information collected by the boot stub before that
+happened.
+
+efi mem
+~~~
+
+This shows the EFI memory map, sorted in order of physical address.
+
+This is normally a very large table. To help reduce the amount of detritus,
+boot-time memory is normally merged with conventional memory. Use the 'all'
+argument to show everything.
+
+The fields are as follows:
+
+#
+Entry number (sequentially from 0)
+
+Type
+Memory type. EFI has a large number of memory types. The type is shown in
+the format : where in is the format number in hex and  is 
the
+name.
+
+Physical
+Physical address
+
+Virtual
+Virtual address
+
+Size
+Size of memory area in bytes
+
+Attributes
+Shows a code for memory attributes. The key for this is shown below the
+table.
+
+Example
+---
+
+::
+
+=> efi mem
+EFI table at 0, memory map 1ad38b60, size 1260, key a79, version 
1, descr. size 0x30
+ #  Type  Physical VirtualSize  Attributes
+ 0  7:conv  00  00  0a  f
+   0a  06
+ 1  7:conv  10  00  70  f
+ 2  a:acpi_nvs  80  00  008000  f
+ 3  7:conv  808000  00  008000  f
+ 4  a:acpi_nvs  81  00  0f  f
+ 5  7:conv  90  00  001efef000  f
+ 6  6:rt_data   001f8ef000  00  10  rf
+ 7  5:rt_code   001f9ef000  00  10  rf
+ 8  0:reserved  001faef000  00  08  f
+ 9  9:acpi_reclaim  001fb6f000  00  01  f
+10  a:acpi_nvs  001fb7f000  00  08  f
+11  7:conv  001fbff000  00  359000  f
+12  6:rt_data   001ff58000  00  02  rf
+13  a:acpi_nvs  001ff78000  00  088000  f
+   002000  009000
+14  0:reserved  00b000  00  001000  1
+
+Attributes key:
+ f: uncached, write-coalescing, write-through, write-back
+rf: uncached, write-coalescing, write-through, write-back, needs runtime 
mapping
+ 1: uncached
+*Some areas are merged (use 'all' to see)
+
+
+=> efi mem  all
+EFI table at 0, memory map 1ad38bb0, size 1260, key a79, version 
1, descr. size 0x30
+ #  Type  Physical VirtualSize  Attributes
+ 0  3:bs_code   00  00  001000  f
+ 1  7:conv  001000  00  09f000  f
+   0a  06
+ 2  7:conv  10  00  70  f
+ 3  a:acpi_nvs  80  00  008000  f
+ 4  7:conv  808000  00  008000  f
+ 5  a:acpi_nvs  81  00  0f  f
+ 6  4:bs_data   90  00  c0  f
+ 7  7:conv  000150  00  000aa36000  f
+ 8  2:loader_data   000bf36000  00  001000  f
+ 9  4:bs_data   001bf36000  00  02  f
+10  7:conv  001bf56000  00  00021e1000  f
+11  1:loader_code   001e137000  00  0c4000  f
+12  7:conv  001e1fb000  00  09b000  f
+13  1:loader_code   001e296000  00  0e2000  f
+14  7:conv  001e378000  00  05b000  f
+15  4:bs_data   001e3d3000  00  01e000  f
+16  7:conv  001e3f1000  00  016000  f
+17  4:bs_data   001e407000  00  016000  f
+18  2:loader_data   001e41d000  00  002000  f
+19  4:bs_data   001e41f000  00  828000  f
+20  3:bs_code   001ec47000  00  045000  f
+21  4:bs_data   001ec8c000  00  001000  f
+22  3:bs_code   001ec8d000  00  00e000  f
+23  4:bs_data   001ec9b000  00  001000 

[PATCH v2 07/12] efi: Add another tranch of GUIDs

2023-03-10 Thread Simon Glass
Provide information about the GUIDs supplied by QEMU, so far as it is
known.

These values are used in the 'efi table' command as well as the printf
format string %sU

Signed-off-by: Simon Glass 
---

Changes in v2:
- Update commit message to explain why these are needed
- Drop EFI_SMBIOS which exists as SMBIOS_TABLE_GUID
- Drop unwanted EFI_GUID_SNBIOS
- Drop EFI_GUID_EFI_ACPI2 which exists as EFI_ACPI_TABLE_GUID

 include/efi_api.h | 22 ++
 lib/uuid.c|  7 +++
 2 files changed, 29 insertions(+)

diff --git a/include/efi_api.h b/include/efi_api.h
index 2d18d25a713..3dd48195885 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1909,6 +1909,28 @@ struct efi_system_resource_table {
EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
 
+#define EFI_LZMA_COMPRESSED \
+   EFI_GUID(0xee4e5898, 0x3914, 0x4259, 0x9d, 0x6e, \
+0xdc, 0x7b, 0xd7, 0x94, 0x03, 0xcf)
+#define EFI_DXE_SERVICES \
+   EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, \
+0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
+#define EFI_HOB_LIST \
+   EFI_GUID(0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a,  \
+0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+#define EFI_MEMORY_TYPE \
+   EFI_GUID(0x4c19049f, 0x4137, 0x4dd3, 0x9c, 0x10, \
+0x8b, 0x97, 0xa8, 0x3f, 0xfd, 0xfa)
+#define EFI_SMBIOS \
+   EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16,  \
+0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+#define EFI_MEM_STATUS_CODE_REC \
+   EFI_GUID(0x060cc026, 0x4c0d, 0x4dda, 0x8f, 0x41, \
+0x59, 0x5f, 0xef, 0x00, 0xa5, 0x02)
+#define EFI_GUID_EFI_ACPI1 \
+   EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, \
+0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
+
 /**
  * struct win_certificate_uefi_guid - A certificate that encapsulates
  * a GUID-specific signature
diff --git a/lib/uuid.c b/lib/uuid.c
index 465e1ac38f5..d86fab72626 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -255,6 +255,13 @@ static const struct {
EFI_CERT_TYPE_PKCS7_GUID,
},
 #endif
+   { "EFI_LZMA_COMPRESSED", EFI_LZMA_COMPRESSED },
+   { "EFI_DXE_SERVICES", EFI_DXE_SERVICES },
+   { "EFI_HOB_LIST", EFI_HOB_LIST },
+   { "EFI_MEMORY_TYPE", EFI_MEMORY_TYPE },
+   { "EFI_SMBIOS", EFI_SMBIOS },
+   { "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC },
+   { "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 },
 };
 
 /*
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 08/12] efi: Include GUID names with EFI app and payload

2023-03-10 Thread Simon Glass
These are currently only available when running with EFI_LOADER.
Expand this to include the app and payload, since it is useful to be
able to decode things there.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to enable GUID names with EFI app and payload

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

diff --git a/lib/uuid.c b/lib/uuid.c
index d86fab72626..09793fb62bc 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -102,7 +102,7 @@ static const struct {
{"lvm", PARTITION_LINUX_LVM_GUID},
{"u-boot-env",  PARTITION_U_BOOT_ENVIRONMENT},
 #endif
-#ifdef CONFIG_CMD_EFIDEBUG
+#if defined(CONFIG_CMD_EFIDEBUG) || defined(CONFIG_EFI)
{
"Device Path",
EFI_DEVICE_PATH_PROTOCOL_GUID,
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 05/12] x86: Exit EFI boot services before starting kernel

2023-03-10 Thread Simon Glass
When running the EFI app, we need to exit boot services before jumping
to Linux.

At some point it may be possible to jump to Linux and pass on the boot
services, so that the Linux efistub can be used. For now, this is not
implemented.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/bootm.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c
index 9beb376bb9c..61cb7bc6116 100644
--- a/arch/x86/lib/bootm.c
+++ b/arch/x86/lib/bootm.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -156,6 +157,23 @@ int boot_linux_kernel(ulong setup_base, ulong entry, bool 
image_64bit)
 #ifdef CONFIG_SYS_COREBOOT
timestamp_add_now(TS_U_BOOT_START_KERNEL);
 #endif
+
+   /*
+* Exit EFI boot services just before jumping, after all console
+* output, since the console won't be available afterwards.
+*/
+   if (IS_ENABLED(CONFIG_EFI_APP)) {
+   int ret;
+
+   ret = efi_store_memory_map(efi_get_priv());
+   if (ret)
+   return ret;
+   printf("Exiting EFI boot services\n");
+   ret = efi_call_exit_boot_services();
+   if (ret)
+   return ret;
+   }
+
if (image_64bit) {
if (!cpu_has_64bit()) {
puts("Cannot boot 64-bit kernel on 32-bit machine\n");
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 06/12] x86: Support zboot and bootm in the EFI app

2023-03-10 Thread Simon Glass
These have been disabled due to the rudimentary support available. It is
a little better now, so enable these options.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/efi-x86_app32_defconfig | 2 +-
 configs/efi-x86_app64_defconfig | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/configs/efi-x86_app32_defconfig b/configs/efi-x86_app32_defconfig
index 905f375a3ef..50975dbfaaf 100644
--- a/configs/efi-x86_app32_defconfig
+++ b/configs/efi-x86_app32_defconfig
@@ -19,7 +19,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PBSIZE=532
-# CONFIG_CMD_BOOTM is not set
+CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_PART=y
 # CONFIG_CMD_NET is not set
 CONFIG_CMD_TIME=y
diff --git a/configs/efi-x86_app64_defconfig b/configs/efi-x86_app64_defconfig
index f1cf43c1ef6..0fc358ddcdf 100644
--- a/configs/efi-x86_app64_defconfig
+++ b/configs/efi-x86_app64_defconfig
@@ -20,7 +20,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_LAST_STAGE_INIT=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PBSIZE=532
-# CONFIG_CMD_BOOTM is not set
+CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_PART=y
 # CONFIG_CMD_NET is not set
 CONFIG_CMD_CACHE=y
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 04/12] x86: Support booting a 64-bit kernel from 64-bit U-Boot

2023-03-10 Thread Simon Glass
Add the missing code to handle this. For a 64-bit kernel the entry
address is 0x200 bytes after the normal entry.

Rename the parameter to boot_linux_kernel() accordingly. Update the
comments to indicate that these are addresses, not pointers.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/include/asm/bootm.h | 12 ++--
 arch/x86/lib/bootm.c | 25 +
 arch/x86/lib/zimage.c| 15 +--
 3 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/arch/x86/include/asm/bootm.h b/arch/x86/include/asm/bootm.h
index 109f686f740..3b641783b9c 100644
--- a/arch/x86/include/asm/bootm.h
+++ b/arch/x86/include/asm/bootm.h
@@ -14,14 +14,14 @@ void bootm_announce_and_cleanup(void);
  * This boots a kernel image, either 32-bit or 64-bit. It will also work with
  * a self-extracting kernel, if you set @image_64bit to false.
  *
- * @setup_base:Pointer to the setup.bin information for the 
kernel
- * @load_address:  Pointer to the start of the kernel image
- * @image_64bit:   true if the image is a raw 64-bit kernel, false if it
- * is raw 32-bit or any type of self-extracting kernel
- * such as a bzImage.
+ * @setup_base:Address of the setup.bin information for the 
kernel
+ * @entry: Address of the kernel entry point
+ * @image_64bit:   true if the image is a raw 64-bit kernel, or a kernel
+ * which supports booting in 64-bit mode; false if it is raw 32-bit or any type
+ * of self-extracting kernel such as a bzImage.
  * Return: -ve error code. This function does not return if the kernel was
  * booted successfully.
  */
-int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit);
+int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit);
 
 #endif
diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c
index 873e2bc176f..9beb376bb9c 100644
--- a/arch/x86/lib/bootm.c
+++ b/arch/x86/lib/bootm.c
@@ -149,7 +149,7 @@ error:
return 1;
 }
 
-int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit)
+int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit)
 {
bootm_announce_and_cleanup();
 
@@ -161,14 +161,23 @@ int boot_linux_kernel(ulong setup_base, ulong 
load_address, bool image_64bit)
puts("Cannot boot 64-bit kernel on 32-bit machine\n");
return -EFAULT;
}
-   /* At present 64-bit U-Boot does not support booting a
+   /*
+* At present 64-bit U-Boot only supports booting a 64-bit
 * kernel.
-* TODO(s...@chromium.org): Support booting both 32-bit and
-* 64-bit kernels from 64-bit U-Boot.
+*
+* TODO(s...@chromium.org): Support booting 32-bit kernels from
+* 64-bit U-Boot
 */
-#if !CONFIG_IS_ENABLED(X86_64)
-   return cpu_jump_to_64bit(setup_base, load_address);
-#endif
+   if (CONFIG_IS_ENABLED(X86_64)) {
+   typedef void (*h_func)(ulong zero, ulong setup);
+   h_func func;
+
+   /* jump to Linux with rdi=0, rsi=setup_base */
+   func = (h_func)entry;
+   func(0, setup_base);
+   } else {
+   return cpu_jump_to_64bit(setup_base, entry);
+   }
} else {
/*
* Set %ebx, %ebp, and %edi to 0, %esi to point to the
@@ -190,7 +199,7 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, 
bool image_64bit)
"movl $0, %%ebp\n"
"cli\n"
"jmp *%[kernel_entry]\n"
-   :: [kernel_entry]"a"(load_address),
+   :: [kernel_entry]"a"(entry),
[boot_params] "S"(setup_base),
"b"(0), "D"(0)
);
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index a6d9151c324..e5ea5129c1e 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -504,13 +504,24 @@ static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, 
int argc,
 static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
   char *const argv[])
 {
+   struct boot_params *params = state.base_ptr;
+   struct setup_header *hdr = >hdr;
+   bool image_64bit;
+   ulong entry;
int ret;
 
disable_interrupts();
 
+   entry = state.load_address;
+   image_64bit = false;
+   if (IS_ENABLED(CONFIG_X86_RUN_64BIT) &&
+   (hdr->xloadflags & XLF_KERNEL_64)) {
+   entry += 0x200;
+   image_64bit = true;
+   }
+
/* we assume that the kernel is in place */
-   ret = boot_linux_kernel((ulong)state.base_ptr, state.load_address,
-   false);
+   ret = 

[PATCH v2 02/12] x86: Adjust bootparam.h to be more like linux

2023-03-10 Thread Simon Glass
This likely came from Linux originally, so update it to match v6.2 more.
This has no functional change.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/include/asm/bootparam.h | 70 +---
 arch/x86/lib/zimage.c|  2 +-
 2 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/arch/x86/include/asm/bootparam.h b/arch/x86/include/asm/bootparam.h
index 7a3c1f51554..ea816ca7469 100644
--- a/arch/x86/include/asm/bootparam.h
+++ b/arch/x86/include/asm/bootparam.h
@@ -9,19 +9,54 @@
 #include 
 #include 
 
-/* setup data types */
-enum {
-   SETUP_NONE = 0,
-   SETUP_E820_EXT,
-   SETUP_DTB,
-};
+/* setup_data/setup_indirect types */
+#define SETUP_NONE 0
+#define SETUP_E820_EXT 1
+#define SETUP_DTB  2
+#define SETUP_PCI  3
+#define SETUP_EFI  4
+#define SETUP_APPLE_PROPERTIES 5
+#define SETUP_JAILHOUSE6
+#define SETUP_CC_BLOB  7
+#define SETUP_IMA  8
+#define SETUP_RNG_SEED 9
+#define SETUP_ENUM_MAX SETUP_RNG_SEED
+
+#define SETUP_INDIRECT BIT(31)
+#define SETUP_TYPE_MAX (SETUP_ENUM_MAX | SETUP_INDIRECT)
+
+/* ram_size flags */
+#define RAMDISK_IMAGE_START_MASK   0x07FF
+#define RAMDISK_PROMPT_FLAG0x8000
+#define RAMDISK_LOAD_FLAG  0x4000
+
+/* loadflags */
+#define LOADED_HIGHBIT(0)
+#define KASLR_FLAG BIT(1)
+#define QUIET_FLAG BIT(5)
+#define KEEP_SEGMENTS  BIT(6)
+#define CAN_USE_HEAP   BIT(7)
+
+#define XLF_KERNEL_64  BIT(0)
+#define XLF_CAN_BE_LOADED_ABOVE_4G BIT(1)
+#define XLF_EFI_HANDOVER_32BIT(2)
+#define XLF_EFI_HANDOVER_64BIT(3)
+#define XLF_EFI_KEXEC  BIT(4)
 
 /* extensible setup data list node */
 struct setup_data {
__u64 next;
__u32 type;
__u32 len;
-   __u8 data[0];
+   __u8 data[];
+};
+
+/* extensible setup indirect data node */
+struct setup_indirect {
+   __u32 type;
+   __u32 reserved;  /* Reserved, must be set to zero. */
+   __u64 len;
+   __u64 addr;
 };
 
 /**
@@ -34,9 +69,6 @@ struct setup_header {
__u16   root_flags;
__u32   syssize;
__u16   ram_size;
-#define RAMDISK_IMAGE_START_MASK   0x07FF
-#define RAMDISK_PROMPT_FLAG0x8000
-#define RAMDISK_LOAD_FLAG  0x4000
__u16   vid_mode;
__u16   root_dev;
__u16   boot_flag;
@@ -44,15 +76,10 @@ struct setup_header {
__u32   header;
__u16   version;
__u32   realmode_swtch;
-   __u16   start_sys;
+   __u16   start_sys_seg;
__u16   kernel_version;
__u8type_of_loader;
__u8loadflags;
-#define LOADED_HIGHBIT(0)
-#define KASLR_FLAG BIT(1)
-#define QUIET_FLAG BIT(5)
-#define KEEP_SEGMENTS  BIT(6)  /* Obsolete */
-#define CAN_USE_HEAP   BIT(7)
__u16   setup_move_size;
__u32   code32_start;
__u32   ramdisk_image;
@@ -65,13 +92,8 @@ struct setup_header {
__u32   initrd_addr_max;
__u32   kernel_alignment;
__u8relocatable_kernel;
-   u8  min_alignment;
-#define XLF_KERNEL_64  BIT(0)
-#define XLF_CAN_BE_LOADED_ABOVE_4G BIT(1)
-#define XLF_EFI_HANDOVER_32BIT(2)
-#define XLF_EFI_HANDOVER_64BIT(3)
-#define XLF_EFI_KEXEC  BIT(4)
-   u16 xloadflags;
+   __u8min_alignment;
+   __u16   xloadflags;
__u32   cmdline_size;
__u32   hardware_subarch;
__u64   hardware_subarch_data;
@@ -81,7 +103,7 @@ struct setup_header {
__u64   pref_address;
__u32   init_size;
__u32   handover_offset;
-   u32 kernel_info_offset;
+   __u32   kernel_info_offset;
 } __attribute__((packed));
 
 struct sys_desc_table {
diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 9cc04490307..a6d9151c324 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -655,7 +655,7 @@ void zimage_dump(struct boot_params *base_ptr)
printf("%-20s  %s\n", "", "Ancient kernel, using version 100");
print_num("Version", hdr->version);
print_num("Real mode switch", hdr->realmode_swtch);
-   print_num("Start sys", hdr->start_sys);
+   print_num("Start sys seg", hdr->start_sys_seg);
print_num("Kernel version", hdr->kernel_version);
version = get_kernel_version(base_ptr, (void *)state.bzimage_addr);
if (version)
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 03/12] x86: Add return-value comment to cpu_jump_to_64bit()

2023-03-10 Thread Simon Glass
This does not mention what it returns. Add the missing documentation.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/include/asm/cpu.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h
index 3346012d335..aa03ef598e1 100644
--- a/arch/x86/include/asm/cpu.h
+++ b/arch/x86/include/asm/cpu.h
@@ -262,6 +262,7 @@ void cpu_call32(ulong code_seg32, ulong target, ulong 
table);
  *
  * @setup_base:Pointer to the setup.bin information for the kernel
  * @target:Pointer to the start of the kernel image
+ * Returns: -EFAULT if the kernel returned; otherwise does not return
  */
 int cpu_jump_to_64bit(ulong setup_base, ulong target);
 
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 01/12] efi: Set RUN_64BIT correctly for the EFI app

2023-03-10 Thread Simon Glass
The U-Boot EFI app can run as a 64-bit program, so set the Kconfig
correctly in that case. Make sure it doesn't build SPL, since there is
no need to switch from 32 to 64 bit when running.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/Kconfig| 4 ++--
 configs/efi-x86_app64_defconfig | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 07be5cd05ec..99e59d94c60 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -32,8 +32,8 @@ config X86_RUN_32BIT
 config X86_RUN_64BIT
bool "64-bit"
select X86_64
-   select SPL
-   select SPL_SEPARATE_BSS
+   select SPL if !EFI_APP
+   select SPL_SEPARATE_BSS if !EFI_APP
help
  Build U-Boot as a 64-bit binary with a 32-bit SPL. This is
  experimental and many features are missing. U-Boot SPL starts up,
diff --git a/configs/efi-x86_app64_defconfig b/configs/efi-x86_app64_defconfig
index dae48840493..f1cf43c1ef6 100644
--- a/configs/efi-x86_app64_defconfig
+++ b/configs/efi-x86_app64_defconfig
@@ -4,6 +4,7 @@ CONFIG_ENV_SIZE=0x1000
 CONFIG_DEFAULT_DEVICE_TREE="efi-x86_app"
 CONFIG_DEBUG_UART_BASE=0
 CONFIG_DEBUG_UART_CLOCK=0
+CONFIG_X86_RUN_64BIT=y
 CONFIG_VENDOR_EFI=y
 CONFIG_TARGET_EFI_APP64=y
 CONFIG_DEBUG_UART=y
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 00/12] efi: Improvements to booting and debugging

2023-03-10 Thread Simon Glass
This series provides support for booting a kernel from the EFI app. So
far this is pretty basic, since it only supports the actual booting, not
providing ACPI tables, etc. But it is a start.

It also includes an enhancement to the 'efi' command and a few other
clean-ups.


Changes in v2:
- Update commit message to explain why these are needed
- Drop EFI_SMBIOS which exists as SMBIOS_TABLE_GUID
- Drop unwanted EFI_GUID_SNBIOS
- Drop EFI_GUID_EFI_ACPI2 which exists as EFI_ACPI_TABLE_GUID
- Add new patch to enable GUID names with EFI app and payload
- Add new patch to split out table-listing code into a new file
- Make use of common code
- Fix typos in commit message

Simon Glass (12):
  efi: Set RUN_64BIT correctly for the EFI app
  x86: Adjust bootparam.h to be more like linux
  x86: Add return-value comment to cpu_jump_to_64bit()
  x86: Support booting a 64-bit kernel from 64-bit U-Boot
  x86: Exit EFI boot services before starting kernel
  x86: Support zboot and bootm in the EFI app
  efi: Add another tranch of GUIDs
  efi: Include GUID names with EFI app and payload
  doc: Add help for the efi command
  efi: Split out table-listing code into a new file
  efi: Support showing tables
  efI: Allow packaging a kernel in the debugging script

 arch/x86/Kconfig |   4 +-
 arch/x86/include/asm/bootm.h |  12 +-
 arch/x86/include/asm/bootparam.h |  70 ++
 arch/x86/include/asm/cpu.h   |   1 +
 arch/x86/lib/bootm.c |  43 --
 arch/x86/lib/zimage.c|  17 ++-
 cmd/Makefile |   4 +-
 cmd/efi.c|  33 -
 cmd/efi_common.c |  26 
 cmd/efidebug.c   |   6 +-
 configs/efi-x86_app32_defconfig  |   2 +-
 configs/efi-x86_app64_defconfig  |   3 +-
 doc/usage/cmd/efi.rst| 219 +++
 doc/usage/index.rst  |   1 +
 include/efi.h|   9 ++
 include/efi_api.h|  22 
 lib/uuid.c   |   9 +-
 scripts/build-efi.sh |  14 +-
 18 files changed, 440 insertions(+), 55 deletions(-)
 create mode 100644 cmd/efi_common.c
 create mode 100644 doc/usage/cmd/efi.rst

-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH 2/2] buildman: Fix CROSS_COMPILE output for sandbox

2023-03-10 Thread Simon Glass
The previous attempt at fixing this broke the normal usage of the -A
flag.

At present, 'buildman -A sandbox' adds the path containing the
toolchain. We can assume that this is in the path and we don't want to
set CROSS_COMPILE=/bin/

Change this to align with what MakeEnvironment() does, but only for
sandbox boards.

Signed-off-by: Simon Glass 
---

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

diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
index 688f2e26872..241e8e69307 100644
--- a/tools/buildman/toolchain.py
+++ b/tools/buildman/toolchain.py
@@ -156,9 +156,10 @@ class Toolchain:
 Returns:
 Value of that environment variable or arguments
 """
-wrapper = self.GetWrapper()
 if which == VAR_CROSS_COMPILE:
-return wrapper + os.path.join(self.path, self.cross)
+wrapper = self.GetWrapper()
+base = '' if self.arch == 'sandbox' else self.path
+return wrapper + os.path.join(base, self.cross)
 elif which == VAR_PATH:
 return self.path
 elif which == VAR_ARCH:
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH 1/2] Revert "buildman: Correct CROSS_COMPILE output for sandbox"

2023-03-10 Thread Simon Glass
This reverts commit bd0a548ad4a155fec29473d4cc8e135832926973.

Signed-off-by: Simon Glass 
---

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

diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
index 8f9130bdcdf..688f2e26872 100644
--- a/tools/buildman/toolchain.py
+++ b/tools/buildman/toolchain.py
@@ -156,8 +156,9 @@ class Toolchain:
 Returns:
 Value of that environment variable or arguments
 """
+wrapper = self.GetWrapper()
 if which == VAR_CROSS_COMPILE:
-return self.GetWrapper() + self.cross
+return wrapper + os.path.join(self.path, self.cross)
 elif which == VAR_PATH:
 return self.path
 elif which == VAR_ARCH:
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 13/13] video: Add a note about the broken implementation

2023-03-10 Thread Simon Glass
The cls command is broken. Previous discussion about this was at [1] and
[2]. For now, add a note to the source code.

[1] https://patchwork.ozlabs.org/project/uboot/patch/
   20221022092058.106052-1-heinrich.schucha...@canonical.com/
[2] https://patchwork.ozlabs.org/project/uboot/patch/
   20230106145243.411626-12-...@chromium.org/

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/cls.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/cmd/cls.c b/cmd/cls.c
index 073ba5a6c86..1125a3f81bb 100644
--- a/cmd/cls.c
+++ b/cmd/cls.c
@@ -17,7 +17,13 @@ static int do_video_clear(struct cmd_tbl *cmdtp, int flag, 
int argc,
 {
__maybe_unused struct udevice *dev;
 
-   /*  Send clear screen and home */
+   /*
+* Send clear screen and home
+*
+* FIXME(Heinrich Schuchardt ): This should go
+* through an API and only be written to serial terminals, not video
+* displays
+*/
printf(CSI "2J" CSI "1;1H");
if (IS_ENABLED(CONFIG_VIDEO_ANSI))
return 0;
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 10/13] video: Remove duplicate cursor-positioning function

2023-03-10 Thread Simon Glass
There are two functions for positioning the cursor on the console. Remove
one of them.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/video/vidconsole-uclass.c | 44 +++
 1 file changed, 10 insertions(+), 34 deletions(-)

diff --git a/drivers/video/vidconsole-uclass.c 
b/drivers/video/vidconsole-uclass.c
index a5f2350ca1c..627db8208b0 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -126,26 +126,14 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int 
x, int y)
priv->ycur = y;
 }
 
-/**
- * set_cursor_position() - set cursor position
- *
- * @priv:  private data of the video console
- * @row:   new row
- * @col:   new column
- */
-static void set_cursor_position(struct vidconsole_priv *priv, int row, int col)
+void vidconsole_position_cursor(struct udevice *dev, uint col, uint row)
 {
-   /*
-* Ensure we stay in the bounds of the screen.
-*/
-   if (row >= priv->rows)
-   row = priv->rows - 1;
-   if (col >= priv->cols)
-   col = priv->cols - 1;
-
-   priv->ycur = row * priv->y_charsize;
-   priv->xcur_frac = priv->xstart_frac +
- VID_TO_POS(col * priv->x_charsize);
+   struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+   short x, y;
+
+   x = min_t(short, col, priv->cols - 1) * priv->x_charsize;
+   y = min_t(short, row, priv->rows - 1) * priv->y_charsize;
+   vidconsole_set_cursor_pos(dev, x, y);
 }
 
 /**
@@ -192,7 +180,7 @@ static void vidconsole_escape_char(struct udevice *dev, 
char ch)
int row = priv->row_saved;
int col = priv->col_saved;
 
-   set_cursor_position(priv, row, col);
+   vidconsole_position_cursor(dev, col, row);
priv->escape = 0;
return;
}
@@ -254,7 +242,7 @@ static void vidconsole_escape_char(struct udevice *dev, 
char ch)
if (row < 0)
row = 0;
/* Right and bottom overflows are handled in the callee. */
-   set_cursor_position(priv, row, col);
+   vidconsole_position_cursor(dev, col, row);
break;
}
case 'H':
@@ -278,7 +266,7 @@ static void vidconsole_escape_char(struct udevice *dev, 
char ch)
if (col)
--col;
 
-   set_cursor_position(priv, row, col);
+   vidconsole_position_cursor(dev, col, row);
 
break;
}
@@ -655,15 +643,3 @@ int vidconsole_memmove(struct udevice *dev, void *dst, 
const void *src,
return vidconsole_sync_copy(dev, dst, dst + size);
 }
 #endif
-
-void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned 
row)
-{
-   struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-   struct udevice *vid_dev = dev->parent;
-   struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
-   short x, y;
-
-   x = min_t(short, col * priv->x_charsize, vid_priv->xsize - 1);
-   y = min_t(short, row * priv->y_charsize, vid_priv->ysize - 1);
-   vidconsole_set_cursor_pos(dev, x, y);
-}
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 12/13] efi: Add dhrystone, dcache and scroll lines to app

2023-03-10 Thread Simon Glass
Add these options to provide some performance measurement, see cache
status and slightly speed up the appallingly slow console.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/efi-x86_app64_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/configs/efi-x86_app64_defconfig b/configs/efi-x86_app64_defconfig
index 605d49ff8cb..dae48840493 100644
--- a/configs/efi-x86_app64_defconfig
+++ b/configs/efi-x86_app64_defconfig
@@ -22,6 +22,7 @@ CONFIG_SYS_PBSIZE=532
 # CONFIG_CMD_BOOTM is not set
 CONFIG_CMD_PART=y
 # CONFIG_CMD_NET is not set
+CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_EXT2=y
 CONFIG_CMD_EXT4=y
@@ -39,7 +40,9 @@ CONFIG_BOOTFILE="bzImage"
 CONFIG_USE_ROOTPATH=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
+CONFIG_CONSOLE_SCROLL_LINES=5
 # CONFIG_REGEX is not set
+CONFIG_CMD_DHRYSTONE=y
 # CONFIG_GZIP is not set
 CONFIG_EFI=y
 CONFIG_EFI_APP_64BIT=y
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 08/13] bbinfo: Show the size of the copy framebuffer

2023-03-10 Thread Simon Glass
If the copy framebuffer is enabled, show its size.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to show the size of the copy framebuffer with bdinfo

 cmd/bdinfo.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index 8ae7fb35fe9..f709904c516 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -88,11 +88,15 @@ static void show_video_info(void)
   device_active(dev) ? "" : "in");
if (device_active(dev)) {
struct video_priv *upriv = dev_get_uclass_priv(dev);
+   struct video_uc_plat *plat = dev_get_uclass_plat(dev);
 
bdinfo_print_num_ll("FB base", (ulong)upriv->fb);
-   if (upriv->copy_fb)
+   if (upriv->copy_fb) {
bdinfo_print_num_ll("FB copy",
(ulong)upriv->copy_fb);
+   bdinfo_print_num_l(" copy size",
+  plat->copy_size);
+   }
printf("%-12s= %dx%dx%d\n", "FB size", upriv->xsize,
   upriv->ysize, 1 << upriv->bpix);
}
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 11/13] video: Clear the vidconsole rather than the video

2023-03-10 Thread Simon Glass
It is better to clear the console device rather than the video device,
since the console has the text display. We also need to reset the cursor
position with the console, but not with the video device.

Add a new function to handle this and update the 'cls' command to use it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/cls.c | 12 
 drivers/video/vidconsole-uclass.c | 12 
 include/video_console.h   |  9 +
 3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/cmd/cls.c b/cmd/cls.c
index 40a32eeab63..073ba5a6c86 100644
--- a/cmd/cls.c
+++ b/cmd/cls.c
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #define CSI "\x1b["
 
@@ -19,12 +19,16 @@ static int do_video_clear(struct cmd_tbl *cmdtp, int flag, 
int argc,
 
/*  Send clear screen and home */
printf(CSI "2J" CSI "1;1H");
-   if (IS_ENABLED(CONFIG_VIDEO) && !IS_ENABLED(CONFIG_VIDEO_ANSI)) {
-   if (uclass_first_device_err(UCLASS_VIDEO, ))
+   if (IS_ENABLED(CONFIG_VIDEO_ANSI))
+   return 0;
+
+   if (IS_ENABLED(CONFIG_VIDEO)) {
+   if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, ))
return CMD_RET_FAILURE;
-   if (video_clear(dev))
+   if (vidconsole_clear_and_reset(dev))
return CMD_RET_FAILURE;
}
+
return CMD_RET_SUCCESS;
 }
 
diff --git a/drivers/video/vidconsole-uclass.c 
b/drivers/video/vidconsole-uclass.c
index 627db8208b0..61f4216750f 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -643,3 +643,15 @@ int vidconsole_memmove(struct udevice *dev, void *dst, 
const void *src,
return vidconsole_sync_copy(dev, dst, dst + size);
 }
 #endif
+
+int vidconsole_clear_and_reset(struct udevice *dev)
+{
+   int ret;
+
+   ret = video_clear(dev_get_parent(dev));
+   if (ret)
+   return ret;
+   vidconsole_position_cursor(dev, 0, 0);
+
+   return 0;
+}
diff --git a/include/video_console.h b/include/video_console.h
index 770103284b7..3db9a7e1fb9 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -285,6 +285,15 @@ int vidconsole_put_string(struct udevice *dev, const char 
*str);
 void vidconsole_position_cursor(struct udevice *dev, unsigned col,
unsigned row);
 
+/**
+ * vidconsole_clear_and_reset() - Clear the console and reset the cursor
+ *
+ * The cursor is placed at the start of the console
+ *
+ * @dev:   vidconsole device to adjust
+ */
+int vidconsole_clear_and_reset(struct udevice *dev);
+
 /**
  * vidconsole_set_cursor_pos() - set cursor position
  *
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 09/13] efi: Adjust script to show pre-relocation output on terminal

2023-03-10 Thread Simon Glass
When running with video enabled, the pre-relocation output of U-Boot is
currently lost. Add a -serial flag to show it on the terminal.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 scripts/build-efi.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/build-efi.sh b/scripts/build-efi.sh
index bc9aeebbf4f..46c28807ef1 100755
--- a/scripts/build-efi.sh
+++ b/scripts/build-efi.sh
@@ -96,6 +96,8 @@ run_qemu() {
fi
if [[ -n "${serial}" ]]; then
extra="-display none -serial mon:stdio"
+   else
+   extra="-serial mon:stdio"
fi
echo "Running ${qemu}"
# Use 512MB since U-Boot EFI likes to have 256MB to play with
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 07/13] video: Allow a copy framebuffer with pre-allocated fb

2023-03-10 Thread Simon Glass
At present it is not possible for the video driver to use a pre-allocated
frame buffer (such as is done with EFI) with the copy framebuffer. This
can be useful to speed up the display.

Adjust the implementation so that copy_size can be set to the required
size, with this being allocated if the normal framebuffer size is 0.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/video/video-uclass.c | 32 
 include/video.h  |  2 ++
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index ab482f11e5d..da89f431441 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -78,24 +78,40 @@ void video_set_flush_dcache(struct udevice *dev, bool flush)
priv->flush_dcache = flush;
 }
 
+static ulong alloc_fb_(ulong align, ulong size, ulong *addrp)
+{
+   ulong base;
+
+   align = align ? align : 1 << 20;
+   base = *addrp - size;
+   base &= ~(align - 1);
+   size = *addrp - base;
+   *addrp = base;
+
+   return size;
+}
+
 static ulong alloc_fb(struct udevice *dev, ulong *addrp)
 {
struct video_uc_plat *plat = dev_get_uclass_plat(dev);
-   ulong base, align, size;
+   ulong size;
+
+   if (!plat->size) {
+   if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_size) {
+   size = alloc_fb_(plat->align, plat->copy_size, addrp);
+   plat->copy_base = *addrp;
+   return size;
+   }
 
-   if (!plat->size)
return 0;
+   }
 
/* Allow drivers to allocate the frame buffer themselves */
if (plat->base)
return 0;
 
-   align = plat->align ? plat->align : 1 << 20;
-   base = *addrp - plat->size;
-   base &= ~(align - 1);
-   plat->base = base;
-   size = *addrp - base;
-   *addrp = base;
+   size = alloc_fb_(plat->align, plat->size, addrp);
+   plat->base = *addrp;
 
return size;
 }
diff --git a/include/video.h b/include/video.h
index 3f67a93bc93..4d99e5dc27f 100644
--- a/include/video.h
+++ b/include/video.h
@@ -24,6 +24,7 @@ struct udevice;
  * @base: Base address of frame buffer, 0 if not yet known
  * @copy_base: Base address of a hardware copy of the frame buffer. See
  * CONFIG_VIDEO_COPY.
+ * @copy_size: Size of copy framebuffer, used if @size is 0
  * @hide_logo: Hide the logo (used for testing)
  */
 struct video_uc_plat {
@@ -31,6 +32,7 @@ struct video_uc_plat {
uint size;
ulong base;
ulong copy_base;
+   ulong copy_size;
bool hide_logo;
 };
 
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 06/13] efi: Support copy framebuffer

2023-03-10 Thread Simon Glass
Add support for this to EFI in case it becomes useful. At present it just
slows things down. You can enable CONFIG_VIDEO_COPY to turn it on.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add a comment about the fallback

Changes in v2:
- Obtain copy framebuffer size from EFI instead of using a fixed value
- Dropping debugging printf()
- Use new bootph-xxx tag

 arch/x86/dts/efi-x86_app.dts |  1 +
 drivers/video/efi.c  | 26 +-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/arch/x86/dts/efi-x86_app.dts b/arch/x86/dts/efi-x86_app.dts
index 6d843a9820b..59e2e402d5e 100644
--- a/arch/x86/dts/efi-x86_app.dts
+++ b/arch/x86/dts/efi-x86_app.dts
@@ -27,6 +27,7 @@
};
efi-fb {
compatible = "efi-fb";
+   bootph-some-ram;
};
 
 };
diff --git a/drivers/video/efi.c b/drivers/video/efi.c
index 169637c2882..28ac15ff61b 100644
--- a/drivers/video/efi.c
+++ b/drivers/video/efi.c
@@ -129,7 +129,6 @@ static int save_vesa_mode(struct vesa_mode_info *vesa, u64 
*fbp)
struct efi_gop_mode_info *info;
int ret;
 
-   printf("start\n");
if (IS_ENABLED(CONFIG_EFI_APP))
ret = get_mode_info(vesa, fbp, );
else
@@ -207,6 +206,30 @@ err:
return ret;
 }
 
+static int efi_video_bind(struct udevice *dev)
+{
+   if (IS_ENABLED(CONFIG_VIDEO_COPY)) {
+   struct video_uc_plat *plat = dev_get_uclass_plat(dev);
+   struct vesa_mode_info vesa;
+   int ret;
+   u64 fb;
+
+   /*
+* Initialise vesa_mode_info structure so we can figure out the
+* required framebuffer size. If something goes wrong, just do
+* without a copy framebuffer
+*/
+   ret = save_vesa_mode(, );
+   if (!ret) {
+   /* this is not reached if the EFI call failed */
+   plat->copy_size = vesa.bytes_per_scanline *
+   vesa.y_resolution;
+   }
+   }
+
+   return 0;
+}
+
 static const struct udevice_id efi_video_ids[] = {
{ .compatible = "efi-fb" },
{ }
@@ -216,5 +239,6 @@ U_BOOT_DRIVER(efi_video) = {
.name   = "efi_video",
.id = UCLASS_VIDEO,
.of_match = efi_video_ids,
+   .bind   = efi_video_bind,
.probe  = efi_video_probe,
 };
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 05/13] efi: Use a fixed value for the timer clock

2023-03-10 Thread Simon Glass
It is not yet clear how to read the timer via EFI. The current value seems
much too high on a Framework laptop I tried. Adjust it to a lower
hard-coded value for now.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add a comment about the value

 drivers/timer/tsc_timer.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/timer/tsc_timer.c b/drivers/timer/tsc_timer.c
index 192c7b71a5a..f86a0b86921 100644
--- a/drivers/timer/tsc_timer.c
+++ b/drivers/timer/tsc_timer.c
@@ -404,6 +404,15 @@ static void tsc_timer_ensure_setup(bool early)
if (!gd->arch.clock_rate) {
unsigned long fast_calibrate;
 
+   /**
+* There is no obvious way to obtain this information from EFI
+* boot services. This value was measured on a Framework Laptop
+* which has a 12th Gen Intel Core
+*/
+   if (IS_ENABLED(CONFIG_EFI_APP)) {
+   fast_calibrate = 2750;
+   goto done;
+   }
fast_calibrate = native_calibrate_tsc();
if (fast_calibrate)
goto done;
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 04/13] x86: Add a few more items to bdinfo

2023-03-10 Thread Simon Glass
Add the timer and vendor/model information.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Show the CPU vendor name also

 arch/x86/lib/bdinfo.c | 6 ++
 cmd/bdinfo.c  | 5 +
 include/init.h| 3 +++
 3 files changed, 14 insertions(+)

diff --git a/arch/x86/lib/bdinfo.c b/arch/x86/lib/bdinfo.c
index 0cb79b01bd3..15390070fe8 100644
--- a/arch/x86/lib/bdinfo.c
+++ b/arch/x86/lib/bdinfo.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -16,6 +17,11 @@ DECLARE_GLOBAL_DATA_PTR;
 void arch_print_bdinfo(void)
 {
bdinfo_print_num_l("prev table", gd->arch.table);
+   bdinfo_print_num_l("clock_rate", gd->arch.clock_rate);
+   bdinfo_print_num_l("tsc_base", gd->arch.tsc_base);
+   bdinfo_print_num_l("vendor", gd->arch.x86_vendor);
+   bdinfo_print_str(" name", cpu_vendor_name(gd->arch.x86_vendor));
+   bdinfo_print_num_l("model", gd->arch.x86_model);
 
if (IS_ENABLED(CONFIG_EFI_STUB))
efi_show_bdinfo();
diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index bf002f84475..8ae7fb35fe9 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -26,6 +26,11 @@ void bdinfo_print_size(const char *name, uint64_t size)
print_size(size, "\n");
 }
 
+void bdinfo_print_str(const char *name, const char *str)
+{
+   printf("%-12s= %s\n", name, str);
+}
+
 void bdinfo_print_num_l(const char *name, ulong value)
 {
printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
diff --git a/include/init.h b/include/init.h
index 699dc2482c0..88730816851 100644
--- a/include/init.h
+++ b/include/init.h
@@ -353,6 +353,9 @@ void relocate_code(ulong start_addr_sp, struct global_data 
*new_gd,
 void bdinfo_print_num_l(const char *name, ulong value);
 void bdinfo_print_num_ll(const char *name, unsigned long long value);
 
+/* Print a string value (for use in arch_print_bdinfo()) */
+void bdinfo_print_str(const char *name, const char *str);
+
 /* Print a clock speed in MHz */
 void bdinfo_print_mhz(const char *name, unsigned long hz);
 
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 03/13] efi: Support a 64-bit frame buffer address

2023-03-10 Thread Simon Glass
The current vesa structure only provides a 32-bit value for the frame
buffer. Many modern machines use an address outside the range.

It is still useful to have this common struct, but add a separate
frame-buffer address as well.

Add a comment for vesa_setup_video_priv() while we are here.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Use Returns instead of @return

 arch/x86/lib/fsp/fsp_graphics.c |  2 +-
 drivers/pci/pci_rom.c   | 10 ++
 drivers/video/coreboot.c|  2 +-
 drivers/video/efi.c | 34 +
 include/vesa.h  | 16 +++-
 5 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/arch/x86/lib/fsp/fsp_graphics.c b/arch/x86/lib/fsp/fsp_graphics.c
index b07c666caf7..2bcc49f6051 100644
--- a/arch/x86/lib/fsp/fsp_graphics.c
+++ b/arch/x86/lib/fsp/fsp_graphics.c
@@ -106,7 +106,7 @@ static int fsp_video_probe(struct udevice *dev)
vesa->phys_base_ptr = dm_pci_read_bar32(dev, 2);
gd->fb_base = vesa->phys_base_ptr;
 
-   ret = vesa_setup_video_priv(vesa, uc_priv, plat);
+   ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat);
if (ret)
goto err;
 
diff --git a/drivers/pci/pci_rom.c b/drivers/pci/pci_rom.c
index 47b6e6e5bcf..f0dfe631490 100644
--- a/drivers/pci/pci_rom.c
+++ b/drivers/pci/pci_rom.c
@@ -325,7 +325,7 @@ err:
return ret;
 }
 
-int vesa_setup_video_priv(struct vesa_mode_info *vesa,
+int vesa_setup_video_priv(struct vesa_mode_info *vesa, u64 fb,
  struct video_priv *uc_priv,
  struct video_uc_plat *plat)
 {
@@ -348,9 +348,9 @@ int vesa_setup_video_priv(struct vesa_mode_info *vesa,
 
/* Use double buffering if enabled */
if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->base)
-   plat->copy_base = vesa->phys_base_ptr;
+   plat->copy_base = fb;
else
-   plat->base = vesa->phys_base_ptr;
+   plat->base = fb;
log_debug("base = %lx, copy_base = %lx\n", plat->base, plat->copy_base);
plat->size = vesa->bytes_per_scanline * vesa->y_resolution;
 
@@ -377,7 +377,9 @@ int vesa_setup_video(struct udevice *dev, int 
(*int15_handler)(void))
return ret;
}
 
-   ret = vesa_setup_video_priv(_info.vesa, uc_priv, plat);
+   ret = vesa_setup_video_priv(_info.vesa,
+   mode_info.vesa.phys_base_ptr, uc_priv,
+   plat);
if (ret) {
if (ret == -ENFILE) {
/*
diff --git a/drivers/video/coreboot.c b/drivers/video/coreboot.c
index d2d87c75c89..c586475e41e 100644
--- a/drivers/video/coreboot.c
+++ b/drivers/video/coreboot.c
@@ -57,7 +57,7 @@ static int coreboot_video_probe(struct udevice *dev)
goto err;
}
 
-   ret = vesa_setup_video_priv(vesa, uc_priv, plat);
+   ret = vesa_setup_video_priv(vesa, vesa->phys_base_ptr, uc_priv, plat);
if (ret) {
ret = log_msg_ret("setup", ret);
goto err;
diff --git a/drivers/video/efi.c b/drivers/video/efi.c
index 0479f207032..169637c2882 100644
--- a/drivers/video/efi.c
+++ b/drivers/video/efi.c
@@ -5,6 +5,8 @@
  * EFI framebuffer driver based on GOP
  */
 
+#define LOG_CATEGORY LOGC_EFI
+
 #include 
 #include 
 #include 
@@ -56,11 +58,12 @@ static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
  * Gets info from the graphics-output protocol
  *
  * @vesa: Place to put the mode information
+ * @fbp: Returns the address of the frame buffer
  * @infop: Returns a pointer to the mode info
  * Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
  * the protocol is not supported by EFI
  */
-static int get_mode_info(struct vesa_mode_info *vesa,
+static int get_mode_info(struct vesa_mode_info *vesa, u64 *fbp,
 struct efi_gop_mode_info **infop)
 {
efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
@@ -74,9 +77,13 @@ static int get_mode_info(struct vesa_mode_info *vesa,
ret = boot->locate_protocol(_gop_guid, NULL, (void **));
if (ret)
return log_msg_ret("prot", -ENOTSUPP);
-
mode = gop->mode;
+   log_debug("maxmode %u, mode %u, info %p, size %lx, fb %lx, fb_size 
%lx\n",
+ mode->max_mode, mode->mode, mode->info, mode->info_size,
+ (ulong)mode->fb_base, (ulong)mode->fb_size);
+
vesa->phys_base_ptr = mode->fb_base;
+   *fbp = mode->fb_base;
vesa->x_resolution = mode->info->width;
vesa->y_resolution = mode->info->height;
*infop = mode->info;
@@ -91,10 +98,11 @@ static int get_mode_info(struct vesa_mode_info *vesa,
  * it into a vesa structure. It also returns the mode information.
  *
  * @vesa: Place to put the mode information
+ * @fbp: Returns the address of the frame buffer
  * @infop: Returns a pointer to 

[PATCH v3 02/13] efi: video: Return mode info for app also

2023-03-10 Thread Simon Glass
The mode info is currently not initialised for the app. Fix this by
returning it from the function.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/video/efi.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/video/efi.c b/drivers/video/efi.c
index fc37a68b376..0479f207032 100644
--- a/drivers/video/efi.c
+++ b/drivers/video/efi.c
@@ -56,10 +56,12 @@ static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
  * Gets info from the graphics-output protocol
  *
  * @vesa: Place to put the mode information
+ * @infop: Returns a pointer to the mode info
  * Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
  * the protocol is not supported by EFI
  */
-static int get_mode_info(struct vesa_mode_info *vesa)
+static int get_mode_info(struct vesa_mode_info *vesa,
+struct efi_gop_mode_info **infop)
 {
efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
struct efi_boot_services *boot = efi_get_boot();
@@ -77,6 +79,7 @@ static int get_mode_info(struct vesa_mode_info *vesa)
vesa->phys_base_ptr = mode->fb_base;
vesa->x_resolution = mode->info->width;
vesa->y_resolution = mode->info->height;
+   *infop = mode->info;
 
return 0;
 }
@@ -118,7 +121,7 @@ static int save_vesa_mode(struct vesa_mode_info *vesa)
int ret;
 
if (IS_ENABLED(CONFIG_EFI_APP))
-   ret = get_mode_info(vesa);
+   ret = get_mode_info(vesa, );
else
ret = get_mode_from_entry(vesa, );
if (ret) {
-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v3 01/13] efi: video: Move payload code into a function

2023-03-10 Thread Simon Glass
Put this into a function, as we have done for the app implementation.
Comment both functions. FOr now the app still does not access it
correctly.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/video/efi.c | 83 +++--
 1 file changed, 57 insertions(+), 26 deletions(-)

diff --git a/drivers/video/efi.c b/drivers/video/efi.c
index b11e42c0ebf..fc37a68b376 100644
--- a/drivers/video/efi.c
+++ b/drivers/video/efi.c
@@ -50,6 +50,15 @@ static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
*size = len;
 }
 
+/**
+ * get_mode_info() - Ask EFI for the mode information
+ *
+ * Gets info from the graphics-output protocol
+ *
+ * @vesa: Place to put the mode information
+ * Returns: 0 if OK, -ENOSYS if boot services are not available, -ENOTSUPP if
+ * the protocol is not supported by EFI
+ */
 static int get_mode_info(struct vesa_mode_info *vesa)
 {
efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
@@ -72,32 +81,54 @@ static int get_mode_info(struct vesa_mode_info *vesa)
return 0;
 }
 
+/**
+ * get_mode_from_entry() - Obtain fb info from the EFIET_GOP_MODE payload entry
+ *
+ * This gets the mode information provided by the stub to the payload and puts
+ * it into a vesa structure. It also returns the mode information.
+ *
+ * @vesa: Place to put the mode information
+ * @infop: Returns a pointer to the mode info
+ * Returns: 0 if OK, -ve on error
+ */
+static int get_mode_from_entry(struct vesa_mode_info *vesa,
+  struct efi_gop_mode_info **infop)
+{
+   struct efi_gop_mode *mode;
+   int size;
+   int ret;
+
+   ret = efi_info_get(EFIET_GOP_MODE, (void **), );
+   if (ret) {
+   printf("EFI graphics output entry not found\n");
+   return ret;
+   }
+   vesa->phys_base_ptr = mode->fb_base;
+   vesa->x_resolution = mode->info->width;
+   vesa->y_resolution = mode->info->height;
+   *infop = mode->info;
+
+   return 0;
+}
+
 static int save_vesa_mode(struct vesa_mode_info *vesa)
 {
-   struct efi_entry_gopmode *mode;
const struct efi_framebuffer *fbinfo;
-   int size;
+   struct efi_gop_mode_info *info;
int ret;
 
-   if (IS_ENABLED(CONFIG_EFI_APP)) {
+   if (IS_ENABLED(CONFIG_EFI_APP))
ret = get_mode_info(vesa);
-   if (ret) {
-   printf("EFI graphics output protocol not found\n");
-   return -ENXIO;
-   }
-   } else {
-   ret = efi_info_get(EFIET_GOP_MODE, (void **), );
-   if (ret == -ENOENT) {
-   printf("EFI graphics output protocol mode not found\n");
-   return -ENXIO;
-   }
-   vesa->phys_base_ptr = mode->fb_base;
-   vesa->x_resolution = mode->info->width;
-   vesa->y_resolution = mode->info->height;
+   else
+   ret = get_mode_from_entry(vesa, );
+   if (ret) {
+   printf("EFI graphics output protocol not found (err=%dE)\n",
+  ret);
+   return ret;
}
 
-   if (mode->info->pixel_format < EFI_GOT_BITMASK) {
-   fbinfo = _framebuffer_format_map[mode->info->pixel_format];
+   if (info->pixel_format < EFI_GOT_BITMASK) {
+   fbinfo = _framebuffer_format_map[info->pixel_format];
vesa->red_mask_size = fbinfo->red.size;
vesa->red_mask_pos = fbinfo->red.pos;
vesa->green_mask_size = fbinfo->green.size;
@@ -108,29 +139,29 @@ static int save_vesa_mode(struct vesa_mode_info *vesa)
vesa->reserved_mask_pos = fbinfo->rsvd.pos;
 
vesa->bits_per_pixel = 32;
-   vesa->bytes_per_scanline = mode->info->pixels_per_scanline * 4;
-   } else if (mode->info->pixel_format == EFI_GOT_BITMASK) {
-   efi_find_pixel_bits(mode->info->pixel_bitmask[0],
+   vesa->bytes_per_scanline = info->pixels_per_scanline * 4;
+   } else if (info->pixel_format == EFI_GOT_BITMASK) {
+   efi_find_pixel_bits(info->pixel_bitmask[0],
>red_mask_pos,
>red_mask_size);
-   efi_find_pixel_bits(mode->info->pixel_bitmask[1],
+   efi_find_pixel_bits(info->pixel_bitmask[1],
>green_mask_pos,
>green_mask_size);
-   efi_find_pixel_bits(mode->info->pixel_bitmask[2],
+   efi_find_pixel_bits(info->pixel_bitmask[2],
>blue_mask_pos,
>blue_mask_size);
-   efi_find_pixel_bits(mode->info->pixel_bitmask[3],
+   efi_find_pixel_bits(info->pixel_bitmask[3],
>reserved_mask_pos,
   

[PATCH v3 00/13] video: efi: Improve the EFI-app video console

2023-03-10 Thread Simon Glass
This does not work on some 64-bit machines since only a 32-bit address for
the framebuffer is supported in the VESA structure.

This series corrects this and makes a few other minor, video-related
improvements.

Changes in v3:
- Use Returns instead of @return
- Show the CPU vendor name also
- Add a comment about the value
- Add a comment about the fallback

Changes in v2:
- Obtain copy framebuffer size from EFI instead of using a fixed value
- Dropping debugging printf()
- Use new bootph-xxx tag
- Add new patch to show the size of the copy framebuffer with bdinfo

Simon Glass (13):
  efi: video: Move payload code into a function
  efi: video: Return mode info for app also
  efi: Support a 64-bit frame buffer address
  x86: Add a few more items to bdinfo
  efi: Use a fixed value for the timer clock
  efi: Support copy framebuffer
  video: Allow a copy framebuffer with pre-allocated fb
  bbinfo: Show the size of the copy framebuffer
  efi: Adjust script to show pre-relocation output on terminal
  video: Remove duplicate cursor-positioning function
  video: Clear the vidconsole rather than the video
  efi: Add dhrystone, dcache and scroll lines to app
  video: Add a note about the broken implementation

 arch/x86/dts/efi-x86_app.dts  |   1 +
 arch/x86/lib/bdinfo.c |   6 ++
 arch/x86/lib/fsp/fsp_graphics.c   |   2 +-
 cmd/bdinfo.c  |  11 ++-
 cmd/cls.c |  20 +++--
 configs/efi-x86_app64_defconfig   |   3 +
 drivers/pci/pci_rom.c |  10 ++-
 drivers/timer/tsc_timer.c |   9 ++
 drivers/video/coreboot.c  |   2 +-
 drivers/video/efi.c   | 138 ++
 drivers/video/vidconsole-uclass.c |  48 ---
 drivers/video/video-uclass.c  |  32 +--
 include/init.h|   3 +
 include/vesa.h|  16 +++-
 include/video.h   |   2 +
 include/video_console.h   |   9 ++
 scripts/build-efi.sh  |   2 +
 17 files changed, 228 insertions(+), 86 deletions(-)

-- 
2.40.0.rc1.284.g88254d51c5-goog



[PATCH v2 2/3] drivers: pci: sandbox: Add stub sandbox PCI MPS support

2023-03-10 Thread stcarlso
From: Stephen Carlson 

Reports the sandbox swapcase PCI Express device to support a 256 byte
Maximum Payload Size for MPS tuning tests.

Signed-off-by: Stephen Carlson 
---
 drivers/misc/swap_case.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c
index 7093ad1cd4..ee5c12bd0a 100644
--- a/drivers/misc/swap_case.c
+++ b/drivers/misc/swap_case.c
@@ -165,6 +165,9 @@ static int sandbox_swap_case_read_config(const struct 
udevice *emul,
case PCI_CAP_ID_EXP_OFFSET + PCI_CAP_LIST_NEXT:
*valuep = PCI_CAP_ID_MSIX_OFFSET;
break;
+   case PCI_CAP_ID_EXP_OFFSET + PCI_EXP_DEVCAP:
+   *valuep = PCI_EXP_DEVCAP_PAYLOAD_256B;
+   break;
case PCI_CAP_ID_MSIX_OFFSET:
if (sandbox_swap_case_use_ea(emul))
*valuep = (PCI_CAP_ID_EA_OFFSET << 8) | PCI_CAP_ID_MSIX;
-- 
2.25.1



[PATCH v2 1/3] cmd: pci: Add command to set MPS of all PCIe devices

2023-03-10 Thread stcarlso
From: Stephen Carlson 

Enable tuning of the PCI Express MPS (Maximum Payload Size) of
each device. The Maximum Read Request Size is not altered.

The SAFE method uses the largest MPS value supported by all devices in the
system for each device. This method is the same algorithm as used by Linux
pci=pcie_bus_safe.

The PEER2PEER method sets all devices to the minimal (128 byte) MPS, which
allows hot plug of devices later that might only support the minimum size,
and ensures compatibility of DMA between two devices on the bus.

Signed-off-by: Stephen Carlson 
---
 cmd/Kconfig   |  10 +++
 cmd/Makefile  |   1 +
 cmd/pci_mps.c | 164 ++
 include/pci.h |   7 +++
 4 files changed, 182 insertions(+)
 create mode 100644 cmd/pci_mps.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index dc0446e02e..632c5c45db 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1390,6 +1390,16 @@ config CMD_PCI
  peripherals. Sub-commands allow bus enumeration, displaying and
  changing configuration space and a few other features.
 
+config CMD_PCI_MPS
+   bool "pci_mps - Configure PCI device MPS"
+   depends on PCI
+   help
+ Enables PCI Express Maximum Packet Size (MPS) tuning. This
+ command configures the PCI Express MPS of each endpoint to the
+ largest value supported by all devices below the root complex.
+ The Maximum Read Request Size will not be altered. This method is
+ the same algorithm as used by Linux pci=pcie_bus_safe.
+
 config CMD_PINMUX
bool "pinmux - show pins muxing"
depends on PINCTRL
diff --git a/cmd/Makefile b/cmd/Makefile
index 7b6ff73186..3365634843 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -133,6 +133,7 @@ obj-$(CONFIG_CMD_PART) += part.o
 obj-$(CONFIG_CMD_PCAP) += pcap.o
 ifdef CONFIG_PCI
 obj-$(CONFIG_CMD_PCI) += pci.o
+obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o
 endif
 obj-$(CONFIG_CMD_PINMUX) += pinmux.o
 obj-$(CONFIG_CMD_PMC) += pmc.o
diff --git a/cmd/pci_mps.c b/cmd/pci_mps.c
new file mode 100644
index 00..555a5fdd8e
--- /dev/null
+++ b/cmd/pci_mps.c
@@ -0,0 +1,164 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2022 Microsoft Corporation 
+ * Stephen Carlson 
+ *
+ * PCI Express Maximum Packet Size (MPS) configuration
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PCI_MPS_SAFE 0
+#define PCI_MPS_PEER2PEER 1
+
+static int pci_mps_find_safe(struct udevice *bus, unsigned int *min_mps,
+unsigned int *n)
+{
+   struct udevice *dev;
+   int res = 0, addr;
+   unsigned int mpss;
+   u32 regval;
+
+   if (!min_mps || !n)
+   return -EINVAL;
+
+   for (device_find_first_child(bus, );
+dev;
+device_find_next_child()) {
+   addr = dm_pci_find_capability(dev, PCI_CAP_ID_EXP);
+   if (addr <= 0)
+   continue;
+
+   res = dm_pci_read_config32(dev, addr + PCI_EXP_DEVCAP,
+  );
+   if (res != 0)
+   return res;
+   mpss = (unsigned int)(regval & PCI_EXP_DEVCAP_PAYLOAD);
+   *n += 1;
+   if (mpss < *min_mps)
+   *min_mps = mpss;
+   }
+
+   return res;
+}
+
+static int pci_mps_set_bus(struct udevice *bus, unsigned int target)
+{
+   struct udevice *dev;
+   u32 mpss, target_mps = (u32)(target << 5);
+   u16 mps;
+   int res = 0, addr;
+
+   for (device_find_first_child(bus, );
+dev && res == 0;
+device_find_next_child()) {
+   addr = dm_pci_find_capability(dev, PCI_CAP_ID_EXP);
+   if (addr <= 0)
+   continue;
+
+   res = dm_pci_read_config32(dev, addr + PCI_EXP_DEVCAP,
+  );
+   if (res != 0)
+   return res;
+
+   /* Do not set device above its maximum MPSS */
+   mpss = (mpss & PCI_EXP_DEVCAP_PAYLOAD) << 5;
+   if (target_mps < mpss)
+   mps = (u16)target_mps;
+   else
+   mps = (u16)mpss;
+   res = dm_pci_clrset_config16(dev, addr + PCI_EXP_DEVCTL,
+PCI_EXP_DEVCTL_PAYLOAD, mps);
+   }
+
+   return res;
+}
+
+/*
+ * Sets the MPS of each PCI Express device to the specified policy.
+ */
+static int pci_mps_set(int policy)
+{
+   struct udevice *bus;
+   int i, res = 0;
+   /* 0 = 128B, min value for hotplug */
+   unsigned int mps = 0;
+
+   if (policy == PCI_MPS_SAFE) {
+   unsigned int min_mps = PCI_EXP_DEVCAP_PAYLOAD_4096B, n = 0;
+
+   /* Find maximum MPS supported by all devices */
+   for (i = 0;
+

[PATCH v2 3/3] test: Add test for new command pci_mps

2023-03-10 Thread stcarlso
From: Stephen Carlson 

Adds a test for the new pci_mps command to ensure that it can set the
Maximum Payload Size (MPS) of all devices to 256 bytes in the sandbox
environment. Enables the pci_mps command in the sandbox environment so
that this test can be run.

Signed-off-by: Stephen Carlson 
---
 MAINTAINERS   |  6 ++
 configs/sandbox_defconfig |  1 +
 include/test/suites.h |  2 ++
 test/cmd/Makefile |  3 +++
 test/cmd/pci_mps.c| 42 +++
 test/cmd_ut.c |  6 ++
 6 files changed, 60 insertions(+)
 create mode 100644 test/cmd/pci_mps.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 3e8e193ecc..c432b0d83b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1242,6 +1242,12 @@ M:   Heiko Schocher 
 S: Maintained
 F: drivers/pci/pci_mpc85xx.c
 
+PCI MPS
+M: Stephen Carlson 
+S: Maintained
+F: cmd/pci_mps.c
+F: test/cmd/pci_mps.c
+
 POWER
 M: Jaehoon Chung 
 S: Maintained
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 34c342b6f5..cd6bb8e2c4 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -77,6 +77,7 @@ CONFIG_CMD_MMC=y
 CONFIG_CMD_MUX=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
+CONFIG_CMD_PCI_MPS=y
 CONFIG_CMD_READ=y
 CONFIG_CMD_REMOTEPROC=y
 CONFIG_CMD_SPI=y
diff --git a/include/test/suites.h b/include/test/suites.h
index 9ce49cbb03..f69adfeba4 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -48,6 +48,8 @@ int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[]);
 int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[]);
+int do_ut_pci_mps(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[]);
 int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[]);
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index 09e410ec30..1bbff6899c 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -14,6 +14,9 @@ obj-$(CONFIG_CMD_FDT) += fdt.o
 obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
 obj-$(CONFIG_CMD_LOADM) += loadm.o
 obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
+ifdef CONFIG_CMD_PCI
+obj-$(CONFIG_CMD_PCI_MPS) += pci_mps.o
+endif
 obj-$(CONFIG_CMD_PINMUX) += pinmux.o
 obj-$(CONFIG_CMD_PWM) += pwm.o
 ifdef CONFIG_SANDBOX
diff --git a/test/cmd/pci_mps.c b/test/cmd/pci_mps.c
new file mode 100644
index 00..fd96f4fba6
--- /dev/null
+++ b/test/cmd/pci_mps.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests that the PCI Maximum Payload Size (MPS) command can set the sandbox
+ * PCI Express device to safe mode and determine the correct payload size.
+ *
+ * Copyright 2023 Microsoft
+ * Written by Stephen Carlson 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#define PCI_MPS_TEST(_name, _flags) UNIT_TEST(_name, _flags, pci_mps_test)
+
+/* Test "pci_mps" command in safe "s" mode */
+static int test_pci_mps_safe(struct unit_test_state *uts)
+{
+   /* Enumerate PCI Express first */
+   ut_assertok(run_command("pci e", 0));
+   ut_assert_console_end();
+
+   /* Test pci_mps s */
+   ut_assertok(run_command("pci_mps s", 0));
+   ut_assert_nextline("Setting MPS of all devices to 256B");
+   ut_assert_console_end();
+
+   return 0;
+}
+
+PCI_MPS_TEST(test_pci_mps_safe, UT_TESTF_CONSOLE_REC);
+
+int do_ut_pci_mps(struct cmd_tbl *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+   struct unit_test *tests = UNIT_TEST_SUITE_START(pci_mps_test);
+   const int n = UNIT_TEST_SUITE_COUNT(pci_mps_test);
+
+   return cmd_ut_category("cmd_pci_mps", "pci_mps_test_", tests, n,
+  argc, argv);
+}
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 1713d0d1c8..6be07c6040 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -110,6 +110,9 @@ static struct cmd_tbl cmd_ut_sub[] = {
 #ifdef CONFIG_CMD_LOADM
U_BOOT_CMD_MKENT(loadm, CONFIG_SYS_MAXARGS, 1, do_ut_loadm, "", ""),
 #endif
+#ifdef CONFIG_CMD_PCI_MPS
+   U_BOOT_CMD_MKENT(pci_mps, CONFIG_SYS_MAXARGS, 1, do_ut_pci_mps, "", ""),
+#endif
 };
 
 static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -206,6 +209,9 @@ static char ut_help_text[] =
 #endif
 #ifdef CONFIG_UT_OVERLAY
"\noverlay - device tree overlays"
+#endif
+#ifdef CONFIG_CMD_PCI_MPS
+   "\npci_mps - PCI Express Maximum Payload Size"
 #endif
"\nprint  - printing things to the console"
"\nsetexpr - setexpr command"
-- 
2.25.1



Re: [RFC/PATCH] lib/Kconfig: Enable OF_LIBFDT_OVERLAY by default when FIT is enabled

2023-03-10 Thread Tom Rini
On Sun, Jan 29, 2023 at 06:30:22PM +0200, Laurent Pinchart wrote:

> FIT image support is commonly used to bundle a kernel image, a device
> tree, and device tree overlays. Applying overlays requires the
> OF_LIBFDT_OVERLAY config option to be set, which lots of boards fail to
> select, most likely because developers never noticed. This leads to an
> error when trying to apply overlays:
> 
> "config with overlays but CONFIG_OF_LIBFDT_OVERLAY not set"
> 
> TI ARM boards select the option by default. Extend this to all systems
> that select the FIT option. This only affects the default, overlay
> support can still be disabled manually in the configuration.
> 
> Signed-off-by: Laurent Pinchart 
> Reviewed-by: Marek Vasut 
> Reviewed-by: Simon Glass 
> ---
> I'm posting this as an RFC to get feedback. If the idea is generally
> appreciated, I'll update the defconfig files accordingly.

Alright, so, I put this through a world build, and most platforms grow
by 4-5kB. I think that means what I'd really like to see as a starting
point is more SoCs doing an "imply OF_LIBFDT_OVERLAY if OF_LIBFDT && FIT"
or adding to the default y list below, or similar.  If that brings us to
the point where a good number of ARM boards with FIT are enabling it, we
can default y if ARM, for example.  But right now it's more like several
hundred boards growing in size, which is uncomfortable, given the size
it's growing by.

-- 
Tom


signature.asc
Description: PGP signature


Re: [GIT PULL] Please pull u-boot-mmc master

2023-03-10 Thread Tom Rini
On Fri, Mar 10, 2023 at 05:28:40PM +0100, Marek Vasut wrote:
> On 3/10/23 16:44, Tom Rini wrote:
> > On Fri, Mar 10, 2023 at 01:22:15PM +0900, Jaehoon Chung wrote:
> > > Dear Tom,
> > > 
> > > 
> > > Please pull u-boot-mmc master into u-boot master branch.
> > > If there is any problem, let me know, plz.
> > 
> > At this point in the cycle I have to ask, are these all fixes of
> > specific issues? If not, I'd rather take this to -next. Thanks!
> 
> The stuff from me can easily go into next.

And on that note, I have bad news.  This commit:
Author: Marek Vasut 
Date:   Thu Jan 5 15:28:31 2023 +0100

spl: mmc: Pass eMMC HW partition 7 through

leads to my pine64_plus board hanging in SPL with:
U-Boot SPL 2023.04-rc3-00084-g85f29eb025cb (Mar 10 2023 - 13:05:36 -0500)
DRAM: 1024 MiB
Trying to boot from MMC1

When trying to boot from SD card. If you don't have something there that
you can get to fail, let me know and I'll get you access to my lab.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH RFC u-boot-mvebu 0/2] arm: mvebu: Fix eMMC boot

2023-03-10 Thread Pali Rohár
On Monday 06 March 2023 12:53:25 Pali Rohár wrote:
> On Monday 06 March 2023 11:15:35 Martin Rowe wrote:
> > On Sun, 5 Mar 2023 at 16:04, Pali Rohár  wrote:
> > 
> > > On Sunday 05 March 2023 12:46:34 Pali Rohár wrote:
> > > > On Sunday 05 March 2023 02:24:27 Martin Rowe wrote:
> > > > > On Sat, 4 Mar 2023 at 10:40, Pali Rohár  wrote:
> > > > >
> > > > > > Boot configuration stored in EXT_CSC register is completely ignored
> > > by
> > > > > > BootROM:
> > > > > >
> > > > > >
> > > https://lore.kernel.org/u-boot/CAOAjy5SYPPzWKok-BSGYwZwcKOQt_aZPgh6FTbrFd3F=8dm...@mail.gmail.com/
> > > > > >
> > > > > > Reflect this eMMC booting in documentation and in the code.
> > > > > >
> > > > > > Martin, can you test this patch series if SPL and main U-Boot is
> > > loaded
> > > > > > from the same eMMC HW partition?
> > > > > >
> > > > >
> > > > > boot0: u-boot
> > > > >
> > > > > Works fine, no issues.
> > > > >
> > > > >
> > > > > boot0: zeroed
> > > > > boot1: u-boot
> > > > > user: zeroed
> > > > >
> > > > > It succeeds, eventually...
> > > > > ==
> > > > > BootROM - 1.73
> > > > >
> > > > > Booting from MMC
> > > > > BootROM: Bad header at offset 
> > > > > BootROM: Bad header at offset 0020
> > > > > Switching BootPartitions.
> > > > >
> > > > > U-Boot SPL 2023.04-rc3-00159-gd1653548d2-dirty (Mar 05 2023 - 11:50:45
> > > > > +1000)
> > > > > High speed PHY - Version: 2.0
> > > > > EEPROM TLV detection failed: Using static config for Clearfog Pro.
> > > > > Detected Device ID 6828
> > > > > board SerDes lanes topology details:
> > > > >  | Lane # | Speed |  Type   |
> > > > >  
> > > > >  |   0|   3   | SATA0   |
> > > > >  |   1|   0   | SGMII1  |
> > > > >  |   2|   5   | PCIe1   |
> > > > >  |   3|   5   | USB3 HOST1  |
> > > > >  |   4|   5   | PCIe2   |
> > > > >  |   5|   0   | SGMII2  |
> > > > >  
> > > > > High speed PHY - Ended Successfully
> > > > > mv_ddr: 14.0.0
> > > > > DDR3 Training Sequence - Switching XBAR Window to FastPath Window
> > > > > mv_ddr: completed successfully
> > > > > Trying to boot from MMC1
> > > > > ERROR: Invalid kwbimage v1
> > > > > mmc_load_image_raw_sector: mmc block read error
> > > > > spl: mmc: wrong boot mode
> > > > > Trying to boot from BOOTROM
> > > > > Returning to BootROM (return address 0x05c4)...
> > > > > Timeout waiting card ready
> > > > > BootROM: Image checksum verification PASSED
> > > > >
> > > > >
> > > > > U-Boot 2023.04-rc3-00159-gd1653548d2-dirty (Mar 05 2023 - 11:50:45
> > > +1000)
> > > > >
> > > > > SoC:   MV88F6828-A0 at 1600 MHz
> > > > > DRAM:  1 GiB (800 MHz, 32-bit, ECC not enabled)
> > > > > Core:  38 devices, 22 uclasses, devicetree: separate
> > > > > MMC:   mv_sdh: 0
> > > > > Loading Environment from MMC... *** Warning - bad CRC, using default
> > > > > environment
> > > > >
> > > > > Model: SolidRun Clearfog A1
> > > > > Board: SolidRun Clearfog Pro
> > > > > Net:
> > > > > Warning: ethernet@7 (eth1) using random MAC address -
> > > 12:07:8b:f9:7a:6f
> > > > > eth1: ethernet@7
> > > > > Warning: ethernet@3 (eth2) using random MAC address -
> > > ee:ed:f3:bb:c2:af
> > > > > , eth2: ethernet@3
> > > > > Warning: ethernet@34000 (eth3) using random MAC address -
> > > ae:34:b9:bb:28:c6
> > > > > , eth3: ethernet@34000
> > > > > Hit any key to stop autoboot:  0
> > > > > =>
> > > > > ==
> > > > >
> > > > > Between "Returning to BootROM" and "Timeout waiting card ready" takes
> > > > > around 315 seconds. That's long enough that I thought it had hung
> > > > > completely and I only noticed it continue because I left it running
> > > while
> > > > > working on something else. I tried several things to reduce this
> > > timeout,
> > > > > including reverting to the "non-removable" dts for shdci, but nothing
> > > seems
> > > > > to affect it.
> > > >
> > > > Ok. So now it is in the state that it is working but is slow. Better
> > > > than nothing.
> > > >
> > > > Message "Returning to BootROM" is printed by SPL and message
> > > > "Timeout waiting card ready" is printed by BootROM. After printing
> > > > "Returning to BootROM" is SPL jumping back to the BootROM so the delay
> > > > is for sure in the BootROM. So seems that SPL reconfigures eMMC into
> > > > state in which BootROM cannot work with it. Something timeouts, BootROM
> > > > reconfigure/retry it and then it work again. It would be needed to
> > > > investigate what is happening here. My guess is that this could have
> > > > something with eMMC HW partition access, and code for switching
> > > > partitions near SPL MMCSD_MODE_EMMCBOOT.
> > >
> > > Try this change?
> > >
> > > diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
> > > index b20eac3dcd38..eb59c41a824e 100644
> > > --- a/arch/arm/mach-mvebu/spl.c
> > > +++ b/arch/arm/mach-mvebu/spl.c
> > > @@ -11,6 +11,7 @@
> > 

Re: [PATCH v2 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-03-10 Thread Pali Rohár
On Friday 10 March 2023 18:36:44 Minda Chen wrote:
> On 2023/3/8 15:31, Pali Rohár wrote:
> > Hello! See few comments below.
> > 
> > On Wednesday 08 March 2023 13:48:31 Minda Chen wrote:
> >> From: Mason Huo 
> >> 
> >> Add pcie driver for StarFive JH7110, the driver depends on
> >> starfive gpio, pinctrl, clk and reset driver to do init.
> >> 
> >> Several devices are tested:
> >> a) M.2 NVMe SSD
> >> b) Realtek 8169 Ethernet adapter.
> >> 
> >> Signed-off-by: Mason Huo 
> >> Signed-off-by: Minda Chen 
> >> ---
> >>  drivers/pci/Kconfig|  11 +
> >>  drivers/pci/Makefile   |   1 +
> >>  drivers/pci/pcie_starfive_jh7110.c | 478 +
> >>  3 files changed, 490 insertions(+)
> >>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
> >> 
> >> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
> >> index ef328d2652..e7b0ff5bc3 100644
> >> --- a/drivers/pci/Kconfig
> >> +++ b/drivers/pci/Kconfig
> >> @@ -374,4 +374,15 @@ config PCIE_UNIPHIER
> >>  Say Y here if you want to enable PCIe controller support on
> >>  UniPhier SoCs.
> >>  
> >> +config PCIE_STARFIVE_JH7110
> >> +  bool "Enable Starfive JH7110 PCIe driver"
> >> +  depends on STARFIVE_JH7110
> >> +  depends on PINCTRL_STARFIVE_JH7110
> >> +  depends on CLK_JH7110
> >> +  depends on RESET_JH7110
> >> +  default y
> >> +  help
> >> +Say Y here if you want to enable PCIe controller support on
> >> +StarFive JH7110 SoC.
> >> +
> >>  endif
> >> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
> >> index 49506e7ba5..bbe3323bb5 100644
> >> --- a/drivers/pci/Makefile
> >> +++ b/drivers/pci/Makefile
> >> @@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
> >>  obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
> >>  obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
> >>  obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
> >> +obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
> >> diff --git a/drivers/pci/pcie_starfive_jh7110.c 
> >> b/drivers/pci/pcie_starfive_jh7110.c
> >> new file mode 100644
> >> index 00..5ccef1ef02
> >> --- /dev/null
> >> +++ b/drivers/pci/pcie_starfive_jh7110.c
> >> @@ -0,0 +1,478 @@
> >> +// SPDX-License-Identifier: GPL-2.0+
> >> +/*
> >> + * StarFive PLDA PCIe host controller driver
> >> + *
> >> + * Copyright (c) 2023 Starfive, Inc.
> >> + * Author: Mason Huo 
> >> + *
> >> + */
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +
> >> +DECLARE_GLOBAL_DATA_PTR;
> >> +
> >> +#define GEN_SETTINGS  0x80
> >> +#define PCIE_PCI_IDS  0x9C
> >> +#define PCIE_WINROM   0xFC
> >> +#define PMSG_SUPPORT_RX   0x3F0
> >> +#define PCI_MISC  0xB4
> >> +
> >> +#define PLDA_EP_ENABLE0
> >> +#define PLDA_RP_ENABLE1
> >> +
> >> +#define IDS_REVISION_ID   0x02
> >> +#define IDS_PCI_TO_PCI_BRIDGE 0x060400
> >> +#define IDS_CLASS_CODE_SHIFT  8
> > 
> > Please do not duplicate standard PCI macros and constants. In U-Boot
> > they are already available in include/pci_ids.h header file.
> > 
> ok
> >> +#define PREF_MEM_WIN_64_SUPPORT   BIT(3)
> >> +#define PMSG_LTR_SUPPORT  BIT(2)
> >> +#define PLDA_FUNCTION_DIS BIT(15)
> >> +#define PLDA_FUNC_NUM 4
> >> +#define PLDA_PHY_FUNC_SHIFT   9
> >> +
> >> +#define XR3PCI_ATR_AXI4_SLV0  0x800
> >> +#define XR3PCI_ATR_SRC_ADDR_LOW   0x0
> >> +#define XR3PCI_ATR_SRC_ADDR_HIGH  0x4
> >> +#define XR3PCI_ATR_TRSL_ADDR_LOW  0x8
> >> +#define XR3PCI_ATR_TRSL_ADDR_HIGH 0xc
> >> +#define XR3PCI_ATR_TRSL_PARAM 0x10
> >> +#define XR3PCI_ATR_TABLE_OFFSET   0x20
> >> +#define XR3PCI_ATR_MAX_TABLE_NUM  8
> >> +
> >> +#define XR3PCI_ATR_SRC_WIN_SIZE_SHIFT 1
> >> +#define XR3PCI_ATR_SRC_ADDR_MASK  GENMASK(31, 12)
> >> +#define XR3PCI_ATR_TRSL_ADDR_MASK GENMASK(31, 12)
> >> +#define XR3_PCI_ECAM_SIZE 28
> >> +#define XR3PCI_ATR_TRSL_DIR   BIT(22)
> >> +/* IDs used in the XR3PCI_ATR_TRSL_PARAM */
> >> +#define XR3PCI_ATR_TRSLID_PCIE_MEMORY 0x0
> >> +#define XR3PCI_ATR_TRSLID_PCIE_CONFIG 0x1
> >> +
> >> +#define ECAM_BUS_SHIFT20
> >> +#define ECAM_DEV_SHIFT15
> >> +#define ECAM_FUNC_SHIFT   12
> > 
> > Please do not implement duplicate PCIe ECAM code. U-Boot and also Linux
> > kernel already provides PCIE_ECAM_OFFSET() macro.
> > 
> >> +/* Secondary bus number offset in config space */
> >> +#define PCI_SECONDARY_BUS 0x19
> > 
> > Unused.
> > 
> ok
> >> +
> >> +/* system control */
> >> +#define STG_SYSCON_K_RP_NEP_MASK  BIT(8)
> >> +#define 

[RESEND PATCH v7 09/23] rockchip: pwm: rk_pwm: use reg variable with phys_addr_t size

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled.
A 32bit CPU can expect 64-bit data from the device tree parser,
so use a reg variable with phys_addr_t size in the
rk_pwm.c file.

Signed-off-by: Johan Jonker 
---

Changed V6:
  new patch
---
 drivers/pwm/rk_pwm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pwm/rk_pwm.c b/drivers/pwm/rk_pwm.c
index 071eb04f..b2784530 100644
--- a/drivers/pwm/rk_pwm.c
+++ b/drivers/pwm/rk_pwm.c
@@ -30,7 +30,7 @@ struct rockchip_pwm_data {
 };

 struct rk_pwm_priv {
-   fdt_addr_t base;
+   phys_addr_t base;
ulong freq;
u32 conf_polarity;
const struct rockchip_pwm_data *data;
--
2.20.1



[PATCH v7 23/23] include: fdtdec: decouple fdt_addr_t and phys_addr_t size

2023-03-10 Thread Johan Jonker
The DT specification supports CPUs with both 32-bit and 64-bit addressing
capabilities. In U-boot the fdt_addr_t and phys_addr_t size are coupled
by a typedef. The MTD NAND drivers for 32-bit CPU's can describe partitions
with a 64-bit reg property. These partitions synced from Linux end up with
the wrong offset and sizes when only the lower 32-bit is passed.
Decouple the fdt_addr_t and phys_addr_t size as they don't necessary
match.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
Reviewed-by: Kever Yang 
---

Note:
  Due to the large number of references to fdt_addr_t
  this patch serie fixes only some bugs, but not all.
  Apply only when all remaining errors and warnings
  due to this patch are fixed.
  Help with testing/debug appreciated.
---
 Kconfig  |  8 
 include/fdtdec.h | 13 +
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/Kconfig b/Kconfig
index a75cce7e..7697dade 100644
--- a/Kconfig
+++ b/Kconfig
@@ -422,11 +422,19 @@ endif # EXPERT

 config PHYS_64BIT
bool "64bit physical address support"
+   select FDT_64BIT
help
  Say Y here to support 64bit physical memory address.
  This can be used not only for 64bit SoCs, but also for
  large physical address extension on 32bit SoCs.

+config FDT_64BIT
+   bool "64bit fdt address support"
+   help
+ Say Y here to support 64bit fdt addresses.
+ This can be used not only for 64bit SoCs, but also
+ for large address extensions on 32bit SoCs.
+
 config HAS_ROM
bool
select BINMAN
diff --git a/include/fdtdec.h b/include/fdtdec.h
index aa61a0fc..6b768ed5 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -18,15 +18,18 @@
 #include 

 /*
- * A typedef for a physical address. Note that fdt data is always big
+ * Support for 64bit fdt addresses.
+ * This can be used not only for 64bit SoCs, but also
+ * for large address extensions on 32bit SoCs.
+ * Note that fdt data is always big
  * endian even on a litle endian machine.
  */
-typedef phys_addr_t fdt_addr_t;
-typedef phys_size_t fdt_size_t;

 #define FDT_SIZE_T_NONE (-1U)

-#ifdef CONFIG_PHYS_64BIT
+#ifdef CONFIG_FDT_64BIT
+typedef u64 fdt_addr_t;
+typedef u64 fdt_size_t;
 #define FDT_ADDR_T_NONE ((ulong)(-1))

 #define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
@@ -35,6 +38,8 @@ typedef phys_size_t fdt_size_t;
 #define cpu_to_fdt_size(reg) cpu_to_be64(reg)
 typedef fdt64_t fdt_val_t;
 #else
+typedef u32 fdt_addr_t;
+typedef u32 fdt_size_t;
 #define FDT_ADDR_T_NONE (-1U)

 #define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
--
2.20.1



[PATCH v7 22/23] arm: stm32mp: spl: fix function with fdt_addr_t input

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled.
A 32bit CPU can expect 64-bit data from the device tree parser,
so fix ofnode_get_addr_size function with fdt_addr_t input to
be able to handle both sizes for stm32mp SoC in spl.c file.

Signed-off-by: Johan Jonker 
---

Changed V7:
  remove cast
---
 arch/arm/mach-stm32mp/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-stm32mp/spl.c b/arch/arm/mach-stm32mp/spl.c
index 19d9fe04..6c79259b 100644
--- a/arch/arm/mach-stm32mp/spl.c
+++ b/arch/arm/mach-stm32mp/spl.c
@@ -112,7 +112,7 @@ uint32_t stm32mp_get_dram_size(void)

 static int optee_get_reserved_memory(uint32_t *start, uint32_t *size)
 {
-   phys_size_t fdt_mem_size;
+   fdt_addr_t fdt_mem_size;
fdt_addr_t fdt_start;
ofnode node;

--
2.20.1



[PATCH v7 21/23] drivers: fix debug string with fdt_addr_t input

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU
can expect 64-bit data from the device tree parser, so fix some
debug strings with fdt_addr_t to be able to handle both sizes.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---

Changed V5:
  new patch
---
 arch/arm/mach-mvebu/cpu.c   | 2 +-
 drivers/clk/ti/clk-ctrl.c   | 9 +
 drivers/phy/phy-stm32-usbphyc.c | 4 ++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-mvebu/cpu.c b/arch/arm/mach-mvebu/cpu.c
index 329d1369..f58689e1 100644
--- a/arch/arm/mach-mvebu/cpu.c
+++ b/arch/arm/mach-mvebu/cpu.c
@@ -631,7 +631,7 @@ int board_xhci_enable(fdt_addr_t base)
 {
const struct mbus_dram_target_info *dram;

-   printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
+   printf("MVEBU XHCI INIT controller @ 0x%llx\n", (fdt64_t)base);

dram = mvebu_mbus_dram_info();
xhci_mvebu_mbus_config((void __iomem *)base, dram);
diff --git a/drivers/clk/ti/clk-ctrl.c b/drivers/clk/ti/clk-ctrl.c
index 6cc02d2e..8926e57e 100644
--- a/drivers/clk/ti/clk-ctrl.c
+++ b/drivers/clk/ti/clk-ctrl.c
@@ -44,7 +44,7 @@ static int clk_ti_ctrl_disable(struct clk *clk)
offs = priv->offs[0].start + clk->id;
err = clk_ti_ctrl_check_offs(clk, offs);
if (err) {
-   dev_err(clk->dev, "invalid offset: 0x%lx\n", offs);
+   dev_err(clk->dev, "invalid offset: 0x%llx\n", (fdt64_t)offs);
return err;
}

@@ -64,7 +64,7 @@ static int clk_ti_ctrl_enable(struct clk *clk)
offs = priv->offs[0].start + clk->id;
err = clk_ti_ctrl_check_offs(clk, offs);
if (err) {
-   dev_err(clk->dev, "invalid offset: 0x%lx\n", offs);
+   dev_err(clk->dev, "invalid offset: 0x%llx\n", (fdt64_t)offs);
return err;
}

@@ -125,8 +125,9 @@ static int clk_ti_ctrl_of_to_plat(struct udevice *dev)
}

priv->offs[i].end = priv->offs[i].start + fdt_size;
-   dev_dbg(dev, "start=0x%08lx, end=0x%08lx\n",
-   priv->offs[i].start, priv->offs[i].end);
+   dev_dbg(dev, "start=0x%016llx, end=0x%016llx\n",
+   (fdt64_t)priv->offs[i].start,
+   (fdt64_t)priv->offs[i].end);
}

return 0;
diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c
index dcf2194e..15bd60ca 100644
--- a/drivers/phy/phy-stm32-usbphyc.c
+++ b/drivers/phy/phy-stm32-usbphyc.c
@@ -583,8 +583,8 @@ static int stm32_usbphyc_probe(struct udevice *dev)

phy_id = ofnode_read_u32_default(node, "reg", FDT_ADDR_T_NONE);
if (phy_id >= MAX_PHYS) {
-   dev_err(dev, "invalid reg value %lx for %s\n",
-   phy_id, ofnode_get_name(node));
+   dev_err(dev, "invalid reg value %llx for %s\n",
+   (fdt64_t)phy_id, ofnode_get_name(node));
return -ENOENT;
}

--
2.20.1



[PATCH v7 20/23] drivers: use devfdt_get_addr_ptr when cast to pointer

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU
can expect 64-bit data from the device tree parser, so use
devfdt_get_addr_ptr instead of the devfdt_get_addr function in
the various files in the drivers directory that cast to a pointer.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---

Changed V6:
  drop cast
  skip livetree.rst

Changed V5:
  new patch
---
 drivers/clk/at91/sama7g5.c | 2 +-
 drivers/clk/at91/sckc.c| 2 +-
 drivers/spi/mtk_snor.c | 2 +-
 drivers/spi/mtk_spim.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/at91/sama7g5.c b/drivers/clk/at91/sama7g5.c
index d1ec3c82..7a5a2906 100644
--- a/drivers/clk/at91/sama7g5.c
+++ b/drivers/clk/at91/sama7g5.c
@@ -1114,7 +1114,7 @@ static const struct pmc_clk_setup {

 static int sama7g5_clk_probe(struct udevice *dev)
 {
-   void __iomem *base = (void *)devfdt_get_addr(dev);
+   void __iomem *base = devfdt_get_addr_ptr(dev);
unsigned int *clkmuxallocs[SAMA7G5_MAX_MUX_ALLOCS];
unsigned int *muxallocs[SAMA7G5_MAX_MUX_ALLOCS];
const char *p[10];
diff --git a/drivers/clk/at91/sckc.c b/drivers/clk/at91/sckc.c
index 34ce611a..43136ab2 100644
--- a/drivers/clk/at91/sckc.c
+++ b/drivers/clk/at91/sckc.c
@@ -123,7 +123,7 @@ U_BOOT_DRIVER(at91_sam9x60_td_slck) = {
 static int at91_sam9x60_sckc_probe(struct udevice *dev)
 {
struct sam9x60_sckc *sckc = dev_get_priv(dev);
-   void __iomem *base = (void *)devfdt_get_addr(dev);
+   void __iomem *base = devfdt_get_addr_ptr(dev);
const char *slow_rc_osc, *slow_osc;
const char *parents[2];
struct clk *clk, c;
diff --git a/drivers/spi/mtk_snor.c b/drivers/spi/mtk_snor.c
index 04f588a7..4b7d4a6e 100644
--- a/drivers/spi/mtk_snor.c
+++ b/drivers/spi/mtk_snor.c
@@ -470,7 +470,7 @@ static int mtk_snor_probe(struct udevice *bus)
int ret;
u32 reg;

-   priv->base = (void __iomem *)devfdt_get_addr(bus);
+   priv->base = devfdt_get_addr_ptr(bus);
if (!priv->base)
return -EINVAL;

diff --git a/drivers/spi/mtk_spim.c b/drivers/spi/mtk_spim.c
index a7c0fc59..ebb8ee8e 100644
--- a/drivers/spi/mtk_spim.c
+++ b/drivers/spi/mtk_spim.c
@@ -641,7 +641,7 @@ static int mtk_spim_probe(struct udevice *dev)
struct mtk_spim_priv *priv = dev_get_priv(dev);
int ret;

-   priv->base = (void __iomem *)devfdt_get_addr(dev);
+   priv->base = devfdt_get_addr_ptr(dev);
if (!priv->base)
return -EINVAL;

--
2.20.1



[PATCH v7 19/23] drivers: use devfdt_get_addr_index_ptr when cast to pointer

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU
can expect 64-bit data from the device tree parser, so use
devfdt_get_addr_index_ptr instead of the devfdt_get_addr_index function
in the various files in the drivers directory that cast to a pointer.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---

Changed V6:
  use -EINVAL on return
  drop cast
---
 drivers/clk/clk-hsdk-cgu.c|  4 ++--
 drivers/ddr/altera/sdram_gen5.c   |  4 ++--
 drivers/mmc/xenon_sdhci.c |  2 +-
 drivers/net/mvpp2.c   | 24 
 drivers/pci/pcie_dw_mvebu.c   |  4 ++--
 drivers/pci/pcie_imx.c|  4 ++--
 drivers/pci/pcie_layerscape_ep.c  |  8 
 drivers/phy/marvell/comphy_core.c | 12 ++--
 drivers/spi/cadence_qspi.c|  2 +-
 drivers/usb/musb-new/ti-musb.c|  2 +-
 10 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/drivers/clk/clk-hsdk-cgu.c b/drivers/clk/clk-hsdk-cgu.c
index 26b0aa9a..e28543ef 100644
--- a/drivers/clk/clk-hsdk-cgu.c
+++ b/drivers/clk/clk-hsdk-cgu.c
@@ -753,11 +753,11 @@ static int hsdk_cgu_clk_probe(struct udevice *dev)
else
hsdk_clk->map = hsdk_4xd_clk_map;

-   hsdk_clk->cgu_regs = (void __iomem *)devfdt_get_addr_index(dev, 0);
+   hsdk_clk->cgu_regs = devfdt_get_addr_index_ptr(dev, 0);
if (!hsdk_clk->cgu_regs)
return -EINVAL;

-   hsdk_clk->creg_regs = (void __iomem *)devfdt_get_addr_index(dev, 1);
+   hsdk_clk->creg_regs = devfdt_get_addr_index_ptr(dev, 1);
if (!hsdk_clk->creg_regs)
return -EINVAL;

diff --git a/drivers/ddr/altera/sdram_gen5.c b/drivers/ddr/altera/sdram_gen5.c
index 8d3ce495..34d2a278 100644
--- a/drivers/ddr/altera/sdram_gen5.c
+++ b/drivers/ddr/altera/sdram_gen5.c
@@ -567,9 +567,9 @@ static int altera_gen5_sdram_of_to_plat(struct udevice *dev)
 {
struct altera_gen5_sdram_plat *plat = dev_get_plat(dev);

-   plat->sdr = (struct socfpga_sdr *)devfdt_get_addr_index(dev, 0);
+   plat->sdr = devfdt_get_addr_index_ptr(dev, 0);
if (!plat->sdr)
-   return -ENODEV;
+   return -EINVAL;

return 0;
 }
diff --git a/drivers/mmc/xenon_sdhci.c b/drivers/mmc/xenon_sdhci.c
index 2f880509..16ac84a2 100644
--- a/drivers/mmc/xenon_sdhci.c
+++ b/drivers/mmc/xenon_sdhci.c
@@ -537,7 +537,7 @@ static int xenon_sdhci_of_to_plat(struct udevice *dev)
host->ioaddr = dev_read_addr_ptr(dev);

if (device_is_compatible(dev, "marvell,armada-3700-sdhci"))
-   priv->pad_ctrl_reg = (void *)devfdt_get_addr_index(dev, 1);
+   priv->pad_ctrl_reg = devfdt_get_addr_index_ptr(dev, 1);

name = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "marvell,pad-type",
   NULL);
diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
index 1bad50d3..a4be8497 100644
--- a/drivers/net/mvpp2.c
+++ b/drivers/net/mvpp2.c
@@ -5349,18 +5349,18 @@ static int mvpp2_base_probe(struct udevice *dev)
}

/* Save base addresses for later use */
-   priv->base = (void *)devfdt_get_addr_index(dev, 0);
-   if (IS_ERR(priv->base))
-   return PTR_ERR(priv->base);
+   priv->base = devfdt_get_addr_index_ptr(dev, 0);
+   if (!priv->base)
+   return -EINVAL;

if (priv->hw_version == MVPP21) {
-   priv->lms_base = (void *)devfdt_get_addr_index(dev, 1);
-   if (IS_ERR(priv->lms_base))
-   return PTR_ERR(priv->lms_base);
+   priv->lms_base = devfdt_get_addr_index_ptr(dev, 1);
+   if (!priv->lms_base)
+   return -EINVAL;
} else {
-   priv->iface_base = (void *)devfdt_get_addr_index(dev, 1);
-   if (IS_ERR(priv->iface_base))
-   return PTR_ERR(priv->iface_base);
+   priv->iface_base = devfdt_get_addr_index_ptr(dev, 1);
+   if (!priv->iface_base)
+   return -EINVAL;

/* Store common base addresses for all ports */
priv->mpcs_base = priv->iface_base + MVPP22_MPCS;
@@ -5399,10 +5399,10 @@ static int mvpp2_probe(struct udevice *dev)
if (priv->hw_version == MVPP21) {
int priv_common_regs_num = 2;

-   port->base = (void __iomem *)devfdt_get_addr_index(
+   port->base = devfdt_get_addr_index_ptr(
dev->parent, priv_common_regs_num + port->id);
-   if (IS_ERR(port->base))
-   return PTR_ERR(port->base);
+   if (!port->base)
+   return -EINVAL;
} else {
port->gop_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
  "gop-port-id", -1);
diff --git a/drivers/pci/pcie_dw_mvebu.c b/drivers/pci/pcie_dw_mvebu.c
index 3b2ada54..c41f3f15 100644
--- a/drivers/pci/pcie_dw_mvebu.c

[PATCH v7 18/23] drivers: use devfdt_get_addr_size_index_ptr when cast to pointer

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU
can expect 64-bit data from the device tree parser, so use
devfdt_get_addr_size_index_ptr instead of the devfdt_get_addr_size_index
function in the various files in the drivers directory that cast to
a pointer.

Signed-off-by: Johan Jonker 
Reviewed-by: Michael Trimarchi 
Reviewed-by: Simon Glass 
---
 drivers/pci/pcie_dw_mvebu.c | 6 +++---
 drivers/spi/cadence_qspi.c  | 3 +--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/pcie_dw_mvebu.c b/drivers/pci/pcie_dw_mvebu.c
index a0b82c78..3b2ada54 100644
--- a/drivers/pci/pcie_dw_mvebu.c
+++ b/drivers/pci/pcie_dw_mvebu.c
@@ -569,9 +569,9 @@ static int pcie_dw_mvebu_of_to_plat(struct udevice *dev)
return -EINVAL;

/* Get the config space base address and size */
-   pcie->cfg_base = (void *)devfdt_get_addr_size_index(dev, 1,
->cfg_size);
-   if ((fdt_addr_t)pcie->cfg_base == FDT_ADDR_T_NONE)
+   pcie->cfg_base = devfdt_get_addr_size_index_ptr(dev, 1,
+   >cfg_size);
+   if (!pcie->cfg_base)
return -EINVAL;

return 0;
diff --git a/drivers/spi/cadence_qspi.c b/drivers/spi/cadence_qspi.c
index c7f10c50..6a52676a 100644
--- a/drivers/spi/cadence_qspi.c
+++ b/drivers/spi/cadence_qspi.c
@@ -384,8 +384,7 @@ static int cadence_spi_of_to_plat(struct udevice *bus)
ofnode subnode;

plat->regbase = (void *)devfdt_get_addr_index(bus, 0);
-   plat->ahbbase = (void *)devfdt_get_addr_size_index(bus, 1,
-   >ahbsize);
+   plat->ahbbase = devfdt_get_addr_size_index_ptr(bus, 1, >ahbsize);
plat->is_decoded_cs = dev_read_bool(bus, "cdns,is-decoded-cs");
plat->fifo_depth = dev_read_u32_default(bus, "cdns,fifo-depth", 128);
plat->fifo_width = dev_read_u32_default(bus, "cdns,fifo-width", 4);
--
2.20.1



[PATCH v7 17/23] drivers: use dev_read_addr_ptr when cast to pointer

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU
can expect 64-bit data from the device tree parser, so use
dev_read_addr_ptr instead of the dev_read_addr function in the
various files in the drivers directory that cast to a pointer.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---

Changed V6:
  use -EINVAL on return
  drop cast

Changed V5:
  rebase
  fix typo
  fix more files
---
 arch/arm/mach-mvebu/system-controller.c| 4 ++--
 doc/develop/driver-model/livetree.rst  | 2 +-
 drivers/ata/dwc_ahsata.c   | 2 +-
 drivers/cache/cache-l2x0.c | 2 +-
 drivers/cache/cache-v5l2.c | 2 +-
 drivers/gpio/mscc_sgpio.c  | 2 +-
 drivers/gpio/tegra_gpio.c  | 4 ++--
 drivers/gpio/xilinx_gpio.c | 2 +-
 drivers/i2c/i2c-cdns.c | 4 ++--
 drivers/i2c/tegra_i2c.c| 4 ++--
 drivers/mmc/am654_sdhci.c  | 2 +-
 drivers/mmc/davinci_mmc.c  | 2 +-
 drivers/mmc/piton_mmc.c| 2 +-
 drivers/mmc/tegra_mmc.c| 2 +-
 drivers/mmc/zynq_sdhci.c   | 6 +++---
 drivers/mtd/nand/raw/arasan_nfc.c  | 2 +-
 drivers/mtd/nand/raw/cortina_nand.c| 2 +-
 drivers/mtd/nand/raw/mxic_nand.c   | 2 +-
 drivers/mtd/nand/raw/tegra_nand.c  | 2 +-
 drivers/mtd/nand/raw/zynq_nand.c   | 2 +-
 drivers/net/mvmdio.c   | 2 +-
 drivers/net/qe/dm_qe_uec_phy.c | 2 +-
 drivers/pci/pci-aardvark.c | 4 ++--
 drivers/phy/allwinner/phy-sun50i-usb3.c| 6 +++---
 drivers/phy/qcom/phy-qcom-usb-hs-28nm.c| 4 ++--
 drivers/phy/qcom/phy-qcom-usb-ss.c | 4 ++--
 drivers/phy/rockchip/phy-rockchip-snps-pcie3.c | 4 ++--
 drivers/phy/rockchip/phy-rockchip-typec.c  | 6 +++---
 drivers/pwm/tegra_pwm.c| 2 +-
 drivers/serial/serial_zynq.c   | 6 +++---
 drivers/spi/mpc8xxx_spi.c  | 2 +-
 drivers/spi/mscc_bb_spi.c  | 2 +-
 drivers/spi/sh_qspi.c  | 2 +-
 drivers/spi/spi-mxic.c | 2 +-
 drivers/spi/xilinx_spi.c   | 2 +-
 drivers/ufs/ufs.c  | 2 +-
 drivers/usb/host/ehci-tegra.c  | 2 +-
 drivers/video/dw_mipi_dsi.c| 4 ++--
 drivers/video/rockchip/rk_vop.c| 2 +-
 drivers/video/stm32/stm32_dsi.c| 4 ++--
 drivers/video/stm32/stm32_ltdc.c   | 4 ++--
 drivers/video/tegra124/display.c   | 2 +-
 drivers/video/tegra124/sor.c   | 6 +++---
 drivers/video/ti/tilcdc.c  | 4 ++--
 drivers/watchdog/cdns_wdt.c| 6 +++---
 drivers/watchdog/sp805_wdt.c   | 6 +++---
 drivers/watchdog/xilinx_tb_wdt.c   | 6 +++---
 47 files changed, 75 insertions(+), 75 deletions(-)

diff --git a/arch/arm/mach-mvebu/system-controller.c 
b/arch/arm/mach-mvebu/system-controller.c
index e90aff0c..7cdde11c 100644
--- a/arch/arm/mach-mvebu/system-controller.c
+++ b/arch/arm/mach-mvebu/system-controller.c
@@ -71,8 +71,8 @@ static int mvebu_reset_of_to_plat(struct udevice *dev)
 {
struct mvebu_reset_data *data = dev_get_priv(dev);

-   data->base = (void *)dev_read_addr(dev);
-   if ((fdt_addr_t)data->base == FDT_ADDR_T_NONE)
+   data->base = dev_read_addr_ptr(dev);
+   if (!data->base)
return -EINVAL;

return 0;
diff --git a/doc/develop/driver-model/livetree.rst 
b/doc/develop/driver-model/livetree.rst
index 579eef5c..20055d55 100644
--- a/doc/develop/driver-model/livetree.rst
+++ b/doc/develop/driver-model/livetree.rst
@@ -103,7 +103,7 @@ The new code is:

 struct udevice *bus;

-i2c_bus->regs = (struct i2c_ctlr *)dev_read_addr(dev);
+i2c_bus->regs = dev_read_addr_ptr(dev);
 plat->frequency = dev_read_u32_default(bus, "spi-max-frequency", 50);

 The dev_read\_...() interface is more convenient and works with both the
diff --git a/drivers/ata/dwc_ahsata.c b/drivers/ata/dwc_ahsata.c
index 167b5a39..6a4d861b 100644
--- a/drivers/ata/dwc_ahsata.c
+++ b/drivers/ata/dwc_ahsata.c
@@ -912,7 +912,7 @@ int dwc_ahsata_probe(struct udevice *dev)
 #endif
uc_priv->host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | ATA_FLAG_NO_ATAPI;
-   uc_priv->mmio_base = (void __iomem *)dev_read_addr(dev);
+   uc_priv->mmio_base = dev_read_addr_ptr(dev);

/* initialize adapter */
ret = ahci_host_init(uc_priv);
diff --git a/drivers/cache/cache-l2x0.c b/drivers/cache/cache-l2x0.c
index a1556fbf..560f4c94 100644
--- a/drivers/cache/cache-l2x0.c
+++ b/drivers/cache/cache-l2x0.c
@@ -13,7 +13,7 @@ static void 

[PATCH v7 16/23] drivers: use dev_read_addr_index_ptr when cast to pointer

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled. A 32bit CPU
can expect 64-bit data from the device tree parser, so use
dev_read_addr_index_ptr instead of the dev_read_addr_index function
in the various files in the drivers directory that cast to a pointer.

Signed-off-by: Johan Jonker 
Reviewed-by: Michael Trimarchi 
---

Changed V6:
  use -EINVAL on return
  drop cast
---
 drivers/mtd/nand/raw/cortina_nand.c |  4 ++--
 drivers/net/dm9000x.c   |  2 +-
 drivers/net/dwmac_meson8b.c |  4 ++--
 drivers/pci/pcie_dw_meson.c |  8 
 drivers/pci/pcie_dw_rockchip.c  |  8 
 drivers/watchdog/sbsa_gwdt.c| 12 ++--
 6 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/mtd/nand/raw/cortina_nand.c 
b/drivers/mtd/nand/raw/cortina_nand.c
index 88798f23..8de35731 100644
--- a/drivers/mtd/nand/raw/cortina_nand.c
+++ b/drivers/mtd/nand/raw/cortina_nand.c
@@ -1175,8 +1175,8 @@ static int fdt_decode_nand(struct udevice *dev, struct 
nand_drv *info)
int ecc_strength;

info->reg = (struct nand_ctlr *)dev_read_addr(dev);
-   info->dma_glb = (struct dma_global *)dev_read_addr_index(dev, 1);
-   info->dma_nand = (struct dma_ssp *)dev_read_addr_index(dev, 2);
+   info->dma_glb = dev_read_addr_index_ptr(dev, 1);
+   info->dma_nand = dev_read_addr_index_ptr(dev, 2);
info->config.enabled = dev_read_enabled(dev);
ecc_strength = dev_read_u32_default(dev, "nand-ecc-strength", 16);
info->flash_base =
diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
index b46bdeb2..bec8d67d 100644
--- a/drivers/net/dm9000x.c
+++ b/drivers/net/dm9000x.c
@@ -651,7 +651,7 @@ static int dm9000_of_to_plat(struct udevice *dev)

pdata->iobase = dev_read_addr_index(dev, 0);
db->base_io = (void __iomem *)pdata->iobase;
-   db->base_data = (void __iomem *)dev_read_addr_index(dev, 1);
+   db->base_data = dev_read_addr_index_ptr(dev, 1);

return 0;
 }
diff --git a/drivers/net/dwmac_meson8b.c b/drivers/net/dwmac_meson8b.c
index ddbaa87d..871171e1 100644
--- a/drivers/net/dwmac_meson8b.c
+++ b/drivers/net/dwmac_meson8b.c
@@ -41,8 +41,8 @@ static int dwmac_meson8b_of_to_plat(struct udevice *dev)
 {
struct dwmac_meson8b_plat *pdata = dev_get_plat(dev);

-   pdata->regs = (void *)dev_read_addr_index(dev, 1);
-   if ((fdt_addr_t)pdata->regs == FDT_ADDR_T_NONE)
+   pdata->regs = dev_read_addr_index_ptr(dev, 1);
+   if (!pdata->regs)
return -EINVAL;

pdata->dwmac_setup = (void *)dev_get_driver_data(dev);
diff --git a/drivers/pci/pcie_dw_meson.c b/drivers/pci/pcie_dw_meson.c
index 07da9fa5..f9537979 100644
--- a/drivers/pci/pcie_dw_meson.c
+++ b/drivers/pci/pcie_dw_meson.c
@@ -337,15 +337,15 @@ static int meson_pcie_parse_dt(struct udevice *dev)
struct meson_pcie *priv = dev_get_priv(dev);
int ret;

-   priv->dw.dbi_base = (void *)dev_read_addr_index(dev, 0);
+   priv->dw.dbi_base = dev_read_addr_index_ptr(dev, 0);
if (!priv->dw.dbi_base)
-   return -ENODEV;
+   return -EINVAL;

dev_dbg(dev, "ELBI address is 0x%p\n", priv->dw.dbi_base);

-   priv->meson_cfg_base = (void *)dev_read_addr_index(dev, 1);
+   priv->meson_cfg_base = dev_read_addr_index_ptr(dev, 1);
if (!priv->meson_cfg_base)
-   return -ENODEV;
+   return -EINVAL;

dev_dbg(dev, "CFG address is 0x%p\n", priv->meson_cfg_base);

diff --git a/drivers/pci/pcie_dw_rockchip.c b/drivers/pci/pcie_dw_rockchip.c
index 9322e735..624ca1cb 100644
--- a/drivers/pci/pcie_dw_rockchip.c
+++ b/drivers/pci/pcie_dw_rockchip.c
@@ -353,15 +353,15 @@ static int rockchip_pcie_parse_dt(struct udevice *dev)
struct rk_pcie *priv = dev_get_priv(dev);
int ret;

-   priv->dw.dbi_base = (void *)dev_read_addr_index(dev, 0);
+   priv->dw.dbi_base = dev_read_addr_index_ptr(dev, 0);
if (!priv->dw.dbi_base)
-   return -ENODEV;
+   return -EINVAL;

dev_dbg(dev, "DBI address is 0x%p\n", priv->dw.dbi_base);

-   priv->apb_base = (void *)dev_read_addr_index(dev, 1);
+   priv->apb_base = dev_read_addr_index_ptr(dev, 1);
if (!priv->apb_base)
-   return -ENODEV;
+   return -EINVAL;

dev_dbg(dev, "APB address is 0x%p\n", priv->apb_base);

diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
index f43cd3fd..96d04665 100644
--- a/drivers/watchdog/sbsa_gwdt.c
+++ b/drivers/watchdog/sbsa_gwdt.c
@@ -98,13 +98,13 @@ static int sbsa_gwdt_of_to_plat(struct udevice *dev)
 {
struct sbsa_gwdt_priv *priv = dev_get_priv(dev);

-   priv->reg_control = (void __iomem *)dev_read_addr_index(dev, 0);
-   if (IS_ERR(priv->reg_control))
-   return PTR_ERR(priv->reg_control);
+   priv->reg_control = dev_read_addr_index_ptr(dev, 0);
+   if (!priv->reg_control)
+   

[PATCH v7 15/23] spi: spi-aspeed-smc: use devfdt_get_addr_index_ptr

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled.
A 32bit CPU can expect 64-bit data from the device tree parser,
so use devfdt_get_addr_index_ptr and devfdt_get_addr_size_index_ptr
function in the spi-aspeed-smc.c file. Also fix dev_dbg to be able
to handle both sizes.

Signed-off-by: Johan Jonker 
Reviewed-by: Michael Trimarchi 
---

Changed V6:
  use -EINVAL on return
---
 drivers/spi/spi-aspeed-smc.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c
index 4b6ea9f8..39620310 100644
--- a/drivers/spi/spi-aspeed-smc.c
+++ b/drivers/spi/spi-aspeed-smc.c
@@ -1125,17 +1125,16 @@ static int apseed_spi_of_to_plat(struct udevice *bus)
int ret;
struct clk hclk;

-   priv->regs = (void __iomem *)devfdt_get_addr_index(bus, 0);
-   if ((u32)priv->regs == FDT_ADDR_T_NONE) {
+   priv->regs = devfdt_get_addr_index_ptr(bus, 0);
+   if (!priv->regs) {
dev_err(bus, "wrong ctrl base\n");
-   return -ENODEV;
+   return -EINVAL;
}

-   plat->ahb_base =
-   (void __iomem *)devfdt_get_addr_size_index(bus, 1, 
>ahb_sz);
-   if ((u32)plat->ahb_base == FDT_ADDR_T_NONE) {
+   plat->ahb_base = devfdt_get_addr_size_index_ptr(bus, 1, >ahb_sz);
+   if (!plat->ahb_base) {
dev_err(bus, "wrong AHB base\n");
-   return -ENODEV;
+   return -EINVAL;
}

plat->max_cs = dev_read_u32_default(bus, "num-cs", ASPEED_SPI_MAX_CS);
@@ -1151,8 +1150,8 @@ static int apseed_spi_of_to_plat(struct udevice *bus)
plat->hclk_rate = clk_get_rate();
clk_free();

-   dev_dbg(bus, "ctrl_base = 0x%x, ahb_base = 0x%p, size = 0x%lx\n",
-   (u32)priv->regs, plat->ahb_base, plat->ahb_sz);
+   dev_dbg(bus, "ctrl_base = 0x%x, ahb_base = 0x%p, size = 0x%llx\n",
+   (u32)priv->regs, plat->ahb_base, (fdt64_t)plat->ahb_sz);
dev_dbg(bus, "hclk = %dMHz, max_cs = %d\n",
plat->hclk_rate / 100, plat->max_cs);

--
2.20.1



[PATCH v7 14/23] core: read: add dev_read_addr_index_ptr function

2023-03-10 Thread Johan Jonker
Add dev_read_addr_index_ptr function with the
same functionality as dev_read_addr_index,
but instead a return pointer is given.
Use map_sysmem() function as cast for the return.
Make same fix for dev_read_addr_ptr() function.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---

Changed V6:
  use map_sysmem()

Changed V5:
  new patch
---
 drivers/core/read.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/core/read.c b/drivers/core/read.c
index e0543bba..0289a2ed 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -131,6 +131,16 @@ fdt_addr_t dev_read_addr_index(const struct udevice *dev, 
int index)
return devfdt_get_addr_index(dev, index);
 }

+void *dev_read_addr_index_ptr(const struct udevice *dev, int index)
+{
+   fdt_addr_t addr = dev_read_addr_index(dev, index);
+
+   if (addr == FDT_ADDR_T_NONE)
+   return NULL;
+
+   return map_sysmem(addr, 0);
+}
+
 fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
fdt_size_t *size)
 {
@@ -190,7 +200,10 @@ void *dev_read_addr_ptr(const struct udevice *dev)
 {
fdt_addr_t addr = dev_read_addr(dev);

-   return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
+   if (addr == FDT_ADDR_T_NONE)
+   return NULL;
+
+   return map_sysmem(addr, 0);
 }

 void *dev_remap_addr(const struct udevice *dev)
--
2.20.1



[PATCH v7 13/23] core: fdtaddr: add devfdt_get_addr_size_index_ptr function

2023-03-10 Thread Johan Jonker
Add devfdt_get_addr_size_index_ptr function with the same
functionality as devfdt_get_addr_size_index, but instead
a return pointer is given.
Use map_sysmem() function as cast for the return.
Make same fix for devfdt_get_addr_index_ptr() function.

Suggested-by: Michael Nazzareno Trimarchi 
Signed-off-by: Johan Jonker 
Reviewed-by: Michael Trimarchi 
---

Changed V7:
  use map_sysmem()

Changed V5:
  fix spelling
  use tabs
---
 drivers/core/fdtaddr.c | 17 -
 include/dm/fdtaddr.h   | 17 -
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c
index 91bcd1a2..546db675 100644
--- a/drivers/core/fdtaddr.c
+++ b/drivers/core/fdtaddr.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -97,7 +98,10 @@ void *devfdt_get_addr_index_ptr(const struct udevice *dev, 
int index)
 {
fdt_addr_t addr = devfdt_get_addr_index(dev, index);

-   return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
+   if (addr == FDT_ADDR_T_NONE)
+   return NULL;
+
+   return map_sysmem(addr, 0);
 }

 fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index,
@@ -122,6 +126,17 @@ fdt_addr_t devfdt_get_addr_size_index(const struct udevice 
*dev, int index,
 #endif
 }

+void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index,
+fdt_size_t *size)
+{
+   fdt_addr_t addr = devfdt_get_addr_size_index(dev, index, size);
+
+   if (addr == FDT_ADDR_T_NONE)
+   return NULL;
+
+   return map_sysmem(addr, 0);
+}
+
 fdt_addr_t devfdt_get_addr_name(const struct udevice *dev, const char *name)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL)
diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h
index c9d2b27b..dcdc1913 100644
--- a/include/dm/fdtaddr.h
+++ b/include/dm/fdtaddr.h
@@ -111,7 +111,7 @@ void *devfdt_get_addr_index_ptr(const struct udevice *dev, 
int index);
  * @dev: Pointer to a device
  * @index: the 'reg' property can hold a list of  pairs
  *and @index is used to select which one is required
- * @size: Pointer to size varible - this function returns the size
+ * @size: Pointer to size variable - this function returns the size
  *specified in the 'reg' property here
  *
  * Return: addr
@@ -119,6 +119,21 @@ void *devfdt_get_addr_index_ptr(const struct udevice *dev, 
int index);
 fdt_addr_t devfdt_get_addr_size_index(const struct udevice *dev, int index,
  fdt_size_t *size);

+/**
+ * devfdt_get_addr_size_index_ptr() - Return indexed pointer to the address of 
the
+ *reg property of a device
+ *
+ * @dev: Pointer to a device
+ * @index: the 'reg' property can hold a list of  pairs
+ *and @index is used to select which one is required
+ * @size: Pointer to size variable - this function returns the size
+ *specified in the 'reg' property here
+ *
+ * Return: Pointer to addr, or NULL if there is no such property
+ */
+void *devfdt_get_addr_size_index_ptr(const struct udevice *dev, int index,
+fdt_size_t *size);
+
 /**
  * devfdt_get_addr_name() - Get the reg property of a device, indexed by name
  *
--
2.20.1



[PATCH v7 12/23] rockchip: rk3288: syscon_rk3288: store syscon platdata in regmap

2023-03-10 Thread Johan Jonker
The Rockchip SoC rk3288 has 2 types of device trees floating around.
A 64bit reg size when synced from Linux and a 32bit for U-boot.
A pre-probe function in the syscon class driver assumes only 32bit.
For other odd reg structures the regmap must be defined in the individual
syscon driver. Store rk3288 platdata in a regmap before pre-probe
during bind.

Signed-off-by: Johan Jonker 
---

Note:
  Proof of concept not tested with rk3288 hardware,
  but with rk3066.

Changed V7:
  new patch
---
 arch/arm/mach-rockchip/rk3288/syscon_rk3288.c | 121 ++
 1 file changed, 121 insertions(+)

diff --git a/arch/arm/mach-rockchip/rk3288/syscon_rk3288.c 
b/arch/arm/mach-rockchip/rk3288/syscon_rk3288.c
index 9c1ae880..8b2c2f32 100644
--- a/arch/arm/mach-rockchip/rk3288/syscon_rk3288.c
+++ b/arch/arm/mach-rockchip/rk3288/syscon_rk3288.c
@@ -6,7 +6,10 @@

 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 

@@ -25,6 +28,103 @@ U_BOOT_DRIVER(syscon_rk3288) = {
 };

 #if CONFIG_IS_ENABLED(OF_PLATDATA)
+#if IS_ENABLED(CONFIG_FDT_64BIT)
+struct rockchip_rk3288_noc_plat {
+   struct dtd_rockchip_rk3288_noc dtplat;
+};
+
+struct rockchip_rk3288_grf_plat {
+   struct dtd_rockchip_rk3288_grf dtplat;
+};
+
+struct rockchip_rk3288_sgrf_plat {
+   struct dtd_rockchip_rk3288_sgrf dtplat;
+};
+
+struct rockchip_rk3288_pmu_plat {
+   struct dtd_rockchip_rk3288_pmu dtplat;
+};
+
+static int rk3288_noc_bind_of_plat(struct udevice *dev)
+{
+   struct rockchip_rk3288_noc_plat *plat = dev_get_plat(dev);
+   struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
+   int size = dev->uclass->uc_drv->per_device_auto;
+
+   if (size && !priv) {
+   priv = calloc(1, size);
+   if (!priv)
+   return -ENOMEM;
+   dev_set_uclass_priv(dev, priv);
+   }
+
+   dev->driver_data = dev->driver->of_match->data;
+   debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
+
+   return regmap_init_mem_plat(dev, plat->dtplat.reg, 
sizeof(plat->dtplat.reg[0]),
+   ARRAY_SIZE(plat->dtplat.reg) / 2, 
>regmap);
+}
+
+static int rk3288_grf_bind_of_plat(struct udevice *dev)
+{
+   struct rockchip_rk3288_grf_plat *plat = dev_get_plat(dev);
+   struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
+   int size = dev->uclass->uc_drv->per_device_auto;
+
+   if (size && !priv) {
+   priv = calloc(1, size);
+   if (!priv)
+   return -ENOMEM;
+   dev_set_uclass_priv(dev, priv);
+   }
+
+   dev->driver_data = dev->driver->of_match->data;
+   debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
+
+   return regmap_init_mem_plat(dev, plat->dtplat.reg, 
sizeof(plat->dtplat.reg[0]),
+   ARRAY_SIZE(plat->dtplat.reg) / 2, 
>regmap);
+}
+
+static int rk3288_sgrf_bind_of_plat(struct udevice *dev)
+{
+   struct rockchip_rk3288_sgrf_plat *plat = dev_get_plat(dev);
+   struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
+   int size = dev->uclass->uc_drv->per_device_auto;
+
+   if (size && !priv) {
+   priv = calloc(1, size);
+   if (!priv)
+   return -ENOMEM;
+   dev_set_uclass_priv(dev, priv);
+   }
+
+   dev->driver_data = dev->driver->of_match->data;
+   debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
+
+   return regmap_init_mem_plat(dev, plat->dtplat.reg, 
sizeof(plat->dtplat.reg[0]),
+   ARRAY_SIZE(plat->dtplat.reg) / 2, 
>regmap);
+}
+
+static int rk3288_pmu_bind_of_plat(struct udevice *dev)
+{
+   struct rockchip_rk3288_pmu_plat *plat = dev_get_plat(dev);
+   struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
+   int size = dev->uclass->uc_drv->per_device_auto;
+
+   if (size && !priv) {
+   priv = calloc(1, size);
+   if (!priv)
+   return -ENOMEM;
+   dev_set_uclass_priv(dev, priv);
+   }
+
+   dev->driver_data = dev->driver->of_match->data;
+   debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
+
+   return regmap_init_mem_plat(dev, plat->dtplat.reg, 
sizeof(plat->dtplat.reg[0]),
+   ARRAY_SIZE(plat->dtplat.reg) / 2, 
>regmap);
+}
+#else
 static int rk3288_syscon_bind_of_plat(struct udevice *dev)
 {
dev->driver_data = dev->driver->of_match->data;
@@ -32,32 +132,53 @@ static int rk3288_syscon_bind_of_plat(struct udevice *dev)

return 0;
 }
+#endif

 U_BOOT_DRIVER(rockchip_rk3288_noc) = {
.name = "rockchip_rk3288_noc",
.id = UCLASS_SYSCON,
.of_match = rk3288_syscon_ids,
+#if IS_ENABLED(CONFIG_FDT_64BIT)
+   .bind = rk3288_noc_bind_of_plat,
+   .plat_auto = sizeof(struct rockchip_rk3288_noc_plat),
+#else
.bind = 

[PATCH v7 11/23] core: remap: fix regmap_init_mem_plat() reg size handeling

2023-03-10 Thread Johan Jonker
The fdt_addr_t and phys_addr_t size have been decoupled.
A 32bit CPU can expect 64-bit data from the device tree parser,
so convert regmap_init_mem_plat() input to handel both. The
syscon class driver also makes use of the regmap_init_mem_plat()
function, but has no way of knowing the format of the
device-specific platform data. In case of odd reg structures other
then that the syscon class driver assumes the regmap must be
filled in the individual syscon driver before pre-probe.
Also fix the ARRAY_SIZE divider in the syscon class driver.

Signed-off-by: Johan Jonker 
---

Changed V7:
  changed title
  add reg size input
  rework function calls
---
 drivers/core/regmap.c   | 23 +++
 drivers/core/syscon-uclass.c| 21 -
 drivers/ram/rockchip/sdram_rk3066.c |  2 +-
 drivers/ram/rockchip/sdram_rk3188.c |  2 +-
 drivers/ram/rockchip/sdram_rk322x.c |  2 +-
 drivers/ram/rockchip/sdram_rk3288.c |  2 +-
 drivers/ram/rockchip/sdram_rk3328.c |  2 +-
 drivers/ram/rockchip/sdram_rk3399.c |  2 +-
 include/regmap.h|  5 +++--
 include/syscon.h| 13 -
 10 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index e33bb9d7..dd323280 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -79,7 +79,7 @@ static struct regmap *regmap_alloc(int count)
 }

 #if CONFIG_IS_ENABLED(OF_PLATDATA)
-int regmap_init_mem_plat(struct udevice *dev, fdt_val_t *reg, int count,
+int regmap_init_mem_plat(struct udevice *dev, void *reg, int size, int count,
 struct regmap **mapp)
 {
struct regmap_range *range;
@@ -89,9 +89,24 @@ int regmap_init_mem_plat(struct udevice *dev, fdt_val_t 
*reg, int count,
if (!map)
return -ENOMEM;

-   for (range = map->ranges; count > 0; reg += 2, range++, count--) {
-   range->start = *reg;
-   range->size = reg[1];
+   if (size == sizeof(fdt32_t)) {
+   fdt32_t *ptr = (fdt32_t *)reg;
+
+   for (range = map->ranges; count > 0;
+ptr += 2, range++, count--) {
+   range->start = *ptr;
+   range->size = ptr[1];
+   }
+   } else if (size == sizeof(fdt64_t)) {
+   fdt64_t *ptr = (fdt64_t *)reg;
+
+   for (range = map->ranges; count > 0;
+ptr += 2, range++, count--) {
+   range->start = *ptr;
+   range->size = ptr[1];
+   }
+   } else {
+   return -EINVAL;
}

*mapp = map;
diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c
index 25fdb66e..7b65db6f 100644
--- a/drivers/core/syscon-uclass.c
+++ b/drivers/core/syscon-uclass.c
@@ -49,17 +49,28 @@ static int syscon_pre_probe(struct udevice *dev)
if (device_get_uclass_id(dev->parent) == UCLASS_PCI)
return 0;

+#if CONFIG_IS_ENABLED(OF_PLATDATA)
/*
 * With OF_PLATDATA we really have no way of knowing the format of
 * the device-specific platform data. So we assume that it starts with
-* a 'reg' member, and this holds a single address and size. Drivers
-* using OF_PLATDATA will need to ensure that this is true.
+* a 'reg' member that holds a single address and size. Drivers
+* using OF_PLATDATA will need to ensure that this is true. In case of
+* odd reg structures other then the syscon_base_plat structure
+* below the regmap must be defined in the individual syscon driver.
 */
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
+   struct syscon_base_plat {
+   phys_addr_t reg[2];
+   };
+
struct syscon_base_plat *plat = dev_get_plat(dev);

-   return regmap_init_mem_plat(dev, plat->reg, ARRAY_SIZE(plat->reg),
-   >regmap);
+   /* Return if the regmap is already defined in the individual
+* syscon driver. */
+   if (priv->regmap)
+   return 0;
+
+   return regmap_init_mem_plat(dev, plat->reg, sizeof(plat->reg[0]),
+   ARRAY_SIZE(plat->reg) / 2, >regmap);
 #else
return regmap_init_mem(dev_ofnode(dev), >regmap);
 #endif
diff --git a/drivers/ram/rockchip/sdram_rk3066.c 
b/drivers/ram/rockchip/sdram_rk3066.c
index a2425f22..39c0be56 100644
--- a/drivers/ram/rockchip/sdram_rk3066.c
+++ b/drivers/ram/rockchip/sdram_rk3066.c
@@ -801,7 +801,7 @@ static int rk3066_dmc_conv_of_plat(struct udevice *dev)
memcpy(>base, of_plat->rockchip_sdram_params, sizeof(plat->base));
/* RK3066 supports dual-channel, set default channel num to 2. */
plat->num_channels = 1;
-   ret = regmap_init_mem_plat(dev, of_plat->reg,
+   ret = regmap_init_mem_plat(dev, of_plat->reg, sizeof(of_plat->reg[0]),
   

Re: [PATCH v7 01/23] mtd: nand: raw: rockchip_nfc: use dev_read_addr_ptr

2023-03-10 Thread Michael Nazzareno Trimarchi
Hi John

On Fri, Mar 10, 2023 at 5:40 PM Johan Jonker  wrote:
>
> The fdt_addr_t and phys_addr_t size have been decoupled.
> A 32bit CPU can expext 64-bit data from the device tree parser,
> so use dev_read_addr_ptr in the rockchip_nfc.c file.
>
> Signed-off-by: Johan Jonker 
> Reviewed-by: Michael Trimarchi 
> ---
>
> Changed V6:
>   use -EINVAL on return
> ---
>  drivers/mtd/nand/raw/rockchip_nfc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/rockchip_nfc.c 
> b/drivers/mtd/nand/raw/rockchip_nfc.c
> index d016d255..9f424a25 100644
> --- a/drivers/mtd/nand/raw/rockchip_nfc.c
> +++ b/drivers/mtd/nand/raw/rockchip_nfc.c
> @@ -1180,9 +1180,9 @@ static int rk_nfc_probe(struct udevice *dev)
> nfc->cfg = (void *)dev_get_driver_data(dev);
> nfc->dev = dev;
>
> -   nfc->regs = (void *)dev_read_addr(dev);
> -   if (IS_ERR(nfc->regs)) {
> -   ret = PTR_ERR(nfc->regs);
> +   nfc->regs = dev_read_addr_ptr(dev);
> +   if (!nfc->regs) {
> +   ret = -EINVAL;
> goto release_nfc;
> }
>
> --
> 2.20.1
>

Patches will be queued for nand as soon as you get the review on
change of dts part

Michael


[PATCH v7 10/23] include: dm: ofnode: fix headers

2023-03-10 Thread Johan Jonker
When fdt_addr_t and phys_addr_t are split it turns out that
the header don't match the functions, so fix the headers.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
Reviewed-by: Kever Yang 
---
 include/dm/ofnode.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 3f6b0843..cd966f6a 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -678,8 +678,8 @@ int ofnode_read_size(ofnode node, const char *propname);
  * @size: Pointer to size of the address
  * Return: address, or FDT_ADDR_T_NONE if not present or invalid
  */
-phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
-  fdt_size_t *size);
+fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index,
+ fdt_size_t *size);

 /**
  * ofnode_get_addr_size_index_notrans() - get an address/size from a node
@@ -695,8 +695,8 @@ phys_addr_t ofnode_get_addr_size_index(ofnode node, int 
index,
  * @size: Pointer to size of the address
  * Return: address, or FDT_ADDR_T_NONE if not present or invalid
  */
-phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
-  fdt_size_t *size);
+fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
+ fdt_size_t *size);

 /**
  * ofnode_get_addr_index() - get an address from a node
@@ -707,7 +707,7 @@ phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, 
int index,
  * @index: Index of address to read (0 for first)
  * Return: address, or FDT_ADDR_T_NONE if not present or invalid
  */
-phys_addr_t ofnode_get_addr_index(ofnode node, int index);
+fdt_addr_t ofnode_get_addr_index(ofnode node, int index);

 /**
  * ofnode_get_addr() - get an address from a node
@@ -717,7 +717,7 @@ phys_addr_t ofnode_get_addr_index(ofnode node, int index);
  * @node: node to read from
  * Return: address, or FDT_ADDR_T_NONE if not present or invalid
  */
-phys_addr_t ofnode_get_addr(ofnode node);
+fdt_addr_t ofnode_get_addr(ofnode node);

 /**
  * ofnode_get_size() - get size from a node
@@ -1067,8 +1067,8 @@ const void *ofprop_get_property(const struct ofprop *prop,
  * @sizep: place to put size value (on success)
  * Return: address value, or FDT_ADDR_T_NONE on error
  */
-phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
-phys_size_t *sizep);
+fdt_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
+   fdt_size_t *sizep);

 /**
  * ofnode_read_u8_array_ptr() - find an 8-bit array
--
2.20.1



  1   2   >