mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 12:55:19 +03:00
Ensured board info is preserved through invalid EEPROM version triggered reset.
This commit is contained in:
parent
432f330e60
commit
467a490a53
3 changed files with 15 additions and 4 deletions
|
@ -94,8 +94,7 @@ void initEEPROM(void)
|
|||
BUILD_BUG_ON(sizeof(configRecord_t) != 6);
|
||||
}
|
||||
|
||||
// Scan the EEPROM config. Returns true if the config is valid.
|
||||
bool isEEPROMStructureValid(void)
|
||||
bool isEEPROMVersionValid(void)
|
||||
{
|
||||
const uint8_t *p = &__config_start;
|
||||
const configHeader_t *header = (const configHeader_t *)p;
|
||||
|
@ -103,6 +102,16 @@ bool isEEPROMStructureValid(void)
|
|||
if (header->eepromConfigVersion != EEPROM_CONF_VERSION) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Scan the EEPROM config. Returns true if the config is valid.
|
||||
bool isEEPROMStructureValid(void)
|
||||
{
|
||||
const uint8_t *p = &__config_start;
|
||||
const configHeader_t *header = (const configHeader_t *)p;
|
||||
|
||||
if (header->magic_be != 0xBE) {
|
||||
return false;
|
||||
}
|
||||
|
@ -254,7 +263,7 @@ void writeConfigToEEPROM(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (success && isEEPROMStructureValid()) {
|
||||
if (success && isEEPROMVersionValid() && isEEPROMStructureValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#define EEPROM_CONF_VERSION 169
|
||||
|
||||
bool isEEPROMVersionValid(void);
|
||||
bool isEEPROMStructureValid(void);
|
||||
bool loadEEPROM(void);
|
||||
void writeConfigToEEPROM(void);
|
||||
|
|
|
@ -240,13 +240,14 @@ void init(void)
|
|||
initEEPROM();
|
||||
|
||||
ensureEEPROMStructureIsValid();
|
||||
|
||||
bool readSuccess = readEEPROM();
|
||||
|
||||
#if defined(USE_BOARD_INFO)
|
||||
initBoardInformation();
|
||||
#endif
|
||||
|
||||
if (!readSuccess || strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) {
|
||||
if (!readSuccess || !isEEPROMVersionValid() || strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) {
|
||||
resetEEPROM();
|
||||
|
||||
activateConfig();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue