diff options
-rw-r--r-- | src/Comms/PanelDueUpdater.cpp | 15 | ||||
-rw-r--r-- | src/Comms/PanelDueUpdater.h | 2 | ||||
-rw-r--r-- | src/GCodes/GCodes.cpp | 1 | ||||
-rw-r--r-- | src/GCodes/GCodes.h | 1 | ||||
-rw-r--r-- | src/GCodes/GCodes3.cpp | 2 | ||||
-rw-r--r-- | src/GCodes/GCodes4.cpp | 6 | ||||
-rw-r--r-- | src/bossa/Flasher.cpp | 148 | ||||
-rw-r--r-- | src/bossa/Flasher.h | 7 |
8 files changed, 79 insertions, 103 deletions
diff --git a/src/Comms/PanelDueUpdater.cpp b/src/Comms/PanelDueUpdater.cpp index 353f2458..373b9156 100644 --- a/src/Comms/PanelDueUpdater.cpp +++ b/src/Comms/PanelDueUpdater.cpp @@ -108,7 +108,7 @@ PanelDueUpdater::PanelDueUpdater() noexcept , offset(0) , erasedAndResetAt(0) , state(FlashState::idle) - , filename(nullptr) + , firmwareFile(nullptr) { } @@ -128,7 +128,7 @@ void PanelDueUpdater::Start(const StringRef& filenameRef, const uint32_t serialC return; } serialChannel = serialChan; - filename = filenameRef.IsEmpty() ? PANEL_DUE_FIRMWARE_FILE : filenameRef.c_str(); + firmwareFile = reprap.GetPlatform().OpenFile(FIRMWARE_DIRECTORY, filenameRef.IsEmpty() ? PANEL_DUE_FIRMWARE_FILE : filenameRef.c_str(), OpenMode::read); state = FlashState::eraseAndReset; } @@ -206,10 +206,11 @@ void PanelDueUpdater::Spin() noexcept case FlashState::bossaWrite: { - bool done = flasher->write(filename, FIRMWARE_DIRECTORY, offset); + bool done = flasher->write(firmwareFile, offset); if (done) { offset = 0; // Reset it for verification + firmwareFile->Seek(offset); state = FlashState::bossaVerify; flasherObserver->Reset(); } @@ -220,7 +221,7 @@ void PanelDueUpdater::Spin() noexcept { uint32_t pageErrors; uint32_t totalErrors; - bool done = flasher->verify(filename, FIRMWARE_DIRECTORY, pageErrors, totalErrors, offset); + bool done = flasher->verify(firmwareFile, pageErrors, totalErrors, offset); if (done && pageErrors == 0) { state = FlashState::bossaWriteOptions; @@ -286,7 +287,11 @@ void PanelDueUpdater::Spin() noexcept offset = 0; erasedAndResetAt = 0; - filename = nullptr; + if (firmwareFile != nullptr) + { + firmwareFile->Close(); + firmwareFile = nullptr; + } state = FlashState::idle; } diff --git a/src/Comms/PanelDueUpdater.h b/src/Comms/PanelDueUpdater.h index a92abfbd..a5387d02 100644 --- a/src/Comms/PanelDueUpdater.h +++ b/src/Comms/PanelDueUpdater.h @@ -62,7 +62,7 @@ private: uint32_t offset; uint32_t erasedAndResetAt; FlashState state; - const char* filename; + FileStore *firmwareFile; UARTClass* GetAuxPort() noexcept; }; diff --git a/src/GCodes/GCodes.cpp b/src/GCodes/GCodes.cpp index 6f9613d7..ed3ba46b 100644 --- a/src/GCodes/GCodes.cpp +++ b/src/GCodes/GCodes.cpp @@ -297,7 +297,6 @@ void GCodes::Reset() noexcept pausePending = filamentChangePausePending = false; moveBuffer.filePos = noFilePosition; firmwareUpdateModuleMap.Clear(); - filenameString.Clear(); isFlashing = false; isFlashingPanelDue = false; lastFilamentError = FilamentSensorStatus::ok; diff --git a/src/GCodes/GCodes.h b/src/GCodes/GCodes.h index 8e59d083..2799f0bb 100644 --- a/src/GCodes/GCodes.h +++ b/src/GCodes/GCodes.h @@ -636,7 +636,6 @@ private: // Firmware update Bitmap<uint8_t> firmwareUpdateModuleMap; // Bitmap of firmware modules to be updated - String<MaxFilenameLength> filenameString; // Filename for the current update bool isFlashing; // Is a new firmware binary going to be flashed? bool isFlashingPanelDue; // Are we in the process of flashing PanelDue? diff --git a/src/GCodes/GCodes3.cpp b/src/GCodes/GCodes3.cpp index a985a576..5fa8c600 100644 --- a/src/GCodes/GCodes3.cpp +++ b/src/GCodes/GCodes3.cpp @@ -1133,7 +1133,7 @@ GCodeResult GCodes::UpdateFirmware(GCodeBuffer& gb, const StringRef &reply) return GCodeResult::ok; // nothing to update } - filenameString.Clear(); + String<MaxFilenameLength> filenameString; if (gb.Seen('P')) { if (firmwareUpdateModuleMap.CountSetBits() > 1) diff --git a/src/GCodes/GCodes4.cpp b/src/GCodes/GCodes4.cpp index c5005067..b89c809a 100644 --- a/src/GCodes/GCodes4.cpp +++ b/src/GCodes/GCodes4.cpp @@ -469,6 +469,9 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept if (FirmwareUpdater::IsReady()) { bool updating = false; + String<MaxFilenameLength> filenameString; + bool dummy; + gb.TryGetQuotedString('P', filenameString.GetRef(), dummy); for (unsigned int module = 1; module < NumFirmwareUpdateModules; ++module) { if (firmwareUpdateModuleMap.IsBitSet(module)) @@ -506,6 +509,9 @@ void GCodes::RunStateMachine(GCodeBuffer& gb, const StringRef& reply) noexcept { // Update main firmware firmwareUpdateModuleMap.Clear(); + String<MaxFilenameLength> filenameString; + bool dummy; + gb.TryGetQuotedString('P', filenameString.GetRef(), dummy); reprap.UpdateFirmware(filenameString.GetRef()); // The above call does not return unless an error occurred } diff --git a/src/bossa/Flasher.cpp b/src/bossa/Flasher.cpp index 976906a0..774c00d6 100644 --- a/src/bossa/Flasher.cpp +++ b/src/bossa/Flasher.cpp @@ -44,7 +44,7 @@ void Flasher::erase(uint32_t foffset) THROWS(GCodeException) _flash->eraseAuto(false); } -bool Flasher::write(const char* filename, const char* dir, uint32_t& foffset) THROWS(GCodeException) +bool Flasher::write(FileStore *infile, uint32_t& foffset) THROWS(GCodeException) { uint32_t pageSize = _flash->pageSize(); uint32_t numPages; @@ -54,64 +54,48 @@ bool Flasher::write(const char* filename, const char* dir, uint32_t& foffset) TH { pageNum = 0; Platform& platform = reprap.GetPlatform(); - infile = platform.OpenFile(dir, filename, OpenMode::read); - if (infile == nullptr) - { - platform.MessageF(ErrorMessage, "Failed to open file %s\n", filename); - throw GCodeException(nullptr); - } if (infile->Length() == 0) { infile->Close(); - platform.MessageF(ErrorMessage, "Firmware file is empty %s\n", filename); + platform.MessageF(ErrorMessage, "Firmware file is empt\n"); throw GCodeException(nullptr); } } - try - { - - numPages = (infile->Length() + pageSize - 1) / pageSize; - if (foffset == 0) - { - if (numPages > _flash->numPages()) - { - throw FileSizeError("Flasher::write: FileSizeError"); - } + numPages = (infile->Length() + pageSize - 1) / pageSize; + if (foffset == 0) + { + if (numPages > _flash->numPages()) + { + throw FileSizeError("Flasher::write: FileSizeError"); + } - _observer.onStatus("Writing %ld bytes to PanelDue flash memory\n", infile->Length()); - } + _observer.onStatus("Writing %ld bytes to PanelDue flash memory\n", infile->Length()); + } - uint8_t buffer[pageSize]; - uint32_t pageOffset = foffset / pageSize; + uint8_t buffer[pageSize]; + uint32_t pageOffset = foffset / pageSize; - if ((fbytes = infile->Read((char*)buffer, pageSize)) > 0) - { - _observer.onProgress(pageNum, numPages); + if ((fbytes = infile->Read((char*)buffer, pageSize)) > 0) + { + _observer.onProgress(pageNum, numPages); - _flash->loadBuffer(buffer, fbytes); - _flash->writePage(pageOffset /* + pageNum */); - foffset += fbytes; + _flash->loadBuffer(buffer, fbytes); + _flash->writePage(pageOffset /* + pageNum */); + foffset += fbytes; - pageNum++; - if (!(pageNum == numPages || fbytes != (int)pageSize)) - { - return false; // We get back in the next PanelDueFlasher::Spin() iteration - } + pageNum++; + if (!(pageNum == numPages || fbytes != (int)pageSize)) + { + return false; // We get back in the next PanelDueFlasher::Spin() iteration } - } - catch(...) - { - infile->Close(); - throw; - } + } - infile->Close(); _observer.onProgress(numPages, numPages); return true; } -bool Flasher::verify(const char* filename, const char* dir, uint32_t& pageErrors, uint32_t& totalErrors, uint32_t& foffset) THROWS(GCodeException) +bool Flasher::verify(FileStore *infile, uint32_t& pageErrors, uint32_t& totalErrors, uint32_t& foffset) THROWS(GCodeException) { uint32_t pageSize = _flash->pageSize(); uint8_t bufferA[pageSize]; @@ -130,62 +114,46 @@ bool Flasher::verify(const char* filename, const char* dir, uint32_t& pageErrors if (foffset == 0) { pageNum = 0; + } - // Note that we can skip all checks for file validity here since - // we would not get here from write() if any of these failed + numPages = (infile->Length() + pageSize - 1) / pageSize; + if (foffset == 0) + { + if (numPages > _flash->numPages()) + throw FileSizeError("Flasher::verify: FileSizeError"); - infile = reprap.GetPlatform().OpenFile(dir, filename, OpenMode::read); - } + _observer.onStatus("Verifying %ld bytes of PanelDue flash memory\n", infile->Length()); + } - try - { + if ((fbytes = infile->Read((char*)bufferA, pageSize)) > 0) + { + byteErrors = 0; + foffset += fbytes; - numPages = (infile->Length() + pageSize - 1) / pageSize; - if (foffset == 0) - { - if (numPages > _flash->numPages()) - throw FileSizeError("Flasher::verify: FileSizeError"); + _observer.onProgress(pageNum, numPages); - _observer.onStatus("Verifying %ld bytes of PanelDue flash memory\n", infile->Length()); - } + { + _flash->readPage(pageOffset /*+ pageNum */, bufferB); - if ((fbytes = infile->Read((char*)bufferA, pageSize)) > 0) - { - byteErrors = 0; - foffset += fbytes; - - _observer.onProgress(pageNum, numPages); - - { - _flash->readPage(pageOffset /*+ pageNum */, bufferB); - - for (uint32_t i = 0; i < (uint32_t) fbytes; i++) - { - if (bufferA[i] != bufferB[i]) - byteErrors++; - } - } - - if (byteErrors != 0) - { - pageErrors++; - totalErrors += byteErrors; - } - - pageNum++; - if (!(pageNum == numPages || fbytes != (int)pageSize)) - { - return false; // We get back in the next PanelDueFlasher::Spin() iteration - } - } - } - catch(...) - { - infile->Close(); - throw; - } + for (uint32_t i = 0; i < (uint32_t) fbytes; i++) + { + if (bufferA[i] != bufferB[i]) + byteErrors++; + } + } + + if (byteErrors != 0) + { + pageErrors++; + totalErrors += byteErrors; + } - infile->Close(); + pageNum++; + if (!(pageNum == numPages || fbytes != (int)pageSize)) + { + return false; // We get back in the next PanelDueFlasher::Spin() iteration + } + } _observer.onProgress(numPages, numPages); diff --git a/src/bossa/Flasher.h b/src/bossa/Flasher.h index e0d365bb..a6ab16e8 100644 --- a/src/bossa/Flasher.h +++ b/src/bossa/Flasher.h @@ -53,13 +53,13 @@ class Flasher { public: Flasher(Samba& samba, Device& device, FlasherObserver& observer) noexcept - : _samba(samba), _flash(device.getFlash()), _observer(observer), pageNum(0), infile(nullptr) + : _samba(samba), _flash(device.getFlash()), _observer(observer), pageNum(0) {} virtual ~Flasher() {} void erase(uint32_t foffset) THROWS(GCodeException); - bool write(const char* filename, const char* dir, uint32_t& foffset) THROWS(GCodeException); - bool verify(const char* filename, const char* dir, uint32_t& pageErrors, uint32_t& totalErrors, uint32_t& foffset) THROWS(GCodeException); + bool write(FileStore *infile, uint32_t& foffset) THROWS(GCodeException); + bool verify(FileStore *infile, uint32_t& pageErrors, uint32_t& totalErrors, uint32_t& foffset) THROWS(GCodeException); void lock(/* std::string& regionArg, */ bool enable) THROWS(GCodeException); private: @@ -68,7 +68,6 @@ private: FlasherObserver& _observer; uint32_t pageNum; - FileStore * infile; }; #endif // _FLASHER_H |