Re: [PATCH v3 6/7] tools: add genguid tool

2024-06-04 Thread Heinrich Schuchardt

On 6/5/24 08:36, Heinrich Schuchardt wrote:

On 5/31/24 15:50, Caleb Connolly wrote:

Add a tool that can generate GUIDs that match those generated internally
by U-Boot for capsule update fw_images.

Dynamic UUIDs in U-Boot work by taking a namespace UUID and hashing it
with the board model, compatible, and fw_image name.

This tool accepts the same inputs and will produce the same GUID as
U-Boot would at runtime.


This functionality should be integrated into the mkeficapsule.

Just pass the device-tree into mkeficapsule and generate the GUIDs
whereever they are needed.

Best regards

Heinrich



Signed-off-by: Caleb Connolly 
---
  doc/genguid.1   |  52 +++
  tools/Kconfig   |   7 +++
  tools/Makefile  |   3 ++
  tools/genguid.c | 154


A change to MAINTAINERS is missing.

Best regards

Heinrich



  4 files changed, 216 insertions(+)

diff --git a/doc/genguid.1 b/doc/genguid.1
new file mode 100644
index ..4128055b3a9a
--- /dev/null
+++ b/doc/genguid.1
@@ -0,0 +1,52 @@
+.\" SPDX-License-Identifier: GPL-2.0+
+.\" Copyright (c) 2024, Linaro Limited
+.TH GENGUID 1 "May 2024"
+
+.SH NAME
+genguid \- Generate deterministic EFI capsule image GUIDs for a board
+
+.SH SYNOPSIS
+.B genguid
+.RI GUID " " [ -vj ] " " -c " " COMPAT " " NAME...
+
+.SH "DESCRIPTION"
+The
+.B genguid
+command is used to determine the update image GUIDs for a board using
+dynamic UUIDs. The command takes a namespace GUID (defined in the boards
+defconfig), the boards first compatible string, and the names of the
+firmware images. The command will output the GUIDs for each image.
+
+As the dynamic UUID mechanism generates GUIDs at runtime, it would be
+necessary to actually boot U-Boot on the board and enable debug logs
+to retrieve the generated GUIDs. This tools just simplifies that
process.
+
+.SH "OPTIONS"
+
+.TP
+.BI GUID
+The namespace/salt GUID, same as CONFIG_EFI_CAPSULE_NAMESPACE_UUID.
+The format is:
+    ----
+
+.TP
+.BI "-v\fR,\fB --verbose "
+Print additional information to stderr.
+
+.TP
+.BI "-j\fR,\fB --json "
+Output the results in JSON format (array of object with name/uuid
properties).
+
+.TP
+.BI "-c\fR,\fB --compat " COMPAT
+The first entry in the boards root compatible property.
+
+.TP
+.BI NAME...
+The names of the firmware images to generate GUIDs for (e.g.
"SANDBOX-UBOOT-ENV").
+
+.SH AUTHORS
+Written by Caleb Connolly 
+
+.SH HOMEPAGE
+https://u-boot.org
diff --git a/tools/Kconfig b/tools/Kconfig
index 667807b33173..13201ff61fd4 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -103,8 +103,15 @@ config TOOLS_MKEFICAPSULE
    This command allows users to create a UEFI capsule file and,
    optionally sign that file. If you want to enable UEFI capsule
    update feature on your target, you certainly need this.

+config TOOLS_GENGUID
+    bool "Build genguid command"
+    default y if EFI_CAPSULE_DYNAMIC_UUIDS


Distros have a package u-boot-tools. You want this package to contain
all tools.

Please, ensure that the new tool is built by tools-only_defconfig.


+    help
+  This command allows users to generate the GUIDs that a given
+  board would use for UEFI capsule update feature.
+
  menuconfig FSPI_CONF_HEADER
  bool "FlexSPI Header Configuration"
  help
    FSPI Header Configuration
diff --git a/tools/Makefile b/tools/Makefile
index 6a4280e3668f..29e9a93b0f24 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -253,8 +253,11 @@ HOSTLDLIBS_mkeficapsule += \
  HOSTLDLIBS_mkeficapsule += \
  $(shell pkg-config --libs uuid 2> /dev/null || echo "-luuid")
  hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule

+genguid-objs := generated/lib/uuid.o generated/lib/sha1.o genguid.o
+hostprogs-$(CONFIG_TOOLS_GENGUID) += genguid
+
  mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o
  HOSTLDLIBS_mkfwumdata += -luuid
  hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata

