From b5e11c59bbacce418a417c5e11aceddfb921378e Mon Sep 17 00:00:00 2001 From: Bitbucket ReadOnly Date: Fri, 24 Jul 2026 11:45:37 +0100 Subject: [PATCH] Query highest GOP Resolution, and set it before handing off to windows bootloader, so that the setup runs at better resolutions than 800x600/1024x768 where buttons may be off screen --- boot.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ boot.h | 1 + uefi-ntfs.inf | 1 + 3 files changed, 55 insertions(+) diff --git a/boot.c b/boot.c index 451cc8b..2563c7f 100644 --- a/boot.c +++ b/boot.c @@ -193,6 +193,54 @@ STATIC EFI_STATUS UnloadDriver( return EFI_NOT_FOUND; } +/* + * Switch GOP Console res to the highest available mode, if possible. + * When chaining windows for example, inherit a larger resolution for the setup screen. + * This is a workaround for the fact that Windows setup does not switch to the highest + * available resolution on its own, instead, it will use the resolution of the UEFI GOP console. + * This is sometimes 800x600 or 1024x768, which is not ideal for modern displays. + */ +STATIC VOID SetHighestGopResolution(VOID) +{ + EFI_STATUS Status; + EFI_GRAPHICS_OUTPUT_PROTOCOL* Gop = NULL; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* Info; + UINTN SizeOfInfo, Index; + UINT32 BestMode = 0; + UINT64 BestArea = 0; + + Status = gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid, NULL, (VOID**)&Gop); + if (EFI_ERROR(Status) || (Gop == NULL)) { + PrintWarning(L"Could not locate GOP - display resolution will not be changed"); + return; + } + + for (Index = 0; Index < Gop->Mode->MaxMode; Index++) { + Status = Gop->QueryMode(Gop, (UINT32)Index, &SizeOfInfo, &Info); + if (EFI_ERROR(Status)) { + continue; + } + if ((UINT64)Info->HorizontalResolution * Info->VerticalResolution > BestArea) { + BestArea = (UINT64)Info->HorizontalResolution * Info->VerticalResolution; + BestMode = (UINT32)Index; + } + } + + if (BestArea == 0) { + PrintWarning(L"No valid GOP mode found - display resolution will not be changed"); + return; + } + + if (Gop->Mode->Mode != BestMode) { + PrintInfo(L"Switching GOP console to highest available resolution: %d (%dx%d)", BestMode, + Info->HorizontalResolution, Info->VerticalResolution); + Status = Gop->SetMode(Gop, BestMode); + if (EFI_ERROR(Status)) { + PrintWarning(L"Could not set GOP mode %d: %r", BestMode, Status); + } + } +} + /* * Display a centered application banner */ @@ -514,6 +562,11 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE BaseImageHandle, EFI_SYSTEM_TABLE *SystemT goto out; } + // Bump the console to its highest GOP res before handing off, + // so that windows boot manager / Setup starts at a large resolution + // instead of whatever the firmware defaulted to (often 800x600 or 1024x768) + SetHighestGopResolution(); + // At this stage, our DevicePath is the partition we are after PrintInfo(L"Launching '%s'...", &LoaderPath[1]); diff --git a/boot.h b/boot.h index c9f5d7f..62167c6 100644 --- a/boot.h +++ b/boot.h @@ -47,6 +47,7 @@ #include #include #include +#include #include #include diff --git a/uefi-ntfs.inf b/uefi-ntfs.inf index 04a45ea..75a54d0 100644 --- a/uefi-ntfs.inf +++ b/uefi-ntfs.inf @@ -51,6 +51,7 @@ gEfiDevicePathToTextProtocolGuid gEfiDiskIoProtocolGuid gEfiDiskIo2ProtocolGuid + gEfiGraphicsOutputProtocolGuid gEfiLoadedImageProtocolGuid gEfiSimpleFileSystemProtocolGuid