+
+#ifdef __MAKEWITH_TIANO
+// default volume badge icon based on disk kind
+static EG_IMAGE * GetDiskBadge(IN UINTN DiskType) {
+ EG_IMAGE * Badge = NULL;
+
+ switch (DiskType) {
+ case BBS_HARDDISK:
+ Badge = BuiltinIcon(BUILTIN_ICON_VOL_INTERNAL);
+ break;
+ case BBS_USB:
+ Badge = BuiltinIcon(BUILTIN_ICON_VOL_EXTERNAL);
+ break;
+ case BBS_CDROM:
+ Badge = BuiltinIcon(BUILTIN_ICON_VOL_OPTICAL);
+ break;
+ } // switch()
+ return Badge;
+} // static EG_IMAGE * GetDiskBadge()
+
+/**
+ Create a rEFInd boot option from a Legacy BIOS protocol option.
+*/
+static LEGACY_ENTRY * AddLegacyEntryUEFI(BDS_COMMON_OPTION *BdsOption, IN UINT16 DiskType)
+{
+ LEGACY_ENTRY *Entry, *SubEntry;
+ REFIT_MENU_SCREEN *SubScreen;
+ CHAR16 ShortcutLetter = 0;
+ CHAR16 *LegacyDescription = BdsOption->Description;
+
+// ScanVolume(Volume);
+
+ // 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_UEFI;
+ 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 = GetDiskBadge(DiskType);
+// Entry->me.BadgeImage = Volume->VolBadgeImage;
+ 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_UEFI;
+ 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 * AddLegacyEntryUEFI() */
+
+/**
+ 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.
+ Restricts output to disks of the specified DiskType.
+*/
+static VOID ScanLegacyUEFI(IN UINTN DiskType)
+{
+ EFI_STATUS Status;
+ EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
+ UINT16 *BootOrder = NULL;
+ UINTN Index = 0;
+ CHAR16 BootOption[10];
+ UINTN BootOrderSize = 0;
+ CHAR16 Buffer[20];
+ BDS_COMMON_OPTION *BdsOption;
+ LIST_ENTRY TempList;
+ BBS_BBS_DEVICE_PATH * BbsDevicePath = NULL;
+// REFIT_VOLUME Volume;
+
+ 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) {
+ BbsDevicePath = (BBS_BBS_DEVICE_PATH *)BdsOption->DevicePath;
+
+ // Only add the entry if it is of a requested type (e.g. USB, HD)
+
+ // Two checks necessary because some systems return EFI boot loaders
+ // with a DeviceType value that would inappropriately include them
+ // as legacy loaders....
+ if ((BbsDevicePath->DeviceType == DiskType) && (BdsOption->DevicePath->Type == DEVICE_TYPE_BIOS)) {
+ AddLegacyEntryUEFI(BdsOption, BbsDevicePath->DeviceType);
+ }
+ }
+ Index++;
+ }
+} /* static VOID ScanLegacyUEFI() */
+#else
+static VOID ScanLegacyUEFI(IN UINTN DiskType){}
+#endif // __MAKEWITH_TIANO
+