safety mechanism on reboots #308

Merged
meierj merged 5 commits from mueller/sdc-safety-mechanism-on-reboot into develop 2022-10-25 14:34:00 +02:00
10 changed files with 82 additions and 7 deletions

View File

@ -3,6 +3,7 @@
#include <fsfw/events/EventManager.h> #include <fsfw/events/EventManager.h>
#include <fsfw/filesystem/HasFileSystemIF.h> #include <fsfw/filesystem/HasFileSystemIF.h>
#include <fsfw/ipc/QueueFactory.h> #include <fsfw/ipc/QueueFactory.h>
#include <fsfw/tasks/TaskFactory.h>
#include "OBSWVersion.h" #include "OBSWVersion.h"
#include "fsfw/serviceinterface/ServiceInterface.h" #include "fsfw/serviceinterface/ServiceInterface.h"
@ -932,6 +933,9 @@ ReturnValue_t CoreController::actionReboot(const uint8_t *data, size_t size) {
ReturnValue_t CoreController::gracefulShutdownTasks(xsc::Chip chip, xsc::Copy copy, ReturnValue_t CoreController::gracefulShutdownTasks(xsc::Chip chip, xsc::Copy copy,
bool &protOpPerformed) { bool &protOpPerformed) {
sdcMan->setBlocking(true); sdcMan->setBlocking(true);
sdcMan->markUnusable();
// Wait two seconds to ensure no one uses the SD cards
TaskFactory::delayTask(2000);
// Attempt graceful shutdown by unmounting and switching off SD cards // Attempt graceful shutdown by unmounting and switching off SD cards
sdcMan->switchOffSdCard(sd::SdCard::SLOT_0); sdcMan->switchOffSdCard(sd::SdCard::SLOT_0);
sdcMan->switchOffSdCard(sd::SdCard::SLOT_1); sdcMan->switchOffSdCard(sd::SdCard::SLOT_1);

View File

@ -459,7 +459,14 @@ void SdCardManager::setBlocking(bool blocking) { this->blocking = blocking; }
void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = print; } void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = print; }
bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) { bool SdCardManager::isSdCardUsable(std::optional<sd::SdCard> sdCard) {
{
MutexGuard mg(mutex);
if (markedUnusable) {
return false;
}
}
SdCardManager::SdStatePair active; SdCardManager::SdStatePair active;
ReturnValue_t result = this->getSdCardsStatus(active); ReturnValue_t result = this->getSdCardsStatus(active);
@ -467,20 +474,30 @@ bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) {
sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state"; sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state";
return false; return false;
} }
if (not sdCard) {
if (active.first == sd::MOUNTED or active.second == sd::MOUNTED) {
return true;
}
return false;
}
if (sdCard == sd::SLOT_0) { if (sdCard == sd::SLOT_0) {
if (active.first == sd::MOUNTED) { if (active.first == sd::MOUNTED) {
return true; return true;
} else { } else {
return false; return false;
} }
} else if (sdCard == sd::SLOT_1) { }
if (sdCard == sd::SLOT_1) {
if (active.second == sd::MOUNTED) { if (active.second == sd::MOUNTED) {
return true; return true;
} else { } else {
return false; return false;
} }
} else { }
sif::debug << "SdCardManager::isSdCardMounted: Unknown SD card specified" << std::endl; if (sdCard == sd::BOTH) {
if (active.first == sd::MOUNTED && active.second == sd::MOUNTED) {
return true;
}
} }
return false; return false;
} }
@ -560,5 +577,13 @@ void SdCardManager::setActiveSdCard(sd::SdCard sdCard) {
std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const { std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const {
MutexGuard mg(mutex); MutexGuard mg(mutex);
if (markedUnusable) {
return std::nullopt;
}
return sdInfo.active; return sdInfo.active;
} }
void SdCardManager::markUnusable() {
MutexGuard mg(mutex);
markedUnusable = true;
}

View File

@ -206,7 +206,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
* *
* @return true if mounted, otherwise false * @return true if mounted, otherwise false
*/ */
bool isSdCardUsable(sd::SdCard sdCard) override; bool isSdCardUsable(std::optional<sd::SdCard> sdCard) override;
ReturnValue_t isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly); ReturnValue_t isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly);
@ -214,12 +214,15 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
ReturnValue_t performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError); ReturnValue_t performFsck(sd::SdCard sdcard, bool printOutput, int& linuxError);
void markUnusable();
private: private:
CommandExecutor cmdExecutor; CommandExecutor cmdExecutor;
Operations currentOp = Operations::IDLE; Operations currentOp = Operations::IDLE;
bool blocking = false; bool blocking = false;
bool sdCardActive = true; bool sdCardActive = true;
bool printCmdOutput = true; bool printCmdOutput = true;
bool markedUnusable = false;
MutexIF* mutex = nullptr; MutexIF* mutex = nullptr;
SdCardManager(); SdCardManager();

