diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index c482c8438..6f63c59cd 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -23,9 +23,12 @@ */ #include "FS.h" +#undef max +#undef min #include "FSImpl.h" #include "spiffs/spiffs.h" #include "debug.h" +#include extern "C" { #include "c_types.h" @@ -119,6 +122,27 @@ protected: config.log_block_size = _blockSize; config.log_page_size = _pageSize; + + if (((uint32_t) std::numeric_limits::max()) < (_size / _blockSize)) { + DEBUGV("spiffs_block_ix type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (_size / _pageSize)) { + DEBUGV("spiffs_page_ix type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (2 + (_size / (2*_pageSize))*2)) { + DEBUGV("spiffs_obj_id type too small"); + abort(); + } + + if (((uint32_t) std::numeric_limits::max()) < (_size / _pageSize - 1)) { + DEBUGV("spiffs_span_ix type too small"); + abort(); + } + // hack: even though fs is not initialized at this point, // SPIFFS_buffer_bytes_for_cache uses only fs->config.log_page_size // suggestion: change SPIFFS_buffer_bytes_for_cache to take @@ -381,8 +405,8 @@ extern "C" uint32_t _SPIFFS_page; extern "C" uint32_t _SPIFFS_block; static SPIFFSImpl s_defaultFs( - (uint32_t) &_SPIFFS_start - 0x40200000, - (uint32_t) (&_SPIFFS_end - &_SPIFFS_start), + (uint32_t) (&_SPIFFS_start) - 0x40200000, + (uint32_t) (&_SPIFFS_end) - (uint32_t) (&_SPIFFS_start), (uint32_t) &_SPIFFS_page, (uint32_t) &_SPIFFS_block, 5); diff --git a/cores/esp8266/spiffs_hal.cpp b/cores/esp8266/spiffs_hal.cpp index 2719eb6e0..6fab52266 100644 --- a/cores/esp8266/spiffs_hal.cpp +++ b/cores/esp8266/spiffs_hal.cpp @@ -31,18 +31,20 @@ extern "C" { } static int spi_flash_read_locked(uint32_t addr, uint32_t* dst, uint32_t size) { - InterruptLock lock; + optimistic_yield(10000); + AutoInterruptLock(5); return spi_flash_read(addr, dst, size); } static int spi_flash_write_locked(uint32_t addr, const uint32_t* src, uint32_t size) { - InterruptLock lock; + optimistic_yield(10000); + AutoInterruptLock(5); return spi_flash_write(addr, (uint32_t*) src, size); } static int spi_flash_erase_sector_locked(uint32_t sector) { optimistic_yield(10000); - InterruptLock lock; + AutoInterruptLock(5); return spi_flash_erase_sector(sector); }