1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Use full erase when possible for FLASHFS erase - fixes single partition targets (#8343)

Use full erase when possible for FLASHFS erase - fixes single partition targets
This commit is contained in:
Michael Keller 2019-05-27 23:19:14 +12:00 committed by GitHub
commit 662b66e91c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View file

@ -395,4 +395,9 @@ bool flashInit(const flashConfig_t *flashConfig)
return haveFlash;
}
int flashPartitionCount(void)
{
return flashPartitions;
}
#endif // USE_FLASH_CHIP

View file

@ -94,3 +94,4 @@ void flashPartitionSet(uint8_t index, uint32_t startSector, uint32_t endSector);
flashPartition_t *flashPartitionFindByType(flashPartitionType_e type);
const flashPartition_t *flashPartitionFindByIndex(uint8_t index);
const char *flashPartitionGetTypeName(flashPartitionType_e type);
int flashPartitionCount(void);

View file

@ -78,10 +78,25 @@ static void flashfsSetTailAddress(uint32_t address)
void flashfsEraseCompletely(void)
{
if (flashGeometry->sectors > 0 && flashPartitionCount() > 0) {
// if there's a single FLASHFS partition and it uses the entire flash then do a full erase
const bool doFullErase = (flashPartitionCount() == 1) && (FLASH_PARTITION_SECTOR_COUNT(flashPartition) == flashGeometry->sectors);
if (doFullErase) {
flashEraseCompletely();
} else {
// TODO - the partial sector-based erase needs to be completely reworked.
// All calls to flashfsEraseCompletely() currently expect the erase to run
// asynchronously and return immediately. The current implementation performs
// the erase synchronously and doesn't return until complete. This breaks calls
// from MSP and runtime mode-switched erasing.
for (flashSector_t sectorIndex = flashPartition->startSector; sectorIndex <= flashPartition->endSector; sectorIndex++) {
uint32_t sectorAddress = sectorIndex * flashGeometry->sectorSize;
flashEraseSector(sectorAddress);
}
}
}
flashfsClearBuffer();