diff --git a/tools/genguid.c b/tools/genguid.c
new file mode 100644
index ..e71bc1d48f95
--- /dev/null
+++ b/tools/genguid.c
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2024 Linaro Ltd.
+ *   Author: Caleb Connolly
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+static struct option options[] = {
+    {"dtb", required_argument, NULL, 'd'},
+    {"compat", required_argument, NULL, 'c'},
+    {"help", no_argument, NULL, 'h'},
+    {"verbose", no_argument, NULL, 'v'},
+    {"json", no_argument, NULL, 'j'},
+    {NULL, 0, NULL, 0},
+};
+
+static void usage(const char *progname)
+{
+    fprintf(stderr, "Usage: %s GUID [-v] -c COMPAT NAME...\n",
progname);
+    fprintf(stderr,
+    "Generate a v5 GUID for one of more U-Boot fw_images the same
way U-Boot does at runtime.\n");
+    fprintf(stderr,
+    "\nOptions:\n"
+    "  GUID namespace/salt GUID in 8-4-4-4-12
format\n"
+    "  -

Re: [PATCH v3 6/7] tools: add genguid tool

2024-06-04 Thread Heinrich Schuchardt

On 5/31/24 15:50, Caleb Connolly wrote:

Add a tool that can generate GUIDs that match those generated internally
by U-Boot for capsule update fw_images.

Dynamic UUIDs in U-Boot work by taking a namespace UUID and hashing it
with the board model, compatible, and fw_image name.

This tool accepts the same inputs and will produce the same GUID as
U-Boot would at runtime.


This functionality should be integrated into the mkeficapsule.

Just pass the device-tree into mkeficapsule and generate the GUIDs
whereever they are needed.

Best regards

Heinrich



Signed-off-by: Caleb Connolly 
---
  doc/genguid.1   |  52 +++
  tools/Kconfig   |   7 +++
  tools/Makefile  |   3 ++
  tools/genguid.c | 154 
  4 files changed, 216 insertions(+)

diff --git a/doc/genguid.1 b/doc/genguid.1
new file mode 100644
index ..4128055b3a9a
--- /dev/null
+++ b/doc/genguid.1
@@ -0,0 +1,52 @@
+.\" SPDX-License-Identifier: GPL-2.0+
+.\" Copyright (c) 2024, Linaro Limited
+.TH GENGUID 1 "May 2024"
+
+.SH NAME
+genguid \- Generate deterministic EFI capsule image GUIDs for a board
+
+.SH SYNOPSIS
+.B genguid
+.RI GUID " " [ -vj ] " " -c " " COMPAT " " NAME...
+
+.SH "DESCRIPTION"
+The
+.B genguid
+command is used to determine the update image GUIDs for a board using
+dynamic UUIDs. The command takes a namespace GUID (defined in the boards
+defconfig), the boards first compatible string, and the names of the
+firmware images. The command will output the GUIDs for each image.
+
+As the dynamic UUID mechanism generates GUIDs at runtime, it would be
+necessary to actually boot U-Boot on the board and enable debug logs
+to retrieve the generated GUIDs. This tools just simplifies that process.
+
+.SH "OPTIONS"
+
+.TP
+.BI GUID
+The namespace/salt GUID, same as CONFIG_EFI_CAPSULE_NAMESPACE_UUID.
+The format is:
+----
+
+.TP
+.BI "-v\fR,\fB --verbose "
+Print additional information to stderr.
+
+.TP
+.BI "-j\fR,\fB --json "
+Output the results in JSON format (array of object with name/uuid properties).
+
+.TP
+.BI "-c\fR,\fB --compat " COMPAT
+The first entry in the boards root compatible property.
+
+.TP
+.BI NAME...
+The names of the firmware images to generate GUIDs for (e.g. 
"SANDBOX-UBOOT-ENV").
+
+.SH AUTHORS
+Written by Caleb Connolly 
+
+.SH HOMEPAGE
+https://u-boot.org
diff --git a/tools/Kconfig b/tools/Kconfig
index 667807b33173..13201ff61fd4 100644
--- a/tools/Kconfig
+++ b/tools/Kconfig
@@ -103,8 +103,15 @@ config TOOLS_MKEFICAPSULE
  This command allows users to create a UEFI capsule file and,
  optionally sign that file. If you want to enable UEFI capsule
  update feature on your target, you certainly need this.

+config TOOLS_GENGUID
+   bool "Build genguid command"
+   default y if EFI_CAPSULE_DYNAMIC_UUIDS


Distros have a package u-boot-tools. You want this package to contain
all tools.

Please, ensure that the new tool is built by tools-only_defconfig.


+   help
+ This command allows users to generate the GUIDs that a given
+ board would use for UEFI capsule update feature.
+
  menuconfig FSPI_CONF_HEADER
bool "FlexSPI Header Configuration"
help
  FSPI Header Configuration
diff --git a/tools/Makefile b/tools/Makefile
index 6a4280e3668f..29e9a93b0f24 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -253,8 +253,11 @@ HOSTLDLIBS_mkeficapsule += \
  HOSTLDLIBS_mkeficapsule += \
$(shell pkg-config --libs uuid 2> /dev/null || echo "-luuid")
  hostprogs-$(CONFIG_TOOLS_MKEFICAPSULE) += mkeficapsule

+genguid-objs := generated/lib/uuid.o generated/lib/sha1.o genguid.o
+hostprogs-$(CONFIG_TOOLS_GENGUID) += genguid
+
  mkfwumdata-objs := mkfwumdata.o generated/lib/crc32.o
  HOSTLDLIBS_mkfwumdata += -luuid
  hostprogs-$(CONFIG_TOOLS_MKFWUMDATA) += mkfwumdata

diff --git a/tools/genguid.c b/tools/genguid.c
new file mode 100644
index ..e71bc1d48f95
--- /dev/null
+++ b/tools/genguid.c
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2024 Linaro Ltd.
+ *   Author: Caleb Connolly
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+static struct option options[] = {
+   {"dtb", required_argument, NULL, 'd'},
+   {"compat", required_argument, NULL, 'c'},
+   {"help", no_argument, NULL, 'h'},
+   {"verbose", no_argument, NULL, 'v'},
+   {"json", no_argument, NULL, 'j'},
+   {NULL, 0, NULL, 0},
+};
+
+static void usage(const char *progname)
+{
+   fprintf(stderr, "Usage: %s GUID [-v] -c COMPAT NAME...\n", progname);
+   fprintf(stderr,
+   "Generate a v5 GUID for one of more U-Boot fw_images the same way 
U-Boot does at runtime.\n");
+   fprintf(stderr,
+   "\nOptions:\n"
+   "  GUID namespace/salt GUID in 8-4-4-4-12 
format\n"
+   "  -h, --help 

Re: [PATCH v3 0/7] efi: CapsuleUpdate: support for dynamic UUIDs

2024-06-04 Thread Heinrich Schuchardt

On 5/31/24 15:50, Caleb Connolly wrote:

As more boards adopt support for the EFI CapsuleUpdate mechanism, there
is a growing issue of being able to target updates to them properly. The
current mechanism of hardcoding UUIDs for each board at compile time is
unsustainable, and maintaining lists of GUIDs is similarly cumbersome.

In this series, I propose that we adopt v5 GUIDs, these are generated
by using a well-known salt GUID as well as board specific information
(like the model/revision), these are hashed together and the result is
truncated to form a new UUID.

The well-known salt GUID can be specific to the architecture (SoC
vendor), or OEM. It is defined in the board defconfig so that vendors
can easily bring their own.

Specifically, the following fields are used to generate a GUID for a
particular fw_image:

* namespace salt
* board compatible (usually the first entry in the dt root compatible
   array).
* fw_image name (the string identifying the specific image, especially
   relevant for board that can update multiple images).

== Usage ==

Boards can integrate dynamic UUID support as follows:

1. Adjust Kconfig to depend on EFI_CAPSULE_DYNAMIC_UUIDS if
EFI_HAVE_CAPSULE_SUPPORT.
2. Skip setting the fw_images image_type_id property.
3. Generate a UUID and set CONFIG_EFI_CAPSULE_NAMESPACE_UUID in your
defconfig.


Why should we have two alternatives?

If we have the dynamic UUIDs, please, get rid of static ones.



== Limitations ==

* Changing GUIDs

The primary limitation with this approach is that if any of the source
fields change, so will the GUID for the board. It is therefore pretty
important to ensure that GUID changes are caught during development.

* Supporting multiple boards with a single image

This now requires having an entry with the GUID for every board which
might lead to larger UpdateCapsule images.


Do we have a test case were a capsule contains images that shall not be
installed?



== Tooling ==

This series introduces a new tool: genguid. This can be used to generate
the same GUIDs that the board would at runtime.


the GUIDs that the board requires at runtime.

Best regards

Heinrich



This series follows a related discussion started by Ilias:
https://lore.kernel.org/u-boot/cac_iwjjnha4gmf897mqyzndbgjfg8k4kwgstxwuy72wkyli...@mail.gmail.com/

---
Changes in v3:
- Add manpage for genguid
- Add dedicated CONFIG_TOOLS_GENGUID option
- Minor code fixes addressing v2 feedback
- Link to v2: 
https://lore.kernel.org/r/20240529-b4-dynamic-uuid-v2-0-c26f31057...@linaro.org

Changes in v2:
- Move namespace UUID to be defined in defconfig
- Add tests and tooling
- Only use the first board compatible to generate UUID.
- Link to v1: 
https://lore.kernel.org/r/20240426-b4-dynamic-uuid-v1-0-e8154e00e...@linaro.org

---
Caleb Connolly (7):
   lib: uuid: add UUID v5 support
   efi: add a helper to generate dynamic UUIDs
   doc: uefi: document dynamic UUID generation
   sandbox: switch to dynamic UUIDs
   lib: uuid: supporting building as part of host tools
   tools: add genguid tool
   test: lib/uuid: add unit tests for dynamic UUIDs

  arch/Kconfig   |   1 +
  board/sandbox/sandbox.c|  16 ---
  configs/sandbox_defconfig  |   1 +
  configs/sandbox_flattree_defconfig |   1 +
  doc/develop/uefi/uefi.rst  |  31 +
  doc/genguid.1  |  52 +++
  include/sandbox_efi_capsule.h  |   6 +-
  include/uuid.h |  21 ++-
  lib/Kconfig|   8 ++
  lib/efi_loader/Kconfig |  23 +++
  lib/efi_loader/efi_capsule.c   |   1 +
  lib/efi_loader/efi_firmware.c  |  66 +
  lib/uuid.c |  81 +--
  test/lib/uuid.c|  88 
  .../test_efi_capsule/test_capsule_firmware_fit.py  |   2 +-
  .../test_efi_capsule/test_capsule_firmware_raw.py  |   8 +-
  .../test_capsule_firmware_signed_fit.py|   2 +-
  .../test_capsule_firmware_signed_raw.py|   4 +-
  test/py/tests/test_efi_capsule/version.dts |   6 +-
  tools/Kconfig  |   7 +
  tools/Makefile |   3 +
  tools/binman/etype/efi_capsule.py  |   2 +-
  tools/binman/ftest.py  |   2 +-
  tools/genguid.c| 154 +
  24 files changed, 538 insertions(+), 48 deletions(-)
---
change-id: 20240422-b4-dynamic-uuid-1a5ab1486c27
base-commit: 2e682a4a406fc81ef32e05c28542cc8067f1e15f

// Caleb (they/them)





Re: [PATCH 2/9] tpm: Avoid code bloat when not using EFI_TCG2_PROTOCOL

2024-06-04 Thread Ilias Apalodimas
Hi Heinrich

On Wed, 5 Jun 2024 at 07:09, Heinrich Schuchardt  wrote:
>
> On 6/5/24 05:25, Simon Glass wrote:
> > It does not make sense to enable all SHA algorithms unless they are
> > needed. It bloats the code and in this case, causes chromebook_link to
> > fail to build.
>
> Why would chromebook_link fail to build?
> Is TPM used by U-Boot on that board at all?
>
> >
> > Add a condition to TPM to correct this. Note that the original commit
> > combines refactoring and new features, which makes it hard to see what
> > is going on.
> >
> > Fixes: 97707f12fda tpm: Support boot measurements
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >   lib/Kconfig | 8 
> >   1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/Kconfig b/lib/Kconfig
> > index 189e6eb31aa..70b32362ada 100644
> > --- a/lib/Kconfig
> > +++ b/lib/Kconfig
> > @@ -438,10 +438,10 @@ config TPM
> >   bool "Trusted Platform Module (TPM) Support"
> >   depends on DM
> >   imply DM_RNG
> > - select SHA1
> > - select SHA256
> > - select SHA384
> > - select SHA512
> > + select SHA1 if EFI_TCG2_PROTOCOL
> > + select SHA256 if EFI_TCG2_PROTOCOL
> > + select SHA384 if EFI_TCG2_PROTOCOL
> > + select SHA512 if EFI_TCG2_PROTOCOL
>
> You need to consider CONFIG_MEASURED_BOOT which allows measured boot in
> the non-UEFI case.
>
> Please, take into account
>
> lib/tpm-v1.c:20:
> #error "TPM_AUTH_SESSIONS require SHA1 to be configured, too"
>
> This #error should be replaced by a Kconfig constraint.
>
> I would prefer the select statements to be in lib/efi_loader/Kconfig
> under EFI_TCG2_PROTOCOL.
>
> @Ilias, Eddie:
>
> Why do we require SHA1 which is considered insecure?
>
> Shouldn't we change tpm2_supported_algorithms[] to include only
> algorithms selected in the configuration? This would allow replacing all
> the select statements in Simon's patch by imply.

The algorithms used and configured by the TPM are device runtime
decisions, not compile-time ones and to my knowledge, there are no
devices out there that disable SHA1.

Failing to extend a PCR in an active bank is a security vulnerability.
It would allow the unsealing of secrets if an attacker can replay a
good set of measurements into an unused bank.

We could potentially fix that in the future since we can configure the
TPM active banks on boot, but IIRC we don't support that yet.

Regards
/Ilias

>
> Best regards
>
> Heinrich
>
> >   help
> > This enables support for TPMs which can be used to provide security
> > features for your board. The TPM can be connected via LPC or I2C
>


Re: [PATCH v3 2/7] efi: add a helper to generate dynamic UUIDs

2024-06-04 Thread Heinrich Schuchardt

On 5/31/24 15:50, Caleb Connolly wrote:

Introduce a new helper efi_capsule_update_info_gen_ids() which populates
the capsule update fw images image_type_id field. This allows for
determinstic UUIDs to be used that can scale to a large number of
different boards and board variants without the need to maintain a big
list.

We call this from efi_fill_image_desc_array() to populate the UUIDs
lazily on-demand.

This is behind an additional config option as it depends on V5 UUIDs and
the SHA1 implementation.

Signed-off-by: Caleb Connolly 
---
  lib/efi_loader/Kconfig| 23 +++
  lib/efi_loader/efi_capsule.c  |  1 +
  lib/efi_loader/efi_firmware.c | 66 +++
  3 files changed, 90 insertions(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 430bb7f0f7dc..e90caf4f8e14 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -235,8 +235,31 @@ config EFI_CAPSULE_ON_DISK_EARLY
  If this option is enabled, capsules will be enforced to be
  executed as part of U-Boot initialisation so that they will
  surely take place whatever is set to distro_bootcmd.

+config EFI_CAPSULE_DYNAMIC_UUIDS
+   bool "Dynamic UUIDs for capsules"
+   depends on EFI_HAVE_CAPSULE_SUPPORT
+   select UUID_GEN_V5


This select will create a build error if CONFIG_SHA1=n as
CONFIG_UUID_GEN_V5 depends on it.


+   help
+ Select this option if you want to use dynamically generated v5
+ UUIDs for your board. To make use of this feature, your board
+ code should call efi_capsule_update_info_gen_ids() with a seed
+ UUID to generate the image_type_id field for each fw_image.
+
+ The CapsuleUpdate payloads are expected to generate matching UUIDs
+ using the same scheme.
+
+config EFI_CAPSULE_NAMESPACE_UUID
+   string "Namespace UUID for dynamic UUIDs"
+   depends on EFI_CAPSULE_DYNAMIC_UUIDS
+   help
+ Define the namespace or "salt" UUID used to generate the per-image
+ UUIDs. This should be a UUID in the standard 8-4-4-4-12 format.


As UUIDs can be formatted low-endian or big-endian I would not know how
the value will be interpreted.

Why do we need a vendor specific name-space if we are using compatible
strings which are vendor specific themselves?


+
+ Device vendors are expected to generate their own namespace UUID
+ to avoid conflicts with existing products.
+
  config EFI_CAPSULE_FIRMWARE
bool

  config EFI_CAPSULE_FIRMWARE_MANAGEMENT
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 0937800e588f..ac02e79ae7d8 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -19,8 +19,9 @@
  #include 
  #include 
  #include 
  #include 
+#include 

  #include 
  #include 
  #include 
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index ba5aba098c0f..a8dafe4f01a5 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -244,8 +244,71 @@ void efi_firmware_fill_version_info(struct 
efi_firmware_image_descriptor *image_

free(var_state);
  }

+#if CONFIG_IS_ENABLED(EFI_CAPSULE_DYNAMIC_UUIDS)
+/**
+ * efi_capsule_update_info_gen_ids - generate GUIDs for the images
+ *
+ * Generate the image_type_id for each image in the update_info.images array
+ * using the first compatible from the device tree and a salt
+ * UUID defined at build time.
+ *
+ * Returns:status code
+ */
+static efi_status_t efi_capsule_update_info_gen_ids(void)
+{
+   int ret, i;
+   struct uuid namespace;
+   const char *compatible; /* Full array including null bytes */
+   struct efi_fw_image *fw_array;
+
+   fw_array = update_info.images;
+   /* Check if we need to run (there are images and we didn't already 
generate their IDs) */
+   if (!update_info.num_images ||
+   memchr_inv(&fw_array[0].image_type_id, 0, 
sizeof(fw_array[0].image_type_id)))
+   return EFI_SUCCESS;
+
+   ret = uuid_str_to_bin(CONFIG_EFI_CAPSULE_NAMESPACE_UUID,
+   (unsigned char *)&namespace, UUID_STR_FORMAT_GUID);
+   if (ret) {
+   log_debug("%s: CONFIG_EFI_CAPSULE_NAMESPACE_UUID is invalid: 
%d\n", __func__, ret);
+   return EFI_UNSUPPORTED;
+   }


You don't want end-users to be the first to find this issue. This must
be a build time check.


+
+   compatible = ofnode_read_string(ofnode_root(), "compatible");
+
+   if (!compatible) {
+   log_debug("%s: model or compatible not defined\n", __func__);


You are not reading model here.


+   return EFI_UNSUPPORTED;
+   }
+
+   if (!update_info.num_images) {
+   log_debug("%s: no fw_images, make sure update_info.num_images is 
set\n", __func__);


I thought we were using capsules without images in A/B updates and need
to process them?


+   return -ENODATA

Re: [PATCH v3 1/7] lib: uuid: add UUID v5 support

2024-06-04 Thread Heinrich Schuchardt

On 5/31/24 15:50, Caleb Connolly wrote:

Add support for generating version 5 UUIDs, these are determistic and work
by hashing a "namespace" UUID together with some unique data. One intended
usecase is to allow for dynamically generate payload UUIDs for UEFI
capsule updates, so that supported boards can have their own UUIDs
without needing to hardcode them.

Tests for this are added in an upcoming patch.

Signed-off-by: Caleb Connolly 
---
  include/uuid.h | 17 +
  lib/Kconfig|  8 
  lib/uuid.c | 37 +
  3 files changed, 62 insertions(+)

diff --git a/include/uuid.h b/include/uuid.h
index f5a941250f48..539affaa47b9 100644
--- a/include/uuid.h
+++ b/include/uuid.h
@@ -10,8 +10,9 @@
  #ifndef __UUID_H__
  #define __UUID_H__

  #include 
+#include 

  /*
   * UUID - Universally Unique IDentifier - 128 bits unique number.
   *There are 5 versions and one variant of UUID defined by RFC4122
@@ -142,8 +143,24 @@ void gen_rand_uuid(unsigned char *uuid_bin);
   * @param  - uuid output type: UUID - 0, GUID - 1
   */
  void gen_rand_uuid_str(char *uuid_str, int str_format);

+#if IS_ENABLED(CONFIG_UUID_GEN_V5)
+/**
+ * gen_uuid_v5() - generate UUID v5 from namespace and other seed data.
+ *
+ * @namespace:   pointer to UUID namespace salt
+ * @uuid:pointer to allocated UUID output
+ * @...: NULL terminated list of seed data as pairs of pointers
+ *   to data and their lengths


It is unclear what this might mean.

According to your description ... could be

struct {
void *data;
u32 *length;
} ...[] = {
{ &data_1, &length_1 },
{ &data_2, &length_2 },
{ NULL, NULL }
}

Do we have pointer to lengths?
Which data type do lengths have?

Please, provide an unambiguous description.

An example would help.


+ */
+void gen_uuid_v5(const struct uuid *namespace, struct uuid *uuid, ...);
+#else
+static inline void gen_uuid_v5(const struct uuid *namespace, struct uuid 
*uuid, ...)
+{
+}
+#endif
+
  /**
   * uuid_str_to_le_bin() - Convert string UUID to little endian binary data.
   * @uuid_str: pointer to UUID string
   * @uuid_bin: pointer to allocated array for little endian output [16B]
diff --git a/lib/Kconfig b/lib/Kconfig
index 189e6eb31aa1..2941532f25cf 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -80,8 +80,16 @@ config RANDOM_UUID
help
  Enable the generation of partitions with random UUIDs if none
  are provided.

+config UUID_GEN_V5
+   bool "Enable UUID version 5 generation"
+   select LIB_UUID
+   depends on SHA1


'select SHA1' might make things easier.


+   help
+ Enable the generation of version 5 UUIDs, these are determistic and


%s/determistic/deterministic/


+ generated from a namespace UUID, and a string (such as a board name).
+
  config SPL_LIB_UUID
depends on SPL
bool

diff --git a/lib/uuid.c b/lib/uuid.c
index dfa2320ba267..2df0523e717f 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -21,8 +21,9 @@
  #include 
  #include 
  #include 
  #include 
+#include 

  int uuid_str_valid(const char *uuid)
  {
int i, valid;
@@ -368,8 +369,44 @@ void uuid_bin_to_str(const unsigned char *uuid_bin, char 
*uuid_str,
}
}
  }

+#if IS_ENABLED(CONFIG_UUID_GEN_V5)
+void gen_uuid_v5(const struct uuid *namespace, struct uuid *uuid, ...)
+{
+   sha1_context ctx;
+   va_list args;
+   const uint8_t *data;
+   uint8_t hash[SHA1_SUM_LEN];
+   uint32_t tmp;
+
+   sha1_starts(&ctx);
+   /* Hash the namespace UUID as salt */
+   sha1_update(&ctx, (unsigned char *)namespace, UUID_BIN_LEN);
+   va_start(args, uuid);
+
+   while ((data = va_arg(args, const uint8_t *))) {
+   unsigned int len = va_arg(args, size_t);
+
+   sha1_update(&ctx, data, len);
+   }
+
+   va_end(args);
+   sha1_finish(&ctx, hash);
+
+   /* Truncate the hash into output UUID, it is already big endian */
+   memcpy(uuid, hash, sizeof(*uuid));
+
+   /* Configure variant/version bits */
+   tmp = be32_to_cpu(uuid->time_hi_and_version);
+   tmp = (tmp & ~UUID_VERSION_MASK) | (5 << UUID_VERSION_SHIFT);


Currently we have

#define UUID_VERSION0x4

Shouldn't we create

#define UUID_VARIANT_4 0x4 - to be used in gen_rand_uuid()
#define UUID_VARIANT_5 0x5 - to be used in gen_uuid_v5()

instead?

Please, provide a unit test for gen_uuid_v5() that passes multiple
strings to gen_uuid_v5() and checks the hash.

Best regards

Heinrich


+   uuid->time_hi_and_version = cpu_to_be32(tmp);
+
+   uuid->clock_seq_hi_and_reserved &= UUID_VARIANT_MASK;
+   uuid->clock_seq_hi_and_reserved |= UUID_VARIANT << UUID_VARIANT_SHIFT;
+}
+#endif
+
  #if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
  void gen_rand_uuid(unsigned char *uuid_bin)
  {
u32 ptr[4];





Re: [PATCH 5/9] fdt: Correct condition for bloblist existing

2024-06-04 Thread Ilias Apalodimas
Hi Simon,

On Wed, 5 Jun 2024 at 06:26, Simon Glass  wrote:
>
> On some boards, the bloblist is created in SPL once SDRAM is ready. It
> cannot be accessed until that point, so is not available early in SPL.
>
> Add a condition to avoid a hang in this case.
>
> This fixes a hang in chromebook_coral
>
> Fixes: 70fe2385943 ("fdt: Allow the devicetree to come from a bloblist")
>
> Signed-off-by: Simon Glass 
> ---
>
>  lib/fdtdec.c | 12 ++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index b2c59ab3818..b141244e3b9 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -1669,8 +1669,16 @@ int fdtdec_setup(void)
>  {
> int ret = -ENOENT;
>
> -   /* If allowing a bloblist, check that first */
> -   if (CONFIG_IS_ENABLED(BLOBLIST)) {
> +   /*
> +* If allowing a bloblist, check that first. This would be better
> +* handled with an OF_BLOBLIST Kconfig, but that caused far too much
> +* argument, so add a hack here, used e.g. by chromebook_coral
> +* The necessary test is whether the previous stage passed a bloblist,
> +* not whether this one creates one.
> +*/
> +   if (CONFIG_IS_ENABLED(OF_BLOBLIST) &&
> +   (spl_prev_phase() != PHASE_TPL ||
> +!IS_ENABLED(CONFIG_TPL_BLOBLIST))) {

The same condition exists in common/bloblist.c.
Carve out a function --e.g

bool can can_enable_bloblist(void)
 return 

instead of open coding that

Thanks
/Ilias
> ret = bloblist_maybe_init();
> if (!ret) {
> gd->fdt_blob = bloblist_find(BLOBLISTT_CONTROL_FDT, 
> 0);
> --
> 2.34.1
>


Re: [PATCH v3 0/8] qcom: implement capsule updates

2024-06-04 Thread Sumit Garg
Hi Caleb,

On Mon, 3 Jun 2024 at 18:19, Caleb Connolly  wrote:
>
> Hook up support for capsule updates loaded from disk on Qualcomm
> platforms.
>
> Most Qualcomm devices have an A/B partition layout, with most partitions
> duplicated. The metadata on which slot is active is stored in the GPT
> headers in the vendor-specific attribute bits of each partition.

It's good to see capsule updates support coming up for Qualcomm
platforms. AFAICS, with this series we only update U-Boot on the
current active partition. IOW, real A/B support is still not
supported. Do you think it is possible for U-Boot to update metadata
in GPT headers and for proprietary bootloaders to pick up the U-Boot
from the updated partition?

-Sumit

>
> Add support for reading this attributes via the disk_partition struct
> and using them to determine which boot partition U-Boot is flashed to
> and generate the appropriate DFU string.
>
> This logic is gated behind a check to ensure that U-Boot is actually
> being chainloaded and not run via some other mechanism.
>
> SCSI support for most Qualcomm platforms is not yet enabled upstream,
> but will follow in future patches.
>
> This series enables capsule updates on the RB2, however [1] is required
> for it to work properly (as otherwise MMC won't be available).
>
> [1]: 
> https://lore.kernel.org/u-boot/20240527-b4-clk-stub-v2-0-29013855e...@linaro.org/
>
> To: Tom Rini 
> To: Simon Glass 
> To: Lukasz Majewski 
> To: Mattijs Korpershoek 
> To: Caleb Connolly 
> To: Neil Armstrong 
> To: Sumit Garg 
> Cc: Ilias Apalodimas 
> Cc: u-boot@lists.denx.de
> Cc: u-boot-q...@groups.io
>
> Changes in v3:
> - Address comments in scsi dfu support
> - enable CONFIG_DFU_SCSI for qcom
> - Link to v2: 
> https://lore.kernel.org/r/20240527-b4-qcom-capsule-updates-v2-0-47583d7ad...@linaro.org
>
> Changes in v2:
> - Add qcom capsule update support patches
> - Link to v1: 
> https://lore.kernel.org/r/20240409-b4-dfu-scsi-v1-0-3e1441a60...@linaro.org
>
> ---
> Caleb Connolly (8):
>   dfu: add scsi backend
>   disk: expose partition type flags
>   mmc: msm_sdhci: work around a bug when writing
>   mach-snapdragon: implement capsule update support
>   qcom_defconfig: savedefconfig
>   mach-snapdragon: use SYSRESET_PSCI
>   mach-snapdragon: bump up heap size
>   qcom_defconfig: enable capsule update support
>
>  arch/arm/Kconfig  |   2 +
>  arch/arm/mach-snapdragon/Kconfig  |   3 +
>  arch/arm/mach-snapdragon/Makefile |   1 +
>  arch/arm/mach-snapdragon/board.c  |   8 +-
>  arch/arm/mach-snapdragon/capsule_update.c | 147 ++
>  arch/arm/mach-snapdragon/qcom-priv.h  |   6 +
>  configs/qcom_defconfig|  19 +-
>  disk/part_efi.c   |   1 +
>  doc/usage/dfu.rst |  32 +++
>  drivers/dfu/Kconfig   |   7 +
>  drivers/dfu/Makefile  |   1 +
>  drivers/dfu/dfu.c |   5 +-
>  drivers/dfu/dfu_scsi.c| 435 
> ++
>  drivers/mmc/msm_sdhci.c   |   7 +
>  include/configs/qcom.h|   5 +
>  include/dfu.h |  26 ++
>  include/part.h|   1 +
>  17 files changed, 695 insertions(+), 11 deletions(-)
> ---
> change-id: 20240523-b4-qcom-capsule-updates-ea2e4f8f0ff0
> base-commit: 5d8881a0801241d68701e8644d495f1d535506f0
>
> // Caleb (they/them)
>


Re: [PATCH v3 4/8] mach-snapdragon: implement capsule update support

2024-06-04 Thread Sumit Garg
Hi Caleb,

On Mon, 3 Jun 2024 at 18:19, Caleb Connolly  wrote:
>
> Qualcomm boards flash U-Boot to the boot partition, implement support
> for determining which slot U-Boot is running from and finding the
> correct boot partition for that slot and configuring the appropriate DFU
> string.
>
> For now this only supports boards with SCSI/UFS storage where U-Boot is
> flashed to the boot partition, and only U-Boot itself is updated. In the
> future we may also support updating additional firmware components (tz,
> hyp, xbl) as well as having U-Boot installed to other partitions (e.g.
> as a first-stage bootloader).
>
> Signed-off-by: Caleb Connolly 
> ---
>  arch/arm/mach-snapdragon/Makefile |   1 +
>  arch/arm/mach-snapdragon/board.c  |   3 +
>  arch/arm/mach-snapdragon/capsule_update.c | 147 
> ++
>  arch/arm/mach-snapdragon/qcom-priv.h  |   6 ++
>  include/configs/qcom.h|   5 +
>  5 files changed, 162 insertions(+)
>
> diff --git a/arch/arm/mach-snapdragon/Makefile 
> b/arch/arm/mach-snapdragon/Makefile
> index 7a4495c8108f..343e825c6fdd 100644
> --- a/arch/arm/mach-snapdragon/Makefile
> +++ b/arch/arm/mach-snapdragon/Makefile
> @@ -2,5 +2,6 @@
>  #
>  # (C) Copyright 2015 Mateusz Kulikowski 
>
>  obj-y += board.o
> +obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += capsule_update.o
>  obj-$(CONFIG_OF_LIVE) += of_fixup.o
> diff --git a/arch/arm/mach-snapdragon/board.c 
> b/arch/arm/mach-snapdragon/board.c
> index b439a19ec7eb..c4a3394706e6 100644
> --- a/arch/arm/mach-snapdragon/board.c
> +++ b/arch/arm/mach-snapdragon/board.c
> @@ -299,8 +299,11 @@ int board_late_init(void)
>
> configure_env();
> qcom_late_init();
>
> +   /* Configure the dfu_string for capsule updates */
> +   qcom_configure_capsule_updates();
> +
> return 0;
>  }
>
>  static void build_mem_map(void)
> diff --git a/arch/arm/mach-snapdragon/capsule_update.c 
> b/arch/arm/mach-snapdragon/capsule_update.c
> new file mode 100644
> index ..505f5bf5ae07
> --- /dev/null
> +++ b/arch/arm/mach-snapdragon/capsule_update.c
> @@ -0,0 +1,147 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Common initialisation for Qualcomm Snapdragon boards.
> + *
> + * Copyright (c) 2024 Linaro Ltd.
> + * Author: Caleb Connolly 
> + */
> +
> +#define pr_fmt(fmt) "QCOM-FMP: " fmt
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "qcom-priv.h"
> +
> +struct efi_fw_image fw_images[] = {
> +   {
> +   .image_type_id = QUALCOMM_UBOOT_BOOT_IMAGE_GUID,
> +   .fw_name = u"QUALCOMM-UBOOT",
> +   .image_index = 1,
> +   },
> +};
> +
> +struct efi_capsule_update_info update_info = {
> +   /* Filled in by configure_dfu_string() */
> +   .dfu_string = NULL,
> +   .num_images = ARRAY_SIZE(fw_images),
> +   .images = fw_images,
> +};
> +
> +/* LSB first */
> +struct part_slot_status {
> +   u16: 2;
> +   u16 active : 1;
> +   u16: 3;
> +   u16 successful : 1;
> +   u16 unbootable : 1;
> +   u16 tries_remaining : 4;
> +};
> +
> +static int find_boot_partition(const char *partname, struct blk_desc 
> *blk_dev, char *name)
> +{
> +   int ret;
> +   int partnum;
> +   struct disk_partition info;
> +   struct part_slot_status *slot_status;
> +
> +   for (partnum = 1;; partnum++) {
> +   ret = part_get_info(blk_dev, partnum, &info);
> +   if (ret)
> +   return ret;
> +
> +   slot_status = (struct part_slot_status *)&info.type_flags;
> +   log_io("%16s: Active: %1d, Successful: %1d, Unbootable: %1d, 
> Tries left: %1d\n",
> +  info.name, slot_status->active,
> +  slot_status->successful, slot_status->unbootable,
> +  slot_status->tries_remaining);
> +   if (!strncmp(info.name, partname, strlen(partname)) && 
> slot_status->active) {
> +   log_debug("Found active %s partition: '%s'!\n", 
> partname, info.name);
> +   strlcpy(name, info.name, sizeof(info.name));
> +   return partnum;
> +   }
> +   }
> +
> +   return -1;
> +}
> +
> +/**
> + * qcom_configure_capsule_updates() - Configure the DFU string for capsule 
> updates
> + *
> + * U-Boot is flashed to the boot partition on Qualcomm boards. In most cases 
> there
> + * are two boot partitions, boot_a and boot_b. As we don't currently support 
> doing
> + * full A/B updates, we only support updating the currently active boot 
> partition.
> + *
> + * So we need to find the current slot suffix and the associated boot 
> partition.
> + * We do this by looking for the boot partition that has the 'active' flag 
> set
> + * in the GPT partition vendor attribute bits.
> + */
> +void qcom_configure_capsule_updates(void)
> +{
> +   struct blk

Re: [PATCH 2/9] tpm: Avoid code bloat when not using EFI_TCG2_PROTOCOL

2024-06-04 Thread Heinrich Schuchardt

On 6/5/24 05:25, Simon Glass wrote:

It does not make sense to enable all SHA algorithms unless they are
needed. It bloats the code and in this case, causes chromebook_link to
fail to build.


Why would chromebook_link fail to build?
Is TPM used by U-Boot on that board at all?



Add a condition to TPM to correct this. Note that the original commit
combines refactoring and new features, which makes it hard to see what
is going on.

Fixes: 97707f12fda tpm: Support boot measurements

Signed-off-by: Simon Glass 
---

  lib/Kconfig | 8 
  1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/Kconfig b/lib/Kconfig
index 189e6eb31aa..70b32362ada 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -438,10 +438,10 @@ config TPM
bool "Trusted Platform Module (TPM) Support"
depends on DM
imply DM_RNG
-   select SHA1
-   select SHA256
-   select SHA384
-   select SHA512
+   select SHA1 if EFI_TCG2_PROTOCOL
+   select SHA256 if EFI_TCG2_PROTOCOL
+   select SHA384 if EFI_TCG2_PROTOCOL
+   select SHA512 if EFI_TCG2_PROTOCOL


You need to consider CONFIG_MEASURED_BOOT which allows measured boot in
the non-UEFI case.

Please, take into account

lib/tpm-v1.c:20:
#error "TPM_AUTH_SESSIONS require SHA1 to be configured, too"

This #error should be replaced by a Kconfig constraint.

I would prefer the select statements to be in lib/efi_loader/Kconfig
under EFI_TCG2_PROTOCOL.

@Ilias, Eddie:

Why do we require SHA1 which is considered insecure?

Shouldn't we change tpm2_supported_algorithms[] to include only
algorithms selected in the configuration? This would allow replacing all
the select statements in Simon's patch by imply.

Best regards

Heinrich


help
  This enables support for TPMs which can be used to provide security
  features for your board. The TPM can be connected via LPC or I2C




Re: [PATCH] ufs: core: remove link_startup_again logic

2024-06-04 Thread Neha Malcom Francis

Hi Neil,

On 28/05/24 14:06, Neil Armstrong wrote:

The link_startup_again logic was added in Linux to handle device
that were set in LinkDown state, which should not be the case since U-boot
doesn't set LinkDown state are init, and Linux sets the device active


s/are/at ?


in ufshcd_init() for the first link startup.

While it worked to far, it breaks link startup for Qualcomm Controllers v5,
let's just remove the logic.



I don't see any repercussions ATM, but will need to get a wider opinion with 
different controllers before acking.



Signed-off-by: Neil Armstrong 
---
  drivers/ufs/ufs.c | 8 
  1 file changed, 8 deletions(-)

diff --git a/drivers/ufs/ufs.c b/drivers/ufs/ufs.c
index be64bf971f1..28c244b70e5 100644
--- a/drivers/ufs/ufs.c
+++ b/drivers/ufs/ufs.c
@@ -456,9 +456,7 @@ static int ufshcd_link_startup(struct ufs_hba *hba)
  {
int ret;
int retries = DME_LINKSTARTUP_RETRIES;
-   bool link_startup_again = true;
  
-link_startup:

do {
ufshcd_ops_link_startup_notify(hba, PRE_CHANGE);
  
@@ -484,12 +482,6 @@ link_startup:

/* failed to get the link up... retire */
goto out;
  
-	if (link_startup_again) {

-   link_startup_again = false;
-   retries = DME_LINKSTARTUP_RETRIES;
-   goto link_startup;
-   }
-
/* Mark that link is up in PWM-G1, 1-lane, SLOW-AUTO mode */
ufshcd_init_pwr_info(hba);
  


---
base-commit: 7e52d6ccfb76e2afc2d183b357abe2a2e2f948cf
change-id: 20240528-topic-sm8x50-ufs-core-link-startup-again-bc2cf907c164

Best regards,


--
Thanking You
Neha Malcom Francis


[PATCH 9/9] Revert "arm: am335x: Enable SPL_OF_CONTROL on some configs"

2024-06-04 Thread Simon Glass
This is a partial revert which makes boneblack_vboot boot again.

This reverts commit f4b64e9736e73ceec14d51600bed9a8ac48f9fe8.

Signed-off-by: Simon Glass 
---

 configs/am335x_boneblack_vboot_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/am335x_boneblack_vboot_defconfig 
b/configs/am335x_boneblack_vboot_defconfig
index d473a1a793b..3ec4abddd77 100644
--- a/configs/am335x_boneblack_vboot_defconfig
+++ b/configs/am335x_boneblack_vboot_defconfig
@@ -40,7 +40,6 @@ CONFIG_SYS_I2C_EEPROM_ADDR_LEN=2
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_BOOTP_DNS2=y
 CONFIG_OF_CONTROL=y
-CONFIG_SPL_OF_CONTROL=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
-- 
2.34.1



[PATCH 8/9] regulator: rk8xx: Fix incorrect parameter

2024-06-04 Thread Simon Glass
A recent change introduced a bug whereby a PMIC device is used in
place of the regulator device. Fix it.

This fixes a hang after 'Loading Environment from nowhere... OK'
on chromebook_jerry

Fixes: f047e4ab976 ("regulator: rk8xx: add indirection level for some..")

Signed-off-by: Simon Glass 
---

 drivers/power/regulator/rk8xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/regulator/rk8xx.c b/drivers/power/regulator/rk8xx.c
index 1bd4605d43a..bffc5d2dd65 100644
--- a/drivers/power/regulator/rk8xx.c
+++ b/drivers/power/regulator/rk8xx.c
@@ -1240,7 +1240,7 @@ static int ldo_set_suspend_value(struct udevice *dev, int 
uvolt)
int ldo = dev->driver_data - 1;
const struct rk8xx_reg_info *info = get_ldo_reg(dev->parent, ldo, 
uvolt);
 
-   return _ldo_set_suspend_value(dev->parent, info, uvolt);
+   return _ldo_set_suspend_value(dev, info, uvolt);
 }
 
 static int nldo_set_suspend_value(struct udevice *dev, int uvolt)
-- 
2.34.1



[PATCH 7/9] rockchip: bob: kevin: Disable dcache in SPL

2024-06-04 Thread Simon Glass
This causes a hang, so disable it.

Fixes: 6d8cdfd1536 ("rockchip: spl: Enable caches to speed up checksum 
validation")

Signed-off-by: Simon Glass 
---

 configs/chromebook_bob_defconfig   | 1 +
 configs/chromebook_kevin_defconfig | 1 +
 2 files changed, 2 insertions(+)

diff --git a/configs/chromebook_bob_defconfig b/configs/chromebook_bob_defconfig
index acfe3934104..b2ecfa6050c 100644
--- a/configs/chromebook_bob_defconfig
+++ b/configs/chromebook_bob_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARM=y
 CONFIG_SKIP_LOWLEVEL_INIT=y
+CONFIG_SPL_SYS_DCACHE_OFF=y
 CONFIG_COUNTER_FREQUENCY=2400
 CONFIG_ARCH_ROCKCHIP=y
 CONFIG_TEXT_BASE=0x0020
diff --git a/configs/chromebook_kevin_defconfig 
b/configs/chromebook_kevin_defconfig
index 95fdb418d82..da748e4f022 100644
--- a/configs/chromebook_kevin_defconfig
+++ b/configs/chromebook_kevin_defconfig
@@ -2,6 +2,7 @@ CONFIG_ARM=y
 CONFIG_SKIP_LOWLEVEL_INIT=y
 CONFIG_COUNTER_FREQUENCY=2400
 CONFIG_ARCH_ROCKCHIP=y
+CONFIG_SPL_SYS_DCACHE_OFF=y
 CONFIG_TEXT_BASE=0x0020
 CONFIG_SPL_GPIO=y
 CONFIG_NR_DRAM_BANKS=1
-- 
2.34.1



[PATCH 6/9] spl: Allow ATF to work when dcache is disabled

2024-06-04 Thread Simon Glass
The dcache may not be enabled in SPL. Add a check to avoid trying to
use an undefined function.

Signed-off-by: Simon Glass 
---

 common/spl/spl_atf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/spl/spl_atf.c b/common/spl/spl_atf.c
index 3bdd013a35f..9afe6456bc4 100644
--- a/common/spl/spl_atf.c
+++ b/common/spl/spl_atf.c
@@ -204,7 +204,8 @@ static void __noreturn bl31_entry(uintptr_t bl31_entry, 
uintptr_t bl32_entry,
   fdt_addr);
 
raw_write_daif(SPSR_EXCEPTION_MASK);
-   dcache_disable();
+   if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
+   dcache_disable();
 
atf_entry(bl31_params, (void *)fdt_addr);
 }
-- 
2.34.1



[PATCH 5/9] fdt: Correct condition for bloblist existing

2024-06-04 Thread Simon Glass
On some boards, the bloblist is created in SPL once SDRAM is ready. It
cannot be accessed until that point, so is not available early in SPL.

Add a condition to avoid a hang in this case.

This fixes a hang in chromebook_coral

Fixes: 70fe2385943 ("fdt: Allow the devicetree to come from a bloblist")

Signed-off-by: Simon Glass 
---

 lib/fdtdec.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index b2c59ab3818..b141244e3b9 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1669,8 +1669,16 @@ int fdtdec_setup(void)
 {
int ret = -ENOENT;
 
-   /* If allowing a bloblist, check that first */
-   if (CONFIG_IS_ENABLED(BLOBLIST)) {
+   /*
+* If allowing a bloblist, check that first. This would be better
+* handled with an OF_BLOBLIST Kconfig, but that caused far too much
+* argument, so add a hack here, used e.g. by chromebook_coral
+* The necessary test is whether the previous stage passed a bloblist,
+* not whether this one creates one.
+*/
+   if (CONFIG_IS_ENABLED(OF_BLOBLIST) &&
+   (spl_prev_phase() != PHASE_TPL ||
+!IS_ENABLED(CONFIG_TPL_BLOBLIST))) {
ret = bloblist_maybe_init();
if (!ret) {
gd->fdt_blob = bloblist_find(BLOBLISTT_CONTROL_FDT, 0);
-- 
2.34.1



[PATCH 4/9] power: regulator: Handle autoset in regulators_enable_boot_on()

2024-06-04 Thread Simon Glass
With a recent change, regulators_enable_boot_on() returns an error if a
regulator is already set. Check for and handle this situation.

Fixes: d99fb64a98a power: regulator: Only run autoset once for each regulator

Signed-off-by: Simon Glass 
---

 drivers/power/regulator/regulator-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/regulator/regulator-uclass.c 
b/drivers/power/regulator/regulator-uclass.c
index 77d101f262e..d9e1fb68295 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -518,7 +518,7 @@ int regulators_enable_boot_on(bool verbose)
 dev;
 uclass_next_device(&dev)) {
ret = regulator_autoset(dev);
-   if (ret == -EMEDIUMTYPE) {
+   if (ret == -EMEDIUMTYPE || ret == -EALREADY) {
ret = 0;
continue;
}
-- 
2.34.1



[PATCH 3/9] rockchip: veyron: Add logging for power init

2024-06-04 Thread Simon Glass
Add better logging for power init so that CONFIG_LOG_ERROR_RETURN can
be enabled.

Signed-off-by: Simon Glass 
---

 board/google/veyron/veyron.c | 27 ---
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/board/google/veyron/veyron.c b/board/google/veyron/veyron.c
index 32dbcdc4d10..23fe8bf088c 100644
--- a/board/google/veyron/veyron.c
+++ b/board/google/veyron/veyron.c
@@ -29,44 +29,41 @@ static int veyron_init(void)
int ret;
 
ret = regulator_get_by_platname("vdd_arm", &dev);
-   if (ret) {
-   debug("Cannot set regulator name\n");
-   return ret;
-   }
+   if (ret)
+   return log_msg_ret("vdd", ret);
 
/* Slowly raise to max CPU voltage to prevent overshoot */
ret = regulator_set_value(dev, 120);
if (ret)
-   return ret;
+   return log_msg_ret("s12", ret);
udelay(175); /* Must wait for voltage to stabilize, 2mV/us */
ret = regulator_set_value(dev, 140);
if (ret)
-   return ret;
+   return log_msg_ret("s14", ret);
udelay(100); /* Must wait for voltage to stabilize, 2mV/us */
 
ret = rockchip_get_clk(&clk.dev);
if (ret)
-   return ret;
+   return log_msg_ret("clk", ret);
clk.id = PLL_APLL;
ret = clk_set_rate(&clk, 18);
if (IS_ERR_VALUE(ret))
-   return ret;
+   return log_msg_ret("s18", ret);
 
ret = regulator_get_by_platname("vcc33_sd", &dev);
if (ret) {
debug("Cannot get regulator name\n");
-   return ret;
+   if (ret)
+   return log_msg_ret("vcc", ret);
}
 
ret = regulator_set_value(dev, 330);
if (ret)
-   return ret;
+   return log_msg_ret("s33", ret);
 
ret = regulators_enable_boot_on(false);
-   if (ret) {
-   debug("%s: Cannot enable boot on regulators\n", __func__);
-   return ret;
-   }
+   if (ret)
+   return log_msg_ret("boo", ret);
 
return 0;
 }
@@ -81,7 +78,7 @@ int board_early_init_r(void)
if (!fdt_node_check_compatible(gd->fdt_blob, 0, "google,veyron")) {
ret = veyron_init();
if (ret)
-   return ret;
+   return log_msg_ret("vey", ret);
}
 #endif
/*
-- 
2.34.1



[PATCH 2/9] tpm: Avoid code bloat when not using EFI_TCG2_PROTOCOL

2024-06-04 Thread Simon Glass
It does not make sense to enable all SHA algorithms unless they are
needed. It bloats the code and in this case, causes chromebook_link to
fail to build.

Add a condition to TPM to correct this. Note that the original commit
combines refactoring and new features, which makes it hard to see what
is going on.

Fixes: 97707f12fda tpm: Support boot measurements

Signed-off-by: Simon Glass 
---

 lib/Kconfig | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/Kconfig b/lib/Kconfig
index 189e6eb31aa..70b32362ada 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -438,10 +438,10 @@ config TPM
bool "Trusted Platform Module (TPM) Support"
depends on DM
imply DM_RNG
-   select SHA1
-   select SHA256
-   select SHA384
-   select SHA512
+   select SHA1 if EFI_TCG2_PROTOCOL
+   select SHA256 if EFI_TCG2_PROTOCOL
+   select SHA384 if EFI_TCG2_PROTOCOL
+   select SHA512 if EFI_TCG2_PROTOCOL
help
  This enables support for TPMs which can be used to provide security
  features for your board. The TPM can be connected via LPC or I2C
-- 
2.34.1



[PATCH 1/9] nvidia: nyan-big: Disable debug UART

2024-06-04 Thread Simon Glass
This cannot be enabled early in boot since some other init is needed.
At this point it is unclear exactly what init is needed, so disable
the debug UART to avoid a hang.

Signed-off-by: Simon Glass 
---

 configs/nyan-big_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/nyan-big_defconfig b/configs/nyan-big_defconfig
index 1483d17d975..4dec710cf8d 100644
--- a/configs/nyan-big_defconfig
+++ b/configs/nyan-big_defconfig
@@ -17,7 +17,6 @@ CONFIG_TEGRA124=y
 CONFIG_TARGET_NYAN_BIG=y
 CONFIG_TEGRA_GPU=y
 CONFIG_SYS_LOAD_ADDR=0x82408000
-CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
 CONFIG_FIT_BEST_MATCH=y
 CONFIG_BOOTSTAGE=y
-- 
2.34.1



[PATCH 0/9] Bug-fixes for a few boards

2024-06-04 Thread Simon Glass
This series includes fixes to get some rockchip and nvidia boards
working again. It also provides a fix (revert) for Beaglebone Black and
a devicetree fix for coral (x86).


Simon Glass (9):
  nvidia: nyan-big: Disable debug UART
  tpm: Avoid code bloat when not using EFI_TCG2_PROTOCOL
  rockchip: veyron: Add logging for power init
  power: regulator: Handle autoset in regulators_enable_boot_on()
  fdt: Correct condition for bloblist existing
  spl: Allow ATF to work when dcache is disabled
  rockchip: bob: kevin: Disable dcache in SPL
  regulator: rk8xx: Fix incorrect parameter
  Revert "arm: am335x: Enable SPL_OF_CONTROL on some configs"

 board/google/veyron/veyron.c   | 27 ++
 common/spl/spl_atf.c   |  3 ++-
 configs/am335x_boneblack_vboot_defconfig   |  1 -
 configs/chromebook_bob_defconfig   |  1 +
 configs/chromebook_kevin_defconfig |  1 +
 configs/nyan-big_defconfig |  1 -
 drivers/power/regulator/regulator-uclass.c |  2 +-
 drivers/power/regulator/rk8xx.c|  2 +-
 lib/Kconfig|  8 +++
 lib/fdtdec.c   | 12 --
 10 files changed, 32 insertions(+), 26 deletions(-)

-- 
2.34.1



Re: Several potential vulnerabilities in the filesystem

2024-06-04 Thread Gao Xiang




On 2024/6/5 06:53, jianqiang wang wrote:

Hi Das U-Boot developers,



...



2. in file fs/erofs/data.c, function z_erofs_read_one_data, the node
data is read from the storage, however, without a proper check, the
data can be corrupted. For example, the inode data is used in function
z_erofs_read_data, map.m_llen will be calculated to a very large
value, which means the length variable will be very large. It will
cause a large memory clear with memset(buffer + end - offset, 0,
length);


Would you mind giving a reproducer or a crafted image to trigger
this?  Or it's your pure observation.

Thanks,
Gao XIang



Re: [PATCH 3/3] tools: patman: fix deprecated Python ConfigParser methods

2024-06-04 Thread Simon Glass
On Tue, 4 Jun 2024 at 10:16, Brandon Maier  wrote:
>
> The method `ConfigParser.readfp()` is marked deprecated[1].
>
> In Python 3.12 this method have been removed, so replace it with
> `ConfigParser.read_file()`.
>
> [1] 
> https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp
>
> Signed-off-by: Brandon Maier 
> CC: Simon Glass 
> ---
>  tools/patman/settings.py | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 2/3] tools: binman: fix deprecated Python ConfigParser methods

2024-06-04 Thread Simon Glass
Hi Brandon,

On Tue, 4 Jun 2024 at 10:16, Brandon Maier  wrote:
>
> The method `ConfigParser.readfp()` is marked deprecated[1].
>
> In Python 3.12 this method have been removed, so replace it with
> `ConfigParser.read_file()`.
>
> [1] 
> https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp
>
> Signed-off-by: Brandon Maier 
> CC: Simon Glass 
> ---
>  tools/buildman/bsettings.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

Does this still work in earlier Pythons?

Regards,
Simon


Re: [PATCH 1/3] tools: binman: fix deprecated Python unittest methods

2024-06-04 Thread Simon Glass
On Tue, 4 Jun 2024 at 10:16, Brandon Maier  wrote:
>
> The methods `unittest.assertEquals()` and
> `unittest.assertRegexpMatches()` are marked deprecated[1].
>
> In Python 3.12 these aliases have been removed, so do a sed to replace
> them with their new names.
>
> [1] https://docs.python.org/3.11/library/unittest.html#deprecated-aliases
>
> Signed-off-by: Brandon Maier 
> CC: Simon Glass 
> CC: Alper Nebi Yasak 
> ---
>  tools/binman/entry_test.py  |  6 +--
>  tools/binman/fdt_test.py| 48 
>  tools/binman/ftest.py   | 42 ++---
>  tools/buildman/func_test.py | 74 ++---
>  tools/buildman/test.py  |  2 +-
>  5 files changed, 86 insertions(+), 86 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 1/1] tools: patman: fix `pip install` with Python 3.12

2024-06-04 Thread Simon Glass
On Tue, 4 Jun 2024 at 10:31, Brandon Maier  wrote:
>
> Installing patman with `cd ./tools/patman && pip install -e .` fails
> with the error below.
>
> As described in the error output, the license line is not allowed to be
> only defined in the setup.py.
>
> > $ cd ./tools/patman && pip install -e .
> > Obtaining file:///.../u-boot/tools/patman
> >   Installing build dependencies ... done
> >   Checking if build backend supports build_editable ... done
> >   Getting requirements to build editable ... error
> >   error: subprocess-exited-with-error
> >
> >   × Getting requirements to build editable did not run successfully.
> >   │ exit code: 1
> >   ╰─> [61 lines of output]
> >   
> > /tmp/pip-build-env-mqjvnmz8/overlay/lib/python3.12/site-packages/setuptools/config/_apply_pyprojecttoml.py:76:
> >   _MissingDynamic: `license` defined outside of `pyproject.toml` is 
> > ignored.
> >   !!
> >
> >   
> > 
> >   The following seems to be defined outside of `pyproject.toml`:
> >
> >   `license = 'GPL-2.0+'`
> >
> >   According to the spec (see the link below), however, setuptools CANNOT
> >   consider this value unless `license` is listed as `dynamic`.
> >
> >   
> > https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table
> >
> >   To prevent this problem, you can list `license` under `dynamic` or 
> > alternatively
> >   remove the `[project]` table from your file and rely entirely on 
> > other means of
> >   configuration.
> >   
> > 
> >
> >   !!
>
> Signed-off-by: Brandon Maier 
> CC: Simon Glass 
> ---
>  tools/patman/pyproject.toml | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 


Re: [PATCH 0/2] Cleanup fit documentation

2024-06-04 Thread Simon Glass
Hi Sam,

On Tue, 4 Jun 2024 at 13:53, Sam Povilus  wrote:
>
> Sam Povilus (2):
>   doc: Remove extraneous curly braces
>   doc: add clarity to what a "fpga" image is
>
>  doc/usage/fit/source_file_format.rst | 28 ++--
>  1 file changed, 14 insertions(+), 14 deletions(-)

This is now at [1]. Could you please instead do a PR for that?

I am not sure yet the best way to incorporate or link the FIT spec
from the U-Boot documentation. I suppose we could employ a script to
sync it?

Regards,
Simon

[1] https://github.com/open-source-firmware/flat-image-tree


Re: [PATCH v5 0/3] Introduce mtdblock device

2024-06-04 Thread Simon Glass
Hi Alexey,

On Mon, Jun 3, 2024, 09:57 Alexey Romanov 
wrote:

> Hello!
>
> This series adds support for the mtdblock device, which
> allows to read/write data block by block. For example,
> it can now be used for BCB or Android AB command:
>
>   $ bcb load mtd 0 part_name
>
> Tested only on SPI NAND, so bind is made only for
> SPI NAND drivers.
>
> ---
>
> Changes V1 -> V2 [1]:
>
>   - Drop patch [2].
>   - Add warning if bind NAND mtdblock device.
>   - Move documentation of mtdblock implementation
> from commit message to the source code.
>   - Remove __maybe_unused from mtd partition functions
> description.
>   - Use blk_enabled() instead of #ifdefs.
>
> Changes V2 -> V3 [2]:
>
>   - Rebased over [3].
>   - Rename mtd_bread/bwrite -> mtd_blk_read/write.
>   - Fix GPL-2.0 license short name definiton in headers.
>   - Add empty line after MTD_ENTRY_NUMBERS define.
>
> Changes V3 -> V4 [4]:
>
>   - Fix build warnings: use LBAF printf format string for lbaint_t types.
>
> Changes V4 -> V5 [5]:
>
>   - Rebased over u-boot/master.
>   - Fix build errors and warnings if CONFIG_BLK isn't enabled.
>   - Fix failed tests in cases is mtdblock device isn't binded.
>
> Links:
>
>   - [1]
> https://lore.kernel.org/all/20240227100441.1811047-1-avroma...@salutedevices.com/
>   - [2]
> https://lore.kernel.org/all/20240227100441.1811047-5-avroma...@salutedevices.com/
>   - [3]
> https://lore.kernel.org/u-boot/20240403114047.84030-1-heinrich.schucha...@canonical.com/T/#u
>   - [4]
> https://lore.kernel.org/all/20240404105813.1520732-1-avroma...@salutedevices.com/
>   - [5]
> https://lore.kernel.org/all/20240524102920.2631731-1-avroma...@salutedevices.com/
>
> Alexey Romanov (3):
>   disk: support MTD partitions
>   drivers: introduce mtdblock abstraction
>   spinand: bind mtdblock
>
>  disk/part.c |   3 +-
>  drivers/block/blk-uclass.c  |   1 +
>  drivers/mtd/Kconfig |   1 +
>  drivers/mtd/Makefile|   1 +
>  drivers/mtd/mtdblock.c  | 227 
>  drivers/mtd/mtdpart.c   |  76 
>  drivers/mtd/nand/spi/core.c |  20 
>  include/linux/mtd/mtd.h |  21 
>  include/part.h  |   3 +
>  9 files changed, 352 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/mtd/mtdblock.c
>
> --
> 2.34.1
>
>


Re: [PATCH v3 1/7] lib: uuid: add UUID v5 support

2024-06-04 Thread Simon Glass
Hi Caleb,

On Fri, 31 May 2024 at 07:50, Caleb Connolly  wrote:
>
> Add support for generating version 5 UUIDs, these are determistic and work

spelling

> by hashing a "namespace" UUID together with some unique data. One intended
> usecase is to allow for dynamically generate payload UUIDs for UEFI
> capsule updates, so that supported boards can have their own UUIDs
> without needing to hardcode them.
>
> Tests for this are added in an upcoming patch.
>
> Signed-off-by: Caleb Connolly 
> ---
>  include/uuid.h | 17 +
>  lib/Kconfig|  8 
>  lib/uuid.c | 37 +
>  3 files changed, 62 insertions(+)
>
> diff --git a/include/uuid.h b/include/uuid.h
> index f5a941250f48..539affaa47b9 100644
> --- a/include/uuid.h
> +++ b/include/uuid.h
> @@ -10,8 +10,9 @@
>  #ifndef __UUID_H__
>  #define __UUID_H__
>
>  #include 
> +#include 
>
>  /*
>   * UUID - Universally Unique IDentifier - 128 bits unique number.
>   *There are 5 versions and one variant of UUID defined by RFC4122
> @@ -142,8 +143,24 @@ void gen_rand_uuid(unsigned char *uuid_bin);
>   * @param  - uuid output type: UUID - 0, GUID - 1
>   */
>  void gen_rand_uuid_str(char *uuid_str, int str_format);
>
> +#if IS_ENABLED(CONFIG_UUID_GEN_V5)
> +/**
> + * gen_uuid_v5() - generate UUID v5 from namespace and other seed data.
> + *
> + * @namespace:   pointer to UUID namespace salt
> + * @uuid:pointer to allocated UUID output
> + * @...: NULL terminated list of seed data as pairs of pointers
> + *   to data and their lengths
> + */
> +void gen_uuid_v5(const struct uuid *namespace, struct uuid *uuid, ...);
> +#else
> +static inline void gen_uuid_v5(const struct uuid *namespace, struct uuid 
> *uuid, ...)
> +{
> +}
> +#endif

Can you explain somewhere why the static inline is needed?

> +
>  /**
>   * uuid_str_to_le_bin() - Convert string UUID to little endian binary data.
>   * @uuid_str:  pointer to UUID string
>   * @uuid_bin:  pointer to allocated array for little endian output [16B]
> diff --git a/lib/Kconfig b/lib/Kconfig
> index 189e6eb31aa1..2941532f25cf 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -80,8 +80,16 @@ config RANDOM_UUID
> help
>   Enable the generation of partitions with random UUIDs if none
>   are provided.
>
> +config UUID_GEN_V5
> +   bool "Enable UUID version 5 generation"
> +   select LIB_UUID
> +   depends on SHA1
> +   help
> + Enable the generation of version 5 UUIDs, these are determistic and

spelling

> + generated from a namespace UUID, and a string (such as a board 
> name).
> +
>  config SPL_LIB_UUID
> depends on SPL
> bool
>
> diff --git a/lib/uuid.c b/lib/uuid.c
> index dfa2320ba267..2df0523e717f 100644
> --- a/lib/uuid.c
> +++ b/lib/uuid.c
> @@ -21,8 +21,9 @@
>  #include 
>  #include 
>  #include 
>  #include 
> +#include 
>
>  int uuid_str_valid(const char *uuid)
>  {
> int i, valid;
> @@ -368,8 +369,44 @@ void uuid_bin_to_str(const unsigned char *uuid_bin, char 
> *uuid_str,
> }
> }
>  }
>
> +#if IS_ENABLED(CONFIG_UUID_GEN_V5)
> +void gen_uuid_v5(const struct uuid *namespace, struct uuid *uuid, ...)
> +{
> +   sha1_context ctx;
> +   va_list args;
> +   const uint8_t *data;
> +   uint8_t hash[SHA1_SUM_LEN];
> +   uint32_t tmp;
> +
> +   sha1_starts(&ctx);
> +   /* Hash the namespace UUID as salt */
> +   sha1_update(&ctx, (unsigned char *)namespace, UUID_BIN_LEN);
> +   va_start(args, uuid);
> +
> +   while ((data = va_arg(args, const uint8_t *))) {
> +   unsigned int len = va_arg(args, size_t);
> +
> +   sha1_update(&ctx, data, len);
> +   }
> +
> +   va_end(args);
> +   sha1_finish(&ctx, hash);
> +
> +   /* Truncate the hash into output UUID, it is already big endian */
> +   memcpy(uuid, hash, sizeof(*uuid));
> +
> +   /* Configure variant/version bits */
> +   tmp = be32_to_cpu(uuid->time_hi_and_version);
> +   tmp = (tmp & ~UUID_VERSION_MASK) | (5 << UUID_VERSION_SHIFT);
> +   uuid->time_hi_and_version = cpu_to_be32(tmp);
> +
> +   uuid->clock_seq_hi_and_reserved &= UUID_VARIANT_MASK;
> +   uuid->clock_seq_hi_and_reserved |= UUID_VARIANT << UUID_VARIANT_SHIFT;
> +}
> +#endif
> +
>  #if defined(CONFIG_RANDOM_UUID) || defined(CONFIG_CMD_UUID)
>  void gen_rand_uuid(unsigned char *uuid_bin)
>  {
> u32 ptr[4];
>
> --
> 2.45.0
>

Regards,
Simon


Re: [PATCH v3 6/7] tools: add genguid tool

2024-06-04 Thread Simon Glass
Hi Caleb,

On Fri, 31 May 2024 at 07:50, Caleb Connolly  wrote:
>
> Add a tool that can generate GUIDs that match those generated internally
> by U-Boot for capsule update fw_images.
>
> Dynamic UUIDs in U-Boot work by taking a namespace UUID and hashing it
> with the board model, compatible, and fw_image name.
>
> This tool accepts the same inputs and will produce the same GUID as
> U-Boot would at runtime.
>
> Signed-off-by: Caleb Connolly 
> ---
>  doc/genguid.1   |  52 +++
>  tools/Kconfig   |   7 +++
>  tools/Makefile  |   3 ++
>  tools/genguid.c | 154 
> 
>  4 files changed, 216 insertions(+)

Reviewed-by: Simon Glass 

Can I suggest you look at patman, which will provide a per-patch change list?

Regards,
SImon


Re: [PATCH 1/3] efi_loader: select BLK not depends on BLK

2024-06-04 Thread Heinrich Schuchardt



Am 5. Juni 2024 03:37:40 MESZ schrieb Tom Rini :
>The BLK symbol is used both for "we have a block device subsystem
>enabled" and "we need to utilize the block device library functions". In
>the case of efi_loader, it is the case of "we need to utilize the block
>device library", so select rather than depends on it. In turn, also
>disable EFI_LOADER on platforms which did not have it on previously due
>to a lack of block devices. They can enable it themselves if desired.
>
>Signed-off-by: Tom Rini 
>---
>Cc: Heinrich Schuchardt 

Acked-by: Heinrich Schuchardt 


>---
> configs/cortina_presidio-asic-base_defconfig | 1 +
> configs/cortina_presidio-asic-pnand_defconfig| 1 +
> configs/crs305-1g-4s-bit_defconfig   | 1 +
> configs/crs305-1g-4s_defconfig   | 1 +
> configs/crs326-24g-2s-bit_defconfig  | 1 +
> configs/crs326-24g-2s_defconfig  | 1 +
> configs/crs328-4c-20s-4s-bit_defconfig   | 1 +
> configs/crs328-4c-20s-4s_defconfig   | 1 +
> configs/gxp_defconfig| 1 +
> configs/maxbcm_defconfig | 1 +
> configs/mt7981_rfb_defconfig | 1 +
> configs/mt7986_rfb_defconfig | 1 +
> configs/mx6memcal_defconfig  | 1 +
> configs/pg_wcom_expu1_defconfig  | 1 +
> configs/pg_wcom_expu1_update_defconfig   | 1 +
> configs/pg_wcom_seli8_defconfig  | 1 +
> configs/pg_wcom_seli8_update_defconfig   | 1 +
> configs/r8a77970_eagle_defconfig | 1 +
> configs/smdkc100_defconfig   | 1 +
> configs/socfpga_is1_defconfig| 1 +
> configs/stm32mp25_defconfig  | 1 +
> configs/thunderx_88xx_defconfig  | 1 +
> configs/xilinx_versal_mini_defconfig | 1 +
> configs/xilinx_versal_mini_ospi_defconfig| 1 +
> configs/xilinx_versal_mini_qspi_defconfig| 1 +
> configs/xilinx_versal_net_mini_defconfig | 1 +
> configs/xilinx_versal_net_mini_ospi_defconfig| 1 +
> configs/xilinx_versal_net_mini_qspi_defconfig| 1 +
> configs/xilinx_zynqmp_mini_defconfig | 1 +
> configs/xilinx_zynqmp_mini_nand_defconfig| 1 +
> configs/xilinx_zynqmp_mini_nand_single_defconfig | 1 +
> configs/xilinx_zynqmp_mini_qspi_defconfig| 1 +
> configs/zynq_cse_nand_defconfig  | 1 +
> configs/zynq_cse_nor_defconfig   | 1 +
> configs/zynq_cse_qspi_defconfig  | 1 +
> lib/efi_loader/Kconfig   | 2 +-
> 36 files changed, 36 insertions(+), 1 deletion(-)
>
>diff --git a/configs/cortina_presidio-asic-base_defconfig 
>b/configs/cortina_presidio-asic-base_defconfig
>index 8f20f6515606..eb5743da64db 100644
>--- a/configs/cortina_presidio-asic-base_defconfig
>+++ b/configs/cortina_presidio-asic-base_defconfig
>@@ -38,3 +38,4 @@ CONFIG_DM_SERIAL=y
> CONFIG_CORTINA_UART=y
> CONFIG_WDT=y
> CONFIG_WDT_CORTINA=y
>+# CONFIG_EFI_LOADER is not set
>diff --git a/configs/cortina_presidio-asic-pnand_defconfig 
>b/configs/cortina_presidio-asic-pnand_defconfig
>index 94dc3e1e2e8e..c7367d4d91cc 100644
>--- a/configs/cortina_presidio-asic-pnand_defconfig
>+++ b/configs/cortina_presidio-asic-pnand_defconfig
>@@ -43,3 +43,4 @@ CONFIG_DM_SERIAL=y
> CONFIG_CORTINA_UART=y
> CONFIG_WDT=y
> CONFIG_WDT_CORTINA=y
>+# CONFIG_EFI_LOADER is not set
>diff --git a/configs/crs305-1g-4s-bit_defconfig 
>b/configs/crs305-1g-4s-bit_defconfig
>index a8f17570ecaa..c3d4594b75f7 100644
>--- a/configs/crs305-1g-4s-bit_defconfig
>+++ b/configs/crs305-1g-4s-bit_defconfig
>@@ -47,3 +47,4 @@ CONFIG_SPI_FLASH_MTD=y
> CONFIG_PCI_MVEBU=y
> CONFIG_SYS_NS16550=y
> CONFIG_KIRKWOOD_SPI=y
>+# CONFIG_EFI_LOADER is not set
>diff --git a/configs/crs305-1g-4s_defconfig b/configs/crs305-1g-4s_defconfig
>index c66d291eb926..1919e8c7794d 100644
>--- a/configs/crs305-1g-4s_defconfig
>+++ b/configs/crs305-1g-4s_defconfig
>@@ -48,3 +48,4 @@ CONFIG_SPI_FLASH_MTD=y
> CONFIG_PCI_MVEBU=y
> CONFIG_SYS_NS16550=y
> CONFIG_KIRKWOOD_SPI=y
>+# CONFIG_EFI_LOADER is not set
>diff --git a/configs/crs326-24g-2s-bit_defconfig 
>b/configs/crs326-24g-2s-bit_defconfig
>index b754dac45ec3..a584c26eb90f 100644
>--- a/configs/crs326-24g-2s-bit_defconfig
>+++ b/configs/crs326-24g-2s-bit_defconfig
>@@ -47,3 +47,4 @@ CONFIG_SPI_FLASH_MTD=y
> CONFIG_PCI_MVEBU=y
> CONFIG_SYS_NS16550=y
> CONFIG_KIRKWOOD_SPI=y
>+# CONFIG_EFI_LOADER is not set
>diff --git a/configs/crs326-24g-2s_defconfig b/configs/crs326-24g-2s_defconfig
>index 870127d38720..43f7455afbf6 100644
>--- a/configs/crs326-24g-2s_defconfig
>+++ b/configs/crs326-24g-2s_defconfig
>@@ -47,3 +47,4 @@ CONFIG_SPI_FLASH_MTD=y
> CONFIG_PCI_MVEBU=y
> CONFIG_SYS_NS16550=y
> CONFIG_KIRKWOOD_SPI=y
>+# CONFIG_EFI_LOADER is not set
>diff --git a/configs/crs328-4c-20s-4s-bit_defconfig 
>b/configs/crs328-4c-20s-4s-bit_defconfig
>index 2373775dc5a9..7bf671643a90 100644
>--- a

[PATCH 3/3] block: Update BLK to be def_bool

2024-06-04 Thread Tom Rini
At this point in the DM migration, all platforms enable DM. BLK requires
DM. Make BLK "def_bool y" in the cases it had been "default y" to make
this clearer. Now remove the symbol requirement from other places as it
is redundant here.

Signed-off-by: Tom Rini 
---
 drivers/ata/Kconfig   |  1 -
 drivers/block/Kconfig |  4 ++--
 drivers/mmc/Kconfig   | 30 ++
 3 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 9bc5283c2688..6cca561f974f 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -61,7 +61,6 @@ config DWC_AHCI
 config DWC_AHSATA
bool "Enable DWC AHSATA driver support"
select LIBATA
-   depends on BLK
help
  Enable this driver to support the DWC AHSATA SATA controller found
  in i.MX5 and i.MX6 SoCs.
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 6ad18889f61e..48529a6982f5 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -1,8 +1,8 @@
 config BLK
bool # "Support block devices"
depends on DM
-   default y if MMC || USB || SCSI || NVME || IDE || AHCI || SATA
-   default y if EFI_MEDIA || VIRTIO_BLK || PVBLOCK
+   def_bool y if MMC || USB || SCSI || NVME || IDE || AHCI || SATA
+   def_bool y if EFI_MEDIA || VIRTIO_BLK || PVBLOCK
help
  Enable support for block devices, such as SCSI, MMC and USB
  flash sticks. These provide a block-level interface which permits
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index d0944793c92d..8b13a0821ee0 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -41,7 +41,6 @@ config MMC_BROKEN_CD
 config DM_MMC
bool "Enable MMC controllers using Driver Model"
depends on DM
-   select BLK
help
  This enables the MultiMediaCard (MMC) uclass which supports MMC and
  Secure Digital I/O (SDIO) cards. Both removable (SD, micro-SD, etc.)
@@ -249,7 +248,6 @@ config MMC_DW_CORTINA
bool "Cortina specific extensions for Synopsys DW Memory Card Interface"
depends on DM_MMC
depends on MMC_DW
-   depends on BLK
help
  This selects support for Cortina SoC specific extensions to the
  Synopsys DesignWare Memory Card Interface driver. Select this option
@@ -313,7 +311,7 @@ config NEXELL_DWMMC
 
 config MMC_MESON_GX
bool "Meson GX EMMC controller support"
-   depends on DM_MMC && BLK && ARCH_MESON
+   depends on DM_MMC && ARCH_MESON
help
 Support for EMMC host controller on Meson GX ARM SoCs platform (S905)
 
@@ -367,7 +365,7 @@ config MMC_OCTEONTX
 
 config MVEBU_MMC
bool "Kirkwood MMC controller support"
-   depends on DM_MMC && BLK && ARCH_KIRKWOOD
+   depends on DM_MMC && ARCH_KIRKWOOD
help
  Support for MMC host controller on Kirkwood SoCs.
  If you are on a Kirkwood architecture, say Y here.
@@ -420,7 +418,7 @@ config SH_MMCIF
 config MMC_UNIPHIER
bool "UniPhier SD/MMC Host Controller support"
depends on ARCH_UNIPHIER
-   depends on BLK && DM_MMC
+   depends on DM_MMC
depends on OF_CONTROL
help
  This selects support for the Matsushita SD/MMC Host Controller on
@@ -429,7 +427,7 @@ config MMC_UNIPHIER
 config RENESAS_SDHI
bool "Renesas R-Car SD/MMC Host Controller support"
depends on ARCH_RENESAS
-   depends on BLK && DM_MMC
+   depends on DM_MMC
depends on OF_CONTROL
select BOUNCE_BUFFER
help
@@ -439,7 +437,7 @@ config RENESAS_SDHI
 config MMC_BCM2835
bool "BCM2835 family custom SD/MMC Host Controller support"
depends on ARCH_BCM283X
-   depends on BLK && DM_MMC
+   depends on DM_MMC
depends on OF_CONTROL
default y
help
@@ -459,7 +457,7 @@ config JZ47XX_MMC
 config MMC_SANDBOX
bool "Sandbox MMC support"
depends on SANDBOX
-   depends on BLK && DM_MMC && OF_CONTROL
+   depends on DM_MMC && OF_CONTROL
help
  This select a dummy sandbox MMC driver. At present this does nothing
  other than allow sandbox to be build with MMC support. This
@@ -561,7 +559,7 @@ config MMC_SDHCI_ASPEED
 config MMC_SDHCI_ATMEL
bool "Atmel SDHCI controller support"
depends on ARCH_AT91
-   depends on DM_MMC && BLK && ARCH_AT91
+   depends on DM_MMC && ARCH_AT91
depends on MMC_SDHCI
help
  This enables support for the Atmel SDHCI controller, which supports
@@ -596,7 +594,7 @@ config MMC_SDHCI_BCMSTB
 
 config MMC_SDHCI_CADENCE
bool "SDHCI support for the Cadence SD/SDIO/eMMC controller"
-   depends on BLK && DM_MMC
+   depends on DM_MMC
depends on MMC_SDHCI
depends on OF_CONTROL
help
@@ -608,7 +606,7 @@ config MMC_SDHCI_CADENCE
 
 config MMC_SDHCI_CV1800B
bool "SDHCI support for the CV1800B SD/SDIO/eMMC controller"
-

[PATCH 2/3] spl: nvme: Make this depend on SPL_BLK

2024-06-04 Thread Tom Rini
As this is an SPL related driver, and in SPL enabling SPL_BLK is
optional, make this depend on the correct symbol.

Signed-off-by: Tom Rini 
---
 common/spl/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 6405374bcc12..80c80d9904fd 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -1293,7 +1293,7 @@ config SPL_SATA_RAW_U_BOOT_SECTOR
 
 config SPL_NVME
bool "NVM Express device support"
-   depends on BLK
+   depends on SPL_BLK
select FS_LOADER
select SPL_BLK_FS
help
-- 
2.34.1



[PATCH 1/3] efi_loader: select BLK not depends on BLK

2024-06-04 Thread Tom Rini
The BLK symbol is used both for "we have a block device subsystem
enabled" and "we need to utilize the block device library functions". In
the case of efi_loader, it is the case of "we need to utilize the block
device library", so select rather than depends on it. In turn, also
disable EFI_LOADER on platforms which did not have it on previously due
to a lack of block devices. They can enable it themselves if desired.

Signed-off-by: Tom Rini 
---
Cc: Heinrich Schuchardt 
---
 configs/cortina_presidio-asic-base_defconfig | 1 +
 configs/cortina_presidio-asic-pnand_defconfig| 1 +
 configs/crs305-1g-4s-bit_defconfig   | 1 +
 configs/crs305-1g-4s_defconfig   | 1 +
 configs/crs326-24g-2s-bit_defconfig  | 1 +
 configs/crs326-24g-2s_defconfig  | 1 +
 configs/crs328-4c-20s-4s-bit_defconfig   | 1 +
 configs/crs328-4c-20s-4s_defconfig   | 1 +
 configs/gxp_defconfig| 1 +
 configs/maxbcm_defconfig | 1 +
 configs/mt7981_rfb_defconfig | 1 +
 configs/mt7986_rfb_defconfig | 1 +
 configs/mx6memcal_defconfig  | 1 +
 configs/pg_wcom_expu1_defconfig  | 1 +
 configs/pg_wcom_expu1_update_defconfig   | 1 +
 configs/pg_wcom_seli8_defconfig  | 1 +
 configs/pg_wcom_seli8_update_defconfig   | 1 +
 configs/r8a77970_eagle_defconfig | 1 +
 configs/smdkc100_defconfig   | 1 +
 configs/socfpga_is1_defconfig| 1 +
 configs/stm32mp25_defconfig  | 1 +
 configs/thunderx_88xx_defconfig  | 1 +
 configs/xilinx_versal_mini_defconfig | 1 +
 configs/xilinx_versal_mini_ospi_defconfig| 1 +
 configs/xilinx_versal_mini_qspi_defconfig| 1 +
 configs/xilinx_versal_net_mini_defconfig | 1 +
 configs/xilinx_versal_net_mini_ospi_defconfig| 1 +
 configs/xilinx_versal_net_mini_qspi_defconfig| 1 +
 configs/xilinx_zynqmp_mini_defconfig | 1 +
 configs/xilinx_zynqmp_mini_nand_defconfig| 1 +
 configs/xilinx_zynqmp_mini_nand_single_defconfig | 1 +
 configs/xilinx_zynqmp_mini_qspi_defconfig| 1 +
 configs/zynq_cse_nand_defconfig  | 1 +
 configs/zynq_cse_nor_defconfig   | 1 +
 configs/zynq_cse_qspi_defconfig  | 1 +
 lib/efi_loader/Kconfig   | 2 +-
 36 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/configs/cortina_presidio-asic-base_defconfig 
b/configs/cortina_presidio-asic-base_defconfig
index 8f20f6515606..eb5743da64db 100644
--- a/configs/cortina_presidio-asic-base_defconfig
+++ b/configs/cortina_presidio-asic-base_defconfig
@@ -38,3 +38,4 @@ CONFIG_DM_SERIAL=y
 CONFIG_CORTINA_UART=y
 CONFIG_WDT=y
 CONFIG_WDT_CORTINA=y
+# CONFIG_EFI_LOADER is not set
diff --git a/configs/cortina_presidio-asic-pnand_defconfig 
b/configs/cortina_presidio-asic-pnand_defconfig
index 94dc3e1e2e8e..c7367d4d91cc 100644
--- a/configs/cortina_presidio-asic-pnand_defconfig
+++ b/configs/cortina_presidio-asic-pnand_defconfig
@@ -43,3 +43,4 @@ CONFIG_DM_SERIAL=y
 CONFIG_CORTINA_UART=y
 CONFIG_WDT=y
 CONFIG_WDT_CORTINA=y
+# CONFIG_EFI_LOADER is not set
diff --git a/configs/crs305-1g-4s-bit_defconfig 
b/configs/crs305-1g-4s-bit_defconfig
index a8f17570ecaa..c3d4594b75f7 100644
--- a/configs/crs305-1g-4s-bit_defconfig
+++ b/configs/crs305-1g-4s-bit_defconfig
@@ -47,3 +47,4 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
+# CONFIG_EFI_LOADER is not set
diff --git a/configs/crs305-1g-4s_defconfig b/configs/crs305-1g-4s_defconfig
index c66d291eb926..1919e8c7794d 100644
--- a/configs/crs305-1g-4s_defconfig
+++ b/configs/crs305-1g-4s_defconfig
@@ -48,3 +48,4 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
+# CONFIG_EFI_LOADER is not set
diff --git a/configs/crs326-24g-2s-bit_defconfig 
b/configs/crs326-24g-2s-bit_defconfig
index b754dac45ec3..a584c26eb90f 100644
--- a/configs/crs326-24g-2s-bit_defconfig
+++ b/configs/crs326-24g-2s-bit_defconfig
@@ -47,3 +47,4 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
+# CONFIG_EFI_LOADER is not set
diff --git a/configs/crs326-24g-2s_defconfig b/configs/crs326-24g-2s_defconfig
index 870127d38720..43f7455afbf6 100644
--- a/configs/crs326-24g-2s_defconfig
+++ b/configs/crs326-24g-2s_defconfig
@@ -47,3 +47,4 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
+# CONFIG_EFI_LOADER is not set
diff --git a/configs/crs328-4c-20s-4s-bit_defconfig 
b/configs/crs328-4c-20s-4s-bit_defconfig
index 2373775dc5a9..7bf671643a90 100644
--- a/configs/crs328-4c-20s-4s-bit_defconfig
+++ b/configs/crs328-4c-20s-4s-bit_defconfig
@@ -47,3 +47,4 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
+# CON

Possible license violation

2024-06-04 Thread pm88hpxmdxke





HiI am copying this message to you and GL team.Regarding license 
violation:U-boot’s license requires Gl.iNet to provide the source-code for 
U-boot (including any modifications they made) to anybody that asks for it. 
So…GL team refused to send source code nor .bin file. I wanted to inspect it 
for possible backdoors but still they are refusing.“ If you choose to provide 
source through a written offer, then anybody who requests the source from you 
is entitled to receive it.If you commercially distribute binaries not 
accompanied with source code, the GPL says you must provide a written offer to 
distribute the source code later. When users non-commercially redistribute the 
binaries they received from you, they must pass along a copy of this written 
offer. This means that people who did not get the binaries directly from you 
can still receive copies of the source code, along with the written offer.The 
reason we require the offer to be valid for any third party is so that people 
who receive the binaries indirectly in that way can order the source code from 
you.”https://www.gnu.org/licenses/old-licenses/gpl-2.0-faq.en.htmlhttps://github.com/u-boot/u-bootSo
 I am sending this message to you to check this situation. They probably will 
not send it to you.Also please use web mail (not business domain) as they can 
sent it to you through it to hide the fact of licensing violation. For example 
send request from Gmail. Please take measures.  










Re: [PATCH v2 00/14] Introduce the lwIP network stack

2024-06-04 Thread Peter Robinson
> On Fri, May 24, 2024 at 06:19:54PM +0200, Jerome Forissier wrote:
> > - Make the support of HTTPS in the wget command easier. Javier T. (CC'd)
> > has some additional lwIP and Mbed TLS patches to do so. With that it
> > becomes possible to fetch and launch a distro installer such as Debian
> > etc. directly from the U-Boot shell.
>
> Why this is enabling this use case? Or it is just that currently,
> without TLS, is not supposed to be something you should do?
> I am a little bit confused reading this sentence, since to me this is
> already possible using tftp.

A lot of companies don't want to run tftp any more when http(s) is
more straight forward, especially when used outside of the data
centre, it can be cached/proxied etc and has a bunch of other benefits
before you even get to things like security and auth. Also a lot of FW
vendors are starting to drop PXE/TFTP support in standards due to
various things like standards requirements from governments.

Peter


Several potential vulnerabilities in the filesystem

2024-06-04 Thread jianqiang wang
Hi Das U-Boot developers,

I found several vulnerabilities in the u-boot filesysetm implementation,

1. in file fs/squashfs/sqfs_inode.c function sqfs_inode_size. The
parameter blk_size is directly or indirectly from the storage data.
Howver, without a sanity check, this value is directly used in the
division operations, leading to a division-by-zero exception

2. in file fs/erofs/data.c, function z_erofs_read_one_data, the node
data is read from the storage, however, without a proper check, the
data can be corrupted. For example, the inode data is used in function
z_erofs_read_data, map.m_llen will be calculated to a very large
value, which means the length variable will be very large. It will
cause a large memory clear with memset(buffer + end - offset, 0,
length);

3. in file fs/squashfs/sqfs.c, function sqfs_frag_lookup, the header
variable is read/calculated from the storage data, however, without a
proper check, memcpy(entries, metadata, SQFS_METADATA_SIZE(header));
will cause a buffer over write when header cannot correctly clear the
higher bits (SQFS_METADATA_SIZE(header)).

Could you please confirmware these vulnerabilities?

Best regards


Re: [PATCH v3 03/25] mbedtls: add mbedtls into the build system

2024-06-04 Thread Raymond Mao
Hi Andy,

On Tue, 4 Jun 2024 at 16:17, Andy Shevchenko <
andriy.shevche...@linux.intel.com> wrote:

> On Tue, May 28, 2024 at 07:09:14AM -0700, Raymond Mao wrote:
> > Port mbedtls with dummy libc header files.
> > Add mbedtls default config header file.
> > Optimize mbedtls default config by disabling unused features to
> > reduce the target size.
> > Add mbedtls kbuild makefile.
> > Add Kconfig and mbedtls config submenu.
> >
> > Prerequisite
> > 
> >
> > This patch series requires mbedtls git repo to be added as a
> > subtree to the main U-Boot repo via:
> >
> > $ git subtree add --prefix lib/mbedtls/external/mbedtls \
> >   https://github.com/Mbed-TLS/mbedtls.git \
> >   v3.6.0 --squash
>
> Is this approach maintainable?
> I don't remember if we have similar in Linux kernel, for example.
> (There are few candidates like compression algorithms that are usually
> being
>  hosted elsewhere)
>
> > Moreover, due to the Windows-style files from mbedtls git repo,
> > we need to convert the CRLF endings to LF and do a commit manually:
> >
> > $ git add --renormalize .
> > $ git commit
>
> ...
>
> >  lib/mbedtls/mbedtls_def_config.h | 4262 ++
>
> This is ridiculously HUGE! This is unreviewable. Moreover, this is even
> hard to
> configure by the user! Can you rather make it modular and maybe create a
> separate documentation for the most important options (I do not believe one
> needs _all_ of them to be set / tuned)?
>
> This is a file from MbedTLS and follows its own style.
And this is how MbedTLS is configured - with all features listed in a
config file and
commenting out the unused features with "//").
The modification here is just to control those existing options with
Kconfigs.

Regards,
Raymond


Re: [PATCH v3 03/25] mbedtls: add mbedtls into the build system

2024-06-04 Thread Andy Shevchenko
On Tue, May 28, 2024 at 07:09:14AM -0700, Raymond Mao wrote:
> Port mbedtls with dummy libc header files.
> Add mbedtls default config header file.
> Optimize mbedtls default config by disabling unused features to
> reduce the target size.
> Add mbedtls kbuild makefile.
> Add Kconfig and mbedtls config submenu.
> 
> Prerequisite
> 
> 
> This patch series requires mbedtls git repo to be added as a
> subtree to the main U-Boot repo via:
> 
> $ git subtree add --prefix lib/mbedtls/external/mbedtls \
>   https://github.com/Mbed-TLS/mbedtls.git \
>   v3.6.0 --squash

Is this approach maintainable?
I don't remember if we have similar in Linux kernel, for example.
(There are few candidates like compression algorithms that are usually being
 hosted elsewhere)

> Moreover, due to the Windows-style files from mbedtls git repo,
> we need to convert the CRLF endings to LF and do a commit manually:
> 
> $ git add --renormalize .
> $ git commit

...

>  lib/mbedtls/mbedtls_def_config.h | 4262 ++

This is ridiculously HUGE! This is unreviewable. Moreover, this is even hard to
configure by the user! Can you rather make it modular and maybe create a
separate documentation for the most important options (I do not believe one
needs _all_ of them to be set / tuned)?

-- 
With Best Regards,
Andy Shevchenko




Re: [PATCH v3 02/25] mbedtls: Add script to update MbedTLS subtree

2024-06-04 Thread Andy Shevchenko
On Fri, May 31, 2024 at 09:32:38AM +0300, Ilias Apalodimas wrote:
> On Tue, 28 May 2024 at 17:10, Raymond Mao  wrote:
> >
> > lib/mbedtls/update-mbedtls-subtree.sh is a wrapper of git subtree
> > commands.
> > Usage from U-Boot top directory, run:

...

> > +if ! git remote get-url mbedtls_upstream 2>/dev/null
> 
> if [ -z "$(git remote get-url rigin 2>/dev/null)" ]; then

Why? I mean why do we need an additional `test` call? Above can be transformed
to `foo && {}` notation to get rid of if completely.

> > +then
> > +echo "Warning: Script automatically adds new git remote via:"
> > +echo "git remote add mbedtls_upstream \\"
> > +echo "https://github.com/Mbed-TLS/mbedtls.git";
> > +git remote add mbedtls_upstream \
> > +https://github.com/Mbed-TLS/mbedtls.git
> > +fi
> > +git fetch mbedtls_upstream master
> > +}

...

> > +if [ "$1" = "pull" ]
> 
> "$1" == 'pull'

Why? Isn't this bashism?

> Also on string literals, you don't need "", 'pull' is enough
> 
> > +then
> > +remote_add_and_fetch
> > +git subtree pull --prefix lib/mbedtls/external/mbedtls 
> > mbedtls_upstream \
> > +"$2" --squash -m "${merge_commit_msg}"
> > +elif [ "$1" = "pick" ]
> move then 'then' one line up and add a ;

>  == 'pick'

Ditto.

> > +then
> > +remote_add_and_fetch
> > +git cherry-pick -x --strategy=subtree \
> > +-Xsubtree=lib/mbedtls/external/mbedtls/ "$2"
> > +else
> > +echo "usage: $0  "
> > +echo "   pull or pick"
> > +echo "  release tag [pull] or commit id [pick]"
> > +fi

Sheel should be written as much as portable and less verbose.

-- 
With Best Regards,
Andy Shevchenko




[PATCH 2/2] doc: add clarity to what a "fpga" image is

2024-06-04 Thread Sam Povilus
Update fit documentation to clarify that FPGA images are vendor specific and 
opaque bitstreams.

Signed-off-by: Sam Povilus 
---
 doc/usage/fit/source_file_format.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/usage/fit/source_file_format.rst 
b/doc/usage/fit/source_file_format.rst
index 310225d839..7727ab77c5 100644
--- a/doc/usage/fit/source_file_format.rst
+++ b/doc/usage/fit/source_file_format.rst
@@ -198,7 +198,7 @@ type
 firmware  Firmware
 firmware_ivt  Firmware with HABv4 IVT
 flat_dt   Flat Device Tree
-fpga  FPGA Image
+fpga  FPGA Device Image (bitstream file, vendor specific)
 gpimage   TI Keystone SPL Image
 imx8image NXP i.MX8 Boot Image
 imx8mimageNXP i.MX8M Boot Image
-- 
2.34.1



[PATCH 1/2] doc: Remove extraneous curly braces

2024-06-04 Thread Sam Povilus
Update documentation to remove un-needed curly braces.

Signed-off-by: Sam Povilus 
---
 doc/usage/fit/source_file_format.rst | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/doc/usage/fit/source_file_format.rst 
b/doc/usage/fit/source_file_format.rst
index b2b1e42bd7..310225d839 100644
--- a/doc/usage/fit/source_file_format.rst
+++ b/doc/usage/fit/source_file_format.rst
@@ -192,13 +192,13 @@ type
 invalid   Invalid Image
 aisimage  Davinci AIS image
 atmelimageATMEL ROM-Boot Image
-copro Coprocessor Image}
+copro Coprocessor Image
 fdt_legacylegacy Image with Flat Device Tree
 filesystemFilesystem Image
 firmware  Firmware
-firmware_ivt  Firmware with HABv4 IVT }
+firmware_ivt  Firmware with HABv4 IVT
 flat_dt   Flat Device Tree
-fpga  FPGA Image }
+fpga  FPGA Image
 gpimage   TI Keystone SPL Image
 imx8image NXP i.MX8 Boot Image
 imx8mimageNXP i.MX8M Boot Image
@@ -207,31 +207,31 @@ type
 kernel_noload Kernel Image (no loading done)
 kwbimage  Kirkwood Boot Image
 lpc32xximage  LPC32XX Boot Image
-mtk_image MediaTek BootROM loadable Image }
+mtk_image MediaTek BootROM loadable Image
 multi Multi-File Image
 mxsimage  Freescale MXS Boot Image
 omapimage TI OMAP SPL With GP CH
 pblimage  Freescale PBL Boot Image
 pmmc  TI Power Management Micro-Controller Firmware
 ramdisk   RAMDisk Image
-rkimage   Rockchip Boot Image }
-rksd  Rockchip SD Boot Image }
-rkspi Rockchip SPI Boot Image }
+rkimage   Rockchip Boot Image
+rksd  Rockchip SD Boot Image
+rkspi Rockchip SPI Boot Image
 scriptScript
 socfpgaimage  Altera SoCFPGA CV/AV preloader
 socfpgaimage_v1   Altera SoCFPGA A10 preloader
-spkgimage Renesas SPKG Image }
+spkgimage Renesas SPKG Image
 standaloneStandalone Program
-stm32imageSTMicroelectronics STM32 Image }
-sunxi_egonAllwinner eGON Boot Image }
-sunxi_toc0Allwinner TOC0 Boot Image }
+stm32imageSTMicroelectronics STM32 Image
+sunxi_egonAllwinner eGON Boot Image
+sunxi_toc0Allwinner TOC0 Boot Image
 tee   Trusted Execution Environment Image
 ublimage  Davinci UBL image
 vybridimage   Vybrid Boot Image
 x86_setup x86 setup.bin
-zynqimage Xilinx Zynq Boot Image }
-zynqmpbif Xilinx ZynqMP Boot Image (bif) }
-zynqmpimage   Xilinx ZynqMP Boot Image }
+zynqimage Xilinx Zynq Boot Image
+zynqmpbif Xilinx ZynqMP Boot Image (bif)
+zynqmpimage   Xilinx ZynqMP Boot Image
   ==
 
 compression
-- 
2.34.1



[PATCH 0/2] Cleanup fit documentation

2024-06-04 Thread Sam Povilus
Sam Povilus (2):
  doc: Remove extraneous curly braces
  doc: add clarity to what a "fpga" image is

 doc/usage/fit/source_file_format.rst | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

-- 
2.34.1



Re: [PATCH v3 15/25] mbedtls: add X509 cert parser porting layer

2024-06-04 Thread Tom Rini
On Tue, Jun 04, 2024 at 07:53:54PM +0300, Ilias Apalodimas wrote:
> On Tue, 4 Jun 2024 at 19:05, Raymond Mao  wrote:
> >
> > Hi Ilias,
> >
> > On Fri, 31 May 2024 at 07:42, Ilias Apalodimas 
> >  wrote:
> >>
> >> On Tue, 28 May 2024 at 17:15, Raymond Mao  wrote:
> >> >
> >> > Add porting layer for X509 cert parser on top of MbedTLS X509
> >> > library.
> >> >
> >> > Signed-off-by: Raymond Mao 
> >> > ---
> >> > Changes in v2
> >> > - Move the porting layer to MbedTLS dir.
> >> > Changes in v3
> >> > - None.
> >> >
> >> >  lib/mbedtls/Makefile   |   1 +
> >> >  lib/mbedtls/x509_cert_parser.c | 497 +
> >> >  2 files changed, 498 insertions(+)
> >> >  create mode 100644 lib/mbedtls/x509_cert_parser.c
> >> >
> >
> > [snip]
> >>
> >> > diff --git a/lib/mbedtls/x509_cert_parser.c 
> >> > b/lib/mbedtls/x509_cert_parser.c
> >> > new file mode 100644
> >> > index 000..b0867d31047
> >> > --- /dev/null
> >> > +++ b/lib/mbedtls/x509_cert_parser.c
> >>
> > [snip]
> >>
> >> > +static int x509_set_cert_flags(struct x509_certificate *cert)
> >> > +{
> >> > +   struct public_key_signature *sig = cert->sig;
> >> > +
> >> > +   if (!sig || !cert->pub) {
> >> > +   pr_err("Signature or public key is not initialized\n");
> >> > +   return -ENOPKG;
> >> > +   }
> >> > +
> >> > +   if (!cert->pub->pkey_algo)
> >> > +   cert->unsupported_key = true;
> >> > +
> >> > +   if (!sig->pkey_algo)
> >> > +   cert->unsupported_sig = true;
> >> > +
> >> > +   if (!sig->hash_algo)
> >> > +   cert->unsupported_sig = true;
> >> > +
> >> > +   /* TODO: is_hash_blacklisted()? */
> >>
> >> Is this supported by our current implementation?
> >>
> > This is not supported currently either. I just copied the TODO mark
> > from legacy lib.
> >
> > [snip]
> >>
> >> > +   }
> >> > +   goto out;
> >> > +   }
> >> > +
> >> > +   pr_devel("Cert Self-signature verified");
> >> > +   cert->self_signed = true;
> >> > +
> >> > +out:
> >> > +   return ret;
> >> > +
> >> > +not_self_signed:
> >> > +   return 0;
> >> > +}
> >>
> >> the whole function looks like a copy of lib/crypto/x509_public_key.c.
> >> Can you move all the c/p ones to a common file that the existing and
> >> mbedTLS implementations can use?
> >>
> > Per a previous discussion with Tom, eventually we tend to keep only one
> > crypto lib, that is the reason I prefer to copy/optimize a few existing
> > functions into MbedTLS implementation instead of creating another
> > common file.
> 
> Regardless of the implementation, the common functions should reside
> in a common file which will be used regardless of mbedTLS or the
> existing stack.
> We do not want to fix bugs twice

And please keep in mind we already have _two_ implementations at times
today, and it will stay that way even when mbedTLS replaces legacy
options.  The ARM HW SHA256 option for example is going to likely be
used over mbedTLS SHA256.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 03/25] mbedtls: add mbedtls into the build system

2024-06-04 Thread Tom Rini
On Fri, May 31, 2024 at 01:07:23PM -0400, Raymond Mao wrote:
> Hi Ilias and Tom,
> 
> On Thu, 30 May 2024 at 16:17, Ilias Apalodimas 
> wrote:
> 
> > Hi Tom
> >
> > On Wed, 29 May 2024 at 22:47, Tom Rini  wrote:
> > >
> > > On Wed, May 29, 2024 at 03:42:04PM -0400, Raymond Mao wrote:
> > > > Hi Tom,
> > > >
> > > > On Wed, 29 May 2024 at 14:43, Tom Rini  wrote:
> > > >
> > > > > On Wed, May 29, 2024 at 02:38:10PM -0400, Raymond Mao wrote:
> > > > > > Hi Tom,
> > > > > >
> > > > > > On Wed, 29 May 2024 at 14:01, Tom Rini  wrote:
> > > > > >
> > > > > > > On Wed, May 29, 2024 at 01:42:16PM -0400, Raymond Mao wrote:
> > > > > > > > Hi Tom,
> > > > > > > >
> > > > > > > > On Wed, 29 May 2024 at 12:58, Tom Rini 
> > wrote:
> > > > > > > >
> > > > > > > > > On Tue, May 28, 2024 at 07:09:14AM -0700, Raymond Mao wrote:
> > > > > > > > >
> > > > > > > > > > Port mbedtls with dummy libc header files.
> > > > > > > > > > Add mbedtls default config header file.
> > > > > > > > > > Optimize mbedtls default config by disabling unused
> > features to
> > > > > > > > > > reduce the target size.
> > > > > > > > > > Add mbedtls kbuild makefile.
> > > > > > > > > > Add Kconfig and mbedtls config submenu.
> > > > > > > > > [snip]
> > > > > > > > > > diff --git a/lib/mbedtls/Kconfig b/lib/mbedtls/Kconfig
> > > > > > > > > > new file mode 100644
> > > > > > > > > > index 000..d6e77d56871
> > > > > > > > > > --- /dev/null
> > > > > > > > > > +++ b/lib/mbedtls/Kconfig
> > > > > > > > > > @@ -0,0 +1,25 @@
> > > > > > > > > > +menuconfig MBEDTLS_LIB
> > > > > > > > > > + bool "Use mbedtls libraries"
> > > > > > > > > > + select MBEDTLS_LIB_CRYPTO
> > > > > > > > > > + select MBEDTLS_LIB_X509
> > > > > > > > > > + help
> > > > > > > > > > +   Enable mbedtls libraries
> > > > > > > > > > +
> > > > > > > > > > +if MBEDTLS_LIB
> > > > > > > > > > +
> > > > > > > > > > +config MBEDTLS_LIB_CRYPTO
> > > > > > > > > > + bool "Crypto library"
> > > > > > > > > > + help
> > > > > > > > > > +   Enable mbedtls crypto library
> > > > > > > > > > +
> > > > > > > > > > +config MBEDTLS_LIB_X509
> > > > > > > > > > + bool "X509 library"
> > > > > > > > > > + help
> > > > > > > > > > +   Enable mbedtls X509 library
> > > > > > > > > > +
> > > > > > > > > > +config MBEDTLS_LIB_TLS
> > > > > > > > > > + bool "TLS library"
> > > > > > > > > > + help
> > > > > > > > > > +   Enable mbedtls TLS library
> > > > > > > > > > +
> > > > > > > > > > +endif # MBEDTLS_LIB
> > > > > > > > >
> > > > > > > > > We need much more granularity here, and to re-think some
> > existing
> > > > > > > > > symbols too perhaps. What we should be able to do is pick
> > mbedTLS
> > > > > or
> > > > > > > > > "legacy SW implementation" or "HW implementation" for the
> > various
> > > > > > > > > algorithms, and that in turn can have some higher level
> > grouping
> > > > > to it.
> > > > > > > > > This should then negate a bunch of the Makefile work you're
> > doing
> > > > > as we
> > > > > > > > > won't have CONFIG_SHA256 enabled as we'll have
> > > > > > > CONFIG_MBEDTLS_LIB_SHA256
> > > > > > > > > or whatever enabled.
> > > > > > > > >
> > > > > > > >
> > > > > > > > I think we should use CONFIG_MBEDTLS_LIB_[CRYPTO,X509,TLS] for
> > > > > high-level
> > > > > > > > grouping.
> > > > > > > > Underneath, the CONFIG_SHA[1,256,512] switches (and other
> > crypto
> > > > > options)
> > > > > > > > can be
> > > > > > > > used as sub build options in both MbedTLS and "legacy libs".
> > > > > > > >
> > > > > > > > Take hash as an example, if the users prefer to use MbedTLS
> > other
> > > > > than
> > > > > > > > "legacy libs" for
> > > > > > > > hash operation, CONFIG_MBEDTLS_LIB_CRYPTO should be defined as
> > the
> > > > > main
> > > > > > > > switch
> > > > > > > > (the users can still prefer to use "legacy libs" for X509 by
> > > > > > > > keeping  CONFIG_MBEDTLS_LIB_X509
> > > > > > > > disabled).
> > > > > > > > Then enable the algorithms they need (e.g. CONFIG_SHA256) - the
> > > > > algorithm
> > > > > > > > options works
> > > > > > > > for both MbedTLS and "legacy libs".
> > > > > > > >
> > > > > > > > HW implementations with MbedTLS (aka, Alternative algorithms in
> > > > > MbedTLS)
> > > > > > > is
> > > > > > > > another
> > > > > > > > topic which is not covered in this patch set (It needs to
> > migrate
> > > > > each
> > > > > > > > vendor's solution under
> > > > > > > > MbedTLS alternative algorithm).
> > > > > > > > Current patch set is focused on SW implementation with MbedTLS.
> > > > > > >
> > > > > > > The "easy" problem with what's in v3 is that X509 and CRYPTO are
> > > > > > > select'd under the main heading.
> > > > > >
> > > > > > Not sure if I get what you mentioned, currently all MbedTLS
> > options are
> > > > > > under
> > > > > > Library routines > Security support
> > > > > > Do you think we should keep them in other places?
> > > > > >
> > > > > >
> > > > > > > The harder problem is t

Re: [PATCH v2 0/5] FUSB302 USB-C controller support

2024-06-04 Thread Soeren Moch

Hi,

On 04.06.24 18:33, Sebastian Reichel wrote:

Hi,

On ROCK 5B power is usually supplied via it's USB-C port. This port has the
data lines connected to RK3588, VBUS connected to the input regulator and
CC pins connected to FUSB302. FUSB302 is a USB-C controller, which can be
accessed via I2C from RK3588. The USB-C controller is needed to figure out
the USB-C cable orientation, but also to do USB PD communication. Thus it
would be great to enable support for it in the operating system.

But the USB-PD specification requires, that a device reacts to USB-PD messages
send by the power-supply within around 5 seconds. If that does not happen the
power-supply assumes, that the device does not support USB-PD. If a device
later starts sending USB-PD messages it is considered an error, which is solved
by doing a hard reset. A USB-PD hard reset means, that all supply voltages are
removed for a short period of time. For boards, which are solely powered
through their USB-C port, like the Radxa Rock 5B, this results in an machine
reset. This is currently worked around by not describing the FUSB302 in the
kernel DT, so nothing will ever speak USB-PD on the Rock 5B. This means

1. the USB-C port cannot be used at all
2. the board will be running via fallback supply, which provides limited
power capabilities

In order to avoid the hard reset, this adds FUSB302 support to U-Boot, so
that we react to the power-supply's queries in time. The code, which is
originally from the Linux kernel, consists of two parts:

1. the tcpm state machine, which implements the Type C port manager state
machine as described in the USB PD specification
2. the fusb302 driver, which knows about specific registers

Especially the first part has been heavily modified compared to the
kernel, which makes use of multiple delayed works and threads. For this
I used a priorly ported version from Rockchip, removed their hacks and
any states not necessary in U-Boot (e.g. audio accessory support).

Changes since PATCHv1:
  * tcpm: split uclass specific code to tcpm-uclass
  * tcpm_print_info: move printing part to cmd/tcpm.c
  * tcpm_print_info: report more information
- PD revision
- Cable orientation
- Power role
- Data role
- Print TCPM state based on connection status
  * tcpm: use "struct udevice *dev" instead of "struct tcpm_port *port"
as function argument in most places and drop dev from the tcpm_port
struct
  * tcpm: avoid useless kzalloc + copy + free for incoming events
  * tcpm: use dev_get_uclass_plat() for tcpm_port
  * tcpm: run tcpm_port_init() and tcpm_poll_event() from UCLASS post_probe()
  * tcpm/fusb302: get rid of tcpc_dev by using dm_tcpm_ops() for the
function pointers and introducing get_connector_node() for the
ofnode
  * fusb302: use "struct udevice *dev" instead of "struct fusb302_chip *chip"
as function argument and drop dev from the fusb302_chip struct
  * fusb302: drop multiple unused members from fusb302_chip
  * fusb302: directly use udelay instead of usleep_range define
  * fusb302: use fusb302_ prefix for all functions. Afterwards tcpm_ prefix
is only used for the tcpm code itself
  * fusb302: move fusb302_poll_event() to avoid forward defintion
  * fusb302: drop probe function
  * fusb302: drop unused LOG_BUFFER defines
  * roughly 20% of all lines of the series changed between v1 and v2, so
I did not collect the Tested-by from Soeren Moch


Makes sense, of course.

I retested this v2 series on top of 2024.07-rc4, everything still works
perfectly fine for me.

Tested-by: Soeren Moch 



U-Boot 2024.07-rc4-5-gc9c6c70498 (Jun 04 2024 - 19:18:57 +0200)

Model: Radxa ROCK 5 Model B
DRAM:  8 GiB
Core:  355 devices, 33 uclasses, devicetree: separate
MMC:   mmc@fe2c: 1, mmc@fe2d: 2, mmc@fe2e: 0
Loading Environment from nowhere... OK
In:    serial@feb5
Out:   serial@feb5
Err:   serial@feb5
Model: Radxa ROCK 5 Model B
Net:   No ethernet found.
Hit any key to stop autoboot:  0
=> tcpm list
| Name    | Parent name | Parent uclass
@ seq
| usb-typec@22    | i2c@feac    | i2c @ 4 |
status: 0
=> tcpm dev usb-typec@22
dev: 0 @ usb-typec@22
=> tcpm info
Orientation: normal
PD Revision: rev3
Power Role:  sink
Data Role:   device
Voltage: 12.000 V
Current:  2.500 A
=>

Thanks again,
Soeren


Re: [PATCH 00/16] LoongArch initial support

2024-06-04 Thread Tom Rini
On Tue, Jun 04, 2024 at 11:50:20AM +0100, Jiaxun Yang wrote:
> 
> 
> 在2024年5月23日五月 下午4:43,Tom Rini写道:
> > On Thu, May 23, 2024 at 04:38:52PM +0100, Jiaxun Yang wrote:
> >> 
> >> 
> >> 在2024年5月23日五月 下午4:25,Tom Rini写道:
> >> > On Wed, May 22, 2024 at 04:34:43PM +0100, Jiaxun Yang wrote:
> >> >
> >> >> Hi all,
> >> >> 
> >> >> Sorry for flooding the mailing list recently, yet another huge RFC 
> >> >> series ahead.
> >> >> 
> >> >> So after working on MIPS, arm64be and Xtensa I'm now on LoongArch, as 
> >> >> suggested
> >> >> by Heinrich.
> >> >
> >> > My big feedback here, and it applies to all of your other series as
> >> > well, is to please update CI to make use of and test this. On the Docker
> >> > side, update tools/docker/Dockerfile as needed. For Azure, you can tell
> >> > it to use a different image and then follow the documentation on
> >> > https://docs.u-boot.org/en/latest/develop/ci_testing.html and for GitLab
> >> > you can at least use their "linter" to make sure that your additions
> >> > have the correct syntax. Thanks.
> >> 
> >> Hi Tom,
> >> 
> >> Thanks for the feedback, I thought CI is for custodians only :-)
> >> 
> >> Do you mean I should include azure/gitlab pipeline file to create
> >> pipeline for those new qemu targets?
> >
> > Yes, just like the rest of the QEMU targets.
> 
> Hi Tom,
> 
> I've got CI working on azure-pipeline for my arm64be, xtensa and LoongArch
> work.
> 
> What is the best way to submit all these changes? I think I can send patches 
> to
> update Dockerfile and CI hooks first, then after new docker image being built
> I'll combine CI related changes into these series and refresh all those 
> series.
> 
> Will it work for you?

Yes, please do a series that updates the Dockerfile and CI yaml files
(do your best to update .gitlab-ci.yml as well, I'll fix it up if
needed). Then say the other series depend on that previous one being
applied. You can post an RFC patch or what have you that just changes to
pointing at your test images instead and so long as it's a stand alone
patch it's easy to drop. Thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 15/25] mbedtls: add X509 cert parser porting layer

2024-06-04 Thread Ilias Apalodimas
On Tue, 4 Jun 2024 at 19:05, Raymond Mao  wrote:
>
> Hi Ilias,
>
> On Fri, 31 May 2024 at 07:42, Ilias Apalodimas  
> wrote:
>>
>> On Tue, 28 May 2024 at 17:15, Raymond Mao  wrote:
>> >
>> > Add porting layer for X509 cert parser on top of MbedTLS X509
>> > library.
>> >
>> > Signed-off-by: Raymond Mao 
>> > ---
>> > Changes in v2
>> > - Move the porting layer to MbedTLS dir.
>> > Changes in v3
>> > - None.
>> >
>> >  lib/mbedtls/Makefile   |   1 +
>> >  lib/mbedtls/x509_cert_parser.c | 497 +
>> >  2 files changed, 498 insertions(+)
>> >  create mode 100644 lib/mbedtls/x509_cert_parser.c
>> >
>
> [snip]
>>
>> > diff --git a/lib/mbedtls/x509_cert_parser.c 
>> > b/lib/mbedtls/x509_cert_parser.c
>> > new file mode 100644
>> > index 000..b0867d31047
>> > --- /dev/null
>> > +++ b/lib/mbedtls/x509_cert_parser.c
>>
> [snip]
>>
>> > +static int x509_set_cert_flags(struct x509_certificate *cert)
>> > +{
>> > +   struct public_key_signature *sig = cert->sig;
>> > +
>> > +   if (!sig || !cert->pub) {
>> > +   pr_err("Signature or public key is not initialized\n");
>> > +   return -ENOPKG;
>> > +   }
>> > +
>> > +   if (!cert->pub->pkey_algo)
>> > +   cert->unsupported_key = true;
>> > +
>> > +   if (!sig->pkey_algo)
>> > +   cert->unsupported_sig = true;
>> > +
>> > +   if (!sig->hash_algo)
>> > +   cert->unsupported_sig = true;
>> > +
>> > +   /* TODO: is_hash_blacklisted()? */
>>
>> Is this supported by our current implementation?
>>
> This is not supported currently either. I just copied the TODO mark
> from legacy lib.
>
> [snip]
>>
>> > +   }
>> > +   goto out;
>> > +   }
>> > +
>> > +   pr_devel("Cert Self-signature verified");
>> > +   cert->self_signed = true;
>> > +
>> > +out:
>> > +   return ret;
>> > +
>> > +not_self_signed:
>> > +   return 0;
>> > +}
>>
>> the whole function looks like a copy of lib/crypto/x509_public_key.c.
>> Can you move all the c/p ones to a common file that the existing and
>> mbedTLS implementations can use?
>>
> Per a previous discussion with Tom, eventually we tend to keep only one
> crypto lib, that is the reason I prefer to copy/optimize a few existing
> functions into MbedTLS implementation instead of creating another
> common file.

