]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: add get_os_indications_supported() helper
authorLennart Poettering <lennart@poettering.net>
Tue, 21 Sep 2021 20:13:23 +0000 (22:13 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 23 Sep 2021 15:24:28 +0000 (17:24 +0200)
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.

src/boot/efi/boot.c
src/boot/efi/util.c
src/boot/efi/util.h

index 9efd157a8ee692650186565b2a5914f72e5db9a5..b0e16f710699958c5c305730b5790039678dc89d 100644 (file)
@@ -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) {
index e500069d512309794664782898c3c7aabd63267a..13697c9433dfd173b85c8a05f1be377bf217e162 100644 (file)
@@ -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;
+}
index ca95514d72b664a7c094f9bdd11b78edbb70cbbe..fa17b18f42d33c7384c00d1b1b3b645feb9b975b 100644 (file)
@@ -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);