diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 25ce04bb..b3f91506 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -1557,6 +1557,7 @@ void CoreController::performMountedSdCardOperations() { initClockFromTimeFile(); } performRebootWatchdogHandling(false); + performRebootCountersHandling(false); } backupTimeFileHandler(); }; @@ -1631,10 +1632,17 @@ ReturnValue_t CoreController::performSdCardCheck() { void CoreController::performRebootWatchdogHandling(bool recreateFile) { using namespace std; std::string path = currMntPrefix + REBOOT_WATCHDOG_FILE; + std::string legacyPath = currMntPrefix + LEGACY_REBOOT_WATCHDOG_FILE; std::error_code e; + // TODO: Remove at some point in the future. + if (std::filesystem::exists(legacyPath)) { + // Old file might still exist, so copy it to new path + std::filesystem::copy(legacyPath, path); + } if (not std::filesystem::exists(path, e) or recreateFile) { #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "CoreController::performRebootFileHandling: Recreating reboot file" << std::endl; + sif::info << "CoreController::performRebootFileHandling: Recreating reboot watchdog file" + << std::endl; #endif rebootWatchdogFile.enabled = false; rebootWatchdogFile.img00Cnt = 0; @@ -1654,6 +1662,7 @@ void CoreController::performRebootWatchdogHandling(bool recreateFile) { } else { if (not parseRebootWatchdogFile(path, rebootWatchdogFile)) { performRebootWatchdogHandling(true); + return; } } @@ -1679,8 +1688,6 @@ void CoreController::performRebootWatchdogHandling(bool recreateFile) { rebootWatchdogFile.bootFlag = false; } - announceBootCounts(); - if (rebootWatchdogFile.mechanismNextChip != xsc::NO_CHIP and rebootWatchdogFile.mechanismNextCopy != xsc::NO_COPY) { if (CURRENT_CHIP != rebootWatchdogFile.mechanismNextChip or @@ -2086,9 +2093,45 @@ void CoreController::resetRebootWatchdogCounters(xsc::Chip tgtChip, xsc::Copy tg } void CoreController::performRebootCountersHandling(bool recreateFile) { + std::string path = currMntPrefix + REBOOT_COUNTERS_FILE; + std::error_code e; + if (not std::filesystem::exists(path, e) or recreateFile) { +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "CoreController::performRebootFileHandling: Recreating reboot counters file" + << std::endl; +#endif + rebootCountersFile.img00Cnt = 0; + rebootCountersFile.img01Cnt = 0; + rebootCountersFile.img10Cnt = 0; + rebootCountersFile.img11Cnt = 0; + rewriteRebootCountersFile(rebootCountersFile); + } else { + if (not parseRebootCountersFile(path, rebootCountersFile)) { + performRebootCountersHandling(true); + return; + } + } + + if (CURRENT_CHIP == xsc::CHIP_0) { + if (CURRENT_COPY == xsc::COPY_0) { + rebootCountersFile.img00Cnt++; + } else { + rebootCountersFile.img01Cnt++; + } + } else { + if (CURRENT_COPY == xsc::COPY_0) { + rebootCountersFile.img10Cnt++; + } else { + rebootCountersFile.img11Cnt++; + } + } + announceBootCounts(); + rewriteRebootCountersFile(rebootCountersFile); } void CoreController::rewriteRebootWatchdogFile(RebootWatchdogFile file) { + using namespace std::filesystem; std::string path = currMntPrefix + REBOOT_WATCHDOG_FILE; + std::string legacyPath = currMntPrefix + LEGACY_REBOOT_WATCHDOG_FILE; std::ofstream rebootFile(path); if (rebootFile.is_open()) { // Initiate reboot file first. Reboot handling will be on on initialization @@ -2102,11 +2145,24 @@ void CoreController::rewriteRebootWatchdogFile(RebootWatchdogFile file) { << "\nnext: " << static_cast(file.mechanismNextChip) << " " << static_cast(file.mechanismNextCopy) << "\n"; } + // TODO: Remove at some point in the future when all images have been updated. + if (std::filesystem::exists(legacyPath)) { + // Keep those two files in sync + std::filesystem::copy(path, legacyPath); + } +} + +void CoreController::rewriteRebootCountersFile(RebootCountersFile file) { + std::string path = currMntPrefix + REBOOT_COUNTERS_FILE; + std::ofstream rebootFile(path); + if (rebootFile.is_open()) { + rebootFile << "\nimg00: " << file.img00Cnt << "\nimg01: " << file.img01Cnt + << "\nimg10: " << file.img10Cnt << "\nimg11: " << file.img11Cnt << "\n"; + } } void CoreController::setRebootMechanismLock(bool lock, xsc::Chip tgtChip, xsc::Copy tgtCopy) { std::string path = currMntPrefix + REBOOT_WATCHDOG_FILE; - // Disable the reboot file mechanism parseRebootWatchdogFile(path, rebootWatchdogFile); if (tgtChip == xsc::CHIP_0) { if (tgtCopy == xsc::COPY_0) { @@ -2408,12 +2464,12 @@ bool CoreController::startSdStateMachine(sd::SdCard targetActiveSd, SdCfgMode mo } void CoreController::announceBootCounts() { - uint64_t totalBootCount = rebootWatchdogFile.img00Cnt + rebootWatchdogFile.img01Cnt + - rebootWatchdogFile.img10Cnt + rebootWatchdogFile.img11Cnt; + uint64_t totalBootCount = rebootCountersFile.img00Cnt + rebootCountersFile.img01Cnt + + rebootCountersFile.img10Cnt + rebootCountersFile.img11Cnt; uint32_t individualBootCountsP1 = - (rebootWatchdogFile.img00Cnt << 16) | rebootWatchdogFile.img01Cnt; + (rebootCountersFile.img00Cnt << 16) | rebootCountersFile.img01Cnt; uint32_t individualBootCountsP2 = - (rebootWatchdogFile.img10Cnt << 16) | rebootWatchdogFile.img11Cnt; + (rebootCountersFile.img10Cnt << 16) | rebootCountersFile.img11Cnt; triggerEvent(core::INDIVIDUAL_BOOT_COUNTS, individualBootCountsP1, individualBootCountsP2); triggerEvent(core::REBOOT_COUNTER, (totalBootCount >> 32) & 0xffffffff, totalBootCount & 0xffffffff); diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index bfca7f27..e3f514d9 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -145,6 +145,9 @@ class CoreController : public ExtendedControllerBase, public ReceivesParameterMe const std::string VERSION_FILE = "/" + std::string(core::CONF_FOLDER) + "/" + std::string(core::VERSION_FILE_NAME); + const std::string LEGACY_REBOOT_WATCHDOG_FILE = + "/" + std::string(core::CONF_FOLDER) + "/" + + std::string(core::LEGACY_REBOOT_WATCHDOG_FILE_NAME); const std::string REBOOT_WATCHDOG_FILE = "/" + std::string(core::CONF_FOLDER) + "/" + std::string(core::REBOOT_WATCHDOG_FILE_NAME); const std::string BACKUP_TIME_FILE = diff --git a/mission/sysDefs.h b/mission/sysDefs.h index 234b1ff3..fe572144 100644 --- a/mission/sysDefs.h +++ b/mission/sysDefs.h @@ -41,6 +41,7 @@ enum SystemctlCmd : uint8_t { START = 0, STOP = 1, RESTART = 2, NUM_CMDS = 3 }; static constexpr char CONF_FOLDER[] = "conf"; static constexpr char VERSION_FILE_NAME[] = "version.txt"; +static constexpr char LEGACY_REBOOT_WATCHDOG_FILE_NAME[] = "reboot.txt"; static constexpr char REBOOT_WATCHDOG_FILE_NAME[] = "reboot_watchdog.txt"; static constexpr char REBOOT_COUNTER_FILE_NAME[] = "reboot_counters.txt"; static constexpr char TIME_FILE_NAME[] = "time_backup.txt"; diff --git a/tmtc b/tmtc index c9f4a807..deb0275b 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit c9f4a8070d20bc659809d5b822ac5a17548f57a4 +Subproject commit deb0275bb5603394122e26f74760d2051685f324