Skip to content

Commit eebbe49

Browse files
committed
rename some handle variables to better reflect their use
* Also set FsMagic as a CONST CHAR8 variable and update
1 parent 4f7ead4 commit eebbe49

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

boot.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,11 @@ static VOID DisplayBanner(VOID)
192192
* Application entry-point
193193
* NB: This must be set to 'efi_main' for gnu-efi crt0 compatibility
194194
*/
195-
EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
195+
EFI_STATUS EFIAPI efi_main(EFI_HANDLE BaseImageHandle, EFI_SYSTEM_TABLE *SystemTable)
196196
{
197+
CONST CHAR8 FsMagic[2][8] = {
198+
{ 'N', 'T', 'F', 'S', ' ', ' ', ' ', ' '} ,
199+
{ 'E', 'X', 'F', 'A', 'T', ' ', ' ', ' '} };
197200
CONST CHAR16* FsName[] = { L"NTFS", L"exFAT" };
198201
CONST CHAR16* DriverName[] = { L"ntfs", L"exfat" };
199202
CHAR16 DriverPath[64], LoaderPath[64];
@@ -202,22 +205,20 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
202205
EFI_STATUS Status;
203206
EFI_DEVICE_PATH *DevicePath, *ParentDevicePath = NULL, *BootDiskPath = NULL;
204207
EFI_DEVICE_PATH *BootPartitionPath = NULL;
205-
EFI_HANDLE *Handles = NULL, DriverHandle, DriverHandleList[2];
208+
EFI_HANDLE *Handles = NULL, ImageHandle, DriverHandleList[2];
206209
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* Volume;
207210
EFI_FILE_SYSTEM_VOLUME_LABEL* VolumeInfo;
208211
EFI_FILE_HANDLE Root;
209212
EFI_BLOCK_IO_PROTOCOL *BlockIo;
210-
CHAR8* Buffer, FsMagic[2][8] = {
211-
{ 'N', 'T', 'F', 'S', ' ', ' ', ' ', ' '} ,
212-
{ 'E', 'X', 'F', 'A', 'T', ' ', ' ', ' '} };
213+
CHAR8* Buffer;
213214
INTN SecureBootStatus;
214215
UINTN Index, FsType = 0, Try, Event, HandleCount = 0, Size;
215216
BOOLEAN SameDevice;
216217

217218
#if defined(_GNU_EFI)
218-
InitializeLib(ImageHandle, SystemTable);
219+
InitializeLib(BaseImageHandle, SystemTable);
219220
#endif
220-
MainImageHandle = ImageHandle;
221+
MainImageHandle = BaseImageHandle;
221222

222223
DisplayBanner();
223224
PrintSystemInfo();
@@ -332,7 +333,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
332333
// Attempt to load the driver.
333334
// NB: If running in a Secure Boot enabled environment, LoadImage() will fail if
334335
// the image being loaded does not pass the Secure Boot signature validation.
335-
Status = gBS->LoadImage(FALSE, MainImageHandle, DevicePath, NULL, 0, &DriverHandle);
336+
Status = gBS->LoadImage(FALSE, MainImageHandle, DevicePath, NULL, 0, &ImageHandle);
336337
SafeFree(DevicePath);
337338
if (EFI_ERROR(Status)) {
338339
// Some platforms (e.g. Intel NUCs) return EFI_ACCESS_DENIED for Secure Boot
@@ -346,7 +347,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
346347
// NB: Some HP firmwares refuse to start drivers that are not of type 'EFI Boot
347348
// System Driver'. For instance, a driver of type 'EFI Runtime Driver' produces
348349
// a 'Load Error' on StartImage() with these firmwares => check the type.
349-
Status = gBS->OpenProtocol(DriverHandle, &gEfiLoadedImageProtocolGuid,
350+
Status = gBS->OpenProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid,
350351
(VOID**)&LoadedImage, MainImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
351352
if (EFI_ERROR(Status)) {
352353
PrintError(L" Unable to access driver interface");
@@ -359,16 +360,16 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
359360
}
360361

361362
// Load was a success - attempt to start the driver
362-
Status = gBS->StartImage(DriverHandle, NULL, NULL);
363+
Status = gBS->StartImage(ImageHandle, NULL, NULL);
363364
if (EFI_ERROR(Status)) {
364365
PrintError(L" Unable to start driver");
365366
goto out;
366367
}
367-
PrintInfo(L" %s", GetDriverName(DriverHandle));
368+
PrintInfo(L" %s", GetDriverName(ImageHandle));
368369

369370
// Calling ConnectController() on a handle, with a NULL-terminated list of
370371
// drivers will start all the drivers from the list that can service it
371-
DriverHandleList[0] = DriverHandle;
372+
DriverHandleList[0] = ImageHandle;
372373
DriverHandleList[1] = NULL;
373374
Status = gBS->ConnectController(Handles[Index], DriverHandleList, NULL, TRUE);
374375
if (EFI_ERROR(Status)) {
@@ -441,7 +442,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
441442
PrintError(L" Could not create path");
442443
goto out;
443444
}
444-
Status = gBS->LoadImage(FALSE, ImageHandle, DevicePath, NULL, 0, &DriverHandle);
445+
Status = gBS->LoadImage(FALSE, MainImageHandle, DevicePath, NULL, 0, &ImageHandle);
445446
SafeFree(DevicePath);
446447
if (EFI_ERROR(Status)) {
447448
if ((Status == EFI_ACCESS_DENIED) && (SecureBootStatus >= 1))
@@ -450,7 +451,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
450451
goto out;
451452
}
452453

453-
Status = gBS->StartImage(DriverHandle, NULL, NULL);
454+
Status = gBS->StartImage(ImageHandle, NULL, NULL);
454455
if (EFI_ERROR(Status))
455456
PrintError(L" Start failure");
456457

0 commit comments

Comments
 (0)