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.
This commit is contained in:
Lennart Poettering 2018-06-25 18:19:09 +02:00
parent f82ecab0a9
commit 0e2bc73274
3 changed files with 28 additions and 1 deletions

View 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 */

View 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) {

View 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;