From 1fff41e80b4629da7519deaf1cdbff7d71b3eb75 Mon Sep 17 00:00:00 2001 From: ficeto Date: Thu, 21 May 2015 02:20:58 +0300 Subject: [PATCH] Make FileSystem take into account the exported page and block sizes --- boards.txt | 4 ++++ cores/esp8266/FileSystem.cpp | 18 +++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/boards.txt b/boards.txt index 19909edaf..0177228e0 100644 --- a/boards.txt +++ b/boards.txt @@ -57,6 +57,7 @@ generic.menu.FlashSize.512K.build.flash_size=512K generic.menu.FlashSize.512K.build.flash_ld=eagle.flash.512k.ld generic.menu.FlashSize.512K.build.spiffs_start=0x6B000 generic.menu.FlashSize.512K.build.spiffs_end=0x7B000 +generic.menu.FlashSize.512K.build.spiffs_blocksize=4096 generic.menu.FlashSize.1M512=1M (512K SPIFFS) generic.menu.FlashSize.1M512.build.flash_size=1M generic.menu.FlashSize.1M512.build.flash_ld=eagle.flash.1m512.ld @@ -68,16 +69,19 @@ generic.menu.FlashSize.1M256.build.flash_size=1M generic.menu.FlashSize.1M256.build.flash_ld=eagle.flash.1m256.ld generic.menu.FlashSize.1M256.build.spiffs_start=0xAB000 generic.menu.FlashSize.1M256.build.spiffs_end=0xFB000 +generic.menu.FlashSize.1M256.build.spiffs_blocksize=4096 generic.menu.FlashSize.1M128=1M (128K SPIFFS) generic.menu.FlashSize.1M128.build.flash_size=1M generic.menu.FlashSize.1M128.build.flash_ld=eagle.flash.1m128.ld generic.menu.FlashSize.1M128.build.spiffs_start=0xCB000 generic.menu.FlashSize.1M128.build.spiffs_end=0xFB000 +generic.menu.FlashSize.1M128.build.spiffs_blocksize=4096 generic.menu.FlashSize.1M64=1M (64K SPIFFS) generic.menu.FlashSize.1M64.build.flash_size=1M generic.menu.FlashSize.1M64.build.flash_ld=eagle.flash.1m64.ld generic.menu.FlashSize.1M64.build.spiffs_start=0xEB000 generic.menu.FlashSize.1M64.build.spiffs_end=0xFB000 +generic.menu.FlashSize.1M64.build.spiffs_blocksize=4096 generic.menu.FlashSize.2M=2M (1M SPIFFS) generic.menu.FlashSize.2M.build.flash_size=2M generic.menu.FlashSize.2M.build.flash_ld=eagle.flash.2m.ld diff --git a/cores/esp8266/FileSystem.cpp b/cores/esp8266/FileSystem.cpp index 34c4b43fa..3edcd0abb 100644 --- a/cores/esp8266/FileSystem.cpp +++ b/cores/esp8266/FileSystem.cpp @@ -22,15 +22,13 @@ #include "Arduino.h" #include "spiffs/spiffs_esp8266.h" -#define LOGICAL_PAGE_SIZE 256 -#define LOGICAL_BLOCK_SIZE (INTERNAL_FLASH_SECTOR_SIZE * 1) - - -// These addresses are defined in the linker script. +// These addresses and sizes are defined in the linker script. // For each flash memory size there is a linker script variant // which sets spiffs location and size. extern "C" uint32_t _SPIFFS_start; extern "C" uint32_t _SPIFFS_end; +extern "C" uint32_t _SPIFFS_page; +extern "C" uint32_t _SPIFFS_block; static s32_t api_spiffs_read(u32_t addr, u32_t size, u8_t *dst); static s32_t api_spiffs_write(u32_t addr, u32_t size, u8_t *src); @@ -51,23 +49,25 @@ int FSClass::_mountInternal(){ SPIFFS_API_DBG_E("Can't start file system, wrong address\r\n"); return SPIFFS_ERR_NOT_CONFIGURED; } + if(_SPIFFS_page == 0) _SPIFFS_page = 256; + if(_SPIFFS_block == 0) _SPIFFS_block = 4096; spiffs_config cfg = {0}; cfg.phys_addr = _beginAddress; cfg.phys_size = _endAddress - _beginAddress; cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; - cfg.log_block_size = LOGICAL_BLOCK_SIZE; - cfg.log_page_size = LOGICAL_PAGE_SIZE; + cfg.log_block_size = _SPIFFS_block; + cfg.log_page_size = _SPIFFS_page; cfg.hal_read_f = api_spiffs_read; cfg.hal_write_f = api_spiffs_write; cfg.hal_erase_f = api_spiffs_erase; SPIFFS_API_DBG_V("FSClass::_mountInternal: start:%x, size:%d Kb\n", cfg.phys_addr, cfg.phys_size / 1024); - _work.reset(new uint8_t[2*LOGICAL_PAGE_SIZE]); + _work.reset(new uint8_t[2*_SPIFFS_page]); _fdsSize = 32 * _maxOpenFiles; _fds.reset(new uint8_t[_fdsSize]); - _cacheSize = (32 + LOGICAL_PAGE_SIZE) * _maxOpenFiles; + _cacheSize = (32 + _SPIFFS_page) * _maxOpenFiles; _cache.reset(new uint8_t[_cacheSize]); s32_t res = SPIFFS_mount(&_fs,