Regardless of the implementation, the common functions should reside
in a common file which will be used regardless of mbedTLS or the
existing stack.
We do not want to fix bugs twice

Regards
/Ilias

>
> Regards,
> Raymond


Re: [PATCH v3 21/25] mbedtls: add RSA helper layer on MbedTLS

2024-06-04 Thread Raymond Mao
Hi Ilias,

On Fri, 31 May 2024 at 06:00, Ilias Apalodimas 
wrote:

> Hi Raymond,
>
> [...]
>
> > +
> > +/**
> > + * rsa_parse_pub_key() - decodes the BER encoded buffer and stores in
> the
> > + *   provided struct rsa_key, pointers to the raw
> key as is,
> > + *   so that the caller can copy it or MPI parse
> it, etc.
> > + *
> > + * @rsa_key:   struct rsa_key key representation
> > + * @key:   key in BER format
> > + * @key_len:   length of key
> > + *
> > + * Return: 0 on success or error code in case of error
> > + */
> > +int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key,
> > + unsigned int key_len)
> > +{
> > +   int ret = 0;
> > +   mbedtls_pk_context pk;
> > +   mbedtls_rsa_context *rsa;
> > +
> > +   mbedtls_pk_init(&pk);
> > +
> > +   ret = mbedtls_pk_parse_public_key(&pk, (const unsigned char
> *)key,
> > + key_len);
> > +   if (ret) {
> > +   pr_err("Failed to parse public key, ret:-0x%04x\n",
> > +  (unsigned int)-ret);
> > +   ret = -EINVAL;
> > +   goto clean_pubkey;
> > +   }
> > +
> > +   /* Ensure that it is a RSA key */
> > +   if (mbedtls_pk_get_type(&pk) != MBEDTLS_PK_RSA) {
> > +   pr_err("Non-RSA keys are not supported\n");
> > +   ret = -EKEYREJECTED;
> > +   goto clean_pubkey;
> > +   }
> > +
> > +   /* Get RSA key context */
> > +   rsa = mbedtls_pk_rsa(pk);
> > +   if (!rsa) {
> > +   pr_err("Failed to get RSA key context, ret:-0x%04x\n",
> > +  (unsigned int)-ret);
>
> Why do we need to cast the result here? Just print ret
> Also, would it make sense to create a mapping between mbedTLS API
> errors and internal error codes?
> instead of doing ret -EINVAL etc  we could have something like
> ret = mbedtls_to_errno(ret);
>
> I can remove all the cast.
But it is not able to 1/1 map the mbedtls errors to general ones via a
helper
function since the error code should reflect the current scenario of the
operation.
Even with the same MbedTLS API and same error code, the purpose of
caller is different, it is hard to get them mapped in a common
interpretation.

[...]

Regards,
Raymond


[PATCH v2 5/5] MAINTAINERS: add TCPM section

2024-06-04 Thread Sebastian Reichel
Add new section for USB TypeC Port Manager (TCPM) support, which
is needed to figure out cable orientation of USB-C plus and to do
USB PD communication.

Signed-off-by: Sebastian Reichel 
---
 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index f8afd7d51e2e..dc9e7112aebf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1679,6 +1679,14 @@ F:   common/usb_kbd.c
 F: common/usb_storage.c
 F: include/usb.h
 
+USB TCPM
+M: Sebastian Reichel 
+S: Maintained
+F: cmd/tcpm.c
+F: drivers/usb/tcpm/
+F: include/usb/pd.h
+F: include/usb/tcpm.h
+
 USB xHCI
 M: Bin Meng 
 S: Maintained
-- 
2.43.0



[PATCH v2 1/5] usb: tcpm: add core framework

2024-06-04 Thread Sebastian Reichel
This adds TCPM framework in preparation for fusb302 support, which can
handle USB power delivery messages. This is needed to solve issues with
devices, that are running from a USB-C port supporting USB-PD, but not
having a battery.

Such a device currently boots to the kernel without interacting with
the power-supply at all. If there are no USB-PD message replies within
5 seconds, the power-supply assumes the peripheral is not capable of
USB-PD. It usually takes more than 5 seconds for the system to reach
the kernel and probe the I2C based fusb302 chip driver. Thus the
system always runs into this state. The power-supply's solution to
fix this error state is a hard reset, which involves removing the
power from VBUS. Boards without a battery (or huge capacitors) will
reset at this point resulting in a boot loop.

This imports the TCPM framework from the kernel. The porting has
originally been done by Rockchip using hardware timers and the Linux
kernel's TCPM code from some years ago.

I had a look at upgrading to the latest TCPM kernel code, but that
beast became a lot more complex due to adding more USB-C features.
I believe these features are not needed in U-Boot and with multiple
kthreads and hrtimers being involved it is non-trivial to port them.
Instead I worked on stripping down features from the Rockchip port
to an even more basic level. Also the TCPM code has been reworked
to avoid complete use of any timers (Rockchip used SoC specific
hardware timers + IRQ to implement delayed work mechanism). Instead
the delayed state changes are handled directly from the poll loop.

Note, that (in contrast to the original Rockchip port) the state
machine has the same hard reset quirk, that the kernel has - i.e.
it avoids disabling the CC pin resistors for devices that are not
self-powered. Without that quirk, the Radxa Rock 5B will not just
end up doing a machine reset when a hard reset is triggered, but will
not even recover, because the CPU will loose power and the FUSB302
will keep this state because of leak voltage arriving through the RX
serial pin (assuming a serial adapter is connected).

This also includes a 'tcpm' command, which can be used to get
information about the current state and the negotiated voltage
and current.

Co-developed-by: Wang Jie 
Signed-off-by: Wang Jie 
Signed-off-by: Sebastian Reichel 
---
 Makefile |1 +
 cmd/Kconfig  |7 +
 cmd/Makefile |1 +
 cmd/tcpm.c   |  142 ++
 drivers/usb/Kconfig  |2 +
 drivers/usb/tcpm/Kconfig |8 +
 drivers/usb/tcpm/Makefile|3 +
 drivers/usb/tcpm/tcpm-internal.h |  174 +++
 drivers/usb/tcpm/tcpm-uclass.c   |  102 ++
 drivers/usb/tcpm/tcpm.c  | 2251 ++
 include/dm/uclass-id.h   |1 +
 include/usb/pd.h |  516 +++
 include/usb/tcpm.h   |   99 ++
 13 files changed, 3307 insertions(+)
 create mode 100644 cmd/tcpm.c
 create mode 100644 drivers/usb/tcpm/Kconfig
 create mode 100644 drivers/usb/tcpm/Makefile
 create mode 100644 drivers/usb/tcpm/tcpm-internal.h
 create mode 100644 drivers/usb/tcpm/tcpm-uclass.c
 create mode 100644 drivers/usb/tcpm/tcpm.c
 create mode 100644 include/usb/pd.h
 create mode 100644 include/usb/tcpm.h

diff --git a/Makefile b/Makefile
index f8206b2e30a5..8f556b8249af 100644
--- a/Makefile
+++ b/Makefile
@@ -879,6 +879,7 @@ libs-y += drivers/usb/musb/
 libs-y += drivers/usb/musb-new/
 libs-y += drivers/usb/isp1760/
 libs-y += drivers/usb/phy/
+libs-y += drivers/usb/tcpm/
 libs-y += drivers/usb/ulpi/
 ifdef CONFIG_POST
 libs-y += post/
diff --git a/cmd/Kconfig b/cmd/Kconfig
index b026439c7731..a27da5467842 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -221,6 +221,13 @@ config CMD_REGINFO
help
  Register dump
 
+config CMD_TCPM
+   bool "tcpm"
+   depends on TYPEC_TCPM
+   help
+ Show voltage and current negotiated via USB PD as well as the
+ current state of the Type C Port Manager (TCPM) state machine.
+
 config CMD_TLV_EEPROM
bool "tlv_eeprom"
depends on I2C_EEPROM
diff --git a/cmd/Makefile b/cmd/Makefile
index 87133cc27a8a..bd0b23ef1013 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -172,6 +172,7 @@ obj-$(CONFIG_CMD_SMBIOS) += smbios.o
 obj-$(CONFIG_CMD_SMC) += smccc.o
 obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o
 obj-$(CONFIG_CMD_STACKPROTECTOR_TEST) += stackprot_test.o
+obj-$(CONFIG_CMD_TCPM) += tcpm.o
 obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
 obj-$(CONFIG_CMD_TERMINAL) += terminal.o
 obj-$(CONFIG_CMD_TIME) += time.o
diff --git a/cmd/tcpm.c b/cmd/tcpm.c
new file mode 100644
index ..37cc3ed6a3b4
--- /dev/null
+++ b/cmd/tcpm.c
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2024 Collabora
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define LIMIT_DEV  32
+#define LIMIT_PARENT   20
+
+static struct udevi

[PATCH v2 2/5] usb: tcpm: fusb302: add driver

2024-06-04 Thread Sebastian Reichel
Now that the TCPM framework exists we can introduce fusb302
driver using it. This chip is a very common USB-C controller
chip with PD support, which can be found in the Radxa Rock 5B
among many other boards. Apart from Power Delivery, it also
handles detection of the cable orientation. That can be used
to control a mux for connecting the right USB3 lane pair to
the USB3 controller.

The driver is originally from the Linux kernel, but has been
adapted to the requirements of U-Boot and its TCPM framework.

Co-developed-by: Wang Jie 
Signed-off-by: Wang Jie 
Signed-off-by: Sebastian Reichel 
---
 drivers/usb/tcpm/Kconfig   |8 +
 drivers/usb/tcpm/Makefile  |1 +
 drivers/usb/tcpm/fusb302.c | 1333 
 drivers/usb/tcpm/fusb302_reg.h |  177 +
 4 files changed, 1519 insertions(+)
 create mode 100644 drivers/usb/tcpm/fusb302.c
 create mode 100644 drivers/usb/tcpm/fusb302_reg.h

diff --git a/drivers/usb/tcpm/Kconfig b/drivers/usb/tcpm/Kconfig
index 55bf8e202b90..9be4b496e82f 100644
--- a/drivers/usb/tcpm/Kconfig
+++ b/drivers/usb/tcpm/Kconfig
@@ -6,3 +6,11 @@ config TYPEC_TCPM
help
  The Type-C Port Controller Manager provides a USB PD and USB Type-C
  state machine for use with Type-C Port Controllers.
+
+config TYPEC_FUSB302
+   tristate "Fairchild FUSB302 Type-C chip driver"
+   depends on DM && DM_I2C && TYPEC_TCPM
+   help
+ The Fairchild FUSB302 Type-C chip driver that works with
+ Type-C Port Controller Manager to provide USB PD and USB
+ Type-C functionalities.
diff --git a/drivers/usb/tcpm/Makefile b/drivers/usb/tcpm/Makefile
index a0f76436f3fd..668d33155bf1 100644
--- a/drivers/usb/tcpm/Makefile
+++ b/drivers/usb/tcpm/Makefile
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_TYPEC_TCPM) += tcpm.o tcpm-uclass.o
+obj-$(CONFIG_TYPEC_FUSB302) += fusb302.o
diff --git a/drivers/usb/tcpm/fusb302.c b/drivers/usb/tcpm/fusb302.c
new file mode 100644
index ..0f84a94f9c70
--- /dev/null
+++ b/drivers/usb/tcpm/fusb302.c
@@ -0,0 +1,1333 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2016-2017 Google, Inc
+ *
+ * Fairchild FUSB302 Type-C Chip Driver
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "fusb302_reg.h"
+
+enum toggling_mode {
+   TOGGLING_MODE_OFF,
+   TOGGLING_MODE_DRP,
+   TOGGLING_MODE_SNK,
+   TOGGLING_MODE_SRC,
+};
+
+enum src_current_status {
+   SRC_CURRENT_DEFAULT,
+   SRC_CURRENT_MEDIUM,
+   SRC_CURRENT_HIGH,
+};
+
+static const u8 ra_mda_value[] = {
+   [SRC_CURRENT_DEFAULT] = 4,  /* 210mV */
+   [SRC_CURRENT_MEDIUM] = 9,   /* 420mV */
+   [SRC_CURRENT_HIGH] = 18,/* 798mV */
+};
+
+static const u8 rd_mda_value[] = {
+   [SRC_CURRENT_DEFAULT] = 38, /* 1638mV */
+   [SRC_CURRENT_MEDIUM] = 38,  /* 1638mV */
+   [SRC_CURRENT_HIGH] = 61,/* 2604mV */
+};
+
+struct fusb302_chip {
+   enum toggling_mode toggling_mode;
+   enum src_current_status src_current_status;
+   bool intr_togdone;
+   bool intr_bc_lvl;
+   bool intr_comp_chng;
+
+   /* port status */
+   bool vconn_on;
+   bool vbus_present;
+   enum typec_cc_polarity cc_polarity;
+   enum typec_cc_status cc1;
+   enum typec_cc_status cc2;
+};
+
+static int fusb302_i2c_write(struct udevice *dev, u8 address, u8 data)
+{
+   int ret = 0;
+
+   ret = dm_i2c_write(dev, address, &data, 1);
+   if (ret)
+   dev_err(dev, "cannot write 0x%02x to 0x%02x, ret=%d\n",
+   data, address, ret);
+
+   return ret;
+}
+
+static int fusb302_i2c_block_write(struct udevice *dev, u8 address,
+  u8 length, const u8 *data)
+{
+   int ret = 0;
+
+   if (length <= 0)
+   return ret;
+
+   ret = dm_i2c_write(dev, address, data, length);
+   if (ret)
+   dev_err(dev, "cannot block write 0x%02x, len=%d, ret=%d\n",
+   address, length, ret);
+
+   return ret;
+}
+
+static int fusb302_i2c_read(struct udevice *dev, u8 address, u8 *data)
+{
+   int ret = 0, retries;
+
+   for (retries = 0; retries < 3; retries++) {
+   ret = dm_i2c_read(dev, address, data, 1);
+   if (ret == 0)
+   return ret;
+   dev_err(dev, "cannot read %02x, ret=%d\n", address, ret);
+   }
+
+   return ret;
+}
+
+static int fusb302_i2c_block_read(struct udevice *dev, u8 address,
+ u8 length, u8 *data)
+{
+   int ret = 0;
+
+   if (length <= 0)
+   return ret;
+
+   ret = dm_i2c_read(dev, address, data, length);
+   if (ret)
+   dev_err(dev, "cannot block read 0x%02x, len=%d, ret=%d\n",
+   address, length, ret);
+   return ret;
+}
+
+static int fusb302_i2c_mask_write(struct udevice *d

[PATCH v2 4/5] board: rock5b-rk3588: enable USB-C in operating system

2024-06-04 Thread Sebastian Reichel
Since older U-Boot releases do not negotiate USB PD, the kernel
DT may not enable the USB-C controller by default to avoid a
regression. The plan is to upstream it with 'status = "fail";'
instead. U-Boot should then mark it as 'status = "okay";' if
it negotiated USB PD.

Signed-off-by: Sebastian Reichel 
---
 board/radxa/rock5b-rk3588/rock5b-rk3588.c | 11 +++
 configs/rock5b-rk3588_defconfig   |  1 +
 2 files changed, 12 insertions(+)

diff --git a/board/radxa/rock5b-rk3588/rock5b-rk3588.c 
b/board/radxa/rock5b-rk3588/rock5b-rk3588.c
index 75856ccb1288..d688ef20b79c 100644
--- a/board/radxa/rock5b-rk3588/rock5b-rk3588.c
+++ b/board/radxa/rock5b-rk3588/rock5b-rk3588.c
@@ -3,6 +3,8 @@
  * Copyright (c) 2023-2024 Collabora Ltd.
  */
 
+#include 
+#include 
 #include 
 
 #ifdef CONFIG_MISC_INIT_R
@@ -20,3 +22,12 @@ int misc_init_r(void)
return 0;
 }
 #endif
+
+#ifdef CONFIG_OF_BOARD_SETUP
+int ft_board_setup(void *blob, struct bd_info *bd)
+{
+   if (IS_ENABLED(CONFIG_MISC_INIT_R))
+   fdt_status_okay_by_compatible(blob, "fcs,fusb302");
+   return 0;
+}
+#endif
diff --git a/configs/rock5b-rk3588_defconfig b/configs/rock5b-rk3588_defconfig
index e368b0439d1d..f056728d338b 100644
--- a/configs/rock5b-rk3588_defconfig
+++ b/configs/rock5b-rk3588_defconfig
@@ -23,6 +23,7 @@ CONFIG_FIT_VERBOSE=y
 CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
+CONFIG_OF_BOARD_SETUP=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3588-rock-5b.dtb"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
-- 
2.43.0



[PATCH v2 3/5] board: rock5b-rk3588: add USB-C controller support

2024-06-04 Thread Sebastian Reichel
Enable support for the fusb302 USB Type-C controller.

This will do early USB PD (power deliver) negotiation, which must happen
within 5 seconds after the USB-C connector has plugged in according to
the specification. It takes almost 5 seconds to go through the bootchain
on Rock 5B and jump to the operating system. When the Linux initializes
the fusb302 usually 20-30 seconds have gone since the device has been
plugged, which is far too late. The USB PD power source reacts with a
hard reset, which disables VBUS for some time. This is not a problem for
a battery driven device, but Rock 5B will loose its power-supply and
reset. By initializing PD in U-Boot, this can be avoided.

The DT node can be sourced from the Linux kernel DT in the future,
but to get things going it makes sense to add it in the U-Boot
specific file for now. Because of the reset issue it is important
to get support in U-Boot first.

Signed-off-by: Sebastian Reichel 
---
 arch/arm/dts/rk3588-rock-5b-u-boot.dtsi   | 28 +++
 board/radxa/rock5b-rk3588/Makefile|  6 +
 board/radxa/rock5b-rk3588/rock5b-rk3588.c | 22 ++
 configs/rock5b-rk3588_defconfig   |  4 
 4 files changed, 60 insertions(+)
 create mode 100644 board/radxa/rock5b-rk3588/Makefile
 create mode 100644 board/radxa/rock5b-rk3588/rock5b-rk3588.c

diff --git a/arch/arm/dts/rk3588-rock-5b-u-boot.dtsi 
b/arch/arm/dts/rk3588-rock-5b-u-boot.dtsi
index 8e318e624a85..e93795359ece 100644
--- a/arch/arm/dts/rk3588-rock-5b-u-boot.dtsi
+++ b/arch/arm/dts/rk3588-rock-5b-u-boot.dtsi
@@ -3,6 +3,7 @@
  * Copyright (c) 2023 Collabora Ltd.
  */
 
+#include 
 #include "rk3588-u-boot.dtsi"
 
 &fspim2_pins {
@@ -65,3 +66,30 @@
dr_mode = "host";
status = "okay";
 };
+
+&i2c4 {
+   pinctrl-names = "default";
+   pinctrl-0 = <&i2c4m1_xfer>;
+   status = "okay";
+
+   usbc0: usb-typec@22 {
+   compatible = "fcs,fusb302";
+   reg = <0x22>;
+   interrupt-parent = <&gpio3>;
+   interrupts = ;
+   pinctrl-names = "default";
+   status = "okay";
+
+   usb_con: connector {
+   compatible = "usb-c-connector";
+   label = "USB-C";
+   data-role = "dual";
+   power-role = "sink";
+   try-power-role = "sink";
+   op-sink-microwatt = <100>;
+   sink-pdos =
+   ,
+   ;
+   };
+   };
+};
diff --git a/board/radxa/rock5b-rk3588/Makefile 
b/board/radxa/rock5b-rk3588/Makefile
new file mode 100644
index ..95d813596da4
--- /dev/null
+++ b/board/radxa/rock5b-rk3588/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2022 Collabora Ltd.
+#
+
+obj-y += rock5b-rk3588.o
diff --git a/board/radxa/rock5b-rk3588/rock5b-rk3588.c 
b/board/radxa/rock5b-rk3588/rock5b-rk3588.c
new file mode 100644
index ..75856ccb1288
--- /dev/null
+++ b/board/radxa/rock5b-rk3588/rock5b-rk3588.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2023-2024 Collabora Ltd.
+ */
+
+#include 
+
+#ifdef CONFIG_MISC_INIT_R
+int misc_init_r(void)
+{
+   struct udevice *dev;
+   int ret;
+
+   ret = tcpm_get("usb-typec@22", &dev);
+   if (ret) {
+   printf("Failed to probe Type-C controller\n");
+   return 0;
+   }
+
+   return 0;
+}
+#endif
diff --git a/configs/rock5b-rk3588_defconfig b/configs/rock5b-rk3588_defconfig
index fc118cea7bae..e368b0439d1d 100644
--- a/configs/rock5b-rk3588_defconfig
+++ b/configs/rock5b-rk3588_defconfig
@@ -102,3 +102,7 @@ CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_USB_FUNCTION_ROCKUSB=y
 CONFIG_ERRNO_STR=y
+CONFIG_TYPEC_TCPM=y
+CONFIG_TYPEC_FUSB302=y
+CONFIG_MISC_INIT_R=y
+CONFIG_CMD_TCPM=y
-- 
2.43.0



[PATCH v2 0/5] FUSB302 USB-C controller support

2024-06-04 Thread Sebastian Reichel
Hi,

On ROCK 5B power is usually supplied via it's USB-C port. This port has the
data lines connected to RK3588, VBUS connected to the input regulator and
CC pins connected to FUSB302. FUSB302 is a USB-C controller, which can be
accessed via I2C from RK3588. The USB-C controller is needed to figure out
the USB-C cable orientation, but also to do USB PD communication. Thus it
would be great to enable support for it in the operating system.

But the USB-PD specification requires, that a device reacts to USB-PD messages
send by the power-supply within around 5 seconds. If that does not happen the
power-supply assumes, that the device does not support USB-PD. If a device
later starts sending USB-PD messages it is considered an error, which is solved
by doing a hard reset. A USB-PD hard reset means, that all supply voltages are
removed for a short period of time. For boards, which are solely powered
through their USB-C port, like the Radxa Rock 5B, this results in an machine
reset. This is currently worked around by not describing the FUSB302 in the
kernel DT, so nothing will ever speak USB-PD on the Rock 5B. This means

1. the USB-C port cannot be used at all
2. the board will be running via fallback supply, which provides limited
   power capabilities

In order to avoid the hard reset, this adds FUSB302 support to U-Boot, so
that we react to the power-supply's queries in time. The code, which is
originally from the Linux kernel, consists of two parts:

1. the tcpm state machine, which implements the Type C port manager state
   machine as described in the USB PD specification
2. the fusb302 driver, which knows about specific registers

Especially the first part has been heavily modified compared to the
kernel, which makes use of multiple delayed works and threads. For this
I used a priorly ported version from Rockchip, removed their hacks and
any states not necessary in U-Boot (e.g. audio accessory support).

Changes since PATCHv1:
 * tcpm: split uclass specific code to tcpm-uclass
 * tcpm_print_info: move printing part to cmd/tcpm.c
 * tcpm_print_info: report more information
   - PD revision
   - Cable orientation
   - Power role
   - Data role
   - Print TCPM state based on connection status
 * tcpm: use "struct udevice *dev" instead of "struct tcpm_port *port"
   as function argument in most places and drop dev from the tcpm_port
   struct
 * tcpm: avoid useless kzalloc + copy + free for incoming events
 * tcpm: use dev_get_uclass_plat() for tcpm_port
 * tcpm: run tcpm_port_init() and tcpm_poll_event() from UCLASS post_probe()
 * tcpm/fusb302: get rid of tcpc_dev by using dm_tcpm_ops() for the
   function pointers and introducing get_connector_node() for the
   ofnode
 * fusb302: use "struct udevice *dev" instead of "struct fusb302_chip *chip"
   as function argument and drop dev from the fusb302_chip struct
 * fusb302: drop multiple unused members from fusb302_chip
 * fusb302: directly use udelay instead of usleep_range define
 * fusb302: use fusb302_ prefix for all functions. Afterwards tcpm_ prefix
   is only used for the tcpm code itself
 * fusb302: move fusb302_poll_event() to avoid forward defintion
 * fusb302: drop probe function
 * fusb302: drop unused LOG_BUFFER defines
 * roughly 20% of all lines of the series changed between v1 and v2, so
   I did not collect the Tested-by from Soeren Moch

Greetings,

-- Sebastian

Sebastian Reichel (5):
  usb: tcpm: add core framework
  usb: tcpm: fusb302: add driver
  board: rock5b-rk3588: add USB-C controller support
  board: rock5b-rk3588: enable USB-C in operating system
  MAINTAINERS: add TCPM section

 MAINTAINERS   |8 +
 Makefile  |1 +
 arch/arm/dts/rk3588-rock-5b-u-boot.dtsi   |   28 +
 board/radxa/rock5b-rk3588/Makefile|6 +
 board/radxa/rock5b-rk3588/rock5b-rk3588.c |   33 +
 cmd/Kconfig   |7 +
 cmd/Makefile  |1 +
 cmd/tcpm.c|  142 ++
 configs/rock5b-rk3588_defconfig   |5 +
 drivers/usb/Kconfig   |2 +
 drivers/usb/tcpm/Kconfig  |   16 +
 drivers/usb/tcpm/Makefile |4 +
 drivers/usb/tcpm/fusb302.c| 1333 
 drivers/usb/tcpm/fusb302_reg.h|  177 ++
 drivers/usb/tcpm/tcpm-internal.h  |  174 ++
 drivers/usb/tcpm/tcpm-uclass.c|  102 +
 drivers/usb/tcpm/tcpm.c   | 2251 +
 include/dm/uclass-id.h|1 +
 include/usb/pd.h  |  516 +
 include/usb/tcpm.h|   99 +
 20 files changed, 4906 insertions(+)
 create mode 100644 board/radxa/rock5b-rk3588/Makefile
 create mode 100644 board/radxa/rock5b-rk3588/rock5b-rk3588.c
 create mode 100644 cmd/tcpm.c
 create mode 100644 drivers/usb/tcpm/Kconfig
 create mode 100644 drivers/usb/tcpm/Makefile
 create mode 100644 dri

[PATCH 1/1] tools: patman: fix `pip install` with Python 3.12

2024-06-04 Thread Brandon Maier
Installing patman with `cd ./tools/patman && pip install -e .` fails
with the error below.

As described in the error output, the license line is not allowed to be
only defined in the setup.py.

> $ cd ./tools/patman && pip install -e .
> Obtaining file:///.../u-boot/tools/patman
>   Installing build dependencies ... done
>   Checking if build backend supports build_editable ... done
>   Getting requirements to build editable ... error
>   error: subprocess-exited-with-error
>
>   × Getting requirements to build editable did not run successfully.
>   │ exit code: 1
>   ╰─> [61 lines of output]
>   
> /tmp/pip-build-env-mqjvnmz8/overlay/lib/python3.12/site-packages/setuptools/config/_apply_pyprojecttoml.py:76:
>   _MissingDynamic: `license` defined outside of `pyproject.toml` is 
> ignored.
>   !!
>
>   
> 
>   The following seems to be defined outside of `pyproject.toml`:
>
>   `license = 'GPL-2.0+'`
>
>   According to the spec (see the link below), however, setuptools CANNOT
>   consider this value unless `license` is listed as `dynamic`.
>
>   
> https://packaging.python.org/en/latest/specifications/pyproject-toml/#declaring-project-metadata-the-project-table
>
>   To prevent this problem, you can list `license` under `dynamic` or 
> alternatively
>   remove the `[project]` table from your file and rely entirely on other 
> means of
>   configuration.
>   
> 
>
>   !!

Signed-off-by: Brandon Maier 
CC: Simon Glass 
---
 tools/patman/pyproject.toml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/patman/pyproject.toml b/tools/patman/pyproject.toml
index fcefcf66960..9e6079cb57e 100644
--- a/tools/patman/pyproject.toml
+++ b/tools/patman/pyproject.toml
@@ -17,6 +17,7 @@ classifiers = [
 "License :: OSI Approved :: GNU General Public License v2 or later 
(GPLv2+)",
 "Operating System :: OS Independent",
 ]
+dynamic = ["license"]
 
 [project.urls]
 "Homepage" = "https://docs.u-boot.org/en/latest/develop/patman.html";
-- 
2.45.1



Re: [PATCH v3 19/25] mbedtls: add MSCode parser porting layer

2024-06-04 Thread Raymond Mao
Hi Ilias,

On Fri, 31 May 2024 at 06:03, Ilias Apalodimas 
wrote:

> On Tue, 28 May 2024 at 17:17, Raymond Mao  wrote:
> >
> > Add porting layer for MSCode on top of MbedTLS ASN1 library.
> >
> > Signed-off-by: Raymond Mao 
> > ---
> > Changes in v2
> > - Move the porting layer to MbedTLS dir.
> > Changes in v3
> > - None.
> >
> >  lib/mbedtls/Makefile|   1 +
> >  lib/mbedtls/mscode_parser.c | 111 
> >  2 files changed, 112 insertions(+)
> >  create mode 100644 lib/mbedtls/mscode_parser.c
> >
>
> [snip]

> > diff --git a/lib/mbedtls/mscode_parser.c b/lib/mbedtls/mscode_parser.c
> > new file mode 100644
> > index 000..34715f3a137
> > --- /dev/null
> > +++ b/lib/mbedtls/mscode_parser.c
>
> [snip]

>
> > + *
> > + */
> > +int mscode_parse(void *_ctx, const void *content_data, size_t data_len,
> > +size_t asn1hdrlen)
> > +{
> > +   struct pefile_context *ctx = _ctx;
> > +   unsigned char *p = (unsigned char *)content_data;
> > +   unsigned char *end = (unsigned char *)content_data + data_len;
>
> Why are you dropping const here?
>
> mbedtls_asn1_get_tag requires the args without const.

Regards,
Raymond


[PATCH 3/3] tools: patman: fix deprecated Python ConfigParser methods

2024-06-04 Thread Brandon Maier
The method `ConfigParser.readfp()` is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with
`ConfigParser.read_file()`.

[1] 
https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp

Signed-off-by: Brandon Maier 
CC: Simon Glass 
---
 tools/patman/settings.py | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/patman/settings.py b/tools/patman/settings.py
index 636983e32da..68c93e313b3 100644
--- a/tools/patman/settings.py
+++ b/tools/patman/settings.py
@@ -59,25 +59,25 @@ class _ProjectConfigParser(ConfigParser.ConfigParser):
 
 # Check to make sure that bogus project gets general alias.
 >>> config = _ProjectConfigParser("zzz")
->>> config.readfp(StringIO(sample_config))
+>>> config.read_file(StringIO(sample_config))
 >>> str(config.get("alias", "enemies"))
 'Evil '
 
 # Check to make sure that alias gets overridden by project.
 >>> config = _ProjectConfigParser("sm")
->>> config.readfp(StringIO(sample_config))
+>>> config.read_file(StringIO(sample_config))
 >>> str(config.get("alias", "enemies"))
 'Green G. '
 
 # Check to make sure that settings get merged with project.
 >>> config = _ProjectConfigParser("linux")
->>> config.readfp(StringIO(sample_config))
+>>> config.read_file(StringIO(sample_config))
 >>> sorted((str(a), str(b)) for (a, b) in config.items("settings"))
 [('am_hero', 'True'), ('check_patch_use_tree', 'True'), ('process_tags', 
'False')]
 
 # Check to make sure that settings works with unknown project.
 >>> config = _ProjectConfigParser("unknown")
->>> config.readfp(StringIO(sample_config))
+>>> config.read_file(StringIO(sample_config))
 >>> sorted((str(a), str(b)) for (a, b) in config.items("settings"))
 [('am_hero', 'True')]
 """
-- 
2.45.1



[PATCH 2/3] tools: binman: fix deprecated Python ConfigParser methods

2024-06-04 Thread Brandon Maier
The method `ConfigParser.readfp()` is marked deprecated[1].

In Python 3.12 this method have been removed, so replace it with
`ConfigParser.read_file()`.

[1] 
https://docs.python.org/3.11/library/configparser.html#configparser.ConfigParser.readfp

Signed-off-by: Brandon Maier 
CC: Simon Glass 
---
 tools/buildman/bsettings.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/buildman/bsettings.py b/tools/buildman/bsettings.py
index e225ac2ca0f..aea724fc559 100644
--- a/tools/buildman/bsettings.py
+++ b/tools/buildman/bsettings.py
@@ -29,7 +29,7 @@ def setup(fname=''):
 settings.read(config_fname)
 
 def add_file(data):
-settings.readfp(io.StringIO(data))
+settings.read_file(io.StringIO(data))
 
 def get_items(section):
 """Get the items from a section of the config.
-- 
2.45.1



[PATCH 1/3] tools: binman: fix deprecated Python unittest methods

2024-06-04 Thread Brandon Maier
The methods `unittest.assertEquals()` and
`unittest.assertRegexpMatches()` are marked deprecated[1].

In Python 3.12 these aliases have been removed, so do a sed to replace
them with their new names.

[1] https://docs.python.org/3.11/library/unittest.html#deprecated-aliases

Signed-off-by: Brandon Maier 
CC: Simon Glass 
CC: Alper Nebi Yasak 
---
 tools/binman/entry_test.py  |  6 +--
 tools/binman/fdt_test.py| 48 
 tools/binman/ftest.py   | 42 ++---
 tools/buildman/func_test.py | 74 ++---
 tools/buildman/test.py  |  2 +-
 5 files changed, 86 insertions(+), 86 deletions(-)

diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py
index ac6582cf86a..40d74d401a2 100644
--- a/tools/binman/entry_test.py
+++ b/tools/binman/entry_test.py
@@ -103,7 +103,7 @@ class TestEntry(unittest.TestCase):
 ent = entry.Entry.Create(None, self.GetNode(), 'missing',
  missing_etype=True)
 self.assertTrue(isinstance(ent, Entry_blob))
-self.assertEquals('missing', ent.etype)
+self.assertEqual('missing', ent.etype)
 
 def testDecompressData(self):
 """Test the DecompressData() method of the base class"""
@@ -111,8 +111,8 @@ class TestEntry(unittest.TestCase):
 base.compress = 'lz4'
 bintools = {}
 base.comp_bintool = base.AddBintool(bintools, '_testing')
-self.assertEquals(tools.get_bytes(0, 1024), base.CompressData(b'abc'))
-self.assertEquals(tools.get_bytes(0, 1024), 
base.DecompressData(b'abc'))
+self.assertEqual(tools.get_bytes(0, 1024), base.CompressData(b'abc'))
+self.assertEqual(tools.get_bytes(0, 1024), base.DecompressData(b'abc'))
 
 def testLookupOffset(self):
 """Test the lookup_offset() method of the base class"""
diff --git a/tools/binman/fdt_test.py b/tools/binman/fdt_test.py
index 7ef87295463..564c1770820 100644
--- a/tools/binman/fdt_test.py
+++ b/tools/binman/fdt_test.py
@@ -44,43 +44,43 @@ class TestFdt(unittest.TestCase):
 fname = self.GetCompiled('045_prop_test.dts')
 dt = FdtScan(fname)
 node = dt.GetNode('/binman/intel-me')
-self.assertEquals('intel-me', node.name)
+self.assertEqual('intel-me', node.name)
 val = fdt_util.GetString(node, 'filename')
-self.assertEquals(str, type(val))
-self.assertEquals('me.bin', val)
+self.assertEqual(str, type(val))
+self.assertEqual('me.bin', val)
 
 prop = node.props['intval']
-self.assertEquals(fdt.Type.INT, prop.type)
-self.assertEquals(3, fdt_util.GetInt(node, 'intval'))
+self.assertEqual(fdt.Type.INT, prop.type)
+self.assertEqual(3, fdt_util.GetInt(node, 'intval'))
 
 prop = node.props['intarray']
-self.assertEquals(fdt.Type.INT, prop.type)
-self.assertEquals(list, type(prop.value))
-self.assertEquals(2, len(prop.value))
-self.assertEquals([5, 6],
+self.assertEqual(fdt.Type.INT, prop.type)
+self.assertEqual(list, type(prop.value))
+self.assertEqual(2, len(prop.value))
+self.assertEqual([5, 6],
   [fdt_util.fdt32_to_cpu(val) for val in prop.value])
 
 prop = node.props['byteval']
-self.assertEquals(fdt.Type.BYTE, prop.type)
-self.assertEquals(chr(8), prop.value)
+self.assertEqual(fdt.Type.BYTE, prop.type)
+self.assertEqual(chr(8), prop.value)
 
 prop = node.props['bytearray']
-self.assertEquals(fdt.Type.BYTE, prop.type)
-self.assertEquals(list, type(prop.value))
-self.assertEquals(str, type(prop.value[0]))
-self.assertEquals(3, len(prop.value))
-self.assertEquals([chr(1), '#', '4'], prop.value)
+self.assertEqual(fdt.Type.BYTE, prop.type)
+self.assertEqual(list, type(prop.value))
+self.assertEqual(str, type(prop.value[0]))
+self.assertEqual(3, len(prop.value))
+self.assertEqual([chr(1), '#', '4'], prop.value)
 
 prop = node.props['longbytearray']
-self.assertEquals(fdt.Type.INT, prop.type)
-self.assertEquals(0x090a0b0c, fdt_util.GetInt(node, 'longbytearray'))
+self.assertEqual(fdt.Type.INT, prop.type)
+self.assertEqual(0x090a0b0c, fdt_util.GetInt(node, 'longbytearray'))
 
 prop = node.props['stringval']
-self.assertEquals(fdt.Type.STRING, prop.type)
-self.assertEquals('message2', fdt_util.GetString(node, 'stringval'))
+self.assertEqual(fdt.Type.STRING, prop.type)
+self.assertEqual('message2', fdt_util.GetString(node, 'stringval'))
 
 prop = node.props['stringarray']
-self.assertEquals(fdt.Type.STRING, prop.type)
-self.assertEquals(list, type(prop.value))
-self.assertEquals(3, len(prop.value))
-self.assertEquals(['another', 'multi-word', 'message'], prop.value)
+self.assertEq

Re: [PATCH v3 15/25] mbedtls: add X509 cert parser porting layer

2024-06-04 Thread Raymond Mao
Hi Ilias,

On Fri, 31 May 2024 at 07:42, Ilias Apalodimas 
wrote:

> On Tue, 28 May 2024 at 17:15, Raymond Mao  wrote:
> >
> > Add porting layer for X509 cert parser on top of MbedTLS X509
> > library.
> >
> > Signed-off-by: Raymond Mao 
> > ---
> > Changes in v2
> > - Move the porting layer to MbedTLS dir.
> > Changes in v3
> > - None.
> >
> >  lib/mbedtls/Makefile   |   1 +
> >  lib/mbedtls/x509_cert_parser.c | 497 +
> >  2 files changed, 498 insertions(+)
> >  create mode 100644 lib/mbedtls/x509_cert_parser.c
> >
>
[snip]

> > diff --git a/lib/mbedtls/x509_cert_parser.c
> b/lib/mbedtls/x509_cert_parser.c
> > new file mode 100644
> > index 000..b0867d31047
> > --- /dev/null
> > +++ b/lib/mbedtls/x509_cert_parser.c
>
> [snip]

> > +static int x509_set_cert_flags(struct x509_certificate *cert)
> > +{
> > +   struct public_key_signature *sig = cert->sig;
> > +
> > +   if (!sig || !cert->pub) {
> > +   pr_err("Signature or public key is not initialized\n");
> > +   return -ENOPKG;
> > +   }
> > +
> > +   if (!cert->pub->pkey_algo)
> > +   cert->unsupported_key = true;
> > +
> > +   if (!sig->pkey_algo)
> > +   cert->unsupported_sig = true;
> > +
> > +   if (!sig->hash_algo)
> > +   cert->unsupported_sig = true;
> > +
> > +   /* TODO: is_hash_blacklisted()? */
>
> Is this supported by our current implementation?
>
> This is not supported currently either. I just copied the TODO mark
from legacy lib.

[snip]

> > +   }
> > +   goto out;
> > +   }
> > +
> > +   pr_devel("Cert Self-signature verified");
> > +   cert->self_signed = true;
> > +
> > +out:
> > +   return ret;
> > +
> > +not_self_signed:
> > +   return 0;
> > +}
>
> the whole function looks like a copy of lib/crypto/x509_public_key.c.
> Can you move all the c/p ones to a common file that the existing and
> mbedTLS implementations can use?
>
> Per a previous discussion with Tom, eventually we tend to keep only one
crypto lib, that is the reason I prefer to copy/optimize a few existing
functions into MbedTLS implementation instead of creating another
common file.

Regards,
Raymond


Re: [PATCH v2 2/2] bootstd: Replace bootmethod(s) -> bootmeth(s)

2024-06-04 Thread Quentin Schulz

Hi Mattijs,

On 6/4/24 5:15 PM, Mattijs Korpershoek wrote:

According to [1], we should use bootmeth when describing the
struct bootmeth:

"""
For version 2, a new naming scheme is used as above:

 - bootdev is used instead of bootdevice, because 'device' is overused,
 is everywhere in U-Boot, can be confused with udevice
 - bootmeth - because 'method' is too vanilla, appears 1300 times in
 U-Boot
"""

Replace all occurences in various comments for consistency.



s/occurences/occurrences/

Sorry, was too tempting to highlight a typo in a commit that fixes typos :)

(Don't send a v3 for this please :) )


[1] https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/


Reviewed-by: Quentin Schulz 

Thanks!
Quentin


Re: [PATCH] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Mattijs Korpershoek
Hi Quentin,

Thanks for the review!

On mar., juin 04, 2024 at 14:22, Quentin Schulz  
wrote:

> Hi Mattijs,
>
> On 6/4/24 2:04 PM, Mattijs Korpershoek wrote:

[...]

>> 
>> There seems indeed to be some inconsistencies around bootmeths versus
>> bootmethods.
>> 
>> To me, we should use 'bootmeth' everywhere.
>> 
>> Simon, as the maintainer of bootflow, do you agree ?
>> 
>> I can spin up another patch to fix this.
>> 
>
> c.f. https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/
>
> """
> For version 2, a new naming scheme is used as above:
>
> - bootdev is used instead of bootdevice, because 'device' is overused,
> is everywhere in U-Boot, can be confused with udevice
> - bootmeth - because 'method' is too vanilla, appears 1300 times in
> U-Boot
> """
>
> SO I think we should change it to bootmeth(s) indeed.

Ah, thank you for the link, that is helpful.

I've done the global rename, made this into a series here:

https://lore.kernel.org/all/20240604-bootmeth-typos-v2-0-821683a95...@baylibre.com

>
> Reviewed-by: Quentin Schulz 
>
> Thanks,
> Quentin


[PATCH v2 2/2] bootstd: Replace bootmethod(s) -> bootmeth(s)

2024-06-04 Thread Mattijs Korpershoek
According to [1], we should use bootmeth when describing the
struct bootmeth:

"""
For version 2, a new naming scheme is used as above:

- bootdev is used instead of bootdevice, because 'device' is overused,
is everywhere in U-Boot, can be confused with udevice
- bootmeth - because 'method' is too vanilla, appears 1300 times in
U-Boot
"""

Replace all occurences in various comments for consistency.

[1] https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/
Signed-off-by: Mattijs Korpershoek 
---
 board/sandbox/sandbox.env |  2 +-
 boot/bootmeth-uclass.c|  2 +-
 include/bootmeth.h| 30 +++---
 include/extlinux.h|  2 +-
 test/boot/bootflow.c  |  2 +-
 test/boot/bootmeth.c  |  6 +++---
 6 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/board/sandbox/sandbox.env b/board/sandbox/sandbox.env
index a2c19702d64d..564dce78a898 100644
--- a/board/sandbox/sandbox.env
+++ b/board/sandbox/sandbox.env
@@ -10,7 +10,7 @@ eth6addr=02:00:11:22:33:47
 ipaddr=192.0.2.1
 
 /*
- * These are used for distro boot which is not supported. But once bootmethod
+ * These are used for distro boot which is not supported. But once bootmeth
  * is provided these will be used again.
  */
 bootm_size=0x1000
diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
index 1d157d54dbdd..e3475f46b34c 100644
--- a/boot/bootmeth-uclass.c
+++ b/boot/bootmeth-uclass.c
@@ -167,7 +167,7 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, 
bool include_global)
if (pass)
iter->first_glob_method = upto;
/*
-* Get a list of bootmethods, in seq order (i.e. using
+* Get a list of bootmeths, in seq order (i.e. using
 * aliases). There may be gaps so try to count up high
 * enough to find them all.
 */
