refactoring: explicit struct for error-related info

This commit is contained in:
Andrey 2024-02-08 22:03:35 -05:00
parent 01299ca9cd
commit 5a258a69c4
2 changed files with 46 additions and 41 deletions

View File

@ -31,22 +31,22 @@ void checkLastBootError() {
#if EFI_BACKUP_SRAM
auto sramState = getBackupSram();
switch (sramState->Cookie) {
switch (sramState->Err.Cookie) {
case ErrorCookie::FirmwareError:
efiPrintf("Last boot had firmware error: %s", sramState->ErrorString);
efiPrintf("Last boot had firmware error: %s", sramState->Err.ErrorString);
break;
case ErrorCookie::HardFault: {
efiPrintf("Last boot had raw: %s", sramState->rawMsg);
efiPrintf("Last boot had hardFile: %s", sramState->hardFile);
efiPrintf("Last boot had line: %d", sramState->hardLine);
efiPrintf("Last boot had check: %d", sramState->check);
efiPrintf("Last boot had error: %s", sramState->ErrorString);
efiPrintf("Last boot had hard fault type: %x addr: %x CSFR: %x", sramState->FaultType, sramState->FaultAddress, sramState->Csfr);
efiPrintf("Last boot had raw: %s", sramState->Err.rawMsg);
efiPrintf("Last boot had hardFile: %s", sramState->Err.hardFile);
efiPrintf("Last boot had line: %d", sramState->Err.hardLine);
efiPrintf("Last boot had check: %d", sramState->Err.check);
efiPrintf("Last boot had error: %s", sramState->Err.ErrorString);
efiPrintf("Last boot had hard fault type: %x addr: %x CSFR: %x", sramState->Err.FaultType, sramState->Err.FaultAddress, sramState->Err.Csfr);
if (engineConfiguration->rethrowHardFault) {
criticalError("Last boot had hard fault type: %x addr: %x CSFR: %x", sramState->FaultType, sramState->FaultAddress, sramState->Csfr);
criticalError("Last boot had hard fault type: %x addr: %x CSFR: %x", sramState->Err.FaultType, sramState->Err.FaultAddress, sramState->Err.Csfr);
}
auto ctx = &sramState->FaultCtx;
auto ctx = &sramState->Err.FaultCtx;
efiPrintf("r0 0x%x", ctx->r0);
efiPrintf("r1 0x%x", ctx->r1);
efiPrintf("r2 0x%x", ctx->r2);
@ -59,7 +59,7 @@ void checkLastBootError() {
/* FPU registers - not very usefull for debug */
if (0) {
// Print rest the context as a sequence of uintptr
uintptr_t* data = reinterpret_cast<uintptr_t*>(&sramState->FaultCtx);
uintptr_t* data = reinterpret_cast<uintptr_t*>(&sramState->Err.FaultCtx);
for (size_t i = 8; i < sizeof(port_extctx) / sizeof(uintptr_t); i++) {
efiPrintf("Fault ctx %d: %x", i, data[i]);
}
@ -73,15 +73,15 @@ void checkLastBootError() {
}
// Reset cookie so we don't print it again.
sramState->Cookie = ErrorCookie::None;
sramState->Err.Cookie = ErrorCookie::None;
if (sramState->BootCountCookie != 0xdeadbeef) {
sramState->BootCountCookie = 0xdeadbeef;
sramState->BootCount = 0;
if (sramState->Err.BootCountCookie != 0xdeadbeef) {
sramState->Err.BootCountCookie = 0xdeadbeef;
sramState->Err.BootCount = 0;
}
efiPrintf("Power cycle count: %d", sramState->BootCount);
sramState->BootCount++;
efiPrintf("Power cycle count: %d", sramState->Err.BootCount);
sramState->Err.BootCount++;
#endif // EFI_BACKUP_SRAM
}
@ -89,12 +89,12 @@ void logHardFault(uint32_t type, uintptr_t faultAddress, port_extctx* ctx, uint3
criticalShutdown();
#if EFI_BACKUP_SRAM
auto sramState = getBackupSram();
sramState->Cookie = ErrorCookie::HardFault;
sramState->check = 321;
sramState->FaultType = type;
sramState->FaultAddress = faultAddress;
sramState->Csfr = csfr;
memcpy(&sramState->FaultCtx, ctx, sizeof(port_extctx));
sramState->Err.Cookie = ErrorCookie::HardFault;
sramState->Err.check = 321;
sramState->Err.FaultType = type;
sramState->Err.FaultAddress = faultAddress;
sramState->Err.Csfr = csfr;
memcpy(&sramState->Err.FaultCtx, ctx, sizeof(port_extctx));
#endif // EFI_BACKUP_SRAM
}
@ -110,10 +110,10 @@ void chDbgPanic3(const char *msg, const char * file, int line) {
#if EFI_BACKUP_SRAM
auto sramState = getBackupSram();
strncpy(sramState->hardFile, file, efi::size(sramState->hardFile) - 1);
sramState->hardLine = line;
sramState->check = 123;
strncpy(sramState->rawMsg, msg, efi::size(sramState->rawMsg) - 1);
strncpy(sramState->Err.hardFile, file, efi::size(sramState->Err.hardFile) - 1);
sramState->Err.hardLine = line;
sramState->Err.check = 123;
strncpy(sramState->Err.rawMsg, msg, efi::size(sramState->Err.rawMsg) - 1);
#endif // EFI_BACKUP_SRAM
if (hasOsPanicError())
@ -306,8 +306,8 @@ void firmwareError(ObdCode code, const char *fmt, ...) {
#if EFI_BACKUP_SRAM
auto sramState = getBackupSram();
strncpy(sramState->ErrorString, criticalErrorMessageBuffer, efi::size(sramState->ErrorString));
sramState->Cookie = ErrorCookie::FirmwareError;
strncpy(sramState->Err.ErrorString, criticalErrorMessageBuffer, efi::size(sramState->Err.ErrorString));
sramState->Err.Cookie = ErrorCookie::FirmwareError;
#endif // EFI_BACKUP_SRAM
#else

View File

@ -49,20 +49,25 @@ enum class ErrorCookie : uint32_t {
#if EFI_PROD_CODE
struct BackupSramData {
ErrorCookie Cookie;
critical_msg_t ErrorString;
critical_msg_t hardFile;
int hardLine;
int check;
critical_msg_t rawMsg;
port_extctx FaultCtx;
uint32_t FaultType;
uint32_t FaultAddress;
uint32_t Csfr;
// Error handling/recovery/reporting information
struct {
ErrorCookie Cookie;
critical_msg_t ErrorString;
critical_msg_t hardFile;
int hardLine;
int check;
critical_msg_t rawMsg;
port_extctx FaultCtx;
uint32_t FaultType;
uint32_t FaultAddress;
uint32_t Csfr;
uint32_t BootCount;
uint32_t BootCountCookie;
} Err;
uint32_t BootCount;
uint32_t BootCountCookie;
};
BackupSramData* getBackupSram();