2
fsfw

@ -1 +1 @@
Subproject commit b0c5a49b504708ec9130228100d7bbd49025598d Subproject commit 1f05e6b297af8a6d310394e959c4d0cf13632831

View File

@ -1917,6 +1917,11 @@ ReturnValue_t PlocSupervisorHandler::checkMramPacketApid() {
} }
ReturnValue_t PlocSupervisorHandler::handleMramDumpFile(DeviceCommandId_t id) { ReturnValue_t PlocSupervisorHandler::handleMramDumpFile(DeviceCommandId_t id) {
#ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
#endif
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
uint16_t packetLen = readSpacePacketLength(spacePacketBuffer); uint16_t packetLen = readSpacePacketLength(spacePacketBuffer);
uint8_t sequenceFlags = readSequenceFlags(spacePacketBuffer); uint8_t sequenceFlags = readSequenceFlags(spacePacketBuffer);

View File

@ -1,6 +1,7 @@
#include "PlocSupvHelper.h" #include "PlocSupvHelper.h"
#include <etl/crc16_ccitt.h> #include <etl/crc16_ccitt.h>
#include <fsfw/filesystem/HasFileSystemIF.h>
#include <cmath> #include <cmath>
#include <filesystem> #include <filesystem>
@ -748,6 +749,11 @@ uint32_t PlocSupvHelper::getFileSize(std::string filename) {
ReturnValue_t PlocSupvHelper::handleEventBufferReception(ploc::SpTmReader& reader) { ReturnValue_t PlocSupvHelper::handleEventBufferReception(ploc::SpTmReader& reader) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
#ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
#endif
std::string filename = Filenaming::generateAbsoluteFilename( std::string filename = Filenaming::generateAbsoluteFilename(
eventBufferReq.path, eventBufferReq.filename, timestamping); eventBufferReq.path, eventBufferReq.filename, timestamping);
std::ofstream file(filename, std::ios_base::app | std::ios_base::out); std::ofstream file(filename, std::ios_base::app | std::ios_base::out);

View File

@ -1,5 +1,7 @@
#include "StrHelper.h" #include "StrHelper.h"
#include <fsfw/filesystem/HasFileSystemIF.h>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@ -176,6 +178,11 @@ void StrHelper::disableTimestamping() { timestamping = false; }
void StrHelper::enableTimestamping() { timestamping = true; } void StrHelper::enableTimestamping() { timestamping = true; }
ReturnValue_t StrHelper::performImageDownload() { ReturnValue_t StrHelper::performImageDownload() {
#ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
#endif
ReturnValue_t result; ReturnValue_t result;
#if OBSW_DEBUG_STARTRACKER == 1 #if OBSW_DEBUG_STARTRACKER == 1
ProgressPrinter progressPrinter("Image download", ImageDownload::LAST_POSITION); ProgressPrinter progressPrinter("Image download", ImageDownload::LAST_POSITION);
@ -244,6 +251,11 @@ ReturnValue_t StrHelper::performImageUpload() {
uint32_t imageSize = 0; uint32_t imageSize = 0;
struct UploadActionRequest uploadReq; struct UploadActionRequest uploadReq;
uploadReq.position = 0; uploadReq.position = 0;
#ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
#endif
std::memset(&uploadReq.data, 0, sizeof(uploadReq.data)); std::memset(&uploadReq.data, 0, sizeof(uploadReq.data));
if (not std::filesystem::exists(uploadImage.uploadFile)) { if (not std::filesystem::exists(uploadImage.uploadFile)) {
triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState)); triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState));
@ -315,6 +327,11 @@ ReturnValue_t StrHelper::performFirmwareUpdate() {
} }
ReturnValue_t StrHelper::performFlashWrite() { ReturnValue_t StrHelper::performFlashWrite() {
#ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
#endif
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
uint32_t size = 0; uint32_t size = 0;
uint32_t bytesWritten = 0; uint32_t bytesWritten = 0;
@ -394,6 +411,11 @@ ReturnValue_t StrHelper::performFlashWrite() {
} }
ReturnValue_t StrHelper::performFlashRead() { ReturnValue_t StrHelper::performFlashRead() {
#ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
#endif
ReturnValue_t result; ReturnValue_t result;
#if OBSW_DEBUG_STARTRACKER == 1 #if OBSW_DEBUG_STARTRACKER == 1
ProgressPrinter progressPrinter("Flash read", flashRead.size); ProgressPrinter progressPrinter("Flash read", flashRead.size);

View File

@ -1,5 +1,6 @@
#include "ScexDeviceHandler.h" #include "ScexDeviceHandler.h"
#include <fsfw/filesystem/HasFileSystemIF.h>
#include <linux/devices/ScexHelper.h> #include <linux/devices/ScexHelper.h>
#include <mission/memory/SdCardMountedIF.h> #include <mission/memory/SdCardMountedIF.h>
@ -200,6 +201,10 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
ReturnValue_t status = OK; ReturnValue_t status = OK;
auto oneFileHandler = [&](std::string cmdName) { auto oneFileHandler = [&](std::string cmdName) {
auto activeSd = sdcMan.getActiveSdCard();
if (not activeSd) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
fileId = date_time_string(); fileId = date_time_string();
std::ostringstream oss; std::ostringstream oss;
auto prefix = sdcMan.getCurrentMountPrefix(); auto prefix = sdcMan.getCurrentMountPrefix();
@ -216,6 +221,10 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
}; };
auto multiFileHandler = [&](std::string cmdName) { auto multiFileHandler = [&](std::string cmdName) {
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) { if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
auto activeSd = sdcMan.getActiveSdCard();
if (not activeSd) {
return HasFileSystemIF::FILESYSTEM_INACTIVE;
}
fileId = date_time_string(); fileId = date_time_string();
std::ostringstream oss; std::ostringstream oss;
auto prefix = sdcMan.getCurrentMountPrefix(); auto prefix = sdcMan.getCurrentMountPrefix();

View File

@ -1,5 +1,6 @@
#include "SolarArrayDeploymentHandler.h" #include "SolarArrayDeploymentHandler.h"
#include <fsfw/filesystem/HasFileSystemIF.h>
#include <fsfw/tasks/TaskFactory.h> #include <fsfw/tasks/TaskFactory.h>
#include <filesystem> #include <filesystem>

View File

@ -10,7 +10,7 @@ class SdCardMountedIF {
public: public:
virtual ~SdCardMountedIF(){}; virtual ~SdCardMountedIF(){};
virtual const std::string& getCurrentMountPrefix() const = 0; virtual const std::string& getCurrentMountPrefix() const = 0;
virtual bool isSdCardUsable(sd::SdCard sdCard) = 0; virtual bool isSdCardUsable(std::optional<sd::SdCard> sdCard) = 0;
virtual std::optional<sd::SdCard> getPreferredSdCard() const = 0; virtual std::optional<sd::SdCard> getPreferredSdCard() const = 0;
virtual void setActiveSdCard(sd::SdCard sdCard) = 0; virtual void setActiveSdCard(sd::SdCard sdCard) = 0;
virtual std::optional<sd::SdCard> getActiveSdCard() const = 0; virtual std::optional<sd::SdCard> getActiveSdCard() const = 0;