debug.log name contains efi file name and timestamp.

This commit is contained in:
jief666 2020-11-24 15:41:47 +03:00
parent 569a2fbe94
commit 2f90c9702a
5 changed files with 100 additions and 93 deletions

View File

@ -73,6 +73,7 @@ PrintBytes(IN void *Bytes, IN UINTN Number)
}
}
static XStringW debugLogFileName;
static EFI_FILE_PROTOCOL* gLogFile = NULL;
// Do not keep a pointer to MemLogBuffer. Because a reallocation, it could become invalid.
@ -133,31 +134,66 @@ static UINTN GetDebugLogFile()
if ( !self.isInitialized() ) return 0;
// Open log file from current root
Status = self.getCloverDir().Open(&self.getCloverDir(), &LogFile, DEBUG_LOG, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
EFI_TIME Now;
Status = gRT->GetTime(&Now, NULL);
if ( EFI_ERROR(Status) ) {
DBG("GetTime return %s\n", efiStrError(Status));
}
if ( !EFI_ERROR (Status) && GlobalConfig.ScratchDebugLogAtStart )
if ( debugLogFileName.isEmpty() )
{
// Here, we may not be at the first line sent to log.
// That's because the setting GlobalConfig.ScratchDebugLogAtStart is not set before the first log is sent.
DGB_nbCallback("GetDebugLogFile() -> deleting the log '%ls'\n", DEBUG_LOG);
EFI_STATUS StatusDelete;
StatusDelete = LogFile->Delete(LogFile);
if ( StatusDelete == EFI_SUCCESS) {
GlobalConfig.ScratchDebugLogAtStart = false;
Status = EFI_NOT_FOUND; // to make be reopened in the next lines.
}else{
DGB_nbCallback("Cannot delete log file '%ls\\%ls' : %s\n", self.getCloverDirFullPath().wc_str(), DEBUG_LOG, efiStrError(StatusDelete));
debugLogFileName = S8Printf("misc\\%d-%d-%d_%d-%d-%d_%ls.log", Now.Year, Now.Month, Now.Day, Now.Hour, Now.Minute, Now.Second, self.getCloverEfiFileName().wc_str());
Status = self.getCloverDir().Open(&self.getCloverDir(), &LogFile, debugLogFileName.wc_str(), EFI_FILE_MODE_READ, 0);
if ( !EFI_ERROR(Status) ) LogFile->Close(LogFile); // DO NOT modify Status here.
INTN i=1;
while ( Status != EFI_NOT_FOUND && (i < MAX_INTN) ) {
debugLogFileName = S8Printf("misc\\%d-%d-%d_%d-%d-%d_%ls(%lld).log", Now.Year, Now.Month, Now.Day, Now.Hour, Now.Minute, Now.Second, self.getCloverEfiFileName().wc_str(), i);
Status = self.getCloverDir().Open(&self.getCloverDir(), &LogFile, debugLogFileName.wc_str(), EFI_FILE_MODE_READ, 0);
if ( !EFI_ERROR(Status) ) LogFile->Close(LogFile); // DO NOT modify Status here.
}
if ( Status != EFI_NOT_FOUND ) {
DBG("Cannot find a free debug log file name\n"); // I can't imagine that to happen...
debugLogFileName.setEmpty(); // To allow to retry at the next call
return 0;
}
Status = self.getCloverDir().Open(&self.getCloverDir(), &LogFile, debugLogFileName.wc_str(), EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
gLogFile = LogFile;
return 0;
}else{
// DGB_nbCallback(" GetDebugLogFile() -> open log : %s\n", efiStrError(Status));
Status = self.getCloverDir().Open(&self.getCloverDir(), &LogFile, debugLogFileName.wc_str(), EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
//// Jief : Instead of EfiLibFileInfo, let's use SetPosition to get the size.
// if (!EFI_ERROR(Status)) {
// 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 (!EFI_ERROR(Status)) {
Status = LogFile->SetPosition(LogFile, 0xFFFFFFFFFFFFFFFFULL);
if ( EFI_ERROR (Status) ) {
DGB_nbCallback("GetDebugLogFile() -> Cannot set log position to 0xFFFFFFFFFFFFFFFFULL : %s\n", efiStrError(Status));
LogFile->Close(LogFile);
}else{
UINTN size;
Status = LogFile->GetPosition(LogFile, &size);
if ( EFI_ERROR (Status) ) {
DGB_nbCallback("GetDebugLogFile() -> Cannot get log position : %s\n", efiStrError(Status));
LogFile->Close(LogFile);
}else{
//DGB_nbCallback("GetDebugLogFile() -> opened. log position = %lld (lwo %lld)\n", size, lastWrittenOffset);
gLogFile = LogFile;
return size;
}
}
}
return 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);
Status = self.getCloverDir().Open(&self.getCloverDir(), &LogFile, DEBUG_LOG, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
}
// Jief : do we need that ?
// if (EFI_ERROR(Status)) {
@ -175,38 +211,6 @@ static UINTN GetDebugLogFile()
// RootDir = NULL;
// }
// }
// Jief : Instead of EfiLibFileInfo, let's use SetPosition to get the size.
// if (!EFI_ERROR(Status)) {
// 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 (!EFI_ERROR(Status)) {
EFI_FILE_INFO *Info = EfiLibFileInfo(LogFile);
Status = LogFile->SetPosition(LogFile, Info->FileSize); //0xFFFFFFFFFFFFFFFFULL);
if ( EFI_ERROR (Status) ) {
DGB_nbCallback("GetDebugLogFile() -> Cannot set log position to 0xFFFFFFFFFFFFFFFFULL : %s\n", efiStrError(Status));
LogFile->Close(LogFile);
}else{
UINTN size;
Status = LogFile->GetPosition(LogFile, &size);
if ( EFI_ERROR (Status) ) {
DGB_nbCallback("GetDebugLogFile() -> Cannot get log position : %s\n", efiStrError(Status));
LogFile->Close(LogFile);
}else{
//DGB_nbCallback("GetDebugLogFile() -> opened. log position = %lld (lwo %lld)\n", size, lastWrittenOffset);
gLogFile = LogFile;
return size;
}
}
}
return 0;
}
VOID SaveMessageToDebugLogFile(IN CHAR8 *LastMessage)
@ -241,7 +245,7 @@ VOID SaveMessageToDebugLogFile(IN CHAR8 *LastMessage)
// }
}
}
// Not all Firmware implements Flush. So we have to close everytime to force flush.
// Not all Firmware implements Flush. So we have to close every time to force flush.
closeDebugLog();
}

