Re: [PATCH v4 13/33] bootstd: Add the bootstd uclass and core implementation

2022-03-12 Thread Simon Glass
Hi Ilias,

On Sat, 12 Mar 2022 at 07:35, Ilias Apalodimas
 wrote:
>
> Hi Simon,
>
>  +
> > +/* For now, bind the boormethod device if none are found in the devicetree 
> > */
> > +int dm_scan_other(bool pre_reloc_only)
> > +{
> > + struct udevice *bootstd;
> > + int ret;
> > +
> > + /* These are not needed before relocation */
> > + if (!(gd->flags & GD_FLG_RELOC))
> > + return 0;
> > +
> > + /* Create a bootstd device if needed */
> > + uclass_find_first_device(UCLASS_BOOTSTD, );
> > + if (!bootstd) {
> > + ret = device_bind_driver(gd->dm_root, "bootstd_drv", 
> > "bootstd",
> > +  );
> > + if (ret)
> > + return log_msg_ret("bootstd", ret);
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +static const struct udevice_id bootstd_ids[] = {
> > + { .compatible = "u-boot,boot-std" },
> > + { }
> > +};
> > +
> > +U_BOOT_DRIVER(bootstd_drv) = {
> > + .id = UCLASS_BOOTSTD,
> > + .name   = "bootstd_drv",
> > + .of_to_plat = bootstd_of_to_plat,
> > + .probe  = bootstd_probe,
> > + .remove = bootstd_remove,
> > + .of_match   = bootstd_ids,
> > + .priv_auto  = sizeof(struct bootstd_priv),
> > +};
> > +
> > +UCLASS_DRIVER(bootstd) = {
> > + .id = UCLASS_BOOTSTD,
> > + .name   = "bootstd",
> > +#if CONFIG_IS_ENABLED(OF_REAL)
> > + .post_bind  = dm_scan_fdt_dev,
> > +#endif
> > +};
> > diff --git a/doc/device-tree-bindings/bootstd.txt 
> > b/doc/device-tree-bindings/bootstd.txt
> > new file mode 100644
> > index 00..f048b9dd32
> > --- /dev/null
> > +++ b/doc/device-tree-bindings/bootstd.txt
> > @@ -0,0 +1,28 @@
> > +U-Boot standard boot device (bootstd)
> > +=
> > +
> > +This is the controlling device for U-Boot standard boot, providing a way to
> > +boot operating systems in a way that can be controlled by distros.
>
> A bit more info on how this can be controlled by distros would be helpful.
> What are you expecting from distros here?  Most of the current installers
> (at least on x86 and armv8) set the Boot to SHIM and assume the
> efibootmgr will take care of that.

Well then it would use the bootmgr bootmeth, which is included in this
series. Most of the code here is related to moving on from the current
scripts.

> > +
> > +Required properties:
> > +
> > +compatible: "u-boot,boot-std"
>
> This needs to end up on every board controldtb? Or is there another way of
> defining those nodes?

No, this node is optional.

>
> > +
> > +Optional properties:
> > +
> > +filename-prefixes:
> > +   List of strings, each a directory to search for bootflow files
> > +
> > +bootdev-order:
> > +   List of bootdevs to check for bootflows, each a bootdev label (the media
> > +   uclass followed by the numeric sequence number of the media device)
> > +
> > +
> > +Example:
> > +
> > + bootstd {
> > + compatible = "u-boot,boot-std";
> > +
> > + filename-prefixes = "/", "/boot/";
> > + bootdev-order = "mmc2", "mmc1";
> > + };
>
> [...]

Regards,
Simon


Re: [PATCH v4 13/33] bootstd: Add the bootstd uclass and core implementation

2022-03-12 Thread Ilias Apalodimas
Hi Simon, 

 +
> +/* For now, bind the boormethod device if none are found in the devicetree */
> +int dm_scan_other(bool pre_reloc_only)
> +{
> + struct udevice *bootstd;
> + int ret;
> +
> + /* These are not needed before relocation */
> + if (!(gd->flags & GD_FLG_RELOC))
> + return 0;
> +
> + /* Create a bootstd device if needed */
> + uclass_find_first_device(UCLASS_BOOTSTD, );
> + if (!bootstd) {
> + ret = device_bind_driver(gd->dm_root, "bootstd_drv", "bootstd",
> +  );
> + if (ret)
> + return log_msg_ret("bootstd", ret);
> + }
> +
> + return 0;
> +}
> +
> +static const struct udevice_id bootstd_ids[] = {
> + { .compatible = "u-boot,boot-std" },
> + { }
> +};
> +
> +U_BOOT_DRIVER(bootstd_drv) = {
> + .id = UCLASS_BOOTSTD,
> + .name   = "bootstd_drv",
> + .of_to_plat = bootstd_of_to_plat,
> + .probe  = bootstd_probe,
> + .remove = bootstd_remove,
> + .of_match   = bootstd_ids,
> + .priv_auto  = sizeof(struct bootstd_priv),
> +};
> +
> +UCLASS_DRIVER(bootstd) = {
> + .id = UCLASS_BOOTSTD,
> + .name   = "bootstd",
> +#if CONFIG_IS_ENABLED(OF_REAL)
> + .post_bind  = dm_scan_fdt_dev,
> +#endif
> +};
> diff --git a/doc/device-tree-bindings/bootstd.txt 
> b/doc/device-tree-bindings/bootstd.txt
> new file mode 100644
> index 00..f048b9dd32
> --- /dev/null
> +++ b/doc/device-tree-bindings/bootstd.txt
> @@ -0,0 +1,28 @@
> +U-Boot standard boot device (bootstd)
> +=
> +
> +This is the controlling device for U-Boot standard boot, providing a way to
> +boot operating systems in a way that can be controlled by distros.

A bit more info on how this can be controlled by distros would be helpful.
What are you expecting from distros here?  Most of the current installers
(at least on x86 and armv8) set the Boot to SHIM and assume the
efibootmgr will take care of that.
> +
> +Required properties:
> +
> +compatible: "u-boot,boot-std"

This needs to end up on every board controldtb? Or is there another way of
defining those nodes?

> +
> +Optional properties:
> +
> +filename-prefixes:
> +   List of strings, each a directory to search for bootflow files
> +
> +bootdev-order:
> +   List of bootdevs to check for bootflows, each a bootdev label (the media
> +   uclass followed by the numeric sequence number of the media device)
> +
> +
> +Example:
> +
> + bootstd {
> + compatible = "u-boot,boot-std";
> +
> + filename-prefixes = "/", "/boot/";
> + bootdev-order = "mmc2", "mmc1";
> + };

[...]

Thanks
/Ilias


[PATCH v4 13/33] bootstd: Add the bootstd uclass and core implementation

2022-03-06 Thread Simon Glass
The 'bootstd' device provides the central information about U-Boot
standard boot.

Add a uclass for bootstd and the various helpers needed to make it
work. Also add a binding file.

Signed-off-by: Simon Glass 
---

Changes in v4:
- NULL-terminate the default prefix list
- Use new Return style in function comments

Changes in v3:
- Add CONFIG_BOOTSTD_FULL to enable the full feature set
- Support bootdev-order and filename-prefixes only with CONFIG_BOOTSTD_FULL

 MAINTAINERS  |   2 +
 boot/Kconfig |  34 ++
 boot/Makefile|   3 +
 boot/bootstd-uclass.c| 152 +++
 doc/device-tree-bindings/bootstd.txt |  28 +
 include/bootstd.h|  80 ++
 include/dm/uclass-id.h   |   1 +
 7 files changed, 300 insertions(+)
 create mode 100644 boot/bootstd-uclass.c
 create mode 100644 doc/device-tree-bindings/bootstd.txt
 create mode 100644 include/bootstd.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 6e6dcd7e26..9df9812978 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -685,6 +685,8 @@ F:  tools/binman/
 BOOTDEVICE
 M: Simon Glass 
 S: Maintained
+F: boot/bootstd.c
+F: include/bootstd.h
 F: include/bootflow.h
 
 BTRFS
diff --git a/boot/Kconfig b/boot/Kconfig
index b83a4e8400..deb2bf386f 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -292,6 +292,40 @@ endif # SPL
 
 endif # FIT
 
+config BOOTSTD
+   bool "Standard boot support"
+   default y
+   depends on DM && OF_CONTROL && BLK
+   help
+ U-Boot supports a standard way of locating something to boot,
+ typically an Operating System such as Linux, provided by a distro such
+ as Arch Linux or Debian. Enable this to support iterating through
+ available bootdevs and using bootmeths to find bootflows suitable for
+ booting.
+
+ Standard boot is not a standard way of booting, just a framework
+ within U-Boot for supporting all the different ways that exist.
+
+ Terminology:
+
+   - bootdev - a device which can hold a distro (e.g. MMC)
+   - bootmeth - a method to scan a bootdev to find bootflows (owned by
+   U-Boot)
+   - bootflow - a description of how to boot (owned by the distro)
+
+config BOOTSTD_FULL
+   bool "Enhanced features for standard boot"
+   default y if SANDBOX
+   help
+ This enables various useful features for standard boot, which are not
+ essential for operation:
+
+ - bootdev, bootmeth commands
+ - extra features in the bootflow command
+ - support for selecting the ordering of bootmeths ("bootmeth order")
+ - support for selecting the ordering of bootdevs using the devicetree
+   as well as the "boot_targets" environment variable
+
 config LEGACY_IMAGE_FORMAT
bool "Enable support for the legacy image format"
default y if !FIT_SIGNATURE
diff --git a/boot/Makefile b/boot/Makefile
index 2938c3f145..48031d1c2b 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -22,6 +22,9 @@ endif
 obj-y += image.o image-board.o
 obj-$(CONFIG_ANDROID_AB) += android_ab.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o
+
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
+
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
 obj-$(CONFIG_$(SPL_TPL_)FIT) += image-fit.o
diff --git a/boot/bootstd-uclass.c b/boot/bootstd-uclass.c
new file mode 100644
index 00..615cd89bf0
--- /dev/null
+++ b/boot/bootstd-uclass.c
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Uclass implementation for standard boot
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* These are used if filename-prefixes is not present */
+const char *const default_prefixes[] = {"/", "/boot/", NULL};
+
+static int bootstd_of_to_plat(struct udevice *dev)
+{
+   struct bootstd_priv *priv = dev_get_priv(dev);
+   int ret;
+
+   if (IS_ENABLED(CONFIG_BOOTSTD_FULL)) {
+   /* Don't check errors since livetree and flattree are different 
*/
+   ret = dev_read_string_list(dev, "filename-prefixes",
+  >prefixes);
+   dev_read_string_list(dev, "bootdev-order",
+>bootdev_order);
+   }
+
+   return 0;
+}
+
+static void bootstd_clear_glob_(struct bootstd_priv *priv)
+{
+   while (!list_empty(>glob_head)) {
+   struct bootflow *bflow;
+
+   bflow = list_first_entry(>glob_head, struct bootflow,
+glob_node);
+   /* add later bootflow_remove(bflow); */
+   }
+}
+
+void