Skip to content
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

Fixed the SPIFFS size calculation. #1653

Merged
merged 5 commits into from
Mar 28, 2019
Merged
Changes from 1 commit
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
16 changes: 8 additions & 8 deletions Sming/appspecific/rboot/overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
spiffs_config spiffs_get_storage_config()
{
spiffs_config cfg = {0};
u32_t maxAllowedEndAddress, requestedEndAddress;
u32_t maxAllowedSector, requestedSector;

#ifdef RBOOT_SPIFFS_0
cfg.phys_addr = RBOOT_SPIFFS_0;
Expand All @@ -18,15 +18,15 @@ spiffs_config spiffs_get_storage_config()
#error "Define either RBOOT_SPIFFS_0 or RBOOT_SPIFFS_1"
#endif

maxAllowedEndAddress = INTERNAL_FLASH_SIZE - 1;
requestedEndAddress = cfg.phys_addr + SPIFF_SIZE - 1;
if(requestedEndAddress > maxAllowedEndAddress) {
cfg.phys_addr &= 0xFFFFF000; // get the start address of the sector
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the following code would be better:

cfg.phys_addr -= cfg.phys_addr % INTERNAL_FLASH_SECTOR_SIZE;


maxAllowedSector = flashmem_get_sector_of_address(INTERNAL_FLASH_SIZE - 1);
requestedSector = flashmem_get_sector_of_address((cfg.phys_addr + SPIFF_SIZE) - 1);
if(requestedSector > maxAllowedSector) {
debug_w("The requested SPIFFS size is too big.");
cfg.phys_size = (maxAllowedEndAddress + 1) - ( ( u32_t )cfg.phys_addr);
}
else {
cfg.phys_size = SPIFF_SIZE;
requestedSector = maxAllowedSector;
}
cfg.phys_size = ((requestedSector + 1) * INTERNAL_FLASH_SECTOR_SIZE) - ( ( u32_t )cfg.phys_addr); // get the max size until the sector end.

cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet
cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE * 2; // Important to make large
Expand Down