[PATCH v5] bosch: Add initial board support for ACC

2022-04-28 Thread Philip Oberfichtner
The Bosch ACC (Air Center Control) Board is based on the i.MX6D.

Signed-off-by: Philip Oberfichtner 

---

Changes in v5:
- Rebase on v2022.07-rc1
- Sync device tree with Linux

Changes in v4:
- Remove obsolete CONFIG_FEC #defines
- Sync device tree with Linux

Changes in v3:
- Rename acc to bosch-acc
- Sync device tree with Linux

Changes in v2:
- Adapt defconfig and device tree to new bootcount driver
- Clean up CONFIG_ENV_FLAGS_LIST_STATIC
- Fix style issues in device trees
- Migrate CONFIG options to Kconfig


This board supports depends on:
- "crypto/fsl: Fallback to SW sha1/256 is misaligned buffers",
  patchwork id 270524
- Linux Device Tree patch, see below

The Device Tree is currently being mainlined into Linux. The
DT in this board support patch will be kept in sync as the DT
patch for Linux evolves. The Linux patch is tracked under
https://lore.kernel.org/linux-devicetree/20220427135229.2339865-4-...@denx.de/

The only difference compared to the Linux DT is the removal of
usbphynop properties. They are defined in the Linux version of
imx6qdl.dtsi, but not in the u-boot version.

---
 arch/arm/dts/Makefile|   1 +
 arch/arm/dts/imx6q-bosch-acc-u-boot.dtsi |  80 +++
 arch/arm/dts/imx6q-bosch-acc.dts | 773 +++
 arch/arm/mach-imx/mx6/Kconfig|  15 +
 board/bosch/acc/Kconfig  |  19 +
 board/bosch/acc/MAINTAINERS  |   9 +
 board/bosch/acc/Makefile |   6 +
 board/bosch/acc/acc.c| 755 ++
 configs/imx6q_bosch_acc_defconfig| 110 
 include/configs/imx6q-bosch-acc.h| 122 
 10 files changed, 1890 insertions(+)
 create mode 100644 arch/arm/dts/imx6q-bosch-acc-u-boot.dtsi
 create mode 100644 arch/arm/dts/imx6q-bosch-acc.dts
 create mode 100644 board/bosch/acc/Kconfig
 create mode 100644 board/bosch/acc/MAINTAINERS
 create mode 100644 board/bosch/acc/Makefile
 create mode 100644 board/bosch/acc/acc.c
 create mode 100644 configs/imx6q_bosch_acc_defconfig
 create mode 100644 include/configs/imx6q-bosch-acc.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 1032ce4c85..a24ac93258 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -777,6 +777,7 @@ endif
 ifneq ($(CONFIG_MX6Q)$(CONFIG_MX6QDL),)
 dtb-y += \
imx6-apalis.dtb \
+   imx6q-bosch-acc.dtb \
imx6q-cm-fx6.dtb \
imx6q-cubox-i.dtb \
imx6q-cubox-i-emmc-som-v15.dtb \
diff --git a/arch/arm/dts/imx6q-bosch-acc-u-boot.dtsi 
b/arch/arm/dts/imx6q-bosch-acc-u-boot.dtsi
new file mode 100644
index 00..37c182d318
--- /dev/null
+++ b/arch/arm/dts/imx6q-bosch-acc-u-boot.dtsi
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/* Copyright (C) 2022 Denx Software Engineering GmbH
+ * Philip Oberfichtner 
+ */
+
+/ {
+   chosen {
+   stdout-path = 
+   };
+
+   soc {
+   u-boot,dm-spl;
+
+   bus@200 {
+   u-boot,dm-spl;
+
+   spba-bus@200 {
+   u-boot,dm-spl;
+   };
+   };
+
+   bus@210 {
+   u-boot,dm-spl;
+   };
+   };
+
+   bootcount {
+   compatible = "u-boot,bootcount-pmic";
+   pmic = <>;
+   };
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
diff --git a/arch/arm/dts/imx6q-bosch-acc.dts b/arch/arm/dts/imx6q-bosch-acc.dts
new file mode 100644
index 00..103a64f331
--- /dev/null
+++ b/arch/arm/dts/imx6q-bosch-acc.dts
@@ -0,0 +1,773 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Support for the i.MX6-based Bosch ACC board.
+ *
+ * Copyright (C) 2016 Garz & Fricke GmbH
+ * Copyright (C) 2018 DENX Software Engineering GmbH, Heiko Schocher 

+ * Copyright (C) 2018 DENX Software Engineering GmbH, Niel Fourie 

+ * Copyright (C) 2019-2021 Bosch Thermotechnik GmbH, Matthias Winker 

+ * Copyright (C) 2022 DENX Software Engineering GmbH, Philip Oberfichtner 

+ */
+
+/dts-v1/;
+
+#include 
+#include 
+#include "imx6q.dtsi"
+
+/ {
+   model = "Bosch ACC";
+   compatible = "bosch,imx6q-acc", "fsl,imx6q";
+
+   aliases {
+   serial0 = 
+   serial1 = 
+   i2c0 = 
+   i2c1 = 
+   i2c2 = 
+   mmc0 = 
+   mmc1 = 
+   };
+
+   memory@1000 {
+   device_type = "memory";
+   reg = <0x1000 0x4000>;
+   };
+
+   backlight_lvds: backlight_lvds {
+   compatible = "pwm-backlight";
+   pwms = 

[PATCH v2 2/2] mkimage: Support signing 'auto' FITs

2022-04-28 Thread Sean Anderson
This adds support for signing images in auto-generated FITs. To do this,
we need to add a signature node. The algorithm name property already has
its own option, but we need one for the key name hint. We could have
gone the -G route and added an explicit name for the public key (like
what is done for the private key). However, many places assume the
public key can be constructed from the key dir and hint, and I don't
want to do the refactoring necessary.

As a consequence of this, it is now easier to add public keys to an
existing image without signing something. This could be done all along,
but now you don't have to create an its just to do it. Ideally, we
wouldn't create a FIT at the end. This could be done by calling
fit_image_setup_sig/info.crypto->add_verify_data directly.

Signed-off-by: Sean Anderson 
---

(no changes since v1)

 doc/mkimage.1 | 24 
 tools/fit_image.c | 41 ++---
 tools/imagetool.h |  1 +
 tools/mkimage.c   |  5 -
 4 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/doc/mkimage.1 b/doc/mkimage.1
index 10ac31a8fc..7f422d0197 100644
--- a/doc/mkimage.1
+++ b/doc/mkimage.1
@@ -213,6 +213,13 @@ the corresponding public key is written into this file for 
for run-time
 verification. Typically the file here is the device tree binary used by
 CONFIG_OF_CONTROL in U-Boot.
 
+.TP
+.BI "\-g [" "key_name_hint" "]"
+Sets the key-name-hint property when used with \-f auto. This is the 
+part of the key. The directory part is set by \-k. This option also indicates
+that the images included in the FIT should be signed. If this option is
+specified, \-o must be specified as well.
+
 .TP
 .BI "\-o [" "signing algorithm" "]"
 Specifies the algorithm to be used for signing a FIT image. The default is
@@ -273,6 +280,15 @@ skipping those for which keys cannot be found. Also add a 
comment.
 .B -c """Kernel 3.8 image for production devices""" kernel.itb
 .fi
 
+.P
+Add public keys to u-boot.dtb without needing a FIT to sign. This will also
+create a FIT containing an images node with no data named unused.itb.
+.nf
+.B mkimage -f auto -d /dev/null -k /public/signing-keys -g dev 
+.br
+.B -o sha256,rsa2048 -K u-boot.dtb unused.itb
+.fi
+
 .P
 Update an existing FIT image, signing it with additional keys.
 Add corresponding public keys into u-boot.dtb. This will resign all images
@@ -301,6 +317,14 @@ automatic mode. No .its file is required.
 .B -c """Kernel 4.4 image for production devices""" -d vmlinuz 
 .B -b /path/to/rk3288-firefly.dtb -b /path/to/rk3288-jerry.dtb kernel.itb
 .fi
+.P
+Create a FIT image containing a signed kernel, using automatic mode. No .its
+file is required.
+.nf
+.B mkimage -f auto -A arm -O linux -T kernel -C none -a 43e0 -e 0 
+.br
+.B -d vmlinuz -k /secret/signing-keys -g dev -o sha256,rsa2048 kernel.itb
+.fi
 
 .SH HOMEPAGE
 http://www.denx.de/wiki/U-Boot/WebHome
diff --git a/tools/fit_image.c b/tools/fit_image.c
index 0d5a6a28f9..48fc1f5579 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -199,15 +199,36 @@ static void get_basename(char *str, int size, const char 
*fname)
 }
 
 /**
- * add_crc_node() - Add a hash node to request a CRC checksum for an image
+ * add_hash_node() - Add a hash or signature node
  *
+ * @params: Image parameters
  * @fdt: Device tree to add to (in sequential-write mode)
+ *
+ * If there is a key name hint, try to sign the images. Otherwise, just add a
+ * CRC.
+ *
+ * Return: 0 on success, or -1 on failure
  */
-static void add_crc_node(void *fdt)
+static int add_hash_node(struct image_tool_params *params, void *fdt)
 {
-   fdt_begin_node(fdt, "hash-1");
-   fdt_property_string(fdt, FIT_ALGO_PROP, "crc32");
+   if (params->keyname) {
+   if (!params->algo_name) {
+   fprintf(stderr,
+   "%s: Algorithm name must be specified\n",
+   params->cmdname);
+   return -1;
+   }
+
+   fdt_begin_node(fdt, "signature-1");
+   fdt_property_string(fdt, FIT_ALGO_PROP, params->algo_name);
+   fdt_property_string(fdt, FIT_KEY_HINT, params->keyname);
+   } else {
+   fdt_begin_node(fdt, "hash-1");
+   fdt_property_string(fdt, FIT_ALGO_PROP, "crc32");
+   }
+
fdt_end_node(fdt);
+   return 0;
 }
 
 /**
@@ -248,7 +269,9 @@ static int fit_write_images(struct image_tool_params 
*params, char *fdt)
ret = fdt_property_file(params, fdt, FIT_DATA_PROP, params->datafile);
if (ret)
return ret;
-   add_crc_node(fdt);
+   ret = add_hash_node(params, fdt);
+   if (ret)
+   return ret;
fdt_end_node(fdt);
 
/* Now the device tree files if available */
@@ -271,7 +294,9 @@ static int fit_write_images(struct image_tool_params 
*params, char *fdt)

[PATCH v2 1/2] mkimage: Document misc options

2022-04-28 Thread Sean Anderson
Over the years, several options have not made it into the help message.
Document them. Do the same for the man page.

Signed-off-by: Sean Anderson 
---

Changes in v2:
- Document secondary image types
- Move -G directly after -k
- Reword documentation for -s

 doc/mkimage.1   | 60 -
 tools/mkimage.c | 15 +
 2 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/doc/mkimage.1 b/doc/mkimage.1
index 287006279f..10ac31a8fc 100644
--- a/doc/mkimage.1
+++ b/doc/mkimage.1
@@ -53,6 +53,10 @@ Parse image file as type.
 Pass \-h as the image to see the list of supported image type.
 Without this option image type is autodetected.
 
+.TP
+.BI "\-q"
+Quiet. Don't print the image header on successful verification.
+
 .P
 .B Create old legacy image:
 
@@ -91,6 +95,35 @@ List the contents of an image.
 .BI "\-n [" "image name" "]"
 Set image name to 'image name'.
 
+.TP
+.BI "\-R [" "secondary image name" "]"
+Some image types support a second image for additional data. For these types,
+use \-R to specify this second image.
+.TS
+allbox;
+lb lbx
+l l.
+Image Type Secondary Image Description
+pblimage   Additional RCW-style header, typically used for PBI commands.
+zynqimage, zynqmpimage T{
+Initialization parameters, one per line. Each parameter has the form
+.sp
+.ti 4
+.I address data
+.sp
+where
+.I address
+and
+.I data
+are hexadecimal integers. The boot ROM will write each
+.I data
+to
+.I address
+when loading the image. At most 256 parameters may be specified in this
+manner.
+T}
+.TE
+
 .TP
 .BI "\-d [" "image data file" "]"
 Use image data from 'image data file'.
@@ -99,6 +132,15 @@ Use image data from 'image data file'.
 .BI "\-x"
 Set XIP (execute in place) flag.
 
+.TP
+.BI "\-s"
+Don't copy in the image data. Depending on the image type, this may create
+just the header, everything but the image data, or nothing at all.
+
+.TP
+.BI "\-v"
+Verbose. Print file names as they are added to the image.
+
 .P
 .B Create FIT image:
 
@@ -126,6 +168,11 @@ in each image will be replaced with 'data-offset' and 
'data-size' properties.
 A 'data-offset' of 0 indicates that it starts in the first (4-byte aligned)
 byte after the FIT.
 
+.TP
+.BI "\-B [" "alignment" "]"
+The alignment, in hexadecimal, that external data will be aligned to. This
+option only has an effect when \-E is specified.
+
 .TP
 .BI "\-f [" "image tree source file" " | " "auto" "]"
 Image tree source file that describes the structure and contents of the
@@ -153,6 +200,11 @@ Specifies the directory containing keys to use for 
signing. This directory
 should contain a private key file .key for use with signing and a
 certificate .crt (containing the public key) for use with verification.
 
+.TP
+.BI "\-G [" "key_file" "]"
+Specifies the private key file to use when signing. This option may be used
+instead of \-k.
+
 .TP
 .BI "\-K [" "key_destination" "]"
 Specifies a compiled device tree binary file (typically .dtb) to write
@@ -173,11 +225,17 @@ a 'data-offset' property defining the offset from the end 
of the FIT, \-p will
 use 'data-position' as the absolute position from the base of the FIT.
 
 .TP
-.BI "\-r
+.BI "\-r"
 Specifies that keys used to sign the FIT are required. This means that they
 must be verified for the image to boot. Without this option, the verification
 will be optional (useful for testing but not for release).
 
+.TP
+.BI "\-N [" "engine" "]"
+The openssl engine to use when signing and verifying the image. For a complete 
list of
+available engines, refer to
+.BR engine (1).
+
 .TP
 .BI "\-t
 Update the timestamp in the FIT.
diff --git a/tools/mkimage.c b/tools/mkimage.c
index be58e56546..5c6a60e851 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -84,7 +84,8 @@ static void usage(const char *msg)
fprintf(stderr, "Error: %s\n", msg);
fprintf(stderr, "Usage: %s [-T type] -l image\n"
 "  -l ==> list image header information\n"
-"  -T ==> parse image file as 'type'\n",
+"  -T ==> parse image file as 'type'\n"
+"  -q ==> quiet\n",
params.cmdname);
fprintf(stderr,
"   %s [-x] -A arch -O os -T type -C comp -a addr -e ep -n 
name -d data_file[:data_file...] image\n"
@@ -95,8 +96,11 @@ static void usage(const char *msg)
"  -a ==> set load address to 'addr' (hex)\n"
"  -e ==> set entry point to 'ep' (hex)\n"
"  -n ==> set image name to 'name'\n"
+   "  -R ==> set second image name to 'name'\n"
"  -d ==> use image data from 'datafile'\n"
-   "  -x ==> set XIP (execute in place)\n",
+   "  -x ==> set XIP (execute in place)\n"
+   "  -s ==> create an image with no data\n"
+   "  

Re: U-Boot and ethernet regression on mx6cuboxi

2022-04-28 Thread Tim Harvey
On Thu, Apr 28, 2022 at 1:41 PM Tom Rini  wrote:
>
> Hey,
>
> So my mx6cuboxi was out of my lab for a bit, and that's how this
> regression got in mainline.  With:
> 4223fb0ee18d11462c55ac94198fdc2055f2c27c is the first bad commit
> commit 4223fb0ee18d11462c55ac94198fdc2055f2c27c
> Author: Tim Harvey 
> Date:   Tue Mar 1 12:15:01 2022 -0800
>
> net: fec: prevent undesired de-assertion of phy-reset on request
>
> I now see:
> => dhcp
> ethernet@2188000 Waiting for PHY auto negotiation to complete. 
> TIMEOUT !
> Could not initialize PHY ethernet@2188000
> BOOTP broadcast 1
> BOOTP broadcast 2
> BOOTP broadcast 3
> BOOTP broadcast 4
> BOOTP broadcast 5
> BOOTP broadcast 6
> BOOTP broadcast 7
> BOOTP broadcast 8
> BOOTP broadcast 9
> BOOTP broadcast 10
> BOOTP broadcast 11
> BOOTP broadcast 12
> BOOTP broadcast 13
> BOOTP broadcast 14
> BOOTP broadcast 15
> BOOTP broadcast 16
>
> Any ideas?  Thanks!
>

Tom,

What PHY is used on that board and can you verify the PHY reset is
properly defined in the dt polarity and all?

What I found is that before commit 4223fb0ee18d11 ("net: fec: prevent
undesired de-assertion of phy-reset on request") my board's
(imx8mm-venice-gw73xx) PHY_RST would driver high during the
gpio-request before it was driven low then high again. The PHY used on
my board (at least new revisions) is the MaxLinear GPY111 and we it
was extremely sensitive to multiple reset events and this behavior
would make it unreliable.

Best Regards,

Tim


U-Boot and ethernet regression on mx6cuboxi

2022-04-28 Thread Tom Rini
Hey,

So my mx6cuboxi was out of my lab for a bit, and that's how this
regression got in mainline.  With:
4223fb0ee18d11462c55ac94198fdc2055f2c27c is the first bad commit
commit 4223fb0ee18d11462c55ac94198fdc2055f2c27c
Author: Tim Harvey 
Date:   Tue Mar 1 12:15:01 2022 -0800

net: fec: prevent undesired de-assertion of phy-reset on request

I now see:
=> dhcp
ethernet@2188000 Waiting for PHY auto negotiation to complete. TIMEOUT !
Could not initialize PHY ethernet@2188000
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
BOOTP broadcast 4
BOOTP broadcast 5
BOOTP broadcast 6
BOOTP broadcast 7
BOOTP broadcast 8
BOOTP broadcast 9
BOOTP broadcast 10
BOOTP broadcast 11
BOOTP broadcast 12
BOOTP broadcast 13
BOOTP broadcast 14
BOOTP broadcast 15
BOOTP broadcast 16

Any ideas?  Thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] efi_loader: disk: allow blk devices even without UCLASS_PARTITION

2022-04-28 Thread Mark Kettenis
> From: AKASHI Takahiro 
> Date: Thu, 28 Apr 2022 13:49:16 +0900
> 
> While GPT partition is mandated in UEFI specification, CONFIG_PARTITION is
> seen optional under the current implementation.
> So modify efi_disk_rw_blocks() to allow accepting UCLASS_BLK devices.
> 
> Fixes: commit d97e98c887ed ("efi_loader: disk: use udevice instead of 
> blk_desc")
> Signed-off-by: AKASHI Takahiro 
> ---
>  lib/efi_loader/efi_disk.c | 29 +++--
>  1 file changed, 15 insertions(+), 14 deletions(-)

confirmed that this does indeed fix the regression

Tested-by: Mark Kettenis 
 
> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> index 8fb5b2363c45..f5b462fb164a 100644
> --- a/lib/efi_loader/efi_disk.c
> +++ b/lib/efi_loader/efi_disk.c
> @@ -99,21 +99,22 @@ static efi_status_t efi_disk_rw_blocks(struct 
> efi_block_io *this,
>   if (buffer_size & (blksz - 1))
>   return EFI_BAD_BUFFER_SIZE;
>  
> -#if CONFIG_IS_ENABLED(PARTITIONS)
> - if (direction == EFI_DISK_READ)
> - n = dev_read(diskobj->dev, lba, blocks, buffer);
> - else
> - n = dev_write(diskobj->dev, lba, blocks, buffer);
> -#else
> - /* dev is always a block device (UCLASS_BLK) */
> - struct blk_desc *desc;
> + if (CONFIG_IS_ENABLED(PARTITIONS) &&
> + device_get_uclass_id(diskobj->dev) == UCLASS_PARTITION) {
> + if (direction == EFI_DISK_READ)
> + n = dev_read(diskobj->dev, lba, blocks, buffer);
> + else
> + n = dev_write(diskobj->dev, lba, blocks, buffer);
> + } else {
> + /* dev is a block device (UCLASS_BLK) */
> + struct blk_desc *desc;
>  
> - desc = dev_get_uclass_plat(diskobj->dev);
> - if (direction == EFI_DISK_READ)
> - n = blk_dread(desc, lba, blocks, buffer);
> - else
> - n = blk_dwrite(desc, lba, blocks, buffer);
> -#endif
> + desc = dev_get_uclass_plat(diskobj->dev);
> + if (direction == EFI_DISK_READ)
> + n = blk_dread(desc, lba, blocks, buffer);
> + else
> + n = blk_dwrite(desc, lba, blocks, buffer);
> + }
>  
>   /* We don't do interrupts, so check for timers cooperatively */
>   efi_timer_check();
> -- 
> 2.33.0
> 
> 


[PATCH] Makefile: update warning about CONFIG_OF_EMBED

2022-04-28 Thread Ralph Siemsen
Update the diagnostic message with revised location of document, which
changed in 3e9fddfc4f1 ("doc: Move devicetree control doc to rST")

Signed-off-by: Ralph Siemsen 
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index ccc87c3a5cd..486a9b9ca23 100644
--- a/Makefile
+++ b/Makefile
@@ -1113,7 +1113,7 @@ ifeq ($(CONFIG_OF_EMBED)$(CONFIG_EFI_APP),y)
@echo >&2 "CONFIG_OF_EMBED is enabled. This option should only"
@echo >&2 "be used for debugging purposes. Please use"
@echo >&2 "CONFIG_OF_SEPARATE for boards in mainline."
-   @echo >&2 "See doc/README.fdt-control for more info."
+   @echo >&2 "See doc/develop/devicetree/control.rst for more info."
@echo >&2 ""
 endif
 ifneq ($(CONFIG_SPL_FIT_GENERATOR),)
-- 
2.25.1



Re: [PATCH] dt-bindings: leds: import common led bindings from linux 5.17

2022-04-28 Thread Tom Rini
On Thu, Apr 28, 2022 at 01:26:53PM +0200, Pali Rohár wrote:

> This allows usage of LED_COLOR_ID_RGB macro in DTS files.
> 
> Signed-off-by: Pali Rohár 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] test: dm: pinmux: Get LED2 udevice in the pinmux test

2022-04-28 Thread Tom Rini
On Mon, Apr 25, 2022 at 06:33:51PM +0200, Marek Vasut wrote:

> The UT reinitializes the pin controller state, get LED2 udevice
> to trigger its probe and configure the pin controller pin state
> as it is expected by the test.
> 
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Steven Lawrance 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] test: dm: led: Fix LED enumeration

2022-04-28 Thread Tom Rini
On Mon, Apr 25, 2022 at 06:33:50PM +0200, Marek Vasut wrote:

> The GPIO LED driver no longer considers the top level node an LED,
> because it is not an LED. With this bug fixed, the LED enumeration
> has changed. Update the test accordingly.
> 
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Steven Lawrance 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] led: Drop led_default_state()

2022-04-28 Thread Tom Rini
On Fri, Apr 22, 2022 at 03:41:42PM +0200, Marek Vasut wrote:

> This function is empty, drop it.
> 
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Steven Lawrance 
> Reviewed-by: Patrice Chotard 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] led: gpio: Use NOP uclass driver for top-level node

2022-04-28 Thread Tom Rini
On Fri, Apr 22, 2022 at 03:34:00PM +0200, Marek Vasut wrote:

> The top level DT node of gpio-leds is not a LED itself, bind NOP uclass
> driver to it, and bind different LED uclass driver to its subnodes which
> represent the actual LEDs. This simplifies the probe() implementation
> and fixes the bogus top-level not-an-LED in 'led list' command output:
> 
> ```
> => led list
> led Error -121 <--- This is removed/fixed by this patch
> green:user0 off
> ```
> 
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Steven Lawrance 
> Reviewed-by: Patrice Chotard 
> Tested-by: Patrice Chotard 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 3/3] led: gpio: Check device compatible string to determine the top level node

