- // close open file handles
- UninitRefitLib();
-
- // turn control over to the image
- // TODO: (optionally) re-enable the EFI watchdog timer!
- ReturnStatus = Status = refit_call3_wrapper(BS->StartImage, ChildImageHandle, NULL, NULL);
- // control returns here when the child image calls Exit()
- SPrint(ErrorInfo, 255, L"returned from %s", ImageTitle);
+ // load the image into memory (and execute it, in the case of a shim/MOK image).
+ ReturnStatus = Status = EFI_NOT_FOUND; // in case the list is empty
+ for (DevicePathIndex = 0; DevicePaths[DevicePathIndex] != NULL; DevicePathIndex++) {
+ // NOTE: Below commented-out line could be more efficient if the ReadFile() and
+ // FindVolumeAndFilename() calls were moved earlier, but it doesn't work on my
+ // 32-bit Mac Mini or my 64-bit Intel box when launching a Linux kernel; the
+ // kernel returns a "Failed to handle fs_proto" error message.
+ // TODO: Track down the cause of this error and fix it, if possible.
+ // ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex],
+ // ImageData, ImageSize, &ChildImageHandle);
+ ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex],
+ NULL, 0, &ChildImageHandle);
+ if ((Status == EFI_ACCESS_DENIED) && (ShimLoaded())) {
+ FindVolumeAndFilename(DevicePaths[DevicePathIndex], &DeviceVolume, &loader);
+ if (DeviceVolume != NULL) {
+ Status = ReadFile(DeviceVolume->RootDir, loader, &File, &ImageSize);
+ ImageData = File.Buffer;
+ } else {
+ Status = EFI_NOT_FOUND;
+ Print(L"Error: device volume not found!\n");
+ } // if/else
+ if (Status != EFI_NOT_FOUND) {
+ ReturnStatus = Status = start_image(SelfImageHandle, loader, ImageData, ImageSize, FullLoadOptions,
+ DeviceVolume, FileDevicePath(DeviceVolume->DeviceHandle, loader));
+// ReturnStatus = Status = start_image(SelfImageHandle, loader, ImageData, ImageSize, FullLoadOptions,
+// DeviceVolume, DevicePaths[DevicePathIndex]);
+ }
+ if (ReturnStatus == EFI_SUCCESS) {
+ UseMok = TRUE;
+ } // if
+ } // if (UEFI SB failed; use shim)
+ if (ReturnStatus != EFI_NOT_FOUND) {
+ break;
+ }
+ }
+ SPrint(ErrorInfo, 255, L"while loading %s", ImageTitle);