[PATCH v2] board: rockchip: Add rk3588 evb

2023-03-01 Thread Kever Yang
rk3588 evb1 v10 is a evalution board from Rockchip, it is a dev board for
rockchip and also a reference board for board vendors.

Hardware:
SoC: RK3588
DRAM: LPDDR4X 8GB
Debug: UART2 via USB
PCIe: 3x4 *1
SATA *2
HDMI out *2
HDMI IN *1
USB2.0 Host *2
USB3.0 Host *1
Type C *1
MIPI DSI panel

dts Sync from Linux v6.2.

Signed-off-by: Kever Yang 
---

Changes in v2:
- Use the same dts name as kernel

 arch/arm/dts/Makefile|   1 +
 arch/arm/dts/rk3588-evb1-v10-u-boot.dtsi |  21 
 arch/arm/dts/rk3588-evb1-v10.dts | 129 +++
 arch/arm/mach-rockchip/rk3588/Kconfig|   7 ++
 board/rockchip/evb_rk3588/Kconfig|  15 +++
 board/rockchip/evb_rk3588/MAINTAINERS|   7 ++
 board/rockchip/evb_rk3588/Makefile   |   6 ++
 board/rockchip/evb_rk3588/evb-rk3588.c   |  39 +++
 configs/evb-rk3588_defconfig |  69 
 doc/board/rockchip/rockchip.rst  |  10 ++
 include/configs/evb_rk3588.h |  15 +++
 11 files changed, 319 insertions(+)
 create mode 100644 arch/arm/dts/rk3588-evb1-v10-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3588-evb1-v10.dts
 create mode 100644 board/rockchip/evb_rk3588/Kconfig
 create mode 100644 board/rockchip/evb_rk3588/MAINTAINERS
 create mode 100644 board/rockchip/evb_rk3588/Makefile
 create mode 100644 board/rockchip/evb_rk3588/evb-rk3588.c
 create mode 100644 configs/evb-rk3588_defconfig
 create mode 100644 include/configs/evb_rk3588.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index c160e884bf6..f854c092893 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -171,6 +171,7 @@ dtb-$(CONFIG_ROCKCHIP_RK3568) += \
 
 dtb-$(CONFIG_ROCKCHIP_RK3588) += \
rk3588-edgeble-neu6a-io.dtb \
+   rk3588-evb1-v10.dtb \
rk3588-rock-5b.dtb
 
 dtb-$(CONFIG_ROCKCHIP_RV1108) += \
