X-Git-Url: https://code.delx.au/refind/blobdiff_plain/dfa921b680497937566695dfefd20a8751947c51..85f7e52b653f9e618ad57d511ed01db94ae3b2b3:/refind/main.c diff --git a/refind/main.c b/refind/main.c index 55ddf89..66d51ff 100644 --- a/refind/main.c +++ b/refind/main.c @@ -58,8 +58,10 @@ #define MACOSX_LOADER_PATH L"System\\Library\\CoreServices\\boot.efi" #if defined (EFIX64) #define SHELL_NAMES L"\\EFI\\tools\\shell.efi,\\shellx64.efi" +#define DRIVER_DIRS L"drivers,drivers_x64" #elif defined (EFI32) #define SHELL_NAMES L"\\EFI\\tools\\shell.efi,\\shellia32.efi" +#define DRIVER_DIRS L"drivers,drivers_ia32" #else #define SHELL_NAMES L"\\EFI\\tools\\shell.efi" #endif @@ -85,7 +87,7 @@ static REFIT_MENU_ENTRY MenuEntryExit = { L"Exit rEFInd", TAG_EXIT, 1, 0, 0, static REFIT_MENU_SCREEN MainMenu = { L"Main Menu", NULL, 0, NULL, 0, NULL, 0, L"Automatic boot" }; static REFIT_MENU_SCREEN AboutMenu = { L"About", NULL, 0, NULL, 0, NULL, 0, NULL }; -REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 20, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 20, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, {TAG_SHELL, TAG_ABOUT, TAG_SHUTDOWN, TAG_REBOOT, 0, 0, 0, 0, 0 }}; // Structure used to hold boot loader filenames and time stamps in @@ -104,7 +106,7 @@ static VOID AboutrEFInd(VOID) { if (AboutMenu.EntryCount == 0) { AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); - AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.3.3.2"); + AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.1.1"); AddMenuInfoLine(&AboutMenu, L""); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer"); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith"); @@ -154,6 +156,8 @@ static EFI_STATUS StartEFIImageList(IN EFI_DEVICE_PATH **DevicePaths, // load the image into memory ReturnStatus = Status = EFI_NOT_FOUND; // in case the list is empty for (DevicePathIndex = 0; DevicePaths[DevicePathIndex] != NULL; DevicePathIndex++) { +// Print(L"About to try loading '%s' from '%s'\n", ImageTitle, DevicePathToStr(DevicePaths[DevicePathIndex])); +// PauseForKey(); ReturnStatus = Status = refit_call6_wrapper(BS->LoadImage, FALSE, SelfImageHandle, DevicePaths[DevicePathIndex], NULL, 0, &ChildImageHandle); if (ReturnStatus != EFI_NOT_FOUND) break; @@ -296,6 +300,63 @@ LOADER_ENTRY * AddPreparedLoaderEntry(LOADER_ENTRY *Entry) { return(Entry); } // LOADER_ENTRY * AddPreparedLoaderEntry() +// Creates a copy of a menu screen. +// Returns a pointer to the copy of the menu screen. +static REFIT_MENU_SCREEN* CopyMenuScreen(REFIT_MENU_SCREEN *Entry) { + REFIT_MENU_SCREEN *NewEntry; + UINTN i; + + NewEntry = AllocateZeroPool(sizeof(REFIT_MENU_SCREEN)); + if ((Entry != NULL) && (NewEntry != NULL)) { + CopyMem(NewEntry, Entry, sizeof(REFIT_MENU_SCREEN)); + NewEntry->Title = StrDuplicate(Entry->Title); + NewEntry->TimeoutText = StrDuplicate(Entry->TimeoutText); + if (Entry->TitleImage != NULL) { + NewEntry->TitleImage = AllocatePool(sizeof(EG_IMAGE)); + if (NewEntry->TitleImage != NULL) + CopyMem(NewEntry->TitleImage, Entry->TitleImage, sizeof(EG_IMAGE)); + } // if + NewEntry->InfoLines = (CHAR16**) AllocateZeroPool(Entry->InfoLineCount * (sizeof(CHAR16*))); + for (i = 0; i < Entry->InfoLineCount && NewEntry->InfoLines; i++) { + NewEntry->InfoLines[i] = StrDuplicate(Entry->InfoLines[i]); + } // for + NewEntry->Entries = (REFIT_MENU_ENTRY**) AllocateZeroPool(Entry->EntryCount * (sizeof (REFIT_MENU_ENTRY*))); + for (i = 0; i < Entry->EntryCount && NewEntry->Entries; i++) { + AddMenuEntry(NewEntry, Entry->Entries[i]); + } // for + } // if + return (NewEntry); +} // static REFIT_MENU_SCREEN* CopyMenuScreen() + +// Creates a copy of a menu entry. Intended to enable moving a stack-based +// menu entry (such as the ones for the "reboot" and "exit" functions) to +// to the heap. This enables easier deletion of the whole set of menu +// entries when re-scanning. +// Returns a pointer to the copy of the menu entry. +static REFIT_MENU_ENTRY* CopyMenuEntry(REFIT_MENU_ENTRY *Entry) { + REFIT_MENU_ENTRY *NewEntry; + + NewEntry = AllocateZeroPool(sizeof(REFIT_MENU_ENTRY)); + if ((Entry != NULL) && (NewEntry != NULL)) { + CopyMem(NewEntry, Entry, sizeof(REFIT_MENU_ENTRY)); + NewEntry->Title = StrDuplicate(Entry->Title); + if (Entry->BadgeImage != NULL) { + NewEntry->BadgeImage = AllocatePool(sizeof(EG_IMAGE)); + if (NewEntry->BadgeImage != NULL) + CopyMem(NewEntry->BadgeImage, Entry->BadgeImage, sizeof(EG_IMAGE)); + } + if (Entry->Image != NULL) { + NewEntry->Image = AllocatePool(sizeof(EG_IMAGE)); + if (NewEntry->Image != NULL) + CopyMem(NewEntry->Image, Entry->Image, sizeof(EG_IMAGE)); + } + if (Entry->SubScreen != NULL) { + NewEntry->SubScreen = CopyMenuScreen(Entry->SubScreen); + } + } // if + return (NewEntry); +} // REFIT_MENU_ENTRY* CopyMenuEntry() + // Creates a new LOADER_ENTRY data structure and populates it with // default values from the specified Entry, or NULL values if Entry // is unspecified (NULL). @@ -641,7 +702,13 @@ LOADER_ENTRY * AddLoaderEntry(IN CHAR16 *LoaderPath, IN CHAR16 *LoaderTitle, IN Entry->me.Title = PoolPrint(L"Boot %s from %s", (LoaderTitle != NULL) ? LoaderTitle : LoaderPath, Volume->VolName); Entry->me.Row = 0; Entry->me.BadgeImage = Volume->VolBadgeImage; - Entry->LoaderPath = StrDuplicate(LoaderPath); + if ((LoaderPath != NULL) && (LoaderPath[0] != L'\\')) { + Entry->LoaderPath = StrDuplicate(L"\\"); + } else { + Entry->LoaderPath = NULL; + } + MergeStrings(&(Entry->LoaderPath), LoaderPath, 0); +// Entry->LoaderPath = StrDuplicate(LoaderPath); Entry->VolName = Volume->VolName; Entry->DevicePath = FileDevicePath(Volume->DeviceHandle, Entry->LoaderPath); SetLoaderDefaults(Entry, LoaderPath, Volume); @@ -720,8 +787,8 @@ static VOID ScanLoaderDir(IN REFIT_VOLUME *Volume, IN CHAR16 *Path, IN CHAR16 *P CHAR16 FileName[256], *Extension; struct LOADER_LIST *LoaderList = NULL, *NewLoader; - if (!SelfDirPath || !Path || ((StriCmp(Path, SelfDirPath) == 0) && Volume != SelfVolume) || - (StriCmp(Path, SelfDirPath) != 0)) { + if ((!SelfDirPath || !Path || ((StriCmp(Path, SelfDirPath) == 0) && Volume->DeviceHandle != SelfVolume->DeviceHandle) || + (StriCmp(Path, SelfDirPath) != 0)) && (!IsIn(Path, GlobalConfig.DontScan))) { // look through contents of the directory DirIterOpen(Volume->RootDir, Path, &DirIter); while (DirIterNext(&DirIter, 2, Pattern, &DirEntry)) { @@ -777,20 +844,22 @@ static VOID ScanEfiFiles(REFIT_VOLUME *Volume) { if ((Volume->RootDir != NULL) && (Volume->VolName != NULL)) { // check for Mac OS X boot loader - StrCpy(FileName, MACOSX_LOADER_PATH); - if (FileExists(Volume->RootDir, FileName)) { - AddLoaderEntry(FileName, L"Mac OS X", Volume); - } + if (!IsIn(L"System\\Library\\CoreServices", GlobalConfig.DontScan)) { + StrCpy(FileName, MACOSX_LOADER_PATH); + if (FileExists(Volume->RootDir, FileName)) { + AddLoaderEntry(FileName, L"Mac OS X", Volume); + } - // check for XOM - StrCpy(FileName, L"System\\Library\\CoreServices\\xom.efi"); - if (FileExists(Volume->RootDir, FileName)) { - AddLoaderEntry(FileName, L"Windows XP (XoM)", Volume); - } + // check for XOM + StrCpy(FileName, L"System\\Library\\CoreServices\\xom.efi"); + if (FileExists(Volume->RootDir, FileName)) { + AddLoaderEntry(FileName, L"Windows XP (XoM)", Volume); + } + } // if Mac directory not in GlobalConfig.DontScan list // check for Microsoft boot loader/menu StrCpy(FileName, L"EFI\\Microsoft\\Boot\\Bootmgfw.efi"); - if (FileExists(Volume->RootDir, FileName)) { + if (FileExists(Volume->RootDir, FileName) && !IsIn(L"EFI\\Microsoft\\Boot", GlobalConfig.DontScan)) { AddLoaderEntry(FileName, L"Microsoft EFI boot", Volume); } @@ -1306,16 +1375,22 @@ Done: // file line. static VOID LoadDrivers(VOID) { - CHAR16 *Directory; + CHAR16 *Directory, *SelfDirectory; UINTN i = 0, Length, NumFound = 0; - // load drivers from the "drivers" subdirectory of rEFInd's home directory - Directory = StrDuplicate(SelfDirPath); - CleanUpPathNameSlashes(Directory); - MergeStrings(&Directory, L"drivers", L'\\'); - NumFound += ScanDriverDir(Directory); + // load drivers from the subdirectories of rEFInd's home directory specified + // in the DRIVER_DIRS constant. + while ((Directory = FindCommaDelimited(DRIVER_DIRS, i++)) != NULL) { + SelfDirectory = StrDuplicate(SelfDirPath); + CleanUpPathNameSlashes(SelfDirectory); + MergeStrings(&SelfDirectory, Directory, L'\\'); + NumFound += ScanDriverDir(SelfDirectory); + FreePool(Directory); + FreePool(SelfDirectory); + } // Scan additional user-specified driver directories.... + i = 0; while ((Directory = FindCommaDelimited(GlobalConfig.DriverDirs, i++)) != NULL) { CleanUpPathNameSlashes(Directory); Length = StrLen(Directory); @@ -1333,18 +1408,6 @@ static VOID ScanForBootloaders(VOID) { UINTN i; ScanVolumes(); - // Commented-out below: Was part of an attempt to get rEFInd to - // re-scan disk devices on pressing Esc; but doesn't work (yet), so - // removed.... -// MainMenu.Title = StrDuplicate(L"Main Menu 2"); -// MainMenu.TitleImage = NULL; -// MainMenu.InfoLineCount = 0; -// MainMenu.InfoLines = NULL; -// MainMenu.EntryCount = 0; -// MainMenu.Entries = NULL; -// MainMenu.TimeoutSeconds = 20; -// MainMenu.TimeoutText = StrDuplicate(L"Automatic boot"); - // DebugPause(); // scan for loaders and tools, add them to the menu for (i = 0; i < NUM_SCAN_OPTIONS; i++) { @@ -1385,25 +1448,30 @@ static VOID ScanForBootloaders(VOID) { // reboot, etc.) static VOID ScanForTools(VOID) { CHAR16 *FileName = NULL; + REFIT_MENU_ENTRY *TempMenuEntry; UINTN i, j; for (i = 0; i < NUM_TOOLS; i++) { switch(GlobalConfig.ShowTools[i]) { case TAG_SHUTDOWN: - MenuEntryShutdown.Image = BuiltinIcon(BUILTIN_ICON_FUNC_SHUTDOWN); - AddMenuEntry(&MainMenu, &MenuEntryShutdown); + TempMenuEntry = CopyMenuEntry(&MenuEntryShutdown); + TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_SHUTDOWN); + AddMenuEntry(&MainMenu, TempMenuEntry); break; case TAG_REBOOT: - MenuEntryReset.Image = BuiltinIcon(BUILTIN_ICON_FUNC_RESET); - AddMenuEntry(&MainMenu, &MenuEntryReset); + TempMenuEntry = CopyMenuEntry(&MenuEntryReset); + TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_RESET); + AddMenuEntry(&MainMenu, TempMenuEntry); break; case TAG_ABOUT: - MenuEntryAbout.Image = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); - AddMenuEntry(&MainMenu, &MenuEntryAbout); + TempMenuEntry = CopyMenuEntry(&MenuEntryAbout); + TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT); + AddMenuEntry(&MainMenu, TempMenuEntry); break; case TAG_EXIT: - MenuEntryExit.Image = BuiltinIcon(BUILTIN_ICON_FUNC_EXIT); - AddMenuEntry(&MainMenu, &MenuEntryExit); + TempMenuEntry = CopyMenuEntry(&MenuEntryExit); + TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_EXIT); + AddMenuEntry(&MainMenu, TempMenuEntry); break; case TAG_SHELL: j = 0; @@ -1427,19 +1495,37 @@ static VOID ScanForTools(VOID) { } // for } // static VOID ScanForTools +// Rescan for boot loaders +VOID RescanAll(VOID) { + EG_PIXEL BGColor; + + BGColor.b = 255; + BGColor.g = 175; + BGColor.r = 100; + BGColor.a = 0; + egDisplayMessage(L"Scanning for new boot loaders; please wait....", &BGColor); + FreeList((VOID ***) &(MainMenu.Entries), &MainMenu.EntryCount); + MainMenu.Entries = NULL; + MainMenu.EntryCount = 0; + ReadConfig(); + ConnectAllDriversToAllControllers(); + ScanForBootloaders(); + ScanForTools(); + SetupScreen(); +} // VOID RescanAll() + // // main entry point // - EFI_STATUS EFIAPI efi_main (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) { - EFI_STATUS Status; - BOOLEAN MainLoopRunning = TRUE; - REFIT_MENU_ENTRY *ChosenEntry; - UINTN MenuExit; - CHAR16 *Selection; + EFI_STATUS Status; + BOOLEAN MainLoopRunning = TRUE; + REFIT_MENU_ENTRY *ChosenEntry; + UINTN MenuExit; + CHAR16 *Selection; // bootstrap InitializeLib(ImageHandle, SystemTable); @@ -1466,14 +1552,9 @@ efi_main (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) while (MainLoopRunning) { MenuExit = RunMainMenu(&MainMenu, Selection, &ChosenEntry); - // We don't allow exiting the main menu with the Escape key. + // The Escape key triggers a re-scan operation.... if (MenuExit == MENU_EXIT_ESCAPE) { - // Commented-out below: Was part of an attempt to get rEFInd to - // re-scan disk devices on pressing Esc; but doesn't work (yet), so - // removed.... -// ReadConfig(); -// ScanForBootloaders(); -// SetupScreen(); + RescanAll(); continue; }