Skip to content

Commit

Permalink
Fixes to the SPIFFS size calculation. (#1653)
Browse files Browse the repository at this point in the history
Special thanks to @jonnykl and @mikee47  for their help and feedback.
  • Loading branch information
slaff authored Mar 28, 2019
1 parent f9f5757 commit 4b4501a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
16 changes: 11 additions & 5 deletions Sming/Services/SpifFS/spiffs_sming.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,31 @@ bool spiffs_format_internal(spiffs_config *cfg)
{
if (cfg->phys_addr == 0)
{
SYSTEM_ERROR("Can't format file system, wrong address");
SYSTEM_ERROR("Can't format file system, wrong address given.");
return false;
}

if (cfg->phys_size == 0)
{
SYSTEM_ERROR("Can't format file system, wrong size given.");
return false;
}

u32_t sect_first, sect_last;
sect_first = cfg->phys_addr;
sect_first = flashmem_get_sector_of_address(sect_first);
sect_last = cfg->phys_addr + cfg->phys_size;
sect_last = cfg->phys_addr + cfg->phys_size - 1;
sect_last = flashmem_get_sector_of_address(sect_last);
debugf("sect_first: %x, sect_last: %x\n", sect_first, sect_last);
ETS_INTR_LOCK();
int total = sect_last - sect_first;
int total = sect_last - sect_first + 1;
int cur = 0;
int last = -1;
while( sect_first <= sect_last )
{
if(flashmem_erase_sector( sect_first++ ))
{
int percent = cur++ * 100 / total;
int percent = ++cur * 100 / total;
if (percent > last)
debugf("%d%%", percent);
last = percent;
Expand All @@ -85,7 +91,7 @@ bool spiffs_format_internal(spiffs_config *cfg)
return false;
}
}
debugf("formated");
debugf("formatted");
ETS_INTR_UNLOCK();

return true;
Expand Down
14 changes: 13 additions & 1 deletion Sming/appspecific/rboot/overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@
spiffs_config spiffs_get_storage_config()
{
spiffs_config cfg = {0};
u32_t max_allowed_sector, requested_sector;

#ifdef RBOOT_SPIFFS_0
cfg.phys_addr = RBOOT_SPIFFS_0;
#elif RBOOT_SPIFFS_1
cfg.phys_addr = RBOOT_SPIFFS_1;
#else
#error "Define either RBOOT_SPIFFS_0 or RBOOT_SPIFFS_1"
#endif
cfg.phys_size = SPIFF_SIZE;

cfg.phys_addr &= 0xFFFFF000; // get the start address of the sector

max_allowed_sector = flashmem_get_sector_of_address(INTERNAL_FLASH_SIZE - 1);
requested_sector = flashmem_get_sector_of_address((cfg.phys_addr + SPIFF_SIZE) - 1);
if(requested_sector > max_allowed_sector) {
debug_w("The requested SPIFFS size is too big.");
requested_sector = max_allowed_sector;
}
cfg.phys_size = ((requested_sector + 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
cfg.log_page_size = LOG_PAGE_SIZE; // as we said
Expand Down

0 comments on commit 4b4501a

Please sign in to comment.