WIP: Start impl auto switch feature #811

Closed
muellerr wants to merge 11 commits from auto-switch-image-feature into main
3 changed files with 31 additions and 1 deletions
Showing only changes of commit 2e210a0572 - Show all commits

View File

@ -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;

View File

@ -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 <libxiphos.h>
#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");

View File

@ -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();