Use OcMain to init OC.

Remove -DMDEPKG_NDEBUG to get OC debug messages.
Refactor InjectKextList as XObjArray<SIDELOAD_KEXT>.
This commit is contained in:
jief666 2020-09-16 02:01:53 +03:00
parent acc2fea810
commit 346661efd2
9 changed files with 189 additions and 155 deletions

View File

@ -748,7 +748,7 @@ DEFINE EXIT_USBKB_FLAG = -DEXIT_USBKB
!endif
DEFINE BUILD_OPTIONS=-DMDEPKG_NDEBUG -DCLOVER_BUILD $(VBIOS_PATCH_CLOVEREFI_FLAG) $(ONLY_SATA_0_FLAG) $(BLOCKIO_FLAG) $(NOUSB_FLAG) $(NOUDMA_FLAG) $(AMD_FLAG) $(SECURE_BOOT_FLAG) $(ANDX86_FLAG) $(PS2MOUSE_LEGACYBOOT_FLAG) $(DEBUG_ON_SERIAL_PORT_FLAG) $(EXIT_USBKB_FLAG)
DEFINE BUILD_OPTIONS=-DCLOVER_BUILD $(VBIOS_PATCH_CLOVEREFI_FLAG) $(ONLY_SATA_0_FLAG) $(BLOCKIO_FLAG) $(NOUSB_FLAG) $(NOUDMA_FLAG) $(AMD_FLAG) $(SECURE_BOOT_FLAG) $(ANDX86_FLAG) $(PS2MOUSE_LEGACYBOOT_FLAG) $(DEBUG_ON_SERIAL_PORT_FLAG) $(EXIT_USBKB_FLAG)
#MSFT:*_*_*_CC_FLAGS = /FAcs /FR$(@R).SBR /wd4701 /wd4703 $(BUILD_OPTIONS)
MSFT:*_*_*_CC_FLAGS = /FAcs $(BUILD_OPTIONS) -Dinline=__inline /Zi -D DISABLE_NEW_DEPRECATED_INTERFACES -D OC_TARGET_DEBUG

@ -1 +1 @@
Subproject commit daa6d7e3bd1a8101b505b3a65a0a6f4f186b1cd8
Subproject commit 3d371324a0e32a67dd399541958e6b676158769b

View File

