Skip to content

Commit ece58b7

Browse files
author
Kyle Kearney
committed
Expand error checks in _calculate_blocksize_match_tdbstore
The minimum size required by tdbstore is either 2 sectors or 10 pages, whichever is larger. Correspondingly, adjust the error checks in _calculate_blocksize_match_tdbstore to match this requirement.
1 parent d6a1ac6 commit ece58b7

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

features/storage/kvstore/conf/kv_config.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,19 @@ int _calculate_blocksize_match_tdbstore(BlockDevice *bd)
176176
{
177177
bd_size_t size = bd->size();
178178
bd_size_t erase_size = bd->get_erase_size();
179+
bd_size_t page_size = bd->get_program_size();
179180
bd_size_t number_of_sector = size / erase_size;
180-
181-
if (number_of_sector < 2) {
181+
bd_size_t number_of_page = size / page_size;
182+
if (number_of_sector < TDBStore::STORE_SECTORS) {
182183
tr_warning("KV Config: There are less than two sectors - TDBStore will not work.");
183184
return -1;
184185
}
185186

187+
if (number_of_page < TDBStore::STORE_PAGES) {
188+
tr_warning("KV Config: There are less than ten pages sectors - TDBStore will not work.");
189+
return -1;
190+
}
191+
186192

187193
if (number_of_sector % 2 != 0) {
188194
tr_warning("KV Config: Number of sectors is not an even number. Consider changing the BlockDevice size");
@@ -575,9 +581,9 @@ int _create_internal_tdb(BlockDevice **internal_bd, KVStore **internal_tdb, bd_s
575581
return MBED_ERROR_FAILED_OPERATION ;
576582
}
577583

578-
//Check if TDBStore has at least 2 sector.
584+
//Check if TDBStore has at least 2 sectors or 10 pages.
579585
if (_calculate_blocksize_match_tdbstore(*internal_bd) != MBED_SUCCESS) {
580-
tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
586+
tr_error("KV Config: Can not create TDBStore with less then 2 sectors or 10 pages.");
581587
return MBED_ERROR_INVALID_ARGUMENT;
582588
}
583589

@@ -743,9 +749,9 @@ int _storage_config_tdb_external_common()
743749
return MBED_ERROR_FAILED_OPERATION ;
744750
}
745751

746-
//Check that there is at least 2 sector for the external TDBStore
752+
//Check that there is at least 2 sectors for the external TDBStore
747753
if (_calculate_blocksize_match_tdbstore(kvstore_config.external_bd) != MBED_SUCCESS) {
748-
tr_error("KV Config: Can not create TDBStore with less then 2 sector.");
754+
tr_error("KV Config: Can not create TDBStore with less then 2 sectors or 10 pages.");
749755
return MBED_ERROR_INVALID_SIZE;
750756
}
751757

features/storage/kvstore/tdbstore/TDBStore.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,11 +1463,6 @@ int TDBStore::get_default_flash_addresses(bd_addr_t *start_address, bd_size_t *s
14631463
return MBED_ERROR_INITIALIZATION_FAILED;
14641464
}
14651465

1466-
// Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger)
1467-
// For each area: must be a minimum of 1 page of reserved and 2 pages for master record
1468-
static const int STORE_SECTORS = 2;
1469-
static const int STORE_PAGES = 10;
1470-
14711466
// Let's work from end of the flash backwards
14721467
bd_addr_t curr_addr = flash.get_flash_start() + flash.get_flash_size();
14731468
bd_size_t sector_space = 0;

features/storage/kvstore/tdbstore/TDBStore.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class TDBStore : public KVStore {
3636

3737
static const uint32_t RESERVED_AREA_SIZE = 64;
3838

39+
// Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger)
40+
// For each area: must be a minimum of 1 page of reserved and 2 pages for master record
41+
/** Minimum number of internal flash sectors required for TDBStore */
42+
static const int STORE_SECTORS = 2;
43+
/** Minimum number of internal flash pages required for TDBStore */
44+
static const int STORE_PAGES = 10;
45+
3946
/**
4047
* @brief Class constructor
4148
*

0 commit comments

Comments
 (0)