2022-04-28 Thread Tom Rini
On Fri, Apr 22, 2022 at 03:15:55PM +0200, Marek Vasut wrote:

> Since 2d1deaf88ed ("led: gpio: Drop duplicate OF "label" property parsing"),
> all LED nodes have some sort of label. Use 
> device_is_compatible(..."leds-gpio")
> to determine whether this is a top-level node, since it is only the top
> level node which is compatible with "leds-gpio", the GPIO LEDs subnodes
> are not.
> 
> Fixes: 2d1deaf88ed ("led: gpio: Drop duplicate OF "label" property parsing")
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Steven Lawrance 
> Reviewed-by: Patrice Chotard 
> Tested-by: Patrice Chotard 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/3] led: Mark device instance with DM_FLAG_PROBE_AFTER_BIND

2022-04-28 Thread Tom Rini
On Fri, Apr 22, 2022 at 03:15:54PM +0200, Marek Vasut wrote:

> Calling device_probe() from uclass .post_bind() callback has all kinds
> of odd side-effects, e.g. device instances not being available just yet.
> Make use of the DM_FLAG_PROBE_AFTER_BIND instead, mark device instances
> which need to be probe()d in order to configure the LED default state
> with this flag and let the DM core do the device_probe() at the right
> time instead.
> 
> Fixes: 72675b063b6 ("led: Configure LED default-state on boot")
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Steven Lawrance 
> Reviewed-by: Patrice Chotard 
> Tested-by: Patrice Chotard 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/3] dm: core: Add DM_FLAG_PROBE_AFTER_BIND flag

2022-04-28 Thread Tom Rini
On Fri, Apr 22, 2022 at 03:15:53PM +0200, Marek Vasut wrote:

> Introduce DM_FLAG_PROBE_AFTER_BIND flag, which can be set by driver or
> uclass in .bind(), to indicate such driver instance should be probe()d
> once binding of all devices is complete.
> 
> This is useful in case the driver determines that hardware initialization
> is mandatory on boot, and such initialization happens only in probe().
> This also solves the inability to call device_probe() from .bind().
> 
> Signed-off-by: Marek Vasut 
> Cc: Patrice Chotard 
> Cc: Patrick Delaunay 
> Cc: Sean Anderson 
> Cc: Simon Glass 
> Cc: Steven Lawrance 
> Reviewed-by: Patrice Chotard 
> Tested-by: Patrice Chotard 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] board: freescale: p1_p2_rdb_pc: Allow to compile without __SW_BOOT_SD macro

2022-04-28 Thread Pali Rohár
Add #ifdef guard for __SW_BOOT_SD macro like there are guards for all other
__SW_BOOT_* macros.

Signed-off-by: Pali Rohár 
---
 board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c 
b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c
index e559a77b2dac..a8318ff40b6a 100644
--- a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c
+++ b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c
@@ -209,8 +209,11 @@ int checkboard(void)
val = ((in ^ invert) & io_config) | (out & (~io_config));
 
puts("rom_loc: ");
-   if ((val & (~__SW_BOOT_MASK)) == __SW_BOOT_SD) {
+   if (0) {
+#ifdef __SW_BOOT_SD
+   } else if ((val & (~__SW_BOOT_MASK)) == __SW_BOOT_SD) {
puts("sd");
+#endif
 #ifdef __SW_BOOT_SD2
} else if ((val & (~__SW_BOOT_MASK)) == __SW_BOOT_SD2) {
puts("sd");
-- 
2.20.1



Re: [PATCH] misc: atsha204a: Add support for atsha204 chip

2022-04-28 Thread Pali Rohár
On Friday 22 April 2022 05:59:28 Heiko Schocher wrote:
> Hello Pali,
> 
> On 21.04.22 11:40, Pali Rohár wrote:
> > On Thursday 21 April 2022 06:11:11 Heiko Schocher wrote:
> >> And not forget, please add a documentation for the compatible string
> >> in u-boot:/doc/device-tree-bindings/
> > 
> > Currently I do not see any information about atsha in
> > u-boot/doc/device-tree-bindings.
> 
> So please add one, thanks!

Hello! Here is the patch for bindings:
https://patchwork.ozlabs.org/project/uboot/patch/20220428185828.19513-1-p...@kernel.org/


[PATCH] doc: Add device-tree-bindings for atsha204 and atsha204a

2022-04-28 Thread Pali Rohár
Document trivial bindings for atsha204 and atsha204a.

Signed-off-by: Pali Rohár 
---
 doc/device-tree-bindings/misc/atsha204.txt | 4 
 1 file changed, 4 insertions(+)
 create mode 100644 doc/device-tree-bindings/misc/atsha204.txt

diff --git a/doc/device-tree-bindings/misc/atsha204.txt 
b/doc/device-tree-bindings/misc/atsha204.txt
new file mode 100644
index ..3adc12112f50
--- /dev/null
+++ b/doc/device-tree-bindings/misc/atsha204.txt
@@ -0,0 +1,4 @@
+Atmel ATSHA204 and ATSHA204A i2c h/w symmetric crypto module
+
+Required properties:
+- compatible : should be "atmel,atsha204" or "atmel,atsha204a"
-- 
2.20.1



Re: [PATCH] ls10xxx: Use a sane SPL_SYS_MALLOC_F_LEN default

2022-04-28 Thread Tom Rini
On Thu, Apr 28, 2022 at 12:31:08PM -0400, Sean Anderson wrote:
> Hi Fabio,
> 
> On 4/28/22 12:23 PM, Fabio Estevam wrote:
> > Hi Sean,
> > 
> > On Thu, Apr 28, 2022 at 1:02 PM Sean Anderson  
> > wrote:
> >>
> >> SPL_SYS_MALLOC_F_LEN defaults to SYS_MALLOC_F_LEN. 0x1 (the new
> >> default) is 64 KiB, or around half of the total OCRAM size. Revert to
> >> the previous default of 0x2000. This fixes SPL boot.
> >>
> >> Fixes: 545eceb520 ("imx8/ls10xx: Use a sane SYS_MALLOC_F_LEN default")
> >> Signed-off-by: Sean Anderson 
> > 
> > Thanks for the fix.
> > 
> > Would it be better to fix it like this instead?
> > 
> > --- a/Kconfig
> > +++ b/Kconfig
> > @@ -257,9 +257,7 @@ config SYS_MALLOC_F_LEN
> > default 0x4000 if SANDBOX || RISCV || ARCH_APPLE || ROCKCHIP_RK3368 
> > || \
> >   ROCKCHIP_RK3399
> > default 0x8000 if RCAR_GEN3
> > -   default 0x1 if ARCH_IMX8 || (ARCH_IMX8M && !IMX8MQ) || \
> > -  ARCH_LS1012A || ARCH_LS1021A || ARCH_LS1043A || \
> > -  ARCH_LS1046A
> > +   default 0x1 if ARCH_IMX8 || (ARCH_IMX8M && !IMX8MQ)
> > default 0x2000
> > help
> >   Before relocation, memory is very limited on many platforms. 
> > Still,
> > 
> 
> That would also work. The primary problem is that between v2 and v3 the 
> default
> got raised from 0x2000 to 0x1. Do you remember why you added layerscape
> stuff in the first place? The only non-default value for this property for 
> this
> family was to set it to 0x6000 for some ls2 (ls3?) SoCs (e.g. ls1088).

So yes, I asked since I _think_ before layerscape was using a
smaller-than-0x2000 value and we have had a number of problems with
that.  Sorry for the noise!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 00/17] enable menu-driven boot device selection

2022-04-28 Thread Heinrich Schuchardt

On 4/28/22 18:31, Heinrich Schuchardt wrote:

On 4/28/22 10:09, Masahisa Kojima wrote:

This patch series adds the menu-driven boot device selection,
by extending the existing "bootmenu" to include UEFI and distro_boot
related entries, and supports menu-driven UEFI boot variable
maintenance.

This patch series also includes the removable media support
that UEFI specification requires to support.

The menu example is as follows.

   *** U-Boot Boot Menu ***

  bootmenu_00   : Boot 1. kernel
  bootmenu_01   : Boot 2. kernel
  bootmenu_02   : Reset board
  UEFI BOOT : debian
  UEFI BOOT0001 : ubuntu
  UEFI BOOT0002 : mmc0:1
  UEFI BOOT0003 : mmc0:2
  UEFI BOOT0004 : nvme0:1
  UEFI BOOT0005 : nvme0:2
  UEFI BOOT0006 : usb0:2
  UEFI BOOT0007 : usb1:1
  UEFI BOOT0008 : usb1:2
  distro_boot   : usb0
  distro_boot   : scsi0
  distro_boot   : virtio0
  distro_boot   : dhcp

   Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit

[How to run on QEMU(arm64)]
1) clone source code
  $ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git \
-b kojima/bootmenu_v5_upstream_0428 --depth 1

2) prepare U-Boot .config
  $ make qemu_arm64_menuconfig
   then, enable CONFIG_CMD_BOOTMENU and CONFIG_AUTOBOOT_MENU_SHOW

3) run on QEMU(arm64) example
  $ qemu-system-aarch64 -machine virt,gic-version=3 -cpu cortex-a57 -m
4G -nographic \
    -no-acpi -bios ./u-boot.bin -hda xxx.img

[Major Changes]
- rebased to v2022.07-rc1
- there is detailed changelog in each commit

AKASHI Takahiro (2):
   efi_loader: export efi_locate_device_handle()
   efi_loader: bootmgr: add booting from removable media

Masahisa Kojima (15):
   lib/charset: add u16_strlcat() function
   test: unit test for u16_strlcat()
   menu: always show the menu regardless of the number of entry
   menu: menu_get_choice() return -ENOENT if menu item is empty
   bootmenu: flush input buffer before waiting user key input
   bootmenu: update bootmenu_entry structure
   bootmenu: add UEFI boot entry into bootmenu
   bootmenu: add distro boot entry
   bootmenu: add Kconfig option not to enter U-Boot console
   bootmenu: factor out the user input handling
   efi_loader: menu-driven addition of UEFI boot option
   efi_loader: menu-driven deletion of UEFI boot variable
   efi_loader: menu-driven update of UEFI bootorder variable
   bootmenu: add removable media entries
   doc:bootmenu: add UEFI boot and distro boot support description

  cmd/Kconfig   |   10 +
  cmd/bootmenu.c    |  807 +
  common/menu.c |  142 ++-
  doc/usage/cmd/bootmenu.rst    |   78 +-
  include/charset.h |   17 +
  include/config_distro_bootcmd.h   |   14 +-
  include/efi_default_filename.h    |   33 +
  include/efi_loader.h  |   61 +
  include/menu.h    |   20 +
  lib/charset.c |   22 +
  lib/efi_loader/Makefile   |    1 +
  lib/efi_loader/efi_bootmenu_maintenance.c | 1245 +
  lib/efi_loader/efi_bootmgr.c  |   50 +-
  lib/efi_loader/efi_boottime.c |   59 +-
  lib/efi_loader/efi_console.c  |   81 ++
  lib/efi_loader/efi_disk.c |   11 +
  lib/efi_loader/efi_file.c |   75 +-
  test/unicode_ut.c |   50 +
  18 files changed, 2518 insertions(+), 258 deletions(-)
  create mode 100644 include/efi_default_filename.h
  create mode 100644 lib/efi_loader/efi_bootmenu_maintenance.c



I prepared my test as follows:

make sandbox_defconfig
CONFIG_CMD_BOOTMENU=y
CONFIG_AUTOBOOT_MENU_SHOW=y
PREBOOT=host bind 0 ../sandbox.img

I created ../sandbox.img as GTP partioned image with a single EF00
partition. Onto the partition I copied lib/efi_loader/helloworld.efi
into path EFI/BOOT/BOOTX64.EFI.

I set up the following boot option:

=> efidebug boot dump
Boot0001:
attributes: A-- (0x0001)
   label: hello host 0:1
   file_path:
/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)/EFI\BOOT\BOOTX64.EFI

   data:
     : 6d 00 79 00 20 00 6d 00 65 00 73 00 73 00 61 00  m.y.
.m.e.s.s.a.
     0010: 67 00 65 00 00 00    g.e...
=> efidebug boot order
  1: Boot0001: hello host 0:1
=> reset

Now the boot menu looks like this:

   *** U-Boot Boot Menu ***

  UEFI BOOT0001 : hello host 0:1
  UEFI BOOT : host0:1
  UEFI Boot Manager Maintenance
  U-Boot console

When I select nothing:

try_load_entry: trying to load "hello host 0:1" from
/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)/EFI\BOOT\BOOTX64.EFI

Booting: hello host 0:1
Hello, world!
Running on UEFI 2.9
Have ACPI 2.0 table
Have SMBIOS table
Load options: my message
Boot device:

Re: [PATCH v5 16/17] bootmenu: add removable media entries

2022-04-28 Thread Heinrich Schuchardt

On 4/28/22 10:09, Masahisa Kojima wrote:

UEFI specification requires booting from removal media using
a architecture-specific default image name such as BOOTAA64.EFI.
This commit adds the removable media entries into bootmenu,
so that user can select the removable media and boot with
default image.

The bootmenu automatically enumerates the possible bootable
media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
add it as new UEFI boot option(BOOT) and update BootOrder
variable. This automatically generated UEFI boot option
has the dedicated guid in the optional_data to distinguish it from
the UEFI boot option user adds manually.

This commit also provides the BOOT variable maintenance feature.
Depending on the system hardware setup, some devices
may not exist at a later system boot, so bootmenu checks the
available device in each bootmenu invocation and automatically
removes the BOOT variable corrensponding to the non-existent
media device.

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- Return EFI_SUCCESS if there is no BootOrder defined
- correctly handle the case if no removable device found
- use guid to identify the automatically generated entry by bootmenu

Newly created in v4

  cmd/bootmenu.c|  94 +++
  include/efi_loader.h  |  20 
  lib/efi_loader/efi_bootmenu_maintenance.c | 139 ++
  3 files changed, 253 insertions(+)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 860cb83182..970db3ee01 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -396,6 +396,89 @@ static int is_blk_device_available(char *token)
return -ENODEV;
  }

+/**
+ * prepare_media_device_entry() - generate the media device entries
+ *
+ * This function enumerates all devices supporting 
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
+ * and generate the bootmenu entries.
+ * This function also provide the BOOT variable maintenance for
+ * the media device entries.
+ *   - Automatically create the BOOT variable for the newly detected 
device,
+ * this BOOT variable is distinguished by the special GUID
+ * stored in the EFI_LOAD_OPTION.optional_data
+ *   - If the device is not attached to the system, the associated BOOT 
variable
+ * is automatically deleted.
+ *
+ * Return: status code
+ */
+static efi_status_t prepare_media_device_entry(void)
+{
+   u32 i;
+   efi_status_t ret;
+   efi_uintn_t count;
+   efi_handle_t *volume_handles = NULL;
+   struct efi_bootmenu_media_boot_option *opt = NULL;
+
+   ret = efi_locate_handle_buffer_int(BY_PROTOCOL, 
_simple_file_system_protocol_guid,
+  NULL, , (efi_handle_t 
**)_handles);
+   if (ret != EFI_SUCCESS)
+   return ret;
+
+   opt = calloc(count, sizeof(struct efi_bootmenu_media_boot_option));
+   if (!opt)
+   goto out;
+
+   /* enumerate all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL */
+   ret = efi_bootmenu_enumerate_boot_option(opt, volume_handles, count);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   /*
+* System hardware configuration may vary depending on the user setup.
+* The boot option is automatically added by the bootmenu.
+* If the device is not attached to the system, the boot option needs
+* to be deleted.
+*/
+   ret = efi_bootmenu_delete_invalid_boot_option(opt, count);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   /* add non-existent boot option */
+   for (i = 0; i < count; i++) {
+   u32 boot_index;
+   u16 var_name[9];
+
+   if (!opt[i].exist) {
+   ret = efi_bootmenu_get_unused_bootoption(var_name, 
sizeof(var_name),
+_index);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   ret = efi_set_variable_int(var_name, 
_global_variable_guid,
+  EFI_VARIABLE_NON_VOLATILE |
+  
EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS,
+  opt[i].size, opt[i].lo, 
false);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   ret = efi_bootmenu_append_bootorder(boot_index);
+   if (ret != EFI_SUCCESS)
+   goto out;
+   }
+   }
+
+out:
+   if (opt) {
+   for (i = 0; i < count; i++)
+   free(opt[i].lo);
+   }
+   free(opt);
+   efi_free_pool(volume_handles);
+
+   return ret;
+}
+
  /**
   * prepare_distro_boot_entry() - generate the distro boot entries
   *
@@ -500,6 +583,7 @@ 

[PATCH v2] ls10xxx: Use a sane SPL_SYS_MALLOC_F_LEN default

2022-04-28 Thread Sean Anderson
SPL_SYS_MALLOC_F_LEN defaults to SYS_MALLOC_F_LEN. 0x1 is 64 KiB, or
around half of the total OCRAM size. Revert to the default of 0x2000. This
fixes SPL boot.

Fixes: 545eceb520 ("imx8/ls10xx: Use a sane SYS_MALLOC_F_LEN default")
Signed-off-by: Sean Anderson 
Reviewed-by: Fabio Estevam 
---

Changes in v2:
- Reduce SYS_MALLOC_F_LEN as well

 Kconfig | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/Kconfig b/Kconfig
index bdae59e06f..9aeb9d52ad 100644
--- a/Kconfig
+++ b/Kconfig
@@ -257,9 +257,7 @@ config SYS_MALLOC_F_LEN
default 0x4000 if SANDBOX || RISCV || ARCH_APPLE || ROCKCHIP_RK3368 || \
  ROCKCHIP_RK3399
default 0x8000 if RCAR_GEN3
-   default 0x1 if ARCH_IMX8 || (ARCH_IMX8M && !IMX8MQ) || \
-  ARCH_LS1012A || ARCH_LS1021A || ARCH_LS1043A || \
-  ARCH_LS1046A
+   default 0x1 if ARCH_IMX8 || (ARCH_IMX8M && !IMX8MQ)
default 0x2000
help
  Before relocation, memory is very limited on many platforms. Still,
-- 
2.35.1.1320.gc452695387.dirty



Re: [PATCH] ls10xxx: Use a sane SPL_SYS_MALLOC_F_LEN default

2022-04-28 Thread Fabio Estevam

Hi Sean,

On 28/04/2022 13:31, Sean Anderson wrote:

That would also work. The primary problem is that between v2 and v3 the 
default
got raised from 0x2000 to 0x1. Do you remember why you added 
layerscape
stuff in the first place? The only non-default value for this property 
for this

family was to set it to 0x6000 for some ls2 (ls3?) SoCs (e.g. ls1088).


My original patch only touched imx8m, but Tom suggested I also bump 
Layerscape too.


Please send a v2 with my suggestion and feel free to add a:

Reviewed-by: Fabio Estevam 989-80 Email: 
feste...@denx.de


Re: [PATCH v5 13/17] efi_loader: menu-driven addition of UEFI boot option

2022-04-28 Thread Heinrich Schuchardt

On 4/28/22 10:09, Masahisa Kojima wrote:

This commit supports the menu-driven UEFI boot option addition.
User can select the block device volume having
efi_simple_file_system_protocol and select the file corresponding
to the Boot variable. Then user enter the label of the BOOT
variable in utf8.

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- remove forward declarations
- add const qualifier for menu items
- fix the possible unaligned access for directory info access
- split into three commit 1)add boot option 2) delete boot option 3)change boot 
order
   This commit is 1)add boot option.
- fix file name buffer allocation size, it should be EFI_BOOTMENU_FILE_PATH_MAX 
* sizeof(u16)
- fix wrong size checking for file selection

Chanes in v4:
- UEFI boot option maintenance menu is integrated into bootmenu
- display the simplified volume name(e.g. usb0:1, nvme1:2) for the
   volume selection
- instead of extending lib/efi_loader/efi_bootmgr.c, newly create
   lib/efi_loader/efi_bootmenu_maintenance.c and implement boot
   variable maintenance into it.

Changes in RFC v3:
  not included in v3 series

Changes in RFC v2:
- enable utf8 user input for boot option name
- create lib/efi_loader/efi_console.c::efi_console_get_u16_string() for
   utf8 user input handling
- use u16_strlcat instead of u16_strcat
- remove the EFI_CALLs, and newly create or expose the following
   xxx_int() functions.
 efi_locate_handle_buffer_int(), efi_open_volume_int(),
 efi_file_open_int(), efi_file_close_int(), efi_file_read_int() and
 efi_file_setpos_int().
   Note that EFI_CALLs still exist for EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
   and EFI_SIMPLE_TEXT_INPUT/OUTPUT_PROTOCOL
- use efi_search_protocol() instead of calling locate_protocol() to get
   the device_path_to_text_protocol interface.
- remove unnecessary puts(ANSI_CLEAR_LINE), this patch is still depends on
   puts(ANSI_CLEAR_CONSOLE)
- skip SetVariable() if the bootorder is not changed

  cmd/bootmenu.c|  69 +-
  include/efi_loader.h  |  37 +
  lib/efi_loader/Makefile   |   1 +
  lib/efi_loader/efi_bootmenu_maintenance.c | 862 ++
  lib/efi_loader/efi_boottime.c |  52 +-
  lib/efi_loader/efi_console.c  |  81 ++
  lib/efi_loader/efi_disk.c |  11 +
  lib/efi_loader/efi_file.c |  75 +-
  8 files changed, 1133 insertions(+), 55 deletions(-)
  create mode 100644 lib/efi_loader/efi_bootmenu_maintenance.c

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index eb23afdd41..860cb83182 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -21,6 +21,8 @@

  /* maximum bootmenu entries */
  #define MAX_COUNT 99
+#define STATIC_ENTRY 2
+#define MAX_DYNAMIC_ENTRY (MAX_COUNT - STATIC_ENTRY)

  /* maximal size of bootmenu env
   *  9 = strlen("bootmenu_")
@@ -41,10 +43,11 @@ enum boot_type {
BOOTMENU_TYPE_BOOTMENU,
BOOTMENU_TYPE_UEFI_BOOT_OPTION,
BOOTMENU_TYPE_DISTRO_BOOT,
+   BOOTMENU_TYPE_UEFI_MAINTENANCE,
  };

  struct bootmenu_entry {
-   unsigned short int num; /* unique number 0 .. MAX_COUNT */
+   unsigned short int num; /* unique number 0 .. MAX_DYNAMIC_ENTRY 
*/
char key[3];/* key identifier of number */
u16 *title; /* title of entry */
char *command;  /* hush command of entry */
@@ -58,7 +61,7 @@ static char *bootmenu_getoption(unsigned short int n)
  {
char name[MAX_ENV_SIZE];

-   if (n > MAX_COUNT)
+   if (n > MAX_DYNAMIC_ENTRY)
return NULL;

sprintf(name, "bootmenu_%d", n);
@@ -229,7 +232,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data 
*menu,
iter = entry;
++i;

-   if (i == MAX_COUNT - 1)
+   if (i == MAX_DYNAMIC_ENTRY)
break;
}

@@ -317,7 +320,7 @@ static int prepare_uefi_bootorder_entry(struct 
bootmenu_data *menu,

free(load_option);

-   if (i == MAX_COUNT - 1)
+   if (i == MAX_DYNAMIC_ENTRY)
break;
}

@@ -481,7 +484,7 @@ static int prepare_distro_boot_entry(struct bootmenu_data 
*menu,
iter = entry;
i++;

-   if (i == MAX_COUNT - 1)
+   if (i == MAX_DYNAMIC_ENTRY)
break;

token = strtok(NULL, " ");
@@ -520,19 +523,56 @@ static struct bootmenu_data *bootmenu_create(int delay)
goto cleanup;

if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) {
-   if (i < MAX_COUNT - 1) {
+   if (i < MAX_DYNAMIC_ENTRY) {
ret = prepare_uefi_bootorder_entry(menu, , );
if (ret < 0 && ret != -ENOENT)
goto cleanup;
}
}

-   if (i < MAX_COUNT - 1) {
+   

Re: [PATCH v5 00/17] enable menu-driven boot device selection

2022-04-28 Thread Heinrich Schuchardt

On 4/28/22 10:09, Masahisa Kojima wrote:

This patch series adds the menu-driven boot device selection,
by extending the existing "bootmenu" to include UEFI and distro_boot
related entries, and supports menu-driven UEFI boot variable
maintenance.

This patch series also includes the removable media support
that UEFI specification requires to support.

The menu example is as follows.

   *** U-Boot Boot Menu ***

  bootmenu_00   : Boot 1. kernel
  bootmenu_01   : Boot 2. kernel
  bootmenu_02   : Reset board
  UEFI BOOT : debian
  UEFI BOOT0001 : ubuntu
  UEFI BOOT0002 : mmc0:1
  UEFI BOOT0003 : mmc0:2
  UEFI BOOT0004 : nvme0:1
  UEFI BOOT0005 : nvme0:2
  UEFI BOOT0006 : usb0:2
  UEFI BOOT0007 : usb1:1
  UEFI BOOT0008 : usb1:2
  distro_boot   : usb0
  distro_boot   : scsi0
  distro_boot   : virtio0
  distro_boot   : dhcp

   Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit

[How to run on QEMU(arm64)]
1) clone source code
  $ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git \
-b kojima/bootmenu_v5_upstream_0428 --depth 1

2) prepare U-Boot .config
  $ make qemu_arm64_menuconfig
   then, enable CONFIG_CMD_BOOTMENU and CONFIG_AUTOBOOT_MENU_SHOW

3) run on QEMU(arm64) example
  $ qemu-system-aarch64 -machine virt,gic-version=3 -cpu cortex-a57 -m 4G 
-nographic \
-no-acpi -bios ./u-boot.bin -hda xxx.img

[Major Changes]
- rebased to v2022.07-rc1
- there is detailed changelog in each commit

AKASHI Takahiro (2):
   efi_loader: export efi_locate_device_handle()
   efi_loader: bootmgr: add booting from removable media

Masahisa Kojima (15):
   lib/charset: add u16_strlcat() function
   test: unit test for u16_strlcat()
   menu: always show the menu regardless of the number of entry
   menu: menu_get_choice() return -ENOENT if menu item is empty
   bootmenu: flush input buffer before waiting user key input
   bootmenu: update bootmenu_entry structure
   bootmenu: add UEFI boot entry into bootmenu
   bootmenu: add distro boot entry
   bootmenu: add Kconfig option not to enter U-Boot console
   bootmenu: factor out the user input handling
   efi_loader: menu-driven addition of UEFI boot option
   efi_loader: menu-driven deletion of UEFI boot variable
   efi_loader: menu-driven update of UEFI bootorder variable
   bootmenu: add removable media entries
   doc:bootmenu: add UEFI boot and distro boot support description

  cmd/Kconfig   |   10 +
  cmd/bootmenu.c|  807 +
  common/menu.c |  142 ++-
  doc/usage/cmd/bootmenu.rst|   78 +-
  include/charset.h |   17 +
  include/config_distro_bootcmd.h   |   14 +-
  include/efi_default_filename.h|   33 +
  include/efi_loader.h  |   61 +
  include/menu.h|   20 +
  lib/charset.c |   22 +
  lib/efi_loader/Makefile   |1 +
  lib/efi_loader/efi_bootmenu_maintenance.c | 1245 +
  lib/efi_loader/efi_bootmgr.c  |   50 +-
  lib/efi_loader/efi_boottime.c |   59 +-
  lib/efi_loader/efi_console.c  |   81 ++
  lib/efi_loader/efi_disk.c |   11 +
  lib/efi_loader/efi_file.c |   75 +-
  test/unicode_ut.c |   50 +
  18 files changed, 2518 insertions(+), 258 deletions(-)
  create mode 100644 include/efi_default_filename.h
  create mode 100644 lib/efi_loader/efi_bootmenu_maintenance.c



I prepared my test as follows:

make sandbox_defconfig
CONFIG_CMD_BOOTMENU=y
CONFIG_AUTOBOOT_MENU_SHOW=y
PREBOOT=host bind 0 ../sandbox.img

I created ../sandbox.img as GTP partioned image with a single EF00
partition. Onto the partition I copied lib/efi_loader/helloworld.efi
into path EFI/BOOT/BOOTX64.EFI.

I set up the following boot option:

=> efidebug boot dump
Boot0001:
attributes: A-- (0x0001)
  label: hello host 0:1
  file_path:
/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)/EFI\BOOT\BOOTX64.EFI
  data:
: 6d 00 79 00 20 00 6d 00 65 00 73 00 73 00 61 00  m.y.
.m.e.s.s.a.
0010: 67 00 65 00 00 00g.e...
=> efidebug boot order
 1: Boot0001: hello host 0:1
=> reset

Now the boot menu looks like this:

  *** U-Boot Boot Menu ***

 UEFI BOOT0001 : hello host 0:1
 UEFI BOOT : host0:1
 UEFI Boot Manager Maintenance
 U-Boot console

When I select nothing:

try_load_entry: trying to load "hello host 0:1" from
/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)/EFI\BOOT\BOOTX64.EFI
Booting: hello host 0:1
Hello, world!
Running on UEFI 2.9
Have ACPI 2.0 table
Have SMBIOS table
Load options: my message
Boot device:
/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/VenHw(bbe4e671-5773-4ea1-9aab-3a7dbf40c482,00)/HD(1,GPT,7e5c17c5-3f5f-49d0-ae96-511b21d7f273,0x800,0x3f7df)

Re: [PATCH] ls10xxx: Use a sane SPL_SYS_MALLOC_F_LEN default

2022-04-28 Thread Sean Anderson
Hi Fabio,

On 4/28/22 12:23 PM, Fabio Estevam wrote:
> Hi Sean,
> 
> On Thu, Apr 28, 2022 at 1:02 PM Sean Anderson  wrote:
>>
>> SPL_SYS_MALLOC_F_LEN defaults to SYS_MALLOC_F_LEN. 0x1 (the new
>> default) is 64 KiB, or around half of the total OCRAM size. Revert to
>> the previous default of 0x2000. This fixes SPL boot.
>>
>> Fixes: 545eceb520 ("imx8/ls10xx: Use a sane SYS_MALLOC_F_LEN default")
>> Signed-off-by: Sean Anderson 
> 
> Thanks for the fix.
> 
> Would it be better to fix it like this instead?
> 
> --- a/Kconfig
> +++ b/Kconfig
> @@ -257,9 +257,7 @@ config SYS_MALLOC_F_LEN
> default 0x4000 if SANDBOX || RISCV || ARCH_APPLE || ROCKCHIP_RK3368 
> || \
>   ROCKCHIP_RK3399
> default 0x8000 if RCAR_GEN3
> -   default 0x1 if ARCH_IMX8 || (ARCH_IMX8M && !IMX8MQ) || \
> -  ARCH_LS1012A || ARCH_LS1021A || ARCH_LS1043A || \
> -  ARCH_LS1046A
> +   default 0x1 if ARCH_IMX8 || (ARCH_IMX8M && !IMX8MQ)
> default 0x2000
> help
>   Before relocation, memory is very limited on many platforms. Still,
> 

That would also work. The primary problem is that between v2 and v3 the default
got raised from 0x2000 to 0x1. Do you remember why you added layerscape
stuff in the first place? The only non-default value for this property for this
family was to set it to 0x6000 for some ls2 (ls3?) SoCs (e.g. ls1088).

--Sean


[PATCH 1/1] efi_loader: BOOTSANDBOX.EFI is not a default file name

2022-04-28 Thread Heinrich Schuchardt
On the sandbox choose a default EFI file name according to the host
architecture.

Signed-off-by: Heinrich Schuchardt 
---
 include/efi_default_filename.h | 48 +-
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/include/efi_default_filename.h b/include/efi_default_filename.h
index cb2ef9e131..13b9de8754 100644
--- a/include/efi_default_filename.h
+++ b/include/efi_default_filename.h
@@ -1,32 +1,44 @@
 /* SPDX-License-Identifier: GPL-2.0+ */
 /*
- * Default boot file name when none is present in the FilePath.
- * This is defined in the UEFI specification.
+ * When a boot option does not provide a file path the EFI file to be
+ * booted is \EFI\BOOT\$(BOOTEFI_NAME).EFI. The architecture specific
+ * file name is defined in this include.
  *
- * Copyright (c) 2022, Linaro Limited
+ * Copyright (c) 2022, Heinrich Schuchardt 
  */
+
 #ifndef _EFI_DEFAULT_FILENAME_H
 #define _EFI_DEFAULT_FILENAME_H
 
-#if defined(CONFIG_ARM64)
-#define BOOTEFI_NAME "BOOTAA64.EFI"
-#elif defined(CONFIG_ARM)
-#define BOOTEFI_NAME "BOOTARM.EFI"
-#elif defined(CONFIG_X86_64)
+#include 
+
+#undef BOOTEFI_NAME
+
+#if HOST_ARCH == HOST_ARCH_X86_64
 #define BOOTEFI_NAME "BOOTX64.EFI"
-#elif defined(CONFIG_X86)
+#endif
+
+#if HOST_ARCH == HOST_ARCH_X86
 #define BOOTEFI_NAME "BOOTIA32.EFI"
-#elif defined(CONFIG_ARCH_RV32I)
+#endif
+
+#if HOST_ARCH == HOST_ARCH_AARCH64
+#define BOOTEFI_NAME "BOOTAA64.EFI"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_ARM
+#define BOOTEFI_NAME "BOOTARM.EFI"
+#endif
+
+#if HOST_ARCH == HOST_ARCH_RISCV32
 #define BOOTEFI_NAME "BOOTRISCV32.EFI"
-#elif defined(CONFIG_ARCH_RV64I)
+#endif
+
+#if HOST_ARCH == HOST_ARCH_RISCV64
 #define BOOTEFI_NAME "BOOTRISCV64.EFI"
-#elif defined(CONFIG_SANDBOX)
-/*
- * SANDBOX is not defined in UEFI specification, but
- * this definition avoids build failure for SANDBOX.
- */
-#define BOOTEFI_NAME "BOOTSANDBOX.EFI"
-#else
+#endif
+
+#ifndef BOOTEFI_NAME
 #error Unsupported UEFI architecture
 #endif
 
-- 
2.34.1



Re: [PATCH] ls10xxx: Use a sane SPL_SYS_MALLOC_F_LEN default

2022-04-28 Thread Fabio Estevam
Hi Sean,

On Thu, Apr 28, 2022 at 1:02 PM Sean Anderson  wrote:
>
> SPL_SYS_MALLOC_F_LEN defaults to SYS_MALLOC_F_LEN. 0x1 (the new
> default) is 64 KiB, or around half of the total OCRAM size. Revert to
> the previous default of 0x2000. This fixes SPL boot.
>
> Fixes: 545eceb520 ("imx8/ls10xx: Use a sane SYS_MALLOC_F_LEN default")
> Signed-off-by: Sean Anderson 

Thanks for the fix.

Would it be better to fix it like this instead?

--- a/Kconfig
+++ b/Kconfig
@@ -257,9 +257,7 @@ config SYS_MALLOC_F_LEN
default 0x4000 if SANDBOX || RISCV || ARCH_APPLE || ROCKCHIP_RK3368 || \
  ROCKCHIP_RK3399
default 0x8000 if RCAR_GEN3
-   default 0x1 if ARCH_IMX8 || (ARCH_IMX8M && !IMX8MQ) || \
-  ARCH_LS1012A || ARCH_LS1021A || ARCH_LS1043A || \
-  ARCH_LS1046A
+   default 0x1 if ARCH_IMX8 || (ARCH_IMX8M && !IMX8MQ)
default 0x2000
help
  Before relocation, memory is very limited on many platforms. Still,


Re: [PATCH v3 00/15] Add support for MediaTek MT7621 SoC

2022-04-28 Thread Marek Behún
On Thu, 28 Apr 2022 18:37:09 +0800
Weijie Gao  wrote:

> This series will add support for MediaTek MT7621 SoC with two reference boards
> and related drivers.
> 
> The MediaTek MT7621 is a network processor integrating a dual-core
> dual-threaded MIPS 1004Kc processor running at a normal frequency of 880MHz.
> This chip can be found in many wireless routers.

Hello Weijie,

doesn't MT7621 U-Boot need a proprietary binary for DDR training?
I remember that it was required in 2016 for MqMaker WitiBoard.

Marek


[PATCH] ls10xxx: Use a sane SPL_SYS_MALLOC_F_LEN default

2022-04-28 Thread Sean Anderson
SPL_SYS_MALLOC_F_LEN defaults to SYS_MALLOC_F_LEN. 0x1 (the new
default) is 64 KiB, or around half of the total OCRAM size. Revert to
the previous default of 0x2000. This fixes SPL boot.

Fixes: 545eceb520 ("imx8/ls10xx: Use a sane SYS_MALLOC_F_LEN default")
Signed-off-by: Sean Anderson 
---

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

diff --git a/Kconfig b/Kconfig
index bdae59e06f..2a8ccd79ec 100644
--- a/Kconfig
+++ b/Kconfig
@@ -285,6 +285,7 @@ config SPL_SYS_MALLOC_F_LEN
depends on SYS_MALLOC_F && SPL
default 0 if !SPL_FRAMEWORK
default 0x2800 if RCAR_GEN3
+   default 0x2000 if ARCH_LS1012A || ARCH_LS1021A || ARCH_LS1043A || 
ARCH_LS1046A
default SYS_MALLOC_F_LEN
help
  In SPL memory is very limited on many platforms. Still,
-- 
2.35.1.1320.gc452695387.dirty



Re: [PATCH] patman: Fix defaults not propegating to subparsers

2022-04-28 Thread Sean Anderson
Hi Alper,

On 4/27/22 4:11 PM, Alper Nebi Yasak wrote:
> On 22/04/2022 19:50, Sean Anderson wrote:
>> On python 3.8.10, subparsers are not updated with defaults. I suspect
>> this is related to [1]. Fix this by explicitly updating subparsers with
>> settings.
>> 
>> [1] https://github.com/python/cpython/issues/89398
>> 
>> Fixes: 3145b63513 ("patman: Update defaults in subparsers")
>> Signed-off-by: Sean Anderson 
>> ---
>> 
>>  tools/patman/settings.py | 6 +-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> Also happens on Python 3.10. I can add the following to ~/.patman:
> 
> [settings]
> ignore_bad_tags: True
> dry_run: True
> 
> and they start taking effect only after this patch.
> 
> Reviewed-by: Alper Nebi Yasak 
> Tested-by: Alper Nebi Yasak 
> 
>> 
>> diff --git a/tools/patman/settings.py b/tools/patman/settings.py
>> index 7c2b5c196c..658fe12be5 100644
>> --- a/tools/patman/settings.py
>> +++ b/tools/patman/settings.py
>> @@ -246,8 +246,10 @@ def _UpdateDefaults(main_parser, config):
>>  
>>  # Collect the defaults from each parser
>>  defaults = {}
>> +parser_defaults = []
>>  for parser in parsers:
>>  pdefs = parser.parse_known_args()[0]
>> +parser_defaults.append(pdefs)
>>  defaults.update(vars(pdefs))
>>  
>>  # Go through the settings and collect defaults
>> @@ -264,8 +266,10 @@ def _UpdateDefaults(main_parser, config):
>>  else:
>>  print("WARNING: Unknown setting %s" % name)
>>  
>> -# Set all the defaults (this propagates through all subparsers)
>> +# Set all the defaults (this does NOT propagate through all subparsers)
> 
> Something like 'Set all the defaults and manually propagate ...' would
> be clearer here.

Sounds good.

>>  main_parser.set_defaults(**defaults)
>> +for parser, pdefs in zip(parsers, parser_defaults):
>> +parser.set_defaults(**{ k: v for k, v in defaults.items() if k in 
>> pdefs})
> 
> I think this would look better if you extract the dict as a variable.

I'm not sure what you mean. I'm not a big fan of single-use variables (though
this is an 81-character line...)

--Sean

