#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
{
if (AboutMenu.EntryCount == 0) {
AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
- AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.3.4.1");
+ 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");
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).
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);
// 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);
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++) {
// 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;
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);
// 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;
}