TDBStore: call `BlockDevice::erase()` regarless of erase value

From the documentations of `BlockDevice::get_erase_value()`:

    -1 if you can't rely on the value of the erased storage

and `BlockDevice::program()`:

    The blocks must have been erased prior to being programmed

So, `BlockDevice::erase()` should always be called regardless of
erase value.
pull/14483/head
Lingkai Dong 2021-04-06 16:06:29 +01:00
parent fb4e5e80b4
commit aedc6009ea
1 changed files with 7 additions and 4 deletions

View File

@ -174,9 +174,12 @@ int TDBStore::erase_area(uint8_t area, uint32_t offset, uint32_t size)
{ {
uint32_t bd_offset = _area_params[area].address + offset; uint32_t bd_offset = _area_params[area].address + offset;
if (_buff_bd->get_erase_value() != -1) { int ret = _buff_bd->erase(bd_offset, size);
return _buff_bd->erase(bd_offset, size); if (ret) {
} else { return ret;
}
if (_buff_bd->get_erase_value() == -1) {
// We need to simulate erase to wipe records, as our block device // We need to simulate erase to wipe records, as our block device
// may not do it. Program in chunks of _work_buf_size if the minimum // may not do it. Program in chunks of _work_buf_size if the minimum
// program size is too small (e.g. one-byte) to avoid performance // program size is too small (e.g. one-byte) to avoid performance
@ -186,7 +189,7 @@ int TDBStore::erase_area(uint8_t area, uint32_t offset, uint32_t size)
memset(_work_buf, 0xFF, _work_buf_size); memset(_work_buf, 0xFF, _work_buf_size);
while (size) { while (size) {
uint32_t chunk = std::min<uint32_t>(_work_buf_size, size); uint32_t chunk = std::min<uint32_t>(_work_buf_size, size);
int ret = _buff_bd->program(_work_buf, bd_offset, chunk); ret = _buff_bd->program(_work_buf, bd_offset, chunk);
if (ret) { if (ret) {
return ret; return ret;
} }