Skip to content

Commit adf409f

Browse files
author
Seppo Takalo
committed
Do not require Flash device for TDBStore
TDBStore used to rely on Flash devices erase value. This logic has been removed, and TDBStore can do the entire erase logic itself, in case the given BlockDevice does not offer erase(). This relies on BlockDevice to properly return -1 in BlockDevice::get_erase_value().
1 parent 3dc6c48 commit adf409f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

features/storage/kvstore/tdbstore/TDBStore.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,22 @@ int TDBStore::erase_erase_unit(uint8_t area, uint32_t offset)
177177
uint32_t bd_offset = _area_params[area].address + offset;
178178
uint32_t eu_size = _buff_bd->get_erase_size(bd_offset);
179179

180-
return _buff_bd->erase(bd_offset, eu_size);
180+
if (_buff_bd->get_erase_value() != -1) {
181+
return _buff_bd->erase(bd_offset, eu_size);
182+
} else {
183+
// We need to simulate erase, as our block device
184+
// does not do it. We can do this one byte at a time
185+
// because we use BufferedBlockDevice that has page buffers
186+
uint8_t val = 0xff;
187+
int ret;
188+
for (; eu_size; --eu_size) {
189+
ret = _buff_bd->program(&val, bd_offset++, 1);
190+
if (ret) {
191+
return ret;
192+
}
193+
}
194+
}
195+
return MBED_SUCCESS;
181196
}
182197

183198
void TDBStore::calc_area_params()
@@ -1017,11 +1032,6 @@ int TDBStore::init()
10171032
goto fail;
10181033
}
10191034

1020-
// Underlying BD must have flash attributes, i.e. have an erase value
1021-
if (_bd->get_erase_value() == -1) {
1022-
MBED_ERROR(MBED_ERROR_INVALID_ARGUMENT, "Underlying BD must have flash attributes");
1023-
}
1024-
10251035
_prog_size = _bd->get_program_size();
10261036
_work_buf = new uint8_t[work_buf_size];
10271037
_key_buf = new char[MAX_KEY_SIZE];

0 commit comments

Comments
 (0)