View File

@ -29,9 +29,9 @@ constexpr const LStringW THEMES_DIRNAME(L"Themes");
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);
Status = m_CloverDir->Open(m_CloverDir, 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));
DBG("Error when opening dir '%ls\\%ls' : %s\n", m_CloverDirFullPath.wc_str(), path.wc_str(), efiStrError(Status));
*efiDir = NULL;
*b = false;
}else{
@ -44,27 +44,27 @@ EFI_STATUS Self::_initialize()
{
EFI_STATUS Status;
Status = gBS->HandleProtocol(self.getSelfImageHandle(), &gEfiLoadedImageProtocolGuid, (void **)&m_SelfLoadedImage);
Status = gBS->HandleProtocol(m_SelfImageHandle, &gEfiLoadedImageProtocolGuid, (void **)&m_SelfLoadedImage);
if ( EFI_ERROR(Status) ) panic("Cannot get SelfLoadedImage");
if ( self.getSelfDeviceHandle() == NULL ) panic("self.getSelfDeviceHandle() == NULL");
if ( m_SelfLoadedImage->DeviceHandle == NULL ) panic("m_SelfLoadedImage->DeviceHandle == NULL");
m_SelfDevicePath = DuplicateDevicePath(DevicePathFromHandle(self.getSelfDeviceHandle()));
m_SelfDevicePath = DuplicateDevicePath(DevicePathFromHandle(m_SelfLoadedImage->DeviceHandle));
if ( m_SelfDevicePath == NULL ) panic("m_SelfDevicePath == NULL");
#ifdef JIEF_DEBUG
DBG("self.getSelfDevicePath()=%ls @%llX\n", FileDevicePathToXStringW(&self.getSelfDevicePath()).wc_str(), (uintptr_t)self.getSelfDeviceHandle());
DBG("Self DevicePath()=%ls @%llX\n", FileDevicePathToXStringW(m_SelfDevicePath).wc_str(), (uintptr_t)m_SelfLoadedImage->DeviceHandle);
#endif
Status = gBS->HandleProtocol(self.getSelfDeviceHandle(), &gEfiSimpleFileSystemProtocolGuid, (void**)&m_SelfSimpleVolume);
Status = gBS->HandleProtocol(m_SelfLoadedImage->DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, (void**)&m_SelfSimpleVolume);
if ( EFI_ERROR(Status) ) panic("Cannot get m_SelfSimpleVolume");
Status = getSelfSimpleVolume().OpenVolume(&getSelfSimpleVolume(), &m_SelfRootDir);
Status = m_SelfSimpleVolume->OpenVolume(m_SelfSimpleVolume, &m_SelfVolumeRootDir);
if ( EFI_ERROR(Status) ) panic("Cannot get m_SelfRootDir");
// find the current directory
m_CloverDirFullPath = FileDevicePathToXStringW(self.getSelfLoadedImage().FilePath);
m_CloverDirFullPath = FileDevicePathToXStringW(m_SelfLoadedImage->FilePath);
// Do this before the next check.
if ( !m_CloverDirFullPath.startWith('\\') ) {
//CHAR16* f = ConvertDevicePathToText(self.getSelfLoadedImage().FilePath, TRUE, TRUE);
//CHAR16* f = ConvertDevicePathToText(m_SelfLoadedImage->FilePath, TRUE, TRUE);
//panic("Bad format for m_CloverDirFullPath(%ls). It must start with a '\\'.\nConvertDevicePathToText=%ls", m_CloverDirFullPath.wc_str(), f);
//
// Somefirmware seems to not put a '\' at the begining. Do not panic anymore, just add it.
@ -77,18 +77,21 @@ EFI_STATUS Self::_initialize()
}
if ( m_CloverDirFullPath.isEmpty() ) panic("m_CloverDirFullPath.isEmpty()");
m_SelfDevicePath = FileDevicePath(self.getSelfDeviceHandle(), m_CloverDirFullPath);
m_SelfDevicePath = FileDevicePath(m_SelfLoadedImage->DeviceHandle, m_CloverDirFullPath);
m_SelfDevicePathAsXStringW = FileDevicePathToXStringW(m_SelfDevicePath);
if ( m_CloverDirFullPath.lastChar() == U'\\' ) panic("m_CloverDirFullPath.lastChar() == U'\\'");
//if ( m_CloverDirFullPath.endsWith('\\') ) panic("m_CloverDirFullPath.endsWith('\\')");
m_efiFileName = m_CloverDirFullPath.basename();
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);
#ifdef JIEF_DEBUG
DBG("SelfDirPath = %ls\n", m_CloverDirFullPath.wc_str());
#endif
Status = self.getSelfVolumeRootDir().Open(&self.getSelfVolumeRootDir(), &m_CloverDir, m_CloverDirFullPath.wc_str(), EFI_FILE_MODE_READ, 0);
Status = m_SelfVolumeRootDir->Open(m_SelfVolumeRootDir, &m_CloverDir, m_CloverDirFullPath.wc_str(), EFI_FILE_MODE_READ, 0);
if ( EFI_ERROR(Status) ) panic("Cannot open getSelfRootDir()");
@ -119,9 +122,9 @@ void Self::closeHandle(void)
m_CloverDir = NULL;
}
if (m_SelfRootDir != NULL) {
m_SelfRootDir->Close(m_SelfRootDir);
m_SelfRootDir = NULL;
if (m_SelfVolumeRootDir != NULL) {
m_SelfVolumeRootDir->Close(m_SelfVolumeRootDir);
m_SelfVolumeRootDir = NULL;
}
}

