Skip to content

Commit b34dd0c

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 06b22d9 commit b34dd0c

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
@@ -124,7 +124,7 @@ static uint32_t calc_crc(uint32_t init_crc, uint32_t data_size, const void *data
124124
TDBStore::TDBStore(BlockDevice *bd) : _ram_table(0), _max_keys(0),
125125
_num_keys(0), _bd(bd), _buff_bd(0), _free_space_offset(0), _master_record_offset(0),
126126
_master_record_size(0), _is_initialized(false), _active_area(0), _active_area_version(0), _size(0),
127-
_area_params{}, _prog_size(0), _work_buf(0), _key_buf(0), _variant_bd_erase_unit_size(false), _inc_set_handle(0)
127+
_area_params{}, _prog_size(0), _work_buf(0), _key_buf(0), _inc_set_handle(0)
128128
{
129129
for (int i = 0; i < _num_areas; i++) {
130130
_area_params[i] = { 0 };
@@ -194,19 +194,19 @@ void TDBStore::calc_area_params()
194194

195195
memset(_area_params, 0, sizeof(_area_params));
196196
size_t area_0_size = 0;
197-
bd_size_t prev_erase_unit_size = _bd->get_erase_size(area_0_size);
198-
_variant_bd_erase_unit_size = 0;
199197

200198
while (area_0_size < bd_size / 2) {
201199
bd_size_t erase_unit_size = _bd->get_erase_size(area_0_size);
202-
_variant_bd_erase_unit_size |= (erase_unit_size != prev_erase_unit_size);
203200
area_0_size += erase_unit_size;
204201
}
205202

206203
_area_params[0].address = 0;
207204
_area_params[0].size = area_0_size;
208205
_area_params[1].address = area_0_size;
209206
_area_params[1].size = bd_size - area_0_size;
207+
208+
// The areas must be of same size
209+
MBED_ASSERT(_area_params[0].size == _area_params[1].size);
210210
}
211211

212212

@@ -1427,14 +1427,8 @@ void TDBStore::offset_in_erase_unit(uint8_t area, uint32_t offset,
14271427
uint32_t &offset_from_start, uint32_t &dist_to_end)
14281428
{
14291429
uint32_t bd_offset = _area_params[area].address + offset;
1430-
if (!_variant_bd_erase_unit_size) {
1431-
uint32_t eu_size = _buff_bd->get_erase_size();
1432-
offset_from_start = bd_offset % eu_size;
1433-
dist_to_end = eu_size - offset_from_start;
1434-
return;
1435-
}
1436-
14371430
uint32_t agg_offset = 0;
1431+
14381432
while (bd_offset >= agg_offset + _buff_bd->get_erase_size(agg_offset)) {
14391433
agg_offset += _buff_bd->get_erase_size(agg_offset);
14401434
}

features/storage/kvstore/tdbstore/TDBStore.h

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

0 commit comments

Comments
 (0)