:: commit 39fb6c6ccf552dc81e32006f8d71d8dbe01b8f3a

lg <abbix@riseup.net> — 2026-03-11 23:37

parents: eef3bf757a

protos/efi_boot_entry: fix inconsistencies

diff --git a/common/menu.c b/common/menu.c
index abdfdc1e..b967d0b0 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -123,7 +123,7 @@ static const char *VALID_KEYS[] = {
     "GPT_UUID",
     "IMAGE_PATH",
 	"DTB_PATH",
-    "REBOOT_FOR_BITLOCKER",
+    "ENTRY",
     NULL
 };
 
diff --git a/common/protos/efi_boot_entry.c b/common/protos/efi_boot_entry.c
index 86ac831b..62062cd6 100644
--- a/common/protos/efi_boot_entry.c
+++ b/common/protos/efi_boot_entry.c
@@ -7,114 +7,113 @@
 #include <stdbool.h>
 
 static bool uefi_string_matches(CHAR16 *desc, CHAR16 *target) {
-  while (*target) {
-    CHAR16 a = *desc >= L'a' && *desc <= L'z' ? *desc - 32 : *desc;
-    CHAR16 b = *target >= L'a' && *target <= L'z' ? *target - 32 : *target;
-    if (a != b)
-      return false;
-    desc++;
-    target++;
-  }
-  return *desc == L'\0';
+    while (*target) {
+        CHAR16 a = *desc >= L'a' && *desc <= L'z' ? *desc - 32 : *desc;
+        CHAR16 b = *target >= L'a' && *target <= L'z' ? *target - 32 : *target;
+        if (a != b)
+            return false;
+        desc++;
+        target++;
+    }
+    return *desc == L'\0';
 }
 
 static void format_boot_var(CHAR16 *out, UINT16 num) {
-  out[0] = L'B';
-  out[1] = L'o';
-  out[2] = L'o';
-  out[3] = L't';
-  out[4] = L"0123456789ABCDEF"[(num >> 12) & 0xF];
-  out[5] = L"0123456789ABCDEF"[(num >> 8) & 0xF];
-  out[6] = L"0123456789ABCDEF"[(num >> 4) & 0xF];
-  out[7] = L"0123456789ABCDEF"[(num >> 0) & 0xF];
-  out[8] = L'\0';
+    out[0] = L'B';
+    out[1] = L'o';
+    out[2] = L'o';
+    out[3] = L't';
+    out[4] = L"0123456789ABCDEF"[(num >> 12) & 0xF];
+    out[5] = L"0123456789ABCDEF"[(num >> 8) & 0xF];
+    out[6] = L"0123456789ABCDEF"[(num >> 4) & 0xF];
+    out[7] = L"0123456789ABCDEF"[(num >> 0) & 0xF];
+    out[8] = L'\0';
 }
 
 static bool find_boot_entry(CHAR16 *entry, uint16_t *out) {
-  EFI_STATUS status;
-  uint16_t boot_order[128];
-  size_t size = sizeof(boot_order);
-  EFI_GUID global_variable = EFI_GLOBAL_VARIABLE;
+    EFI_STATUS status;
+    uint16_t boot_order[128];
+    size_t size = sizeof(boot_order);
+    EFI_GUID global_variable = EFI_GLOBAL_VARIABLE;
 
-  status =
-      gRT->GetVariable(L"BootOrder", &global_variable, NULL, &size, boot_order);
+    status = gRT->GetVariable(L"BootOrder", &global_variable, NULL, &size, boot_order);
 
-  if (EFI_ERROR(status)) {
-    panic(true, "reboot_for_bitlocker: Failed to get BootOrder variable (%X)",
-          (uint64_t)status);
-  }
+    if (EFI_ERROR(status)) {
+        panic(true, "efi_boot_entry: Failed to get BootOrder variable (%X)",
+            (uint64_t)status);
+    }
 
-  size_t count = size / sizeof(uint16_t);
+    size_t count = size / sizeof(uint16_t);
 
-  for (size_t i = 0; i < count; i++) {
-    CHAR16 var_name[9];
+    for (size_t i = 0; i < count; i++) {
+        CHAR16 var_name[9];
 
-    format_boot_var(var_name, boot_order[i]);
+        format_boot_var(var_name, boot_order[i]);
 
-    uint8_t buf[128];
-    size_t buf_size = sizeof(buf);
+        uint8_t buf[128];
+        size_t buf_size = sizeof(buf);
 
-    status = gRT->GetVariable(var_name, &global_variable, NULL, &buf_size, buf);
-    if (EFI_ERROR(status)) {
-      continue;
-    }
+        status = gRT->GetVariable(var_name, &global_variable, NULL, &buf_size, buf);
+        
+        if (EFI_ERROR(status))
+            continue;
 
-    /* Get the description */
-    CHAR16 *desc = (CHAR16 *)(buf + sizeof(uint32_t) + sizeof(uint16_t));
+        /* Get the description */
+        CHAR16 *desc = (CHAR16 *)(buf + sizeof(uint32_t) + sizeof(uint16_t));
 
-    if (uefi_string_matches(desc, entry)) {
-      *out = boot_order[i];
-      return true;
+        if (uefi_string_matches(desc, entry)) {
+            *out = boot_order[i];
+            return true;
+        }
     }
-  }
 
-  return false;
+    return false;
 }
 
 noreturn void efi_boot_entry(char *config) {
-  char *boot_entry = config_get_value(config, 0, "entry");
+    char *boot_entry = config_get_value(config, 0, "entry");
 
-  if (boot_entry == NULL) {
-    panic(true, "efi: No entry specified for efi_boot_entry protocol");
-  }
+    if (boot_entry == NULL) {
+        panic(true, "efi_boot_entry: No entry specified");
+    }
 
-  /* Convert entry string to UTF-16 */
-  CHAR16 boot_entry_utf16[128];
-  size_t i;
+    /* Convert entry string to UTF-16 */
+    CHAR16 boot_entry_utf16[128];
+    size_t i;
 
-  for (i = 0;
-       i < sizeof(boot_entry_utf16) / sizeof(CHAR16) - 1 && boot_entry[i];
-       i++) {
-    boot_entry_utf16[i] = (CHAR16)boot_entry[i];
-  }
+    for (i = 0;
+        i < sizeof(boot_entry_utf16) / sizeof(CHAR16) - 1 && boot_entry[i];
+        i++) {
+        boot_entry_utf16[i] = (CHAR16)boot_entry[i];
+    }
 
-  boot_entry_utf16[i] = L'\0';
+    boot_entry_utf16[i] = L'\0';
 
-  /* Find the desired boot entry */
-  uint16_t boot_next = 0;
+    /* Find the desired boot entry */
+    uint16_t boot_next = 0;
 
-  if (!find_boot_entry(boot_entry_utf16, &boot_next)) {
-    panic(true, "efi_boot_entry: Failed to find boot entry '%s'", boot_entry);
-  }
+    if (!find_boot_entry(boot_entry_utf16, &boot_next)) {
+        panic(true, "efi_boot_entry: Failed to find boot entry '%s'", boot_entry);
+    }
 
-  EFI_GUID global_variable = EFI_GLOBAL_VARIABLE;
+    EFI_GUID global_variable = EFI_GLOBAL_VARIABLE;
 
-  /* Set BootNext to it */
-  EFI_STATUS status = gRT->SetVariable(L"BootNext", &global_variable,
+    /* Set BootNext to it */
+    EFI_STATUS status = gRT->SetVariable(L"BootNext", &global_variable,
                                        EFI_VARIABLE_NON_VOLATILE |
-                                           EFI_VARIABLE_BOOTSERVICE_ACCESS |
-                                           EFI_VARIABLE_RUNTIME_ACCESS,
+                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
+                                       EFI_VARIABLE_RUNTIME_ACCESS,
                                        sizeof(boot_next), &boot_next);
 
-  if (status) {
-    panic(true, "efi_boot_entry: Failed to set BootNext variable (%X)",
-          (uint64_t)status);
-  }
+    if (status) {
+        panic(true, "efi_boot_entry: Failed to set BootNext variable (%X)",
+            (uint64_t)status);
+    }
 
-  /* Now reboot */
-  gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
+    /* Now reboot */
+    gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
 
-  panic(true, "efi_boot_entry: Failed to reboot");
+    panic(true, "efi_boot_entry: Failed to reboot");
 }
 
 #endif
\ No newline at end of file
tab: 248 wrap: offon