diff --git a/arch/arm/dts/rk3588-evb1-v10-u-boot.dtsi 
b/arch/arm/dts/rk3588-evb1-v10-u-boot.dtsi
new file mode 100644
index 000..bd2e2594863
--- /dev/null
+++ b/arch/arm/dts/rk3588-evb1-v10-u-boot.dtsi
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2023 Rockchip Electronics Co., Ltd.
+ */
+
+#include "rk3588-u-boot.dtsi"
+
+/ {
+   aliases {
+   mmc0 = 
+   mmc1 = 
+   };
+
+   chosen {
+   u-boot,spl-boot-order = 
+   };
+};
+
+ {
+   bootph-all;
+};
diff --git a/arch/arm/dts/rk3588-evb1-v10.dts b/arch/arm/dts/rk3588-evb1-v10.dts
new file mode 100644
index 000..b91af0204db
--- /dev/null
+++ b/arch/arm/dts/rk3588-evb1-v10.dts
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
+ *
+ */
+
+/dts-v1/;
+
+#include 
+#include 
+#include "rk3588.dtsi"
+
+/ {
+   model = "Rockchip RK3588 EVB1 V10 Board";
+   compatible = "rockchip,rk3588-evb1-v10", "rockchip,rk3588";
+
+   aliases {
+   mmc0 = 
+   serial2 = 
+   };
+
+   chosen {
+   stdout-path = "serial2:150n8";
+   };
+
+   backlight: backlight {
+   compatible = "pwm-backlight";
+   power-supply = <_dcin>;
+   pwms = < 0 25000 0>;
+   };
+
+   vcc12v_dcin: vcc12v-dcin-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc12v_dcin";
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <1200>;
+   regulator-max-microvolt = <1200>;
+   };
+
+   vcc5v0_sys: vcc5v0-sys-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc5v0_sys";
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   vin-supply = <_dcin>;
+   };
+};
+
+ {
+   clock_in_out = "output";
+   phy-handle = <_phy>;
+   phy-mode = "rgmii-rxid";
+   pinctrl-0 = <_miim
+_tx_bus2
+_rx_bus2
+_rgmii_clk
+_rgmii_bus>;
+   pinctrl-names = "default";
+   rx_delay = <0x00>;
+   tx_delay = <0x43>;
+   status = "okay";
+};
+
+ {
+   status = "okay";
+
+   hym8563: rtc@51 {
+   compatible = "haoyu,hym8563";
+   reg = <0x51>;
+   #clock-cells = <0>;
+   clock-output-names = "hym8563";
+   pinctrl-names = "default";
+   pinctrl-0 = <_int>;
+   interrupt-parent = <>;
+   interrupts = ;
+   wakeup-source;
+   };
+};
+
+ {
+   rgmii_phy: ethernet-phy@1 {
+   /* RTL8211F */
+   compatible = "ethernet-phy-id001c.c916";
+   reg = <0x1>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_rst>;
+   

Re: [RFC PATCH 1/1] eficonfig: Add a 'scan-only' mode in eficonfig

2023-03-01 Thread AKASHI Takahiro
On Thu, Mar 02, 2023 at 11:21:05AM +0900, Masahisa Kojima wrote:
> Hi Ilias,
> 
> On Wed, 1 Mar 2023 at 23:44, Ilias Apalodimas
>  wrote:
> >
> > eficonfig will automatically scan and add Boot variables on launch.
> > It will also perform automatic management of the automatically added
> > variables (e.g it might decide to delete a boot option if the DP
> > disappears).  This functionality is useful outside the context of
> > eficonfig as well.
> >
> > So let's add a -a flag to eficonfig that will only perform the
> > automatic variable management and exit.  That would allow users
> > to define a bootcmd along the lines of 'eficonfig -a && bootefi bootmgr',
> > that matches the §3.5.1.1 'Removable Media Boot Behavior' behaviour
> > described in the EFI spec.
> >
> > Open questions:
> > - Is this ok to add on eficonfig? Similar functionality is described in the 
> > EFI
> >   spec as part of the efibootmgr
> > - Having the functionality on the command gives us the flexibility to run 
> > the
> >   run the command when needed.  Alternatively we could move it to the 
> > efibootmgr
> >   and hide it behing a Kconfig option
> 
> In current implementation, "bootmenu" and "eficonfig" invoke this
> automatic load option
> management function, but I think "bootmenu" should not have responsibility for
> load option management.
> So I'll vote for moving this automatic load option management into efibootmgr,
> then it is invoked in efi subsystem initialization.

Basically +1, but
I think that we can implement this kind of action by using 'event' hook
as "removable media support" itself is implemented.

-Takahiro Akashi


> Regards,
> Masahisa Kojima
> 
> > Signed-off-by: Ilias Apalodimas 
> > ---
> >  cmd/eficonfig.c | 23 ---
> >  1 file changed, 20 insertions(+), 3 deletions(-)
> >
> > diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
> > index 720f52b48b8c..9b6631816997 100644
> > --- a/cmd/eficonfig.c
> > +++ b/cmd/eficonfig.c
> > @@ -2693,10 +2693,18 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int 
> > flag, int argc, char *const a
> >  {
> > efi_status_t ret;
> > struct efimenu *efi_menu;
> > +   bool exit_on_scan = false;
> >
> > -   if (argc > 1)
> > +   if (argc > 2)
> > return CMD_RET_USAGE;
> >
> > +   if (argc > 1) {
> > +   if (!strcmp(argv[1], "-a"))
> > +   exit_on_scan = true;
> > +   else
> > +   return CMD_RET_FAILURE;
> > +   }
> > +
> > ret = efi_init_obj_list();
> > if (ret != EFI_SUCCESS) {
> > log_err("Error: Cannot initialize UEFI sub-system, r = 
> > %lu\n",
> > @@ -2713,6 +2721,9 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int 
> > flag, int argc, char *const a
> > if (ret != EFI_SUCCESS && ret != EFI_NOT_FOUND)
> > return ret;
> >
> > +   if (exit_on_scan)
> > +   return EFI_SUCCESS;
> > +
> > while (1) {
> > efi_menu = 
> > eficonfig_create_fixed_menu(maintenance_menu_items,
> >
> > ARRAY_SIZE(maintenance_menu_items));
> > @@ -2734,8 +2745,14 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int 
> > flag, int argc, char *const a
> > return CMD_RET_SUCCESS;
> >  }
> >
> > +static char eficonfig_help_text[] =
> > +   " - UEFI menu to configure UEFI variables\n"
> > +   "\n"
> > +   "eficonfig - Spawn the configuration menu\n"
> > +   "  -a Scan, configure Boot variables and exit\n";
> > +
> >  U_BOOT_CMD(
> > -   eficonfig, 1, 0, do_eficonfig,
> > +   eficonfig, 2, 0, do_eficonfig,
> > "provide menu-driven UEFI variable maintenance interface",
> > -   ""
> > +   eficonfig_help_text
> >  );
> > --
> > 2.39.2
> >


Re: [PATCH V7 04/15] iot2050: Migrate settings into board env file

2023-03-01 Thread Jan Kiszka
On 02.03.23 00:38, Simon Glass wrote:
> Hi Jan,
> 
> On Tue, 28 Feb 2023 at 11:20, Jan Kiszka  wrote:
>>
>> From: Jan Kiszka 
>>
>> Anything that is not boot-env related is better kept there by now.
>>
>> At this chance, also drop a stale comment from iot2050.h
>>
>> Signed-off-by: Jan Kiszka 
>> ---
>>  board/siemens/iot2050/iot2050.env |  9 +
>>  include/configs/iot2050.h | 11 ++-
>>  2 files changed, 11 insertions(+), 9 deletions(-)
>>  create mode 100644 board/siemens/iot2050/iot2050.env
>>
>> diff --git a/board/siemens/iot2050/iot2050.env 
>> b/board/siemens/iot2050/iot2050.env
>> new file mode 100644
>> index 000..4bd93f0b2f4
>> --- /dev/null
>> +++ b/board/siemens/iot2050/iot2050.env
>> @@ -0,0 +1,9 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Copyright (c) Siemens AG, 2023
>> + *
>> + * Authors:
>> + *   Jan Kiszka 
>> + */
>> +
>> +usb_pgood_delay=900
>> diff --git a/include/configs/iot2050.h b/include/configs/iot2050.h
>> index cfff46ce339..8dfeaddf541 100644
>> --- a/include/configs/iot2050.h
>> +++ b/include/configs/iot2050.h
>> @@ -13,12 +13,6 @@
>>
>>  #include 
>>
>> -/* SPL Loader Configuration */
>> -
>> -/* U-Boot general configuration */
>> -#define EXTRA_ENV_IOT2050_BOARD_SETTINGS   \
>> -   "usb_pgood_delay=900\0"
>> -
>>  #if IS_ENABLED(CONFIG_CMD_USB)
>>  # define BOOT_TARGET_USB(func) \
>> func(USB, usb, 0) \
>> @@ -40,10 +34,9 @@
>>
>>  #include 
>>
>> -#define CFG_EXTRA_ENV_SETTINGS \
>> +#define CFG_EXTRA_ENV_SETTINGS \
>> DEFAULT_LINUX_BOOT_ENV  \
>> -   BOOTENV \
>> -   EXTRA_ENV_IOT2050_BOARD_SETTINGS
>> +   BOOTENV
>>
>>  #include 
>>
>> --
>> 2.35.3
>>
> 
> You might want to move to standard boot so you can use a text-based
> environment. See for example [1] [2] and later patches from [3].
> 

Err, this patch is about introducing a text-based env for the parts that
can be moved. I don't see a relevant delta after this patch to the
referenced examples (btw, [2] is missing).

Jan

> Regards,
> Simon
> 
> [1] https://patchwork.ozlabs.org/project/uboot/list/?series=342718
> [2]
> [3] from 
> https://patchwork.ozlabs.org/project/uboot/list/?series=338993=*

-- 
Siemens AG, Technology
Competence Center Embedded Linux



Re: [PATCH V7 15/15] iot2050: Add support for configuring M.2 connector

2023-03-01 Thread Jan Kiszka
On 02.03.23 00:38, Simon Glass wrote:
> Hi Jan,
> 
> On Tue, 28 Feb 2023 at 11:23, Jan Kiszka  wrote:
>>
>> From: Jan Kiszka 
>>
>> The M.2 slots of the related IOT2050 variant need to be configured
>> according to the plugged cards. This tries to detect the card using the
>> M.2 configuration pins of the B-key slot. If that fails, a U-Boot
>> environment variable can be set to configure manually. This variable is
>> write-permitted also in secure boot mode as it is not able to undermine
>> the integrity of the booted system.
>>
>> The configuration is then applied to mux the serdes and to fix up the
>> device tree passed to or loaded by the bootloader. The fix-ups are
>> coming from device tree overlays that are embedded into the firmware
>> image and there also integrity protected. The OS remains free to load
>> a device tree to which they do not apply: U-Boot will not fail to boot
>> in that case.
>>
>> Based on original patch by Chao Zeng.
>>
>> Signed-off-by: Jan Kiszka 
>> ---
>>  arch/arm/dts/Makefile |   4 +-
>>  arch/arm/dts/k3-am65-iot2050-boot-image.dtsi  |  38 ++-
>>  ...050-advanced-m2-bkey-ekey-pcie-overlay.dts |  27 ++
>>  ...-iot2050-advanced-m2-bkey-usb3-overlay.dts |  47 
>>  board/siemens/iot2050/board.c | 259 +-
>>  doc/board/siemens/iot2050.rst |  18 ++
>>  include/configs/iot2050.h |   1 +
>>  7 files changed, 391 insertions(+), 3 deletions(-)
>>  create mode 100644 
>> arch/arm/dts/k3-am6548-iot2050-advanced-m2-bkey-ekey-pcie-overlay.dts
>>  create mode 100644 
>> arch/arm/dts/k3-am6548-iot2050-advanced-m2-bkey-usb3-overlay.dts
> 
> There is an 'extension' command and associated infra available.

To my understanding, this is about scripting, open-coding extension
detection and overlay application. Here we are making this automatic.
Also, we are not really detecting an extension board, more the used
connector. struct extension therefore does not really fit.

> Also
> there is sysinfo. I just wanted to check if either of those is helpful
> here.

This might save a handful of lines of own code around gpio parsing. We
will have a look on top of this.

Thanks,
Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux



Re: [PATCH v2 3/5] usb: xhci-mtk: modify the SOF/ITP interval for mt8195

2023-03-01 Thread 云春峰
Hi Marek,

On Fri, 2023-02-17 at 14:35 +0100, Marek Vasut wrote:
> On 2/17/23 10:04, Chunfeng Yun wrote:
> > There are 4 USB controllers on MT8195, the controllers (IP1~IP3,
> > exclude IP0) have a wrong default SOF/ITP interval which is
> > calculated from the frame counter clock 24Mhz by default, but
> > in fact, the frame counter clock is 48Mhz, so we shall set the
> > accurate interval according to 48Mhz for those controllers.
> > 
> > Note:
> > The first controller no need set it, but if set it, shall change
> > tphy's pll at the same time.
> > 
> > Signed-off-by: Chunfeng Yun 
> 
> Reviewed-by: Marek Vasut 
> 
> Feel free to pull the entire series via mediatek tree, so it would go
> in 
> together.
Could you help to apply this series patch, seems no mediatek tree,
thanks a lot



Re: [PATCH v2 4/4] mkeficapsule: add FMP Payload Header

2023-03-01 Thread Takahiro Akashi
On Wed, Mar 01, 2023 at 06:15:22PM +0900, Masahisa Kojima wrote:
> Current mkeficapsule tool does not provide firmware
> version management. EDK2 reference implementation inserts
> the FMP Payload Header right before the payload.
> It coutains the fw_version and lowest supported version.
> 
> This commit adds three new parameters required to generate
> the FMP Payload Header for mkeficapsule tool.
>  '-f' indicates whether FMP Payload Header is inserted.
>  '-v' indicates the firmware version.
>  '-l' indicates the lowest supported version.

from user's point of view, '-f' looks redundant since '-v' or '-l'
implicitly means '-f'.

> When mkeficapsule tool is invoked without '-f' option,
> FMP Payload Header is not inserted, the behavior is same as
> current implementation.
> 
> Signed-off-by: Masahisa Kojima 
> ---
> Newly created in v2
> 
>  tools/mkeficapsule.c | 81 
>  1 file changed, 75 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
> index b71537beee..e0a6948df8 100644
> --- a/tools/mkeficapsule.c
> +++ b/tools/mkeficapsule.c
> @@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";
>  efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
>  efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
>  
> -static const char *opts_short = "g:i:I:v:p:c:m:o:dhAR";
> +static const char *opts_short = "g:i:I:v:l:p:c:m:o:dfhAR";
>  
>  enum {
>   CAPSULE_NORMAL_BLOB = 0,
> @@ -41,6 +41,9 @@ static struct option options[] = {
>   {"guid", required_argument, NULL, 'g'},
>   {"index", required_argument, NULL, 'i'},
>   {"instance", required_argument, NULL, 'I'},
> + {"fmp-payload-header", no_argument, NULL, 'f'},
> + {"fw-version", required_argument, NULL, 'v'},
> + {"lsv", required_argument, NULL, 'l'},
>   {"private-key", required_argument, NULL, 'p'},
>   {"certificate", required_argument, NULL, 'c'},
>   {"monotonic-count", required_argument, NULL, 'm'},
> @@ -60,6 +63,9 @@ static void print_usage(void)
>   "\t-g, --guid guid for image blob type\n"
>   "\t-i, --index  update image index\n"
>   "\t-I, --instanceupdate hardware instance\n"
> + "\t-f, --fmp-payload-headerinsert fmp payload header\n"
> + "\t-v, --fw-version   firmware version\n"
> + "\t-l, --lsv  lowest supported version\n"
>   "\t-p, --private-key   private key file\n"
>   "\t-c, --certificate  signer's certificate 
> file\n"
>   "\t-m, --monotonic-count  monotonic count\n"
> @@ -71,6 +77,30 @@ static void print_usage(void)
>   tool_name);
>  }
>  
> +#define SIGNATURE_16(A, B)   ((A) | ((B) << 8))
> +#define SIGNATURE_32(A, B, C, D) \
> + (SIGNATURE_16(A, B) | (SIGNATURE_16(C, D) << 16))
> +
> +#define FMP_PAYLOAD_HDR_SIGNATURESIGNATURE_32('M', 'S', 'S', '1')
> +
> +/**
> + * struct fmp_payload_header - EDK2 header for the FMP payload
> + *
> + * This structure describes the header which is preprended to the
> + * FMP payload by the edk2 capsule generation scripts.
> + *
> + * @signature:   Header signature used to identify the 
> header
> + * @header_size: Size of the structure
> + * @fw_version:  Firmware versions used
> + * @lowest_supported_version:Lowest supported version
> + */
> +struct fmp_payload_header {
> + uint32_t signature;
> + uint32_t header_size;
> + uint32_t fw_version;
> + uint32_t lowest_supported_version;
> +};
> +
>  /**
>   * auth_context - authentication context
>   * @key_file:Path to a private key file
> @@ -95,6 +125,12 @@ struct auth_context {
>   size_t sig_size;
>  };
>  
> +struct fmp_payload_header_params {
> + bool have_header;
> + uint32_t fw_version;
> + uint32_t lowest_supported_version;
> +};
> +

You may put those definitions in tools/eficapsule.h.

>  static int dump_sig;
>  
>  /**
> @@ -402,6 +438,7 @@ static void free_sig_data(struct auth_context *ctx)
>   */
>  static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
>   unsigned long index, unsigned long instance,
> + struct fmp_payload_header_params *fmp_ph_params,
>   uint64_t mcount, char *privkey_file, char *cert_file,
>   uint16_t oemflags)
>  {
> @@ -410,10 +447,11 @@ static int create_fwbin(char *path, char *bin, 
> efi_guid_t *guid,
>   struct efi_firmware_management_capsule_image_header image;
>   struct auth_context auth_context;
>   FILE *f;
> - uint8_t *data;
> + uint8_t *data, *new_data, *buf;
>   off_t bin_size;
>   uint64_t offset;
>   int ret;
> + struct fmp_payload_header payload_header;
>  
>  #ifdef DEBUG
>   fprintf(stderr, "For output: %s\n", path);
> @@ -423,6 +461,7 @@ static 

Re: [PATCH v2 2/4] efi_loader: versioning support in GetImageInfo

2023-03-01 Thread Takahiro Akashi
On Wed, Mar 01, 2023 at 06:15:20PM +0900, Masahisa Kojima wrote:
> Current FMP->GetImageInfo() always return 0 for the firmware
> version, user can not identify which firmware version is currently
> running through the EFI interface.
> 
> This commit reads the "FmpState" EFI variable, then fills the
> firmware version, lowest supported version, last attempt version
> and last attempt status in FMP->GetImageInfo().
> 
> Now FMP->GetImageInfo() and ESRT have the meaningful version number.
> 
> Signed-off-by: Masahisa Kojima 
> ---
> No update since v1
> 
>  lib/efi_loader/efi_firmware.c | 30 ++
>  1 file changed, 26 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
> index d1afafb052..ead20fa914 100644
> --- a/lib/efi_loader/efi_firmware.c
> +++ b/lib/efi_loader/efi_firmware.c
> @@ -173,13 +173,38 @@ static efi_status_t efi_fill_image_desc_array(
>   *package_version_name = NULL; /* not supported */
>  
>   for (i = 0; i < num_image_type_guids; i++) {
> + u16 varname[13]; /* u"FmpState" */
> + efi_status_t ret;
> + efi_uintn_t size;
> + struct fmp_state var_state = { 0 };
> +
>   image_info[i].image_index = fw_array[i].image_index;
>   image_info[i].image_type_id = fw_array[i].image_type_id;
>   image_info[i].image_id = fw_array[i].image_index;
>  
>   image_info[i].image_id_name = fw_array[i].fw_name;
>  
> - image_info[i].version = 0; /* not supported */
> + efi_create_indexed_name(varname, sizeof(varname), "FmpState",
> + fw_array[i].image_index);

Don't we have to think of the systems where multiple FMP drivers are
used? In those cases, 'image_index' doesn't work as an unique ID.
It is unlikely under the current code, but we should consider
any future extension.

-Takahiro Akashi


> + size = sizeof(var_state);
> + ret = efi_get_variable_int(varname, _guid_fmp_state, NULL,
> +, _state, NULL);
> + if (ret == EFI_SUCCESS) {
> + image_info[i].version = var_state.fw_version;
> + image_info[i].lowest_supported_image_version =
> + var_state.lowest_supported_version;
> + image_info[i].last_attempt_version =
> + var_state.last_attempt_version;
> + image_info[i].last_attempt_status =
> + var_state.last_attempt_status;
> + } else {
> + image_info[i].version = 0;
> + image_info[i].lowest_supported_image_version = 0;
> + image_info[i].last_attempt_version = 0;
> + image_info[i].last_attempt_status =
> + LAST_ATTEMPT_STATUS_SUCCESS;
> + }
> +
>   image_info[i].version_name = NULL; /* not supported */
>   image_info[i].size = 0;
>   image_info[i].attributes_supported =
> @@ -193,9 +218,6 @@ static efi_status_t efi_fill_image_desc_array(
>   image_info[0].attributes_setting |=
>   IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED;
>  
> - image_info[i].lowest_supported_image_version = 0;
> - image_info[i].last_attempt_version = 0;
> - image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS;
>   image_info[i].hardware_instance = 1;
>   image_info[i].dependencies = NULL;
>   }
> -- 
> 2.17.1
> 


Re: [PATCH v2 1/4] efi_loader: store firmware version into FmpState variable

2023-03-01 Thread Takahiro Akashi
On Wed, Mar 01, 2023 at 06:15:19PM +0900, Masahisa Kojima wrote:
> Firmware version management is not implemented in the current
> FMP protocol.
> EDK2 reference implementation capsule generation script inserts
> the FMP Payload Header right before the payload, it contains the
> firmware version and lowest supported version.
> 
> This commit utilizes the FMP Payload Header, read the header and
> stores the firmware version, lowest supported version,
> last attempt version and last attempt status into "FmpState"
> EFI non-volatile variable.  indicates the image index,
> since FMP protocol handles multiple image indexes.
> 
> This change is compatible with the existing FMP implementation.
> This change does not mandate the FMP Payload Header.
> If no FMP Payload Header is found in the capsule file, fw_version,
> lowest supported version, last attempt version and last attempt
> status is 0 and this is the same behavior as existing FMP
> implementation.
> 
> Signed-off-by: Masahisa Kojima 
> ---
> Changes in v2:
> - modify indent
> 
>  lib/efi_loader/efi_firmware.c | 198 ++
>  1 file changed, 175 insertions(+), 23 deletions(-)
> 
> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
> index 93e2b01c07..d1afafb052 100644
> --- a/lib/efi_loader/efi_firmware.c
> +++ b/lib/efi_loader/efi_firmware.c
> @@ -10,6 +10,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -18,6 +19,12 @@
>  
>  #define FMP_PAYLOAD_HDR_SIGNATURESIGNATURE_32('M', 'S', 'S', '1')
>  
> +#define EFI_FMP_STATE_GUID \
> + EFI_GUID(0x84bed885, 0x193a, 0x403f, 0xa2, 0x78, \
> +  0xe8, 0x9e, 0x23, 0x8a, 0xd6, 0xe1)
> +
> +static const efi_guid_t efi_guid_fmp_state = EFI_FMP_STATE_GUID;
> +
>  /**
>   * struct fmp_payload_header - EDK2 header for the FMP payload
>   *
> @@ -36,6 +43,24 @@ struct fmp_payload_header {
>   u32 lowest_supported_version;
>  };
>  
> +/**
> + * struct fmp_state - fmp firmware update state
> + *
> + * This structure describes the state of the firmware update
> + * through FMP protocol.
> + *
> + * @fw_version:  Firmware versions used
> + * @lowest_supported_version:Lowest supported version
> + * @last_attempt_version:Last attempt version
> + * @last_attempt_status: Last attempt status
> + */
> +struct fmp_state {
> + u32 fw_version;
> + u32 lowest_supported_version;
> + u32 last_attempt_version;
> + u32 last_attempt_status;
> +};
> +
>  __weak void set_dfu_alt_info(char *interface, char *devstr)
>  {
>   env_set("dfu_alt_info", update_info.dfu_string);
> @@ -182,6 +207,7 @@ static efi_status_t efi_fill_image_desc_array(
>   * efi_firmware_capsule_authenticate - authenticate the capsule if enabled
>   * @p_image: Pointer to new image
>   * @p_image_size:Pointer to size of new image
> + * @statePointer to fmp state
>   *
>   * Authenticate the capsule if authentication is enabled.
>   * The image pointer and the image size are updated in case of success.
> @@ -190,12 +216,11 @@ static efi_status_t efi_fill_image_desc_array(
>   */
>  static
>  efi_status_t efi_firmware_capsule_authenticate(const void **p_image,
> -efi_uintn_t *p_image_size)
> +efi_uintn_t *p_image_size,
> +struct fmp_state *state)
>  {
>   const void *image = *p_image;
>   efi_uintn_t image_size = *p_image_size;
> - u32 fmp_hdr_signature;
> - struct fmp_payload_header *header;
>   void *capsule_payload;
>   efi_status_t status;
>   efi_uintn_t capsule_payload_size;
> @@ -209,8 +234,12 @@ efi_status_t efi_firmware_capsule_authenticate(const 
> void **p_image,
>  
>   if (status == EFI_SECURITY_VIOLATION) {
>   printf("Capsule authentication check failed. Aborting 
> update\n");
> + state->last_attempt_status =
> + LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR;
>   return status;
>   } else if (status != EFI_SUCCESS) {
> + state->last_attempt_status =
> + LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
>   return status;
>   }
>  
> @@ -222,24 +251,124 @@ efi_status_t efi_firmware_capsule_authenticate(const 
> void **p_image,
>   debug("Updating capsule without authenticating.\n");
>   }
>  
> - fmp_hdr_signature = FMP_PAYLOAD_HDR_SIGNATURE;
> - header = (void *)image;
> + *p_image = image;
> + *p_image_size = image_size;
> +
> + return EFI_SUCCESS;
> +}
> +
> +/**
> + * efi_firmware_set_fmp_state_var - set FmpState variable
> + * @state:   Pointer to fmp state
> + * @image_index: image index
> + * @updated: flag to indicate firmware update is successful
> + *

Re: [PATCH v2 5/6] Kconfig: j721e: Change K3_MCU_SCRATCHPAD_BASE to non firewalled region

2023-03-01 Thread Manorit Chawdhry
On 10:47-20230301, Tom Rini wrote:
> On Wed, Mar 01, 2023 at 03:01:30PM +0530, Manorit Chawdhry wrote:
> 
> > In non-combined boot flow for K3, all the firewalls are locked by default
> > until sysfw comes up. Rom configures some of the firewall for its usage
> > along with the SRAM for R5 but the PSRAM region is still locked.
> > 
> > The K3 MCU Scratchpad for j721e was set to a PSRAM region triggering the
> > firewall exception before sysfw came up. The exception started happening
> > after adding multi dtb support that accesses the scratchpad for reading
> > EEPROM contents.
> > 
> > The commit changes R5 MCU scratchpad for j721e to an SRAM region.
> > 
> > Old Map:
> > ┌─┐ 0x41c0
> > │ SPL │
> > ├─┤ 0x41c4 (approx)
> > │STACK│
> > ├─┤ 0x41c85b20
> > │ Global data │
> > │  sizeof(struct global_data) = 0xd8  │
> > ├─┤ gd->malloc_base = 0x41c85bfc
> > │HEAP │
> > │  CONFIG_SYS_MALLOC_F_LEN = 0x7  │
> > ├─┤ CONFIG_SPL_BSS_START_ADDR
> > │   SPL BSS   │ (0x41cf5bfc)
> > │  CONFIG_SPL_BSS_MAX_SIZE = 0xA000   │
> > └─┘ CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX
> > (0x41cffbfc)
> > 
> > New Map:
> > ┌─┐ 0x41c0
> > │ SPL │
> > ├─┤ 0x41c4 (approx)
> > │EMPTY│
> > ├─┤ 0x41c81920
> > │STACK│
> > │ SPL_SIZE_LIMIT_PROVIDE_STACK=0x4000 │
> > ├─┤ 0x41c85920
> > │ Global data │
> > │  sizeof(struct global_data) = 0xd8  │
> > ├─┤ gd->malloc_base = 0x41c859f0
> > │HEAP │
> > │  CONFIG_SYS_MALLOC_F_LEN = 0x7  │
> > ├─┤ CONFIG_SPL_BSS_START_ADDR
> > │   SPL BSS   │ (0x41cf59f0)
> > │  CONFIG_SPL_BSS_MAX_SIZE = 0xA000   │
> > ├─┤ 0x41cff9fc
> > │ NEW MCU SCRATCHPAD  │
> > │  SYS_K3_MCU_SCRATCHPAD_SIZE = 0x200 │
> > └─┘ CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX
> > (0x41cffbfc)
> > 
> > Fixes: ab977c8b91b4 ("configs: j721s2_evm_r5: Enable support for building 
> > multiple dtbs into FIT")
> > 
> > Signed-off-by: Manorit Chawdhry 
> > [n-fran...@ti.com: SRAM allocation addressing diagram]
> > Signed-off-by: Neha Francis 
> 
> Reviewed-by: Tom Rini 
> 
> But can we please get that map information in something under
> doc/board/ti/ as a follow-up?
> 

Hi Tom,

Sure, I'll be updating the same and sending a v3.

Thanks and regards,
Manorit

> -- 
> Tom




[PATCH v2 7/8] rockchip: Move to standard boot

2023-03-01 Thread Simon Glass
Drop the distro-boot scripts and use standard boot instead.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to move rockchip to standard boot

 arch/arm/Kconfig  |  1 -
 include/configs/px30_common.h |  4 +--
 include/configs/rk3036_common.h   |  5 +--
 include/configs/rk3066_common.h   |  5 +--
 include/configs/rk3128_common.h   |  4 +--
 include/configs/rk3188_common.h   |  5 +--
 include/configs/rk322x_common.h   |  5 +--
 include/configs/rk3288_common.h   |  5 +--
 include/configs/rk3308_common.h   |  4 +--
 include/configs/rk3328_common.h   |  4 +--
 include/configs/rk3368_common.h   |  5 +--
 include/configs/rk3399_common.h   |  2 +-
 include/configs/rk3568_common.h   |  4 +--
 include/configs/rockchip-common.h | 58 ---
 include/configs/rv1108_common.h   |  3 +-
 15 files changed, 13 insertions(+), 101 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 4e7ebeaee87..11e1fe53edf 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1955,7 +1955,6 @@ config ARCH_ROCKCHIP
imply ADC
imply CMD_DM
imply DEBUG_UART_BOARD_INIT
-   imply DISTRO_DEFAULTS if !ROCKCHIP_RK3399
imply FAT_WRITE
imply SARADC_ROCKCHIP
imply SPL_SYSRESET
diff --git a/include/configs/px30_common.h b/include/configs/px30_common.h
index c0896e5f628..a4c8bfebdf8 100644
--- a/include/configs/px30_common.h
+++ b/include/configs/px30_common.h
@@ -25,12 +25,10 @@
"kernel_addr_c=0x03e8\0" \
"ramdisk_addr_r=0x0a20\0"
 
-#include 
 #define CFG_EXTRA_ENV_SETTINGS \
ENV_MEM_LAYOUT_SETTINGS \
"fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
"partitions=" PARTS_DEFAULT \
-   ROCKCHIP_DEVICE_SETTINGS \
-   BOOTENV
+   ROCKCHIP_DEVICE_SETTINGS
 
 #endif
diff --git a/include/configs/rk3036_common.h b/include/configs/rk3036_common.h
index ea6073f2944..e056555276a 100644
--- a/include/configs/rk3036_common.h
+++ b/include/configs/rk3036_common.h
@@ -21,15 +21,12 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
-
 /* Linux fails to load the fdt if it's loaded above 512M on a evb-rk3036 board,
  * so limit the fdt reallocation to that */
 #define CFG_EXTRA_ENV_SETTINGS \
"fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \
"fdt_high=0x7fff\0" \
"partitions=" PARTS_DEFAULT \
-   ENV_MEM_LAYOUT_SETTINGS \
-   BOOTENV
+   ENV_MEM_LAYOUT_SETTINGS
 
 #endif
diff --git a/include/configs/rk3066_common.h b/include/configs/rk3066_common.h
index 1a6d3678df3..7f4d48c1ea9 100644
--- a/include/configs/rk3066_common.h
+++ b/include/configs/rk3066_common.h
@@ -22,14 +22,11 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
-
 #define CFG_EXTRA_ENV_SETTINGS \
"fdt_high=0x6fff\0" \
"initrd_high=0x6fff\0" \
"partitions=" PARTS_DEFAULT \
ENV_MEM_LAYOUT_SETTINGS \
-   ROCKCHIP_DEVICE_SETTINGS \
-   BOOTENV
+   ROCKCHIP_DEVICE_SETTINGS
 
 #endif
diff --git a/include/configs/rk3128_common.h b/include/configs/rk3128_common.h
index 8aa17bfbd36..6d531f6bc81 100644
--- a/include/configs/rk3128_common.h
+++ b/include/configs/rk3128_common.h
@@ -26,11 +26,9 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
 #define CFG_EXTRA_ENV_SETTINGS \
ENV_MEM_LAYOUT_SETTINGS \
"fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \
-   "partitions=" PARTS_DEFAULT \
-   BOOTENV
+   "partitions=" PARTS_DEFAULT
 
 #endif
diff --git a/include/configs/rk3188_common.h b/include/configs/rk3188_common.h
index ac9195672fb..80d2619fb78 100644
--- a/include/configs/rk3188_common.h
+++ b/include/configs/rk3188_common.h
@@ -27,8 +27,6 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
-
 /* Linux fails to load the fdt if it's loaded above 256M on a Rock board,
  * so limit the fdt reallocation to that */
 #define CFG_EXTRA_ENV_SETTINGS \
@@ -37,7 +35,6 @@
"initrd_high=0x6fff\0" \
"partitions=" PARTS_DEFAULT \
ENV_MEM_LAYOUT_SETTINGS \
-   ROCKCHIP_DEVICE_SETTINGS \
-   BOOTENV
+   ROCKCHIP_DEVICE_SETTINGS
 
 #endif
diff --git a/include/configs/rk322x_common.h b/include/configs/rk322x_common.h
index fcaf9c52c4b..fb6c1033499 100644
--- a/include/configs/rk322x_common.h
+++ b/include/configs/rk322x_common.h
@@ -23,15 +23,12 @@
"kernel_addr_r=0x6200\0" \
"ramdisk_addr_r=0x6400\0"
 
-#include 
-
 /* Linux fails to load the fdt if it's loaded above 512M on a evb-rk3036 board,
  * so limit the fdt reallocation to that */
 #define CFG_EXTRA_ENV_SETTINGS \
"fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
"fdt_high=0x7fff\0" \
"partitions=" PARTS_DEFAULT \
-   ENV_MEM_LAYOUT_SETTINGS \
-   BOOTENV
+   ENV_MEM_LAYOUT_SETTINGS
 
 #endif
diff --git 

[PATCH v2 8/8] bootstd: Relax the argument requirements for bootflow scan

2023-03-01 Thread Simon Glass
Currently this does not allow the -lb flags unless CMD_BOOTFLOW_FULL is
enabled, which means that we need two separate boot commands. Relax this
to make things easier. It is only a small amount of extra code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Kconfig   |  3 +--
 cmd/bootflow.c | 14 --
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 7f7ec208a54..24116e6f7cd 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -1541,8 +1541,7 @@ config USE_BOOTCOMMAND
 config BOOTCOMMAND
string "bootcmd value"
depends on USE_BOOTCOMMAND && !USE_DEFAULT_ENV_FILE
-   default "bootflow scan -lb" if BOOTSTD_BOOTCOMMAND && CMD_BOOTFLOW_FULL
-   default "bootflow scan" if BOOTSTD_BOOTCOMMAND && !CMD_BOOTFLOW_FULL
+   default "bootflow scan -lb" if BOOTSTD_BOOTCOMMAND
default "run distro_bootcmd" if !BOOTSTD_BOOTCOMMAND && DISTRO_DEFAULTS
help
  This is the string of commands that will be used as bootcmd and if
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index 3548bbb6830..6455f403791 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -124,9 +124,19 @@ static int do_bootflow_scan(struct cmd_tbl *cmdtp, int 
flag, int argc,
if (!label)
dev = std->cur_bootdev;
} else {
+   /*
+* allow -b and -l (which is ignored) but complain about
+* anything else
+*/
if (has_args) {
-   printf("Flags not supported: enable 
CONFIG_BOOTFLOW_FULL\n");
-   return CMD_RET_USAGE;
+   char *p;
+
+   for (p = argv[1] + 1; *p; p++) {
+   if (*p != 'b' && *p != 'l') {
+   printf("Flags not supported: enable 
CONFIG_BOOTFLOW_FULL\n");
+   return CMD_RET_USAGE;
+   }
+   }
}
boot = true;
}
-- 
2.40.0.rc0.216.gc4246ad0f0-goog



[PATCH v2 5/8] lmb: Enable LMB if SYS_BOOT_RAMDISK_HIGH

2023-03-01 Thread Simon Glass
Ramdisk relocation requires LMB, so enable it automatically to avoid
build errors.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/boot/Kconfig b/boot/Kconfig
index 7815341ada7..da18d4738a7 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -814,6 +814,7 @@ config SYS_BOOT_RAMDISK_HIGH
depends on CMD_BOOTM || CMD_BOOTI || CMD_BOOTZ
depends on !(NIOS2 || SANDBOX || SH || XTENSA)
def_bool y
+   select LMB
help
  Enable initrd_high functionality.  If defined then the initrd_high
  feature is enabled and the boot* ramdisk subcommand is enabled.
-- 
2.40.0.rc0.216.gc4246ad0f0-goog



[PATCH v2 4/8] Move DISTRO_DEFAULTS into boot/

2023-03-01 Thread Simon Glass
This relates to booting so move it in to that Kconfig file, before
changing it.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add new patch to move DISTRO_DEFAULTS into boot/

 Kconfig  | 27 ---
 boot/Kconfig | 28 +++-
 2 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/Kconfig b/Kconfig
index a75cce7e28f..b8f65589f45 100644
--- a/Kconfig
+++ b/Kconfig
@@ -191,33 +191,6 @@ config XEN
 
  [1] - https://xenproject.org/
 
-config DISTRO_DEFAULTS
-   bool "Select defaults suitable for booting general purpose Linux 
distributions"
-   select AUTO_COMPLETE
-   select CMDLINE_EDITING
-   select CMD_BOOTI if ARM64
-   select CMD_BOOTZ if ARM && !ARM64
-   select CMD_DHCP if CMD_NET
-   select CMD_ENV_EXISTS
-   select CMD_EXT2
-   select CMD_EXT4
-   select CMD_FAT
-   select CMD_FS_GENERIC
-   select CMD_PART if PARTITIONS
-   select CMD_PING if CMD_NET
-   select CMD_PXE if NET
-   select CMD_SYSBOOT
-   select ENV_VARS_UBOOT_CONFIG
-   select HUSH_PARSER
-   select SUPPORT_RAW_INITRD
-   select SYS_LONGHELP
-   imply CMD_MII if NET
-   imply USB_STORAGE
-   imply USE_BOOTCOMMAND
-   help
- Select this to enable various options and commands which are suitable
- for building u-boot for booting general purpose Linux distributions.
-
 config ENV_VARS_UBOOT_CONFIG
bool "Add arch, board, vendor and soc variables to default environment"
help
diff --git a/boot/Kconfig b/boot/Kconfig
index 8759b863b00..7815341ada7 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -408,7 +408,6 @@ if BOOTSTD
 
 config BOOTSTD_DEFAULTS
bool "Select some common defaults for standard boot"
-   depends on BOOTSTD
default y
imply USE_BOOTCOMMAND
# Bring in some defaults which are generally needed. Boards can drop
@@ -821,6 +820,33 @@ config SYS_BOOT_RAMDISK_HIGH
 
 endmenu# Boot images
 
+config DISTRO_DEFAULTS
+   bool "Select defaults suitable for booting general purpose Linux 
distributions"
+   select AUTO_COMPLETE
+   select CMDLINE_EDITING
+   select CMD_BOOTI if ARM64
+   select CMD_BOOTZ if ARM && !ARM64
+   select CMD_DHCP if CMD_NET
+   select CMD_ENV_EXISTS
+   select CMD_EXT2
+   select CMD_EXT4
+   select CMD_FAT
+   select CMD_FS_GENERIC
+   select CMD_PART if PARTITIONS
+   select CMD_PING if CMD_NET
+   select CMD_PXE if NET
+   select CMD_SYSBOOT
+   select ENV_VARS_UBOOT_CONFIG
+   select HUSH_PARSER
+   select SUPPORT_RAW_INITRD
+   select SYS_LONGHELP
+   imply CMD_MII if NET
+   imply USB_STORAGE
+   imply USE_BOOTCOMMAND
+   help
+ Select this to enable various options and commands which are suitable
+ for building u-boot for booting general purpose Linux distributions.
+
 menu "Boot timing"
 
 config BOOTSTAGE
-- 
2.40.0.rc0.216.gc4246ad0f0-goog



[PATCH v2 3/8] bootstd: Enable BOOTSTD_DEFAULTS by default

2023-03-01 Thread Simon Glass
This is needed to enable the boot command used to start standard boot.
Enable it by default. This brings in quite a few features, mostly in
common with DISTRO_DEFAULTS

Disable this option for boards which don't have enough space.

Disable CONFIG_ENV_VARS_UBOOT_CONFIG for some zynq boards which have
a very small environment. Disable BOOTSTD_DEFAULTS for smartweb since
it is too close to its limit.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 boot/Kconfig | 1 +
 configs/bk4r1_defconfig  | 1 +
 configs/sama5d27_giantboard_defconfig| 1 +
 configs/sama5d27_som1_ek_mmc1_defconfig  | 1 +
 configs/sama5d27_som1_ek_mmc_defconfig   | 1 +
 configs/sama5d27_som1_ek_qspiflash_defconfig | 1 +
 configs/sama5d27_wlsom1_ek_mmc_defconfig | 1 +
 configs/sama5d2_icp_mmc_defconfig| 1 +
 configs/sama5d2_xplained_emmc_defconfig  | 1 +
 configs/sama5d2_xplained_mmc_defconfig   | 1 +
 configs/sama5d2_xplained_qspiflash_defconfig | 1 +
 configs/sheevaplug_defconfig | 1 +
 configs/smartweb_defconfig   | 1 +
 configs/taurus_defconfig | 1 +
 configs/tools-only_defconfig | 2 +-
 configs/xilinx_versal_mini_emmc0_defconfig   | 4 +---
 configs/xilinx_versal_mini_emmc1_defconfig   | 4 +---
 configs/xilinx_zynqmp_mini_emmc0_defconfig   | 4 +---
 configs/xilinx_zynqmp_mini_emmc1_defconfig   | 4 +---
 19 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 5f491625c82..8759b863b00 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -409,6 +409,7 @@ if BOOTSTD
 config BOOTSTD_DEFAULTS
bool "Select some common defaults for standard boot"
depends on BOOTSTD
+   default y
imply USE_BOOTCOMMAND
# Bring in some defaults which are generally needed. Boards can drop
# these as needed to save code space. Bootstd does not generally require
diff --git a/configs/bk4r1_defconfig b/configs/bk4r1_defconfig
index 66adeac725c..298518e7ea5 100644
--- a/configs/bk4r1_defconfig
+++ b/configs/bk4r1_defconfig
@@ -21,6 +21,7 @@ CONFIG_SYS_MEMTEST_END=0x87c0
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
 CONFIG_BOARD_SIZE_LIMIT=520192
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_BOOTDELAY=3
 CONFIG_AUTOBOOT_KEYED=y
 CONFIG_AUTOBOOT_PROMPT="Enter passphrase to stop autoboot, booting in %d 
seconds\n"
diff --git a/configs/sama5d27_giantboard_defconfig 
b/configs/sama5d27_giantboard_defconfig
index 39d1dcdbb79..39680fcf69d 100644
--- a/configs/sama5d27_giantboard_defconfig
+++ b/configs/sama5d27_giantboard_defconfig
@@ -29,6 +29,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_SD_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_AUTOBOOT_KEYED=y
diff --git a/configs/sama5d27_som1_ek_mmc1_defconfig 
b/configs/sama5d27_som1_ek_mmc1_defconfig
index cdb000fe1eb..dd76c79b82e 100644
--- a/configs/sama5d27_som1_ek_mmc1_defconfig
+++ b/configs/sama5d27_som1_ek_mmc1_defconfig
@@ -28,6 +28,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_SD_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/sama5d27_som1_ek_mmc_defconfig 
b/configs/sama5d27_som1_ek_mmc_defconfig
index 1471cebaf4d..d5c3c01cf70 100644
--- a/configs/sama5d27_som1_ek_mmc_defconfig
+++ b/configs/sama5d27_som1_ek_mmc_defconfig
@@ -29,6 +29,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_SD_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/sama5d27_som1_ek_qspiflash_defconfig 
b/configs/sama5d27_som1_ek_qspiflash_defconfig
index 1c8adfbb7a3..f765379985f 100644
--- a/configs/sama5d27_som1_ek_qspiflash_defconfig
+++ b/configs/sama5d27_som1_ek_qspiflash_defconfig
@@ -29,6 +29,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_QSPI_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/sama5d27_wlsom1_ek_mmc_defconfig 
b/configs/sama5d27_wlsom1_ek_mmc_defconfig
index eeb8d209f2b..ec11575224e 100644
--- a/configs/sama5d27_wlsom1_ek_mmc_defconfig
+++ b/configs/sama5d27_wlsom1_ek_mmc_defconfig
@@ -27,6 +27,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS is not set
 CONFIG_SD_BOOT=y
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/sama5d2_icp_mmc_defconfig 
b/configs/sama5d2_icp_mmc_defconfig
index e1b602d8e5e..2abe775480c 100644
--- a/configs/sama5d2_icp_mmc_defconfig
+++ b/configs/sama5d2_icp_mmc_defconfig
@@ -27,6 +27,7 @@ CONFIG_DEBUG_UART=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_SYS_MONITOR_LEN=524288
 CONFIG_FIT=y
+# CONFIG_BOOTSTD_DEFAULTS 

[PATCH v2 2/8] rockchip: Disable DISTRO_DEFAULTS for rk3399 boards

2023-03-01 Thread Simon Glass
These board have moved to standard boot but the old 'distro_bootcmd'
command is still active. Disable DISTRO_DEFAULTS to fix this.

Signed-off-by: Simon Glass 
Tested-by: Vagrant Cascadian 
---

(no changes since v1)

 arch/arm/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index bd7fffcce0b..4e7ebeaee87 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1955,7 +1955,7 @@ config ARCH_ROCKCHIP
imply ADC
imply CMD_DM
imply DEBUG_UART_BOARD_INIT
-   imply DISTRO_DEFAULTS
+   imply DISTRO_DEFAULTS if !ROCKCHIP_RK3399
imply FAT_WRITE
imply SARADC_ROCKCHIP
imply SPL_SYSRESET
-- 
2.40.0.rc0.216.gc4246ad0f0-goog



[PATCH v2 1/8] rockchip: Drop bootstage stash in TPL and SPL for rockpro64

2023-03-01 Thread Simon Glass
Unfortunately the IRAM used to stash the bootstage records in TPL
becomes inaccessible after SPL runs. Presumably this is because of ATF
taking it over.

We could move the stash to another address in SPL, before passing it to
U-Boot proper. But it seems easier to wait until we have support for
standard passage[1] which should not be too far away.

For now, disable it in TPL and SPL.

[1] https://patchwork.ozlabs.org/project/uboot/cover/
20220117150428.1580273-1-...@chromium.org/

Signed-off-by: Simon Glass 
Tested-by: Vagrant Cascadian 
---

Changes in v2:
- Fix 'accessible' typo

 configs/rockpro64-rk3399_defconfig | 5 -
 1 file changed, 5 deletions(-)

diff --git a/configs/rockpro64-rk3399_defconfig 
b/configs/rockpro64-rk3399_defconfig
index dd67f9dff64..49614236819 100644
--- a/configs/rockpro64-rk3399_defconfig
+++ b/configs/rockpro64-rk3399_defconfig
@@ -13,7 +13,6 @@ CONFIG_DM_RESET=y
 CONFIG_ROCKCHIP_RK3399=y
 CONFIG_TARGET_ROCKPRO64_RK3399=y
 CONFIG_SPL_STACK=0x40
-CONFIG_BOOTSTAGE_STASH_ADDR=0xff8e
 CONFIG_DEBUG_UART_BASE=0xFF1A
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
@@ -21,11 +20,7 @@ CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x800800
 CONFIG_DEBUG_UART=y
 CONFIG_BOOTSTAGE=y
-CONFIG_SPL_BOOTSTAGE=y
-CONFIG_TPL_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
-CONFIG_SPL_BOOTSTAGE_RECORD_COUNT=10
-CONFIG_BOOTSTAGE_STASH=y
 CONFIG_USE_PREBOOT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3399-rockpro64.dtb"
 CONFIG_DISPLAY_BOARDINFO_LATE=y
-- 
2.40.0.rc0.216.gc4246ad0f0-goog



Re: [PATCH 2/2] serial: sh: Add HSCIF support for R-Car SoC

2023-03-01 Thread Marek Vasut

On 3/1/23 16:01, Simon Glass wrote:

On Tue, 28 Feb 2023 at 14:29, Marek Vasut
 wrote:


From: Hai Pham 

Provide the basic HSCIF support for R-Car SoC.

Reviewed-by: Marek Vasut 
Signed-off-by: Hai Pham 
Signed-off-by: Marek Vasut 
[Marek: Fill in HSSRR offset for Gen2 and SCBRR calculation for Gen2 and Gen3]
---
Cc: Simon Glass 
---
  doc/device-tree-bindings/serial/sh.txt |  2 +-
  drivers/serial/serial_sh.c |  6 ++
  drivers/serial/serial_sh.h | 26 ++
  include/dm/platform_data/serial_sh.h   |  1 +
  4 files changed, 30 insertions(+), 5 deletions(-)



Reviewed-by: Simon Glass 

but it should really not be looking at CONFIG options in the driver


No, it shouldn't, but untangling that macro mess in serial_sh.h is for 
another day. This one CFG_ is just the tip of a very large and very 
lethal iceberg.


Re: [PATCH] image: Fix potentially uninitialized data variable

2023-03-01 Thread Marek Vasut

On 3/1/23 17:02, Tom Rini wrote:

On Mon, Feb 27, 2023 at 08:56:31PM +0100, Marek Vasut wrote:


In case fitImage support is disabled, and image_locate_script() is
passed a fitImage, then the 'data' variable is used uninitialized.
Drop into the default: branch of the switch-case statement and do
not return the uninitialized data, and do not modify the return
pointer either, just print an error message.

Reported by clang build:
"
$ make HOSTCC=clang CC=clang KCFLAGS=-Werror sandbox64_defconfig && make 
HOSTCC=clang CC=clang KCFLAGS=-Werror
...
boot/image-board.c:1006:7: error: variable 'data' is used uninitialized 
whenever switch case is taken [-Werror,-Wsometimes-uninitialized]
 case IMAGE_FORMAT_LEGACY:
  ^~~
include/image.h:608:29: note: expanded from macro 'IMAGE_FORMAT_LEGACY'
 ^~~~
boot/image-board.c:1128:19: note: uninitialized use occurs here
 *datap = (char *)data;
  ^~~~
boot/image-board.c:1001:11: note: initialize the variable 'data' to silence 
this warning
 u32 *data;
  ^
   = NULL
"

Signed-off-by: Marek Vasut 


Reviewed-by: Tom Rini 

And can you please do a follow-up that adds sandbox64 + clang, after the
sandbox + clang test in GitLab/Azure?


The CI is chewing on it here:

ahttps://source.denx.de/u-boot/custodians/u-boot-sh/-/commit/f80a434c2ea4fdae7adf0e4c4a0ecd9784d6808e


[PATCH v2 31/32] test: cmd: fdt: Test fdt apply

2023-03-01 Thread Marek Vasut
Add 'fdt chosen' test which works as follows:
- Create basic DT, map it to sysmem
- Apply DTO which adds single property via fragment (without address spec)
- Apply DTO which adds more properties (string, u32, empty) and a subnode,
  with phandle via frament@0 and thus tests /__symbols__ node
- Apply DTO which modifies property of the previous DTO via phandle and thus
  tests the /__fixups__ node
- Print modified DT, verify it contains updates from DTOs

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index d320f1f7b79..99e6450bb10 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -1360,6 +1360,158 @@ static int fdt_test_chosen(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_chosen, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_apply(struct unit_test_state *uts)
+{
+   char fdt[8192], fdto[8192];
+   ulong addr, addro;
+
+   /* Create base DT with __symbols__ node */
+   ut_assertok(fdt_create(fdt, sizeof(fdt)));
+   ut_assertok(fdt_finish_reservemap(fdt));
+   ut_assert(fdt_begin_node(fdt, "") >= 0);
+   ut_assert(fdt_begin_node(fdt, "__symbols__") >= 0);
+   ut_assertok(fdt_end_node(fdt));
+   ut_assertok(fdt_end_node(fdt));
+   ut_assertok(fdt_finish(fdt));
+   fdt_shrink_to_minimum(fdt, 4096);   /* Resize with 4096 extra bytes 
*/
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Create DTO which adds single property to root node / */
+   ut_assertok(fdt_create(fdto, sizeof(fdto)));
+   ut_assertok(fdt_finish_reservemap(fdto));
+   ut_assert(fdt_begin_node(fdto, "") >= 0);
+   ut_assert(fdt_begin_node(fdto, "fragment") >= 0);
+   ut_assertok(fdt_property_string(fdto, "target-path", "/"));
+   ut_assert(fdt_begin_node(fdto, "__overlay__") >= 0);
+   ut_assertok(fdt_property_string(fdto, "newstring", "newvalue"));
+   ut_assertok(fdt_end_node(fdto));
+   ut_assertok(fdt_end_node(fdto));
+   ut_assertok(fdt_finish(fdto));
+   addro = map_to_sysmem(fdto);
+
+   /* Test default DT print */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt print /"));
+   ut_assert_nextline("/ {");
+   ut_assert_nextline("\t__symbols__ {");
+   ut_assert_nextline("\t};");
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test simple DTO application */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt apply 0x%08x", addro));
+   ut_assertok(run_commandf("fdt print /"));
+   ut_assert_nextline("/ {");
+   ut_assert_nextline("\tnewstring = \"newvalue\";");
+   ut_assert_nextline("\t__symbols__ {");
+   ut_assert_nextline("\t};");
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   /*
+* Create complex DTO which:
+* - modifies newstring property in root node /
+* - adds new properties to root node /
+* - adds new subnode with properties to root node /
+* - adds phandle to the subnode and therefore __symbols__ node
+*/
+   ut_assertok(fdt_create(fdto, sizeof(fdto)));
+   ut_assertok(fdt_finish_reservemap(fdto));
+   ut_assert(fdt_begin_node(fdto, "") >= 0);
+   ut_assertok(fdt_property_cell(fdto, "#address-cells", 1));
+   ut_assertok(fdt_property_cell(fdto, "#size-cells", 0));
+
+   ut_assert(fdt_begin_node(fdto, "fragment@0") >= 0);
+   ut_assertok(fdt_property_string(fdto, "target-path", "/"));
+   ut_assert(fdt_begin_node(fdto, "__overlay__") >= 0);
+   ut_assertok(fdt_property_string(fdto, "newstring", "newervalue"));
+   ut_assertok(fdt_property_u32(fdto, "newu32", 0x12345678));
+   ut_assertok(fdt_property(fdto, "empty-property", NULL, 0));
+   ut_assert(fdt_begin_node(fdto, "subnode") >= 0);
+   ut_assertok(fdt_property_string(fdto, "subnewstring", "newervalue"));
+   ut_assertok(fdt_property_u32(fdto, "subnewu32", 0x12345678));
+   ut_assertok(fdt_property(fdto, "subempty-property", NULL, 0));
+   ut_assertok(fdt_property_u32(fdto, "phandle", 0x01));
+   ut_assertok(fdt_end_node(fdto));
+   ut_assertok(fdt_end_node(fdto));
+   ut_assertok(fdt_end_node(fdto));
+
+   ut_assert(fdt_begin_node(fdto, "__symbols__") >= 0);
+   ut_assertok(fdt_property_string(fdto, "subnodephandle", 
"/fragment@0/__overlay__/subnode"));
+   ut_assertok(fdt_end_node(fdto));
+   ut_assertok(fdt_finish(fdto));
+   addro = map_to_sysmem(fdto);
+
+   /* Test complex DTO application */
+   

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

2023-03-01 Thread Marek Vasut
Add list of missing tests for the 'fdt' command, currently
the missing sandbox tests are only 'fdt boardsetup' and
'fdt checksign' .

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 99e6450bb10..79ec45bbc2a 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -15,6 +15,13 @@
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
+/*
+ * Missing tests:
+ * fdt boardsetup - Do board-specific set up
+ * fdt checksign [] - check FIT signature
+ *   - address of key blob
+ *   default gd->fdt_blob
+ */
 
 /* Declare a new fdt test */
 #define FDT_TEST(_name, _flags)UNIT_TEST(_name, _flags, fdt_test)
-- 
2.39.2



[PATCH v2 30/32] test: cmd: fdt: Test fdt chosen

2023-03-01 Thread Marek Vasut
Add 'fdt chosen' test which works as follows:
- Create basic DT, map it to sysmem
- Print /chosen node, verify it is nonexistent
- Create chosen node
- Print /chosen node, verify it contains only version
- Create /chosen node with initrd entries
- Print /chosen node, verify it contains version and initrd entries

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index fc552d11a0f..d320f1f7b79 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -1312,6 +1312,54 @@ static int fdt_test_rsvmem(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_rsvmem, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_chosen(struct unit_test_state *uts)
+{
+   const char *env_bootargs = env_get("bootargs");
+   char fdt[8192];
+   ulong addr;
+
+   ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+   fdt_shrink_to_minimum(fdt, 4096);   /* Resize with 4096 extra bytes 
*/
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test default chosen node presence, fail as there is no /chosen node 
*/
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt print /chosen"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test add new chosen node without initrd */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt chosen"));
+   ut_assertok(run_commandf("fdt print /chosen"));
+   ut_assert_nextline("chosen {");
+   ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version 
string */
+   if (env_bootargs)
+   ut_assert_nextline("\tbootargs = \"%s\";", env_bootargs);
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test add new chosen node with initrd */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt chosen 0x1234 0x5678"));
+   ut_assertok(run_commandf("fdt print /chosen"));
+   ut_assert_nextline("chosen {");
+   ut_assert_nextline("\tlinux,initrd-end = <0x%08x 0x%08x>;",
+  upper_32_bits(0x1234 + 0x5678 - 1),
+  lower_32_bits(0x1234 + 0x5678 - 1));
+   ut_assert_nextline("\tlinux,initrd-start = <0x%08x 0x%08x>;",
+  upper_32_bits(0x1234), lower_32_bits(0x1234));
+   ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version 
string */
+   if (env_bootargs)
+   ut_assert_nextline("\tbootargs = \"%s\";", env_bootargs);
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FDT_TEST(fdt_test_chosen, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
-- 
2.39.2



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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 03ec080716c..27eb1349a2b 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -1166,6 +1166,89 @@ static int fdt_test_bootcpu(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_bootcpu, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_memory_cells(struct unit_test_state *uts,
+const unsigned int cells)
+{
+   unsigned char *pada, *pads;
+   unsigned char *seta, *sets;
+   char fdt[8192];
+   const int size = sizeof(fdt);
+   fdt32_t *regs;
+   ulong addr;
+   char *spc;
+   int i;
+
+   /* Create DT with node /memory { regs = <0x100 0x200>; } and #*cells */
+   ut_assertnonnull(regs = calloc(2 * cells, sizeof(*regs)));
+   ut_assertnonnull(pada = calloc(12, cells));
+   ut_assertnonnull(pads = calloc(12, cells));
+   ut_assertnonnull(seta = calloc(12, cells));
+   ut_assertnonnull(sets = calloc(12, cells));
+   for (i = cells; i >= 1; i--) {
+   regs[cells - 1] = cpu_to_fdt32(i * 0x1);
+   regs[(cells * 2) - 1] = cpu_to_fdt32(~i);
+   snprintf(seta + (8 * (cells - i)), 9, "%08x", i * 0x1);
+   snprintf(sets + (8 * (cells - i)), 9, "%08x", ~i);
+   spc = (i != 1) ? " " : "";
+   snprintf(pada + (11 * (cells - i)), 12, "0x%08x%s", i * 
0x1, spc);
+   snprintf(pads + (11 * (cells - i)), 12, "0x%08x%s", ~i, spc);
+   }
+
+   ut_assertok(fdt_create(fdt, size));
+   ut_assertok(fdt_finish_reservemap(fdt));
+   ut_assert(fdt_begin_node(fdt, "") >= 0);
+   ut_assertok(fdt_property_u32(fdt, "#address-cells", cells));
+   ut_assertok(fdt_property_u32(fdt, "#size-cells", cells));
+   ut_assert(fdt_begin_node(fdt, "memory") >= 0);
+   ut_assertok(fdt_property_string(fdt, "device_type", "memory"));
+   ut_assertok(fdt_property(fdt, "reg", , cells * 2));
+   ut_assertok(fdt_end_node(fdt));
+   ut_assertok(fdt_end_node(fdt));
+   ut_assertok(fdt_finish(fdt));
+   fdt_shrink_to_minimum(fdt, 4096);   /* Resize with 4096 extra bytes 
*/
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test updating the memory node */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt memory 0x%s 0x%s", seta, sets));
+   ut_assertok(run_commandf("fdt print /memory"));
+   ut_assert_nextline("memory {");
+   ut_assert_nextline("\tdevice_type = \"memory\";");
+   ut_assert_nextline("\treg = <%s %s>;", pada, pads);
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   free(sets);
+   free(seta);
+   free(pads);
+   free(pada);
+   free(regs);
+
+   return 0;
+}
+
+static int fdt_test_memory(struct unit_test_state *uts)
+{
+   /*
+* Test memory fixup for 32 and 64 bit systems, anything bigger is
+* so far unsupported and fails because of simple_stroull() being
+* 64bit tops in the 'fdt memory' command implementation.
+*/
+   fdt_test_memory_cells(uts, 1);
+   fdt_test_memory_cells(uts, 2);
+
+   /*
+* The 'fdt memory' command is limited to /memory node, it does
+* not support any other valid DT memory node format, which is
+* either one or multiple /memory@adresss nodes. Therefore, this
+* DT variant is not tested here.
+*/
+
+   return 0;
+}
+FDT_TEST(fdt_test_memory, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
-- 
2.39.2



[PATCH v2 29/32] test: cmd: fdt: Test fdt rsvmem

2023-03-01 Thread Marek Vasut
Add 'fdt rsvmem' test which works as follows:
- Create custom FDT with single reserved memory (rsvmem) entry, map it to sysmem
- Add new rsvmem entry
- Delete existing older rsvmem entry
- Add new rsvmem entry again
- Always print the rsvmem list and validate it

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 27eb1349a2b..fc552d11a0f 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -1249,6 +1249,69 @@ static int fdt_test_memory(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_memory, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_rsvmem(struct unit_test_state *uts)
+{
+   char fdt[8192];
+   ulong addr;
+
+   ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+   fdt_shrink_to_minimum(fdt, 4096);   /* Resize with 4096 extra bytes 
*/
+   fdt_add_mem_rsv(fdt, 0x42, 0x1701);
+   fdt_add_mem_rsv(fdt, 0x74656, 0x9);
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test default reserved memory node presence */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt rsvmem print"));
+   ut_assert_nextline("index\t\t   start\t\tsize");
+   ut_assert_nextline("");
+   ut_assert_nextline("%x\t%016x\t%016x", 0, 0x42, 0x1701);
+   ut_assert_nextline("%x\t%016x\t%016x", 1, 0x74656, 0x9);
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test add new reserved memory node */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt rsvmem add 0x1234 0x5678"));
+   ut_assertok(run_commandf("fdt rsvmem print"));
+   ut_assert_nextline("index\t\t   start\t\tsize");
+   ut_assert_nextline("");
+   ut_assert_nextline("%x\t%016x\t%016x", 0, 0x42, 0x1701);
+   ut_assert_nextline("%x\t%016x\t%016x", 1, 0x74656, 0x9);
+   ut_assert_nextline("%x\t%016x\t%016x", 2, 0x1234, 0x5678);
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test delete reserved memory node */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt rsvmem delete 0"));
+   ut_assertok(run_commandf("fdt rsvmem print"));
+   ut_assert_nextline("index\t\t   start\t\tsize");
+   ut_assert_nextline("");
+   ut_assert_nextline("%x\t%016x\t%016x", 0, 0x74656, 0x9);
+   ut_assert_nextline("%x\t%016x\t%016x", 1, 0x1234, 0x5678);
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test re-add new reserved memory node */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt rsvmem add 0x42 0x1701"));
+   ut_assertok(run_commandf("fdt rsvmem print"));
+   ut_assert_nextline("index\t\t   start\t\tsize");
+   ut_assert_nextline("");
+   ut_assert_nextline("%x\t%016x\t%016x", 0, 0x74656, 0x9);
+   ut_assert_nextline("%x\t%016x\t%016x", 1, 0x1234, 0x5678);
+   ut_assert_nextline("%x\t%016x\t%016x", 2, 0x42, 0x1701);
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test delete nonexistent reserved memory node */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt rsvmem delete 10"));
+   ut_assert_nextline("libfdt fdt_del_mem_rsv(): FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FDT_TEST(fdt_test_rsvmem, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
-- 
2.39.2



[PATCH v2 26/32] test: cmd: fdt: Test fdt header

2023-03-01 Thread Marek Vasut
Add 'fdt header' test which works as follows:
- Create basic FDT, map it to sysmem
- Print the FDT header
- Get all members of the FDT header into variable and
  verify the variables contain correct data

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 509e9e8369b..7dc9e800d38 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -1074,6 +1074,65 @@ static int fdt_test_rm(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_rm, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_header_get(struct unit_test_state *uts, char fdt[4096],
+  const char *field, const unsigned long val)
+{
+   /* Test getting valid header entry */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt header get fvar %s", field));
+   ut_asserteq(val, env_get_hex("fvar", 0x1234));
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting malformed header entry */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt header get fvar typo%stypo", field));
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+static int fdt_test_header(struct unit_test_state *uts)
+{
+   char fdt[256];
+   ulong addr;
+
+   ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test header print */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt header"));
+   ut_assert_nextline("magic:\t\t\t0x%x", fdt_magic(fdt));
+   ut_assert_nextline("totalsize:\t\t0x%x (%d)", fdt_totalsize(fdt), 
fdt_totalsize(fdt));
+   ut_assert_nextline("off_dt_struct:\t\t0x%x", fdt_off_dt_struct(fdt));
+   ut_assert_nextline("off_dt_strings:\t\t0x%x", fdt_off_dt_strings(fdt));
+   ut_assert_nextline("off_mem_rsvmap:\t\t0x%x", fdt_off_mem_rsvmap(fdt));
+   ut_assert_nextline("version:\t\t%d", fdt_version(fdt));
+   ut_assert_nextline("last_comp_version:\t%d", 
fdt_last_comp_version(fdt));
+   ut_assert_nextline("boot_cpuid_phys:\t0x%x", fdt_boot_cpuid_phys(fdt));
+   ut_assert_nextline("size_dt_strings:\t0x%x", fdt_size_dt_strings(fdt));
+   ut_assert_nextline("size_dt_struct:\t\t0x%x", fdt_size_dt_struct(fdt));
+   ut_assert_nextline("number mem_rsv:\t\t0x%x", fdt_num_mem_rsv(fdt));
+   ut_assert_nextline_empty();
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test header get */
+   fdt_test_header_get(uts, fdt, "magic", fdt_magic(fdt));
+   fdt_test_header_get(uts, fdt, "totalsize", fdt_totalsize(fdt));
+   fdt_test_header_get(uts, fdt, "off_dt_struct", fdt_off_dt_struct(fdt));
+   fdt_test_header_get(uts, fdt, "off_dt_strings", 
fdt_off_dt_strings(fdt));
+   fdt_test_header_get(uts, fdt, "off_mem_rsvmap", 
fdt_off_mem_rsvmap(fdt));
+   fdt_test_header_get(uts, fdt, "version", fdt_version(fdt));
+   fdt_test_header_get(uts, fdt, "last_comp_version", 
fdt_last_comp_version(fdt));
+   fdt_test_header_get(uts, fdt, "boot_cpuid_phys", 
fdt_boot_cpuid_phys(fdt));
+   fdt_test_header_get(uts, fdt, "size_dt_strings", 
fdt_size_dt_strings(fdt));
+   fdt_test_header_get(uts, fdt, "size_dt_struct", 
fdt_size_dt_struct(fdt));
+
+   return 0;
+}
+FDT_TEST(fdt_test_header, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
-- 
2.39.2



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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 7dc9e800d38..03ec080716c 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -1133,6 +1133,39 @@ static int fdt_test_header(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_header, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_bootcpu(struct unit_test_state *uts)
+{
+   char fdt[256];
+   ulong addr;
+   int i;
+
+   ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test getting default bootcpu entry */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt header get bootcpu boot_cpuid_phys"));
+   ut_asserteq(0, env_get_ulong("bootcpu", 10, 0x1234));
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test setting and getting new bootcpu entry, twice, to test overwrite 
*/
+   for (i = 42; i <= 43; i++) {
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt bootcpu %d", i));
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting new bootcpu entry */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt header get bootcpu 
boot_cpuid_phys"));
+   ut_asserteq(i, env_get_ulong("bootcpu", 10, 0x1234));
+   ut_assertok(ut_check_console_end(uts));
+   }
+
+   return 0;
+}
+FDT_TEST(fdt_test_bootcpu, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
-- 
2.39.2



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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 5e395e23fed..509e9e8369b 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -990,6 +990,90 @@ static int fdt_test_mknode(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_mknode, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_rm(struct unit_test_state *uts)
+{
+   char fdt[4096];
+   ulong addr;
+
+   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test removal of property in root node / */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt print / compatible"));
+   ut_assert_nextline("compatible = \"u-boot,fdt-test\"");
+   ut_assertok(run_commandf("fdt rm / compatible"));
+   ut_asserteq(1, run_commandf("fdt print / compatible"));
+   ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of property clock-names in subnode /test-node@1234 */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt print /test-node@1234 clock-names"));
+   ut_assert_nextline("clock-names = \"fixed\", \"i2c\", \"spi\", 
\"uart2\", \"uart1\"");
+   ut_assertok(run_commandf("fdt rm /test-node@1234 clock-names"));
+   ut_asserteq(1, run_commandf("fdt print /test-node@1234 clock-names"));
+   ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of property u-boot,empty-property in subnode 
/test-node@1234 by alias */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt print testnodealias 
u-boot,empty-property"));
+   ut_assert_nextline("testnodealias u-boot,empty-property");
+   ut_assertok(run_commandf("fdt rm testnodealias u-boot,empty-property"));
+   ut_asserteq(1, run_commandf("fdt print testnodealias 
u-boot,empty-property"));
+   ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of non-existent property noprop in subnode 
/test-node@1234 */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt rm /test-node@1234 noprop"));
+   ut_assert_nextline("libfdt fdt_delprop(): FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of non-existent node /no-node@5678 */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt rm /no-node@5678"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of subnode /test-node@1234/subnode by alias */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt rm subnodealias"));
+   ut_asserteq(1, run_commandf("fdt print /test-node@1234/subnode"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of node by non-existent alias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt rm noalias"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of node by bad alias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt rm noalias"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of node /test-node@1234 */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt rm /test-node@1234"));
+   ut_asserteq(1, run_commandf("fdt print /test-node@1234"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test removal of node / */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt rm /"));
+   ut_asserteq(1, run_commandf("fdt print /"));
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FDT_TEST(fdt_test_rm, 

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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 9adcbc7bb19..64d04f2f2ed 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -778,6 +778,150 @@ static int fdt_test_get_size(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_get_size, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_set_single(struct unit_test_state *uts,
+  const char *path, const char *prop,
+  const char *sval, int ival, bool integer)
+{
+   /*
+* Set single element string/integer/ property into DT, that is:
+* => fdt set /path property string
+* => fdt set /path property integer
+* => fdt set /path property
+*/
+   ut_assertok(console_record_reset_enable());
+   if (sval) {
+   ut_assertok(run_commandf("fdt set %s %s %s", path, prop, sval));
+   } else if (integer) {
+   ut_assertok(run_commandf("fdt set %s %s <%d>", path, prop, 
ival));
+   } else {
+   ut_assertok(run_commandf("fdt set %s %s", path, prop));
+   }
+
+   /* Validate the property is present and has correct value. */
+   ut_assertok(run_commandf("fdt get value svar %s %s", path, prop));
+   if (sval) {
+   ut_asserteq_str(sval, env_get("svar"));
+   } else if (integer) {
+   ut_asserteq(ival, env_get_hex("svar", 0x1234));
+   } else {
+   ut_assertnull(env_get("svar"));
+   }
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+static int fdt_test_set_multi(struct unit_test_state *uts,
+ const char *path, const char *prop,
+ const char *sval1, const char *sval2,
+ int ival1, int ival2)
+{
+   /*
+* Set multi element string/integer array property in DT, that is:
+* => fdt set /path property 
+* => fdt set /path property 
+*
+* The set is done twice in here deliberately, The first set adds
+* the property with an extra trailing element in its array to make
+* the array longer, the second set is the expected final content of
+* the array property. The longer array is used to verify that the
+* new array is correctly sized and read past the new array length
+* triggers failure.
+*/
+   ut_assertok(console_record_reset_enable());
+   if (sval1 && sval2) {
+   ut_assertok(run_commandf("fdt set %s %s %s %s end", path, prop, 
sval1, sval2));
+   ut_assertok(run_commandf("fdt set %s %s %s %s", path, prop, 
sval1, sval2));
+   } else {
+   ut_assertok(run_commandf("fdt set %s %s <%d %d 10>", path, 
prop, ival1, ival2));
+   ut_assertok(run_commandf("fdt set %s %s <%d %d>", path, prop, 
ival1, ival2));
+   }
+
+   /*
+* Validate the property is present and has correct value.
+*
+* The "end/10" above and "svarn" below is used to validate that
+* previous 'fdt set' to longer array does not polute newly set
+* shorter array.
+*/
+   ut_assertok(run_commandf("fdt get value svar1 %s %s 0", path, prop));
+   ut_assertok(run_commandf("fdt get value svar2 %s %s 1", path, prop));
+   ut_asserteq(1, run_commandf("fdt get value svarn %s %s 2", path, prop));
+   if (sval1 && sval2) {
+   ut_asserteq_str(sval1, env_get("svar1"));
+   ut_asserteq_str(sval2, env_get("svar2"));
+   ut_assertnull(env_get("svarn"));
+   } else {
+   ut_asserteq(ival1, env_get_hex("svar1", 0x1234));
+   ut_asserteq(ival2, env_get_hex("svar2", 0x1234));
+   ut_assertnull(env_get("svarn"));
+   }
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+static int fdt_test_set_node(struct unit_test_state *uts,
+const char *path, const char *prop)
+{
+   fdt_test_set_single(uts, path, prop, "new", 0, false);
+   fdt_test_set_single(uts, path, prop, "rewrite", 0, false);
+   fdt_test_set_single(uts, path, prop, NULL, 42, true);
+   fdt_test_set_single(uts, path, prop, NULL, 0, false);
+   fdt_test_set_multi(uts, path, prop, NULL, NULL, 42, 1701);
+   

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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 64d04f2f2ed..5e395e23fed 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -922,6 +922,74 @@ static int fdt_test_set(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_set, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_mknode(struct unit_test_state *uts)
+{
+   char fdt[8192];
+   ulong addr;
+
+   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+   fdt_shrink_to_minimum(fdt, 4096);   /* Resize with 4096 extra bytes 
*/
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test creation of new node in / */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt mknode / newnode"));
+   ut_assertok(run_commandf("fdt list /newnode"));
+   ut_assert_nextline("newnode {");
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test creation of new node in /test-node@1234 */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt mknode /test-node@1234 newsubnode"));
+   ut_assertok(run_commandf("fdt list /test-node@1234/newsubnode"));
+   ut_assert_nextline("newsubnode {");
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test creation of new node in /test-node@1234 by alias */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt mknode testnodealias newersubnode"));
+   ut_assertok(run_commandf("fdt list testnodealias/newersubnode"));
+   ut_assert_nextline("newersubnode {");
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test creation of new node in /test-node@1234 over existing node */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt mknode testnodealias newsubnode"));
+   ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test creation of new node in /test-node@1234 by alias over existing 
node */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt mknode testnodealias newersubnode"));
+   ut_assert_nextline("libfdt fdt_add_subnode(): FDT_ERR_EXISTS");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test creation of new node in non-existent node */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt mknode /no-node newnosubnode"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test creation of new node in non-existent alias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt mknode noalias newfailsubnode"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test creation of new node in bad alias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt mknode badalias newbadsubnode"));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FDT_TEST(fdt_test_mknode, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
-- 
2.39.2



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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 27c23926ce0..9adcbc7bb19 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -691,6 +691,93 @@ static int fdt_test_get_addr(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_get_addr, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_get_size_common(struct unit_test_state *uts,
+const char *path, const char *prop,
+const unsigned int val)
+{
+   ut_assertok(console_record_reset_enable());
+   if (prop) {
+   ut_assertok(run_commandf("fdt get size sstr %s %s", path, 
prop));
+   } else {
+   ut_assertok(run_commandf("fdt get size sstr %s", path));
+   }
+   ut_asserteq(val, env_get_hex("sstr", 0x1234));
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+static int fdt_test_get_size(struct unit_test_state *uts)
+{
+   char fdt[4096];
+   ulong addr;
+
+   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test getting size of root node / string property "compatible" */
+   fdt_test_get_size_common(uts, "/", "compatible", 16);
+
+   /* Test getting size of node /test-node@1234 stringlist property 
"clock-names" */
+   fdt_test_get_size_common(uts, "/test-node@1234", "clock-names", 26);
+   fdt_test_get_size_common(uts, "testnodealias", "clock-names", 26);
+
+   /* Test getting size of node /test-node@1234 u32 property 
"clock-frequency" */
+   fdt_test_get_size_common(uts, "/test-node@1234", "clock-frequency", 4);
+   fdt_test_get_size_common(uts, "testnodealias", "clock-frequency", 4);
+
+   /* Test getting size of node /test-node@1234 empty property 
"u-boot,empty-property" */
+   fdt_test_get_size_common(uts, "/test-node@1234", 
"u-boot,empty-property", 0);
+   fdt_test_get_size_common(uts, "testnodealias", "u-boot,empty-property", 
0);
+
+   /* Test getting size of node /test-node@1234 array property "regs" */
+   fdt_test_get_size_common(uts, "/test-node@1234", "regs", 8);
+   fdt_test_get_size_common(uts, "testnodealias", "regs", 8);
+
+   /* Test getting node count of node / */
+   fdt_test_get_size_common(uts, "/", NULL, 2);
+
+   /* Test getting node count of node /test-node@1234/subnode */
+   fdt_test_get_size_common(uts, "/test-node@1234/subnode", NULL, 0);
+   fdt_test_get_size_common(uts, "subnodealias", NULL, 0);
+
+   /* Test getting size of node /test-node@1234/subnode non-existent 
property "noprop" */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get size pnoprop 
/test-node@1234/subnode noprop", 1));
+   ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
+   ut_asserteq(1, run_command("fdt get size pnoprop subnodealias noprop", 
1));
+   ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting size of non-existent node /test-node@1234/nonode@1 
property "noprop" */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get size pnonode 
/test-node@1234/nonode@1 noprop", 1));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting node count of non-existent node 
/test-node@1234/nonode@1 */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get size pnonode 
/test-node@1234/nonode@1", 1));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting node count of bad alias badalias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get size pnonode badalias noprop", 1));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting node count of non-existent alias noalias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get size pnonode noalias", 1));
+   ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
+   

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

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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index fa95241c8f2..27c23926ce0 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -624,6 +624,73 @@ static int fdt_test_get_name(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_get_name, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_get_addr_common(struct unit_test_state *uts, char *fdt,
+   const char *path, const char *prop)
+{
+   unsigned int offset;
+   int path_offset;
+   void *prop_ptr;
+   int len = 0;
+
+   path_offset = fdt_path_offset(fdt, path);
+   ut_assert(path_offset >= 0);
+   prop_ptr = (void *)fdt_getprop(fdt, path_offset, prop, );
+   ut_assertnonnull(prop_ptr);
+   offset = (char *)prop_ptr - fdt;
+
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt get addr pstr %s %s", path, prop));
+   ut_asserteq((ulong)map_sysmem(env_get_hex("fdtaddr", 0x1234), 0),
+   (ulong)(map_sysmem(env_get_hex("pstr", 0x1234), 0) - 
offset));
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+static int fdt_test_get_addr(struct unit_test_state *uts)
+{
+   char fdt[4096];
+   ulong addr;
+
+   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test getting address of root node / string property "compatible" */
+   fdt_test_get_addr_common(uts, fdt, "/", "compatible");
+
+   /* Test getting address of node /test-node@1234 stringlist property 
"clock-names" */
+   fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "clock-names");
+   fdt_test_get_addr_common(uts, fdt, "testnodealias", "clock-names");
+
+   /* Test getting address of node /test-node@1234 u32 property 
"clock-frequency" */
+   fdt_test_get_addr_common(uts, fdt, "/test-node@1234", 
"clock-frequency");
+   fdt_test_get_addr_common(uts, fdt, "testnodealias", "clock-frequency");
+
+   /* Test getting address of node /test-node@1234 empty property 
"u-boot,empty-property" */
+   fdt_test_get_addr_common(uts, fdt, "/test-node@1234", 
"u-boot,empty-property");
+   fdt_test_get_addr_common(uts, fdt, "testnodealias", 
"u-boot,empty-property");
+
+   /* Test getting address of node /test-node@1234 array property "regs" */
+   fdt_test_get_addr_common(uts, fdt, "/test-node@1234", "regs");
+   fdt_test_get_addr_common(uts, fdt, "testnodealias", "regs");
+
+   /* Test getting address of node /test-node@1234/subnode non-existent 
property "noprop" */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get addr pnoprop 
/test-node@1234/subnode noprop", 1));
+   ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting address of non-existent node /test-node@1234/nonode@1 
property "noprop" */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get addr pnonode 
/test-node@1234/nonode@1 noprop", 1));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FDT_TEST(fdt_test_get_addr, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
-- 
2.39.2



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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 793525c02c5..fa95241c8f2 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -545,6 +545,85 @@ static int fdt_test_get_value(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_get_value, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_get_name(struct unit_test_state *uts)
+{
+   char fdt[4096];
+   ulong addr;
+
+   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test getting name of node 0 in /, which is /aliases node */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_command("fdt get name nzero / 0", 0));
+   ut_asserteq_str("aliases", env_get("nzero"));
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of node 1 in /, which is /test-node@1234 node */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_command("fdt get name none / 1", 0));
+   ut_asserteq_str("test-node@1234", env_get("none"));
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of node -1 in /, which is /aliases node, same as 0 
*/
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_command("fdt get name nmone / -1", 0));
+   ut_asserteq_str("aliases", env_get("nmone"));
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of node 2 in /, which does not exist */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get name ntwo / 2", 1));
+   ut_assert_nextline("libfdt node not found");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of node 0 in /test-node@1234, which is /subnode 
node */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_command("fdt get name snzero /test-node@1234 0", 0));
+   ut_asserteq_str("subnode", env_get("snzero"));
+   ut_assertok(run_command("fdt get name asnzero testnodealias 0", 0));
+   ut_asserteq_str("subnode", env_get("asnzero"));
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of node 1 in /test-node@1234, which does not exist 
*/
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get name snone /test-node@1234 1", 1));
+   ut_assert_nextline("libfdt node not found");
+   ut_asserteq(1, run_command("fdt get name asnone testnodealias 1", 1));
+   ut_assert_nextline("libfdt node not found");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of node -1 in /test-node@1234, which is /subnode 
node, same as 0 */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_command("fdt get name snmone /test-node@1234 -1", 0));
+   ut_asserteq_str("subnode", env_get("snmone"));
+   ut_assertok(run_command("fdt get name asnmone testnodealias -1", 0));
+   ut_asserteq_str("subnode", env_get("asnmone"));
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of nonexistent node */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get name nonode /nonexistent 0", 1));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of bad alias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get name vbadalias badalias 0", 1));
+   ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Test getting name of nonexistent alias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get name vnoalias noalias 0", 1));
+   ut_assert_nextline("libfdt fdt_path_offset() returned FDT_ERR_BADPATH");
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FDT_TEST(fdt_test_get_name, UT_TESTF_CONSOLE_REC);
+
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct 

[PATCH v2 19/32] test: cmd: fdt: Test fdt print and list

2023-03-01 Thread Marek Vasut
Add 'fdt print' and 'fdt list' test which works as follows:
- Create fuller FDT, map it to sysmem
- Print the entire FDT, parts of the FDT and select properties
- Compare output from the print or list

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 266fb6e3ed0..793525c02c5 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -296,6 +296,149 @@ static int fdt_test_resize(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_print_list_common(struct unit_test_state *uts,
+ const char *opc, const char *node)
+{
+   /*
+* Test printing/listing the working FDT
+* subnode $node/subnode
+*/
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt %s %s/subnode", opc, node));
+   ut_assert_nextline("subnode {");
+   ut_assert_nextline("\t#address-cells = <0x>;");
+   ut_assert_nextline("\t#size-cells = <0x>;");
+   ut_assert_nextline("\tcompatible = 
\"u-boot,fdt-subnode-test-device\";");
+   ut_assert_nextline("};");
+   ut_assertok(ut_check_console_end(uts));
+
+   /*
+* Test printing/listing the working FDT
+* path / string property model
+*/
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt %s / model", opc));
+   ut_assert_nextline("model = \"U-Boot FDT test\"");
+   ut_assertok(ut_check_console_end(uts));
+
+   /*
+* Test printing/listing the working FDT
+* path $node string property compatible
+*/
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt %s %s compatible", opc, node));
+   ut_assert_nextline("compatible = \"u-boot,fdt-test-device1\"");
+   ut_assertok(ut_check_console_end(uts));
+
+   /*
+* Test printing/listing the working FDT
+* path $node stringlist property clock-names
+*/
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt %s %s clock-names", opc, node));
+   ut_assert_nextline("clock-names = \"fixed\", \"i2c\", \"spi\", 
\"uart2\", \"uart1\"");
+   ut_assertok(ut_check_console_end(uts));
+
+   /*
+* Test printing/listing the working FDT
+* path $node u32 property clock-frequency
+*/
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt %s %s clock-frequency", opc, node));
+   ut_assert_nextline("clock-frequency = <0x00fde800>");
+   ut_assertok(ut_check_console_end(uts));
+
+   /*
+* Test printing/listing the working FDT
+* path $node empty property u-boot,empty-property
+*/
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt %s %s u-boot,empty-property", opc, node));
+   /*
+* This is the only 'fdt print' / 'fdt list' incantation which
+* prefixes the property with node path. This has been in U-Boot
+* since the beginning of the command 'fdt', keep it.
+*/
+   ut_assert_nextline("%s u-boot,empty-property", node);
+   ut_assertok(ut_check_console_end(uts));
+
+   /*
+* Test printing/listing the working FDT
+* path $node prop-encoded array property regs
+*/
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt %s %s regs", opc, node));
+   ut_assert_nextline("regs = <0x1234 0x1000>");
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
+static int fdt_test_print_list(struct unit_test_state *uts, bool print)
+{
+   const char *opc = print ? "print" : "list";
+   char fdt[4096];
+   ulong addr;
+   int ret;
+
+   /* Original source DT */
+   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test printing/listing the working FDT -- node / */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt %s", opc));
+   ut_assert_nextline("/ {");
+   ut_assert_nextline("\t#address-cells = <0x0001>;");
+   ut_assert_nextline("\t#size-cells = <0x0001>;");
+   ut_assert_nextline("\tcompatible = \"u-boot,fdt-test\";");
+   ut_assert_nextline("\tmodel = \"U-Boot FDT test\";");
+   ut_assert_nextline("\taliases {");
+   if (print) {
+   ut_assert_nextline("\t\tbadalias = \"/bad/alias\";");
+   ut_assert_nextline("\t\tsubnodealias = 

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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 023b83eb019..266fb6e3ed0 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -272,6 +272,30 @@ static int fdt_test_move(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_move, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_resize(struct unit_test_state *uts)
+{
+   char fdt[256];
+   const unsigned int newsize = 0x2000;
+   uint32_t ts;
+   ulong addr;
+
+   /* Original source DT */
+   ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+   fdt_shrink_to_minimum(fdt, 0);  /* Resize with 0 extra bytes */
+   ts = fdt_totalsize(fdt);
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Test resizing the working FDT and verify the new space was added */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt resize %x", newsize));
+   ut_asserteq(ts + newsize, fdt_totalsize(fdt));
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC);
+
 /* Test 'fdt get value' reading an fdt */
 static int fdt_test_get_value_string(struct unit_test_state *uts,
 const char *node, const char *prop,
-- 
2.39.2



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

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 69a69c5c75c..023b83eb019 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -238,6 +238,40 @@ static int fdt_test_addr_resize(struct unit_test_state 
*uts)
 }
 FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_move(struct unit_test_state *uts)
+{
+   char fdt[256];
+   ulong addr, newaddr = 0x1;
+   const int size = sizeof(fdt);
+   uint32_t ts;
+   void *buf;
+
+   /* Original source DT */
+   ut_assertok(make_test_fdt(uts, fdt, size));
+   ts = fdt_totalsize(fdt);
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   /* Moved target DT location */
+   buf = map_sysmem(newaddr, size);
+   memset(buf, 0, size);
+
+   /* Test moving the working FDT to a new location */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt move %08x %08x %x", addr, newaddr, ts));
+   ut_assert_nextline("Working FDT set to %lx", newaddr);
+   ut_assertok(ut_check_console_end(uts));
+
+   /* Compare the source and destination DTs */
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("cmp.b %08x %08x %x", addr, newaddr, ts));
+   ut_assert_nextline("Total of %d byte(s) were the same", ts);
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+FDT_TEST(fdt_test_move, UT_TESTF_CONSOLE_REC);
+
 /* Test 'fdt get value' reading an fdt */
 static int fdt_test_get_value_string(struct unit_test_state *uts,
 const char *node, const char *prop,
-- 
2.39.2



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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 21553a2f3dc..e04ba37f19f 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -239,56 +239,81 @@ static int fdt_test_addr_resize(struct unit_test_state 
*uts)
 FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
 
 /* Test 'fdt get value' reading an fdt */
-static int fdt_test_get_value(struct unit_test_state *uts)
+static int fdt_test_get_value_common(struct unit_test_state *uts,
+const char *node)
 {
-   char fdt[4096];
-   ulong addr;
-
-   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
-   addr = map_to_sysmem(fdt);
-   set_working_fdt_addr(addr);
-
-   /* Test getting default element of /test-node@1234 node clock-names 
property */
+   /* Test getting default element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
-   ut_assertok(run_command("fdt get value fdflt /test-node@1234 
clock-names", 0));
+   ut_assertok(run_commandf("fdt get value fdflt %s clock-names", node));
ut_asserteq_str("fixed", env_get("fdflt"));
ut_assertok(ut_check_console_end(uts));
 
-   /* Test getting 0th element of /test-node@1234 node clock-names 
property */
+   /* Test getting 0th element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
-   ut_assertok(run_command("fdt get value fzero /test-node@1234 
clock-names 0", 0));
+   ut_assertok(run_commandf("fdt get value fzero %s clock-names 0", node));
ut_asserteq_str("fixed", env_get("fzero"));
ut_assertok(ut_check_console_end(uts));
 
-   /* Test getting 1st element of /test-node@1234 node clock-names 
property */
+   /* Test getting 1st element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
-   ut_assertok(run_command("fdt get value fone /test-node@1234 clock-names 
1", 0));
+   ut_assertok(run_commandf("fdt get value fone %s clock-names 1", node));
ut_asserteq_str("i2c", env_get("fone"));
ut_assertok(ut_check_console_end(uts));
 
-   /* Test getting 2nd element of /test-node@1234 node clock-names 
property */
+   /* Test getting 2nd element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
-   ut_assertok(run_command("fdt get value ftwo /test-node@1234 clock-names 
2", 0));
+   ut_assertok(run_commandf("fdt get value ftwo %s clock-names 2", node));
ut_asserteq_str("spi", env_get("ftwo"));
ut_assertok(ut_check_console_end(uts));
 
-   /* Test missing 10th element of /test-node@1234 node clock-names 
property */
+   /* Test missing 10th element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
-   ut_asserteq(1, run_command("fdt get value ften /test-node@1234 
clock-names 10", 0));
+   ut_asserteq(1, run_commandf("fdt get value ften %s clock-names 10", 
node));
ut_assertok(ut_check_console_end(uts));
 
-   /* Test getting default element of /test-node@1234 node nonexistent 
property */
+   /* Test getting default element of $node node nonexistent property */
ut_assertok(console_record_reset_enable());
-   ut_asserteq(1, run_command("fdt get value fnone /test-node@1234 
nonexistent", 1));
+   ut_asserteq(1, run_commandf("fdt get value fnone %s nonexistent", 
node));
ut_assert_nextline("libfdt fdt_getprop(): FDT_ERR_NOTFOUND");
ut_assertok(ut_check_console_end(uts));
 
+   return 0;
+}
+
+static int fdt_test_get_value(struct unit_test_state *uts)
+{
+   char fdt[4096];
+   ulong addr;
+   int ret;
+
+   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+   addr = map_to_sysmem(fdt);
+   set_working_fdt_addr(addr);
+
+   ret = fdt_test_get_value_common(uts, "/test-node@1234");
+   if (!ret)
+   ret = fdt_test_get_value_common(uts, "testnodealias");
+   if (ret)
+   return ret;
+
/* Test getting default element of /nonexistent node */
ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_command("fdt get value fnode /nonexistent 
nonexistent", 1));
ut_assert_nextline("libfdt fdt_path_offset() returned 
FDT_ERR_NOTFOUND");
ut_assertok(ut_check_console_end(uts));
 
+   /* Test getting default element of bad alias */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_command("fdt get value vbadalias badalias 
nonexistent", 

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index e04ba37f19f..69a69c5c75c 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -239,38 +239,64 @@ static int fdt_test_addr_resize(struct unit_test_state 
*uts)
 FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
 
 /* Test 'fdt get value' reading an fdt */
+static int fdt_test_get_value_string(struct unit_test_state *uts,
+const char *node, const char *prop,
+const char *idx,  const char *strres,
+const int intres)
+{
+   ut_assertok(console_record_reset_enable());
+   ut_assertok(run_commandf("fdt get value var %s %s %s",
+node, prop, idx ? : ""));
+   if (strres) {
+   ut_asserteq_str(strres, env_get("var"));
+   } else {
+   ut_asserteq(intres, env_get_hex("var", 0x1234));
+   }
+   ut_assertok(ut_check_console_end(uts));
+
+   return 0;
+}
+
 static int fdt_test_get_value_common(struct unit_test_state *uts,
 const char *node)
 {
/* Test getting default element of $node node clock-names property */
-   ut_assertok(console_record_reset_enable());
-   ut_assertok(run_commandf("fdt get value fdflt %s clock-names", node));
-   ut_asserteq_str("fixed", env_get("fdflt"));
-   ut_assertok(ut_check_console_end(uts));
+   fdt_test_get_value_string(uts, node, "clock-names", NULL, "fixed", 0);
 
/* Test getting 0th element of $node node clock-names property */
-   ut_assertok(console_record_reset_enable());
-   ut_assertok(run_commandf("fdt get value fzero %s clock-names 0", node));
-   ut_asserteq_str("fixed", env_get("fzero"));
-   ut_assertok(ut_check_console_end(uts));
+   fdt_test_get_value_string(uts, node, "clock-names", "0", "fixed", 0);
 
/* Test getting 1st element of $node node clock-names property */
-   ut_assertok(console_record_reset_enable());
-   ut_assertok(run_commandf("fdt get value fone %s clock-names 1", node));
-   ut_asserteq_str("i2c", env_get("fone"));
-   ut_assertok(ut_check_console_end(uts));
+   fdt_test_get_value_string(uts, node, "clock-names", "1", "i2c", 0);
 
/* Test getting 2nd element of $node node clock-names property */
-   ut_assertok(console_record_reset_enable());
-   ut_assertok(run_commandf("fdt get value ftwo %s clock-names 2", node));
-   ut_asserteq_str("spi", env_get("ftwo"));
-   ut_assertok(ut_check_console_end(uts));
+   fdt_test_get_value_string(uts, node, "clock-names", "2", "spi", 0);
+
+   /*
+* Test getting default element of $node node regs property.
+* The result here is highly unusual, the non-index value read from
+* integer array is a string of concatenated values from the array,
+* but only if the array is shorter than 40 characters. Anything
+* longer is an error. This is a special case for handling hashes.
+*/
+   fdt_test_get_value_string(uts, node, "regs", NULL, "34120010", 
0);
+
+   /* Test getting 0th element of $node node regs property */
+   fdt_test_get_value_string(uts, node, "regs", "0", NULL, 0x1234);
+
+   /* Test getting 1st element of $node node regs property */
+   fdt_test_get_value_string(uts, node, "regs", "1", NULL, 0x1000);
 
/* Test missing 10th element of $node node clock-names property */
ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt get value ften %s clock-names 10", 
node));
ut_assertok(ut_check_console_end(uts));
 
+   /* Test missing 10th element of $node node regs property */
+   ut_assertok(console_record_reset_enable());
+   ut_asserteq(1, run_commandf("fdt get value ften %s regs 10", node));
+   ut_assertok(ut_check_console_end(uts));
+
/* Test getting default element of $node node nonexistent property */
ut_assertok(console_record_reset_enable());
ut_asserteq(1, run_commandf("fdt get value fnone %s nonexistent", 
node));
-- 
2.39.2



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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 03a29c6b9c0..21553a2f3dc 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -39,6 +39,102 @@ static int make_test_fdt(struct unit_test_state *uts, void 
*fdt, int size)
return 0;
 }
 
+/**
+ * make_fuller_fdt() - Create an FDT with root node and properties
+ *
+ * The size is set to the minimum needed
+ *
+ * @uts: Test state
+ * @fdt: Place to write FDT
+ * @size: Maximum size of space for fdt
+ */
+static int make_fuller_fdt(struct unit_test_state *uts, void *fdt, int size)
+{
+   fdt32_t regs[2] = { cpu_to_fdt32(0x1234), cpu_to_fdt32(0x1000) };
+
+   /*
+* Assemble the following DT for test purposes:
+*
+* / {
+*  #address-cells = <0x0001>;
+*  #size-cells = <0x0001>;
+*  compatible = "u-boot,fdt-test";
+*  model = "U-Boot FDT test";
+*
+*  aliases {
+*  badalias = "/bad/alias";
+*  subnodealias = "/test-node@1234/subnode";
+*  testnodealias = "/test-node@1234";
+*  };
+*
+*  test-node@1234 {
+*  #address-cells = <0x>;
+*  #size-cells = <0x>;
+*  compatible = "u-boot,fdt-test-device1";
+*  clock-names = "fixed", "i2c", "spi", "uart2", "uart1";
+*  u-boot,empty-property;
+*  clock-frequency = <0x00fde800>;
+*  regs = <0x1234 0x1000>;
+*
+*  subnode {
+*  #address-cells = <0x>;
+*  #size-cells = <0x>;
+*  compatible = "u-boot,fdt-subnode-test-device";
+*  };
+*  };
+* };
+*/
+
+   ut_assertok(fdt_create(fdt, size));
+   ut_assertok(fdt_finish_reservemap(fdt));
+   ut_assert(fdt_begin_node(fdt, "") >= 0);
+
+   ut_assertok(fdt_property_u32(fdt, "#address-cells", 1));
+   ut_assertok(fdt_property_u32(fdt, "#size-cells", 1));
+   /*  */
+   ut_assertok(fdt_property_string(fdt, "compatible", "u-boot,fdt-test"));
+   /*  */
+   ut_assertok(fdt_property_string(fdt, "model", "U-Boot FDT test"));
+
+   ut_assert(fdt_begin_node(fdt, "aliases") >= 0);
+   /*  */
+   ut_assertok(fdt_property_string(fdt, "badalias", "/bad/alias"));
+   /*  */
+   ut_assertok(fdt_property_string(fdt, "subnodealias", 
"/test-node@1234/subnode"));
+   /*  */
+   ut_assertok(fdt_property_string(fdt, "testnodealias", 
"/test-node@1234"));
+   ut_assertok(fdt_end_node(fdt));
+
+   ut_assert(fdt_begin_node(fdt, "test-node@1234") >= 0);
+   ut_assertok(fdt_property_cell(fdt, "#address-cells", 0));
+   ut_assertok(fdt_property_cell(fdt, "#size-cells", 0));
+   /*  */
+   ut_assertok(fdt_property_string(fdt, "compatible", 
"u-boot,fdt-test-device1"));
+   /*  */
+   ut_assertok(fdt_property(fdt, "clock-names", 
"fixed\0i2c\0spi\0uart2\0uart1\0", 26));
+   /*  */
+   ut_assertok(fdt_property(fdt, "u-boot,empty-property", NULL, 0));
+   /*
+* 
+* This value is deliberate as it used to break cmd/fdt.c
+* is_printable_string() implementation.
+*/
+   ut_assertok(fdt_property_u32(fdt, "clock-frequency", 1664));
+   /*  */
+   ut_assertok(fdt_property(fdt, "regs", , sizeof(regs)));
+   ut_assert(fdt_begin_node(fdt, "subnode") >= 0);
+   ut_assertok(fdt_property_cell(fdt, "#address-cells", 0));
+   ut_assertok(fdt_property_cell(fdt, "#size-cells", 0));
+   ut_assertok(fdt_property_string(fdt, "compatible", 
"u-boot,fdt-subnode-test-device"));
+   ut_assertok(fdt_end_node(fdt));
+   ut_assertok(fdt_end_node(fdt));
+
+   ut_assertok(fdt_end_node(fdt));
+   ut_assertok(fdt_finish(fdt));
+
+   return 0;
+}
+
 /* Test 'fdt addr' getting/setting address */
 static int fdt_test_addr(struct unit_test_state *uts)
 {
@@ -145,43 +241,45 @@ FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
 /* Test 'fdt get value' reading an fdt */
 static int fdt_test_get_value(struct unit_test_state *uts)
 {
+   char fdt[4096];
ulong addr;
 
-   addr = map_to_sysmem(gd->fdt_blob);
+   ut_assertok(make_fuller_fdt(uts, fdt, sizeof(fdt)));
+   addr = 

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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index a50285eafab..03a29c6b9c0 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -142,8 +142,8 @@ static int fdt_test_addr_resize(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
 
-/* Test 'fdt get' reading an fdt */
-static int fdt_test_get(struct unit_test_state *uts)
+/* Test 'fdt get value' reading an fdt */
+static int fdt_test_get_value(struct unit_test_state *uts)
 {
ulong addr;
 
@@ -193,7 +193,7 @@ static int fdt_test_get(struct unit_test_state *uts)
 
return 0;
 }
-FDT_TEST(fdt_test_get, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_get_value, UT_TESTF_CONSOLE_REC);
 
 int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
-- 
2.39.2



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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 7974c88c0d6..a50285eafab 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -108,7 +108,7 @@ static int fdt_test_addr(struct unit_test_state *uts)
 FDT_TEST(fdt_test_addr, UT_TESTF_CONSOLE_REC);
 
 /* Test 'fdt addr' resizing an fdt */
-static int fdt_test_resize(struct unit_test_state *uts)
+static int fdt_test_addr_resize(struct unit_test_state *uts)
 {
char fdt[256];
const int newsize = sizeof(fdt) / 2;
@@ -140,7 +140,7 @@ static int fdt_test_resize(struct unit_test_state *uts)
 
return 0;
 }
-FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC);
+FDT_TEST(fdt_test_addr_resize, UT_TESTF_CONSOLE_REC);
 
 /* Test 'fdt get' reading an fdt */
 static int fdt_test_get(struct unit_test_state *uts)
-- 
2.39.2



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

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

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

diff --git a/include/test/ut.h b/include/test/ut.h
index 4d00b4eeca1..2b0dab32f68 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -334,6 +334,10 @@ int ut_check_console_dump(struct unit_test_state *uts, int 
total_bytes);
return CMD_RET_FAILURE; \
}   \
 
+/* Assert that the next console output line is empty */
+#define ut_assert_nextline_empty() \
+   ut_assert_nextline("%s", "")
+
 /**
  * ut_check_free() - Return the number of bytes free in the malloc() pool
  *
-- 
2.39.2



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

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

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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index f2576ab4b38..f38fe909c3e 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -77,7 +77,17 @@ static int fdt_value_env_set(const void *nodep, int len,
 
sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep));
env_set(var, buf);
-   } else if (len%4 == 0 && len <= 20) {
+   } else if (len % 4 == 0 && index >= 0) {
+   /* Needed to print integer arrays. */
+   const unsigned int *nodec = (const unsigned int *)nodep;
+   char buf[11];
+
+   if (index * 4 >= len)
+   return 1;
+
+   sprintf(buf, "0x%08X", fdt32_to_cpu(*(nodec + index)));
+   env_set(var, buf);
+   } else if (len % 4 == 0 && len <= 20) {
/* Needed to print things like sha1 hashes. */
char buf[41];
int i;
@@ -448,7 +458,7 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
working_fdt, nodeoffset, prop, );
if (nodep && len >= 0) {
if (subcmd[0] == 'v') {
-   int index = 0;
+   int index = -1;
int ret;
 
if (len == 0) {
-- 
2.39.2



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

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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index bc19303159d..f2576ab4b38 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -468,7 +468,8 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
/* Get address */
char buf[19];
 
-   snprintf(buf, sizeof(buf), "0x%p", 
nodep);
+   snprintf(buf, sizeof(buf), "0x%lx",
+(ulong)map_to_sysmem(nodep));
env_set(var, buf);
} else if (subcmd[0] == 's') {
/* Get size */
-- 
2.39.2



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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 279dad9fe11..bc19303159d 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -466,9 +466,9 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
return ret;
} else if (subcmd[0] == 'a') {
/* Get address */
-   char buf[11];
+   char buf[19];
 
-   sprintf(buf, "0x%p", nodep);
+   snprintf(buf, sizeof(buf), "0x%p", 
nodep);
env_set(var, buf);
} else if (subcmd[0] == 's') {
/* Get size */
-- 
2.39.2



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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index f257bee8643..279dad9fe11 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -1138,8 +1138,8 @@ static char fdt_help_text[] =
"/ - initrd start 
addr/size\n"
 #if defined(CONFIG_FIT_SIGNATURE)
"fdt checksign []  - check FIT signature\n"
-   " - addr of key blob\n"
-   "  default 
gd->fdt_blob\n"
+   "   - address of key blob\n"
+   "   default gd->fdt_blob\n"
 #endif
"NOTE: Dereference aliases by omitting the leading '/', "
"e.g. fdt print ethernet0.";
-- 
2.39.2



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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 734c9b36a07..f257bee8643 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -611,6 +611,10 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
} else if (strncmp(argv[1], "me", 2) == 0) {
uint64_t addr, size;
int err;
+
+   if (argc != 4)
+   return CMD_RET_USAGE;
+
addr = simple_strtoull(argv[2], NULL, 16);
size = simple_strtoull(argv[3], NULL, 16);
err = fdt_fixup_memory(working_fdt, addr, size);
-- 
2.39.2



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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 29d748891d0..734c9b36a07 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -597,7 +597,12 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
 * Set boot cpu id
 */
} else if (strncmp(argv[1], "boo", 3) == 0) {
-   unsigned long tmp = hextoul(argv[2], NULL);
+   unsigned long tmp;
+
+   if (argc != 3)
+   return CMD_RET_USAGE;
+
+   tmp = hextoul(argv[2], NULL);
fdt_set_boot_cpuid_phys(working_fdt, tmp);
 
/*
-- 
2.39.2



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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 644b58ac4d7..29d748891d0 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -644,18 +644,18 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
err = fdt_add_mem_rsv(working_fdt, addr, size);
 
if (err < 0) {
-   printf("libfdt fdt_add_mem_rsv():  %s\n",
+   printf("libfdt fdt_add_mem_rsv(): %s\n",
fdt_strerror(err));
-   return err;
+   return CMD_RET_FAILURE;
}
} else if (argv[2][0] == 'd') {
unsigned long idx = hextoul(argv[3], NULL);
int err = fdt_del_mem_rsv(working_fdt, idx);
 
if (err < 0) {
-   printf("libfdt fdt_del_mem_rsv():  %s\n",
+   printf("libfdt fdt_del_mem_rsv(): %s\n",
fdt_strerror(err));
-   return err;
+   return CMD_RET_FAILURE;
}
} else {
/* Unrecognized command */
-- 
2.39.2



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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 56b3585c3ac..644b58ac4d7 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -547,16 +547,16 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
if (argc > 3) {
err = fdt_delprop(working_fdt, nodeoffset, argv[3]);
if (err < 0) {
-   printf("libfdt fdt_delprop():  %s\n",
+   printf("libfdt fdt_delprop(): %s\n",
fdt_strerror(err));
-   return err;
+   return CMD_RET_FAILURE;
}
} else {
err = fdt_del_node(working_fdt, nodeoffset);
if (err < 0) {
-   printf("libfdt fdt_del_node():  %s\n",
+   printf("libfdt fdt_del_node(): %s\n",
fdt_strerror(err));
-   return err;
+   return CMD_RET_FAILURE;
}
}
 
-- 
2.39.2



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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index bf2415661e2..56b3585c3ac 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -446,15 +446,17 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
} else {
nodep = fdt_getprop(
working_fdt, nodeoffset, prop, );
-   if (len == 0) {
-   /* no property value */
-   env_set(var, "");
-   return 0;
-   } else if (nodep && len > 0) {
+   if (nodep && len >= 0) {
if (subcmd[0] == 'v') {
int index = 0;
int ret;
 
+   if (len == 0) {
+   /* no property value */
+   env_set(var, "");
+   return 0;
+   }
+
if (argc == 7)
index = simple_strtoul(argv[6], 
NULL, 10);
 
-- 
2.39.2



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

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

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

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

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

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

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

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 1972490bdc2..bf2415661e2 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -878,41 +878,33 @@ static int fdt_parse_prop(char * const *newval, int 
count, char *data, int *len)
 static int is_printable_string(const void *data, int len)
 {
const char *s = data;
+   const char *ss, *se;
 
/* zero length is not */
if (len == 0)
return 0;
 
-   /* must terminate with zero or '\n' */
-   if (s[len - 1] != '\0' && s[len - 1] != '\n')
+   /* must terminate with zero */
+   if (s[len - 1] != '\0')
return 0;
 
-   /* printable or a null byte (concatenated strings) */
-   while (((*s == '\0') || isprint(*s) || isspace(*s)) && (len > 0)) {
-   /*
-* If we see a null, there are three possibilities:
-* 1) If len == 1, it is the end of the string, printable
-* 2) Next character also a null, not printable.
-* 3) Next character not a null, continue to check.
-*/
-   if (s[0] == '\0') {
-   if (len == 1)
-   return 1;
-   if (s[1] == '\0')
-   return 0;
-   }
+   se = s + len;
+
+   while (s < se) {
+   ss = s;
+   while (s < se && *s && isprint((unsigned char)*s))
+   s++;
+
+   /* not zero, or not done yet */
+   if (*s != '\0' || s == ss)
+   return 0;
+
s++;
-   len--;
}
 
-   /* Not the null termination, or not done yet: not printable */
-   if (*s != '\0' || (len != 0))
-   return 0;
-
return 1;
 }
 
-
 /*
  * Print the property in the best format, a heuristic guess.  Print as
  * a string, concatenated strings, a byte, word, double word, or (if all
-- 
2.39.2



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

2023-03-01 Thread Marek Vasut

On 3/1/23 16:02, Simon Glass wrote:

Hi Marek,

On Mon, 27 Feb 2023 at 12:55, Marek Vasut
 wrote:


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

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

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

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index ae67b468b71..42d067090aa 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -777,6 +777,129 @@ static int fdt_test_get_size(struct unit_test_state *uts)
  }
  FDT_TEST(fdt_test_get_size, UT_TESTF_CONSOLE_REC);

+static int fdt_test_set_single(struct unit_test_state *uts,
+  const char *path, const char *prop,
+  const char *sval, int ival, bool integer)


Please  add a comment for this function.


+{
+   ut_assertok(console_record_reset_enable());
+   if (sval) {
+   ut_assertok(run_commandf("fdt set %s %s %s", path, prop, sval));
+   } else if (integer) {
+   ut_assertok(run_commandf("fdt set %s %s <%d>", path, prop, 
ival));
+   } else {
+   ut_assertok(run_commandf("fdt set %s %s", path, prop));
+   }


Should drop {} on single-line statements - please check patman


This one isn't as simple as "drop the {}" in fact, I sent a separate 
series to address that:


https://patchwork.ozlabs.org/project/uboot/list/?series=344329


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

2023-03-01 Thread Marek Vasut

On 3/1/23 16:02, Simon Glass wrote:

On Mon, 27 Feb 2023 at 12:55, Marek Vasut
 wrote:


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

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



Reviewed-by: Simon Glass 



diff --git a/cmd/fdt.c b/cmd/fdt.c
index 279dad9fe11..bc19303159d 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -466,9 +466,9 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
 return ret;
 } else if (subcmd[0] == 'a') {
 /* Get address */
-   char buf[11];
+   char buf[19];

-   sprintf(buf, "0x%p", nodep);
+   snprintf(buf, sizeof(buf), "0x%p", 
nodep);


Do we need the 0x? I believe that is always the base.


I would argue this behavior is an ABI by now.
I did send a separate patch on top, which can then be reverted if that 
would break anything:


https://patchwork.ozlabs.org/project/uboot/patch/20230302030440.322361-1-marek.vasut+rene...@mailbox.org/


[PATCH 1/2] test: Wrap assert macros in ({ ... }) and fix missing semicolons

2023-03-01 Thread Marek Vasut
Wrap the assert macros in ({ ... }) so they can be safely used both as
right side argument as well as in conditionals without curly brackets
around them. In the process, find a bunch of missing semicolons, fix
them.

Signed-off-by: Marek Vasut 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
 include/test/ut.h  | 152 ++---
 test/cmd/pwm.c |   4 +-
 test/dm/acpigen.c  |   2 +-
 test/dm/misc.c |   4 +-
 test/dm/phy.c  |   8 +--
 test/dm/scmi.c |   4 +-
 test/lib/kconfig.c |  10 +--
 test/unicode_ut.c  |   6 +-
 8 files changed, 121 insertions(+), 69 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index 2b0dab32f68..dddf9ad241f 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -125,36 +125,47 @@ int ut_check_console_dump(struct unit_test_state *uts, 
int total_bytes);
 fmt, ##args)
 
 /* Assert that a condition is non-zero */
-#define ut_assert(cond)
\
+#define ut_assert(cond) ({ \
+   int __ret = 0;  \
+   \
if (!(cond)) {  \
ut_fail(uts, __FILE__, __LINE__, __func__, #cond);  \
-   return CMD_RET_FAILURE; \
-   }
+   __ret = CMD_RET_FAILURE;\
+   }   \
+   __ret;  \
+})
 
 /* Assert that a condition is non-zero, with printf() string */
-#define ut_assertf(cond, fmt, args...) \
+#define ut_assertf(cond, fmt, args...) ({  \
+   int __ret = 0;  \
+   \
if (!(cond)) {  \
ut_failf(uts, __FILE__, __LINE__, __func__, #cond,  \
 fmt, ##args);  \
-   return CMD_RET_FAILURE; \
-   }
+   __ret = CMD_RET_FAILURE;\
+   }   \
+   __ret;  \
+})
 
 /* Assert that two int expressions are equal */
-#define ut_asserteq(expr1, expr2) {\
+#define ut_asserteq(expr1, expr2) ({   \
unsigned int _val1 = (expr1), _val2 = (expr2);  \
+   int __ret = 0;  \
\
if (_val1 != _val2) {   \
ut_failf(uts, __FILE__, __LINE__, __func__, \
 #expr1 " == " #expr2,  \
 "Expected %#x (%d), got %#x (%d)", \
 _val1, _val1, _val2, _val2);   \
-   return CMD_RET_FAILURE; \
+   __ret = CMD_RET_FAILURE;\
}   \
-}
+   __ret;  \
+})
 
 /* Assert that two 64 int expressions are equal */
-#define ut_asserteq_64(expr1, expr2) { \
+#define ut_asserteq_64(expr1, expr2) ({
\
u64 _val1 = (expr1), _val2 = (expr2);   \
+   int __ret = 0;  \
\
if (_val1 != _val2) {   \
ut_failf(uts, __FILE__, __LINE__, __func__, \
@@ -164,43 +175,49 @@ int ut_check_console_dump(struct unit_test_state *uts, 
int total_bytes);
 (unsigned long long)_val1, \
 (unsigned long long)_val2, \
 (unsigned long long)_val2);\
-   return CMD_RET_FAILURE; \
+   __ret = CMD_RET_FAILURE;\
}   \
-}
+   __ret;  \
+})
 
 /* Assert that two string expressions are equal */
-#define ut_asserteq_str(expr1, expr2) {   

[PATCH 2/2] test: cmd: fdt: Drop new unneeded curly brackets

2023-03-01 Thread Marek Vasut
Drop no longer needed { } around ut_assert*() functions in FDT test.
No functional change.

Signed-off-by: Marek Vasut 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
 test/cmd/fdt.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 79ec45bbc2a..e1a07ceb67f 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -796,23 +796,21 @@ static int fdt_test_set_single(struct unit_test_state 
*uts,
 * => fdt set /path property
 */
ut_assertok(console_record_reset_enable());
-   if (sval) {
+   if (sval)
ut_assertok(run_commandf("fdt set %s %s %s", path, prop, sval));
-   } else if (integer) {
+   else if (integer)
ut_assertok(run_commandf("fdt set %s %s <%d>", path, prop, 
ival));
-   } else {
+   else
ut_assertok(run_commandf("fdt set %s %s", path, prop));
-   }
 
/* Validate the property is present and has correct value. */
ut_assertok(run_commandf("fdt get value svar %s %s", path, prop));
-   if (sval) {
+   if (sval)
ut_asserteq_str(sval, env_get("svar"));
-   } else if (integer) {
+   else if (integer)
ut_asserteq(ival, env_get_hex("svar", 0x1234));
-   } else {
+   else
ut_assertnull(env_get("svar"));
-   }
ut_assertok(ut_check_console_end(uts));
 
return 0;
-- 
2.39.2



[PATCH] cmd: fdt: Drop the 0x prefix

2023-03-01 Thread Marek Vasut
The 'fdt get addr' is always assumed to be hex value, drop the prefix.
Since this might break existing users who depend on the existing
behavior with 0x prefix, this is a separate patch. Revert if this
breaks anything.

Signed-off-by: Marek Vasut 
---
Cc: Heinrich Schuchardt 
Cc: Simon Glass 
Cc: Tom Rini 
---
 cmd/fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/fdt.c b/cmd/fdt.c
index f38fe909c3e..04b664e652c 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -478,7 +478,7 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
/* Get address */
char buf[19];
 
-   snprintf(buf, sizeof(buf), "0x%lx",
+   snprintf(buf, sizeof(buf), "%lx",
 (ulong)map_to_sysmem(nodep));
env_set(var, buf);
} else if (subcmd[0] == 's') {
-- 
2.39.2



Re: [PATCH V2 1/9] gpio: gpio-rockchip: parse gpio-ranges for bank id

2023-03-01 Thread Kever Yang

Hi Linus,

On 2023/2/23 16:59, Linus Walleij wrote:

On Mon, Feb 13, 2023 at 11:28 PM Chris Morgan  wrote:


From: Chris Morgan 

Use the new devicetree property of gpio-ranges to determine the GPIO
bank ID. Preserve the "old" way of doing things too, so that boards
can be migrated and tested gradually (I only have a 3566 and 3326 to
test).

Signed-off-by: Chris Morgan 

gpio-ranges are not supposed to be used like this, because there is
no semantic restrictions on how gpio-ranges are set up. For example:

gpio-ranges = < 0 0 32>;

that looks nice for this usecase, and I guess this is something
like what you have but then look at this from arch/arm/boot/dts/hi3620.dtsi:

 gpio-ranges = <  0 14 1  1 15 1  2 16 1
  3 16 1  4 16 1  5 16 1
  6 16 1  7 16 1>;


I can understand the gpio-ranges and pinctrl framework are flexible 
enough for different hardware.


Rockchip SoC do not have this kind of GPIO/PINMUX hardware, one bank 
GPIO is always


in one pinctrl/ioc for now, so this driver do work for rockchip platform 
in U-Boot for now.



Thanks,

- Kever



This is perfectly fine as well. Ranges can start anywhere in the hardware
offsets and go anywhere, and be set up in smaller chunks however
the author of the DTS file wants it.

I am pretty sure the same discontiguous
ranges can be encoded into the rk_gpio relevant DTS files as well,
so this is not a good solution to your problem.

What has been used in the past is just some unique hardware ID in the
device tree, so I would just add that.

Yours,
Linus Walleij


Re: [PATCH V2 8/9] arm64: dts: rockchip: add gpio-ranges property to gpio nodes

2023-03-01 Thread Kever Yang

Hi Quentin, Vasily,

On 2023/2/28 19:26, Quentin Schulz wrote:

Hi Vasily,

On 2/23/23 22:12, Vasily Khoruzhick wrote:
On Mon, Feb 13, 2023 at 2:30 PM Chris Morgan  
wrote:


From: Chris Morgan 

Add gpio-ranges property to GPIO nodes so that the bank ID can
be correctly derived for each GPIO bank.


Should not it be merged into linux first? Otherwise it will be
overwritten during the next dts sync with linux.



Considering that Linux maintainers have just rejected this 
implementation, yes we should wait on it being merged before 
supporting it in U-Boot :)



There are still some drivers are different with kernel, eg. 
pinctrl, and clock driver and etc, and kernel driver also changes.


Since the gpio bank support issue has been a period, I would like to 
take one version driver at least can fix it and make U-Boot work with 
new kernel dts


and new device. The U-Boot only use small set of the devices, so we want 
to have a small enough but enough for U-Boot version driver.


So I have take this patch set, and we can improve later when kernel have 
a version and we have a better solution for U-Boot.



Thanks,

- Kever



Cheers,
Quentin


Re: [RFC PATCH 1/1] eficonfig: Add a 'scan-only' mode in eficonfig

2023-03-01 Thread Masahisa Kojima
Hi Ilias,

On Wed, 1 Mar 2023 at 23:44, Ilias Apalodimas
 wrote:
>
> eficonfig will automatically scan and add Boot variables on launch.
> It will also perform automatic management of the automatically added
> variables (e.g it might decide to delete a boot option if the DP
> disappears).  This functionality is useful outside the context of
> eficonfig as well.
>
> So let's add a -a flag to eficonfig that will only perform the
> automatic variable management and exit.  That would allow users
> to define a bootcmd along the lines of 'eficonfig -a && bootefi bootmgr',
> that matches the §3.5.1.1 'Removable Media Boot Behavior' behaviour
> described in the EFI spec.
>
> Open questions:
> - Is this ok to add on eficonfig? Similar functionality is described in the 
> EFI
>   spec as part of the efibootmgr
> - Having the functionality on the command gives us the flexibility to run the
>   run the command when needed.  Alternatively we could move it to the 
> efibootmgr
>   and hide it behing a Kconfig option

In current implementation, "bootmenu" and "eficonfig" invoke this
automatic load option
management function, but I think "bootmenu" should not have responsibility for
load option management.
So I'll vote for moving this automatic load option management into efibootmgr,
then it is invoked in efi subsystem initialization.

Regards,
Masahisa Kojima

> Signed-off-by: Ilias Apalodimas 
> ---
>  cmd/eficonfig.c | 23 ---
>  1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c
> index 720f52b48b8c..9b6631816997 100644
> --- a/cmd/eficonfig.c
> +++ b/cmd/eficonfig.c
> @@ -2693,10 +2693,18 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int 
> flag, int argc, char *const a
>  {
> efi_status_t ret;
> struct efimenu *efi_menu;
> +   bool exit_on_scan = false;
>
> -   if (argc > 1)
> +   if (argc > 2)
> return CMD_RET_USAGE;
>
> +   if (argc > 1) {
> +   if (!strcmp(argv[1], "-a"))
> +   exit_on_scan = true;
> +   else
> +   return CMD_RET_FAILURE;
> +   }
> +
> ret = efi_init_obj_list();
> if (ret != EFI_SUCCESS) {
> log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
> @@ -2713,6 +2721,9 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int 
> flag, int argc, char *const a
> if (ret != EFI_SUCCESS && ret != EFI_NOT_FOUND)
> return ret;
>
> +   if (exit_on_scan)
> +   return EFI_SUCCESS;
> +
> while (1) {
> efi_menu = eficonfig_create_fixed_menu(maintenance_menu_items,
>
> ARRAY_SIZE(maintenance_menu_items));
> @@ -2734,8 +2745,14 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int 
> flag, int argc, char *const a
> return CMD_RET_SUCCESS;
>  }
>
> +static char eficonfig_help_text[] =
> +   " - UEFI menu to configure UEFI variables\n"
> +   "\n"
> +   "eficonfig - Spawn the configuration menu\n"
> +   "  -a Scan, configure Boot variables and exit\n";
> +
>  U_BOOT_CMD(
> -   eficonfig, 1, 0, do_eficonfig,
> +   eficonfig, 2, 0, do_eficonfig,
> "provide menu-driven UEFI variable maintenance interface",
> -   ""
> +   eficonfig_help_text
>  );
> --
> 2.39.2
>


Re: Pull request: u-boot-rockchip-20230228

2023-03-01 Thread Kever Yang

Hi Tom,

On 2023/3/1 22:54, Tom Rini wrote:

On Wed, Mar 01, 2023 at 08:23:50AM +0800, Kever Yang wrote:


Hi Tom,

Please pull the updates for rockchip platform:
- Add support for rk3588 soc;
- Add rk3588 Edgeble Neu6 board and Radxa ROCK5B board;
- Add rk3308 Radxa ROCK Pi S board;
- Add rk3568 Radxa ROCK 3 board,
- Add rk3566 Radxa Compute Module 3 board;
- Add support for sdram reg info version 3
- Refactor rockchip OTP/eFuse driver and add more soc support;
- Add external TPL support for binman;

binman support for mkimage ignore missing entry is based on [1];

CI:
https://source.denx.de/u-boot/custodians/u-boot-rockchip/-/pipelines/15403

Thanks,
- Kever

[1] 
https://patchwork.ozlabs.org/project/uboot/patch/20230219220158.4160763-7-jo...@kwiboo.se/


The following changes since commit e8c80ac0f7a13bf0fc016ce324b870c0cff7a2b8:

   Prepare v2023.04-rc3 (2023-02-27 17:18:36 -0500)

are available in the Git repository at:

   https://source.denx.de/u-boot/custodians/u-boot-rockchip.git 
tags/u-boot-rockchip-20230228

for you to fetch changes up to a6e85a35b50ade7df5f32092c1cc05ade303a22a:

   board: rock5b-rk3588: add memory gaps into kernel's DTB (2023-02-28 18:07:29 
+0800)


As I have been waiting for this, as it resolves some fairly important
fixes, I've taken this to master for the next release. But looking
forward, lets please try and get these bigger PRs done by -rc1 or -rc2
at the latest.  Thanks!


Got it, thanks.

This is a bit late because I do wait for the binman support external TPL 
patch ready, and also fix some


other CI build errors.

Thanks,

- Kever





[PATCH] mtd: spi-nor: Add CHIP_ERASE optimization

2023-03-01 Thread Marek Vasut
Add support for CHIP_ERASE opcode 0xc7 . This is useful in case the
entire SPI NOR is supposed to be erase at once, as is it considerably
faster than 4k sector erase and even slightly faster than 64k block
erase. The spi_nor_erase_chip() implementation is adapted from Linux
6.1.y as of commit 7d54cb2c26dad ("Linux 6.1.14") . The chip erase is
only used in case the entire MTD device is being erased, and the chip
does support this functionality.

Timing figures from W25Q128JW:
16 MiB erase using 4kiB sector erase opcode 0x20 ... 107.5s
16 MiB erase using 64kiB block erase opcode 0xd8 ... 39.1s
16 MiB erase using chip erase opcode 0xc7 .. 38.7s

Signed-off-by: Marek Vasut 
---
Cc: Jagan Teki 
Cc: Vignesh R 
---
 drivers/mtd/spi/spi-nor-core.c | 31 ++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 2c3116ee530..83d7fe44ee1 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -903,6 +903,30 @@ static int read_bar(struct spi_nor *nor, const struct 
flash_info *info)
 }
 #endif
 
+/**
+ * spi_nor_erase_chip() - Erase the entire flash memory.
+ * @nor:   pointer to 'struct spi_nor'.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int spi_nor_erase_chip(struct spi_nor *nor)
+{
+   struct spi_mem_op op =
+   SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_CHIP_ERASE, 0),
+  SPI_MEM_OP_NO_ADDR,
+  SPI_MEM_OP_NO_DUMMY,
+  SPI_MEM_OP_NO_DATA);
+   int ret;
+
+   spi_nor_setup_op(nor, , nor->write_proto);
+
+   ret = spi_mem_exec_op(nor->spi, );
+   if (ret)
+   return ret;
+
+   return nor->mtd.size;
+}
+
 /*
  * Initiate the erasure of a single sector. Returns the number of bytes erased
  * on success, a negative error code on error.
@@ -974,7 +998,12 @@ static int spi_nor_erase(struct mtd_info *mtd, struct 
erase_info *instr)
if (ret < 0)
goto erase_err;
 
-   ret = spi_nor_erase_sector(nor, addr);
+   if (len == mtd->size &&
+   !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) {
+   ret = spi_nor_erase_chip(nor);
+   } else {
+   ret = spi_nor_erase_sector(nor, addr);
+   }
if (ret < 0)
goto erase_err;
 
-- 
2.39.2



Re: [PATCH V7 07/15] arm: dts: iot2050: Allow verifying U-Boot proper by SPL

2023-03-01 Thread Simon Glass
On Tue, 28 Feb 2023 at 11:19, Jan Kiszka  wrote:
>
> From: Jan Kiszka 
>
> Add hashes and configuration signature stubs to prepare verified boot
> of main U-Boot by SPL.
>
> Signed-off-by: Jan Kiszka 
> ---
>  arch/arm/dts/k3-am65-iot2050-boot-image.dtsi | 16 
>  1 file changed, 16 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH V7 02/15] arm: dts: iot2050: Use the auto generator nodes for fdt

2023-03-01 Thread Simon Glass
On Tue, 28 Feb 2023 at 11:20, Jan Kiszka  wrote:
>
> From: Su Baocheng 
>
> Refactor according to the entry `fit: Entry containing a FIT` of
> document tools/binman/README.entries.
>
> As the generator uses the device tree name for the config description,
> board_fit_config_name_match requires a small adjustment as well.
>
> Signed-off-by: Su Baocheng 
> [Jan: re-add now required CONFIG_OF_LIST, update config matching]
> Signed-off-by: Jan Kiszka 
> ---
>  arch/arm/dts/k3-am65-iot2050-boot-image.dtsi | 44 
>  board/siemens/iot2050/board.c|  3 ++
>  configs/iot2050_pg1_defconfig|  1 +
>  configs/iot2050_pg2_defconfig|  1 +
>  4 files changed, 12 insertions(+), 37 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH V7 12/15] board: siemens: iot2050: use the named gpio to control the user-button

2023-03-01 Thread Simon Glass
Hi Jan,

On Tue, 28 Feb 2023 at 11:21, Jan Kiszka  wrote:
>
> From: chao zeng 
>
> User-button is controlled by the mcu domain gpio number 25.
> But main0 main1 mcu domain all have gpio number 25.
>
> To identify where the gpio is from, Using gpio controll base as the prefix
> to indicate the gpio resource.
>
> Signed-off-by: chao zeng 
> ---
>  board/siemens/iot2050/board.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
Reviewed-by: Simon Glass 


You might consider having a board note with this sort of information,
e.g. using sysinfo, as using a node name in the code is pretty ugly.

> diff --git a/board/siemens/iot2050/board.c b/board/siemens/iot2050/board.c
> index 57d7009e8c7..2735ae3fb74 100644
> --- a/board/siemens/iot2050/board.c
> +++ b/board/siemens/iot2050/board.c
> @@ -183,7 +183,7 @@ static bool user_button_pressed(void)
>
> memset(, 0, sizeof(gpio));
>
> -   if (dm_gpio_lookup_name("25", ) < 0 ||
> +   if (dm_gpio_lookup_name("gpio@4211_25", ) < 0 ||
> dm_gpio_request(, "USER button") < 0 ||
> dm_gpio_set_dir_flags(, GPIOD_IS_IN) < 0)
> return false;
> --
> 2.35.3
>

Regards,
Simon


Re: [PATCH V7 13/15] iot2050: Refresh defconfigs and activate CONFIG_EFI_SCROLL_ON_CLEAR_SCREEN

2023-03-01 Thread Simon Glass
On Tue, 28 Feb 2023 at 11:22, Jan Kiszka  wrote:
>
> From: Jan Kiszka 
>
> This feature is desired on the platform.
>
> Signed-off-by: Jan Kiszka 
> ---
>  configs/iot2050_pg1_defconfig | 1 +
>  configs/iot2050_pg2_defconfig | 5 +
>  2 files changed, 2 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH V7 15/15] iot2050: Add support for configuring M.2 connector

2023-03-01 Thread Simon Glass
Hi Jan,

On Tue, 28 Feb 2023 at 11:23, Jan Kiszka  wrote:
>
> From: Jan Kiszka 
>
> The M.2 slots of the related IOT2050 variant need to be configured
> according to the plugged cards. This tries to detect the card using the
> M.2 configuration pins of the B-key slot. If that fails, a U-Boot
> environment variable can be set to configure manually. This variable is
> write-permitted also in secure boot mode as it is not able to undermine
> the integrity of the booted system.
>
> The configuration is then applied to mux the serdes and to fix up the
> device tree passed to or loaded by the bootloader. The fix-ups are
> coming from device tree overlays that are embedded into the firmware
> image and there also integrity protected. The OS remains free to load
> a device tree to which they do not apply: U-Boot will not fail to boot
> in that case.
>
> Based on original patch by Chao Zeng.
>
> Signed-off-by: Jan Kiszka 
> ---
>  arch/arm/dts/Makefile |   4 +-
>  arch/arm/dts/k3-am65-iot2050-boot-image.dtsi  |  38 ++-
>  ...050-advanced-m2-bkey-ekey-pcie-overlay.dts |  27 ++
>  ...-iot2050-advanced-m2-bkey-usb3-overlay.dts |  47 
>  board/siemens/iot2050/board.c | 259 +-
>  doc/board/siemens/iot2050.rst |  18 ++
>  include/configs/iot2050.h |   1 +
>  7 files changed, 391 insertions(+), 3 deletions(-)
>  create mode 100644 
> arch/arm/dts/k3-am6548-iot2050-advanced-m2-bkey-ekey-pcie-overlay.dts
>  create mode 100644 
> arch/arm/dts/k3-am6548-iot2050-advanced-m2-bkey-usb3-overlay.dts

There is an 'extension' command and associated infra available. Also
there is sysinfo. I just wanted to check if either of those is helpful
here.

Regards,
Simon


Re: [PATCH v2 2/5] cmd: introduce 'write' command

2023-03-01 Thread Simon Glass
On Wed, 1 Mar 2023 at 14:13, Rasmus Villemoes
 wrote:
>
> It's almost no extra code to hook up a buddy to the 'read' command. In
> fact, since the command is passed its own 'struct cmd_tbl', we can use
> the exact same callback, and let it figure out for itself whether it
> was invoked as "read" or "write".
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  cmd/Kconfig  |  5 +
>  cmd/Makefile |  1 +
>  cmd/read.c   | 29 ++---
>  3 files changed, 28 insertions(+), 7 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 5/5] test: add tests of 'read' and 'write' shell commands

2023-03-01 Thread Simon Glass
On Wed, 1 Mar 2023 at 14:13, Rasmus Villemoes
 wrote:
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  test/cmd/Makefile |   1 +
>  test/cmd/rw.c | 104 ++
>  2 files changed, 105 insertions(+)
>  create mode 100644 test/cmd/rw.c

Reviewed-by: Simon Glass 

nit below

>
> diff --git a/test/cmd/Makefile b/test/cmd/Makefile
> index 2ffde8703a..7848f348bc 100644
> --- a/test/cmd/Makefile
> +++ b/test/cmd/Makefile
> @@ -18,6 +18,7 @@ obj-$(CONFIG_CMD_PINMUX) += pinmux.o
>  obj-$(CONFIG_CMD_PWM) += pwm.o
>  obj-$(CONFIG_CMD_SEAMA) += seama.o
>  ifdef CONFIG_SANDBOX
> +obj-$(CONFIG_CMD_READ) += rw.o
>  obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
>  endif
>  obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
> diff --git a/test/cmd/rw.c b/test/cmd/rw.c
> new file mode 100644
> index 00..74c2fe5f31
> --- /dev/null
> +++ b/test/cmd/rw.c
> @@ -0,0 +1,104 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Tests for read and write commands
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static int setup_partitions(struct unit_test_state *uts, struct blk_desc 
> **mmc_dev_desc)
> +{
> +   char str_disk_guid[UUID_STR_LEN + 1];
> +   struct disk_partition parts[2] = {
> +   {
> +   .start = 48, /* GPT data takes up the first 34 blocks 
> or so */
> +   .size = 4,
> +   .name = "data",
> +   },
> +   {
> +   .start = 52,
> +   .size = 10,
> +   .name = "log",
> +   },
> +   };
> +
> +   ut_asserteq(2, blk_get_device_by_str("mmc", "2", mmc_dev_desc));
> +   if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
> +   gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD);
> +   gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD);
> +   gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD);
> +   }
> +   ut_assertok(gpt_restore(*mmc_dev_desc, str_disk_guid, parts,
> +   ARRAY_SIZE(parts)));
> +   return 0;
> +}
> +
> +/* Fill the write buffer with pseudo-random data, clear the read buffer. */
> +static void init_buffers(char *rb, char *wb, size_t size, unsigned seed)
> +{
> +   memset(rb, 0, size);
> +   while (size--) {
> +   *wb++ = seed;
> +   seed *= 43;
> +   seed += 17 + size/4;
> +   }
> +}
> +
> +static int dm_test_read_write(struct unit_test_state *uts)
> +{
> +   struct blk_desc *dev_desc;
> +   char wbuf[1024], rbuf[1024];
> +   ulong wa, ra;
> +
> +#define INIT_BUFFERS() init_buffers(rbuf, wbuf, sizeof(rbuf), __LINE__)
> +
> +   ut_assertok(setup_partitions(uts, _desc));
> +
> +   wa = map_to_sysmem(wbuf);
> +   ra = map_to_sysmem(rbuf);
> +
> +   /* Simple test, write to/read from same partition. */
> +   INIT_BUFFERS();
> +   ut_assertok(run_commandf("write mmc 2:1 0x%lx 0 2", wa));
> +   ut_assertok(run_commandf("read  mmc 2:1 0x%lx 0 2", ra));
> +   ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
> +   ut_assertok(run_commandf("read  mmc 2:1 0x%lx 1 1", ra));
> +   ut_assertok(memcmp([512], rbuf, 512));
> +
> +   /* Use name for write, number for read. */
> +   INIT_BUFFERS();
> +   ut_assertok(run_commandf("write mmc 2#log 0x%lx 0 2", wa));
> +   ut_assertok(run_commandf("read  mmc 2:2   0x%lx 0 2", ra));
> +   ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
> +
> +   /* Use full device for write, name for read. */
> +   INIT_BUFFERS();
> +   ut_assertok(run_commandf("write mmc 2:00x%lx 0x30 2", wa));
> +   ut_assertok(run_commandf("read  mmc 2#data 0x%lx0 2", ra));
> +   ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
> +
> +   /* Use name for write, full device for read */
> +   INIT_BUFFERS();
> +   ut_assertok(run_commandf("write mmc 2#log 0x%lx1 2", wa));
> +   ut_assertok(run_commandf("read  mmc 2:0   0x%lx 0x35 2", ra));
> +   ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
> +
> +   /* Read/write outside partition bounds should be rejected upfront. */
> +   console_record_reset_enable();
> +ut_asserteq(1, run_commandf("read mmc 2#data 0x%lx 3 2", ra));

There are spaces in front of these lines

> +ut_assert_nextlinen("read out of range");
> +ut_assert_console_end();
> +
> +   console_record_reset_enable();
> +ut_asserteq(1, run_commandf("write mmc 2#log 0x%lx 9 2", wa));
> +ut_assert_nextlinen("write out of range");
> +ut_assert_console_end();
> +
> +   return 0;
> +}
> +
> +DM_TEST(dm_test_read_write, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
> --
> 2.37.2
>

Regards,
Simon


Re: [PATCH v2 4/5] sandbox: enable CMD_WRITE

2023-03-01 Thread Simon Glass
On Wed, 1 Mar 2023 at 14:13, Rasmus Villemoes
 wrote:
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  configs/sandbox64_defconfig | 1 +
>  configs/sandbox_defconfig   | 1 +
>  2 files changed, 2 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH v2 3/5] doc: document read/write commands

2023-03-01 Thread Simon Glass
Hi Rasmus,

On Wed, 1 Mar 2023 at 14:13, Rasmus Villemoes
 wrote:
>
> Signed-off-by: Rasmus Villemoes 
> ---
>  doc/usage/cmd/read.rst | 40 
>  doc/usage/index.rst|  1 +
>  2 files changed, 41 insertions(+)
>  create mode 100644 doc/usage/cmd/read.rst
>

Reviewed-by: Simon Glass 

Please add a commit msg

> diff --git a/doc/usage/cmd/read.rst b/doc/usage/cmd/read.rst
> new file mode 100644
> index 00..705d5a3e0c
> --- /dev/null
> +++ b/doc/usage/cmd/read.rst
> @@ -0,0 +1,40 @@
> +.. SPDX-License-Identifier: GPL-2.0+:
> +
> +read/write commands
> +===
> +
> +Synopsis
> +
> +
> +::
> +
> +read 
> +write 
> +
> +The read and write commands can be used for raw access to data in
> +block devices (or partitions therein), i.e. without going through a
> +file system.
> +
> +read
> +
> +
> +The block device is specified using the  (e.g. "mmc") and
> + parameters. If the block device has a partition table, one can
> +optionally specify a partition number (using the :part syntax) or
> +partition name (using the #partname syntax). The command then reads
> +the  blocks of data starting at block number  of the given
> +device/partition to the memory address .
> +
> +Examples:

For other commands the examples go at the bottom.

> +
> +# Read 2 MiB from partition 3 of mmc device 2 to $loadaddr
> +read mmc 2.3 $loadaddr 0 0x1000
> +
> +# Read 16 MiB from the partition named 'kernel' of mmc device 1 to 
> $loadaddr
> +read mmc 1#kernel $loadaddr 0 0x8000
> +
> +write
> +-

I think this needs its own file, with the material basically repeated
(perhaps even use an example which includes a read and a write?)

> +
> +The write command is completely equivalent to the read command, except
> +of course that the transer direction is reversed.

transfer

> diff --git a/doc/usage/index.rst b/doc/usage/index.rst
> index 840c20c934..d6365cf8a4 100644
> --- a/doc/usage/index.rst
> +++ b/doc/usage/index.rst
> @@ -71,6 +71,7 @@ Shell commands
> cmd/printenv
> cmd/pstore
> cmd/qfw
> +   cmd/read
> cmd/reset
> cmd/rng
> cmd/sbi
> --
> 2.37.2
>

Regards,
Simon


Re: [PATCH V7 04/15] iot2050: Migrate settings into board env file

2023-03-01 Thread Simon Glass
Hi Jan,

On Tue, 28 Feb 2023 at 11:20, Jan Kiszka  wrote:
>
> From: Jan Kiszka 
>
> Anything that is not boot-env related is better kept there by now.
>
> At this chance, also drop a stale comment from iot2050.h
>
> Signed-off-by: Jan Kiszka 
> ---
>  board/siemens/iot2050/iot2050.env |  9 +
>  include/configs/iot2050.h | 11 ++-
>  2 files changed, 11 insertions(+), 9 deletions(-)
>  create mode 100644 board/siemens/iot2050/iot2050.env
>
> diff --git a/board/siemens/iot2050/iot2050.env 
> b/board/siemens/iot2050/iot2050.env
> new file mode 100644
> index 000..4bd93f0b2f4
> --- /dev/null
> +++ b/board/siemens/iot2050/iot2050.env
> @@ -0,0 +1,9 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (c) Siemens AG, 2023
> + *
> + * Authors:
> + *   Jan Kiszka 
> + */
> +
> +usb_pgood_delay=900
> diff --git a/include/configs/iot2050.h b/include/configs/iot2050.h
> index cfff46ce339..8dfeaddf541 100644
> --- a/include/configs/iot2050.h
> +++ b/include/configs/iot2050.h
> @@ -13,12 +13,6 @@
>
>  #include 
>
> -/* SPL Loader Configuration */
> -
> -/* U-Boot general configuration */
> -#define EXTRA_ENV_IOT2050_BOARD_SETTINGS   \
> -   "usb_pgood_delay=900\0"
> -
>  #if IS_ENABLED(CONFIG_CMD_USB)
>  # define BOOT_TARGET_USB(func) \
> func(USB, usb, 0) \
> @@ -40,10 +34,9 @@
>
>  #include 
>
> -#define CFG_EXTRA_ENV_SETTINGS \
> +#define CFG_EXTRA_ENV_SETTINGS \
> DEFAULT_LINUX_BOOT_ENV  \
> -   BOOTENV \
> -   EXTRA_ENV_IOT2050_BOARD_SETTINGS
> +   BOOTENV
>
>  #include 
>
> --
> 2.35.3
>

You might want to move to standard boot so you can use a text-based
environment. See for example [1] [2] and later patches from [3].

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=342718
[2]
[3] from https://patchwork.ozlabs.org/project/uboot/list/?series=338993=*


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

2023-03-01 Thread Simon Glass
On Mon, 27 Feb 2023 at 12:55, Marek Vasut
 wrote:
>
> Implement function to generate internal test DT fragment and switch
> the 'fdt get value' test to this instead of depending on the sandbox
> DT. Rename clk-test node to test-node node. This FDT fragment will be
> reused by other tests. No functional change.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Heinrich Schuchardt 
> Cc: Simon Glass 
> Cc: Tom Rini 
> ---
>  test/cmd/fdt.c | 124 +++--
>  1 file changed, 111 insertions(+), 13 deletions(-)
>

Reviewed-by: Simon Glass 


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

2023-03-01 Thread Simon Glass
On Mon, 27 Feb 2023 at 12:55, Marek Vasut
 wrote:
>
> Currently any integer array value is set as long up-to-40 character
> hexadecimal string into environment variable when extracted from an
> FDT using 'fdt get value path prop index', because the support for
> handling integer arrays is not implemented, and fdt_value_env_set()
> code falls back into the hash handling behavior instead.
>
> Implement this support simply by checking whether user supplied any
> index. If index is set and the property length is multiple of four,
> then this is an integer array, and the code would extract value at
> specified index.
>
> There is a subtle change where default index is set to -1 instead of 0.
> This is OK, since the only place which checks for index to be less or
> equal zero is the string array handling code in fdt_value_env_set() and
> that code would work perfectly well with index -1 too.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Heinrich Schuchardt 
> Cc: Simon Glass 
> Cc: Tom Rini 
> ---
>  cmd/fdt.c | 14 --
>  1 file changed, 12 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH 07/10] efi: Add another tranch of GUIDs

2023-03-01 Thread Simon Glass
Hi Ilias,

On Wed, 1 Mar 2023 at 01:52, Ilias Apalodimas
 wrote:
>
> Hi Simon
>
> On Sun, 26 Feb 2023 at 03:33, Simon Glass  wrote:
> >
> > Provide information about the GUIDs supplied by QEMU, so far as it is
> > known.
>
> What the patch does is obvious.  Can you explain why this is needed though?

Yes. It allows seeing what the tables actually are, since the GUIDs
are impenetrable for that. See for example the 'efi table' command in
this series.

I think %sU uses it too.

>
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  include/efi_api.h | 28 
> >  lib/uuid.c| 12 
> >  2 files changed, 40 insertions(+)
> >
> > diff --git a/include/efi_api.h b/include/efi_api.h
> > index 2d18d25a713..90caee4038c 100644
> > --- a/include/efi_api.h
> > +++ b/include/efi_api.h
> > @@ -1909,6 +1909,34 @@ struct efi_system_resource_table {
> > EFI_GUID(0x4aafd29d, 0x68df, 0x49ee, 0x8a, 0xa9, \
> >  0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7)
> >
> > +#define EFI_LZMA_COMPRESSED \
> > +   EFI_GUID(0xee4e5898, 0x3914, 0x4259, 0x9d, 0x6e, \
> > +0xdc, 0x7b, 0xd7, 0x94, 0x03, 0xcf)
> > +#define EFI_DXE_SERVICES \
> > +   EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, \
> > +0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
> > +#define EFI_HOB_LIST \
> > +   EFI_GUID(0x7739f24c, 0x93d7, 0x11d4, 0x9a, 0x3a,  \
> > +0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
> > +#define EFI_MEMORY_TYPE \
> > +   EFI_GUID(0x4c19049f, 0x4137, 0x4dd3, 0x9c, 0x10, \
> > +0x8b, 0x97, 0xa8, 0x3f, 0xfd, 0xfa)
> > +#define EFI_SMBIOS \
> > +   EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16,  \
> > +0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
>
> This already exists as SMBIOS_TABLE_GUID

Oh dear, OK. Would you mind if I rename it? It is hard to find things
if the naming is inconsistent.

>
> > +#define EFI_MEM_STATUS_CODE_REC \
> > +   EFI_GUID(0x060cc026, 0x4c0d, 0x4dda, 0x8f, 0x41, \
> > +0x59, 0x5f, 0xef, 0x00, 0xa5, 0x02)
> > +#define EFI_GUID_SNBIOS \
> > +   EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, \
> > +0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
>
> what is SNBIOS? I assume it's a typos since it matches the existing
> SMBIOS_TABLE_GUID?

Yes, a typo

>
> > +#define EFI_GUID_EFI_ACPI1 \
> > +   EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, \
> > +0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
> > +#define EFI_GUID_EFI_ACPI2 \
> > +   EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, \
> > +0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
>
> Already exists as EFI_ACPI_TABLE_GUID

OK, bind if I rename it so we have these consistent?
>
> > +
> >  /**
> >   * struct win_certificate_uefi_guid - A certificate that encapsulates
> >   * a GUID-specific signature
> > diff --git a/lib/uuid.c b/lib/uuid.c
> > index 465e1ac38f5..77aef746a2e 100644
> > --- a/lib/uuid.c
> > +++ b/lib/uuid.c
> > @@ -255,6 +255,18 @@ static const struct {
> > EFI_CERT_TYPE_PKCS7_GUID,
> > },
> >  #endif
> > +#ifdef CONFIG_EFI_APP
> > +#endif
> > +   { "EFI_LZMA_COMPRESSED", EFI_LZMA_COMPRESSED },
> > +   { "EFI_DXE_SERVICES", EFI_DXE_SERVICES },
> > +   { "EFI_HOB_LIST", EFI_HOB_LIST },
> > +   { "EFI_MEMORY_TYPE", EFI_MEMORY_TYPE },
> > +   { "EFI_SMBIOS", EFI_SMBIOS },
> > +   { "EFI_MEM_STATUS_CODE_REC", EFI_MEM_STATUS_CODE_REC },
> > +   { "EFI_GUID_SNBIOS", EFI_GUID_SNBIOS },
> > +   { "EFI_GUID_EFI_ACPI1", EFI_GUID_EFI_ACPI1 },
> > +   { "EFI_GUID_EFI_ACPI2", EFI_GUID_EFI_ACPI2 },
> > +
> >  };
> >
> >  /*
> > --
> > 2.39.2.637.g21b0678d19-goog
> >

Regards,
Simon


Re: [PATCH] image: Fix potentially uninitialized data variable

2023-03-01 Thread Simon Glass
On Mon, 27 Feb 2023 at 12:56, Marek Vasut
 wrote:
>
> In case fitImage support is disabled, and image_locate_script() is
> passed a fitImage, then the 'data' variable is used uninitialized.
> Drop into the default: branch of the switch-case statement and do
> not return the uninitialized data, and do not modify the return
> pointer either, just print an error message.
>
> Reported by clang build:
> "
> $ make HOSTCC=clang CC=clang KCFLAGS=-Werror sandbox64_defconfig && make 
> HOSTCC=clang CC=clang KCFLAGS=-Werror
> ...
> boot/image-board.c:1006:7: error: variable 'data' is used uninitialized 
> whenever switch case is taken [-Werror,-Wsometimes-uninitialized]
> case IMAGE_FORMAT_LEGACY:
>  ^~~
> include/image.h:608:29: note: expanded from macro 'IMAGE_FORMAT_LEGACY'
> ^~~~
> boot/image-board.c:1128:19: note: uninitialized use occurs here
> *datap = (char *)data;
>  ^~~~
> boot/image-board.c:1001:11: note: initialize the variable 'data' to silence 
> this warning
> u32 *data;
>  ^
>   = NULL
> "
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Heinrich Schuchardt 
> Cc: Michal Simek 
> Cc: Oleksandr Suvorov 
> Cc: Simon Glass 
> Cc: Stefan Roese 
> Cc: Tom Rini 
> ---
>  boot/image-board.c | 15 +++
>  1 file changed, 11 insertions(+), 4 deletions(-)
>

Reviewed-by: Simon Glass 


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

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

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

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

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

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

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

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

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

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

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

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

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



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

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

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

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

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

Re: u-boot crashes if mass-storage devices are connected via USB-C

2023-03-01 Thread Marek Vasut

On 3/1/23 21:34, Simon Glass wrote:

+Marek Vasut +Bin Meng +Mark Kettenis +Tom Rini

On Wed, 1 Mar 2023 at 08:12, bluetail  wrote:


Hello. user kettenis aka "Mark Kettenis" guided me write my bug report
to this email. "bluetail: please report these usb bugs upstream; they're
almost certainly not hardware-specific"

But before, jannau aka Janne Grunau asked me to give the version output
of  `pacman -Qi uboot-asahi` to which I replied 2022.10.asahi1-1.
Because I had the feeling that sometimes the reboot with a USB-C
connected device succeeds, depending how many bays are populated. But I
have no evidence for that.
I did try other USB Type C Cables, but without success of fixing the
underlying issue. The device works fine via USB Type A or C fine if
plugged in AFTER u-boot.
But, u-boot does not support USB Type A yet, which is why it wont break
my boot sequence with USB Type A.

Essentially, I connect a mass-storage device to the USB-C port of a Mac
Mini 2020 (M1), and it leads to the issue in the attachment.
I was able to reproduce it with Icy Box IB-3810 and ICY BOX IB-3805.
Initially I thought this issue was only for some devices (also attached
here) https://github.com/AsahiLinux/u-boot/issues/4 but it appears this
might be a issue that is with many devices.

If you need any more information, please feel free to ask. I am very
eager to have this issue fixed because it seems to be a very broad issue
with mass media storage in general.
uname-r returns 6.1.0-asahi-2-2-edge-ARCH
Would it be possible to check whether current u-boot/master works any 
better ?


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

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

Signed-off-by: Eddie James 
Reviewed-by: Simon Glass 
---
Changes since v6:
 - Added comment for bootm_measure
 - Fixed line length in bootm_measure

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

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

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

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

Signed-off-by: Eddie James 
Reviewed-by: Simon Glass 
Acked-by: Ilias Apalodimas 
---
Changes since v5:
 - Remove the !SANDBOX dependency for EFI TCG2

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

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

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

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

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

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



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

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

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

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

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

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

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

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

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

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

-- 
2.31.1



Re: [PATCH v6 6/6] doc: Add measured boot documentation

2023-03-01 Thread Eddie James



On 2/22/23 14:26, Heinrich Schuchardt wrote:


Am 22. Februar 2023 19:02:42 MEZ schrieb Eddie James :

Briefly describe the feature and specify the requirements.

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

diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index cde7dcb14a..0cf78cb0e7 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -12,6 +12,7 @@ Use U-Boot
partitions
cmdline
semihosting
+   measured_boot

Shell commands
--
diff --git a/doc/usage/measured_boot.rst b/doc/usage/measured_boot.rst
new file mode 100644
index 00..8357b1f480
--- /dev/null
+++ b/doc/usage/measured_boot.rst
@@ -0,0 +1,23 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Measured Boot
+=

This completely misses o describe measured boot with UEFI.

@Ilias, do you want to add that in a follow up patch?


+
+U-Boot can perform a measured boot, the process of hashing various components
+of the boot process, extending the results in the TPM and logging the
+component's measurement in memory for the operating system to consume.
+
+Requirements
+-
+
+* A hardware TPM 2.0 supported by the U-Boot drivers
+* CONFIG_TPM=y
+* CONFIG_MEASURED_BOOT=y
+* Device-tree configuration of the TPM device to specify the memory area
+  for event logging. The TPM device node must either contain a phandle to
+  a reserved memory region or "linux,sml-base" and "linux,sml-size"
+  indicating the address and size of the memory region. An example can be
+  found in arch/sandbox/dts/test.dts
+* The operating system must also be configured to use the memory regions
+  specified in the U-Boot device-tree in order to make use of the event
+  log.

Please, provide enough information such that a reader can set this up. This 
should include example code.



Hi Heinrich,


I'm not sure what example code you mean. No additional code is necessary 
for U-Boot to perform the measurements, only the requirements stated. If 
you mean the operating system setup, I don't think here is the right 
place to document that, as it has nothing to do with U-Boot. Either way, 
Linux would not require any code, only a similar devicetree entry and 
TPM driver.



Thanks,

Eddie




Best regards

Heinrich


Re: [PATCH v7 01/10] video console: refactoring and optimization

2023-03-01 Thread Anatolij Gustschin
Hi Dzmitry,

On Mon, 27 Feb 2023 20:37:01 +0300
Dzmitry Sankouski dsankou...@gmail.com wrote:

> - move common code to vidconsole_internal.h and console_core.c
> - unite probe functions
> - get rid of code duplications in switch across bpp values
> - extract common pixel fill logic in two functions one per
> horizontal and vertical filling
> - rearrange statements in put_xy* methods in unified way
> - replace types - uint*_t to u*
> 
> Signed-off-by: Dzmitry Sankouski 
> Reviewed-by: Simon Glass 
> ---
> Changes for v2: none
> Changes for v3: none
> Changes for v4:
> - move common code to vidconsole_internal.h
> - unite probe functions
> Changes for v5:
> - move common functions to console-core.c file
> - remove static keyword from shared functions
> Changes for v6: none
> Changes for v7: none
> 
>  drivers/video/Makefile  |   6 +
>  drivers/video/console_core.c| 141 +

Building console_core.c fails for board configs without CONFIG_VIDEO_COPY,
i.e.:

  https://source.denx.de/u-boot/custodians/u-boot-video/-/jobs/587261

I fixed it for further build testing by additionally applying:

diff --git a/include/video_console.h b/include/video_console.h
index 9d2c0f210e..3e1e00c23f 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -340,6 +340,9 @@ int vidconsole_sync_copy(struct udevice *dev, void *from, 
void *to);
 int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
   int size);
 #else
+
+#include 
+
 static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
   void *to)
 {


--
Anatolij


Re: [PATCH v7 10/10] video console: add 12x22 console simple font test

2023-03-01 Thread Anatolij Gustschin
Hi Dzmitry,

On Mon, 27 Feb 2023 20:37:10 +0300
Dzmitry Sankouski dsankou...@gmail.com wrote:

> Tests fonts wider than a byte.
> 
> Signed-off-by: Dzmitry Sankouski 
> Reviewed-by: Simon Glass 
> ---
> Changes for v2: N/A
> Changes for v2: none
> Charges for v4: N/A
> Charges for v5: N/A
> Charges for v6:
> - rebase
> - move sandbox defconfig change to separate patch
> - run savedefconfig
> Charges for v7: none
> 
>  test/dm/video.c | 41 +
>  1 file changed, 41 insertions(+)

I've applied this patch series for build testing, this test fails:

 https://source.denx.de/u-boot/custodians/u-boot-video/-/jobs/587666

Could you please fix it? Thanks!
 
--
Anatolij


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

2023-03-01 Thread Doug Anderson
Hi,

On Sun, Feb 19, 2023 at 3:50 PM Simon Glass  wrote:
>
> For large series this can take a while. Run checkpatch in parallel to
> try to reduce the time. The checkpatch information is still reported in
> sequential order, so a very slow patch at the start can still slow
> things down. But overall this gives good results.
>
> Signed-off-by: Simon Glass 
> ---
>
> (no changes since v1)
>
>  tools/patmanu/checkpatch.py | 46 +
>  1 file changed, 26 insertions(+), 20 deletions(-)

Reviewed-by: Douglas Anderson 


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

2023-03-01 Thread Doug Anderson
Hi,

On Sun, Feb 19, 2023 at 3:50 PM Simon Glass  wrote:
>
> This script can take ages on some series. Try to limit the time by
> using threads. If a few stubborn patches remain, show progress so the
> user has some idea what is going on.
>
> Signed-off-by: Simon Glass 
> ---
>
> (no changes since v1)
>
>  tools/patmanu/func_test.py |  2 ++
>  tools/patmanu/series.py| 33 ++---
>  2 files changed, 32 insertions(+), 3 deletions(-)
>
> diff --git a/tools/patmanu/func_test.py b/tools/patmanu/func_test.py
> index 238fd5b6100..48109ae5725 100644
> --- a/tools/patmanu/func_test.py
> +++ b/tools/patmanu/func_test.py
> @@ -240,6 +240,8 @@ class TestFunctional(unittest.TestCase):
>  self.assertEqual('Change log missing for v3', next(lines))
>  self.assertEqual('Change log for unknown version v4', next(lines))
>  self.assertEqual("Alias 'pci' not found", next(lines))
> +while next(lines) != 'Cc processing complete':
> +pass
>  self.assertIn('Dry run', next(lines))
>  self.assertEqual('', next(lines))
>  self.assertIn('Send a total of %d patches' % count, next(lines))
> diff --git a/tools/patmanu/series.py b/tools/patmanu/series.py
> index 8ead87ef53e..e7a5f91da87 100644
> --- a/tools/patmanu/series.py
> +++ b/tools/patmanu/series.py
> @@ -5,8 +5,11 @@
>  from __future__ import print_function
>
>  import collections
> +import concurrent.futures
>  import itertools
>  import os
> +import sys
> +import time
>
>  from patmanu import get_maintainer
>  from patmanu import gitutil
> @@ -302,10 +305,34 @@ class Series(dict):
>  fd = open(fname, 'w', encoding='utf-8')
>  all_ccs = []
>  all_skips = set()
> +with concurrent.futures.ThreadPoolExecutor(max_workers=16) as 
> executor:
> +for i, commit in enumerate(self.commits):
> +commit.seq = i
> +commit.future = executor.submit(
> +self.GetCcForCommit, commit, process_tags, warn_on_error,
> +add_maintainers, limit, get_maintainer_script, all_skips)
> +
> +# Show progress any commits that are taking forever
> +lastlen = 0
> +while True:
> +left = [commit for commit in self.commits
> +if not commit.future.done()]
> +if not left:
> +break
> +names = ', '.join(f'{c.seq + 1}:{c.subject}'
> +  for c in left[:2])
> +out = f'\r{len(left)} remaining: {names}'[:79]
> +spaces = ' ' * (lastlen - len(out))
> +if lastlen:  # Don't print anything the first time
> +print(out, spaces, end='')
> +sys.stdout.flush()
> +lastlen = len(out)
> +time.sleep(.25)
> +print(f'\rdone{" " * lastlen}\r', end='')
> +print('Cc processing complete')
> +
>  for commit in self.commits:
> -cc = self.GetCcForCommit(commit, process_tags, warn_on_error,
> - add_maintainers, limit,
> - get_maintainer_script, all_skips)
> +cc = commit.future.result()

I've never used "concurrent.futures" before, but looks reasonable to me.

Reviewed-by: Douglas Anderson 


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

2023-03-01 Thread Doug Anderson
Hi,

On Sun, Feb 19, 2023 at 3:50 PM Simon Glass  wrote:
>
> @@ -234,6 +234,48 @@ class Series(dict):
>  str = 'Change log exists, but no version is set'
>  print(col.build(col.RED, str))
>
> +def GetCcForCommit(self, commit, process_tags, warn_on_error,
> +   add_maintainers, limit, get_maintainer_script,
> +   all_skips):
> +"""Get the email CCs to use with a particular commit
> +
> +Uses subject tags and get_maintainers.pl script to find people to cc
> +on a patch
> +
> +Args:
> +commit (Commit): Commit to process
> +process_tags (bool): Process tags as if they were aliases
> +warn_on_error (bool): True to print a warning when an alias 
> fails to
> +match, False to ignore it.
> +add_maintainers (bool or list of str): Either:
> +True/False to call the get_maintainers to CC maintainers
> +List of maintainers to include (for testing)
> +limit (int): Limit the length of the Cc list (None if no limit)
> +get_maintainer_script (str): The file name of the 
> get_maintainer.pl
> +script (or compatible).
> +all_skips (set of str): Set of bouncing email address that were
> +dropped from the output

It wouldn't hurt to mention that "all_skips" is essentially a return
value from this function (this function updates it to include the
email addresses that were skipped).


> @@ -259,28 +301,18 @@ class Series(dict):
>  fname = '/tmp/patman.%d' % os.getpid()
>  fd = open(fname, 'w', encoding='utf-8')
>  all_ccs = []
> +all_skips = set()
>  for commit in self.commits:
> -cc = []
> -if process_tags:
> -cc += gitutil.build_email_list(commit.tags,
> -   warn_on_error=warn_on_error)
> -cc += gitutil.build_email_list(commit.cc_list,
> -   warn_on_error=warn_on_error)
> -if type(add_maintainers) == type(cc):
> -cc += add_maintainers
> -elif add_maintainers:
> -
> -cc += get_maintainer.get_maintainer(get_maintainer_script,
> -commit.patch)
> -for x in set(cc) & set(settings.bounces):
> -print(col.build(col.YELLOW, 'Skipping "%s"' % x))
> -cc = list(set(cc) - set(settings.bounces))
> -if limit is not None:
> -cc = cc[:limit]
> +cc = self.GetCcForCommit(commit, process_tags, warn_on_error,
> + add_maintainers, limit,
> + get_maintainer_script, all_skips)
>  all_ccs += cc
>  print(commit.patch, '\0'.join(sorted(set(cc))), file=fd)
>  self._generated_cc[commit.patch] = cc
>
> +for x in sorted(list(all_skips)):

Why "sorted(list(all_skips))" and not just "sorted(all_skips)"?

Both of the above are nits, so I'm OK w/:

Reviewed-by: Douglas Anderson 


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

2023-03-01 Thread Doug Anderson
Hi,

On Sun, Feb 19, 2023 at 3:50 PM Simon Glass  wrote:
>
> Patman does not do this anymore, so drop the comment.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v2:
> - Fix 'uncorrect' typo in subject
>
>  tools/patmanu/control.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

I guess this is as-of commit 7428dc14b0f2 ("patman: Remove the -a
option") ? It would be nice to mention that in the commit message...

Reviewed-by: Douglas Anderson 


[PATCH v2 5/5] test: add tests of 'read' and 'write' shell commands

2023-03-01 Thread Rasmus Villemoes
Signed-off-by: Rasmus Villemoes 
---
 test/cmd/Makefile |   1 +
 test/cmd/rw.c | 104 ++
 2 files changed, 105 insertions(+)
 create mode 100644 test/cmd/rw.c

diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index 2ffde8703a..7848f348bc 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_CMD_PINMUX) += pinmux.o
 obj-$(CONFIG_CMD_PWM) += pwm.o
 obj-$(CONFIG_CMD_SEAMA) += seama.o
 ifdef CONFIG_SANDBOX
+obj-$(CONFIG_CMD_READ) += rw.o
 obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
 endif
 obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
diff --git a/test/cmd/rw.c b/test/cmd/rw.c
new file mode 100644
index 00..74c2fe5f31
--- /dev/null
+++ b/test/cmd/rw.c
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for read and write commands
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int setup_partitions(struct unit_test_state *uts, struct blk_desc 
**mmc_dev_desc)
+{
+   char str_disk_guid[UUID_STR_LEN + 1];
+   struct disk_partition parts[2] = {
+   {
+   .start = 48, /* GPT data takes up the first 34 blocks 
or so */
+   .size = 4,
+   .name = "data",
+   },
+   {
+   .start = 52,
+   .size = 10,
+   .name = "log",
+   },
+   };
+
+   ut_asserteq(2, blk_get_device_by_str("mmc", "2", mmc_dev_desc));
+   if (CONFIG_IS_ENABLED(RANDOM_UUID)) {
+   gen_rand_uuid_str(parts[0].uuid, UUID_STR_FORMAT_STD);
+   gen_rand_uuid_str(parts[1].uuid, UUID_STR_FORMAT_STD);
+   gen_rand_uuid_str(str_disk_guid, UUID_STR_FORMAT_STD);
+   }
+   ut_assertok(gpt_restore(*mmc_dev_desc, str_disk_guid, parts,
+   ARRAY_SIZE(parts)));
+   return 0;
+}
+
+/* Fill the write buffer with pseudo-random data, clear the read buffer. */
+static void init_buffers(char *rb, char *wb, size_t size, unsigned seed)
+{
+   memset(rb, 0, size);
+   while (size--) {
+   *wb++ = seed;
+   seed *= 43;
+   seed += 17 + size/4;
+   }
+}
+
+static int dm_test_read_write(struct unit_test_state *uts)
+{
+   struct blk_desc *dev_desc;
+   char wbuf[1024], rbuf[1024];
+   ulong wa, ra;
+
+#define INIT_BUFFERS() init_buffers(rbuf, wbuf, sizeof(rbuf), __LINE__)
+
+   ut_assertok(setup_partitions(uts, _desc));
+
+   wa = map_to_sysmem(wbuf);
+   ra = map_to_sysmem(rbuf);
+
+   /* Simple test, write to/read from same partition. */
+   INIT_BUFFERS();
+   ut_assertok(run_commandf("write mmc 2:1 0x%lx 0 2", wa));
+   ut_assertok(run_commandf("read  mmc 2:1 0x%lx 0 2", ra));
+   ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
+   ut_assertok(run_commandf("read  mmc 2:1 0x%lx 1 1", ra));
+   ut_assertok(memcmp([512], rbuf, 512));
+
+   /* Use name for write, number for read. */
+   INIT_BUFFERS();
+   ut_assertok(run_commandf("write mmc 2#log 0x%lx 0 2", wa));
+   ut_assertok(run_commandf("read  mmc 2:2   0x%lx 0 2", ra));
+   ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
+   
+   /* Use full device for write, name for read. */
+   INIT_BUFFERS();
+   ut_assertok(run_commandf("write mmc 2:00x%lx 0x30 2", wa));
+   ut_assertok(run_commandf("read  mmc 2#data 0x%lx0 2", ra));
+   ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
+
+   /* Use name for write, full device for read */
+   INIT_BUFFERS();
+   ut_assertok(run_commandf("write mmc 2#log 0x%lx1 2", wa));
+   ut_assertok(run_commandf("read  mmc 2:0   0x%lx 0x35 2", ra));
+   ut_assertok(memcmp(wbuf, rbuf, sizeof(wbuf)));
+
+   /* Read/write outside partition bounds should be rejected upfront. */
+   console_record_reset_enable();
+ut_asserteq(1, run_commandf("read mmc 2#data 0x%lx 3 2", ra));
+ut_assert_nextlinen("read out of range");
+ut_assert_console_end();
+
+   console_record_reset_enable();
+ut_asserteq(1, run_commandf("write mmc 2#log 0x%lx 9 2", wa));
+ut_assert_nextlinen("write out of range");
+ut_assert_console_end();
+
+   return 0;
+}
+
+DM_TEST(dm_test_read_write, UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
-- 
2.37.2



[PATCH v2 3/5] doc: document read/write commands

2023-03-01 Thread Rasmus Villemoes
Signed-off-by: Rasmus Villemoes 
---
 doc/usage/cmd/read.rst | 40 
 doc/usage/index.rst|  1 +
 2 files changed, 41 insertions(+)
 create mode 100644 doc/usage/cmd/read.rst

diff --git a/doc/usage/cmd/read.rst b/doc/usage/cmd/read.rst
new file mode 100644
index 00..705d5a3e0c
--- /dev/null
+++ b/doc/usage/cmd/read.rst
@@ -0,0 +1,40 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+read/write commands
+===
+
+Synopsis
+
+
+::
+
+read 
+write 
+
+The read and write commands can be used for raw access to data in
+block devices (or partitions therein), i.e. without going through a
+file system.
+
+read
+
+
+The block device is specified using the  (e.g. "mmc") and
+ parameters. If the block device has a partition table, one can
+optionally specify a partition number (using the :part syntax) or
+partition name (using the #partname syntax). The command then reads
+the  blocks of data starting at block number  of the given
+device/partition to the memory address .
+
+Examples:
+
+# Read 2 MiB from partition 3 of mmc device 2 to $loadaddr
+read mmc 2.3 $loadaddr 0 0x1000
+
+# Read 16 MiB from the partition named 'kernel' of mmc device 1 to 
$loadaddr
+read mmc 1#kernel $loadaddr 0 0x8000
+
+write
+-
+
+The write command is completely equivalent to the read command, except
+of course that the transer direction is reversed.
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 840c20c934..d6365cf8a4 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -71,6 +71,7 @@ Shell commands
cmd/printenv
cmd/pstore
cmd/qfw
+   cmd/read
cmd/reset
cmd/rng
cmd/sbi
-- 
2.37.2



[PATCH v2 4/5] sandbox: enable CMD_WRITE

2023-03-01 Thread Rasmus Villemoes
Signed-off-by: Rasmus Villemoes 
---
 configs/sandbox64_defconfig | 1 +
 configs/sandbox_defconfig   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index ccbc18aad0..b7737814af 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -58,6 +58,7 @@ CONFIG_CMD_SPI=y
 CONFIG_CMD_TEMPERATURE=y
 CONFIG_CMD_USB=y
 CONFIG_CMD_WDT=y
+CONFIG_CMD_WRITE=y
 CONFIG_CMD_CAT=y
 CONFIG_BOOTP_DNS2=y
 CONFIG_CMD_TFTPPUT=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 77ade1f1d8..daae539102 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -84,6 +84,7 @@ CONFIG_CMD_SPI=y
 CONFIG_CMD_TEMPERATURE=y
 CONFIG_CMD_USB=y
 CONFIG_CMD_WDT=y
+CONFIG_CMD_WRITE=y
 CONFIG_CMD_AXI=y
 CONFIG_CMD_CAT=y
 CONFIG_CMD_SETEXPR_FMT=y
-- 
2.37.2



[PATCH v2 2/5] cmd: introduce 'write' command

2023-03-01 Thread Rasmus Villemoes
It's almost no extra code to hook up a buddy to the 'read' command. In
fact, since the command is passed its own 'struct cmd_tbl', we can use
the exact same callback, and let it figure out for itself whether it
was invoked as "read" or "write".

Signed-off-by: Rasmus Villemoes 
---
 cmd/Kconfig  |  5 +
 cmd/Makefile |  1 +
 cmd/read.c   | 29 ++---
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2caa4af71c..008ae55e02 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1562,6 +1562,11 @@ config CMD_WDT
help
  This provides commands to control the watchdog timer devices.
 
+config CMD_WRITE
+   bool "write - Write binary data to a partition"
+   help
+ Provides low-level write access to a partition.
+
 config CMD_AXI
bool "axi"
depends on AXI
diff --git a/cmd/Makefile b/cmd/Makefile
index 36d2daf22a..f2429c18ab 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -140,6 +140,7 @@ obj-$(CONFIG_CMD_PXE) += pxe.o
 obj-$(CONFIG_CMD_WOL) += wol.o
 obj-$(CONFIG_CMD_QFW) += qfw.o
 obj-$(CONFIG_CMD_READ) += read.o
+obj-$(CONFIG_CMD_WRITE) += read.o
 obj-$(CONFIG_CMD_REGINFO) += reginfo.o
 obj-$(CONFIG_CMD_REISER) += reiser.o
 obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o
diff --git a/cmd/read.c b/cmd/read.c
index 8645db49bb..1218e7acfd 100644
--- a/cmd/read.c
+++ b/cmd/read.c
@@ -13,14 +13,14 @@
 #include 
 #include 
 
-int do_read(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+static int
+do_rw(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
struct blk_desc *dev_desc = NULL;
struct disk_partition part_info;
ulong offset, limit;
+   uint blk, cnt, res;
void *addr;
-   uint blk;
-   uint cnt;
int part;
 
if (argc != 6) {
@@ -47,20 +47,35 @@ int do_read(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
}
 
if (cnt + blk > limit) {
-   printf("Read out of range\n");
+   printf("%s out of range\n", cmdtp->name);
return 1;
}
 
-   if (blk_dread(dev_desc, offset + blk, cnt, addr) != cnt) {
-   printf("Error reading blocks\n");
+   if (IS_ENABLED(CONFIG_CMD_WRITE) && !strcmp(cmdtp->name, "write"))
+   res = blk_dwrite(dev_desc, offset + blk, cnt, addr);
+   else
+   res = blk_dread(dev_desc, offset + blk, cnt, addr);
+
+   if (res != cnt) {
+   printf("%s error\n", cmdtp->name);
return 1;
}
 
return 0;
 }
 
+#ifdef CONFIG_CMD_READ
 U_BOOT_CMD(
-   read,   6,  0,  do_read,
+   read,   6,  0,  do_rw,
"Load binary data from a partition",
"  addr blk# cnt"
 );
+#endif
+
+#ifdef CONFIG_CMD_WRITE
+U_BOOT_CMD(
+   write,  6,  0,  do_rw,
+   "Store binary data to a partition",
+   "  addr blk# cnt"
+);
+#endif
-- 
2.37.2



[PATCH v2 1/5] cmd: read: use part_get_info_by_dev_and_name_or_num() instead of open-coded dev_part parsing

2023-03-01 Thread Rasmus Villemoes
Use the helper part_get_info_by_dev_and_name_or_num() for parsing a
dev[:part] string and obtaining the partition info in one go, instead
of open-coding all that.

As a bonus, this will automatically allow using the dev#partname
syntax as well, for accessing raw partitions by name.

Reviewed-by: Simon Glass 
Signed-off-by: Rasmus Villemoes 
---
 cmd/read.c | 32 
 1 file changed, 8 insertions(+), 24 deletions(-)

diff --git a/cmd/read.c b/cmd/read.c
index fecfadaa1f..8645db49bb 100644
--- a/cmd/read.c
+++ b/cmd/read.c
@@ -15,50 +15,34 @@
 
 int do_read(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
-   char *ep;
struct blk_desc *dev_desc = NULL;
-   int dev;
-   int part = 0;
struct disk_partition part_info;
-   ulong offset = 0u;
-   ulong limit = 0u;
+   ulong offset, limit;
void *addr;
uint blk;
uint cnt;
+   int part;
 
if (argc != 6) {
cmd_usage(cmdtp);
return 1;
}
 
-   dev = (int)hextoul(argv[2], );
-   if (*ep) {
-   if (*ep != ':') {
-   printf("Invalid block device %s\n", argv[2]);
-   return 1;
-   }
-   part = (int)hextoul(++ep, NULL);
-   }
-
-   dev_desc = blk_get_dev(argv[1], dev);
-   if (dev_desc == NULL) {
-   printf("Block device %s %d not supported\n", argv[1], dev);
+   part = part_get_info_by_dev_and_name_or_num(argv[1], argv[2],
+   _desc, _info, 1);
+   if (part < 0)
return 1;
-   }
 
addr = map_sysmem(hextoul(argv[3], NULL), 0);
blk = hextoul(argv[4], NULL);
cnt = hextoul(argv[5], NULL);
 
-   if (part != 0) {
-   if (part_get_info(dev_desc, part, _info)) {
-   printf("Cannot find partition %d\n", part);
-   return 1;
-   }
+   if (part > 0) {
offset = part_info.start;
limit = part_info.size;
} else {
/* Largest address not available in struct blk_desc. */
+   offset = 0;
limit = ~0;
}
 
@@ -78,5 +62,5 @@ int do_read(struct cmd_tbl *cmdtp, int flag, int argc, char 
*const argv[])
 U_BOOT_CMD(
read,   6,  0,  do_read,
"Load binary data from a partition",
-   "  addr blk# cnt"
+   "  addr blk# cnt"
 );
-- 
2.37.2



[PATCH v2 0/5] improve 'read' command, add 'write' command

2023-03-01 Thread Rasmus Villemoes
The first patch simplies do_read somewhat by making use of an existing
helper instead of parsing the dev_part string manually. As a bonus
(and my actual motivation), it now understands dev#partname syntax -
hard-coded partition numbers are so last decade.

I also need the symmetrical operation, being able to write to a named
raw partition, and fortunately it doesn't require that many lines of
code to implement that.

There's a very minor change in the error reporting due to using
cmdtp->name to generate the new messages, but I don't think "Error
reading blocks" offers much that "read error" doesn't.

New in v2: the last three patches add documentation, ensure CMD_WRITE
is set for sandbox and adds some basic test cases for the various ways
of accessing the partitions (by number, name, or as raw offset within
the whole disk).

Rasmus Villemoes (5):
  cmd: read: use part_get_info_by_dev_and_name_or_num() instead of
open-coded dev_part parsing
  cmd: introduce 'write' command
  doc: document read/write commands
  sandbox: enable CMD_WRITE
  test: add tests of 'read' and 'write' shell commands

 cmd/Kconfig |   5 ++
 cmd/Makefile|   1 +
 cmd/read.c  |  61 +++--
 configs/sandbox64_defconfig |   1 +
 configs/sandbox_defconfig   |   1 +
 doc/usage/cmd/read.rst  |  40 ++
 doc/usage/index.rst |   1 +
 test/cmd/Makefile   |   1 +
 test/cmd/rw.c   | 104 
 9 files changed, 184 insertions(+), 31 deletions(-)
 create mode 100644 doc/usage/cmd/read.rst
 create mode 100644 test/cmd/rw.c

-- 
2.37.2



Re: u-boot crashes if mass-storage devices are connected via USB-C

2023-03-01 Thread Simon Glass
+Marek Vasut +Bin Meng +Mark Kettenis +Tom Rini

On Wed, 1 Mar 2023 at 08:12, bluetail  wrote:
>
> Hello. user kettenis aka "Mark Kettenis" guided me write my bug report
> to this email. "bluetail: please report these usb bugs upstream; they're
> almost certainly not hardware-specific"
>
> But before, jannau aka Janne Grunau asked me to give the version output
> of  `pacman -Qi uboot-asahi` to which I replied 2022.10.asahi1-1.
> Because I had the feeling that sometimes the reboot with a USB-C
> connected device succeeds, depending how many bays are populated. But I
> have no evidence for that.
> I did try other USB Type C Cables, but without success of fixing the
> underlying issue. The device works fine via USB Type A or C fine if
> plugged in AFTER u-boot.
> But, u-boot does not support USB Type A yet, which is why it wont break
> my boot sequence with USB Type A.
>
> Essentially, I connect a mass-storage device to the USB-C port of a Mac
> Mini 2020 (M1), and it leads to the issue in the attachment.
> I was able to reproduce it with Icy Box IB-3810 and ICY BOX IB-3805.
> Initially I thought this issue was only for some devices (also attached
> here) https://github.com/AsahiLinux/u-boot/issues/4 but it appears this
> might be a issue that is with many devices.
>
> If you need any more information, please feel free to ask. I am very
> eager to have this issue fixed because it seems to be a very broad issue
> with mass media storage in general.
> uname-r returns 6.1.0-asahi-2-2-edge-ARCH
>
> Best regards,
> bluetail
> --
> aka zDEFz


Re: [PATCH] sandbox: Correctly define BITS_PER_LONG

2023-03-01 Thread Simon Glass
On Sun, Oct 23, 2022 at 09:56:29AM +0200, Heinrich Schuchardt wrote:
> On 10/23/22 09:50, Michal Suchánek wrote:
> > On Sat, Oct 22, 2022 at 11:52:29PM +0200, Heinrich Schuchardt wrote:
> > >
> > >
> > > Am 22. Oktober 2022 23:22:01 MESZ schrieb Michal Suchanek 
> > > :
> > > > SANDBOX_BITS_PER_LONG is the number of bits in long on the sandbox
> > > > platform.
> > >
> > > Please, explain in the commit message what this patch is good for.
> >
> > For setting BITS_PER_LONG correctly.
> >
> > > Aren't further patches needed to make use of it?
> >
> > 'make ue of it' would likely by running 32bit sandbox with 64bit
> > phys_addr_t, and that indeed won't be fixed by this patch alone.
> >
> > Nonetheless, since nobody noticed that this is broken so far I figured I
> > will send the patch anyway.
> >
> > Thanks
> >
> > Michal
> >
> > > Best regards
> > >
> > > Heinrich
> > >
> > > >
> > > > Signed-off-by: Michal Suchanek 
> > > > ---
> > > >
> > > > arch/sandbox/include/asm/types.h | 6 +-
> > > > 1 file changed, 1 insertion(+), 5 deletions(-)
> > > >
Applied to u-boot-dm, thanks!


Re: [PATCH 17/17] RFC: tools: Add a camel-case conversion script

2023-03-01 Thread Simon Glass
This is only for posterity, since once the conversion is done, the script
is of no use.

Signed-off-by: Simon Glass 
---

 scripts/style.py | 180 +++
 1 file changed, 180 insertions(+)
 create mode 100755 scripts/style.py

Applied to u-boot-dm, thanks!


Re: [PATCH] arm64: a37xx: pinctrl: probe after binding

2023-03-01 Thread Simon Glass
On Mon, Feb 13, 2023 at 12:36 AM Simon Glass  wrote:
>
> Hi,
>
> On Thu, 19 Jan 2023 at 00:00, Stefan Roese  wrote:
> >
> > On 1/17/23 15:08, Robert Marko wrote:
> > > Currently, pinctrl drivers are getting probed during post-bind, however
> > > that is being reverted, and on A37XX pinctrl driver is the one that
> > > registers the GPIO driver during the probe.
> > >
> > > So, if the pinctrl driver doesn't get probed GPIO-s won't get registered
> > > and thus they cannot be used.
> > >
> > > This is a problem on the Methode eDPU as it just uses SB pins as GPIO-s
> > > and without them being registered networking won't work as it only has
> > > one SFP slot and the TX disable GPIO is on the SB controller.
> > >
> > > So, lets just add a flag only to A37XX driver to probe after binding
> > > in order for the GPIO driver to always get registered.
> > >
> > > Signed-off-by: Robert Marko 
> >
> > Reviewed--by: Stefan Roese 
> >
> > Thanks,
> > Stefan
> >
> > > ---
> > >   drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 14 ++
> > >   1 file changed, 14 insertions(+)
> > >
Applied to u-boot-dm, thanks!


Re: [PATCH] MAINTAINERS: assign sandbox drivers to SANDBOX

2023-03-01 Thread Simon Glass
On Sat, 18 Feb 2023 at 02:38, Heinrich Schuchardt
 wrote:
>
> Drivers should have a maintainer.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
>  MAINTAINERS | 1 +
>  1 file changed, 1 insertion(+)

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


  1   2   3   >