X-Git-Url: https://code.delx.au/refind/blobdiff_plain/b7734df2ccc0b0e943a8ce2c1f6d25e76e78e6f8..65eb839a6d8d68a439056473a0d3728dfd39d2c4:/refind/main.c diff --git a/refind/main.c b/refind/main.c index 6bdc3a1..8dd041e 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, +REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 20, 0, 0, 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.1.2"); + AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.0"); AddMenuInfoLine(&AboutMenu, L""); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer"); AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith"); @@ -273,8 +275,8 @@ static CHAR16 * FindInitrd(IN CHAR16 *LoaderPath, IN REFIT_VOLUME *Volume) { while ((DirIterNext(&DirIter, 2, L"init*", &DirEntry)) && (InitrdName == NULL)) { InitrdVersion = FindNumbers(DirEntry->FileName); if (KernelVersion != NULL) { - if (StriCmp(InitrdVersion, KernelVersion) == 0) - InitrdName = PoolPrint(L"%s%s", Path, DirEntry->FileName); + if (StriCmp(InitrdVersion, KernelVersion) == 0) + InitrdName = PoolPrint(L"%s%s", Path, DirEntry->FileName); } else { if (InitrdVersion == NULL) InitrdName = PoolPrint(L"%s%s", Path, DirEntry->FileName); @@ -296,6 +298,66 @@ 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); +// NewEntry->SubScreen = AllocatePool(sizeof(REFIT_MENU_SCREEN)); +// if (NewEntry->SubScreen != NULL) +// CopyMem(NewEntry->SubScreen, Entry->SubScreen, sizeof(REFIT_MENU_SCREEN)); + } + } // 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). @@ -604,6 +666,9 @@ VOID SetLoaderDefaults(LOADER_ENTRY *Entry, CHAR16 *LoaderPath, IN REFIT_VOLUME Entry->OSType = 'E'; if (ShortcutLetter == 0) ShortcutLetter = 'L'; + } else if (StriSubCmp(L"grub", FileName)) { + Entry->OSType = 'G'; + ShortcutLetter = 'G'; } else if (StriCmp(FileName, L"cdboot.efi") == 0 || StriCmp(FileName, L"bootmgr.efi") == 0 || StriCmp(FileName, L"Bootmgfw.efi") == 0) { @@ -635,11 +700,16 @@ LOADER_ENTRY * AddLoaderEntry(IN CHAR16 *LoaderPath, IN CHAR16 *LoaderTitle, IN Entry = InitializeLoaderEntry(NULL); if (Entry != NULL) { Entry->Title = StrDuplicate((LoaderTitle != NULL) ? LoaderTitle : LoaderPath); -// Entry->Title = StrDuplicate(LoaderTitle); 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); @@ -1173,10 +1243,10 @@ static VOID ScanLegacyExternal(VOID) static VOID StartTool(IN LOADER_ENTRY *Entry) { - BeginExternalScreen(Entry->UseGraphicsMode, Entry->me.Title + 6); // assumes "Start " as assigned below - StartEFIImage(Entry->DevicePath, Entry->LoadOptions, Basename(Entry->LoaderPath), - Basename(Entry->LoaderPath), NULL, TRUE); - FinishExternalScreen(); + BeginExternalScreen(Entry->UseGraphicsMode, Entry->me.Title + 6); // assumes "Start <title>" as assigned below + StartEFIImage(Entry->DevicePath, Entry->LoadOptions, Basename(Entry->LoaderPath), + Basename(Entry->LoaderPath), NULL, TRUE); + FinishExternalScreen(); } /* static VOID StartTool() */ static LOADER_ENTRY * AddToolEntry(IN CHAR16 *LoaderPath, IN CHAR16 *LoaderTitle, IN EG_IMAGE *Image, @@ -1304,16 +1374,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); @@ -1331,18 +1407,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++) { @@ -1383,31 +1447,36 @@ 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; while ((FileName = FindCommaDelimited(SHELL_NAMES, j++)) != NULL) { if (FileExists(SelfRootDir, FileName)) { - AddToolEntry(FileName, L"EFI Shell", BuiltinIcon(BUILTIN_ICON_TOOL_SHELL), 'E', FALSE); + AddToolEntry(FileName, L"EFI Shell", BuiltinIcon(BUILTIN_ICON_TOOL_SHELL), 'S', FALSE); } } // while break; @@ -1433,10 +1502,11 @@ 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; + EFI_STATUS Status; + BOOLEAN MainLoopRunning = TRUE; + REFIT_MENU_ENTRY *ChosenEntry; + UINTN MenuExit; + CHAR16 *Selection; // bootstrap InitializeLib(ImageHandle, SystemTable); @@ -1459,17 +1529,20 @@ efi_main (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) ScanForBootloaders(); ScanForTools(); + Selection = StrDuplicate(GlobalConfig.DefaultSelection); while (MainLoopRunning) { - MenuExit = RunMainMenu(&MainMenu, GlobalConfig.DefaultSelection, &ChosenEntry); + MenuExit = RunMainMenu(&MainMenu, Selection, &ChosenEntry); // We don't allow exiting the main menu with the Escape key. 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(); + FreeList((VOID ***) &(MainMenu.Entries), &MainMenu.EntryCount); + MainMenu.Entries = NULL; + MainMenu.EntryCount = 0; + ReadConfig(); + ConnectAllDriversToAllControllers(); + ScanForBootloaders(); + ScanForTools(); + SetupScreen(); continue; } @@ -1508,8 +1581,10 @@ efi_main (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) return EFI_SUCCESS; break; - } - } + } // switch() + FreePool(Selection); + Selection = StrDuplicate(ChosenEntry->Title); + } // while() // If we end up here, things have gone wrong. Try to reboot, and if that // fails, go into an endless loop.