Browse Source

AP_Flashstorage: fixed init bug on F1

we can't mark available just before we mark in use on F1
mission-4.1.18
Andrew Tridgell 5 years ago
parent
commit
40431100a9
  1. 15
      libraries/AP_FlashStorage/AP_FlashStorage.cpp
  2. 2
      libraries/AP_FlashStorage/AP_FlashStorage.h

15
libraries/AP_FlashStorage/AP_FlashStorage.cpp

@ -120,7 +120,7 @@ bool AP_FlashStorage::init(void) @@ -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) @@ -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) @@ -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) @@ -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;
}

2
libraries/AP_FlashStorage/AP_FlashStorage.h

@ -160,7 +160,7 @@ private: @@ -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();

Loading…
Cancel
Save