VirtualBox

Changeset 82322 in vbox for trunk/src/VBox/Devices/EFI


Ignore:
Timestamp:
Dec 2, 2019 2:24:28 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135146
Message:

EFI/Firmware: Workaround two issues with device paths created by macOS AppleACPIPlatofrm.kext which result in non working boot entries, bugref:6930

Location:
trunk/src/VBox/Devices/EFI/Firmware
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/C/DevicePath/DevicePathFromText.c

    r80721 r82322  
    33383338  {L"UartFlowCtrl",            DevPathFromTextUartFlowCtrl            },
    33393339  {L"SAS",                     DevPathFromTextSAS                     },
     3340#ifndef VBOX
    33403341  {L"SasEx",                   DevPathFromTextSasEx                   },
     3342#else
     3343  {L"NVMe",                    DevPathFromTextNVMe                    },
     3344#endif
    33413345  {L"NVMe",                    DevPathFromTextNVMe                    },
    33423346  {L"UFS",                     DevPathFromTextUfs                     },
  • trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Core/Dxe/Hand/Locate.c

    r80721 r82322  
    398398  return Handle;
    399399}
     400
     401
     402#ifdef VBOX
     403/**
     404 * This works around several issues with device paths created by macOS AppleACPIPlatform.kext.
     405 *
     406 * See @bugref{6930} comment 84 and following for an in depth explanation.
     407 */
     408BOOLEAN
     409EFIAPI
     410vboxDevicePathCompareMacOsHacks(IN EFI_DEVICE_PATH_PROTOCOL *LocateDevicePath,
     411                                IN EFI_DEVICE_PATH_PROTOCOL *HandleDevicePath,
     412                                UINTN Size)
     413{
     414    EFI_DEVICE_PATH_PROTOCOL *AlteredDevicePath = NULL;
     415    EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath = LocateDevicePath;
     416
     417    /* First check whether the device path to be located contains a NVMe or SATA node where we have to employ the hacks. */
     418    while (!IsDevicePathEnd(TmpDevicePath)) {
     419        if (IsDevicePathEndInstance(TmpDevicePath)) {
     420          //
     421          // If DevicePath is a multi-instance device path,
     422          // the function will operate on the first instance
     423          //
     424          break;
     425        }
     426
     427        if (   DevicePathType(TmpDevicePath) == MESSAGING_DEVICE_PATH
     428            && DevicePathSubType(TmpDevicePath) == MSG_SASEX_DP)
     429        {
     430            /*
     431             * macOS uses the SasEx path sub type for NVMe entries (the node is actually an
     432             * NVMe one). So we alter the device path to contain a proper NVMe sub type for
     433             * matching against the devices device path.
     434             */
     435            AlteredDevicePath = DuplicateDevicePath(LocateDevicePath);
     436            if (AlteredDevicePath != NULL)
     437            {
     438                UINTN offNode = (UINTN)TmpDevicePath - (UINTN)LocateDevicePath;
     439                EFI_DEVICE_PATH_PROTOCOL *NvmeNode = (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)AlteredDevicePath + offNode);
     440
     441                NvmeNode->SubType = MSG_NVME_NAMESPACE_DP;
     442            }
     443            break;
     444        }
     445        else if (   DevicePathType(TmpDevicePath) == MESSAGING_DEVICE_PATH
     446                 && DevicePathSubType(TmpDevicePath) == MSG_SATA_DP)
     447        {
     448            /*
     449             * macOS uses a 0 port multiplier number for devices directly attached
     450             * to the HBA while it should be 0xffff according to the UEFI spec.
     451             * We alter this here and try to match against the devices device path.
     452             */
     453            AlteredDevicePath = DuplicateDevicePath(LocateDevicePath);
     454            if (AlteredDevicePath != NULL)
     455            {
     456                UINTN offNode = (UINTN)TmpDevicePath - (UINTN)LocateDevicePath;
     457                SATA_DEVICE_PATH *SataNode = (SATA_DEVICE_PATH *)((UINTN)AlteredDevicePath + offNode);
     458
     459                SataNode->PortMultiplierPortNumber = 0xffff;
     460            }
     461            break;
     462        }
     463
     464        TmpDevicePath = NextDevicePathNode(TmpDevicePath);
     465    }
     466
     467    if (AlteredDevicePath != NULL)
     468    {
     469        BOOLEAN fMatch = CompareMem(AlteredDevicePath, HandleDevicePath, Size) == 0;
     470        FreePool(AlteredDevicePath);
     471        return fMatch;
     472    }
     473
     474    return FALSE;
     475}
     476#endif
    400477
    401478
     
    485562    Size = GetDevicePathSize (TmpDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
    486563    ASSERT (Size >= 0);
     564#ifndef VBOX
    487565    if ((Size <= SourceSize) && CompareMem (SourcePath, TmpDevicePath, (UINTN) Size) == 0) {
     566#else
     567    if (   (Size <= SourceSize)
     568        && (   CompareMem (SourcePath, TmpDevicePath, (UINTN) Size) == 0
     569            || vboxDevicePathCompareMacOsHacks(SourcePath, TmpDevicePath, (UINTN)Size))) {
     570#endif
    488571      //
    489572      // If the size is equal to the best match, then we
  • trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c

    r80721 r82322  
    34933493  {L"UartFlowCtrl",            DevPathFromTextUartFlowCtrl            },
    34943494  {L"SAS",                     DevPathFromTextSAS                     },
     3495#ifndef VBOX
    34953496  {L"SasEx",                   DevPathFromTextSasEx                   },
     3497#else
     3498  {L"NVMe",                    DevPathFromTextNVMe                    },
     3499#endif
    34963500  {L"NVMe",                    DevPathFromTextNVMe                    },
    34973501  {L"UFS",                     DevPathFromTextUfs                     },
  • trunk/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c

    r80721 r82322  
    22772277  {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP,              DevPathToTextFibre          },
    22782278  {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNELEX_DP,            DevPathToTextFibreEx        },
     2279#ifndef VBOX
    22792280  {MESSAGING_DEVICE_PATH, MSG_SASEX_DP,                     DevPathToTextSasEx          },
     2281#else
     2282  {MESSAGING_DEVICE_PATH, MSG_SASEX_DP,                     DevPathToTextNVMe           },
     2283#endif
    22802284  {MESSAGING_DEVICE_PATH, MSG_NVME_NAMESPACE_DP,            DevPathToTextNVMe           },
    22812285  {MESSAGING_DEVICE_PATH, MSG_UFS_DP,                       DevPathToTextUfs            },
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette