summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan M. <ian@aptel.org>2026-09-11 05:00:24 +0000
committerIan M. <ian@aptel.org>2026-09-11 05:00:24 +0000
commitf8636711a0ce0431d7917dc6751b4762e6441b41 (patch)
tree060ba113ff656b14c83fd84bb210db6e93e8e6c8
parent09a38cfa889fda6bd63063b0516950d18e5e2110 (diff)
core: sboot: Add menu
Signed-off-by: Ian M. <ian@aptel.org>
-rw-r--r--core/menu.c61
-rw-r--r--core/sboot.c12
-rw-r--r--head/sboot/sboot.h9
3 files changed, 72 insertions, 10 deletions
diff --git a/core/menu.c b/core/menu.c
new file mode 100644
index 0000000..955b750
--- /dev/null
+++ b/core/menu.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#include <sboot/sboot.h>
+#include <sboot/fwi.h>
+#include <sboot/config.h>
+
+#define MENU_CLEAR() \
+ Print(L"\r\t\t\t\t\t\t\r")
+#define MENU_WRITE(ENTRY) \
+ Print(L"<-- %s -->", (ENTRY)->Name);
+
+VOID
+SBootMenu(OUT BOOT_ENTRY *Entry)
+{
+ EFI_INPUT_KEY Key;
+ UINTN CurrentEntryIndex;
+ BOOT_ENTRY *CurrentEntry;
+ EFI_STATUS Status;
+ BOOLEAN Run = TRUE;
+
+ Print(L" ===== USE LEFT/RIGHT ARROW KEYS TO SELECT ====\n\n");
+ CurrentEntryIndex = 0;
+ CurrentEntry = &ConfigBootEntries[CurrentEntryIndex];
+ MENU_WRITE(CurrentEntry);
+
+ while (Run) {
+ Status = uefi_call_wrapper(gST->ConIn->ReadKeyStroke, 2, gST->ConIn, &Key);
+ if (EFI_ERROR(Status)) {
+ continue;
+ }
+
+ switch (Key.ScanCode) {
+ case 0x0:
+ Run = FALSE;
+ continue;
+ case SCAN_RIGHT:
+ if (CurrentEntryIndex < NELEM(ConfigBootEntries) - 2) {
+ ++CurrentEntryIndex;
+ CurrentEntry = &ConfigBootEntries[CurrentEntryIndex];
+ MENU_CLEAR();
+ MENU_WRITE(CurrentEntry);
+ }
+ break;
+ case SCAN_LEFT:
+ if (CurrentEntryIndex == 0)
+ continue;
+
+ --CurrentEntryIndex;
+ CurrentEntry = &ConfigBootEntries[CurrentEntryIndex];
+ MENU_CLEAR();
+ MENU_WRITE(CurrentEntry);
+ break;
+ }
+ }
+
+ Print(L"\nBooting %s (%s)\n", CurrentEntry->Name, CurrentEntry->BootPath);
+ *Entry = *CurrentEntry;
+}
diff --git a/core/sboot.c b/core/sboot.c
index 1649b7e..1a3d7d1 100644
--- a/core/sboot.c
+++ b/core/sboot.c
@@ -13,18 +13,9 @@ EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
- UINTN NrBootEntries;
- BOOT_PROTOCOL LastProtocol;
+ BOOT_ENTRY Entry;
InitializeLib(ImageHandle, SystemTable);
- NrBootEntries = NELEM(ConfigBootEntries);
-
- /* Ensure the list is terminated */
- LastProtocol = ConfigBootEntries[NrBootEntries - 1].Protocol;
- if (LastProtocol != PROTOCOL_END) {
- Print(L"fatal: boot entry list not terminated\n");
- Hcf();
- }
/* Disable the watchdog timer */
FwiSetWatchdogTimer(
@@ -40,5 +31,6 @@ efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
NELEM(ConfigBootEntries) - 1
);
+ SBootMenu(&Entry);
for (;;);
}
diff --git a/head/sboot/sboot.h b/head/sboot/sboot.h
index 749fbc7..2efbfa5 100644
--- a/head/sboot/sboot.h
+++ b/head/sboot/sboot.h
@@ -6,6 +6,10 @@
#ifndef _COMMON_SBOOT_H_
#define _COMMON_SBOOT_H_ 1
+#include <efi.h>
+#include <efilib.h>
+#include <sboot/config.h>
+
/* Bootloader version */
#define SBOOT_VERSION L"v0.0.1"
@@ -16,4 +20,9 @@
#define Hcf() \
for (;;);
+/*
+ * Begin the SBoot selection menu
+ */
+VOID SBootMenu(OUT BOOT_ENTRY *Entry);
+
#endif /* !_COMMON_SBOOT_H_ */