Skip to content

Commit d62d143

Browse files
committed
fix esp8266#5246 - also add optional SPIFFS.begin(false): will not try to format (default is true)
1 parent 2eb5b56 commit d62d143

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

cores/esp8266/spiffs_api.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,6 @@ bool isSpiffsFilenameValid(const char* name)
110110

111111
// these symbols should be defined in the linker script for each flash layout
112112
#ifdef ARDUINO
113-
extern "C" uint32_t _SPIFFS_start;
114-
extern "C" uint32_t _SPIFFS_end;
115-
extern "C" uint32_t _SPIFFS_page;
116-
extern "C" uint32_t _SPIFFS_block;
117-
118-
#define SPIFFS_PHYS_ADDR ((uint32_t) (&_SPIFFS_start) - 0x40200000)
119-
#define SPIFFS_PHYS_SIZE ((uint32_t) (&_SPIFFS_end) - (uint32_t) (&_SPIFFS_start))
120-
#define SPIFFS_PHYS_PAGE ((uint32_t) &_SPIFFS_page)
121-
#define SPIFFS_PHYS_BLOCK ((uint32_t) &_SPIFFS_block)
122-
123113
#ifndef SPIFFS_MAX_OPEN_FILES
124114
#define SPIFFS_MAX_OPEN_FILES 5
125115
#endif

cores/esp8266/spiffs_api.h

+21
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535

3636
using namespace fs;
3737

38+
extern "C" uint32_t _SPIFFS_start;
39+
extern "C" uint32_t _SPIFFS_end;
40+
extern "C" uint32_t _SPIFFS_page;
41+
extern "C" uint32_t _SPIFFS_block;
42+
43+
#define SPIFFS_PHYS_ADDR ((uint32_t) (&_SPIFFS_start) - 0x40200000)
44+
#define SPIFFS_PHYS_SIZE ((uint32_t) (&_SPIFFS_end) - (uint32_t) (&_SPIFFS_start))
45+
#define SPIFFS_PHYS_PAGE ((uint32_t) &_SPIFFS_page)
46+
#define SPIFFS_PHYS_BLOCK ((uint32_t) &_SPIFFS_block)
47+
3848
extern int32_t spiffs_hal_write(uint32_t addr, uint32_t size, uint8_t *src);
3949
extern int32_t spiffs_hal_erase(uint32_t addr, uint32_t size);
4050
extern int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst);
@@ -114,6 +124,14 @@ class SPIFFSImpl : public FSImpl
114124

115125
bool begin() override
116126
{
127+
return begin(true);
128+
}
129+
130+
bool begin(bool autoformat)
131+
{
132+
if (_SPIFFS_start <= _SPIFFS_end)
133+
return false;
134+
117135
if (SPIFFS_mounted(&_fs) != 0) {
118136
return true;
119137
}
@@ -124,6 +142,9 @@ class SPIFFSImpl : public FSImpl
124142
if (_tryMount()) {
125143
return true;
126144
}
145+
if (!autoformat) {
146+
return false;
147+
}
127148
auto rc = SPIFFS_format(&_fs);
128149
if (rc != SPIFFS_OK) {
129150
DEBUGV("SPIFFS_format: rc=%d, err=%d\r\n", rc, _fs.err_code);

0 commit comments

Comments
 (0)