From fbf2b71749307688f7258ad8235bc0f5d068e926 Mon Sep 17 00:00:00 2001 From: arihant daga Date: Thu, 18 Jul 2019 04:35:25 +0530 Subject: [PATCH] Backup EEPROM before performing OTA (#1808, #1809) * [Fix] Backing up EEPROM before performing OTA.For fixing - [#1808] * Guard ArduinoOTA, different handler for async --- code/espurna/eeprom.ino | 7 +++++++ code/espurna/nofuss.ino | 5 +++++ code/espurna/ota.ino | 3 +++ 3 files changed, 15 insertions(+) diff --git a/code/espurna/eeprom.ino b/code/espurna/eeprom.ino index 2c2e5da9..9b03f80e 100644 --- a/code/espurna/eeprom.ino +++ b/code/espurna/eeprom.ino @@ -23,6 +23,9 @@ void eepromRotate(bool value) { DEBUG_MSG_P(PSTR("[EEPROM] Disabling EEPROM rotation\n")); } EEPROMr.rotate(value); + + // Because .rotate(false) marks EEPROM as dirty, this is equivalent to the .backup(0) + eepromCommit(); } } @@ -54,6 +57,10 @@ void eepromCommit() { _eeprom_commit = true; } +void eepromBackup(uint32_t index){ + EEPROMr.backup(index); +} + #if TERMINAL_SUPPORT void _eepromInitCommands() { diff --git a/code/espurna/nofuss.ino b/code/espurna/nofuss.ino index 5f28007f..aba702de 100644 --- a/code/espurna/nofuss.ino +++ b/code/espurna/nofuss.ino @@ -122,6 +122,9 @@ void nofussSetup() { // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade eepromRotate(false); + + // Force backup right now, because NoFUSS library will immediatly reset on success + eepromBackup(0); } if (code == NOFUSS_FILESYSTEM_UPDATE_ERROR) { @@ -145,6 +148,8 @@ void nofussSetup() { #if WEB_SUPPORT wsSend_P(PSTR("{\"action\": \"reload\"}")); #endif + // TODO: NoFUSS will reset the board after this callback returns. + // Maybe this should be optional nice_delay(100); } diff --git a/code/espurna/ota.ino b/code/espurna/ota.ino index 0f504adb..69ae888e 100644 --- a/code/espurna/ota.ino +++ b/code/espurna/ota.ino @@ -251,6 +251,9 @@ void otaSetup() { // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade eepromRotate(false); + // Because ArduinoOTA is synchronous, force backup right now instead of waiting for the next loop() + eepromBackup(0); + DEBUG_MSG_P(PSTR("[OTA] Start\n")); #if WEB_SUPPORT