From: Lennart Poettering Date: Mon, 25 Jun 2018 16:19:09 +0000 (+0200) Subject: sd-boot: write the IDs of all discovered entries to an EFI variable X-Git-Tag: v240~522^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0e2bc7327428b410feb0e7d7a23ca07f0e810222;p=thirdparty%2Fsystemd.git sd-boot: write the IDs of all discovered entries to an EFI variable 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. --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 02c46c44c2e..7fff8804144 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -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 */ diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index e286b14bcc6..fd4be681a53 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -10,7 +10,7 @@ * the (ESP)\loader\entries\-.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) { diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index ae064440142..40ede66d4a9 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -50,3 +50,5 @@ static inline void FileHandleClosep(EFI_FILE_HANDLE *handle) { uefi_call_wrapper((*handle)->Close, 1, *handle); } + +const EFI_GUID loader_guid;