:: commit 2d404d6fc1f265b7052f718b731c412e5f48cd6d

mintsuki <mintsuki@protonmail.com> — 2025-03-09 22:42

parents: c39be10c92

misc: Do not attempt to use serial if not detected on EFI

This addresses an issue reported on Macs that lack a serial port and also lack a working ConOut screen console, resulting in nothing but a blank screen instead of the menu
diff --git a/common/lib/misc.c b/common/lib/misc.c
index 5013b5bf..a028e06b 100644
--- a/common/lib/misc.c
+++ b/common/lib/misc.c
@@ -25,6 +25,31 @@ UINT32 efi_desc_ver = 0;
 bool editor_enabled = true;
 bool help_hidden = false;
 
+#if defined (UEFI)
+bool is_efi_serial_present(void) {
+    EFI_STATUS status;
+    EFI_SERIAL_IO_PROTOCOL *serial = NULL;
+    EFI_GUID serial_io_guid = EFI_SERIAL_IO_PROTOCOL_GUID;
+
+    status = gBS->LocateProtocol(&serial_io_guid, NULL, (void **)&serial);
+    if (status) {
+        return false;
+    }
+
+    if (serial == NULL) {
+        return false;
+    }
+
+    UINT32 control;
+    status = serial->GetControl(serial, &control);
+    if (status) {
+        return false;
+    }
+
+    return true;
+}
+#endif
+
 bool parse_resolution(size_t *width, size_t *height, size_t *bpp, const char *buf) {
     size_t res[3] = {0};
 
diff --git a/common/lib/misc.h b/common/lib/misc.h
index dc7a6f2c..fb6a1044 100644
--- a/common/lib/misc.h
+++ b/common/lib/misc.h
@@ -26,6 +26,8 @@ extern UINT32 efi_desc_ver;
 
 extern bool efi_boot_services_exited;
 bool efi_exit_boot_services(void);
+
+bool is_efi_serial_present(void);
 #endif
 
 void *get_device_tree_blob(const char *config, size_t extra_size);
diff --git a/common/menu.c b/common/menu.c
index 434932e6..059b51fd 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -764,7 +764,11 @@ noreturn void _menu(bool first_run) {
     verbose = verbose_str != NULL && strcmp(verbose_str, "yes") == 0;
 
     char *serial_str = config_get_value(NULL, 0, "SERIAL");
-    serial = serial_str != NULL && strcmp(serial_str, "yes") == 0;
+    serial =
+#if defined (UEFI)
+        is_efi_serial_present() &&
+#endif
+        serial_str != NULL && strcmp(serial_str, "yes") == 0;
 
     char *hash_mismatch_panic_str = config_get_value(NULL, 0, "HASH_MISMATCH_PANIC");
     hash_mismatch_panic = hash_mismatch_panic_str == NULL || strcmp(hash_mismatch_panic_str, "yes") == 0;
tab: 248 wrap: offon