AP_Flashstorage: fixed init bug on F1

we can't mark available just before we mark in use on F1
This commit is contained in:
Andrew Tridgell 2019-10-20 20:20:20 +11:00
parent 5efaea2d92
commit 40431100a9
2 changed files with 11 additions and 6 deletions

View File

@ -120,7 +120,7 @@ bool AP_FlashStorage::init(void)
// erase any sectors marked full
for (uint8_t i=0; i<2; i++) {
if (states[i] == SECTOR_STATE_FULL) {
if (!erase_sector(i)) {
if (!erase_sector(i, true)) {
return false;
}
}
@ -148,7 +148,7 @@ bool AP_FlashStorage::switch_full_sector(void)
return false;
}
if (!erase_sector(current_sector ^ 1)) {
if (!erase_sector(current_sector ^ 1, true)) {
return false;
}
@ -276,12 +276,14 @@ bool AP_FlashStorage::load_sector(uint8_t sector)
/*
erase one sector
*/
bool AP_FlashStorage::erase_sector(uint8_t sector)
bool AP_FlashStorage::erase_sector(uint8_t sector, bool mark_available)
{
if (!flash_erase(sector)) {
return false;
}
if (!mark_available) {
return true;
}
struct sector_header header;
header.signature = signature;
header.state = SECTOR_STATE_AVAILABLE;
@ -298,7 +300,10 @@ bool AP_FlashStorage::erase_all(void)
current_sector = 0;
write_offset = sizeof(struct sector_header);
if (!erase_sector(0) || !erase_sector(1)) {
if (!erase_sector(0, current_sector!=0)) {
return false;
}
if (!erase_sector(1, current_sector!=1)) {
return false;
}

View File

@ -160,7 +160,7 @@ private:
bool load_sector(uint8_t sector);
// erase a sector and write header
bool erase_sector(uint8_t sector);
bool erase_sector(uint8_t sector, bool mark_available);
// erase all sectors and reset
bool erase_all();