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.
pull/11629/head
Kyle Kearney 2019-10-29 16:20:47 -07:00
parent cda0af66eb
commit 7cd4d11a8a
3 changed files with 19 additions and 11 deletions

View File

@ -180,13 +180,19 @@ int _calculate_blocksize_match_tdbstore(BlockDevice *bd)
{ {
bd_size_t size = bd->size(); bd_size_t size = bd->size();
bd_size_t erase_size = bd->get_erase_size(); bd_size_t erase_size = bd->get_erase_size();
bd_size_t page_size = bd->get_program_size();
bd_size_t number_of_sector = size / erase_size; bd_size_t number_of_sector = size / erase_size;
bd_size_t number_of_page = size / page_size;
if (number_of_sector < 2) { if (number_of_sector < TDBStore::STORE_SECTORS) {
tr_warning("KV Config: There are less than two sectors - TDBStore will not work."); tr_warning("KV Config: There are less than two sectors - TDBStore will not work.");
return -1; return -1;
} }
if (number_of_page < TDBStore::STORE_PAGES) {
tr_warning("KV Config: There are less than ten pages sectors - TDBStore will not work.");
return -1;
}
if (number_of_sector % 2 != 0) { if (number_of_sector % 2 != 0) {
tr_warning("KV Config: Number of sectors is not an even number. Consider changing the BlockDevice size"); tr_warning("KV Config: Number of sectors is not an even number. Consider changing the BlockDevice size");
@ -586,9 +592,9 @@ int _create_internal_tdb(BlockDevice **internal_bd, KVStore **internal_tdb, bd_s
return MBED_ERROR_FAILED_OPERATION ; return MBED_ERROR_FAILED_OPERATION ;
} }
//Check if TDBStore has at least 2 sector. //Check if TDBStore has at least 2 sectors or 10 pages.
if (_calculate_blocksize_match_tdbstore(*internal_bd) != MBED_SUCCESS) { if (_calculate_blocksize_match_tdbstore(*internal_bd) != MBED_SUCCESS) {
tr_error("KV Config: Can not create TDBStore with less then 2 sector."); tr_error("KV Config: Can not create TDBStore with less then 2 sectors or 10 pages.");
return MBED_ERROR_INVALID_ARGUMENT; return MBED_ERROR_INVALID_ARGUMENT;
} }
@ -754,9 +760,9 @@ int _storage_config_tdb_external_common()
return MBED_ERROR_FAILED_OPERATION ; return MBED_ERROR_FAILED_OPERATION ;
} }
//Check that there is at least 2 sector for the external TDBStore //Check that there is at least 2 sectors for the external TDBStore
if (_calculate_blocksize_match_tdbstore(kvstore_config.external_bd) != MBED_SUCCESS) { if (_calculate_blocksize_match_tdbstore(kvstore_config.external_bd) != MBED_SUCCESS) {
tr_error("KV Config: Can not create TDBStore with less then 2 sector."); tr_error("KV Config: Can not create TDBStore with less then 2 sectors or 10 pages.");
return MBED_ERROR_INVALID_SIZE; return MBED_ERROR_INVALID_SIZE;
} }

View File

@ -1438,11 +1438,6 @@ int TDBStore::get_default_flash_addresses(bd_addr_t *start_address, bd_size_t *s
return MBED_ERROR_INITIALIZATION_FAILED; return MBED_ERROR_INITIALIZATION_FAILED;
} }
// Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger)
// For each area: must be a minimum of 1 page of reserved and 2 pages for master record
static const int STORE_SECTORS = 2;
static const int STORE_PAGES = 10;
// Let's work from end of the flash backwards // Let's work from end of the flash backwards
bd_addr_t curr_addr = flash.get_flash_start() + flash.get_flash_size(); bd_addr_t curr_addr = flash.get_flash_start() + flash.get_flash_size();
bd_size_t sector_space = 0; bd_size_t sector_space = 0;

View File

@ -37,6 +37,13 @@ public:
static const uint32_t RESERVED_AREA_SIZE = 64; static const uint32_t RESERVED_AREA_SIZE = 64;
// Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger)
// For each area: must be a minimum of 1 page of reserved and 2 pages for master record
/** Minimum number of internal flash sectors required for TDBStore */
static const int STORE_SECTORS = 2;
/** Minimum number of internal flash pages required for TDBStore */
static const int STORE_PAGES = 10;
/** /**
* @brief Class constructor * @brief Class constructor
* *