[PATCH v4 06/41] doc: Document how sandbox_spl_tests are run

2021-02-06 Thread Simon Glass
Add a few notes about the sandbox_spl tests, since they are special.

Signed-off-by: Simon Glass 
Acked-by: Pratyush Yadav 
---

Changes in v4:
- Fix 'of-pldata' typo

Changes in v3:
- Reword the SPL tests section for clarity

Changes in v2:
- Add a note that SPL tests can in fact be run individualy
- Document how to run all C tests with 'ut all'
- Fix 'get list' typo

 doc/develop/testing.rst   |  5 +++
 doc/develop/tests_sandbox.rst | 82 +++
 2 files changed, 87 insertions(+)

diff --git a/doc/develop/testing.rst b/doc/develop/testing.rst
index 87c90eee271..b181c2e2e41 100644
--- a/doc/develop/testing.rst
+++ b/doc/develop/testing.rst
@@ -58,6 +58,11 @@ also select particular tests with -k::
 
./test/py/test.py --bd sandbox_flattree --build -k hello
 
+There are some special tests that run in SPL. For this you need the sandbox_spl
+build::
+
+   ./test/py/test.py --bd sandbox_spl --build -k test_spl
+
 See test/py/README.md for more information about the pytest suite.
 
 See :doc:`tests_sandbox` for how to run tests directly (not through pytest).
diff --git a/doc/develop/tests_sandbox.rst b/doc/develop/tests_sandbox.rst
index 85bbd4f6734..daf87e53a99 100644
--- a/doc/develop/tests_sandbox.rst
+++ b/doc/develop/tests_sandbox.rst
@@ -77,3 +77,85 @@ You can easily use gdb on these tests, without needing 
--gdbserver::
 
 You can then single-step and look at variables as needed.
 
+
+Running sandbox_spl tests directly
+--
+
+SPL is the phase before U-Boot proper. It is present in the sandbox_spl build,
+so you can run SPL like this::
+
+   ./spl/u-boot-spl
+
+SPL tests are special in that they run (only in the SPL phase, of course) if 
the
+-u flag is given::
+
+   ./spl/u-boot-spl -u
+
+   U-Boot SPL 2021.01-00723-g43c77b51be5-dirty (Jan 24 2021 - 16:38:24 -0700)
+   Running 5 driver model tests
+   Test: dm_test_of_plat_base: of_platdata.c (flat tree)
+   Test: dm_test_of_plat_dev: of_platdata.c (flat tree)
+   Test: dm_test_of_plat_parent: of_platdata.c (flat tree)
+   Test: dm_test_of_plat_phandle: of_platdata.c (flat tree)
+   Test: dm_test_of_plat_props: of_platdata.c (flat tree)
+   Failures: 0
+
+
+   U-Boot 2021.01-00723-g43c77b51be5-dirty (Jan 24 2021 - 16:38:24 -0700)
+
+   DRAM:  128 MiB
+   ...
+
+It is not possible to run SPL tests in U-Boot proper, firstly because they are
+not built into U-Boot proper and secondly because the environment is very
+different, e.g. some SPL tests rely on of-platdata which is only available in
+SPL.
+
+Note that after running, SPL continues to boot into U-Boot proper. You can add
+'-c exit' to make U-Boot quit without doing anything further. It is not
+currently possible to run SPL tests and then stop, since the pytests require
+that U-Boot produces the expected banner.
+
+You can use the -k flag to select which tests run::
+
+   ./spl/u-boot-spl -u -k dm_test_of_plat_parent
+
+Of course you can use gdb with sandbox_spl, just as with sandbox.
+
+
+Running all tests directly
+--
+
+A fast way to run all sandbox tests is::
+
+   ./u-boot -T -c "ut all"
+
+It typically runs single-thread in 6 seconds on 2021 hardware, with 2s of that
+to the delays in the time test.
+
+This should not be considered a substitute for 'make check', but can be helpful
+for git bisect, etc.
+
+
+What tests are built in?
+
+
+Whatever sandbox build is used, which tests are present is determined by which
+source files are built. For sandbox_spl, the of_platdata tests are built
+because of the build rule in test/dm/Makefile::
+
+   ifeq ($(CONFIG_SPL_BUILD),y)
+   obj-$(CONFIG_SPL_OF_PLATDATA) += of_platdata.o
+   else
+   ...other tests for non-spl
+   endif
+
+You can get a list of tests in a U-Boot ELF file by looking for the
+linker_list::
+
+   $ nm /tmp/b/sandbox_spl/spl/u-boot-spl |grep 2_dm_test
+   0001f200 D _u_boot_list_2_dm_test_2_dm_test_of_plat_base
+   0001f220 D _u_boot_list_2_dm_test_2_dm_test_of_plat_dev
+   0001f240 D _u_boot_list_2_dm_test_2_dm_test_of_plat_parent
+   0001f260 D _u_boot_list_2_dm_test_2_dm_test_of_plat_phandle
+   0001f280 D _u_boot_list_2_dm_test_2_dm_test_of_plat_props
-- 
2.30.0.478.g8a0d178c01-goog



Re: [PATCH 1/2] dm: core: Fix allocation of empty of-platdata

2021-02-06 Thread Simon Glass
With of-platdata we always have a dtv struct that holds the platform data
provided by the driver_info record. However, this struct can be empty if
there are no actual devicetree properties provided.

The upshot of empty platform data is that it will end up as a zero-size
member in the BSS section, which is fine. But if the driver specifies
plat_auto then it expects the correct amount of space to be allocated.

At present this does not happen, since device_bind() assumes that the
platform-data size will always be >0. As a result we end up not
allocating the space and just use the BSS region, overwriting whatever
other contents are present.

Fix this by removing the condition that platform data be non-empty, always
allocating space if requested.

This fixes a strange bug that has been lurking since of-platdata was
implemented. It has likely never been noticed since devices normally have
at least some devicetree properties, BSS is seldom used on SPL, the dtv
structs are normally at the end of bss and the overwriting only happens
if a driver changes its platform data.

It was discovered using sandbox_spl, which exercises more features than
a normal board might, and the critical global_data variable 'gd' happened
to be at the end of BSS.

Fixes: 9fa28190091 ("dm: core: Expand platdata for of-platdata devices")
Signed-off-by: Simon Glass 
---

 drivers/core/device.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 06/33] dtoc: Support scanning of uclasses

2021-02-06 Thread Simon Glass
Uclasses can have per-device private / platform data so dtoc needs to
scan these drivers. This allows it to find out the size of this data so
it can be allocated a build time.

Add a parser for uclass information, similar to drivers. Keep a dict of
the uclasses that were found.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/src_scan.py  | 122 
 tools/dtoc/test_src_scan.py |  55 
 2 files changed, 177 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 16/33] dtoc: Support headers needed for drivers

2021-02-06 Thread Simon Glass
Typically dtoc can detect the header file needed for a driver by looking
for the structs that it uses. For example, if a driver as a .priv_auto
that uses 'struct serial_priv', then dtoc can search header files for the
definition of that struct and use the file.

In some cases, enums are used in drivers, typically with the .data field
of struct udevice_id. Since dtoc does not support searching for these,
add a way to tell dtoc which header to use. This works as a macro included
in the driver definition.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/dm/device.h | 18 ++
 tools/dtoc/src_scan.py  |  7 +++
 tools/dtoc/test_src_scan.py |  4 
 3 files changed, 29 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 12/33] dtoc: Process nodes to set up required properties

2021-02-06 Thread Simon Glass
Add logic to assign property values to nodes as required by dtoc. The
references allow nodes to refer to each other in C code. The macros used
by dtoc are not yet defined in driver model. They will be added along
with the actual driver model implementation.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py | 37 +++
 tools/dtoc/src_scan.py | 11 ++
 tools/dtoc/test_dtoc.py| 76 ++
 3 files changed, 124 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 09/33] dtoc: Rename sandbox_i2c_test and sandbox_pmic_test

2021-02-06 Thread Simon Glass
These have '_test' suffixes which are not present on the drivers in the
source code. Drop the suffixes to avoid a mismatch when scanning.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/test/dtoc_test_simple.dts |  4 ++--
 tools/dtoc/test_dtoc.py  | 12 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 13/33] dtoc: Track nodes which are actually used

2021-02-06 Thread Simon Glass
Mark all nodes that are actually used, so we can perform extra checks on
them.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py  |  3 +++
 tools/dtoc/src_scan.py  | 25 ++---
 tools/dtoc/test_dtoc.py | 11 +++
 tools/dtoc/test_src_scan.py |  2 +-
 4 files changed, 37 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 15/33] Makefile: Pass the U-Boot phase to dtoc

2021-02-06 Thread Simon Glass
Pass the U-Boot phase as a parameter so dtoc can use it. At present it is
ether "spl" or "tpl".

Signed-off-by: Simon Glass 
---

(no changes since v1)

 scripts/Makefile.spl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 31/33] dtoc: Generate a summary in the dt-plat.c file

2021-02-06 Thread Simon Glass
Add a summary to the top of the generated code, to make it easier to see
what the file contains.

Also add a tab to .plat so that its value lines up with the others.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py |  20 +++-
 tools/dtoc/test_dtoc.py| 184 ++---
 2 files changed, 169 insertions(+), 35 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 23/33] dtoc: Support processing the root node

2021-02-06 Thread Simon Glass
The device for the root node is normally bound by driver model on init.
With devices being instantiated at build time, we must handle the root
device also.

Add support for processing the root node, which may not have a compatible
string.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py  | 10 --
 tools/dtoc/src_scan.py  | 39 ++---
 tools/dtoc/test_dtoc.py | 23 --
 tools/dtoc/test_src_scan.py |  7 +++
 4 files changed, 59 insertions(+), 20 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v1] fix patman --limit-cc option

2021-02-06 Thread Simon Glass
Hi Bernhard,

On Fri, 29 Jan 2021 at 07:10, Bernhard Kirchen
 wrote:
>
> patman's --limit-cc option parses its argument to an integer and uses
> that to trim the list of CC recipients to a particular maximum. but that
> only works if the cc variable is a list, which it is not.
>
> Signed-off-by: Bernhard Kirchen 
> ---
>
>  tools/patman/series.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

A test would be useful for this please as it is obviously missing...

Applied to u-boot-dm, thanks!


Re: [PATCH v2 24/33] dtoc: Add an option for device instantiation

2021-02-06 Thread Simon Glass
Add an option to instantiate devices at build time. For now this just
parses the option and sets up a few parameters.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py | 17 +++--
 tools/dtoc/main.py |  4 +++-
 tools/dtoc/test_dtoc.py| 37 ++---
 3 files changed, 36 insertions(+), 22 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 1/1] sandbox: host bind must close file descriptor

2021-02-06 Thread Simon Glass
On Tue, 2 Feb 2021 at 16:22, Heinrich Schuchardt  wrote:
>
> Each invocation of the 'host bind' command with a file name argument opens
> a file descriptor. The next invocation of the 'host bind' command destroys
> the block device but the file descriptor remains open. The same holds true
> for the 'unbind blk' command.
>
> Close the file descriptor when unbinding the host block device.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
> remove superfluous data checking
> ---
>  drivers/block/sandbox.c | 13 +
>  1 file changed, 13 insertions(+)

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH v2 27/33] dtoc: Don't generate platform data with instantiation

2021-02-06 Thread Simon Glass
This file is not used when instantiating devices. Update dtoc to skip
generating its contents and just add a comment instead.

Also it is useful to see the driver name and parent for each device.
Update the file to show that information, to avoid updating the same
tests twice.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py | 35 ++---
 tools/dtoc/test_dtoc.py| 53 +++---
 2 files changed, 75 insertions(+), 13 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 04/33] dtoc: Ignore unwanted files when scanning for drivers

2021-02-06 Thread Simon Glass
We should ignore anything in the .git directory or any of the
build-sandbox, etc. directories created by 'make check'. These can confuse
dtoc. Update the code to ignore these.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/src_scan.py  | 5 +
 tools/dtoc/test_src_scan.py | 5 -
 2 files changed, 9 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 29/33] sandbox: i2c: Rename driver names to work with of-platdata

2021-02-06 Thread Simon Glass
Some of these do not follow the rules. Make sure the driver name matches
the compatible string in all cases.

Signed-off-by: Simon Glass 
---

Changes in v2:
- New patch

 arch/sandbox/dts/test.dts | 4 ++--
 drivers/i2c/i2c-emul-uclass.c | 4 ++--
 drivers/rtc/i2c_rtc_emul.c| 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 01/33] bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT

2021-02-06 Thread Simon Glass
At present these three Kconfigs exist even when bootstage is not enabled.
This is not necessary since bootstage.c is only built if BOOTSTAGE is
enabled.

Make them conditional. Also fix up the overflow message to mention TPL.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/Kconfig.boot | 3 +++
 common/bootstage.c  | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 03/33] dtoc: Save scan information across test runs

2021-02-06 Thread Simon Glass
At present most of the tests scan the U-Boot source tree as part of their
run. This information does not change across tests, so we can save time
by remembering it.

Add a way to set up this information and use it for each test, taking a
copy first, so as not to mess up the original.

This reduces the run time from about 1.6 seconds to 1.5 seconds on my
machine. For code coverage (which cannot run in parallel), it reduces from
33 seconds to 5.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py | 11 ---
 tools/dtoc/main.py |  2 ++
 tools/dtoc/test_dtoc.py| 40 +++---
 3 files changed, 43 insertions(+), 10 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 02/33] dtoc: Scan drivers for available information

2021-02-06 Thread Simon Glass
At present we simply record the name of a driver parsed from its
implementation file. We also need to get the uclass and a few other
things so we can instantiate devices at build time. Add support for
collecting this information. This requires parsing each driver file.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/src_scan.py  | 194 ++--
 tools/dtoc/test_src_scan.py | 131 +++-
 2 files changed, 311 insertions(+), 14 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 05/33] dtoc: Collect priv/plat struct info from drivers

2021-02-06 Thread Simon Glass
In order to output variables to hold the priv/plat information used by
each device, dtoc needs to know the struct for each. With this, it can
declare this at build time:

   u8 xxx_priv [sizeof(struct )];

Collect the various struct names from the drivers.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/src_scan.py  | 25 +++--
 tools/dtoc/test_src_scan.py | 32 
 2 files changed, 55 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 07/33] dtoc: Support scanning of structs in header files

2021-02-06 Thread Simon Glass
Drivers can have private / platform data contained in structs and these
struct definitions are generally kept in header files. In order to
generate build-time devices, dtoc needs to generate code that declares
the data contained in those structs. This generated code must include the
relevant header file, to avoid a build error.

We need a way for dtoc to scan header files for struct definitions. Then,
when it wants to generate code that uses a struct, it can make sure it
includes the correct header file, first.

Add a parser for struct information, similar to drivers. Keep a dict of
the structs that were found.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/src_scan.py  | 86 +++--
 tools/dtoc/test_src_scan.py | 45 +++
 2 files changed, 128 insertions(+), 3 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 28/33] sandbox: Make sandbox,emul more conventional

2021-02-06 Thread Simon Glass
At present this property is a phandle but does not have a #xxx-cells
property to match it. Add one so that is works the same as gpio and clock
phandles.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/sandbox/dts/sandbox.dtsi | 6 +-
 doc/driver-model/pci-info.rst | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 08/33] dtoc: Move test files into a test/ directory

2021-02-06 Thread Simon Glass
It is confusing to have the test files in the same places as the
implementation. Move them into a separate directory.

Add a helper function for test_dtoc, to avoid repeating the same
path.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/{ => test}/dtoc_test.dts   |  0
 tools/dtoc/{ => test}/dtoc_test_add_prop.dts  |  0
 tools/dtoc/{ => test}/dtoc_test_addr32.dts|  0
 tools/dtoc/{ => test}/dtoc_test_addr32_64.dts |  0
 tools/dtoc/{ => test}/dtoc_test_addr64.dts|  0
 tools/dtoc/{ => test}/dtoc_test_addr64_32.dts |  0
 tools/dtoc/{ => test}/dtoc_test_aliases.dts   |  0
 tools/dtoc/{ => test}/dtoc_test_bad_reg.dts   |  0
 tools/dtoc/{ => test}/dtoc_test_bad_reg2.dts  |  0
 .../{ => test}/dtoc_test_driver_alias.dts |  0
 tools/dtoc/{ => test}/dtoc_test_empty.dts |  0
 .../{ => test}/dtoc_test_invalid_driver.dts   |  0
 tools/dtoc/{ => test}/dtoc_test_phandle.dts   |  0
 .../dtoc/{ => test}/dtoc_test_phandle_bad.dts |  0
 .../{ => test}/dtoc_test_phandle_bad2.dts |  0
 .../{ => test}/dtoc_test_phandle_cd_gpios.dts |  0
 .../{ => test}/dtoc_test_phandle_reorder.dts  |  0
 .../{ => test}/dtoc_test_phandle_single.dts   |  0
 .../{ => test}/dtoc_test_scan_drivers.cxx |  0
 tools/dtoc/{ => test}/dtoc_test_simple.dts|  0
 tools/dtoc/test_dtoc.py   |  2 +-
 tools/dtoc/test_fdt.py| 31 +--
 tools/dtoc/test_src_scan.py   |  3 +-
 23 files changed, 24 insertions(+), 12 deletions(-)
 rename tools/dtoc/{ => test}/dtoc_test.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_add_prop.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr32.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr32_64.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr64.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_addr64_32.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_aliases.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_bad_reg.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_bad_reg2.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_driver_alias.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_empty.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_invalid_driver.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_bad.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_bad2.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_cd_gpios.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_reorder.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_phandle_single.dts (100%)
 rename tools/dtoc/{ => test}/dtoc_test_scan_drivers.cxx (100%)
 rename tools/dtoc/{ => test}/dtoc_test_simple.dts (100%)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 11/33] dtoc: Make use of node properties

2021-02-06 Thread Simon Glass
Now that we have these available, use them instead of recalculating
things each time.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py | 45 --
 1 file changed, 19 insertions(+), 26 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 10/33] dtoc: Add some extra properties to nodes

2021-02-06 Thread Simon Glass
It is convenient to attach drivers, etc. to nodes so that we can use the
Node object as the main data structure in this module.

Add a function which adds the new properties, along with documentation.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py | 37 +
 1 file changed, 37 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 14/33] dtoc: Support tracking the phase of U-Boot

2021-02-06 Thread Simon Glass
U-Boot operates in several phases, typically TPL, SPL and U-Boot proper.
The latter does not use dtoc.

In some rare cases different drivers are used for two phases. For example,
in TPL it may not be necessary to use the full PCI subsystem, so a simple
driver can be used instead.

This works in the build system simply by compiling in one driver or the
other (e.g. PCI driver + uclass for SPL; simple_bus for TPL). But dtoc has
no way of knowing which code is compiled in for which phase, since it does
not inspect Makefiles or dependency graphs.

So to make this work for dtoc, we need to be able to explicitly mark
drivers with their phase. This is done by adding an empty macro to the
driver. Add support for this in dtoc.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/dm/device.h | 16 
 tools/dtoc/dtb_platdata.py  |  7 +--
 tools/dtoc/main.py  |  5 -
 tools/dtoc/src_scan.py  | 12 +++-
 tools/dtoc/test_dtoc.py | 16 
 tools/dtoc/test_src_scan.py |  3 +++
 6 files changed, 47 insertions(+), 12 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 19/33] dtoc: Read aliases for uclasses

2021-02-06 Thread Simon Glass
Scan the aliases in the device tree to establish the number of devices
within each uclass, and the sequence number of each.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py   | 28 ++
 tools/dtoc/src_scan.py   | 32 ++-
 tools/dtoc/test/dtoc_test_alias_bad.dts  | 58 
 tools/dtoc/test/dtoc_test_alias_bad_path.dts | 58 
 tools/dtoc/test/dtoc_test_alias_bad_uc.dts   | 58 
 tools/dtoc/test/dtoc_test_inst.dts   | 58 
 tools/dtoc/test_dtoc.py  | 56 ++-
 7 files changed, 345 insertions(+), 3 deletions(-)
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad.dts
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad_path.dts
 create mode 100644 tools/dtoc/test/dtoc_test_alias_bad_uc.dts
 create mode 100644 tools/dtoc/test/dtoc_test_inst.dts

Applied to u-boot-dm, thanks!


Re: [PATCH v2 18/33] dtoc: Warn of duplicate drivers

2021-02-06 Thread Simon Glass
If drivers have the same name then we cannot distinguish them. This only
matters if the driver is actually used by dtoc, but in that case, issue
a warning.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/src_scan.py  | 28 ++-
 tools/dtoc/test_src_scan.py | 95 +
 2 files changed, 122 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 17/33] dtoc: Process driver aliases along with drivers

2021-02-06 Thread Simon Glass
Instead of using a separate step for this processing, handle it while
scanning its associated driver. This allows us to drop the code coverage
exception in this case.

Note that only files containing drivers are scanned by dtoc, so aliases
declared in a file that doesn't hold a driver will not be noticed. It
would be confusing to put them anywhere other than in the driver that they
relate to, but update the documentation to say this explicitly, just in
case.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/driver-model/of-plat.rst   |  3 ++-
 tools/dtoc/src_scan.py | 16 +---
 tools/dtoc/test/dtoc_test_scan_drivers.cxx |  4 
 3 files changed, 11 insertions(+), 12 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 20/33] dtoc: Detect drivers only at the start of start of line

2021-02-06 Thread Simon Glass
If a driver declaration is included in a comment, dtoc currently gets
confused. Update the parser to only consider declarations that begin at
the start of a line. Since multi-line comments begin with an asterisk,
this avoids the problem.

Signed-off-by: Simon Glass 
---

Changes in v2:
- New patch

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

Applied to u-boot-dm, thanks!


Re: [PATCH v2 26/33] dtoc: Add support for decl file

2021-02-06 Thread Simon Glass
Add an option to generate the declaration file, which declares all
drivers and uclasses, so references can be used in the code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py | 36 +++
 tools/dtoc/test_dtoc.py| 91 +++---
 2 files changed, 120 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 21/33] dtoc: Assign a sequence number to each node

2021-02-06 Thread Simon Glass
Now that we have the alias information we can assign a sequence number
to each device in the uclass. Store this in the node associated with each
device.

This requires renaming the sandbox test drivers to have the right name.
Note that test coverage is broken with this patch, but fixed in the next
one.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/misc/test_drv.c|  6 +++--
 test/dm/test-fdt.c |  6 ++---
 tools/dtoc/dtb_platdata.py | 55 +++---
 tools/dtoc/test_dtoc.py|  6 +
 4 files changed, 53 insertions(+), 20 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 22/33] dtoc: Set up the uclasses that are used

2021-02-06 Thread Simon Glass
We only care about uclasses that are actually used. This is determined by
the drivers that use them. Check all the used drivers and build a list of
'valid' uclasses.

Also add references to the uclasses so we can generate C code that uses
them. Attach a uclass to each valid driver.

For the tests, now that we have uclasses we must create an explicit test
for the case where a node does not have one. This should only happen if
the source code does not build, or the source-code scanning fails to find
it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py  | 46 -
 tools/dtoc/src_scan.py  | 45 
 tools/dtoc/test_dtoc.py | 29 +--
 tools/dtoc/test_src_scan.py | 17 ++
 4 files changed, 119 insertions(+), 18 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 25/33] dm: of-platadata: Add option for device instantiation

2021-02-06 Thread Simon Glass
Add Kconfig options to support build-time device instantiation. When
fully implemented, this will allow dtoc to create U-Boot devices (i.e.
struct udevice records) at build time, thus reducing code space in
SPL.

For now this defaults to off, but will be enabled when the rest of
the implementation is in place.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 dts/Kconfig  | 23 +--
 scripts/Makefile.spl |  4 
 2 files changed, 25 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 30/33] dtoc: Tidy up the list of supported phandle properties

2021-02-06 Thread Simon Glass
For now dtoc only supports a hard-coded list of phandle properties, to
avoid any situation where it makes a mistake in its determination.

Make this into a constant dict, recording both the phandle property name
and the associated #cells property in the target node. This makes it
easier to find and modify.

Signed-off-by: Simon Glass 
---

Changes in v2:
- New patch

 tools/dtoc/dtb_platdata.py | 28 +---
 1 file changed, 21 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 32/33] dtoc: Generate uclass devices

2021-02-06 Thread Simon Glass
Add support for generating a file containing uclass instances. This avoids
the need to create these at run time.

Update a test uclass to include a 'priv_auto' member, to increase test
coverage.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/misc/test_drv.c|   1 +
 include/dm/test.h  |   5 ++
 tools/dtoc/dtb_platdata.py |  93 +
 tools/dtoc/test_dtoc.py| 164 ++---
 4 files changed, 250 insertions(+), 13 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 33/33] dtoc: Generate device instances

2021-02-06 Thread Simon Glass
Add support for generating a file containing udevice instances. This
avoids the need to create these at run time.

Update a test uclass to include a 'per_device_plat_auto' member, to
increase test coverage.

