Last active
May 31, 2026 16:56
-
-
Save paigeadelethompson/01497708d6e333c4f483fc96593fe82b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Library/BaseMemoryLib.h> | |
| #include <Library/MemoryAllocationLib.h> | |
| #include <Library/UefiBootServicesTableLib.h> | |
| #include <Library/UefiRuntimeServicesTableLib.h> | |
| #include <Library/DevicePathLib.h> | |
| #include <Guid/GlobalVariable.h> | |
| /** | |
| Scrubs all serial and UART device paths from the ConOut variable. | |
| **/ | |
| VOID | |
| PurgeSerialFromConOut ( | |
| VOID | |
| ) | |
| { | |
| EFI_STATUS Status; | |
| EFI_DEVICE_PATH_PROTOCOL *FullConOutPath; | |
| EFI_DEVICE_PATH_PROTOCOL *Instance; | |
| EFI_DEVICE_PATH_PROTOCOL *NewConOutPath; | |
| EFI_DEVICE_PATH_PROTOCOL *NextInstance; | |
| UINTN Size; | |
| BOOLEAN IsSerial; | |
| NewConOutPath = NULL; | |
| // 1. Fetch the existing ConOut variable string | |
| GetEfiGlobalVariable2 (L"ConOut", (VOID **)&FullConOutPath, &Size); | |
| if (FullConOutPath == NULL) { | |
| return; // ConOut is empty, nothing to purge | |
| } | |
| // 2. Loop through every device instance bound to the console output splitter | |
| Instance = FullConOutPath; | |
| while (Instance != NULL) { | |
| NextInstance = NextDevicePathInstance (Instance, &Size); | |
| IsSerial = FALSE; | |
| // Check every node inside this specific device path instance | |
| EFI_DEVICE_PATH_PROTOCOL *Node = Instance; | |
| while (!IsDevicePathEnd (Node)) { | |
| // MESSAGING_DEVICE_PATH (0x03) + MSG_UART_DP (0x0E) or MSG_VENDOR_DP (0x0A) | |
| if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && | |
| ((DevicePathSubType (Node) == MSG_UART_DP) || (DevicePathSubType (Node) == MSG_VENDOR_DP))) { | |
| IsSerial = TRUE; | |
| break; | |
| } | |
| Node = NextDevicePathNode (Node); | |
| } | |
| // 3. If it is NOT a serial line, append it to our clean ConOut path structure | |
| if (!IsSerial) { | |
| NewConOutPath = AppendDevicePathInstance (NewConOutPath, Instance); | |
| } | |
| FreePool (Instance); | |
| Instance = NextInstance; | |
| } | |
| // 4. Commit the sanitized, video-only path back to the NVRAM / volatile storage | |
| if (NewConOutPath != NULL) { | |
| gRT->SetVariable ( | |
| L"ConOut", | |
| &gEfiGlobalVariableGuid, | |
| EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_VOLATILE, | |
| GetDevicePathSize (NewConOutPath), | |
| NewConOutPath | |
| ); | |
| FreePool (NewConOutPath); | |
| } else { | |
| // If only serial existed, wipe the variable entirely to force standard display fallback | |
| gRT->SetVariable (L"ConOut", &gEfiGlobalVariableGuid, 0, 0, NULL); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment