Use full erase when possible for FLASHFS erase
If there is only a single partition, its type is FLASHFS, and it uses the entire geometry, then perform a full rather than a sector-based erase. The full erase is significantly faster than erasing by individual sectors.
This commit is contained in:
parent
e54ef4815a
commit
aaa2f9682d
|
@ -395,4 +395,9 @@ bool flashInit(const flashConfig_t *flashConfig)
|
|||
|
||||
return haveFlash;
|
||||
}
|
||||
|
||||
int flashPartitionCount(void)
|
||||
{
|
||||
return flashPartitions;
|
||||
}
|
||||
#endif // USE_FLASH_CHIP
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -78,9 +78,24 @@ static void flashfsSetTailAddress(uint32_t address)
|
|||
|
||||
void flashfsEraseCompletely(void)
|
||||
{
|
||||
for (flashSector_t sectorIndex = flashPartition->startSector; sectorIndex <= flashPartition->endSector; sectorIndex++) {
|
||||
uint32_t sectorAddress = sectorIndex * flashGeometry->sectorSize;
|
||||
flashEraseSector(sectorAddress);
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue