From 703ab8df641c0028245d400cf9d1b2d609571f13 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sat, 4 Jul 2015 01:20:33 +0300 Subject: [PATCH] make Update erase/write sector by sector as well --- cores/esp8266/Updater.cpp | 26 +++++++++---------- .../examples/WebUpdate/WebUpdate.ino | 4 +++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index aba181fe7..e9ecd5d5d 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -51,18 +51,6 @@ bool UpdaterClass::begin(size_t size){ return false; } - //erase the neede space - noInterrupts(); - int rc = SPIEraseAreaEx(updateStartAddress, roundedSize); - interrupts(); - if (rc){ - _error = UPDATE_ERROR_ERASE; -#ifdef DEBUG_UPDATER - printError(DEBUG_UPDATER); -#endif - return false; - } - //initialize _startAddress = updateStartAddress; _currentAddress = _startAddress; @@ -122,7 +110,19 @@ bool UpdaterClass::end(bool evenIfRemaining){ bool UpdaterClass::_writeBuffer(){ WDT_FEED(); noInterrupts(); - int rc = SPIWrite(_currentAddress, _buffer, _bufferLen); + int rc = SPIEraseSector(_currentAddress/FLASH_SECTOR_SIZE); + interrupts(); + if (rc){ + _error = UPDATE_ERROR_ERASE; +#ifdef DEBUG_UPDATER + printError(DEBUG_UPDATER); +#endif + return false; + } + + WDT_FEED(); + noInterrupts(); + rc = SPIWrite(_currentAddress, _buffer, _bufferLen); interrupts(); if (rc) { _error = UPDATE_ERROR_WRITE; diff --git a/libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino b/libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino index 4962b35e8..665dd6199 100644 --- a/libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino +++ b/libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino @@ -1,3 +1,7 @@ +/* + To upload through terminal you can use: curl -F "image=@firmware.bin" esp8266-webupdate.local/update +*/ + #include #include #include