Skip to content

Commit a852c00

Browse files
committed
Merge pull request #5 from esp8266/esp8266
pull master
2 parents 82729bd + aafacdc commit a852c00

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

hardware/esp8266com/esp8266/cores/esp8266/spiffs_api.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
*/
2424

2525
#include "FS.h"
26+
#undef max
27+
#undef min
2628
#include "FSImpl.h"
2729
#include "spiffs/spiffs.h"
2830
#include "debug.h"
31+
#include <limits>
2932

3033
extern "C" {
3134
#include "c_types.h"
@@ -119,6 +122,27 @@ class SPIFFSImpl : public FSImpl {
119122
config.log_block_size = _blockSize;
120123
config.log_page_size = _pageSize;
121124

125+
126+
if (((uint32_t) std::numeric_limits<spiffs_block_ix>::max()) < (_size / _blockSize)) {
127+
DEBUGV("spiffs_block_ix type too small");
128+
abort();
129+
}
130+
131+
if (((uint32_t) std::numeric_limits<spiffs_page_ix>::max()) < (_size / _pageSize)) {
132+
DEBUGV("spiffs_page_ix type too small");
133+
abort();
134+
}
135+
136+
if (((uint32_t) std::numeric_limits<spiffs_obj_id>::max()) < (2 + (_size / (2*_pageSize))*2)) {
137+
DEBUGV("spiffs_obj_id type too small");
138+
abort();
139+
}
140+
141+
if (((uint32_t) std::numeric_limits<spiffs_span_ix>::max()) < (_size / _pageSize - 1)) {
142+
DEBUGV("spiffs_span_ix type too small");
143+
abort();
144+
}
145+
122146
// hack: even though fs is not initialized at this point,
123147
// SPIFFS_buffer_bytes_for_cache uses only fs->config.log_page_size
124148
// suggestion: change SPIFFS_buffer_bytes_for_cache to take
@@ -381,8 +405,8 @@ extern "C" uint32_t _SPIFFS_page;
381405
extern "C" uint32_t _SPIFFS_block;
382406

383407
static SPIFFSImpl s_defaultFs(
384-
(uint32_t) &_SPIFFS_start - 0x40200000,
385-
(uint32_t) (&_SPIFFS_end - &_SPIFFS_start),
408+
(uint32_t) (&_SPIFFS_start) - 0x40200000,
409+
(uint32_t) (&_SPIFFS_end) - (uint32_t) (&_SPIFFS_start),
386410
(uint32_t) &_SPIFFS_page,
387411
(uint32_t) &_SPIFFS_block,
388412
5);

hardware/esp8266com/esp8266/cores/esp8266/spiffs_hal.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ extern "C" {
3131
}
3232

3333
static int spi_flash_read_locked(uint32_t addr, uint32_t* dst, uint32_t size) {
34-
InterruptLock lock;
34+
optimistic_yield(10000);
35+
AutoInterruptLock(5);
3536
return spi_flash_read(addr, dst, size);
3637
}
3738

3839
static int spi_flash_write_locked(uint32_t addr, const uint32_t* src, uint32_t size) {
39-
InterruptLock lock;
40+
optimistic_yield(10000);
41+
AutoInterruptLock(5);
4042
return spi_flash_write(addr, (uint32_t*) src, size);
4143
}
4244

4345
static int spi_flash_erase_sector_locked(uint32_t sector) {
4446
optimistic_yield(10000);
45-
InterruptLock lock;
47+
AutoInterruptLock(5);
4648
return spi_flash_erase_sector(sector);
4749
}
4850

0 commit comments

Comments
 (0)