Skip to content

Commit 516203f

Browse files
committed
Initial support for loading VGA BIOS from file. Addresses #37
1 parent 48a0b70 commit 516203f

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/csmwrap.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,39 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
105105

106106
printf("%s", banner);
107107

108+
EFI_GUID loaded_image_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
109+
EFI_LOADED_IMAGE_PROTOCOL *loaded_image = NULL;
110+
if (gBS->HandleProtocol(ImageHandle, &loaded_image_guid, (void **)&loaded_image) != EFI_SUCCESS) {
111+
loaded_image = NULL;
112+
}
113+
114+
EFI_GUID sfs_protocol_guid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
115+
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *sfs_protocol = NULL;
116+
if (loaded_image == NULL || gBS->HandleProtocol(loaded_image->DeviceHandle, &sfs_protocol_guid, (void **)&sfs_protocol) != EFI_SUCCESS) {
117+
sfs_protocol = NULL;
118+
}
119+
120+
EFI_FILE_PROTOCOL *sfs_dir = NULL;
121+
if (sfs_protocol == NULL || sfs_protocol->OpenVolume(sfs_protocol, &sfs_dir) != EFI_SUCCESS) {
122+
sfs_dir = NULL;
123+
}
124+
125+
EFI_FILE_PROTOCOL *vgabios_file_handle = NULL;
126+
if (sfs_dir != NULL) {
127+
if (sfs_dir->Open(sfs_dir, &vgabios_file_handle, L"\\EFI\\BOOT\\vgabios.bin", EFI_FILE_MODE_READ, 0) == EFI_SUCCESS) {
128+
printf("Found 'vgabios.bin' file. Using it as our VBIOS!\n");
129+
UINTN max_size = 256 * 1024;
130+
if (gBS->AllocatePool(EfiLoaderData, max_size, &vbios_loc) == EFI_SUCCESS
131+
&& vgabios_file_handle->Read(vgabios_file_handle, &max_size, vbios_loc) == EFI_SUCCESS) {
132+
vbios_size = max_size;
133+
} else {
134+
vbios_loc = NULL;
135+
vbios_size = 0;
136+
}
137+
}
138+
sfs_dir->Close(sfs_dir);
139+
}
140+
108141
gBS->RaiseTPL(TPL_NOTIFY);
109142
gBS->SetWatchdogTimer(0, 0, 0, NULL);
110143

src/video.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Generated by: xxd -i vgabios.bin >> vgabios.h
77
#include <bins/vgabios.h>
88

9-
void *vbios_loc;
9+
void *vbios_loc = NULL;
1010
uintptr_t vbios_size;
1111

1212
static EFI_STATUS FindGopPciDevice(struct csmwrap_priv *priv)
@@ -587,6 +587,10 @@ EFI_STATUS csmwrap_video_init(struct csmwrap_priv *priv)
587587
status = csmwrap_pci_vgaarb(priv);
588588
}
589589

590+
if (vbios_loc != NULL) {
591+
return 0;
592+
}
593+
590594
status = csmwrap_video_oprom_init(priv);
591595
if (status == EFI_SUCCESS) {
592596
return 0;

0 commit comments

Comments
 (0)