From 2e210a0572296bd500a598529ace80020374e354 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 19 Oct 2023 13:31:43 +0200 Subject: [PATCH 1/9] start impl auto switch feature --- bsp_q7s/memory/scratchApi.h | 1 - bsp_q7s/obsw.cpp | 25 +++++++++++++++++++++++++ bsp_q7s/obsw.h | 6 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) 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(); -- 2.34.1 From 01ce1f154e8a00aacf80a0ae93f42ab3ac2f2621 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 19 Oct 2023 14:43:29 +0200 Subject: [PATCH 2/9] that should get the job done --- bsp_q7s/core/CoreController.cpp | 23 +++++++++++++++++++++++ bsp_q7s/memory/scratchApi.h | 1 + bsp_q7s/obsw.cpp | 15 ++++++++------- mission/sysDefs.h | 2 ++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index e1b48fd2..ad4caf92 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -359,6 +359,29 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_ case (OBSW_UPDATE_FROM_TMP): { return executeSwUpdate(SwUpdateSources::TMP_DIR, data, size); } + case (ENABLE_AUTO_SWITCH): { + if (size < 2) { + return HasActionsIF::INVALID_PARAMETERS; + } + uint8_t chip = data[0]; + uint8_t copy = data[1]; + if (chip > 1 or copy > 1) { + return HasActionsIF::INVALID_PARAMETERS; + } + std::string value = std::to_string(chip) + std::to_string(copy); + ReturnValue_t result = scratch::writeString(scratch::AUTO_SWITCH_IMAGE, value); + if (result == returnvalue::OK) { + return EXECUTION_FINISHED; + } + return result; + } + case (DISABLE_AUTO_SWITCH): { + ReturnValue_t result = scratch::clearValue(scratch::AUTO_SWITCH_IMAGE); + if (result != returnvalue::OK and result != scratch::KEY_NOT_FOUND) { + return result; + } + return EXECUTION_FINISHED; + } case (SWITCH_TO_SD_0): { if (not startSdStateMachine(sd::SdCard::SLOT_0, SdCfgMode::COLD_REDUNDANT, commandedBy, actionId)) { diff --git a/bsp_q7s/memory/scratchApi.h b/bsp_q7s/memory/scratchApi.h index 1221f328..fd8b94cd 100644 --- a/bsp_q7s/memory/scratchApi.h +++ b/bsp_q7s/memory/scratchApi.h @@ -19,6 +19,7 @@ namespace scratch { static constexpr char PREFERED_SDC_KEY[] = "PREFSD"; static constexpr char ALLOC_FAILURE_COUNT[] = "ALLOCERR"; +static constexpr char AUTO_SWITCH_IMAGE[] = "ASWI"; static constexpr uint8_t INTERFACE_ID = CLASS_ID::SCRATCH_BUFFER; static constexpr ReturnValue_t KEY_NOT_FOUND = returnvalue::makeCode(INTERFACE_ID, 0); diff --git a/bsp_q7s/obsw.cpp b/bsp_q7s/obsw.cpp index a69953d9..f6334b65 100644 --- a/bsp_q7s/obsw.cpp +++ b/bsp_q7s/obsw.cpp @@ -1,5 +1,6 @@ #include "obsw.h" +#include #include #include #include @@ -10,16 +11,15 @@ #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" +#include "memory/scratchApi.h" #include "mission/acs/defs.h" #include "mission/com/defs.h" #include "mission/system/systemTree.h" #include "q7sConfig.h" #include "scheduling.h" -#include #include "watchdog/definitions.h" static constexpr int OBSW_ALREADY_RUNNING = -2; @@ -89,20 +89,21 @@ int obsw::obsw(int argc, char* argv[]) { 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); + scratch::clearValue(scratch::AUTO_SWITCH_IMAGE); + xsc_boot_copy(chip, copy); }; - if (scratch::readString("ASWI", autoSwitchTarget) == returnvalue::OK) { + if (scratch::readString(scratch::AUTO_SWITCH_IMAGE, 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") { + } 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; + sif::warning << "Invalid Auto Switch Image (ASWI) value detected: " << autoSwitchTarget + << std::endl; } } } diff --git a/mission/sysDefs.h b/mission/sysDefs.h index 8fade60a..0d35855f 100644 --- a/mission/sysDefs.h +++ b/mission/sysDefs.h @@ -75,6 +75,8 @@ static constexpr ActionId_t OBSW_UPDATE_FROM_TMP = 12; static constexpr ActionId_t SWITCH_TO_SD_0 = 16; static constexpr ActionId_t SWITCH_TO_SD_1 = 17; static constexpr ActionId_t SWITCH_TO_BOTH_SD_CARDS = 18; +static constexpr ActionId_t ENABLE_AUTO_SWITCH = 19; +static constexpr ActionId_t DISABLE_AUTO_SWITCH = 20; //! Reboot using the xsc_boot_copy command static constexpr ActionId_t XSC_REBOOT_OBC = 32; -- 2.34.1 From befe7ec441843dca3c434b8e79ae85f8cfdb5cdd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 19 Oct 2023 15:06:26 +0200 Subject: [PATCH 3/9] bump tmtc --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 60f7ae54..728b7c64 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 60f7ae5453b387ee5ebcf6a338c34284004dbce7 +Subproject commit 728b7c647cf826d0dd751126935c1cb559aa16ee -- 2.34.1 From fecaad7af72fc473907d08c645107dbba5226cf8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 19 Oct 2023 15:18:06 +0200 Subject: [PATCH 4/9] better printout --- bsp_q7s/obsw.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bsp_q7s/obsw.cpp b/bsp_q7s/obsw.cpp index f6334b65..d32579b4 100644 --- a/bsp_q7s/obsw.cpp +++ b/bsp_q7s/obsw.cpp @@ -89,6 +89,9 @@ int obsw::obsw(int argc, char* argv[]) { void obsw::autoSwitchHandling() { std::string autoSwitchTarget; auto switchToTarget = [](xsc_libnor_chip_t chip, xsc_libnor_copy_t copy) { + sif::debug << "Detected ASWI=" << autoSwitchTarget + << "in ProASIC scratch buffer, auto-switching to image " << int(chip) << " " + << int(copy) << std::endl; scratch::clearValue(scratch::AUTO_SWITCH_IMAGE); xsc_boot_copy(chip, copy); }; -- 2.34.1 From 674202c6fb61df531b08f6cc28f07a67cbd2fb5d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 19 Oct 2023 15:18:39 +0200 Subject: [PATCH 5/9] delay --- bsp_q7s/obsw.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bsp_q7s/obsw.cpp b/bsp_q7s/obsw.cpp index d32579b4..77ac13c4 100644 --- a/bsp_q7s/obsw.cpp +++ b/bsp_q7s/obsw.cpp @@ -92,6 +92,8 @@ void obsw::autoSwitchHandling() { sif::debug << "Detected ASWI=" << autoSwitchTarget << "in ProASIC scratch buffer, auto-switching to image " << int(chip) << " " << int(copy) << std::endl; + // A bit of delay to ensure printout works.. + TaskFactory::delayTask(500); scratch::clearValue(scratch::AUTO_SWITCH_IMAGE); xsc_boot_copy(chip, copy); }; -- 2.34.1 From f0ade7274abb59e50e55ccaa2d09e20296b51ace Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 19 Oct 2023 15:23:23 +0200 Subject: [PATCH 6/9] works --- bsp_q7s/obsw.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bsp_q7s/obsw.cpp b/bsp_q7s/obsw.cpp index 77ac13c4..60ededab 100644 --- a/bsp_q7s/obsw.cpp +++ b/bsp_q7s/obsw.cpp @@ -88,10 +88,10 @@ int obsw::obsw(int argc, char* argv[]) { void obsw::autoSwitchHandling() { std::string autoSwitchTarget; - auto switchToTarget = [](xsc_libnor_chip_t chip, xsc_libnor_copy_t copy) { - sif::debug << "Detected ASWI=" << autoSwitchTarget - << "in ProASIC scratch buffer, auto-switching to image " << int(chip) << " " - << int(copy) << std::endl; + auto switchToTarget = [&](xsc_libnor_chip_t chip, xsc_libnor_copy_t copy) { + sif::warning << "Detected ASWI=" << autoSwitchTarget + << " in ProASIC scratch buffer, auto-switching to image " << int(chip) << " " + << int(copy) << std::endl; // A bit of delay to ensure printout works.. TaskFactory::delayTask(500); scratch::clearValue(scratch::AUTO_SWITCH_IMAGE); -- 2.34.1 From 18bcb434e943ffc4b75f92efdc6588dcd90383ba Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 19 Oct 2023 15:24:52 +0200 Subject: [PATCH 7/9] tiny tweak --- bsp_q7s/obsw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp_q7s/obsw.cpp b/bsp_q7s/obsw.cpp index 60ededab..5cf1849a 100644 --- a/bsp_q7s/obsw.cpp +++ b/bsp_q7s/obsw.cpp @@ -92,9 +92,9 @@ void obsw::autoSwitchHandling() { sif::warning << "Detected ASWI=" << autoSwitchTarget << " in ProASIC scratch buffer, auto-switching to image " << int(chip) << " " << int(copy) << std::endl; + scratch::clearValue(scratch::AUTO_SWITCH_IMAGE); // A bit of delay to ensure printout works.. TaskFactory::delayTask(500); - scratch::clearValue(scratch::AUTO_SWITCH_IMAGE); xsc_boot_copy(chip, copy); }; if (scratch::readString(scratch::AUTO_SWITCH_IMAGE, autoSwitchTarget) == returnvalue::OK) { -- 2.34.1 From 4fd18e94fd890f0d67ba5e1c535afb27fe83f2f6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 23 Oct 2023 13:30:45 +0200 Subject: [PATCH 8/9] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9308d71d..1ddfd538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ will consitute of a breaking change warranting a new major release: CFDP interface. - Proper back pressure handling for the CFDP handler, where the `LiveTmTask` is able to throttle the CFDP handler. +- Added a new 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. ## Fixed -- 2.34.1 From 4e0842c607955e6d85bd3b09fa701ac49cd48aa5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 23 Oct 2023 13:39:47 +0200 Subject: [PATCH 9/9] add link --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ddfd538..4f9bd66f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ will consitute of a breaking change warranting a new major release: - Added a new 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. + See more information [here](https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/OBC_Auto_Switch_Image) ## Fixed -- 2.34.1