sd-boot: write the IDs of all discovered entries to an EFI variable
authorLennart Poettering <lennart@poettering.net>
Mon, 25 Jun 2018 16:19:09 +0000 (18:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 16 Oct 2018 14:44:34 +0000 (16:44 +0200)
This is primarily useful for debugging, but can be useful for other
purposes too. For example userspace could check whether "auto-windows"
is included in the list, before triggering a boot-into-windows
operation.

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

index 02c46c4..7fff880 100644 (file)
@@ -2028,6 +2028,29 @@ static VOID config_free(Config *config) {
         FreePool(config->entry_oneshot);
 }
 
+static VOID config_write_entries_to_variable(Config *config) {
+        _cleanup_freepool_ CHAR16 *buffer = NULL;
+        UINTN i, sz = 0;
+        CHAR16 *p;
+
+        for (i = 0; i < config->entry_count; i++)
+                sz += StrLen(config->entries[i]->id) + 1;
+
+        p = buffer = AllocatePool(sz * sizeof(CHAR16));
+
+        for (i = 0; i < config->entry_count; i++) {
+                UINTN l;
+
+                l = StrLen(config->entries[i]->id) + 1;
+                CopyMem(p, config->entries[i]->id, l * sizeof(CHAR16));
+
+                p += l;
+        }
+
+        /* Store the full list of discovered entries. */
+        (void) efivar_set_raw(&loader_guid, L"LoaderEntries", buffer, (UINT8*) p - (UINT8*) buffer, FALSE);
+}
+
 EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         _cleanup_freepool_ CHAR16 *infostr = NULL, *typestr = NULL;
         CHAR8 *b;
@@ -2119,6 +2142,8 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                 goto out;
         }
 
+        config_write_entries_to_variable(&config);
+
         config_title_generate(&config);
 
         /* select entry by configured pattern or EFI LoaderDefaultEntry= variable */
index e286b14..fd4be68 100644 (file)
@@ -10,7 +10,7 @@
  * the (ESP)\loader\entries\<vendor>-<revision>.conf convention and the
  * associated EFI variables.
  */
-static const EFI_GUID loader_guid = { 0x4a67b082, 0x0a4c, 0x41cf, {0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f} };
+const EFI_GUID loader_guid = { 0x4a67b082, 0x0a4c, 0x41cf, {0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f} };
 
 #ifdef __x86_64__
 UINT64 ticks_read(VOID) {
index ae06444..40ede66 100644 (file)
@@ -50,3 +50,5 @@ static inline void FileHandleClosep(EFI_FILE_HANDLE *handle) {
 
         uefi_call_wrapper((*handle)->Close, 1, *handle);
 }
+
+const EFI_GUID loader_guid;