diff --git a/include/bootmeth.h b/include/bootmeth.h
index 529c4d813d82..2570d9593d49 100644
--- a/include/bootmeth.h
+++ b/include/bootmeth.h
@@ -47,7 +47,7 @@ struct bootmeth_ops {
 * This may involve reading state from the system, e.g. some data in
 * the firmware area.
 *
-* @dev:Bootmethod device to check
+* @dev:Bootmeth device to check
 * @buf:Buffer to place the info in (terminator must fit)
 * @maxsize:Size of buffer
 * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if
@@ -74,7 +74,7 @@ struct bootmeth_ops {
 *
 * It may update only the flags in @iter
 *
-* @dev:Bootmethod device to check against
+* @dev:Bootmeth device to check against
 * @iter:   On entry, provides bootdev, hwpart, part
 * Return: 0 if OK, -ENOTSUPP if this bootdev is not supported
 */
@@ -83,7 +83,7 @@ struct bootmeth_ops {
/**
 * read_bootflow() - read a bootflow for a device
 *
-* @dev:Bootmethod device to use
+* @dev:Bootmeth device to use
 * @bflow:  On entry, provides dev, hwpart, part and method.
 *  Returns updated bootflow if found
 * Return: 0 if OK, -ve on error
@@ -96,7 +96,7 @@ struct bootmeth_ops {
 * This provides a bootflow file to the bootmeth, to see if it is valid.
 * If it is, the bootflow is set up accordingly.
 *
-* @dev:Bootmethod device to use
+* @dev:Bootmeth device to use
 * @bflow:  On entry, provides bootdev.
 *  Returns updated bootflow if found
 * @buf:Buffer containing the possible bootflow file
@@ -111,7 +111,7 @@ struct bootmeth_ops {
 *
 * Read a file from the same place as the bootflow came from
 *
-* @dev:Bootmethod device to use
+* @dev:Bootmeth device to use
 * @bflow:  Bootflow providing info on where to read from
 * @file_path:  Path to file (may be absolute or relative)
 * @addr:   Address to load file
@@ -126,7 +126,7 @@ struct bootmeth_ops {
/**
 * readall() - read all files for a bootflow
 *
-* @dev:Bootmethod device to boot
+* @dev:Bootmeth device to boot
 * @bflow:  Bootflow to read
 * Return: 0 if OK, -EIO on I/O error, other -ve on other error
 */
@@ -135,7 +135,7 @@ struct bootmeth_ops {
/**
 * boot() - boot a bootflow
 *
-* @dev:Bootmethod device to boot
+* @dev:Bootmeth device to boot
 * @bflow:  Bootflow to boot
 * Return: does not return on success, since it should boot the
 *  Operating System. Returns -EFAULT if that fails, -ENOTSUPP if
@@ -158,7 +158,7 @@ struct bootmeth_ops {
  * Thi

[PATCH v2 1/2] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Mattijs Korpershoek
Fix some trivial typos found by browsing the code.
Done with flyspell.

Reviewed-by: Quentin Schulz 
Signed-off-by: Mattijs Korpershoek 
---
 include/bootmeth.h | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/bootmeth.h b/include/bootmeth.h
index 0fc36104ece0..529c4d813d82 100644
--- a/include/bootmeth.h
+++ b/include/bootmeth.h
@@ -40,7 +40,7 @@ struct bootmeth_ops {
/**
 * get_state_desc() - get detailed state information
 *
-* Prodecues a textual description of the state of the bootmeth. This
+* Produces a textual description of the state of the bootmeth. This
 * can include newline characters if it extends to multiple lines. It
 * must be a nul-terminated string.
 *
@@ -138,7 +138,7 @@ struct bootmeth_ops {
 * @dev:Bootmethod device to boot
 * @bflow:  Bootflow to boot
 * Return: does not return on success, since it should boot the
-*  Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
+*  Operating System. Returns -EFAULT if that fails, -ENOTSUPP if
 *  trying method resulted in finding out that is not actually
 *  supported for this boot and should not be tried again unless
 *  something changes, other -ve on other error
@@ -151,7 +151,7 @@ struct bootmeth_ops {
 /**
  * bootmeth_get_state_desc() - get detailed state information
  *
- * Prodecues a textual description of the state of the bootmeth. This
+ * Produces a textual description of the state of the bootmeth. This
  * can include newline characters if it extends to multiple lines. It
  * must be a nul-terminated string.
  *
@@ -244,7 +244,7 @@ int bootmeth_read_file(struct udevice *dev, struct bootflow 
*bflow,
  * @dev:   Bootmethod device to use
  * @bflow: Bootflow to read
  * Return: does not return on success, since it should boot the
- * Operating Systemn. Returns -EFAULT if that fails, other -ve on
+ * Operating System. Returns -EFAULT if that fails, other -ve on
  * other error
  */
 int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow);
@@ -255,7 +255,7 @@ int bootmeth_read_all(struct udevice *dev, struct bootflow 
*bflow);
  * @dev:   Bootmethod device to boot
  * @bflow: Bootflow to boot
  * Return: does not return on success, since it should boot the
- * Operating Systemn. Returns -EFAULT if that fails, other -ve on
+ * Operating System. Returns -EFAULT if that fails, other -ve on
  * other error
  */
 int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
@@ -264,7 +264,7 @@ int bootmeth_boot(struct udevice *dev, struct bootflow 
*bflow);
  * bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
  *
  * This sets up the ordering information in @iter, based on the selected
- * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is no
+ * ordering of the bootmeths in bootstd_priv->bootmeth_order. If there is no
  * ordering there, then all bootmethods are added
  *
  * @iter: Iterator to update with the order

-- 
2.45.0



[PATCH v2 0/2] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Mattijs Korpershoek
While working on bootflow, we noticed some wording inconsistencies with
bootmeth versus bootmethod.

According to [1], we should use bootmeth(s), not bootmethod(s):

"""
For version 2, a new naming scheme is used as above:

- bootdev is used instead of bootdevice, because 'device' is overused,
is everywhere in U-Boot, can be confused with udevice
- bootmeth - because 'method' is too vanilla, appears 1300 times in
U-Boot
"""

[1] c.f. https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/

First patch fixes some trivial typos, second patch replaces all
occurences of bootmethod(s) -> bootmeth(s).

Signed-off-by: Mattijs Korpershoek 
---
Changes in v2:
- Made into a series
- New patch replaces all bootmethod(s) -> bootmeth(s)
- Link to v1: 
https://lore.kernel.org/r/20240603-bootmeth-typos-v1-1-6edbdb469...@baylibre.com

---
Mattijs Korpershoek (2):
  bootstd: Fix a handful of doc typos in bootmeth
  bootstd: Replace bootmethod(s) -> bootmeth(s)

 board/sandbox/sandbox.env |  2 +-
 boot/bootmeth-uclass.c|  2 +-
 include/bootmeth.h| 42 +-
 include/extlinux.h|  2 +-
 test/boot/bootflow.c  |  2 +-
 test/boot/bootmeth.c  |  6 +++---
 6 files changed, 28 insertions(+), 28 deletions(-)
---
base-commit: ea722aa5eb33740ae77e8816aeb72b385e621cd0
change-id: 20240603-bootmeth-typos-47c865e70ccf

Best regards,
-- 
Mattijs Korpershoek 



[PATCH v3 7/7] drivers: misc: Add driver to access ZynqMP efuses

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 

Add driver to access ZynqMP efuses. This is a u-boot port of [1].

Note: Accessing eFuses requires eFuse access to be enabled in the
underlying PMU firmware.

[1] 
https://lore.kernel.org/all/20240224114516.86365-8-srinivas.kandaga...@linaro.org/

Signed-off-by: Lukas Funke 
---

Changes in v3:
- Align ZynqMP eFuse driver with Linux kernel
- Adapt versal, versal-net and zynqmp to use common chip-id function
- Enable CMD_FUSE and ZYNQMP_EFUSE for zynqmp_virt and zynqmp_kria defconfig
- Use 'dev_err' instead 'log_msg_ret' if possible

Changes in v2:
- Drop vendor specific fuse cmd, use existing fuse cmd
- Minor code refactoring (reverse x-mas tree)

 drivers/misc/Kconfig|   8 +
 drivers/misc/Makefile   |   1 +
 drivers/misc/zynqmp_efuse.c | 360 
 3 files changed, 369 insertions(+)
 create mode 100644 drivers/misc/zynqmp_efuse.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 6009d55f400..c07f50c9a76 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -298,6 +298,14 @@ config FSL_SEC_MON
  Security Monitor can be transitioned on any security failures,
  like software violations or hardware security violations.
 
+config ZYNQMP_EFUSE
+   bool "Enable ZynqMP eFUSE Driver"
+   depends on ZYNQMP_FIRMWARE
+   help
+ Enable access to Zynq UltraScale (ZynqMP) eFUSEs thought PMU firmware
+ interface. ZnyqMP has 256 eFUSEs where some of them are security 
related
+ and cannot be read back (i.e. AES key).
+
 choice
prompt "Security monitor interaction endianess"
depends on FSL_SEC_MON
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index e53d52c47b3..68ba5648eab 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -92,3 +92,4 @@ obj-$(CONFIG_ESM_K3) += k3_esm.o
 obj-$(CONFIG_ESM_PMIC) += esm_pmic.o
 obj-$(CONFIG_SL28CPLD) += sl28cpld.o
 obj-$(CONFIG_SPL_SOCFPGA_DT_REG) += socfpga_dtreg.o
+obj-$(CONFIG_ZYNQMP_EFUSE) += zynqmp_efuse.o
diff --git a/drivers/misc/zynqmp_efuse.c b/drivers/misc/zynqmp_efuse.c
new file mode 100644
index 000..d12de7494d2
--- /dev/null
+++ b/drivers/misc/zynqmp_efuse.c
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2014 - 2015 Xilinx, Inc.
+ * Michal Simek 
+ *
+ * (C) Copyright 2024 Weidmueller Interface GmbH
+ * Lukas Funke 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SILICON_REVISION_MASK 0xF
+#define P_USER_0_64_UPPER_MASK GENMASK(31, 16)
+#define P_USER_127_LOWER_4_BIT_MASK GENMASK(3, 0)
+#define WORD_INBYTES   4
+#define SOC_VER_SIZE   0x4
+#define EFUSE_MEMORY_SIZE  0x177
+#define UNUSED_SPACE   0x8
+#define ZYNQMP_NVMEM_SIZE  (SOC_VER_SIZE + UNUSED_SPACE + \
+EFUSE_MEMORY_SIZE)
+#define SOC_VERSION_OFFSET 0x0
+#define EFUSE_START_OFFSET 0xC
+#define EFUSE_END_OFFSET   0xFC
+#define EFUSE_PUF_START_OFFSET 0x100
+#define EFUSE_PUF_MID_OFFSET   0x140
+#define EFUSE_PUF_END_OFFSET   0x17F
+#define EFUSE_NOT_ENABLED  29
+
+/*
+ * efuse access type
+ */
+enum efuse_access {
+   EFUSE_READ = 0,
+   EFUSE_WRITE
+};
+
+/**
+ * struct xilinx_efuse - the basic structure
+ * @src:   address of the buffer to store the data to be write/read
+ * @size:  read/write word count
+ * @offset:read/write offset
+ * @flag:  0 - represents efuse read and 1- represents efuse write
+ * @pufuserfuse:0 - represents non-puf efuses, offset is used for read/write
+ * 1 - represents puf user fuse row number.
+ *
+ * this structure stores all the required details to
+ * read/write efuse memory.
+ */
+struct xilinx_efuse {
+   u64 src;
+   u32 size;
+   u32 offset;
+   enum efuse_access flag;
+   u32 pufuserfuse;
+};
+
+/**
+ * struct efuse_map_entry - offset and length of zynqmp fuses
+ * @offset:offset of efuse to be read/write
+ * @length:length of efuse
+ */
+struct efuse_map_entry {
+   u32 offset;
+   u32 length;
+};
+
+struct efuse_map_entry zynqmp_efuse_table[] = {
+   {0x000, 0x04}, /* soc revision */
+   {0x00c, 0x0c}, /* SoC DNA */
+   {0x020, 0x04}, /* efuse-usr0 */
+   {0x024, 0x04}, /* efuse-usr1 */
+   {0x028, 0x04}, /* efuse-usr2 */
+   {0x02c, 0x04}, /* efuse-usr3 */
+   {0x030, 0x04}, /* efuse-usr4 */
+   {0x034, 0x04}, /* efuse-usr5 */
+   {0x038, 0x04}, /* efuse-usr6 */
+   {0x03c, 0x04}, /* efuse-usr7 */
+   {0x040, 0x04}, /* efuse-miscusr */
+   {0x050, 0x04}, /* efuse-chash */
+   {0x054, 0x04}, /* efuse-pufmisc */
+   {0x058, 0x04}, /* efuse-sec */
+   {0x05c, 0x04}, /* efuse-spkid */
+   {0x060, 0x30}, /* efuse-aeskey */
+   {0x0a0, 0x30}, /* ppk0-hash */
+   {0x0d0, 0x30}, /* ppk1-hash */
+   {0x100, 0x7f}, /* pufuser */
+};
+
+static int zynqmp_efuse_get_length(u32 offset, u32 *base_offs

[PATCH v3 6/7] firmware: zynqmp: Add support to access efuses

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 

Add functions to access efuses through PMU firmware
interface.

Signed-off-by: Lukas Funke 
---

(no changes since v1)

 drivers/firmware/firmware-zynqmp.c | 31 ++
 include/zynqmp_firmware.h  |  2 ++
 2 files changed, 33 insertions(+)

diff --git a/drivers/firmware/firmware-zynqmp.c 
b/drivers/firmware/firmware-zynqmp.c
index dfad798a2e7..8e9687693dd 100644
--- a/drivers/firmware/firmware-zynqmp.c
+++ b/drivers/firmware/firmware-zynqmp.c
@@ -211,6 +211,37 @@ int zynqmp_pm_feature(const u32 api_id)
return ret_payload[1] & FIRMWARE_VERSION_MASK;
 }
 
+int zynqmp_pm_get_chipid(u32 *idcode, u32 *version)
+{
+   u32 ret_payload[PAYLOAD_ARG_CNT];
+   int ret;
+
+   if (!idcode || !version)
+   return -EINVAL;
+
+   ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
+   *idcode = ret_payload[1];
+   *version = ret_payload[2];
+
+   return ret;
+}
+
+int zynqmp_pm_efuse_access(const u64 address, u32 *out)
+{
+   u32 ret_payload[PAYLOAD_ARG_CNT];
+   int ret;
+
+   if (!out)
+   return -EINVAL;
+
+   ret = xilinx_pm_request(PM_EFUSE_ACCESS, upper_32_bits(address),
+   lower_32_bits(address), 0, 0, ret_payload);
+
+   *out = ret_payload[1];
+
+   return ret;
+}
+
 int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id)
 {
int ret;
diff --git a/include/zynqmp_firmware.h b/include/zynqmp_firmware.h
index 73198a6a6ea..7f18b4d59bf 100644
--- a/include/zynqmp_firmware.h
+++ b/include/zynqmp_firmware.h
@@ -453,6 +453,8 @@ int xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 
arg2,
 int zynqmp_pm_set_sd_config(u32 node, enum pm_sd_config_type config, u32 
value);
 int zynqmp_pm_set_gem_config(u32 node, enum pm_gem_config_type config,
 u32 value);
+int zynqmp_pm_get_chipid(u32 *idcode, u32 *version);
+int zynqmp_pm_efuse_access(const u64 address, u32 *out);
 int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id);
 int zynqmp_mmio_read(const u32 address, u32 *value);
 int zynqmp_mmio_write(const u32 address, const u32 mask, const u32 value);
-- 
2.30.2



[PATCH v3 5/7] soc: xilinx: zynqmp: Use zynqmp_pm_get_chipid() to get chip revision

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 

Use common zynqmp_pm_get_chipid() function to get the chip revision

Signed-off-by: Lukas Funke 
---

(no changes since v1)

 drivers/soc/soc_xilinx_zynqmp.c | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/soc/soc_xilinx_zynqmp.c b/drivers/soc/soc_xilinx_zynqmp.c
index d8b4f172a39..8a65810b7d7 100644
--- a/drivers/soc/soc_xilinx_zynqmp.c
+++ b/drivers/soc/soc_xilinx_zynqmp.c
@@ -346,22 +346,21 @@ static const struct soc_ops soc_xilinx_zynqmp_ops = {
 static int soc_xilinx_zynqmp_probe(struct udevice *dev)
 {
struct soc_xilinx_zynqmp_priv *priv = dev_get_priv(dev);
-   u32 ret_payload[PAYLOAD_ARG_CNT];
+   u32 idcode, version;
int ret;
 
priv->family = zynqmp_family;
 
-   if (!IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE))
-   ret = zynqmp_mmio_read(ZYNQMP_PS_VERSION, &ret_payload[2]);
+   if (!CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE))
+   ret = zynqmp_mmio_read(ZYNQMP_PS_VERSION, &version);
else
-   ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
-   ret_payload);
+   ret = zynqmp_pm_get_chipid(&idcode, &version);
if (ret < 0)
return ret;
 
-   priv->revision = ret_payload[2] & ZYNQMP_PS_VER_MASK;
+   priv->revision = version & ZYNQMP_PS_VER_MASK;
 
-   if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
+   if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) {
/*
 * Firmware returns:
 * payload[0][31:0] = status of the operation
@@ -370,11 +369,9 @@ static int soc_xilinx_zynqmp_probe(struct udevice *dev)
 * payload[2][28:20] = EXTENDED_IDCODE
 * payload[2][29] = PL_INIT
 */
-   u32 idcode = ret_payload[1];
-   u32 idcode2 = ret_payload[2] >>
-  ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
-   dev_dbg(dev, "IDCODE: 0x%0x, IDCODE2: 0x%0x\n", idcode,
-   idcode2);
+   u32 idcode2 = version >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
+
+   dev_dbg(dev, "IDCODE: 0x%0x, IDCODE2: 0x%0x\n", idcode, 
idcode2);
 
ret = soc_xilinx_zynqmp_detect_machine(dev, idcode, idcode2);
if (ret)
-- 
2.30.2



[PATCH v3 3/7] soc: xilinx: versal: Use zynqmp_pm_get_chipid() to get chip revision

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 

Use common zynqmp_pm_get_chipid() function to get the chip revision

Signed-off-by: Lukas Funke 
---

(no changes since v1)

 drivers/soc/soc_xilinx_versal.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/soc/soc_xilinx_versal.c b/drivers/soc/soc_xilinx_versal.c
index 3d8c25c19bb..3d949c4e612 100644
--- a/drivers/soc/soc_xilinx_versal.c
+++ b/drivers/soc/soc_xilinx_versal.c
@@ -45,23 +45,22 @@ static const struct soc_ops soc_xilinx_versal_ops = {
 static int soc_xilinx_versal_probe(struct udevice *dev)
 {
struct soc_xilinx_versal_priv *priv = dev_get_priv(dev);
-   u32 ret_payload[PAYLOAD_ARG_CNT];
+   u32 idcode, version;
int ret;
 
priv->family = versal_family;
 
-   if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
-   ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
-   ret_payload);
+   if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) {
+   ret = zynqmp_pm_get_chipid(&idcode, &version);
if (ret)
return ret;
} else {
-   ret_payload[2] = readl(VERSAL_PS_PMC_VERSION);
-   if (!ret_payload[2])
+   version = readl(VERSAL_PS_PMC_VERSION);
+   if (!version)
return -EINVAL;
}
 
-   priv->revision = ret_payload[2] >> VERSAL_PS_VER_SHIFT;
+   priv->revision = version >> VERSAL_PS_VER_SHIFT;
 
return 0;
 }
-- 
2.30.2



[PATCH v3 4/7] soc: xilinx: versal-net: Use zynqmp_pm_get_chipid() to get chip revision

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 

Use common zynqmp_pm_get_chipid() function to get the chip revision

Signed-off-by: Lukas Funke 
---

(no changes since v1)

 drivers/soc/soc_xilinx_versal_net.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/soc/soc_xilinx_versal_net.c 
b/drivers/soc/soc_xilinx_versal_net.c
index 146d068bb4a..76467a3bbb5 100644
--- a/drivers/soc/soc_xilinx_versal_net.c
+++ b/drivers/soc/soc_xilinx_versal_net.c
@@ -47,23 +47,22 @@ static const struct soc_ops soc_xilinx_versal_net_ops = {
 static int soc_xilinx_versal_net_probe(struct udevice *dev)
 {
struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
-   u32 ret_payload[PAYLOAD_ARG_CNT];
+   u32 idcode, version;
int ret;
 
priv->family = versal_family;
 
-   if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
-   ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
-   ret_payload);
+   if (CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) {
+   ret = zynqmp_pm_get_chipid(&idcode, &version);
if (ret)
return ret;
} else {
-   ret_payload[2] = readl(PMC_TAP_VERSION);
-   if (!ret_payload[2])
+   version = readl(PMC_TAP_VERSION);
+   if (!version)
return -EINVAL;
}
 
-   priv->revision = FIELD_GET(PS_VERSION_MASK, ret_payload[2]);
+   priv->revision = FIELD_GET(PS_VERSION_MASK, version);
 
return 0;
 }
-- 
2.30.2



[PATCH v3 2/7] configs: zynqmp_virt: Enable CMD_FUSE and ZYNQMP_EFUSE

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 

Enable CMD_FUSE and ZYNQMP_EFUSE in order to be able to write
ZyqnMP eFuses from within the bootloader.

Signed-off-by: Lukas Funke 
---

(no changes since v1)

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

diff --git a/configs/xilinx_zynqmp_kria_defconfig 
b/configs/xilinx_zynqmp_kria_defconfig
index ba42f0c7848..ac91dccbe64 100644
--- a/configs/xilinx_zynqmp_kria_defconfig
+++ b/configs/xilinx_zynqmp_kria_defconfig
@@ -65,6 +65,7 @@ CONFIG_CMD_DFU=y
 CONFIG_CMD_FPGA_LOADBP=y
 CONFIG_CMD_FPGA_LOADP=y
 CONFIG_CMD_FPGA_LOAD_SECURE=y
+CONFIG_CMD_FUSE=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_PWM=y
 CONFIG_CMD_GPT=y
@@ -147,6 +148,7 @@ CONFIG_I2C_MUX_PCA954x=y
 CONFIG_LED=y
 CONFIG_LED_GPIO=y
 CONFIG_MISC=y
+CONFIG_ZYNQMP_EFUSE=y
 CONFIG_I2C_EEPROM=y
 CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_MMC_IO_VOLTAGE=y
-- 
2.30.2



[PATCH v3 1/7] configs: zynqmp_kria: Enable CMD_FUSE and ZYNQMP_EFUSE

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 

Enable CMD_FUSE and ZYNQMP_EFUSE in order to be able to write
ZyqnMP eFuses from within the bootloader for Kria SoM.

Signed-off-by: Lukas Funke 
---

(no changes since v1)

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

diff --git a/configs/xilinx_zynqmp_virt_defconfig 
b/configs/xilinx_zynqmp_virt_defconfig
index ee87beb19c6..1edd4ac77b1 100644
--- a/configs/xilinx_zynqmp_virt_defconfig
+++ b/configs/xilinx_zynqmp_virt_defconfig
@@ -65,6 +65,7 @@ CONFIG_CMD_DFU=y
 CONFIG_CMD_FPGA_LOADBP=y
 CONFIG_CMD_FPGA_LOADP=y
 CONFIG_CMD_FPGA_LOAD_SECURE=y
+CONFIG_CMD_FUSE=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_PWM=y
 CONFIG_CMD_GPT=y
@@ -147,6 +148,7 @@ CONFIG_I2C_MUX_PCA954x=y
 CONFIG_LED=y
 CONFIG_LED_GPIO=y
 CONFIG_MISC=y
+CONFIG_ZYNQMP_EFUSE=y
 CONFIG_I2C_EEPROM=y
 CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_MMC_IO_VOLTAGE=y
-- 
2.30.2



[PATCH v3 0/7] Add eFuse access for ZynqMP

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 


This series adds a driver to read and write ZynqMP eFuses [1]. The
driver can be accessed by the 'fuse read' and 'fuse write' commands

Example:

=> fuse read 0 0xc 3
Reading bank 0:

Word 0x000c: 3cb16685 013af244 4000

Note: Accessing eFuses requires eFuse access to be enabled in the
underlying PMU firmware.

Use cases are:
 - Reading/writing user specific eFuses to enable device specific
   implementations
 - Revoking SPK IDs
 - Reading SoC version/DNA

[1] https://docs.amd.com/r/en-US/ug1085-zynq-ultrascale-trm/eFUSE


Changes in v3:
- Align ZynqMP eFuse driver with Linux kernel
- Adapt versal, versal-net and zynqmp to use common chip-id function
- Enable CMD_FUSE and ZYNQMP_EFUSE for zynqmp_virt and zynqmp_kria defconfig
- Use 'dev_err' instead 'log_msg_ret' if possible

Changes in v2:
- Drop vendor specific fuse cmd, use existing fuse cmd
- Minor code refactoring (reverse x-mas tree)

Lukas Funke (7):
  configs: zynqmp_kria: Enable CMD_FUSE and ZYNQMP_EFUSE
  configs: zynqmp_virt: Enable CMD_FUSE and ZYNQMP_EFUSE
  soc: xilinx: versal: Use zynqmp_pm_get_chipid() to get chip revision
  soc: xilinx: versal-net: Use zynqmp_pm_get_chipid() to get chip
revision
  soc: xilinx: zynqmp: Use zynqmp_pm_get_chipid() to get chip revision
  firmware: zynqmp: Add support to access efuses
  drivers: misc: Add driver to access ZynqMP efuses

 configs/xilinx_zynqmp_kria_defconfig |   2 +
 configs/xilinx_zynqmp_virt_defconfig |   2 +
 drivers/firmware/firmware-zynqmp.c   |  31 +++
 drivers/misc/Kconfig |   8 +
 drivers/misc/Makefile|   1 +
 drivers/misc/zynqmp_efuse.c  | 360 +++
 drivers/soc/soc_xilinx_versal.c  |  13 +-
 drivers/soc/soc_xilinx_versal_net.c  |  13 +-
 drivers/soc/soc_xilinx_zynqmp.c  |  21 +-
 include/zynqmp_firmware.h|   2 +
 10 files changed, 427 insertions(+), 26 deletions(-)
 create mode 100644 drivers/misc/zynqmp_efuse.c

-- 
2.30.2



Re: [PATCH 1/1] Added arm64 assembly for examples/api crt0

2024-06-04 Thread Tom Rini
On Tue, Jun 04, 2024 at 07:57:38AM +0200, Heinrich Schuchardt wrote:
> On 6/4/24 05:34, Brunham, Kalen wrote:
> > Hi Tom/Heinrich,
> > 
> > I have https://github.com/u-boot/u-boot/pull/574 that has a proposed 
> > change. It is currently failing clang sandbox, which looks a little strange 
> > and I'm looking into it. Please let me know if you have any feedback on the 
> > general strategy.
> > 
> > Thanks,
> > -Kalen
> > 
> > -Original Message-
> > From: Tom Rini 
> > Sent: Monday, June 3, 2024 1:23 PM
> > To: Brunham, Kalen 
> > Cc: Jiaxun Yang ; Heinrich Schuchardt 
> > ; Ilias Apalodimas ; 
> > U-Boot@lists.denx.de
> > Subject: Re: [PATCH 1/1] Added arm64 assembly for examples/api crt0
> > 
> > On Sun, Jun 02, 2024 at 12:16:38AM +, Brunham, Kalen wrote:
> > > Thanks Tom.
> > > 
> > > Can you suggest who is the existing owner of this code I could work with?
> > 
> > You should CC Heinrich for sure once you have things working.
> > 
> > > 
> > > -Original Message-
> > > From: Tom Rini 
> > > Sent: Friday, May 31, 2024 12:03 PM
> > > To: Brunham, Kalen 
> > > Cc: Jiaxun Yang ; Heinrich Schuchardt 
> > > ; Ilias Apalodimas ; 
> > > U-Boot@lists.denx.de
> > > Subject: Re: [PATCH 1/1] Added arm64 assembly for examples/api crt0
> > > 
> > > On Thu, May 30, 2024 at 02:53:17PM +, Brunham, Kalen wrote:
> > > 
> > > > Hi Tom,
> > > > 
> > > > What are next steps on this change?
> > > > 
> > > > I'm committed to the idea of EFI apps opposed to examples/standalone.
> > > > EFI currently requires block devices which is not enabled when only 
> > > > using flash.
> > > > 
> > > > Should config BLK be updated to include DM_SPI_FLASH?
> 
> The UEFI implementation should not depend on DM_SPI_FLASH.
> 
> You could make BLK manually selectable again instead:
> 
> diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
> index 6ad18889f61..1f0e1010f0e 100644
> --- a/drivers/block/Kconfig
> +++ b/drivers/block/Kconfig
> @@ -1,5 +1,5 @@
>  config BLK
> -   bool # "Support block devices"
> +   bool "Support block devices"
> 
> Cf. 0417b8523c47 ("blk: Hide the BLK and SPL_LEGACY_BLOCK options")

They're hidden on purpose because most things should select them, not
depend on them. If EFI_LOADER is making its own virtual block devices,
it should be select'ing it not depending on it. There's a few other
places getting this backwards I see.

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v2 0/1] Enable reset_cpu() in SPL for ZynqMP

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 


This series enables the CPU reset in the SPL for ZynqMP based platforms.
This only works if CONFIG_SYSRESET is disabled. This is usually the
case since the the regular sysreset requires bl31 firmware to be loaded
in order to hand the sysreset over to PMU firmware. In SPL we can talk
to the PMU firmware directly and request a CPU reset.


Changes in v2:
- Drop 2/2 since reworking ZYNQMP_FIRMWARE dependency is out-of-scope

Lukas Funke (1):
  xilinx: zynqmp: Enable reset_cpu() in SPL

 board/xilinx/zynqmp/zynqmp.c | 9 +
 1 file changed, 9 insertions(+)

-- 
2.30.2



[PATCH v2 1/1] xilinx: zynqmp: Enable reset_cpu() in SPL

2024-06-04 Thread lukas . funke-oss
From: Lukas Funke 

This commit enables SPL to reset the CPU via PMU-firmware. The usual
reset mechanism requires bl31 to be loaded which may not be the case in
SPL.

Signed-off-by: Lukas Funke 
---

Changes in v2:
- Drop 2/2 since reworking ZYNQMP_FIRMWARE dependency is out-of-scope

 board/xilinx/zynqmp/zynqmp.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index f370fb7347a..a129b1dbbbc 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "../common/board.h"
 
 #include "pm_cfg_obj.h"
@@ -285,6 +286,14 @@ int dram_init(void)
 #if !CONFIG_IS_ENABLED(SYSRESET)
 void reset_cpu(void)
 {
+   if (!IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
+   log_warning("reset failed: ZYNQMP_FIRMWARE disabled");
+   return;
+   }
+
+   xilinx_pm_request(PM_RESET_ASSERT,
+ ZYNQMP_PM_RESET_START + ZYNQMP_RESET_SOFT,
+ PM_RESET_ACTION_ASSERT, 0, 0, NULL);
 }
 #endif
 
-- 
2.30.2



[PATCH] arm: dts; am625_beagleplay: Switch to OF_UPSTREAM

2024-06-04 Thread Nishanth Menon
Enable OF_UPSTREAM for AM625-beagleplay board. Remove DT files that
are now available in dts/upstream. Update the appended files based on
version of latest OF_UPSTREAM sync point (v6.10-rc1).

Signed-off-by: Nishanth Menon 
---

Based off u-boot
next 15d0dcc0ec1f Merge tag 'u-boot-imx-next-20240603' of 
https://gitlab.denx.de/u-boot/custodians/u-boot-imx into next

bootph properties are in sync, so nothing much to do there.

 arch/arm/dts/Makefile|   1 -
 arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi |   4 +-
 arch/arm/dts/k3-am625-beagleplay.dts | 932 ---
 configs/am62x_beagleplay_a53_defconfig   |   3 +-
 4 files changed, 4 insertions(+), 936 deletions(-)
 delete mode 100644 arch/arm/dts/k3-am625-beagleplay.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index cd7fcb3a3e6d..8461c70ff093 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1207,7 +1207,6 @@ dtb-$(CONFIG_SOC_K3_AM642) += k3-am642-r5-evm.dtb \
 
 dtb-$(CONFIG_SOC_K3_AM625) += k3-am625-sk.dtb \
  k3-am625-r5-sk.dtb \
- k3-am625-beagleplay.dtb \
  k3-am625-r5-beagleplay.dtb \
  k3-am625-verdin-r5.dtb \
  k3-am625-r5-phycore-som-2gb.dtb
diff --git a/arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi 
b/arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi
index 9ac4a825f841..dd5b335ed2ee 100644
--- a/arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi
+++ b/arch/arm/dts/k3-am625-beagleplay-u-boot.dtsi
@@ -66,9 +66,9 @@
 #ifdef CONFIG_TARGET_AM625_A53_BEAGLEPLAY
 
 #define SPL_NODTB "spl/u-boot-spl-nodtb.bin"
-#define SPL_AM625_BEAGLEPLAY_DTB "spl/dts/k3-am625-beagleplay.dtb"
+#define SPL_AM625_BEAGLEPLAY_DTB "spl/dts/ti/k3-am625-beagleplay.dtb"
 #define UBOOT_NODTB "u-boot-nodtb.bin"
