memory check always based on file now
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-08-22 13:50:24 +02:00
parent b3bb029c47
commit 663b65f159
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
6 changed files with 127 additions and 59 deletions

View File

@ -60,7 +60,7 @@ static const DeviceCommandId_t REQUEST_ADC_REPORT = 57;
static const DeviceCommandId_t RESET_PL = 58; static const DeviceCommandId_t RESET_PL = 58;
static const DeviceCommandId_t ENABLE_NVMS = 59; static const DeviceCommandId_t ENABLE_NVMS = 59;
static const DeviceCommandId_t CONTINUE_UPDATE = 60; static const DeviceCommandId_t CONTINUE_UPDATE = 60;
static const DeviceCommandId_t MEMORY_CHECK = 61; static const DeviceCommandId_t MEMORY_CHECK_WITH_FILE = 61;
/** Reply IDs */ /** Reply IDs */
static const DeviceCommandId_t ACK_REPORT = 100; static const DeviceCommandId_t ACK_REPORT = 100;

View File

@ -1,5 +1,7 @@
#include "PlocSupervisorHandler.h" #include "PlocSupervisorHandler.h"
#include <fsfw/memory/HasFileSystemIF.h>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -132,27 +134,16 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId,
plocSupvHelperExecuting = true; plocSupvHelperExecuting = true;
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
case MEMORY_CHECK: { case MEMORY_CHECK_WITH_FILE: {
size_t deserLen = 9; UpdateParams params;
uint8_t memId; ReturnValue_t result = extractBaseParams(&data, size, params);
uint32_t startAddr;
uint32_t sizeToCheck;
result =
SerializeAdapter::deSerialize(&memId, &data, &deserLen, SerializeIF::Endianness::NETWORK);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
result = SerializeAdapter::deSerialize(&startAddr, &data, &deserLen, if (not std::filesystem::exists(params.file)) {
SerializeIF::Endianness::NETWORK); return HasFileSystemIF::FILE_DOES_NOT_EXIST;
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
} }
result = SerializeAdapter::deSerialize(&sizeToCheck, &data, &deserLen, supvHelper->performMemCheck(params.file, params.memId, params.startAddr);
SerializeIF::Endianness::NETWORK);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
supvHelper->performMemCheck(memId, startAddr, sizeToCheck);
plocSupvHelperExecuting = true; plocSupvHelperExecuting = true;
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
@ -886,7 +877,9 @@ void PlocSupervisorHandler::handleEvent(EventMessage* eventMessage) {
if (event == PlocSupvHelper::SUPV_UPDATE_FAILED || if (event == PlocSupvHelper::SUPV_UPDATE_FAILED ||
event == PlocSupvHelper::SUPV_UPDATE_SUCCESSFUL || event == PlocSupvHelper::SUPV_UPDATE_SUCCESSFUL ||
event == PlocSupvHelper::SUPV_CONTINUE_UPDATE_FAILED || event == PlocSupvHelper::SUPV_CONTINUE_UPDATE_FAILED ||
event == PlocSupvHelper::SUPV_CONTINUE_UPDATE_SUCCESSFUL) { event == PlocSupvHelper::SUPV_CONTINUE_UPDATE_SUCCESSFUL ||
event == PlocSupvHelper::SUPV_MEM_CHECK_FAIL ||
event == PlocSupvHelper::SUPV_MEM_CHECK_OK) {
result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0); result = this->executeAction(supv::SHUTDOWN_MPSOC, NO_COMMANDER, nullptr, 0);
if (result != RETURN_OK) { if (result != RETURN_OK) {
triggerEvent(SUPV_MPSOC_SHUWDOWN_BUILD_FAILED); triggerEvent(SUPV_MPSOC_SHUWDOWN_BUILD_FAILED);
@ -1998,30 +1991,15 @@ ReturnValue_t PlocSupervisorHandler::getTimeStampString(std::string& timeStamp)
ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* commandData, size_t size, ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* commandData, size_t size,
UpdateParams& params) { UpdateParams& params) {
ReturnValue_t result = RETURN_OK; size_t remSize = size;
if (size > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE + sizeof(params.memId)) + if (size > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE + sizeof(params.memId)) +
sizeof(params.startAddr)) { sizeof(params.startAddr) + sizeof(params.bytesWritten) + sizeof(params.seqCount)) {
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Data size too big" << std::endl; sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Data size too big" << std::endl;
return SupvReturnValuesIF::INVALID_LENGTH; return SupvReturnValuesIF::INVALID_LENGTH;
} }
params.file = std::string(reinterpret_cast<const char*>(commandData)); ReturnValue_t result = RETURN_OK;
if (params.file.size() > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE)) { result = extractBaseParams(&commandData, size, params);
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Filename too long" << std::endl; result = SerializeAdapter::deSerialize(&params.bytesWritten, &commandData, &remSize,
return SupvReturnValuesIF::FILENAME_TOO_LONG;
}
params.memId = *(commandData + params.file.size() + SIZE_NULL_TERMINATOR);
const uint8_t* startAddressPtr =
commandData + params.file.size() + SIZE_NULL_TERMINATOR + sizeof(params.memId);
size_t remainingSize = 10;
result = SerializeAdapter::deSerialize(&params.startAddr, &startAddressPtr, &remainingSize,
SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::warning
<< "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize start address"
<< std::endl;
return result;
}
result = SerializeAdapter::deSerialize(&params.bytesWritten, &startAddressPtr, &remainingSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize bytes " sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Failed to deserialize bytes "
@ -2029,7 +2007,7 @@ ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* command
<< std::endl; << std::endl;
return result; return result;
} }
result = SerializeAdapter::deSerialize(&params.seqCount, &startAddressPtr, &remainingSize, result = SerializeAdapter::deSerialize(&params.seqCount, &commandData, &remSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning sif::warning
@ -2040,6 +2018,38 @@ ReturnValue_t PlocSupervisorHandler::extractUpdateCommand(const uint8_t* command
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t PlocSupervisorHandler::extractBaseParams(const uint8_t** commandData, size_t& remSize,
UpdateParams& params) {
bool nullTermFound = false;
for (size_t idx = 0; idx < remSize; idx++) {
if ((*commandData)[idx] == '\0') {
nullTermFound = true;
break;
}
}
if (not nullTermFound) {
return HasReturnvaluesIF::RETURN_FAILED;
}
params.file = std::string(reinterpret_cast<const char*>(*commandData));
if (params.file.size() > (config::MAX_FILENAME_SIZE + config::MAX_PATH_SIZE)) {
sif::warning << "PlocSupervisorHandler::extractUpdateCommand: Filename too long" << std::endl;
return SupvReturnValuesIF::FILENAME_TOO_LONG;
}
*commandData += params.file.size() + SIZE_NULL_TERMINATOR;
remSize -= (params.file.size() + SIZE_NULL_TERMINATOR);
params.memId = **commandData;
*commandData += 1;
remSize -= 1;
ReturnValue_t result = SerializeAdapter::deSerialize(&params.startAddr, commandData, &remSize,
SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::warning << "PlocSupervisorHandler::extractBaseParams: Failed to deserialize start address"
<< std::endl;
return result;
}
return result;
}
ReturnValue_t PlocSupervisorHandler::eventSubscription() { ReturnValue_t PlocSupervisorHandler::eventSubscription() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER); EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);

View File

@ -376,6 +376,8 @@ class PlocSupervisorHandler : public DeviceHandlerBase {
}; };
ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size, UpdateParams& params); ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size, UpdateParams& params);
ReturnValue_t extractBaseParams(const uint8_t** commandData, size_t& remSize,
UpdateParams& params);
ReturnValue_t eventSubscription(); ReturnValue_t eventSubscription();
ReturnValue_t handleExecutionSuccessReport(const uint8_t* data); ReturnValue_t handleExecutionSuccessReport(const uint8_t* data);

