From 8c1518db43e12f82ed39167c90500fadbf354953 Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Tue, 26 Mar 2019 15:12:01 +0100 Subject: [PATCH 1/5] Fixed the SPIFFS size calculation. --- Sming/appspecific/rboot/overrides.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sming/appspecific/rboot/overrides.c b/Sming/appspecific/rboot/overrides.c index fcf3d83333..4de3da4828 100644 --- a/Sming/appspecific/rboot/overrides.c +++ b/Sming/appspecific/rboot/overrides.c @@ -8,6 +8,8 @@ spiffs_config spiffs_get_storage_config() { spiffs_config cfg = {0}; + u32_t maxAllowedEndAddress, requestedEndAddress; + #ifdef RBOOT_SPIFFS_0 cfg.phys_addr = RBOOT_SPIFFS_0; #elif RBOOT_SPIFFS_1 @@ -15,7 +17,17 @@ spiffs_config spiffs_get_storage_config() #else #error "Define either RBOOT_SPIFFS_0 or RBOOT_SPIFFS_1" #endif - cfg.phys_size = SPIFF_SIZE; + + maxAllowedEndAddress = INTERNAL_FLASH_SIZE; + requestedEndAddress = cfg.phys_addr + SPIFF_SIZE; + if(requestedEndAddress > maxAllowedEndAddress) { + debug_w("The requested SPIFFS size is too big."); + cfg.phys_size = maxAllowedEndAddress - ( ( u32_t )cfg.phys_addr); + } + else { + cfg.phys_size = SPIFF_SIZE; + } + 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 From af41784ee5aff7a8669295b1f27b885287442364 Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Tue, 26 Mar 2019 18:05:15 +0100 Subject: [PATCH 2/5] In the debug print the already completed percentage. --- Sming/Services/SpifFS/spiffs_sming.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sming/Services/SpifFS/spiffs_sming.c b/Sming/Services/SpifFS/spiffs_sming.c index 4af5d71998..08bcdb2064 100644 --- a/Sming/Services/SpifFS/spiffs_sming.c +++ b/Sming/Services/SpifFS/spiffs_sming.c @@ -56,7 +56,13 @@ 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; } @@ -67,14 +73,14 @@ bool spiffs_format_internal(spiffs_config *cfg) 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; @@ -85,7 +91,7 @@ bool spiffs_format_internal(spiffs_config *cfg) return false; } } - debugf("formated"); + debugf("formatted"); ETS_INTR_UNLOCK(); return true; From 1751c9651aee7a9b673b1ce7280f06f043f59ea7 Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Wed, 27 Mar 2019 10:02:07 +0100 Subject: [PATCH 3/5] Fixes to addresses and sizes. --- Sming/Services/SpifFS/spiffs_sming.c | 2 +- Sming/appspecific/rboot/overrides.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sming/Services/SpifFS/spiffs_sming.c b/Sming/Services/SpifFS/spiffs_sming.c index 08bcdb2064..c7186e127f 100644 --- a/Sming/Services/SpifFS/spiffs_sming.c +++ b/Sming/Services/SpifFS/spiffs_sming.c @@ -69,7 +69,7 @@ bool spiffs_format_internal(spiffs_config *cfg) 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(); diff --git a/Sming/appspecific/rboot/overrides.c b/Sming/appspecific/rboot/overrides.c index 4de3da4828..f0034afcbc 100644 --- a/Sming/appspecific/rboot/overrides.c +++ b/Sming/appspecific/rboot/overrides.c @@ -18,11 +18,11 @@ spiffs_config spiffs_get_storage_config() #error "Define either RBOOT_SPIFFS_0 or RBOOT_SPIFFS_1" #endif - maxAllowedEndAddress = INTERNAL_FLASH_SIZE; - requestedEndAddress = cfg.phys_addr + SPIFF_SIZE; + maxAllowedEndAddress = INTERNAL_FLASH_SIZE - 1; + requestedEndAddress = cfg.phys_addr + SPIFF_SIZE - 1; if(requestedEndAddress > maxAllowedEndAddress) { debug_w("The requested SPIFFS size is too big."); - cfg.phys_size = maxAllowedEndAddress - ( ( u32_t )cfg.phys_addr); + cfg.phys_size = (maxAllowedEndAddress + 1) - ( ( u32_t )cfg.phys_addr); } else { cfg.phys_size = SPIFF_SIZE; From 1bf5e393b1b0e135f8fc42bcb73ceef7b1b8aa98 Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Wed, 27 Mar 2019 15:27:44 +0100 Subject: [PATCH 4/5] Adjust the start adress to be the start address of the sector. Adjust the size to include the end of the sector. --- Sming/appspecific/rboot/overrides.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sming/appspecific/rboot/overrides.c b/Sming/appspecific/rboot/overrides.c index f0034afcbc..24e60e42b8 100644 --- a/Sming/appspecific/rboot/overrides.c +++ b/Sming/appspecific/rboot/overrides.c @@ -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; @@ -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 + + 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 From 9f00a7d5e1239b31a5f215a2ab00831947dbae82 Mon Sep 17 00:00:00 2001 From: Slavey Karadzhov Date: Thu, 28 Mar 2019 09:48:00 +0100 Subject: [PATCH 5/5] Coding style fixes. --- Sming/appspecific/rboot/overrides.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sming/appspecific/rboot/overrides.c b/Sming/appspecific/rboot/overrides.c index 24e60e42b8..d0b452fe61 100644 --- a/Sming/appspecific/rboot/overrides.c +++ b/Sming/appspecific/rboot/overrides.c @@ -8,7 +8,7 @@ spiffs_config spiffs_get_storage_config() { spiffs_config cfg = {0}; - u32_t maxAllowedSector, requestedSector; + u32_t max_allowed_sector, requested_sector; #ifdef RBOOT_SPIFFS_0 cfg.phys_addr = RBOOT_SPIFFS_0; @@ -20,13 +20,13 @@ spiffs_config spiffs_get_storage_config() cfg.phys_addr &= 0xFFFFF000; // get the start address of the sector - 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) { + 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."); - requestedSector = maxAllowedSector; + requested_sector = max_allowed_sector; } - cfg.phys_size = ((requestedSector + 1) * INTERNAL_FLASH_SECTOR_SIZE) - ( ( u32_t )cfg.phys_addr); // get the max size until the sector end. + 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