bootoptions: unify esp32+esp8266 crash detection, add api to force reboot to safemode
This commit is contained in:
parent
b1ec20982b
commit
87ac61b061
@ -14,10 +14,21 @@ retained bool LAST_BOOT_WAS_FLASH;
|
||||
retained bool LAST_BOOT_WAS_SERIAL;
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_ESP32
|
||||
__NOINIT_ATTR uint8_t s_rebootCount = 0;
|
||||
#ifndef __NOINIT_ATTR // Pre-defined on esp32
|
||||
#define __NOINIT_ATTR __attribute__ ((section (".noinit")))
|
||||
#endif
|
||||
|
||||
#define SAFE_MODE_MAGIC 6942
|
||||
|
||||
__NOINIT_ATTR uint8_t s_rebootCount;
|
||||
__NOINIT_ATTR uint16_t s_forceSafeMode;
|
||||
|
||||
void
|
||||
BootOptions::forceSafeMode()
|
||||
{
|
||||
s_forceSafeMode = SAFE_MODE_MAGIC;
|
||||
}
|
||||
|
||||
void
|
||||
BootOptions::initPins()
|
||||
{
|
||||
@ -60,23 +71,20 @@ BootOptions::BootOptions()
|
||||
#ifdef BOARD_ESP8266
|
||||
struct rst_info resetInfo = *ESP.getResetInfoPtr();
|
||||
resetReason = resetInfo.reason;
|
||||
EEPROM.begin(sizeof(crashCount));
|
||||
EEPROM.get(sizeof(HardwareConfig) + 32, crashCount);
|
||||
EEPROM.end();
|
||||
if (resetInfo.reason == REASON_WDT_RST || resetInfo.reason == REASON_EXCEPTION_RST) {
|
||||
crashCount = s_rebootCount;
|
||||
if (resetInfo.reason == REASON_SOFT_WDT_RST || resetInfo.reason == REASON_WDT_RST || resetInfo.reason == REASON_EXCEPTION_RST) {
|
||||
if (crashCount++ >= 3) {
|
||||
// Boot into safe mode if the watchdog reset us three times in a row.
|
||||
isSafeMode = true;
|
||||
} else {
|
||||
EEPROM.begin(sizeof(crashCount));
|
||||
EEPROM.put(sizeof(HardwareConfig) + 32, crashCount);
|
||||
EEPROM.end();
|
||||
}
|
||||
} else if (crashCount != 0) {
|
||||
} else {
|
||||
crashCount = 0;
|
||||
EEPROM.begin(sizeof(crashCount));
|
||||
EEPROM.put(sizeof(HardwareConfig) + 32, crashCount);
|
||||
EEPROM.end();
|
||||
}
|
||||
s_rebootCount = crashCount;
|
||||
|
||||
if (resetInfo.reason > 0 && s_forceSafeMode == SAFE_MODE_MAGIC) {
|
||||
isSafeMode = true;
|
||||
s_forceSafeMode = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ struct BootOptions {
|
||||
BootOptions();
|
||||
|
||||
void waitForRelease();
|
||||
void forceSafeMode();
|
||||
|
||||
bool isSetup = false;
|
||||
bool isSerial = false;
|
||||
|
Loading…
Reference in New Issue
Block a user