mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-21 21:22:31 +03:00
Copy the existing flash mode over the one set in an OTA update image. (#4877)
This commit is contained in:
@ -204,12 +204,36 @@ bool UpdaterClass::end(bool evenIfRemaining){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool UpdaterClass::_writeBuffer(){
|
bool UpdaterClass::_writeBuffer(){
|
||||||
|
#define FLASH_MODE_PAGE 0
|
||||||
|
#define FLASH_MODE_OFFSET 2
|
||||||
|
|
||||||
bool eraseResult = true, writeResult = true;
|
bool eraseResult = true, writeResult = true;
|
||||||
if (_currentAddress % FLASH_SECTOR_SIZE == 0) {
|
if (_currentAddress % FLASH_SECTOR_SIZE == 0) {
|
||||||
if(!_async) yield();
|
if(!_async) yield();
|
||||||
eraseResult = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE);
|
eraseResult = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the flash settings don't match what we already have, modify them.
|
||||||
|
// But restore them after the modification, so the hash isn't affected.
|
||||||
|
// This is analogous to what esptool.py does when it receives a --flash_mode argument.
|
||||||
|
bool modifyFlashMode = false;
|
||||||
|
FlashMode_t flashMode = FM_QIO;
|
||||||
|
FlashMode_t bufferFlashMode = FM_QIO;
|
||||||
|
if (_currentAddress == _startAddress + FLASH_MODE_PAGE) {
|
||||||
|
flashMode = ESP.getFlashChipMode();
|
||||||
|
#ifdef DEBUG_UPDATER
|
||||||
|
DEBUG_UPDATER.printf("Header: 0x%1X %1X %1X %1X\n", _buffer[0], _buffer[1], _buffer[2], _buffer[3]);
|
||||||
|
#endif
|
||||||
|
bufferFlashMode = ESP.magicFlashChipMode(_buffer[FLASH_MODE_OFFSET]);
|
||||||
|
if (bufferFlashMode != flashMode) {
|
||||||
|
#ifdef DEBUG_UPDATER
|
||||||
|
DEBUG_UPDATER.printf("Set flash mode from 0x%1X to 0x%1X\n", bufferFlashMode, flashMode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_buffer[FLASH_MODE_OFFSET] = flashMode;
|
||||||
|
modifyFlashMode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (eraseResult) {
|
if (eraseResult) {
|
||||||
if(!_async) yield();
|
if(!_async) yield();
|
||||||
@ -220,6 +244,12 @@ bool UpdaterClass::_writeBuffer(){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore the old flash mode, if we modified it.
|
||||||
|
// Ensures that the MD5 hash will still match what was sent.
|
||||||
|
if (modifyFlashMode) {
|
||||||
|
_buffer[FLASH_MODE_OFFSET] = bufferFlashMode;
|
||||||
|
}
|
||||||
|
|
||||||
if (!writeResult) {
|
if (!writeResult) {
|
||||||
_currentAddress = (_startAddress + _size);
|
_currentAddress = (_startAddress + _size);
|
||||||
_setError(UPDATE_ERROR_WRITE);
|
_setError(UPDATE_ERROR_WRITE);
|
||||||
|
Reference in New Issue
Block a user