Add another tab to the driver_info output so it lines up nicely like the
device-instance output.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Drop patches previously applied
- Update cover letter
- Fix the naming for uclass_plat_name so it is different from uclass_priv
- Tidy up tabbing to make the code output line up better
- Add a summary to the top of the generated file

 drivers/misc/test_drv.c|   4 +
 tools/dtoc/dtb_platdata.py | 168 ++-
 tools/dtoc/test_dtoc.py| 327 +++--
 3 files changed, 484 insertions(+), 15 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 1/2] lib: Fix BINMAN_FDT dependency

2021-02-06 Thread Simon Glass
On Wed, 3 Feb 2021 at 06:20, Bin Meng  wrote:
>
> lib/binman.c references the following 3 ofnode APIs:
> ofnode_first_subnode(), ofnode_path() and ofnode_read_bool().
>
> These APIs get built only when DM is on. Fix the dependency then.
>
> Signed-off-by: Bin Meng 
> ---
>
>  lib/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 2/2] dts: Fix OF_LIVE dependency

2021-02-06 Thread Simon Glass
On Wed, 3 Feb 2021 at 06:20, Bin Meng  wrote:
>
> lib/of_live.c references the following 2 ofnode APIs:
> of_alias_scan() and of_get_property().
>
> These APIs get built only when DM is on. Fix the dependency then.
>
> Signed-off-by: Bin Meng 
> ---
>
>  dts/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH] serial: ns16550: Handle zero value

2021-02-06 Thread Simon Glass
Hi Simon,

On Thu, Feb 4, 2021 at 8:33 AM Simon Glass  wrote:
>
> On Wed, 3 Feb 2021 at 17:20, Bin Meng  wrote:
> >
> > Hi Simon,
> >
> > On Thu, Feb 4, 2021 at 5:42 AM Simon Glass  wrote:
> > >
> > > Hi Bin,
> > >
> > > On Wed, 3 Feb 2021 at 07:42, Bin Meng  wrote:
> > > >
> > > > A working device tree node of ns16550 should never be populated
> > > > with value zero for the  property. Unfortunately
> > > > this is the case for the QEMU ppce500 target.
> > > >
> > > > Let's try to assign plat->clock to CONFIG_SYS_NS16550_CLK as the
> > > > last resort to handle such case.
> > > >
> > > > This commit should be reverted when:
> > > >
> > > > - The following QEMU patch [1] is merged, and
> > > > - U-Boot CI has upgraded its QEMU version that contains the fix
> > > >
> > > > [1] 
> > > > http://patchwork.ozlabs.org/project/qemu-devel/patch/1612362288-22216-2-git-send-email-bmeng...@gmail.com/
> > > >
> > > > Signed-off-by: Bin Meng 
> > > > ---
> > > >
> > > >  drivers/serial/ns16550.c | 2 ++
> > > >  1 file changed, 2 insertions(+)
> > > >
Applied to u-boot-dm, thanks!


Re: [PATCH] serial: ns16550: Correct the base address type

2021-02-06 Thread Simon Glass
On Wed, 3 Feb 2021 at 06:22, Bin Meng  wrote:
>
> Currently ns16550_serial_assign_base() treats the argument 'base'
> with type `ulong`. This is incorrect because the base address was
> obtained from device tree with type `fdt_addr_t` that can represent
> a physical address larger than 32-bit in a 32-bit system.
>
> Fixes: 9e6ce62190b7 ("serial: ns16550: Fix ordering of getting base address")
> Signed-off-by: Bin Meng 
> ---
>
>  drivers/serial/ns16550.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 2/2] dm: core: Add DM_DEVICE_REMOVE condition to all exit paths

2021-02-06 Thread Simon Glass
At present device_bind() does some unnecessary work if a device fails to
bind in SPL. Add the missing conditions.

Also fix a style nit in the same function while we are here.

Signed-off-by: Simon Glass 
---

 drivers/core/device.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v4 8/9] fastboot: Allow u-boot-style partitions

2021-02-06 Thread Sean Anderson

On 2/6/21 12:37 PM, Lukasz Majewski wrote:

Hi Sean,


On 2/5/21 9:46 AM, Lukasz Majewski wrote:
  > Hi Sean,
  >
  >> This adds support for partitions of the form "dev.hwpart:part" and
  >> "dev#partname". This allows one to flash to eMMC boot partitions
  >> without having to use CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT. It also
  >> allows one to flash to an entire device without needing
  >> CONFIG_FASTBOOT_MMC_USER_NAME. Lastly, one can also flash MMC
  >> devices other than CONFIG_FASTBOOT_FLASH_MMC_DEV.
  >
  > This patch series causes following build errors:
  >
https://dev.azure.com/lukma633/U-Boot/_build/results?buildId=20&view=results

Yes, I saw those errors; they should be addressed in v5.

  >
  > I saw the v5 of this patch series. Could you check if it pass with
  > green the CI tests?

It is building at [1].

[1]
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=1748&view=results.



Interesting as
https://dev.azure.com/lukma633/U-Boot/_build/results?buildId=22&view=logs&j=425537f6-562f-5a62-0856-6c59be70cbe4&t=62b0f1ee-aadf-504c-f243-098b7c952989

Still shows errors after applying patch v5 version.


It looks like it's due to the following construct in fastboot.h

#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_BOOTBUS)
FASTBOOT_COMMAND_OEM_BOOTBUS,
#if CONFIG_IS_ENABLED(FASTBOOT_UUU_SUPPORT)
FASTBOOT_COMMAND_ACMD,
FASTBOOT_COMMAND_UCMD,
#endif

Which was added in 427f563 ("fastboot: add UUU command UCmd and ACmd support")

It seems like Heiko made an error while rebasing, CCing him.

--Sean



I'm using this series applied on top of Marek's usb tree:
https://github.com/lmajewski/u-boot-dfu/commits/testing

Could you look on this issue?


--Sean

  >
  > Thanks in advance,
  >
  >>
  >> Because devices can be specified explicitly,
  >> CONFIG_FASTBOOT_FLASH_MMC_DEV is used only when necessary for
  >> existing functionality. For those cases, fastboot_mmc_get_dev has
  >> been added as a helper function. This allows
  >>
  >> There should be no conflicts with the existing system, but just in
  >> case, I have ordered detection of these names after all existing
  >> names.
  >>
  >> The fastboot_mmc_part test has been updated for these new names.
  >>
  >> Signed-off-by: Sean Anderson 
  >> Reviewed-by: Simon Glass 
  >> ---
  >>
  >> Changes in v4:
  >> - Fix missing closing brace
  >>
  >>   drivers/fastboot/fb_mmc.c | 157
  >> -- test/dm/fastboot.c|
  >> 37 - 2 files changed, 132 insertions(+), 62 deletions(-)
  >>
  >> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
  >> index 71eeb02c8f..8e74e50e91 100644
  >> --- a/drivers/fastboot/fb_mmc.c
  >> +++ b/drivers/fastboot/fb_mmc.c
  >> @@ -76,12 +76,37 @@ static int raw_part_get_info_by_name(struct
  >> blk_desc *dev_desc, return 0;
  >>   }
  >>
  >> -static int part_get_info_by_name_or_alias(struct blk_desc
  >> *dev_desc,
  >> -const char *name, struct disk_partition *info)
  >> +static int do_get_part_info(struct blk_desc **dev_desc, const
  >> char *name,
  >> +struct disk_partition *info)
  >>   {
  >>  int ret;
  >>
  >> -ret = part_get_info_by_name(dev_desc, name, info);
  >> +/* First try partition names on the default device */
  >> +*dev_desc = blk_get_dev("mmc",
  >> CONFIG_FASTBOOT_FLASH_MMC_DEV);
  >> +if (*dev_desc) {
  >> +ret = part_get_info_by_name(*dev_desc, name,
  >> info);
  >> +if (ret >= 0)
  >> +return ret;
  >> +
  >> +/* Then try raw partitions */
  >> +ret = raw_part_get_info_by_name(*dev_desc, name,
  >> info);
  >> +if (ret >= 0)
  >> +return ret;
  >> +}
  >> +
  >> +/* Then try dev.hwpart:part */
  >> +ret = part_get_info_by_dev_and_name_or_num("mmc", name,
  >> dev_desc,
  >> +   info, true);
  >> +return ret;
  >> +}
  >> +
  >> +static int part_get_info_by_name_or_alias(struct blk_desc
  >> **dev_desc,
  >> +  const char *name,
  >> +  struct disk_partition
  >> *info) +{
  >> +int ret;
  >> +
  >> +ret = do_get_part_info(dev_desc, name, info);
  >>  if (ret < 0) {
  >>  /* strlen("fastboot_partition_alias_") +
  >> PART_NAME_LEN + 1 */ char env_alias_name[25 + PART_NAME_LEN + 1];
  >> @@ -92,8 +117,8 @@ static int
  >> part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
  >> strncat(env_alias_name, name, PART_NAME_LEN); aliased_part_name =
  >> env_get(env_alias_name); if (aliased_part_name != NULL)
  >> -ret = part_get_info_by_name(dev_desc,
  >> -aliased_part_name, info);
  >> +ret = do_get_part_info(dev_desc,
  >> aliased_part_name,
  >> +   info);
  >>  }
  >>  return ret;
  >>  

[PATCHv2 3/3] drivers: tee: sandbox: secure channel protocol control

2021-02-06 Thread Jorge Ramirez-Ortiz
Adds support for SCP03 emulation.

Signed-off-by: Jorge Ramirez-Ortiz 
---
 drivers/tee/optee/Kconfig |  6 
 drivers/tee/sandbox.c | 60 +--
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
index d489834df9..b7f704a5e6 100644
--- a/drivers/tee/optee/Kconfig
+++ b/drivers/tee/optee/Kconfig
@@ -22,6 +22,12 @@ config OPTEE_TA_AVB
  The TA can support the "avb" subcommands "read_rb", "write"rb"
  and "is_unlocked".
 
+config OPTEE_TA_SCP03
+   bool "Support SCP03 TA"
+   default y
+   help
+ Enables support for the SCP03 Trusted Application (TA) in OP-TEE.
+
 endmenu
 
 endif
diff --git a/drivers/tee/sandbox.c b/drivers/tee/sandbox.c
index e1ba027fd6..273c23239a 100644
--- a/drivers/tee/sandbox.c
+++ b/drivers/tee/sandbox.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * The sandbox tee driver tries to emulate a generic Trusted Exectution
@@ -32,7 +33,7 @@ struct ta_entry {
   struct tee_param *params);
 };
 
-#ifdef CONFIG_OPTEE_TA_AVB
+#if defined(CONFIG_OPTEE_TA_SCP03) || defined(CONFIG_OPTEE_TA_AVB)
 static u32 get_attr(uint n, uint num_params, struct tee_param *params)
 {
if (n >= num_params)
@@ -44,7 +45,7 @@ static u32 get_attr(uint n, uint num_params, struct tee_param 
*params)
 static u32 check_params(u8 p0, u8 p1, u8 p2, u8 p3, uint num_params,
struct tee_param *params)
 {
-   u8 p[] = { p0, p1, p2, p3};
+   u8 p[] = { p0, p1, p2, p3 };
uint n;
 
for (n = 0; n < ARRAY_SIZE(p); n++)
@@ -62,6 +63,55 @@ bad_params:
 
return TEE_ERROR_BAD_PARAMETERS;
 }
+#endif
+
+#ifdef CONFIG_OPTEE_TA_SCP03
+static u32 pta_scp03_open_session(struct udevice *dev, uint num_params,
+ struct tee_param *params)
+{
+   /*
+* We don't expect additional parameters when opening a session to
+* this TA.
+*/
+   return check_params(TEE_PARAM_ATTR_TYPE_NONE, TEE_PARAM_ATTR_TYPE_NONE,
+   TEE_PARAM_ATTR_TYPE_NONE, TEE_PARAM_ATTR_TYPE_NONE,
+   num_params, params);
+}
+
+static u32 pta_scp03_invoke_func(struct udevice *dev, u32 func, uint 
num_params,
+struct tee_param *params)
+{
+   u32 res;
+   static bool enabled;
+
+   switch (func) {
+   case PTA_CMD_ENABLE_SCP03:
+   res = check_params(TEE_PARAM_ATTR_TYPE_VALUE_INPUT,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  num_params, params);
+   if (res)
+   return res;
+
+   if (!enabled) {
+   printf("SCP03 enabled\n");
+   enabled = true;
+   } else {
+   printf("SCP03 already enabled, no action\n");
+   }
+
+   if (params[0].u.value.a)
+   printf("SCP03 keys rotated\n");
+
+   return TEE_SUCCESS;
+   default:
+   return TEE_ERROR_NOT_SUPPORTED;
+   }
+}
+#endif
+
+#ifdef CONFIG_OPTEE_TA_AVB
 
 static u32 ta_avb_open_session(struct udevice *dev, uint num_params,
   struct tee_param *params)
@@ -223,6 +273,12 @@ static const struct ta_entry ta_entries[] = {
  .invoke_func = ta_avb_invoke_func,
},
 #endif
+#ifdef CONFIG_OPTEE_TA_SCP03
+   { .uuid = PTA_SCP03_UUID,
+ .open_session = pta_scp03_open_session,
+ .invoke_func = pta_scp03_invoke_func,
+   },
+#endif
 };
 
 static void sandbox_tee_get_version(struct udevice *dev,
-- 
2.30.0



[PATCHv2 2/3] cmd: SCP03: enable and provision command

2021-02-06 Thread Jorge Ramirez-Ortiz
Enable and provision the SCP03 keys on a TEE controlled secured elemt
from the U-Boot shell.

Signed-off-by: Jorge Ramirez-Ortiz 
---
 cmd/Kconfig  |  9 
 cmd/Makefile |  3 +++
 cmd/scp03.c  | 64 
 3 files changed, 76 insertions(+)
 create mode 100644 cmd/scp03.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 928a2a0a2d..4f990249b4 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2021,6 +2021,15 @@ config HASH_VERIFY
help
  Add -v option to verify data against a hash.
 
+config CMD_SCP03
+   bool "scp03 - SCP03 enable and rotate/provision operations"
+   depends on SCP03
+   help
+ Enables the SCP03 commands to activate I2C channel encryption and
+ provision the SCP03 keys.
+   scp03 enable
+   scp03 provision
+
 config CMD_TPM_V1
bool
 
diff --git a/cmd/Makefile b/cmd/Makefile
index 176bf925fd..a7017e8452 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -193,6 +193,9 @@ obj-$(CONFIG_CMD_BLOB) += blob.o
 # Android Verified Boot 2.0
 obj-$(CONFIG_CMD_AVB) += avb.o
 
+# Foundries.IO SCP03
+obj-$(CONFIG_CMD_SCP03) += scp03.o
+
 obj-$(CONFIG_ARM) += arm/
 obj-$(CONFIG_RISCV) += riscv/
 obj-$(CONFIG_SANDBOX) += sandbox/
diff --git a/cmd/scp03.c b/cmd/scp03.c
new file mode 100644
index 00..07913dbd3e
--- /dev/null
+++ b/cmd/scp03.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+int do_scp03_enable(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   if (argc != 1)
+   return CMD_RET_USAGE;
+
+   if (tee_enable_scp03())
+   return CMD_RET_FAILURE;
+
+   return CMD_RET_SUCCESS;
+}
+
+int do_scp03_provision(struct cmd_tbl *cmdtp, int flag, int argc,
+  char *const argv[])
+{
+   if (argc != 1)
+   return CMD_RET_USAGE;
+
+   if (tee_provision_scp03())
+   return CMD_RET_FAILURE;
+
+   return CMD_RET_SUCCESS;
+}
+
+static struct cmd_tbl cmd_scp03[] = {
+   U_BOOT_CMD_MKENT(enable, 1, 0, do_scp03_enable, "", ""),
+   U_BOOT_CMD_MKENT(provision, 1, 0, do_scp03_provision, "", ""),
+};
+
+static int do_scp03(struct cmd_tbl *cmdtp, int flag, int argc,
+   char * const argv[])
+{
+   struct cmd_tbl *cp;
+
+   cp = find_cmd_tbl(argv[1], cmd_scp03, ARRAY_SIZE(cmd_scp03));
+
+   argc--;
+   argv++;
+
+   if (!cp || argc > cp->maxargs)
+   return CMD_RET_USAGE;
+
+   if (flag == CMD_FLAG_REPEAT)
+   return CMD_RET_FAILURE;
+
+   return cp->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(scp03, 2, 0, do_scp03,
+  "Provides a command to enable SCP03 and provision the SCP03 keys\n",
+  "\tenable- enable SCP03\n"
+  "\tprovision - provision SCP03\n"
+);
-- 
2.30.0



[PATCHv2 1/3] common: SCP03 control (enable and provision of keys)

2021-02-06 Thread Jorge Ramirez-Ortiz
This Trusted Application allows enabling and provisioning SCP03 keys
on TEE controlled secure element (ie, NXP SE050)

For information on SCP03, check the Global Platform HomePage[1]
[1] globalplatform.org

Signed-off-by: Jorge Ramirez-Ortiz 
---
 common/Kconfig   |  8 ++
 common/Makefile  |  1 +
 common/scp03.c   | 52 
 include/scp03.h  | 19 +
 include/tee/optee_ta_scp03.h | 21 +++
 5 files changed, 101 insertions(+)
 create mode 100644 common/scp03.c
 create mode 100644 include/scp03.h
 create mode 100644 include/tee/optee_ta_scp03.h

diff --git a/common/Kconfig b/common/Kconfig
index 2bb3798f80..482f123534 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -588,6 +588,14 @@ config AVB_BUF_SIZE
 
 endif # AVB_VERIFY
 
+config SCP03
+   bool "Build SCP03 - Secure Channel Protocol O3 - controls"
+   depends on OPTEE || SANDBOX
+   depends on TEE
+   help
+ This option allows U-Boot to enable and or provision SCP03 on an OPTEE
+ controlled Secured Element.
+
 config SPL_HASH
bool # "Support hashing API (SHA1, SHA256, etc.)"
help
diff --git a/common/Makefile b/common/Makefile
index daeea67cf2..215b8b26fd 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -137,3 +137,4 @@ obj-$(CONFIG_CMD_LOADB) += xyzModem.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
 
 obj-$(CONFIG_AVB_VERIFY) += avb_verify.o
+obj-$(CONFIG_SCP03) += scp03.o
diff --git a/common/scp03.c b/common/scp03.c
new file mode 100644
index 00..c655283387
--- /dev/null
+++ b/common/scp03.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+
+#include 
+#include 
+#include 
+
+static int scp03_enable(bool provision)
+{
+   const struct tee_optee_ta_uuid uuid = PTA_SCP03_UUID;
+   struct tee_open_session_arg session;
+   struct tee_invoke_arg invoke;
+   struct tee_param param;
+   struct udevice *tee = NULL;
+
+   tee = tee_find_device(tee, NULL, NULL, NULL);
+   if (!tee)
+   return -ENODEV;
+
+   memset(&session, 0, sizeof(session));
+   tee_optee_ta_uuid_to_octets(session.uuid, &uuid);
+   if (tee_open_session(tee, &session, 0, NULL))
+   return -ENODEV;
+
+   memset(¶m, 0, sizeof(param));
+   param.attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
+   param.u.value.a = provision;
+
+   memset(&invoke, 0, sizeof(invoke));
+   invoke.func = PTA_CMD_ENABLE_SCP03;
+   invoke.session = session.session;
+
+   if (tee_invoke_func(tee, &invoke, 1, ¶m))
+   return -EIO;
+
+   tee_close_session(tee, session.session);
+
+   return 0;
+}
+
+int tee_enable_scp03(void)
+{
+   return scp03_enable(false);
+}
+
+int tee_provision_scp03(void)
+{
+   return scp03_enable(true);
+}
diff --git a/include/scp03.h b/include/scp03.h
new file mode 100644
index 00..034796ada3
--- /dev/null
+++ b/include/scp03.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+
+#ifndef _SCP03_H
+#define _SCP03_H
+
+/*
+ * Requests to OPTEE to enable or provision the Secure Channel Protocol on its
+ * Secure Element
+ *
+ *  If key provisioning is requested, OPTEE shall generate new SCP03 keys and
+ *  write them to the Secure Element.
+ */
+int tee_enable_scp03(void);
+int tee_provision_scp03(void);
+#endif /* _SCP03_H */
diff --git a/include/tee/optee_ta_scp03.h b/include/tee/optee_ta_scp03.h
new file mode 100644
index 00..13f9956d98
--- /dev/null
+++ b/include/tee/optee_ta_scp03.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+#ifndef __TA_SCP03_H
+#define __TA_SCP03_H
+
+#define PTA_SCP03_UUID { 0xbe0e5821, 0xe718, 0x4f77, \
+   { 0xab, 0x3e, 0x8e, 0x6c, 0x73, 0xa9, 0xc7, 0x35 } }
+
+/*
+ * Enable Secure Channel Protocol functionality (SCP03) on the Secure Element.
+ *   Setting the operation value to something different than NULL will trigger
+ *   the SCP03 provisioning request.
+ *
+ *   inparams[0].a = operation
+ */
+#define PTA_CMD_ENABLE_SCP03   0
+
+#endif /*__TA_SCP03_H*/
-- 
2.30.0



[PATCH 1/3] common: SCP03 control (enable and provision of keys)

2021-02-06 Thread Jorge Ramirez-Ortiz
This Trusted Application allows enabling and provisioning SCP03 keys
on TEE controlled secure element (ie, NXP SE050)

For information on SCP03, check the Global Platform HomePage[1]
[1] globalplatform.org

Signed-off-by: Jorge Ramirez-Ortiz 
---
 common/Kconfig   |  8 ++
 common/Makefile  |  1 +
 common/scp03.c   | 52 
 include/scp03.h  | 19 +
 include/tee/optee_ta_scp03.h | 21 +++
 5 files changed, 101 insertions(+)
 create mode 100644 common/scp03.c
 create mode 100644 include/scp03.h
 create mode 100644 include/tee/optee_ta_scp03.h

diff --git a/common/Kconfig b/common/Kconfig
index 2bb3798f80..482f123534 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -588,6 +588,14 @@ config AVB_BUF_SIZE
 
 endif # AVB_VERIFY
 
+config SCP03
+   bool "Build SCP03 - Secure Channel Protocol O3 - controls"
+   depends on OPTEE || SANDBOX
+   depends on TEE
+   help
+ This option allows U-Boot to enable and or provision SCP03 on an OPTEE
+ controlled Secured Element.
+
 config SPL_HASH
bool # "Support hashing API (SHA1, SHA256, etc.)"
help
diff --git a/common/Makefile b/common/Makefile
index daeea67cf2..215b8b26fd 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -137,3 +137,4 @@ obj-$(CONFIG_CMD_LOADB) += xyzModem.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
 
 obj-$(CONFIG_AVB_VERIFY) += avb_verify.o
+obj-$(CONFIG_SCP03) += scp03.o
diff --git a/common/scp03.c b/common/scp03.c
new file mode 100644
index 00..c655283387
--- /dev/null
+++ b/common/scp03.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+
+#include 
+#include 
+#include 
+
+static int scp03_enable(bool provision)
+{
+   const struct tee_optee_ta_uuid uuid = PTA_SCP03_UUID;
+   struct tee_open_session_arg session;
+   struct tee_invoke_arg invoke;
+   struct tee_param param;
+   struct udevice *tee = NULL;
+
+   tee = tee_find_device(tee, NULL, NULL, NULL);
+   if (!tee)
+   return -ENODEV;
+
+   memset(&session, 0, sizeof(session));
+   tee_optee_ta_uuid_to_octets(session.uuid, &uuid);
+   if (tee_open_session(tee, &session, 0, NULL))
+   return -ENODEV;
+
+   memset(¶m, 0, sizeof(param));
+   param.attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT;
+   param.u.value.a = provision;
+
+   memset(&invoke, 0, sizeof(invoke));
+   invoke.func = PTA_CMD_ENABLE_SCP03;
+   invoke.session = session.session;
+
+   if (tee_invoke_func(tee, &invoke, 1, ¶m))
+   return -EIO;
+
+   tee_close_session(tee, session.session);
+
+   return 0;
+}
+
+int tee_enable_scp03(void)
+{
+   return scp03_enable(false);
+}
+
+int tee_provision_scp03(void)
+{
+   return scp03_enable(true);
+}
diff --git a/include/scp03.h b/include/scp03.h
new file mode 100644
index 00..034796ada3
--- /dev/null
+++ b/include/scp03.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+
+#ifndef _SCP03_H
+#define _SCP03_H
+
+/*
+ * Requests to OPTEE to enable or provision the Secure Channel Protocol on its
+ * Secure Element
+ *
+ *  If key provisioning is requested, OPTEE shall generate new SCP03 keys and
+ *  write them to the Secure Element.
+ */
+int tee_enable_scp03(void);
+int tee_provision_scp03(void);
+#endif /* _SCP03_H */
diff --git a/include/tee/optee_ta_scp03.h b/include/tee/optee_ta_scp03.h
new file mode 100644
index 00..13f9956d98
--- /dev/null
+++ b/include/tee/optee_ta_scp03.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+#ifndef __TA_SCP03_H
+#define __TA_SCP03_H
+
+#define PTA_SCP03_UUID { 0xbe0e5821, 0xe718, 0x4f77, \
+   { 0xab, 0x3e, 0x8e, 0x6c, 0x73, 0xa9, 0xc7, 0x35 } }
+
+/*
+ * Enable Secure Channel Protocol functionality (SCP03) on the Secure Element.
+ *   Setting the operation value to something different than NULL will trigger
+ *   the SCP03 provisioning request.
+ *
+ *   inparams[0].a = operation
+ */
+#define PTA_CMD_ENABLE_SCP03   0
+
+#endif /*__TA_SCP03_H*/
-- 
2.30.0



