Skip to content

Commit c02827e

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 23187d3 commit c02827e

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
@@ -172,7 +172,22 @@ int TDBStore::erase_erase_unit(uint8_t area, uint32_t offset)
172172
uint32_t bd_offset = _area_params[area].address + offset;
173173
uint32_t eu_size = _buff_bd->get_erase_size(bd_offset);
174174

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

178193
void TDBStore::calc_area_params()
@@ -1013,11 +1028,6 @@ int TDBStore::init()
10131028
goto fail;
10141029
}
10151030

1016-
// Underlying BD must have flash attributes, i.e. have an erase value
1017-
if (_bd->get_erase_value() == -1) {
1018-
MBED_ERROR(MBED_ERROR_INVALID_ARGUMENT, "Underlying BD must have flash attributes");
1019-
}
1020-
10211031
_prog_size = _bd->get_program_size();
10221032
_work_buf = new uint8_t[work_buf_size];
10231033
_key_buf = new char[MAX_KEY_SIZE];

0 commit comments

Comments
 (0)