From 1aeebcc0ee2dd049de8adc22f66a8253c8d64ff4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 23 Aug 2022 18:26:14 +0200 Subject: [PATCH] important bugfix for update conitnuation --- linux/devices/ploc/PlocSupvHelper.cpp | 37 +++++++++++++++++---------- linux/devices/ploc/PlocSupvHelper.h | 2 ++ tmtc | 2 +- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/linux/devices/ploc/PlocSupvHelper.cpp b/linux/devices/ploc/PlocSupvHelper.cpp index 6c195865..836e7fc0 100644 --- a/linux/devices/ploc/PlocSupvHelper.cpp +++ b/linux/devices/ploc/PlocSupvHelper.cpp @@ -135,7 +135,13 @@ ReturnValue_t PlocSupvHelper::performUpdate(std::string file, uint8_t memoryId, } #endif update.file = file; - update.length = getFileSize(update.file); + update.fullFileSize = getFileSize(update.file); + if (startBytesWritten > update.fullFileSize) { + sif::warning << "Invalid start bytes counter " << startBytesWritten + << ", smaller than full file length" << update.fullFileSize << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + update.length = update.fullFileSize - startBytesWritten; update.memoryId = memoryId; update.startAddress = startAddress; update.progressPercent = 0; @@ -152,6 +158,7 @@ ReturnValue_t PlocSupvHelper::performUpdate(std::string file, uint8_t memoryId, ReturnValue_t PlocSupvHelper::performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress) { update.file = file; + update.fullFileSize = getFileSize(file); return performMemCheck(memoryId, startAddress, getFileSize(update.file), true); } @@ -268,20 +275,20 @@ ReturnValue_t PlocSupvHelper::updateOperation() { ReturnValue_t PlocSupvHelper::writeUpdatePackets() { ReturnValue_t result = RETURN_OK; #if OBSW_DEBUG_PLOC_SUPERVISOR == 1 - ProgressPrinter progressPrinter("Supervisor update", update.length, + ProgressPrinter progressPrinter("Supervisor update", update.fullFileSize, ProgressPrinter::HALF_PERCENT); #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ uint8_t tempData[supv::WriteMemory::CHUNK_MAX + 1]{}; std::ifstream file(update.file, std::ifstream::binary); uint16_t dataLength = 0; ccsds::SequenceFlags seqFlags; - while (update.bytesWritten < update.length) { + while (update.bytesWritten < update.fullFileSize) { if (terminate) { terminate = false; triggerEvent(TERMINATED_UPDATE_PROCEDURE); return PROCESS_TERMINATED; } - size_t remainingSize = update.length - update.bytesWritten; + size_t remainingSize = update.fullFileSize - update.bytesWritten; bool lastSegment = false; if (remainingSize > supv::WriteMemory::CHUNK_MAX) { dataLength = supv::WriteMemory::CHUNK_MAX; @@ -309,7 +316,7 @@ ReturnValue_t PlocSupvHelper::writeUpdatePackets() { seqFlags = ccsds::SequenceFlags::CONTINUATION; } resetSpParams(); - float progress = static_cast(update.bytesWritten) / update.length; + float progress = static_cast(update.bytesWritten) / update.fullFileSize; uint8_t progPercent = std::floor(progress * 100); if (progPercent > update.progressPercent) { update.progressPercent = progPercent; @@ -410,7 +417,8 @@ ReturnValue_t PlocSupvHelper::eraseMemory() { ReturnValue_t result = RETURN_OK; resetSpParams(); supv::EraseMemory eraseMemory(spParams); - result = eraseMemory.buildPacket(update.memoryId, update.startAddress, update.length); + result = eraseMemory.buildPacket(update.memoryId, update.startAddress + update.bytesWritten, + update.length); if (result != RETURN_OK) { return result; } @@ -579,7 +587,7 @@ ReturnValue_t PlocSupvHelper::receive(uint8_t* data, size_t* readBytes, size_t r ReturnValue_t PlocSupvHelper::calcImageCrc() { ReturnValue_t result = RETURN_OK; - if (update.length == 0) { + if (update.fullFileSize == 0) { return HasReturnvaluesIF::RETURN_FAILED; } #ifdef XIPHOS_Q7S @@ -593,17 +601,19 @@ ReturnValue_t PlocSupvHelper::calcImageCrc() { auto crc16Calcer = etl::crc16_ccitt(); std::ifstream file(update.file, std::ifstream::binary); - std::array crcBuf; + std::array crcBuf{}; #if OBSW_DEBUG_PLOC_SUPERVISOR == 1 - ProgressPrinter progress("Supervisor update crc calculation", update.length, + ProgressPrinter progress("Supervisor update crc calculation", update.fullFileSize, ProgressPrinter::ONE_PERCENT); #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ uint32_t byteCount = 0; - while (byteCount < update.length) { - size_t bytesToRead = 1024; - size_t remLen = update.length - byteCount; + size_t bytesToRead = 1024; + while (byteCount < update.fullFileSize) { + size_t remLen = update.fullFileSize - byteCount; if (remLen < 1024) { bytesToRead = remLen; + } else { + bytesToRead = 1024; } file.seekg(byteCount, file.beg); file.read(reinterpret_cast(crcBuf.data()), bytesToRead); @@ -617,7 +627,6 @@ ReturnValue_t PlocSupvHelper::calcImageCrc() { #if OBSW_DEBUG_PLOC_SUPERVISOR == 1 progress.print(byteCount); #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ - file.close(); update.crc = crc16Calcer.value(); return result; } @@ -630,7 +639,7 @@ ReturnValue_t PlocSupvHelper::handleCheckMemoryCommand() { supv::UpdateStatusReport updateStatusReport(tmBuf.data(), tmBuf.size()); // Verification of update write procedure supv::CheckMemory packet(spParams); - result = packet.buildPacket(update.memoryId, update.startAddress, update.length); + result = packet.buildPacket(update.memoryId, update.startAddress, update.fullFileSize); if (result != RETURN_OK) { return result; } diff --git a/linux/devices/ploc/PlocSupvHelper.h b/linux/devices/ploc/PlocSupvHelper.h index abd43187..3fc60145 100644 --- a/linux/devices/ploc/PlocSupvHelper.h +++ b/linux/devices/ploc/PlocSupvHelper.h @@ -167,6 +167,8 @@ class PlocSupvHelper : public SystemObject, public ExecutableObjectIF, public Ha uint32_t startAddress; // Absolute name of file containing update data std::string file; + // Length of full file + size_t fullFileSize; // Size of update uint32_t length; uint32_t crc; diff --git a/tmtc b/tmtc index 61375956..aec55035 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 613759562ed855f692936bad5b25e8e2570dca52 +Subproject commit aec55035d7602226a2e61845565c94b5ed8f561c