diff --git a/bsp_q7s/memory/scratchApi.h b/bsp_q7s/memory/scratchApi.h index b3ea4a6a..1221f328 100644 --- a/bsp_q7s/memory/scratchApi.h +++ b/bsp_q7s/memory/scratchApi.h @@ -76,7 +76,6 @@ ReturnValue_t readToFile(std::string name, std::ifstream& file, std::string& fil int result = std::system(oss.str().c_str()); if (result != 0) { if (WEXITSTATUS(result) == 1) { - sif::warning << "scratch::readToFile: Key " << name << " does not exist" << std::endl; // Could not find value std::remove(filename.c_str()); return KEY_NOT_FOUND; diff --git a/bsp_q7s/obsw.cpp b/bsp_q7s/obsw.cpp index fc49c369..a69953d9 100644 --- a/bsp_q7s/obsw.cpp +++ b/bsp_q7s/obsw.cpp @@ -10,6 +10,7 @@ #include "OBSWConfig.h" #include "bsp_q7s/core/WatchdogHandler.h" +#include "memory/scratchApi.h" #include "commonConfig.h" #include "fsfw/tasks/TaskFactory.h" #include "fsfw/version.h" @@ -18,6 +19,7 @@ #include "mission/system/systemTree.h" #include "q7sConfig.h" #include "scheduling.h" +#include #include "watchdog/definitions.h" static constexpr int OBSW_ALREADY_RUNNING = -2; @@ -50,6 +52,8 @@ int obsw::obsw(int argc, char* argv[]) { } #endif + autoSwitchHandling(); + // Delay the boot if applicable. bootDelayHandling(); @@ -82,6 +86,27 @@ int obsw::obsw(int argc, char* argv[]) { return 0; } +void obsw::autoSwitchHandling() { + std::string autoSwitchTarget; + auto switchToTarget = [](xsc_libnor_chip_t chip, xsc_libnor_copy_t copy) { + scratch::clearValue("ASWI"); + xsc_boot_copy(chip, copy); + }; + if (scratch::readString("ASWI", autoSwitchTarget) == returnvalue::OK) { + if (autoSwitchTarget == "00") { + switchToTarget(XSC_LIBNOR_CHIP_0, XSC_LIBNOR_COPY_NOMINAL); + } else if (autoSwitchTarget == "01") { + switchToTarget(XSC_LIBNOR_CHIP_0, XSC_LIBNOR_COPY_GOLD); + } else if (autoSwitchTarget == "10") { + switchToTarget(XSC_LIBNOR_CHIP_1, XSC_LIBNOR_COPY_NOMINAL); + } else if(autoSwitchTarget == "11") { + switchToTarget(XSC_LIBNOR_CHIP_1, XSC_LIBNOR_COPY_GOLD); + } else { + sif::warning << "Invalid Auto Switch Image (ASWI) value detected: " << autoSwitchTarget << std::endl; + } + } +} + void obsw::bootDelayHandling() { const char* homedir = nullptr; homedir = getenv("HOME"); diff --git a/bsp_q7s/obsw.h b/bsp_q7s/obsw.h index 8260a605..55002df0 100644 --- a/bsp_q7s/obsw.h +++ b/bsp_q7s/obsw.h @@ -5,6 +5,12 @@ namespace obsw { int obsw(int argc, char* argv[]); +/** + * This is a safety mechanism where the ProASIC scratch buffer can be used to trigger an + * auto-boot to another image. The auto-boot is currently implemented as a one-shot mechanism: + * The key-value pair which triggers the auto-boot will be removed from the scratch buffer. + */ +void autoSwitchHandling(); void bootDelayHandling(); void commandEiveSystemToSafe(); void commandComSubsystemRxOnly();