>>  
>>  def _ReadAliasFile(fname):
>>  """Read in the U-Boot git alias file if it exists.
> 


Re: [PATCH] efi_loader: Improve console screen clearing and reset

2022-04-28 Thread Jan Kiszka
On 28.04.22 13:52, Heinrich Schuchardt wrote:
> On 4/25/22 11:23, Jan Kiszka wrote:
>> From: Jan Kiszka 
>>
>> Ensure that the default colors are set when clearing the screen so that
>> the background is properly filled and succeeding colored outputs will
>> have no differently colored trail.
>>
>> Before clearing, ensure that no previous output of firmware or UEFI
>> programs will overwritten on serial devices or other streaming consoles.
>> This helps generating complete boot logs.
>>
>> Signed-off-by: Jan Kiszka 
>> ---
>>   lib/efi_loader/efi_console.c | 16 +---
>>   1 file changed, 13 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
>> index ba68a150172..0270b20bafe 100644
>> --- a/lib/efi_loader/efi_console.c
>> +++ b/lib/efi_loader/efi_console.c
>> @@ -463,8 +463,18 @@ static efi_status_t EFIAPI efi_cout_set_attribute(
>>   static efi_status_t EFIAPI efi_cout_clear_screen(
>>   struct efi_simple_text_output_protocol *this)
>>   {
>> +    unsigned int row;
>> +
>>   EFI_ENTRY("%p", this);
>>
>> +    /* Avoid overwriting previous outputs on streaming consoles */
> 
> Thank you for addressing the inconvenience of the partially deleted
> scrollback buffer.
> 
> Don't assume that the cursor is in the last line. You first have to move
> it there:
> 
>     printf(ESC "%d;1H", efi_cout_modes[efi_con_mode.mode].rows);

Not necessarily - we may just inject more lines than needed. But we
could also avoid that, true.

> 
>> +    for (row = 1; row < efi_cout_modes[efi_con_mode.mode].rows; row++)
>> +    printf("\n");
> 
> We may have both video output and serial output. The proposed logic may
> not work out correctly if the video screen size differs from the screen
> size of the serial console.

OK, but video is not a streaming output with scroll-back buffer, is it?
All we need to ensure is that the geometry used here is that of the
largest streaming output - and rather scroll more than needed to avoid
overwriting. Other outputs should not notice the difference.

> 
> Your solution does not cover the cls command.

Not sure I can follow here yet - which cls are you referring to?

> 
> It will not work with the proposed UEFI boot menu
> (https://patchwork.ozlabs.org/project/uboot/list/?series=297320).
> 

How will it fail? Guess I need to try this out.

> A complete solution would have to reside in _serial_puts(). But I doubt
> that we want to enlarge the code size there.

What is the logic right now when there are multiple outputs attached?

> 
> Therefore I am a bit skeptical about the suggested change.
> 
>> +
>> +    /* Set default colors if not done yet */
>> +    if (efi_con_mode.attribute == 0)
>> +    efi_cout_set_attribute(this, 0x07);
> 
> The UEFI specification has this sentence: "The ClearScreen() function
> clears the output device(s) display to the currently selected background
> color."
> 
> So we should not switch colors here.

We don't do that. We only do that if none was selected so far.

> 
> The currently selected background when starting the first UEFI
> application depends on CONFIG_SYS_WHITE_ON_BLACK.

On ClearScreen, we switch to 0x07 unconditionally (white on black) so far.

> 
>> +
>>   /*
>>    * The Linux console wants both a clear and a home command. The
>> video
>>    * uclass does not support [H without coordinates, yet.
>> @@ -522,11 +532,11 @@ static efi_status_t EFIAPI efi_cout_reset(
>>   {
>>   EFI_ENTRY("%p, %d", this, extended_verification);
>>
>> +    /* Trigger reset to default colors */
>> +    efi_con_mode.attribute = 0;
>> +
>>   /* Clear screen */
>>   EFI_CALL(efi_cout_clear_screen(this));
>> -    /* Set default colors */
>> -    efi_con_mode.attribute = 0x07;
> 
> This value should depend on CONFIG_SYS_WHITE_ON_BLACK:
> 
> Also efi_cout_set_attribute(efi_con_out, 0) should consider
> CONFIG_SYS_WHITE_ON_BLACK.
> 
> The best thing to do is fixing efi_cout_set_attribute() and invoking
> 
>     EFI_CALL(efi_cout_set_attributed(efi_con_out, 0));
> 
> But this is a subject for a separate patch.

Indeed, I was just preserving existing behavior (or issues).

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux


please modify output of i.MX8MSCALE DDR Tool

2022-04-28 Thread Rasmus Villemoes
Hi NXP folks

Is it possible for you to modify the i.MX8MSCALE DDR Tool so that the
lpddr4_timing.c files it emits use "static" in front of ddr_ddrc_cfg[]
and all the other arrays it defines; the only symbol that file defines
which should have external linkage is the final "struct dram_timing_info
dram_timing" one.

When preparing the timing data for a board which will ship with
different amounts of RAM, and thus needing to have some board-logic to
choose between multiple instances of struct dram_timing_info, it is
quite a nuisance to have to modify these files manually over and over -
there's not much to do about the dram_timing symbol, but all the other
ones might as well be static always.

Rasmus


Re: [PATCH 4/4] spl: spl_nand: Fix bad block handling in fitImage

2022-04-28 Thread Tom Rini
On Wed, Apr 27, 2022 at 07:50:25AM +0200, Michael Trimarchi wrote:

> If the fitImage has some bad block in fit image area, the
> offset must be recalulcated. This should be done always.
> After implementing it in mxs now is possible to call the function
> even for that platform.
> 
> Cc: Fabio Estevam 
> Signed-off-by: Michael Trimarchi 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] efi_loader: Improve console screen clearing and reset

2022-04-28 Thread Heinrich Schuchardt

On 4/25/22 11:23, Jan Kiszka wrote:

From: Jan Kiszka 

Ensure that the default colors are set when clearing the screen so that
the background is properly filled and succeeding colored outputs will
have no differently colored trail.

Before clearing, ensure that no previous output of firmware or UEFI
programs will overwritten on serial devices or other streaming consoles.
This helps generating complete boot logs.

Signed-off-by: Jan Kiszka 
---
  lib/efi_loader/efi_console.c | 16 +---
  1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index ba68a150172..0270b20bafe 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -463,8 +463,18 @@ static efi_status_t EFIAPI efi_cout_set_attribute(
  static efi_status_t EFIAPI efi_cout_clear_screen(
struct efi_simple_text_output_protocol *this)
  {
+   unsigned int row;
+
EFI_ENTRY("%p", this);

+   /* Avoid overwriting previous outputs on streaming consoles */


Thank you for addressing the inconvenience of the partially deleted
scrollback buffer.

Don't assume that the cursor is in the last line. You first have to move
it there:

printf(ESC "%d;1H", efi_cout_modes[efi_con_mode.mode].rows);


+   for (row = 1; row < efi_cout_modes[efi_con_mode.mode].rows; row++)
+   printf("\n");


We may have both video output and serial output. The proposed logic may
not work out correctly if the video screen size differs from the screen
size of the serial console.

Your solution does not cover the cls command.

It will not work with the proposed UEFI boot menu
(https://patchwork.ozlabs.org/project/uboot/list/?series=297320).

A complete solution would have to reside in _serial_puts(). But I doubt
that we want to enlarge the code size there.

Therefore I am a bit skeptical about the suggested change.


+
+   /* Set default colors if not done yet */
+   if (efi_con_mode.attribute == 0)
+   efi_cout_set_attribute(this, 0x07);


The UEFI specification has this sentence: "The ClearScreen() function
clears the output device(s) display to the currently selected background
color."

So we should not switch colors here.

The currently selected background when starting the first UEFI
application depends on CONFIG_SYS_WHITE_ON_BLACK.


+
/*
 * The Linux console wants both a clear and a home command. The video
 * uclass does not support [H without coordinates, yet.
@@ -522,11 +532,11 @@ static efi_status_t EFIAPI efi_cout_reset(
  {
EFI_ENTRY("%p, %d", this, extended_verification);

+   /* Trigger reset to default colors */
+   efi_con_mode.attribute = 0;
+
/* Clear screen */
EFI_CALL(efi_cout_clear_screen(this));
-   /* Set default colors */
-   efi_con_mode.attribute = 0x07;


This value should depend on CONFIG_SYS_WHITE_ON_BLACK:

Also efi_cout_set_attribute(efi_con_out, 0) should consider
CONFIG_SYS_WHITE_ON_BLACK.

The best thing to do is fixing efi_cout_set_attribute() and invoking

EFI_CALL(efi_cout_set_attributed(efi_con_out, 0));

But this is a subject for a separate patch.

Best regards

Heinrich


-   printf(ESC "[0;37;40m");

return EFI_EXIT(EFI_SUCCESS);
  }




[PATCH] board: synquacer: developerbox: Remove Masami from MAINTAINERS

2022-04-28 Thread Masami Hiramatsu
Remove Masami Hiramatsu from MAINTAINERS since he will leave
Linaro and his email will be not available anymore.

Signed-off-by: Masami Hiramatsu 
---
 board/socionext/developerbox/MAINTAINERS |1 -
 1 file changed, 1 deletion(-)

diff --git a/board/socionext/developerbox/MAINTAINERS 
b/board/socionext/developerbox/MAINTAINERS
index aa672b6e05..c6d4f2749d 100644
--- a/board/socionext/developerbox/MAINTAINERS
+++ b/board/socionext/developerbox/MAINTAINERS
@@ -1,5 +1,4 @@
 DEVELOPER BOX
-M: Masami Hiramatsu 
 M: Jassi Brar 
 S: Maintained
 F: arch/arm/dts/synquacer-*



Re: [PATCH] misc: i2c_eeprom: fix at24c32 offset_len

2022-04-28 Thread Rasmus Villemoes
On 28/04/2022 13.11, Eugen Hristev wrote:
> According to at24c32 datasheet:
> 
> RANDOM READ: A random read requires a “dummy” byte write sequence to load in
> the dataword address. Once the device address word and data word address are
> clocked in and acknowledged by the EEPROM, the microcontroller must generate
> another start condition.
> 
> BYTE WRITE: A write operation requires two 8-bit data word addresses following
> the device address word and acknowledgment. Upon receipt of this address, the
> EEPROM will again respond with a zero and then clock in the first 8-bit data
> word.
> 
> From this, my understanding is that dataword is 1 byte, and when reading the
> offset is just 1 byte.

Yes, you read data byte by byte, but that doesn't mean all those bytes
can be addressed using a single byte...

>  drivers/misc/i2c_eeprom.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c
> index 89a450d0f8..c8c67cf028 100644
> --- a/drivers/misc/i2c_eeprom.c
> +++ b/drivers/misc/i2c_eeprom.c
> @@ -230,7 +230,7 @@ static const struct i2c_eeprom_drv_data atmel24c32_data = 
> {
>   .size = 4096,
>   .pagesize = 32,
>   .addr_offset_mask = 0,
> - .offset_len = 2,
> + .offset_len = 1,
>  };

But this can't be correct, because how could one then possibly address
all 4096 bytes? Note that some eeproms larger than 256 bytes exist but
still use a 1-byte address; that's because they then respond to multiple
i2c addresses - that's what the "addr_offset_mask" is about.

Something else must be going on in your case, I think. Are you sure the
device tree is correct, i.e. that the eeprom is actually that one and
not one that does indeed use 1-byte addressing? I got curious and
downloaded the "SAM9X60-EK Board Design Files" from
https://www.microchip.com/en-us/development-tool/DT100126#Documentation,
inside which one finds mention of a "MCHP MEMORY SERIAL EEPROM 2Kb I2C
24AA025E48T-I/OT SOT-23-6", and 2Kb == 256 byte.

If you have the physical board handy, I'd try to locate the eeprom and
see what's printed on it.

Rasmus


[PATCH] watchdog: Fix SPL build with watchdog disabled in asm files

2022-04-28 Thread Pali Rohár
Allow to compile assembler files in SPL build which calls WATCHDOG_RESET
function when watchdog is disabled in SPL and enabled in U-Boot proper.

This issue was fixed in past by commit 7fbd42f5afc4 ("watchdog: Handle SPL
build with watchdog disabled") for C source files, but not for assembler
source files.

Currently the only assembler source file which calls WATCHDOG_RESET is
arch/powerpc/lib/ticks.S, so this patch affects and fixes powerpc SPL
builds.

Signed-off-by: Pali Rohár 
---
 include/watchdog.h | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/watchdog.h b/include/watchdog.h
index 14fa5fda259e..813cc8f2a5d3 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -49,7 +49,13 @@ int init_func_watchdog_reset(void);
 */
#if defined(CONFIG_WATCHDOG)
#if defined(__ASSEMBLY__)
-   #define WATCHDOG_RESET bl watchdog_reset
+   /* Don't require the watchdog to be enabled in SPL */
+   #if defined(CONFIG_SPL_BUILD) &&\
+   !defined(CONFIG_SPL_WATCHDOG)
+   #define WATCHDOG_RESET /*XXX 
DO_NOT_DEL_THIS_COMMENT*/
+   #else
+   #define WATCHDOG_RESET bl watchdog_reset
+   #endif
#else
/* Don't require the watchdog to be enabled in SPL */
#if defined(CONFIG_SPL_BUILD) &&\
-- 
2.20.1



[PATCH] powerpc: mpc85xx: Fix compilation with CONFIG_WDT

2022-04-28 Thread Pali Rohár
When CONFIG_WDT is enabled then non-DM watchdog code cannot be used due to
conflicting functions like watchdog_reset(). So disable compilation of
mpc85xx watchdog_reset() function when CONFIG_WDT is enabled.

Signed-off-by: Pali Rohár 
---
 arch/powerpc/cpu/mpc85xx/cpu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/cpu/mpc85xx/cpu.c b/arch/powerpc/cpu/mpc85xx/cpu.c
index 261f79e40585..226a26ba320a 100644
--- a/arch/powerpc/cpu/mpc85xx/cpu.c
+++ b/arch/powerpc/cpu/mpc85xx/cpu.c
@@ -348,6 +348,7 @@ __weak unsigned long get_tbclk(void)
 }
 
 
+#ifndef CONFIG_WDT
 #if defined(CONFIG_WATCHDOG)
 #define WATCHDOG_MASK (TCR_WP(63) | TCR_WRC(3) | TCR_WIE)
 void
@@ -376,6 +377,7 @@ watchdog_reset(void)
enable_interrupts();
 }
 #endif /* CONFIG_WATCHDOG */
+#endif
 
 /*
  * Initializes on-chip MMC controllers.
-- 
2.20.1



[PATCH] dt-bindings: leds: import common led bindings from linux 5.17

2022-04-28 Thread Pali Rohár
This allows usage of LED_COLOR_ID_RGB macro in DTS files.

Signed-off-by: Pali Rohár 
---
 include/dt-bindings/leds/common.h | 48 ---
 1 file changed, 37 insertions(+), 11 deletions(-)

diff --git a/include/dt-bindings/leds/common.h 
b/include/dt-bindings/leds/common.h
index 9e1256a7c1bf..3be89a7c20a9 100644
--- a/include/dt-bindings/leds/common.h
+++ b/include/dt-bindings/leds/common.h
@@ -6,6 +6,7 @@
  * Author: Jacek Anaszewski 
  *
  * Copyright (C) 2019 Jacek Anaszewski 
+ * Copyright (C) 2020 Pavel Machek 
  */
 
 #ifndef __DT_BINDINGS_LEDS_H
@@ -29,19 +30,51 @@
 #define LED_COLOR_ID_VIOLET5
 #define LED_COLOR_ID_YELLOW6
 #define LED_COLOR_ID_IR7
-#define LED_COLOR_ID_MAX   8
+#define LED_COLOR_ID_MULTI 8   /* For multicolor LEDs */
+#define LED_COLOR_ID_RGB   9   /* For multicolor LEDs that can do 
arbitrary color,
+  so this would include RGBW and 
similar */
+#define LED_COLOR_ID_MAX   10
 
 /* Standard LED functions */
+/* Keyboard LEDs, usually it would be input4::capslock etc. */
+/*   Obsolete equivalent: "shift-key-light" */
+#define LED_FUNCTION_CAPSLOCK "capslock"
+#define LED_FUNCTION_SCROLLLOCK "scrolllock"
+#define LED_FUNCTION_NUMLOCK "numlock"
+/*   Obsolete equivalents: "tpacpi::thinklight" (IBM/Lenovo Thinkpads),
+ "lp5523:kb{1,2,3,4,5,6}" (Nokia N900) */
+#define LED_FUNCTION_KBD_BACKLIGHT "kbd_backlight"
+
+/* System LEDs, usually found on system body.
+   platform::mute (etc) is sometimes seen, :mute would be better */
+#define LED_FUNCTION_POWER "power"
+#define LED_FUNCTION_DISK "disk"
+
+/*   Obsolete: "platform:*:charging" (allwinner sun50i) */
+#define LED_FUNCTION_CHARGING "charging"
+/*   Used RGB notification LEDs common on phones.
+ Obsolete equivalents: "status-led:{red,green,blue}" (Motorola Droid 4),
+ "lp5523:{r,g,b}" (Nokia N900) */
+#define LED_FUNCTION_STATUS "status"
+
+#define LED_FUNCTION_MICMUTE "micmute"
+#define LED_FUNCTION_MUTE "mute"
+
+/* Used for player LEDs as found on game controllers from e.g. Nintendo, Sony. 
*/
+#define LED_FUNCTION_PLAYER1 "player-1"
+#define LED_FUNCTION_PLAYER2 "player-2"
+#define LED_FUNCTION_PLAYER3 "player-3"
+#define LED_FUNCTION_PLAYER4 "player-4"
+#define LED_FUNCTION_PLAYER5 "player-5"
+
+/* Miscelleaus functions. Use functions above if you can. */
 #define LED_FUNCTION_ACTIVITY "activity"
 #define LED_FUNCTION_ALARM "alarm"
 #define LED_FUNCTION_BACKLIGHT "backlight"
 #define LED_FUNCTION_BLUETOOTH "bluetooth"
 #define LED_FUNCTION_BOOT "boot"
 #define LED_FUNCTION_CPU "cpu"
-#define LED_FUNCTION_CAPSLOCK "capslock"
-#define LED_FUNCTION_CHARGING "charging"
 #define LED_FUNCTION_DEBUG "debug"
-#define LED_FUNCTION_DISK "disk"
 #define LED_FUNCTION_DISK_ACTIVITY "disk-activity"
 #define LED_FUNCTION_DISK_ERR "disk-err"
 #define LED_FUNCTION_DISK_READ "disk-read"
@@ -50,21 +83,14 @@
 #define LED_FUNCTION_FLASH "flash"
 #define LED_FUNCTION_HEARTBEAT "heartbeat"
 #define LED_FUNCTION_INDICATOR "indicator"
-#define LED_FUNCTION_KBD_BACKLIGHT "kbd_backlight"
 #define LED_FUNCTION_LAN "lan"
 #define LED_FUNCTION_MAIL "mail"
 #define LED_FUNCTION_MTD "mtd"
-#define LED_FUNCTION_MICMUTE "micmute"
-#define LED_FUNCTION_MUTE "mute"
-#define LED_FUNCTION_NUMLOCK "numlock"
 #define LED_FUNCTION_PANIC "panic"
 #define LED_FUNCTION_PROGRAMMING "programming"
-#define LED_FUNCTION_POWER "power"
 #define LED_FUNCTION_RX "rx"
 #define LED_FUNCTION_SD "sd"
-#define LED_FUNCTION_SCROLLLOCK "scrolllock"
 #define LED_FUNCTION_STANDBY "standby"
-#define LED_FUNCTION_STATUS "status"
 #define LED_FUNCTION_TORCH "torch"
 #define LED_FUNCTION_TX "tx"
 #define LED_FUNCTION_USB "usb"
-- 
2.20.1



Re: [PATCH] efi_loader: Select EVENT as well

2022-04-28 Thread Heinrich Schuchardt

On 4/28/22 12:03, Jan Kiszka wrote:

On 27.04.22 07:55, AKASHI Takahiro wrote:

On Wed, Apr 27, 2022 at 07:47:15AM +0200, Jan Kiszka wrote:

From: Jan Kiszka 

Fixes

WARNING: unmet direct dependencies detected for EVENT_DYNAMIC
   Depends on [n]: EVENT [=n]
   Selected by [y]:
   - EFI_LOADER [=y] && OF_LIBFDT [=y] && ...

and the succeeding build breakage.

Signed-off-by: Jan Kiszka 
---
  lib/efi_loader/Kconfig | 1 +
  1 file changed, 1 insertion(+)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 6b245f50a72..1bfb9ddbda9 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -15,6 +15,7 @@ config EFI_LOADER
depends on !EFI_APP
default y if !ARM || SYS_CPU = armv7 || SYS_CPU = armv8
select DM_EVENT
+   select EVENT


event_notify_null() used for the DM_EVENT implementation is not
available without EVENT.

Please, let DM_EVENT select on EVENT (drivers/core/Kconfig).

Best regards

Heinrich



I wonder why DM_EVENT does not *select*, but implies EVENT.
Should any subsystem relying on DM_EVENT work without EVENT?
 -> Simon?



Looks like you forgot to CC him.

Jan


-Takahiro Akashi


select EVENT_DYNAMIC
select LIB_UUID
imply PARTITION_UUIDS
--
2.34.1






Re: [PATCH] efi_loader: disk: allow blk devices even without UCLASS_PARTITION

2022-04-28 Thread Heinrich Schuchardt

On 4/28/22 06:49, AKASHI Takahiro wrote:

While GPT partition is mandated in UEFI specification, CONFIG_PARTITION is
seen optional under the current implementation.
So modify efi_disk_rw_blocks() to allow accepting UCLASS_BLK devices.

Fixes: commit d97e98c887ed ("efi_loader: disk: use udevice instead of blk_desc")
Signed-off-by: AKASHI Takahiro 
---
  lib/efi_loader/efi_disk.c | 29 +++--
  1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 8fb5b2363c45..f5b462fb164a 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -99,21 +99,22 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io 
*this,
if (buffer_size & (blksz - 1))
return EFI_BAD_BUFFER_SIZE;

-#if CONFIG_IS_ENABLED(PARTITIONS)
-   if (direction == EFI_DISK_READ)
-   n = dev_read(diskobj->dev, lba, blocks, buffer);
-   else
-   n = dev_write(diskobj->dev, lba, blocks, buffer);
-#else
-   /* dev is always a block device (UCLASS_BLK) */
-   struct blk_desc *desc;
+   if (CONFIG_IS_ENABLED(PARTITIONS) &&
+   device_get_uclass_id(diskobj->dev) == UCLASS_PARTITION) {
+   if (direction == EFI_DISK_READ)
+   n = dev_read(diskobj->dev, lba, blocks, buffer);
+   else
+   n = dev_write(diskobj->dev, lba, blocks, buffer);


Thanks for the patch. It solves the problem with the block IO protocol.

Why should dev_read() and dev_write only work for UCLASS_PARTITION?
Can't we make it work for any block device? I think the treatment of
different types of block devices should be moved to disk/disk-uclass.c.

I will pull this patch as a fast fix. But this should not be the final
design.

Reviewed-by: Heinrich Schuchardt 


+   } else {
+   /* dev is a block device (UCLASS_BLK) */
+   struct blk_desc *desc;

-   desc = dev_get_uclass_plat(diskobj->dev);
-   if (direction == EFI_DISK_READ)
-   n = blk_dread(desc, lba, blocks, buffer);
-   else
-   n = blk_dwrite(desc, lba, blocks, buffer);
-#endif
+   desc = dev_get_uclass_plat(diskobj->dev);
+   if (direction == EFI_DISK_READ)
+   n = blk_dread(desc, lba, blocks, buffer);
+   else
+   n = blk_dwrite(desc, lba, blocks, buffer);
+   }

/* We don't do interrupts, so check for timers cooperatively */
efi_timer_check();




Re: [PATCH v5 00/12] efi_loader: more tightly integrate UEFI disks to driver model

2022-04-28 Thread Mark Kettenis
> Date: Thu, 28 Apr 2022 11:42:19 +0200
> From: Heinrich Schuchardt 
> 
> On 4/28/22 11:09, Mark Kettenis wrote:
> >> We call efi_disk_init() after the MMC device is probed. Therefore
> >> probing of the MCC device does not trigger EVT_DM_POST_PROBE.
> >>
> >> We have to move the efi_disk_init() call before initr_dm().
> >>
> >> [PATCH 1/1] efi_loader: call efi_init_early() earlier
> >> https://lists.denx.de/pipermail/u-boot/2022-April/482701.html
> >>
> >> With the patch GRUB now sees the MMC device but it is still not seeing
> >> the partitions:
> >>
> >> grub rescue> ls
> >> (hd0) (hd1)
> >>
> >> This is strange because devices and protocols look rather normal now:
> > Do you have the fix for the raw disk support in your tree?  I suspect
> > that GRUB needs that to read the partition table.
> >
> 
> Do you relate to an existing patch or only to the bug that you reported?

There is a patch now:

https://patchwork.ozlabs.org/project/uboot/patch/20220428044916.52250-1-takahiro.aka...@linaro.org/

Cheers,

Mark


Re: [PATCH] efi_loader: Select EVENT as well

2022-04-28 Thread Jan Kiszka
On 27.04.22 07:55, AKASHI Takahiro wrote:
> On Wed, Apr 27, 2022 at 07:47:15AM +0200, Jan Kiszka wrote:
>> From: Jan Kiszka 
>>
>> Fixes
>>
>> WARNING: unmet direct dependencies detected for EVENT_DYNAMIC
>>   Depends on [n]: EVENT [=n]
>>   Selected by [y]:
>>   - EFI_LOADER [=y] && OF_LIBFDT [=y] && ...
>>
>> and the succeeding build breakage.
>>
>> Signed-off-by: Jan Kiszka 
>> ---
>>  lib/efi_loader/Kconfig | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
>> index 6b245f50a72..1bfb9ddbda9 100644
>> --- a/lib/efi_loader/Kconfig
>> +++ b/lib/efi_loader/Kconfig
>> @@ -15,6 +15,7 @@ config EFI_LOADER
>>  depends on !EFI_APP
>>  default y if !ARM || SYS_CPU = armv7 || SYS_CPU = armv8
>>  select DM_EVENT
>> +select EVENT
> 
> I wonder why DM_EVENT does not *select*, but implies EVENT.
> Should any subsystem relying on DM_EVENT work without EVENT?
> -> Simon?
> 

Looks like you forgot to CC him.

Jan

> -Takahiro Akashi
> 
>>  select EVENT_DYNAMIC
>>  select LIB_UUID
>>  imply PARTITION_UUIDS
>> -- 
>> 2.34.1

-- 
Siemens AG, Technology
Competence Center Embedded Linux


Re: [PATCH v5 00/12] efi_loader: more tightly integrate UEFI disks to driver model

2022-04-28 Thread Heinrich Schuchardt

On 4/28/22 11:09, Mark Kettenis wrote:

We call efi_disk_init() after the MMC device is probed. Therefore
probing of the MCC device does not trigger EVT_DM_POST_PROBE.

We have to move the efi_disk_init() call before initr_dm().

[PATCH 1/1] efi_loader: call efi_init_early() earlier
https://lists.denx.de/pipermail/u-boot/2022-April/482701.html

With the patch GRUB now sees the MMC device but it is still not seeing
the partitions:

grub rescue> ls
(hd0) (hd1)

This is strange because devices and protocols look rather normal now:

Do you have the fix for the raw disk support in your tree?  I suspect
that GRUB needs that to read the partition table.



Do you relate to an existing patch or only to the bug that you reported?

Best regards

Heinrich


Re: [PATCH v5 00/12] efi_loader: more tightly integrate UEFI disks to driver model

2022-04-28 Thread Mark Kettenis
> Date: Thu, 28 Apr 2022 08:45:51 +0200
> Content-Language: en-US
> From: Heinrich Schuchardt 
> Cc: masami.hirama...@linaro.org, u-boot@lists.denx.de, s...@chromium.org,
>  ilias.apalodi...@linaro.org, Tom Rini ,
>  Mark Kettenis 
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> On 4/28/22 06:52, AKASHI Takahiro wrote:
> > On Wed, Apr 27, 2022 at 12:26:09PM +0900, AKASHI Takahiro wrote:
> >> Heinrich,
> >>
> >> On Tue, Apr 26, 2022 at 07:02:46PM +0200, Heinrich Schuchardt wrote:
> >>> On 4/26/22 16:44, AKASHI Takahiro wrote:
>  On Tue, Apr 26, 2022 at 03:57:26PM +0200, Heinrich Schuchardt wrote:
> > On 4/26/22 01:44, AKASHI Takahiro wrote:
> > I expect that boards that booted with previous versions of U-Boot using
> > the respective defconfig still boot. But they don't. Here is one example
> > (orangepi_pc_defconfig):
> >
> >  Found U-Boot script /boot.scr.uimg
> >  189 bytes read in 2 ms (91.8 KiB/s)
> >  ## Executing script at 4310
> >  22979 bytes read in 8 ms (2.7 MiB/s)
> >  98304 bytes read in 8 ms (11.7 MiB/s)
> >  Booting /EFI\debian\grubarm.efi
> >  Welcome to GRUB!
> >
> >  error: disk `,msdos2' not found.
> >  grub rescue>
> >
> > In U-Boot v2022.04 function efi_disk_register() ensured that all block
> > devices and their partitions were added as EFI handles.
>  Not the all block devices, but the block devices which have already
>  enumerated when efi_init_obj_list() is called.
> 
> > But that
> > function is missing now.
>  What (boot) device are you using here?
> 
>  Please show me the values of env variables, particularly, "boot_targets".
> 
>  Please show me the content of boot.scr.uimg, too.
> 
>  Please show me the output from
>  => dm tree
>  => efidebug devices
>  for 2022.04 and 2022.07-rc1.
> 
>  -Takahiro Akashi
> 
> 
> 
> >>>
> >>>
> >>> I am booting from mmc. Boot.scr just loads the device-tree from mmc-
> >>>
> >>> mmcblk0 179:00 29.8G  0 disk
> >>> ├─mmcblk0p1 179:101G  0 part /boot/efi
> >>> ├─mmcblk0p2 179:201G  0 part /boot
> >>> └─mmcblk0p3 179:30 27.8G  0 part /
> >>
> >> Okay.
> >>
> >>>
> >>> U-Boot 2022.04 (Apr 26 2022 - 16:02:27 +) Allwinner Technology
> >>> --
> >>>
> >>> grub> ls
> >>> (hd0) (hd0,msdos1) (hd1) (hd1,msdos3) (hd1,msdos2) (hd1,msdos1)
> >>>
> >>> hd0 is a USB stick
> >>> hd1 is the SD card
> >>>
> >>> boot.scr
> >>> 
> >>>
> >>> #
> >>> # flash-kernel: bootscr.sunxi
> >>> #
> >>>
> >>> # boot script for Allwinner SunXi-based devices
> >>>
> >>> # Mainline u-boot v2014.10 introduces a new default environment and
> >>> # a new common bootcmd handling for all platforms, which is not fully
> >>> # compatible with the old-style environment used by u-boot-sunxi.
> >>> # This script therefore needs to check in which environment it
> >>> # is running and set some variables accordingly.
> >>>
> >>> # On u-boot-sunxi, this script assumes that ${device} and ${partition}
> >>> # are set.
> >>>
> >>> # The new-style environment predefines ${boot_targets}, the old-style
> >>> # environment does not.
> >>> if test -n "${boot_targets}"
> >>> then
> >>>echo "Mainline u-boot / new-style environment detected."
> >>># Mainline u-boot v2014.10 uses ${devtype}, ${devnum} and
> >>># ${bootpart} where u-boot-sunxi uses ${device} and ${partition}.
> >>># ${distro_bootpart} replaced ${bootpart} in u-boot v2016.01.
> >>>if test -z "${device}"; then setenv device "${devtype}"; fi
> >>>if test -z "${partition}${distro_bootpart}"; then setenv partition
> >>> "${devnum}:${bootpart}"; fi
> >>>if test -z "${partition}"; then setenv partition
> >>> "${devnum}:${distro_bootpart}"; fi
> >>> else
> >>>echo "U-boot-sunxi / old-style environment detected."
> >>># U-boot-sunxi does not predefine kernel_addr_r, fdt_addr_r and
> >>># ramdisk_addr_r, so they have to be manually set. Use the values
> >>># from mainline u-boot v2014.10, except for ramdisk_addr_r,
> >>># which is set to 0x4430 to allow for initrds larger than
> >>># 13MB on u-boot-sunxi.
> >>>setenv kernel_addr_r 0x4200
> >>>setenv fdt_addr_r 0x4300
> >>>setenv ramdisk_addr_r 0x4430
> >>> fi
> >>>
> >>> if test -n "${console}"; then
> >>>setenv bootargs "${bootargs} console=${console}"
> >>> fi
> >>>
> >>> setenv bootargs  ${bootargs} quiet
> >>>
> >>>
> >>> if test -z "${image_locations}"; then
> >>> setenv image_locations ${prefix}
> >>> fi
> >>> if test -z "${image_locations}"; then
> >>> setenv image_locations /boot/ /
> >>> fi
> >>>
> >>> if test -z "${fk_kvers}"; then
> >>> setenv fk_kvers '5.16.0-4-armmp-lpae'
> >>> fi
> >>>
> >>> if test -n "${fdtfile}"; then
> >>> setenv fdtpath dtbs/${fk_kvers}/${fdtfile}
> >>> else
> 

Re: [PATCH 2/2] doc: imx8mn_evk: Do not export ATF_LOAD_ADDR

2022-04-28 Thread Peng Fan (OSS)




On 2022/4/19 1:15, Fabio Estevam wrote:

From: Fabio Estevam 

The imx8mn_evk target have been converted to use binman.

With the binman approach the ATF load address is described via
devicetree, so remove the now unneeded instruction of exporting
ATF_LOAD_ADDR.

Signed-off-by: Fabio Estevam 


Reviewed-by: Peng Fan 


---
  doc/board/nxp/imx8mn_evk.rst | 1 -
  1 file changed, 1 deletion(-)

diff --git a/doc/board/nxp/imx8mn_evk.rst b/doc/board/nxp/imx8mn_evk.rst
index 711545af896a..c45bb7bac7a1 100644
--- a/doc/board/nxp/imx8mn_evk.rst
+++ b/doc/board/nxp/imx8mn_evk.rst
@@ -42,7 +42,6 @@ Build U-Boot
  
 $ export CROSS_COMPILE=aarch64-poky-linux-

 $ make imx8mn_ddr4_evk_defconfig
-   $ export ATF_LOAD_ADDR=0x96
 $ make
  
  Burn the flash.bin to MicroSD card offset 32KB:




Re: [PATCH 1/2] imx8mn_evk: Enable cache in SPL

2022-04-28 Thread Peng Fan (OSS)




On 2022/4/19 1:15, Fabio Estevam wrote:

From: Fabio Estevam 

There is no reason for disabling I-cache and D-cache
in SPL.

Remove the unneeded CONFIG_SPL_SYS_ICACHE_OFF and
CONFIG_SPL_SYS_DCACHE_OFF options.

Signed-off-by: Fabio Estevam 


Reviewed-by: Peng Fan 

---
  configs/imx8mn_evk_defconfig | 2 --
  1 file changed, 2 deletions(-)

diff --git a/configs/imx8mn_evk_defconfig b/configs/imx8mn_evk_defconfig
index b2981d1e3692..e661b3ba7e55 100644
--- a/configs/imx8mn_evk_defconfig
+++ b/configs/imx8mn_evk_defconfig
@@ -1,6 +1,4 @@
  CONFIG_ARM=y
-CONFIG_SPL_SYS_ICACHE_OFF=y
-CONFIG_SPL_SYS_DCACHE_OFF=y
  CONFIG_ARCH_IMX8M=y
  CONFIG_SYS_TEXT_BASE=0x4020
  CONFIG_SYS_MALLOC_LEN=0x200



Re: [PATCH] spl_imx_romapi: Remove extraneous character

2022-04-28 Thread Peng Fan (OSS)




On 2022/4/21 22:01, Fabio Estevam wrote:

From: Fabio Estevam 

Currently the following output is shown:
...
Trying to boot from BOOTROM
Find img info 0x&48020a00, size 872
...

Remove the extraneous "&" character, so that the correct output
can be seen.

Signed-off-by: Fabio Estevam 


Acked-by: Peng Fan 


---
  arch/arm/mach-imx/spl_imx_romapi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/spl_imx_romapi.c 
b/arch/arm/mach-imx/spl_imx_romapi.c
index c47f5a6bdb44..2996d2761690 100644
--- a/arch/arm/mach-imx/spl_imx_romapi.c
+++ b/arch/arm/mach-imx/spl_imx_romapi.c
@@ -306,7 +306,7 @@ static int spl_romapi_load_image_stream(struct 
spl_image_info *spl_image,
}
  
  	imagesize = img_info_size(phdr);

-   printf("Find img info 0x&%p, size %d\n", phdr, imagesize);
+   printf("Find img info 0x%p, size %d\n", phdr, imagesize);
  
  	if (p - phdr < imagesize) {

imagesize -= p - phdr;



[PATCH v5 17/17] doc:bootmenu: add UEFI boot and distro boot support description

2022-04-28 Thread Masahisa Kojima
The bootmenu enumerates the UEFI boot options and distro boot
(boot_targets) for boot device selection.

This commit adds the description how the UEFI boot and distro boot
work in bootmenu. This commit also adds "Synopsis", "Description"
and "Configuration" sections to follow the U-Boot command
documentation format.

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- follow the cmd documentation format same as other command, add "Synopsis",
  "Description" add "Configuration" sections

Newly created in v4

 doc/usage/cmd/bootmenu.rst | 78 +-
 1 file changed, 77 insertions(+), 1 deletion(-)

diff --git a/doc/usage/cmd/bootmenu.rst b/doc/usage/cmd/bootmenu.rst
index 1016ac8ceb..48f76a82a3 100644
--- a/doc/usage/cmd/bootmenu.rst
+++ b/doc/usage/cmd/bootmenu.rst
@@ -4,7 +4,17 @@
 bootmenu command
 
 
-The "bootmenu" command uses U-Boot menu interfaces and provides
+Synopsis
+
+
+::
+
+bootmenu
+
+Description
+---
+
+The *bootmenu* command uses U-Boot menu interfaces and provides
 a simple mechanism for creating menus with different boot items.
 The cursor keys "Up" and "Down" are used for navigation through
 the items. Current active menu item is highlighted and can be
@@ -79,6 +89,67 @@ The above example will be rendered as below::
 The selected menu entry will be highlighted - it will have inverted
 background and text colors.
 
+UEFI boot variable enumeration
+''
+
+The bootmenu automatically generates the UEFI boot variable("BOOT")
+in order of "BootOrder". When the user selects the UEFI boot
+variable entry, bootmenu sets the selected boot variable index
+to "BootNext", then call the uefi boot manager with the command
+"bootefi bootmgr".
+
+The bootmenu automatically enumerates the possible bootable
+media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.
+
+The bootmenu prints the EFI_LOAD_OPTION.Description[] as title
+of the entry together with "UEFI" prefix and BOOT variable name.
+
+Example bootmenu is as below::
+
+*** U-Boot Boot Menu ***
+
+   UEFI BOOT : mmc0:1
+   UEFI BOOT0001 : mmc0:2
+   UEFI BOOT0002 : debian
+   UEFI BOOT0003 : nvme0:1
+   UEFI BOOT0004 : ubuntu
+   UEFI BOOT0005 : nvme0:2
+   UEFI BOOT0006 : usb0:2
+
+To scan the discoverable devices connected to the buses such as
+USB and PCIe prior to bootmenu showing up, CONFIG_PREBOOT can be
+used to run the command before showing the bootmenu, i.e.::
+
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="pci enum; usb start; scsi scan; nvme scan; virtio scan"
+
+distro boot command enumeration
+'''
+
+The bootmenu also automatically generates the entries for
+distro boot command. The bootmenu shows the devices in boot_targets
+environment variable.
+When the user selects the distro boot command entry, the bootmenu
+runs the command defined in "bootcmd_xxx" environment variable.
+As an example, if user selects "usb0" entry, bootmenu runs the
+command defined in "bootcmd_usb0".
+
+Example boot_targets::
+
+usb0, scsi0, nvme0, dhcp
+
+Example bootmenu is as below::
+
+*** U-Boot Boot Menu ***
+
+   distro_boot   : usb0
+   distro_boot   : scsi0
+   distro_boot   : nvme0
+   distro_boot   : dhcp
+
+Configuration
+-
+
 The "bootmenu" cammand is enabled by::
 
 CONFIG_CMD_BOOTMENU=y
@@ -88,3 +159,8 @@ To run the bootmenu at startup add these additional 
settings::
 CONFIG_AUTOBOOT_KEYED=y
 CONFIG_BOOTDELAY=30
 CONFIG_AUTOBOOT_MENU_SHOW=y
+
+To improve the product security, entering U-Boot console from bootmenu
+can be disabled by::
+
+CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE=n
-- 
2.17.1



[PATCH v5 15/17] efi_loader: menu-driven update of UEFI bootorder variable

2022-04-28 Thread Masahisa Kojima
This commit adds the menu-driven update of UEFI bootorder
variable.

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- split into the separate patch

 lib/efi_loader/efi_bootmenu_maintenance.c | 102 ++
 1 file changed, 102 insertions(+)

diff --git a/lib/efi_loader/efi_bootmenu_maintenance.c 
b/lib/efi_loader/efi_bootmenu_maintenance.c
index 26320a8b73..8c3f94c695 100644
--- a/lib/efi_loader/efi_bootmenu_maintenance.c
+++ b/lib/efi_loader/efi_bootmenu_maintenance.c
@@ -719,6 +719,56 @@ static efi_status_t 
efi_bootmenu_boot_add_enter_name(struct efi_bootmenu_boot_op
return ret;
 }
 
+static efi_status_t allow_decimal(struct efi_input_key *key)
+{
+   if (u'0' <= key->unicode_char && key->unicode_char <= u'9')
+   return EFI_SUCCESS;
+
+   return EFI_INVALID_PARAMETER;
+}
+
+static efi_status_t efi_bootmenu_change_boot_order(int selected, int max, int 
*new)
+{
+   efi_status_t ret;
+   u16 new_order[EFI_BOOT_ORDER_MAX_SIZE_IN_DECIMAL] = {0};
+
+   printf(ANSI_CURSOR_POSITION, 2, 1);
+   puts("  *** U-Boot EFI Boot Manager Menu ***");
+   printf(ANSI_CURSOR_POSITION, 4, 1);
+   printf("  current boot order  : %d", selected);
+
+   printf(ANSI_CURSOR_POSITION, 6, 1);
+   printf("  new boot order(0 - %4d): ", max);
+
+   printf(ANSI_CURSOR_POSITION, 8, 1);
+   puts("  ENTER to complete, ESC/CTRL+C to quit");
+
+   printf(ANSI_CURSOR_POSITION, 6, 29);
+   puts(ANSI_CURSOR_SHOW);
+
+   for (;;) {
+   memset(new_order, 0, sizeof(new_order));
+   ret = efi_console_get_u16_string(cin, cout, new_order, 6, 
allow_decimal, 6, 29);
+   if (ret == EFI_SUCCESS) {
+   int i;
+   int val = 0;
+
+   for (i = 0;
+i < u16_strnlen(new_order, 
EFI_BOOT_ORDER_MAX_SIZE_IN_DECIMAL - 1);
+i++)
+   val = (val * 10) + (new_order[i] - u'0');
+
+   if (val > max)
+   continue;
+
+   *new = val;
+   return EFI_SUCCESS;
+   } else {
+   return ret;
+   }
+   }
+}
+
 static efi_status_t efi_bootmenu_select_file_handler(struct 
efi_bootmenu_boot_option *bo)
 {
efi_status_t ret;
@@ -958,6 +1008,57 @@ static efi_status_t 
efi_bootmenu_process_delete_boot_option(void *data, bool *ex
return ret;
 }
 
+static efi_status_t efi_bootmenu_process_change_boot_order(void *data, bool 
*exit)
+{
+   int selected;
+   int new_order;
+   efi_status_t ret;
+   efi_uintn_t num, size;
+   u16 *bootorder = NULL;
+   u16 *new_bootorder = NULL;
+
+   bootorder = efi_get_var(u"BootOrder", _global_variable_guid, );
+   if (!bootorder)
+   return EFI_NOT_FOUND;
+
+   num = size / sizeof(u16);
+   ret = efi_bootmenu_show_boot_selection(bootorder, num, );
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   ret = efi_bootmenu_change_boot_order(selected, num - 1, _order);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   new_bootorder = calloc(1, size);
+   if (!new_bootorder)
+   goto out;
+
+   memcpy(new_bootorder, bootorder, size);
+   if (selected > new_order) {
+   new_bootorder[new_order] = bootorder[selected];
+   memcpy(_bootorder[new_order + 1], [new_order],
+  (selected - new_order) * sizeof(u16));
+   } else if (selected < new_order) {
+   new_bootorder[new_order] = bootorder[selected];
+   memcpy(_bootorder[selected], [selected + 1],
+  (new_order - selected) * sizeof(u16));
+   } else {
+   /* nothing to change */
+   goto out;
+   }
+   ret = efi_set_variable_int(u"BootOrder", _global_variable_guid,
+  EFI_VARIABLE_NON_VOLATILE |
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS,
+  size, new_bootorder, false);
+out:
+   free(new_bootorder);
+   free(bootorder);
+
+   return ret;
+}
+
 static efi_status_t efi_bootmenu_init(void)
 {
efi_status_t ret;
@@ -987,6 +1088,7 @@ static efi_status_t efi_bootmenu_init(void)
 static const struct efi_bootmenu_item maintenance_menu_items[] = {
{u"Add Boot Option", efi_bootmenu_process_add_boot_option},
{u"Delete Boot Option", efi_bootmenu_process_delete_boot_option},
+   {u"Change Boot Order", efi_bootmenu_process_change_boot_order},
{u"Quit", NULL},
 };
 
-- 
2.17.1



[PATCH v5 16/17] bootmenu: add removable media entries

2022-04-28 Thread Masahisa Kojima
UEFI specification requires booting from removal media using
a architecture-specific default image name such as BOOTAA64.EFI.
This commit adds the removable media entries into bootmenu,
so that user can select the removable media and boot with
default image.

The bootmenu automatically enumerates the possible bootable
media devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL,
add it as new UEFI boot option(BOOT) and update BootOrder
variable. This automatically generated UEFI boot option
has the dedicated guid in the optional_data to distinguish it from
the UEFI boot option user adds manually.

This commit also provides the BOOT variable maintenance feature.
Depending on the system hardware setup, some devices
may not exist at a later system boot, so bootmenu checks the
available device in each bootmenu invocation and automatically
removes the BOOT variable corrensponding to the non-existent
media device.

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- Return EFI_SUCCESS if there is no BootOrder defined
- correctly handle the case if no removable device found
- use guid to identify the automatically generated entry by bootmenu

Newly created in v4

 cmd/bootmenu.c|  94 +++
 include/efi_loader.h  |  20 
 lib/efi_loader/efi_bootmenu_maintenance.c | 139 ++
 3 files changed, 253 insertions(+)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 860cb83182..970db3ee01 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -396,6 +396,89 @@ static int is_blk_device_available(char *token)
return -ENODEV;
 }
 
+/**
+ * prepare_media_device_entry() - generate the media device entries
+ *
+ * This function enumerates all devices supporting 
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
+ * and generate the bootmenu entries.
+ * This function also provide the BOOT variable maintenance for
+ * the media device entries.
+ *   - Automatically create the BOOT variable for the newly detected 
device,
+ * this BOOT variable is distinguished by the special GUID
+ * stored in the EFI_LOAD_OPTION.optional_data
+ *   - If the device is not attached to the system, the associated BOOT 
variable
+ * is automatically deleted.
+ *
+ * Return: status code
+ */
+static efi_status_t prepare_media_device_entry(void)
+{
+   u32 i;
+   efi_status_t ret;
+   efi_uintn_t count;
+   efi_handle_t *volume_handles = NULL;
+   struct efi_bootmenu_media_boot_option *opt = NULL;
+
+   ret = efi_locate_handle_buffer_int(BY_PROTOCOL, 
_simple_file_system_protocol_guid,
+  NULL, , (efi_handle_t 
**)_handles);
+   if (ret != EFI_SUCCESS)
+   return ret;
+
+   opt = calloc(count, sizeof(struct efi_bootmenu_media_boot_option));
+   if (!opt)
+   goto out;
+
+   /* enumerate all devices supporting EFI_SIMPLE_FILE_SYSTEM_PROTOCOL */
+   ret = efi_bootmenu_enumerate_boot_option(opt, volume_handles, count);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   /*
+* System hardware configuration may vary depending on the user setup.
+* The boot option is automatically added by the bootmenu.
+* If the device is not attached to the system, the boot option needs
+* to be deleted.
+*/
+   ret = efi_bootmenu_delete_invalid_boot_option(opt, count);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   /* add non-existent boot option */
+   for (i = 0; i < count; i++) {
+   u32 boot_index;
+   u16 var_name[9];
+
+   if (!opt[i].exist) {
+   ret = efi_bootmenu_get_unused_bootoption(var_name, 
sizeof(var_name),
+_index);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   ret = efi_set_variable_int(var_name, 
_global_variable_guid,
+  EFI_VARIABLE_NON_VOLATILE |
+  
EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS,
+  opt[i].size, opt[i].lo, 
false);
+   if (ret != EFI_SUCCESS)
+   goto out;
+
+   ret = efi_bootmenu_append_bootorder(boot_index);
+   if (ret != EFI_SUCCESS)
+   goto out;
+   }
+   }
+
+out:
+   if (opt) {
+   for (i = 0; i < count; i++)
+   free(opt[i].lo);
+   }
+   free(opt);
+   efi_free_pool(volume_handles);
+
+   return ret;
+}
+
 /**
  * prepare_distro_boot_entry() - generate the distro boot entries
  *
@@ -500,6 +583,7 @@ static int prepare_distro_boot_entry(struct 

[PATCH v5 13/17] efi_loader: menu-driven addition of UEFI boot option

2022-04-28 Thread Masahisa Kojima
This commit supports the menu-driven UEFI boot option addition.
User can select the block device volume having
efi_simple_file_system_protocol and select the file corresponding
to the Boot variable. Then user enter the label of the BOOT
variable in utf8.

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- remove forward declarations
- add const qualifier for menu items
- fix the possible unaligned access for directory info access
- split into three commit 1)add boot option 2) delete boot option 3)change boot 
order
  This commit is 1)add boot option.
- fix file name buffer allocation size, it should be EFI_BOOTMENU_FILE_PATH_MAX 
* sizeof(u16)
- fix wrong size checking for file selection

Chanes in v4:
- UEFI boot option maintenance menu is integrated into bootmenu
- display the simplified volume name(e.g. usb0:1, nvme1:2) for the
  volume selection
- instead of extending lib/efi_loader/efi_bootmgr.c, newly create
  lib/efi_loader/efi_bootmenu_maintenance.c and implement boot
  variable maintenance into it.

Changes in RFC v3:
 not included in v3 series

Changes in RFC v2:
- enable utf8 user input for boot option name
- create lib/efi_loader/efi_console.c::efi_console_get_u16_string() for
  utf8 user input handling
- use u16_strlcat instead of u16_strcat
- remove the EFI_CALLs, and newly create or expose the following
  xxx_int() functions.
efi_locate_handle_buffer_int(), efi_open_volume_int(),
efi_file_open_int(), efi_file_close_int(), efi_file_read_int() and
efi_file_setpos_int().
  Note that EFI_CALLs still exist for EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
  and EFI_SIMPLE_TEXT_INPUT/OUTPUT_PROTOCOL
- use efi_search_protocol() instead of calling locate_protocol() to get
  the device_path_to_text_protocol interface.
- remove unnecessary puts(ANSI_CLEAR_LINE), this patch is still depends on
  puts(ANSI_CLEAR_CONSOLE)
- skip SetVariable() if the bootorder is not changed

 cmd/bootmenu.c|  69 +-
 include/efi_loader.h  |  37 +
 lib/efi_loader/Makefile   |   1 +
 lib/efi_loader/efi_bootmenu_maintenance.c | 862 ++
 lib/efi_loader/efi_boottime.c |  52 +-
 lib/efi_loader/efi_console.c  |  81 ++
 lib/efi_loader/efi_disk.c |  11 +
 lib/efi_loader/efi_file.c |  75 +-
 8 files changed, 1133 insertions(+), 55 deletions(-)
 create mode 100644 lib/efi_loader/efi_bootmenu_maintenance.c

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index eb23afdd41..860cb83182 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -21,6 +21,8 @@
 
 /* maximum bootmenu entries */
 #define MAX_COUNT  99
+#define STATIC_ENTRY 2
+#define MAX_DYNAMIC_ENTRY (MAX_COUNT - STATIC_ENTRY)
 
 /* maximal size of bootmenu env
  *  9 = strlen("bootmenu_")
@@ -41,10 +43,11 @@ enum boot_type {
BOOTMENU_TYPE_BOOTMENU,
BOOTMENU_TYPE_UEFI_BOOT_OPTION,
BOOTMENU_TYPE_DISTRO_BOOT,
+   BOOTMENU_TYPE_UEFI_MAINTENANCE,
 };
 
 struct bootmenu_entry {
-   unsigned short int num; /* unique number 0 .. MAX_COUNT */
+   unsigned short int num; /* unique number 0 .. MAX_DYNAMIC_ENTRY 
*/
char key[3];/* key identifier of number */
u16 *title; /* title of entry */
char *command;  /* hush command of entry */
@@ -58,7 +61,7 @@ static char *bootmenu_getoption(unsigned short int n)
 {
char name[MAX_ENV_SIZE];
 
-   if (n > MAX_COUNT)
+   if (n > MAX_DYNAMIC_ENTRY)
return NULL;
 
sprintf(name, "bootmenu_%d", n);
@@ -229,7 +232,7 @@ static int prepare_bootmenu_entry(struct bootmenu_data 
*menu,
iter = entry;
++i;
 
-   if (i == MAX_COUNT - 1)
+   if (i == MAX_DYNAMIC_ENTRY)
break;
}
 
@@ -317,7 +320,7 @@ static int prepare_uefi_bootorder_entry(struct 
bootmenu_data *menu,
 
free(load_option);
 
-   if (i == MAX_COUNT - 1)
+   if (i == MAX_DYNAMIC_ENTRY)
break;
}
 
@@ -481,7 +484,7 @@ static int prepare_distro_boot_entry(struct bootmenu_data 
*menu,
iter = entry;
i++;
 
-   if (i == MAX_COUNT - 1)
+   if (i == MAX_DYNAMIC_ENTRY)
break;
 
token = strtok(NULL, " ");
@@ -520,19 +523,56 @@ static struct bootmenu_data *bootmenu_create(int delay)
goto cleanup;
 
if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) {
-   if (i < MAX_COUNT - 1) {
+   if (i < MAX_DYNAMIC_ENTRY) {
ret = prepare_uefi_bootorder_entry(menu, , );
if (ret < 0 && ret != -ENOENT)
goto cleanup;
}
}
 
-   if (i < MAX_COUNT - 1) {
+   if (i < MAX_DYNAMIC_ENTRY) {
ret = 

[PATCH v5 14/17] efi_loader: menu-driven deletion of UEFI boot variable

2022-04-28 Thread Masahisa Kojima
This commit adds the menu-driven deletion of UEFI boot variable.

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- split into the separate patch

 lib/efi_loader/efi_bootmenu_maintenance.c | 142 ++
 1 file changed, 142 insertions(+)

diff --git a/lib/efi_loader/efi_bootmenu_maintenance.c 
b/lib/efi_loader/efi_bootmenu_maintenance.c
index 77401a7829..26320a8b73 100644
--- a/lib/efi_loader/efi_bootmenu_maintenance.c
+++ b/lib/efi_loader/efi_bootmenu_maintenance.c
@@ -70,6 +70,12 @@ struct efi_bootmenu_item {
void *data;
 };
 
+struct efi_bootmenu_boot_selection_data {
+   u16 bootorder_index;
+   void *load_option;
+   int *selected;
+};
+
 struct efi_bootmenu_boot_option {
struct efi_simple_file_system_protocol *current_volume;
struct efi_device_path *dp_volume;
@@ -322,6 +328,89 @@ out:
return ret;
 }
 
+static efi_status_t efi_bootmenu_process_boot_selected(void *data, bool *exit)
+{
+   struct efi_bootmenu_boot_selection_data *info = data;
+
+   *exit = true;
+
+   if (info)
+   *info->selected = info->bootorder_index;
+
+   return EFI_SUCCESS;
+}
+
+static efi_status_t efi_bootmenu_show_boot_selection(u16 *bootorder, 
efi_uintn_t count,
+int *selected)
+{
+   u32 i;
+   efi_status_t ret;
+   efi_uintn_t size;
+   void *load_option;
+   struct efi_load_option lo;
+   u16 varname[] = u"Boot";
+   struct efi_bootmenu_item *menu_item, *iter;
+
+   menu_item = calloc(count + 1, sizeof(struct efi_bootmenu_item));
+   if (!menu_item) {
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
+
+   iter = menu_item;
+   for (i = 0; i < count; i++) {
+   efi_create_indexed_name(varname, sizeof(varname),
+   "Boot", bootorder[i]);
+   load_option = efi_get_var(varname, _global_variable_guid, 
);
+   if (!load_option)
+   continue;
+
+   ret = efi_deserialize_load_option(, load_option, );
+   if (ret != EFI_SUCCESS) {
+   log_warning("Invalid load option for %ls\n", varname);
+   free(load_option);
+   continue;
+   }
+
+   if (lo.attributes & LOAD_OPTION_ACTIVE) {
+   struct efi_bootmenu_boot_selection_data *info;
+
+   info = calloc(1, sizeof(struct 
efi_bootmenu_boot_selection_data));
+   if (!info) {
+   ret = EFI_OUT_OF_RESOURCES;
+   goto out;
+   }
+
+   info->bootorder_index = i;
+   info->load_option = load_option;
+   info->selected = selected;
+   iter->title = lo.label;
+   iter->func = efi_bootmenu_process_boot_selected;
+   iter->data = info;
+   iter++;
+   }
+   }
+
+   /* add "Quit" entry */
+   iter->title = u"Quit";
+   iter->func = NULL;
+   iter->data = NULL;
+   count += 1;
+
+   ret = efi_bootmenu_process_common(menu_item, count, -1);
+
+out:
+   iter = menu_item;
+   for (i = 0; i < count - 1; i++, iter++) {
+   free(((struct efi_bootmenu_boot_selection_data 
*)iter->data)->load_option);
+   free(iter->data);
+   }
+
+   free(menu_item);
+
+   return ret;
+}
+
 static efi_status_t efi_bootmenu_volume_selected(void *data, bool *exit)
 {
struct efi_bootmenu_volume_entry_data *info = data;
@@ -817,6 +906,58 @@ out:
return ret;
 }
 
+static efi_status_t delete_boot_option(u16 *bootorder, u16 index, efi_uintn_t 
size)
+{
+   u16 var_name[9];
+   efi_status_t ret;
+   efi_uintn_t num;
+
+   efi_create_indexed_name(var_name, sizeof(var_name),
+   "Boot", bootorder[index]);
+   ret = efi_set_variable_int(var_name, _global_variable_guid,
+  0, 0, NULL, false);
+   if (ret != EFI_SUCCESS) {
+   log_err("delete boot option(%ls) failed\n", var_name);
+   return ret;
+   }
+
+   /* update BootOrder */
+   num = size / sizeof(u16);
+   memmove([index], [index + 1],
+   (num - index - 1) * sizeof(u16));
+   size -= sizeof(u16);
+   ret = efi_set_variable_int(u"BootOrder", _global_variable_guid,
+  EFI_VARIABLE_NON_VOLATILE |
+  EFI_VARIABLE_BOOTSERVICE_ACCESS |
+  EFI_VARIABLE_RUNTIME_ACCESS,
+  size, bootorder, false);
+
+   return ret;
+}
+
+static efi_status_t efi_bootmenu_process_delete_boot_option(void *data, bool 
*exit)
+{
+   int selected;
+  

[PATCH v5 12/17] bootmenu: factor out the user input handling

2022-04-28 Thread Masahisa Kojima
This commit moves the user input handling from cmd/bootmenu.c
to common/menu.c to reuse it from other modules.

Signed-off-by: Masahisa Kojima 
---
No change since v4

Newly created in v4.

 cmd/bootmenu.c | 149 -
 common/menu.c  | 137 +
 include/menu.h |  20 +++
 3 files changed, 157 insertions(+), 149 deletions(-)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index bfbb1b5248..eb23afdd41 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -54,21 +54,6 @@ struct bootmenu_entry {
struct bootmenu_entry *next;/* next menu entry (num+1) */
 };
 
-struct bootmenu_data {
-   int delay;  /* delay for autoboot */
-   int active; /* active menu entry */
-   int count;  /* total count of menu entries */
-   struct bootmenu_entry *first;   /* first menu entry */
-};
-
-enum bootmenu_key {
-   KEY_NONE = 0,
-   KEY_UP,
-   KEY_DOWN,
-   KEY_SELECT,
-   KEY_QUIT,
-};
-
 static char *bootmenu_getoption(unsigned short int n)
 {
char name[MAX_ENV_SIZE];
@@ -109,140 +94,6 @@ static void bootmenu_print_entry(void *data)
puts(ANSI_COLOR_RESET);
 }
 
-static void bootmenu_autoboot_loop(struct bootmenu_data *menu,
-   enum bootmenu_key *key, int *esc)
-{
-   int i, c;
-
-   if (menu->delay > 0) {
-   /* flush input */
-   while (tstc())
-   getchar();
-
-   printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
-   printf("  Hit any key to stop autoboot: %2d ", menu->delay);
-   }
-
-   while (menu->delay > 0) {
-   for (i = 0; i < 100; ++i) {
-   if (!tstc()) {
-   WATCHDOG_RESET();
-   mdelay(10);
-   continue;
-   }
-
-   menu->delay = -1;
-   c = getchar();
-
-   switch (c) {
-   case '\e':
-   *esc = 1;
-   *key = KEY_NONE;
-   break;
-   case '\r':
-   *key = KEY_SELECT;
-   break;
-   case 0x3: /* ^C */
-   *key = KEY_QUIT;
-   break;
-   default:
-   *key = KEY_NONE;
-   break;
-   }
-
-   break;
-   }
-
-   if (menu->delay < 0)
-   break;
-
-   --menu->delay;
-   printf("\b\b\b%2d ", menu->delay);
-   }
-
-   printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
-   puts(ANSI_CLEAR_LINE);
-
-   if (menu->delay == 0)
-   *key = KEY_SELECT;
-}
-
-static void bootmenu_loop(struct bootmenu_data *menu,
-   enum bootmenu_key *key, int *esc)
-{
-   int c;
-
-   if (*esc == 1) {
-   if (tstc()) {
-   c = getchar();
-   } else {
-   WATCHDOG_RESET();
-   mdelay(10);
-   if (tstc())
-   c = getchar();
-   else
-   c = '\e';
-   }
-   } else {
-   while (!tstc()) {
-   WATCHDOG_RESET();
-   mdelay(10);
-   }
-   c = getchar();
-   }
-
-   switch (*esc) {
-   case 0:
-   /* First char of ANSI escape sequence '\e' */
-   if (c == '\e') {
-   *esc = 1;
-   *key = KEY_NONE;
-   }
-   break;
-   case 1:
-   /* Second char of ANSI '[' */
-   if (c == '[') {
-   *esc = 2;
-   *key = KEY_NONE;
-   } else {
-   /* Alone ESC key was pressed */
-   *key = KEY_QUIT;
-   *esc = (c == '\e') ? 1 : 0;
-   }
-   break;
-   case 2:
-   case 3:
-   /* Third char of ANSI (number '1') - optional */
-   if (*esc == 2 && c == '1') {
-   *esc = 3;
-   *key = KEY_NONE;
-   break;
-   }
-
-   *esc = 0;
-
-   /* ANSI 'A' - key up was pressed */
-   if (c == 'A')
-   *key = KEY_UP;
-   /* ANSI 'B' - key down was pressed */
-   else if (c == 'B')
-   *key = KEY_DOWN;
-   /* other key was pressed */
-   else
-   

[PATCH v5 09/17] bootmenu: add UEFI boot entry into bootmenu

2022-04-28 Thread Masahisa Kojima
This commit adds the UEFI related menu entries
into the bootmenu.

User can select which UEFI "Boot" option to execute
from bootmenu, then bootmenu sets the "BootNext" UEFI
variable and invoke efi bootmgr. The efi bootmgr
will handle the "BootNext" UEFI variable.

If the "BootNext" UEFI variable is preset and efi bootmgr is enabled,
bootmenu invokes efi bootmgr to handle "BootNext" as first priority.

The UEFI boot entry has the "UEFI BOOT" prefix as below.

  *** U-Boot Boot Menu ***

 UEFI BOOT : debian
 UEFI BOOT0001 : ubuntu

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- split into the separate patch
- add function description comment
- remove non-volatile attribute for BootNext variable to minimize
  the access to the non-volatile storage

 cmd/bootmenu.c | 155 -
 1 file changed, 154 insertions(+), 1 deletion(-)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 15ad621c9f..da688e6213 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -7,6 +7,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -28,6 +30,7 @@
 enum boot_type {
BOOTMENU_TYPE_NONE = 0,
BOOTMENU_TYPE_BOOTMENU,
+   BOOTMENU_TYPE_UEFI_BOOT_OPTION,
 };
 
 struct bootmenu_entry {
@@ -85,6 +88,8 @@ static void bootmenu_print_entry(void *data)
 
if (entry->type == BOOTMENU_TYPE_BOOTMENU)
printf("bootmenu_%02d   : %ls", entry->bootorder, entry->title);
+   else if (entry->type == BOOTMENU_TYPE_UEFI_BOOT_OPTION)
+   printf("UEFI BOOT%04X : %ls", entry->bootorder, entry->title);
else
printf("%ls", entry->title);
 
@@ -371,6 +376,95 @@ static int prepare_bootmenu_entry(struct bootmenu_data 
*menu,
return 1;
 }
 
+/**
+ * prepare_uefi_bootorder_entry() - generate the uefi bootmenu entries
+ *
+ * This function read the "BootOrder" UEFI variable
+ * and generate the bootmenu entries in the order of "BootOrder".
+ *
+ * @menu:  pointer to the bootmenu structure
+ * @current:   pointer to the last bootmenu entry list
+ * @index: pointer to the index of the last bootmenu entry,
+ * the number of uefi entry is added by this function
+ * Return: 1 on success, negative value on error
+ */
+static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu,
+   struct bootmenu_entry **current,
+   unsigned short int *index)
+{
+   u16 *bootorder;
+   efi_status_t ret;
+   unsigned short j;
+   efi_uintn_t num, size;
+   void *load_option;
+   struct efi_load_option lo;
+   u16 varname[] = u"Boot";
+   unsigned short int i = *index;
+   struct bootmenu_entry *entry = NULL;
+   struct bootmenu_entry *iter = *current;
+
+   bootorder = efi_get_var(u"BootOrder", _global_variable_guid, );
+   if (!bootorder)
+   return -ENOENT;
+
+   num = size / sizeof(u16);
+   for (j = 0; j < num; j++) {
+   entry = malloc(sizeof(struct bootmenu_entry));
+   if (!entry)
+   return -ENOMEM;
+
+   efi_create_indexed_name(varname, sizeof(varname),
+   "Boot", bootorder[j]);
+   load_option = efi_get_var(varname, _global_variable_guid, 
);
+   if (!load_option)
+   continue;
+
+   ret = efi_deserialize_load_option(, load_option, );
+   if (ret != EFI_SUCCESS) {
+   log_warning("Invalid load option for %ls\n", varname);
+   free(load_option);
+   free(entry);
+   continue;
+   }
+
+   if (lo.attributes & LOAD_OPTION_ACTIVE) {
+   entry->title = u16_strdup(lo.label);
+   if (!entry->title) {
+   free(load_option);
+   free(entry);
+   free(bootorder);
+   return -ENOMEM;
+   }
+   entry->command = strdup("bootefi bootmgr");
+   sprintf(entry->key, "%d", i);
+   entry->num = i;
+   entry->menu = menu;
+   entry->type = BOOTMENU_TYPE_UEFI_BOOT_OPTION;
+   entry->bootorder = bootorder[j];
+   entry->next = NULL;
+
+   if (!iter)
+   menu->first = entry;
+   else
+   iter->next = entry;
+
+   iter = entry;
+   i++;
+   }
+
+   free(load_option);
+
+   if (i == MAX_COUNT - 1)
+   break;
+   }
+
+   free(bootorder);
+   *index = i;
+   *current 

[PATCH v5 11/17] bootmenu: add Kconfig option not to enter U-Boot console

2022-04-28 Thread Masahisa Kojima
This commit adds the Kconfig option to disable to enter
the U-Boot console from bootmenu.

If CMD_BOOTMENU_ENTER_UBOOT_CONSOLE is enabled, "U-Boot console"
entry is appeared as the last entry in the bootmenu, then user can
enter U-Boot console.

If CMD_BOOTMENU_ENTER_UBOOT_CONSOLE is disabled, "Quit" entry
is appeared as the last entry instead of "U-Boot console".
When user chooses "Quit" from bootmenu, the following default
commands are invoked.

 - "bootefi bootmgr" (if efi bootmgr is enabled)
 - "run bootcmd"

If the both commands are executed and returns to the bootmenu,
the bootmenu will appears again.

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- split into the separate patch
- clear the console when user select "U-Boot console"
- if the console is disabled, the last entry title is "Quit"

 cmd/Kconfig| 10 
 cmd/bootmenu.c | 69 ++
 2 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2b575a2b42..99a1435467 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -356,6 +356,16 @@ config CMD_BOOTMENU
help
  Add an ANSI terminal boot menu command.
 
+config CMD_BOOTMENU_ENTER_UBOOT_CONSOLE
+   bool "Allow Bootmenu to enter the U-Boot console"
+   depends on CMD_BOOTMENU
+   default n
+   help
+ Add an entry to enter U-Boot console in bootmenu.
+ If this option is disabled, user can not enter
+ the U-Boot console from bootmenu. It increases
+ the system security.
+
 config CMD_ADTIMG
bool "adtimg"
help
diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index afe42b8041..bfbb1b5248 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -29,6 +29,13 @@
  */
 #define MAX_ENV_SIZE   (9 + 2 + 1)
 
+enum bootmenu_ret {
+   BOOTMENU_RET_SUCCESS = 0,
+   BOOTMENU_RET_FAIL,
+   BOOTMENU_RET_QUIT,
+   BOOTMENU_RET_UPDATED,
+};
+
 enum boot_type {
BOOTMENU_TYPE_NONE = 0,
BOOTMENU_TYPE_BOOTMENU,
@@ -681,7 +688,12 @@ static struct bootmenu_data *bootmenu_create(int delay)
if (!entry)
goto cleanup;
 
-   entry->title = u16_strdup(u"U-Boot console");
+   /* Add Quit entry if entering U-Boot console is disabled */
+   if (IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE))
+   entry->title = u16_strdup(u"U-Boot console");
+   else
+   entry->title = u16_strdup(u"Quit");
+
if (!entry->title) {
free(entry);
goto cleanup;
@@ -777,15 +789,17 @@ static void handle_uefi_bootnext(void)
run_command("bootefi bootmgr", 0);
 }
 
-static void bootmenu_show(int delay)
+static enum bootmenu_ret bootmenu_show(int delay)
 {
+   int cmd_ret;
int init = 0;
void *choice = NULL;
u16 *title = NULL;
char *command = NULL;
struct menu *menu;
-   struct bootmenu_data *bootmenu;
struct bootmenu_entry *iter;
+   int ret = BOOTMENU_RET_SUCCESS;
+   struct bootmenu_data *bootmenu;
efi_status_t efi_ret = EFI_SUCCESS;
char *option, *sep;
 
@@ -797,27 +811,27 @@ static void bootmenu_show(int delay)
option = bootmenu_getoption(0);
if (!option) {
puts("bootmenu option 0 was not found\n");
-   return;
+   return BOOTMENU_RET_FAIL;
}
sep = strchr(option, '=');
if (!sep) {
puts("bootmenu option 0 is invalid\n");
-   return;
+   return BOOTMENU_RET_FAIL;
}
-   run_command(sep+1, 0);
-   return;
+   cmd_ret = run_command(sep + 1, 0);
+   return (cmd_ret == CMD_RET_SUCCESS ? BOOTMENU_RET_SUCCESS : 
BOOTMENU_RET_FAIL);
}
 
bootmenu = bootmenu_create(delay);
if (!bootmenu)
-   return;
+   return BOOTMENU_RET_FAIL;
 
menu = menu_create(NULL, bootmenu->delay, 1, menu_display_statusline,
   bootmenu_print_entry, bootmenu_choice_entry,
   bootmenu);
if (!menu) {
bootmenu_destroy(bootmenu);
-   return;
+   return BOOTMENU_RET_FAIL;
}
 
for (iter = bootmenu->first; iter; iter = iter->next) {
@@ -838,6 +852,14 @@ static void bootmenu_show(int delay)
iter = choice;
title = u16_strdup(iter->title);
command = strdup(iter->command);
+
+   /* last entry is U-Boot console or Quit */
+   if (iter->num == iter->menu->count - 1) {
+   ret = BOOTMENU_RET_QUIT;
+   goto cleanup;
+   }
+   } else {
+   goto cleanup;
}

[PATCH v5 10/17] bootmenu: add distro boot entry

2022-04-28 Thread Masahisa Kojima
This commit adds the distro_boot entries into the bootmenu.
The bootmenu read the "boot_targets" U-Boot environment variable
and enumerate it.
User can select the distro boot entry, then bootmenu executes
"run bootcmd_xxx" command.

The bootmenu also checks the existing block devices and network
option("dhcp" and "pxe") availability, then filter out
the "boot_targets" appeared in bootmenu.

The bootmenu example is as follows, distro boot entry has the
"distro_boot" prefix.

  *** U-Boot Boot Menu ***

 distro_boot   : usb0
 distro_boot   : scsi0
 distro_boot   : virtio0
 distro_boot   : dhcp

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- split into the separate patch
- add function description comment
- handle the case boot_targets variable is empty
- filter out the non-exist device entry

 cmd/bootmenu.c | 177 +
 1 file changed, 177 insertions(+)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index da688e6213..afe42b8041 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -14,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -31,6 +33,7 @@ enum boot_type {
BOOTMENU_TYPE_NONE = 0,
BOOTMENU_TYPE_BOOTMENU,
BOOTMENU_TYPE_UEFI_BOOT_OPTION,
+   BOOTMENU_TYPE_DISTRO_BOOT,
 };
 
 struct bootmenu_entry {
@@ -90,6 +93,8 @@ static void bootmenu_print_entry(void *data)
printf("bootmenu_%02d   : %ls", entry->bootorder, entry->title);
else if (entry->type == BOOTMENU_TYPE_UEFI_BOOT_OPTION)
printf("UEFI BOOT%04X : %ls", entry->bootorder, entry->title);
+   else if (entry->type == BOOTMENU_TYPE_DISTRO_BOOT)
+   printf("distro_boot   : %ls", entry->title);
else
printf("%ls", entry->title);
 
@@ -465,6 +470,172 @@ static int prepare_uefi_bootorder_entry(struct 
bootmenu_data *menu,
return 1;
 }
 
+static int is_blk_device_available(char *token)
+{
+   struct driver *d = ll_entry_start(struct driver, driver);
+   const int n_ents = ll_entry_count(struct driver, driver);
+   struct driver *entry;
+   struct udevice *udev;
+   struct uclass *uc;
+   struct blk_desc *desc;
+   int ret, i;
+   const char *if_type_name;
+
+   ret = uclass_get(UCLASS_BLK, );
+   if (ret)
+   return -ENODEV;
+
+   for (entry = d; entry < d + n_ents; entry++) {
+   if (entry->id != UCLASS_BLK)
+   continue;
+   i = 0;
+   uclass_foreach_dev(udev, uc) {
+   if (udev->driver != entry)
+   continue;
+   desc = dev_get_uclass_plat(udev);
+   if_type_name = blk_get_if_type_name(desc->if_type);
+   if (strncmp(token, if_type_name, strlen(if_type_name)) 
== 0) {
+   char *p;
+   int j, len;
+   int devnum = 0;
+
+   p = token + strlen(if_type_name);
+   len = strlen(p);
+   if (!len)
+   continue; /* no device number */
+
+   for (j = 0; j < len; j++) {
+   if (!isdigit(*p)) {
+   /* invalid device number */
+   devnum = INT_MAX;
+   break;
+   }
+   devnum = (devnum * 10) + (*p++ - '0');
+   }
+
+   if (devnum == INT_MAX)
+   continue;
+
+   if (devnum == desc->devnum)
+   return 1;
+   }
+   }
+   }
+
+   if (strncmp(token, "dhcp", strlen("dhcp")) == 0) {
+   if (IS_ENABLED(CONFIG_CMD_DHCP))
+   return 1;
+   }
+
+   if (strncmp(token, "pxe", strlen("pxe")) == 0) {
+   if (IS_ENABLED(CONFIG_CMD_PXE))
+   return 1;
+   }
+
+   return -ENODEV;
+}
+
+/**
+ * prepare_distro_boot_entry() - generate the distro boot entries
+ *
+ * This function read the "boot_targets" U-Boot environment variable
+ * and generate the bootmenu entries.
+ *
+ * @menu:  pointer to the bootmenu structure
+ * @current:   pointer to the last bootmenu entry list
+ * @index: pointer to the index of the last bootmenu entry,
+ * the number of uefi entry is added by this function
+ * Return: 1 on success, negative value on error
+ */
+static int prepare_distro_boot_entry(struct bootmenu_data *menu,
+  

[PATCH v5 08/17] bootmenu: update bootmenu_entry structure

2022-04-28 Thread Masahisa Kojima
This is a preparation for succeeding addition of uefi boot
and distro boot menu entries into bootmenu.
The bootmenu_entry title is updated to u16 string because
uefi use u16 string. This commit also factors out the function
to prepare the entries generated by "bootmenu_x" U-Boot environment
variable.

This commit also updates the bootmenu entry title.
The entry derived from "bootmenu_x" U-Boot environment variable
has the "bootmenu_xx" prefix as below.

  *** U-Boot Boot Menu ***

 bootmenu_00   : Boot 1. kernel
 bootmenu_01   : Boot 2. kernel
 bootmenu_02   : Reset board

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- split into the separate patch
- add function description comment

 cmd/bootmenu.c | 110 +++--
 1 file changed, 78 insertions(+), 32 deletions(-)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 9a32a18b19..15ad621c9f 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -3,6 +3,7 @@
  * (C) Copyright 2011-2013 Pali Rohár 
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -24,11 +25,18 @@
  */
 #define MAX_ENV_SIZE   (9 + 2 + 1)
 
+enum boot_type {
+   BOOTMENU_TYPE_NONE = 0,
+   BOOTMENU_TYPE_BOOTMENU,
+};
+
 struct bootmenu_entry {
unsigned short int num; /* unique number 0 .. MAX_COUNT */
char key[3];/* key identifier of number */
-   char *title;/* title of entry */
+   u16 *title; /* title of entry */
char *command;  /* hush command of entry */
+   enum boot_type type;/* boot type of entry */
+   u16 bootorder;  /* order for each boot type */
struct bootmenu_data *menu; /* this bootmenu */
struct bootmenu_entry *next;/* next menu entry (num+1) */
 };
@@ -75,7 +83,10 @@ static void bootmenu_print_entry(void *data)
if (reverse)
puts(ANSI_COLOR_REVERSE);
 
-   puts(entry->title);
+   if (entry->type == BOOTMENU_TYPE_BOOTMENU)
+   printf("bootmenu_%02d   : %ls", entry->bootorder, entry->title);
+   else
+   printf("%ls", entry->title);
 
if (reverse)
puts(ANSI_COLOR_RESET);
@@ -279,31 +290,32 @@ static void bootmenu_destroy(struct bootmenu_data *menu)
free(menu);
 }
 
-static struct bootmenu_data *bootmenu_create(int delay)
+/**
+ * prepare_bootmenu_entry() - generate the bootmenu_xx entries
+ *
+ * This function read the "bootmenu_x" U-Boot environment variable
+ * and generate the bootmenu entries.
+ *
+ * @menu:  pointer to the bootmenu structure
+ * @current:   pointer to the last bootmenu entry list
+ * @index: pointer to the index of the last bootmenu entry,
+ * the number of bootmenu entry is added by this function
+ * Return: 1 on success, negative value on error
+ */
+static int prepare_bootmenu_entry(struct bootmenu_data *menu,
+ struct bootmenu_entry **current,
+ unsigned short int *index)
 {
-   unsigned short int i = 0;
-   const char *option;
-   struct bootmenu_data *menu;
-   struct bootmenu_entry *iter = NULL;
-
int len;
char *sep;
-   char *default_str;
-   struct bootmenu_entry *entry;
-
-   menu = malloc(sizeof(struct bootmenu_data));
-   if (!menu)
-   return NULL;
-
-   menu->delay = delay;
-   menu->active = 0;
-   menu->first = NULL;
-
-   default_str = env_get("bootmenu_default");
-   if (default_str)
-   menu->active = (int)simple_strtol(default_str, NULL, 10);
+   const char *option;
+   unsigned short int i = *index;
+   struct bootmenu_entry *entry = NULL;
+   struct bootmenu_entry *iter = *current;
 
while ((option = bootmenu_getoption(i))) {
+   u16 *buf;
+
sep = strchr(option, '=');
if (!sep) {
printf("Invalid bootmenu entry: %s\n", option);
@@ -312,23 +324,23 @@ static struct bootmenu_data *bootmenu_create(int delay)
 
entry = malloc(sizeof(struct bootmenu_entry));
if (!entry)
-   goto cleanup;
+   return -ENOMEM;
 
len = sep-option;
-   entry->title = malloc(len + 1);
+   buf = calloc(1, (len + 1) * sizeof(u16));
+   entry->title = buf;
if (!entry->title) {
free(entry);
-   goto cleanup;
+   return -ENOMEM;
}
-   memcpy(entry->title, option, len);
-   entry->title[len] = 0;
+   utf8_utf16_strncpy(, option, len);
 
len = strlen(sep + 1);
entry->command = malloc(len + 1);
if (!entry->command) {
free(entry->title);
 

[PATCH v5 07/17] bootmenu: flush input buffer before waiting user key input

2022-04-28 Thread Masahisa Kojima
Before waiting user key input to stop autoboot, the input buffer
must be flushed.

Signed-off-by: Masahisa Kojima 
---
Change in v5:
- newly created, split into separate patch

 cmd/bootmenu.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index d573487272..9a32a18b19 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -87,6 +87,10 @@ static void bootmenu_autoboot_loop(struct bootmenu_data 
*menu,
int i, c;
 
if (menu->delay > 0) {
+   /* flush input */
+   while (tstc())
+   getchar();
+
printf(ANSI_CURSOR_POSITION, menu->count + 5, 1);
printf("  Hit any key to stop autoboot: %2d ", menu->delay);
}
-- 
2.17.1



[PATCH v5 06/17] efi_loader: bootmgr: add booting from removable media

2022-04-28 Thread Masahisa Kojima
From: AKASHI Takahiro 

Under the current implementation, booting from removable media using
a architecture-specific default image name, say BOOTAA64.EFI, is
supported only in distro_bootcmd script. See the commit 74522c898b35
("efi_loader: Add distro boot script for removable media").

This is, however, half-baked implementation because
1) UEFI specification requires this feature to be implemented as part
   of Boot Manager's responsibility:

  3 - Boot Manager
  3.5.1 Boot via the Simple File Protocol
  When booting via the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, the FilePath will
  start with a device path that points to the device that implements the
  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL or the EFI_BLOCK_IO_PROTOCOL. The next
  part of the FilePath may point to the file name, including
  subdirectories, which contain the bootable image. If the file name is
  a null device path, the file name must be generated from the rules
  defined below.
  ...
  3.5.1.1 Removable Media Boot Behavior
  To generate a file name when none is present in the FilePath, the
  firmware must append a default file name in the form
  \EFI\BOOT\BOOT{machine type short-name}.EFI ...

2) So (1) entails the hehavior that the user's preference of boot media
   order should be determined by Boot and BootOrder variables.

With this patch, the semantics mentioned above is fully implemented.
For example, if you want to boot the system from USB and SCSI in this
order,
* define Boot0001 which contains only a device path to the USB device
  (without any file path/name)
* define Boot0002 which contains only a device path to the SCSI device,
and
* set BootOrder to Boot0001:Boot0002

To avoid build error for sandbox, default file name "BOOTSANDBOX.efi"
is defined even if it is out of scope of UEFI specification.

Signed-off-by: AKASHI Takahiro 
Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- add default file name definition for SANDBOX to avoid build error

Changes from original version:
- create new include file "efi_default_filename.h" to
  avoid conflict with config_distro_bootcmd.h
- modify the target pointer of efi_free_pool(), expand_media_path() should
  only free the pointer allocated by efi_dp_from_file() function.
 include/config_distro_bootcmd.h | 14 +
 include/efi_default_filename.h  | 33 ++
 lib/efi_loader/efi_bootmgr.c| 50 -
 3 files changed, 83 insertions(+), 14 deletions(-)
 create mode 100644 include/efi_default_filename.h

diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
index c55023889c..6a3110f27b 100644
--- a/include/config_distro_bootcmd.h
+++ b/include/config_distro_bootcmd.h
@@ -91,19 +91,7 @@
 #endif
 
 #ifdef CONFIG_EFI_LOADER
-#if defined(CONFIG_ARM64)
-#define BOOTEFI_NAME "bootaa64.efi"
-#elif defined(CONFIG_ARM)
-#define BOOTEFI_NAME "bootarm.efi"
-#elif defined(CONFIG_X86_RUN_32BIT)
-#define BOOTEFI_NAME "bootia32.efi"
-#elif defined(CONFIG_X86_RUN_64BIT)
-#define BOOTEFI_NAME "bootx64.efi"
-#elif defined(CONFIG_ARCH_RV32I)
-#define BOOTEFI_NAME "bootriscv32.efi"
-#elif defined(CONFIG_ARCH_RV64I)
-#define BOOTEFI_NAME "bootriscv64.efi"
-#endif
+#include 
 #endif
 
 #ifdef BOOTEFI_NAME
diff --git a/include/efi_default_filename.h b/include/efi_default_filename.h
new file mode 100644
index 00..cb2ef9e131
--- /dev/null
+++ b/include/efi_default_filename.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Default boot file name when none is present in the FilePath.
+ * This is defined in the UEFI specification.
+ *
+ * Copyright (c) 2022, Linaro Limited
+ */
+#ifndef _EFI_DEFAULT_FILENAME_H
+#define _EFI_DEFAULT_FILENAME_H
+
+#if defined(CONFIG_ARM64)
+#define BOOTEFI_NAME "BOOTAA64.EFI"
+#elif defined(CONFIG_ARM)
+#define BOOTEFI_NAME "BOOTARM.EFI"
+#elif defined(CONFIG_X86_64)
+#define BOOTEFI_NAME "BOOTX64.EFI"
+#elif defined(CONFIG_X86)
+#define BOOTEFI_NAME "BOOTIA32.EFI"
+#elif defined(CONFIG_ARCH_RV32I)
+#define BOOTEFI_NAME "BOOTRISCV32.EFI"
+#elif defined(CONFIG_ARCH_RV64I)
+#define BOOTEFI_NAME "BOOTRISCV64.EFI"
+#elif defined(CONFIG_SANDBOX)
+/*
+ * SANDBOX is not defined in UEFI specification, but
+ * this definition avoids build failure for SANDBOX.
+ */
+#define BOOTEFI_NAME "BOOTSANDBOX.EFI"
+#else
+#error Unsupported UEFI architecture
+#endif
+
+#endif
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 8c04ecbdc8..22a4302aac 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -30,6 +31,50 @@ static const struct efi_runtime_services *rs;
  * should do normal or recovery boot.
  */
 
+/**
+ * expand_media_path() - expand a device path for default file name
+ * @device_path:   device path to check against
+ *
+ * If @device_path is a media or disk partition which houses a file
+ * system, this function returns a full device path which 

[PATCH v5 05/17] efi_loader: export efi_locate_device_handle()

2022-04-28 Thread Masahisa Kojima
From: AKASHI Takahiro 

This function will be used in the next commit where some behavior
of EFI boot manager will be expanded.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Ilias Apalodimas 
---
No changes from original version

 include/efi_loader.h  | 4 
 lib/efi_loader/efi_boottime.c | 7 +++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index ba79a9afb4..effb43369d 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -595,6 +595,10 @@ efi_status_t efi_create_handle(efi_handle_t *handle);
 void efi_delete_handle(efi_handle_t obj);
 /* Call this to validate a handle and find the EFI object for it */
 struct efi_object *efi_search_obj(const efi_handle_t handle);
+/* Locate device_path handle */
+efi_status_t EFIAPI efi_locate_device_path(const efi_guid_t *protocol,
+  struct efi_device_path **device_path,
+  efi_handle_t *device);
 /* Load image */
 efi_status_t EFIAPI efi_load_image(bool boot_policy,
   efi_handle_t parent_image,
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 5bcb8253ed..4da64b5d29 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -1799,10 +1799,9 @@ failure:
  *
  * Return: status code
  */
-static efi_status_t EFIAPI efi_locate_device_path(
-   const efi_guid_t *protocol,
-   struct efi_device_path **device_path,
-   efi_handle_t *device)
+efi_status_t EFIAPI efi_locate_device_path(const efi_guid_t *protocol,
+  struct efi_device_path **device_path,
+  efi_handle_t *device)
 {
struct efi_device_path *dp;
size_t i;
-- 
2.17.1



[PATCH v5 03/17] menu: always show the menu regardless of the number of entry

2022-04-28 Thread Masahisa Kojima
To make user aware of the menu entry selection, menu always
appears regardless of the number of entry.

Signed-off-by: Masahisa Kojima 
---
No changes since v4

Newly created in v4

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

diff --git a/common/menu.c b/common/menu.c
index 5fb2ffbd06..b577d80b4f 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -271,7 +271,7 @@ int menu_get_choice(struct menu *m, void **choice)
if (!m || !choice)
return -EINVAL;
 
-   if (!m->prompt || m->item_cnt == 1)
+   if (!m->prompt)
return menu_default_choice(m, choice);
 
return menu_interactive_choice(m, choice);
-- 
2.17.1



[PATCH v5 04/17] menu: menu_get_choice() return -ENOENT if menu item is empty

2022-04-28 Thread Masahisa Kojima
menu_get_choice() needs to handle the case that menu item
is empty. In this case, menu_get_choice() returns -ENOENT.

Signed-off-by: Masahisa Kojima 
---
Newly created in v5

 common/menu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/menu.c b/common/menu.c
index b577d80b4f..4118c6dc3c 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -271,6 +271,9 @@ int menu_get_choice(struct menu *m, void **choice)
if (!m || !choice)
return -EINVAL;
 
+   if (m->item_cnt == 0)
+   return -ENOENT;
+
if (!m->prompt)
return menu_default_choice(m, choice);
 
-- 
2.17.1



[PATCH v5 02/17] test: unit test for u16_strlcat()

2022-04-28 Thread Masahisa Kojima
Provide a unit test for function u16_strlcat().

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- u16_strlcat() 3rd agument update from buffer size
  to maximum string count
- increase buffer size for test
- change u16 string for the test, the letters in the test are different each 
other
- buffer to be used for the test is filled with non-zero value except for the
  last two bytes
- add test cases

Newly created in v2

 test/unicode_ut.c | 50 +++
 1 file changed, 50 insertions(+)

diff --git a/test/unicode_ut.c b/test/unicode_ut.c
index f2f63d5367..81c9549ba5 100644
--- a/test/unicode_ut.c
+++ b/test/unicode_ut.c
@@ -758,6 +758,56 @@ static int unicode_test_efi_create_indexed_name(struct 
unit_test_state *uts)
 UNICODE_TEST(unicode_test_efi_create_indexed_name);
 #endif
 
+static int unicode_test_u16_strlcat(struct unit_test_state *uts)
+{
+   u16 buf[40];
+   u16 dest[] = {0x3053, 0x3093, 0x306b, 0x3061, 0x306f, 0}; /* u"こんにちは" */
+   u16 src[] = {0x03B1, 0x2172, 0x6F5C, 0x8247, 0}; /* u"αⅲ潜艇" */
+   u16 concat_str[] = {0x3053, 0x3093, 0x306b, 0x3061, 0x306f,
+   0x03B1, 0x2172, 0x6F5C, 0x8247, 0};
+   u16 null_src = u'\0';
+   size_t ret, expected;
+   int i;
+
+   /* dest and src are empty string */
+   memset(buf, 0, sizeof(buf));
+   ret = u16_strlcat(buf, _src, sizeof(buf));
+   ut_asserteq(0, ret);
+
+   /* dest is empty string */
+   memset(buf, 0, sizeof(buf));
+   ret = u16_strlcat(buf, src, sizeof(buf));
+   ut_asserteq(4, ret);
+   ut_assert(!unicode_test_u16_strcmp(buf, src, 40));
+
+   /* src is empty string */
+   memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
+   buf[39] = 0;
+   memcpy(buf, dest, sizeof(dest));
+   ret = u16_strlcat(buf, _src, sizeof(buf));
+   ut_asserteq(5, ret);
+   ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
+
+   for (i = 0; i <= 40; i++) {
+   memset(buf, 0xCD, (sizeof(buf) - sizeof(u16)));
+   buf[39] = 0;
+   memcpy(buf, dest, sizeof(dest));
+   expected = min(i, 5 /* u16_strlen(dest) */) + 4 /* 
u16_strlen(src) */;
+   ret = u16_strlcat(buf, src, i);
+   ut_asserteq(expected, ret);
+   if (i <= 6) {
+   ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
+   } else if (i < 10) {
+   ut_assert(!unicode_test_u16_strcmp(buf, concat_str, i - 
1));
+   } else {
+   ut_assert(!unicode_test_u16_strcmp(buf, concat_str, 
40));
+   }
+   }
+
+   return 0;
+}
+UNICODE_TEST(unicode_test_u16_strlcat);
+
 int do_ut_unicode(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
 {
struct unit_test *tests = UNIT_TEST_SUITE_START(unicode_test);
-- 
2.17.1



[PATCH v5 01/17] lib/charset: add u16_strlcat() function

2022-04-28 Thread Masahisa Kojima
Provide u16 string version of strlcat().

Signed-off-by: Masahisa Kojima 
---
Changes in v5:
- change 3rd argument from size to count, it indicates
  the maximum u16 string count that dest buffer can have.
  Other u16_strXXX functions in U-Boot use string count, not the
  buffer size. u16_strlcat() should follow.
- update function comment to clealy describe the behavior
- use strlen() instead of strnlen(), to correctly handle
  the case if the count is smaller than or equal to initial dest count

Changes in v4:
- add blank line above the return statement

Changes in v2:
- implement u16_strlcat(with the destination buffer size in argument)
  instead of u16_strcat
 include/charset.h | 17 +
 lib/charset.c | 22 ++
 2 files changed, 39 insertions(+)

diff --git a/include/charset.h b/include/charset.h
index 38908e08f0..ae356ad9a5 100644
--- a/include/charset.h
+++ b/include/charset.h
@@ -261,6 +261,23 @@ u16 *u16_strcpy(u16 *dest, const u16 *src);
  */
 u16 *u16_strdup(const void *src);
 
+/**
+ * u16_strlcat() - Append a length-limited, %NUL-terminated string to another
+ *
+ * Append the src string to the dest string, overwriting the terminating
+ * null word at the end of dest, and then adds a terminating null word.
+ *
+ * @dest:  destination buffer (must include the trailing 0x)
+ * @src:   source buffer (must include the trailing 0x)
+ * @count: maximum number of code points that dest buffer can have,
+ * including the trailing 0x
+ * Return: total count of the created u16 string
+ * u16_strlen(src) + min(count, u16_strlen(initial dest)),
+ * does not include trailing 0x.
+ * If return value >= count, truncation occurred.
+ */
+size_t u16_strlcat(u16 *dest, const u16 *src, size_t size);
+
 /**
  * utf16_to_utf8() - Convert an utf16 string to utf8
  *
diff --git a/lib/charset.c b/lib/charset.c
index de201cf3b9..f295dfc11a 100644
--- a/lib/charset.c
+++ b/lib/charset.c
@@ -416,6 +416,28 @@ u16 *u16_strdup(const void *src)
return new;
 }
 
+size_t u16_strlcat(u16 *dest, const u16 *src, size_t count)
+{
+   size_t destlen, srclen, ret;
+
+   destlen = u16_strlen(dest);
+   srclen = u16_strlen(src);
+   ret = min(count, destlen) + srclen; /* does not include trailing 0x 
*/
+
+   if (destlen >= count)
+   return ret;
+
+   dest += destlen;
+   count -= destlen;
+   if (srclen >= count)
+   srclen = count - 1 /* for trailing 0x */;
+
+   memcpy(dest, src, srclen * sizeof(u16));
+   dest[srclen] = u'\0';
+
+   return ret;
+}
+
 /* Convert UTF-16 to UTF-8.  */
 uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size)
 {
-- 
2.17.1



[PATCH v5 00/17] enable menu-driven boot device selection

2022-04-28 Thread Masahisa Kojima
This patch series adds the menu-driven boot device selection,
by extending the existing "bootmenu" to include UEFI and distro_boot
related entries, and supports menu-driven UEFI boot variable
maintenance.

This patch series also includes the removable media support
that UEFI specification requires to support.

The menu example is as follows.

  *** U-Boot Boot Menu ***

 bootmenu_00   : Boot 1. kernel
 bootmenu_01   : Boot 2. kernel
 bootmenu_02   : Reset board
 UEFI BOOT : debian
 UEFI BOOT0001 : ubuntu
 UEFI BOOT0002 : mmc0:1
 UEFI BOOT0003 : mmc0:2
 UEFI BOOT0004 : nvme0:1
 UEFI BOOT0005 : nvme0:2
 UEFI BOOT0006 : usb0:2
 UEFI BOOT0007 : usb1:1
 UEFI BOOT0008 : usb1:2
 distro_boot   : usb0
 distro_boot   : scsi0
 distro_boot   : virtio0
 distro_boot   : dhcp

  Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit

[How to run on QEMU(arm64)]
1) clone source code
 $ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git \
-b kojima/bootmenu_v5_upstream_0428 --depth 1

2) prepare U-Boot .config
 $ make qemu_arm64_menuconfig
  then, enable CONFIG_CMD_BOOTMENU and CONFIG_AUTOBOOT_MENU_SHOW

3) run on QEMU(arm64) example
 $ qemu-system-aarch64 -machine virt,gic-version=3 -cpu cortex-a57 -m 4G 
-nographic \
   -no-acpi -bios ./u-boot.bin -hda xxx.img

[Major Changes]
- rebased to v2022.07-rc1
- there is detailed changelog in each commit

AKASHI Takahiro (2):
  efi_loader: export efi_locate_device_handle()
  efi_loader: bootmgr: add booting from removable media

Masahisa Kojima (15):
  lib/charset: add u16_strlcat() function
  test: unit test for u16_strlcat()
  menu: always show the menu regardless of the number of entry
  menu: menu_get_choice() return -ENOENT if menu item is empty
  bootmenu: flush input buffer before waiting user key input
  bootmenu: update bootmenu_entry structure
  bootmenu: add UEFI boot entry into bootmenu
  bootmenu: add distro boot entry
  bootmenu: add Kconfig option not to enter U-Boot console
  bootmenu: factor out the user input handling
  efi_loader: menu-driven addition of UEFI boot option
  efi_loader: menu-driven deletion of UEFI boot variable
  efi_loader: menu-driven update of UEFI bootorder variable
  bootmenu: add removable media entries
  doc:bootmenu: add UEFI boot and distro boot support description

 cmd/Kconfig   |   10 +
 cmd/bootmenu.c|  807 +
 common/menu.c |  142 ++-
 doc/usage/cmd/bootmenu.rst|   78 +-
 include/charset.h |   17 +
 include/config_distro_bootcmd.h   |   14 +-
 include/efi_default_filename.h|   33 +
 include/efi_loader.h  |   61 +
 include/menu.h|   20 +
 lib/charset.c |   22 +
 lib/efi_loader/Makefile   |1 +
 lib/efi_loader/efi_bootmenu_maintenance.c | 1245 +
 lib/efi_loader/efi_bootmgr.c  |   50 +-
 lib/efi_loader/efi_boottime.c |   59 +-
 lib/efi_loader/efi_console.c  |   81 ++
 lib/efi_loader/efi_disk.c |   11 +
 lib/efi_loader/efi_file.c |   75 +-
 test/unicode_ut.c |   50 +
 18 files changed, 2518 insertions(+), 258 deletions(-)
 create mode 100644 include/efi_default_filename.h
 create mode 100644 lib/efi_loader/efi_bootmenu_maintenance.c

-- 
2.17.1



Re: [PATCH v4 02/11] lib/charset: add u16_strlcat() function

2022-04-28 Thread Masahisa Kojima
Hi Heinrich,

On Mon, 18 Apr 2022 at 16:47, Masahisa Kojima
 wrote:
>
> On Sat, 16 Apr 2022 at 16:32, Heinrich Schuchardt  wrote:
> >
> > On 3/24/22 14:54, Masahisa Kojima wrote:
> > > Provide u16 string version of strlcat().
> > >
> > > Signed-off-by: Masahisa Kojima 
> > > Reviewed-by: Simon Glass 
> > > ---
> > > Changes in v4:
> > > - add blank line above the return statement
> > >
> > > Changes in v2:
> > > - implement u16_strlcat(with the destination buffer size in argument)
> > >instead of u16_strcat
> > >
> > >   include/charset.h | 15 +++
> > >   lib/charset.c | 21 +
> > >   2 files changed, 36 insertions(+)
> > >
> > > diff --git a/include/charset.h b/include/charset.h
> > > index b93d023092..dc5fc275ec 100644
> > > --- a/include/charset.h
> > > +++ b/include/charset.h
> > > @@ -259,6 +259,21 @@ u16 *u16_strcpy(u16 *dest, const u16 *src);
> > >*/
> > >   u16 *u16_strdup(const void *src);
> > >
> > > +/**
> > > + * u16_strlcat() - Append a length-limited, %NUL-terminated string to 
> > > another
> > > + *
> > > + * Append the src string to the dest string, overwriting the terminating
> > > + * null word at the end of dest, and then adds a terminating null word.
> > > + * It will append at most size - u16_strlen(dst) - 1 bytes, 
> > > NUL-terminating the result.
> >
> > Why "- 1"?
>
> It is my mistake, it should be 2.
>
> >
> > If size is even, we append up to size - u16_strlen(dst) - 2 bytes. The
> > two extra bytes used for 0x.
> > If size is odd, we append up to size - u16_strlen(dst) - 3 bytes leaving
> > one byte of the buffer unused.

To make behavior simple, I update the meaning of the 3rd parameter
from buffer size to u16 string count.
It is the same behavior as other u16_strxxx functions in U-boot.

Thanks,
Masahisa Kojima
>
> Thanks, It clearly explains the behavior.
>
> >
> > > + *
> > > + * @dest:destination buffer (null terminated)
> > > + * @src: source buffer (null terminated)
> > > + * @size:destination buffer size in bytes
> >
> > s/$/ including the trailing 0x/
>
> OK, I will update "(null terminated)" to the suggested one.
>
> >
> > > + * Return:   total size of the created string in bytes.
> > > + *   If return value >= size, truncation occurred.
> > > + */
> > > +size_t u16_strlcat(u16 *dest, const u16 *src, size_t size);
> > > +
> > >   /**
> > >* utf16_to_utf8() - Convert an utf16 string to utf8
> > >*
> > > diff --git a/lib/charset.c b/lib/charset.c
> > > index f44c58d9d8..47997eca7d 100644
> > > --- a/lib/charset.c
> > > +++ b/lib/charset.c
> > > @@ -428,6 +428,27 @@ u16 *u16_strdup(const void *src)
> > >   return new;
> > >   }
> > >
> > > +size_t u16_strlcat(u16 *dest, const u16 *src, size_t size)
> > > +{
> >
> > If you start the function with
> >
> >  size >>= 1;
> >
> > or
> >
> >  size /= sizeof(u16);
> >
> > this might simplify the code.
>
> In u16_strlcat(), there are two size definitions, u16 string size and
> buffer size.
> I will rename some of the variables to clearly identify the meaning.
>
> >
> > > + size_t dstrlen = u16_strnlen(dest, size >> 1);
> > > + size_t dlen = dstrlen * sizeof(u16);
> > > + size_t len = u16_strlen(src) * sizeof(u16);
> > > + size_t ret = dlen + len;
> >
> > This misses the  trailing 0x.
>
> Strlcat() is not the C standard function, but the linux implementation
> of strlcat() does not include trailing 0x00[1],
> also the same for openbsd.
> [1] https://github.com/torvalds/linux/blob/master/lib/string.c#L319.
>
> The current U-Boot strlcat() contains trailing 0x00, I think it needs
> to be updated.
>
> Thanks,
> Masahisa Kojima
>
> >
> > Best regards
> >
> > Heinrich
> >
> > > +
> > > + if (dlen >= size)
> > > + return ret;
> > > +
> > > + dest += dstrlen;
> > > + size -= dlen;
> > > + if (len >= size)
> > > + len = size - sizeof(u16);
> > > +
> > > + memcpy(dest, src, len);
> > > + dest[len >> 1] = u'\0';
> > > +
> > > + return ret;
> > > +}
> > > +
> > >   /* Convert UTF-16 to UTF-8.  */
> > >   uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size)
> > >   {
> >


Re: [PATCH v4 00/11] enable menu-driven boot device selection

2022-04-28 Thread Masahisa Kojima
Hi Heinrich,

On Sat, 16 Apr 2022 at 15:46, Heinrich Schuchardt  wrote:
>
> On 3/24/22 14:54, Masahisa Kojima wrote:
> > This patch series adds the menu-driven boot device selection,
> > by extending the existing "bootmenu" to include UEFI and distro_boot
> > related entries, and supports menu-driven UEFI boot variable
> > maintenance.
> >
> > This patch series also includes the removable media support
> > that UEFI specification requires to support.
> >
> > The menu example is as follows.
> >
> >*** U-Boot Boot Menu ***
> >
> >   bootmenu_00   : Boot 1. kernel
> >   bootmenu_01   : Boot 2. kernel
> >   bootmenu_02   : Reset board
> >   UEFI BOOT : debian
> >   UEFI BOOT0001 : ubuntu
> >   UEFI BOOT0002 : mmc0:1
> >   UEFI BOOT0003 : mmc0:2
> >   UEFI BOOT0004 : nvme0:1
> >   UEFI BOOT0005 : nvme0:2
> >   UEFI BOOT0006 : usb0:2
> >   UEFI BOOT0007 : usb1:1
> >   UEFI BOOT0008 : usb1:2
> >   distro_boot   : usb0
> >   distro_boot   : scsi0
> >   distro_boot   : virtio0
> >   distro_boot   : dhcp
> >
> >Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit
> >
> > [Major changes from RFC v3]
> > - add Kconfig option to disable U-Boot console
> > - add UEFI boot variable maintenance feature
> > - support removable media support and user selection
> > - app bootmenu enhancement documentation
> >
> > [How to run on QEMU(arm64)]
> > 1) clone source code
> >   $ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git \
> > -b kojima/bootmenu_v4_upstream_0324 --depth 1
> >
> > 2) prepare U-Boot .config
> >   $ make qemu_arm64_menuconfig
> >then, enable CONFIG_CMD_BOOTMENU and CONFIG_AUTOBOOT_MENU_SHOW
> >
> > 3) run on QEMU(arm64) example
> >   $ qemu-system-aarch64 -machine virt,gic-version=3 -cpu cortex-a57 -m 4G 
> > -nographic \
> > -no-acpi -bios ./u-boot.bin -hda xxx.img
>
>
> I applied the series to origin/master and added the two config options.
>
> This is the output if the disk image does not have an EFI partition:
>
> Found 0 disks
> No EFI system partition
> Unable to find TPMv2 device
>
> Even if there is no EFI system partition on virtio 0 I would expect the
> menu to be shown.

This issue is fixed in the next version.

>
> When having an image with an EFI system partition I get:
>
>*** U-Boot Boot Menu ***
>
>   UEFI BOOT0003 : test3
>   UEFI BOOT00A0 : hello
>   UEFI BOOT : virtio0:1
>   distro_boot   : usb0
>   distro_boot   : scsi0
>   distro_boot   : virtio0
>   distro_boot   : nvme0
>   distro_boot   : dhcp
>   UEFI Boot Manager Maintenance
>   U-Boot console
>
> The entries usb0, scsi0, nvme0 should not exist as there is no such device.

Non-existent devices are filtered out in the next version.

>
> => lsblk
> Block Driver  Devices
> -
> efi_blk : 
> nvme-blk: 
> scsi_blk: 
> usb_storage_blk : 
> virtio-blk  : virtio 0
>
>
> When I select "U-Boot console" the prompt is written in the middle of
> the screen. I would expect the screen to be cleared.
>
> If I disable networking, I get
>
> Missing RNG device for EFI_RNG_PROTOCOL
> No EFI system partition
> Unable to find TPMv2 device
> =>
>
> though the disk has an EFI partition.

I fixed the issue that no menu appears if networking is disabled.

But the issue of no EFI system partition found if networking is
disabled seems a fundamental issue of U-Boot, not specific to this
series.
If networking is disabled, "lsblk" also can not find any block device.

o networking disabled
=> lsblk
Block Driver  Devices
-
efi_blk : 
nvme-blk: 
scsi_blk: 
usb_storage_blk : 
virtio-blk  : 

o networking enabled
=> lsblk
Block Driver  Devices
-
efi_blk : 
nvme-blk: 
scsi_blk: 
usb_storage_blk : 
virtio-blk  : virtio 0

Thanks,
Masahisa Kojima

>
> So this series needs some rework.
>
> Best regards
>
> Heinrich
>
> >
> >
> > AKASHI Takahiro (2):
> >efi_loader: export efi_locate_device_handle()
> >efi_loader: bootmgr: add booting from removable media
> >
> > Masahisa Kojima (9):
> >bootmenu: fix menu API error handling
> >lib/charset: add u16_strlcat() function
> >test: unit test for u16_strlcat()
> >menu: always show the menu regardless of the number or entry
> >bootmenu: add UEFI and disto_boot entries
> >bootmenu: factor out the user input handling
> >efi_loader: add menu-driven UEFI Boot Variable maintenance
> >bootmenu: add removable media entries
> >doc:bootmenu: add UEFI boot variable and distro boot support
> >
> >   cmd/Kconfig   |   10 +
> >   cmd/bootmenu.c|  678 +++
> >   common/menu.c |  139 ++-
> >   doc/usage/bootmenu.rst

Re: [PATCH v5 00/12] efi_loader: more tightly integrate UEFI disks to driver model

2022-04-28 Thread Heinrich Schuchardt

On 4/28/22 06:52, AKASHI Takahiro wrote:

On Wed, Apr 27, 2022 at 12:26:09PM +0900, AKASHI Takahiro wrote:

Heinrich,

On Tue, Apr 26, 2022 at 07:02:46PM +0200, Heinrich Schuchardt wrote:

On 4/26/22 16:44, AKASHI Takahiro wrote:

On Tue, Apr 26, 2022 at 03:57:26PM +0200, Heinrich Schuchardt wrote:

On 4/26/22 01:44, AKASHI Takahiro wrote:
I expect that boards that booted with previous versions of U-Boot using
the respective defconfig still boot. But they don't. Here is one example
(orangepi_pc_defconfig):

 Found U-Boot script /boot.scr.uimg
 189 bytes read in 2 ms (91.8 KiB/s)
 ## Executing script at 4310
 22979 bytes read in 8 ms (2.7 MiB/s)
 98304 bytes read in 8 ms (11.7 MiB/s)
 Booting /EFI\debian\grubarm.efi
 Welcome to GRUB!

 error: disk `,msdos2' not found.
 grub rescue>

In U-Boot v2022.04 function efi_disk_register() ensured that all block
devices and their partitions were added as EFI handles.

Not the all block devices, but the block devices which have already
enumerated when efi_init_obj_list() is called.


But that
function is missing now.

What (boot) device are you using here?

Please show me the values of env variables, particularly, "boot_targets".

Please show me the content of boot.scr.uimg, too.

Please show me the output from
=> dm tree
=> efidebug devices
for 2022.04 and 2022.07-rc1.

-Takahiro Akashi






I am booting from mmc. Boot.scr just loads the device-tree from mmc-

mmcblk0 179:00 29.8G  0 disk
├─mmcblk0p1 179:101G  0 part /boot/efi
├─mmcblk0p2 179:201G  0 part /boot
└─mmcblk0p3 179:30 27.8G  0 part /


Okay.



U-Boot 2022.04 (Apr 26 2022 - 16:02:27 +) Allwinner Technology
--

grub> ls
(hd0) (hd0,msdos1) (hd1) (hd1,msdos3) (hd1,msdos2) (hd1,msdos1)

hd0 is a USB stick
hd1 is the SD card

boot.scr


#
# flash-kernel: bootscr.sunxi
#

# boot script for Allwinner SunXi-based devices

# Mainline u-boot v2014.10 introduces a new default environment and
# a new common bootcmd handling for all platforms, which is not fully
# compatible with the old-style environment used by u-boot-sunxi.
# This script therefore needs to check in which environment it
# is running and set some variables accordingly.

# On u-boot-sunxi, this script assumes that ${device} and ${partition}
# are set.

# The new-style environment predefines ${boot_targets}, the old-style
# environment does not.
if test -n "${boot_targets}"
then
   echo "Mainline u-boot / new-style environment detected."
   # Mainline u-boot v2014.10 uses ${devtype}, ${devnum} and
   # ${bootpart} where u-boot-sunxi uses ${device} and ${partition}.
   # ${distro_bootpart} replaced ${bootpart} in u-boot v2016.01.
   if test -z "${device}"; then setenv device "${devtype}"; fi
   if test -z "${partition}${distro_bootpart}"; then setenv partition
"${devnum}:${bootpart}"; fi
   if test -z "${partition}"; then setenv partition
"${devnum}:${distro_bootpart}"; fi
else
   echo "U-boot-sunxi / old-style environment detected."
   # U-boot-sunxi does not predefine kernel_addr_r, fdt_addr_r and
   # ramdisk_addr_r, so they have to be manually set. Use the values
   # from mainline u-boot v2014.10, except for ramdisk_addr_r,
   # which is set to 0x4430 to allow for initrds larger than
   # 13MB on u-boot-sunxi.
   setenv kernel_addr_r 0x4200
   setenv fdt_addr_r 0x4300
   setenv ramdisk_addr_r 0x4430
fi

if test -n "${console}"; then
   setenv bootargs "${bootargs} console=${console}"
fi

setenv bootargs  ${bootargs} quiet


if test -z "${image_locations}"; then
setenv image_locations ${prefix}
fi
if test -z "${image_locations}"; then
setenv image_locations /boot/ /
fi

if test -z "${fk_kvers}"; then
setenv fk_kvers '5.16.0-4-armmp-lpae'
fi

if test -n "${fdtfile}"; then
setenv fdtpath dtbs/${fk_kvers}/${fdtfile}
else
setenv fdtpath dtb-${fk_kvers}
fi

for pathprefix in ${image_locations}
do
   if test -e ${device} ${partition} ${pathprefix}vmlinuz-${fk_kvers}
   then
 load ${device} ${partition} ${kernel_addr_r}
${pathprefix}vmlinuz-${fk_kvers} \
 && load ${device} ${partition} ${fdt_addr_r} ${pathprefix}${fdtpath} \
 && load ${device} ${partition} ${ramdisk_addr_r}
${pathprefix}initrd.img-${fk_kvers} \
 && echo "Booting Debian ${fk_kvers} from ${device} ${partition}..." \
 && bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
   fi
done


Nothing special done here.



U-Boot 2022.04 (Apr 26 2022 - 16:02:27 +) Allwinner Technology

=> echo $boot_targets
fel mmc0 usb0 pxe dhcp

=> dm tree
  Class Index  Probed  DriverName
---
  root  0  [ + ]   root_driver   root_driver
  video 0  [   ]   sunxi_de2 |-- sunxi_de2
  display   0  [   ]   sunxi_dw_hdmi |-- sunxi_dw_hdmi
  simple_bus0  [ + ]   simple_bus   

[PATCH 1/1] efi_loader: call efi_init_early() earlier

2022-04-28 Thread Heinrich Schuchardt
efi_init_early() creates an event hook for block device probing.
It has to be called before any block device is probed.

Signed-off-by: Heinrich Schuchardt 
---
 common/board_r.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/common/board_r.c b/common/board_r.c
index ff17720cf3..93c9c2e50d 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -693,6 +693,9 @@ static init_fnc_t init_sequence_r[] = {
/* initialize higher level parts of CPU like time base and timers */
cpu_init_r,
 #endif
+#ifdef CONFIG_EFI_SETUP_EARLY
+   efi_init_early,
+#endif
 #ifdef CONFIG_CMD_NAND
initr_nand,
 #endif
@@ -792,9 +795,6 @@ static init_fnc_t init_sequence_r[] = {
 #endif
 #if defined(CONFIG_PRAM)
initr_mem,
-#endif
-#ifdef CONFIG_EFI_SETUP_EARLY
-   efi_init_early,
 #endif
run_main_loop,
 };
--
2.30.2