View File

@ -19,8 +19,9 @@ protected:
XStringW m_SelfDevicePathAsXStringW; // path to device containing this efi.
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *m_SelfSimpleVolume; // Volume containing this efi.
EFI_FILE* m_SelfRootDir; // Root dir of the volume containing this efi.
EFI_FILE* m_SelfVolumeRootDir; // Root dir of the volume containing this efi.
XStringW m_efiFileName = L""_XSW;
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.
@ -37,7 +38,7 @@ protected:
public:
Self () : m_SelfImageHandle(NULL), m_SelfLoadedImage(NULL), m_SelfDevicePath(NULL), m_SelfDevicePathAsXStringW(),
m_SelfSimpleVolume(NULL), m_SelfRootDir(NULL),
m_SelfSimpleVolume(NULL), m_SelfVolumeRootDir(NULL),
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;
@ -49,25 +50,32 @@ public:
void closeHandle();
bool isInitialized() const { return m_CloverDir != NULL; }
void checkInitialized() const
{
if ( !isInitialized() ) {
panic("Self in not initialized");
}
}
EFI_HANDLE getSelfImageHandle() { return m_SelfImageHandle; }
const EFI_LOADED_IMAGE& getSelfLoadedImage() { return *m_SelfLoadedImage; }
EFI_HANDLE getSelfDeviceHandle() { return getSelfLoadedImage().DeviceHandle; }
const EFI_DEVICE_PATH& getSelfDevicePath() { return *m_SelfDevicePath; }
EFI_HANDLE getSelfImageHandle() { checkInitialized(); return m_SelfImageHandle; }
const EFI_LOADED_IMAGE& getSelfLoadedImage() { checkInitialized(); return *m_SelfLoadedImage; }
EFI_HANDLE getSelfDeviceHandle() { checkInitialized(); return getSelfLoadedImage().DeviceHandle; }
const EFI_DEVICE_PATH& getSelfDevicePath() { checkInitialized(); return *m_SelfDevicePath; }
const EFI_SIMPLE_FILE_SYSTEM_PROTOCOL& getSelfSimpleVolume() { return *m_SelfSimpleVolume; }
const EFI_FILE& getSelfVolumeRootDir() { return *m_SelfRootDir; }
const EFI_SIMPLE_FILE_SYSTEM_PROTOCOL& getSelfSimpleVolume() { checkInitialized(); return *m_SelfSimpleVolume; }
const EFI_FILE& getSelfVolumeRootDir() { checkInitialized(); return *m_SelfVolumeRootDir; }
const EFI_DEVICE_PATH& getCloverDirFullDevicePath() { return *m_CloverDirFullDevicePath; }
const EFI_FILE& getCloverDir() { return *m_CloverDir; }
const XStringW& getCloverDirFullPath() { return m_CloverDirFullPath; }
// const XStringW& getCloverDirPath() { return m_CloverDirPath; } // returns path containing this efi. Like \\EFI\\CLOVER
const XStringW& getCloverEfiFileName() { checkInitialized(); return m_efiFileName; }
const EFI_DEVICE_PATH& getCloverDirFullDevicePath() { checkInitialized(); return *m_CloverDirFullDevicePath; }
const EFI_FILE& getCloverDir() { checkInitialized(); return *m_CloverDir; }
const XStringW& getCloverDirFullPath() { checkInitialized(); return m_CloverDirFullPath; }
// const XStringW& getCloverDirPath() { checkInitialized(); return m_CloverDirPath; } // returns path containing this efi. Like \\EFI\\CLOVER
// bool oemDirExists() { return m_OemDirExists; }
// const EFI_FILE& getOemDir() { return *m_OemDir; } // Oem dir name under SelfDir. Like "OEM\\MyBoard"
// bool oemDirExists() { checkInitialized(); return m_OemDirExists; }
// const EFI_FILE& getOemDir() { checkInitialized(); return *m_OemDir; } // Oem dir name under SelfDir. Like "OEM\\MyBoard"
bool themesDirExists() { return m_ThemesDirExists; }
const EFI_FILE& getThemesDir() { return *m_ThemesDir; }
bool themesDirExists() { checkInitialized(); return m_ThemesDirExists; }
const EFI_FILE& getThemesDir() { checkInitialized(); return *m_ThemesDir; }
};

