+uint8_t
+ao_storage_erase(uint32_t start_pos, uint32_t len)
+{
+ /* Round 'len' up to ao_storage_block units */
+ len = ((len + ao_storage_block - 1) / ao_storage_block) * ao_storage_block;
+
+ /*
+ * Start at the end of the area to erase so that the
+ * last block cleared is the first block; this will ensure
+ * that partially erased flight logs still appear in the list
+ * and can be re-erased.
+ */
+ uint32_t pos = start_pos + len - ao_storage_block;
+ while (len) {
+ int tries;
+
+#define MAX_TRIES 4 /* needs to be at least 2 */
+ for (tries = 0; tries < MAX_TRIES; tries++) {
+ if (ao_storage_is_erased(pos))
+ break;
+ if (!ao_storage_device_erase(pos))
+ return 0;
+ }
+ if (tries == MAX_TRIES)
+ return 0;
+ pos -= ao_storage_block;
+ len -= ao_storage_block;
+ }
+ return 1;
+}