Hardcode order of some kexts.

Improve test in USBFix to avoid crash.
This commit is contained in:
jief666 2020-09-09 00:25:26 +03:00
parent 86f90ef0dc
commit dfac7119f6
3 changed files with 38 additions and 17 deletions

View File

@ -350,13 +350,12 @@ VOID LOADER_ENTRY::AddKextsInArray(const XStringW& SrcDir, const XStringW& Path,
SIDELOAD_KEXT *CurrentKext;
SIDELOAD_KEXT *CurrentPlugInKext;
MsgLog("Preparing kexts injection from %ls\n", SrcDir.wc_str());
MsgLog("AddKextsInArray from %ls\n", SrcDir.wc_str());
CurrentKext = InjectKextList;
while (CurrentKext) {
// DBG(" current kext name=%ls path=%ls, match against=%ls\n", CurrentKext->FileName, CurrentKext->KextDirNameUnderOEMPath, Path);
DBG(" current kext name=%ls path=%ls, match against=%ls\n", CurrentKext->FileName, CurrentKext->KextDirNameUnderOEMPath, Path);
if ( CurrentKext->KextDirNameUnderOEMPath == Path ) {
FileName = SWPrintf("%ls\\%ls", SrcDir.wc_str(), CurrentKext->FileName.wc_str());
// snwprintf(FileName, 512, "%s\\%s", SrcDir, CurrentKext->FileName);
if (!(CurrentKext->MenuItem.BValue)) {
// inject require
MsgLog("->Extra kext: %ls (v.%ls)\n", FileName.wc_str(), CurrentKext->Version.wc_str());

View File

@ -108,7 +108,7 @@ FixOwnership(VOID)
DBG("USB UHCI Base=%X PortBase=%X\n", Base, PortBase);
Command = 0x8f00;
Status = PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, 0xC0, 1, &Command);
if (PortBase) {
if (PortBase && (PortBase & BIT0) == 0) {
IoWrite16 (PortBase, 0x0002);
gBS->Stall (500);
IoWrite16 (PortBase+4, 0);

View File

@ -1068,6 +1068,22 @@ InternalCalculateARTFrequencyIntel (
ocString.Size = len; \
} while (0)
size_t setKextAtPos(XObjArray<SIDELOAD_KEXT>* kextArrayPtr, const XString8& kextName, size_t pos)
{
XObjArray<SIDELOAD_KEXT>& kextArray = *kextArrayPtr;
for (size_t kextIdx = 0 ; kextIdx < kextArray.size() ; kextIdx++ ) {
if ( XString8(LString8(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath.Value)).contains(kextName) ) {
if ( pos >= kextArray.size() ) panic("pos >= kextArray.size()");
OC_KERNEL_ADD_ENTRY* entry = mOpenCoreConfiguration.Kernel.Add.Values[kextIdx];
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx] = mOpenCoreConfiguration.Kernel.Add.Values[pos];
mOpenCoreConfiguration.Kernel.Add.Values[pos] = entry;
return pos+1;
}
}
return pos;
}
VOID LOADER_ENTRY::StartLoader11()
{
EFI_STATUS Status;
@ -1208,11 +1224,17 @@ VOID LOADER_ENTRY::StartLoader11()
RemoveStartupDiskVolume();
}
{
EFI_HANDLE Interface = NULL;
Status = gBS->LocateProtocol(&gAptioMemoryFixProtocolGuid, NULL, &Interface );
if ( !EFI_ERROR(Status) ) {
panic("Remove AptioMemoryFix.efi and OcQuirks.efi from your driver folder\n");
}
}
// Attempt to unload AptioMemoryFix. Something doesn't work well.
// UINTN HandleCount = 0;
// EFI_HANDLE* HandleBuffer = NULL;
// EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo = NULL;
// UINTN OpenInfoCount;
//
//
// Status = gBS->LocateHandleBuffer (ByProtocol, &gAptioMemoryFixProtocolGuid, NULL, &HandleCount, &HandleBuffer);
// if ( !EFI_ERROR(Status) )
@ -1291,22 +1313,22 @@ VOID LOADER_ENTRY::StartLoader11()
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->PlistDataSize = 0;
}
// Seems that Lilu must be first.
if ( kextArray.size() > 1 ) {
for (size_t kextIdx = 1 ; kextIdx < kextArray.size() ; kextIdx++ ) {
if ( XString8(LString8(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath.Value)).contains("Lilu.kext") ) {
OC_KERNEL_ADD_ENTRY* v0 = mOpenCoreConfiguration.Kernel.Add.Values[0];
mOpenCoreConfiguration.Kernel.Add.Values[0] = mOpenCoreConfiguration.Kernel.Add.Values[kextIdx];
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx] = v0;
}
}
}
size_t pos = setKextAtPos(&kextArray, "Lilu.kext"_XS8, 0);
pos = setKextAtPos(&kextArray, "VirtualSMC.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "WhateverGreen.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "AppleALC.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "IntelMausi.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "SMCProcessor.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "SMCSuperIO.kext"_XS8, pos);
pos = setKextAtPos(&kextArray, "USBPorts.kext"_XS8, pos);
XObjArray<KEXT_PATCH> selectedPathArray;
for (size_t kextPatchIdx = 0 ; kextPatchIdx < KernelAndKextPatches.KextPatches.size() ; kextPatchIdx++ )
{
if ( KernelAndKextPatches.KextPatches[kextPatchIdx].MenuItem.BValue ) selectedPathArray.AddReference(&KernelAndKextPatches.KextPatches[kextPatchIdx], false);
}
mOpenCoreConfiguration.Kernel.Patch.Count = selectedPathArray.size();
mOpenCoreConfiguration.Kernel.Patch.AllocCount = mOpenCoreConfiguration.Kernel.Patch.Count;
mOpenCoreConfiguration.Kernel.Patch.ValueSize = sizeof(__typeof_am__(**mOpenCoreConfiguration.Kernel.Patch.Values));