[PATCH 3/3] drivers: tee: sandbox: secure channel protocol control

2021-02-06 Thread Jorge Ramirez-Ortiz
Adds support for SCP03 emulation.

Signed-off-by: Jorge Ramirez-Ortiz 
---
 drivers/tee/optee/Kconfig |  6 
 drivers/tee/sandbox.c | 60 +--
 2 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
index d489834df9..b7f704a5e6 100644
--- a/drivers/tee/optee/Kconfig
+++ b/drivers/tee/optee/Kconfig
@@ -22,6 +22,12 @@ config OPTEE_TA_AVB
  The TA can support the "avb" subcommands "read_rb", "write"rb"
  and "is_unlocked".
 
+config OPTEE_TA_SCP03
+   bool "Support SCP03 TA"
+   default y
+   help
+ Enables support for the SCP03 Trusted Application (TA) in OP-TEE.
+
 endmenu
 
 endif
diff --git a/drivers/tee/sandbox.c b/drivers/tee/sandbox.c
index e1ba027fd6..273c23239a 100644
--- a/drivers/tee/sandbox.c
+++ b/drivers/tee/sandbox.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * The sandbox tee driver tries to emulate a generic Trusted Exectution
@@ -32,7 +33,7 @@ struct ta_entry {
   struct tee_param *params);
 };
 
-#ifdef CONFIG_OPTEE_TA_AVB
+#if defined(CONFIG_OPTEE_TA_SCP03) || defined(CONFIG_OPTEE_TA_AVB)
 static u32 get_attr(uint n, uint num_params, struct tee_param *params)
 {
if (n >= num_params)
@@ -44,7 +45,7 @@ static u32 get_attr(uint n, uint num_params, struct tee_param 
*params)
 static u32 check_params(u8 p0, u8 p1, u8 p2, u8 p3, uint num_params,
struct tee_param *params)
 {
-   u8 p[] = { p0, p1, p2, p3};
+   u8 p[] = { p0, p1, p2, p3 };
uint n;
 
for (n = 0; n < ARRAY_SIZE(p); n++)
@@ -62,6 +63,55 @@ bad_params:
 
return TEE_ERROR_BAD_PARAMETERS;
 }
+#endif
+
+#ifdef CONFIG_OPTEE_TA_SCP03
+static u32 pta_scp03_open_session(struct udevice *dev, uint num_params,
+ struct tee_param *params)
+{
+   /*
+* We don't expect additional parameters when opening a session to
+* this TA.
+*/
+   return check_params(TEE_PARAM_ATTR_TYPE_NONE, TEE_PARAM_ATTR_TYPE_NONE,
+   TEE_PARAM_ATTR_TYPE_NONE, TEE_PARAM_ATTR_TYPE_NONE,
+   num_params, params);
+}
+
+static u32 pta_scp03_invoke_func(struct udevice *dev, u32 func, uint 
num_params,
+struct tee_param *params)
+{
+   u32 res;
+   static bool enabled;
+
+   switch (func) {
+   case PTA_CMD_ENABLE_SCP03:
+   res = check_params(TEE_PARAM_ATTR_TYPE_VALUE_INPUT,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  num_params, params);
+   if (res)
+   return res;
+
+   if (!enabled) {
+   printf("SCP03 enabled\n");
+   enabled = true;
+   } else {
+   printf("SCP03 already enabled, no action\n");
+   }
+
+   if (params[0].u.value.a)
+   printf("SCP03 keys rotated\n");
+
+   return TEE_SUCCESS;
+   default:
+   return TEE_ERROR_NOT_SUPPORTED;
+   }
+}
+#endif
+
+#ifdef CONFIG_OPTEE_TA_AVB
 
 static u32 ta_avb_open_session(struct udevice *dev, uint num_params,
   struct tee_param *params)
@@ -223,6 +273,12 @@ static const struct ta_entry ta_entries[] = {
  .invoke_func = ta_avb_invoke_func,
},
 #endif
+#ifdef CONFIG_OPTEE_TA_SCP03
+   { .uuid = PTA_SCP03_UUID,
+ .open_session = pta_scp03_open_session,
+ .invoke_func = pta_scp03_invoke_func,
+   },
+#endif
 };
 
 static void sandbox_tee_get_version(struct udevice *dev,
-- 
2.30.0



[PATCH 2/3] cmd: SCP03: enable and provision command

2021-02-06 Thread Jorge Ramirez-Ortiz
Enable and provision the SCP03 keys on a TEE controlled secured elemt
from the U-Boot shell.

Signed-off-by: Jorge Ramirez-Ortiz 
---
 cmd/Kconfig  |  9 
 cmd/Makefile |  3 +++
 cmd/scp03.c  | 64 
 3 files changed, 76 insertions(+)
 create mode 100644 cmd/scp03.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 928a2a0a2d..4f990249b4 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2021,6 +2021,15 @@ config HASH_VERIFY
help
  Add -v option to verify data against a hash.
 
+config CMD_SCP03
+   bool "scp03 - SCP03 enable and rotate/provision operations"
+   depends on SCP03
+   help
+ Enables the SCP03 commands to activate I2C channel encryption and
+ provision the SCP03 keys.
+   scp03 enable
+   scp03 provision
+
 config CMD_TPM_V1
bool
 
diff --git a/cmd/Makefile b/cmd/Makefile
index 176bf925fd..a7017e8452 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -193,6 +193,9 @@ obj-$(CONFIG_CMD_BLOB) += blob.o
 # Android Verified Boot 2.0
 obj-$(CONFIG_CMD_AVB) += avb.o
 
+# Foundries.IO SCP03
+obj-$(CONFIG_CMD_SCP03) += scp03.o
+
 obj-$(CONFIG_ARM) += arm/
 obj-$(CONFIG_RISCV) += riscv/
 obj-$(CONFIG_SANDBOX) += sandbox/
diff --git a/cmd/scp03.c b/cmd/scp03.c
new file mode 100644
index 00..07913dbd3e
--- /dev/null
+++ b/cmd/scp03.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2021, Foundries.IO
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+int do_scp03_enable(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   if (argc != 1)
+   return CMD_RET_USAGE;
+
+   if (tee_enable_scp03())
+   return CMD_RET_FAILURE;
+
+   return CMD_RET_SUCCESS;
+}
+
+int do_scp03_provision(struct cmd_tbl *cmdtp, int flag, int argc,
+  char *const argv[])
+{
+   if (argc != 1)
+   return CMD_RET_USAGE;
+
+   if (tee_provision_scp03())
+   return CMD_RET_FAILURE;
+
+   return CMD_RET_SUCCESS;
+}
+
+static struct cmd_tbl cmd_scp03[] = {
+   U_BOOT_CMD_MKENT(enable, 1, 0, do_scp03_enable, "", ""),
+   U_BOOT_CMD_MKENT(provision, 1, 0, do_scp03_provision, "", ""),
+};
+
+static int do_scp03(struct cmd_tbl *cmdtp, int flag, int argc,
+   char * const argv[])
+{
+   struct cmd_tbl *cp;
+
+   cp = find_cmd_tbl(argv[1], cmd_scp03, ARRAY_SIZE(cmd_scp03));
+
+   argc--;
+   argv++;
+
+   if (!cp || argc > cp->maxargs)
+   return CMD_RET_USAGE;
+
+   if (flag == CMD_FLAG_REPEAT)
+   return CMD_RET_FAILURE;
+
+   return cp->cmd(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(scp03, 2, 0, do_scp03,
+  "Provides a command to enable SCP03 and provision the SCP03 keys\n",
+  "\tenable- enable SCP03\n"
+  "\tprovision - provision SCP03\n"
+);
-- 
2.30.0



[PATCH] drivers: tee: sandbox: secure channel protocol control

2021-02-06 Thread Jorge Ramirez-Ortiz
Adds support for SCP03 emulation.

Signed-off-by: Jorge Ramirez-Ortiz 
---
 drivers/tee/optee/Kconfig |  6 
 drivers/tee/sandbox.c | 59 +--
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig
index d489834df9..b7f704a5e6 100644
--- a/drivers/tee/optee/Kconfig
+++ b/drivers/tee/optee/Kconfig
@@ -22,6 +22,12 @@ config OPTEE_TA_AVB
  The TA can support the "avb" subcommands "read_rb", "write"rb"
  and "is_unlocked".
 
+config OPTEE_TA_SCP03
+   bool "Support SCP03 TA"
+   default y
+   help
+ Enables support for the SCP03 Trusted Application (TA) in OP-TEE.
+
 endmenu
 
 endif
diff --git a/drivers/tee/sandbox.c b/drivers/tee/sandbox.c
index e1ba027fd6..5ad5ddf588 100644
--- a/drivers/tee/sandbox.c
+++ b/drivers/tee/sandbox.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * The sandbox tee driver tries to emulate a generic Trusted Exectution
@@ -32,7 +33,7 @@ struct ta_entry {
   struct tee_param *params);
 };
 
-#ifdef CONFIG_OPTEE_TA_AVB
+#if defined(CONFIG_OPTEE_TA_SCP03) || defined(CONFIG_OPTEE_TA_AVB)
 static u32 get_attr(uint n, uint num_params, struct tee_param *params)
 {
if (n >= num_params)
@@ -44,7 +45,7 @@ static u32 get_attr(uint n, uint num_params, struct tee_param 
*params)
 static u32 check_params(u8 p0, u8 p1, u8 p2, u8 p3, uint num_params,
struct tee_param *params)
 {
-   u8 p[] = { p0, p1, p2, p3};
+   u8 p[] = { p0, p1, p2, p3 };
uint n;
 
for (n = 0; n < ARRAY_SIZE(p); n++)
@@ -62,6 +63,54 @@ bad_params:
 
return TEE_ERROR_BAD_PARAMETERS;
 }
+#endif
+
+#ifdef CONFIG_OPTEE_TA_SCP03
+static u32 pta_scp03_open_session(struct udevice *dev, uint num_params,
+ struct tee_param *params)
+{
+   /*
+* We don't expect additional parameters when opening a session to
+* this TA.
+*/
+   return check_params(TEE_PARAM_ATTR_TYPE_NONE, TEE_PARAM_ATTR_TYPE_NONE,
+   TEE_PARAM_ATTR_TYPE_NONE, TEE_PARAM_ATTR_TYPE_NONE,
+   num_params, params);
+}
+
+static u32 pta_scp03_invoke_func(struct udevice *dev, u32 func, uint 
num_params,
+struct tee_param *params)
+{
+   u32 res;
+   static bool enabled;
+
+   switch (func) {
+   case PTA_CMD_ENABLE_SCP03:
+   res = check_params(TEE_PARAM_ATTR_TYPE_VALUE_INPUT,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  TEE_PARAM_ATTR_TYPE_NONE,
+  num_params, params);
+   if (res)
+   return res;
+
+   if (!enabled) {
+   printf("SCP03 enabled\n");
+   enabled = true;
+   } else
+   printf("SCP03 already enabled, no action\n");
+
+   if (params[0].u.value.a)
+   printk("SCP03 keys rotated\n");
+
+   return TEE_SUCCESS;
+   default:
+   return TEE_ERROR_NOT_SUPPORTED;
+   }
+}
+#endif
+
+#ifdef CONFIG_OPTEE_TA_AVB
 
 static u32 ta_avb_open_session(struct udevice *dev, uint num_params,
   struct tee_param *params)
@@ -223,6 +272,12 @@ static const struct ta_entry ta_entries[] = {
  .invoke_func = ta_avb_invoke_func,
},
 #endif
+#ifdef CONFIG_OPTEE_TA_SCP03
+   { .uuid = PTA_SCP03_UUID,
+ .open_session = pta_scp03_open_session,
+ .invoke_func = pta_scp03_invoke_func,
+   },
+#endif
 };
 
 static void sandbox_tee_get_version(struct udevice *dev,
-- 
2.30.0



[PATCH v4 11/11] tpm: Allow disabling platform hierarchy with TPM2

2021-02-06 Thread Simon Glass
With TPM2 we don't actually lock the TPM once verified boot is finished.
Instead we disable the platform hierarchy which serves the same purpose.
Add an implementation of this so we can safely boot into the kernel.

Signed-off-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---

(no changes since v2)

Changes in v2:
- Add definition of TPM2_RC_NV_DEFINED return code

 include/tpm-v2.h | 13 +
 lib/tpm-v2.c | 35 +++
 2 files changed, 48 insertions(+)

diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 1ca1e7e2011..e18c8b1ccca 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -235,6 +235,7 @@ enum tpm2_handles {
 enum tpm2_command_codes {
TPM2_CC_STARTUP = 0x0144,
TPM2_CC_SELF_TEST   = 0x0143,
+   TPM2_CC_HIER_CONTROL= 0x0121,
TPM2_CC_CLEAR   = 0x0126,
TPM2_CC_CLEARCONTROL= 0x0127,
TPM2_CC_HIERCHANGEAUTH  = 0x0129,
@@ -272,6 +273,7 @@ enum tpm2_return_codes {
TPM2_RC_COMMAND_CODE= TPM2_RC_VER1 + 0x0043,
TPM2_RC_AUTHSIZE= TPM2_RC_VER1 + 0x0044,
TPM2_RC_AUTH_CONTEXT= TPM2_RC_VER1 + 0x0045,
+   TPM2_RC_NV_DEFINED  = TPM2_RC_VER1 + 0x004c,
TPM2_RC_NEEDS_TEST  = TPM2_RC_VER1 + 0x0053,
TPM2_RC_WARN= 0x0900,
TPM2_RC_TESTING = TPM2_RC_WARN + 0x000A,
@@ -582,4 +584,15 @@ u32 tpm2_get_random(struct udevice *dev, void *data, u32 
count);
  */
 u32 tpm2_write_lock(struct udevice *dev, u32 index);
 
+/**
+ * Disable access to any platform data
+ *
+ * This can be called to close off access to the firmware data in the data,
+ * before calling the kernel.
+ *
+ * @devTPM device
+ * @return code of the operation
+ */
+u32 tpm2_disable_platform_hierarchy(struct udevice *dev);
+
 #endif /* __TPM_V2_H */
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index b796004930e..235f8c20d43 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -624,3 +624,38 @@ u32 tpm2_write_lock(struct udevice *dev, u32 index)
 
return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
+
+u32 tpm2_disable_platform_hierarchy(struct udevice *dev)
+{
+   struct tpm_chip_priv *priv = dev_get_uclass_priv(dev);
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
+   tpm_u32(10 + 4 + 13 + 5),   /* Length */
+   tpm_u32(TPM2_CC_HIER_CONTROL),  /* Command code */
+
+   /* 4 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
+
+   /* session header 9 bytes */
+   tpm_u32(9), /* Header size */
+   tpm_u32(TPM2_RS_PW),/* Password authorisation */
+   tpm_u16(0), /* nonce_size */
+   0,  /* session_attrs */
+   tpm_u16(0), /* auth_size */
+
+   /* payload 5 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Hierarchy to disable */
+   0,  /* 0=disable */
+   };
+   int ret;
+
+   ret = tpm_sendrecv_command(dev, command_v2, NULL, NULL);
+   log_info("ret=%s, %x\n", dev->name, ret);
+   if (ret)
+   return ret;
+
+   priv->plat_hier_disabled = true;
+
+   return 0;
+}
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 05/11] tpm: Switch TPMv1 over to use the new API

2021-02-06 Thread Simon Glass
Take over the plain 'tpm_...' functions for use by the new TPM API. Rename
all the TPMv1 functions so they are called from the API.

Update the TPMv1 functions so that they are called from the API. Change
existing users to use the tpm1_ prefix so they don't need to go through
the API, which might introduce uncertainty.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 board/gdsys/a38x/controlcenterdc.c|   4 +-
 board/gdsys/a38x/hre.c|  28 +++
 board/gdsys/a38x/keyprogram.c |   8 +-
 board/gdsys/mpc8308/gazerbeam.c   |   4 +-
 board/gdsys/p1022/controlcenterd-id.c |  36 
 cmd/tpm-v1.c  |  25 +++---
 cmd/tpm_test.c|  40 +
 include/tpm-v1.h  |  76 -
 lib/Makefile  |   1 +
 lib/tpm-v1.c  | 115 --
 10 files changed, 168 insertions(+), 169 deletions(-)

diff --git a/board/gdsys/a38x/controlcenterdc.c 
b/board/gdsys/a38x/controlcenterdc.c
index a2287f9deb1..187ac8c4f9f 100644
--- a/board/gdsys/a38x/controlcenterdc.c
+++ b/board/gdsys/a38x/controlcenterdc.c
@@ -286,8 +286,8 @@ int last_stage_init(void)
ccdc_eth_init();
 #endif
ret = get_tpm(&tpm);
-   if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
-   tpm_continue_self_test(tpm)) {
+   if (ret || tpm_init(tpm) || tpm1_startup(tpm, TPM_ST_CLEAR) ||
+   tpm1_continue_self_test(tpm)) {
return 1;
}
 
diff --git a/board/gdsys/a38x/hre.c b/board/gdsys/a38x/hre.c
index 699241b3e62..de5411a6b93 100644
--- a/board/gdsys/a38x/hre.c
+++ b/board/gdsys/a38x/hre.c
@@ -107,8 +107,8 @@ static int get_tpm_nv_size(struct udevice *tpm, uint32_t 
index, uint32_t *size)
uint8_t *ptr;
uint16_t v16;
 
-   err = tpm_get_capability(tpm, TPM_CAP_NV_INDEX, index,
-info, sizeof(info));
+   err = tpm1_get_capability(tpm, TPM_CAP_NV_INDEX, index, info,
+ sizeof(info));
if (err) {
printf("tpm_get_capability(CAP_NV_INDEX, %08x) failed: %u\n",
   index, err);
@@ -150,8 +150,8 @@ static int find_key(struct udevice *tpm, const uint8_t 
auth[20],
unsigned int i;
 
/* fetch list of already loaded keys in the TPM */
-   err = tpm_get_capability(tpm, TPM_CAP_HANDLE, TPM_RT_KEY, buf,
-sizeof(buf));
+   err = tpm1_get_capability(tpm, TPM_CAP_HANDLE, TPM_RT_KEY, buf,
+ sizeof(buf));
if (err)
return -1;
key_count = get_unaligned_be16(buf);
@@ -162,8 +162,8 @@ static int find_key(struct udevice *tpm, const uint8_t 
auth[20],
/* now search a(/ the) key which we can access with the given auth */
for (i = 0; i < key_count; ++i) {
buf_len = sizeof(buf);
-   err = tpm_get_pub_key_oiap(tpm, key_handles[i], auth, buf,
-  &buf_len);
+   err = tpm1_get_pub_key_oiap(tpm, key_handles[i], auth, buf,
+   &buf_len);
if (err && err != TPM_AUTHFAIL)
return -1;
if (err)
@@ -192,8 +192,8 @@ static int read_common_data(struct udevice *tpm)
if (get_tpm_nv_size(tpm, NV_COMMON_DATA_INDEX, &size) ||
size < NV_COMMON_DATA_MIN_SIZE)
return 1;
-   err = tpm_nv_read_value(tpm, NV_COMMON_DATA_INDEX,
-   buf, min(sizeof(buf), size));
+   err = tpm1_nv_read_value(tpm, NV_COMMON_DATA_INDEX, buf,
+min(sizeof(buf), size));
if (err) {
printf("tpm_nv_read_value() failed: %u\n", err);
return 1;
@@ -270,8 +270,8 @@ static struct h_reg *access_hreg(struct udevice *tpm, 
uint8_t spec,
if (mode & HREG_RD) {
if (!result->valid) {
if (IS_PCR_HREG(spec)) {
-   hre_tpm_err = tpm_pcr_read(tpm, HREG_IDX(spec),
-   result->digest, 20);
+   hre_tpm_err = tpm1_pcr_read(tpm, HREG_IDX(spec),
+   result->digest, 20);
result->valid = (hre_tpm_err == TPM_SUCCESS);
} else if (IS_FIX_HREG(spec)) {
switch (HREG_IDX(spec)) {
@@ -357,8 +357,8 @@ static int hre_op_loadkey(struct udevice *tpm, struct h_reg 
*src_reg,
return -1;
if (find_key(tpm, src_reg->digest, dst_reg->digest, &parent_handle))
return -1;
-   hre_tpm_err = tpm_load_key2_oiap(tpm, parent_handle, key, key_size,
-src_reg->digest, &key_handle);
+   hre_tpm_err = tpm1_load_

[PATCH v4 10/11] tpm: Add TPM2 support for write_lock

2021-02-06 Thread Simon Glass
Implement this API function for TPM2.

Signed-off-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---

(no changes since v1)

 include/tpm-v2.h | 12 
 lib/tpm-v2.c | 23 +++
 lib/tpm_api.c|  2 +-
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 6a400771af1..1ca1e7e2011 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -241,6 +241,7 @@ enum tpm2_command_codes {
TPM2_CC_NV_DEFINE_SPACE = 0x012a,
TPM2_CC_PCR_SETAUTHPOL  = 0x012C,
TPM2_CC_NV_WRITE= 0x0137,
+   TPM2_CC_NV_WRITELOCK= 0x0138,
TPM2_CC_DAM_RESET   = 0x0139,
TPM2_CC_DAM_PARAMETERS  = 0x013A,
TPM2_CC_NV_READ = 0x014E,
@@ -570,4 +571,15 @@ u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char 
*pw,
  */
 u32 tpm2_get_random(struct udevice *dev, void *data, u32 count);
 
+/**
+ * Lock data in the TPM
+ *
+ * Once locked the data cannot be written until after a reboot
+ *
+ * @devTPM device
+ * @index  Index of data to lock
+ * @return code of the operation
+ */
+u32 tpm2_write_lock(struct udevice *dev, u32 index);
+
 #endif /* __TPM_V2_H */
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 9f1699131e1..b796004930e 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -601,3 +601,26 @@ u32 tpm2_get_random(struct udevice *dev, void *data, u32 
count)
 
return 0;
 }
+
+u32 tpm2_write_lock(struct udevice *dev, u32 index)
+{
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
+   tpm_u32(10 + 8 + 13), /* Length */
+   tpm_u32(TPM2_CC_NV_WRITELOCK), /* Command code */
+
+   /* handles 8 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
+   tpm_u32(HR_NV_INDEX + index),   /* Password authorisation */
+
+   /* session header 9 bytes */
+   tpm_u32(9), /* Header size */
+   tpm_u32(TPM2_RS_PW),/* Password authorisation */
+   tpm_u16(0), /* nonce_size */
+   0,  /* session_attrs */
+   tpm_u16(0), /* auth_size */
+   };
+
+   return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
+}
diff --git a/lib/tpm_api.c b/lib/tpm_api.c
index 687fc8bc7ee..4c662640a92 100644
--- a/lib/tpm_api.c
+++ b/lib/tpm_api.c
@@ -144,7 +144,7 @@ u32 tpm_write_lock(struct udevice *dev, u32 index)
if (is_tpm1(dev))
return -ENOSYS;
else if (is_tpm2(dev))
-   return -ENOSYS;
+   return tpm2_write_lock(dev, index);
else
return -ENOSYS;
 }
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 09/11] tpm: Add TPM2 support for read/write values

2021-02-06 Thread Simon Glass
Implement this API function for TPM2.

Signed-off-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---

(no changes since v1)

 include/tpm-common.h |  3 ++
 include/tpm-v2.h | 38 
 lib/tpm-v2.c | 84 
 lib/tpm_api.c|  4 +--
 4 files changed, 127 insertions(+), 2 deletions(-)

diff --git a/include/tpm-common.h b/include/tpm-common.h
index e29b10b1766..080183779b3 100644
--- a/include/tpm-common.h
+++ b/include/tpm-common.h
@@ -53,6 +53,8 @@ enum tpm_version {
  * @buf:   Buffer used during the exchanges with the chip
  * @pcr_count: Number of PCR per bank
  * @pcr_select_min:Minimum size in bytes of the pcrSelect array
+ * @plat_hier_disabled:Platform hierarchy has been disabled (TPM is 
locked
+ * down until next reboot)
  */
 struct tpm_chip_priv {
enum tpm_version version;
@@ -64,6 +66,7 @@ struct tpm_chip_priv {
/* TPM v2 specific data */
uint pcr_count;
uint pcr_select_min;
+   bool plat_hier_disabled;
 };
 
 /**
diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index 2766dc72a65..6a400771af1 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -240,6 +240,7 @@ enum tpm2_command_codes {
TPM2_CC_HIERCHANGEAUTH  = 0x0129,
TPM2_CC_NV_DEFINE_SPACE = 0x012a,
TPM2_CC_PCR_SETAUTHPOL  = 0x012C,
+   TPM2_CC_NV_WRITE= 0x0137,
TPM2_CC_DAM_RESET   = 0x0139,
TPM2_CC_DAM_PARAMETERS  = 0x013A,
TPM2_CC_NV_READ = 0x014E,
@@ -354,6 +355,20 @@ enum {
TPM_MAX_BUF_SIZE= 1260,
 };
 
+enum {
+   /* Secure storage for firmware settings */
+   TPM_HT_PCR = 0,
+   TPM_HT_NV_INDEX,
+   TPM_HT_HMAC_SESSION,
+   TPM_HT_POLICY_SESSION,
+
+   HR_SHIFT= 24,
+   HR_PCR  = TPM_HT_PCR << HR_SHIFT,
+   HR_HMAC_SESSION = TPM_HT_HMAC_SESSION << HR_SHIFT,
+   HR_POLICY_SESSION   = TPM_HT_POLICY_SESSION << HR_SHIFT,
+   HR_NV_INDEX = TPM_HT_NV_INDEX << HR_SHIFT,
+};
+
 /**
  * Issue a TPM2_Startup command.
  *
@@ -418,6 +433,29 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 
space_index,
 u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
const u8 *digest, u32 digest_len);
 
+/**
+ * Read data from the secure storage
+ *
+ * @devTPM device
+ * @index  Index of data to read
+ * @data   Place to put data
+ * @count  Number of bytes of data
+ * @return code of the operation
+ */
+u32 tpm2_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count);
+
+/**
+ * Write data to the secure storage
+ *
+ * @devTPM device
+ * @index  Index of data to write
+ * @data   Data to write
+ * @count  Number of bytes of data
+ * @return code of the operation
+ */
+u32 tpm2_nv_write_value(struct udevice *dev, u32 index, const void *data,
+   u32 count);
+
 /**
  * Issue a TPM2_PCR_Read command.
  *
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index e9bf4018fed..9f1699131e1 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -169,6 +169,90 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 
algorithm,
return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
+u32 tpm2_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count)
+{
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
+   tpm_u32(10 + 8 + 4 + 9 + 4),/* Length */
+   tpm_u32(TPM2_CC_NV_READ),   /* Command code */
+
+   /* handles 8 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
+   tpm_u32(HR_NV_INDEX + index),   /* Password authorisation */
+
+   /* AUTH_SESSION */
+   tpm_u32(9), /* Authorization size */
+   tpm_u32(TPM2_RS_PW),/* Session handle */
+   tpm_u16(0), /* Size of  */
+   /*  (if any) */
+   0,  /* Attributes: Cont/Excl/Rst */
+   tpm_u16(0), /* Size of  */
+   /*  (if any) */
+
+   tpm_u16(count), /* Number of bytes */
+   tpm_u16(0), /* Offset */
+   };
+   size_t response_len = COMMAND_BUFFER_SIZE;
+   u8 response[COMMAND_BUFFER_SIZE];
+   int ret;
+   u16 tag;
+   u32 size, code;
+
+   ret = tpm_sendrecv_command(dev, command_v2, response, &response_len);
+   if (ret)
+   return log_msg_ret("read", ret);
+   if (unpack_byte_string(response, response_len, "wdds",
+  0, &tag, 2, &size, 6, &code,
+   

[PATCH v4 08/11] tpm: Add an implementation of define_space

2021-02-06 Thread Simon Glass
Add support for this so that the TPM can be set up for use with
Chromium OS verified boot.

Signed-off-by: Simon Glass 
---

Changes in v4:
- Drop unnecessary update of offset

Changes in v3:
- Add a comment to the offset and fix up the value

 include/tpm-v2.h | 18 ++
 lib/tpm-v2.c | 47 +++
 2 files changed, 65 insertions(+)

diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index fab6b86ca2f..2766dc72a65 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -238,6 +238,7 @@ enum tpm2_command_codes {
TPM2_CC_CLEAR   = 0x0126,
TPM2_CC_CLEARCONTROL= 0x0127,
TPM2_CC_HIERCHANGEAUTH  = 0x0129,
+   TPM2_CC_NV_DEFINE_SPACE = 0x012a,
TPM2_CC_PCR_SETAUTHPOL  = 0x012C,
TPM2_CC_DAM_RESET   = 0x0139,
TPM2_CC_DAM_PARAMETERS  = 0x013A,
@@ -386,6 +387,23 @@ u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no 
full_test);
 u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
   const ssize_t pw_sz);
 
+/**
+ * Issue a TPM_NV_DefineSpace command
+ *
+ * This allows a space to be defined with given attributes and policy
+ *
+ * @devTPM device
+ * @space_indexindex of the area
+ * @space_size size of area in bytes
+ * @nv_attributes  TPM_NV_ATTRIBUTES of the area
+ * @nv_policy  policy to use
+ * @nv_policy_size size of the policy
+ * @return return code of the operation
+ */
+u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index,
+size_t space_size, u32 nv_attributes,
+const u8 *nv_policy, size_t nv_policy_size);
+
 /**
  * Issue a TPM2_PCR_Extend command.
  *
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index c4e869ec5b5..e9bf4018fed 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -81,6 +81,53 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char 
*pw,
return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
+u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index,
+size_t space_size, u32 nv_attributes,
+const u8 *nv_policy, size_t nv_policy_size)
+{
+   /*
+* Calculate the offset of the nv_policy piece by adding each of the
+* chunks below.
+*/
+   uint offset = 10 + 8 + 13 + 14;
+   u8 command_v2[COMMAND_BUFFER_SIZE] = {
+   /* header 10 bytes */
+   tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
+   tpm_u32(offset + nv_policy_size),/* Length */
+   tpm_u32(TPM2_CC_NV_DEFINE_SPACE),/* Command code */
+
+   /* handles 8 bytes */
+   tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
+
+   /* session header 13 bytes */
+   tpm_u32(9), /* Header size */
+   tpm_u32(TPM2_RS_PW),/* Password authorisation */
+   tpm_u16(0), /* nonce_size */
+   0,  /* session_attrs */
+   tpm_u16(0), /* auth_size */
+
+   /* message 14 bytes + policy */
+   tpm_u16(12 + nv_policy_size),   /* size */
+   tpm_u32(space_index),
+   tpm_u16(TPM2_ALG_SHA256),
+   tpm_u32(nv_attributes),
+   tpm_u16(nv_policy_size),
+   /* nv_policy */
+   };
+   int ret;
+
+   /*
+* Fill the command structure starting from the first buffer:
+* - the password (if any)
+*/
+   ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
+  offset, nv_policy, nv_policy_size);
+   if (ret)
+   return TPM_LIB_ERROR;
+
+   return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
+}
+
 u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
const u8 *digest, u32 digest_len)
 {
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 07/11] tpm: Reduce duplication in a few functions

2021-02-06 Thread Simon Glass
Update tpm2_clear() and tpm2_pcr_extend() so that the command size
is not repeated twice. Add a small comment to the latter.

Signed-off-by: Simon Glass 
Reviewed-by: Ilias Apalodimas 
---

(no changes since v2)

Changes in v2:
- Add comments for the offset value

 lib/tpm-v2.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 1f3deb06e48..c4e869ec5b5 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -47,9 +47,11 @@ u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no 
full_test)
 u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
   const ssize_t pw_sz)
 {
+   /* Length of the message header, up to start of password */
+   uint offset = 27;
u8 command_v2[COMMAND_BUFFER_SIZE] = {
tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
-   tpm_u32(27 + pw_sz),/* Length */
+   tpm_u32(offset + pw_sz),/* Length */
tpm_u32(TPM2_CC_CLEAR), /* Command code */
 
/* HANDLE */
@@ -64,7 +66,6 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char 
*pw,
tpm_u16(pw_sz), /* Size of  */
/* STRING(pw)   (if any) */
};
-   unsigned int offset = 27;
int ret;
 
/*
@@ -83,9 +84,11 @@ u32 tpm2_clear(struct udevice *dev, u32 handle, const char 
*pw,
 u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
const u8 *digest, u32 digest_len)
 {
+   /* Length of the message header, up to start of digest */
+   uint offset = 33;
u8 command_v2[COMMAND_BUFFER_SIZE] = {
tpm_u16(TPM2_ST_SESSIONS),  /* TAG */
-   tpm_u32(33 + digest_len),   /* Length */
+   tpm_u32(offset + digest_len),   /* Length */
tpm_u32(TPM2_CC_PCR_EXTEND),/* Command code */
 
/* HANDLE */
@@ -99,11 +102,12 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 
algorithm,
0,  /* Attributes: Cont/Excl/Rst */
tpm_u16(0), /* Size of  */
/*  (if any) */
+
+   /* hashes */
tpm_u32(1), /* Count (number of hashes) */
tpm_u16(algorithm), /* Algorithm of the hash */
/* STRING(digest)  Digest */
};
-   unsigned int offset = 33;
int ret;
 
/*
@@ -112,7 +116,6 @@ u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 
algorithm,
 */
ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
   offset, digest, digest_len);
-   offset += digest_len;
if (ret)
return TPM_LIB_ERROR;
 
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 04/11] tpm: Add an API that can support v1.2 and v2

2021-02-06 Thread Simon Glass
There are two different TPM standards. U-Boot supports both but each has
its own set of functions. We really need a single TPM API that can call
one or the other. This is not always possible as there are some
differences between the two standards, but it is mostly possible.

Add an API to handle this. So far it is not plumbed into the build and
only supports TPMv1.

Signed-off-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---

(no changes since v1)

 include/tpm_api.h | 322 ++
 lib/tpm_api.c | 215 +++
 2 files changed, 537 insertions(+)
 create mode 100644 include/tpm_api.h
 create mode 100644 lib/tpm_api.c

diff --git a/include/tpm_api.h b/include/tpm_api.h
new file mode 100644
index 000..f13d98cae47
--- /dev/null
+++ b/include/tpm_api.h
@@ -0,0 +1,322 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2013 The Chromium OS Authors.
+ * Coypright (c) 2013 Guntermann & Drunck GmbH
+ */
+
+#ifndef __TPM_API_H
+#define __TPM_API_H
+
+#include 
+#include 
+#include 
+
+/**
+ * Issue a TPM_Startup command.
+ *
+ * @param dev  TPM device
+ * @param mode TPM startup mode
+ * @return return code of the operation
+ */
+u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode);
+
+/**
+ * Issue a TPM_SelfTestFull command.
+ *
+ * @param dev  TPM device
+ * @return return code of the operation
+ */
+u32 tpm_self_test_full(struct udevice *dev);
+
+/**
+ * Issue a TPM_ContinueSelfTest command.
+ *
+ * @param dev  TPM device
+ * @return return code of the operation
+ */
+u32 tpm_continue_self_test(struct udevice *dev);
+
+/**
+ * Issue a TPM_NV_DefineSpace command.  The implementation is limited
+ * to specify TPM_NV_ATTRIBUTES and size of the area.  The area index
+ * could be one of the special value listed in enum tpm_nv_index.
+ *
+ * @param dev  TPM device
+ * @param indexindex of the area
+ * @param perm TPM_NV_ATTRIBUTES of the area
+ * @param size size of the area
+ * @return return code of the operation
+ */
+u32 tpm_nv_define_space(struct udevice *dev, u32 index, u32 perm, u32 size);
+
+/**
+ * Issue a TPM_NV_ReadValue command.  This implementation is limited
+ * to read the area from offset 0.  The area index could be one of
+ * the special value listed in enum tpm_nv_index.
+ *
+ * @param dev  TPM device
+ * @param indexindex of the area
+ * @param data output buffer of the area contents
+ * @param countsize of output buffer
+ * @return return code of the operation
+ */
+u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count);
+
+/**
+ * Issue a TPM_NV_WriteValue command.  This implementation is limited
+ * to write the area from offset 0.  The area index could be one of
+ * the special value listed in enum tpm_nv_index.
+ *
+ * @param dev  TPM device
+ * @param indexindex of the area
+ * @param data input buffer to be wrote to the area
+ * @param length   length of data bytes of input buffer
+ * @return return code of the operation
+ */
+u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
+  u32 length);
+
+/**
+ * Issue a TPM_Extend command.
+ *
+ * @param dev  TPM device
+ * @param indexindex of the PCR
+ * @param in_digest160-bit value representing the event to be
+ * recorded
+ * @param out_digest   160-bit PCR value after execution of the
+ * command
+ * @return return code of the operation
+ */
+u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest,
+  void *out_digest);
+
+/**
+ * Issue a TPM_PCRRead command.
+ *
+ * @param dev  TPM device
+ * @param indexindex of the PCR
+ * @param data output buffer for contents of the named PCR
+ * @param countsize of output buffer
+ * @return return code of the operation
+ */
+u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count);
+
+/**
+ * Issue a TSC_PhysicalPresence command.  TPM physical presence flag
+ * is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
+ *
+ * @param dev  TPM device
+ * @param presence TPM physical presence flag
+ * @return return code of the operation
+ */
+u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence);
+
+/**
+ * Issue a TPM_ReadPubek command.
+ *
+ * @param dev  TPM device
+ * @param data output buffer for the public endorsement key
+ * @param countsize of output buffer
+ * @return return code of the operation
+ */
+u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count);
+
+/**
+ * Issue a TPM_ForceClear command.
+ *
+ * @param dev  TPM device
+ * @return return code of the operation
+ */
+u32 tpm_force_clear(struct udevice *dev);
+
+/**
+ * Issue a TPM_Ph

[PATCH v4 02/11] tpm: Use logging in the uclass

2021-02-06 Thread Simon Glass
Update this to use log_debug() instead of the old debug().

Signed-off-by: Simon Glass 
Reviewed-by: Ilias Apalodimas 
---

(no changes since v1)

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

diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
index beb0fa3f93c..35774a6289e 100644
--- a/drivers/tpm/tpm-uclass.c
+++ b/drivers/tpm/tpm-uclass.c
@@ -4,6 +4,8 @@
  * Written by Simon Glass 
  */
 