View File

@ -2335,21 +2335,14 @@ GetEarlyUserSettings (
if ( Prop->isString() ) {
if ( Prop->getString()->stringValue().equalIC("true") ) GlobalConfig.DebugLog = true;
else if ( Prop->getString()->stringValue().equalIC("false") ) GlobalConfig.DebugLog = false;
else if ( Prop->getString()->stringValue().equalIC("scratch") ) {
GlobalConfig.DebugLog = true;
GlobalConfig.ScratchDebugLogAtStart = true;
}
else MsgLog("MALFORMED config.plist : property Boot/Debug must be true, false, or scratch\n");
}else if ( Prop->isBool() ) {
GlobalConfig.DebugLog = Prop->getBool()->boolValue();
}else{
MsgLog("MALFORMED config.plist : property Boot/Debug must be a string (true, false, or scratch) or <true/> or <false/>\n");
MsgLog("MALFORMED config.plist : property Boot/Debug must be a string (true, false) or <true/> or <false/>\n");
}
}
Prop = BootDict->propertyForKey("EmptyDebugLogAtStart");
GlobalConfig.ScratchDebugLogAtStart = IsPropertyNotNullAndTrue(Prop);
Prop = BootDict->propertyForKey("Fast");
GlobalConfig.FastBoot = IsPropertyNotNullAndTrue(Prop);

View File

@ -839,7 +839,6 @@ public:
BOOLEAN LegacyFirst;
BOOLEAN NoLegacy;
BOOLEAN DebugLog;
BOOLEAN ScratchDebugLogAtStart;
BOOLEAN FastBoot;
BOOLEAN NeverHibernate;
BOOLEAN StrictHibernate;
@ -886,7 +885,7 @@ public:
*
*/
REFIT_CONFIG() : Timeout(-1), DisableFlags(0), TextOnly(FALSE), Quiet(TRUE), LegacyFirst(FALSE), NoLegacy(FALSE),
DebugLog(FALSE), ScratchDebugLogAtStart(FALSE), FastBoot(FALSE), NeverHibernate(FALSE), StrictHibernate(FALSE),
DebugLog(FALSE), FastBoot(FALSE), NeverHibernate(FALSE), StrictHibernate(FALSE),
RtcHibernateAware(FALSE), HibernationFixup(FALSE), SignatureFixup(FALSE), Theme(), ScreenResolution(), ConsoleMode(0), CustomIcons(FALSE), IconFormat(ICON_FORMAT_DEF), NoEarlyProgress(FALSE), Timezone(0xFF),
ShowOptimus(FALSE), Codepage(0xC0), CodepageSize(0xC0) {};
REFIT_CONFIG(const REFIT_CONFIG& other) = delete; // Can be defined if needed