Skip to content

Give the app space to grow in internal KVStore default configuration #9156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions features/storage/kvstore/conf/kv_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,27 @@ int _storage_config_TDB_INTERNAL()
return MBED_ERROR_FAILED_OPERATION;
}
internal_start_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR));

// Give the application a couple of spare sectors to grow (if there are such)
bd_size_t spare_size_for_app = 0;
bd_addr_t curr_addr = internal_start_address;
bd_addr_t flash_end_address = flash.get_flash_start() + flash.get_flash_size();

int spare_sectors_for_app = 2;
int min_sectors_for_storage = 2;
for (int i = 0; i < spare_sectors_for_app + min_sectors_for_storage - 1; i++) {
bd_size_t sector_size = flash.get_sector_size(curr_addr);
curr_addr += sector_size;
if (curr_addr >= flash_end_address) {
spare_size_for_app = 0;
break;
}
if (i < spare_sectors_for_app) {
spare_size_for_app += sector_size;
}
}
internal_start_address += spare_size_for_app;

flash.deinit();
}

Expand Down