From ff2cde85be73e79a6d5e03ec0efbfe0128595399 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 30 Aug 2019 13:23:49 +0200 Subject: [PATCH] Bsongis/boot issue invalid eeprom (#6684) Boot issue on invalid eeprom --- radio/src/opentx.cpp | 6 +++--- radio/src/storage/eeprom_common.cpp | 17 ++++++++++------- radio/src/storage/eeprom_common.h | 10 +++++----- radio/src/storage/eeprom_raw.cpp | 12 ++++-------- radio/src/storage/eeprom_raw.h | 2 +- radio/src/storage/eeprom_rlc.cpp | 12 +++++------- radio/src/storage/eeprom_rlc.h | 2 +- 7 files changed, 29 insertions(+), 32 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index dff7480a5..02a156356 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1817,8 +1817,7 @@ void opentxInit() #endif #if defined(EEPROM) - storageClearRadioSetting(); - storageReadRadioSettings(false); + bool radioSettingsValid = storageReadRadioSettings(false); #endif BACKLIGHT_ENABLE(); // we start the backlight during the startup animation @@ -1877,7 +1876,8 @@ void opentxInit() #endif #if defined(EEPROM) - storageReadRadioSettings(true); + if (!radioSettingsValid) + storageReadRadioSettings(); storageReadCurrentModel(); #endif diff --git a/radio/src/storage/eeprom_common.cpp b/radio/src/storage/eeprom_common.cpp index b31115e30..c6b511d68 100644 --- a/radio/src/storage/eeprom_common.cpp +++ b/radio/src/storage/eeprom_common.cpp @@ -86,17 +86,18 @@ void eeLoadModelHeaders() } } -void storageClearRadioSetting() +void storageClearRadioSettings() { memclear(&g_eeGeneral, sizeof(RadioData)); } -void storageReadRadioSettings(bool allowConversion) +bool storageReadRadioSettings(bool allowFixes) { - if (g_eeGeneral.version != 0) - return; - - if (!eepromOpen() || !eeLoadGeneral(allowConversion)) { + if (!eepromOpen() || !eeLoadGeneral(allowFixes)) { + if (!allowFixes) { + storageClearRadioSettings(); + return false; + } storageEraseAll(true); } else { @@ -109,6 +110,8 @@ void storageReadRadioSettings(bool allowConversion) currentLanguagePack = languagePacks[i]; } } + + return true; } void storageReadCurrentModel() @@ -118,7 +121,7 @@ void storageReadCurrentModel() void storageReadAll() { - storageReadRadioSettings(true); + storageReadRadioSettings(); storageReadCurrentModel(); } diff --git a/radio/src/storage/eeprom_common.h b/radio/src/storage/eeprom_common.h index bab56b07a..1241faf24 100644 --- a/radio/src/storage/eeprom_common.h +++ b/radio/src/storage/eeprom_common.h @@ -28,11 +28,11 @@ void eeLoadModel(uint8_t id); uint8_t eeFindEmptyModel(uint8_t id, bool down); void selectModel(uint8_t sub); - extern ModelHeader modelHeaders[MAX_MODELS]; - void eeLoadModelHeader(uint8_t id, ModelHeader *header); - void eeLoadModelHeaders(); +extern ModelHeader modelHeaders[MAX_MODELS]; +void eeLoadModelHeader(uint8_t id, ModelHeader *header); +void eeLoadModelHeaders(); -void storageClearRadioSetting(); -void storageReadRadioSettings(bool allowConversion); +void storageClearRadioSettings(); +bool storageReadRadioSettings(bool allowFixes = true); void storageReadCurrentModel(); diff --git a/radio/src/storage/eeprom_raw.cpp b/radio/src/storage/eeprom_raw.cpp index 1d329b1e3..71af9d436 100644 --- a/radio/src/storage/eeprom_raw.cpp +++ b/radio/src/storage/eeprom_raw.cpp @@ -256,21 +256,17 @@ void writeModel(int index) writeFile(index+1, (uint8_t *)&g_model, sizeof(g_model)); } -bool eeLoadGeneral(bool allowConversion) +bool eeLoadGeneral(bool allowFixes) { eeLoadGeneralSettingsData(); if (g_eeGeneral.version != EEPROM_VER) { TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER); #if defined(PCBSKY9X) - if (!allowConversion) { - storageClearRadioSetting(); - return true; // prevent eeprom from being wiped - } - - if (!eeConvert()) { + if (!allowFixes) + return false; // prevent eeprom from being wiped + if (!eeConvert()) return false; - } #else return false; #endif diff --git a/radio/src/storage/eeprom_raw.h b/radio/src/storage/eeprom_raw.h index b8f63c191..353a850a5 100644 --- a/radio/src/storage/eeprom_raw.h +++ b/radio/src/storage/eeprom_raw.h @@ -24,7 +24,7 @@ #include #include -bool eeLoadGeneral(bool allowConversion); +bool eeLoadGeneral(bool allowFixes); void eeDeleteModel( uint8_t id ); bool eeCopyModel(uint8_t dst, uint8_t src); void eeSwapModels(uint8_t id1, uint8_t id2); diff --git a/radio/src/storage/eeprom_rlc.cpp b/radio/src/storage/eeprom_rlc.cpp index 6c458f088..33f561e6c 100644 --- a/radio/src/storage/eeprom_rlc.cpp +++ b/radio/src/storage/eeprom_rlc.cpp @@ -757,7 +757,7 @@ uint16_t eeLoadModelData(uint8_t index) return theFile.readRlc((uint8_t*)&g_model, sizeof(g_model)); } -bool eeLoadGeneral(bool allowConversion) +bool eeLoadGeneral(bool allowFixes) { theFile.openRlc(FILE_GENERAL); if (theFile.readRlc((uint8_t*)&g_eeGeneral, 3) == 3 && g_eeGeneral.version == EEPROM_VER) { @@ -794,16 +794,14 @@ bool eeLoadGeneral(bool allowConversion) return false; } #endif + #if defined(EEPROM_CONVERSIONS) 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); - if (!eeConvert()) { + if (!allowFixes) + return false; // prevent eeprom from being wiped + if (!eeConvert()) return false; - } } return true; #else diff --git a/radio/src/storage/eeprom_rlc.h b/radio/src/storage/eeprom_rlc.h index d9ad5d588..0c766a81d 100644 --- a/radio/src/storage/eeprom_rlc.h +++ b/radio/src/storage/eeprom_rlc.h @@ -180,7 +180,7 @@ void loadModel(int index, bool alarms=true); bool eepromOpen(); void eeLoadModelName(uint8_t id, char * name); -bool eeLoadGeneral(bool allowConversion); +bool eeLoadGeneral(bool allowFixes); // For EEPROM backup/restore inline bool isEepromStart(const void * buffer)