#include "driver_support.h"
#include "../include/syslinux_mbr.h"
+#ifdef __MAKEWITH_TIANO
+#include "../EfiLib/BdsHelper.h"
+#endif // __MAKEWITH_TIANO
+
//
// variables
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, GRAPHICS_FOR_OSX, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+REFIT_CONFIG GlobalConfig = { FALSE, FALSE, 0, 0, 20, 0, 0, GRAPHICS_FOR_OSX, LEGACY_TYPE_MAC, 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
if (AboutMenu.EntryCount == 0) {
AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
- AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.2.1");
+ AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.4.5.4");
AddMenuInfoLine(&AboutMenu, L"");
AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012 Roderick W. Smith");
AddMenuInfoLine(&AboutMenu, L"Distributed under the terms of the GNU GPLv3 license");
AddMenuInfoLine(&AboutMenu, L"");
AddMenuInfoLine(&AboutMenu, L"Running on:");
- TempStr = AllocateZeroPool(255 * sizeof(CHAR16));
+ TempStr = AllocateZeroPool(256 * sizeof(CHAR16));
SPrint(TempStr, 255, L" EFI Revision %d.%02d", ST->Hdr.Revision >> 16, ST->Hdr.Revision & ((1 << 16) - 1));
AddMenuInfoLine(&AboutMenu, TempStr);
#if defined(EFI32)
#else
AddMenuInfoLine(&AboutMenu, L" Platform: unknown");
#endif
- TempStr = AllocateZeroPool(255 * sizeof(CHAR16));
+ TempStr = AllocateZeroPool(256 * sizeof(CHAR16));
SPrint(TempStr, 255, L" Firmware: %s %d.%02d",
ST->FirmwareVendor, ST->FirmwareRevision >> 16, ST->FirmwareRevision & ((1 << 16) - 1));
AddMenuInfoLine(&AboutMenu, TempStr);
- TempStr = AllocateZeroPool(255 * sizeof(CHAR16));
+ TempStr = AllocateZeroPool(256 * sizeof(CHAR16));
SPrint(TempStr, 255, L" Screen Output: %s", egScreenDescription());
AddMenuInfoLine(&AboutMenu, TempStr);
AddMenuInfoLine(&AboutMenu, L"");
MergeStrings(&FullLoadOptions, L" ", 0);
// NOTE: That last space is also added by the EFI shell and seems to be significant
// when passing options to Apple's boot.efi...
- }
+ } else {
+ MergeStrings(&FullLoadOptions, LoadOptions, 0);
+ } // if/else
// NOTE: We also include the terminating null in the length for safety.
ChildLoadedImage->LoadOptions = (VOID *)FullLoadOptions;
ChildLoadedImage->LoadOptionsSize = ((UINT32)StrLen(FullLoadOptions) + 1) * sizeof(CHAR16);
// Returns a pointer to the new subscreen data structure, or NULL if there
// were problems allocating memory.
REFIT_MENU_SCREEN *InitializeSubScreen(IN LOADER_ENTRY *Entry) {
- CHAR16 *FileName, *Temp = NULL, *TitleStr;
+ CHAR16 *FileName, *Temp = NULL;
REFIT_MENU_SCREEN *SubScreen = NULL;
LOADER_ENTRY *SubEntry;
if (Entry->me.SubScreen == NULL) { // No subscreen yet; initialize default entry....
SubScreen = AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
if (SubScreen != NULL) {
- TitleStr = AllocateZeroPool(sizeof(CHAR16) * 256);
- SPrint(TitleStr, 255, L"Boot Options for %s on %s", (Entry->Title != NULL) ? Entry->Title : FileName, Entry->VolName);
- SubScreen->Title = TitleStr;
+ SubScreen->Title = AllocateZeroPool(sizeof(CHAR16) * 256);
+ SPrint(SubScreen->Title, 255, L"Boot Options for %s on %s",
+ (Entry->Title != NULL) ? Entry->Title : FileName, Entry->VolName);
SubScreen->TitleImage = Entry->me.Image;
// default entry
SubEntry = InitializeLoaderEntry(Entry);
// for icons, options, etc.
LOADER_ENTRY * AddLoaderEntry(IN CHAR16 *LoaderPath, IN CHAR16 *LoaderTitle, IN REFIT_VOLUME *Volume) {
LOADER_ENTRY *Entry;
- CHAR16 *PoolStr;
CleanUpPathNameSlashes(LoaderPath);
Entry = InitializeLoaderEntry(NULL);
if (Entry != NULL) {
Entry->Title = StrDuplicate((LoaderTitle != NULL) ? LoaderTitle : LoaderPath);
- PoolStr = AllocateZeroPool(sizeof(CHAR16) * 256);
- SPrint(PoolStr, 255, L"Boot %s from %s", (LoaderTitle != NULL) ? LoaderTitle : LoaderPath, Volume->VolName);
- Entry->me.Title = PoolStr;
+ Entry->me.Title = AllocateZeroPool(sizeof(CHAR16) * 256);
+ SPrint(Entry->me.Title, 255, L"Boot %s from %s", (LoaderTitle != NULL) ? LoaderTitle : LoaderPath, Volume->VolName);
Entry->me.Row = 0;
Entry->me.BadgeImage = Volume->VolBadgeImage;
if ((LoaderPath != NULL) && (LoaderPath[0] != L'\\')) {
(UGAHeight - BootLogoImage->Height) >> 1,
&StdBackgroundPixel);
- if (Entry->Volume->IsMbrPartition)
+ if (Entry->Volume->IsMbrPartition) {
ActivateMbrPartition(Entry->Volume->WholeDiskBlockIO, Entry->Volume->MbrPartitionIndex);
+ }
ExtractLegacyLoaderPaths(DiscoveredPathList, MAX_DISCOVERED_PATHS, LegacyLoaderList);
FinishExternalScreen();
} /* static VOID StartLegacy() */
+// Start a device on a non-Mac using the EFI_LEGACY_BIOS_PROTOCOL
+#ifdef __MAKEWITH_TIANO
+static VOID StartLegacyNonMac(IN LEGACY_ENTRY *Entry)
+{
+ BdsLibConnectDevicePath (Entry->BdsOption->DevicePath);
+ BdsLibDoLegacyBoot(Entry->BdsOption);
+}
+#endif // __MAKEWITH_TIANO
+
static LEGACY_ENTRY * AddLegacyEntry(IN CHAR16 *LoaderTitle, IN REFIT_VOLUME *Volume)
{
LEGACY_ENTRY *Entry, *SubEntry;
REFIT_MENU_SCREEN *SubScreen;
CHAR16 *VolDesc;
CHAR16 ShortcutLetter = 0;
- CHAR16 *PoolStr;
if (LoaderTitle == NULL) {
if (Volume->OSName != NULL) {
// prepare the menu entry
Entry = AllocateZeroPool(sizeof(LEGACY_ENTRY));
- PoolStr = AllocateZeroPool(256 * sizeof(CHAR16));
- SPrint(PoolStr, 255, L"Boot %s from %s", LoaderTitle, VolDesc);
- Entry->me.Title = PoolStr;
+ Entry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16));
+ SPrint(Entry->me.Title, 255, L"Boot %s from %s", LoaderTitle, VolDesc);
Entry->me.Tag = TAG_LEGACY;
Entry->me.Row = 0;
Entry->me.ShortcutLetter = ShortcutLetter;
// create the submenu
SubScreen = AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
- PoolStr = AllocateZeroPool(256 * sizeof(CHAR16));
- SPrint(PoolStr, 255, L"Boot Options for %s on %s", LoaderTitle, VolDesc);
- SubScreen->Title = PoolStr;
+ SubScreen->Title = AllocateZeroPool(256 * sizeof(CHAR16));
+ SPrint(SubScreen->Title, 255, L"Boot Options for %s on %s", LoaderTitle, VolDesc);
SubScreen->TitleImage = Entry->me.Image;
// default entry
SubEntry = AllocateZeroPool(sizeof(LEGACY_ENTRY));
- PoolStr = AllocateZeroPool(256 * sizeof(CHAR16));
- SPrint(PoolStr, 255, L"Boot %s", LoaderTitle);
- SubEntry->me.Title = PoolStr;
+ SubEntry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16));
+ SPrint(SubEntry->me.Title, 255, L"Boot %s", LoaderTitle);
SubEntry->me.Tag = TAG_LEGACY;
SubEntry->Volume = Entry->Volume;
SubEntry->LoadOptions = Entry->LoadOptions;
return Entry;
} /* static LEGACY_ENTRY * AddLegacyEntry() */
+
+#ifdef __MAKEWITH_TIANO
+/**
+ Create a rEFInd boot option from a Legacy BIOS protocol option.
+*/
+static LEGACY_ENTRY * AddLegacyEntryNonMac(BDS_COMMON_OPTION *BdsOption, IN UINT16 DiskType)
+{
+ LEGACY_ENTRY *Entry, *SubEntry;
+ REFIT_MENU_SCREEN *SubScreen;
+ CHAR16 ShortcutLetter = 0;
+ CHAR16 *LegacyDescription = BdsOption->Description;
+
+ // prepare the menu entry
+ Entry = AllocateZeroPool(sizeof(LEGACY_ENTRY));
+ Entry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16));
+ SPrint(Entry->me.Title, 255, L"Boot legacy target %s", LegacyDescription);
+ Entry->me.Tag = TAG_LEGACY_NON_MAC;
+ Entry->me.Row = 0;
+ Entry->me.ShortcutLetter = ShortcutLetter;
+ Entry->me.Image = LoadOSIcon(L"legacy", L"legacy", TRUE);
+ Entry->LoadOptions = (DiskType == BBS_CDROM) ? L"CD" :
+ ((DiskType == BBS_USB) ? L"USB" : L"HD");
+ Entry->me.BadgeImage = NULL;
+ Entry->BdsOption = BdsOption;
+ Entry->Enabled = TRUE;
+
+ // create the submenu
+ SubScreen = AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
+ SubScreen->Title = AllocateZeroPool(256 * sizeof(CHAR16));
+ SPrint(SubScreen->Title, 255, L"No boot options for legacy target");
+ SubScreen->TitleImage = Entry->me.Image;
+
+ // default entry
+ SubEntry = AllocateZeroPool(sizeof(LEGACY_ENTRY));
+ SubEntry->me.Title = AllocateZeroPool(256 * sizeof(CHAR16));
+ SPrint(SubEntry->me.Title, 255, L"Boot %s", LegacyDescription);
+ SubEntry->me.Tag = TAG_LEGACY_NON_MAC;
+ Entry->BdsOption = BdsOption;
+ AddMenuEntry(SubScreen, (REFIT_MENU_ENTRY *)SubEntry);
+
+ AddMenuEntry(SubScreen, &MenuEntryReturn);
+ Entry->me.SubScreen = SubScreen;
+ AddMenuEntry(&MainMenu, (REFIT_MENU_ENTRY *)Entry);
+ return Entry;
+} /* static LEGACY_ENTRY * AddLegacyEntryNonMac() */
+
+/**
+ Scan for legacy BIOS targets on machines that implement EFI_LEGACY_BIOS_PROTOCOL.
+ In testing, protocol has not been implemented on Macs but has been
+ implemented on several Dell PCs and an ASUS motherboard.
+*/
+static VOID ScanLegacyNonMac(IN UINTN DiskType)
+{
+ EFI_STATUS Status;
+ EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
+ UINT16 *BootOrder = NULL;
+ UINTN Index = 0;
+ UINT16 BootOption[10];
+ UINTN BootOrderSize = 0;
+ CHAR16 Buffer[20];
+ BDS_COMMON_OPTION *BdsOption;
+ LIST_ENTRY TempList;
+ BBS_BBS_DEVICE_PATH * BbsDevicePath = NULL;
+
+ InitializeListHead (&TempList);
+ ZeroMem (Buffer, sizeof (Buffer));
+
+ // If LegacyBios protocol is not implemented on this platform, then
+ //we do not support this type of legacy boot on this machine.
+ Status = gBS->LocateProtocol (&gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios);
+ if (EFI_ERROR (Status))
+ return;
+
+ // Grab the boot order
+ BootOrder = BdsLibGetVariableAndSize (L"BootOrder", &gEfiGlobalVariableGuid, &BootOrderSize);
+ if (BootOrder == NULL) {
+ BootOrderSize = 0;
+ }
+
+ Index = 0;
+ while (Index < BootOrderSize / sizeof (UINT16))
+ {
+ // Grab each boot option variable from the boot order, and convert
+ // the variable into a BDS boot option
+ UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
+ BdsOption = BdsLibVariableToOption (&TempList, BootOption);
+
+ if(BdsOption != NULL) {
+ //Print(L"Option description = '%s'\n", BdsOption->Description);
+ BbsDevicePath = (BBS_BBS_DEVICE_PATH *)BdsOption->DevicePath;
+
+ // Only add the entry if it is of a supported type (e.g. USB, HD)
+ // See BdsHelper.c for currently supported types
+ if (BbsDevicePath->DeviceType == DiskType) {
+// if(IsBbsDeviceTypeSupported(BbsDevicePath->DeviceType)) {
+ AddLegacyEntryNonMac(BdsOption, BbsDevicePath->DeviceType);
+ }
+ }
+ Index++;
+ }
+} /* static VOID ScanLegacyNonMac() */
+#else
+static VOID ScanLegacyNonMac(IN UINTN DiskType){}
+#endif // __MAKEWITH_TIANO
+
static VOID ScanLegacyVolume(REFIT_VOLUME *Volume, UINTN VolumeIndex) {
UINTN VolumeIndex2;
BOOLEAN ShowVolume, HideIfOthersFound;
UINTN VolumeIndex;
REFIT_VOLUME *Volume;
- for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
- Volume = Volumes[VolumeIndex];
- if (Volume->DiskKind == DISK_KIND_OPTICAL)
- ScanLegacyVolume(Volume, VolumeIndex);
- } // for
+ if (GlobalConfig.LegacyType == LEGACY_TYPE_MAC) {
+ for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+ Volume = Volumes[VolumeIndex];
+ if (Volume->DiskKind == DISK_KIND_OPTICAL)
+ ScanLegacyVolume(Volume, VolumeIndex);
+ } // for
+ } else if (GlobalConfig.LegacyType == LEGACY_TYPE_UEFI) {
+ ScanLegacyNonMac(BBS_CDROM);
+ }
} /* static VOID ScanLegacyDisc() */
// Scan internal hard disks for legacy (BIOS) boot code
UINTN VolumeIndex;
REFIT_VOLUME *Volume;
- for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
- Volume = Volumes[VolumeIndex];
- if (Volume->DiskKind == DISK_KIND_INTERNAL)
- ScanLegacyVolume(Volume, VolumeIndex);
- } // for
+ if (GlobalConfig.LegacyType == LEGACY_TYPE_MAC) {
+ for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+ Volume = Volumes[VolumeIndex];
+ if (Volume->DiskKind == DISK_KIND_INTERNAL)
+ ScanLegacyVolume(Volume, VolumeIndex);
+ } // for
+ } else if (GlobalConfig.LegacyType == LEGACY_TYPE_UEFI) {
+ ScanLegacyNonMac(BBS_HARDDISK);
+ }
} /* static VOID ScanLegacyInternal() */
// Scan external disks for legacy (BIOS) boot code
UINTN VolumeIndex;
REFIT_VOLUME *Volume;
- for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
- Volume = Volumes[VolumeIndex];
- if (Volume->DiskKind == DISK_KIND_EXTERNAL)
- ScanLegacyVolume(Volume, VolumeIndex);
- } // for
+ if (GlobalConfig.LegacyType == LEGACY_TYPE_MAC) {
+ for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
+ Volume = Volumes[VolumeIndex];
+ if (Volume->DiskKind == DISK_KIND_EXTERNAL)
+ ScanLegacyVolume(Volume, VolumeIndex);
+ } // for
+ } else if (GlobalConfig.LegacyType == LEGACY_TYPE_UEFI) {
+ ScanLegacyNonMac(BBS_USB);
+ }
} /* static VOID ScanLegacyExternal() */
//
ConnectAllDriversToAllControllers();
} /* static VOID LoadDrivers() */
+
static VOID ScanForBootloaders(VOID) {
- UINTN i;
+ UINTN i;
+#ifdef __MAKEWITH_TIANO
+ EFI_STATUS Status;
+ EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
+#endif
ScanVolumes();
+#ifdef __MAKEWITH_TIANO
+ // Check for UEFI-style legacy BIOS support. If present, set the appropriate
+ // GlobalConfig flag for it.
+ Status = gBS->LocateProtocol (&gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios);
+ if (!EFI_ERROR (Status))
+ GlobalConfig.LegacyType = LEGACY_TYPE_UEFI;
+#endif
+
// scan for loaders and tools, add them to the menu
for (i = 0; i < NUM_SCAN_OPTIONS; i++) {
switch(GlobalConfig.ScanFor[i]) {
// gImageHandle = ImageHandle;
gBS = SystemTable->BootServices;
// gRS = SystemTable->RuntimeServices;
+ gRT = SystemTable->RuntimeServices; // Some BDS functions need gRT to be set
EfiGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);
InitializeConsoleSim();
EFI_STATUS Status;
BOOLEAN MainLoopRunning = TRUE;
REFIT_MENU_ENTRY *ChosenEntry;
- UINTN MenuExit;
+ UINTN MenuExit, i;
CHAR16 *Selection;
+ EG_PIXEL BGColor;
// bootstrap
InitializeLib(ImageHandle, SystemTable);
return Status;
// read configuration
- CopyMem(GlobalConfig.ScanFor, "ieo ", NUM_SCAN_OPTIONS);
+ CopyMem(GlobalConfig.ScanFor, "ieom ", NUM_SCAN_OPTIONS);
ReadConfig();
MainMenu.TimeoutSeconds = GlobalConfig.Timeout;
// further bootstrap (now with config available)
SetupScreen();
+ if (GlobalConfig.ScanDelay > 0) {
+ BGColor.b = 255;
+ BGColor.g = 175;
+ BGColor.r = 100;
+ BGColor.a = 0;
+ egDisplayMessage(L"Pausing before disk scan; please wait....", &BGColor);
+ for (i = 0; i < GlobalConfig.ScanDelay; i++)
+ refit_call1_wrapper(BS->Stall, 1000000);
+ } // if
LoadDrivers();
ScanForBootloaders();
ScanForTools();
StartLegacy((LEGACY_ENTRY *)ChosenEntry);
break;
+#ifdef __MAKEWITH_TIANO
+ case TAG_LEGACY_NON_MAC: // Boot a legacy OS on a non-Mac
+ StartLegacyNonMac((LEGACY_ENTRY *)ChosenEntry);
+ break;
+#endif // __MAKEWITH_TIANO
+
case TAG_TOOL: // Start a EFI tool
StartTool((LOADER_ENTRY *)ChosenEntry);
break;