diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index 39fd7c0f06..e0148fedce 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -245,6 +245,8 @@ class FS } // namespace fs +extern void spiffs_weak_end(); + #ifndef FS_NO_GLOBALS using fs::FS; using fs::File; diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index 04fc461d1e..6ca1b79147 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -38,10 +38,9 @@ int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) { } - - namespace spiffs_impl { + FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode) { if (!isSpiffsFilenameValid(path)) { diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h index 44f34cd1d4..8b5a923908 100644 --- a/cores/esp8266/spiffs_api.h +++ b/cores/esp8266/spiffs_api.h @@ -58,6 +58,7 @@ extern int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst) __att +extern void enable_real_spiffs_weak_end(); namespace spiffs_impl { @@ -171,6 +172,8 @@ class SPIFFSImpl : public FSImpl bool begin() override { + enable_real_spiffs_weak_end(); // Ensure spiffs_weak_end actually calls SPIFFS.end(); + if (SPIFFS_mounted(&_fs) != 0) { return true; } diff --git a/cores/esp8266/spiffs_weak.cpp b/cores/esp8266/spiffs_weak.cpp new file mode 100644 index 0000000000..d752cd393c --- /dev/null +++ b/cores/esp8266/spiffs_weak.cpp @@ -0,0 +1,20 @@ +/* + * Called from SPIFFS.begin() to avoid linking in httpUpdateServer FS when not needed + */ + +#include + +void enable_real_spiffs_weak_end() +{ + /* + * does nothing + * allows overriding below + */ +} + +/* the following code is linked only if a call to the above function is made somewhere */ + +extern void spiffs_weak_end_redefinable() +{ + SPIFFS.end(); +} diff --git a/cores/esp8266/spiffs_weak_internal.cpp b/cores/esp8266/spiffs_weak_internal.cpp new file mode 100644 index 0000000000..68e71775f3 --- /dev/null +++ b/cores/esp8266/spiffs_weak_internal.cpp @@ -0,0 +1,15 @@ +extern void spiffs_weak_end_redefinable() __attribute__((weak)); +extern void spiffs_weak_end_redefinable(void) +{ + /* noop unless oveerridden by SPIFFS.begin() */ +} + +static void spiffs_weak_end_custom (void) __attribute__((weakref("spiffs_weak_end_redefinable"))); + +extern void spiffs_weak_end (void) +{ + spiffs_weak_end_custom(); +} + + + diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h index 6761177a0a..2f633e1680 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h @@ -94,8 +94,8 @@ void ESP8266HTTPUpdateServerTemplate::setup(ESP8266WebServerTemplate Serial.printf("Update: %s\n", upload.filename.c_str()); if (upload.name == "filesystem") { size_t fsSize = ((size_t) &_FS_end - (size_t) &_FS_start); - SPIFFS.end(); - LittleFS.end(); + spiffs_weak_end(); + littlefs_weak_end(); if (!Update.begin(fsSize, U_FS)){//start with max available size if (_serial_output) Update.printError(Serial); } diff --git a/libraries/LittleFS/src/LittleFS.h b/libraries/LittleFS/src/LittleFS.h index 2a35869eda..ac359894f7 100644 --- a/libraries/LittleFS/src/LittleFS.h +++ b/libraries/LittleFS/src/LittleFS.h @@ -39,6 +39,9 @@ using namespace fs; +extern void enable_real_littlefs_weak_end(); +extern void littlefs_weak_end(); + namespace littlefs_impl { class LittleFSFileImpl; @@ -181,6 +184,8 @@ class LittleFSImpl : public FSImpl } bool begin() override { + enable_real_littlefs_weak_end(); // Ensure littlefs_weak_end actually calls LittleFS.end(); + if (_size <= 0) { DEBUGV("LittleFS size is <= zero"); return false; diff --git a/libraries/LittleFS/src/littlefs_weak.cpp b/libraries/LittleFS/src/littlefs_weak.cpp new file mode 100644 index 0000000000..d88298d8bf --- /dev/null +++ b/libraries/LittleFS/src/littlefs_weak.cpp @@ -0,0 +1,20 @@ +/* + * Called from LittleFS.begin() to avoid linking in httpUpdateServer FS when not needed + */ + +#include + +void enable_real_littlefs_weak_end() +{ + /* + * does nothing + * allows overriding below + */ +} + +/* the following code is linked only if a call to the above function is made somewhere */ + +extern void littlefs_weak_end_redefinable() +{ + LittleFS.end(); +} diff --git a/libraries/LittleFS/src/littlefs_weak_internal.cpp b/libraries/LittleFS/src/littlefs_weak_internal.cpp new file mode 100644 index 0000000000..e8b9bc97e9 --- /dev/null +++ b/libraries/LittleFS/src/littlefs_weak_internal.cpp @@ -0,0 +1,15 @@ +extern void littlefs_weak_end_redefinable() __attribute__((weak)); +extern void littlefs_weak_end_redefinable(void) +{ + /* noop unless oveerridden by SPIFFS.begin() */ +} + +static void littlefs_weak_end_custom (void) __attribute__((weakref("littlefs_weak_end_redefinable"))); + +extern void littlefs_weak_end (void) +{ + littlefs_weak_end_custom(); +} + + +