pw_kvs: Check that the flash partition has minimum needed sectors
Verify that the KVS's flash partition has enough sectors to actually
function. That is 1 working sector + 1 free sector, for a minimum
required of 2 sectors.
Change-Id: Ic850bf2c19aa66fa1cc143a433c3f624f292387b
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index 84cc4cf..68a8412 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -70,6 +70,13 @@
return Status::FAILED_PRECONDITION;
}
+ if (partition_.sector_count() < 2) {
+ ERR("KVS init failed: FlashParition sector count (=%u) must be at 2. KVS "
+ "requires at least 1 working sector + 1 free/reserved sector",
+ unsigned(partition_.sector_count()));
+ return Status::FAILED_PRECONDITION;
+ }
+
const size_t sector_size_bytes = partition_.sector_size_bytes();
// TODO: investigate doing this as a static assert/compile-time check.