+#define LOG_CATEGORY UCLASS_TPM
+
 #include 
 #include 
 #include 
@@ -87,15 +89,15 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, 
size_t send_size,
ordinal = get_unaligned_be32(sendbuf + TPM_CMD_ORDINAL_BYTE);
 
if (count == 0) {
-   debug("no data\n");
+   log_debug("no data\n");
return -ENODATA;
}
if (count > send_size) {
-   debug("invalid count value %x %zx\n", count, send_size);
+   log_debug("invalid count value %x %zx\n", count, send_size);
return -E2BIG;
}
 
-   debug("%s: Calling send\n", __func__);
+   log_debug("%s: Calling send\n", __func__);
ret = ops->send(dev, sendbuf, send_size);
if (ret < 0)
return ret;
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 06/11] tpm: Add a basic API implementation for TPMv2

2021-02-06 Thread Simon Glass
Add support for TPMv2 versions of API functions. So far this is not
complete as the standard is quite large, but it implements everything
currently available for TPMv2 in U-Boot.

Signed-off-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---

(no changes since v1)

 lib/tpm_api.c | 84 ++-
 1 file changed, 77 insertions(+), 7 deletions(-)

diff --git a/lib/tpm_api.c b/lib/tpm_api.c
index 758350bd18d..f1553512cc5 100644
--- a/lib/tpm_api.c
+++ b/lib/tpm_api.c
@@ -16,18 +16,41 @@ static bool is_tpm1(struct udevice *dev)
return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1;
 }
 
+static bool is_tpm2(struct udevice *dev)
+{
+   return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2;
+}
+
 u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode)
 {
-   if (is_tpm1(dev))
+   if (is_tpm1(dev)) {
return tpm1_startup(dev, mode);
-   else
+   } else if (is_tpm2(dev)) {
+   enum tpm2_startup_types type;
+
+   switch (mode) {
+   case TPM_ST_CLEAR:
+   type = TPM2_SU_CLEAR;
+   break;
+   case TPM_ST_STATE:
+   type = TPM2_SU_STATE;
+   break;
+   default:
+   case TPM_ST_DEACTIVATED:
+   return -EINVAL;
+   }
+   return tpm2_startup(dev, type);
+   } else {
return -ENOSYS;
+   }
 }
 
 u32 tpm_resume(struct udevice *dev)
 {
if (is_tpm1(dev))
return tpm1_startup(dev, TPM_ST_STATE);
+   else if (is_tpm2(dev))
+   return tpm2_startup(dev, TPM2_SU_STATE);
else
return -ENOSYS;
 }
@@ -36,6 +59,8 @@ u32 tpm_self_test_full(struct udevice *dev)
 {
if (is_tpm1(dev))
return tpm1_self_test_full(dev);
+   else if (is_tpm2(dev))
+   return tpm2_self_test(dev, TPMI_YES);
else
return -ENOSYS;
 }
@@ -44,6 +69,8 @@ u32 tpm_continue_self_test(struct udevice *dev)
 {
if (is_tpm1(dev))
return tpm1_continue_self_test(dev);
+   else if (is_tpm2(dev))
+   return tpm2_self_test(dev, TPMI_NO);
else
return -ENOSYS;
 }
@@ -71,8 +98,6 @@ u32 tpm_clear_and_reenable(struct udevice *dev)
log_err("TPM: Can't set deactivated state\n");
return ret;
}
-   } else {
-   return -ENOSYS;
}
 
return TPM_SUCCESS;
@@ -82,6 +107,8 @@ u32 tpm_nv_enable_locking(struct udevice *dev)
 {
if (is_tpm1(dev))
return tpm1_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0);
+   else if (is_tpm2(dev))
+   return -ENOSYS;
else
return -ENOSYS;
 }
@@ -90,6 +117,8 @@ u32 tpm_nv_read_value(struct udevice *dev, u32 index, void 
*data, u32 count)
 {
if (is_tpm1(dev))
return tpm1_nv_read_value(dev, index, data, count);
+   else if (is_tpm2(dev))
+   return -ENOSYS;
else
return -ENOSYS;
 }
