mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 05:06:32 +00:00
Fix ESP32 bootloop control using RTC memory
This commit is contained in:
parent
0f3619238f
commit
eab612871c
@ -65,42 +65,6 @@ uint32_t ESP_getBootVersion(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ESP32 RTC memory is kept ONLY on deep_sleep wake. Any other restart will erase RTC memory
|
|
||||||
// Current solution is using NVS hopig it survives many writes ;-)
|
|
||||||
bool ESP_rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size)
|
|
||||||
{
|
|
||||||
char sName[16];
|
|
||||||
snprintf_P(sName, sizeof(sName), PSTR("rtc%d"), offset);
|
|
||||||
|
|
||||||
nvs_handle handle;
|
|
||||||
noInterrupts();
|
|
||||||
nvs_open("tasrtc", NVS_READWRITE, &handle);
|
|
||||||
nvs_set_blob(handle, sName, data, size);
|
|
||||||
nvs_commit(handle);
|
|
||||||
nvs_close(handle);
|
|
||||||
interrupts();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ESP32 RTC memory is kept ONLY on deep_sleep wake. Any other restart will erase RTC memory
|
|
||||||
// Current solution is using NVS hopig it survives many writes ;-)
|
|
||||||
bool ESP_rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
|
|
||||||
{
|
|
||||||
char sName[16];
|
|
||||||
snprintf_P(sName, sizeof(sName), PSTR("rtc%d"), offset);
|
|
||||||
|
|
||||||
nvs_handle handle;
|
|
||||||
noInterrupts();
|
|
||||||
nvs_open("tasrtc", NVS_READONLY, &handle);
|
|
||||||
size_t tsize = size;
|
|
||||||
nvs_get_blob(handle, sName, data, &tsize);
|
|
||||||
nvs_close(handle);
|
|
||||||
interrupts();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ESP_reset()
|
void ESP_reset()
|
||||||
{
|
{
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
@ -36,8 +36,6 @@
|
|||||||
String ESP_getResetReason(void);
|
String ESP_getResetReason(void);
|
||||||
uint32_t ESP_ResetInfoReason(void);
|
uint32_t ESP_ResetInfoReason(void);
|
||||||
uint32_t ESP_getBootVersion(void);
|
uint32_t ESP_getBootVersion(void);
|
||||||
bool ESP_rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size);
|
|
||||||
bool ESP_rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);
|
|
||||||
void ESP_reset();
|
void ESP_reset();
|
||||||
uint32_t ESP_getFlashChipId();
|
uint32_t ESP_getFlashChipId();
|
||||||
uint32_t ESP_getChipId();
|
uint32_t ESP_getChipId();
|
||||||
|
@ -551,6 +551,9 @@ typedef struct {
|
|||||||
uint8_t free_003[1]; // 283
|
uint8_t free_003[1]; // 283
|
||||||
} TRtcReboot;
|
} TRtcReboot;
|
||||||
TRtcReboot RtcReboot;
|
TRtcReboot RtcReboot;
|
||||||
|
#ifdef ESP32
|
||||||
|
RTC_NOINIT_ATTR TRtcReboot RtcDataReboot;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t valid; // 290 (RTC memory offset 100)
|
uint16_t valid; // 290 (RTC memory offset 100)
|
||||||
@ -570,6 +573,9 @@ typedef struct {
|
|||||||
// 2EC - 2FF free locations
|
// 2EC - 2FF free locations
|
||||||
} TRtcSettings;
|
} TRtcSettings;
|
||||||
TRtcSettings RtcSettings;
|
TRtcSettings RtcSettings;
|
||||||
|
#ifdef ESP32
|
||||||
|
RTC_NOINIT_ATTR TRtcSettings RtcDataSettings;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct TIME_T {
|
struct TIME_T {
|
||||||
uint8_t second;
|
uint8_t second;
|
||||||
|
@ -40,14 +40,22 @@ void RtcSettingsSave(void)
|
|||||||
{
|
{
|
||||||
if (GetRtcSettingsCrc() != rtc_settings_crc) {
|
if (GetRtcSettingsCrc() != rtc_settings_crc) {
|
||||||
RtcSettings.valid = RTC_MEM_VALID;
|
RtcSettings.valid = RTC_MEM_VALID;
|
||||||
ESP_rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings));
|
#ifdef ESP8266
|
||||||
|
ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings));
|
||||||
|
#else
|
||||||
|
RtcDataSettings = RtcSettings;
|
||||||
|
#endif
|
||||||
rtc_settings_crc = GetRtcSettingsCrc();
|
rtc_settings_crc = GetRtcSettingsCrc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtcSettingsLoad(void)
|
void RtcSettingsLoad(void)
|
||||||
{
|
{
|
||||||
ESP_rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290
|
#ifdef ESP8266
|
||||||
|
ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RtcSettings)); // 0x290
|
||||||
|
#else
|
||||||
|
RtcSettings = RtcDataSettings;
|
||||||
|
#endif
|
||||||
if (RtcSettings.valid != RTC_MEM_VALID) {
|
if (RtcSettings.valid != RTC_MEM_VALID) {
|
||||||
memset(&RtcSettings, 0, sizeof(RtcSettings));
|
memset(&RtcSettings, 0, sizeof(RtcSettings));
|
||||||
RtcSettings.valid = RTC_MEM_VALID;
|
RtcSettings.valid = RTC_MEM_VALID;
|
||||||
@ -87,7 +95,11 @@ void RtcRebootSave(void)
|
|||||||
{
|
{
|
||||||
if (GetRtcRebootCrc() != rtc_reboot_crc) {
|
if (GetRtcRebootCrc() != rtc_reboot_crc) {
|
||||||
RtcReboot.valid = RTC_MEM_VALID;
|
RtcReboot.valid = RTC_MEM_VALID;
|
||||||
ESP_rtcUserMemoryWrite(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot));
|
#ifdef ESP8266
|
||||||
|
ESP.rtcUserMemoryWrite(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot));
|
||||||
|
#else
|
||||||
|
RtcDataReboot = RtcReboot;
|
||||||
|
#endif
|
||||||
rtc_reboot_crc = GetRtcRebootCrc();
|
rtc_reboot_crc = GetRtcRebootCrc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,7 +112,11 @@ void RtcRebootReset(void)
|
|||||||
|
|
||||||
void RtcRebootLoad(void)
|
void RtcRebootLoad(void)
|
||||||
{
|
{
|
||||||
ESP_rtcUserMemoryRead(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot)); // 0x280
|
#ifdef ESP8266
|
||||||
|
ESP.rtcUserMemoryRead(100 - sizeof(RtcReboot), (uint32_t*)&RtcReboot, sizeof(RtcReboot)); // 0x280
|
||||||
|
#else
|
||||||
|
RtcReboot = RtcDataReboot;
|
||||||
|
#endif
|
||||||
if (RtcReboot.valid != RTC_MEM_VALID) {
|
if (RtcReboot.valid != RTC_MEM_VALID) {
|
||||||
memset(&RtcReboot, 0, sizeof(RtcReboot));
|
memset(&RtcReboot, 0, sizeof(RtcReboot));
|
||||||
RtcReboot.valid = RTC_MEM_VALID;
|
RtcReboot.valid = RTC_MEM_VALID;
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
// ESP8266
|
// ESP8266
|
||||||
#define PACKED
|
#define PACKED
|
||||||
#define ESP_rtcUserMemoryWrite(offset, data, size) ESP.rtcUserMemoryWrite(offset, data, size)
|
|
||||||
#define ESP_rtcUserMemoryRead(offset, data, size) ESP.rtcUserMemoryRead(offset, data, size)
|
|
||||||
#define ESP_getResetReason() ESP.getResetReason()
|
#define ESP_getResetReason() ESP.getResetReason()
|
||||||
#define ESP_reset() ESP.reset()
|
#define ESP_reset() ESP.reset()
|
||||||
#define ESP_getBootVersion() ESP.getBootVersion()
|
#define ESP_getBootVersion() ESP.getBootVersion()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user