mirror of https://github.com/rusefi/rusefi.git
reducing code duplication - internal flash order of operations (#5672)
* reducing code duplication * reducing code duplication --------- Co-authored-by: rusefillc <sdfsdfqsf2334234234>
This commit is contained in:
parent
3235b3da48
commit
ffd1ff4a17
|
@ -219,19 +219,7 @@ enum class FlashState {
|
|||
BlankChip,
|
||||
};
|
||||
|
||||
/**
|
||||
* Read single copy of rusEFI configuration from flash
|
||||
*/
|
||||
static FlashState readOneConfigurationCopy(flashaddr_t address) {
|
||||
efiPrintf("readFromFlash %x", address);
|
||||
|
||||
// error already reported, return
|
||||
if (!address) {
|
||||
return FlashState::BlankChip;
|
||||
}
|
||||
|
||||
intFlashRead(address, (char *) &persistentState, sizeof(persistentState));
|
||||
|
||||
static FlashState validatePersistentState() {
|
||||
auto flashCrc = flashStateCrc(persistentState);
|
||||
|
||||
if (flashCrc != persistentState.crc) {
|
||||
|
@ -248,6 +236,22 @@ static FlashState readOneConfigurationCopy(flashaddr_t address) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read single copy of rusEFI configuration from flash
|
||||
*/
|
||||
static FlashState readOneConfigurationCopy(flashaddr_t address) {
|
||||
efiPrintf("readFromFlash %x", address);
|
||||
|
||||
// error already reported, return
|
||||
if (!address) {
|
||||
return FlashState::BlankChip;
|
||||
}
|
||||
|
||||
intFlashRead(address, (char *) &persistentState, sizeof(persistentState));
|
||||
|
||||
return validatePersistentState();
|
||||
}
|
||||
|
||||
/**
|
||||
* this method could and should be executed before we have any
|
||||
* connectivity so no console output here
|
||||
|
@ -264,22 +268,7 @@ static FlashState readConfiguration() {
|
|||
// readed size is not exactly the same
|
||||
if (settings_size != sizeof(persistentState))
|
||||
return FlashState::IncompatibleVersion;
|
||||
// claimed size or version is not the same
|
||||
if (persistentState.version != FLASH_DATA_VERSION || persistentState.size != sizeof(persistentState))
|
||||
return FlashState::IncompatibleVersion;
|
||||
|
||||
// now crc
|
||||
auto flashCrc = flashStateCrc(persistentState);
|
||||
|
||||
if (flashCrc != persistentState.crc) {
|
||||
// If the stored crc is all 1s, that probably means the flash is actually blank, not that the crc failed.
|
||||
if (persistentState.crc == ((decltype(persistentState.crc))-1)) {
|
||||
return FlashState::BlankChip;
|
||||
} else {
|
||||
return FlashState::CrcFailed;
|
||||
}
|
||||
}
|
||||
return FlashState::Ok;
|
||||
return validatePersistentState();
|
||||
} else {
|
||||
return FlashState::BlankChip;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue