Skip to content

Commit 0ec410e

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 e89b93c commit 0ec410e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

UNITTESTS/moduletests/storage/kvstore/TDBStore/moduletest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ HeapBlockDevice sd{DEVICE_SIZE};
3434

3535
class TDBStoreModuleTest : public testing::Test {
3636
protected:
37-
FlashSimBlockDevice flash{&sd};
38-
TDBStore tdb{&flash};
37+
TDBStore tdb{&sd};
3938

4039
virtual void SetUp()
4140
{

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()
@@ -1018,11 +1033,6 @@ int TDBStore::init()
10181033
goto fail;
10191034
}
10201035

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

0 commit comments

Comments
 (0)