efi_loader: support EFI_OS_INDICATIONS_BOOT_TO_FW_UI
PATCH 1/1 efi_loader: support EFI_OS_INDICATIONS_BOOT_TO_FW_UI
EFI variable OsIndications have a bit EFI_OS_INDICATIONS_BOOT_TO_FW_UI indicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.
Support it by having autoboot.c asking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).
With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
--- common/autoboot.c | 4 +++- include/efi_loader.h | 2 ++ lib/efi_loader/efi_bootmgr.c | 45 ++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 4 ++++ 4 files changed, 54 insertions(+), 1 deletion(-)
common/autoboot.c +3 -1
@@ -11,6 +11,7 @@#include <cli.h> #include <command.h> #include <console.h> +#include <efi_loader.h> #include <env.h> #include <errno.h> #include <fdtdec.h>
@@ -503,7 +504,8 @@ void autoboot_command(const char *s) {debug ("### main_loop: bootcmd=\"%s\"\n" , s ? s :"<UNDEFINED>" ); -if (s && (stored_bootdelay ==-2 || +if (s && !(IS_ENABLED (CONFIG_EFI_BOOTMGR ) &&efi_should_abort_autoboot ()) && + (stored_bootdelay ==-2 || (stored_bootdelay !=-1 && !abortboot (stored_bootdelay)))) {bool lock;int prev;
include/efi_loader.h +2 -0
@@ -583,6 +583,8 @@ efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf,efi_status_t efi_bootmgr_update_media_device_boot_option (void );/* Delete selected boot option */ efi_status_t efi_bootmgr_delete_boot_option (u16 boot_index); +/* Check if autoboot should be aborted based on EFI vars */ +bool efi_should_abort_autoboot (void );/* Invoke EFI boot manager */ efi_status_t efi_bootmgr_run (void *fdt);/* search the boot option index in BootOrder */
lib/efi_loader/efi_bootmgr.c +45 -0
51 lines not on this page · raw message
lib/efi_loader/efi_setup.c +4 -0
@@ -156,6 +156,10 @@ static efi_status_t efi_init_os_indications(void) {u64 os_indications_supported =0 ; +if (IS_ENABLED (CONFIG_EFI_BOOTMGR )) + os_indications_supported |= +EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; +if (IS_ENABLED (CONFIG_EFI_HAVE_CAPSULE_SUPPORT )) os_indications_supported |=EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED ;
Signature · 1 line
2.51.2
Am 31. März 2026 21:18:51 MESZ schrieb Gary Guo <[email protected]>:
Quoted 4 lines
EFI variable OsIndications have a bit
EFI_OS_INDICATIONS_BOOT_TO_FW_UIindicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.
Quoted 8 lines
Support it by having
autoboot.casking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
Signed-off-by Gary Guo <[email protected]>
Thank you Gary for the patch. I am currently on travel and will have to look at it once I have returned.
@Ilias
Should we preferably integrate the detection of this bit into efi_init_early()?
Best regards
Heinrich
Quoted 113 lines
---
common/autoboot.c | 4 +++- include/efi_loader.h | 2 ++ lib/efi_loader/efi_bootmgr.c | 45 ++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 4 ++++ 4 files changed, 54 insertions(+), 1 deletion(-)common/autoboot.c +3
-1@@ -11,6 +11,7 @@#include <cli.h> #include <command.h> #include <console.h> +#include <efi_loader.h> #include <env.h> #include <errno.h> #include <fdtdec.h> @@ -503,7 +504,8 @@ void autoboot_command(const char *s) {debug ("### main_loop: bootcmd=\"%s\"\n" , s ? s :"<UNDEFINED>" ); -if (s && (stored_bootdelay ==-2 || +if (s && !(IS_ENABLED (CONFIG_EFI_BOOTMGR ) &&efi_should_abort_autoboot ()) && + (stored_bootdelay ==-2 || (stored_bootdelay !=-1 && !abortboot (stored_bootdelay)))) {bool lock;int prev;include/efi_loader.h +2
-0@@ -583,6 +583,8 @@ efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf,efi_status_t efi_bootmgr_update_media_device_boot_option (void );/* Delete selected boot option */ efi_status_t efi_bootmgr_delete_boot_option (u16 boot_index); +/* Check if autoboot should be aborted based on EFI vars */ +bool efi_should_abort_autoboot (void );/* Invoke EFI boot manager */ efi_status_t efi_bootmgr_run (void *fdt);/* search the boot option index in BootOrder */ lib/efi_loader/efi_bootmgr.c +45
-0@@ -1290,6 +1290,51 @@ out:return ret; } +/** +* efi_should_abort_autoboot() - check if autoboot should be aborted per EFI vars +* +* Return: true if autoboot should abort +*/ +bool efi_should_abort_autoboot (void ) +{ +efi_status_t ret; +u64 os_indications =0x0 ; +efi_uintn_t size; +efi_status_t r; + +/* Initialize EFI drivers */ + ret =efi_init_obj_list (); +if (ret !=EFI_SUCCESS ) { +log_err ("Error: Cannot initialize UEFI sub-system, r = %lu\n" , + ret & ~EFI_ERROR_MASK ); +return false; + } + + size =sizeof (os_indications); + r =efi_get_variable_int (u"OsIndications" , &efi_global_variable_guid, +NULL , &size, &os_indications,NULL ); +if (r !=EFI_SUCCESS || size !=sizeof (os_indications)) +return false; + +if (!(os_indications &EFI_OS_INDICATIONS_BOOT_TO_FW_UI )) +return false; + +/* Clear the BOOT_TO_FW_UI so next boot returns to normal */ + os_indications &= ~EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; + r =efi_set_variable_int (u"OsIndications" , + &efi_global_variable_guid, +EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS , +sizeof (os_indications), + &os_indications, false); + +if (r !=EFI_SUCCESS ) +log_err ("Setting %ls failed\n" ,L"OsIndications" ); + +return true; +} +/** * efi_bootmgr_run() - execute EFI boot manager * @fdt: Flat device tree lib/efi_loader/efi_setup.c +4
-0@@ -156,6 +156,10 @@ static efi_status_t efi_init_os_indications(void) {u64 os_indications_supported =0 ; +if (IS_ENABLED (CONFIG_EFI_BOOTMGR )) + os_indications_supported |= +EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; +if (IS_ENABLED (CONFIG_EFI_HAVE_CAPSULE_SUPPORT )) os_indications_supported |=EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED ;
Hi Heinrich,
Quoted 9 lines · Heinrich Schuchardt
Am 31. März 2026 21:18:51 MESZ schrieb Gary Guo <[email protected]>:
Quoted 7 lines
EFI variable OsIndications have a bit
EFI_OS_INDICATIONS_BOOT_TO_FW_UIindicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.Support it by having
autoboot.casking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).
Quoted 7 lines
Quoted 5 lines
With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
Signed-off-by Gary Guo <[email protected]>Thank you Gary for the patch. I am currently on travel and will have to look at it once I have returned.
On vacation here as well. I'll be off next week as well, nut I might have time to take a closer look
Quoted 3 lines
@Ilias
Should we preferably integrate the detection of this bit intoefi_init_early()?
Which part? This patch also touched EFI variables, which are not initialized in the eraly code.
Thanks
/Ilias
Quoted 121 lines
Best regards
Heinrich
Quoted 113 lines
---
common/autoboot.c | 4 +++- include/efi_loader.h | 2 ++ lib/efi_loader/efi_bootmgr.c | 45 ++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 4 ++++ 4 files changed, 54 insertions(+), 1 deletion(-)common/autoboot.c +3
-1@@ -11,6 +11,7 @@#include <cli.h> #include <command.h> #include <console.h> +#include <efi_loader.h> #include <env.h> #include <errno.h> #include <fdtdec.h> @@ -503,7 +504,8 @@ void autoboot_command(const char *s) {debug ("### main_loop: bootcmd=\"%s\"\n" , s ? s :"<UNDEFINED>" ); -if (s && (stored_bootdelay ==-2 || +if (s && !(IS_ENABLED (CONFIG_EFI_BOOTMGR ) &&efi_should_abort_autoboot ()) && + (stored_bootdelay ==-2 || (stored_bootdelay !=-1 && !abortboot (stored_bootdelay)))) {bool lock;int prev;include/efi_loader.h +2
-0@@ -583,6 +583,8 @@ efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf,efi_status_t efi_bootmgr_update_media_device_boot_option (void );/* Delete selected boot option */ efi_status_t efi_bootmgr_delete_boot_option (u16 boot_index); +/* Check if autoboot should be aborted based on EFI vars */ +bool efi_should_abort_autoboot (void );/* Invoke EFI boot manager */ efi_status_t efi_bootmgr_run (void *fdt);/* search the boot option index in BootOrder */ lib/efi_loader/efi_bootmgr.c +45
-0@@ -1290,6 +1290,51 @@ out:return ret; } +/** +* efi_should_abort_autoboot() - check if autoboot should be aborted per EFI vars +* +* Return: true if autoboot should abort +*/ +bool efi_should_abort_autoboot (void ) +{ +efi_status_t ret; +u64 os_indications =0x0 ; +efi_uintn_t size; +efi_status_t r; + +/* Initialize EFI drivers */ + ret =efi_init_obj_list (); +if (ret !=EFI_SUCCESS ) { +log_err ("Error: Cannot initialize UEFI sub-system, r = %lu\n" , + ret & ~EFI_ERROR_MASK ); +return false; + } + + size =sizeof (os_indications); + r =efi_get_variable_int (u"OsIndications" , &efi_global_variable_guid, +NULL , &size, &os_indications,NULL ); +if (r !=EFI_SUCCESS || size !=sizeof (os_indications)) +return false; + +if (!(os_indications &EFI_OS_INDICATIONS_BOOT_TO_FW_UI )) +return false; + +/* Clear the BOOT_TO_FW_UI so next boot returns to normal */ + os_indications &= ~EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; + r =efi_set_variable_int (u"OsIndications" , + &efi_global_variable_guid, +EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS , +sizeof (os_indications), + &os_indications, false); + +if (r !=EFI_SUCCESS ) +log_err ("Setting %ls failed\n" ,L"OsIndications" ); + +return true; +} +/** * efi_bootmgr_run() - execute EFI boot manager * @fdt: Flat device tree lib/efi_loader/efi_setup.c +4
-0@@ -156,6 +156,10 @@ static efi_status_t efi_init_os_indications(void) {u64 os_indications_supported =0 ; +if (IS_ENABLED (CONFIG_EFI_BOOTMGR )) + os_indications_supported |= +EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; +if (IS_ENABLED (CONFIG_EFI_HAVE_CAPSULE_SUPPORT )) os_indications_supported |=EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED ;
Hi Gary,
Quoted 17 lines · Gary Guo
efi_loader: supportEFI_OS_INDICATIONS_BOOT_TO_FW_UIEFI variable OsIndications have a bit
EFI_OS_INDICATIONS_BOOT_TO_FW_UIindicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.Support it by having
autoboot.casking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
Signed-off-by Gary Guo <[email protected]>
lib/efi_loader/efi_bootmgr.c out: · line 1295
Quoted 6 lines
lib/efi_loader/efi_bootmgr.c +6
-0@@ -1290,6 +1290,51 @@ out: +bool efi_should_abort_autoboot (void ) +{ +efi_status_t ret; +u64 os_indications =0x0 ; +efi_uintn_t size; +efi_status_t r;
(I'm leaving the proper review to Ilias & Heinrich, this is just a few nits and a though)
Please can you use a single variable name for both efi_status_t variables.
lib/efi_loader/efi_bootmgr.c out: · line 1309
Quoted 4 lines
lib/efi_loader/efi_bootmgr.c +4
-0+ ret =efi_init_obj_list (); +if (ret !=EFI_SUCCESS ) { +log_err ("Error: Cannot initialize UEFI sub-system, r = %lu\n" , + ret & ~EFI_ERROR_MASK );
The log message says "r = " but prints ret. The similar message in efi_bootmgr_run() just prints the value without a prefix.
I would also like to see the code which adjusts the variable placed in a function.
Regards,
Simon
Quoted 30 lines · Simon Glass
Hi Gary,
Quoted 17 lines · Gary Guo
efi_loader: supportEFI_OS_INDICATIONS_BOOT_TO_FW_UIEFI variable OsIndications have a bit
EFI_OS_INDICATIONS_BOOT_TO_FW_UIindicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.Support it by having
autoboot.casking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
Signed-off-by Gary Guo <[email protected]>lib/efi_loader/efi_bootmgr.c out: · line 1295
Quoted 6 lines
lib/efi_loader/efi_bootmgr.c +6
-0@@ -1290,6 +1290,51 @@ out: +bool efi_should_abort_autoboot (void ) +{ +efi_status_t ret; +u64 os_indications =0x0 ; +efi_uintn_t size; +efi_status_t r;(I'm leaving the proper review to Ilias & Heinrich, this is just a few nits and a though)
Quoted 1 line
Please can you use a single variable name for both
efi_status_tvariables.
Ah, I think I copied the init part from somewhere else and forget to merge the variable names.
I'll adjust the variable name in the next version after receiving more reviews.
Quoted 8 lines
lib/efi_loader/efi_bootmgr.c out: · line 1309
Quoted 5 lines
lib/efi_loader/efi_bootmgr.c +4
-0+ ret =efi_init_obj_list (); +if (ret !=EFI_SUCCESS ) { +log_err ("Error: Cannot initialize UEFI sub-system, r = %lu\n" , + ret & ~EFI_ERROR_MASK );The log message says "r = " but prints ret. The similar message in
efi_bootmgr_run()just prints the value without a prefix.
Sorry, what do you mean by "without a prefix"? I think the code is identical to the one in efi_bootmgr_run?
Quoted 3 lines
I would also like to see the code which adjusts the variable placed in a function.
You mean the bit clearing part? What benefit does that provide, considering that this is just a single function call?
Thanks,
Gary
Hi Gary,
Quoted 45 lines · Gary Guo
Quoted 30 lines · Simon Glass
Hi Gary,
Quoted 17 lines · Gary Guo
efi_loader: supportEFI_OS_INDICATIONS_BOOT_TO_FW_UIEFI variable OsIndications have a bit
EFI_OS_INDICATIONS_BOOT_TO_FW_UIindicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.Support it by having
autoboot.casking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
Signed-off-by Gary Guo <[email protected]>lib/efi_loader/efi_bootmgr.c out: · line 1295
Quoted 6 lines
lib/efi_loader/efi_bootmgr.c +6
-0@@ -1290,6 +1290,51 @@ out: +bool efi_should_abort_autoboot (void ) +{ +efi_status_t ret; +u64 os_indications =0x0 ; +efi_uintn_t size; +efi_status_t r;(I'm leaving the proper review to Ilias & Heinrich, this is just a few nits and a though)
Quoted 1 line
Please can you use a single variable name for both
efi_status_tvariables.Ah, I think I copied the init part from somewhere else and forget to merge the variable names.
I'll adjust the variable name in the next version after receiving more reviews.
Quoted 6 lines
Quoted 5 lines
lib/efi_loader/efi_bootmgr.c +4
-0+ ret =efi_init_obj_list (); +if (ret !=EFI_SUCCESS ) { +log_err ("Error: Cannot initialize UEFI sub-system, r = %lu\n" , + ret & ~EFI_ERROR_MASK );
Quoted 5 lines
Quoted 2 lines
The log message says "r = " but prints ret. The similar message in
efi_bootmgr_run()just prints the value without a prefix.Sorry, what do you mean by "without a prefix"? I think the code is identical to the one in
efi_bootmgr_run?
I mean you don't need r = in the message. You could say (err %lu) perhaps?
Quoted 7 lines
Quoted 4 lines
I would also like to see the code which adjusts the variable placed in a function.
You mean the bit clearing part? What benefit does that provide, considering that this is just a single function call?
There is reading and write. Being able to control that could end up in a command at some point. It is a useful feature. Up to you though.
Regards,
Simon
Am 3. April 2026 18:31:14 MESZ schrieb Simon Glass <[email protected]>:
Quoted 47 lines
Hi Gary,
Quoted 44 lines · Gary Guo
Quoted 30 lines · Simon Glass
Hi Gary,
Quoted 17 lines · Gary Guo
efi_loader: supportEFI_OS_INDICATIONS_BOOT_TO_FW_UIEFI variable OsIndications have a bit
EFI_OS_INDICATIONS_BOOT_TO_FW_UIindicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.Support it by having
autoboot.casking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
Signed-off-by Gary Guo <[email protected]>lib/efi_loader/efi_bootmgr.c out: · line 1295
Quoted 6 lines
lib/efi_loader/efi_bootmgr.c +6
-0@@ -1290,6 +1290,51 @@ out: +bool efi_should_abort_autoboot (void ) +{ +efi_status_t ret; +u64 os_indications =0x0 ; +efi_uintn_t size; +efi_status_t r;(I'm leaving the proper review to Ilias & Heinrich, this is just a few nits and a though)
Quoted 1 line
Please can you use a single variable name for both
efi_status_tvariables.Ah, I think I copied the init part from somewhere else and forget to merge the variable names.
I'll adjust the variable name in the next version after receiving more reviews.
Quoted 5 lines
Quoted 5 lines
lib/efi_loader/efi_bootmgr.c +4
-0+ ret =efi_init_obj_list (); +if (ret !=EFI_SUCCESS ) { + log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret &
The return value does not help anybody to understand what went wrong as there are a lot of different failure modes.
We should write specific messages inside the routine and not a message in the caller.
It might make sense to have a generic translation of EFI return codes to a string message in vsprintf.c. Which end user would know what error 14 is?
Best regards
Heinrich
~EFI_ERROR_MASK);
Quoted 22 lines
Quoted 6 lines
Quoted 3 lines
The log message says "r = " but prints ret. The similar message in
efi_bootmgr_run()just prints the value without a prefix.Sorry, what do you mean by "without a prefix"? I think the code is identical to the one in
efi_bootmgr_run?I mean you don't need r = in the message. You could say (err %lu) perhaps?
Quoted 7 lines
Quoted 4 lines
I would also like to see the code which adjusts the variable placed in a function.
You mean the bit clearing part? What benefit does that provide, considering that this is just a single function call?
There is reading and write. Being able to control that could end up in a command at some point. It is a useful feature. Up to you though.
Regards,
Simon
Quoted 32 lines · Gary Guo
EFI variable OsIndications have a bit
EFI_OS_INDICATIONS_BOOT_TO_FW_UIindicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.Support it by having
autoboot.casking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
Signed-off-by Gary Guo <[email protected]>--- common/autoboot.c | 4 +++- include/efi_loader.h | 2 ++ lib/efi_loader/efi_bootmgr.c | 45 ++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 4 ++++ 4 files changed, 54 insertions(+), 1 deletion(-)common/autoboot.c +1
-0@@ -11,6 +11,7 @@#include <cli.h> #include <command.h> #include <console.h> +#include <efi_loader.h> #include <env.h> #include <errno.h> #include <fdtdec.h>
common/autoboot.c void autoboot_command(const char *s) · line 507
Quoted 5 lines
common/autoboot.c +1
-1@@ -503,7 +504,8 @@ void autoboot_command(const char *s) {debug ("### main_loop: bootcmd=\"%s\"\n" , s ? s :"<UNDEFINED>" ); - if (s && (stored_bootdelay == -2 || + if (s && !(IS_ENABLED(CONFIG_EFI_BOOTMGR) && efi_should_abort_autoboot()) &&
I do not understand why the logic should depend on CONFIG_EFI_BOOTMGR instead of CONFIG_EFI_LOADER. It seems applicable whenever we support UEFI.
Quoted 22 lines
common/autoboot.c +1
-0+ (stored_bootdelay == -2 || (stored_bootdelay != -1 && !abortboot(stored_bootdelay)))) {bool lock;int prev;include/efi_loader.h +2
-0@@ -583,6 +583,8 @@ efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf,efi_status_t efi_bootmgr_update_media_device_boot_option (void );/* Delete selected boot option */ efi_status_t efi_bootmgr_delete_boot_option (u16 boot_index); +/* Check if autoboot should be aborted based on EFI vars */ +bool efi_should_abort_autoboot (void );/* Invoke EFI boot manager */ efi_status_t efi_bootmgr_run (void *fdt);/* search the boot option index in BootOrder */ lib/efi_loader/efi_bootmgr.c +0
-0
lib/efi_loader/efi_bootmgr.c out: · line 1294
Quoted 5 lines
lib/efi_loader/efi_bootmgr.c +2
-0@@ -1290,6 +1290,51 @@ out:return ret; } +/** +* efi_should_abort_autoboot() - check if autoboot should be aborted per EFI vars
Please, mention the relevant flag.
lib/efi_loader/efi_bootmgr.c out: · line 1306
Quoted 12 lines
lib/efi_loader/efi_bootmgr.c +12
-0+* +* Return: true if autoboot should abort +*/ +bool efi_should_abort_autoboot (void ) +{ +efi_status_t ret; +u64 os_indications =0x0 ; +efi_uintn_t size; +efi_status_t r; + +/* Initialize EFI drivers */ + ret =efi_init_obj_list ();
@Ilias:
Essentially this ends up in always running efi_init_obj_list() if we have UEFI enabled.
Shouldn't we then replace all invocations of efi_init_obj_list() by a single call after preboot but before EVT_POST_PREBOOT?
Best regards
Heinrich
Quoted 49 lines
lib/efi_loader/efi_bootmgr.c +31
-0+if (ret !=EFI_SUCCESS ) { +log_err ("Error: Cannot initialize UEFI sub-system, r = %lu\n" , + ret & ~EFI_ERROR_MASK ); +return false; + } + + size =sizeof (os_indications); + r =efi_get_variable_int (u"OsIndications" , &efi_global_variable_guid, +NULL , &size, &os_indications,NULL ); +if (r !=EFI_SUCCESS || size !=sizeof (os_indications)) +return false; + +if (!(os_indications &EFI_OS_INDICATIONS_BOOT_TO_FW_UI )) +return false; + +/* Clear the BOOT_TO_FW_UI so next boot returns to normal */ + os_indications &= ~EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; + r =efi_set_variable_int (u"OsIndications" , + &efi_global_variable_guid, +EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS , +sizeof (os_indications), + &os_indications, false); + +if (r !=EFI_SUCCESS ) +log_err ("Setting %ls failed\n" ,L"OsIndications" ); + +return true; +} +/** * efi_bootmgr_run() - execute EFI boot manager * @fdt: Flat device tree lib/efi_loader/efi_setup.c +4
-0@@ -156,6 +156,10 @@ static efi_status_t efi_init_os_indications(void) {u64 os_indications_supported =0 ; +if (IS_ENABLED (CONFIG_EFI_BOOTMGR )) + os_indications_supported |= +EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; +if (IS_ENABLED (CONFIG_EFI_HAVE_CAPSULE_SUPPORT )) os_indications_supported |=EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED ;
Hi Heinrich
Quoted 37 lines · Heinrich Schuchardt
Quoted 35 lines · Gary Guo
EFI variable OsIndications have a bit
EFI_OS_INDICATIONS_BOOT_TO_FW_UIindicating that the OS (or next stage bootloader) requests booting into firmware UI instead of continuing autoboot process.Support it by having
autoboot.casking EFI bootmgr if boot should continue, which checks and clear the bit (so the next boot continue as normal).With this change, systemd-boot will show a "Reboot Into Firmware Interface" option which will be able to drop back to u-boot. This can be useful if bootdelay is configured to be -2.
Signed-off-by Gary Guo <[email protected]>--- common/autoboot.c | 4 +++- include/efi_loader.h | 2 ++ lib/efi_loader/efi_bootmgr.c | 45 ++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 4 ++++ 4 files changed, 54 insertions(+), 1 deletion(-)common/autoboot.c +1
-0@@ -11,6 +11,7 @@#include <cli.h> #include <command.h> #include <console.h> +#include <efi_loader.h> #include <env.h> #include <errno.h> #include <fdtdec.h> @@ -503,7 +504,8 @@ void autoboot_command(const char *s) {debug ("### main_loop: bootcmd=\"%s\"\n" , s ? s :"<UNDEFINED>" );
Quoted 5 lines
common/autoboot.c void autoboot_command(const char *s) · line 507
Quoted 2 lines
common/autoboot.c +1
-1- if (s && (stored_bootdelay == -2 || + if (s && !(IS_ENABLED(CONFIG_EFI_BOOTMGR) && efi_should_abort_autoboot()) &&I do not understand why the logic should depend on
CONFIG_EFI_BOOTMGRinstead ofCONFIG_EFI_LOADER. It seems applicable whenever we support UEFI.
That's a good point, but we install some protocols that are useful for booting distros only when we boot via the bootmgr e.g the load_initrd stuff. OTOH grub, systemd etc install their own version of the protocl nowadays so I don't mind if we allow it in the generic case as well.
Quoted 47 lines
Quoted 24 lines
common/autoboot.c +1
-0+ (stored_bootdelay == -2 || (stored_bootdelay != -1 && !abortboot(stored_bootdelay)))) {bool lock;int prev;include/efi_loader.h +2
-0@@ -583,6 +583,8 @@ efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf,efi_status_t efi_bootmgr_update_media_device_boot_option (void );/* Delete selected boot option */ efi_status_t efi_bootmgr_delete_boot_option (u16 boot_index); +/* Check if autoboot should be aborted based on EFI vars */ +bool efi_should_abort_autoboot (void );/* Invoke EFI boot manager */ efi_status_t efi_bootmgr_run (void *fdt);/* search the boot option index in BootOrder */ lib/efi_loader/efi_bootmgr.c +0
-0lib/efi_loader/efi_bootmgr.c out: · line 1294
Quoted 5 lines
lib/efi_loader/efi_bootmgr.c +2
-0@@ -1290,6 +1290,51 @@ out:return ret; } +/** +* efi_should_abort_autoboot() - check if autoboot should be aborted per EFI vars Please, mention the relevant flag.
lib/efi_loader/efi_bootmgr.c out: · line 1306
Quoted 12 lines
lib/efi_loader/efi_bootmgr.c +12
-0+* +* Return: true if autoboot should abort +*/ +bool efi_should_abort_autoboot (void ) +{ +efi_status_t ret; +u64 os_indications =0x0 ; +efi_uintn_t size; +efi_status_t r; + +/* Initialize EFI drivers */ + ret =efi_init_obj_list ();@Ilias:
Quoted 5 lines
Essentially this ends up in always running
efi_init_obj_list()if we have UEFI enabled.Shouldn't we then replace all invocations of
efi_init_obj_list()by a single call after preboot but beforeEVT_POST_PREBOOT?
I agree with you here and if we do that, your point above to depend on EFI_LOADER instead of the bootmanager makes more sense.
Tom keeping in mind that more and more distros work out of the box with U-Boot, can we bite the bullet and always init the subsystem early now ?
If people don't plan to boot with EFI that can always disable the EFI_LOADER.
Thanks
/Ilias
Quoted 55 lines
Best regards
Heinrich
Quoted 49 lines
lib/efi_loader/efi_bootmgr.c +31
-0+if (ret !=EFI_SUCCESS ) { +log_err ("Error: Cannot initialize UEFI sub-system, r = %lu\n" , + ret & ~EFI_ERROR_MASK ); +return false; + } + + size =sizeof (os_indications); + r =efi_get_variable_int (u"OsIndications" , &efi_global_variable_guid, +NULL , &size, &os_indications,NULL ); +if (r !=EFI_SUCCESS || size !=sizeof (os_indications)) +return false; + +if (!(os_indications &EFI_OS_INDICATIONS_BOOT_TO_FW_UI )) +return false; + +/* Clear the BOOT_TO_FW_UI so next boot returns to normal */ + os_indications &= ~EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; + r =efi_set_variable_int (u"OsIndications" , + &efi_global_variable_guid, +EFI_VARIABLE_NON_VOLATILE | +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS , +sizeof (os_indications), + &os_indications, false); + +if (r !=EFI_SUCCESS ) +log_err ("Setting %ls failed\n" ,L"OsIndications" ); + +return true; +} +/** * efi_bootmgr_run() - execute EFI boot manager * @fdt: Flat device tree lib/efi_loader/efi_setup.c +4
-0@@ -156,6 +156,10 @@ static efi_status_t efi_init_os_indications(void) {u64 os_indications_supported =0 ; +if (IS_ENABLED (CONFIG_EFI_BOOTMGR )) + os_indications_supported |= +EFI_OS_INDICATIONS_BOOT_TO_FW_UI ; +if (IS_ENABLED (CONFIG_EFI_HAVE_CAPSULE_SUPPORT )) os_indications_supported |=EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED ;