Skip to content

Commit

Permalink
Add better config corruption recovery
Browse files Browse the repository at this point in the history
- Add better config corruption recovery (#9046)
- Remove support for 1-step upgrade from versions before 6.6.0.11 to versions after 8.4.0.1
  • Loading branch information
arendst committed Aug 13, 2020
1 parent 94e8712 commit 731ca29
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
4 changes: 3 additions & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ The following binary downloads have been compiled with ESP8266/Arduino library c

## Changelog

### Version 8.4.0.1
### Version 8.4.0.2

- Remove support for 1-step upgrade from versions before 6.6.0.11 to versions after 8.4.0.1
- Fix ESP32 PWM range
- Add Zigbee better support for IKEA Motion Sensor
- Add ESP32 Analog input support for GPIO32 to GPIO39
- Add Zigbee options to ``ZbSend`` ``Config`` and ``ReadCondig``
- Add command ``Restart 2`` to halt system. Needs hardware reset or power cycle to restart (#9046)
- Add better config corruption recovery (#9046)
5 changes: 5 additions & 0 deletions tasmota/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased (development)

### 8.4.0.2 20200813

- Add better config corruption recovery (#9046)
- Remove support for 1-step upgrade from versions before 6.6.0.11 to versions after 8.4.0.1

### 8.4.0.1 20200730

- Fix ESP32 PWM range
Expand Down
35 changes: 29 additions & 6 deletions tasmota/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ void SettingsSave(uint8_t rotate)
RtcSettingsSave();
}

void SettingsLoad(void)
{
void SettingsLoad(void) {
#ifdef ESP8266
// Load configuration from eeprom or one of 7 slots below if first valid load does not stop_flash_rotate
#ifdef CFG_LEGACY_LOAD
struct {
uint16_t cfg_holder; // 000
uint16_t cfg_size; // 002
Expand All @@ -566,7 +566,7 @@ void SettingsLoad(void)
settings_location = 0;
uint32_t flash_location = SETTINGS_LOCATION +1;
uint16_t cfg_holder = 0;
for (uint32_t i = 0; i < CFG_ROTATES; i++) {
for (uint32_t i = 0; i < CFG_ROTATES; i++) { // Read all config pages in search of valid and latest
flash_location--;
ESP.flashRead(flash_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
bool valid = false;
Expand All @@ -583,10 +583,32 @@ void SettingsLoad(void)
valid = (Settings.cfg_holder == _SettingsH.cfg_holder);
}
if (valid) {
if (Settings.save_flag > save_flag) {
if (Settings.save_flag > save_flag) { // Find latest page based on incrementing save_flag
save_flag = Settings.save_flag;
settings_location = flash_location;
if (Settings.flag.stop_flash_rotate && (0 == i)) { // Stop if only eeprom area should be used and it is valid
break;
}
}
}
delay(1);
}
if (settings_location > 0) {
ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
AddLog_P2(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %lu"), settings_location, Settings.save_flag);
}
#else // CFG_RESILIENT
settings_location = 0;
uint32_t save_flag = 0;
uint32_t flash_location = SETTINGS_LOCATION +1;
for (uint32_t i = 0; i < CFG_ROTATES; i++) { // Read all config pages in search of valid and latest
flash_location--;
ESP.flashRead(flash_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
if ((Settings.cfg_crc32 != 0xFFFFFFFF) && (Settings.cfg_crc32 != 0x00000000) && (Settings.cfg_crc32 == GetSettingsCrc32())) {
if (Settings.save_flag > save_flag) { // Find latest page based on incrementing save_flag
save_flag = Settings.save_flag;
settings_location = flash_location;
if (Settings.flag.stop_flash_rotate && (0 == i)) { // Stop only if eeprom area should be used and it is valid
if (Settings.flag.stop_flash_rotate && (0 == i)) { // Stop if only eeprom area should be used and it is valid
break;
}
}
Expand All @@ -597,13 +619,14 @@ void SettingsLoad(void)
ESP.flashRead(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(Settings));
AddLog_P2(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %lu"), settings_location, Settings.save_flag);
}
#endif // CFG_RESILIENT
#else // ESP32
SettingsRead(&Settings, sizeof(Settings));
AddLog_P2(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG "Loaded, " D_COUNT " %lu"), Settings.save_flag);
#endif // ESP8266 - ESP32

#ifndef FIRMWARE_MINIMAL
if (!settings_location || (Settings.cfg_holder != (uint16_t)CFG_HOLDER)) { // Init defaults if cfg_holder differs from user settings in my_user_config.h
if ((0 == settings_location) || (Settings.cfg_holder != (uint16_t)CFG_HOLDER)) { // Init defaults if cfg_holder differs from user settings in my_user_config.h
SettingsDefault();
}
settings_crc32 = GetSettingsCrc32();
Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef _TASMOTA_VERSION_H_
#define _TASMOTA_VERSION_H_

const uint32_t VERSION = 0x08040001;
const uint32_t VERSION = 0x08040002;

// Lowest compatible version
const uint32_t VERSION_COMPATIBLE = 0x07010006;
Expand Down

0 comments on commit 731ca29

Please sign in to comment.