dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
ac3a84
From 071cef46b87b605f8b4918a95dcecae08b843e23 Mon Sep 17 00:00:00 2001
ac3a84
From: Jan Janssen <medhefgo@web.de>
ac3a84
Date: Sun, 27 Nov 2022 13:38:18 +0100
ac3a84
Subject: [PATCH] boot: Use EFI_BOOT_MANAGER_POLICY_PROTOCOL to connect console
ac3a84
 devices
ac3a84
ac3a84
(cherry picked from commit b99bf5811850afdb2502ba37251c48348da63c82)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/boot/efi/console.c     | 16 ++++++++++++++++
ac3a84
 src/boot/efi/missing_efi.h | 19 +++++++++++++++++++
ac3a84
 2 files changed, 35 insertions(+)
ac3a84
ac3a84
diff --git a/src/boot/efi/console.c b/src/boot/efi/console.c
ac3a84
index 14c0008afb..cd980fd535 100644
ac3a84
--- a/src/boot/efi/console.c
ac3a84
+++ b/src/boot/efi/console.c
ac3a84
@@ -12,6 +12,20 @@
ac3a84
 #define VERTICAL_MAX_OK 1080
ac3a84
 #define VIEWPORT_RATIO 10
ac3a84
 
ac3a84
+static EFI_STATUS console_connect(void) {
ac3a84
+        EFI_BOOT_MANAGER_POLICY_PROTOCOL *boot_policy;
ac3a84
+        EFI_STATUS err;
ac3a84
+
ac3a84
+        /* This should make console devices appear/fully initialize on fastboot firmware. */
ac3a84
+
ac3a84
+        err = BS->LocateProtocol(
ac3a84
+                        &(EFI_GUID) EFI_BOOT_MANAGER_POLICY_PROTOCOL_GUID, NULL, (void **) &boot_policy);
ac3a84
+        if (err != EFI_SUCCESS)
ac3a84
+                return err;
ac3a84
+
ac3a84
+        return boot_policy->ConnectDeviceClass(boot_policy, &(EFI_GUID) EFI_BOOT_MANAGER_POLICY_CONSOLE_GUID);
ac3a84
+}
ac3a84
+
ac3a84
 static inline void event_closep(EFI_EVENT *event) {
ac3a84
         if (!*event)
ac3a84
                 return;
ac3a84
@@ -47,6 +61,8 @@ EFI_STATUS console_key_read(uint64_t *key, uint64_t timeout_usec) {
ac3a84
         assert(key);
ac3a84
 
ac3a84
         if (!checked) {
ac3a84
+                console_connect();
ac3a84
+
ac3a84
                 /* Get the *first* TextInputEx device.*/
ac3a84
                 err = BS->LocateProtocol(&SimpleTextInputExProtocol, NULL, (void **) &extraInEx);
ac3a84
                 if (err != EFI_SUCCESS || BS->CheckEvent(extraInEx->WaitForKeyEx) == EFI_INVALID_PARAMETER)
ac3a84
diff --git a/src/boot/efi/missing_efi.h b/src/boot/efi/missing_efi.h
ac3a84
index 250c84c248..b446e0399f 100644
ac3a84
--- a/src/boot/efi/missing_efi.h
ac3a84
+++ b/src/boot/efi/missing_efi.h
ac3a84
@@ -398,3 +398,22 @@ typedef struct {
ac3a84
         void *StdErr;
ac3a84
 } EFI_SHELL_PARAMETERS_PROTOCOL;
ac3a84
 #endif
ac3a84
+
ac3a84
+#ifndef EFI_BOOT_MANAGER_POLICY_PROTOCOL_GUID
ac3a84
+#define EFI_BOOT_MANAGER_POLICY_PROTOCOL_GUID \
ac3a84
+        { 0xFEDF8E0C, 0xE147, 0x11E3, { 0x99, 0x03, 0xB8, 0xE8, 0x56, 0x2C, 0xBA, 0xFA } }
ac3a84
+#define EFI_BOOT_MANAGER_POLICY_CONSOLE_GUID \
ac3a84
+        { 0xCAB0E94C, 0xE15F, 0x11E3, { 0x91, 0x8D, 0xB8, 0xE8, 0x56, 0x2C, 0xBA, 0xFA } }
ac3a84
+
ac3a84
+typedef struct EFI_BOOT_MANAGER_POLICY_PROTOCOL EFI_BOOT_MANAGER_POLICY_PROTOCOL;
ac3a84
+struct EFI_BOOT_MANAGER_POLICY_PROTOCOL {
ac3a84
+        UINT64 Revision;
ac3a84
+        EFI_STATUS (EFIAPI *ConnectDevicePath)(
ac3a84
+                EFI_BOOT_MANAGER_POLICY_PROTOCOL *This,
ac3a84
+                EFI_DEVICE_PATH *DevicePath,
ac3a84
+                BOOLEAN Recursive);
ac3a84
+        EFI_STATUS (EFIAPI *ConnectDeviceClass)(
ac3a84
+                EFI_BOOT_MANAGER_POLICY_PROTOCOL *This,
ac3a84
+                EFI_GUID *Class);
ac3a84
+};
ac3a84
+#endif