@ -139,7 +139,6 @@ DumpUefiCallsEntrypoint (
)
{
#ifdef JIEF_DEBUG
{
EFI_LOADED_IMAGE* LoadedImage;
EFI_STATUS Status = gBS->HandleProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
@ -148,16 +147,14 @@ DumpUefiCallsEntrypoint (
CHAR8 buf[50];
AsciiSPrint(buf, sizeof(buf)-1, "DumpEfiCalls : Image base = 0x%X\n", (UINTN)LoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger
SerialPortWrite((UINT8*)buf, AsciiStrLen(buf));
AsciiSPrint(buf, sizeof(buf)-1, "LoadedImage.DeviceHandle = 0x%X\n", (UINTN)LoadedImage->DeviceHandle); // do not change, it's used by grep to feed the debugger
AsciiSPrint(buf, sizeof(buf)-1, "2LoadedImage.DeviceHandle = 0x%X\n", (UINTN)LoadedImage->DeviceHandle);
SerialPortWrite((UINT8*)buf, AsciiStrLen(buf));
}else{
CHAR8 buf[50];
AsciiSPrint(buf, sizeof(buf)-1, "DumpEfiCalls : HandleProtocol(gEfiLoadedImageProtocolGuid) = %r\n", Status);
SerialPortWrite((UINT8*)buf, AsciiStrLen(buf));
}
// if ( !EFI_ERROR(Status) ) DBG("DumpEfiCalls : Image base = 0x%llX\n", (uintptr_t)LoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger
gBS->Stall(3500000); // to give time to gdb to connect
// gBS->Stall(0500000); // to give time to gdb to connect
// PauseForKey(L"press\n");
}
#endif
//
// Override StartImage

View File

@ -69,7 +69,7 @@ INTN LayoutTextOffset = 0;
INTN LayoutButtonOffset = 0;
ACPI_PATCHED_AML *ACPIPatchedAML = NULL;
SIDELOAD_KEXT *InjectKextList = NULL;
XObjArray<SIDELOAD_KEXT> InjectKextList;
//SYSVARIABLES *SysVariables;
CHAR16 *IconFormat = NULL;
@ -3182,18 +3182,17 @@ VOID GetListOfInjectKext(CHAR16 *KextDirNameUnderOEMPath)
*/
FullName = SWPrintf("%ls\\%ls", FullPath.wc_str(), DirEntry->FileName);
mKext = new SIDELOAD_KEXT;
mKext->FileName = SWPrintf("%ls", DirEntry->FileName);
mKext->FileName.SWPrintf("%ls", DirEntry->FileName);
mKext->MenuItem.BValue = Blocked;
mKext->KextDirNameUnderOEMPath = SWPrintf("%ls", KextDirNameUnderOEMPath);
mKext->Next = InjectKextList;
mKext->KextDirNameUnderOEMPath.SWPrintf("%ls", KextDirNameUnderOEMPath);
mKext->Version = GetBundleVersion(FullName);
InjectKextList = mKext;
InjectKextList.AddReference(mKext, true);
DBG("Added Kext=%ls\\%ls\n", KextDirNameUnderOEMPath, mKext->FileName.wc_str());
// Obtain PlugInList
// Iterate over PlugIns directory
PlugInsPath = SWPrintf("%ls\\%ls", FullName.wc_str(), L"Contents\\PlugIns");
PlugInsPath = SWPrintf("%ls\\Contents\\PlugIns", FullName.wc_str());
DirIterOpen(SelfRootDir, PlugInsPath.wc_str(), &PlugInsIter);
while (DirIterNext(&PlugInsIter, 1, L"*.kext", &PlugInEntry)) {
@ -3202,12 +3201,11 @@ VOID GetListOfInjectKext(CHAR16 *KextDirNameUnderOEMPath)
}
PlugInsName = SWPrintf("%ls\\%ls", PlugInsPath.wc_str(), PlugInEntry->FileName);
mPlugInKext = new SIDELOAD_KEXT;
mPlugInKext->FileName = SWPrintf("%ls", PlugInEntry->FileName);
mPlugInKext->FileName.SWPrintf("%ls", PlugInEntry->FileName);
mPlugInKext->MenuItem.BValue = Blocked;
mPlugInKext->KextDirNameUnderOEMPath = SWPrintf("%ls", KextDirNameUnderOEMPath);
mPlugInKext->Next = mKext->PlugInList;
mPlugInKext->KextDirNameUnderOEMPath = SWPrintf("%ls\\%ls\\Contents\\PlugIns", KextDirNameUnderOEMPath, mKext->FileName.wc_str());
mPlugInKext->Version = GetBundleVersion(PlugInsName);
mKext->PlugInList = mPlugInKext;
mKext->PlugInList.AddReference(mPlugInKext, true);
// DBG("---| added plugin=%ls, MatchOS=%ls\n", mPlugInKext->FileName, mPlugInKext->MatchOS);
}
DirIterClose(&PlugInsIter);
@ -3221,7 +3219,7 @@ VOID InitKextList()
EFI_FILE_INFO *FolderEntry = NULL;
XStringW KextsPath;
if (InjectKextList) {
if (InjectKextList.notEmpty()) {
return; //don't scan again
}
KextsPath = SWPrintf("%ls\\kexts", OEMPath.wc_str());

View File

@ -711,17 +711,16 @@ public:
class SIDELOAD_KEXT
{
public:
SIDELOAD_KEXT *Next;
SIDELOAD_KEXT *PlugInList;
XObjArray<SIDELOAD_KEXT> PlugInList;
XStringW FileName;
XStringW KextDirNameUnderOEMPath;
XStringW Version;
INPUT_ITEM MenuItem;
SIDELOAD_KEXT() : Next(0), PlugInList(0), FileName(), KextDirNameUnderOEMPath(), Version(), MenuItem() {};
SIDELOAD_KEXT() : PlugInList(), FileName(), KextDirNameUnderOEMPath(), Version(), MenuItem() {};
SIDELOAD_KEXT(const SIDELOAD_KEXT& other) = delete; // Can be defined if needed
const SIDELOAD_KEXT& operator = ( const SIDELOAD_KEXT & ) = delete; // Can be defined if needed
~SIDELOAD_KEXT() { delete Next; delete PlugInList; }
~SIDELOAD_KEXT() { }
};
class RT_VARIABLES
@ -788,7 +787,7 @@ extern TagDict* gConfigDict[];
extern ACPI_PATCHED_AML *ACPIPatchedAML;
// Sideload/inject kext
extern SIDELOAD_KEXT *InjectKextList;
extern XObjArray<SIDELOAD_KEXT> InjectKextList;
// SysVariables
//extern SYSVARIABLES *SysVariables;

View File

@ -338,52 +338,48 @@ VOID LOADER_ENTRY::LoadPlugInKexts(IN EFI_FILE *RootDir, const XString8& DirName
//}
// Jief : this should replace LOADER_ENTRY::AddKexts
VOID LOADER_ENTRY::AddKextsFromDirInArray(const XString8& SrcDir, const XString8& Path, cpu_type_t archCpuType, XString8Array* kextArray)
VOID LOADER_ENTRY::AddKextsFromDirInArray(const XString8& SrcDir, const XString8& Path, cpu_type_t archCpuType, XObjArray<SIDELOAD_KEXT>* kextArray)
{
XStringW FileName;
XStringW PlugInName;
SIDELOAD_KEXT *CurrentKext;
SIDELOAD_KEXT *CurrentPlugInKext;
MsgLog("AddKextsInArray from %s\n", SrcDir.c_str());
CurrentKext = InjectKextList;
while (CurrentKext) {
DBG(" current kext name=%ls path=%ls, match against=%s\n", CurrentKext->FileName.wc_str(), CurrentKext->KextDirNameUnderOEMPath.wc_str(), Path.c_str());
if ( CurrentKext->KextDirNameUnderOEMPath == Path ) {
FileName = SWPrintf("%s\\%ls", SrcDir.c_str(), CurrentKext->FileName.wc_str());
if (!(CurrentKext->MenuItem.BValue)) {
for ( size_t idx = 0 ; idx < InjectKextList.size() ; idx ++ ) {
SIDELOAD_KEXT& CurrentKext = InjectKextList[idx];
DBG(" current kext name=%ls path=%ls, match against=%s\n", CurrentKext.FileName.wc_str(), CurrentKext.KextDirNameUnderOEMPath.wc_str(), Path.c_str());
if ( CurrentKext.KextDirNameUnderOEMPath == Path ) {
FileName = SWPrintf("%s\\%ls", SrcDir.c_str(), CurrentKext.FileName.wc_str());
if (!(CurrentKext.MenuItem.BValue)) {
// inject require
MsgLog("->Extra kext: %ls (v.%ls)\n", FileName.wc_str(), CurrentKext->Version.wc_str());
MsgLog("->Extra kext: %ls (v.%ls)\n", FileName.wc_str(), CurrentKext.Version.wc_str());
// Status = AddKext(SelfVolume->RootDir, FileName.wc_str(), archCpuType);
kextArray->Add(FileName.forgetDataWithoutFreeing()); // do not free, CurrentKext belongs to an other object
kextArray->AddReference(&CurrentKext, false); // do not free, CurrentKext belongs to an other object
// decide which plugins to inject
CurrentPlugInKext = CurrentKext->PlugInList;
while (CurrentPlugInKext) {
PlugInName = SWPrintf("%ls\\%ls\\%ls", FileName.wc_str(), L"Contents\\PlugIns", CurrentPlugInKext->FileName.wc_str());
// snwprintf(PlugInName, 512, L"%s\\%s\\%s", FileName, "Contents\\PlugIns", CurrentPlugInKext->FileName);
if (!(CurrentPlugInKext->MenuItem.BValue)) {
for ( size_t idxPlugin = 0 ; idxPlugin < CurrentKext.PlugInList.size() ; idxPlugin ++ ) {
SIDELOAD_KEXT& CurrentPlugInKext = CurrentKext.PlugInList[idxPlugin];
PlugInName = SWPrintf("%ls\\Contents\\PlugIns\\%ls", FileName.wc_str(), CurrentPlugInKext.FileName.wc_str());
// snwprintf(PlugInName, 512, L"%s\\%s\\%s", FileName, "Contents\\PlugIns", CurrentPlugInKext.FileName);
if (!(CurrentPlugInKext.MenuItem.BValue)) {
// inject PlugIn require
MsgLog(" |-- PlugIn kext: %ls (v.%ls)\n", PlugInName.wc_str(), CurrentPlugInKext->Version.wc_str());
MsgLog(" |-- PlugIn kext: %ls (v.%ls)\n", PlugInName.wc_str(), CurrentPlugInKext.Version.wc_str());
// AddKext(SelfVolume->RootDir, PlugInName.wc_str(), archCpuType);
kextArray->Add(PlugInName.forgetDataWithoutFreeing()); // do not free, CurrentKext belongs to an other object
kextArray->AddReference(&CurrentPlugInKext, false); // do not free, CurrentKext belongs to an other object
} else {
MsgLog(" |-- Disabled plug-in kext: %ls (v.%ls)\n", PlugInName.wc_str(), CurrentPlugInKext->Version.wc_str());
MsgLog(" |-- Disabled plug-in kext: %ls (v.%ls)\n", PlugInName.wc_str(), CurrentPlugInKext.Version.wc_str());
}
CurrentPlugInKext = CurrentPlugInKext->Next;
} // end of plug-in kext injection
} else {
// disable current kext injection
if ( SrcDir.containsIC(L"Off") ) {
MsgLog("Disabled kext: %ls (v.%ls)\n", FileName.wc_str(), CurrentKext->Version.wc_str());
MsgLog("Disabled kext: %ls (v.%ls)\n", FileName.wc_str(), CurrentKext.Version.wc_str());
}
}
}
CurrentKext = CurrentKext->Next;
} // end of kext injection
}
void LOADER_ENTRY::AddKextsInArray(XString8Array* kextArray)
void LOADER_ENTRY::AddKextsInArray(XObjArray<SIDELOAD_KEXT>* kextArray)
{
XStringW SrcDir;
REFIT_DIR_ITER PlugInIter;
@ -553,7 +549,7 @@ void LOADER_ENTRY::AddKextsInArray(XString8Array* kextArray)
EFI_STATUS LOADER_ENTRY::LoadKexts()
{
XString8Array kextArray;
XObjArray<SIDELOAD_KEXT> kextArray;
AddKextsInArray(&kextArray);
@ -583,7 +579,7 @@ EFI_STATUS LOADER_ENTRY::LoadKexts()
}
for (size_t idx = 0 ; idx < kextArray.size() ; idx++ ) {
AddKext(Volume->RootDir, kextArray[idx], archCpuType);
AddKext(Volume->RootDir, kextArray[idx].FileName, archCpuType);
}
UINTN mm_extra_size;
@ -608,8 +604,7 @@ EFI_STATUS LOADER_ENTRY::LoadKexts()
FreePool(extra);
}
delete InjectKextList;
InjectKextList = NULL;
InjectKextList.setEmpty();
return EFI_SUCCESS;
}

View File

@ -465,8 +465,8 @@ class REFIT_ABSTRACT_MENU_ENTRY
EFI_STATUS AddKext(IN EFI_FILE *RootDir, const XString8& FileName, IN cpu_type_t archCpuType);
void LoadPlugInKexts(IN EFI_FILE *RootDir, const XString8& DirName, IN cpu_type_t archCpuType, IN BOOLEAN Force);
// void AddKexts(const XStringW& SrcDir, const XStringW& Path, cpu_type_t archCpuType);
void AddKextsFromDirInArray(const XString8& SrcDir, const XString8& Path, cpu_type_t archCpuType, XString8Array* kextArray);
void AddKextsInArray(XString8Array* kextArray);
void AddKextsFromDirInArray(const XString8& SrcDir, const XString8& Path, cpu_type_t archCpuType, XObjArray<SIDELOAD_KEXT>* kextArray);
void AddKextsInArray(XObjArray<SIDELOAD_KEXT>* kextArray);
void KextPatcherRegisterKexts(void *FSInject, void *ForceLoadKexts);
void KextPatcherStart();
void PatchPrelinkedKexts();

View File

@ -1002,6 +1002,7 @@ VOID LOADER_ENTRY::StartLoader()
// PauseForKey(L"System started?!");
}
extern "C" {
#include <Library/OcRtcLib.h>
#include <Library/OcOSInfoLib.h>
#include <Library/OcVirtualFsLib.h>
#include <Library/OcConfigurationLib.h>
@ -1012,6 +1013,16 @@ extern OC_STORAGE_CONTEXT mOpenCoreStorage;
extern OC_CPU_INFO mOpenCoreCpuInfo;
extern OC_BOOTSTRAP_PROTOCOL mOpenCoreBootStrap;
extern OC_RSA_PUBLIC_KEY* mOpenCoreVaultKey;
extern EFI_HANDLE mLoadHandle;
EFI_STATUS
EFIAPI
OcStartImage_2 (
IN OC_BOOT_ENTRY *Chosen,
IN EFI_HANDLE ImageHandle,
OUT UINTN *ExitDataSize,
OUT CHAR16 **ExitData OPTIONAL
);
EFI_STATUS
EFIAPI
@ -1056,38 +1067,50 @@ InternalCalculateARTFrequencyIntel (
} // extern "C"
#define OC_STRING_ASSIGN(ocString, value) do { \
ocString.DynValue = NULL; \
strcpy(ocString.Value, value); \
ocString.MaxSize = sizeof(ocString.Value); \
ocString.Size = (UINT32)strlen(value)+1; /* unsafe cast */ \
} while (0)
#define OC_STRING_ASSIGN_N(ocString, value, len) do { \
ocString.DynValue = NULL; \
memcpy(ocString.Value, value, len); \
ocString.MaxSize = sizeof(ocString.Value); \
ocString.Size = (UINT32)len; /* unsafe cast */ \
if( len >= sizeof(ocString.Value) ) { \
memset(ocString.Value, 0, sizeof(ocString.Value)); \
ocString.DynValue = (__typeof__(ocString.DynValue))malloc(len); \
memcpy(ocString.DynValue, value, len); \
ocString.MaxSize = (UINT32)len; \
ocString.Size = (UINT32)len; /* unsafe cast */ \
}else{ \
ocString.DynValue = NULL; \
memcpy(ocString.Value, value, len); \
ocString.MaxSize = sizeof(ocString.Value); \
ocString.Size = (UINT32)len; /* unsafe cast */ \
} \
} while (0)
size_t setKextAtPos(XString8Array* kextArrayPtr, const XString8& kextName, size_t pos)
#define OC_STRING_ASSIGN(ocString, value) OC_STRING_ASSIGN_N(ocString, value, strlen(value)+1)
size_t setKextAtPos(XObjArray<SIDELOAD_KEXT>* kextArrayPtr, const XString8& kextName, size_t pos)
{
XString8Array& kextArray = *kextArrayPtr;
XObjArray<SIDELOAD_KEXT>& kextArray = *kextArrayPtr;
for (size_t kextIdx = 0 ; kextIdx < kextArray.size() ; kextIdx++ ) {
if ( kextArray[kextIdx].contains(kextName) ) {
if ( kextArray[kextIdx].FileName.contains(kextName) ) {
if ( pos >= kextArray.size() ) panic("pos >= kextArray.size()");
if ( pos == kextIdx ) return pos+1;
if ( pos > kextIdx ) pos -= 1;
XString8 kextToMove;
kextToMove.stealValueFrom(kextArray[kextIdx].forgetDataWithoutFreeing());
kextArray.removeAtPos(kextIdx);
kextArray.insertAtPos(kextToMove, pos);
SIDELOAD_KEXT* kextToMove = &kextArray[kextIdx];
kextArray.RemoveWithoutFreeingAtIndex(kextIdx);
kextArray.InsertRef(kextToMove, pos, false);
return pos+1;
}
}
return pos;
}
extern "C" {
VOID
OcMain (
IN OC_STORAGE_CONTEXT *Storage,
IN EFI_DEVICE_PATH_PROTOCOL *LoadPath OPTIONAL
);
}
VOID LOADER_ENTRY::StartLoader11()
{
EFI_STATUS Status;
@ -1145,30 +1168,30 @@ VOID LOADER_ENTRY::StartLoader11()
FilterKernelPatches();
FilterBootPatches();
// Set boot argument for kernel if no caches, this should force kernel loading
if ( OSFLAG_ISSET(Flags, OSFLAG_NOCACHES) && !LoadOptions.containsStartWithIC("Kernel=") ) {
XString8 KernelLocation;
// // Set boot argument for kernel if no caches, this should force kernel loading
// if ( OSFLAG_ISSET(Flags, OSFLAG_NOCACHES) && !LoadOptions.containsStartWithIC("Kernel=") ) {
// XString8 KernelLocation;
//
// if (OSVersion.notEmpty() && AsciiOSVersionToUint64(OSVersion) <= AsciiOSVersionToUint64("10.9"_XS8)) {
// KernelLocation.S8Printf("\"Kernel=/mach_kernel\"");
// } else {
// // used for 10.10, 10.11, and new version.
// KernelLocation.S8Printf("\"Kernel=/System/Library/Kernels/kernel\"");
// }
// LoadOptions.AddID(KernelLocation);
// }
//
// //we are booting OSX - restore emulation if it's not installed before g boot.efi
// if (gEmuVariableControl != NULL) {
// gEmuVariableControl->InstallEmulation(gEmuVariableControl);
// }
if (OSVersion.notEmpty() && AsciiOSVersionToUint64(OSVersion) <= AsciiOSVersionToUint64("10.9"_XS8)) {
KernelLocation.S8Printf("\"Kernel=/mach_kernel\"");
} else {
// used for 10.10, 10.11, and new version.
KernelLocation.S8Printf("\"Kernel=/System/Library/Kernels/kernel\"");
}
LoadOptions.AddID(KernelLocation);
}
//we are booting OSX - restore emulation if it's not installed before g boot.efi
if (gEmuVariableControl != NULL) {
gEmuVariableControl->InstallEmulation(gEmuVariableControl);
}
// first patchACPI and find PCIROOT and RTC
// but before ACPI patch we need smbios patch
CheckEmptyFB();
PatchSmbios();
// DBG("PatchACPI\n");
PatchACPI(Volume, OSVersion);
// // first patchACPI and find PCIROOT and RTC
// // but before ACPI patch we need smbios patch
// CheckEmptyFB();
// PatchSmbios();
//// DBG("PatchACPI\n");
// PatchACPI(Volume, OSVersion);
// If KPDebug is true boot in verbose mode to see the debug messages
if (KernelAndKextPatches.KPDebug) {
@ -1177,24 +1200,24 @@ VOID LOADER_ENTRY::StartLoader11()
DbgHeader("RestSetup macOS");
// DBG("SetDevices\n");
SetDevices(this);
// DBG("SetFSInjection\n");
//SetFSInjection();
//PauseForKey(L"SetFSInjection");
// DBG("SetVariablesForOSX\n");
SetVariablesForOSX(this);
// DBG("SetVariablesForOSX\n");
// EventsInitialize(this);
// DBG("FinalizeSmbios\n");
FinalizeSmbios();
SetCPUProperties();
if (OSFLAG_ISSET(Flags, OSFLAG_HIBERNATED)) {
DoHibernateWake = PrepareHibernation(Volume);
}
SetupDataForOSX(DoHibernateWake);
//// DBG("SetDevices\n");
// SetDevices(this);
//// DBG("SetFSInjection\n");
// //SetFSInjection();
// //PauseForKey(L"SetFSInjection");
//// DBG("SetVariablesForOSX\n");
// SetVariablesForOSX(this);
//// DBG("SetVariablesForOSX\n");
//// EventsInitialize(this);
//// DBG("FinalizeSmbios\n");
// FinalizeSmbios();
//
// SetCPUProperties();
//
// if (OSFLAG_ISSET(Flags, OSFLAG_HIBERNATED)) {
// DoHibernateWake = PrepareHibernation(Volume);
// }
// SetupDataForOSX(DoHibernateWake);
if ( gDriversFlags.AptioFixLoaded &&
@ -1251,8 +1274,6 @@ VOID LOADER_ENTRY::StartLoader11()
// }
//
memset(&mOpenCoreConfiguration, 0, sizeof(mOpenCoreConfiguration));
UINT64 CPUFrequencyFromART;
InternalCalculateARTFrequencyIntel(&CPUFrequencyFromART, NULL, 1);
@ -1261,21 +1282,44 @@ VOID LOADER_ENTRY::StartLoader11()
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* FileSystem = LocateFileSystem(OcLoadedImage->DeviceHandle, OcLoadedImage->FilePath);
Status = OcStorageInitFromFs(&mOpenCoreStorage, FileSystem, L"EFI\\CLOVER", NULL);
OcConfigureLogProtocol (
9,
0,
2151678018,
2147483648,
OPEN_CORE_LOG_PREFIX_PATH,
mOpenCoreStorage.FileSystem
);
DEBUG ((DEBUG_INFO, "OC: Log initialized...\n"));
OcAppleDebugLogInstallProtocol(0);
OcMain(&mOpenCoreStorage, NULL);
// Uncomment OcMiscBoot to run the OC bootpicker
// OcMiscBoot (
// &mOpenCoreStorage,
// &mOpenCoreConfiguration,
// NULL,
// OcStartImage_2,
// mOpenCoreConfiguration.Uefi.Quirks.RequestBootVarRouting,
// mLoadHandle
// );
#ifdef JIEF_DEBUG
// Save mOpenCoreConfiguration built from OC config.plist for debug
OC_GLOBAL_CONFIG mOpenCoreConfigurationBak = mOpenCoreConfiguration;
#endif
// OcConfigureLogProtocol (
// 9,
// 0,
// 2151678018,
// 2147483648,
// OPEN_CORE_LOG_PREFIX_PATH,
// mOpenCoreStorage.FileSystem
// );
// DEBUG ((DEBUG_INFO, "OC: Log initialized...\n"));
// OcAppleDebugLogInstallProtocol(0);
memset(&mOpenCoreConfiguration, 0, sizeof(mOpenCoreConfiguration));
mOpenCoreConfiguration.Booter.MmioWhitelist.Count = (UINT32)gSettings.mmioWhiteListArray.size();
mOpenCoreConfiguration.Booter.MmioWhitelist.AllocCount = mOpenCoreConfiguration.Booter.MmioWhitelist.Count;
mOpenCoreConfiguration.Booter.MmioWhitelist.ValueSize = sizeof(__typeof_am__(**mOpenCoreConfiguration.Booter.MmioWhitelist.Values)); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
mOpenCoreConfiguration.Booter.MmioWhitelist.Values = (OC_BOOTER_WL_ENTRY**)AllocatePool(mOpenCoreConfiguration.Booter.MmioWhitelist.AllocCount*sizeof(*mOpenCoreConfiguration.Booter.MmioWhitelist.Values)); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
if ( mOpenCoreConfiguration.Booter.MmioWhitelist.Count > 0 ) {
mOpenCoreConfiguration.Booter.MmioWhitelist.Values = (OC_BOOTER_WL_ENTRY**)AllocatePool(mOpenCoreConfiguration.Booter.MmioWhitelist.AllocCount*sizeof(*mOpenCoreConfiguration.Booter.MmioWhitelist.Values)); // sizeof(OC_KERNEL_ADD_ENTRY) == 680
}else{
mOpenCoreConfiguration.Booter.MmioWhitelist.Values = NULL;
}
for ( size_t idx = 0 ; idx < gSettings.mmioWhiteListArray.size() ; idx++ ) {
const MMIOWhiteList& entry = gSettings.mmioWhiteListArray[idx];
DBG("Bridge mmioWhiteList[%zu] to OC : comment=%s\n", idx, entry.comment.c_str());
@ -1288,11 +1332,11 @@ VOID LOADER_ENTRY::StartLoader11()
memcpy(&mOpenCoreConfiguration.Booter.Quirks, &gSettings.ocBooterQuirks, sizeof(mOpenCoreConfiguration.Booter.Quirks));
OcLoadBooterUefiSupport(&mOpenCoreConfiguration);
OcLoadKernelSupport(&mOpenCoreStorage, &mOpenCoreConfiguration, &mOpenCoreCpuInfo);
OcImageLoaderInit ();
// OcLoadBooterUefiSupport(&mOpenCoreConfiguration);
// OcLoadKernelSupport(&mOpenCoreStorage, &mOpenCoreConfiguration, &mOpenCoreCpuInfo);
// OcImageLoaderInit ();
XString8Array kextArray;
XObjArray<SIDELOAD_KEXT> kextArray;
if (!DoHibernateWake) {
AddKextsInArray(&kextArray);
}
@ -1322,8 +1366,8 @@ VOID LOADER_ENTRY::StartLoader11()
for (size_t kextIdx = 0 ; kextIdx < kextArray.size() ; kextIdx++ )
{
const XString8& KextEntry = kextArray[kextIdx];
DBG("Bridge kext to OC : Path=%s\n", KextEntry.c_str());
const SIDELOAD_KEXT& KextEntry = kextArray[kextIdx];
DBG("Bridge kext to OC : Path=%ls\n", KextEntry.FileName.wc_str());
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx] = (__typeof_am__(*mOpenCoreConfiguration.Kernel.Add.Values))AllocatePool(mOpenCoreConfiguration.Kernel.Add.ValueSize);
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->Enabled = 1;
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->Arch, "Any");
@ -1331,8 +1375,8 @@ VOID LOADER_ENTRY::StartLoader11()
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->MaxKernel, "");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->MinKernel, "");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->Identifier, "");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath, KextEntry.c_str()); // do NOT delete kextArray, or make a copy.
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ExecutablePath, S8Printf("Contents/MacOS/%s", KextEntry.subString(0, KextEntry.indexOf(".")).c_str()).c_str());
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->BundlePath, S8Printf("%ls\\%ls", KextEntry.KextDirNameUnderOEMPath.wc_str(), KextEntry.FileName.wc_str()).c_str()); // do NOT delete kextArray, or make a copy.
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ExecutablePath, S8Printf("Contents\\MacOS\\%ls", KextEntry.FileName.subString(0, KextEntry.FileName.rindexOf(".")).wc_str()).c_str());
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->PlistPath, "Contents/Info.plist"); // TODO : is always Contents/Info.plist ?
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ImageData = NULL;
mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->ImageDataSize = 0;
@ -1360,7 +1404,8 @@ VOID LOADER_ENTRY::StartLoader11()
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Comment, kextPatch.Label.c_str());
mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Count = 0;
mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Enabled = 1;
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Find, kextPatch.Data.vdata(), kextPatch.Data.size());
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Find, kextPatch.Data.data(), kextPatch.Data.size());
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Identifier, "kernel");
mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Limit = (UINT32)kextPatch.Count;
OC_STRING_ASSIGN_N(mOpenCoreConfiguration.Kernel.Patch.Values[kextPatchIdx]->Mask, kextPatch.MaskFind.vdata(), kextPatch.MaskFind.size());
@ -1376,13 +1421,16 @@ VOID LOADER_ENTRY::StartLoader11()
DBG("TODO !!!!!!!! Bridge force kext to OC : %ls\n", forceKext.wc_str());
}
if (OcOSInfoInstallProtocol (false) == NULL) {
DEBUG ((DEBUG_ERROR, "OC: Failed to install os info protocol\n"));
}
// if (OcOSInfoInstallProtocol (false) == NULL) {
// DEBUG ((DEBUG_ERROR, "OC: Failed to install os info protocol\n"));
// }
// if (OcAppleRtcRamInstallProtocol (false) == NULL) {
// DEBUG ((DEBUG_ERROR, "OC: Failed to install rtc ram protocol\n"));
// }
EFI_HANDLE EntryHandle = NULL;
Status = InternalEfiLoadImage (
// point to InternalEfiLoadImage from OC
Status = gBS->LoadImage (
FALSE,
gImageHandle,
DevicePath,
@ -1405,8 +1453,8 @@ VOID LOADER_ENTRY::StartLoader11()
LoadedImage->LoadOptions = (void*)LoadOptionsAsXStringW.wc_str();
LoadedImage->LoadOptionsSize = (UINT32)LoadOptionsAsXStringW.sizeInBytesIncludingTerminator();
Status = OcStartImage (EntryHandle, 0, NULL);
// point to OcStartImage from OC
Status = gBS->StartImage (EntryHandle, 0, NULL);
if ( EFI_ERROR(Status) ) return; // TODO message ?
}

View File

@ -1768,39 +1768,36 @@ REFIT_ABSTRACT_MENU_ENTRY* SubMenuKextBlockInjection(const XString8& UniSysVer)
REFIT_MENU_ITEM_OPTIONS *Entry = NULL;
REFIT_MENU_SCREEN *SubScreen = NULL;
REFIT_INPUT_DIALOG *InputBootArgs;
SIDELOAD_KEXT *Kext = NULL;
XString8 sysVer = S8Printf("%s->", UniSysVer.c_str());
Kext = InjectKextList;
while (Kext) {
if ( Kext->KextDirNameUnderOEMPath == UniSysVer ) {
for ( size_t idx = 0 ; idx < InjectKextList.size() ; idx ++ ) {
SIDELOAD_KEXT& Kext = InjectKextList[idx];
if ( Kext.KextDirNameUnderOEMPath == UniSysVer ) {
if ( SubScreen == NULL ) {
Entry = newREFIT_MENU_ITEM_OPTIONS(&SubScreen, ActionEnter, SCREEN_KEXT_INJECT, sysVer);
SubScreen->AddMenuInfoLine_f("Choose/check kext to disable:");
}
InputBootArgs = new REFIT_INPUT_DIALOG;
InputBootArgs->Title.SWPrintf("%ls, v.%ls", Kext->FileName.wc_str(), Kext->Version.wc_str());
InputBootArgs->Title.SWPrintf("%ls, v.%ls", Kext.FileName.wc_str(), Kext.Version.wc_str());
// InputBootArgs->Tag = TAG_INPUT;
InputBootArgs->Row = 0xFFFF; //cursor
InputBootArgs->Item = &(Kext->MenuItem);
InputBootArgs->Item = &(Kext.MenuItem);
InputBootArgs->AtClick = ActionEnter;
InputBootArgs->AtRightClick = ActionDetails;
SubScreen->AddMenuEntry(InputBootArgs, true);
SIDELOAD_KEXT *plugInKext = Kext->PlugInList;
while (plugInKext) {
for ( size_t idxPlugin = 0 ; idxPlugin < Kext.PlugInList.size() ; idxPlugin ++ ) {
SIDELOAD_KEXT& plugInKext = Kext.PlugInList[idxPlugin];
InputBootArgs = new REFIT_INPUT_DIALOG;
InputBootArgs->Title.SWPrintf(" |-- %ls, v.%ls", plugInKext->FileName.wc_str(), plugInKext->Version.wc_str());
InputBootArgs->Title.SWPrintf(" |-- %ls, v.%ls", plugInKext.FileName.wc_str(), plugInKext.Version.wc_str());
// InputBootArgs->Tag = TAG_INPUT;
InputBootArgs->Row = 0xFFFF; //cursor
InputBootArgs->Item = &(plugInKext->MenuItem);
InputBootArgs->Item = &(plugInKext.MenuItem);
InputBootArgs->AtClick = ActionEnter;
InputBootArgs->AtRightClick = ActionDetails;
SubScreen->AddMenuEntry(InputBootArgs, true);
plugInKext = plugInKext->Next;
}
}
Kext = Kext->Next;
}
if ( SubScreen != NULL ) SubScreen->AddMenuEntry(&MenuEntryReturn, false);