Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Backing up EEPROM before performing OTA For fixing - [#1808] #1809

Merged
merged 3 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions code/espurna/eeprom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -54,6 +57,10 @@ void eepromCommit() {
_eeprom_commit = true;
}

void eepromBackup(uint32_t index){
EEPROMr.backup(index);
}

#if TERMINAL_SUPPORT

void _eepromInitCommands() {
Expand Down
5 changes: 5 additions & 0 deletions code/espurna/nofuss.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions code/espurna/ota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down