summaryrefslogtreecommitdiff
path: root/fallback.c
diff options
context:
space:
mode:
authorSteve McIntyre <steve@einval.com>2021-03-23 23:49:46 +0000
committerSteve McIntyre <steve@einval.com>2021-03-23 23:49:46 +0000
commit1251a7ba86fc40a6aad8b4fecdbca2b61808d9fa (patch)
tree2125fda549aaca55cb49a48d54be77dec7fbf3df /fallback.c
parent85b409232ce89b34626df9d72abedf5d4f5ccef6 (diff)
parent031e5cce385d3f96b1caa1d53495332a7eb03749 (diff)
downloadefi-boot-shim-debian/15.3-1.tar.gz
efi-boot-shim-debian/15.3-1.zip
Update upstream source from tag 'upstream/15.3'debian/15.3-1
Update to upstream version '15.3' with Debian dir 1b484f1c1ac270604a5a1451b34de4b0865c6211
Diffstat (limited to 'fallback.c')
-rw-r--r--fallback.c85
1 files changed, 57 insertions, 28 deletions
diff --git a/fallback.c b/fallback.c
index 12e8064c..8d89917a 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,10 +3,6 @@
* Copyright Red Hat, Inc.
* Copyright Peter Jones <pjones@redhat.com>
*/
-
-#include <efi.h>
-#include <efilib.h>
-
#include "shim.h"
#define NO_REBOOT L"FB_NO_REBOOT"
@@ -16,6 +12,9 @@ EFI_LOADED_IMAGE *this_image = NULL;
int
get_fallback_verbose(void)
{
+#ifdef FALLBACK_VERBOSE
+ return 1;
+#else
UINT8 *data = NULL;
UINTN dataSize = 0;
EFI_STATUS efi_status;
@@ -43,6 +42,7 @@ get_fallback_verbose(void)
if (data)
FreePool(data);
return state;
+#endif
}
#define VerbosePrintUnprefixed(fmt, ...) \
@@ -242,9 +242,9 @@ add_boot_option(EFI_DEVICE_PATH *hddp, EFI_DEVICE_PATH *fulldp,
cursor += DevicePathSize(hddp);
StrCpy((CHAR16 *)cursor, arguments);
- console_print(L"Creating boot entry \"%s\" with label \"%s\" "
- L"for file \"%s\"\n",
- varname, label, filename);
+ VerbosePrint(L"Creating boot entry \"%s\" with label \"%s\" "
+ L"for file \"%s\"\n",
+ varname, label, filename);
if (!first_new_option) {
first_new_option = DuplicateDevicePath(fulldp);
@@ -280,13 +280,11 @@ add_boot_option(EFI_DEVICE_PATH *hddp, EFI_DEVICE_PATH *fulldp,
}
bootorder = newbootorder;
nbootorder += 1;
-#ifdef DEBUG_FALLBACK
- console_print(L"nbootorder: %d\nBootOrder: ",
+ VerbosePrint(L"nbootorder: %d\nBootOrder: ",
nbootorder);
for (j = 0 ; j < nbootorder ; j++)
- console_print(L"%04x ", bootorder[j]);
- console_print(L"\n");
-#endif
+ VerbosePrintUnprefixed(L"%04x ", bootorder[j]);
+ VerbosePrintUnprefixed(L"\n");
return EFI_SUCCESS;
}
@@ -398,8 +396,9 @@ find_boot_option(EFI_DEVICE_PATH *dp, EFI_DEVICE_PATH *fulldp,
CHAR16 *filename, CHAR16 *label, CHAR16 *arguments,
UINT16 *optnum)
{
+ unsigned int label_size = StrLen(label)*2 + 2;
unsigned int size = sizeof(UINT32) + sizeof (UINT16) +
- StrLen(label)*2 + 2 + DevicePathSize(dp) +
+ label_size + DevicePathSize(dp) +
StrLen(arguments) * 2;
CHAR8 *data = AllocateZeroPool(size + 2);
@@ -411,15 +410,14 @@ find_boot_option(EFI_DEVICE_PATH *dp, EFI_DEVICE_PATH *fulldp,
*(UINT16 *)cursor = DevicePathSize(dp);
cursor += sizeof (UINT16);
StrCpy((CHAR16 *)cursor, label);
- cursor += StrLen(label)*2 + 2;
+ cursor += label_size;
CopyMem(cursor, dp, DevicePathSize(dp));
cursor += DevicePathSize(dp);
StrCpy((CHAR16 *)cursor, arguments);
- int i = 0;
- CHAR16 varname[] = L"Boot0000";
- CHAR16 hexmap[] = L"0123456789ABCDEF";
+ CHAR16 varname[256];
EFI_STATUS efi_status;
+ EFI_GUID vendor_guid = NullGuid;
UINTN max_candidate_size = calc_masked_boot_option_size(size);
CHAR8 *candidate = AllocateZeroPool(max_candidate_size);
@@ -428,11 +426,18 @@ find_boot_option(EFI_DEVICE_PATH *dp, EFI_DEVICE_PATH *fulldp,
return EFI_OUT_OF_RESOURCES;
}
- for(i = 0; i < nbootorder && i < 0x10000; i++) {
- varname[4] = hexmap[(bootorder[i] & 0xf000) >> 12];
- varname[5] = hexmap[(bootorder[i] & 0x0f00) >> 8];
- varname[6] = hexmap[(bootorder[i] & 0x00f0) >> 4];
- varname[7] = hexmap[(bootorder[i] & 0x000f) >> 0];
+ varname[0] = 0;
+ while (1) {
+ UINTN varname_size = sizeof(varname);
+ efi_status = gRT->GetNextVariableName(&varname_size, varname,
+ &vendor_guid);
+ if (EFI_ERROR(efi_status))
+ break;
+
+ if (StrLen(varname) != 8 || StrnCmp(varname, L"Boot", 4) ||
+ !isxdigit(varname[4]) || !isxdigit(varname[5]) ||
+ !isxdigit(varname[6]) || !isxdigit(varname[7]))
+ continue;
UINTN candidate_size = max_candidate_size;
efi_status = gRT->GetVariable(varname, &GV_GUID, NULL,
@@ -457,7 +462,7 @@ find_boot_option(EFI_DEVICE_PATH *dp, EFI_DEVICE_PATH *fulldp,
first_new_option_size = StrLen(arguments) * sizeof (CHAR16);
}
- *optnum = i;
+ *optnum = xtoi(varname + 4);
FreePool(candidate);
FreePool(data);
return EFI_SUCCESS;
@@ -475,8 +480,15 @@ set_boot_order(void)
oldbootorder = LibGetVariableAndSize(L"BootOrder", &GV_GUID, &size);
if (oldbootorder) {
+ int i;
nbootorder = size / sizeof (CHAR16);
bootorder = oldbootorder;
+
+ VerbosePrint(L"Original nbootorder: %d\nOriginal BootOrder: ",
+ nbootorder);
+ for (i = 0 ; i < nbootorder ; i++)
+ VerbosePrintUnprefixed(L"%04x ", bootorder[i]);
+ VerbosePrintUnprefixed(L"\n");
}
return EFI_SUCCESS;
@@ -500,7 +512,7 @@ update_boot_order(void)
UINTN j;
for (j = 0 ; j < size / sizeof (CHAR16); j++)
VerbosePrintUnprefixed(L"%04x ", newbootorder[j]);
- console_print(L"\n");
+ VerbosePrintUnprefixed(L"\n");
efi_status = gRT->GetVariable(L"BootOrder", &GV_GUID, NULL, &len, NULL);
if (efi_status == EFI_BUFFER_TOO_SMALL)
LibDeleteVariable(L"BootOrder", &GV_GUID);
@@ -600,7 +612,7 @@ err:
}
EFI_STATUS
-populate_stanza(CHAR16 *dirname, CHAR16 *filename, CHAR16 *csv)
+populate_stanza(CHAR16 *dirname, CHAR16 *filename UNUSED, CHAR16 *csv)
{
CHAR16 *file = csv;
VerbosePrint(L"CSV data: \"%s\"\n", csv);
@@ -933,6 +945,17 @@ try_start_first_option(EFI_HANDLE parent_image_handle)
EFI_STATUS efi_status;
EFI_HANDLE image_handle;
+ if (get_fallback_verbose()) {
+ int fallback_verbose_wait = 500000; /* default to 0.5s */
+#ifdef FALLBACK_VERBOSE_WAIT
+ fallback_verbose_wait = FALLBACK_VERBOSE_WAIT;
+#endif
+ console_print(L"Verbose enabled, sleeping for %d mseconds... "
+ L"Press the Pause key now to hold for longer.\n",
+ fallback_verbose_wait);
+ msleep(fallback_verbose_wait);
+ }
+
if (!first_new_option) {
return EFI_SUCCESS;
}
@@ -1082,7 +1105,7 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
return efi_status;
}
- console_print(L"System BootOrder not found. Initializing defaults.\n");
+ VerbosePrint(L"System BootOrder not found. Initializing defaults.\n");
set_boot_order();
@@ -1124,8 +1147,14 @@ reset:
console_print(L"Reset System\n");
if (get_fallback_verbose()) {
- console_print(L"Verbose enabled, sleeping for half a second\n");
- msleep(500000);
+ int fallback_verbose_wait = 500000; /* default to 0.5s */
+#ifdef FALLBACK_VERBOSE_WAIT
+ fallback_verbose_wait = FALLBACK_VERBOSE_WAIT;
+#endif
+ console_print(L"Verbose enabled, sleeping for %d mseconds... "
+ L"Press the Pause key now to hold for longer.\n",
+ fallback_verbose_wait);
+ msleep(fallback_verbose_wait);
}
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);