From: Lennart Poettering Date: Tue, 21 Sep 2021 20:13:23 +0000 (+0200) Subject: boot: add get_os_indications_supported() helper X-Git-Tag: v250-rc1~629^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a6249127eeef8c949a3aa5fad7914cf5f755589;p=thirdparty%2Fsystemd.git boot: add get_os_indications_supported() helper We inquire the EFI var for this at two places, let's add a helper that queries it and gracefully handles it if we can't get it, by returning a zero mask, i.e. no features supported. --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 9efd157a8ee..b0e16f71069 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -367,7 +367,7 @@ static UINTN entry_lookup_key(Config *config, UINTN start, CHAR16 key) { } static VOID print_status(Config *config, CHAR16 *loaded_image_path) { - UINT64 key, indvar; + UINT64 key; UINTN timeout; BOOLEAN modevar; _cleanup_freepool_ CHAR16 *partstr = NULL, *defaultstr = NULL; @@ -395,8 +395,7 @@ static VOID print_status(Config *config, CHAR16 *loaded_image_path) { if (shim_loaded()) Print(L"Shim: present\n"); - if (efivar_get_uint64_le(EFI_GLOBAL_GUID, L"OsIndicationsSupported", &indvar) == EFI_SUCCESS) - Print(L"OsIndicationsSupported: %d\n", indvar); + Print(L"OsIndicationsSupported: %d\n", get_os_indications_supported()); Print(L"\n--- press key ---\n\n"); console_key_read(&key, 0); @@ -2427,8 +2426,6 @@ static VOID config_load_all_entries( const CHAR16 *loaded_image_path, EFI_FILE *root_dir) { - UINT64 osind = 0; - assert(config); assert(loaded_image); assert(loaded_image_path); @@ -2456,13 +2453,11 @@ static VOID config_load_all_entries( config_entry_add_loader_auto(config, loaded_image->DeviceHandle, root_dir, loaded_image_path, L"auto-efi-default", '\0', L"EFI Default Loader", NULL); - if (config->auto_firmware && efivar_get_uint64_le(EFI_GLOBAL_GUID, L"OsIndicationsSupported", &osind) == EFI_SUCCESS) { - if (osind & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) - config_entry_add_call(config, - L"auto-reboot-to-firmware-setup", - L"Reboot Into Firmware Interface", - reboot_into_firmware); - } + if (config->auto_firmware && (get_os_indications_supported() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) + config_entry_add_call(config, + L"auto-reboot-to-firmware-setup", + L"Reboot Into Firmware Interface", + reboot_into_firmware); } EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index e500069d512..13697c9433d 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -743,3 +743,17 @@ EFI_STATUS open_directory( *ret = TAKE_PTR(dir); return EFI_SUCCESS; } + +UINT64 get_os_indications_supported(VOID) { + UINT64 osind; + EFI_STATUS err; + + /* Returns the supported OS indications. If we can't acquire it, returns a zeroed out mask, i.e. no + * supported features. */ + + err = efivar_get_uint64_le(EFI_GLOBAL_GUID, L"OsIndicationsSupported", &osind); + if (EFI_ERROR(err)) + return 0; + + return osind; +} diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index ca95514d72b..fa17b18f42d 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -144,3 +144,5 @@ static inline void *PHYSICAL_ADDRESS_TO_POINTER(EFI_PHYSICAL_ADDRESS addr) { return (void*) (UINTN) addr; } + +UINT64 get_os_indications_supported(VOID);