From 40431100a98d68ad0479bb62aa5e3f6afaf92ea0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 20 Oct 2019 20:20:20 +1100 Subject: [PATCH] AP_Flashstorage: fixed init bug on F1 we can't mark available just before we mark in use on F1 --- libraries/AP_FlashStorage/AP_FlashStorage.cpp | 15 ++++++++++----- libraries/AP_FlashStorage/AP_FlashStorage.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/AP_FlashStorage/AP_FlashStorage.cpp b/libraries/AP_FlashStorage/AP_FlashStorage.cpp index b8e2e99324..16384c18d0 100644 --- a/libraries/AP_FlashStorage/AP_FlashStorage.cpp +++ b/libraries/AP_FlashStorage/AP_FlashStorage.cpp @@ -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; } diff --git a/libraries/AP_FlashStorage/AP_FlashStorage.h b/libraries/AP_FlashStorage/AP_FlashStorage.h index 1ee8897f15..6f4e1fe1f7 100644 --- a/libraries/AP_FlashStorage/AP_FlashStorage.h +++ b/libraries/AP_FlashStorage/AP_FlashStorage.h @@ -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();