- UINTN VolumeIndex;
-
- for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) {
- if (Volumes[VolumeIndex]->DiskKind == DISK_KIND_OPTICAL) {
- ScanEfiFiles(Volumes[VolumeIndex]);
- }
- } // for
-} // static VOID ScanOptical()
-
-//
-// legacy boot functions
-//
-
-static EFI_STATUS ActivateMbrPartition(IN EFI_BLOCK_IO *BlockIO, IN UINTN PartitionIndex)
-{
- EFI_STATUS Status;
- UINT8 SectorBuffer[512];
- MBR_PARTITION_INFO *MbrTable, *EMbrTable;
- UINT32 ExtBase, ExtCurrent, NextExtCurrent;
- UINTN LogicalPartitionIndex = 4;
- UINTN i;
- BOOLEAN HaveBootCode;
-
- // read MBR
- Status = refit_call5_wrapper(BlockIO->ReadBlocks, BlockIO, BlockIO->Media->MediaId, 0, 512, SectorBuffer);
- if (EFI_ERROR(Status))
- return Status;
- if (*((UINT16 *)(SectorBuffer + 510)) != 0xaa55)
- return EFI_NOT_FOUND; // safety measure #1
-
- // add boot code if necessary
- HaveBootCode = FALSE;
- for (i = 0; i < MBR_BOOTCODE_SIZE; i++) {
- if (SectorBuffer[i] != 0) {
- HaveBootCode = TRUE;
- break;
- }
- }
- if (!HaveBootCode) {
- // no boot code found in the MBR, add the syslinux MBR code
- SetMem(SectorBuffer, MBR_BOOTCODE_SIZE, 0);
- CopyMem(SectorBuffer, syslinux_mbr, SYSLINUX_MBR_SIZE);
- }
-
- // set the partition active
- MbrTable = (MBR_PARTITION_INFO *)(SectorBuffer + 446);
- ExtBase = 0;
- for (i = 0; i < 4; i++) {
- if (MbrTable[i].Flags != 0x00 && MbrTable[i].Flags != 0x80)
- return EFI_NOT_FOUND; // safety measure #2
- if (i == PartitionIndex)
- MbrTable[i].Flags = 0x80;
- else if (PartitionIndex >= 4 && IS_EXTENDED_PART_TYPE(MbrTable[i].Type)) {
- MbrTable[i].Flags = 0x80;
- ExtBase = MbrTable[i].StartLBA;
- } else
- MbrTable[i].Flags = 0x00;
- }
-
- // write MBR
- Status = refit_call5_wrapper(BlockIO->WriteBlocks, BlockIO, BlockIO->Media->MediaId, 0, 512, SectorBuffer);
- if (EFI_ERROR(Status))
- return Status;
-
- if (PartitionIndex >= 4) {
- // we have to activate a logical partition, so walk the EMBR chain
-
- // NOTE: ExtBase was set above while looking at the MBR table
- for (ExtCurrent = ExtBase; ExtCurrent; ExtCurrent = NextExtCurrent) {
- // read current EMBR
- Status = refit_call5_wrapper(BlockIO->ReadBlocks, BlockIO, BlockIO->Media->MediaId, ExtCurrent, 512, SectorBuffer);
- if (EFI_ERROR(Status))
- return Status;
- if (*((UINT16 *)(SectorBuffer + 510)) != 0xaa55)
- return EFI_NOT_FOUND; // safety measure #3
-
- // scan EMBR, set appropriate partition active
- EMbrTable = (MBR_PARTITION_INFO *)(SectorBuffer + 446);
- NextExtCurrent = 0;
- for (i = 0; i < 4; i++) {
- if (EMbrTable[i].Flags != 0x00 && EMbrTable[i].Flags != 0x80)
- return EFI_NOT_FOUND; // safety measure #4
- if (EMbrTable[i].StartLBA == 0 || EMbrTable[i].Size == 0)
- break;
- if (IS_EXTENDED_PART_TYPE(EMbrTable[i].Type)) {
- // link to next EMBR
- NextExtCurrent = ExtBase + EMbrTable[i].StartLBA;
- EMbrTable[i].Flags = (PartitionIndex >= LogicalPartitionIndex) ? 0x80 : 0x00;
- break;
- } else {
- // logical partition
- EMbrTable[i].Flags = (PartitionIndex == LogicalPartitionIndex) ? 0x80 : 0x00;
- LogicalPartitionIndex++;
- }
- }
-
- // write current EMBR
- Status = refit_call5_wrapper(BlockIO->WriteBlocks, BlockIO, BlockIO->Media->MediaId, ExtCurrent, 512, SectorBuffer);
- if (EFI_ERROR(Status))
- return Status;
-
- if (PartitionIndex < LogicalPartitionIndex)
- break; // stop the loop, no need to touch further EMBRs
- }
-
- }
-
- return EFI_SUCCESS;
-} /* static EFI_STATUS ActivateMbrPartition() */
-
-// early 2006 Core Duo / Core Solo models
-static UINT8 LegacyLoaderDevicePath1Data[] = {
- 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xF9, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
- 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
- 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
-};
-// mid-2006 Mac Pro (and probably other Core 2 models)
-static UINT8 LegacyLoaderDevicePath2Data[] = {
- 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xF7, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
- 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
- 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
-};
-// mid-2007 MBP ("Santa Rosa" based models)
-static UINT8 LegacyLoaderDevicePath3Data[] = {
- 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xE0, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
- 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
- 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
-};
-// early-2008 MBA
-static UINT8 LegacyLoaderDevicePath4Data[] = {
- 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xFF, 0xF8, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
- 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
- 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
-};
-// late-2008 MB/MBP (NVidia chipset)
-static UINT8 LegacyLoaderDevicePath5Data[] = {
- 0x01, 0x03, 0x18, 0x00, 0x0B, 0x00, 0x00, 0x00,
- 0x00, 0x40, 0xCB, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0xFF, 0xBF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
- 0x04, 0x06, 0x14, 0x00, 0xEB, 0x85, 0x05, 0x2B,
- 0xB8, 0xD8, 0xA9, 0x49, 0x8B, 0x8C, 0xE2, 0x1B,
- 0x01, 0xAE, 0xF2, 0xB7, 0x7F, 0xFF, 0x04, 0x00,
-};
-
-static EFI_DEVICE_PATH *LegacyLoaderList[] = {
- (EFI_DEVICE_PATH *)LegacyLoaderDevicePath1Data,
- (EFI_DEVICE_PATH *)LegacyLoaderDevicePath2Data,
- (EFI_DEVICE_PATH *)LegacyLoaderDevicePath3Data,
- (EFI_DEVICE_PATH *)LegacyLoaderDevicePath4Data,
- (EFI_DEVICE_PATH *)LegacyLoaderDevicePath5Data,
- NULL
-};
-
-#define MAX_DISCOVERED_PATHS (16)
-
-static VOID StartLegacy(IN LEGACY_ENTRY *Entry, IN CHAR16 *SelectionName)
-{
- EFI_STATUS Status;
- EG_IMAGE *BootLogoImage;
- UINTN ErrorInStep = 0;
- EFI_DEVICE_PATH *DiscoveredPathList[MAX_DISCOVERED_PATHS];
-
- BeginExternalScreen(TRUE, L"Booting Legacy OS (Mac mode)");
-
- BootLogoImage = LoadOSIcon(Entry->Volume->OSIconName, L"legacy", TRUE);
- if (BootLogoImage != NULL)
- BltImageAlpha(BootLogoImage,
- (UGAWidth - BootLogoImage->Width ) >> 1,
- (UGAHeight - BootLogoImage->Height) >> 1,
- &StdBackgroundPixel);
-
- if (Entry->Volume->IsMbrPartition) {
- ActivateMbrPartition(Entry->Volume->WholeDiskBlockIO, Entry->Volume->MbrPartitionIndex);
- }
-
- ExtractLegacyLoaderPaths(DiscoveredPathList, MAX_DISCOVERED_PATHS, LegacyLoaderList);