]> code.delx.au - refind/blobdiff - refind/main.c
0.5.1.1 release (changed install.sh & documentation, nothing to main
[refind] / refind / main.c
index 7297c629f4ef0663f2d0ace4ff7a708d96640cf8..01584014792425f855a8616f7140a782b79ac176 100644 (file)
@@ -118,7 +118,7 @@ static VOID AboutrEFInd(VOID)
 
     if (AboutMenu.EntryCount == 0) {
         AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
-        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.7.10");
+        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.5.1");
         AddMenuInfoLine(&AboutMenu, L"");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith");
@@ -178,7 +178,7 @@ static EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
     CHAR16                  ErrorInfo[256];
     CHAR16                  *FullLoadOptions = NULL;
     CHAR16                  *loader = NULL;
-    BOOLEAN                 UseMok = FALSE, SecureMode;
+    BOOLEAN                 UseMok = FALSE;
 
     if (ErrorInStep != NULL)
         *ErrorInStep = 0;
@@ -196,32 +196,28 @@ static EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
         } else {
             MergeStrings(&FullLoadOptions, LoadOptions, 0);
         } // if/else
-        // NOTE: We also include the terminating null in the length for safety.
-    } // if (LoadOptions != NULL)
+    } else { // LoadOptions == NULL
+       // NOTE: We provide a non-null string when no options are specified for safety;
+       // some systems (at least DUET) can hang when launching some programs (such as
+       // an EFI shell) without this.
+       FullLoadOptions = StrDuplicate(L" ");
+    }
     if (Verbose)
        Print(L"Starting %s\nUsing load options '%s'\n", ImageTitle, FullLoadOptions);
 
     // 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
-    SecureMode = secure_mode();
-//    SecureMode = TRUE;
     for (DevicePathIndex = 0; DevicePaths[DevicePathIndex] != NULL; DevicePathIndex++) {
-       // NOTE: Below commented-out line could simplify logic by loading the image once, 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.
+       // 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);
-       // In Secure Boot mode, try to use shim/MOK-style loading first, and if
-       // that fails, try the standard EFI system call (LoadImage()). This is
-       // done for efficiency, to prevent loading a binary twice, which can
-       // take several seconds to load a Linux kernel with EFI stub support on
-       // some systems. Linux kernels are likely to be shim/MOK signed, so
-       // this is quickest for them; and delays for most other boot loaders
-       // will be unnoticeably short. To prevent delays or failures in case
-       // of buggy shim/MOK code on non-SB systems, skip that attempt and
-       // call LoadImage() directly when not in SB mode.
-       if (SecureMode) {
+        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);
@@ -232,21 +228,14 @@ static EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
           } // if/else
           if (Status != EFI_NOT_FOUND) {
              ReturnStatus = Status = start_image(SelfImageHandle, loader, ImageData, ImageSize, FullLoadOptions,
-                                                 DeviceVolume, DevicePaths[DevicePathIndex]);
+                                                 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 shim/MOK load fails, try regular EFI load, in case it's an unsupported
-          // binary type....
-          if (!UseMok) {
-             ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex],
-                                                         NULL, 0, &ChildImageHandle);
-          } // if (!UseMok)
-       } else { // Secure Boot inactive; only do standard call....
-          ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex],
-                                                      NULL, 0, &ChildImageHandle);
-       } // if/else (SecureMode)
+       } // if (UEFI SB failed; use shim)
        if (ReturnStatus != EFI_NOT_FOUND) {
           break;
        }
@@ -728,6 +717,7 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME
    Temp = FindLastDirName(LoaderPath);
    MergeStrings(&OSIconName, Temp, L',');
    MyFreePool(Temp);
+   Temp = NULL;
    if (OSIconName != NULL) {
       ShortcutLetter = OSIconName[0];
    }
@@ -754,9 +744,15 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME
       Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_OSX;
    } else if (StriCmp(FileName, L"diags.efi") == 0) {
       MergeStrings(&OSIconName, L"hwtest", L',');
-   } else if (StriCmp(FileName, L"e.efi") == 0 || StriCmp(FileName, L"elilo.efi") == 0) {
+   } else if (StriCmp(FileName, L"e.efi") == 0 || StriCmp(FileName, L"elilo.efi") == 0 || StriSubCmp(L"elilo", FileName)) {
       MergeStrings(&OSIconName, L"elilo,linux", L',');
       Entry->OSType = 'E';
+//       if (secure_mode()) { // hack to enable ELILO to boot in secure mode
+//          Temp = StrDuplicate(L"-C ");
+//          MergeStrings(&Temp, PathOnly, 0);
+//          MergeStrings(&Temp, L"elilo.conf", L'\\');
+//          Entry->LoadOptions = Temp;
+//       }
       if (ShortcutLetter == 0)
          ShortcutLetter = 'L';
       Entry->UseGraphicsMode = GlobalConfig.GraphicsFor & GRAPHICS_FOR_ELILO;
@@ -1864,7 +1860,7 @@ VOID RescanAll(VOID) {
    FreeList((VOID ***) &(MainMenu.Entries), &MainMenu.EntryCount);
    MainMenu.Entries = NULL;
    MainMenu.EntryCount = 0;
-   ReadConfig();
+   ReadConfig(CONFIG_FILE_NAME);
    ConnectAllDriversToAllControllers();
    ScanVolumes();
    ScanForBootloaders();
@@ -1914,7 +1910,7 @@ efi_main (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
     FindLegacyBootType();
     if (GlobalConfig.LegacyType == LEGACY_TYPE_MAC)
        CopyMem(GlobalConfig.ScanFor, "ihebocm   ", NUM_SCAN_OPTIONS);
-    ReadConfig();
+    ReadConfig(CONFIG_FILE_NAME);
     WarnIfLegacyProblems();
     MainMenu.TimeoutSeconds = GlobalConfig.Timeout;