mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 13:25:30 +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:
commit
662b66e91c
3 changed files with 24 additions and 3 deletions
|
@ -395,4 +395,9 @@ bool flashInit(const flashConfig_t *flashConfig)
|
||||||
|
|
||||||
return haveFlash;
|
return haveFlash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int flashPartitionCount(void)
|
||||||
|
{
|
||||||
|
return flashPartitions;
|
||||||
|
}
|
||||||
#endif // USE_FLASH_CHIP
|
#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);
|
flashPartition_t *flashPartitionFindByType(flashPartitionType_e type);
|
||||||
const flashPartition_t *flashPartitionFindByIndex(uint8_t index);
|
const flashPartition_t *flashPartitionFindByIndex(uint8_t index);
|
||||||
const char *flashPartitionGetTypeName(flashPartitionType_e type);
|
const char *flashPartitionGetTypeName(flashPartitionType_e type);
|
||||||
|
int flashPartitionCount(void);
|
||||||
|
|
|
@ -78,9 +78,24 @@ static void flashfsSetTailAddress(uint32_t address)
|
||||||
|
|
||||||
void flashfsEraseCompletely(void)
|
void flashfsEraseCompletely(void)
|
||||||
{
|
{
|
||||||
for (flashSector_t sectorIndex = flashPartition->startSector; sectorIndex <= flashPartition->endSector; sectorIndex++) {
|
if (flashGeometry->sectors > 0 && flashPartitionCount() > 0) {
|
||||||
uint32_t sectorAddress = sectorIndex * flashGeometry->sectorSize;
|
// if there's a single FLASHFS partition and it uses the entire flash then do a full erase
|
||||||
flashEraseSector(sectorAddress);
|
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();
|
flashfsClearBuffer();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue