Skip to contentSkip to conversation

bootstd: Make efi_mgr bootmeth work for non-sandbox setups

PATCH In review Mark Kettenis 4 participants 9 messages Sep 3, 2023 – Nov 2, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bootstd: Make efi_mgr bootmeth work for non-sandbox setups

Enable the bootflow based on this bootmeth if the BootOrder EFI variable is set.

---

ChangeLog:

v2: - Initialize EFI subsystem to populate EFI variables

 boot/bootmeth_efi_mgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +16 -1
index e9d973429f..e6c42d41fb 100644
@@ -14,6 +14,8 @@
 #include <bootmeth.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
 	struct efi_mgr_priv *priv = dev_get_priv(dev);
+	efi_status_t ret;
+	efi_uintn_t size;
+	u16 *bootorder;
 
 	if (priv->fake_dev) {
 		bflow->state = BOOTFLOWST_READY;
 		return 0;
 	}
 
-	/* To be implemented */
+	ret = efi_init_obj_list();
+	if (ret)
+		return log_msg_ret("init", ret);
+
+	/* Enable this method if the "BootOrder" UEFI exists. */
+	bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid,
+				&size);
+	if (bootorder) {
+		bflow->state = BOOTFLOWST_READY;
+		return 0;
+	}
 
 	return -EINVAL;
 }
Signature · 1 line
2.42.0
#1 lore raw

Hi Mark,

Quoted 33 lines · Mark Kettenis

Enable the bootflow based on this bootmeth if the BootOrder EFI variable is set.

---

ChangeLog:

v2: - Initialize EFI subsystem to populate EFI variables

 boot/bootmeth_efi_mgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +3 -0
index e9d973429f..e6c42d41fb 100644
@@ -14,6 +14,8 @@
 #include <bootmeth.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct efi_mgr_priv *priv = dev_get_priv(dev);
+       efi_status_t ret;

boot/bootmeth_efi_mgr.c static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter) · line 60

Quoted 10 lines
boot/bootmeth_efi_mgr.c +3 -1
+       efi_uintn_t size;
+       u16 *bootorder;
 
        if (priv->fake_dev) {
                bflow->state = BOOTFLOWST_READY;
                return 0;
        }
 
-       /* To be implemented */
+       ret = efi_init_obj_list();

Doesn't this start up the whole EFI system? Is there a cheaper way to see if the variable subsystem exists, or can work?

Quoted 14 lines
boot/bootmeth_efi_mgr.c +10 -1
+       if (ret)
+               return log_msg_ret("init", ret);
+
+       /* Enable this method if the "BootOrder" UEFI exists. */
+       bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid,
+                               &size);
+       if (bootorder) {
+               bflow->state = BOOTFLOWST_READY;
+               return 0;
+       }
 
        return -EINVAL;
 }
--
Quoted 2 lines

2.42.0

Regards,
Simon

#2 lore raw
Quoted 47 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 06:23:10 -0600

Hi Mark,

Quoted 41 lines · Mark Kettenis

Enable the bootflow based on this bootmeth if the BootOrder EFI variable is set.

---

ChangeLog:

v2: - Initialize EFI subsystem to populate EFI variables

 boot/bootmeth_efi_mgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +5 -0
index e9d973429f..e6c42d41fb 100644
@@ -14,6 +14,8 @@
 #include <bootmeth.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct efi_mgr_priv *priv = dev_get_priv(dev);
+       efi_status_t ret;
+       efi_uintn_t size;
+       u16 *bootorder;
 
        if (priv->fake_dev) {
                bflow->state = BOOTFLOWST_READY;
                return 0;
        }
 
Quoted 5 lines

boot/bootmeth_efi_mgr.c static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter) · line 60

Quoted 2 lines
boot/bootmeth_efi_mgr.c +1 -1
-       /* To be implemented */
+       ret = efi_init_obj_list();

Doesn't this start up the whole EFI system? Is there a cheaper way to see if the variable subsystem exists, or can work?

A fair bit of it at least. With the possible exception of launching EFI capsules (which shouldn't happen for a "normal" boot), I don't think this is very expensive though.

There currently isn't a way to only initialize the variable subsystem; we can't just call efi_init_variables() here since we have to also call efi_disks_register() and a later efi_init_obj_list() call would call efi_init_variables() again, which would leak memory.

Alternatively we could just unconditionally declare the efi_mgr bootmeth as "ready" (like you already do for sandbox). That would postpone initialization of the EFI subsystem until we actually execute this bootmeth.

But we need to do something before we switch more targets to standard boot since otherwise booting through the EFI boot manager is just plain broken.

Quoted 20 lines
Quoted 14 lines
boot/bootmeth_efi_mgr.c +10 -1
+       if (ret)
+               return log_msg_ret("init", ret);
+
+       /* Enable this method if the "BootOrder" UEFI exists. */
+       bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid,
+                               &size);
+       if (bootorder) {
+               bflow->state = BOOTFLOWST_READY;
+               return 0;
+       }
 
        return -EINVAL;
 }
