Bsongis/boot issue invalid eeprom (#6684)

Boot issue on invalid eeprom
This commit is contained in:
Bertrand Songis
2019-08-30 13:23:49 +02:00
committed by GitHub
parent ae4a80f4be
commit ff2cde85be
7 changed files with 29 additions and 32 deletions
+3 -3
View File
@@ -1817,8 +1817,7 @@ void opentxInit()
#endif #endif
#if defined(EEPROM) #if defined(EEPROM)
storageClearRadioSetting(); bool radioSettingsValid = storageReadRadioSettings(false);
storageReadRadioSettings(false);
#endif #endif
BACKLIGHT_ENABLE(); // we start the backlight during the startup animation BACKLIGHT_ENABLE(); // we start the backlight during the startup animation
@@ -1877,7 +1876,8 @@ void opentxInit()
#endif #endif
#if defined(EEPROM) #if defined(EEPROM)
storageReadRadioSettings(true); if (!radioSettingsValid)
storageReadRadioSettings();
storageReadCurrentModel(); storageReadCurrentModel();
#endif #endif
+10 -7
View File
@@ -86,17 +86,18 @@ void eeLoadModelHeaders()
} }
} }
void storageClearRadioSetting() void storageClearRadioSettings()
{ {
memclear(&g_eeGeneral, sizeof(RadioData)); memclear(&g_eeGeneral, sizeof(RadioData));
} }
void storageReadRadioSettings(bool allowConversion) bool storageReadRadioSettings(bool allowFixes)
{ {
if (g_eeGeneral.version != 0) if (!eepromOpen() || !eeLoadGeneral(allowFixes)) {
return; if (!allowFixes) {
storageClearRadioSettings();
if (!eepromOpen() || !eeLoadGeneral(allowConversion)) { return false;
}
storageEraseAll(true); storageEraseAll(true);
} }
else { else {
@@ -109,6 +110,8 @@ void storageReadRadioSettings(bool allowConversion)
currentLanguagePack = languagePacks[i]; currentLanguagePack = languagePacks[i];
} }
} }
return true;
} }
void storageReadCurrentModel() void storageReadCurrentModel()
@@ -118,7 +121,7 @@ void storageReadCurrentModel()
void storageReadAll() void storageReadAll()
{ {
storageReadRadioSettings(true); storageReadRadioSettings();
storageReadCurrentModel(); storageReadCurrentModel();
} }
+5 -5
View File
@@ -28,11 +28,11 @@ void eeLoadModel(uint8_t id);
uint8_t eeFindEmptyModel(uint8_t id, bool down); uint8_t eeFindEmptyModel(uint8_t id, bool down);
void selectModel(uint8_t sub); void selectModel(uint8_t sub);
extern ModelHeader modelHeaders[MAX_MODELS]; extern ModelHeader modelHeaders[MAX_MODELS];
void eeLoadModelHeader(uint8_t id, ModelHeader *header); void eeLoadModelHeader(uint8_t id, ModelHeader *header);
void eeLoadModelHeaders(); void eeLoadModelHeaders();
void storageClearRadioSetting(); void storageClearRadioSettings();
void storageReadRadioSettings(bool allowConversion); bool storageReadRadioSettings(bool allowFixes = true);
void storageReadCurrentModel(); void storageReadCurrentModel();
+4 -8
View File
@@ -256,21 +256,17 @@ void writeModel(int index)
writeFile(index+1, (uint8_t *)&g_model, sizeof(g_model)); writeFile(index+1, (uint8_t *)&g_model, sizeof(g_model));
} }
bool eeLoadGeneral(bool allowConversion) bool eeLoadGeneral(bool allowFixes)
{ {
eeLoadGeneralSettingsData(); eeLoadGeneralSettingsData();
if (g_eeGeneral.version != EEPROM_VER) { if (g_eeGeneral.version != EEPROM_VER) {
TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER); TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER);
#if defined(PCBSKY9X) #if defined(PCBSKY9X)
if (!allowConversion) { if (!allowFixes)
storageClearRadioSetting(); return false; // prevent eeprom from being wiped
return true; // prevent eeprom from being wiped if (!eeConvert())
}
if (!eeConvert()) {
return false; return false;
}
#else #else
return false; return false;
#endif #endif
+1 -1
View File
@@ -24,7 +24,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h> #include <stdint.h>
bool eeLoadGeneral(bool allowConversion); bool eeLoadGeneral(bool allowFixes);
void eeDeleteModel( uint8_t id ); void eeDeleteModel( uint8_t id );
bool eeCopyModel(uint8_t dst, uint8_t src); bool eeCopyModel(uint8_t dst, uint8_t src);
void eeSwapModels(uint8_t id1, uint8_t id2); void eeSwapModels(uint8_t id1, uint8_t id2);
+5 -7
View File
@@ -757,7 +757,7 @@ uint16_t eeLoadModelData(uint8_t index)
return theFile.readRlc((uint8_t*)&g_model, sizeof(g_model)); return theFile.readRlc((uint8_t*)&g_model, sizeof(g_model));
} }
bool eeLoadGeneral(bool allowConversion) bool eeLoadGeneral(bool allowFixes)
{ {
theFile.openRlc(FILE_GENERAL); theFile.openRlc(FILE_GENERAL);
if (theFile.readRlc((uint8_t*)&g_eeGeneral, 3) == 3 && g_eeGeneral.version == EEPROM_VER) { if (theFile.readRlc((uint8_t*)&g_eeGeneral, 3) == 3 && g_eeGeneral.version == EEPROM_VER) {
@@ -794,16 +794,14 @@ bool eeLoadGeneral(bool allowConversion)
return false; return false;
} }
#endif #endif
#if defined(EEPROM_CONVERSIONS) #if defined(EEPROM_CONVERSIONS)
if (g_eeGeneral.version != EEPROM_VER) { if (g_eeGeneral.version != EEPROM_VER) {
if (!allowConversion) {
storageClearRadioSetting();
return true; // prevent eeprom from being wiped
}
TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER); TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER);
if (!eeConvert()) { if (!allowFixes)
return false; // prevent eeprom from being wiped
if (!eeConvert())
return false; return false;
}
} }
return true; return true;
#else #else
+1 -1
View File
@@ -180,7 +180,7 @@ void loadModel(int index, bool alarms=true);
bool eepromOpen(); bool eepromOpen();
void eeLoadModelName(uint8_t id, char * name); void eeLoadModelName(uint8_t id, char * name);
bool eeLoadGeneral(bool allowConversion); bool eeLoadGeneral(bool allowFixes);
// For EEPROM backup/restore // For EEPROM backup/restore
inline bool isEepromStart(const void * buffer) inline bool isEepromStart(const void * buffer)