Skip to content

WIP -Make SPIFFS and LittleFS stay out of link when not needed #6697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ class FS

} // namespace fs

extern void spiffs_weak_end();

#ifndef FS_NO_GLOBALS
using fs::FS;
using fs::File;
Expand Down
3 changes: 1 addition & 2 deletions cores/esp8266/spiffs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions cores/esp8266/spiffs_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 20 additions & 0 deletions cores/esp8266/spiffs_weak.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Called from SPIFFS.begin() to avoid linking in httpUpdateServer FS when not needed
*/

#include <FS.h>

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();
}
15 changes: 15 additions & 0 deletions cores/esp8266/spiffs_weak_internal.cpp
Original file line number Diff line number Diff line change
@@ -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();
}



Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::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);
}
Expand Down
5 changes: 5 additions & 0 deletions libraries/LittleFS/src/LittleFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@

using namespace fs;

extern void enable_real_littlefs_weak_end();
extern void littlefs_weak_end();

namespace littlefs_impl {

class LittleFSFileImpl;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions libraries/LittleFS/src/littlefs_weak.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Called from LittleFS.begin() to avoid linking in httpUpdateServer FS when not needed
*/

#include <LittleFS.h>

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();
}
15 changes: 15 additions & 0 deletions libraries/LittleFS/src/littlefs_weak_internal.cpp
Original file line number Diff line number Diff line change
@@ -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();
}