Skip to content

Commit 2f0907c

Browse files
author
Jarno Lamsa
committed
Remove _variant_bd_erase_unit_size
In some cases, it is possible that every erase unit in area 0 has the same size, but they are still different than in area 1. Remove the flag for varying erase sizes and instead check from flash, what is the erase size of the current unit.
1 parent e642a7d commit 2f0907c

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

features/storage/kvstore/tdbstore/TDBStore.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static uint32_t calc_crc(uint32_t init_crc, uint32_t data_size, const void *data
126126
TDBStore::TDBStore(BlockDevice *bd) : _ram_table(0), _max_keys(0),
127127
_num_keys(0), _bd(bd), _buff_bd(0), _free_space_offset(0), _master_record_offset(0),
128128
_master_record_size(0), _is_initialized(false), _active_area(0), _active_area_version(0), _size(0),
129-
_area_params{}, _prog_size(0), _work_buf(0), _key_buf(0), _variant_bd_erase_unit_size(false), _inc_set_handle(0)
129+
_area_params{}, _prog_size(0), _work_buf(0), _key_buf(0), _inc_set_handle(0)
130130
{
131131
for (int i = 0; i < _num_areas; i++) {
132132
_area_params[i] = { 0 };
@@ -186,19 +186,19 @@ void TDBStore::calc_area_params()
186186

187187
memset(_area_params, 0, sizeof(_area_params));
188188
size_t area_0_size = 0;
189-
bd_size_t prev_erase_unit_size = _bd->get_erase_size(area_0_size);
190-
_variant_bd_erase_unit_size = 0;
191189

192190
while (area_0_size < bd_size / 2) {
193191
bd_size_t erase_unit_size = _bd->get_erase_size(area_0_size);
194-
_variant_bd_erase_unit_size |= (erase_unit_size != prev_erase_unit_size);
195192
area_0_size += erase_unit_size;
196193
}
197194

198195
_area_params[0].address = 0;
199196
_area_params[0].size = area_0_size;
200197
_area_params[1].address = area_0_size;
201198
_area_params[1].size = bd_size - area_0_size;
199+
200+
// The areas must be of same size
201+
MBED_ASSERT(_area_params[0].size == _area_params[1].size);
202202
}
203203

204204

@@ -1487,14 +1487,8 @@ void TDBStore::offset_in_erase_unit(uint8_t area, uint32_t offset,
14871487
uint32_t &offset_from_start, uint32_t &dist_to_end)
14881488
{
14891489
uint32_t bd_offset = _area_params[area].address + offset;
1490-
if (!_variant_bd_erase_unit_size) {
1491-
uint32_t eu_size = _buff_bd->get_erase_size();
1492-
offset_from_start = bd_offset % eu_size;
1493-
dist_to_end = eu_size - offset_from_start;
1494-
return;
1495-
}
1496-
14971490
uint32_t agg_offset = 0;
1491+
14981492
while (bd_offset >= agg_offset + _buff_bd->get_erase_size(agg_offset)) {
14991493
agg_offset += _buff_bd->get_erase_size(agg_offset);
15001494
}

features/storage/kvstore/tdbstore/TDBStore.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ class TDBStore : public KVStore {
308308
uint32_t _prog_size;
309309
uint8_t *_work_buf;
310310
char *_key_buf;
311-
bool _variant_bd_erase_unit_size;
312311
void *_inc_set_handle;
313312
void *_iterator_table[_max_open_iterators];
314313

0 commit comments

Comments
 (0)