-#define AM625_BEAGLEPLAY_DTB "arch/arm/dts/k3-am625-beagleplay.dtb"
+#define AM625_BEAGLEPLAY_DTB 
"dts/upstream/src/arm64/ti/k3-am625-beagleplay.dtb"
 
 &binman {
ti-dm {
diff --git a/arch/arm/dts/k3-am625-beagleplay.dts 
b/arch/arm/dts/k3-am625-beagleplay.dts
deleted file mode 100644
index 8ab838f1697c..
--- a/arch/arm/dts/k3-am625-beagleplay.dts
+++ /dev/null
@@ -1,932 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only OR MIT
-/*
- * https://beagleplay.org/
- *
- * Copyright (C) 2022-2024 Texas Instruments Incorporated - https://www.ti.com/
- * Copyright (C) 2022-2024 Robert Nelson, BeagleBoard.org Foundation
- */
-
-/dts-v1/;
-
-#include 
-#include 
-#include 
-#include "k3-am625.dtsi"
-
-/ {
-   compatible = "beagle,am625-beagleplay", "ti,am625";
-   model = "BeagleBoard.org BeaglePlay";
-
-   aliases {
-   ethernet0 = &cpsw_port1;
-   ethernet1 = &cpsw_port2;
-   gpio0 = &main_gpio0;
-   gpio1 = &main_gpio1;
-   gpio2 = &mcu_gpio0;
-   i2c0 = &main_i2c0;
-   i2c1 = &main_i2c1;
-   i2c2 = &main_i2c2;
-   i2c3 = &main_i2c3;
-   i2c4 = &wkup_i2c0;
-   i2c5 = &mcu_i2c0;
-   mmc0 = &sdhci0;
-   mmc1 = &sdhci1;
-   mmc2 = &sdhci2;
-   rtc0 = &rtc;
-   serial0 = &main_uart5;
-   serial1 = &main_uart6;
-   serial2 = &main_uart0;
-   usb0 = &usb0;
-   usb1 = &usb1;
-   };
-
-   chosen {
-   stdout-path = "serial2:115200n8";
-   };
-
-   memory@8000 {
-   bootph-pre-ram;
-   device_type = "memory";
-   /* 2G RAM */
-   reg = <0x 0x8000 0x 0x8000>;
-   };
-
-   reserved-memory {
-   #address-cells = <2>;
-   #size-cells = <2>;
-   ranges;
-
-   ramoops: ramoops@9ca0 {
-   compatible = "ramoops";
-   reg = <0x00 0x9ca0 0x00 0x0010>;
-   record-size = <0x8000>;
-   console-size = <0x8000>;
-   ftrace-size = <0x00>;
-   pmsg-size = <0x8000>;
-   };
-
-   secure_tfa_ddr: tfa@9e78 {
-   reg = <0x00 0x9e78 0x00 0x8>;
-   no-map;
-   };
-
-   secure_ddr: optee@9e80 {
-   reg = <0x00 0x9e80 0x00 0x0180>;
-   no-map;
-   };
-
-   wkup_r5fss0_core0_dma_memory_region: r5f-dma-memory@9db0 {
-   compatible = "shared-dma-pool";
-   reg = <0x00 0x9db0 0x00 0xc0>;
-   no-map;
-   };
-   };
-
-   vsys_5v0: regulator-1 {
-   bootph-all;
-   compatible = "regulator-fixed";
-   regulator-name = "vsys_5v0";
-   regulator-min-microv

[PATCH v2 1/1] usb: Assimilate usb_get_descriptor() to linux

2024-06-04 Thread Philip Oberfichtner
Before this commit, usb_get_descriptor() failed for some flakey USB
devices. We hereby adopt the more robust linux implementation [1].

For instance, for the "Alcor Micro Corp. Flash Drive" (VID 0x058f, PID
0x6387), the following behavior occurs from time to time:

=> usb start
starting USB...
Bus xhci_pci: Register 1840 NbrPorts 16
Starting the controller
USB XHCI 1.20
scanning bus xhci_pci for devices... usb_new_device: Cannot read configuration, 
skipping device 058f:6387

Signed-off-by: Philip Oberfichtner 

[1] From a38297e3fb012 (Linux 6.9), see

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/usb/core/message.c?h=v6.9#n781
---

Notes:
Changes in V2: Adapt commit message to
- state kernel version
- state which exact USB device is being fixed
- include error log

 common/usb.c | 37 ++---
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/common/usb.c b/common/usb.c
index 99e6b857c7..661ec0a9c4 100644
--- a/common/usb.c
+++ b/common/usb.c
@@ -215,8 +215,9 @@ int usb_int_msg(struct usb_device *dev, unsigned long pipe,
  * clear keyboards LEDs). For data transfers, (storage transfers) we don't
  * allow control messages with 0 timeout, by previousely resetting the flag
  * asynch_allowed (usb_disable_asynch(1)).
- * returns the transferred length if OK or -1 if error. The transferred length
- * and the current status are stored in the dev->act_len and dev->status.
+ * returns the transferred length if OK, otherwise a negative error code. The
+ * transferred length and the current status are stored in the dev->act_len and
+ * dev->status.
  */
 int usb_control_msg(struct usb_device *dev, unsigned int pipe,
unsigned char request, unsigned char requesttype,
@@ -258,11 +259,14 @@ int usb_control_msg(struct usb_device *dev, unsigned int 
pipe,
break;
mdelay(1);
}
+
+   if (timeout == 0)
+   return -ETIMEDOUT;
+
if (dev->status)
return -1;
 
return dev->act_len;
-
 }
 
 /*---
@@ -563,10 +567,29 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
 static int usb_get_descriptor(struct usb_device *dev, unsigned char type,
unsigned char index, void *buf, int size)
 {
-   return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
-  USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
-  (type << 8) + index, 0, buf, size,
-  USB_CNTL_TIMEOUT);
+   int i;
+   int result;
+
+   if (size <= 0)  /* No point in asking for no data */
+   return -EINVAL;
+
+   memset(buf, 0, size);   /* Make sure we parse really received data */
+
+   for (i = 0; i < 3; ++i) {
+   /* retry on length 0 or error; some devices are flakey */
+   result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
+(type << 8) + index, 0, buf, size,
+USB_CNTL_TIMEOUT);
+   if (result <= 0 && result != -ETIMEDOUT)
+   continue;
+   if (result > 1 && ((u8 *)buf)[1] != type) {
+   result = -ENODATA;
+   continue;
+   }
+   break;
+   }
+   return result;
 }
 
 /**
-- 
2.39.2



Re: obscure microsd detection issue between U-Boot and kernel

2024-06-04 Thread Christian Loehle
On 6/3/24 22:28, Tim Harvey wrote:
> On Mon, Jun 3, 2024 at 1:18 AM Christian Loehle
>  wrote:
>>
>> On 5/31/24 21:47, Tim Harvey wrote:
>>> Greetings,
>>>
>>> I'm seeing an issue on an imx8mm board (imx8mm-venice-gw73xx) where
>>> for a specific set of microsd cards if I have accessed the microsd in
>>> U-Boot with UHS/1.8V the kernel will not recognize that microsd when
>>> scanning.
>>>
>>> The issue does not occur with all microsd cards but seems to appear
>>> with a large sample size of a specific card/model (Kingston SDC32 32GB
>>> SDR104 card). I do not see a signal integrity issue on the scope.
>>>
>>> Instrumenting the kernel the issue is that the host reports a CRC
>>> error as soon as the first mmc_send_if_cond call which occurs in
>>> mmc_rescan_try_freq.
>>>
>>> I can avoid the issue by either not accessing the microsd in U-Boot or
>>> by disabling UHS/1.8V mode in U-Boot therefore what I think is
>>> happening is that U-Boot leaves the card in UHS/1.8V signalling mode
>>> and when the kernel scans it sets the voltage back to 3.3V
>>> standard/default and default timings then issues its clock cycles to
>>> 'reset' the card and the card does not recognize the reset. I'm
>>> wondering if this is because the reset is done via clock cycles after
>>> the kernel has set the I/O voltage back to 3.3V when perhaps the card
>>> is still in 1.8V mode (although I don't see how that would cause an
>>> issue)?
>>
>> It will cause an issue for many cards and might break some cards.
>>
>>>
>>> Is there some sort of MMC 'reset' I can/should do in U-Boot before
>>> booting the kernel? Has anyone encountered anything like this before?
>>
>> There is no 'switching back' to 3.3V signalling from UHS 1.8V.
>> The only way this can be done is therefore a full power-off.
>> Is that done correctly for your system?
>> AFAIR spec dictates 500ms of <0.5V on VCC. Note that  driving CLK/signal
>> lines can also sustain the card somewhat, as leakage is only limited
>> within operating voltage.
> 
> Hi Christian,
> 
> Are you saying the only way to properly reset from 1.8V is to have a
> VDD supply on the microSD card that can be turned off before booting
> to Linux? We have never had that before and never encountered
> something like this.

Yes, the only safe way to use UHS-I really anyway.
You could disable UHS for u-boot but that still leaves (potentially)
problematic warm-reboots of the board.
Having a (software-controlled) switchable regulator on SD VCC is pretty
common for this reason and you should be able to find it in most dts
for host controllers with sd-uhs-* property.
I'm afraid that the relevant spec section isn't available in the
simplified version.

Kind Regards,
Christian


[PATCH v2 1/1] xilinx: Add option to load environment from outside of boot media

2024-06-04 Thread Vasileios Amoiridis
From: Vasileios Amoiridis 

Currently, if the environment is not in the current boot media, the
env_get_location() is returning ENVL_UNKNOWN or ENVL_NOWHERE which
is not true (i.e booting from FLASH with environment in eMMC). This
commit adds an extra check to find the environment in the other
supported boot media, keeping the same priority as of now.

Signed-off-by: Vasileios Amoiridis 
---
 board/xilinx/versal-net/board.c | 47 ++--
 board/xilinx/versal/board.c | 47 ++--
 board/xilinx/zynq/board.c   | 49 +++--
 board/xilinx/zynqmp/zynqmp.c| 55 +
 4 files changed, 101 insertions(+), 97 deletions(-)

diff --git a/board/xilinx/versal-net/board.c b/board/xilinx/versal-net/board.c
index da03024e16..5295221aaa 100644
--- a/board/xilinx/versal-net/board.c
+++ b/board/xilinx/versal-net/board.c
@@ -377,29 +377,30 @@ enum env_location env_get_location(enum env_operation op, 
int prio)
 {
u8 bootmode = versal_net_get_bootmode();
 
-   if (prio)
-   return ENVL_UNKNOWN;
-
-   switch (bootmode) {
-   case EMMC_MODE:
-   case SD_MODE:
-   case SD1_LSHFT_MODE:
-   case SD_MODE1:
-   if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
-   return ENVL_FAT;
-   if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
-   return ENVL_EXT4;
-   return ENVL_NOWHERE;
-   case OSPI_MODE:
-   case QSPI_MODE_24BIT:
-   case QSPI_MODE_32BIT:
-   if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
-   return ENVL_SPI_FLASH;
-   return ENVL_NOWHERE;
-   case JTAG_MODE:
-   case SELECTMAP_MODE:
-   default:
-   return ENVL_NOWHERE;
+   if (!prio) {
+   switch (bootmode) {
+   case EMMC_MODE:
+   case SD_MODE:
+   case SD1_LSHFT_MODE:
+   case SD_MODE1:
+   if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
+   return ENVL_FAT;
+   if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
+   return ENVL_EXT4;
+   break;
+   case OSPI_MODE:
+   case QSPI_MODE_24BIT:
+   case QSPI_MODE_32BIT:
+   if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+   return ENVL_SPI_FLASH;
+   break;
+   case JTAG_MODE:
+   case SELECTMAP_MODE:
+   default:
+   return ENVL_NOWHERE;
+   }
}
+
+   return arch_env_get_location(op, prio);
 }
 #endif
diff --git a/board/xilinx/versal/board.c b/board/xilinx/versal/board.c
index 4f6d56119d..4201c3e2ef 100644
--- a/board/xilinx/versal/board.c
+++ b/board/xilinx/versal/board.c
@@ -296,29 +296,30 @@ enum env_location env_get_location(enum env_operation op, 
int prio)
 {
u32 bootmode = versal_get_bootmode();
 
-   if (prio)
-   return ENVL_UNKNOWN;
-
-   switch (bootmode) {
-   case EMMC_MODE:
-   case SD_MODE:
-   case SD1_LSHFT_MODE:
-   case SD_MODE1:
-   if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
-   return ENVL_FAT;
-   if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
-   return ENVL_EXT4;
-   return ENVL_NOWHERE;
-   case OSPI_MODE:
-   case QSPI_MODE_24BIT:
-   case QSPI_MODE_32BIT:
-   if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
-   return ENVL_SPI_FLASH;
-   return ENVL_NOWHERE;
-   case JTAG_MODE:
-   case SELECTMAP_MODE:
-   default:
-   return ENVL_NOWHERE;
+   if (!prio) {
+   switch (bootmode) {
+   case EMMC_MODE:
+   case SD_MODE:
+   case SD1_LSHFT_MODE:
+   case SD_MODE1:
+   if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
+   return ENVL_FAT;
+   if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4))
+   return ENVL_EXT4;
+   break;
+   case OSPI_MODE:
+   case QSPI_MODE_24BIT:
+   case QSPI_MODE_32BIT:
+   if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
+   return ENVL_SPI_FLASH;
+   break;
+   case JTAG_MODE:
+   case SELECTMAP_MODE:
+   default:
+   return ENVL_NOWHERE;
+   }
}
+
+   return arch_env_get_location(op, prio);
 }
 #endif
diff --git a/board/xilinx/zynq/board.c b/board/xilinx/zynq/board.c
index 6c36591001..4c9923de18 100644
--- a/board/xilinx/zynq/board.c
+++ b/board/xilinx/zynq/board.c
@@ -138,31 +138,32 @@ enum env_location env_get_location(enum env_operation op, 
int prio)
 {

[PATCH v2 0/1] xilinx: Add option to load environment from outside of

2024-06-04 Thread Vasileios Amoiridis
From: Vasileios Amoiridis 

Changes in v2:
- Remove duplication of custom hardcoded env_locations[] code.
- Add implementation with general arch_env_get_location(op, prio)

v1: 
https://lore.kernel.org/u-boot/20240522174738.73522-1-vassilisa...@gmail.com/

Vasileios Amoiridis (1):
  xilinx: Add option to load environment from outside of boot media

 board/xilinx/versal-net/board.c | 47 ++--
 board/xilinx/versal/board.c | 47 ++--
 board/xilinx/zynq/board.c   | 49 +++--
 board/xilinx/zynqmp/zynqmp.c| 55 +
 4 files changed, 101 insertions(+), 97 deletions(-)

-- 
2.34.1



[PATCH v4 6/6] spinand: bind UBI block

2024-06-04 Thread Alexey Romanov
UBI block is virtual block device, which is an abstraction
over MTD layer. Therefore it is logical to use it in
combination with MTD drivers.

Signed-off-by: Alexey Romanov 
---
 drivers/mtd/nand/spi/core.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 8edb468aed..db71e0627b 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1181,8 +1182,13 @@ static int spinand_bind(struct udevice *dev)
 {
if (blk_enabled()) {
struct spinand_plat *plat = dev_get_plat(dev);
+   int ret;
+
+   ret = mtd_bind(dev, &plat->mtd);
+   if (ret)
+   return ret;
 
-   return mtd_bind(dev, &plat->mtd);
+   return ubi_bind(dev);
}
 
return 0;
-- 
2.34.1



[PATCH v4 5/6] disk: support UBI partitions

2024-06-04 Thread Alexey Romanov
UBI partition is abstraction over UBI volumes.
Can be used by UBI block device.

Signed-off-by: Alexey Romanov 
Reviewed-by: Heiko Schocher 
---
 drivers/mtd/ubi/Makefile |  2 +-
 drivers/mtd/ubi/part.c   | 99 
 include/part.h   |  2 +
 3 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/ubi/part.c

diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile
index 67b1a05348..63dc428813 100644
--- a/drivers/mtd/ubi/Makefile
+++ b/drivers/mtd/ubi/Makefile
@@ -7,4 +7,4 @@ obj-y += attach.o build.o vtbl.o vmt.o upd.o kapi.o eba.o io.o 
wl.o crc32.o
 obj-$(CONFIG_MTD_UBI_FASTMAP) += fastmap.o
 obj-y += misc.o
 obj-y += debug.o
-obj-$(CONFIG_BLK) += block.o
+obj-$(CONFIG_BLK) += block.o part.o
diff --git a/drivers/mtd/ubi/part.c b/drivers/mtd/ubi/part.c
new file mode 100644
index 00..8dd7b874af
--- /dev/null
+++ b/drivers/mtd/ubi/part.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2024 SaluteDevices, Inc.
+ *
+ * Author: Alexey Romanov 
+ */
+
+#include 
+#include 
+#include 
+
+static inline struct ubi_device *get_ubi_device(void)
+{
+   return ubi_devices[0];
+}
+
+static struct ubi_volume *ubi_get_volume_by_index(int vol_id)
+{
+   struct ubi_device *ubi = get_ubi_device();
+   int i;
+
+   for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
+   struct ubi_volume *volume = ubi->volumes[i];
+
+   if (!volume)
+   continue;
+
+   if (volume->vol_id >= UBI_INTERNAL_VOL_START)
+   continue;
+
+   if (volume->vol_id == vol_id)
+   return volume;
+   }
+
+   return NULL;
+}
+
+static int __maybe_unused part_get_info_ubi(struct blk_desc *dev_desc, int 
part_idx,
+   struct disk_partition *info)
+{
+   struct ubi_volume *vol;
+
+   /*
+* We must use part_idx - 1 instead of part_idx, because
+* part_get_info_by_name() start indexing at 1, not 0.
+* ubi volumes idexed starting at 0
+*/
+   vol = ubi_get_volume_by_index(part_idx - 1);
+   if (!vol)
+   return 0;
+
+   snprintf(info->name, PART_NAME_LEN, vol->name);
+
+   info->start = 0;
+   info->size = vol->used_bytes / dev_desc->blksz;
+   info->blksz = dev_desc->blksz;
+
+   /* Save UBI volume ID in blk device descriptor */
+   dev_desc->hwpart = vol->vol_id;
+
+   return 0;
+}
+
+static void __maybe_unused part_print_ubi(struct blk_desc *dev_desc)
+{
+   struct ubi_device *ubi = get_ubi_device();
+   int i;
+
+   for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
+   struct ubi_volume *volume = ubi->volumes[i];
+
+   if (!volume)
+   continue;
+
+   if (volume->vol_id >= UBI_INTERNAL_VOL_START)
+   continue;
+
+   printf("%d: %s\n", volume->vol_id, volume->name);
+   }
+}
+
+static int part_test_ubi(struct blk_desc *dev_desc)
+{
+   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+
+   if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
+   return -1;
+
+   return 0;
+}
+
+U_BOOT_PART_TYPE(ubi) = {
+   .name   = "ubi",
+   .part_type  = PART_TYPE_UBI,
+   .max_entries= UBI_ENTRY_NUMBERS,
+   .get_info   = part_get_info_ptr(part_get_info_ubi),
+   .print  = part_print_ptr(part_print_ubi),
+   .test   = part_test_ubi,
+};
diff --git a/include/part.h b/include/part.h
index 40419fdf2f..72b98b3512 100644
--- a/include/part.h
+++ b/include/part.h
@@ -31,6 +31,7 @@ struct block_drvr {
 #define PART_TYPE_AMIGA0x04
 #define PART_TYPE_EFI  0x05
 #define PART_TYPE_MTD  0x06
+#define PART_TYPE_UBI  0x07
 
 /* maximum number of partition entries supported by search */
 #define DOS_ENTRY_NUMBERS  8
@@ -38,6 +39,7 @@ struct block_drvr {
 #define MAC_ENTRY_NUMBERS  64
 #define AMIGA_ENTRY_NUMBERS8
 #define MTD_ENTRY_NUMBERS  64
+#define UBI_ENTRY_NUMBERS  UBI_MAX_VOLUMES
 
 /*
  * Type string for U-Boot bootable partitions
-- 
2.34.1



[PATCH v4 4/6] disk: don't try search for partition type if already set

2024-06-04 Thread Alexey Romanov
Block devices can already set partition type at initialization
stage, so, in this case is no point in searching for partition type.

Signed-off-by: Alexey Romanov 
Reviewed-by: Heiko Schocher 
---
 disk/part.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/disk/part.c b/disk/part.c
index 3f0fce5cfa..0aced6eb72 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -286,6 +286,13 @@ void part_init(struct blk_desc *desc)
 
blkcache_invalidate(desc->uclass_id, desc->devnum);
 
+   if (desc->part_type != PART_TYPE_UNKNOWN) {
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   if (entry->part_type == desc->part_type && 
!entry->test(desc))
+   return;
+   }
+   }
+
desc->part_type = PART_TYPE_UNKNOWN;
for (entry = drv; entry != drv + n_ents; entry++) {
int ret;
-- 
2.34.1



[PATCH v4 3/6] drivers: introduce UBI block abstraction

2024-06-04 Thread Alexey Romanov
UBI block is an virtual device, that runs on top
of the MTD layer. The blocks are UBI volumes.
Intended to be used in combination with other MTD
drivers.

Despite the fact that it, like mtdblock abstraction,
it used with UCLASS_MTD, they can be used together
on the system without conflicting. For example,
using bcb command:

  # Trying to load bcb via mtdblock:
  $ bcb load mtd 0 mtd_partition_name

  # Trying to load bcb via UBI block:
  $ bcb load ubi 1 ubi_volume_name

User always must attach UBI layer (for example, using
ubi_part()) before using UBI block device.

Signed-off-by: Alexey Romanov 
Reviewed-by: Heiko Schocher 
Acked-by: Heiko Schocher 
---
 drivers/block/blk-uclass.c |   1 +
 drivers/mtd/ubi/Makefile   |   1 +
 drivers/mtd/ubi/block.c| 130 +
 include/ubi_uboot.h|   4 ++
 4 files changed, 136 insertions(+)
 create mode 100644 drivers/mtd/ubi/block.c

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index ab0a9105c9..8a457e9f70 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -38,6 +38,7 @@ static struct {
{ UCLASS_BLKMAP, "blkmap" },
{ UCLASS_RKMTD, "rkmtd" },
{ UCLASS_MTD, "mtd" },
+   { UCLASS_MTD, "ubi" },
 };
 
 static enum uclass_id uclass_name_to_iftype(const char *uclass_idname)
diff --git a/drivers/mtd/ubi/Makefile b/drivers/mtd/ubi/Makefile
index 30d00fbdfe..67b1a05348 100644
--- a/drivers/mtd/ubi/Makefile
+++ b/drivers/mtd/ubi/Makefile
@@ -7,3 +7,4 @@ obj-y += attach.o build.o vtbl.o vmt.o upd.o kapi.o eba.o io.o 
wl.o crc32.o
 obj-$(CONFIG_MTD_UBI_FASTMAP) += fastmap.o
 obj-y += misc.o
 obj-y += debug.o
+obj-$(CONFIG_BLK) += block.o
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
new file mode 100644
index 00..2464decb81
--- /dev/null
+++ b/drivers/mtd/ubi/block.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2024 SaluteDevices, Inc.
+ *
+ * Author: Alexey Romanov 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int ubi_bind(struct udevice *dev)
+{
+   struct blk_desc *bdesc;
+   struct udevice *bdev;
+   int ret;
+
+   ret = blk_create_devicef(dev, "ubi_blk", "blk", UCLASS_MTD,
+dev_seq(dev), 512, 0, &bdev);
+   if (ret) {
+   pr_err("Cannot create block device");
+   return ret;
+   }
+
+   bdesc = dev_get_uclass_plat(bdev);
+
+   bdesc->bdev = bdev;
+   bdesc->part_type = PART_TYPE_UBI;
+
+   return 0;
+}
+
+static struct ubi_device *get_ubi_device(void)
+{
+   return ubi_devices[0];
+}
+
+static char *get_volume_name(int vol_id)
+{
+   struct ubi_device *ubi = get_ubi_device();
+   int i;
+
+   for (i = 0; i < (ubi->vtbl_slots + 1); i++) {
+   struct ubi_volume *volume = ubi->volumes[i];
+
+   if (!volume)
+   continue;
+
+   if (volume->vol_id >= UBI_INTERNAL_VOL_START)
+   continue;
+
+   if (volume->vol_id == vol_id)
+   return volume->name;
+   }
+
+   return NULL;
+}
+
+static ulong ubi_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
+  void *dst)
+{
+   struct blk_desc *block_dev = dev_get_uclass_plat(dev);
+   char *volume_name = get_volume_name(block_dev->hwpart);
+   unsigned int size = blkcnt * block_dev->blksz;
+   loff_t offset = start * block_dev->blksz;
+   int ret;
+
+   if (!volume_name) {
+   pr_err("%s: failed to find volume name for blk=" LBAF "\n", 
__func__, start);
+   return -EINVAL;
+   }
+
+   ret = ubi_volume_read(volume_name, dst, offset, size);
+   if (ret) {
+   pr_err("%s: failed to read from %s UBI volume\n", __func__, 
volume_name);
+   return ret;
+   }
+
+   return blkcnt;
+}
+
+static ulong ubi_bwrite(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
+   const void *src)
+{
+   struct blk_desc *block_dev = dev_get_uclass_plat(dev);
+   char *volume_name = get_volume_name(block_dev->hwpart);
+   unsigned int size = blkcnt * block_dev->blksz;
+   loff_t offset = start * block_dev->blksz;
+   int ret;
+
+   if (!volume_name) {
+   pr_err("%s: failed to find volume for blk=" LBAF "\n", 
__func__, start);
+   return -EINVAL;
+   }
+
+   ret = ubi_volume_write(volume_name, (void *)src, offset, size);
+   if (ret) {
+   pr_err("%s: failed to write from %s UBI volume\n", __func__, 
volume_name);
+   return ret;
+   }
+
+   return blkcnt;
+}
+
+static int ubi_blk_probe(struct udevice *dev)
+{
+   int ret;
+
+   ret = device_probe(dev);
+   if (ret) {
+   pr_err("Probing %s failed (err=%d)\n", dev->name, ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+stat

[PATCH v4 2/6] ubi: allow to write to volume with offset

2024-06-04 Thread Alexey Romanov
Introduce ubi_volume_offset_write() helper, which
allow to write to ubi volume with specified offset.

Signed-off-by: Alexey Romanov 
Reviewed-by: Heiko Schocher 
Acked-by: Heiko Schocher 
---
 cmd/ubi.c   | 71 +++--
 env/ubi.c   | 10 +++
 include/ubi_uboot.h |  2 +-
 3 files changed, 74 insertions(+), 9 deletions(-)

diff --git a/cmd/ubi.c b/cmd/ubi.c
index 2257f68498..df235829b9 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -415,9 +415,74 @@ int ubi_volume_begin_write(char *volume, void *buf, size_t 
size,
return ubi_volume_continue_write(volume, buf, size);
 }
 
-int ubi_volume_write(char *volume, void *buf, size_t size)
+static int ubi_volume_offset_write(char *volume, void *buf, loff_t offset,
+  size_t size)
 {
-   return ubi_volume_begin_write(volume, buf, size, size);
+   int lnum, len, tbuf_size, ret;
+   struct ubi_volume *vol;
+   loff_t off = offset;
+   void *tbuf;
+
+   vol = ubi_find_volume(volume);
+   if (!vol)
+   return -ENODEV;
+
+   if (size > vol->reserved_pebs * (ubi->leb_size - vol->data_pad))
+   return -EINVAL;
+
+   tbuf_size = vol->usable_leb_size;
+   tbuf = malloc_cache_aligned(tbuf_size);
+   if (!tbuf)
+   return -ENOMEM;
+
+   lnum = off;
+   off = do_div(lnum, vol->usable_leb_size);
+
+   do {
+   struct ubi_volume_desc desc = {
+   .vol = vol,
+   .mode = UBI_READWRITE,
+   };
+
+   len = size > tbuf_size ? tbuf_size : size;
+   if (off + len >= vol->usable_leb_size)
+   len = vol->usable_leb_size - off;
+
+   ret = ubi_read(&desc, lnum, tbuf, 0, tbuf_size);
+   if (ret) {
+   pr_err("Failed to read leb %d (%d)\n", lnum, ret);
+   goto exit;
+   }
+
+   memcpy(tbuf + off, buf, len);
+
+   ret = ubi_leb_change(&desc, lnum, tbuf, tbuf_size);
+   if (ret) {
+   pr_err("Failed to write leb %d (%d)\n", lnum, ret);
+   goto exit;
+   }
+
+   off += len;
+   if (off >= vol->usable_leb_size) {
+   lnum++;
+   off -= vol->usable_leb_size;
+   }
+
+   buf += len;
+   size -= len;
+   } while (size);
+
+exit:
+   free(tbuf);
+   return ret;
+}
+
+int ubi_volume_write(char *volume, void *buf, loff_t offset, size_t size)
+{
+   if (!offset)
+   return ubi_volume_begin_write(volume, buf, size, size);
+
+   return ubi_volume_offset_write(volume, buf, offset, size);
 }
 
 int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size)
@@ -761,7 +826,7 @@ static int do_ubi(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
(void *)addr, size, full_size);
}
} else {
-   ret = ubi_volume_write(argv[3], (void *)addr, size);
+   ret = ubi_volume_write(argv[3], (void *)addr, 0, size);
}
if (!ret) {
printf("%lld bytes written to volume %s\n", size,
diff --git a/env/ubi.c b/env/ubi.c
index 661801d5a9..6ae74a500b 100644
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -54,7 +54,7 @@ static int env_ubi_save(void)
if (gd->env_valid == ENV_VALID) {
puts("Writing to redundant UBI... ");
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME_REDUND,
-(void *)env_new, CONFIG_ENV_SIZE)) {
+(void *)env_new, 0, CONFIG_ENV_SIZE)) {
printf("\n** Unable to write env to %s:%s **\n",
   CONFIG_ENV_UBI_PART,
   CONFIG_ENV_UBI_VOLUME_REDUND);
@@ -63,7 +63,7 @@ static int env_ubi_save(void)
} else {
puts("Writing to UBI... ");
if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME,
-(void *)env_new, CONFIG_ENV_SIZE)) {
+(void *)env_new, 0, CONFIG_ENV_SIZE)) {
printf("\n** Unable to write env to %s:%s **\n",
   CONFIG_ENV_UBI_PART,
   CONFIG_ENV_UBI_VOLUME);
@@ -93,7 +93,7 @@ static int env_ubi_save(void)
return 1;
}
 
-   if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new,
+   if (ubi_volume_write(CONFIG_ENV_UBI_VOLUME, (void *)env_new, 0,
 CONFIG_ENV_SIZE)) {
printf("\n** Unable to write env to %s:%s **\n",
   CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
@@ -197,7 +197,7 @@ static int en

[PATCH v4 1/6] ubi: allow to read from volume with offset

2024-06-04 Thread Alexey Romanov
Now user can pass an additional parameter 'offset'
to ubi_volume_read() function.

Signed-off-by: Alexey Romanov 
Reviewed-by: Heiko Schocher 
Acked-by: Heiko Schocher 
---
 cmd/ubi.c   | 6 +++---
 env/ubi.c   | 6 +++---
 include/ubi_uboot.h | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/cmd/ubi.c b/cmd/ubi.c
index 0a6a80bdd1..2257f68498 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -420,13 +420,13 @@ int ubi_volume_write(char *volume, void *buf, size_t size)
return ubi_volume_begin_write(volume, buf, size, size);
 }
 
-int ubi_volume_read(char *volume, char *buf, size_t size)
+int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t size)
 {
int err, lnum, off, len, tbuf_size;
void *tbuf;
unsigned long long tmp;
struct ubi_volume *vol;
-   loff_t offp = 0;
+   loff_t offp = offset;
size_t len_read;
 
vol = ubi_find_volume(volume);
@@ -787,7 +787,7 @@ static int do_ubi(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
}
 
if (argc == 3) {
-   return ubi_volume_read(argv[3], (char *)addr, size);
+   return ubi_volume_read(argv[3], (char *)addr, 0, size);
}
}
 
diff --git a/env/ubi.c b/env/ubi.c
index 445d34fedb..661801d5a9 100644
--- a/env/ubi.c
+++ b/env/ubi.c
@@ -135,13 +135,13 @@ static int env_ubi_load(void)
return -EIO;
}
 
-   read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1,
+   read1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, (void *)tmp_env1, 0,
 CONFIG_ENV_SIZE);
if (read1_fail)
printf("\n** Unable to read env from %s:%s **\n",
   CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
 
-   read2_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME_REDUND,
+   read2_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME_REDUND, 0,
 (void *)tmp_env2, CONFIG_ENV_SIZE);
if (read2_fail)
printf("\n** Unable to read redundant env from %s:%s **\n",
@@ -172,7 +172,7 @@ static int env_ubi_load(void)
return -EIO;
}
 
-   if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, CONFIG_ENV_SIZE)) {
+   if (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, 0, CONFIG_ENV_SIZE)) {
printf("\n** Unable to read env from %s:%s **\n",
   CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);
env_set_default(NULL, 0);
diff --git a/include/ubi_uboot.h b/include/ubi_uboot.h
index d7a8851094..a4be0feabb 100644
--- a/include/ubi_uboot.h
+++ b/include/ubi_uboot.h
@@ -49,7 +49,7 @@ extern int ubi_init(void);
 extern void ubi_exit(void);
 extern int ubi_part(char *part_name, const char *vid_header_offset);
 extern int ubi_volume_write(char *volume, void *buf, size_t size);
-extern int ubi_volume_read(char *volume, char *buf, size_t size);
+extern int ubi_volume_read(char *volume, char *buf, loff_t offset, size_t 
size);
 
 extern struct ubi_device *ubi_devices[];
 int cmd_ubifs_mount(char *vol_name);
-- 
2.34.1



[PATCH v4 0/6] Introduce UBI block device

2024-06-04 Thread Alexey Romanov
Hello!

This series adds support for the UBI block device, which
allows to read/write data block by block. For example,
it can now be used for BCB or Android AB command:

  $ bcb load ubi 0 part_name

Tested only on SPI NAND, so bind is made only for
SPI NAND drivers. Can be used with mtdblock device [1].

---

Changes V1 -> V2 [2]:

 - Rebased over mtdblock v2 patchset [3].
 - Compile UBI partitions support only if CONFIG_BLK option
   is enabled.

Changes V2 -> V3 [4]:

 - Fix build warnings: use LBAF printf format string for lbaint_t types.

Changes V3 -> V4 [5]:

 - Rebased over u-boot/master.
 - Fix build errors and warnings if CONFIG_BLK isn't enabled.
 - Fix failed tests in cases is ubiblock device isn't binded.

Links:

  [1] 
https://lore.kernel.org/all/20240227100441.1811047-1-avroma...@salutedevices.com/
  [2] 
https://lore.kernel.org/all/20240306134906.1179285-1-avroma...@salutedevices.com/
  [3] 
https://lore.kernel.org/all/20240307130726.1582487-1-avroma...@salutedevices.com/
  [4] 
https://lore.kernel.org/all/20240325144148.3738195-1-avroma...@salutedevices.com/
  [5] 
https://lore.kernel.org/all/20240524111319.3512009-1-avroma...@salutedevices.com/

Alexey Romanov (6):
  ubi: allow to read from volume with offset
  ubi: allow to write to volume with offset
  drivers: introduce UBI block abstraction
  disk: don't try search for partition type if already set
  disk: support UBI partitions
  spinand: bind UBI block

 cmd/ubi.c   |  77 +++--
 disk/part.c |   7 ++
 drivers/block/blk-uclass.c  |   1 +
 drivers/mtd/nand/spi/core.c |   8 ++-
 drivers/mtd/ubi/Makefile|   1 +
 drivers/mtd/ubi/block.c | 130 
 drivers/mtd/ubi/part.c  |  99 +++
 env/ubi.c   |  16 ++---
 include/part.h  |   2 +
 include/ubi_uboot.h |   8 ++-
 10 files changed, 332 insertions(+), 17 deletions(-)
 create mode 100644 drivers/mtd/ubi/block.c
 create mode 100644 drivers/mtd/ubi/part.c

-- 
2.34.1



[PATCH v5 3/3] spinand: bind mtdblock

2024-06-04 Thread Alexey Romanov
Bind SPI-NAND driver to MTD block driver.

Reviewed-by: Frieder Schrempf 
Signed-off-by: Alexey Romanov 
---
 drivers/mtd/nand/spi/core.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 62c28aa422..8edb468aed 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -34,6 +34,10 @@
 #include 
 #endif
 
+struct spinand_plat {
+   struct mtd_info *mtd;
+};
+
 /* SPI NAND index visible in MTD names */
 static int spi_nand_idx;
 
@@ -1173,12 +1177,24 @@ static void spinand_cleanup(struct spinand_device 
*spinand)
kfree(spinand->scratchbuf);
 }
 
+static int spinand_bind(struct udevice *dev)
+{
+   if (blk_enabled()) {
+   struct spinand_plat *plat = dev_get_plat(dev);
+
+   return mtd_bind(dev, &plat->mtd);
+   }
+
+   return 0;
+}
+
 static int spinand_probe(struct udevice *dev)
 {
struct spinand_device *spinand = dev_get_priv(dev);
struct spi_slave *slave = dev_get_parent_priv(dev);
struct mtd_info *mtd = dev_get_uclass_priv(dev);
struct nand_device *nand = spinand_to_nand(spinand);
+   struct spinand_plat *plat = dev_get_plat(dev);
int ret;
 
 #ifndef __UBOOT__
@@ -1218,6 +1234,8 @@ static int spinand_probe(struct udevice *dev)
if (ret)
goto err_spinand_cleanup;
 
+   plat->mtd = mtd;
+
return 0;
 
 err_spinand_cleanup:
@@ -1287,4 +1305,6 @@ U_BOOT_DRIVER(spinand) = {
.of_match = spinand_ids,
.priv_auto  = sizeof(struct spinand_device),
.probe = spinand_probe,
+   .bind = spinand_bind,
+   .plat_auto = sizeof(struct spinand_plat),
 };
-- 
2.34.1



[PATCH v5 2/3] drivers: introduce mtdblock abstraction

2024-06-04 Thread Alexey Romanov
MTD block - abstraction over MTD subsystem, allowing
to read and write in blocks using BLK UCLASS.

Signed-off-by: Alexey Romanov 
---
 drivers/block/blk-uclass.c |   1 +
 drivers/mtd/Makefile   |   1 +
 drivers/mtd/mtdblock.c | 227 +
 include/linux/mtd/mtd.h|  21 
 4 files changed, 250 insertions(+)
 create mode 100644 drivers/mtd/mtdblock.c

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 77066da352..ab0a9105c9 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -37,6 +37,7 @@ static struct {
{ UCLASS_PVBLOCK, "pvblock" },
{ UCLASS_BLKMAP, "blkmap" },
{ UCLASS_RKMTD, "rkmtd" },
+   { UCLASS_MTD, "mtd" },
 };
 
 static enum uclass_id uclass_name_to_iftype(const char *uclass_idname)
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index c2fc80b10f..f7eab71bcd 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -26,6 +26,7 @@ obj-y += onenand/
 obj-y += spi/
 obj-$(CONFIG_MTD_UBI) += ubi/
 obj-$(CONFIG_NVMXIP) += nvmxip/
+obj-$(CONFIG_BLK) += mtdblock.o
 
 #SPL/TPL build
 else
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
new file mode 100644
index 00..33c9c56a4c
--- /dev/null
+++ b/drivers/mtd/mtdblock.c
@@ -0,0 +1,227 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * MTD block - abstraction over MTD subsystem, allowing
+ * to read and write in blocks using BLK UCLASS.
+ *
+ * - Read algorithm:
+ *
+ *   1. Convert start block number to start address.
+ *   2. Read block_dev->blksz bytes using mtd_read() and
+ *  add to start address pointer block_dev->blksz bytes,
+ *  until the requested number of blocks have been read.
+ *
+ * - Write algorithm:
+ *
+ *   1. Convert start block number to start address.
+ *   2. Round this address down by mtd->erasesize.
+ *
+ *   Erase addr  Start addr
+ *  ||
+ *  vv
+ *  ++++
+ *  | blksz  |  blksz |  blksz |
+ *  ++++
+ *
+ *   3. Calculate offset between this two addresses.
+ *   4. Read mtd->erasesize bytes using mtd_read() into
+ *  temporary buffer from erase address.
+ *
+ *   Erase addr  Start addr
+ *  ||
+ *  vv
+ *  ++++
+ *  | blksz  |  blksz |  blksz |
+ *  ++++
+ *  ^
+ *  |
+ *  |
+ *   mtd_read()
+ *   from here
+ *
+ *   5. Copy data from user buffer to temporary buffer with offset,
+ *  calculated at step 3.
+ *   6. Erase and write mtd->erasesize bytes at erase address
+ *  pointer using mtd_erase/mtd_write().
+ *   7. Add to erase address pointer mtd->erasesize bytes.
+ *   8. goto 1 until the requested number of blocks have
+ *  been written.
+ *
+ * (C) Copyright 2024 SaluteDevices, Inc.
+ *
+ * Author: Alexey Romanov 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int mtd_bind(struct udevice *dev, struct mtd_info **mtd)
+{
+   struct blk_desc *bdesc;
+   struct udevice *bdev;
+   int ret;
+
+   ret = blk_create_devicef(dev, "mtd_blk", "blk", UCLASS_MTD,
+dev_seq(dev), 512, 0, &bdev);
+   if (ret) {
+   pr_err("Cannot create block device\n");
+   return ret;
+   }
+
+   bdesc = dev_get_uclass_plat(bdev);
+   dev_set_priv(bdev, mtd);
+   bdesc->bdev = bdev;
+   bdesc->part_type = PART_TYPE_MTD;
+
+   return 0;
+}
+
+static ulong mtd_blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
+ void *dst)
+{
+   struct blk_desc *block_dev = dev_get_uclass_plat(dev);
+   struct mtd_info *mtd = blk_desc_to_mtd(block_dev);
+   unsigned int sect_size = block_dev->blksz;
+   lbaint_t cur = start;
+   ulong read_cnt = 0;
+
+   while (read_cnt < blkcnt) {
+   int ret;
+   loff_t sect_start = cur * sect_size;
+   size_t retlen;
+
+   ret = mtd_read(mtd, sect_start, sect_size, &retlen, dst);
+   if (ret)
+   return ret;
+
+   if (retlen != sect_size) {
+   pr_err("mtdblock: failed to read block 0x" LBAF "\n", 
cur);
+   return -EIO;
+   }
+
+   cur++;
+   dst += sect_size;
+   read_cnt++;
+   }
+
+   return read_cnt;
+}
+
+static int mtd_erase_write(struct mtd_info *mtd, uint64_t start, const void 
*src)
+{
+   int ret;
+   size_t retlen;
+   struct erase_info erase = { 0 };
+
+   erase.mtd = mtd;
+   erase.addr = start;
+   erase.len = mtd->erasesize;
+
+   ret = mtd_erase(mtd, &erase);
+   if (ret)
+   re

[PATCH v5 1/3] disk: support MTD partitions

2024-06-04 Thread Alexey Romanov
Add new MTD partition driver, which can be useful with
mtdblock driver combination.

Signed-off-by: Alexey Romanov 
---
 disk/part.c   |  3 +-
 drivers/mtd/Kconfig   |  1 +
 drivers/mtd/mtdpart.c | 76 +++
 include/part.h|  3 ++
 4 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/disk/part.c b/disk/part.c
index 2bee669582..3f0fce5cfa 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -305,7 +305,8 @@ static void print_part_header(const char *type, struct 
blk_desc *desc)
CONFIG_IS_ENABLED(DOS_PARTITION) || \
CONFIG_IS_ENABLED(ISO_PARTITION) || \
CONFIG_IS_ENABLED(AMIGA_PARTITION) || \
-   CONFIG_IS_ENABLED(EFI_PARTITION)
+   CONFIG_IS_ENABLED(EFI_PARTITION) || \
+   CONFIG_IS_ENABLED(MTD_PARTITIONS)
printf("\nPartition Map for %s device %d  --   Partition Type: %s\n\n",
   uclass_get_name(desc->uclass_id), desc->devnum, type);
 #endif /* any CONFIG_..._PARTITION */
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 4fdc9645d0..e4e29e0a3c 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -2,6 +2,7 @@ menu "MTD Support"
 
 config MTD_PARTITIONS
bool
+   select PARTITIONS
 
 config MTD
bool "Enable MTD layer"
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 4886392a1c..826d235dc9 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -21,6 +21,8 @@
 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -1055,3 +1057,77 @@ uint64_t mtd_get_device_size(const struct mtd_info *mtd)
return mtd->size;
 }
 EXPORT_SYMBOL_GPL(mtd_get_device_size);
+
+static struct mtd_info *mtd_get_partition_by_index(struct mtd_info *mtd, int 
index)
+{
+   struct mtd_info *part;
+   int i = 0;
+
+   list_for_each_entry(part, &mtd->partitions, node)
+   if (i++ == index)
+   return part;
+
+   debug("Partition with idx=%d not found on MTD device %s\n", index, 
mtd->name);
+   return NULL;
+}
+
+static int __maybe_unused part_get_info_mtd(struct blk_desc *dev_desc, int 
part_idx,
+struct disk_partition *info)
+{
+   struct mtd_info *master = blk_desc_to_mtd(dev_desc);
+   struct mtd_info *part;
+
+   if (!master) {
+   debug("MTD device is NULL\n");
+   return -EINVAL;
+   }
+
+   part = mtd_get_partition_by_index(master, part_idx);
+   if (!part) {
+   debug("Failed to find partition with idx=%d\n", part_idx);
+   return -EINVAL;
+   }
+
+   snprintf(info->name, PART_NAME_LEN, part->name);
+   info->start = part->offset / dev_desc->blksz;
+   info->size = part->size / dev_desc->blksz;
+   info->blksz = dev_desc->blksz;
+
+   return 0;
+}
+
+static void __maybe_unused part_print_mtd(struct blk_desc *dev_desc)
+{
+   struct mtd_info *master = blk_desc_to_mtd(dev_desc);
+   struct mtd_info *part;
+
+   if (!master)
+   return;
+
+   list_for_each_entry(part, &master->partitions, node)
+   printf("- 0x%012llx-0x%012llx : \"%s\"\n",
+  part->offset, part->offset + part->size, part->name);
+}
+
+static int part_test_mtd(struct blk_desc *dev_desc)
+{
+   struct mtd_info *master = blk_desc_to_mtd(dev_desc);
+   ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
+
+   if (!master)
+   return -1;
+
+   if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
+   return -1;
+
+   return 0;
+}
+
+U_BOOT_PART_TYPE(mtd) = {
+   .name   = "MTD",
+   .part_type  = PART_TYPE_MTD,
+   .max_entries= MTD_ENTRY_NUMBERS,
+   .get_info   = part_get_info_ptr(part_get_info_mtd),
+   .print  = part_print_ptr(part_print_mtd),
+   .test   = part_test_mtd,
+};
diff --git a/include/part.h b/include/part.h
index 32ee404885..40419fdf2f 100644
--- a/include/part.h
+++ b/include/part.h
@@ -30,12 +30,15 @@ struct block_drvr {
 #define PART_TYPE_ISO  0x03
 #define PART_TYPE_AMIGA0x04
 #define PART_TYPE_EFI  0x05
+#define PART_TYPE_MTD  0x06
 
 /* maximum number of partition entries supported by search */
 #define DOS_ENTRY_NUMBERS  8
 #define ISO_ENTRY_NUMBERS  64
 #define MAC_ENTRY_NUMBERS  64
 #define AMIGA_ENTRY_NUMBERS8
+#define MTD_ENTRY_NUMBERS  64
+
 /*
  * Type string for U-Boot bootable partitions
  */
-- 
2.34.1



[PATCH v5 0/3] Introduce mtdblock device

2024-06-04 Thread Alexey Romanov
Hello!

This series adds support for the mtdblock device, which
allows to read/write data block by block. For example,
it can now be used for BCB or Android AB command:

  $ bcb load mtd 0 part_name

Tested only on SPI NAND, so bind is made only for
SPI NAND drivers.

---

Changes V1 -> V2 [1]:

  - Drop patch [2].
  - Add warning if bind NAND mtdblock device.
  - Move documentation of mtdblock implementation
from commit message to the source code.
  - Remove __maybe_unused from mtd partition functions
description.
  - Use blk_enabled() instead of #ifdefs.

Changes V2 -> V3 [2]:

  - Rebased over [3].
  - Rename mtd_bread/bwrite -> mtd_blk_read/write.
  - Fix GPL-2.0 license short name definiton in headers.
  - Add empty line after MTD_ENTRY_NUMBERS define.

Changes V3 -> V4 [4]:

  - Fix build warnings: use LBAF printf format string for lbaint_t types.

Changes V4 -> V5 [5]:

  - Rebased over u-boot/master.
  - Fix build errors and warnings if CONFIG_BLK isn't enabled.
  - Fix failed tests in cases is mtdblock device isn't binded.

Links:

  - [1] 
https://lore.kernel.org/all/20240227100441.1811047-1-avroma...@salutedevices.com/
  - [2] 
https://lore.kernel.org/all/20240227100441.1811047-5-avroma...@salutedevices.com/
  - [3] 
https://lore.kernel.org/u-boot/20240403114047.84030-1-heinrich.schucha...@canonical.com/T/#u
  - [4] 
https://lore.kernel.org/all/20240404105813.1520732-1-avroma...@salutedevices.com/
  - [5] 
https://lore.kernel.org/all/20240524102920.2631731-1-avroma...@salutedevices.com/

Alexey Romanov (3):
  disk: support MTD partitions
  drivers: introduce mtdblock abstraction
  spinand: bind mtdblock

 disk/part.c |   3 +-
 drivers/block/blk-uclass.c  |   1 +
 drivers/mtd/Kconfig |   1 +
 drivers/mtd/Makefile|   1 +
 drivers/mtd/mtdblock.c  | 227 
 drivers/mtd/mtdpart.c   |  76 
 drivers/mtd/nand/spi/core.c |  20 
 include/linux/mtd/mtd.h |  21 
 include/part.h  |   3 +
 9 files changed, 352 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/mtdblock.c

-- 
2.34.1



Fwd: A potential bug in das u-boot nfs implemnetation

2024-06-04 Thread jianqiang wang
Hi,

I sent this email to das u-boot one month ago, however, I haven't
gotten a reply yet. Do you know what happened?

Best

-- Forwarded message -
发件人: jianqiang wang 
Date: 2024年5月1日周三 16:14
Subject: A potential bug in das u-boot nfs implemnetation
To: 


Dear all

I found a potential bug in the das-boot network filesystem
implementation. I tried to mount a remote file system in U-boot.
However, it failed. I checked the network packet. The server said it
was a bad directory handler. After deeply checking the packet field, I
found that u-boot calculated the wrong length for the directory
handler and added it to the packet. After I commented line 381 in
net/nfs.c: *p++ = htonl(dirfh3_length); It worked. Please check if it
is a bug implementation.

Best regards


Re: [PATCH] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Quentin Schulz

Hi Mattijs,

On 6/4/24 2:04 PM, Mattijs Korpershoek wrote:

Hi Quentin,

On mar., juin 04, 2024 at 11:47, Quentin Schulz  
wrote:


Hi Mattijs,

On 6/3/24 11:11 AM, Mattijs Korpershoek wrote:

Fix some trivial typos found by browsing the code.
Done with flyspell.

Signed-off-by: Mattijs Korpershoek  > ---
   include/bootmeth.h | 12 ++--
   1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/bootmeth.h b/include/bootmeth.h
index 0fc36104ece0..529c4d813d82 100644
--- a/include/bootmeth.h
+++ b/include/bootmeth.h
@@ -40,7 +40,7 @@ struct bootmeth_ops {
/**
 * get_state_desc() - get detailed state information
 *
-* Prodecues a textual description of the state of the bootmeth. This
+* Produces a textual description of the state of the bootmeth. This
 * can include newline characters if it extends to multiple lines. It
 * must be a nul-terminated string.
 *
@@ -138,7 +138,7 @@ struct bootmeth_ops {
 * @dev:Bootmethod device to boot
 * @bflow:  Bootflow to boot
 * Return: does not return on success, since it should boot the
-*  Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
+*  Operating System. Returns -EFAULT if that fails, -ENOTSUPP if
 *  trying method resulted in finding out that is not actually
 *  supported for this boot and should not be tried again unless
 *  something changes, other -ve on other error
@@ -151,7 +151,7 @@ struct bootmeth_ops {
   /**
* bootmeth_get_state_desc() - get detailed state information
*
- * Prodecues a textual description of the state of the bootmeth. This
+ * Produces a textual description of the state of the bootmeth. This
* can include newline characters if it extends to multiple lines. It
* must be a nul-terminated string.


I see we have a mix of null-terminated and nul-terminated in the tree,
is the latter correct?


Thank you for your review.

I believe nul-terminated is correct: nul is the character, and null is the 
pointer.

See:
- https://news.ycombinator.com/item?id=22283217
- https://internals.rust-lang.org/t/null-consistency/16767



Ah, thanks for the pointers, makes much more sense to me now :)


I'll check the tree and submit another patch to fix this.




*
@@ -244,7 +244,7 @@ int bootmeth_read_file(struct udevice *dev, struct bootflow 
*bflow,
* @dev: Bootmethod device to use
* @bflow:   Bootflow to read
* Return: does not return on success, since it should boot the
- * Operating Systemn. Returns -EFAULT if that fails, other -ve on
+ * Operating System. Returns -EFAULT if that fails, other -ve on
*   other error
*/
   int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow);
@@ -255,7 +255,7 @@ int bootmeth_read_all(struct udevice *dev, struct bootflow 
*bflow);
* @dev: Bootmethod device to boot
* @bflow:   Bootflow to boot
* Return: does not return on success, since it should boot the
- * Operating Systemn. Returns -EFAULT if that fails, other -ve on
+ * Operating System. Returns -EFAULT if that fails, other -ve on
*   other error
*/
   int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
@@ -264,7 +264,7 @@ int bootmeth_boot(struct udevice *dev, struct bootflow 
*bflow);
* bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
*
* This sets up the ordering information in @iter, based on the selected
- * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is no
+ * ordering of the bootmeths in bootstd_priv->bootmeth_order. If there is no
* ordering there, then all bootmethods are added
*


Shouldn't this be bootmeths here as well?

(And there's another occurrence in boot/bootmeth-uclass.c


There seems indeed to be some inconsistencies around bootmeths versus
bootmethods.

To me, we should use 'bootmeth' everywhere.

Simon, as the maintainer of bootflow, do you agree ?

I can spin up another patch to fix this.



c.f. https://lore.kernel.org/u-boot/20211023232635.9195-1-...@chromium.org/

"""
For version 2, a new naming scheme is used as above:

   - bootdev is used instead of bootdevice, because 'device' is overused,
   is everywhere in U-Boot, can be confused with udevice
   - bootmeth - because 'method' is too vanilla, appears 1300 times in
   U-Boot
"""

SO I think we should change it to bootmeth(s) indeed.

Reviewed-by: Quentin Schulz 

Thanks,
Quentin


Re: [PATCH] bootstd: Fix a handful of doc typos in bootmeth

2024-06-04 Thread Mattijs Korpershoek
Hi Quentin,

On mar., juin 04, 2024 at 11:47, Quentin Schulz  
wrote:

> Hi Mattijs,
>
> On 6/3/24 11:11 AM, Mattijs Korpershoek wrote:
>> Fix some trivial typos found by browsing the code.
>> Done with flyspell.
>> 
>> Signed-off-by: Mattijs Korpershoek  > ---
>>   include/bootmeth.h | 12 ++--
>>   1 file changed, 6 insertions(+), 6 deletions(-)
>> 
>> diff --git a/include/bootmeth.h b/include/bootmeth.h
>> index 0fc36104ece0..529c4d813d82 100644
>> --- a/include/bootmeth.h
>> +++ b/include/bootmeth.h
>> @@ -40,7 +40,7 @@ struct bootmeth_ops {
>>  /**
>>   * get_state_desc() - get detailed state information
>>   *
>> - * Prodecues a textual description of the state of the bootmeth. This
>> + * Produces a textual description of the state of the bootmeth. This
>>   * can include newline characters if it extends to multiple lines. It
>>   * must be a nul-terminated string.
>>   *
>> @@ -138,7 +138,7 @@ struct bootmeth_ops {
>>   * @dev:Bootmethod device to boot
>>   * @bflow:  Bootflow to boot
>>   * Return: does not return on success, since it should boot the
>> - *  Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
>> + *  Operating System. Returns -EFAULT if that fails, -ENOTSUPP if
>>   *  trying method resulted in finding out that is not actually
>>   *  supported for this boot and should not be tried again unless
>>   *  something changes, other -ve on other error
>> @@ -151,7 +151,7 @@ struct bootmeth_ops {
>>   /**
>>* bootmeth_get_state_desc() - get detailed state information
>>*
>> - * Prodecues a textual description of the state of the bootmeth. This
>> + * Produces a textual description of the state of the bootmeth. This
>>* can include newline characters if it extends to multiple lines. It
>>* must be a nul-terminated string.
>
> I see we have a mix of null-terminated and nul-terminated in the tree,
> is the latter correct?

Thank you for your review.

I believe nul-terminated is correct: nul is the character, and null is the 
pointer.

See:
- https://news.ycombinator.com/item?id=22283217
- https://internals.rust-lang.org/t/null-consistency/16767

I'll check the tree and submit another patch to fix this.

>
>>*
>> @@ -244,7 +244,7 @@ int bootmeth_read_file(struct udevice *dev, struct 
>> bootflow *bflow,
>>* @dev:   Bootmethod device to use
>>* @bflow: Bootflow to read
>>* Return: does not return on success, since it should boot the
>> - *  Operating Systemn. Returns -EFAULT if that fails, other -ve on
>> + *  Operating System. Returns -EFAULT if that fails, other -ve on
>>* other error
>>*/
>>   int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow);
>> @@ -255,7 +255,7 @@ int bootmeth_read_all(struct udevice *dev, struct 
>> bootflow *bflow);
>>* @dev:   Bootmethod device to boot
>>* @bflow: Bootflow to boot
>>* Return: does not return on success, since it should boot the
>> - *  Operating Systemn. Returns -EFAULT if that fails, other -ve on
>> + *  Operating System. Returns -EFAULT if that fails, other -ve on
>>* other error
>>*/
>>   int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
>> @@ -264,7 +264,7 @@ int bootmeth_boot(struct udevice *dev, struct bootflow 
>> *bflow);
>>* bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
>>*
>>* This sets up the ordering information in @iter, based on the selected
>> - * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is 
>> no
>> + * ordering of the bootmeths in bootstd_priv->bootmeth_order. If there is no
>>* ordering there, then all bootmethods are added
>>*
>
> Shouldn't this be bootmeths here as well?
>
> (And there's another occurrence in boot/bootmeth-uclass.c

There seems indeed to be some inconsistencies around bootmeths versus
bootmethods.

To me, we should use 'bootmeth' everywhere.

Simon, as the maintainer of bootflow, do you agree ?

I can spin up another patch to fix this.

>
> Cheers,
> Quentin


Re: [PATCH 00/16] LoongArch initial support

2024-06-04 Thread Jiaxun Yang



在2024年5月23日五月 下午4:43,Tom Rini写道:
> On Thu, May 23, 2024 at 04:38:52PM +0100, Jiaxun Yang wrote:
>> 
>> 
>> 在2024年5月23日五月 下午4:25,Tom Rini写道:
>> > On Wed, May 22, 2024 at 04:34:43PM +0100, Jiaxun Yang wrote:
>> >
>> >> Hi all,
>> >> 
>> >> Sorry for flooding the mailing list recently, yet another huge RFC series 
>> >> ahead.
>> >> 
>> >> So after working on MIPS, arm64be and Xtensa I'm now on LoongArch, as 
>> >> suggested
>> >> by Heinrich.
>> >
>> > My big feedback here, and it applies to all of your other series as
>> > well, is to please update CI to make use of and test this. On the Docker
>> > side, update tools/docker/Dockerfile as needed. For Azure, you can tell
>> > it to use a different image and then follow the documentation on
>> > https://docs.u-boot.org/en/latest/develop/ci_testing.html and for GitLab
>> > you can at least use their "linter" to make sure that your additions
>> > have the correct syntax. Thanks.
>> 
>> Hi Tom,
>> 
>> Thanks for the feedback, I thought CI is for custodians only :-)
>> 
>> Do you mean I should include azure/gitlab pipeline file to create
>> pipeline for those new qemu targets?
>
> Yes, just like the rest of the QEMU targets.

Hi Tom,

I've got CI working on azure-pipeline for my arm64be, xtensa and LoongArch
work.

What is the best way to submit all these changes? I think I can send patches to
update Dockerfile and CI hooks first, then after new docker image being built
I'll combine CI related changes into these series and refresh all those series.

Will it work for you?

Thanks

>
> -- 
> Tom
>
> 附件:
> * signature.asc

-- 
- Jiaxun


Re: [PATCH 2/7] efi: Allow runtime relocate to be disabled

2024-06-04 Thread Jiaxun Yang



在2024年6月1日六月 下午5:37,Maciej W. Rozycki写道:
> On Tue, 21 May 2024, Jiaxun Yang wrote:
>
>> It's nearly impossible to run MIPS OS in virtual (or paged)
>> segment. All MIPS OS and bootloaders are running in KSEG/XKPHYS
>> segment, which directly mapping lower bits of virtual address
>> into physical address. So I suppose set_virtual_address_map
>> is unnecessary on MIPS because the mapping for U-Boot is
>> always here and can't be disabled in hardware.
>
>  Surely it's possible to run a MIPS OS kernel mapped via page tables, it 
> is what KSEG2 and XKSEG segments can be used for with 32-bit and 64-bit 
> configurations respectively.  Both CP0.Context and CP0.XContext registers 
> support placing page tables in virtual memory too, KSEG2 and XKSEG 
> segments respectively, and a nested TLB refill exception is supported.  
> Only the TLB exception handlers themselves obviously have to be unmapped.
>
>  These features have hardly ever been used (original MIPSCO OS reportedly 
> was an example, perhaps unsurprisingly), but they are there and it cannot 
> be stated that it is nearly impossible to make use of them.  It is not.
>
>  Note that the MIPS architecture does not have a real mode, but its 
> purpose is served by the unmapped segments, which are also convenient to 
> use for various reasons by OSes that otherwise do virtual addressing.
>
>  Also for the record there are SGI IP27 Linux configurations that run from 
> XKSEG rather than XKPHYS (running from KSEG2 used to be supported too, but 
> has been since dropped), via a wired page mapping.
>
>  I guess none of this really matters for U-Boot, but let's get the facts 
> straight so that people who are not MIPS experts are not led into false 
> understanding.
Hi Maciej,

Thanks for your insights!

I was trying to implement a mapped kernel on MIPS M5150 and faced many
many issues like wired entry + FTLB is not big enough to hold page table,
thus I came out with this conclusion.

Thanks for letting me know it's possible!

For U-Boot this is irrelevant as the main concern is whether KSEG0
is working after hand over control to OS. Disabling KSEG0 is impossible
without SegCtl.

Anyway, nice to have you here.

Thanks
>
>   Maciej

-- 
- Jiaxun


Re: [PATCH 2/2] xilinx: zynqmp: Enable reset_cpu() in SPL

2024-06-04 Thread Michal Simek




On 6/4/24 11:12, Lukas Funke wrote:

On 03.06.2024 17:08, Michal Simek wrote:



On 6/3/24 16:50, Lukas Funke wrote:

On 03.06.2024 16:32, Michal Simek wrote:



On 6/3/24 15:34, lukas.funke-...@weidmueller.com wrote:

From: Lukas Funke 

This commit enables SPL to reset the CPU via PMU-firmware. The usual
reset mechanism requires bl31 to be loaded which may not be the case in
SPL.

Signed-off-by: Lukas Funke 
---

  board/xilinx/zynqmp/zynqmp.c | 9 +
  1 file changed, 9 insertions(+)

diff --git a/board/xilinx/zynqmp/zynqmp.c b/board/xilinx/zynqmp/zynqmp.c
index 95a134b972d..99f5c178c1d 100644
--- a/board/xilinx/zynqmp/zynqmp.c
+++ b/board/xilinx/zynqmp/zynqmp.c
@@ -40,6 +40,7 @@
  #include 
  #include 
  #include 
+#include 
  #include "../common/board.h"
  #include "pm_cfg_obj.h"
@@ -285,6 +286,14 @@ int dram_init(void)
  #if !CONFIG_IS_ENABLED(SYSRESET)
  void reset_cpu(void)
  {
+    if (!CONFIG_IS_ENABLED(ZYNQMP_FIRMWARE)) {
+    log_warning("reset failed: ZYNQMP_FIRMWARE disabled");
+    return;
+    }
+
+    xilinx_pm_request(PM_RESET_ASSERT,
+  ZYNQMP_PM_RESET_START + ZYNQMP_RESET_SOFT,
+  PM_RESET_ACTION_ASSERT, 0, 0, NULL);


If you disable ZYNQMP_FIRMWARE xilinx_pm_request() should fail.

we should likely fix it in drivers/mmc/zynq_sdhci.c:114


That's an odd place for a default implementation. I'd like to move the 
functions to a common location but I've no idea where. That's probably why 
the last developer moved it here. Any suggestions?


static inline to include/zynqmp_firmware.h?


Sound like the right place.

Currently zynqmp is not buildable when disabling CONFIG_ZYNQMP_FIRMWARE. I'm not 
sure if it even makes sense to disable it. Maybe this should be enforced!?


However, I'll drop the 1/2 patch and convert 'CONFIG_IS_ENABLED' to 'IS_ENABLED' 
in v2 to get finish this series. Refactoring should be addressed in another series.


In past it was mandatory and then it was changed by this patch because mini 
u-boot configurations don't need it.


commit 71efd45a5fc70e29e391e0b57c700de8708ae6d9
Author: Michal Simek 
AuthorDate: Fri Jan 14 13:08:42 2022 +0100
Commit: Michal Simek 
CommitDate: Wed Jan 19 11:36:11 2022 +0100

arm64: zynqmp: Change firmware dependency

In case of mini U-Boot configurations there is no need to enable firmware
driver which just consume space for nothing. That's why add an option to
disable it.

Signed-off-by: Michal Simek 
Link: 
https://lore.kernel.org/r/d439399160ff3374f2b39f54f7dd70fa8c8bfea0.1642162121.git.michal.si...@xilinx.com


Back to your question. Even if we skip mini u-boot cases there could be still 
value not to use firmware interface but it is not tested or used at this stage. 
But if you simply used fixed clocks it should be possible to use it.


That's why imply has been used not to force everybody to use it but also it is 
necessary to say that I don't want to block others to do it.


Thanks,
Michal


Re: [PATCH 1/1] usb: Assimilate usb_get_descriptor() to linux

2024-06-04 Thread Philip Oberfichtner
Good point. See V2.

On Fri, May 17, 2024 at 11:16:19PM +0200, Marek Vasut wrote:
> On 5/17/24 11:18 AM, Philip Oberfichtner wrote:
> > Before this commit, usb_get_descriptor() failed for some flakey USB
> > devices. We hereby adopt the more robust linux implementation [1].
> 
> Can you include which exact device fails and how? Details of the failure are
> valuable for the next person who runs into such a bug. Search engines index
> the ML posts too, so they become searchable using those.
> 
> Which kernel version is this imported from ? Commit ID would be good to add.
> 
> [...]

-- 
=
DENX Software Engineering GmbH,Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-22  Fax: +49-8142-66989-80   Email: p...@denx.de
=


  1   2   >