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
Show file tree
Hide file tree
Changes from 4 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
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;
Copy link

Choose a reason for hiding this comment

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

This is not correct (see PR 1313)

Copy link

Choose a reason for hiding this comment

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

As you can see (here) I also did the same change but in conjunction with the change in line 67 (which is the fix of the bug).

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 maxAllowedSector, requestedSector;

#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
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.");
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
cfg.log_page_size = LOG_PAGE_SIZE; // as we said
Expand Down