mmc_card: report files delete command

This commit is contained in:
Andrey Gusakov 2025-01-23 19:32:38 +03:00 committed by rusefillc
parent 09105c6a3e
commit 985d49a42b
6 changed files with 76 additions and 1 deletions

View File

@ -261,6 +261,7 @@ typedef enum {
TS_SD_MOUNT_ECU = 0x18,
TS_SD_UNMOUNT = 0x19,
TS_SD_FORMAT = 0x1A,
TS_SD_DELETE_REPORTS = 0x1B,
} ts_14_command;
typedef enum {

View File

@ -530,6 +530,9 @@ static void handleCommandX14(uint16_t index) {
case TS_SD_FORMAT:
sdCardRequestMode(SD_MODE_FORMAT);
return;
case TS_SD_DELETE_REPORTS:
sdCardRemoveReportFiles();
return;
#endif // EFI_FILE_LOGGING
default:

View File

@ -326,6 +326,42 @@ int errorHandlerCheckReportFiles() {
return hasReportFile;
}
static void errorHandlerDeleteTypedReport(ErrorCookie cookie) {
bool failed = false;
FRESULT fr; /* Return value */
DIR dj; /* Directory object */
FILINFO fno; /* File information */
TCHAR pattern[32];
sprintf(pattern, "*%s*", errorHandlerGetErrorName(cookie));
do {
fr = f_findfirst(&dj, &fno, "", pattern);
f_closedir(&dj);
if ((fr == FR_OK) && (fno.fname[0])) {
efiPrintf("deleting %s", fno.fname);
FRESULT ret = f_unlink(fno.fname);
if (ret != FR_OK) {
efiPrintf("Faield to delete %s: %d", fno.fname, ret);
failed = true;
} else {
efiPrintf("%s removed", fno.fname);
}
}
} while ((!failed) && (fr == FR_OK) && (fno.fname[0]));
}
void errorHandlerDeleteReports() {
errorHandlerDeleteTypedReport(ErrorCookie::FirmwareError);
errorHandlerDeleteTypedReport(ErrorCookie::HardFault);
errorHandlerDeleteTypedReport(ErrorCookie::ChibiOsPanic);
// update
errorHandlerCheckReportFiles();
}
#endif
backupErrorState *errorHandlerGetLastErrorDescriptor(void)

View File

@ -151,6 +151,7 @@ static NO_CACHE SdLogBufferWriter logBuffer;
// cause simulator fail to build.
extern void errorHandlerWriteReportFile(FIL *fd);
extern int errorHandlerCheckReportFiles();
extern void errorHandlerDeleteReports();
typedef enum {
SD_STATUS_INIT = 0,
@ -304,6 +305,16 @@ static void sdStatistics() {
#endif
}
static void sdSetMode(const char *mode) {
if (strcmp(mode, "pc") == 0) {
sdCardRequestMode(SD_MODE_PC);
} else if (strcmp(mode, "ecu") == 0) {
sdCardRequestMode(SD_MODE_ECU);
} else {
efiPrintf("Invalid mode %s allowed modes pc and ecu", mode);
}
}
static void prepareLogFileName() {
strcpy(logName, RUSEFI_LOG_PREFIX);
char *ptr;
@ -376,6 +387,11 @@ static void sdLoggerCloseFile(FIL *fd)
}
static void removeFile(const char *pathx) {
if (sdMode != SD_MODE_ECU) {
efiPrintf("SD card should be mounted to ECU");
return;
}
f_unlink(pathx);
}
@ -919,6 +935,8 @@ void initEarlyMmcCard() {
addConsoleAction("sdinfo", sdStatistics);
addConsoleActionS("del", removeFile);
addConsoleActionS("sdmode", sdSetMode);
addConsoleAction("delreports", sdCardRemoveReportFiles);
//incLogFileName() use same shared FDLogFile, calling it while FDLogFile is used by log writer will cause damage
//addConsoleAction("incfilename", incLogFileName);
#endif // EFI_PROD_CODE
@ -948,6 +966,16 @@ void sdCardRequestMode(SD_MODE mode)
sdTargerMode = mode;
}
}
void sdCardRemoveReportFiles() {
if (sdMode != SD_MODE_ECU) {
efiPrintf("SD card should be mounted to ECU");
return;
}
errorHandlerDeleteReports();
}
#endif // EFI_PROD_CODE
#endif /* EFI_FILE_LOGGING */

View File

@ -32,3 +32,4 @@ struct USBDriver;
bool msd_request_hook_new(USBDriver *usbp);
void sdCardRequestMode(SD_MODE mode);
void sdCardRemoveReportFiles();

View File

@ -2425,6 +2425,7 @@ cmd_mount_pc = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_X14_16_hex@@@@ts
cmd_mount_ecu = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_X14_16_hex@@@@ts_14_command_TS_SD_MOUNT_ECU_16_hex@@"
cmd_unmount = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_X14_16_hex@@@@ts_14_command_TS_SD_UNMOUNT_16_hex@@"
cmd_format = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_X14_16_hex@@@@ts_14_command_TS_SD_FORMAT_16_hex@@"
cmd_delete_reports = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_X14_16_hex@@@@ts_14_command_TS_SD_DELETE_REPORTS_16_hex@@"
; See 'executeTSCommand' in firmware source code
@ -4418,6 +4419,11 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_
indicatorPanel = sdCardErrorReportIndicators, 1, { isSdCardEnabled }
indicator = { hasFaultReportFile }, "No error reports", "Error report on SD", white, black, red, black
dialog = sdReportCommands, "Fail reports"
field = "Executed only when SD card is mounted to ECU"
commandButton = "Remove all fail reports", cmd_delete_reports
panel = sdCardErrorReportIndicators
dialog = sdCard, "SD Card"
panel = sdCardHW
panel = sdPresentIndicators
@ -4425,7 +4431,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_
panel = sdCardLogging
panel = sdCardStateIndicators
panel = sdCardCommands
panel = sdCardErrorReportIndicators
panel = sdReportCommands
dialog = tle8888Dialog, "TLE8888", yAxis
field = "TLE8888 SPI", tle8888spiDevice @@if_ts_show_spi