From a2bc72a7981bcd53e23e4f86c01c8b0421bbef55 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 28 Feb 2022 16:35:16 +0100 Subject: [PATCH] improved mount logic, create conf folder is missing --- bsp_q7s/core/CoreController.cpp | 177 ++++++++++++------------ bsp_q7s/core/CoreController.h | 12 +- fsfw | 2 +- unittest/rebootLogic/CoreController.cpp | 158 ++++++++++----------- unittest/rebootLogic/main.cpp | 2 +- 5 files changed, 177 insertions(+), 174 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index c106cd7e..d9022b57 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -59,7 +59,7 @@ ReturnValue_t CoreController::handleCommandMessage(CommandMessage *message) { void CoreController::performControlOperation() { performWatchdogControlOperation(); sdStateMachine(); - performRebootFileHandling(false); + performMountedSdCardOperations(); } ReturnValue_t CoreController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, @@ -94,7 +94,7 @@ ReturnValue_t CoreController::initializeAfterTaskCreation() { } } sdStateMachine(); - result = initVersionFile(); + performMountedSdCardOperations(); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "CoreController::initialize: Version initialization failed" << std::endl; } @@ -1174,102 +1174,93 @@ void CoreController::performWatchdogControlOperation() { } void CoreController::performRebootFileHandling(bool recreateFile) { - bool sdCardMounted = false; - if (not recreateFile and doPerformRebootFileHandling) { - sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref); + using namespace std; + std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; + if (not std::filesystem::exists(path) or recreateFile) { +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "CoreController::performRebootFileHandling: Recreating reboot file" << std::endl; +#endif + rebootFile.enabled = true; + rebootFile.img00Cnt = 0; + rebootFile.img01Cnt = 0; + rebootFile.img10Cnt = 0; + rebootFile.img11Cnt = 0; + rebootFile.lastChip = xsc::Chip::CHIP_0; + rebootFile.lastCopy = xsc::Copy::COPY_0; + rebootFile.bootFlag = false; + rewriteRebootFile(rebootFile); + } else { + if (not parseRebootFile(path, rebootFile)) { + performRebootFileHandling(true); + } } - if ((doPerformRebootFileHandling and sdCardMounted) or recreateFile) { - using namespace std; - if (recreateFile) { -#if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "CoreController::performRebootFileHandling: Recreating reboot file" << std::endl; -#endif - } - std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; - if (not std::filesystem::exists(path) or recreateFile) { - rebootFile.enabled = true; - rebootFile.img00Cnt = 0; - rebootFile.img01Cnt = 0; - rebootFile.img10Cnt = 0; - rebootFile.img11Cnt = 0; - rebootFile.lastChip = xsc::Chip::CHIP_0; - rebootFile.lastCopy = xsc::Copy::COPY_0; - rebootFile.bootFlag = false; - rewriteRebootFile(rebootFile); - } else { - if (not parseRebootFile(path, rebootFile)) { - performRebootFileHandling(true); - } - } - if (rebootFile.bootFlag) { - // Trigger event to inform ground that a reboot was triggered - uint32_t p1 = rebootFile.lastChip << 16 | rebootFile.lastCopy; - uint32_t p2 = rebootFile.img00Cnt << 24 | rebootFile.img01Cnt << 16 | - rebootFile.img10Cnt << 8 | rebootFile.img11Cnt; - triggerEvent(REBOOT_MECHANISM_TRIGGERED, p1, p2); - // Clear the boot flag - rebootFile.bootFlag = false; - } + if (rebootFile.bootFlag) { + // Trigger event to inform ground that a reboot was triggered + uint32_t p1 = rebootFile.lastChip << 16 | rebootFile.lastCopy; + uint32_t p2 = rebootFile.img00Cnt << 24 | rebootFile.img01Cnt << 16 | + rebootFile.img10Cnt << 8 | rebootFile.img11Cnt; + triggerEvent(REBOOT_MECHANISM_TRIGGERED, p1, p2); + // Clear the boot flag + rebootFile.bootFlag = false; + } - switch (CURRENT_CHIP) { - case (xsc::CHIP_0): { - switch (CURRENT_COPY) { - case (xsc::COPY_0): { - rebootFile.img00Cnt++; - break; - } - case (xsc::COPY_1): { - rebootFile.img01Cnt++; - break; - } - default: { - break; - } + switch (CURRENT_CHIP) { + case (xsc::CHIP_0): { + switch (CURRENT_COPY) { + case (xsc::COPY_0): { + rebootFile.img00Cnt++; + break; } - break; - } - case (xsc::CHIP_1): { - switch (CURRENT_COPY) { - case (xsc::COPY_0): { - rebootFile.img10Cnt++; - break; - } - case (xsc::COPY_1): { - rebootFile.img11Cnt++; - break; - } - default: { - break; - } + case (xsc::COPY_1): { + rebootFile.img01Cnt++; + break; + } + default: { + break; } - break; } - default: { - break; + break; + } + case (xsc::CHIP_1): { + switch (CURRENT_COPY) { + case (xsc::COPY_0): { + rebootFile.img10Cnt++; + break; + } + case (xsc::COPY_1): { + rebootFile.img11Cnt++; + break; + } + default: { + break; + } } + break; } - if (CURRENT_CHIP == xsc::CHIP_0 and CURRENT_COPY == xsc::COPY_0) { + default: { + break; } - if (rebootFile.relevantBootCnt > rebootFile.maxCount) { - // Reboot to other image - bool doReboot = false; - determineAndExecuteReboot(rebootFile, doReboot, rebootFile.lastChip, rebootFile.lastCopy); - if (doReboot) { - rebootFile.bootFlag = true; + } + if (CURRENT_CHIP == xsc::CHIP_0 and CURRENT_COPY == xsc::COPY_0) { + } + if (rebootFile.relevantBootCnt > rebootFile.maxCount) { + // Reboot to other image + bool doReboot = false; + determineAndExecuteReboot(rebootFile, doReboot, rebootFile.lastChip, rebootFile.lastCopy); + if (doReboot) { + rebootFile.bootFlag = true; #if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Boot counter for image " << CURRENT_CHIP << " " << CURRENT_COPY - << "too high. Rebooting to " << rebootFile.lastChip << " " << rebootFile.lastCopy - << std::endl; + sif::info << "Boot counter for image " << CURRENT_CHIP << " " << CURRENT_COPY + << "too high. Rebooting to " << rebootFile.lastChip << " " << rebootFile.lastCopy + << std::endl; #endif - rewriteRebootFile(rebootFile); - xsc_boot_copy(static_cast(rebootFile.lastChip), - static_cast(rebootFile.lastCopy)); - } - } else { rewriteRebootFile(rebootFile); + xsc_boot_copy(static_cast(rebootFile.lastChip), + static_cast(rebootFile.lastCopy)); } - doPerformRebootFileHandling = false; + } else { + rewriteRebootFile(rebootFile); } } @@ -1520,6 +1511,22 @@ void CoreController::resetRebootCount(xsc::Chip tgtChip, xsc::Copy tgtCopy) { rewriteRebootFile(rebootFile); } +void CoreController::performMountedSdCardOperations() { + if(doPerformMountedSdCardOps) { + bool sdCardMounted = false; + sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref); + if(sdCardMounted) { + std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + "/" + CONF_FOLDER; + if(not std::filesystem::exists(path)) { + std::filesystem::create_directory(path); + } + initVersionFile(); + performRebootFileHandling(true); + doPerformMountedSdCardOps = false; + } + } +} + void CoreController::rewriteRebootFile(RebootFile file) { std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; std::ofstream rebootFile(path); diff --git a/bsp_q7s/core/CoreController.h b/bsp_q7s/core/CoreController.h index c7577e02..6a8bb8cd 100644 --- a/bsp_q7s/core/CoreController.h +++ b/bsp_q7s/core/CoreController.h @@ -43,8 +43,11 @@ class CoreController : public ExtendedControllerBase { static constexpr char CHIP_PROT_SCRIPT[] = "/home/root/scripts/get-chip-prot-status.sh"; static constexpr char CHIP_STATE_FILE[] = "/tmp/chip_prot_status.txt"; static constexpr char CURR_COPY_FILE[] = "/tmp/curr_copy.txt"; - static constexpr char VERSION_FILE[] = "/conf/version.txt"; - static constexpr char REBOOT_FILE[] = "/conf/reboot.txt"; + static constexpr char CONF_FOLDER[] = "conf"; + static constexpr char VERSION_FILE_NAME[] = "version.txt"; + static constexpr char REBOOT_FILE_NAME[] = "reboot.txt"; + const std::string VERSION_FILE = "/" + std::string(CONF_FOLDER) + "/" + std::string(VERSION_FILE_NAME); + const std::string REBOOT_FILE = "/" + std::string(CONF_FOLDER) + "/" + std::string(REBOOT_FILE_NAME); static constexpr ActionId_t LIST_DIRECTORY_INTO_FILE = 0; static constexpr ActionId_t SWITCH_REBOOT_FILE_HANDLING = 5; @@ -162,7 +165,7 @@ class CoreController : public ExtendedControllerBase { sd::SdState commandedState = sd::SdState::OFF; } sdInfo; RebootFile rebootFile = {}; - bool doPerformRebootFileHandling = true; + bool doPerformMountedSdCardOps = true; /** * Index 0: Chip 0 Copy 0 @@ -177,7 +180,7 @@ class CoreController : public ExtendedControllerBase { LocalDataPoolManager& poolManager) override; LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t* msToReachTheMode); - + void performMountedSdCardOperations(); ReturnValue_t initVersionFile(); ReturnValue_t initBootCopy(); ReturnValue_t initWatchdogFifo(); @@ -189,6 +192,7 @@ class CoreController : public ExtendedControllerBase { ReturnValue_t sdCardSetup(sd::SdCard sdCard, sd::SdState targetState, std::string sdChar, bool printOutput = true); ReturnValue_t sdColdRedundantBlockingInit(); + void currentStateSetter(sd::SdCard sdCard, sd::SdState newState); void determinePreferredSdCard(); void executeNextExternalSdCommand(); diff --git a/fsfw b/fsfw index 2d9216ba..6e0b9069 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 2d9216ba19f1931225daa5b6b6f244a48c09f1b9 +Subproject commit 6e0b90696da2dfd2ec4749dfdb73950be2283c25 diff --git a/unittest/rebootLogic/CoreController.cpp b/unittest/rebootLogic/CoreController.cpp index 127c4a92..d9269c06 100644 --- a/unittest/rebootLogic/CoreController.cpp +++ b/unittest/rebootLogic/CoreController.cpp @@ -16,105 +16,97 @@ CoreController::CoreController() { } void CoreController::performRebootFileHandling(bool recreateFile) { - bool sdCardMounted = false; - if (not recreateFile and doPerformRebootFileHandling) { - sdCardMounted = sdcMan->isSdCardMounted(sdInfo.pref); + using namespace std; + std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; + if (not std::filesystem::exists(path) or recreateFile) { +#if OBSW_VERBOSE_LEVEL >= 1 + std::cout << "CoreController::performRebootFileHandling: Recreating reboot file" << std::endl; +#endif + rebootFile.enabled = true; + rebootFile.img00Cnt = 0; + rebootFile.img01Cnt = 0; + rebootFile.img10Cnt = 0; + rebootFile.img11Cnt = 0; + rebootFile.lastChip = xsc::Chip::CHIP_0; + rebootFile.lastCopy = xsc::Copy::COPY_0; + rebootFile.bootFlag = false; + rewriteRebootFile(rebootFile); + } else { + if (not parseRebootFile(path, rebootFile)) { + performRebootFileHandling(true); + } } - if ((doPerformRebootFileHandling and sdCardMounted) or recreateFile) { - using namespace std; - if (recreateFile) { -#if OBSW_VERBOSE_LEVEL >= 1 - std::cout << "CoreController::performRebootFileHandling: Recreating reboot file" << std::endl; -#endif - } - std::string path = sdcMan->getCurrentMountPrefix(sdInfo.pref) + REBOOT_FILE; - if (not std::filesystem::exists(path) or recreateFile) { - rebootFile.enabled = true; - rebootFile.img00Cnt = 0; - rebootFile.img01Cnt = 0; - rebootFile.img10Cnt = 0; - rebootFile.img11Cnt = 0; - rebootFile.lastChip = xsc::Chip::CHIP_0; - rebootFile.lastCopy = xsc::Copy::COPY_0; - rebootFile.bootFlag = false; - rewriteRebootFile(rebootFile); - } else { - if (not parseRebootFile(path, rebootFile)) { - performRebootFileHandling(true); - } - } - if (rebootFile.bootFlag) { - // Trigger event to inform ground that a reboot was triggered - uint32_t p1 = rebootFile.lastChip << 16 | rebootFile.lastCopy; - uint32_t p2 = rebootFile.img00Cnt << 24 | rebootFile.img01Cnt << 16 | - rebootFile.img10Cnt << 8 | rebootFile.img11Cnt; - triggerEvent(REBOOT_MECHANISM_TRIGGERED, p1, p2); - // Clear the boot flag - rebootFile.bootFlag = false; - } + if (rebootFile.bootFlag) { + // Trigger event to inform ground that a reboot was triggered + uint32_t p1 = rebootFile.lastChip << 16 | rebootFile.lastCopy; + uint32_t p2 = rebootFile.img00Cnt << 24 | rebootFile.img01Cnt << 16 | + rebootFile.img10Cnt << 8 | rebootFile.img11Cnt; + triggerEvent(REBOOT_MECHANISM_TRIGGERED, p1, p2); + // Clear the boot flag + rebootFile.bootFlag = false; + } - switch (CURRENT_CHIP) { - case (xsc::CHIP_0): { - switch (CURRENT_COPY) { - case (xsc::COPY_0): { - rebootFile.img00Cnt++; - break; - } - case (xsc::COPY_1): { - rebootFile.img01Cnt++; - break; - } - default: { - break; - } + switch (CURRENT_CHIP) { + case (xsc::CHIP_0): { + switch (CURRENT_COPY) { + case (xsc::COPY_0): { + rebootFile.img00Cnt++; + break; } - break; - } - case (xsc::CHIP_1): { - switch (CURRENT_COPY) { - case (xsc::COPY_0): { - rebootFile.img10Cnt++; - break; - } - case (xsc::COPY_1): { - rebootFile.img11Cnt++; - break; - } - default: { - break; - } + case (xsc::COPY_1): { + rebootFile.img01Cnt++; + break; + } + default: { + break; } - break; } - default: { - break; + break; + } + case (xsc::CHIP_1): { + switch (CURRENT_COPY) { + case (xsc::COPY_0): { + rebootFile.img10Cnt++; + break; + } + case (xsc::COPY_1): { + rebootFile.img11Cnt++; + break; + } + default: { + break; + } } + break; } - if (CURRENT_CHIP == xsc::CHIP_0 and CURRENT_COPY == xsc::COPY_0) { + default: { + break; } - if (rebootFile.relevantBootCnt > rebootFile.maxCount) { - // Reboot to other image - bool doReboot = false; - determineAndExecuteReboot(rebootFile, doReboot, rebootFile.lastChip, rebootFile.lastCopy); - if (doReboot) { - rebootFile.bootFlag = true; + } + if (CURRENT_CHIP == xsc::CHIP_0 and CURRENT_COPY == xsc::COPY_0) { + } + if (rebootFile.relevantBootCnt > rebootFile.maxCount) { + // Reboot to other image + bool doReboot = false; + determineAndExecuteReboot(rebootFile, doReboot, rebootFile.lastChip, rebootFile.lastCopy); + if (doReboot) { + rebootFile.bootFlag = true; #if OBSW_VERBOSE_LEVEL >= 1 - std::cout << "Boot counter for image " << CURRENT_CHIP << " " << CURRENT_COPY - << "too high. Rebooting to " << rebootFile.lastChip << " " << rebootFile.lastCopy - << std::endl; + std::cout << "Boot counter for image " << CURRENT_CHIP << " " << CURRENT_COPY + << "too high. Rebooting to " << rebootFile.lastChip << " " << rebootFile.lastCopy + << std::endl; #endif - rewriteRebootFile(rebootFile); - xsc_boot_copy(static_cast(rebootFile.lastChip), - static_cast(rebootFile.lastCopy)); - } - } else { rewriteRebootFile(rebootFile); + xsc_boot_copy(static_cast(rebootFile.lastChip), + static_cast(rebootFile.lastCopy)); } - doPerformRebootFileHandling = false; + } else { + rewriteRebootFile(rebootFile); } } + void CoreController::determineAndExecuteReboot(RebootFile &rf, bool &needsReboot, xsc::Chip &tgtChip, xsc::Copy &tgtCopy) { tgtChip = xsc::CHIP_0; diff --git a/unittest/rebootLogic/main.cpp b/unittest/rebootLogic/main.cpp index cd6117ab..1a7748c9 100644 --- a/unittest/rebootLogic/main.cpp +++ b/unittest/rebootLogic/main.cpp @@ -4,5 +4,5 @@ TEST_CASE( "Core Controller Reboot File Handling", "[reboot-file]" ) { CoreController ctrl; - std::cout << "Hello, world!\n"; + ctrl.performRebootFileHandling(true); }