Refactor selfOem. Created getConfigDir... methods.

Enclose access to getOemDir... by if (selfOem.oemDirExists()).
Enclose access to getKextsDir... by if (selfOem.isKextsDirFound()).
closeDebugLog() in UninitRefitLib().
Prevent DBG loop.
This commit is contained in:
jief666 2020-10-17 16:01:33 +03:00
parent aee426fa30
commit 70988228c4
29 changed files with 644 additions and 240 deletions

View File

@ -88,6 +88,14 @@ SetMemLogCallback (
);
/**
Sets callback that will be called when message is added to mem log.
**/
MEM_LOG_CALLBACK
EFIAPI
GetMemLogCallback ();
/**
Returns TSC ticks per second.
**/

View File

@ -403,6 +403,16 @@ SetMemLogCallback (
mMemLog->Callback = Callback;
}
/**
Sets callback that will be called when message is added to mem log.
**/
MEM_LOG_CALLBACK
EFIAPI
GetMemLogCallback ()
{
return mMemLog->Callback;
}
/**
Returns TSC ticks per second.
**/

View File

@ -222,7 +222,7 @@ EFI_STATUS
(EFIAPI *EFI_FILE_WRITE)(
IN EFI_FILE_PROTOCOL *This,
IN OUT UINTN *BufferSize,
IN VOID *Buffer
IN JCONST VOID *Buffer
);
/**

@ -1 +1 @@
Subproject commit 002ba502e48ce073f180191d9d52617733fba3e9
Subproject commit b2824181efe897583c7c6d7b817e6707842eb564

View File

@ -203,6 +203,8 @@
9AABBE1D2524863E0033A009 /* SelfOem.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AABBE1B2524863E0033A009 /* SelfOem.h */; };
9AC269A824E0514100254048 /* Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC269A624E0514000254048 /* Utils.cpp */; };
9AC269A924E0514100254048 /* Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC269A724E0514000254048 /* Utils.h */; };
9AC44EDD253AE78C00326488 /* MemoryOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC44EDB253AE78C00326488 /* MemoryOperation.h */; };
9AC44EDE253AE78C00326488 /* MemoryOperation.c in Sources */ = {isa = PBXBuildFile; fileRef = 9AC44EDC253AE78C00326488 /* MemoryOperation.c */; };
9AC77FB924176C04005CDD5C /* XStringArray_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ECC24176C04005CDD5C /* XStringArray_test.h */; };
9AC77FBA24176C04005CDD5C /* XArray_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ECD24176C04005CDD5C /* XArray_tests.h */; };
9AC77FBB24176C04005CDD5C /* XStringArray_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ECE24176C04005CDD5C /* XStringArray_test.cpp */; };
@ -795,6 +797,8 @@
9AABBE1B2524863E0033A009 /* SelfOem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelfOem.h; sourceTree = "<group>"; };
9AC269A624E0514000254048 /* Utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Utils.cpp; sourceTree = "<group>"; };
9AC269A724E0514000254048 /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utils.h; sourceTree = "<group>"; };
9AC44EDB253AE78C00326488 /* MemoryOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryOperation.h; sourceTree = "<group>"; };
9AC44EDC253AE78C00326488 /* MemoryOperation.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = MemoryOperation.c; sourceTree = "<group>"; };
9AC77EC424176BF2005CDD5C /* libCloverX64.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCloverX64.a; sourceTree = BUILT_PRODUCTS_DIR; };
9AC77ECC24176C04005CDD5C /* XStringArray_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringArray_test.h; sourceTree = "<group>"; };
9AC77ECD24176C04005CDD5C /* XArray_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XArray_tests.h; sourceTree = "<group>"; };
@ -1145,6 +1149,8 @@
9AC77F1624176C04005CDD5C /* Platform */ = {
isa = PBXGroup;
children = (
9AC44EDC253AE78C00326488 /* MemoryOperation.c */,
9AC44EDB253AE78C00326488 /* MemoryOperation.h */,
9AABBE1A2524863D0033A009 /* SelfOem.cpp */,
9AABBE1B2524863E0033A009 /* SelfOem.h */,
9A61B2FE2522165100AEE0FA /* Self.cpp */,
@ -1432,6 +1438,7 @@
9AC780B52417EE53005CDD5C /* global_test.h in Headers */,
9A105B7224483AE40006DE06 /* posix.h in Headers */,
9AC7806324176C04005CDD5C /* CanonicalDB.h in Headers */,
9AC44EDD253AE78C00326488 /* MemoryOperation.h in Headers */,
9AC7805924176C04005CDD5C /* nanosvg.h in Headers */,
9AF41566242BAD5600D2644C /* printf_lite-test-cpp_conf.h in Headers */,
9A105B7624483AE40006DE06 /* stdint.h in Headers */,
@ -1970,6 +1977,7 @@
9AC7800924176C04005CDD5C /* AcpiPatcher.cpp in Sources */,
9AC7800D24176C04005CDD5C /* BdsConnect.cpp in Sources */,
9AC7802924176C04005CDD5C /* spd.cpp in Sources */,
9AC44EDE253AE78C00326488 /* MemoryOperation.c in Sources */,
9A105B85244852D70006DE06 /* VersionString.cpp in Sources */,
9A9D3B2324221563006D8CD9 /* printf_lite-test.cpp in Sources */,
9AC7800424176C04005CDD5C /* kext_patcher.cpp in Sources */,

View File

@ -755,7 +755,7 @@ EFI_STATUS SaveBufferToDisk(void *Buffer, UINTN Length, CONST CHAR16 *DirName, C
XStringW PathName = SWPrintf("%ls\\%ls", DirName, FileName);
EFI_STATUS Status = egSaveFile(&selfOem.getOemDir(), PathName.wc_str(), Buffer, Length);
EFI_STATUS Status = egSaveFile(&selfOem.getConfigDir(), PathName.wc_str(), Buffer, Length);
// Do not write outside OemDir
// if (EFI_ERROR(Status)) {
// Status = egSaveFile(NULL, PathName.wc_str(), Buffer, Length);
@ -1505,14 +1505,14 @@ void SaveOemDsdt(BOOLEAN FullPatch)
XStringW OriginDsdt = SWPrintf("ACPI\\origin\\DSDT.aml");
XStringW OriginDsdtFixed = SWPrintf("ACPI\\origin\\DSDT-%x.aml", gSettings.FixDsdt);
// constexpr LStringW PathPatched = L"\\EFI\\CL OVER\\ACPI\\patched";
XStringW PathDsdt;
// XStringW PathDsdt;
// XStringW AcpiOemPath = SWPrintf("ACPI\\patched");
// PathDsdt.SWPrintf("\\%ls", gSettings.DsdtName.wc_str());
if (FileExists(&selfOem.getOemDir(), SWPrintf("ACPI\\patched\\%ls", gSettings.DsdtName.wc_str()))) {
DBG("SaveOemDsdt: DSDT found in Clover volume OEM folder: ACPI\\patched\\%ls\n", gSettings.DsdtName.wc_str());
Status = egLoadFile(&selfOem.getOemDir(), SWPrintf("ACPI\\patched\\%ls", gSettings.DsdtName.wc_str()).wc_str(), &buffer, &DsdtLen);
if (FileExists(selfOem.getConfigDir(), SWPrintf("ACPI\\patched\\%ls", gSettings.DsdtName.wc_str()))) {
DBG("SaveOemDsdt: DSDT found in Clover volume OEM folder: \\%ls\\ACPI\\patched\\%ls\n", selfOem.getConfigDirFullPath().wc_str(), gSettings.DsdtName.wc_str());
Status = egLoadFile(&selfOem.getConfigDir(), SWPrintf("ACPI\\patched\\%ls", gSettings.DsdtName.wc_str()).wc_str(), &buffer, &DsdtLen);
}
// Jief : Do not write outside OemPath
@ -1558,15 +1558,15 @@ void SaveOemDsdt(BOOLEAN FullPatch)
DsdtLen = ((EFI_ACPI_DESCRIPTION_HEADER*)buffer)->Length;
OriginDsdt = OriginDsdtFixed;
}
Status = egSaveFile(&selfOem.getOemDir(), OriginDsdt.wc_str(), buffer, DsdtLen);
Status = egSaveFile(&selfOem.getConfigDir(), OriginDsdt.wc_str(), buffer, DsdtLen);
// Jief : do not write outside of OemDir
// if (EFI_ERROR(Status)) {
// Status = egSaveFile(NULL, OriginDsdt.wc_str(), buffer, DsdtLen);
// }
if (!EFI_ERROR(Status)) {
MsgLog("DSDT saved to %ls\n", OriginDsdt.wc_str());
MsgLog("DSDT saved to %ls\\%ls\n", selfOem.getConfigDirFullPath().wc_str(), OriginDsdt.wc_str());
} else {
MsgLog("Saving DSDT to %ls\\%ls failed - %s\n", selfOem.getOemFullPath().wc_str(), OriginDsdt.wc_str(), efiStrError(Status));
MsgLog("Saving DSDT to %ls\\%ls failed - %s\n", selfOem.getConfigDirFullPath().wc_str(), OriginDsdt.wc_str(), efiStrError(Status));
}
gBS->FreePages(dsdt, Pages);
}
@ -1639,8 +1639,8 @@ void LoadAllPatchedAML(const XStringW& acpiPathUnderOem, UINTN Pass)
}
}
if (!ACPIPatchedAMLTmp) { // NULL when not disabled
DBG("Inserting table[%llu]:%ls from %ls\\%ls: ", Index, gSettings.SortedACPI[Index], selfOem.getOemFullPath().wc_str(), acpiPathUnderOem.wc_str());
if (LoadPatchedAML(selfOem.getOemDir(), acpiPathUnderOem, gSettings.SortedACPI[Index], Pass)) {
DBG("Inserting table[%llu]:%ls from %ls\\%ls: ", Index, gSettings.SortedACPI[Index], selfOem.getConfigDirFullPath().wc_str(), acpiPathUnderOem.wc_str());
if (LoadPatchedAML(selfOem.getConfigDir(), acpiPathUnderOem, gSettings.SortedACPI[Index], Pass)) {
// avoid inserting table again on second pass
for (ACPI_PATCHED_AML* temp2 = ACPIPatchedAML; temp2; temp2 = temp2->Next) {
if (0 == StriCmp(temp2->FileName, gSettings.SortedACPI[Index])) {
@ -1656,8 +1656,8 @@ void LoadAllPatchedAML(const XStringW& acpiPathUnderOem, UINTN Pass)
DBG("Unsorted\n");
for (ACPIPatchedAMLTmp = ACPIPatchedAML; ACPIPatchedAMLTmp; ACPIPatchedAMLTmp = ACPIPatchedAMLTmp->Next) {
if (!ACPIPatchedAMLTmp->MenuItem.BValue) {
DBG("Inserting %ls from %ls\\%ls: ", ACPIPatchedAMLTmp->FileName, selfOem.getOemFullPath().wc_str(), acpiPathUnderOem.wc_str());
if (LoadPatchedAML(selfOem.getOemDir(), acpiPathUnderOem, ACPIPatchedAMLTmp->FileName, Pass)) {
DBG("Inserting %ls from %ls\\%ls: ", ACPIPatchedAMLTmp->FileName, selfOem.getConfigDirFullPath().wc_str(), acpiPathUnderOem.wc_str());
if (LoadPatchedAML(selfOem.getConfigDir(), acpiPathUnderOem, ACPIPatchedAMLTmp->FileName, Pass)) {
// avoid inserting table again on second pass
ACPIPatchedAMLTmp->MenuItem.BValue = BVALUE_ATTEMPTED;
}
@ -1687,7 +1687,7 @@ EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion)
UINT8 *buffer = NULL;
UINTN bufferLen = 0;
// constexpr LStringW PathPatched = L"\\EFI\\CL OVER\\ACPI\\patched";
XStringW PathDsdt; // = L"\\DSDT.aml";
// XStringW PathDsdt; // = L"\\DSDT.aml";
// CHAR16* PatchedAPIC = L"\\EFI\\CL OVER\\ACPI\\origin\\APIC-p.aml";
UINT32* rf = NULL;
UINT64* xf = NULL;
@ -1713,7 +1713,6 @@ EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion)
DbgHeader("PatchACPI");
PathDsdt = SWPrintf("\\%ls", gSettings.DsdtName.wc_str());
//try to find in SystemTable
for(Index = 0; Index < gST->NumberOfTableEntries; Index++) {
if(CompareGuid (&gST->ConfigurationTable[Index].VendorGuid, &gEfiAcpi20TableGuid)) {
@ -1962,12 +1961,15 @@ EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion)
// RootDir = Volume->RootDir;
Status = EFI_NOT_FOUND;
XStringW acpiPath = SWPrintf("ACPI\\patched\\%ls", PathDsdt.wc_str());
XStringW acpiPath = SWPrintf("ACPI\\patched\\%ls", gSettings.DsdtName.wc_str());
if ( FileExists(&selfOem.getOemDir(), acpiPath) ) {
DBG("DSDT found in Clover volume OEM folder: %ls\\%ls\n", selfOem.getOemFullPath().wc_str(), acpiPath.wc_str());
Status = egLoadFile(&selfOem.getOemDir(), acpiPath.wc_str(), &buffer, &bufferLen);
//REVIEW: memory leak... buffer
if ( selfOem.oemDirExists() ) {
if ( FileExists(&selfOem.getOemDir(), acpiPath) ) {
DBG("DSDT found in Clover volume OEM folder: %ls\\%ls\n", selfOem.getOemFullPath().wc_str(), acpiPath.wc_str());
Status = egLoadFile(&selfOem.getOemDir(), acpiPath.wc_str(), &buffer, &bufferLen);
//REVIEW: memory leak... buffer
}
}
//Slice: the idea was from past
@ -1975,6 +1977,7 @@ EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion)
// second priority is DSDT from OEM folder
// third priority is /EFI/CLOVER/ACPI/patched/DSDT*.aml choosen from GUI.
XStringW PathDsdt = SWPrintf("\\%ls", gSettings.DsdtName.wc_str());
if (EFI_ERROR(Status) && FileExists(Volume->RootDir, PathDsdt)) {
DBG("DSDT found in booted volume\n");
Status = egLoadFile(Volume->RootDir, PathDsdt.wc_str(), &buffer, &bufferLen);
@ -1982,7 +1985,7 @@ EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion)
// Jief : may I suggest to remove that. Loading from outside of OemPath might be confusing
if ( EFI_ERROR(Status) && FileExists(&self.getCloverDir(), acpiPath) ) {
DBG("DSDT found in Clover volume: %ls\\%ls\n", self.getCloverDirPathAsXStringW().wc_str(), acpiPath.wc_str());
DBG("DSDT found in Clover volume: %ls\\%ls\n", self.getCloverDirFullPath().wc_str(), acpiPath.wc_str());
Status = egLoadFile(&self.getCloverDir(), acpiPath.wc_str(), &buffer, &bufferLen);
}
//
@ -2046,8 +2049,8 @@ EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion)
// }
if (gSettings.DebugDSDT) {
DBG("Output DSDT before patch to %ls\\ACPI\\origin\\DSDT-or.aml\n", selfOem.getOemFullPath().wc_str());
Status = egSaveFile(&selfOem.getOemDir(), L"ACPI\\origin\\DSDT-or.aml", (UINT8*)(UINTN)FadtPointer->XDsdt, bufferLen);
DBG("Output DSDT before patch to %ls\\ACPI\\origin\\DSDT-or.aml\n", selfOem.getConfigDirFullPath().wc_str());
Status = egSaveFile(&selfOem.getConfigDir(), L"ACPI\\origin\\DSDT-or.aml", (UINT8*)(UINTN)FadtPointer->XDsdt, bufferLen);
}
//native DSDT or loaded we want to apply autoFix to this
// if (gSettings.FixDsdt) { //fix even with zero mask because we want to know PCIRootUID and count(?)
@ -2057,8 +2060,8 @@ EFI_STATUS PatchACPI(IN REFIT_VOLUME *Volume, const XString8& OSVersion)
if (gSettings.DebugDSDT) {
for (Index=0; Index < 60; Index++) {
XStringW DsdtPatchedName = SWPrintf("ACPI\\origin\\DSDT-pa%llu.aml", Index);
if(!FileExists(&selfOem.getOemDir(), DsdtPatchedName)){
Status = egSaveFile(&selfOem.getOemDir(), DsdtPatchedName.wc_str(), (UINT8*)(UINTN)FadtPointer->XDsdt, bufferLen);
if(!FileExists(&selfOem.getConfigDir(), DsdtPatchedName)){
Status = egSaveFile(&selfOem.getConfigDir(), DsdtPatchedName.wc_str(), (UINT8*)(UINTN)FadtPointer->XDsdt, bufferLen);
if (!EFI_ERROR(Status)) {
break;
}
@ -2317,7 +2320,7 @@ EFI_STATUS LoadAndInjectDSDT(CONST CHAR16 *PathPatched,
if (!EFI_ERROR(Status)) {
// loaded - allocate EfiACPIReclaim
DBG("Loaded DSDT at %ls\\%ls\\%ls\n", self.getCloverDirPathAsXStringW().wc_str(), PathPatched, gSettings.DsdtName.wc_str());
DBG("Loaded DSDT at \\%ls\\%ls\\%ls\n", self.getCloverDirFullPath().wc_str(), PathPatched, gSettings.DsdtName.wc_str());
Dsdt = EFI_SYSTEM_TABLE_MAX_ADDRESS; //0xFE000000;
Status = gBS->AllocatePages (
AllocateMaxAddress,
@ -2478,16 +2481,19 @@ EFI_STATUS PatchACPI_OtherOS(CONST CHAR16* OsSubdir, BOOLEAN DropSSDT)
//
// prepare dirs that will be searched for custom ACPI tables
XStringW AcpiOemPath = SWPrintf("%ls\\ACPI\\%ls", selfOem.getOemPathRelToSelfDir().wc_str(), OsSubdir);
XStringW PathPatched;
if (FileExists(&self.getCloverDir(), AcpiOemPath)) {
PathPatched = AcpiOemPath;
} else {
PathPatched = SWPrintf("ACPI\\%ls", OsSubdir);
if ( selfOem.oemDirExists() ) {
PathPatched = SWPrintf("%ls\\ACPI\\%ls", selfOem.getOemPathRelToSelfDir().wc_str(), OsSubdir);
if ( !FileExists(&self.getCloverDir(), PathPatched) ) {
PathPatched.setEmpty();
}
}
if (!FileExists(&self.getCloverDir(), PathPatched)) {
DBG("Dir %ls not found. No patching will be done.\n", OsSubdir);
return EFI_NOT_FOUND;
if ( PathPatched.isEmpty() ) {
PathPatched = SWPrintf("ACPI\\%ls", OsSubdir);
if (!FileExists(&self.getCloverDir(), PathPatched)) {
DBG("Dir '\\%ls\\%ls' not found. No patching will be done.\n", self.getCloverDirFullPath().wc_str(), PathPatched.wc_str());
return EFI_NOT_FOUND;
}
}
//

View File

@ -16,6 +16,22 @@
#include "guid.h"
#ifndef DEBUG_ALL
#define DEBUG_BOOTLOG 1
#else
#define DEBUG_BOOTLOG DEBUG_ALL
#endif
#if DEBUG_BOOTLOG == 0
#define DBG(...)
#else
#define DBG(...) DebugLog (DEBUG_BOOTLOG, __VA_ARGS__)
#endif
void EFIAPI MemLogCallback(IN INTN DebugMode, IN CHAR8 *LastMessage);
/** Prints Number of bytes in a row (hex and ascii). Row size is MaxNumber. */
void
PrintBytesRow(IN UINT8 *Bytes, IN UINTN Number, IN UINTN MaxNumber)
@ -58,117 +74,160 @@ PrintBytes(IN void *Bytes, IN UINTN Number)
}
static EFI_FILE_PROTOCOL* gLogFile = NULL;
STATIC BOOLEAN FirstTimeSave = TRUE;
class SuspendMemLogCallback
{
MEM_LOG_CALLBACK memlogCallBack_saved;
public:
SuspendMemLogCallback() {
memlogCallBack_saved = GetMemLogCallback();
SetMemLogCallback(NULL);
};
~SuspendMemLogCallback() { SetMemLogCallback(memlogCallBack_saved); };
};
void closeDebugLog()
{
EFI_STATUS Status;
if ( !gLogFile ) return;
SuspendMemLogCallback smc;
Status = gLogFile->Close(gLogFile);
DBG("closeDebugLog() -> %s\n", efiStrError(Status));
gLogFile = NULL;
}
EFI_FILE_PROTOCOL* GetDebugLogFile()
{
EFI_STATUS Status;
EFI_LOADED_IMAGE *LoadedImage;
EFI_FILE_PROTOCOL *RootDir;
EFI_FILE_PROTOCOL *LogFile;
if ( gLogFile ) return gLogFile;
if ( !self.isInitialized() ) return NULL;
// // get RootDir from device we are loaded from
// Status = gBS->HandleProtocol(gImageHandle, &gEfiLoadedImageProtocolGuid, (void **) &LoadedImage);
// if (EFI_ERROR(Status)) {
// return NULL;
// }
// RootDir = EfiLibOpenRoot(LoadedImage->DeviceHandle);
// if (RootDir == NULL) {
// return NULL;
// }
// Avoid debug looping. We don't want DBG from this function to call this function through the callback.
SuspendMemLogCallback smc;
// get RootDir from device we are loaded from
Status = gBS->HandleProtocol(gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
if (EFI_ERROR(Status)) {
DBG(" GetDebugLogFile() -> HandleProtocol : %s\n", efiStrError(Status));
return NULL;
}
RootDir = EfiLibOpenRoot(LoadedImage->DeviceHandle);
if (RootDir == NULL) {
DBG(" GetDebugLogFile() -> EfiLibOpenRoot : %s\n", efiStrError(Status));
return NULL;
}
// Open log file from current root
Status = self.getCloverDir().Open(&self.getCloverDir(), &LogFile, DEBUG_LOG_new, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
if ( GlobalConfig.ScratchDebugLogAtStart && Status == EFI_SUCCESS)
Status = RootDir->Open(RootDir, &LogFile, SWPrintf("%ls\\%ls", self.getCloverDirFullPath().wc_str(), DEBUG_LOG).wc_str(),
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
if ( !EFI_ERROR (Status) && GlobalConfig.ScratchDebugLogAtStart )
{
// Here, we are not at the beginning. Some log was already sent.
// That's because the setting GlobalConfig.ScratchDebugLogAtStart is not set before the first log sent.
DBG(" GetDebugLogFile() -> deleting the log '%ls'\n", DEBUG_LOG);
EFI_STATUS StatusDelete;
StatusDelete = LogFile->Delete(LogFile);
if ( StatusDelete == EFI_SUCCESS) {
Status = EFI_NOT_FOUND; // to get it created next.
GlobalConfig.ScratchDebugLogAtStart = false;
FirstTimeSave = true;
LogFile = NULL;
Status = EFI_NOT_FOUND; // to make be reopened in the next lines.
}else{
DebugLog(1, "Cannot delete log file %ls\\%ls from current root : %s\n", self.getCloverDirPathAsXStringW().wc_str(), DEBUG_LOG_new, efiStrError(StatusDelete));
DBG(" Cannot delete log file '%ls\\%ls' : %s\n", self.getCloverDirFullPath().wc_str(), DEBUG_LOG, efiStrError(StatusDelete));
RootDir->Close(RootDir);
return NULL;
}
}else{
// DBG(" GetDebugLogFile() -> open log : %s\n", efiStrError(Status));
}
// If the log file is not found try to create it
if (Status == EFI_NOT_FOUND) {
Status = self.getCloverDir().Open(&self.getCloverDir(), &LogFile, DEBUG_LOG_new, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
Status = RootDir->Open(RootDir, &LogFile, SWPrintf("%ls\\%ls", self.getCloverDirFullPath().wc_str(), DEBUG_LOG).wc_str(),
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
}
// RootDir->Close(RootDir);
// RootDir = NULL;
// Jief : do we really need this ?
if (EFI_ERROR(Status)) {
// try on first EFI partition
EFI_FILE* RootDir;
Status = egFindESP(&RootDir);
if (!EFI_ERROR(Status)) {
Status = RootDir->Open(RootDir, &LogFile, SWPrintf("%ls\\%ls", self.getCloverDirPathAsXStringW().wc_str(), DEBUG_LOG_new).wc_str(), EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
if ( GlobalConfig.ScratchDebugLogAtStart && Status == EFI_SUCCESS)
{
EFI_STATUS StatusDelete;
StatusDelete = LogFile->Delete(LogFile);
if ( StatusDelete == EFI_SUCCESS) {
Status = EFI_NOT_FOUND; // to get it created next.
}else{
DebugLog(1, "Cannot delete log file %ls from 1st EFI partition : %s\n", SWPrintf("%ls\\%ls", self.getCloverDirPathAsXStringW().wc_str(), DEBUG_LOG_new).wc_str(), efiStrError(StatusDelete));
}
}
// If the log file is not found try to create it
if (Status == EFI_NOT_FOUND) {
Status = RootDir->Open(RootDir, &LogFile, SWPrintf("%ls\\%ls", self.getCloverDirPathAsXStringW().wc_str(), DEBUG_LOG_new).wc_str(), EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
}
RootDir->Close(RootDir);
RootDir = NULL;
}
}
RootDir->Close(RootDir);
RootDir = NULL;
// if (EFI_ERROR(Status)) {
// // try on first EFI partition
// Status = egFindESP(&RootDir);
// if (!EFI_ERROR(Status)) {
// Status = RootDir->Open(RootDir, &LogFile, SWPrintf("%ls\\%ls", self.getCloverDirFullPath().wc_str(), DEBUG_LOG).wc_str(),
// EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
// // If the log file is not found try to create it
// if (Status == EFI_NOT_FOUND) {
// Status = RootDir->Open(RootDir, &LogFile, SWPrintf("%ls\\%ls", self.getCloverDirFullPath().wc_str(), DEBUG_LOG).wc_str(),
// EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
// }
// RootDir->Close(RootDir);
// RootDir = NULL;
// }
// }
if (EFI_ERROR(Status)) {
DBG(" GetDebugLogFile() -> !opened : %s\n", efiStrError(Status));
LogFile = NULL;
}
gLogFile = LogFile;
return LogFile;
}
void SaveMessageToDebugLogFile(IN CHAR8 *LastMessage)
VOID SaveMessageToDebugLogFile(IN CHAR8 *LastMessage)
{
EFI_STATUS Status;
STATIC BOOLEAN FirstTimeSave = TRUE;
// STATIC UINTN Position = 0;
CHAR8 *MemLogBuffer;
UINTN MemLogLen;
CHAR8 *Text;
UINTN TextLen;
EFI_FILE* LogFile;
EFI_FILE_HANDLE LogFile;
EFI_STATUS Status;
// Avoid debug looping. We don't want DBG from this function to call this function through the callback.
SuspendMemLogCallback smc;
MemLogBuffer = GetMemLogBuffer();
MemLogLen = GetMemLogLen();
Text = LastMessage;
TextLen = AsciiStrLen(LastMessage);
LogFile = GetDebugLogFile();
// Write to the log file
if (LogFile != NULL) {
// Advance to the EOF so we append
EFI_FILE_INFO *Info = EfiLibFileInfo(LogFile);
if (Info) {
Status = LogFile->SetPosition(LogFile, Info->FileSize);
if ( EFI_ERROR(Status) ) {
DBG("SaveMessageToDebugLogFile SetPosition error %s\n", efiStrError(Status));
}
// If we haven't had root before this write out whole log
if (FirstTimeSave) {
Text = MemLogBuffer;
TextLen = MemLogLen;
FirstTimeSave = FALSE;
DBG("SaveMessageToDebugLogFile first time\n");
}
// Write out this message
Status = LogFile->Write(LogFile, &TextLen, Text);
Status = LogFile->Flush(LogFile);
(void)Status;
UINTN TextLen2 = TextLen;
Status = LogFile->Write(LogFile, &TextLen2, Text);
if ( EFI_ERROR(Status) ) {
DBG("SaveMessageToDebugLogFile write error %s\n", efiStrError(Status));
}else{
if ( TextLen2 != TextLen ) {
DBG("SaveMessageToDebugLogFile TextLen2(%lld) != TextLen(%lld)\n", TextLen2, TextLen);
}
}
}
// LogFile->Close(LogFile);
LogFile->Close(LogFile);
}
}

View File

@ -16,11 +16,11 @@ extern "C" {
//#define SAFE_LOG_SIZE 80
//#define MSG_LOG_SIZE (256 * 1024)
#define PREBOOT_LOG_new L"misc\\preboot.log"
#define LEGBOOT_LOG_new L"misc\\legacy_boot.log"
#define BOOT_LOG_new L"misc\\boot.log"
#define SYSTEM_LOG_new L"misc\\system.log"
#define DEBUG_LOG_new L"misc\\debug.log"
#define PREBOOT_LOG L"misc\\preboot.log"
#define LEGBOOT_LOG L"misc\\legacy_boot.log"
//#define BOOT_LOG_new L"misc\\boot.log"
//#define SYSTEM_LOG_new L"misc\\system.log"
#define DEBUG_LOG L"misc\\debug.log"
//#define PREWAKE_LOG L"misc\\prewake.log"
@ -28,6 +28,8 @@ extern "C" {
void
InitBooterLog (void);
void closeDebugLog();
EFI_STATUS
SetupBooterLog (
BOOLEAN AllowGrownSize

View File

@ -398,7 +398,7 @@ EFI_STATUS bootElTorito(REFIT_VOLUME* volume)
return Status;
}
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG_new);
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG);
// Jief : don't write outside of SelfDir
// if (EFI_ERROR(Status)) {
@ -516,7 +516,7 @@ EFI_STATUS bootMBR(REFIT_VOLUME* volume)
DBG("\n");
}
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG_new);
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG);
// Jief : don't write outside SelfDir
// if (EFI_ERROR(Status)) {
// Status = SaveBooterLog(NULL, LEGBOOT_LOG);
@ -671,7 +671,7 @@ EFI_STATUS bootPBRtest(REFIT_VOLUME* volume)
DBG("\n");
}
DBG("Reset disk controller 0x80\n");
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG_new);
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG);
if (EFI_ERROR(Status)) {
DBG("can't save legacy-boot.log\n");
// Jief : don't write outside SelfDir
@ -723,7 +723,7 @@ EFI_STATUS bootPBRtest(REFIT_VOLUME* volume)
*/
//if not success then save legacyboot.log
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG_new);
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG);
if (EFI_ERROR(Status)) {
DBG("can't save legacy-boot.log\n");
// Jief : don't write outside SelfDir
@ -975,7 +975,7 @@ EFI_STATUS bootPBR(REFIT_VOLUME* volume, BOOLEAN SataReset)
//Status = gLegacy8259->SetMask(gLegacy8259, &OldMask, NULL, NULL, NULL);
PauseForKey(L"save legacy-boot.log ...\n");
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG_new);
Status = SaveBooterLog(&self.getCloverDir(), LEGBOOT_LOG);
if (EFI_ERROR(Status)) {
DBG("can't save legacy-boot.log\n");
// Jief : don't write outside SelfDir

View File

@ -75,3 +75,13 @@ void panic(void)
{
panic(nullptr);
}
void _assert(bool b, const char* format, ...)
{
if ( !b ) {
VA_LIST va;
VA_START(va, format);
panic_(format, va); // panic doesn't return
}
}

View File

@ -22,6 +22,11 @@ void panic(const char* format, ...) __attribute__((__format__(__printf__, 1, 2))
#endif
;
#define assert(expr) _assert(expr, "Expression \"%s\" failed in %s", #expr, __PRETTY_FUNCTION__)
#define assertf(...) _assert(__VA_ARGS__)
void _assert(bool b, const char* format, ...) __attribute__((__format__(__printf__, 2, 3)));
#ifdef __cplusplus
class DontStopAtPanic
{

View File

@ -31,7 +31,7 @@ EFI_STATUS Self::_openDir(const XStringW& path, bool* b, EFI_FILE** efiDir)
EFI_STATUS Status;
Status = self.getCloverDir().Open(&self.getCloverDir(), efiDir, path.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) {
DBG("Error when opening dir '%ls\\%ls' : %s\n", self.getCloverDirPathAsXStringW().wc_str(), path.wc_str(), efiStrError(Status));
DBG("Error when opening dir '%ls\\%ls' : %s\n", self.getCloverDirFullPath().wc_str(), path.wc_str(), efiStrError(Status));
*efiDir = NULL;
*b = false;
}else{
@ -59,26 +59,29 @@ EFI_STATUS Self::_initialize()
// find the current directory
m_CloverDirPathAsXStringW = FileDevicePathToXStringW(self.getSelfLoadedImage().FilePath);
m_CloverDirFullPath = FileDevicePathToXStringW(self.getSelfLoadedImage().FilePath);
// History : if this Clover was started as BootX64.efi, redirect to /EFI/CLOVER
if ( m_CloverDirPathAsXStringW.equalIC("\\EFI\\Boot\\BootX64.efi") ) {
m_CloverDirPathAsXStringW.takeValueFrom("\\EFI\\CLOVER\\CloverX64.efi");
if ( m_CloverDirFullPath.equalIC("\\EFI\\Boot\\BootX64.efi") ) {
m_CloverDirFullPath.takeValueFrom("\\EFI\\CLOVER\\CloverX64.efi");
}
if ( m_CloverDirPathAsXStringW.isEmpty() ) panic("m_CloverDirPathAsXStringW.isEmpty()");
if ( m_CloverDirFullPath.isEmpty() ) panic("m_CloverDirFullPath.isEmpty()");
m_SelfDevicePath = FileDevicePath(self.getSelfDeviceHandle(), m_CloverDirPathAsXStringW);
m_SelfDevicePath = FileDevicePath(self.getSelfDeviceHandle(), m_CloverDirFullPath);
m_SelfDevicePathAsXStringW = FileDevicePathToXStringW(m_SelfDevicePath);
if ( !m_CloverDirPathAsXStringW.startWith('\\') ) panic("m_CloverDirPathAsXStringW.endsWith('\\')");
if ( m_CloverDirPathAsXStringW.lastChar() == U'\\' ) panic("m_CloverDirPathAsXStringW.lastChar() == U'\\'");
//if ( m_CloverDirPathAsXStringW.endsWith('\\') ) panic("m_CloverDirPathAsXStringW.endsWith('\\')");
if ( !m_CloverDirFullPath.startWith('\\') ) {
CHAR16* f = ConvertDevicePathToText(self.getSelfLoadedImage().FilePath, TRUE, TRUE);
panic("Bad format for m_CloverDirFullPath(%ls). It must start with a '\\'.\nConvertDevicePathToText=%ls", m_CloverDirFullPath.wc_str(), f);
}
if ( m_CloverDirFullPath.lastChar() == U'\\' ) panic("m_CloverDirFullPath.lastChar() == U'\\'");
//if ( m_CloverDirFullPath.endsWith('\\') ) panic("m_CloverDirFullPath.endsWith('\\')");
size_t i = m_CloverDirPathAsXStringW.rindexOf(U'\\', SIZE_T_MAX-1);
if ( i != SIZE_T_MAX && i > 0 ) m_CloverDirPathAsXStringW.deleteCharsAtPos(i, SIZE_T_MAX);
size_t i = m_CloverDirFullPath.rindexOf(U'\\', SIZE_T_MAX-1);
if ( i != SIZE_T_MAX && i > 0 ) m_CloverDirFullPath.deleteCharsAtPos(i, SIZE_T_MAX);
DBG("SelfDirPath = %ls\n", m_CloverDirPathAsXStringW.wc_str());
DBG("SelfDirPath = %ls\n", m_CloverDirFullPath.wc_str());
Status = self.getSelfVolumeRootDir().Open(&self.getSelfVolumeRootDir(), &m_CloverDir, m_CloverDirPathAsXStringW.wc_str(), EFI_FILE_MODE_READ, 0);
Status = self.getSelfVolumeRootDir().Open(&self.getSelfVolumeRootDir(), &m_CloverDir, m_CloverDirFullPath.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) panic("Cannot open getSelfRootDir()");

View File

@ -21,9 +21,9 @@ protected:
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *m_SelfSimpleVolume; // Volume containing this efi.
EFI_FILE* m_SelfRootDir; // Root dir of the volume containing this efi.
EFI_DEVICE_PATH* m_CloverDirFullDevicePath; // full path, including device, to this efi.
EFI_FILE* m_CloverDir; // opened m_SelfDirPath
XStringW m_CloverDirPathAsXStringW; // full path, including device, to this efi.
EFI_DEVICE_PATH* m_CloverDirFullDevicePath; // full path, including device, of the folder containing this efi.
EFI_FILE* m_CloverDir; // opened folder containing this efi
XStringW m_CloverDirFullPath; // full path of folder containing this efi.
// XStringW m_CloverDirPath; // dirname containing this efi (contains just the dir, not the device path)
// bool m_OemDirExists;
@ -38,7 +38,7 @@ protected:
public:
Self () : m_SelfImageHandle(NULL), m_SelfLoadedImage(NULL), m_SelfDevicePath(NULL), m_SelfDevicePathAsXStringW(),
m_SelfSimpleVolume(NULL), m_SelfRootDir(NULL),
m_CloverDirFullDevicePath(NULL), m_CloverDir(NULL), m_CloverDirPathAsXStringW()/*, m_CloverDirPath()*/, m_ThemesDirExists(false), m_ThemesDir(0) {};
m_CloverDirFullDevicePath(NULL), m_CloverDir(NULL), m_CloverDirFullPath()/*, m_CloverDirPath()*/, m_ThemesDirExists(false), m_ThemesDir(0) {};
Self(const Self&) = delete;
Self& operator = (const Self&) = delete;
@ -60,7 +60,7 @@ public:
const EFI_DEVICE_PATH& getCloverDirFullDevicePath() { return *m_CloverDirFullDevicePath; }
const EFI_FILE& getCloverDir() { return *m_CloverDir; }
const XStringW& getCloverDirPathAsXStringW() { return m_CloverDirPathAsXStringW; }
const XStringW& getCloverDirFullPath() { return m_CloverDirFullPath; }
// const XStringW& getCloverDirPath() { return m_CloverDirPath; } // returns path containing this efi. Like \\EFI\\CLOVER
// bool oemDirExists() { return m_OemDirExists; }

View File

@ -28,19 +28,19 @@ constexpr const LStringW KEXTS_DIRNAME(L"Kexts");
SelfOem selfOem;
EFI_STATUS SelfOem::_openDir(const XStringW& path, bool* b, EFI_FILE** efiDir)
{
EFI_STATUS Status;
Status = self.getCloverDir().Open(&self.getCloverDir(), efiDir, path.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) {
DBG("Error when opening dir '%ls\\%ls' : %s\n", self.getCloverDirPathAsXStringW().wc_str(), path.wc_str(), efiStrError(Status));
*efiDir = NULL;
*b = false;
}else{
*b = true;
}
return Status;
}
//EFI_STATUS SelfOem::_openDir(const XStringW& path, bool* b, EFI_FILE** efiDir)
//{
// EFI_STATUS Status;
// Status = self.getCloverDir().Open(&self.getCloverDir(), efiDir, path.wc_str(), EFI_FILE_MODE_READ, 0);
// if ( EFI_ERROR(Status) ) {
// DBG("Error when opening dir '%ls\\%ls' : %s\n", self.getCloverDirFullPath().wc_str(), path.wc_str(), efiStrError(Status));
// *efiDir = NULL;
// *b = false;
// }else{
// *b = true;
// }
// return Status;
//}
bool SelfOem::_checkOEMPath()
@ -49,26 +49,30 @@ bool SelfOem::_checkOEMPath()
// if ( !selfOem.oemDirExists() ) return false;
EFI_FILE* efiDir;
Status = self.getCloverDir().Open(&self.getCloverDir(), &efiDir, m_OemPathRelToSelfDir.wc_str(), EFI_FILE_MODE_READ, 0);
// EFI_FILE* efiDir;
Status = self.getCloverDir().Open(&self.getCloverDir(), &m_OemDir, m_OemPathRelToSelfDir.wc_str(), EFI_FILE_MODE_READ, 0);
if ( Status == EFI_NOT_FOUND ) {
DBG("_checkOEMPath Look for oem dir at path '%ls\\%ls'. Dir doesn't exist.\n", self.getCloverDirPathAsXStringW().wc_str(), m_OemPathRelToSelfDir.wc_str());
DBG("_checkOEMPath Look for oem dir at path '%ls\\%ls'. Dir doesn't exist.\n", self.getCloverDirFullPath().wc_str(), m_OemPathRelToSelfDir.wc_str());
m_OemDir = NULL;
return false;
}
if ( EFI_ERROR(Status) != EFI_SUCCESS ) {
DBG("Cannot open dir at '%ls\\%ls' dir : %s\n", self.getCloverDirPathAsXStringW().wc_str(), m_OemPathRelToSelfDir.wc_str(), efiStrError(Status));
DBG("Cannot open dir at '%ls\\%ls' dir : %s\n", self.getCloverDirFullPath().wc_str(), m_OemPathRelToSelfDir.wc_str(), efiStrError(Status));
m_OemDir = NULL;
return false;
}
BOOLEAN res2 = FileExists(efiDir, SWPrintf("%s.plist", m_ConfName.c_str()));
BOOLEAN res2 = FileExists(m_OemDir, SWPrintf("%s.plist", m_ConfName.c_str()));
if ( !res2 ) {
DBG("_checkOEMPath looked for config file at '%ls\\%ls\\%s.plist'. File doesn't exist.\n", self.getCloverDirPathAsXStringW().wc_str(), m_OemPathRelToSelfDir.wc_str(), m_ConfName.c_str());
DBG("_checkOEMPath looked for config file at '%ls\\%ls\\%s.plist'. File doesn't exist.\n", self.getCloverDirFullPath().wc_str(), m_OemPathRelToSelfDir.wc_str(), m_ConfName.c_str());
m_OemDir->Close(m_OemDir);
m_OemDir = NULL;
return false;
}
DBG("_checkOEMPath: set OEMPath: '%ls\\%ls'\n", self.getCloverDirPathAsXStringW().wc_str(), m_OemPathRelToSelfDir.wc_str());
DBG("_checkOEMPath: set OEMPath: '%ls\\%ls'\n", self.getCloverDirFullPath().wc_str(), m_OemPathRelToSelfDir.wc_str());
return true;
}
bool SelfOem::_setOEMPath(bool isFirmwareClover, const XString8& OEMBoard, const XString8& OEMProduct, INT32 frequency, UINTN nLanCards, UINT8 gLanMac[4][6])
bool SelfOem::_setOemPathRelToSelfDir(bool isFirmwareClover, const XString8& OEMBoard, const XString8& OEMProduct, INT32 frequency, UINTN nLanCards, UINT8 gLanMac[4][6])
{
if ( nLanCards > 0 ) {
@ -100,8 +104,9 @@ bool SelfOem::_setOEMPath(bool isFirmwareClover, const XString8& OEMBoard, const
m_OemPathRelToSelfDir.SWPrintf("OEM\\%s-%d", OEMBoard.c_str(), frequency);
if ( _checkOEMPath() ) return true;
m_OemPathRelToSelfDir.takeValueFrom(".");
DBG("set OEMPath to \".\"\n");
// m_OemPathRelToSelfDir.takeValueFrom(".");
// DBG("set OEMPath to \".\"\n");
m_OemPathRelToSelfDir.setEmpty();
return false;
}
@ -111,34 +116,66 @@ EFI_STATUS SelfOem::_initialize()
{
EFI_STATUS Status;
Status = self.getCloverDir().Open(&self.getCloverDir(), &m_OemDir, m_OemPathRelToSelfDir.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) panic("Cannot open oem dir at '%ls\\%ls'", self.getCloverDirPathAsXStringW().wc_str(), m_OemPathRelToSelfDir.wc_str());
DBG("Oem dir = %ls\n", (*this).getOemFullPath().wc_str());
if ( oemDirExists() ) {
m_OemFulPath = SWPrintf("%ls\\%ls", self.getCloverDirFullPath().wc_str(), m_OemPathRelToSelfDir.wc_str());
m_configDirPathRelToSelfDir = getOemPathRelToSelfDir();
m_configDirPathRelToSelfDirWithTrailingSlash.SWPrintf("%ls\\", m_configDirPathRelToSelfDir.wc_str());
}else{
m_OemFulPath.setEmpty();
m_configDirPathRelToSelfDir.setEmpty();
m_configDirPathRelToSelfDirWithTrailingSlash.setEmpty();
}
if ( m_OemDir == NULL ) {
assert( m_OemPathRelToSelfDir.isEmpty() );
assert( m_OemFulPath.isEmpty() );
}else{
assert( m_OemPathRelToSelfDir.notEmpty() );
assert( m_OemFulPath.notEmpty() );
}
Status = m_OemDir->Open(m_OemDir, &m_KextsDir, KEXTS_DIRNAME.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) {
DBG("Cannot open %ls\\%ls : %s", getOemFullPath().wc_str(), KEXTS_DIRNAME.wc_str(), efiStrError(Status));
if ( m_KextsDir != NULL ) panic("%s : m_KextsDir != NULL", __FUNCTION__);
if ( oemDirExists() ) {
Status = m_OemDir->Open(m_OemDir, &m_KextsDir, KEXTS_DIRNAME.wc_str(), EFI_FILE_MODE_READ, 0);
if ( !EFI_ERROR(Status) ) {
m_KextsPathRelToSelfDir.SWPrintf("%ls\\%ls", getOemPathRelToSelfDir().wc_str(), KEXTS_DIRNAME.wc_str());
m_KextsFullPath.SWPrintf("%ls\\%ls", getOemFullPath().wc_str(), KEXTS_DIRNAME.wc_str());
}else{
DBG("Cannot open %ls\\%ls : %s", getOemFullPath().wc_str(), KEXTS_DIRNAME.wc_str(), efiStrError(Status));
m_KextsDir = NULL;
}
}
// if ( Status != EFI_SUCCESS && Status != EFI_NOT_FOUND ) {
// panic("Cannot open kexts dir %ls\\%ls : %s", getOemFullPath().wc_str(), KEXTS_DIRNAME.wc_str(), efiStrError(Status));
// }
if ( EFI_ERROR(Status) ) {
if ( m_KextsDir == NULL ) {
Status = self.getCloverDir().Open(&self.getCloverDir(), &m_KextsDir, KEXTS_DIRNAME.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) {
DBG("Cannot open %ls\\%ls : %s", self.getCloverDirPathAsXStringW().wc_str(), KEXTS_DIRNAME.wc_str(), efiStrError(Status));
//panic("Cannot open kexts dir at '%ls\\%ls'", self.getCloverDirPathAsXStringW().wc_str(), KEXTS_DIRNAME.wc_str());
DBG("Cannot open %ls\\%ls : %s", self.getCloverDirFullPath().wc_str(), KEXTS_DIRNAME.wc_str(), efiStrError(Status));
//panic("Cannot open kexts dir at '%ls\\%ls'", self.getCloverDirFullPath().wc_str(), KEXTS_DIRNAME.wc_str());
m_KextsDir = NULL;
m_KextsPathRelToSelfDir.setEmpty();
m_KextsFullPath.setEmpty();
}else{
m_KextsPathRelToSelfDir = KEXTS_DIRNAME;
m_KextsFullPath.SWPrintf("%ls\\%ls", self.getCloverDirPathAsXStringW().wc_str(), KEXTS_DIRNAME.wc_str());
m_KextsFullPath.SWPrintf("%ls\\%ls", self.getCloverDirFullPath().wc_str(), KEXTS_DIRNAME.wc_str());
}
}else{
m_KextsPathRelToSelfDir.SWPrintf("%ls\\%ls", getOemPathRelToSelfDir().wc_str(), KEXTS_DIRNAME.wc_str());
m_KextsFullPath.SWPrintf("%ls\\%ls", getOemFullPath().wc_str(), KEXTS_DIRNAME.wc_str());
}
DBG("Kexts dir = '%ls'\n", m_KextsFullPath.wc_str()); // do not use 'getKextsFullPath()', it could panic
if ( m_KextsDir == NULL ) {
assert( m_KextsPathRelToSelfDir.isEmpty() );
assert( m_KextsFullPath.isEmpty() );
}else{
assert( m_KextsPathRelToSelfDir.notEmpty() );
assert( m_KextsFullPath.notEmpty() );
}
if ( isKextsDirFound() ) {
DBG("Kexts dir = '%ls'\n", getKextsFullPath().wc_str());
}else{
DBG("Kexts dir = none\n");
}
return EFI_SUCCESS;
}
@ -146,28 +183,41 @@ EFI_STATUS SelfOem::_initialize()
EFI_STATUS SelfOem::initialize(const XString8& confName, bool isFirmwareClover, const XString8& OEMBoard, const XString8& OEMProduct, INT32 frequency, UINTN nLanCards, UINT8 gLanMac[4][6])
{
m_ConfName = confName;
if ( _setOEMPath(isFirmwareClover, OEMBoard, OEMProduct, frequency, nLanCards, gLanMac) ) {
m_OemFulPath = SWPrintf("%ls\\%ls", self.getCloverDirPathAsXStringW().wc_str(), m_OemPathRelToSelfDir.wc_str());
m_OemDirExists = true;
}else{
m_OemFulPath = self.getCloverDirPathAsXStringW();
m_OemDirExists = false;
}
// Initialise m_OemPathRelToSelfDir and leave m_OemDir opened.
_setOemPathRelToSelfDir(isFirmwareClover, OEMBoard, OEMProduct, frequency, nLanCards, gLanMac);
return _initialize();
}
EFI_STATUS SelfOem::reInitialize()
{
closeHandle();
// No need to call _setOemPathRelToSelfDir again, but need to open m_OemDir, if it exists
if ( oemDirExists() ) {
EFI_STATUS Status = self.getCloverDir().Open(&self.getCloverDir(), &m_OemDir, m_OemPathRelToSelfDir.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) {
panic("Impossible to reopen dir '%ls\\%ls', although it was opened the first time : %s", self.getCloverDirFullPath().wc_str(), m_OemPathRelToSelfDir.wc_str(), efiStrError(Status));
}
}
return _initialize();
}
void SelfOem::closeHandle(void)
{
if (m_KextsDir != NULL) {
m_KextsDir->Close(m_KextsDir);
m_KextsDir = NULL;
m_KextsPathRelToSelfDir.setEmpty();
m_KextsFullPath.setEmpty();
}
if (m_OemDir != NULL) {
m_OemDir->Close(m_OemDir);
m_OemDir = NULL;
// m_OemPathRelToSelfDir.setEmpty(); // do not empty m_OemPathRelToSelfDir, we need it in reInitialize()
// m_OemFulPath.setEmpty(); // doesn't matter, it'll be re-initialised in _initialize()
}
}

View File

@ -9,28 +9,33 @@
#define PLATFORM_SELFOEM_H_
#include <Platform.h>
#include "Self.h"
class SelfOem
{
protected:
XString8 m_ConfName;
bool m_OemDirExists;
EFI_FILE* m_OemDir;
// bool m_OemDirExists;
EFI_FILE* m_OemDir = NULL;
XStringW m_OemPathRelToSelfDir;
XStringW m_OemFulPath;
EFI_FILE* m_KextsDir;
// const EFI_FILE* m_userConfigDir = NULL;
XStringW m_configDirPathRelToSelfDir; // could also be empty if config dir is clover dir.
XStringW m_configDirPathRelToSelfDirWithTrailingSlash; // could also be empty if config dir is clover dir.
EFI_FILE* m_KextsDir = NULL;
XStringW m_KextsPathRelToSelfDir;
XStringW m_KextsFullPath;
EFI_STATUS _openDir(const XStringW& path, bool* b, EFI_FILE** efiDir);
// EFI_STATUS _openDir(const XStringW& path, bool* b, EFI_FILE** efiDir);
bool _checkOEMPath();
bool _setOEMPath(bool isFirmwareClover, const XString8& OEMBoard, const XString8& OEMProduct, INT32 frequency, UINTN nLanCards, UINT8 gLanMac[4][6]);
bool _setOemPathRelToSelfDir(bool isFirmwareClover, const XString8& OEMBoard, const XString8& OEMProduct, INT32 frequency, UINTN nLanCards, UINT8 gLanMac[4][6]);
EFI_STATUS _initialize();
public:
SelfOem () : m_ConfName(), m_OemDirExists(false), m_OemDir(NULL), m_OemPathRelToSelfDir(), m_OemFulPath(), m_KextsDir(NULL), m_KextsPathRelToSelfDir(), m_KextsFullPath() {};
SelfOem () {};
SelfOem(const SelfOem&) = delete;
SelfOem& operator = (const SelfOem&) = delete;
@ -42,15 +47,21 @@ public:
const XString8& getConfName() { return m_ConfName; }
bool oemDirExists() { return m_OemDirExists; }
const EFI_FILE& getOemDir() { return *m_OemDir; }
const XStringW& getOemPathRelToSelfDir() { return m_OemPathRelToSelfDir; }
const XStringW& getOemFullPath() { return m_OemFulPath; }
bool oemDirExists() { return m_OemPathRelToSelfDir.notEmpty(); }
const EFI_FILE& getOemDir() { assert(m_OemDir != NULL); return *m_OemDir; }
const XStringW& getOemPathRelToSelfDir() { assert(m_OemPathRelToSelfDir.notEmpty()); return m_OemPathRelToSelfDir; }
const XStringW& getOemFullPath() { assert(m_OemFulPath.notEmpty()); return m_OemFulPath; }
const EFI_FILE& getConfigDir() { if ( m_OemDir != NULL ) return *m_OemDir; return self.getCloverDir(); }
const XStringW& getConfigDirPathRelToSelfDir() { return m_configDirPathRelToSelfDirWithTrailingSlash; }
const XStringW& getConfigDirPathRelToSelfDirWithTrailingSlash() { return m_configDirPathRelToSelfDirWithTrailingSlash; }
const XStringW& getConfigDirFullPath() { if ( m_OemDir != NULL ) return getOemFullPath(); return self.getCloverDirFullPath(); }
bool isKextsDirFound() { return m_KextsDir != NULL; }
const EFI_FILE& getKextsDir() { if ( m_KextsDir == NULL) panic("Kexts dir wasn't found at initialization"); return *m_KextsDir; }
const XStringW& getKextsPathRelToSelfDir() { if ( m_KextsDir == NULL) panic("Kexts dir wasn't found at initialization"); return m_KextsPathRelToSelfDir; }
const XStringW& getKextsFullPath() { if ( m_KextsDir == NULL) panic("Kexts dir wasn't found at initialization"); return m_KextsFullPath; }
const EFI_FILE& getKextsDir() { assert(m_KextsDir != NULL); return *m_KextsDir; }
const XStringW& getKextsDirPathRelToSelfDir() { assert(m_KextsPathRelToSelfDir.notEmpty()); return m_KextsPathRelToSelfDir; }
const XStringW& getKextsFullPath() { assert(m_KextsFullPath.notEmpty()); return m_KextsFullPath; }
};

View File

@ -138,7 +138,7 @@ const LString8 gBuildId __attribute__((used)) = "Clover build id: " BUILD_ID;
const LString8 gBuildId __attribute__((used)) = "Clover build id: " "unknown";
#endif
const char* path_independant __attribute__((used)) = "path_independant";
const char* path_independant = "path_independant";
EMU_VARIABLE_CONTROL_PROTOCOL *gEmuVariableControl = NULL;
@ -518,22 +518,27 @@ LoadUserSettings (
// ConfigPlistPath = SWPrintf("%ls.plist", ConfName.wc_str());
// ConfigOemPath = SWPrintf("%ls\\%ls.plist", selfOem.getOOEMPath.wc_str(), ConfName.wc_str());
Status = EFI_NOT_FOUND;
XStringW configFilename = SWPrintf("%ls.plist", ConfName.wc_str());
if (FileExists (&selfOem.getOemDir(), configFilename)) {
Status = egLoadFile(&selfOem.getOemDir(), configFilename.wc_str(), (UINT8**)&ConfigPtr, &Size);
if ( selfOem.oemDirExists() ) {
if (FileExists (&selfOem.getOemDir(), configFilename)) {
Status = egLoadFile(&selfOem.getOemDir(), configFilename.wc_str(), (UINT8**)&ConfigPtr, &Size);
if (EFI_ERROR(Status)) {
DBG("Cannot find %ls at path (%s): '%ls', trying '%ls'\n", configFilename.wc_str(), efiStrError(Status), selfOem.getOemFullPath().wc_str(), self.getCloverDirFullPath().wc_str());
}else{
DBG("Using %ls at path: %ls\n", configFilename.wc_str(), selfOem.getOemFullPath().wc_str());
}
}
}
if (EFI_ERROR(Status)) {
DBG("Cannot find %ls at path: '%ls', trying '%ls'\n", configFilename.wc_str(), selfOem.getOemFullPath().wc_str(), self.getCloverDirPathAsXStringW().wc_str());
if ( FileExists(&self.getCloverDir(), configFilename.wc_str())) {
Status = egLoadFile(&self.getCloverDir(), configFilename.wc_str(), (UINT8**)&ConfigPtr, &Size);
}
if (!EFI_ERROR(Status)) {
DBG("Using %ls at path: %ls\n", configFilename.wc_str(), self.getCloverDirPathAsXStringW().wc_str());
if (EFI_ERROR(Status)) {
DBG("Cannot find %ls at path '%ls' : %s\n", configFilename.wc_str(), self.getCloverDirFullPath().wc_str(), efiStrError(Status));
} else {
DBG("Cannot find %ls at path: '%ls'\n", configFilename.wc_str(), self.getCloverDirPathAsXStringW().wc_str());
DBG("Using %ls at path: %ls\n", configFilename.wc_str(), self.getCloverDirFullPath().wc_str());
}
}else{
DBG("Using %ls at path: %ls\n", configFilename.wc_str(), selfOem.getOemFullPath().wc_str());
}
if (!EFI_ERROR(Status) && ConfigPtr != NULL) {
@ -2297,6 +2302,9 @@ GetEarlyUserSettings (
}
}
Prop = BootDict->propertyForKey("EmptyDebugLogAtStart");
GlobalConfig.ScratchDebugLogAtStart = IsPropertyNotNullAndTrue(Prop);
Prop = BootDict->propertyForKey("Fast");
GlobalConfig.FastBoot = IsPropertyNotNullAndTrue(Prop);
@ -3125,7 +3133,7 @@ GetListOfConfigs ()
ConfigsNum = 0;
OldChosenConfig = 0;
DirIterOpen(&selfOem.getOemDir(), NULL, &DirIter);
DirIterOpen(&selfOem.getConfigDir(), NULL, &DirIter);
DbgHeader("Found config plists");
while (DirIterNext(&DirIter, 2, L"config*.plist", &DirEntry)) {
if (DirEntry->FileName[0] == L'.') {
@ -3159,7 +3167,7 @@ GetListOfDsdts()
DsdtsNum = 0;
OldChosenDsdt = 0xFFFF;
DirIterOpen(&selfOem.getOemDir(), L"ACPI\\patched", &DirIter);
DirIterOpen(&selfOem.getConfigDir(), L"ACPI\\patched", &DirIter);
DbgHeader("Found DSDT tables");
while (DirIterNext(&DirIter, 2, L"DSDT*.aml", &DirEntry)) {
if (DirEntry->FileName[0] == L'.') {
@ -3196,7 +3204,7 @@ GetListOfACPI()
}
ACPIPatchedAML = NULL;
// DBG("free acpi list done\n");
DirIterOpen(&selfOem.getOemDir(), L"ACPI\\patched", &DirIter);
DirIterOpen(&selfOem.getConfigDir(), L"ACPI\\patched", &DirIter);
while (DirIterNext(&DirIter, 2, L"*.aml", &DirEntry)) {
// DBG("next entry is %ls\n", DirEntry->FileName);
@ -3276,9 +3284,13 @@ void GetListOfInjectKext(CHAR16 *KextDirNameUnderOEMPath)
XStringW PlugInsPath;
XStringW PlugInsName;
BOOLEAN Blocked = FALSE;
if( !selfOem.isKextsDirFound() ) return;
if (StrCmp(KextDirNameUnderOEMPath, L"Off") == 0) {
Blocked = TRUE;
}
DirIterOpen(&selfOem.getKextsDir(), KextDirNameUnderOEMPath, &DirIter);
while (DirIterNext(&DirIter, 1, L"*.kext", &DirEntry)) {
if (DirEntry->FileName[0] == L'.' || StrStr(DirEntry->FileName, L".kext") == NULL) {
@ -3289,7 +3301,7 @@ void GetListOfInjectKext(CHAR16 *KextDirNameUnderOEMPath)
<string>8.8.8</string>
*/
// FullName = SWPrintf("%ls\\%ls", FullPath.wc_str(), DirEntry->FileName);
XStringW pathRelToSelfDir = SWPrintf("%ls\\%ls\\%ls", selfOem.getKextsPathRelToSelfDir().wc_str(), KextDirNameUnderOEMPath, DirEntry->FileName);
XStringW pathRelToSelfDir = SWPrintf("%ls\\%ls\\%ls", selfOem.getKextsDirPathRelToSelfDir().wc_str(), KextDirNameUnderOEMPath, DirEntry->FileName);
mKext = new SIDELOAD_KEXT;
mKext->FileName.SWPrintf("%ls", DirEntry->FileName);
mKext->MenuItem.BValue = Blocked;
@ -7977,7 +7989,7 @@ SetDevices (LOADER_ENTRY *Entry)
mPropSize = hex2bin (gDeviceProperties, mProperties, mPropSize);
// DBG("Final size of mProperties=%d\n", mPropSize);
//---------
// Status = egSaveFile(&self.getSelfRootDir(), SWPrintf("%ls\\misc\\devprop.bin", self.getCloverDirPathAsXStringW().wc_str()).wc_str() , (UINT8*)mProperties, mPropSize);
// Status = egSaveFile(&self.getSelfRootDir(), SWPrintf("%ls\\misc\\devprop.bin", self.getCloverDirFullPath().wc_str()).wc_str() , (UINT8*)mProperties, mPropSize);
//and now we can free memory?
if (gSettings.AddProperties) {
FreePool(gSettings.AddProperties);
@ -8108,15 +8120,16 @@ XStringW GetOtherKextsDir (BOOLEAN On)
return NullXStringW;
}
//dmazar
XStringW
GetOSVersionKextsDir (
const XString8& OSVersion
)
// Jief 2020-10: this is only called by SetFSInjection(). SetFSInjection() doesn't check for return value emptiness.
XStringW GetOSVersionKextsDir(const XString8& OSVersion)
{
XString8 FixedVersion;
CHAR8 *DotPtr;
if ( !selfOem.isKextsDirFound() ) return NullXStringW;
if (OSVersion.notEmpty()) {
FixedVersion.strncpy(OSVersion.c_str(), 5);
// DBG("%s\n", FixedVersion);
@ -8135,14 +8148,10 @@ GetOSVersionKextsDir (
// find source injection folder with kexts
// note: we are just checking for existance of particular folder, not checking if it is empty or not
// check OEM subfolders: version specific or default to Other
XStringW SrcDir = SWPrintf("%ls\\kexts\\%s", selfOem.getOemFullPath().wc_str(), FixedVersion.c_str());
if (!FileExists (&self.getSelfVolumeRootDir(), SrcDir)) {
SrcDir = SWPrintf("\\%ls\\kexts\\%s", self.getCloverDirPathAsXStringW().wc_str(), FixedVersion.c_str());
if (!FileExists (SelfVolume->RootDir, SrcDir)) {
SrcDir.setEmpty();
}
}
return SrcDir;
// Jief : NOTE selfOem.getKextsFullPath() return a path under OEM if exists, or in Clover if not.
XStringW SrcDir = SWPrintf("%ls\\%s", selfOem.getKextsFullPath().wc_str(), FixedVersion.c_str());
if (FileExists (&self.getSelfVolumeRootDir(), SrcDir)) return SrcDir;
return NullXStringW;
}
EFI_STATUS
@ -8160,7 +8169,7 @@ InjectKextsFromDir (
return Status;
}
EFI_STATUS LOADER_ENTRY::SetFSInjection ()
EFI_STATUS LOADER_ENTRY::SetFSInjection()
{
EFI_STATUS Status;
FSINJECTION_PROTOCOL *FSInject;

View File

@ -16,6 +16,8 @@
// INPUT_ITEM MenuItem;
//};
extern const char* path_independant;
class HDA_OUTPUTS
{
public:

View File

@ -1637,11 +1637,13 @@ BOOLEAN load_vbios_file(UINT16 vendor_id, UINT16 device_id)
UINT8* buffer = 0;
XStringW FileName = SWPrintf("ROM\\%04hX_%04hX.rom", vendor_id, device_id);
if (FileExists(&selfOem.getOemDir(), FileName)) {
DBG("Found generic VBIOS ROM file (%04hX_%04hX.rom)\n", vendor_id, device_id);
Status = egLoadFile(&selfOem.getOemDir(), FileName.wc_str(), &buffer, &bufferLen);
if ( selfOem.oemDirExists() ) {
if (FileExists(&selfOem.getOemDir(), FileName)) {
DBG("Found oem generic VBIOS ROM file (%04hX_%04hX.rom)\n", vendor_id, device_id);
Status = egLoadFile(&selfOem.getOemDir(), FileName.wc_str(), &buffer, &bufferLen);
}
}
if (EFI_ERROR(Status)) {
if ( Status == EFI_NOT_FOUND ) {
if (FileExists(&self.getCloverDir(), FileName)){
DBG("Found generic VBIOS ROM file (%04hX_%04hX.rom)\n", vendor_id, device_id);
Status = egLoadFile(&self.getCloverDir(), FileName.wc_str(), &buffer, &bufferLen);

View File

@ -10,6 +10,7 @@ extern "C" {
#include "../Platform/plist/plist.h"
#include "../Platform/Settings.h"
#include "../Platform/guid.h"
#include "../Platform/SelfOem.h"
#include "MemoryOperation.h"
#ifndef DEBUG_ALL
@ -455,6 +456,9 @@ void LOADER_ENTRY::AddKextsInArray(XObjArray<SIDELOAD_KEXT>* kextArray)
XString8 PlugIns;
// CONST CHAR16 *Arch = NULL;
// CONST CHAR16 *Ptr = NULL;
if ( !selfOem.isKextsDirFound() ) return;
#if defined(MDE_CPU_X64)
cpu_type_t archCpuType=CPU_TYPE_X86_64;
#else

View File

@ -2262,19 +2262,22 @@ BOOLEAN setup_nvidia_devprop(pci_dt_t *nvda_dev)
if (load_vbios) {
XStringW FileName = SWPrintf("ROM\\10de_%04hX_%04hX_%04hX.rom", nvda_dev->device_id, nvda_dev->subsys_id.subsys.vendor_id, nvda_dev->subsys_id.subsys.device_id);
if (FileExists(&selfOem.getOemDir(), FileName)) {
DBG("Found specific VBIOS ROM file (10de_%04hX_%04hX_%04hX.rom)\n", nvda_dev->device_id, nvda_dev->subsys_id.subsys.vendor_id, nvda_dev->subsys_id.subsys.device_id);
Status = egLoadFile(&selfOem.getOemDir(), FileName.wc_str(), &buffer, &bufferLen);
} else {
FileName.SWPrintf("ROM\\10de_%04hX.rom", nvda_dev->device_id);
Status = EFI_NOT_FOUND;
if ( selfOem.oemDirExists() ) {
if (FileExists(&selfOem.getOemDir(), FileName)) {
DBG("Found generic VBIOS ROM file (10de_%04hX.rom)\n", nvda_dev->device_id);
DBG("Found specific VBIOS ROM file (10de_%04hX_%04hX_%04hX.rom)\n", nvda_dev->device_id, nvda_dev->subsys_id.subsys.vendor_id, nvda_dev->subsys_id.subsys.device_id);
Status = egLoadFile(&selfOem.getOemDir(), FileName.wc_str(), &buffer, &bufferLen);
} else {
FileName.SWPrintf("ROM\\10de_%04hX.rom", nvda_dev->device_id);
if (FileExists(&selfOem.getOemDir(), FileName)) {
DBG("Found generic VBIOS ROM file (10de_%04hX.rom)\n", nvda_dev->device_id);
Status = egLoadFile(&selfOem.getOemDir(), FileName.wc_str(), &buffer, &bufferLen);
}
}
}
FileName.SWPrintf("ROM\\10de_%04hX_%04hX_%04hX.rom", nvda_dev->device_id, nvda_dev->subsys_id.subsys.vendor_id, nvda_dev->subsys_id.subsys.device_id);
if (EFI_ERROR(Status)) {
if ( Status == EFI_NOT_FOUND ) {
FileName.SWPrintf("ROM\\10de_%04hX_%04hX_%04hX.rom", nvda_dev->device_id, nvda_dev->subsys_id.subsys.vendor_id, nvda_dev->subsys_id.subsys.device_id);
if (FileExists(&self.getCloverDir(), FileName)) {
DBG("Found specific VBIOS ROM file (10de_%04hX_%04hX_%04hX.rom)\n", nvda_dev->device_id, nvda_dev->subsys_id.subsys.vendor_id, nvda_dev->subsys_id.subsys.device_id);
Status = egLoadFile(&self.getCloverDir(), FileName.wc_str(), &buffer, &bufferLen);

View File

@ -2202,7 +2202,7 @@ void FinalizeSmbios() //continue
//PauseForKey(L"installing SMBIOS in Hob\n");
*Table = (UINT32)(UINTN)SmbiosEpsNew;
}
// egSaveFile(NULL, SWPrintf("%ls\\misc\\smbios.bin", self.getCloverDirPathAsXStringW().wc_str()).wc_str(), (UINT8*)(UINTN)SmbiosEpsNew, SmbiosEpsNew->TableLength);
// egSaveFile(NULL, SWPrintf("%ls\\misc\\smbios.bin", self.getCloverDirFullPath().wc_str()).wc_str(), (UINT8*)(UINTN)SmbiosEpsNew, SmbiosEpsNew->TableLength);
return;
}

View File

@ -0,0 +1,9 @@
/*
* sharedptr.cpp
*
* Created on: Oct 17, 2020
* Author: jief
*/
#include "shared_ptr.h"

View File

@ -0,0 +1,193 @@
/*
* sharedptr.h
*
* Created on: Oct 17, 2020
* Author: jief
* From https://www.geeksforgeeks.org/how-to-implement-user-defined-shared-pointers-in-c/
*/
#ifndef CPP_FOUNDATION_SHARED_PTR_H_
#define CPP_FOUNDATION_SHARED_PTR_H_
// Class representing a reference counter class
class Counter {
public:
// Constructor
Counter()
: m_counter(0){};
Counter(const Counter&) = delete;
Counter& operator=(const Counter&) = delete;
// Destructor
~Counter()
{
}
void reset()
{
m_counter = 0;
}
unsigned int get()
{
return m_counter;
}
// Overload post/pre increment
void operator++()
{
m_counter++;
}
void operator++(int)
{
m_counter++;
}
// Overload post/pre decrement
void operator--()
{
m_counter--;
}
void operator--(int)
{
m_counter--;
}
private:
unsigned int m_counter{};
};
// Class representing a shared pointer
template <typename T>
class Shared_ptr {
public:
// Constructor
explicit Shared_ptr(T* ptr = nullptr)
{
m_ptr = ptr;
m_counter = new Counter();
if (ptr) {
(*m_counter)++;
}
}
// Copy constructor
Shared_ptr(Shared_ptr<T>& sp)
{
m_ptr = sp.m_ptr;
m_counter = sp.m_counter;
(*m_counter)++;
}
// Reference count
unsigned int use_count()
{
return m_counter->get();
}
// Get the pointer
T* get()
{
return m_ptr;
}
// Overload * operator
T& operator*() {
return *m_ptr;
}
// Overload -> operator
T* operator->() {
return m_ptr;
}
// Destructor
~Shared_ptr()
{
(*m_counter)--;
if (m_counter->get() == 0) {
delete m_counter;
delete m_ptr;
}
}
//// shared_ptr comparisons:
//template<class T, class U>
// bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
//template<class T, class U>
// bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
//template <class T>
// bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
//template <class T>
// bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
//template <class T>
// bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
//template <class T>
// bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
// shared_ptr bool cast ?
//see /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory
private:
// Reference counter
Counter* m_counter;
// Shared pointer
T* m_ptr;
};
//int main()
//{
// // ptr1 pointing to an integer.
// Shared_ptr<int> ptr1(new int(151));
// cout << "--- Shared pointers ptr1 ---\n";
// *ptr1 = 100;
// cout << " ptr1's value now: " << *ptr1 << endl;
// cout << ptr1;
//
// {
// // ptr2 pointing to same integer
// // which ptr1 is pointing to
// // Shared pointer reference counter
// // should have increased now to 2.
// Shared_ptr<int> ptr2 = ptr1;
// cout << "--- Shared pointers ptr1, ptr2 ---\n";
// cout << ptr1;
// cout << ptr2;
//
// {
// // ptr3 pointing to same integer
// // which ptr1 and ptr2 are pointing to.
// // Shared pointer reference counter
// // should have increased now to 3.
// Shared_ptr<int> ptr3(ptr2);
// cout << "--- Shared pointers ptr1, ptr2, ptr3 ---\n";
// cout << ptr1;
// cout << ptr2;
// cout << ptr3;
// }
//
// // ptr3 is out of scope.
// // It would have been destructed.
// // So shared pointer reference counter
// // should have decreased now to 2.
// cout << "--- Shared pointers ptr1, ptr2 ---\n";
// cout << ptr1;
// cout << ptr2;
// }
//
// // ptr2 is out of scope.
// // It would have been destructed.
// // So shared pointer reference counter
// // should have decreased now to 1.
// cout << "--- Shared pointers ptr1 ---\n";
// cout << ptr1;
//
// return 0;
//}
#endif /* CPP_FOUNDATION_SHARED_PTR_H_ */

View File

@ -196,8 +196,8 @@ void ScanTool(void)
// DBG("Scanning for tools...\n");
if (!(ThemeX.HideUIFlags & HIDEUI_FLAG_SHELL)) {
if (!AddToolEntry(SWPrintf("%ls\\tools\\Shell64U.efi", self.getCloverDirPathAsXStringW().wc_str()), NULL, L"UEFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXString8Array)) {
AddToolEntry(SWPrintf("%ls\\tools\\Shell64.efi", self.getCloverDirPathAsXStringW().wc_str()), NULL, L"EFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXString8Array);
if (!AddToolEntry(SWPrintf("%ls\\tools\\Shell64U.efi", self.getCloverDirFullPath().wc_str()), NULL, L"UEFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXString8Array)) {
AddToolEntry(SWPrintf("%ls\\tools\\Shell64.efi", self.getCloverDirFullPath().wc_str()), NULL, L"EFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXString8Array);
}
}
@ -222,7 +222,7 @@ void ScanTool(void)
if (FileExists(&self.getCloverDir(), CLOVER_MEDIA_FILE_NAME)) {
DBG(" Found Clover\n");
// Volume->BootType = BOOTING_BY_EFI;
AddCloverEntry(SWPrintf("%ls\\%ls", self.getCloverDirPathAsXStringW().wc_str(), CLOVER_MEDIA_FILE_NAME.wc_str()), L"Clover Boot Options", Volume);
AddCloverEntry(SWPrintf("%ls\\%ls", self.getCloverDirFullPath().wc_str(), CLOVER_MEDIA_FILE_NAME.wc_str()), L"Clover Boot Options", Volume);
break;
}
}

View File

@ -965,7 +965,7 @@ UINTN REFIT_MENU_SCREEN::RunGenericMenu(IN MENU_STYLE_FUNC StyleFunc, IN OUT INT
case SCAN_F2:
SavePreBootLog = TRUE;
//let it be twice
Status = SaveBooterLog(&self.getCloverDir(), PREBOOT_LOG_new);
Status = SaveBooterLog(&self.getCloverDir(), PREBOOT_LOG);
// Jief : don't write outside SelfDir
// if (EFI_ERROR(Status)) {
// Status = SaveBooterLog(NULL, PREBOOT_LOG);
@ -1959,10 +1959,10 @@ void REFIT_MENU_SCREEN::DrawTextCorner(UINTN TextC, UINT8 Align)
case TEXT_CORNER_REVISION:
// Display Clover boot volume
if (SelfVolume->VolLabel.notEmpty() && SelfVolume->VolLabel[0] != L'#') {
Text = SWPrintf("%ls, booted from %ls %ls", gFirmwareRevision, SelfVolume->VolLabel.wc_str(), self.getCloverDirPathAsXStringW().wc_str());
Text = SWPrintf("%ls, booted from %ls %ls", gFirmwareRevision, SelfVolume->VolLabel.wc_str(), self.getCloverDirFullPath().wc_str());
}
if (Text.isEmpty()) {
Text = SWPrintf("%ls %ls %ls", gFirmwareRevision, SelfVolume->VolName.wc_str(), self.getCloverDirPathAsXStringW().wc_str());
Text = SWPrintf("%ls %ls %ls", gFirmwareRevision, SelfVolume->VolName.wc_str(), self.getCloverDirFullPath().wc_str());
}
break;
case TEXT_CORNER_HELP:

View File

@ -163,7 +163,7 @@ EFI_STATUS GetRootFromPath(IN EFI_DEVICE_PATH_PROTOCOL* DevicePath, OUT EFI_FILE
EFI_STATUS InitRefitLib(IN EFI_HANDLE ImageHandle)
{
self.initialize(ImageHandle);
// DBG("SelfDirPath = %ls\n", self.getCloverDirPathAsXStringW().wc_str());
// DBG("SelfDirPath = %ls\n", self.getCloverDirFullPath().wc_str());
return EFI_SUCCESS;
}
@ -173,9 +173,10 @@ void UninitRefitLib(void)
ThemeX.closeThemeDir();
self.closeHandle();
selfOem.closeHandle();
self.closeHandle();
closeDebugLog();
UninitVolumes();
}
@ -1215,11 +1216,16 @@ BOOLEAN FileExists(IN CONST EFI_FILE *Root, IN CONST CHAR16 *RelativePath)
return FALSE;
}
BOOLEAN FileExists(IN CONST EFI_FILE *Root, IN CONST XStringW& RelativePath)
BOOLEAN FileExists(const EFI_FILE *Root, const XStringW& RelativePath)
{
return FileExists(Root, RelativePath.wc_str());
}
BOOLEAN FileExists(const EFI_FILE& Root, const XStringW& RelativePath)
{
return FileExists(&Root, RelativePath.wc_str());
}
BOOLEAN DeleteFile(const EFI_FILE *Root, IN CONST CHAR16 *RelativePath)
{
EFI_STATUS Status;

View File

@ -329,8 +329,9 @@ void ScanVolumes(void);
REFIT_VOLUME *FindVolumeByName(IN CONST CHAR16 *VolName);
BOOLEAN FileExists(IN CONST EFI_FILE *BaseDir, IN CONST CHAR16 *RelativePath);
BOOLEAN FileExists(IN CONST EFI_FILE *BaseDir, IN CONST XStringW& RelativePath);
BOOLEAN FileExists(const EFI_FILE *BaseDir, const CHAR16 *RelativePath);
BOOLEAN FileExists(const EFI_FILE *BaseDir, const XStringW& RelativePath);
BOOLEAN FileExists(const EFI_FILE& Root, const XStringW& RelativePath);
inline EFI_DEVICE_PATH_PROTOCOL* FileDevicePath (IN EFI_HANDLE Device, IN CONST XStringW& FileName) { return FileDevicePath(Device, FileName.wc_str()); }

View File

@ -716,7 +716,7 @@ MsgLog("debugStartImageWithOC\n");
EFI_LOADED_IMAGE* OcLoadedImage;
EFI_STATUS Status = gBS->HandleProtocol(gImageHandle, &gEfiLoadedImageProtocolGuid, (void **) &OcLoadedImage);
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* FileSystem = LocateFileSystem(OcLoadedImage->DeviceHandle, OcLoadedImage->FilePath);
Status = OcStorageInitFromFs(&mOpenCoreStorage, FileSystem, self.getCloverDirPathAsXStringW().wc_str(), NULL);
Status = OcStorageInitFromFs(&mOpenCoreStorage, FileSystem, self.getCloverDirFullPath().wc_str(), NULL);
Status = ClOcReadConfigurationFile(&mOpenCoreStorage, L"config-oc.plist", &mOpenCoreConfiguration);
if ( EFI_ERROR(Status) ) panic("ClOcReadConfigurationFile");
@ -1108,7 +1108,8 @@ DBG("Beginning OC\n");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->MinKernel, "");
OC_STRING_ASSIGN(mOpenCoreConfiguration.Kernel.Add.Values[kextIdx]->Identifier, "");
XStringW dirPath = SWPrintf("%ls\\%ls", selfOem.getKextsPathRelToSelfDir().wc_str(), KextEntry.KextDirNameUnderOEMPath.wc_str());
assert( selfOem.isKextsDirFound() ); // be sure before calling getKextsPathRelToSelfDir()
XStringW dirPath = SWPrintf("%ls\\%ls", selfOem.getKextsDirPathRelToSelfDir().wc_str(), KextEntry.KextDirNameUnderOEMPath.wc_str());
// XString8 bundlePath = S8Printf("%ls\\%ls\\%ls", selfOem.getKextsPathRelToSelfDir().wc_str(), KextEntry.KextDirNameUnderOEMPath.wc_str(), KextEntry.FileName.wc_str());
XString8 bundlePath = S8Printf("%ls\\%ls", dirPath.wc_str(), KextEntry.FileName.wc_str());
if ( FileExists(&self.getCloverDir(), bundlePath) ) {
@ -1202,9 +1203,9 @@ DBG("Beginning OC\n");
EFI_LOADED_IMAGE* OcLoadedImage;
Status = gBS->HandleProtocol(gImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &OcLoadedImage);
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* FileSystem = LocateFileSystem(OcLoadedImage->DeviceHandle, OcLoadedImage->FilePath);
Status = OcStorageInitFromFs(&mOpenCoreStorage, FileSystem, self.getCloverDirPathAsXStringW().wc_str(), NULL);
Status = OcStorageInitFromFs(&mOpenCoreStorage, FileSystem, self.getCloverDirFullPath().wc_str(), NULL);
XStringW FileName = SWPrintf("%ls\\%ls\\%s", self.getCloverDirPathAsXStringW().wc_str(), getDriversPath().wc_str(), "OpenRuntime.efi");
XStringW FileName = SWPrintf("%ls\\%ls\\%s", self.getCloverDirFullPath().wc_str(), getDriversPath().wc_str(), "OpenRuntime.efi");
EFI_HANDLE DriverHandle;
Status = gBS->LoadImage(false, gImageHandle, FileDevicePath(self.getSelfLoadedImage().DeviceHandle, FileName), NULL, 0, &DriverHandle);
DBG("Load OpenRuntime.efi : Status %s\n", efiStrError(Status));
@ -1580,7 +1581,7 @@ DBG("Beginning OC\n");
DBG("Closing log\n");
if (SavePreBootLog) {
Status = SaveBooterLog(&self.getCloverDir(), PREBOOT_LOG_new);
Status = SaveBooterLog(&self.getCloverDir(), PREBOOT_LOG);
// Jief : do not write outside of SelfDir
// if (EFI_ERROR(Status)) {
// /*Status = */SaveBooterLog(NULL, PREBOOT_LOG);
@ -1775,7 +1776,7 @@ static void ScanDriverDir(IN CONST CHAR16 *Path, OUT EFI_HANDLE **DriversToConne
}
#undef BOOLEAN_AT_INDEX
XStringW FileName = SWPrintf("%ls\\%ls\\%ls", self.getCloverDirPathAsXStringW().wc_str(), Path, DirEntry->FileName);
XStringW FileName = SWPrintf("%ls\\%ls\\%ls", self.getCloverDirFullPath().wc_str(), Path, DirEntry->FileName);
Status = StartEFIImage(FileDevicePath(self.getSelfLoadedImage().DeviceHandle, FileName), NullXString8Array, DirEntry->FileName, XStringW().takeValueFrom(DirEntry->FileName), NULL, &DriverHandle);
if (EFI_ERROR(Status)) {
continue;
@ -2143,6 +2144,7 @@ static void LoadDrivers(void)
DriversToConnectNum++;
}
UninitRefitLib();
if (DriversToConnectNum > 0) {
DBG("%llu drivers needs connecting ...\n", DriversToConnectNum);
// note: our platform driver protocol
@ -2170,6 +2172,7 @@ static void LoadDrivers(void)
}else{
BdsLibConnectAllEfi(); // jief : without any driver loaded, i couldn't see my CD, unless I call BdsLibConnectAllEfi
}
ReinitRefitLib();
}
@ -2548,7 +2551,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
} else {
selfOem.initialize(ConfName, gFirmwareClover, gSettings.OEMBoard, gSettings.OEMProduct, (INT32)(DivU64x32(gCPUStructure.CPUFrequency, Mega)), nLanCards, gLanMac);
Status = LoadUserSettings(ConfName, &gConfigDict[1]);
DBG("%ls\\%ls.plist %ls loaded with name from LoadOptions: %s\n", selfOem.getOemFullPath().wc_str(), ConfName.wc_str(), EFI_ERROR(Status) ? L" not" : L"", efiStrError(Status));
DBG("%ls\\%ls.plist %ls loaded with name from LoadOptions: %s\n", selfOem.getConfigDirFullPath().wc_str(), ConfName.wc_str(), EFI_ERROR(Status) ? L" not" : L"", efiStrError(Status));
if (EFI_ERROR(Status)) {
gConfigDict[1] = NULL;
}
@ -2565,7 +2568,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
if (!gConfigDict[1] || UniteConfigs) {
selfOem.initialize("config"_XS8, gFirmwareClover, gSettings.OEMBoard, gSettings.OEMProduct, (INT32)(DivU64x32(gCPUStructure.CPUFrequency, Mega)), nLanCards, gLanMac);
Status = LoadUserSettings(L"config"_XSW, &gConfigDict[0]);
DBG("%ls\\config.plist %ls loaded: %s\n", selfOem.getOemFullPath().wc_str(), EFI_ERROR(Status) ? L" not" : L"", efiStrError(Status));
DBG("%ls\\config.plist %ls loaded: %s\n", selfOem.getConfigDirFullPath().wc_str(), EFI_ERROR(Status) ? L" not" : L"", efiStrError(Status));
}
snwprintf(gSettings.ConfigName, 64, "%ls%ls%ls",
gConfigDict[0] ? L"config": L"",

View File

@ -1094,7 +1094,7 @@ void AboutRefit(void)
// AboutMenu.TitleImage.setEmpty(); //done in the constructor
// }
// AboutMenu.AddMenuInfo_f(("Clover Version 5.0"));
if ( "unknown"_XS8 != LString8(gRevisionStr) ) AboutMenu.AddMenuInfo_f("%s", gRevisionStr);
if ( "unknown"_XS8 != LString8(gRevisionStr) ) AboutMenu.AddMenuInfo_f("%s%s", gRevisionStr, path_independant!=NULL ? "" : ""); // trick to let the compiler think path_independant is used and must be kept in binary.
if ( "unknown"_XS8 != LString8(gFirmwareBuildDate) ) AboutMenu.AddMenuInfo_f(" Build: %s", gFirmwareBuildDate);
if ( "unknown"_XS8 != gBuildId ) AboutMenu.AddMenuInfo_f(" Build id: %s", gBuildId.c_str());
AboutMenu.AddMenuInfo_f(" ");