mirror of https://github.com/ARMmbed/mbed-os.git
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().pull/11987/head
parent
3dc6c4879f
commit
adf409f7f7
|
@ -177,7 +177,22 @@ int TDBStore::erase_erase_unit(uint8_t area, uint32_t offset)
|
|||
uint32_t bd_offset = _area_params[area].address + offset;
|
||||
uint32_t eu_size = _buff_bd->get_erase_size(bd_offset);
|
||||
|
||||
if (_buff_bd->get_erase_value() != -1) {
|
||||
return _buff_bd->erase(bd_offset, eu_size);
|
||||
} else {
|
||||
// We need to simulate erase, as our block device
|
||||
// does not do it. We can do this one byte at a time
|
||||
// because we use BufferedBlockDevice that has page buffers
|
||||
uint8_t val = 0xff;
|
||||
int ret;
|
||||
for (; eu_size; --eu_size) {
|
||||
ret = _buff_bd->program(&val, bd_offset++, 1);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return MBED_SUCCESS;
|
||||
}
|
||||
|
||||
void TDBStore::calc_area_params()
|
||||
|
@ -1017,11 +1032,6 @@ int TDBStore::init()
|
|||
goto fail;
|
||||
}
|
||||
|
||||
// Underlying BD must have flash attributes, i.e. have an erase value
|
||||
if (_bd->get_erase_value() == -1) {
|
||||
MBED_ERROR(MBED_ERROR_INVALID_ARGUMENT, "Underlying BD must have flash attributes");
|
||||
}
|
||||
|
||||
_prog_size = _bd->get_program_size();
|
||||
_work_buf = new uint8_t[work_buf_size];
|
||||
_key_buf = new char[MAX_KEY_SIZE];
|
||||
|
|
Loading…
Reference in New Issue