mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +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);
|
BUILD_BUG_ON(sizeof(configRecord_t) != 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan the EEPROM config. Returns true if the config is valid.
|
bool isEEPROMVersionValid(void)
|
||||||
bool isEEPROMStructureValid(void)
|
|
||||||
{
|
{
|
||||||
const uint8_t *p = &__config_start;
|
const uint8_t *p = &__config_start;
|
||||||
const configHeader_t *header = (const configHeader_t *)p;
|
const configHeader_t *header = (const configHeader_t *)p;
|
||||||
|
@ -103,6 +102,16 @@ bool isEEPROMStructureValid(void)
|
||||||
if (header->eepromConfigVersion != EEPROM_CONF_VERSION) {
|
if (header->eepromConfigVersion != EEPROM_CONF_VERSION) {
|
||||||
return false;
|
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) {
|
if (header->magic_be != 0xBE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -254,7 +263,7 @@ void writeConfigToEEPROM(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success && isEEPROMStructureValid()) {
|
if (success && isEEPROMVersionValid() && isEEPROMStructureValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#define EEPROM_CONF_VERSION 169
|
#define EEPROM_CONF_VERSION 169
|
||||||
|
|
||||||
|
bool isEEPROMVersionValid(void);
|
||||||
bool isEEPROMStructureValid(void);
|
bool isEEPROMStructureValid(void);
|
||||||
bool loadEEPROM(void);
|
bool loadEEPROM(void);
|
||||||
void writeConfigToEEPROM(void);
|
void writeConfigToEEPROM(void);
|
||||||
|
|
|
@ -240,13 +240,14 @@ void init(void)
|
||||||
initEEPROM();
|
initEEPROM();
|
||||||
|
|
||||||
ensureEEPROMStructureIsValid();
|
ensureEEPROMStructureIsValid();
|
||||||
|
|
||||||
bool readSuccess = readEEPROM();
|
bool readSuccess = readEEPROM();
|
||||||
|
|
||||||
#if defined(USE_BOARD_INFO)
|
#if defined(USE_BOARD_INFO)
|
||||||
initBoardInformation();
|
initBoardInformation();
|
||||||
#endif
|
#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();
|
resetEEPROM();
|
||||||
|
|
||||||
activateConfig();
|
activateConfig();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue