Implement OC FuzzyMatch, KernelCache and Quirks.

This commit is contained in:
jief666 2020-09-07 20:33:38 +03:00
parent 257667f2f1
commit 7e31ca1319
4 changed files with 124 additions and 88 deletions

View File

@ -844,6 +844,107 @@ FillinKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Patches,
return FALSE;
}
Prop = DictPointer->propertyForKey("OcFuzzyMatch");
if (Prop != NULL || gBootChanged) {
Patches->FuzzyMatch = IsPropertyNotNullAndTrue(Prop);
}
Prop = DictPointer->propertyForKey("OcKernelCache");
if (Prop != NULL || gBootChanged) {
if ( Prop->isString() ) {
Patches->OcKernelCache = Prop->getString()->stringValue();
}else{
MsgLog("MALFORMED PLIST : KernelAndKextPatches/KernelCache must be a string");
Patches->OcKernelCache = "Auto"_XS8;
}
}
{
const TagDict* OcQuirksDict = DictPointer->dictPropertyForKey("OcQuirks");
if ( OcQuirksDict )
{
Prop = OcQuirksDict->propertyForKey("AppleCpuPmCfgLock");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.AppleCpuPmCfgLock = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("AppleXcpmCfgLock");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.AppleXcpmCfgLock = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("AppleXcpmExtraMsrs");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.AppleXcpmExtraMsrs = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("AppleXcpmForceBoost");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.AppleXcpmForceBoost = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("CustomSMBIOSGuid");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.CustomSmbiosGuid = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("DisableIoMapper");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.DisableIoMapper = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("DisableLinkeditJettison");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.DisableLinkeditJettison = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("DisableRtcChecksum");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.DisableRtcChecksum = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("DummyPowerManagement");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.DummyPowerManagement = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("ExternalDiskIcons");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.ExternalDiskIcons = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("IncreasePciBarSize");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.IncreasePciBarSize = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("LapicKernelPanic");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.LapicKernelPanic = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("PanicNoKextDump");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.PanicNoKextDump = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("PowerTimeoutKernelPanic");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.PowerTimeoutKernelPanic = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("ThirdPartyDrives");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.ThirdPartyDrives = IsPropertyNotNullAndTrue(Prop);
}
Prop = OcQuirksDict->propertyForKey("XhciPortLimit");
if (Prop != NULL || gBootChanged) {
Patches->OcKernelQuirks.XhciPortLimit = IsPropertyNotNullAndTrue(Prop);
}
}
}
Prop = DictPointer->propertyForKey("Debug");
if (Prop != NULL || gBootChanged) {
Patches->KPDebug = IsPropertyNotNullAndTrue(Prop);

View File

@ -462,7 +462,7 @@ public:
XString8Array HVHideStrings;
// KernelAndKextPatches
KERNEL_AND_KEXT_PATCHES KernelAndKextPatches; //zzzz
KERNEL_AND_KEXT_PATCHES KernelAndKextPatches;
BOOLEAN KextPatchesAllowed;
BOOLEAN KernelPatchesAllowed; //From GUI: Only for user patches, not internal Clover
@ -980,10 +980,6 @@ ParseSMBIOSSettings (
const TagDict* dictPointer
);
//BOOLEAN
//CopyKernelAndKextPatches (IN OUT KERNEL_AND_KEXT_PATCHES *Dst,
// IN CONST KERNEL_AND_KEXT_PATCHES *Src);
void testConfigPlist();

View File

@ -42,6 +42,11 @@
#include "../cpp_foundation/XString.h"
#include "../cpp_foundation/XStringArray.h"
#include "../cpp_foundation/XBuffer.h"
extern "C" {
#include <Library/OcConfigurationLib.h>
}
/* types */
typedef enum {
@ -267,6 +272,9 @@ public:
class KERNEL_AND_KEXT_PATCHES
{
public:
BOOLEAN FuzzyMatch;
XString8 OcKernelCache;
OC_KERNEL_QUIRKS OcKernelQuirks;
BOOLEAN KPDebug;
// BOOLEAN KPKernelCpu;
BOOLEAN KPKernelLapic;
@ -317,7 +325,7 @@ public:
// INT32 NrBoots;
XObjArray<KEXT_PATCH> BootPatches;
KERNEL_AND_KEXT_PATCHES() : KPDebug(0), KPKernelLapic(0), KPKernelXCPM(0), KPKernelPm(0), KPAppleIntelCPUPM(0), KPAppleRTC(0), KPDELLSMBIOS(0), KPPanicNoKextDump(0),
KERNEL_AND_KEXT_PATCHES() : FuzzyMatch(0), OcKernelCache(), OcKernelQuirks{0}, KPDebug(0), KPKernelLapic(0), KPKernelXCPM(0), KPKernelPm(0), KPAppleIntelCPUPM(0), KPAppleRTC(0), KPDELLSMBIOS(0), KPPanicNoKextDump(0),
EightApple(0), pad{0}, FakeCPUID(0), KPATIConnectorsController(0), KPATIConnectorsData(),
KPATIConnectorsPatch(), align40(0), KextPatches(), align50(0), ForceKexts(),
KernelPatches(), BootPatches()

View File

@ -1241,8 +1241,8 @@ VOID LOADER_ENTRY::StartLoader11()
memset(&mOpenCoreConfiguration, 0, sizeof(mOpenCoreConfiguration));
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Scheme.KernelCache, "Auto");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Misc.Security.SecureBootModel, "Default");
mOpenCoreConfiguration.Kernel.Scheme.FuzzyMatch = 0;
mOpenCoreConfiguration.Kernel.Force.Count = 0;
mOpenCoreConfiguration.Kernel.Scheme.FuzzyMatch = gSettings.KernelAndKextPatches.FuzzyMatch;
memcpy(&mOpenCoreConfiguration.Kernel.Quirks, &gSettings.KernelAndKextPatches.OcKernelQuirks, sizeof(mOpenCoreConfiguration.Kernel.Quirks));
mOpenCoreConfiguration.Kernel.Add.Count = kextArray.size();
mOpenCoreConfiguration.Kernel.Add.AllocCount = mOpenCoreConfiguration.Kernel.Add.Count;
@ -1252,7 +1252,7 @@ VOID LOADER_ENTRY::StartLoader11()
for (size_t kextIdx = 0 ; kextIdx < kextArray.size() ; kextIdx++ )
{
const SIDELOAD_KEXT& KextEntry = kextArray[kextIdx];
DBG("load kext : KextDirNameUnderOEMPath=%ls FileName=%ls\n", KextEntry.KextDirNameUnderOEMPath.wc_str(), KextEntry.FileName.wc_str());
DBG("Bridge kext to OC : KextDirNameUnderOEMPath=%ls FileName=%ls\n", KextEntry.KextDirNameUnderOEMPath.wc_str(), KextEntry.FileName.wc_str());
size_t allocSize = sizeof(__typeof_am__(*mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]));
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx] = (OC_KERNEL_ADD_ENTRY*) AllocatePool (allocSize); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->Enabled = 1;
@ -1279,6 +1279,16 @@ VOID LOADER_ENTRY::StartLoader11()
}
}
}
for (size_t kextPatchIdx = 0 ; kextPatchIdx < KernelAndKextPatches.KextPatches.size() ; kextPatchIdx++ )
{
const KEXT_PATCH& kextPatch = KernelAndKextPatches.KextPatches[kextPatchIdx];
DBG("TODO !!!!!!!! Bridge kext patch to OC : %s\n", kextPatch.Label.c_str());
}
for (size_t forceKextIdx = 0 ; forceKextIdx < KernelAndKextPatches.ForceKexts.size() ; forceKextIdx++ )
{
const XStringW& forceKext = KernelAndKextPatches.ForceKexts[forceKextIdx];
DBG("TODO !!!!!!!! Bridge force kext to OC : %ls\n", forceKext.wc_str());
}
EFI_HANDLE EntryHandle = NULL;
@ -2806,85 +2816,6 @@ RefitMain (IN EFI_HANDLE ImageHandle,
gEmuVariableControl->InstallEmulation(gEmuVariableControl);
}
//
//
// OC_GLOBAL_CONFIG* Config = &mOpenCoreConfiguration;
//
//
// memset(Config, 0, sizeof(*Config));
// OC_STRING_ASSIGN(Config->Kernel.Scheme.KernelCache, "Auto");
// OC_STRING_ASSIGN(Config->Misc.Security.SecureBootModel, "Default");
// Config->Kernel.Scheme.FuzzyMatch = 0;
// Config->Kernel.Force.Count = 0;
//
// Config->Kernel.Add.Count = 2;
// Config->Kernel.Add.AllocCount = Config->Kernel.Add.Count;
// Config->Kernel.Add.ValueSize = sizeof(OC_KERNEL_ADD_ENTRY); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
// Config->Kernel.Add.Values = (OC_KERNEL_ADD_ENTRY**)AllocatePool(Config->Kernel.Add.AllocCount*sizeof(*Config->Kernel.Add.Values)); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
//
// Config->Kernel.Add.Values[0] = (OC_KERNEL_ADD_ENTRY*)AllocatePool(sizeof(__typeof_am__(*Config->Kernel.Add.Values[0]))); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
// Config->Kernel.Add.Values[0]->Enabled = 1;
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[0]->Arch, "Any");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[0]->Comment, "Comment Lilu.kext");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[0]->MaxKernel, "");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[0]->MinKernel, "");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[0]->Identifier, "");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[0]->BundlePath, "11/Lilu.kext");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[0]->ExecutablePath, "Contents/MacOS/Lilu");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[0]->PlistPath, "Contents/Info.plist");
// Config->Kernel.Add.Values[0]->ImageData = NULL;
// Config->Kernel.Add.Values[0]->ImageDataSize = 0;
// Config->Kernel.Add.Values[0]->PlistData = NULL;
// Config->Kernel.Add.Values[0]->PlistDataSize = 0;
//
// Config->Kernel.Add.Values[1] = (OC_KERNEL_ADD_ENTRY*)AllocatePool(sizeof(__typeof_am__(*Config->Kernel.Add.Values[1]))); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
// Config->Kernel.Add.Values[1]->Enabled = 1;
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[1]->Arch, "Any");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[1]->Comment, "Comment VirtualSMC.kext");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[1]->MaxKernel, "");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[1]->MinKernel, "");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[1]->Identifier, "");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[1]->BundlePath, "11/VirtualSMC.kext");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[1]->ExecutablePath, "Contents/MacOS/VirtualSMC");
// OC_STRING_ASSIGN(Config->Kernel.Add.Values[1]->PlistPath, "Contents/Info.plist");
// Config->Kernel.Add.Values[1]->ImageData = NULL;
// Config->Kernel.Add.Values[1]->ImageDataSize = 0;
// Config->Kernel.Add.Values[1]->PlistData = NULL;
// Config->Kernel.Add.Values[1]->PlistDataSize = 0;
//
// UINTN HandleCount = 0;
// EFI_HANDLE *Handles = NULL;
// Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles);
// UINTN HandleIndex;
// for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
// EFI_DEVICE_PATH_PROTOCOL* DevicePath = DevicePathFromHandle(Handles[HandleIndex]);
// XStringW DevicePathXString = DevicePathToXStringW(DevicePath);
// if ( LString8("PciRoot(0x0)/Pci(0x11,0x0)/Pci(0x5,0x0)/Sata(0x1,0x0,0x0)/HD(3,0,0,0x40040,0x1BBFFC0)") == DevicePathXString ) break;
// }
// EFI_DEVICE_PATH_PROTOCOL* jfkImagePath = FileDevicePath(Handles[HandleIndex], L"\\System\\Library\\CoreServices\\boot.efi");
// XStringW DevicePathXString = DevicePathToXStringW(jfkImagePath);
//
// EFI_HANDLE EntryHandle = NULL;
// Status = InternalEfiLoadImage (
// FALSE,
// gImageHandle,
// jfkImagePath,
// NULL,
// 0,
// &EntryHandle
// );
// // OcLoadBootEntry (Context, Context->
// Status = OcStartImage (EntryHandle, 0, NULL);
DbgHeader("InitScreen");
if (!GlobalConfig.FastBoot) {