--
Quoted 2 lines

2.42.0

Regards,
Simon

#3 lore raw

Hi Mark,

Quoted 63 lines · Mark Kettenis
Quoted 48 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 06:23:10 -0600

Hi Mark,

Quoted 41 lines · Mark Kettenis

Enable the bootflow based on this bootmeth if the BootOrder EFI variable is set.

---

ChangeLog:

v2: - Initialize EFI subsystem to populate EFI variables

 boot/bootmeth_efi_mgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +5 -0
index e9d973429f..e6c42d41fb 100644
@@ -14,6 +14,8 @@
 #include <bootmeth.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct efi_mgr_priv *priv = dev_get_priv(dev);
+       efi_status_t ret;
+       efi_uintn_t size;
+       u16 *bootorder;
 
        if (priv->fake_dev) {
                bflow->state = BOOTFLOWST_READY;
                return 0;
        }
 
Quoted 5 lines

boot/bootmeth_efi_mgr.c static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter) · line 60

Quoted 2 lines
boot/bootmeth_efi_mgr.c +1 -1
-       /* To be implemented */
+       ret = efi_init_obj_list();

Doesn't this start up the whole EFI system? Is there a cheaper way to see if the variable subsystem exists, or can work?

A fair bit of it at least. With the possible exception of launching EFI capsules (which shouldn't happen for a "normal" boot), I don't think this is very expensive though.

There currently isn't a way to only initialize the variable subsystem; we can't just call efi_init_variables() here since we have to also call efi_disks_register() and a later efi_init_obj_list() call would call efi_init_variables() again, which would leak memory.

Quoted 8 lines

Alternatively we could just unconditionally declare the efi_mgr bootmeth as "ready" (like you already do for sandbox). That would postpone initialization of the EFI subsystem until we actually execute this bootmeth.

But we need to do something before we switch more targets to standard boot since otherwise booting through the EFI boot manager is just plain broken.

Yes...

I don't have any great ideas on this. If we could get the EFI code better integrated into U-Boot then perhaps we would not need this 'monolithm' init?

Regards,
Simon

#4 lore raw
Quoted 78 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 09:57:34 -0600

Hi Mark,

Quoted 63 lines · Mark Kettenis
Quoted 48 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 06:23:10 -0600

Hi Mark,

Quoted 41 lines · Mark Kettenis

Enable the bootflow based on this bootmeth if the BootOrder EFI variable is set.

---

ChangeLog:

v2: - Initialize EFI subsystem to populate EFI variables

 boot/bootmeth_efi_mgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +5 -0
index e9d973429f..e6c42d41fb 100644
@@ -14,6 +14,8 @@
 #include <bootmeth.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct efi_mgr_priv *priv = dev_get_priv(dev);
+       efi_status_t ret;
+       efi_uintn_t size;
+       u16 *bootorder;
 
        if (priv->fake_dev) {
                bflow->state = BOOTFLOWST_READY;
                return 0;
        }
 
Quoted 5 lines

boot/bootmeth_efi_mgr.c static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter) · line 60

Quoted 2 lines
boot/bootmeth_efi_mgr.c +1 -1
-       /* To be implemented */
+       ret = efi_init_obj_list();

Doesn't this start up the whole EFI system? Is there a cheaper way to see if the variable subsystem exists, or can work?

A fair bit of it at least. With the possible exception of launching EFI capsules (which shouldn't happen for a "normal" boot), I don't think this is very expensive though.

There currently isn't a way to only initialize the variable subsystem; we can't just call efi_init_variables() here since we have to also call efi_disks_register() and a later efi_init_obj_list() call would call efi_init_variables() again, which would leak memory.

Quoted 8 lines

Alternatively we could just unconditionally declare the efi_mgr bootmeth as "ready" (like you already do for sandbox). That would postpone initialization of the EFI subsystem until we actually execute this bootmeth.

But we need to do something before we switch more targets to standard boot since otherwise booting through the EFI boot manager is just plain broken.

Quoted 5 lines

Yes...

I don't have any great ideas on this. If we could get the EFI code better integrated into U-Boot then perhaps we would not need this 'monolithm' init?

You'll have to take that up with the maintainers of the EFI loader subsystem. I just want to repair the breakage that was introduced with bootstd.

#5 lore raw

Hi Mark,

Quoted 81 lines · Mark Kettenis
Quoted 81 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 09:57:34 -0600

Hi Mark,

Quoted 63 lines · Mark Kettenis
Quoted 48 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 06:23:10 -0600

Hi Mark,

Quoted 41 lines · Mark Kettenis

Enable the bootflow based on this bootmeth if the BootOrder EFI variable is set.

---

ChangeLog:

v2: - Initialize EFI subsystem to populate EFI variables

 boot/bootmeth_efi_mgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +5 -0
index e9d973429f..e6c42d41fb 100644
@@ -14,6 +14,8 @@
 #include <bootmeth.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct efi_mgr_priv *priv = dev_get_priv(dev);
+       efi_status_t ret;
+       efi_uintn_t size;
+       u16 *bootorder;
 
        if (priv->fake_dev) {
                bflow->state = BOOTFLOWST_READY;
                return 0;
        }
 
Quoted 5 lines

boot/bootmeth_efi_mgr.c static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter) · line 60

Quoted 2 lines
boot/bootmeth_efi_mgr.c +1 -1
-       /* To be implemented */
+       ret = efi_init_obj_list();

Doesn't this start up the whole EFI system? Is there a cheaper way to see if the variable subsystem exists, or can work?

A fair bit of it at least. With the possible exception of launching EFI capsules (which shouldn't happen for a "normal" boot), I don't think this is very expensive though.

There currently isn't a way to only initialize the variable subsystem; we can't just call efi_init_variables() here since we have to also call efi_disks_register() and a later efi_init_obj_list() call would call efi_init_variables() again, which would leak memory.

Quoted 8 lines

Alternatively we could just unconditionally declare the efi_mgr bootmeth as "ready" (like you already do for sandbox). That would postpone initialization of the EFI subsystem until we actually execute this bootmeth.

But we need to do something before we switch more targets to standard boot since otherwise booting through the EFI boot manager is just plain broken.

Yes...

Quoted 7 lines
Quoted 3 lines

I don't have any great ideas on this. If we could get the EFI code better integrated into U-Boot then perhaps we would not need this 'monolithm' init?

You'll have to take that up with the maintainers of the EFI loader subsystem. I just want to repair the breakage that was introduced with bootstd.

Yes, understood. Do you know how long it takes to do this step?

The control for this feature is CMD_BOOTEFI_BOOTMGR...I think it would be better to have BOOTEFI_BOOTMGR as well as CMD_BOOTEFI_BOOTMGR, since it is strange to have a CMD Kconfig in lib/efi_loader

I am OK with this patch as I don't see any alternative. We need to do something and we can always improve it if it causes problems.

Heinrich?

Regards,
Simon

#6 lore raw
Quoted 91 lines

From: Simon Glass <[email protected]>
Date: Sun, 10 Sep 2023 13:13:16 -0600

Hi Mark,

Quoted 85 lines · Mark Kettenis
Quoted 84 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 09:57:34 -0600

Hi Mark,

Quoted 63 lines · Mark Kettenis
Quoted 48 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 06:23:10 -0600

Hi Mark,

Quoted 41 lines · Mark Kettenis

Enable the bootflow based on this bootmeth if the BootOrder EFI variable is set.

---

ChangeLog:

v2: - Initialize EFI subsystem to populate EFI variables

 boot/bootmeth_efi_mgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +5 -0
index e9d973429f..e6c42d41fb 100644
@@ -14,6 +14,8 @@
 #include <bootmeth.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct efi_mgr_priv *priv = dev_get_priv(dev);
+       efi_status_t ret;
+       efi_uintn_t size;
+       u16 *bootorder;
 
        if (priv->fake_dev) {
                bflow->state = BOOTFLOWST_READY;
                return 0;
        }
 
Quoted 5 lines

boot/bootmeth_efi_mgr.c static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter) · line 60

Quoted 2 lines
boot/bootmeth_efi_mgr.c +1 -1
-       /* To be implemented */
+       ret = efi_init_obj_list();

Doesn't this start up the whole EFI system? Is there a cheaper way to see if the variable subsystem exists, or can work?

A fair bit of it at least. With the possible exception of launching EFI capsules (which shouldn't happen for a "normal" boot), I don't think this is very expensive though.

There currently isn't a way to only initialize the variable subsystem; we can't just call efi_init_variables() here since we have to also call efi_disks_register() and a later efi_init_obj_list() call would call efi_init_variables() again, which would leak memory.

Quoted 8 lines

Alternatively we could just unconditionally declare the efi_mgr bootmeth as "ready" (like you already do for sandbox). That would postpone initialization of the EFI subsystem until we actually execute this bootmeth.

But we need to do something before we switch more targets to standard boot since otherwise booting through the EFI boot manager is just plain broken.

Yes...

I don't have any great ideas on this. If we could get the EFI code better integrated into U-Boot then perhaps we would not need this 'monolithm' init?

Quoted 5 lines
Quoted 3 lines

You'll have to take that up with the maintainers of the EFI loader subsystem. I just want to repair the breakage that was introduced with bootstd.

Yes, understood. Do you know how long it takes to do this step?

It is instant. But then this is on a fast machine with the EFI variables stored on the internal NVMe disk, which is plenty fast as well. And I haven't enabled any of the capsule or TPM stuff hich may take more time.

Quoted 12 lines

The control for this feature is CMD_BOOTEFI_BOOTMGR...I think it would be better to have BOOTEFI_BOOTMGR as well as CMD_BOOTEFI_BOOTMGR, since it is strange to have a CMD Kconfig in lib/efi_loader

I am OK with this patch as I don't see any alternative. We need to do something and we can always improve it if it causes problems.

Heinrich?

Regards,
Simon

Reviewed-by
#7 lore raw
Quoted 96 lines · Mark Kettenis
Quoted 96 lines

From: Simon Glass <[email protected]>
Date: Sun, 10 Sep 2023 13:13:16 -0600

Hi Mark,

Quoted 88 lines · Mark Kettenis
Quoted 79 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 09:57:34 -0600

Hi Mark,

Quoted 63 lines · Mark Kettenis
Quoted 48 lines

From: Simon Glass <[email protected]>
Date: Thu, 7 Sep 2023 06:23:10 -0600

Hi Mark,

Quoted 41 lines · Mark Kettenis

Enable the bootflow based on this bootmeth if the BootOrder EFI variable is set.

---

ChangeLog:

v2: - Initialize EFI subsystem to populate EFI variables

 boot/bootmeth_efi_mgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
boot/bootmeth_efi_mgr.c +5 -0
index e9d973429f..e6c42d41fb 100644
@@ -14,6 +14,8 @@
 #include <bootmeth.h>
 #include <command.h>
 #include <dm.h>
+#include <efi_loader.h>
+#include <efi_variable.h>
 
 /**
  * struct efi_mgr_priv - private info for the efi-mgr driver
@@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter)
 static int efi_mgr_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
        struct efi_mgr_priv *priv = dev_get_priv(dev);
+       efi_status_t ret;
+       efi_uintn_t size;
+       u16 *bootorder;
 
        if (priv->fake_dev) {
                bflow->state = BOOTFLOWST_READY;
                return 0;
        }
 
Quoted 5 lines

boot/bootmeth_efi_mgr.c static int efi_mgr_check(struct udevice *dev, struct bootflow_iter *iter) · line 60

Quoted 2 lines
boot/bootmeth_efi_mgr.c +1 -1
-       /* To be implemented */
+       ret = efi_init_obj_list();

Doesn't this start up the whole EFI system? Is there a cheaper way to see if the variable subsystem exists, or can work?

A fair bit of it at least. With the possible exception of launching EFI capsules (which shouldn't happen for a "normal" boot), I don't think this is very expensive though.

There currently isn't a way to only initialize the variable subsystem; we can't just call efi_init_variables() here since we have to also call efi_disks_register() and a later efi_init_obj_list() call would call efi_init_variables() again, which would leak memory.

Quoted 8 lines

Alternatively we could just unconditionally declare the efi_mgr bootmeth as "ready" (like you already do for sandbox). That would postpone initialization of the EFI subsystem until we actually execute this bootmeth.

But we need to do something before we switch more targets to standard boot since otherwise booting through the EFI boot manager is just plain broken.

Quoted 5 lines

Yes...

I don't have any great ideas on this. If we could get the EFI code better integrated into U-Boot then perhaps we would not need this 'monolithm' init?

You'll have to take that up with the maintainers of the EFI loader subsystem. I just want to repair the breakage that was introduced with bootstd.

Quoted 15 lines
Quoted 1 line

Yes, understood. Do you know how long it takes to do this step?

It is instant. But then this is on a fast machine with the EFI variables stored on the internal NVMe disk, which is plenty fast as well. And I haven't enabled any of the capsule or TPM stuff hich may take more time.

Quoted 8 lines

The control for this feature is CMD_BOOTEFI_BOOTMGR...I think it would be better to have BOOTEFI_BOOTMGR as well as CMD_BOOTEFI_BOOTMGR, since it is strange to have a CMD Kconfig in lib/efi_loader

I am OK with this patch as I don't see any alternative. We need to do something and we can always improve it if it causes problems.

Heinrich?