View File

@ -58,9 +58,7 @@ ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) {
break; break;
} }
case InternalState::CHECK_MEMORY: { case InternalState::CHECK_MEMORY: {
sif::info << "PlocSupvHelper::performUpdate: Memory Check" << std::endl; executeFullCheckMemoryCommand();
result = handleCheckMemoryCommand();
triggerEvent(SUPV_MEM_CHECK_STATUS, result);
internalState = InternalState::IDLE; internalState = InternalState::IDLE;
break; break;
} }
@ -150,11 +148,18 @@ ReturnValue_t PlocSupvHelper::performUpdate(std::string file, uint8_t memoryId,
return result; return result;
} }
ReturnValue_t PlocSupvHelper::performMemCheck(std::string file, uint8_t memoryId,
uint32_t startAddress) {
update.file = file;
return performMemCheck(memoryId, startAddress, getFileSize(update.file), true);
}
ReturnValue_t PlocSupvHelper::performMemCheck(uint8_t memoryId, uint32_t startAddress, ReturnValue_t PlocSupvHelper::performMemCheck(uint8_t memoryId, uint32_t startAddress,
size_t sizeToCheck) { size_t sizeToCheck, bool checkCrc) {
update.memoryId = memoryId; update.memoryId = memoryId;
update.startAddress = startAddress; update.startAddress = startAddress;
update.length = sizeToCheck; update.length = sizeToCheck;
update.crcShouldBeChecked = checkCrc;
internalState = InternalState::CHECK_MEMORY; internalState = InternalState::CHECK_MEMORY;
uartComIF->flushUartTxAndRxBuf(comCookie); uartComIF->flushUartTxAndRxBuf(comCookie);
semaphore.release(); semaphore.release();
@ -185,6 +190,37 @@ ReturnValue_t PlocSupvHelper::startEventbBufferRequest(std::string path) {
void PlocSupvHelper::stopProcess() { terminate = true; } void PlocSupvHelper::stopProcess() { terminate = true; }
void PlocSupvHelper::executeFullCheckMemoryCommand() {
ReturnValue_t result;
if (update.crcShouldBeChecked) {
sif::info << "PlocSupvHelper::performUpdate: Calculating Image CRC" << std::endl;
result = calcImageCrc();
if (result != RETURN_OK) {
triggerEvent(SUPV_MEM_CHECK_FAIL, result);
return;
}
}
sif::info << "PlocSupvHelper::executeFullCheckMemoryCommand: Selecting Memory" << std::endl;
result = selectMemory();
if (result != RETURN_OK) {
triggerEvent(SUPV_MEM_CHECK_FAIL, result);
return;
}
sif::info << "PlocSupvHelper::executeFullCheckMemoryCommand: Preparing Update" << std::endl;
result = prepareUpdate();
if (result != RETURN_OK) {
triggerEvent(SUPV_MEM_CHECK_FAIL, result);
return;
}
sif::info << "PlocSupvHelper::executeFullCheckMemoryCommand: Memory Check" << std::endl;
result = handleCheckMemoryCommand();
if (result == HasReturnvaluesIF::RETURN_OK) {
triggerEvent(SUPV_MEM_CHECK_OK, result);
} else {
triggerEvent(SUPV_MEM_CHECK_FAIL, result);
}
}
ReturnValue_t PlocSupvHelper::performUpdate() { ReturnValue_t PlocSupvHelper::performUpdate() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
sif::info << "PlocSupvHelper::performUpdate: Calculating Image CRC" << std::endl; sif::info << "PlocSupvHelper::performUpdate: Calculating Image CRC" << std::endl;
@ -471,7 +507,7 @@ ReturnValue_t PlocSupvHelper::exeReportHandling() {
} }
return result; return result;
} }
return exeReportHandling(); return result;
} }
ReturnValue_t PlocSupvHelper::handleTmReception(size_t remainingBytes, uint8_t* readBuf, ReturnValue_t PlocSupvHelper::handleTmReception(size_t remainingBytes, uint8_t* readBuf,
@ -542,15 +578,19 @@ ReturnValue_t PlocSupvHelper::receive(uint8_t* data, size_t* readBytes, size_t r
ReturnValue_t PlocSupvHelper::calcImageCrc() { ReturnValue_t PlocSupvHelper::calcImageCrc() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
if (update.length == 0) {
return HasReturnvaluesIF::RETURN_FAILED;
}
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
result = FilesystemHelper::checkPath(update.file); result = FilesystemHelper::checkPath(update.file);
#endif
auto crc16Calcer = etl::crc16_ccitt();
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::calcImageCrc: File " << update.file << " does not exist" sif::warning << "PlocSupvHelper::calcImageCrc: File " << update.file << " does not exist"
<< std::endl; << std::endl;
return result; return result;
} }
#endif
auto crc16Calcer = etl::crc16_ccitt();
std::ifstream file(update.file, std::ifstream::binary); std::ifstream file(update.file, std::ifstream::binary);
std::array<uint8_t, 1025> crcBuf; std::array<uint8_t, 1025> crcBuf;
#if OBSW_DEBUG_PLOC_SUPERVISOR == 1 #if OBSW_DEBUG_PLOC_SUPERVISOR == 1
@ -586,7 +626,7 @@ ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() {
resetSpParams(); resetSpParams();
// Will hold status report for later processing // Will hold status report for later processing
std::array<uint8_t, 32> statusReportBuf{}; std::array<uint8_t, 32> statusReportBuf{};
supv::UpdateStatusReport updateStatusReport(statusReportBuf.data(), statusReportBuf.size()); supv::UpdateStatusReport updateStatusReport(tmBuf.data(), tmBuf.size());
// Verification of update write procedure // Verification of update write procedure
supv::CheckMemory packet(spParams); supv::CheckMemory packet(spParams);
result = packet.buildPacket(update.memoryId, update.startAddress, update.length); result = packet.buildPacket(update.memoryId, update.startAddress, update.length);
@ -611,7 +651,10 @@ ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() {
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Reading exe failure report failed" << std::endl; sif::warning << "Reading exe failure report failed" << std::endl;
} }
return exeReportHandling(); result = exeReportHandling();
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Handling exe report failed" << std::endl;
}
} else if (spReader.getApid() == supv::APID_UPDATE_STATUS_REPORT) { } else if (spReader.getApid() == supv::APID_UPDATE_STATUS_REPORT) {
size_t remBytes = spReader.getPacketDataLen() + 1; size_t remBytes = spReader.getPacketDataLen() + 1;
result = handleTmReception(remBytes, tmBuf.data() + ccsds::HEADER_LEN); result = handleTmReception(remBytes, tmBuf.data() + ccsds::HEADER_LEN);
@ -623,9 +666,11 @@ ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() {
} }
result = updateStatusReport.checkCrc(); result = updateStatusReport.checkCrc();
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::handleTmReception: CRC check failed" << std::endl; sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: CRC check failed" << std::endl;
return result; return result;
} }
// Copy into other buffer because data will be overwritten when reading execution report
std::memcpy(statusReportBuf.data(), tmBuf.data(), updateStatusReport.getNominalSize());
} }
result = handleExe(CRC_EXECUTION_TIMEOUT); result = handleExe(CRC_EXECUTION_TIMEOUT);
@ -634,17 +679,21 @@ ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() {
} }
// Now process the status report // Now process the status report
updateStatusReport.setData(statusReportBuf.data(), statusReportBuf.size());
result = updateStatusReport.parseDataField(); result = updateStatusReport.parseDataField();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
if (update.crcShouldBeChecked) {
result = updateStatusReport.verifycrc(update.crc); result = updateStatusReport.verifycrc(update.crc);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: CRC failure. Expected CRC 0x" sif::warning << "PlocSupvHelper::handleCheckMemoryCommand: CRC failure. Expected CRC 0x"
<< std::hex << update.crc << " but received CRC 0x" << updateStatusReport.getCrc() << std::setfill('0') << std::hex << std::setw(4)
<< std::endl; << static_cast<uint16_t>(update.crc) << " but received CRC 0x" << std::setw(4)
<< updateStatusReport.getCrc() << std::dec << std::endl;
return result; return result;
} }
}
return result; return result;
} }

View File

@ -94,7 +94,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
static constexpr Event SUPV_UPDATE_PROGRESS = MAKE_EVENT(22, severity::INFO); static constexpr Event SUPV_UPDATE_PROGRESS = MAKE_EVENT(22, severity::INFO);
//! Status of memory check command //! Status of memory check command
//! P1: Returncode, 0 for success, other value with returncode for failure //! P1: Returncode, 0 for success, other value with returncode for failure
static constexpr Event SUPV_MEM_CHECK_STATUS = MAKE_EVENT(23, severity::INFO); static constexpr Event SUPV_MEM_CHECK_OK = MAKE_EVENT(23, severity::INFO);
static constexpr Event SUPV_MEM_CHECK_FAIL = MAKE_EVENT(24, severity::INFO);
PlocSupvHelper(object_id_t objectId); PlocSupvHelper(object_id_t objectId);
virtual ~PlocSupvHelper(); virtual ~PlocSupvHelper();
@ -118,7 +119,10 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
size_t startBytesWritten, uint16_t initSeqCount); size_t startBytesWritten, uint16_t initSeqCount);
ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress); ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress);
ReturnValue_t performMemCheck(uint8_t memoryId, uint32_t startAddress, size_t sizeToCheck); ReturnValue_t performMemCheck(uint8_t memoryId, uint32_t startAddress, size_t sizeToCheck,
bool checkCrc);
ReturnValue_t performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress);
/** /**
* @brief This initiate the continuation of a failed update. * @brief This initiate the continuation of a failed update.
*/ */
@ -165,6 +169,7 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
// Size of update // Size of update
uint32_t length; uint32_t length;
uint32_t crc; uint32_t crc;
bool crcShouldBeChecked = false;
// size_t remainingSize; // size_t remainingSize;
size_t bytesWritten; size_t bytesWritten;
uint32_t packetNum; uint32_t packetNum;
@ -211,6 +216,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha
// Remembers APID to know at which command a procedure failed // Remembers APID to know at which command a procedure failed
uint16_t rememberApid = 0; uint16_t rememberApid = 0;
void executeFullCheckMemoryCommand();
ReturnValue_t performUpdate(); ReturnValue_t performUpdate();
ReturnValue_t continueUpdate(); ReturnValue_t continueUpdate();
ReturnValue_t updateOperation(); ReturnValue_t updateOperation();

2
tmtc

@ -1 +1 @@
Subproject commit 425870d16150f5b99e8e450ac892104e557aff20 Subproject commit 56514759551204c20687c393f463e74204b821f2