Re: [PATCH v3 24/31] bootstd: Add an implementation of EFI bootmgr

2022-03-12 Thread Simon Glass
Hi Ilias,

On Sat, 12 Mar 2022 at 02:37, Ilias Apalodimas
 wrote:
>
> Hi Simon
>
> On Sun, 6 Mar 2022 at 05:08, Simon Glass  wrote:
>>
>> Hi Heinrich,
>>
>> On Wed, 19 Jan 2022 at 04:47, Heinrich Schuchardt  wrote:
>> >
>> > On 1/19/22 02:43, Simon Glass wrote:
>> > > Add a bootmeth driver which handles EFI boot manager, using EFI_LOADER.
>> > >
>> > > In effect, this provides the same functionality as the 'bootefi bootmgr'
>> > > command and shares the same code. But the interface into it is via a
>> > > bootmeth, so it does not require any special scripts, etc.
>> > >
>> > > For now this requires the 'bootefi' command be enabled. Future work may
>> > > tidy this up so that it can be used without CONFIG_CMDLINE being enabled.
>> > >
>> > > Signed-off-by: Simon Glass 
>> > > ---
>> > >
>> > > Changes in v3:
>> > > - Add a log category
>> > >
>> > >   boot/Makefile   |  3 ++
>> > >   boot/bootmeth_efi_mgr.c | 86 +
>> > >   2 files changed, 89 insertions(+)
>> > >   create mode 100644 boot/bootmeth_efi_mgr.c
>> > >
>> > > diff --git a/boot/Makefile b/boot/Makefile
>> > > index 795665f7ce5..38b10d81f0d 100644
>> > > --- a/boot/Makefile
>> > > +++ b/boot/Makefile
>> > > @@ -31,6 +31,9 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
>> > >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
>> > >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
>> > >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
>> > > +ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
>> > > +obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
>> > > +endif
>> > >
>> > >   obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
>> > >   obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
>> > > diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
>> > > new file mode 100644
>> > > index 000..a6914466db7
>> > > --- /dev/null
>> > > +++ b/boot/bootmeth_efi_mgr.c
>> > > @@ -0,0 +1,86 @@
>> > > +// SPDX-License-Identifier: GPL-2.0+
>> > > +/*
>> > > + * Bootmethod for EFI boot manager
>> > > + *
>> > > + * Copyright 2021 Google LLC
>> > > + * Written by Simon Glass 
>> > > + */
>> > > +
>> > > +#define LOG_CATEGORY UCLASS_BOOTSTD
>> > > +
>> > > +#include 
>> > > +#include 
>> > > +#include 
>> > > +#include 
>> > > +#include 
>> > > +#include 
>> > > +
>> > > +static int efi_mgr_check(struct udevice *dev, struct bootflow_iter 
>> > > *iter)
>> > > +{
>> > > + int ret;
>> > > +
>> > > + /* Must be an bootstd device */
>> > > + ret = bootflow_iter_uses_system(iter);
>> > > + if (ret)
>> > > + return log_msg_ret("net", ret);
>> > > +
>> > > + return 0;
>> > > +}
>> > > +
>> > > +static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow 
>> > > *bflow)
>> > > +{
>> > > + /*
>> > > +  * Just assume there is something to boot since we don't have any 
>> > > way
>> > > +  * of knowing in advance
>> > > +  */
>> > > + bflow->state = BOOTFLOWST_READY;
>> > > +
>> > > + return 0;
>> > > +}
>> > > +
>> > > +static int efi_mgr_read_file(struct udevice *dev, struct bootflow 
>> > > *bflow,
>> > > + const char *file_path, ulong addr, ulong 
>> > > *sizep)
>> > > +{
>> > > + /* Files are loaded by the 'bootefi bootmgr' command */
>> > > +
>> > > + return -ENOSYS;
>> > > +}
>> > > +
>> > > +static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow)
>> > > +{
>> > > + int ret;
>> > > +
>> > > + /* Booting is handled by the 'bootefi bootmgr' command */
>> > > + ret = run_command("bootefi bootmgr", 0);
>> >
>> > You are missing to provide the device tree.
>>
>> OK well I can deal with that when I get to it, I suppose. Which distro
>> can I try with?
>
>
> Any recent distro would work.  If you try to run an installer keep in mind 
> setting up grub will fail (since runtime variable support isn't yet 
> supported).  You can find more info on installing fedora here[1] just skip 
> the security and encryption parts

I see that Fedora 35 is out, so I will give that a go at some point.

>
> [1] https://www.linaro.org/blog/securing-a-device-with-trusted-substrate/

Regards,
Simon


Re: [PATCH v3 24/31] bootstd: Add an implementation of EFI bootmgr

2022-03-12 Thread Ilias Apalodimas
Hi Simon

On Sun, 6 Mar 2022 at 05:08, Simon Glass  wrote:

> Hi Heinrich,
>
> On Wed, 19 Jan 2022 at 04:47, Heinrich Schuchardt 
> wrote:
> >
> > On 1/19/22 02:43, Simon Glass wrote:
> > > Add a bootmeth driver which handles EFI boot manager, using EFI_LOADER.
> > >
> > > In effect, this provides the same functionality as the 'bootefi
> bootmgr'
> > > command and shares the same code. But the interface into it is via a
> > > bootmeth, so it does not require any special scripts, etc.
> > >
> > > For now this requires the 'bootefi' command be enabled. Future work may
> > > tidy this up so that it can be used without CONFIG_CMDLINE being
> enabled.
> > >
> > > Signed-off-by: Simon Glass 
> > > ---
> > >
> > > Changes in v3:
> > > - Add a log category
> > >
> > >   boot/Makefile   |  3 ++
> > >   boot/bootmeth_efi_mgr.c | 86
> +
> > >   2 files changed, 89 insertions(+)
> > >   create mode 100644 boot/bootmeth_efi_mgr.c
> > >
> > > diff --git a/boot/Makefile b/boot/Makefile
> > > index 795665f7ce5..38b10d81f0d 100644
> > > --- a/boot/Makefile
> > > +++ b/boot/Makefile
> > > @@ -31,6 +31,9 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
> > >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
> > >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
> > >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
> > > +ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
> > > +obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
> > > +endif
> > >
> > >   obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
> > >   obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
> > > diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
> > > new file mode 100644
> > > index 000..a6914466db7
> > > --- /dev/null
> > > +++ b/boot/bootmeth_efi_mgr.c
> > > @@ -0,0 +1,86 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +/*
> > > + * Bootmethod for EFI boot manager
> > > + *
> > > + * Copyright 2021 Google LLC
> > > + * Written by Simon Glass 
> > > + */
> > > +
> > > +#define LOG_CATEGORY UCLASS_BOOTSTD
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +static int efi_mgr_check(struct udevice *dev, struct bootflow_iter
> *iter)
> > > +{
> > > + int ret;
> > > +
> > > + /* Must be an bootstd device */
> > > + ret = bootflow_iter_uses_system(iter);
> > > + if (ret)
> > > + return log_msg_ret("net", ret);
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow
> *bflow)
> > > +{
> > > + /*
> > > +  * Just assume there is something to boot since we don't have
> any way
> > > +  * of knowing in advance
> > > +  */
> > > + bflow->state = BOOTFLOWST_READY;
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static int efi_mgr_read_file(struct udevice *dev, struct bootflow
> *bflow,
> > > + const char *file_path, ulong addr, ulong
> *sizep)
> > > +{
> > > + /* Files are loaded by the 'bootefi bootmgr' command */
> > > +
> > > + return -ENOSYS;
> > > +}
> > > +
> > > +static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow)
> > > +{
> > > + int ret;
> > > +
> > > + /* Booting is handled by the 'bootefi bootmgr' command */
> > > + ret = run_command("bootefi bootmgr", 0);
> >
> > You are missing to provide the device tree.
>
> OK well I can deal with that when I get to it, I suppose. Which distro
> can I try with?
>

Any recent distro would work.  If you try to run an installer keep in mind
setting up grub will fail (since runtime variable support isn't yet
supported).  You can find more info on installing fedora here[1] just skip
the security and encryption parts

[1] https://www.linaro.org/blog/securing-a-device-with-trusted-substrate/

Cheers
/Ilias

>
> Regards,
> Simon
>


Re: [PATCH v3 24/31] bootstd: Add an implementation of EFI bootmgr

2022-03-05 Thread Simon Glass
Hi Heinrich,

On Wed, 19 Jan 2022 at 04:47, Heinrich Schuchardt  wrote:
>
> On 1/19/22 02:43, Simon Glass wrote:
> > Add a bootmeth driver which handles EFI boot manager, using EFI_LOADER.
> >
> > In effect, this provides the same functionality as the 'bootefi bootmgr'
> > command and shares the same code. But the interface into it is via a
> > bootmeth, so it does not require any special scripts, etc.
> >
> > For now this requires the 'bootefi' command be enabled. Future work may
> > tidy this up so that it can be used without CONFIG_CMDLINE being enabled.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v3:
> > - Add a log category
> >
> >   boot/Makefile   |  3 ++
> >   boot/bootmeth_efi_mgr.c | 86 +
> >   2 files changed, 89 insertions(+)
> >   create mode 100644 boot/bootmeth_efi_mgr.c
> >
> > diff --git a/boot/Makefile b/boot/Makefile
> > index 795665f7ce5..38b10d81f0d 100644
> > --- a/boot/Makefile
> > +++ b/boot/Makefile
> > @@ -31,6 +31,9 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
> >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
> >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
> >   obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
> > +ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
> > +obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
> > +endif
> >
> >   obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
> >   obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
> > diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
> > new file mode 100644
> > index 000..a6914466db7
> > --- /dev/null
> > +++ b/boot/bootmeth_efi_mgr.c
> > @@ -0,0 +1,86 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Bootmethod for EFI boot manager
> > + *
> > + * Copyright 2021 Google LLC
> > + * Written by Simon Glass 
> > + */
> > +
> > +#define LOG_CATEGORY UCLASS_BOOTSTD
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
> > +{
> > + int ret;
> > +
> > + /* Must be an bootstd device */
> > + ret = bootflow_iter_uses_system(iter);
> > + if (ret)
> > + return log_msg_ret("net", ret);
> > +
> > + return 0;
> > +}
> > +
> > +static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow 
> > *bflow)
> > +{
> > + /*
> > +  * Just assume there is something to boot since we don't have any way
> > +  * of knowing in advance
> > +  */
> > + bflow->state = BOOTFLOWST_READY;
> > +
> > + return 0;
> > +}
> > +
> > +static int efi_mgr_read_file(struct udevice *dev, struct bootflow *bflow,
> > + const char *file_path, ulong addr, ulong 
> > *sizep)
> > +{
> > + /* Files are loaded by the 'bootefi bootmgr' command */
> > +
> > + return -ENOSYS;
> > +}
> > +
> > +static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow)
> > +{
> > + int ret;
> > +
> > + /* Booting is handled by the 'bootefi bootmgr' command */
> > + ret = run_command("bootefi bootmgr", 0);
>
> You are missing to provide the device tree.

OK well I can deal with that when I get to it, I suppose. Which distro
can I try with?

Regards,
Simon


Re: [PATCH v3 24/31] bootstd: Add an implementation of EFI bootmgr

2022-01-19 Thread Heinrich Schuchardt

On 1/19/22 02:43, Simon Glass wrote:

Add a bootmeth driver which handles EFI boot manager, using EFI_LOADER.

In effect, this provides the same functionality as the 'bootefi bootmgr'
command and shares the same code. But the interface into it is via a
bootmeth, so it does not require any special scripts, etc.

For now this requires the 'bootefi' command be enabled. Future work may
tidy this up so that it can be used without CONFIG_CMDLINE being enabled.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add a log category

  boot/Makefile   |  3 ++
  boot/bootmeth_efi_mgr.c | 86 +
  2 files changed, 89 insertions(+)
  create mode 100644 boot/bootmeth_efi_mgr.c

diff --git a/boot/Makefile b/boot/Makefile
index 795665f7ce5..38b10d81f0d 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -31,6 +31,9 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
  obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
+ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
+obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
+endif

  obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
  obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
new file mode 100644
index 000..a6914466db7
--- /dev/null
+++ b/boot/bootmeth_efi_mgr.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmethod for EFI boot manager
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass 
+ */
+
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
+{
+   int ret;
+
+   /* Must be an bootstd device */
+   ret = bootflow_iter_uses_system(iter);
+   if (ret)
+   return log_msg_ret("net", ret);
+
+   return 0;
+}
+
+static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
+{
+   /*
+* Just assume there is something to boot since we don't have any way
+* of knowing in advance
+*/
+   bflow->state = BOOTFLOWST_READY;
+
+   return 0;
+}
+
+static int efi_mgr_read_file(struct udevice *dev, struct bootflow *bflow,
+   const char *file_path, ulong addr, ulong *sizep)
+{
+   /* Files are loaded by the 'bootefi bootmgr' command */
+
+   return -ENOSYS;
+}
+
+static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow)
+{
+   int ret;
+
+   /* Booting is handled by the 'bootefi bootmgr' command */
+   ret = run_command("bootefi bootmgr", 0);


You are missing to provide the device tree.

Best regards

Heinrich


+
+   return 0;
+}
+
+static int bootmeth_efi_mgr_bind(struct udevice *dev)
+{
+   struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
+
+   plat->desc = "EFI bootmgr flow";
+
+   return 0;
+}
+
+static struct bootmeth_ops efi_mgr_bootmeth_ops = {
+   .check  = efi_mgr_check,
+   .read_bootflow  = efi_mgr_read_bootflow,
+   .read_file  = efi_mgr_read_file,
+   .boot   = efi_mgr_boot,
+};
+
+static const struct udevice_id efi_mgr_bootmeth_ids[] = {
+   { .compatible = "u-boot,efi-bootmgr" },
+   { }
+};
+
+U_BOOT_DRIVER(bootmeth_zefi_mgr) = {
+   .name   = "bootmeth_efi_mgr",
+   .id = UCLASS_BOOTMETH,
+   .of_match   = efi_mgr_bootmeth_ids,
+   .ops= _mgr_bootmeth_ops,
+   .bind   = bootmeth_efi_mgr_bind,
+};




[PATCH v3 24/31] bootstd: Add an implementation of EFI bootmgr

2022-01-18 Thread Simon Glass
Add a bootmeth driver which handles EFI boot manager, using EFI_LOADER.

In effect, this provides the same functionality as the 'bootefi bootmgr'
command and shares the same code. But the interface into it is via a
bootmeth, so it does not require any special scripts, etc.

For now this requires the 'bootefi' command be enabled. Future work may
tidy this up so that it can be used without CONFIG_CMDLINE being enabled.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add a log category

 boot/Makefile   |  3 ++
 boot/bootmeth_efi_mgr.c | 86 +
 2 files changed, 89 insertions(+)
 create mode 100644 boot/bootmeth_efi_mgr.c

diff --git a/boot/Makefile b/boot/Makefile
index 795665f7ce5..38b10d81f0d 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -31,6 +31,9 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) += bootmeth_distro.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) += bootmeth_pxe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) += bootmeth_efi.o
+ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
+obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
+endif
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
 obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) += fdt_region.o
diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
new file mode 100644
index 000..a6914466db7
--- /dev/null
+++ b/boot/bootmeth_efi_mgr.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Bootmethod for EFI boot manager
+ *
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass 
+ */
+
+#define LOG_CATEGORY UCLASS_BOOTSTD
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
+{
+   int ret;
+
+   /* Must be an bootstd device */
+   ret = bootflow_iter_uses_system(iter);
+   if (ret)
+   return log_msg_ret("net", ret);
+
+   return 0;
+}
+
+static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
+{
+   /*
+* Just assume there is something to boot since we don't have any way
+* of knowing in advance
+*/
+   bflow->state = BOOTFLOWST_READY;
+
+   return 0;
+}
+
+static int efi_mgr_read_file(struct udevice *dev, struct bootflow *bflow,
+   const char *file_path, ulong addr, ulong *sizep)
+{
+   /* Files are loaded by the 'bootefi bootmgr' command */
+
+   return -ENOSYS;
+}
+
+static int efi_mgr_boot(struct udevice *dev, struct bootflow *bflow)
+{
+   int ret;
+
+   /* Booting is handled by the 'bootefi bootmgr' command */
+   ret = run_command("bootefi bootmgr", 0);
+
+   return 0;
+}
+
+static int bootmeth_efi_mgr_bind(struct udevice *dev)
+{
+   struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);
+
+   plat->desc = "EFI bootmgr flow";
+
+   return 0;
+}
+
+static struct bootmeth_ops efi_mgr_bootmeth_ops = {
+   .check  = efi_mgr_check,
+   .read_bootflow  = efi_mgr_read_bootflow,
+   .read_file  = efi_mgr_read_file,
+   .boot   = efi_mgr_boot,
+};
+
+static const struct udevice_id efi_mgr_bootmeth_ids[] = {
+   { .compatible = "u-boot,efi-bootmgr" },
+   { }
+};
+
+U_BOOT_DRIVER(bootmeth_zefi_mgr) = {
+   .name   = "bootmeth_efi_mgr",
+   .id = UCLASS_BOOTMETH,
+   .of_match   = efi_mgr_bootmeth_ids,
+   .ops= _mgr_bootmeth_ops,
+   .bind   = bootmeth_efi_mgr_bind,
+};
-- 
2.34.1.703.g22d0c6ccf7-goog