@@ -99,6 +128,8 @@ u32 tpm_nv_write_value(struct udevice *dev, u32 index, const 
void *data,
 {
if (is_tpm1(dev))
return tpm1_nv_write_value(dev, index, data, count);
+   else if (is_tpm2(dev))
+   return -ENOSYS;
else
return -ENOSYS;
 }
@@ -112,6 +143,8 @@ u32 tpm_write_lock(struct udevice *dev, u32 index)
 {
if (is_tpm1(dev))
return -ENOSYS;
+   else if (is_tpm2(dev))
+   return -ENOSYS;
else
return -ENOSYS;
 }
@@ -121,6 +154,9 @@ u32 tpm_pcr_extend(struct udevice *dev, u32 index, const 
void *in_digest,
 {
if (is_tpm1(dev))
return tpm1_extend(dev, index, in_digest, out_digest);
+   else if (is_tpm2(dev))
+   return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest,
+  TPM2_DIGEST_LEN);
else
return -ENOSYS;
 }
@@ -129,6 +165,8 @@ u32 tpm_pcr_read(struct udevice *dev, u32 index, void 
*data, size_t count)
 {
if (is_tpm1(dev))
return tpm1_pcr_read(dev, index, data, count);
+   else if (is_tpm2(dev))
+   return -ENOSYS;
else
return -ENOSYS;
 }
@@ -137,6 +175,13 @@ u32 tpm_tsc_physical_presence(struct udevice *dev, u16 
presence)
 {
if (is_tpm1(dev))
return tpm1_tsc_physical_presence(dev, presence);
+
+   /*
+* Nothing to do on TPM2 for this; use platform hierarchy availability
+* instead.
+*/
+   else if (is_tpm2(dev))
+   return 0;
else
return -ENOSYS;
 }
@@ -145,6 +190,10 @@ u32 tpm_finalise_physical_presence(struct udevice *dev)
 {
if (is_tpm1(dev))

[PATCH v4 03/11] tpm: Add debugging of request in tpm_sendrecv_command()

2021-02-06 Thread Simon Glass
The response is shown but not the request. Update the code to show both
if debugging is enabled.

Use a 'uint' type for size so it matches the register-word size on both
32- and 64-bit machines.

Signed-off-by: Simon Glass 
---

Changes in v4:
- Use uint type for size and explain it in the commit message

 lib/tpm-common.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/tpm-common.c b/lib/tpm-common.c
index e4af87f76aa..4277846fdd0 100644
--- a/lib/tpm-common.c
+++ b/lib/tpm-common.c
@@ -166,6 +166,7 @@ u32 tpm_sendrecv_command(struct udevice *dev, const void 
*command,
u8 response_buffer[COMMAND_BUFFER_SIZE];
size_t response_length;
int i;
+   uint size;
 
if (response) {
response_length = *size_ptr;
@@ -174,8 +175,13 @@ u32 tpm_sendrecv_command(struct udevice *dev, const void 
*command,
response_length = sizeof(response_buffer);
}
 
-   err = tpm_xfer(dev, command, tpm_command_size(command),
-  response, &response_length);
+   size = tpm_command_size(command);
+   log_debug("TPM request [size:%d]: ", size);
+   for (i = 0; i < size; i++)
+   log_debug("%02x ", ((u8 *)command)[i]);
+   log_debug("\n");
+
+   err = tpm_xfer(dev, command, size, response, &response_length);
 
if (err < 0)
return err;
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 01/11] tpm: Don't include cr50 in TPL/SPL

2021-02-06 Thread Simon Glass
At present the security chip is not used in these U-Boot phases. Update
the Makefile to exclude it.

Fix a few logging statements while we are here.

Signed-off-by: Simon Glass 
Reviewed-by: Ilias Apalodimas 
---

(no changes since v1)

 drivers/tpm/Makefile   | 2 +-
 drivers/tpm/cr50_i2c.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
index 8f075b9f45f..f64d20067f8 100644
--- a/drivers/tpm/Makefile
+++ b/drivers/tpm/Makefile
@@ -10,7 +10,7 @@ obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o
 obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o
 obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o
 
-obj-$(CONFIG_TPM2_CR50_I2C) += cr50_i2c.o
+obj-$(CONFIG_$(SPL_TPL_)TPM2_CR50_I2C) += cr50_i2c.o
 obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o
 obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o
 obj-$(CONFIG_TPM2_FTPM_TEE) += tpm2_ftpm_tee.o
diff --git a/drivers/tpm/cr50_i2c.c b/drivers/tpm/cr50_i2c.c
index b103a6fdc39..76432bdec1f 100644
--- a/drivers/tpm/cr50_i2c.c
+++ b/drivers/tpm/cr50_i2c.c
@@ -309,7 +309,7 @@ static int cr50_i2c_recv(struct udevice *dev, u8 *buf, 
size_t buf_len)
int status;
int ret;
 
-   log_debug("%s: len=%x\n", __func__, buf_len);
+   log_debug("%s: buf_len=%x\n", __func__, buf_len);
if (buf_len < TPM_HEADER_SIZE)
return -E2BIG;
 
@@ -386,7 +386,7 @@ static int cr50_i2c_send(struct udevice *dev, const u8 
*buf, size_t len)
ulong timeout;
int ret;
 
-   log_debug("%s: len=%x\n", __func__, len);
+   log_debug("len=%x\n", len);
timeout = timer_get_us() + TIMEOUT_LONG_US;
do {
ret = cr50_i2c_status(dev);
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 00/11] tpm: Support using TPM1 and TPM2 from a single API

2021-02-06 Thread Simon Glass
At present if an application wants to be written so it can work with
both TPMv1.2 and TPM2 it must use two different APIs. This is inconvenient
since it requires adding code to deal with the mismatch between the two.
It would be better to have a common API that all boards could share.

This series provides a simple API the covers some basic features and
implements them for both TPM standards.

Changes in v4:
- Use uint type for size and explain it in the commit message
- Drop unnecessary update of offset

Changes in v3:
- Add a comment to the offset and fix up the value

Changes in v2:
- Add comments for the offset value
- Add definition of TPM2_RC_NV_DEFINED return code

Simon Glass (11):
  tpm: Don't include cr50 in TPL/SPL
  tpm: Use logging in the uclass
  tpm: Add debugging of request in tpm_sendrecv_command()
  tpm: Add an API that can support v1.2 and v2
  tpm: Switch TPMv1 over to use the new API
  tpm: Add a basic API implementation for TPMv2
  tpm: Reduce duplication in a few functions
  tpm: Add an implementation of define_space
  tpm: Add TPM2 support for read/write values
  tpm: Add TPM2 support for write_lock
  tpm: Allow disabling platform hierarchy with TPM2

 board/gdsys/a38x/controlcenterdc.c|   4 +-
 board/gdsys/a38x/hre.c|  28 +--
 board/gdsys/a38x/keyprogram.c |   8 +-
 board/gdsys/mpc8308/gazerbeam.c   |   4 +-
 board/gdsys/p1022/controlcenterd-id.c |  36 +--
 cmd/tpm-v1.c  |  25 +-
 cmd/tpm_test.c|  40 ++--
 drivers/tpm/Makefile  |   2 +-
 drivers/tpm/cr50_i2c.c|   4 +-
 drivers/tpm/tpm-uclass.c  |   8 +-
 include/tpm-common.h  |   3 +
 include/tpm-v1.h  |  76 +++---
 include/tpm-v2.h  |  81 +++
 include/tpm_api.h | 322 ++
 lib/Makefile  |   1 +
 lib/tpm-common.c  |  10 +-
 lib/tpm-v1.c  | 115 +
 lib/tpm-v2.c  | 202 +++-
 lib/tpm_api.c | 285 +++
 19 files changed, 1072 insertions(+), 182 deletions(-)
 create mode 100644 include/tpm_api.h
 create mode 100644 lib/tpm_api.c

-- 
2.30.0.478.g8a0d178c01-goog



Re: [PATCH v4 8/9] fastboot: Allow u-boot-style partitions

2021-02-06 Thread Lukasz Majewski
Hi Sean,

> On 2/5/21 9:46 AM, Lukasz Majewski wrote:
>  > Hi Sean,
>  >  
>  >> This adds support for partitions of the form "dev.hwpart:part" and
>  >> "dev#partname". This allows one to flash to eMMC boot partitions
>  >> without having to use CONFIG_FASTBOOT_MMC_BOOT1_SUPPORT. It also
>  >> allows one to flash to an entire device without needing
>  >> CONFIG_FASTBOOT_MMC_USER_NAME. Lastly, one can also flash MMC
>  >> devices other than CONFIG_FASTBOOT_FLASH_MMC_DEV.  
>  >
>  > This patch series causes following build errors:
>  >   
> https://dev.azure.com/lukma633/U-Boot/_build/results?buildId=20&view=results
> 
> Yes, I saw those errors; they should be addressed in v5.
> 
>  >
>  > I saw the v5 of this patch series. Could you check if it pass with
>  > green the CI tests?  
> 
> It is building at [1].
> 
> [1] 
> https://dev.azure.com/u-boot/u-boot/_build/results?buildId=1748&view=results.
> 

Interesting as 
https://dev.azure.com/lukma633/U-Boot/_build/results?buildId=22&view=logs&j=425537f6-562f-5a62-0856-6c59be70cbe4&t=62b0f1ee-aadf-504c-f243-098b7c952989

Still shows errors after applying patch v5 version.

I'm using this series applied on top of Marek's usb tree:
https://github.com/lmajewski/u-boot-dfu/commits/testing

Could you look on this issue?

> --Sean
> 
>  >
>  > Thanks in advance,
>  >  
>  >>
>  >> Because devices can be specified explicitly,
>  >> CONFIG_FASTBOOT_FLASH_MMC_DEV is used only when necessary for
>  >> existing functionality. For those cases, fastboot_mmc_get_dev has
>  >> been added as a helper function. This allows
>  >>
>  >> There should be no conflicts with the existing system, but just in
>  >> case, I have ordered detection of these names after all existing
>  >> names.
>  >>
>  >> The fastboot_mmc_part test has been updated for these new names.
>  >>
>  >> Signed-off-by: Sean Anderson 
>  >> Reviewed-by: Simon Glass 
>  >> ---
>  >>
>  >> Changes in v4:
>  >> - Fix missing closing brace
>  >>
>  >>   drivers/fastboot/fb_mmc.c | 157
>  >> -- test/dm/fastboot.c|
>  >> 37 - 2 files changed, 132 insertions(+), 62 deletions(-)
>  >>
>  >> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
>  >> index 71eeb02c8f..8e74e50e91 100644
>  >> --- a/drivers/fastboot/fb_mmc.c
>  >> +++ b/drivers/fastboot/fb_mmc.c
>  >> @@ -76,12 +76,37 @@ static int raw_part_get_info_by_name(struct
>  >> blk_desc *dev_desc, return 0;
>  >>   }
>  >>
>  >> -static int part_get_info_by_name_or_alias(struct blk_desc
>  >> *dev_desc,
>  >> - const char *name, struct disk_partition *info)
>  >> +static int do_get_part_info(struct blk_desc **dev_desc, const
>  >> char *name,
>  >> + struct disk_partition *info)
>  >>   {
>  >>   int ret;
>  >>
>  >> - ret = part_get_info_by_name(dev_desc, name, info);
>  >> + /* First try partition names on the default device */
>  >> + *dev_desc = blk_get_dev("mmc",
>  >> CONFIG_FASTBOOT_FLASH_MMC_DEV);
>  >> + if (*dev_desc) {
>  >> + ret = part_get_info_by_name(*dev_desc, name,
>  >> info);
>  >> + if (ret >= 0)
>  >> + return ret;
>  >> +
>  >> + /* Then try raw partitions */
>  >> + ret = raw_part_get_info_by_name(*dev_desc, name,
>  >> info);
>  >> + if (ret >= 0)
>  >> + return ret;
>  >> + }
>  >> +
>  >> + /* Then try dev.hwpart:part */
>  >> + ret = part_get_info_by_dev_and_name_or_num("mmc", name,
>  >> dev_desc,
>  >> +info, true);
>  >> + return ret;
>  >> +}
>  >> +
>  >> +static int part_get_info_by_name_or_alias(struct blk_desc
>  >> **dev_desc,
>  >> +   const char *name,
>  >> +   struct disk_partition
>  >> *info) +{
>  >> + int ret;
>  >> +
>  >> + ret = do_get_part_info(dev_desc, name, info);
>  >>   if (ret < 0) {
>  >>   /* strlen("fastboot_partition_alias_") +
>  >> PART_NAME_LEN + 1 */ char env_alias_name[25 + PART_NAME_LEN + 1];
>  >> @@ -92,8 +117,8 @@ static int
>  >> part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
>  >> strncat(env_alias_name, name, PART_NAME_LEN); aliased_part_name =
>  >> env_get(env_alias_name); if (aliased_part_name != NULL)
>  >> - ret = part_get_info_by_name(dev_desc,
>  >> - aliased_part_name, info);
>  >> + ret = do_get_part_info(dev_desc,
>  >> aliased_part_name,
>  >> +info);
>  >>   }
>  >>   return ret;
>  >>   }
>  >> @@ -430,27 +455,49 @@ int fastboot_mmc_get_part_info(const char
>  >> *part_name, struct blk_desc **dev_desc,
>  >>  struct disk_partition *part_info,
>  >> char *response) {
>  >> - int r = 0;
>  >> + int ret;
>  >>
>  >> - *dev_desc = blk_get_dev("mmc",
>  >> CONFIG_FASTBOOT_FLASH_MMC_DEV);
>  >> - if (!*dev_desc) {
>  >> -

[PATCH v4 8/9] sandbox: Write out bloblist when exiting

2021-02-06 Thread Simon Glass
Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass 
---

Changes in v4:
- Fix 'existing' typo

 arch/sandbox/cpu/state.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index 4ffaf163789..f63cfd38ee4 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -4,6 +4,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -398,8 +399,12 @@ int state_uninit(void)
 {
int err;
 
+   log_info("Writing sandbox state\n");
state = &main_state;
 
+   /* Finish the bloblist, so that it is correct before writing memory */
+   bloblist_finish();
+
if (state->write_ram_buf) {
err = os_write_ram_buf(state->ram_buf_fname);
if (err) {
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 7/9] sandbox: Avoid using malloc() for system state

2021-02-06 Thread Simon Glass
This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Drop unnecessary check before calling os_free()
- Update the comment for os_free()
- Also free the RAM buffer
- Convert the rest of the allocations in os.c, etc.

 arch/sandbox/cpu/os.c| 24 
 arch/sandbox/cpu/spl.c   | 10 +++---
 arch/sandbox/cpu/start.c | 12 +++-
 arch/sandbox/cpu/state.c | 18 +-
 include/os.h |  3 ++-
 5 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index d23aad318be..f5000e64966 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -153,7 +153,7 @@ int os_read_file(const char *fname, void **bufp, int *sizep)
printf("Cannot seek to start of file '%s'\n", fname);
goto err;
}
-   *bufp = malloc(size);
+   *bufp = os_malloc(size);
if (!*bufp) {
printf("Not enough memory to read file '%s'\n", fname);
ret = -ENOMEM;
@@ -391,8 +391,8 @@ int os_parse_args(struct sandbox_state *state, int argc, 
char *argv[])
state->argv = argv;
 
/* dynamically construct the arguments to the system getopt_long */
-   short_opts = malloc(sizeof(*short_opts) * num_options * 2 + 1);
-   long_opts = malloc(sizeof(*long_opts) * (num_options + 1));
+   short_opts = os_malloc(sizeof(*short_opts) * num_options * 2 + 1);
+   long_opts = os_malloc(sizeof(*long_opts) * (num_options + 1));
if (!short_opts || !long_opts)
return 1;
 
@@ -471,7 +471,7 @@ void os_dirent_free(struct os_dirent_node *node)
 
while (node) {
next = node->next;
-   free(node);
+   os_free(node);
node = next;
}
 }
@@ -496,7 +496,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node 
**headp)
/* Create a buffer upfront, with typically sufficient size */
dirlen = strlen(dirname) + 2;
len = dirlen + 256;
-   fname = malloc(len);
+   fname = os_malloc(len);
if (!fname) {
ret = -ENOMEM;
goto done;
@@ -509,7 +509,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node 
**headp)
ret = errno;
break;
}
-   next = malloc(sizeof(*node) + strlen(entry->d_name) + 1);
+   next = os_malloc(sizeof(*node) + strlen(entry->d_name) + 1);
if (!next) {
os_dirent_free(head);
ret = -ENOMEM;
@@ -518,10 +518,10 @@ int os_dirent_ls(const char *dirname, struct 
os_dirent_node **headp)
if (dirlen + strlen(entry->d_name) > len) {
len = dirlen + strlen(entry->d_name);
old_fname = fname;
-   fname = realloc(fname, len);
+   fname = os_realloc(fname, len);
if (!fname) {
-   free(old_fname);
-   free(next);
+   os_free(old_fname);
+   os_free(next);
os_dirent_free(head);
ret = -ENOMEM;
goto done;
@@ -555,7 +555,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node 
**headp)
 
 done:
closedir(dir);
-   free(fname);
+   os_free(fname);
return ret;
 }
 
@@ -672,7 +672,7 @@ static int add_args(char ***argvp, char *add_args[], int 
count)
for (argc = 0; (*argvp)[argc]; argc++)
;
 
-   argv = malloc((argc + count + 1) * sizeof(char *));
+   argv = os_malloc((argc + count + 1) * sizeof(char *));
if (!argv) {
printf("Out of memory for %d argv\n", count);
return -ENOMEM;
@@ -755,7 +755,7 @@ static int os_jump_to_file(const char *fname)
os_exit(2);
 
err = execv(fname, argv);
-   free(argv);
+   os_free(argv);
if (err) {
perror("Unable to run image");
printf("Image filename '%s'\n", fname);
diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 9a77da15619..197b98c9828 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -42,10 +42,14 @@ static int spl_board_load_image(struct spl_image_info 
*spl_image,
return ret;
 

[PATCH v4 9/9] bootm: Fix duplicate debugging in bootm_process_cmdline()

2021-02-06 Thread Simon Glass
These two returns use the same string so are not distinguishable with
LOG_ERROR_RETURN. Fix it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/bootm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/bootm.c b/common/bootm.c
index 8298693900d..48a5b04cd7a 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -585,7 +585,7 @@ int bootm_process_cmdline(char *buf, int maxlen, int flags)
if (IS_ENABLED(CONFIG_BOOTARGS_SUBST) && (flags & BOOTM_CL_SUBST)) {
ret = process_subst(buf, maxlen);
if (ret)
-   return log_msg_ret("silent", ret);
+   return log_msg_ret("subst", ret);
}
 
return 0;
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 5/9] s5p4418_nanopi2: Drop dead code

2021-02-06 Thread Simon Glass
This code is still using the old command typedef. It was not noticed since
this file is not currently built. It is using a non-existent option in the
Makefile.

Drop this file since it is not needed for correct operation.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Drop the file instead of fixing it up

 arch/arm/mach-nexell/Makefile |   1 -
 arch/arm/mach-nexell/cmd_boot_linux.c | 144 --
 2 files changed, 145 deletions(-)
 delete mode 100644 arch/arm/mach-nexell/cmd_boot_linux.c

diff --git a/arch/arm/mach-nexell/Makefile b/arch/arm/mach-nexell/Makefile
index 10b3963ed10..dda16dbb8e6 100644
--- a/arch/arm/mach-nexell/Makefile
+++ b/arch/arm/mach-nexell/Makefile
@@ -10,4 +10,3 @@ obj-y += nx_gpio.o
 obj-y  += tieoff.o
 obj-$(CONFIG_ARCH_S5P4418) += reg-call.o
 obj-$(CONFIG_ARCH_S5P4418) += nx_sec_reg.o
-obj-$(CONFIG_CMD_BOOTL)+= cmd_boot_linux.o
diff --git a/arch/arm/mach-nexell/cmd_boot_linux.c 
b/arch/arm/mach-nexell/cmd_boot_linux.c
deleted file mode 100644
index f2dedfe1625..000
--- a/arch/arm/mach-nexell/cmd_boot_linux.c
+++ /dev/null
@@ -1,144 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * (C) Copyright 2016 nexell
- * jhkim 
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_CLI_FRAMEWORK)
-
-DECLARE_GLOBAL_DATA_PTR;
-
-static bootm_headers_t linux_images;
-
-static void boot_go_set_os(cmd_tbl_t *cmdtp, int flag, int argc,
-  char * const argv[],
-  bootm_headers_t *images)
-{
-   char * const img_addr = argv[0];
-
-   images->os.type = IH_TYPE_KERNEL;
-   images->os.comp = IH_COMP_NONE;
-   images->os.os = IH_OS_LINUX;
-   images->os.load = simple_strtoul(img_addr, NULL, 16);
-   images->ep = images->os.load;
-#if defined(CONFIG_ARM)
-   images->os.arch = IH_ARCH_ARM;
-#elif defined(CONFIG_ARM64)
-   images->os.arch = IH_ARCH_ARM64;
-#else
-   #error "Not support architecture ..."
-#endif
-   if (!IS_ENABLED(CONFIG_OF_LIBFDT) && !IS_ENABLED(CONFIG_SPL_BUILD)) {
-   /* set DTB address for linux kernel */
-   if (argc > 2) {
-   unsigned long ft_addr;
-
-   ft_addr = simple_strtol(argv[2], NULL, 16);
-   images->ft_addr = (char *)ft_addr;
-
-   /*
-* if not defined IMAGE_ENABLE_OF_LIBFDT,
-* must be set to fdt address
-*/
-   if (!IMAGE_ENABLE_OF_LIBFDT)
-   gd->bd->bi_boot_params = ft_addr;
-
-   debug("## set ft:%08lx and boot params:%08lx [control 
of:%s]"
- "...\n", ft_addr, gd->bd->bi_boot_params,
- IMAGE_ENABLE_OF_LIBFDT ? "on" : "off");
-   }
-   }
-}
-
-#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
-static void boot_start_lmb(bootm_headers_t *images)
-{
-   ulong   mem_start;
-   phys_size_t mem_size;
-
-   lmb_init(&images->lmb);
-
-   mem_start = getenv_bootm_low();
-   mem_size = getenv_bootm_size();
-
-   lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
-
-   arch_lmb_reserve(&images->lmb);
-   board_lmb_reserve(&images->lmb);
-}
-#else
-#define lmb_reserve(lmb, base, size)
-static inline void boot_start_lmb(bootm_headers_t *images) { }
-#endif
-
-int do_boot_linux(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-   boot_os_fn *boot_fn;
-   bootm_headers_t *images = &linux_images;
-   int flags;
-   int ret;
-
-   boot_start_lmb(images);
-
-   flags  = BOOTM_STATE_START;
-
-   argc--; argv++;
-   boot_go_set_os(cmdtp, flag, argc, argv, images);
-
-   if (IS_ENABLED(CONFIG_OF_LIBFDT)) {
-   /* find flattened device tree */
-   ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, images,
-  &images->ft_addr, &images->ft_len);
-   if (ret) {
-   puts("Could not find a valid device tree\n");
-   return 1;
-   }
-   set_working_fdt_addr((ulong)images->ft_addr);
-   }
-
-   if (!IS_ENABLED(CONFIG_OF_LIBFDT))
-   flags |= BOOTM_STATE_OS_GO;
-
-   boot_fn = do_bootm_linux;
-   ret = boot_fn(flags, argc, argv, images);
-
-   if (ret == BOOTM_ERR_UNIMPLEMENTED)
-   show_boot_progress(BOOTSTAGE_ID_DECOMP_UNIMPL);
-   else if (ret == BOOTM_ERR_RESET)
-   do_reset(cmdtp, flag, argc, argv);
-
-   return ret;
-}
-
-U_BOOT_CMD(bootl, CONFIG_SYS_MAXARGS, 1, do_boot_linux,
-  "boot linux image from memory",
-  "[addr [arg ...]]\n- boot linux image stored in

[PATCH v4 6/9] sandbox: Add os_realloc()

2021-02-06 Thread Simon Glass
We provide os_malloc() and os_free() but not os_realloc(). Add this,
following the usual semantics. Also update os_malloc() to behave correctly
when passed a zero size.

Signed-off-by: Simon Glass 
Reviewed-by: Heinrich Schuchardt 
---

(no changes since v3)

Changes in v3:
- Add comments as to why we have os_malloc() and os_realloc()

Changes in v2:
- Add new patch to add os_realloc()

 arch/sandbox/cpu/os.c | 48 +++
 include/os.h  | 12 ++-
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 3d8af0a52bb..d23aad318be 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -267,11 +267,18 @@ void os_tty_raw(int fd, bool allow_sigs)
signal(SIGINT, os_sigint_handler);
 }
 
+/*
+ * Provide our own malloc so we don't use space in the sandbox ram_buf for
+ * allocations that are internal to sandbox, or need to be done before U-Boot's
+ * malloc() is ready.
+ */
 void *os_malloc(size_t length)
 {
int page_size = getpagesize();
struct os_mem_hdr *hdr;
 
+   if (!length)
+   return NULL;
/*
 * Use an address that is hopefully available to us so that pointers
 * to this memory are fairly obvious. If we end up with a different
@@ -298,6 +305,47 @@ void os_free(void *ptr)
}
 }
 
+/* These macros are from kernel.h but not accessible in this file */
+#define ALIGN(x, a)__ALIGN_MASK((x), (typeof(x))(a) - 1)
+#define __ALIGN_MASK(x, mask)  (((x) + (mask)) & ~(mask))
+
+/*
+ * Provide our own malloc so we don't use space in the sandbox ram_buf for
+ * allocations that are internal to sandbox, or need to be done before U-Boot's
+ * malloc() is ready.
+ */
+void *os_realloc(void *ptr, size_t length)
+{
+   int page_size = getpagesize();
+   struct os_mem_hdr *hdr;
+   void *new_ptr;
+
+   /* Reallocating a NULL pointer is just an alloc */
+   if (!ptr)
+   return os_malloc(length);
+
+   /* Changing a length to 0 is just a free */
+   if (length) {
+   os_free(ptr);
+   return NULL;
+   }
+
+   /*
+* If the new size is the same number of pages as the old, nothing to
+* do. There isn't much point in shrinking things
+*/
+   hdr = ptr - page_size;
+   if (ALIGN(length, page_size) <= ALIGN(hdr->length, page_size))
+   return ptr;
+
+   /* We have to grow it, so allocate something new */
+   new_ptr = os_malloc(length);
+   memcpy(new_ptr, ptr, hdr->length);
+   os_free(ptr);
+
+   return new_ptr;
+}
+
 void os_usleep(unsigned long usec)
 {
usleep(usec);
diff --git a/include/os.h b/include/os.h
index 65bcb232cab..fd010cfee83 100644
--- a/include/os.h
+++ b/include/os.h
@@ -114,7 +114,7 @@ void os_fd_restore(void);
  * os_malloc() - aquires some memory from the underlying os.
  *
  * @length:Number of bytes to be allocated
- * Return: Pointer to length bytes or NULL on error
+ * Return: Pointer to length bytes or NULL if @length is 0 or on error
  */
 void *os_malloc(size_t length);
 
@@ -127,6 +127,16 @@ void *os_malloc(size_t length);
  */
 void os_free(void *ptr);
 
+/**
+ * os_realloc() - reallocate memory
+ *
+ * This follows the semantics of realloc(), so can perform an os_malloc() or
+ * os_free() depending on @ptr and @length.
+ *
+ * Return: Pointer to reallocated memory or NULL if @length is 0
+ */
+void *os_realloc(void *ptr, size_t length);
+
 /**
  * os_usleep() - access to the usleep function of the os
  *
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 3/9] doc: describe the md command

2021-02-06 Thread Simon Glass
Provide a man-page for the md command.

Signed-off-by: Simon Glass 
---

(no changes since v3)

Changes in v3:
- Add new patch to describe the md command

 doc/Makefile|  1 -
 doc/usage/index.rst |  1 +
 doc/usage/md.rst| 96 +
 3 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 doc/usage/md.rst

diff --git a/doc/Makefile b/doc/Makefile
index a686d4728ec..683e4b56099 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -56,7 +56,6 @@ quiet_cmd_sphinx = SPHINX  $@ --> file://$(abspath 
$(BUILDDIR)/$3/$4)
PYTHONDONTWRITEBYTECODE=1 \
BUILDDIR=$(abspath $(BUILDDIR)) SPHINX_CONF=$(abspath 
$(srctree)/$(src)/$5/$(SPHINX_CONF)) \
$(SPHINXBUILD) \
-   -W \
-b $2 \
-c $(abspath $(srctree)/$(src)) \
-d $(abspath $(BUILDDIR)/.doctrees/$3) \
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 5754958d7e4..8f302c26688 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -26,6 +26,7 @@ Shell commands
load
loady
mbr
+   md
pstore
sbi
true
diff --git a/doc/usage/md.rst b/doc/usage/md.rst
new file mode 100644
index 000..3951b0d58f5
--- /dev/null
+++ b/doc/usage/md.rst
@@ -0,0 +1,96 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+md command
+==
+
+Synopis
+---
+
+::
+
+md [] []
+
+Description
+---
+
+The md command is used to dump the contents of memory. It uses a standard
+format that includes the address, hex data and ASCII display. It supports
+various data sizes and uses the endianness of the target.
+
+The specified data_size and length become the defaults for future memory
+commands commands.
+
+address
+start address to display
+
+data_size
+size of each value to display (defaults to .l):
+
+=  ===
+data_size  Output size
+=  ===
+.b byte
+.w word (16 bits)
+.l long (32 bits)
+.q quadword (64 bits)
+=  ===
+
+length
+number of values to dump. Defaults to 40 (0d64). Note that this is not
+the same as the number of bytes, unless .b is used.
+
+
+Example
+---
+
+::
+
+=> md 1
+0001: 0001  f0f30f00 5596.U..
+00010010: 10011010  10011010 
+00010020: 10011050  b96d4cd8 7fffPLm.
+00010030:   f0f30f18 5596.U..
+00010040: 10011040  10011040 @...@...
+00010050: b96d4cd8 7fff 10011020 .Lm. ...
+00010060: 0003 00c3  
+00010070:   f0e892f3 5596.U..
+00010080:  00a1  
+00010090:   f0e38aa6 5596.U..
+000100a0:  00a6 0022 "...
+000100b0: 0001  f0e38aa1 5596.U..
+000100c0:  00be  
+000100d0:    
+000100e0:    
+000100f0:    
+=> md.b 1
+0001: 00 00 01 00 00 00 00 00 00 0f f3 f0 96 55 00 00
.U..
+00010010: 10 10 01 10 00 00 00 00 10 10 01 10 00 00 00 00

+00010020: 50 10 01 10 00 00 00 00 d8 4c 6d b9 ff 7f 00 00
PLm.
+00010030: 00 00 00 00 00 00 00 00 18 0f f3 f0 96 55 00 00
.U..
+=> md.b 1 10
+0001: 00 00 01 00 00 00 00 00 00 0f f3 f0 96 55 00 00
.U..
+=>
+00010010: 10 10 01 10 00 00 00 00 10 10 01 10 00 00 00 00

+=>
+00010020: 50 10 01 10 00 00 00 00 d8 4c 6d b9 ff 7f 00 00
PLm.
+=>
+=> md.q 1
+0001: 0001 5596f0f30f00.U..
+00010010: 10011010 10011010
+00010020: 10011050 7fffb96d4cd8PLm.
+00010030:  5596f0f30f18.U..
+00010040: 10011040 10011040@...@...
+00010050: 7fffb96d4cd8 10011020.Lm. ...
+00010060: 00c30003 
+00010070:  5596f0e892f3.U..
+
+The empty commands cause a 'repeat', so that md shows the next available data
+in the same format as before.
+
+
+Return value
+
+
+The return value $? is always 0 (true).
+
+
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 2/9] binman: Indicate how to make binman verbose

2021-02-06 Thread Simon Glass
Add notes about how to make binman produce verbose logging when building.

Add a comment on how to do this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile| 1 +
 tools/binman/README | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index ebbedb1fb1a..2917af20ecd 100644
--- a/Makefile
+++ b/Makefile
@@ -1330,6 +1330,7 @@ u-boot.ldr:   u-boot
 # binman
 # ---
 # Use 'make BINMAN_DEBUG=1' to enable debugging
+# Use 'make BINMAN_VERBOSE=3' to set vebosity level
 default_dt := $(if $(DEVICE_TREE),$(DEVICE_TREE),$(CONFIG_DEFAULT_DEVICE_TREE))
 quiet_cmd_binman = BINMAN  $@
 cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
diff --git a/tools/binman/README b/tools/binman/README
index a00c9026163..45f0a0c2cd3 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -637,7 +637,8 @@ Logging
 
 Binman normally operates silently unless there is an error, in which case it
 just displays the error. The -D/--debug option can be used to create a full
-backtrace when errors occur.
+backtrace when errors occur. You can use BINMAN_DEBUG=1 when building to select
+this.
 
 Internally binman logs some output while it is running. This can be displayed
 by increasing the -v/--verbosity from the default of 1:
@@ -649,6 +650,7 @@ by increasing the -v/--verbosity from the default of 1:
4: detailed information about each operation
5: debug (all output)
 
+You can use BINMAN_VERBOSE=5 (for example) when building to select this.
 
 Hashing Entries
 ---
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 4/9] doc: Add a note about producing 'md.b' output using hexdump

2021-02-06 Thread Simon Glass
Comparing a hex dump on the U-Boot command line with the contents of a
file on the host system is fairly easy and convenient to do manually if
it is small. But the format used hexdump by default differs from that
shown by U-Boot. Add a note about how to make them the same.

(For large dumps, writing the data to the network with tftpput, or to a
USB stick with ext4save is easiest.)

Signed-off-by: Simon Glass 
---

Changes in v4:
- Indicate that hd does not show the offset correctly
- Add an xxd + sed example too

Changes in v3:
- Add this to the docs for the md command

 doc/usage/md.rst | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/doc/usage/md.rst b/doc/usage/md.rst
index 3951b0d58f5..4c1073ea354 100644
--- a/doc/usage/md.rst
+++ b/doc/usage/md.rst
@@ -39,6 +39,16 @@ length
 number of values to dump. Defaults to 40 (0d64). Note that this is not
 the same as the number of bytes, unless .b is used.
 
+Note that the format of 'md.b' can be emulated from linux with::
+
+# This works but requires using sed to get the extra spaces
+#  is the address,  is the filename
+xxd -o  -g1  |sed 's/  //' >bad
+
+# This uses a single tool but the offset always starts at 0
+#  is the filename
+hexdump -v -e '"%08.8_ax: " 16/1 "%02x " ""' -e '16/1 "%_p" "\n" ' 
+
 
 Example
 ---
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 1/9] spl: Drop duplicate 'Jumping to U-Boot' message

2021-02-06 Thread Simon Glass
This is printed twice but we only need one message, since there is very
little processing in between them. Drop the second one, since all branches
of the switch() already have output. Update the U-Boot message to include
the phase being jumped to.

Signed-off-by: Simon Glass 
---

(no changes since v3)

Changes in v3:
- Show phase only for IH_OS_U_BOOT, drop the last debug()

 common/spl/spl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index cdd7b05f279..42004506446 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -693,7 +693,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 #endif
switch (spl_image.os) {
case IH_OS_U_BOOT:
-   debug("Jumping to U-Boot\n");
+   debug("Jumping to %s...\n", spl_phase_name(spl_next_phase()));
break;
 #if CONFIG_IS_ENABLED(ATF)
case IH_OS_ARM_TRUSTED_FIRMWARE:
@@ -740,7 +740,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
debug("Failed to stash bootstage: err=%d\n", ret);
 #endif
 
-   debug("loaded - jumping to %s...\n", spl_phase_name(spl_next_phase()));
spl_board_prepare_for_boot();
jump_to_image_no_args(&spl_image);
 }
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 0/9] Various minor fixes

2021-02-06 Thread Simon Glass
This series collects a few minor fixes and improvements that have been
hanging around in a branch for a while.

Changes in v4:
- Indicate that hd does not show the offset correctly
- Add an xxd + sed example too
- Fix 'existing' typo

Changes in v3:
- Show phase only for IH_OS_U_BOOT, drop the last debug()
- Add new patch to describe the md command
- Add this to the docs for the md command
- Add comments as to why we have os_malloc() and os_realloc()

Changes in v2:
- Drop the file instead of fixing it up
- Add new patch to add os_realloc()
- Drop unnecessary check before calling os_free()
- Update the comment for os_free()
- Also free the RAM buffer
- Convert the rest of the allocations in os.c, etc.

Simon Glass (9):
  spl: Drop duplicate 'Jumping to U-Boot' message
  binman: Indicate how to make binman verbose
  doc: describe the md command
  doc: Add a note about producing 'md.b' output using hexdump
  s5p4418_nanopi2: Drop dead code
  sandbox: Add os_realloc()
  sandbox: Avoid using malloc() for system state
  sandbox: Write out bloblist when exiting
  bootm: Fix duplicate debugging in bootm_process_cmdline()

 Makefile  |   1 +
 arch/arm/mach-nexell/Makefile |   1 -
 arch/arm/mach-nexell/cmd_boot_linux.c | 144 --
 arch/sandbox/cpu/os.c |  72 ++---
 arch/sandbox/cpu/spl.c|  10 +-
 arch/sandbox/cpu/start.c  |  12 ++-
 arch/sandbox/cpu/state.c  |  23 ++--
 common/bootm.c|   2 +-
 common/spl/spl.c  |   3 +-
 doc/Makefile  |   1 -
 doc/usage/index.rst   |   1 +
 doc/usage/md.rst  | 106 +++
 include/os.h  |  15 ++-
 tools/binman/README   |   4 +-
 14 files changed, 214 insertions(+), 181 deletions(-)
 delete mode 100644 arch/arm/mach-nexell/cmd_boot_linux.c
 create mode 100644 doc/usage/md.rst

-- 
2.30.0.478.g8a0d178c01-goog



Re: [RESEND PATCH 12/16] arm: omap3: Compile lowlevel_init() function only when it is used

2021-02-06 Thread Marek Vasut

On 2/6/21 4:45 PM, Pali Rohár wrote:

On Saturday 06 February 2021 16:40:18 Marek Vasut wrote:

On 2/5/21 8:12 PM, Pali Rohár wrote:

Function lowlevel_init() is called only from cpu_init_crit() and this
function is wrapped into #if .. #endif section. So compile also
lowlevel_init() function under same #if condition.

Signed-off-by: Pali Rohár 
---
   arch/arm/mach-omap2/omap3/lowlevel_init.S | 6 +-
   1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/omap3/lowlevel_init.S 
b/arch/arm/mach-omap2/omap3/lowlevel_init.S
index 2a05b5e521..4fa89418a1 100644
--- a/arch/arm/mach-omap2/omap3/lowlevel_init.S
+++ b/arch/arm/mach-omap2/omap3/lowlevel_init.S
@@ -45,7 +45,7 @@ ENDPROC(do_omap3_emu_romcode_call)
   ENTRY(cpy_clk_code)
/* Copy DPLL code into SRAM */
adr r0, go_to_speed /* copy from start of go_to_speed... */
-   adr r2, lowlevel_init   /* ... up to start of low_level_init */
+   adr r2, go_to_speed_end /* ... up to start of go_to_speed_end */
   next2:
ldmia   r0!, {r3 - r10} /* copy from source address [r0] */
stmia   r1!, {r3 - r10} /* copy to   target address [r1] */
@@ -167,8 +167,11 @@ pll_div_add5:
   pll_div_val5:
.word CLSEL1_EMU_VAL
+go_to_speed_end:
   #endif


This hunk above seems like an unrelated change ^ ?


Entry 'lowlevel_init' is defined 3 lines below and is available only
when !CONFIG_SKIP_LOWLEVEL_INIT && !CONFIG_SKIP_LOWLEVEL_INIT_ONLY.

Few lines above is code which copies DPLL code into SRAM and this code
ends at address where 'lowlevel_init' entry starts.

Entry 'cpy_clk_code' is compiled also when CONFIG_SKIP_LOWLEVEL_INIT is
defined, therefore it is required to define label which is outside of
the #if code defined below and ends after the 'go_to_speed' code.

So I defined a new 'go_to_speed_end' label to allow compiling
'cpy_clk_code' entry when CONFIG_SKIP_LOWLEVEL_INIT is defined.


Can you add exactly this description to the commit message -- the change 
isn't immediately obviously, collect the RBs and resend the patchset, so 
it can be picked ?


Thanks


Re: [PATCH v5 2/4] button: add a simple Analog to Digital Converter device based button driver

2021-02-06 Thread Simon Glass
Hi Marek,

On Thu, 4 Feb 2021 at 03:36, Marek Szyprowski  wrote:
>
> Hi Simon,
>
> On 01.02.2021 21:38, Simon Glass wrote:
> > On Tue, 26 Jan 2021 at 06:03, Heinrich Schuchardt  
> > wrote:
> >> On 26.01.21 12:25, Marek Szyprowski wrote:
> >>> On 26.01.2021 12:10, Heinrich Schuchardt wrote:
>  On 1/26/21 10:50 AM, Marek Szyprowski wrote:
> > Add a simple Analog to Digital Converter device based button driver.
> > This
> > driver binds to the 'adc-keys' device tree node.
> >
> > Signed-off-by: Marek Szyprowski 
> > ---
> >drivers/button/Kconfig  |   8 ++
> >drivers/button/Makefile |   1 +
> >drivers/button/button-adc.c | 156 
> > 
> >3 files changed, 165 insertions(+)
> >create mode 100644 drivers/button/button-adc.c
> >
> > diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig
> > index 6b3ec7e55d..6db3c5e93a 100644
> > --- a/drivers/button/Kconfig
> > +++ b/drivers/button/Kconfig
> > @@ -9,6 +9,14 @@ config BUTTON
> >  can provide access to board-specific buttons. Use of the
> > device tree
> >  for configuration is encouraged.
> >
> > +config BUTTON_ADC
> > +bool "Button adc"
> > +depends on BUTTON
> > +help
> > +  Enable support for buttons which are connected to Analog to
> > Digital
> > +  Converter device. The ADC driver must use driver model.
> > Buttons are
> > +  configured using the device tree.
> > +
> >config BUTTON_GPIO
> >bool "Button gpio"
> >depends on BUTTON
> > diff --git a/drivers/button/Makefile b/drivers/button/Makefile
> > index fcc10ebe8d..bbd18af149 100644
> > --- a/drivers/button/Makefile
> > +++ b/drivers/button/Makefile
> > @@ -3,4 +3,5 @@
> ># Copyright (C) 2020 Philippe Reynes 
> >
> >obj-$(CONFIG_BUTTON) += button-uclass.o
> > +obj-$(CONFIG_BUTTON_ADC) += button-adc.o
> >obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o
> > diff --git a/drivers/button/button-adc.c b/drivers/button/button-adc.c
> > new file mode 100644
> > index 00..1901d59a0e
> > --- /dev/null
> > +++ b/drivers/button/button-adc.c
> > @@ -0,0 +1,156 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2021 Samsung Electronics Co., Ltd.
> > + *http://www.samsung.com
> > + * Author: Marek Szyprowski 
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/**
> > + * struct button_adc_priv - private data for button-adc driver.
> > + *
> > + * @adc: Analog to Digital Converter device to which button is
> > connected.
> > + * @channel: channel of the ADC device to probe the button state.
> > + * @min: minimal raw ADC sample value to consider button as pressed.
> > + * @max: maximal raw ADC sample value to consider button as pressed.
> > + */
> > +struct button_adc_priv {
> > +struct udevice *adc;
> > +int channel;
> > +int min;
> > +int max;
> > +};
> > +
> > +static enum button_state_t button_adc_get_state(struct udevice *dev)
> > +{
> > +struct button_adc_priv *priv = dev_get_priv(dev);
> > +unsigned int val;
> > +int ret;
> > +
> > +ret = adc_start_channel(priv->adc, priv->channel);
> > +if (ret)
> > +return ret;
> > +
> > +ret = adc_channel_data(priv->adc, priv->channel, &val);
> > +if (ret)
> > +return ret;
> > +
> > +if (ret == 0)
> > +return (val >= priv->min && val < priv->max) ?
> > +BUTTON_ON : BUTTON_OFF;
> > +
> > +return ret;
> > +}
> > +
> > +static int button_adc_probe(struct udevice *dev)
> > +{
> > +struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
> > +struct button_adc_priv *priv = dev_get_priv(dev);
> > +struct ofnode_phandle_args args;
> > +u32 treshold, up_treshold, t;
> > +unsigned int mask;
> > +ofnode node;
> > +int ret, vdd;
> > +
> > +/* Ignore the top-level button node */
> > +if (!uc_plat->label)
> > +return 0;
> > +
> > +ret = dev_read_phandle_with_args(dev->parent, "io-channels",
> > + "#io-channel-cells", 0, 0, &args);
> > +if (ret)
> > +return ret;
> > +
> > +ret = uclass_get_device_by_ofnode(UCLASS_ADC, args.node,
> > &priv->adc);
> > +if (ret)
> > +return ret;
> > +
> > +ret = ofnode_read_u32(dev_ofnode(dev->parent),
> > +  "keyup-threshold-microvolt", &up_treshold);
> > +if (ret)
> > + 

[PATCH v4 2/2] x86: coral: Show memory config and SKU ID on startup

2021-02-06 Thread Simon Glass
Provide the model information through sysinfo so that it shows up on
boot. For memconfig 4 pins are provided, for 16 combinations. For SKU
ID there are two options:

   - two pins provided in a ternary arrangement, for 9 combinations.
   - reading from the EC

Add a binding doc and drop the unused #defines as well.

Example:

   U-Boot 2021.01-rc5

   CPU:   Intel(R) Celeron(R) CPU N3450 @ 1.10GHz
   DRAM:  3.9 GiB
   MMC:   sdmmc@1b,0: 1, emmc@1c,0: 2
   Video: 1024x768x32 @ b000
   Model: Google Coral (memconfig 5, SKU 3)

This depends on the GPIO series:

   http://patchwork.ozlabs.org/project/uboot/list/?series=228126

Signed-off-by: Simon Glass 

Acked-by: Bin Meng 
---

Changes in v4:
- Rebase to x86/master (but will not build until GPIO series lands)
- Update cover letter

Changes in v3:
- Rebase to master
- Drop patches previously applied

Changes in v2:
- Fix two missing asterisks in comments

 arch/x86/dts/chromebook_coral.dts |  11 ++
 board/google/chromebook_coral/coral.c | 139 +-
 board/google/chromebook_coral/variant_gpio.h  |   6 -
 .../sysinfo/google,coral.txt  |  37 +
 4 files changed, 179 insertions(+), 14 deletions(-)
 create mode 100644 doc/device-tree-bindings/sysinfo/google,coral.txt

diff --git a/arch/x86/dts/chromebook_coral.dts 
b/arch/x86/dts/chromebook_coral.dts
index 2ffe3b423c3..18bbafe5981 100644
--- a/arch/x86/dts/chromebook_coral.dts
+++ b/arch/x86/dts/chromebook_coral.dts
@@ -55,6 +55,17 @@
recovery-gpios = <&gpio_nw (-1) GPIO_ACTIVE_LOW>;
write-protect-gpios = <&gpio_nw GPIO_75 GPIO_ACTIVE_HIGH>;
phase-enforce-gpios = <&gpio_n GPIO_10 GPIO_ACTIVE_HIGH>;
+   memconfig-gpios = <&gpio_nw GPIO_101 GPIO_ACTIVE_HIGH
+   &gpio_nw GPIO_102 GPIO_ACTIVE_HIGH
+   &gpio_n GPIO_38 GPIO_ACTIVE_HIGH
+   &gpio_n GPIO_45 GPIO_ACTIVE_HIGH>;
+
+   /*
+* This is used for reef only:
+*
+* skuconfig-gpios = <&gpio_nw GPIO_16 GPIO_ACTIVE_HIGH
+*  &gpio_nw GPIO_17 GPIO_ACTIVE_HIGH>;
+*/
smbios {
/* Type 1 table */
system {
diff --git a/board/google/chromebook_coral/coral.c 
b/board/google/chromebook_coral/coral.c
index f9fb3f163f0..77a6cca4497 100644
--- a/board/google/chromebook_coral/coral.c
+++ b/board/google/chromebook_coral/coral.c
@@ -3,9 +3,12 @@
  * Copyright 2019 Google LLC
  */
 
+#define LOG_CATEGORY   UCLASS_SYSINFO
+
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "variant_gpio.h"
 
 struct cros_gpio_info {
@@ -29,10 +33,125 @@ int arch_misc_init(void)
return 0;
 }
 
-/* This function is needed if CONFIG_CMDLINE is not enabled */
-int board_run_command(const char *cmdline)
+static int get_memconfig(struct udevice *dev)
 {
-   printf("No command line\n");
+   struct gpio_desc gpios[4];
+   int cfg;
+   int ret;
+
+   ret = gpio_request_list_by_name(dev, "memconfig-gpios", gpios,
+   ARRAY_SIZE(gpios),
+   GPIOD_IS_IN | GPIOD_PULL_UP);
+   if (ret < 0) {
+   log_debug("Cannot get GPIO list '%s' (%d)\n", dev->name, ret);
+   return ret;
+   }
+
+   /* Give the lines time to settle */
+   udelay(10);
+
+   ret = dm_gpio_get_values_as_int(gpios, ARRAY_SIZE(gpios));
+   if (ret < 0)
+   return log_msg_ret("get", ret);
+   cfg = ret;
+
+   ret = gpio_free_list(dev, gpios, ARRAY_SIZE(gpios));
+   if (ret)
+   return log_msg_ret("free", ret);
+
+   return cfg;
+}
+
+/**
+ * get_skuconfig() - Get the SKU number either from pins or the EC
+ *
+ * Two options are supported:
+ * skuconfig-gpios - two pins in the device tree (tried first)
+ * EC  - reading from the EC (backup)
+ *
+ * @dev: sysinfo device to use
+ * @return SKU ID, or -ve error if not found
+ */
+static int get_skuconfig(struct udevice *dev)
+{
+   struct gpio_desc gpios[2];
+   int cfg;
+   int ret;
+
+   ret = gpio_request_list_by_name(dev, "skuconfig-gpios", gpios,
+   ARRAY_SIZE(gpios),
+   GPIOD_IS_IN);
+   if (ret != ARRAY_SIZE(gpios)) {
+   struct udevice *cros_ec;
+
+   log_debug("Cannot get GPIO list '%s' (%d)\n", dev->name, ret);
+
+   /* Try the EC */
+   ret = uclass_first_device_err(UCLASS_CROS_EC, &cros_ec);
+   if (ret < 0) {
+   log_err("Cannot find EC for SKU details\n");
+   return log_msg_ret("sku", ret);
+   }
+   ret = cros_ec_get_sku_id(cros_ec);
+ 

[PATCH v4 1/2] sysinfo: Allow showing model info from sysinfo

2021-02-06 Thread Simon Glass
Some boards may want to show the SKU ID or other information obtained at
runtime. Allow this to come from sysinfo. The board can then provide a
sysinfo driver to provide it.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v3)

Changes in v3:
- Rebase to master

 common/board_info.c | 37 +
 include/sysinfo.h   |  4 
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/common/board_info.c b/common/board_info.c
index a6db087f960..20a2dea1f35 100644
--- a/common/board_info.c
+++ b/common/board_info.c
@@ -1,30 +1,51 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int __weak checkboard(void)
 {
return 0;
 }
 
 /*
- * If the root node of the DTB has a "model" property, show it.
+ * Check sysinfo for board information. Failing that if the root node of the 
DTB
+ * has a "model" property, show it.
+ *
  * Then call checkboard().
  */
 int __weak show_board_info(void)
 {
-#ifdef CONFIG_OF_CONTROL
-   DECLARE_GLOBAL_DATA_PTR;
-   const char *model;
+   if (IS_ENABLED(CONFIG_OF_CONTROL)) {
+   struct udevice *dev;
+   const char *model;
+   char str[80];
+   int ret = -ENOSYS;
+
+   if (IS_ENABLED(CONFIG_SYSINFO)) {
+   /* This might provide more detail */
+   ret = uclass_first_device_err(UCLASS_SYSINFO, &dev);
+   if (!ret)
+   ret = sysinfo_get_str(dev,
+ SYSINFO_ID_BOARD_MODEL,
+ sizeof(str), str);
+   }
 
-   model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
+   /* Fail back to the main 'model' if available */
+   if (ret)
+   model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
+   else
+   model = str;
 
-   if (model)
-   printf("Model: %s\n", model);
-#endif
+   if (model)
+   printf("Model: %s\n", model);
+   }
 
return checkboard();
 }
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 743f3554659..f4ffb1a3503 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -35,9 +35,13 @@
 enum sysinfo_id {
SYSINFO_ID_NONE,
 
+   /* For SMBIOS tables */
SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
 
+   /* For show_board_info() */
+   SYSINFO_ID_BOARD_MODEL,
+
/* First value available for downstream/board used */
SYSINFO_ID_USER = 0x1000,
 };
-- 
2.30.0.478.g8a0d178c01-goog



[PATCH v4 0/2] x86: Minor improvements mostly for image loading

2021-02-06 Thread Simon Glass
This series provides a few improvements for loading of images. It also
provides a way to show more detailed model information as well as an
of-platdata fix noticed recently.

Note that this series depends on the GPIO series here:

   http://patchwork.ozlabs.org/project/uboot/list/?series=226118

Changes in v4:
- Rebase to x86/master (but will not build until GPIO series lands)
- Update cover letter

Changes in v3:
- Rebase to master
- Rebase to master
- Drop patches previously applied

Changes in v2:
- Fix two missing asterisks in comments

Simon Glass (2):
  sysinfo: Allow showing model info from sysinfo
  x86: coral: Show memory config and SKU ID on startup

 arch/x86/dts/chromebook_coral.dts |  11 ++
 board/google/chromebook_coral/coral.c | 139 +-
 board/google/chromebook_coral/variant_gpio.h  |   6 -
 common/board_info.c   |  37 -
 .../sysinfo/google,coral.txt  |  37 +
 include/sysinfo.h |   4 +
 6 files changed, 212 insertions(+), 22 deletions(-)
 create mode 100644 doc/device-tree-bindings/sysinfo/google,coral.txt

-- 
2.30.0.478.g8a0d178c01-goog



Re: [PATCH v2 3/3] fs: fat: remove trailing periods from long name

2021-02-06 Thread Simon Glass
On Thu, 4 Feb 2021 at 00:40, Heinrich Schuchardt  wrote:
>
> The FAT32 File System Specification [1] requires leading and trailing
> spaces as well as trailing periods of long names to be ignored.
>
> [1]
> Microsoft Extensible Firmware Initiative
> FAT32 File System Specification
> Version 1.03, December 6, 2000
> Microsoft Corporation
> https://www.win.tue.nl/~aeb/linux/fs/fat/fatgen103.pdf
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
> special treatment of '.' and '..'
> ---
>  fs/fat/fat_write.c | 30 --
>  1 file changed, 28 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 2/3] fs: fat: must not write directory '.' and '..'

2021-02-06 Thread Simon Glass
On Thu, 4 Feb 2021 at 00:40, Heinrich Schuchardt  wrote:
>
> Directories or files called '.' or '..' cannot be created or written to
> in any directory. Move the test to normalize_longname() to check this
> early.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v2:
> check for file length 0, simplify check for invalid file names
> ---
>  fs/fat/fat_write.c | 13 +++--
>  1 file changed, 3 insertions(+), 10 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v3 0/2] x86: Minor improvements mostly for image loading

2021-02-06 Thread Simon Glass
Hi Bin,

On Sat, 6 Feb 2021 at 04:24, Bin Meng  wrote:
>
> Hi Simon,
>
> On Fri, Feb 5, 2021 at 12:18 PM Simon Glass  wrote:
> >
> > This series provides a few improvements for loading of images. It also
> > provides a way to show more detailed model information as well as an
> > of-platdata fix noticed recently.
> >
> > Note that this series depends on the GPIO series here:
> >
> >http://patchwork.ozlabs.org/project/uboot/list/?series=226118
> >
> > Changes in v3:
> > - Rebase to master
> > - Rebase to master
> > - Drop patches previously applied
> >
>
> Unfortunately this series still does not apply on u-boot-x86, which
> has your smbios series applied and is conflicting with this series..

When I sent this, the smbios series was not there, so I sent it based
on master. I will send v4 based on x86/master instead.

But please note that we need the GPIO series before this will build.
I'll note that in the cover letter.

Regards,
Simon


Re: [RESEND PATCH 12/16] arm: omap3: Compile lowlevel_init() function only when it is used

2021-02-06 Thread Pali Rohár
On Saturday 06 February 2021 16:40:18 Marek Vasut wrote:
> On 2/5/21 8:12 PM, Pali Rohár wrote:
> > Function lowlevel_init() is called only from cpu_init_crit() and this
> > function is wrapped into #if .. #endif section. So compile also
> > lowlevel_init() function under same #if condition.
> > 
> > Signed-off-by: Pali Rohár 
> > ---
> >   arch/arm/mach-omap2/omap3/lowlevel_init.S | 6 +-
> >   1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm/mach-omap2/omap3/lowlevel_init.S 
> > b/arch/arm/mach-omap2/omap3/lowlevel_init.S
> > index 2a05b5e521..4fa89418a1 100644
> > --- a/arch/arm/mach-omap2/omap3/lowlevel_init.S
> > +++ b/arch/arm/mach-omap2/omap3/lowlevel_init.S
> > @@ -45,7 +45,7 @@ ENDPROC(do_omap3_emu_romcode_call)
> >   ENTRY(cpy_clk_code)
> > /* Copy DPLL code into SRAM */
> > adr r0, go_to_speed /* copy from start of go_to_speed... */
> > -   adr r2, lowlevel_init   /* ... up to start of low_level_init */
> > +   adr r2, go_to_speed_end /* ... up to start of go_to_speed_end */
> >   next2:
> > ldmia   r0!, {r3 - r10} /* copy from source address [r0] */
> > stmia   r1!, {r3 - r10} /* copy to   target address [r1] */
> > @@ -167,8 +167,11 @@ pll_div_add5:
> >   pll_div_val5:
> > .word CLSEL1_EMU_VAL
> > +go_to_speed_end:
> >   #endif
> 
> This hunk above seems like an unrelated change ^ ?

Entry 'lowlevel_init' is defined 3 lines below and is available only
when !CONFIG_SKIP_LOWLEVEL_INIT && !CONFIG_SKIP_LOWLEVEL_INIT_ONLY.

Few lines above is code which copies DPLL code into SRAM and this code
ends at address where 'lowlevel_init' entry starts.

Entry 'cpy_clk_code' is compiled also when CONFIG_SKIP_LOWLEVEL_INIT is
defined, therefore it is required to define label which is outside of
the #if code defined below and ends after the 'go_to_speed' code.

So I defined a new 'go_to_speed_end' label to allow compiling
'cpy_clk_code' entry when CONFIG_SKIP_LOWLEVEL_INIT is defined.

> > +#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \
> > +   !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY)
> >   ENTRY(lowlevel_init)
> > ldr sp, SRAM_STACK
> > str ip, [sp]/* stash ip register */
> > @@ -187,6 +190,7 @@ ENTRY(lowlevel_init)
> > b   s_init
> >   ENDPROC(lowlevel_init)
> > +#endif
> > /* the literal pools origin */
> > .ltorg
> > 
> 
> [...]


Re: [RESEND PATCH 12/16] arm: omap3: Compile lowlevel_init() function only when it is used

2021-02-06 Thread Marek Vasut

On 2/5/21 8:12 PM, Pali Rohár wrote:

Function lowlevel_init() is called only from cpu_init_crit() and this
function is wrapped into #if .. #endif section. So compile also
lowlevel_init() function under same #if condition.

Signed-off-by: Pali Rohár 
---
  arch/arm/mach-omap2/omap3/lowlevel_init.S | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/omap3/lowlevel_init.S 
b/arch/arm/mach-omap2/omap3/lowlevel_init.S
index 2a05b5e521..4fa89418a1 100644
--- a/arch/arm/mach-omap2/omap3/lowlevel_init.S
+++ b/arch/arm/mach-omap2/omap3/lowlevel_init.S
@@ -45,7 +45,7 @@ ENDPROC(do_omap3_emu_romcode_call)
  ENTRY(cpy_clk_code)
/* Copy DPLL code into SRAM */
adr r0, go_to_speed /* copy from start of go_to_speed... */
-   adr r2, lowlevel_init   /* ... up to start of low_level_init */
+   adr r2, go_to_speed_end /* ... up to start of go_to_speed_end */
  next2:
ldmia   r0!, {r3 - r10} /* copy from source address [r0] */
stmia   r1!, {r3 - r10} /* copy to   target address [r1] */
@@ -167,8 +167,11 @@ pll_div_add5:
  pll_div_val5:
.word CLSEL1_EMU_VAL
  
+go_to_speed_end:

  #endif


This hunk above seems like an unrelated change ^ ?


+#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \
+   !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY)
  ENTRY(lowlevel_init)
ldr sp, SRAM_STACK
str ip, [sp]/* stash ip register */
@@ -187,6 +190,7 @@ ENTRY(lowlevel_init)
b   s_init
  
  ENDPROC(lowlevel_init)

+#endif
  
  	/* the literal pools origin */

.ltorg



[...]


Re: [RESEND PATCH 16/16] Nokia RX-51: Enable usbtty serial console by default

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:12 +0100
Pali Rohár  wrote:

> Now when usbtty serial console is fixed in U-Boot enable
> CONFIG_USB_TTY for Nokia RX-51 board by default.
> 
> Fix also USB product id as U-Boot ignores CONFIG_USBD_PRODUCTID macro
> and include U-Boot string into USB product name to indicate usage of
> U-Boot.
> 
> CONFIG_CONSOLE_MUX is already used and U-Boot console is available for
> all in/out devices. Therefore there is no need to have separate
> commands 'run sercon', 'run usbcon' and 'run vgacon', so remove them.
> 
> As space for U-Boot is limited to 256kB, disable some other unused
> options so CONFIG_USB_TTY can be enabled.
> 
> Nokia RX-51 does not have easily accessible UART serial console so
> the only option for easy debugging is to use device's keyboard+screen
> or this usbtty serial console over USB.
> 
> Signed-off-by: Pali Rohár 
> ---
>  configs/nokia_rx51_defconfig |  7 ---
>  doc/README.nokia_rx51| 15 +--
>  include/configs/nokia_rx51.h | 21 +++--
>  3 files changed, 12 insertions(+), 31 deletions(-)
> 
> diff --git a/configs/nokia_rx51_defconfig
> b/configs/nokia_rx51_defconfig index 3b782715c7..bce55c4fe5 100644
> --- a/configs/nokia_rx51_defconfig
> +++ b/configs/nokia_rx51_defconfig
> @@ -13,6 +13,7 @@ CONFIG_AUTOBOOT_MENU_SHOW=y
>  CONFIG_USE_PREBOOT=y
>  CONFIG_PREBOOT="run preboot"
>  CONFIG_CONSOLE_MUX=y
> +# CONFIG_SYS_DEVICE_NULLDEV is not set
>  CONFIG_HUSH_PARSER=y
>  CONFIG_SYS_PROMPT="Nokia RX-51 # "
>  # CONFIG_CMD_BDI is not set
> @@ -47,9 +48,11 @@ CONFIG_ENV_OVERWRITE=y
>  CONFIG_SYS_RELOC_GD_ENV_ADDR=y
>  # CONFIG_NET is not set
>  CONFIG_DM=y
> +# CONFIG_DM_WARN is not set
>  # CONFIG_DM_DEVICE_REMOVE is not set
> +# CONFIG_DM_SEQ_ALIAS is not set
> +# CONFIG_BLOCK_CACHE is not set
>  CONFIG_DM_I2C=y
> -CONFIG_TWL4030_LED=y
>  CONFIG_DM_MMC=y
>  # CONFIG_MMC_HW_PARTITIONING is not set
>  # CONFIG_MMC_VERBOSE is not set
> @@ -59,10 +62,8 @@ CONFIG_CONS_INDEX=3
>  CONFIG_SYS_NS16550=y
>  CONFIG_SPI=y
>  CONFIG_USB=y
> -CONFIG_USB_MUSB_HCD=y
>  CONFIG_USB_MUSB_UDC=y
>  CONFIG_USB_OMAP3=y
> -CONFIG_TWL4030_USB=y
>  CONFIG_CFB_CONSOLE=y
>  CONFIG_CFB_CONSOLE_ANSI=y
>  # CONFIG_VGA_AS_SINGLE_DEVICE is not set
> diff --git a/doc/README.nokia_rx51 b/doc/README.nokia_rx51
> index 320b5efc7d..84d1912ddd 100644
> --- a/doc/README.nokia_rx51
> +++ b/doc/README.nokia_rx51
> @@ -24,8 +24,7 @@ called u-boot-gen-combined. It is available in
> following repository: There is support for hardware watchdog.
> Hardware watchdog is started by NOLO so u-boot must kick watchdog to
> prevent reboot device (but not very often, max every 2 seconds).
> There is also support for framebuffer display -output with ANSI
> escape codes and the N900 HW keyboard input. USB tty works -but is
> disabled because it prevents the current Maemo kernel from booting.
> +output with ANSI escape codes and the N900 HW keyboard input. 
>  When U-Boot is starting it enable IBE bit in Auxiliary Control
> Register, which is needed for Thumb-2 ISA support. It is workaround
> for errata 430973. @@ -49,10 +48,6 @@ Boot from SD or eMMC in this
> order: 
>  Available additional commands/variables:
>  
> - * run sercon - Use serial port for control
> - * run usbcon - Use usbtty for control
> - * run vgacon - Use framebuffer and HW keyboard for control (default)
> -
>   * run sdboot - Boot from external SD card (see boot order)
>   * run emmcboot - Boot from internal eMMC memory (see boot order)
>   * run attachboot - Boot attached kernel image (attached to U-Boot
> binary) @@ -87,14 +82,6 @@ Additional variables for booting kernel:
>   and u-boot standard output is set to serial then setup_console_atag
> is automatically set to 1. So output from Maemo kernel would go to
> serial port. 
> -USB TTY:
> -
> - Maemo kernel 2.6.28 will crash if u-boot enable usb tty. So USB TTY
> is disabled.
> - For enabling USB TTY just add this line to file
> include/configs/nokia_rx51.h -
> - #define CONFIG_USB_TTY
> -
> -
>  UBIFS support:
>  
>   UBIFS support is disabled, because U-Boot image is too big and
> cannot be diff --git a/include/configs/nokia_rx51.h
> b/include/configs/nokia_rx51.h index 3f2700d8e2..23368de624 100644
> --- a/include/configs/nokia_rx51.h
> +++ b/include/configs/nokia_rx51.h
> @@ -70,10 +70,12 @@
>  
>  /* USB device configuration */
>  #define CONFIG_USB_DEVICE
> +#define CONFIG_USB_TTY
>  #define CONFIG_USBD_VENDORID 0x0421
> -#define CONFIG_USBD_PRODUCTID0x01c8
> +#define CONFIG_USBD_PRODUCTID_CDCACM 0x01c8
> +#define CONFIG_USBD_PRODUCTID_GSERIAL0x01c8
>  #define CONFIG_USBD_MANUFACTURER "Nokia"
> -#define CONFIG_USBD_PRODUCT_NAME "N900"
> +#define CONFIG_USBD_PRODUCT_NAME "N900 (U-Boot)"
>  
>  #define GPIO_SLIDE   71
>  
> @@ -108,15 +110,9 @@ int rx51_kp_getc(struct stdio_dev *sdev);
>  /* Environment information */
>  #define CONFIG_EXTRA_ENV_SETTINGS \
>   "usbtty=cdc_acm\0" \
> - "stdin=

Re: [RESEND PATCH 15/16] Nokia RX-51: Move content of rx51.h to rx51.c

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:11 +0100
Pali Rohár  wrote:

> After removal of MUX configuration there is no need to have extra
> rx51.h.
> 
> Signed-off-by: Pali Rohár 
> ---
>  board/nokia/rx51/rx51.c | 17 -
>  board/nokia/rx51/rx51.h | 31 ---
>  2 files changed, 16 insertions(+), 32 deletions(-)
>  delete mode 100644 board/nokia/rx51/rx51.h
> 
> diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
> index cb72ffaaa9..0597a94faa 100644
> --- a/board/nokia/rx51/rx51.c
> +++ b/board/nokia/rx51/rx51.c
> @@ -39,9 +39,24 @@
>  #include 
>  #include 
>  
> -#include "rx51.h"
>  #include "tag_omap.h"
>  
> +/* Needed for ROM SMC call */
> +struct emu_hal_params_rx51 {
> + u32 num_params;
> + u32 param1;
> + u32 param2;
> + u32 param3;
> + u32 param4;
> +};
> +
> +#define ONENAND_GPMC_CONFIG1_RX510xfb001202
> +#define ONENAND_GPMC_CONFIG2_RX510x0000
> +#define ONENAND_GPMC_CONFIG3_RX510x00020200
> +#define ONENAND_GPMC_CONFIG4_RX510x11001102
> +#define ONENAND_GPMC_CONFIG5_RX510x03101616
> +#define ONENAND_GPMC_CONFIG6_RX510x9006
> +
>  DECLARE_GLOBAL_DATA_PTR;
>  
>  GraphicDevice gdev;
> diff --git a/board/nokia/rx51/rx51.h b/board/nokia/rx51/rx51.h
> deleted file mode 100644
> index 0eddb06219..00
> --- a/board/nokia/rx51/rx51.h
> +++ /dev/null
> @@ -1,31 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0+ */
> -/*
> - * (C) Copyright 2012
> - * Ивайло Димитров 
> - *
> - * (C) Copyright 2011-2012
> - * Pali Rohár 
> - *
> - * (C) Copyright 2008
> - * Dirk Behme 
> - */
> -#ifndef _RX51_H_
> -#define _RX51_H_
> -
> -/* Needed for ROM SMC call */
> -struct emu_hal_params_rx51 {
> - u32 num_params;
> - u32 param1;
> - u32 param2;
> - u32 param3;
> - u32 param4;
> -};
> -
> -#define ONENAND_GPMC_CONFIG1_RX510xfb001202
> -#define ONENAND_GPMC_CONFIG2_RX510x0000
> -#define ONENAND_GPMC_CONFIG3_RX510x00020200
> -#define ONENAND_GPMC_CONFIG4_RX510x11001102
> -#define ONENAND_GPMC_CONFIG5_RX510x03101616
> -#define ONENAND_GPMC_CONFIG6_RX510x9006
> -
> -#endif

Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgp_yehQp27I5.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 14/16] Nokia RX-51: Remove function set_muxconf_regs()

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:10 +0100
Pali Rohár  wrote:

> This function is not used and was never called.
> 
> This board contains '#define CONFIG_SKIP_LOWLEVEL_INIT' because
> X-Loader set everything up, including MUX configuration.
> 
> Also this MUX configuration is incorrect and does not match hardware.
> 
> So remove this dead, unused and broken code.
> 
> This change will decrease size of U-Boot binary.
> 
> Signed-off-by: Pali Rohár 
> ---
>  board/nokia/rx51/rx51.c |  11 --
>  board/nokia/rx51/rx51.h | 346
>  2 files changed, 357
> deletions(-)
> 
> diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c
> index 84739ae129..cb72ffaaa9 100644
> --- a/board/nokia/rx51/rx51.c
> +++ b/board/nokia/rx51/rx51.c
> @@ -467,17 +467,6 @@ int misc_init_r(void)
>   return 0;
>  }
>  
> -/*
> - * Routine: set_muxconf_regs
> - * Description: Setting up the configuration Mux registers specific
> to the
> - *   hardware. Many pins need to be moved from protect
> to primary
> - *   mode.
> - */
> -void set_muxconf_regs(void)
> -{
> - MUX_RX51();
> -}
> -
>  static unsigned long int twl_wd_time; /* last time of watchdog reset
> */ static unsigned long int twl_i2c_lock;
>  
> diff --git a/board/nokia/rx51/rx51.h b/board/nokia/rx51/rx51.h
> index 4eff823a1b..0eddb06219 100644
> --- a/board/nokia/rx51/rx51.h
> +++ b/board/nokia/rx51/rx51.h
> @@ -21,352 +21,6 @@ struct emu_hal_params_rx51 {
>   u32 param4;
>  };
>  
> -/*
> - * IEN  - Input Enable
> - * IDIS - Input Disable
> - * PTD  - Pull type Down
> - * PTU  - Pull type Up
> - * DIS  - Pull type selection is inactive
> - * EN   - Pull type selection is active
> - * M0   - Mode 0
> - * The commented string gives the final mux configuration for that
> pin
> - */
> -#define MUX_RX51() \
> -/* SDRC */\
> - MUX_VAL(CP(SDRC_D0),(IEN  | PTD | DIS | M0))
> /*SDRC_D0*/\
> - MUX_VAL(CP(SDRC_D1),(IEN  | PTD | DIS | M0))
> /*SDRC_D1*/\
> - MUX_VAL(CP(SDRC_D2),(IEN  | PTD | DIS | M0))
> /*SDRC_D2*/\
> - MUX_VAL(CP(SDRC_D3),(IEN  | PTD | DIS | M0))
> /*SDRC_D3*/\
> - MUX_VAL(CP(SDRC_D4),(IEN  | PTD | DIS | M0))
> /*SDRC_D4*/\
> - MUX_VAL(CP(SDRC_D5),(IEN  | PTD | DIS | M0))
> /*SDRC_D5*/\
> - MUX_VAL(CP(SDRC_D6),(IEN  | PTD | DIS | M0))
> /*SDRC_D6*/\
> - MUX_VAL(CP(SDRC_D7),(IEN  | PTD | DIS | M0))
> /*SDRC_D7*/\
> - MUX_VAL(CP(SDRC_D8),(IEN  | PTD | DIS | M0))
> /*SDRC_D8*/\
> - MUX_VAL(CP(SDRC_D9),(IEN  | PTD | DIS | M0))
> /*SDRC_D9*/\
> - MUX_VAL(CP(SDRC_D10),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D10*/\
> - MUX_VAL(CP(SDRC_D11),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D11*/\
> - MUX_VAL(CP(SDRC_D12),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D12*/\
> - MUX_VAL(CP(SDRC_D13),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D13*/\
> - MUX_VAL(CP(SDRC_D14),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D14*/\
> - MUX_VAL(CP(SDRC_D15),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D15*/\
> - MUX_VAL(CP(SDRC_D16),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D16*/\
> - MUX_VAL(CP(SDRC_D17),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D17*/\
> - MUX_VAL(CP(SDRC_D18),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D18*/\
> - MUX_VAL(CP(SDRC_D19),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D19*/\
> - MUX_VAL(CP(SDRC_D20),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D20*/\
> - MUX_VAL(CP(SDRC_D21),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D21*/\
> - MUX_VAL(CP(SDRC_D22),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D22*/\
> - MUX_VAL(CP(SDRC_D23),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D23*/\
> - MUX_VAL(CP(SDRC_D24),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D24*/\
> - MUX_VAL(CP(SDRC_D25),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D25*/\
> - MUX_VAL(CP(SDRC_D26),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D26*/\
> - MUX_VAL(CP(SDRC_D27),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D27*/\
> - MUX_VAL(CP(SDRC_D28),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D28*/\
> - MUX_VAL(CP(SDRC_D29),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D29*/\
> - MUX_VAL(CP(SDRC_D30),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D30*/\
> - MUX_VAL(CP(SDRC_D31),   (IEN  | PTD | DIS |
> M0)) /*SDRC_D31*/\
> - MUX_VAL(CP(SDRC_CLK),   (IEN  | PTD | DIS |
> M0)) /*SDRC_CLK*/\
> - MUX_VAL(CP(SDRC_DQS0),  (IEN  | PTD | DIS |
> M0)) /*SDRC_DQS0*/\
> - MUX_VAL(CP(SDRC_DQS1),  (IEN  | PTD | DIS |
> M0)) /*SDRC_DQS1*/\
> - MUX_VAL(CP(SDRC_DQS2),  (IEN  | PTD | DIS |
> M0)) /*SDRC_DQS2*/\
> - MUX_VAL(CP(SDRC_DQS3),  (IEN  | PTD | DIS |
> M0)) /*SDRC_DQS3*/\ -/* GPMC */\
> - MUX_VAL(CP(GPMC_A1),(IDIS | PTD | DIS | M0))
> /*GPMC_A1*/\
> - MUX_VAL(CP(GPMC_A2),(IDIS | PTD | DIS | M0))
> /*GPMC

Re: [RESEND PATCH 13/16] arm: omap3: Compile s_init() function only when it is used

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:09 +0100
Pali Rohár  wrote:

> Function s_init() is called only from lowlevel_init(). So compile it
> only when function lowlevel_init() is compiled.
> 

Reviewed-by: Lukasz Majewski 

> Signed-off-by: Pali Rohár 
> ---
>  arch/arm/mach-omap2/omap3/board.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/arm/mach-omap2/omap3/board.c
> b/arch/arm/mach-omap2/omap3/board.c index 4da8df47cc..029bd54595
> 100644 --- a/arch/arm/mach-omap2/omap3/board.c
> +++ b/arch/arm/mach-omap2/omap3/board.c
> @@ -179,6 +179,8 @@ void early_system_init(void)
>   hw_data_init();
>  }
>  
> +#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \
> + !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY)
>  
> /**
>   * Routine: s_init
>   * Description: Does early system init of muxing and clocks.
> @@ -207,6 +209,7 @@ void s_init(void)
>   ehci_clocks_enable();
>  #endif
>  }
> +#endif
>  
>  #ifdef CONFIG_SPL_BUILD
>  void board_init_f(ulong dummy)




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpQsbmYtVGH3.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 12/16] arm: omap3: Compile lowlevel_init() function only when it is used

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:08 +0100
Pali Rohár  wrote:

> Function lowlevel_init() is called only from cpu_init_crit() and this
> function is wrapped into #if .. #endif section. So compile also
> lowlevel_init() function under same #if condition.
> 
> Signed-off-by: Pali Rohár 
> ---
>  arch/arm/mach-omap2/omap3/lowlevel_init.S | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-omap2/omap3/lowlevel_init.S
> b/arch/arm/mach-omap2/omap3/lowlevel_init.S index
> 2a05b5e521..4fa89418a1 100644 ---
> a/arch/arm/mach-omap2/omap3/lowlevel_init.S +++
> b/arch/arm/mach-omap2/omap3/lowlevel_init.S @@ -45,7 +45,7 @@
> ENDPROC(do_omap3_emu_romcode_call) ENTRY(cpy_clk_code)
>   /* Copy DPLL code into SRAM */
>   adr r0, go_to_speed /* copy from start
> of go_to_speed... */
> - adr r2, lowlevel_init   /* ... up to start of
> low_level_init */
> + adr r2, go_to_speed_end /* ... up to start of
> go_to_speed_end */ next2:
>   ldmia   r0!, {r3 - r10} /* copy from
> source address [r0] */ stmia  r1!, {r3 - r10} /*
> copy to   target address [r1] */ @@ -167,8 +167,11 @@ pll_div_add5:
>  pll_div_val5:
>   .word CLSEL1_EMU_VAL
>  
> +go_to_speed_end:
>  #endif
>  
> +#if !defined(CONFIG_SKIP_LOWLEVEL_INIT) && \
> + !defined(CONFIG_SKIP_LOWLEVEL_INIT_ONLY)
>  ENTRY(lowlevel_init)
>   ldr sp, SRAM_STACK
>   str ip, [sp]/* stash ip register */
> @@ -187,6 +190,7 @@ ENTRY(lowlevel_init)
>   b   s_init
>  
>  ENDPROC(lowlevel_init)
> +#endif
>  
>   /* the literal pools origin */
>   .ltorg

Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpOLUtWWcI5g.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 11/16] usb: gadget: Use dbg_ep0() macro instead of serial_printf()

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:07 +0100
Pali Rohár  wrote:

> All debug messages from ep0.c except a few are printed by dbg_ep0()
> macro. So for remaining few exception use also dbg_ep0() instead of
> serial_printf().

Reviewed-by: Lukasz Majewski 

> 
> Signed-off-by: Pali Rohár 
> ---
>  drivers/usb/gadget/ep0.c | 16 
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/gadget/ep0.c b/drivers/usb/gadget/ep0.c
> index 457679f0a4..6624f61b76 100644
> --- a/drivers/usb/gadget/ep0.c
> +++ b/drivers/usb/gadget/ep0.c
> @@ -294,7 +294,7 @@ static int ep0_get_descriptor (struct
> usb_device_instance *device, {
>   struct usb_string_descriptor
> *string_descriptor; if (!(string_descriptor = usbd_get_string
> (index))) {
> - serial_printf("Invalid string index
> %d\n", index);
> + dbg_ep0(0, "Invalid string index
> %d\n", index); return -1;
>   }
>   dbg_ep0(3, "string_descriptor: %p length
> %d", string_descriptor, string_descriptor->bLength); @@ -302,14
> +302,14 @@ static int ep0_get_descriptor (struct usb_device_instance
> *device, } break;
>   case USB_DESCRIPTOR_TYPE_INTERFACE:
> - serial_printf("USB_DESCRIPTOR_TYPE_INTERFACE - error not
> implemented\n");
> + dbg_ep0(2, "USB_DESCRIPTOR_TYPE_INTERFACE - error
> not implemented\n"); return -1;
>   case USB_DESCRIPTOR_TYPE_ENDPOINT:
> - serial_printf("USB_DESCRIPTOR_TYPE_ENDPOINT - error
> not implemented\n");
> + dbg_ep0(2, "USB_DESCRIPTOR_TYPE_ENDPOINT - error not
> implemented\n"); return -1;
>   case USB_DESCRIPTOR_TYPE_HID:
>   {
> - serial_printf("USB_DESCRIPTOR_TYPE_HID -
> error not implemented\n");
> + dbg_ep0(2, "USB_DESCRIPTOR_TYPE_HID - error
> not implemented\n"); return -1;   /* unsupported at this time */
>  #if 0
>   int bNumInterface =
> @@ -338,7 +338,7 @@ static int ep0_get_descriptor (struct
> usb_device_instance *device, break;
>   case USB_DESCRIPTOR_TYPE_REPORT:
>   {
> - serial_printf("USB_DESCRIPTOR_TYPE_REPORT -
> error not implemented\n");
> + dbg_ep0(2, "USB_DESCRIPTOR_TYPE_REPORT -
> error not implemented\n"); return -1; /* unsupported at this
> time */ #if 0
>   int bNumInterface =
> @@ -531,7 +531,7 @@ int ep0_recv_setup (struct urb *urb)
>  le16_to_cpu
> (request->wValue) & 0xff); 
>   case USB_REQ_GET_CONFIGURATION:
> - serial_printf("get config %d\n",
> device->configuration);
> + dbg_ep0(2, "get config %d\n",
> device->configuration); return ep0_get_one (device, urb,
>   device->configuration);
>  
> @@ -621,14 +621,14 @@ int ep0_recv_setup (struct urb *urb)
>   device->interface = device->alternate = 0;
>  
>   /*dbg_ep0(2, "set configuration: %d",
> device->configuration); */
> - /*serial_printf("DEVICE_CONFIGURED..
> event?\n"); */
> + /*dbg_ep0(2, "DEVICE_CONFIGURED..
> event?\n"); */ return 0;
>  
>   case USB_REQ_SET_INTERFACE:
>   device->interface = le16_to_cpu
> (request->wIndex); device->alternate = le16_to_cpu (request->wValue);
>   /*dbg_ep0(2, "set interface: %d alternate:
> %d", device->interface, device->alternate); */
> - serial_printf("DEVICE_SET_INTERFACE..
> event?\n");
> + dbg_ep0(2, "DEVICE_SET_INTERFACE..
> event?\n"); return 0;
>  
>   case USB_REQ_GET_STATUS:




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgp66gNTCFHCQ.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 10/16] usb: musb: Ensure that we set musb dynamic FIFO buffer for every endpoint

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:06 +0100
Pali Rohár  wrote:

> If we do not set FIFO buffer address and size for some endpoint which
> is in use then default address 0x0 would be used which is in conflict
> with FIFO buffer for endpoint 0 which is at fixed address 0x0.
> Sharing address space between more endpoint cause data loss and
> unexpected errors.
> 
> This patch is fixing transmission of characters over usbtty serial
> console and allow using of usbtty for debugging purposes on Nokia
> N900.

Reviewed-by: Lukasz Majewski 

> 
> Signed-off-by: Pali Rohár 
> ---
>  drivers/usb/musb/musb_udc.c | 14 ++
>  1 file changed, 2 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
> index 50d8bc319c..ea1284850e 100644
> --- a/drivers/usb/musb/musb_udc.c
> +++ b/drivers/usb/musb/musb_udc.c
> @@ -875,18 +875,8 @@ void udc_setup_ep(struct usb_device_instance
> *device, unsigned int id, ep0_endpoint->endpoint_address = 0xff;
>   ep0_urb = usbd_alloc_urb(device, endpoint);
>   } else if (MAX_ENDPOINT >= id) {
> - int ep_addr;
> -
> - /* Check the direction */
> - ep_addr = endpoint->endpoint_address;
> - if (USB_DIR_IN == (ep_addr & USB_ENDPOINT_DIR_MASK))
> {
> - /* IN */
> - epinfo[(id * 2) + 1].epsize =
> endpoint->tx_packetSize;
> - } else {
> - /* OUT */
> - epinfo[id * 2].epsize =
> endpoint->rcv_packetSize;
> - }
> -
> + epinfo[(id * 2) + 0].epsize =
> endpoint->rcv_packetSize;
> + epinfo[(id * 2) + 1].epsize =
> endpoint->tx_packetSize; musb_configure_ep(&epinfo[0],
> ARRAY_SIZE(epinfo)); } else {
>   if (debug_level > 0)




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgplw0wBEGRFp.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 09/16] usb: musb: Fix handling interrupts for EP0 and SET ADDRESS commmand

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:05 +0100
Pali Rohár  wrote:

> Interrupt for EP0 is indicated in intrtx register via first bit. It
> is set for both RX and TX. First bit in intrrx register is reserved
> and not set.
> 
> So remove calling musb_peri_ep0() function at every iteration of
> udc_irq() and musb_peri_rx() and call it only from musb_peri_tx()
> when correct interrupt bit in initrtx it set.
> 
> Address from SET ADDRESS command must be set to faddr register only
> after acknowledging SERV_RXPKTRDY followed by received EP0 interrupt.
> So prior calling musb_peri_ep0_set_address() check for EP0 interrupt
> instead of (incorrect) MUSB_INTR_SOF interrupt.
> 
> This patch fixes issue that host (computer) cannot register U-Boot USB
> device and failing with errors:
> 
> usb 1-1: new full-speed USB device number 86 using xhci_hcd
> usb 1-1: Device not responding to setup address.
> usb 1-1: Device not responding to setup address.
> usb 1-1: device not accepting address 86, error -71
> 
> U-Boot was writing address to faddr register too early and did not
> wait for correct interrupt after which should update address.
> 


Reviewed-by: Lukasz Majewski 

> Signed-off-by: Pali Rohár 
> ---
>  drivers/usb/musb/musb_udc.c | 12 
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
> index 7c74422623..50d8bc319c 100644
> --- a/drivers/usb/musb/musb_udc.c
> +++ b/drivers/usb/musb/musb_udc.c
> @@ -707,9 +707,7 @@ static void musb_peri_rx(u16 intr)
>  {
>   unsigned int ep;
>  
> - /* Check for EP0 */
> - if (0x01 & intr)
> - musb_peri_ep0();
> + /* First bit is reserved and does not indicate interrupt for
> EP0 */ 
>   for (ep = 1; ep < 16; ep++) {
>   if ((1 << ep) & intr)
> @@ -721,9 +719,9 @@ static void musb_peri_tx(u16 intr)
>  {
>   unsigned int ep;
>  
> - /* Check for EP0 */
> + /* Check for EP0: first bit indicates interrupt for both RX
> and TX */ if (0x01 & intr)
> - musb_peri_ep0_tx();
> + musb_peri_ep0();
>  
>   for (ep = 1; ep < 16; ep++) {
>   if ((1 << ep) & intr)
> @@ -750,8 +748,6 @@ void udc_irq(void)
>   musb_peri_resume();
>   }
>  
> - musb_peri_ep0();
> -
>   if (MUSB_INTR_RESET & intrusb) {
>   usbd_device_event_irq(udc_device,
> DEVICE_RESET, 0); musb_peri_reset();
> @@ -790,7 +786,7 @@ void udc_irq(void)
>   if (intrtx)
>   musb_peri_tx(intrtx);
>   } else {
> - if (MUSB_INTR_SOF & intrusb) {
> + if (readw(&musbr->intrtx) & 0x1) {
>   u8 faddr;
>   faddr = readb(&musbr->faddr);
>   /*




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpHszgm5sIKH.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 08/16] usb: musb: Fix receiving of bigger buffers

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:04 +0100
Pali Rohár  wrote:

> If musb_peri_rx_ep() was called to processed received HW buffer but
> U-Boot cannot read it yet (e.g. because U-Boot SW buffer is full)
> then interrupt was marked as processed but HW buffer stayed
> unprocessed.
> 
> U-Boot tried to process this buffer again when it receive interrupt
> again, but it can receive it only when sender (host) send a new data.
> As sender (host) is not going to send a new data until U-Boot process
> current data this issue caused a deadlock in case sender (host) is
> emitting data faster than U-Boot can process it.
> 
> Reading musb intrrx register automatically clears this register and
> mark interrupt as processed. So to prevent marking interrupt in
> U-Boot as processed and a new variable pending_intrrx which would
> contain unprocessed bits of intrrx register.
> 
> And as a second step, every time when musb_peri_rx_ep() is called and
> there are waiting data to be processed (signaled by
> MUSB_RXCSR_RXPKTRDY) either acknowledge sender (via
> musb_peri_rx_ack()) that whole HW buffer was processed or set
> corresponding bit in pending_intrrx that HW buffer was not fully
> processed yet and next iteration is required after U-Boot allocate
> space for reading HW buffer.
> 
> This patch fixes receiving large usb buffers, e.g. file transfer via
> Kermit protocol implemented by 'loadb' U-Boot command over usbtty
> serial console.

Reviewed-by: Lukasz Majewski 

> 
> Signed-off-by: Pali Rohár 
> ---
>  drivers/usb/musb/musb_udc.c | 16 +++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
> index 28719cc3f6..7c74422623 100644
> --- a/drivers/usb/musb/musb_udc.c
> +++ b/drivers/usb/musb/musb_udc.c
> @@ -104,6 +104,8 @@ struct usb_endpoint_instance *ep0_endpoint;
>  static struct usb_device_instance *udc_device;
>  static int enabled;
>  
> +u16 pending_intrrx;
> +
>  #ifdef MUSB_DEBUG
>  static void musb_db_regs(void)
>  {
> @@ -664,7 +666,10 @@ static void musb_peri_rx_ep(unsigned int ep)
>   /* The common musb fifo reader */
>   read_fifo(ep, length, data);
>  
> - musb_peri_rx_ack(ep);
> + if (length == peri_rxcount)
> + musb_peri_rx_ack(ep);
> + else
> + pending_intrrx |= (1 << ep);
>  
>   /*
>* urb's actual_length is updated in
> @@ -677,18 +682,24 @@ static void musb_peri_rx_ep(unsigned int ep)
>   serial_printf("ERROR : %s %d
> no space " "in rcv buffer\n",
> __PRETTY_FUNCTION__,
> ep); +
> + pending_intrrx |= (1 << ep);
>   }
>   } else {
>   if (debug_level > 0)
>   serial_printf("ERROR : %s %d problem
> with " "endpoint\n",
> __PRETTY_FUNCTION__,
> ep); +
> + pending_intrrx |= (1 << ep);
>   }
>  
>   } else {
>   if (debug_level > 0)
>   serial_printf("ERROR : %s %d with nothing to
> do\n", __PRETTY_FUNCTION__, ep);
> +
> + musb_peri_rx_ack(ep);
>   }
>  }
>  
> @@ -770,6 +781,9 @@ void udc_irq(void)
>   intrrx = readw(&musbr->intrrx);
>   intrtx = readw(&musbr->intrtx);
>  
> + intrrx |= pending_intrrx;
> + pending_intrrx = 0;
> +
>   if (intrrx)
>   musb_peri_rx(intrrx);
>  




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpaD_rshHxnV.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 07/16] usb: musb: Fix transmission of bigger buffers

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:03 +0100
Pali Rohár  wrote:

> If udc_endpoint_write() was called with bigger payload which does not
> fit into one USB packet it needs to be transmitted in more USB
> packets. First packet is transmitted by udc_endpoint_write() call
> itself and other packets are put into waiting queue.
> 
> Implement function musb_peri_tx() which transmit checks when
> endpoints are ready and continue transmitting of waiting queue.
> 
> This patch fixes sending e.g. output of printenv command over usbtty
> serial console.

Reviewed-by: Lukasz Majewski 

> 
> Signed-off-by: Pali Rohár 
> ---
>  drivers/usb/musb/musb_udc.c | 17 ++---
>  1 file changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
> index 67d1c56f9a..28719cc3f6 100644
> --- a/drivers/usb/musb/musb_udc.c
> +++ b/drivers/usb/musb/musb_udc.c
> @@ -708,21 +708,16 @@ static void musb_peri_rx(u16 intr)
>  
>  static void musb_peri_tx(u16 intr)
>  {
> + unsigned int ep;
> +
>   /* Check for EP0 */
>   if (0x01 & intr)
>   musb_peri_ep0_tx();
>  
> - /*
> -  * Use this in the future when handling epN tx
> -  *
> -  * u8 ep;
> -  *
> -  * for (ep = 1; ep < 16; ep++) {
> -  *  if ((1 << ep) & intr) {
> -  *  / * handle tx for this endpoint * /
> -  *  }
> -  * }
> -  */
> + for (ep = 1; ep < 16; ep++) {
> + if ((1 << ep) & intr)
> + udc_endpoint_write(GET_ENDPOINT(udc_device,
> ep));
> + }
>  }
>  
>  void udc_irq(void)




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpz1LTH9UfUj.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 06/16] usb: musb: Read value of PERI_RXCSR to 16bit variable

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:02 +0100
Pali Rohár  wrote:

> PERI_RXCSR is 16bit register so store its value into 16bit local
> variable.
> 
> Signed-off-by: Pali Rohár 
> ---
>  drivers/usb/musb/musb_udc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c
> index d901f8777c..67d1c56f9a 100644
> --- a/drivers/usb/musb/musb_udc.c
> +++ b/drivers/usb/musb/musb_udc.c
> @@ -629,7 +629,7 @@ static void musb_peri_ep0(void)
>  static void musb_peri_rx_ep(unsigned int ep)
>  {
>   u16 peri_rxcount;
> - u8 peri_rxcsr = readw(&musbr->ep[ep].epN.rxcsr);
> + u16 peri_rxcsr = readw(&musbr->ep[ep].epN.rxcsr);
>  
>   if (!(peri_rxcsr & MUSB_RXCSR_RXPKTRDY)) {
>   if (debug_level > 0)

Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgp7_qrfeztP4.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 05/16] usb: musb: Fix configuring FIFO for endpoints

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:01 +0100
Pali Rohár  wrote:

> This patch fixes configuring FIFO for one-directional endpoints which
> have either RX or TX queue and therefore only one FIFO.
> 
> Size of FIFO buffer is 2^(idx+3) bytes and starting address is
> 2^(addr+3). Moreover first 64 bytes are reserved for EP0.
> 
> Without this patch if FIFO size specified by caller was zero then idx
> was incorrectly calculated (expr. ffs(0)-1) and size overflowed in
> fifosz register. This register uses has only 4 bits for FIFO size.
> Moreover specifying zero size is not possible.
> 
> This patch is fixing calculation of start address and buffer size to
> minimal value and ensure that it would not overlap with reserved EP0
> buffer.
> 
> This issue caused loose of packets on USB bus in both directions and
> basically usbtty was unusable.
> 

Reviewed-by: Lukasz Majewski 

> Signed-off-by: Pali Rohár 
> 
> ---
> Changes in v2:
> * Correctly calculate minimal buffer size
> * Store into fifoaddr address in musb units (8 bytes)
> ---
>  drivers/usb/musb/musb_core.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_core.c
> b/drivers/usb/musb/musb_core.c index cc6dc3839d..9651f074a4 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -50,7 +50,7 @@ void musb_start(void)
>  # define config_fifo(dir, idx, addr) \
>   do { \
>   writeb(idx, &musbr->dir##fifosz); \
> - writew(fifoaddr >> 3, &musbr->dir##fifoadd); \
> + writew(addr, &musbr->dir##fifoadd); \
>   } while (0)
>  #endif
>  
> @@ -66,14 +66,14 @@ void musb_start(void)
>  void musb_configure_ep(const struct musb_epinfo *epinfo, u8 cnt)
>  {
>   u16 csr;
> - u16 fifoaddr = 64; /* First 64 bytes of FIFO reserved for
> EP0 */
> + u16 fifoaddr = 64 >> 3; /* First 64 bytes of FIFO reserved
> for EP0 */ u32 fifosize;
>   u8  idx;
>  
>   while (cnt--) {
>   /* prepare fifosize to write to register */
>   fifosize = epinfo->epsize >> 3;
> - idx = ffs(fifosize) - 1;
> + idx = fifosize ? ((ffs(fifosize) - 1) & 0xF) : 0;
>  
>   writeb(epinfo->epnum, &musbr->index);
>   if (epinfo->epdir) {
> @@ -99,7 +99,7 @@ void musb_configure_ep(const struct musb_epinfo
> *epinfo, u8 cnt) writew(csr | MUSB_RXCSR_FLUSHFIFO,
>   &musbr->rxcsr);
>   }
> - fifoaddr += epinfo->epsize;
> + fifoaddr += 1 << idx;
>   epinfo++;
>   }
>  }




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpjHE5zNHUTN.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 04/16] usb: musb: Always clear the data toggle bit when configuring ep

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:12:00 +0100
Pali Rohár  wrote:

> Without this patch it was done only when U-Boot was compiled with
> MUSB Host Controller. But it is needed also for MUSB Device
> Controller, otherwise Device Controller does not work.
> 

Reviewed-by: Lukasz Majewski 

> Signed-off-by: Pali Rohár 
> ---
>  drivers/usb/musb/musb_core.c | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_core.c
> b/drivers/usb/musb/musb_core.c index 147b2eb929..cc6dc3839d 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -81,10 +81,8 @@ void musb_configure_ep(const struct musb_epinfo
> *epinfo, u8 cnt) config_fifo(tx, idx, fifoaddr);
>  
>   csr = readw(&musbr->txcsr);
> -#if defined(CONFIG_USB_MUSB_HCD)
>   /* clear the data toggle bit */
>   writew(csr | MUSB_TXCSR_CLRDATATOG,
> &musbr->txcsr); -#endif
>   /* Flush fifo if required */
>   if (csr & MUSB_TXCSR_TXPKTRDY)
>   writew(csr | MUSB_TXCSR_FLUSHFIFO,
> @@ -94,10 +92,8 @@ void musb_configure_ep(const struct musb_epinfo
> *epinfo, u8 cnt) config_fifo(rx, idx, fifoaddr);
>  
>   csr = readw(&musbr->rxcsr);
> -#if defined(CONFIG_USB_MUSB_HCD)
>   /* clear the data toggle bit */
>   writew(csr | MUSB_RXCSR_CLRDATATOG,
> &musbr->rxcsr); -#endif
>   /* Flush fifo if required */
>   if (csr & MUSB_RXCSR_RXPKTRDY)
>   writew(csr | MUSB_RXCSR_FLUSHFIFO,




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpuoEsqkuVu6.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 03/16] usb: musb: Fix compilation of gadget code

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:11:59 +0100
Pali Rohár  wrote:

> musb udc code depends on usb gadget code provided by
> CONFIG_USB_DEVICE and defined in drivers/usb/gadget/Makefile. But
> this Makefile is not included into U-Boot build when
> CONFIG_USB_GADGET is not set. As CONFIG_USB_DEVICE cannot be enabled
> together with CONFIG_USB_GADGET it means that dependency for musb udc
> code is not compiled during build. Fix it by including
> drivers/usb/gadget dependency also when CONFIG_USB_DEVICE is set.
> 
> This patch fixes compile errors:
> 
> arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function
> `musb_peri_ep0_rx': u-boot/drivers/usb/musb/musb_udc.c: undefined
> reference to `ep0_recv_setup' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o: in function `musb_peri_ep0_idle':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `ep0_recv_setup' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o: in function
> `musb_peri_ep0_zero_data_request':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o: in function `musb_peri_ep0_idle':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `ep0_recv_setup' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o: in function `musb_peri_ep0_rx':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_rcv_complete' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o: in function `musb_peri_rx_ep':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_rcv_complete' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o: in function `udc_endpoint_write':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_tx_complete' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o: in function `udc_irq':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' arm-linux-gnueabi-ld.bfd:
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' arm-linux-gnueabi-ld.bfd:
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' arm-linux-gnueabi-ld.bfd:
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' arm-linux-gnueabi-ld.bfd:
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o:u-boot/drivers/usb/musb/musb_udc.c: more
> undefined references to `usbd_device_event_irq' follow
> arm-linux-gnueabi-ld.bfd: drivers/usb/musb/built-in.o: in function
> `udc_setup_ep': u-boot/drivers/usb/musb/musb_udc.c: undefined
> reference to `usbd_alloc_urb' arm-linux-gnueabi-ld.bfd:
> drivers/usb/musb/built-in.o: in function `udc_startup_events':
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' arm-linux-gnueabi-ld.bfd:
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' arm-linux-gnueabi-ld.bfd:
> u-boot/drivers/usb/musb/musb_udc.c: undefined reference to
> `usbd_device_event_irq' make: *** [Makefile:1762: u-boot] Error 1
> 

Reviewed-by: Lukasz Majewski 

> Signed-off-by: Pali Rohár 
> ---
>  Makefile | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Makefile b/Makefile
> index 23dd11f723..2173344497 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -792,6 +792,7 @@ libs-y += drivers/usb/dwc3/
>  libs-y += drivers/usb/common/
>  libs-y += drivers/usb/emul/
>  libs-y += drivers/usb/eth/
> +libs-$(CONFIG_USB_DEVICE) += drivers/usb/gadget/
>  libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/
>  libs-$(CONFIG_USB_GADGET) += drivers/usb/gadget/udc/
>  libs-y += drivers/usb/host/




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpG67Njn9efs.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 02/16] serial: usbtty: Send urb data in correct order

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:11:58 +0100
Pali Rohár  wrote:

> Function next_urb() selects the last urb data buffer from linked list
> to which next data from usbtty puts should be appended.
> 
> But to check if TX data still exists it is needed to look at the
> first urb data buffer from linked list. So check for endpoint->tx_urb
> (first from the linked list) instead of current_urb (the last from
> the linked list).
> 
> Successful call to udc_endpoint_write() may invalidate active urb and
> allocate new in queue which invalidate pointer returned by next_urb()
> function.
> 
> So call next_urb() prior putting data into urb buffer and call it
> every time after using udc_endpoint_write() function to prevent
> sending data from usbtty puts in incorrect order.
> 
> This patch fixes issue that usbtty code does not transmit data when
> they are waiting in the tx queue.

Reviewed-by: Lukasz Majewski 

> 
> Signed-off-by: Pali Rohár 
> ---
>  drivers/serial/usbtty.c | 12 +++-
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c
> index 02f8edf200..4f4eb02de0 100644
> --- a/drivers/serial/usbtty.c
> +++ b/drivers/serial/usbtty.c
> @@ -849,17 +849,9 @@ static int write_buffer (circbuf_t * buf)
>   &endpoint_instance[tx_endpoint];
>   struct urb *current_urb = NULL;
>  
> - current_urb = next_urb (device_instance, endpoint);
> -
> - if (!current_urb) {
> - TTYERR ("current_urb is NULL, buf->size %d\n",
> - buf->size);
> - return 0;
> - }
> -
>   /* TX data still exists - send it now
>*/
> - if(endpoint->sent < current_urb->actual_length){
> + if(endpoint->sent < endpoint->tx_urb->actual_length){
>   if(udc_endpoint_write (endpoint)){
>   /* Write pre-empted by RX */
>   return -1;
> @@ -878,6 +870,8 @@ static int write_buffer (circbuf_t * buf)
>*/
>   while (buf->size > 0) {
>  
> + current_urb = next_urb (device_instance,
> endpoint); +
>   dest = (char*)current_urb->buffer +
>   current_urb->actual_length;
>  




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpWTS27MBAgK.pgp
Description: OpenPGP digital signature


Re: [RESEND PATCH 01/16] serial: usbtty: Fix puts function

2021-02-06 Thread Lukasz Majewski
On Fri,  5 Feb 2021 20:11:57 +0100
Pali Rohár  wrote:

> This function has incorrect implementation of prepending CR prior LF.
> Without this patch it prepended CR prior whole string which is going
> to be written and let LF without leading CR. Fix this issue by
> inserting CR at correct place to make output on usbtty serial console
> more readable.
> 
> Signed-off-by: Pali Rohár 
> ---
>  drivers/serial/usbtty.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c
> index f1c1a260da..02f8edf200 100644
> --- a/drivers/serial/usbtty.c
> +++ b/drivers/serial/usbtty.c
> @@ -500,8 +500,8 @@ void usbtty_puts(struct stdio_dev *dev, const
> char *str) n = next_nl_pos (str);
>  
>   if (str[n] == '\n') {
> - __usbtty_puts("\r", 1);
> - __usbtty_puts(str, n + 1);
> + __usbtty_puts(str, n);
> + __usbtty_puts("\r\n", 2);
>   str += (n + 1);
>   len -= (n + 1);
>   } else {

Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lu...@denx.de


pgpu8wb8m6tru.pgp
Description: OpenPGP digital signature


Re: [PATCH v2 0/3] mmc: mmc_spi: Fix potential spec violation in receiving card response

2021-02-06 Thread Bin Meng
On Tue, Feb 2, 2021 at 10:48 AM Bin Meng  wrote:
>
>
> After command is sent and before card response shows up on the line,
> there is a variable number of clock cycles in between called Ncr.
> The spec [1] says the minimum is 1 byte and the maximum is 8 bytes.
>
> Current logic in mmc_spi_sendcmd() has a flaw that it could only work
> with certain SD cards with their Ncr being just 1 byte.
>
> When resp_match is false, the codes try to receive only 1 byte from
> the SD card. On the other hand when resp_match is true, the logic
> happens to be no problem as it loops until timeout to receive as many
> bytes as possible to see a match of the expected resp_match_value.
> However not every call to mmc_spi_sendcmd() is made with resp_match
> being true hence this exposes a potential issue with SD cards that
> have a larger Ncr value.
>
> Given no issue was reported as of today, we can reasonably conclude
> that all cards being used on the supported boards happen to have a 1
> byte Ncr timing requirement. But a broken case can be triggered by
> utilizing QEMU to emulate a larger value of Ncr (by default 1 byte
> Ncr is used on QEMU). This series fixes such potential spec violation
> to improve the card compatibility.
>
> [1] "Physical Layer Specification Version 8.00"
>  chapter 7.5.1: Command / Response
>  chapter 7.5.4: Timing Values
>
> Changes in v2:
> - move the check before the debug output
>
> Bin Meng (3):
>   mmc: mmc_spi: Move argument check to the beginning of
> mmc_spi_sendcmd()
>   mmc: mmc_spi: Fix potential spec violation in receiving card response
>   mmc: mmc_spi: Document the 3 local functions
>
>  drivers/mmc/mmc_spi.c | 74 
> ++-
>  1 file changed, 55 insertions(+), 19 deletions(-)
>

Peng, ping?


  1   2   >