1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Make SPIFFS and LittleFS stay out of link when not needed (#6699)

* define two weak functions defaulting to no-op
redefine them to do something useful when either spiffs or littlefs are used

* noop

* single entry point for closing FSes

* rename functions, override when instanciated, add link to explanation

* spiffs: call end on destructor
This commit is contained in:
david gauchard 2019-11-07 01:37:52 +01:00 committed by Develo
parent c28838d980
commit 6f7eb2828a
6 changed files with 62 additions and 3 deletions

View File

@ -245,6 +245,13 @@ protected:
} // namespace fs } // namespace fs
extern "C"
{
void close_all_fs(void);
void littlefs_request_end(void);
void spiffs_request_end(void);
}
#ifndef FS_NO_GLOBALS #ifndef FS_NO_GLOBALS
using fs::FS; using fs::FS;
using fs::File; using fs::File;

33
cores/esp8266/FSnoop.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* no-op implementations
* used/linked when no strong implementation already exists elsewhere
*/
#include <FS.h>
extern "C"
{
void close_all_fs(void)
{
littlefs_request_end();
spiffs_request_end();
}
// default weak definitions
// they are overriden in their respective real implementation
// hint: https://github.com/esp8266/Arduino/pull/6699#issuecomment-549085382
void littlefs_request_end(void) __attribute__((weak));
void littlefs_request_end(void)
{
//ets_printf("debug: noop: littlefs_request_end\n");
}
void spiffs_request_end(void) __attribute__((weak));
void spiffs_request_end(void)
{
//ets_printf("debug: noop: spiffs_request_end\n");
}
}

View File

@ -141,6 +141,14 @@ FS SPIFFS = FS(FSImplPtr(new spiffs_impl::SPIFFSImpl(
FS_PHYS_PAGE, FS_PHYS_PAGE,
FS_PHYS_BLOCK, FS_PHYS_BLOCK,
SPIFFS_MAX_OPEN_FILES))); SPIFFS_MAX_OPEN_FILES)));
extern "C" void spiffs_request_end(void)
{
// override default weak function
//ets_printf("debug: not weak spiffs end\n");
SPIFFS.end();
}
#endif // ARDUINO #endif // ARDUINO
#endif // !CORE_MOCK #endif // !CORE_MOCK

View File

@ -80,6 +80,11 @@ public:
memset(&_fs, 0, sizeof(_fs)); memset(&_fs, 0, sizeof(_fs));
} }
~SPIFFSImpl()
{
end();
}
FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) override; FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) override;
bool exists(const char* path) override; bool exists(const char* path) override;
DirImplPtr openDir(const char* path) override; DirImplPtr openDir(const char* path) override;

View File

@ -5,7 +5,6 @@
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <flash_hal.h> #include <flash_hal.h>
#include <FS.h> #include <FS.h>
#include <LittleFS.h>
#include "StreamString.h" #include "StreamString.h"
#include "ESP8266HTTPUpdateServer.h" #include "ESP8266HTTPUpdateServer.h"
@ -94,8 +93,7 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
Serial.printf("Update: %s\n", upload.filename.c_str()); Serial.printf("Update: %s\n", upload.filename.c_str());
if (upload.name == "filesystem") { if (upload.name == "filesystem") {
size_t fsSize = ((size_t) &_FS_end - (size_t) &_FS_start); size_t fsSize = ((size_t) &_FS_end - (size_t) &_FS_start);
SPIFFS.end(); close_all_fs();
LittleFS.end();
if (!Update.begin(fsSize, U_FS)){//start with max available size if (!Update.begin(fsSize, U_FS)){//start with max available size
if (_serial_output) Update.printError(Serial); if (_serial_output) Update.printError(Serial);
} }

View File

@ -190,6 +190,14 @@ int LittleFSImpl::lfs_flash_sync(const struct lfs_config *c) {
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_LITTLEFS) #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_LITTLEFS)
FS LittleFS = FS(FSImplPtr(new littlefs_impl::LittleFSImpl(FS_PHYS_ADDR, FS_PHYS_SIZE, FS_PHYS_PAGE, FS_PHYS_BLOCK, FS_MAX_OPEN_FILES))); FS LittleFS = FS(FSImplPtr(new littlefs_impl::LittleFSImpl(FS_PHYS_ADDR, FS_PHYS_SIZE, FS_PHYS_PAGE, FS_PHYS_BLOCK, FS_MAX_OPEN_FILES)));
extern "C" void littlefs_request_end(void)
{
// override default weak function
//ets_printf("debug: not weak littlefs end\n");
LittleFS.end();
}
#endif #endif
#endif // !CORE_MOCK #endif // !CORE_MOCK